osd.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * (C) Copyright 2010
  3. * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <i2c.h>
  25. #include <asm/io.h>
  26. #include "fpga.h"
  27. #define CH7301_I2C_ADDR 0x75
  28. #define PIXCLK_640_480_60 25180000
  29. #define BASE_WIDTH 32
  30. #define BASE_HEIGHT 16
  31. #define BUFSIZE (BASE_WIDTH * BASE_HEIGHT)
  32. enum {
  33. REG_CONTROL = 0x0010,
  34. REG_MPC3W_CONTROL = 0x001a,
  35. REG_VIDEOCONTROL = 0x0042,
  36. REG_OSDVERSION = 0x0100,
  37. REG_OSDFEATURES = 0x0102,
  38. REG_OSDCONTROL = 0x0104,
  39. REG_XY_SIZE = 0x0106,
  40. REG_VIDEOMEM = 0x0800,
  41. };
  42. enum {
  43. CH7301_CM = 0x1c, /* Clock Mode Register */
  44. CH7301_IC = 0x1d, /* Input Clock Register */
  45. CH7301_GPIO = 0x1e, /* GPIO Control Register */
  46. CH7301_IDF = 0x1f, /* Input Data Format Register */
  47. CH7301_CD = 0x20, /* Connection Detect Register */
  48. CH7301_DC = 0x21, /* DAC Control Register */
  49. CH7301_HPD = 0x23, /* Hot Plug Detection Register */
  50. CH7301_TCTL = 0x31, /* DVI Control Input Register */
  51. CH7301_TPCP = 0x33, /* DVI PLL Charge Pump Ctrl Register */
  52. CH7301_TPD = 0x34, /* DVI PLL Divide Register */
  53. CH7301_TPVT = 0x35, /* DVI PLL Supply Control Register */
  54. CH7301_TPF = 0x36, /* DVI PLL Filter Register */
  55. CH7301_TCT = 0x37, /* DVI Clock Test Register */
  56. CH7301_TSTP = 0x48, /* Test Pattern Register */
  57. CH7301_PM = 0x49, /* Power Management register */
  58. CH7301_VID = 0x4a, /* Version ID Register */
  59. CH7301_DID = 0x4b, /* Device ID Register */
  60. CH7301_DSP = 0x56, /* DVI Sync polarity Register */
  61. };
  62. static void mpc92469ac_calc_parameters(unsigned int fout,
  63. unsigned int *post_div, unsigned int *feedback_div)
  64. {
  65. unsigned int n = *post_div;
  66. unsigned int m = *feedback_div;
  67. unsigned int a;
  68. unsigned int b = 14745600 / 16;
  69. if (fout < 50169600)
  70. n = 8;
  71. else if (fout < 100339199)
  72. n = 4;
  73. else if (fout < 200678399)
  74. n = 2;
  75. else
  76. n = 1;
  77. a = fout * n + (b / 2); /* add b/2 for proper rounding */
  78. m = a / b;
  79. *post_div = n;
  80. *feedback_div = m;
  81. }
  82. static void mpc92469ac_set(unsigned int fout)
  83. {
  84. unsigned int n;
  85. unsigned int m;
  86. unsigned int bitval = 0;
  87. mpc92469ac_calc_parameters(fout, &n, &m);
  88. switch (n) {
  89. case 1:
  90. bitval = 0x00;
  91. break;
  92. case 2:
  93. bitval = 0x01;
  94. break;
  95. case 4:
  96. bitval = 0x02;
  97. break;
  98. case 8:
  99. bitval = 0x03;
  100. break;
  101. }
  102. fpga_set_reg(REG_MPC3W_CONTROL, (bitval << 9) | m);
  103. }
  104. static int osd_write_videomem(unsigned offset, u16 *data, size_t charcount)
  105. {
  106. unsigned int k;
  107. for (k = 0; k < charcount; ++k) {
  108. if (offset + k >= BUFSIZE)
  109. return -1;
  110. fpga_set_reg(REG_VIDEOMEM + 2 * (offset + k), data[k]);
  111. }
  112. return charcount;
  113. }
  114. static int osd_print(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  115. {
  116. unsigned x;
  117. unsigned y;
  118. unsigned charcount;
  119. unsigned len;
  120. u8 color;
  121. unsigned int k;
  122. u16 buf[BUFSIZE];
  123. char *text;
  124. if (argc < 5) {
  125. return cmd_usage(cmdtp);
  126. }
  127. x = simple_strtoul(argv[1], NULL, 16);
  128. y = simple_strtoul(argv[2], NULL, 16);
  129. color = simple_strtoul(argv[3], NULL, 16);
  130. text = argv[4];
  131. charcount = strlen(text);
  132. len = (charcount > BUFSIZE) ? BUFSIZE : charcount;
  133. for (k = 0; k < len; ++k)
  134. buf[k] = (text[k] << 8) | color;
  135. return osd_write_videomem(y * BASE_WIDTH + x, buf, len);
  136. }
  137. int osd_probe(void)
  138. {
  139. u8 value;
  140. u16 version = fpga_get_reg(REG_OSDVERSION);
  141. u16 features = fpga_get_reg(REG_OSDFEATURES);
  142. unsigned width;
  143. unsigned height;
  144. width = ((features & 0x3f00) >> 8) + 1;
  145. height = (features & 0x001f) + 1;
  146. printf("OSD: Digital-OSD version %01d.%02d, %d" "x%d characters\n",
  147. version/100, version%100, width, height);
  148. value = i2c_reg_read(CH7301_I2C_ADDR, CH7301_DID);
  149. if (value != 0x17) {
  150. printf(" Probing CH7301 failed, DID %02x\n", value);
  151. return -1;
  152. }
  153. i2c_reg_write(CH7301_I2C_ADDR, CH7301_TPCP, 0x08);
  154. i2c_reg_write(CH7301_I2C_ADDR, CH7301_TPD, 0x16);
  155. i2c_reg_write(CH7301_I2C_ADDR, CH7301_TPF, 0x60);
  156. i2c_reg_write(CH7301_I2C_ADDR, CH7301_DC, 0x09);
  157. i2c_reg_write(CH7301_I2C_ADDR, CH7301_PM, 0xc0);
  158. mpc92469ac_set(PIXCLK_640_480_60);
  159. fpga_set_reg(REG_VIDEOCONTROL, 0x0002);
  160. fpga_set_reg(REG_OSDCONTROL, 0x0049);
  161. fpga_set_reg(REG_XY_SIZE, ((32 - 1) << 8) | (16 - 1));
  162. return 0;
  163. }
  164. int osd_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  165. {
  166. unsigned x;
  167. unsigned y;
  168. unsigned k;
  169. u16 buffer[BASE_WIDTH];
  170. char *rp;
  171. u16 *wp = buffer;
  172. unsigned count = (argc > 4) ? simple_strtoul(argv[4], NULL, 16) : 1;
  173. if ((argc < 4) || (strlen(argv[3]) % 4)) {
  174. return cmd_usage(cmdtp);
  175. }
  176. x = simple_strtoul(argv[1], NULL, 16);
  177. y = simple_strtoul(argv[2], NULL, 16);
  178. rp = argv[3];
  179. while (*rp) {
  180. char substr[5];
  181. memcpy(substr, rp, 4);
  182. substr[4] = 0;
  183. *wp = simple_strtoul(substr, NULL, 16);
  184. rp += 4;
  185. wp++;
  186. if (wp - buffer > BASE_WIDTH)
  187. break;
  188. }
  189. for (k = 0; k < count; ++k) {
  190. unsigned offset = y * BASE_WIDTH + x + k * (wp - buffer);
  191. osd_write_videomem(offset, buffer, wp - buffer);
  192. }
  193. return 0;
  194. }
  195. U_BOOT_CMD(
  196. osdw, 5, 0, osd_write,
  197. "write 16-bit hex encoded buffer to osd memory",
  198. "pos_x pos_y buffer count\n"
  199. );
  200. U_BOOT_CMD(
  201. osdp, 5, 0, osd_print,
  202. "write ASCII buffer to osd memory",
  203. "pos_x pos_y color text\n"
  204. );