Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010 |
| 3 | * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Dirk Eibach | 20614a2 | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 9 | #include <i2c.h> |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 10 | #include <malloc.h> |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 11 | |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 12 | #include "ch7301.h" |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 13 | #include "dp501.h" |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 14 | #include <gdsys_fpga.h> |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 15 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 16 | #define ICS8N3QV01_I2C_ADDR 0x6E |
Dirk Eibach | cad3e71 | 2011-04-06 13:53:43 +0200 | [diff] [blame] | 17 | #define ICS8N3QV01_FREF 114285000 |
| 18 | #define ICS8N3QV01_FREF_LL 114285000LL |
| 19 | #define ICS8N3QV01_F_DEFAULT_0 156250000LL |
| 20 | #define ICS8N3QV01_F_DEFAULT_1 125000000LL |
| 21 | #define ICS8N3QV01_F_DEFAULT_2 100000000LL |
| 22 | #define ICS8N3QV01_F_DEFAULT_3 25175000LL |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 23 | |
| 24 | #define SIL1178_MASTER_I2C_ADDRESS 0x38 |
| 25 | #define SIL1178_SLAVE_I2C_ADDRESS 0x39 |
| 26 | |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 27 | #define PIXCLK_640_480_60 25180000 |
Dirk Eibach | ec2a3a6 | 2015-10-28 11:46:37 +0100 | [diff] [blame] | 28 | #define MAX_X_CHARS 53 |
| 29 | #define MAX_Y_CHARS 26 |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 30 | |
Dirk Eibach | 981bacd | 2015-10-28 11:46:35 +0100 | [diff] [blame] | 31 | #ifdef CONFIG_SYS_OSD_DH |
| 32 | #define MAX_OSD_SCREEN 8 |
| 33 | #define OSD_DH_BASE 4 |
| 34 | #else |
| 35 | #define MAX_OSD_SCREEN 4 |
| 36 | #endif |
| 37 | |
| 38 | #ifdef CONFIG_SYS_OSD_DH |
| 39 | #define OSD_SET_REG(screen, fld, val) \ |
| 40 | do { \ |
| 41 | if (screen >= OSD_DH_BASE) \ |
| 42 | FPGA_SET_REG(screen - OSD_DH_BASE, osd1.fld, val); \ |
| 43 | else \ |
| 44 | FPGA_SET_REG(screen, osd0.fld, val); \ |
| 45 | } while (0) |
| 46 | #else |
| 47 | #define OSD_SET_REG(screen, fld, val) \ |
| 48 | FPGA_SET_REG(screen, osd0.fld, val) |
| 49 | #endif |
| 50 | |
| 51 | #ifdef CONFIG_SYS_OSD_DH |
| 52 | #define OSD_GET_REG(screen, fld, val) \ |
| 53 | do { \ |
| 54 | if (screen >= OSD_DH_BASE) \ |
| 55 | FPGA_GET_REG(screen - OSD_DH_BASE, osd1.fld, val); \ |
| 56 | else \ |
| 57 | FPGA_GET_REG(screen, osd0.fld, val); \ |
| 58 | } while (0) |
| 59 | #else |
| 60 | #define OSD_GET_REG(screen, fld, val) \ |
| 61 | FPGA_GET_REG(screen, osd0.fld, val) |
| 62 | #endif |
| 63 | |
Dirk Eibach | c0033c3 | 2013-06-26 16:04:30 +0200 | [diff] [blame] | 64 | unsigned int base_width; |
| 65 | unsigned int base_height; |
| 66 | size_t bufsize; |
| 67 | u16 *buf; |
| 68 | |
Dirk Eibach | 981bacd | 2015-10-28 11:46:35 +0100 | [diff] [blame] | 69 | unsigned int osd_screen_mask = 0; |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 70 | |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 71 | #ifdef CONFIG_SYS_ICS8N3QV01_I2C |
| 72 | int ics8n3qv01_i2c[] = CONFIG_SYS_ICS8N3QV01_I2C; |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 73 | #endif |
| 74 | |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 75 | #ifdef CONFIG_SYS_SIL1178_I2C |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 76 | int sil1178_i2c[] = CONFIG_SYS_SIL1178_I2C; |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 77 | #endif |
| 78 | |
| 79 | #ifdef CONFIG_SYS_MPC92469AC |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 80 | static void mpc92469ac_calc_parameters(unsigned int fout, |
| 81 | unsigned int *post_div, unsigned int *feedback_div) |
| 82 | { |
| 83 | unsigned int n = *post_div; |
| 84 | unsigned int m = *feedback_div; |
| 85 | unsigned int a; |
| 86 | unsigned int b = 14745600 / 16; |
| 87 | |
| 88 | if (fout < 50169600) |
| 89 | n = 8; |
| 90 | else if (fout < 100339199) |
| 91 | n = 4; |
| 92 | else if (fout < 200678399) |
| 93 | n = 2; |
| 94 | else |
| 95 | n = 1; |
| 96 | |
| 97 | a = fout * n + (b / 2); /* add b/2 for proper rounding */ |
| 98 | |
| 99 | m = a / b; |
| 100 | |
| 101 | *post_div = n; |
| 102 | *feedback_div = m; |
| 103 | } |
| 104 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 105 | static void mpc92469ac_set(unsigned screen, unsigned int fout) |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 106 | { |
| 107 | unsigned int n; |
| 108 | unsigned int m; |
| 109 | unsigned int bitval = 0; |
| 110 | mpc92469ac_calc_parameters(fout, &n, &m); |
| 111 | |
| 112 | switch (n) { |
| 113 | case 1: |
| 114 | bitval = 0x00; |
| 115 | break; |
| 116 | case 2: |
| 117 | bitval = 0x01; |
| 118 | break; |
| 119 | case 4: |
| 120 | bitval = 0x02; |
| 121 | break; |
| 122 | case 8: |
| 123 | bitval = 0x03; |
| 124 | break; |
| 125 | } |
| 126 | |
Dirk Eibach | 20614a2 | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 127 | FPGA_SET_REG(screen, mpc3w_control, (bitval << 9) | m); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 128 | } |
| 129 | #endif |
| 130 | |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 131 | #ifdef CONFIG_SYS_ICS8N3QV01_I2C |
Dirk Eibach | cad3e71 | 2011-04-06 13:53:43 +0200 | [diff] [blame] | 132 | |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 133 | static unsigned int ics8n3qv01_get_fout_calc(unsigned index) |
Dirk Eibach | cad3e71 | 2011-04-06 13:53:43 +0200 | [diff] [blame] | 134 | { |
| 135 | unsigned long long n; |
| 136 | unsigned long long mint; |
| 137 | unsigned long long mfrac; |
| 138 | u8 reg_a, reg_b, reg_c, reg_d, reg_f; |
| 139 | unsigned long long fout_calc; |
| 140 | |
| 141 | if (index > 3) |
| 142 | return 0; |
| 143 | |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 144 | reg_a = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 0 + index); |
| 145 | reg_b = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 4 + index); |
| 146 | reg_c = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 8 + index); |
| 147 | reg_d = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 12 + index); |
| 148 | reg_f = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 20 + index); |
Dirk Eibach | cad3e71 | 2011-04-06 13:53:43 +0200 | [diff] [blame] | 149 | |
| 150 | mint = ((reg_a >> 1) & 0x1f) | (reg_f & 0x20); |
| 151 | mfrac = ((reg_a & 0x01) << 17) | (reg_b << 9) | (reg_c << 1) |
| 152 | | (reg_d >> 7); |
| 153 | n = reg_d & 0x7f; |
| 154 | |
| 155 | fout_calc = (mint * ICS8N3QV01_FREF_LL |
| 156 | + mfrac * ICS8N3QV01_FREF_LL / 262144LL |
| 157 | + ICS8N3QV01_FREF_LL / 524288LL |
| 158 | + n / 2) |
| 159 | / n |
| 160 | * 1000000 |
| 161 | / (1000000 - 100); |
| 162 | |
| 163 | return fout_calc; |
| 164 | } |
| 165 | |
| 166 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 167 | static void ics8n3qv01_calc_parameters(unsigned int fout, |
| 168 | unsigned int *_mint, unsigned int *_mfrac, |
| 169 | unsigned int *_n) |
| 170 | { |
| 171 | unsigned int n; |
| 172 | unsigned int foutiic; |
| 173 | unsigned int fvcoiic; |
| 174 | unsigned int mint; |
| 175 | unsigned long long mfrac; |
| 176 | |
Dirk Eibach | cad3e71 | 2011-04-06 13:53:43 +0200 | [diff] [blame] | 177 | n = (2215000000U + fout / 2) / fout; |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 178 | if ((n & 1) && (n > 5)) |
| 179 | n -= 1; |
| 180 | |
| 181 | foutiic = fout - (fout / 10000); |
| 182 | fvcoiic = foutiic * n; |
| 183 | |
| 184 | mint = fvcoiic / 114285000; |
| 185 | if ((mint < 17) || (mint > 63)) |
| 186 | printf("ics8n3qv01_calc_parameters: cannot determine mint\n"); |
| 187 | |
| 188 | mfrac = ((unsigned long long)fvcoiic % 114285000LL) * 262144LL |
| 189 | / 114285000LL; |
| 190 | |
| 191 | *_mint = mint; |
| 192 | *_mfrac = mfrac; |
| 193 | *_n = n; |
| 194 | } |
| 195 | |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 196 | static void ics8n3qv01_set(unsigned int fout) |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 197 | { |
| 198 | unsigned int n; |
| 199 | unsigned int mint; |
| 200 | unsigned int mfrac; |
Dirk Eibach | cad3e71 | 2011-04-06 13:53:43 +0200 | [diff] [blame] | 201 | unsigned int fout_calc; |
| 202 | unsigned long long fout_prog; |
| 203 | long long off_ppm; |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 204 | u8 reg0, reg4, reg8, reg12, reg18, reg20; |
| 205 | |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 206 | fout_calc = ics8n3qv01_get_fout_calc(1); |
Dirk Eibach | cad3e71 | 2011-04-06 13:53:43 +0200 | [diff] [blame] | 207 | off_ppm = (fout_calc - ICS8N3QV01_F_DEFAULT_1) * 1000000 |
| 208 | / ICS8N3QV01_F_DEFAULT_1; |
| 209 | printf(" PLL is off by %lld ppm\n", off_ppm); |
| 210 | fout_prog = (unsigned long long)fout * (unsigned long long)fout_calc |
| 211 | / ICS8N3QV01_F_DEFAULT_1; |
| 212 | ics8n3qv01_calc_parameters(fout_prog, &mint, &mfrac, &n); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 213 | |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 214 | reg0 = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 0) & 0xc0; |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 215 | reg0 |= (mint & 0x1f) << 1; |
| 216 | reg0 |= (mfrac >> 17) & 0x01; |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 217 | i2c_reg_write(ICS8N3QV01_I2C_ADDR, 0, reg0); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 218 | |
| 219 | reg4 = mfrac >> 9; |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 220 | i2c_reg_write(ICS8N3QV01_I2C_ADDR, 4, reg4); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 221 | |
| 222 | reg8 = mfrac >> 1; |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 223 | i2c_reg_write(ICS8N3QV01_I2C_ADDR, 8, reg8); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 224 | |
| 225 | reg12 = mfrac << 7; |
| 226 | reg12 |= n & 0x7f; |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 227 | i2c_reg_write(ICS8N3QV01_I2C_ADDR, 12, reg12); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 228 | |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 229 | reg18 = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 18) & 0x03; |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 230 | reg18 |= 0x20; |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 231 | i2c_reg_write(ICS8N3QV01_I2C_ADDR, 18, reg18); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 232 | |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 233 | reg20 = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 20) & 0x1f; |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 234 | reg20 |= mint & (1 << 5); |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 235 | i2c_reg_write(ICS8N3QV01_I2C_ADDR, 20, reg20); |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 236 | } |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 237 | #endif |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 238 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 239 | static int osd_write_videomem(unsigned screen, unsigned offset, |
| 240 | u16 *data, size_t charcount) |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 241 | { |
| 242 | unsigned int k; |
| 243 | |
| 244 | for (k = 0; k < charcount; ++k) { |
Dirk Eibach | c0033c3 | 2013-06-26 16:04:30 +0200 | [diff] [blame] | 245 | if (offset + k >= bufsize) |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 246 | return -1; |
Dirk Eibach | 981bacd | 2015-10-28 11:46:35 +0100 | [diff] [blame] | 247 | #ifdef CONFIG_SYS_OSD_DH |
| 248 | if (screen >= OSD_DH_BASE) |
| 249 | FPGA_SET_REG(screen - OSD_DH_BASE, |
| 250 | videomem1[offset + k], data[k]); |
| 251 | else |
| 252 | FPGA_SET_REG(screen, videomem0[offset + k], data[k]); |
| 253 | #else |
| 254 | FPGA_SET_REG(screen, videomem0[offset + k], data[k]); |
| 255 | #endif |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | return charcount; |
| 259 | } |
| 260 | |
| 261 | static int osd_print(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 262 | { |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 263 | unsigned screen; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 264 | |
Dirk Eibach | 981bacd | 2015-10-28 11:46:35 +0100 | [diff] [blame] | 265 | if (argc < 5) { |
| 266 | cmd_usage(cmdtp); |
| 267 | return 1; |
| 268 | } |
| 269 | |
| 270 | for (screen = 0; screen < MAX_OSD_SCREEN; ++screen) { |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 271 | unsigned x; |
| 272 | unsigned y; |
| 273 | unsigned charcount; |
| 274 | unsigned len; |
| 275 | u8 color; |
| 276 | unsigned int k; |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 277 | char *text; |
| 278 | int res; |
| 279 | |
Dirk Eibach | 981bacd | 2015-10-28 11:46:35 +0100 | [diff] [blame] | 280 | if (!(osd_screen_mask & (1 << screen))) |
| 281 | continue; |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 282 | |
| 283 | x = simple_strtoul(argv[1], NULL, 16); |
| 284 | y = simple_strtoul(argv[2], NULL, 16); |
| 285 | color = simple_strtoul(argv[3], NULL, 16); |
| 286 | text = argv[4]; |
| 287 | charcount = strlen(text); |
Dirk Eibach | c0033c3 | 2013-06-26 16:04:30 +0200 | [diff] [blame] | 288 | len = (charcount > bufsize) ? bufsize : charcount; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 289 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 290 | for (k = 0; k < len; ++k) |
| 291 | buf[k] = (text[k] << 8) | color; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 292 | |
Dirk Eibach | c0033c3 | 2013-06-26 16:04:30 +0200 | [diff] [blame] | 293 | res = osd_write_videomem(screen, y * base_width + x, buf, len); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 294 | if (res < 0) |
| 295 | return res; |
Dirk Eibach | 6577285 | 2015-10-28 11:46:38 +0100 | [diff] [blame] | 296 | |
| 297 | OSD_SET_REG(screen, control, 0x0049); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 298 | } |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 299 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 300 | return 0; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 301 | } |
| 302 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 303 | int osd_probe(unsigned screen) |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 304 | { |
Dirk Eibach | 20614a2 | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 305 | u16 version; |
| 306 | u16 features; |
Dirk Eibach | 437145e | 2013-07-25 19:28:13 +0200 | [diff] [blame] | 307 | int old_bus = i2c_get_bus_num(); |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 308 | bool pixclock_present = false; |
| 309 | bool output_driver_present = false; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 310 | |
Dirk Eibach | 981bacd | 2015-10-28 11:46:35 +0100 | [diff] [blame] | 311 | OSD_GET_REG(0, version, &version); |
| 312 | OSD_GET_REG(0, features, &features); |
Dirk Eibach | 20614a2 | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 313 | |
Dirk Eibach | c0033c3 | 2013-06-26 16:04:30 +0200 | [diff] [blame] | 314 | base_width = ((features & 0x3f00) >> 8) + 1; |
| 315 | base_height = (features & 0x001f) + 1; |
| 316 | bufsize = base_width * base_height; |
| 317 | buf = malloc(sizeof(u16) * bufsize); |
| 318 | if (!buf) |
| 319 | return -1; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 320 | |
Dirk Eibach | 981bacd | 2015-10-28 11:46:35 +0100 | [diff] [blame] | 321 | #ifdef CONFIG_SYS_OSD_DH |
| 322 | printf("OSD%d-%d: Digital-OSD version %01d.%02d, %d" "x%d characters\n", |
| 323 | (screen >= OSD_DH_BASE) ? (screen - OSD_DH_BASE) : screen, |
| 324 | (screen > 3) ? 1 : 0, version/100, version%100, base_width, |
| 325 | base_height); |
| 326 | #else |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 327 | printf("OSD%d: Digital-OSD version %01d.%02d, %d" "x%d characters\n", |
Dirk Eibach | 981bacd | 2015-10-28 11:46:35 +0100 | [diff] [blame] | 328 | screen, version/100, version%100, base_width, base_height); |
| 329 | #endif |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 330 | /* setup pixclock */ |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 331 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 332 | #ifdef CONFIG_SYS_MPC92469AC |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 333 | pixclock_present = true; |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 334 | mpc92469ac_set(screen, PIXCLK_640_480_60); |
| 335 | #endif |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 336 | |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 337 | #ifdef CONFIG_SYS_ICS8N3QV01_I2C |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 338 | i2c_set_bus_num(ics8n3qv01_i2c[screen]); |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 339 | if (!i2c_probe(ICS8N3QV01_I2C_ADDR)) { |
| 340 | ics8n3qv01_set(PIXCLK_640_480_60); |
| 341 | pixclock_present = true; |
| 342 | } |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 343 | #endif |
| 344 | |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 345 | if (!pixclock_present) |
| 346 | printf(" no pixelclock found\n"); |
| 347 | |
| 348 | /* setup output driver */ |
| 349 | |
| 350 | #ifdef CONFIG_SYS_CH7301_I2C |
Dirk Eibach | b355f17 | 2015-10-28 11:46:32 +0100 | [diff] [blame] | 351 | if (!ch7301_probe(screen, true)) |
| 352 | output_driver_present = true; |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 353 | #endif |
| 354 | |
| 355 | #ifdef CONFIG_SYS_SIL1178_I2C |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 356 | i2c_set_bus_num(sil1178_i2c[screen]); |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 357 | if (!i2c_probe(SIL1178_SLAVE_I2C_ADDRESS)) { |
Dirk Eibach | fffbb2f | 2014-11-13 19:21:15 +0100 | [diff] [blame] | 358 | if (i2c_reg_read(SIL1178_SLAVE_I2C_ADDRESS, 0x02) == 0x06) { |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 359 | /* |
| 360 | * magic initialization sequence, |
| 361 | * adapted from datasheet |
| 362 | */ |
| 363 | i2c_reg_write(SIL1178_SLAVE_I2C_ADDRESS, 0x08, 0x36); |
| 364 | i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0f, 0x44); |
| 365 | i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0f, 0x4c); |
| 366 | i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0e, 0x10); |
| 367 | i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0a, 0x80); |
| 368 | i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x09, 0x30); |
| 369 | i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0c, 0x89); |
| 370 | i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0d, 0x60); |
| 371 | i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x08, 0x36); |
| 372 | i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x08, 0x37); |
| 373 | output_driver_present = true; |
| 374 | } |
| 375 | } |
| 376 | #endif |
| 377 | |
| 378 | #ifdef CONFIG_SYS_DP501_I2C |
Dirk Eibach | e9539ed | 2016-03-16 09:20:11 +0100 | [diff] [blame] | 379 | if (!dp501_probe(screen, true)) |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 380 | output_driver_present = true; |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 381 | #endif |
| 382 | |
Dirk Eibach | ca185b0 | 2014-07-03 09:28:22 +0200 | [diff] [blame] | 383 | if (!output_driver_present) |
| 384 | printf(" no output driver found\n"); |
| 385 | |
Dirk Eibach | 981bacd | 2015-10-28 11:46:35 +0100 | [diff] [blame] | 386 | OSD_SET_REG(screen, xy_size, ((32 - 1) << 8) | (16 - 1)); |
| 387 | OSD_SET_REG(screen, x_pos, 0x007f); |
| 388 | OSD_SET_REG(screen, y_pos, 0x005f); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 389 | |
Dirk Eibach | 981bacd | 2015-10-28 11:46:35 +0100 | [diff] [blame] | 390 | if (pixclock_present && output_driver_present) |
| 391 | osd_screen_mask |= 1 << screen; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 392 | |
Dirk Eibach | 4a3eae1 | 2014-07-03 09:28:17 +0200 | [diff] [blame] | 393 | i2c_set_bus_num(old_bus); |
| 394 | |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | int osd_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 399 | { |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 400 | unsigned screen; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 401 | |
Dirk Eibach | 981bacd | 2015-10-28 11:46:35 +0100 | [diff] [blame] | 402 | if ((argc < 4) || (strlen(argv[3]) % 4)) { |
| 403 | cmd_usage(cmdtp); |
| 404 | return 1; |
| 405 | } |
| 406 | |
| 407 | for (screen = 0; screen < MAX_OSD_SCREEN; ++screen) { |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 408 | unsigned x; |
| 409 | unsigned y; |
| 410 | unsigned k; |
Dirk Eibach | c0033c3 | 2013-06-26 16:04:30 +0200 | [diff] [blame] | 411 | u16 buffer[base_width]; |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 412 | char *rp; |
| 413 | u16 *wp = buffer; |
| 414 | unsigned count = (argc > 4) ? |
| 415 | simple_strtoul(argv[4], NULL, 16) : 1; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 416 | |
Dirk Eibach | 981bacd | 2015-10-28 11:46:35 +0100 | [diff] [blame] | 417 | if (!(osd_screen_mask & (1 << screen))) |
| 418 | continue; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 419 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 420 | x = simple_strtoul(argv[1], NULL, 16); |
| 421 | y = simple_strtoul(argv[2], NULL, 16); |
| 422 | rp = argv[3]; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 423 | |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 424 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 425 | while (*rp) { |
| 426 | char substr[5]; |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 427 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 428 | memcpy(substr, rp, 4); |
| 429 | substr[4] = 0; |
| 430 | *wp = simple_strtoul(substr, NULL, 16); |
| 431 | |
| 432 | rp += 4; |
| 433 | wp++; |
Dirk Eibach | c0033c3 | 2013-06-26 16:04:30 +0200 | [diff] [blame] | 434 | if (wp - buffer > base_width) |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 435 | break; |
| 436 | } |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 437 | |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 438 | for (k = 0; k < count; ++k) { |
| 439 | unsigned offset = |
Dirk Eibach | c0033c3 | 2013-06-26 16:04:30 +0200 | [diff] [blame] | 440 | y * base_width + x + k * (wp - buffer); |
Dirk Eibach | 81b3793 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 441 | osd_write_videomem(screen, offset, buffer, |
| 442 | wp - buffer); |
| 443 | } |
Dirk Eibach | 6577285 | 2015-10-28 11:46:38 +0100 | [diff] [blame] | 444 | |
| 445 | OSD_SET_REG(screen, control, 0x0049); |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
Dirk Eibach | ec2a3a6 | 2015-10-28 11:46:37 +0100 | [diff] [blame] | 451 | int osd_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 452 | { |
| 453 | unsigned screen; |
| 454 | unsigned x; |
| 455 | unsigned y; |
| 456 | |
| 457 | if (argc < 3) { |
| 458 | cmd_usage(cmdtp); |
| 459 | return 1; |
| 460 | } |
| 461 | |
| 462 | x = simple_strtoul(argv[1], NULL, 16); |
| 463 | y = simple_strtoul(argv[2], NULL, 16); |
| 464 | |
| 465 | if (!x || (x > 64) || (x > MAX_X_CHARS) || |
| 466 | !y || (y > 32) || (y > MAX_Y_CHARS)) { |
| 467 | cmd_usage(cmdtp); |
| 468 | return 1; |
| 469 | } |
| 470 | |
| 471 | for (screen = 0; screen < MAX_OSD_SCREEN; ++screen) { |
| 472 | OSD_SET_REG(screen, xy_size, ((x - 1) << 8) | (y - 1)); |
| 473 | OSD_SET_REG(screen, x_pos, 32767 * (640 - 12 * x) / 65535); |
| 474 | OSD_SET_REG(screen, y_pos, 32767 * (480 - 18 * y) / 65535); |
| 475 | } |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
Dirk Eibach | 9a13d81 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 480 | U_BOOT_CMD( |
| 481 | osdw, 5, 0, osd_write, |
| 482 | "write 16-bit hex encoded buffer to osd memory", |
| 483 | "pos_x pos_y buffer count\n" |
| 484 | ); |
| 485 | |
| 486 | U_BOOT_CMD( |
| 487 | osdp, 5, 0, osd_print, |
| 488 | "write ASCII buffer to osd memory", |
| 489 | "pos_x pos_y color text\n" |
| 490 | ); |
Dirk Eibach | ec2a3a6 | 2015-10-28 11:46:37 +0100 | [diff] [blame] | 491 | |
| 492 | U_BOOT_CMD( |
| 493 | osdsize, 3, 0, osd_size, |
| 494 | "set OSD XY size in characters", |
| 495 | "size_x(max. " __stringify(MAX_X_CHARS) |
| 496 | ") size_y(max. " __stringify(MAX_Y_CHARS) ")\n" |
| 497 | ); |