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