162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright (C) 2009 Francisco Jerez. 362306a36Sopenharmony_ci * All Rights Reserved. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 662306a36Sopenharmony_ci * a copy of this software and associated documentation files (the 762306a36Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 862306a36Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 962306a36Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to 1062306a36Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 1162306a36Sopenharmony_ci * the following conditions: 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the 1462306a36Sopenharmony_ci * next paragraph) shall be included in all copies or substantial 1562306a36Sopenharmony_ci * portions of the Software. 1662306a36Sopenharmony_ci * 1762306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 1862306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 1962306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 2062306a36Sopenharmony_ci * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 2162306a36Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 2262306a36Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 2362306a36Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2462306a36Sopenharmony_ci * 2562306a36Sopenharmony_ci */ 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#ifndef __NV17_TV_H__ 2862306a36Sopenharmony_ci#define __NV17_TV_H__ 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_cistruct nv17_tv_state { 3162306a36Sopenharmony_ci uint8_t tv_enc[0x40]; 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci uint32_t hfilter[4][7]; 3462306a36Sopenharmony_ci uint32_t hfilter2[4][7]; 3562306a36Sopenharmony_ci uint32_t vfilter[4][7]; 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci uint32_t ptv_200; 3862306a36Sopenharmony_ci uint32_t ptv_204; 3962306a36Sopenharmony_ci uint32_t ptv_208; 4062306a36Sopenharmony_ci uint32_t ptv_20c; 4162306a36Sopenharmony_ci uint32_t ptv_304; 4262306a36Sopenharmony_ci uint32_t ptv_500; 4362306a36Sopenharmony_ci uint32_t ptv_504; 4462306a36Sopenharmony_ci uint32_t ptv_508; 4562306a36Sopenharmony_ci uint32_t ptv_600; 4662306a36Sopenharmony_ci uint32_t ptv_604; 4762306a36Sopenharmony_ci uint32_t ptv_608; 4862306a36Sopenharmony_ci uint32_t ptv_60c; 4962306a36Sopenharmony_ci uint32_t ptv_610; 5062306a36Sopenharmony_ci uint32_t ptv_614; 5162306a36Sopenharmony_ci}; 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_cienum nv17_tv_norm{ 5462306a36Sopenharmony_ci TV_NORM_PAL, 5562306a36Sopenharmony_ci TV_NORM_PAL_M, 5662306a36Sopenharmony_ci TV_NORM_PAL_N, 5762306a36Sopenharmony_ci TV_NORM_PAL_NC, 5862306a36Sopenharmony_ci TV_NORM_NTSC_M, 5962306a36Sopenharmony_ci TV_NORM_NTSC_J, 6062306a36Sopenharmony_ci NUM_LD_TV_NORMS, 6162306a36Sopenharmony_ci TV_NORM_HD480I = NUM_LD_TV_NORMS, 6262306a36Sopenharmony_ci TV_NORM_HD480P, 6362306a36Sopenharmony_ci TV_NORM_HD576I, 6462306a36Sopenharmony_ci TV_NORM_HD576P, 6562306a36Sopenharmony_ci TV_NORM_HD720P, 6662306a36Sopenharmony_ci TV_NORM_HD1080I, 6762306a36Sopenharmony_ci NUM_TV_NORMS 6862306a36Sopenharmony_ci}; 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_cistruct nv17_tv_encoder { 7162306a36Sopenharmony_ci struct nouveau_encoder base; 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci struct nv17_tv_state state; 7462306a36Sopenharmony_ci struct nv17_tv_state saved_state; 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci int overscan; 7762306a36Sopenharmony_ci int flicker; 7862306a36Sopenharmony_ci int saturation; 7962306a36Sopenharmony_ci int hue; 8062306a36Sopenharmony_ci enum nv17_tv_norm tv_norm; 8162306a36Sopenharmony_ci int subconnector; 8262306a36Sopenharmony_ci int select_subconnector; 8362306a36Sopenharmony_ci uint32_t pin_mask; 8462306a36Sopenharmony_ci}; 8562306a36Sopenharmony_ci#define to_tv_enc(x) container_of(nouveau_encoder(x), \ 8662306a36Sopenharmony_ci struct nv17_tv_encoder, base) 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ciextern const char * const nv17_tv_norm_names[NUM_TV_NORMS]; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ciextern struct nv17_tv_norm_params { 9162306a36Sopenharmony_ci enum { 9262306a36Sopenharmony_ci TV_ENC_MODE, 9362306a36Sopenharmony_ci CTV_ENC_MODE, 9462306a36Sopenharmony_ci } kind; 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci union { 9762306a36Sopenharmony_ci struct { 9862306a36Sopenharmony_ci int hdisplay; 9962306a36Sopenharmony_ci int vdisplay; 10062306a36Sopenharmony_ci int vrefresh; /* mHz */ 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci uint8_t tv_enc[0x40]; 10362306a36Sopenharmony_ci } tv_enc_mode; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci struct { 10662306a36Sopenharmony_ci struct drm_display_mode mode; 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci uint32_t ctv_regs[38]; 10962306a36Sopenharmony_ci } ctv_enc_mode; 11062306a36Sopenharmony_ci }; 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci} nv17_tv_norms[NUM_TV_NORMS]; 11362306a36Sopenharmony_ci#define get_tv_norm(enc) (&nv17_tv_norms[to_tv_enc(enc)->tv_norm]) 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ciextern const struct drm_display_mode nv17_tv_modes[]; 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_cistatic inline int interpolate(int y0, int y1, int y2, int x) 11862306a36Sopenharmony_ci{ 11962306a36Sopenharmony_ci return y1 + (x < 50 ? y1 - y0 : y2 - y1) * (x - 50) / 50; 12062306a36Sopenharmony_ci} 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_civoid nv17_tv_state_save(struct drm_device *dev, struct nv17_tv_state *state); 12362306a36Sopenharmony_civoid nv17_tv_state_load(struct drm_device *dev, struct nv17_tv_state *state); 12462306a36Sopenharmony_civoid nv17_tv_update_properties(struct drm_encoder *encoder); 12562306a36Sopenharmony_civoid nv17_tv_update_rescaler(struct drm_encoder *encoder); 12662306a36Sopenharmony_civoid nv17_ctv_update_rescaler(struct drm_encoder *encoder); 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci/* TV hardware access functions */ 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_cistatic inline void nv_write_ptv(struct drm_device *dev, uint32_t reg, 13162306a36Sopenharmony_ci uint32_t val) 13262306a36Sopenharmony_ci{ 13362306a36Sopenharmony_ci struct nvif_device *device = &nouveau_drm(dev)->client.device; 13462306a36Sopenharmony_ci nvif_wr32(&device->object, reg, val); 13562306a36Sopenharmony_ci} 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_cistatic inline uint32_t nv_read_ptv(struct drm_device *dev, uint32_t reg) 13862306a36Sopenharmony_ci{ 13962306a36Sopenharmony_ci struct nvif_device *device = &nouveau_drm(dev)->client.device; 14062306a36Sopenharmony_ci return nvif_rd32(&device->object, reg); 14162306a36Sopenharmony_ci} 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_cistatic inline void nv_write_tv_enc(struct drm_device *dev, uint8_t reg, 14462306a36Sopenharmony_ci uint8_t val) 14562306a36Sopenharmony_ci{ 14662306a36Sopenharmony_ci nv_write_ptv(dev, NV_PTV_TV_INDEX, reg); 14762306a36Sopenharmony_ci nv_write_ptv(dev, NV_PTV_TV_DATA, val); 14862306a36Sopenharmony_ci} 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_cistatic inline uint8_t nv_read_tv_enc(struct drm_device *dev, uint8_t reg) 15162306a36Sopenharmony_ci{ 15262306a36Sopenharmony_ci nv_write_ptv(dev, NV_PTV_TV_INDEX, reg); 15362306a36Sopenharmony_ci return nv_read_ptv(dev, NV_PTV_TV_DATA); 15462306a36Sopenharmony_ci} 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci#define nv_load_ptv(dev, state, reg) \ 15762306a36Sopenharmony_ci nv_write_ptv(dev, NV_PTV_OFFSET + 0x##reg, state->ptv_##reg) 15862306a36Sopenharmony_ci#define nv_save_ptv(dev, state, reg) \ 15962306a36Sopenharmony_ci state->ptv_##reg = nv_read_ptv(dev, NV_PTV_OFFSET + 0x##reg) 16062306a36Sopenharmony_ci#define nv_load_tv_enc(dev, state, reg) \ 16162306a36Sopenharmony_ci nv_write_tv_enc(dev, 0x##reg, state->tv_enc[0x##reg]) 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci#endif 164