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