1 1.3 riastrad /* $NetBSD: tvnv17.h,v 1.4 2021/12/18 23:45:32 riastradh Exp $ */ 2 1.3 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright (C) 2009 Francisco Jerez. 5 1.1 riastrad * All Rights Reserved. 6 1.1 riastrad * 7 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining 8 1.1 riastrad * a copy of this software and associated documentation files (the 9 1.1 riastrad * "Software"), to deal in the Software without restriction, including 10 1.1 riastrad * without limitation the rights to use, copy, modify, merge, publish, 11 1.1 riastrad * distribute, sublicense, and/or sell copies of the Software, and to 12 1.1 riastrad * permit persons to whom the Software is furnished to do so, subject to 13 1.1 riastrad * the following conditions: 14 1.1 riastrad * 15 1.1 riastrad * The above copyright notice and this permission notice (including the 16 1.1 riastrad * next paragraph) shall be included in all copies or substantial 17 1.1 riastrad * portions of the Software. 18 1.1 riastrad * 19 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 1.1 riastrad * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 1.1 riastrad * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 1.1 riastrad * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 23 1.1 riastrad * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 1.1 riastrad * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 1.1 riastrad * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 1.1 riastrad * 27 1.1 riastrad */ 28 1.1 riastrad 29 1.1 riastrad #ifndef __NV17_TV_H__ 30 1.1 riastrad #define __NV17_TV_H__ 31 1.1 riastrad 32 1.1 riastrad struct nv17_tv_state { 33 1.1 riastrad uint8_t tv_enc[0x40]; 34 1.1 riastrad 35 1.1 riastrad uint32_t hfilter[4][7]; 36 1.1 riastrad uint32_t hfilter2[4][7]; 37 1.1 riastrad uint32_t vfilter[4][7]; 38 1.1 riastrad 39 1.1 riastrad uint32_t ptv_200; 40 1.1 riastrad uint32_t ptv_204; 41 1.1 riastrad uint32_t ptv_208; 42 1.1 riastrad uint32_t ptv_20c; 43 1.1 riastrad uint32_t ptv_304; 44 1.1 riastrad uint32_t ptv_500; 45 1.1 riastrad uint32_t ptv_504; 46 1.1 riastrad uint32_t ptv_508; 47 1.1 riastrad uint32_t ptv_600; 48 1.1 riastrad uint32_t ptv_604; 49 1.1 riastrad uint32_t ptv_608; 50 1.1 riastrad uint32_t ptv_60c; 51 1.1 riastrad uint32_t ptv_610; 52 1.1 riastrad uint32_t ptv_614; 53 1.1 riastrad }; 54 1.1 riastrad 55 1.1 riastrad enum nv17_tv_norm{ 56 1.1 riastrad TV_NORM_PAL, 57 1.1 riastrad TV_NORM_PAL_M, 58 1.1 riastrad TV_NORM_PAL_N, 59 1.1 riastrad TV_NORM_PAL_NC, 60 1.1 riastrad TV_NORM_NTSC_M, 61 1.1 riastrad TV_NORM_NTSC_J, 62 1.1 riastrad NUM_LD_TV_NORMS, 63 1.1 riastrad TV_NORM_HD480I = NUM_LD_TV_NORMS, 64 1.1 riastrad TV_NORM_HD480P, 65 1.1 riastrad TV_NORM_HD576I, 66 1.1 riastrad TV_NORM_HD576P, 67 1.1 riastrad TV_NORM_HD720P, 68 1.1 riastrad TV_NORM_HD1080I, 69 1.1 riastrad NUM_TV_NORMS 70 1.1 riastrad }; 71 1.1 riastrad 72 1.1 riastrad struct nv17_tv_encoder { 73 1.1 riastrad struct nouveau_encoder base; 74 1.1 riastrad 75 1.1 riastrad struct nv17_tv_state state; 76 1.1 riastrad struct nv17_tv_state saved_state; 77 1.1 riastrad 78 1.1 riastrad int overscan; 79 1.1 riastrad int flicker; 80 1.1 riastrad int saturation; 81 1.1 riastrad int hue; 82 1.1 riastrad enum nv17_tv_norm tv_norm; 83 1.1 riastrad int subconnector; 84 1.1 riastrad int select_subconnector; 85 1.1 riastrad uint32_t pin_mask; 86 1.1 riastrad }; 87 1.1 riastrad #define to_tv_enc(x) container_of(nouveau_encoder(x), \ 88 1.1 riastrad struct nv17_tv_encoder, base) 89 1.1 riastrad 90 1.3 riastrad extern const char * const nv17_tv_norm_names[NUM_TV_NORMS]; 91 1.1 riastrad 92 1.2 riastrad extern const struct nv17_tv_norm_params { 93 1.1 riastrad enum { 94 1.1 riastrad TV_ENC_MODE, 95 1.1 riastrad CTV_ENC_MODE, 96 1.1 riastrad } kind; 97 1.1 riastrad 98 1.1 riastrad union { 99 1.1 riastrad struct { 100 1.1 riastrad int hdisplay; 101 1.1 riastrad int vdisplay; 102 1.1 riastrad int vrefresh; /* mHz */ 103 1.1 riastrad 104 1.1 riastrad uint8_t tv_enc[0x40]; 105 1.1 riastrad } tv_enc_mode; 106 1.1 riastrad 107 1.1 riastrad struct { 108 1.1 riastrad struct drm_display_mode mode; 109 1.1 riastrad 110 1.1 riastrad uint32_t ctv_regs[38]; 111 1.1 riastrad } ctv_enc_mode; 112 1.1 riastrad }; 113 1.1 riastrad 114 1.1 riastrad } nv17_tv_norms[NUM_TV_NORMS]; 115 1.1 riastrad #define get_tv_norm(enc) (&nv17_tv_norms[to_tv_enc(enc)->tv_norm]) 116 1.1 riastrad 117 1.1 riastrad extern const struct drm_display_mode nv17_tv_modes[]; 118 1.1 riastrad 119 1.1 riastrad static inline int interpolate(int y0, int y1, int y2, int x) 120 1.1 riastrad { 121 1.1 riastrad return y1 + (x < 50 ? y1 - y0 : y2 - y1) * (x - 50) / 50; 122 1.1 riastrad } 123 1.1 riastrad 124 1.1 riastrad void nv17_tv_state_save(struct drm_device *dev, struct nv17_tv_state *state); 125 1.1 riastrad void nv17_tv_state_load(struct drm_device *dev, struct nv17_tv_state *state); 126 1.1 riastrad void nv17_tv_update_properties(struct drm_encoder *encoder); 127 1.1 riastrad void nv17_tv_update_rescaler(struct drm_encoder *encoder); 128 1.1 riastrad void nv17_ctv_update_rescaler(struct drm_encoder *encoder); 129 1.1 riastrad 130 1.1 riastrad /* TV hardware access functions */ 131 1.1 riastrad 132 1.1 riastrad static inline void nv_write_ptv(struct drm_device *dev, uint32_t reg, 133 1.1 riastrad uint32_t val) 134 1.1 riastrad { 135 1.4 riastrad struct nvif_device *device = &nouveau_drm(dev)->client.device; 136 1.3 riastrad nvif_wr32(&device->object, reg, val); 137 1.1 riastrad } 138 1.1 riastrad 139 1.1 riastrad static inline uint32_t nv_read_ptv(struct drm_device *dev, uint32_t reg) 140 1.1 riastrad { 141 1.4 riastrad struct nvif_device *device = &nouveau_drm(dev)->client.device; 142 1.3 riastrad return nvif_rd32(&device->object, reg); 143 1.1 riastrad } 144 1.1 riastrad 145 1.1 riastrad static inline void nv_write_tv_enc(struct drm_device *dev, uint8_t reg, 146 1.1 riastrad uint8_t val) 147 1.1 riastrad { 148 1.1 riastrad nv_write_ptv(dev, NV_PTV_TV_INDEX, reg); 149 1.1 riastrad nv_write_ptv(dev, NV_PTV_TV_DATA, val); 150 1.1 riastrad } 151 1.1 riastrad 152 1.1 riastrad static inline uint8_t nv_read_tv_enc(struct drm_device *dev, uint8_t reg) 153 1.1 riastrad { 154 1.1 riastrad nv_write_ptv(dev, NV_PTV_TV_INDEX, reg); 155 1.1 riastrad return nv_read_ptv(dev, NV_PTV_TV_DATA); 156 1.1 riastrad } 157 1.1 riastrad 158 1.1 riastrad #define nv_load_ptv(dev, state, reg) \ 159 1.1 riastrad nv_write_ptv(dev, NV_PTV_OFFSET + 0x##reg, state->ptv_##reg) 160 1.1 riastrad #define nv_save_ptv(dev, state, reg) \ 161 1.1 riastrad state->ptv_##reg = nv_read_ptv(dev, NV_PTV_OFFSET + 0x##reg) 162 1.1 riastrad #define nv_load_tv_enc(dev, state, reg) \ 163 1.1 riastrad nv_write_tv_enc(dev, 0x##reg, state->tv_enc[0x##reg]) 164 1.1 riastrad 165 1.1 riastrad #endif 166