tvnv17.h 4.2 KB

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