blob: b288df894ae6e00ad9a1c80c360813c904449ca3 [file] [log] [blame]
Dirk Eibach9a13d812010-10-21 10:50:05 +02001/*
2 * (C) Copyright 2010
3 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Dirk Eibach9a13d812010-10-21 10:50:05 +02006 */
7
8#include <common.h>
Dirk Eibach20614a22013-06-26 16:04:26 +02009#include <i2c.h>
Dirk Eibach437145e2013-07-25 19:28:13 +020010#include <malloc.h>
Dirk Eibach9a13d812010-10-21 10:50:05 +020011
Dirk Eibachb355f172015-10-28 11:46:32 +010012#include "ch7301.h"
Dirk Eibachca185b02014-07-03 09:28:22 +020013#include "dp501.h"
Dirk Eibach81b37932011-01-21 09:31:21 +010014#include <gdsys_fpga.h>
Dirk Eibach9a13d812010-10-21 10:50:05 +020015
Dirk Eibach81b37932011-01-21 09:31:21 +010016#define ICS8N3QV01_I2C_ADDR 0x6E
Dirk Eibachcad3e712011-04-06 13:53:43 +020017#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 Eibach81b37932011-01-21 09:31:21 +010023
24#define SIL1178_MASTER_I2C_ADDRESS 0x38
25#define SIL1178_SLAVE_I2C_ADDRESS 0x39
26
Dirk Eibachca185b02014-07-03 09:28:22 +020027#define DP501_I2C_ADDR 0x08
28
Dirk Eibach9a13d812010-10-21 10:50:05 +020029#define PIXCLK_640_480_60 25180000
30
Dirk Eibach981bacd2015-10-28 11:46:35 +010031#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 Eibachc0033c32013-06-26 16:04:30 +020064unsigned int base_width;
65unsigned int base_height;
66size_t bufsize;
67u16 *buf;
68
Dirk Eibach981bacd2015-10-28 11:46:35 +010069unsigned int osd_screen_mask = 0;
Dirk Eibach437145e2013-07-25 19:28:13 +020070
Dirk Eibachca185b02014-07-03 09:28:22 +020071#ifdef CONFIG_SYS_ICS8N3QV01_I2C
72int ics8n3qv01_i2c[] = CONFIG_SYS_ICS8N3QV01_I2C;
Dirk Eibach437145e2013-07-25 19:28:13 +020073#endif
74
Dirk Eibachca185b02014-07-03 09:28:22 +020075#ifdef CONFIG_SYS_SIL1178_I2C
Dirk Eibach4a3eae12014-07-03 09:28:17 +020076int sil1178_i2c[] = CONFIG_SYS_SIL1178_I2C;
Dirk Eibach81b37932011-01-21 09:31:21 +010077#endif
78
Dirk Eibachca185b02014-07-03 09:28:22 +020079#ifdef CONFIG_SYS_DP501_I2C
80int dp501_i2c[] = CONFIG_SYS_DP501_I2C;
81#endif
82
Dirk Eibach981bacd2015-10-28 11:46:35 +010083#ifdef CONFIG_SYS_DP501_BASE
84int dp501_base[] = CONFIG_SYS_DP501_BASE;
85#endif
Dirk Eibachca185b02014-07-03 09:28:22 +020086
Dirk Eibach81b37932011-01-21 09:31:21 +010087#ifdef CONFIG_SYS_MPC92469AC
Dirk Eibach9a13d812010-10-21 10:50:05 +020088static void mpc92469ac_calc_parameters(unsigned int fout,
89 unsigned int *post_div, unsigned int *feedback_div)
90{
91 unsigned int n = *post_div;
92 unsigned int m = *feedback_div;
93 unsigned int a;
94 unsigned int b = 14745600 / 16;
95
96 if (fout < 50169600)
97 n = 8;
98 else if (fout < 100339199)
99 n = 4;
100 else if (fout < 200678399)
101 n = 2;
102 else
103 n = 1;
104
105 a = fout * n + (b / 2); /* add b/2 for proper rounding */
106
107 m = a / b;
108
109 *post_div = n;
110 *feedback_div = m;
111}
112
Dirk Eibach81b37932011-01-21 09:31:21 +0100113static void mpc92469ac_set(unsigned screen, unsigned int fout)
Dirk Eibach9a13d812010-10-21 10:50:05 +0200114{
115 unsigned int n;
116 unsigned int m;
117 unsigned int bitval = 0;
118 mpc92469ac_calc_parameters(fout, &n, &m);
119
120 switch (n) {
121 case 1:
122 bitval = 0x00;
123 break;
124 case 2:
125 bitval = 0x01;
126 break;
127 case 4:
128 bitval = 0x02;
129 break;
130 case 8:
131 bitval = 0x03;
132 break;
133 }
134
Dirk Eibach20614a22013-06-26 16:04:26 +0200135 FPGA_SET_REG(screen, mpc3w_control, (bitval << 9) | m);
Dirk Eibach81b37932011-01-21 09:31:21 +0100136}
137#endif
138
Dirk Eibachca185b02014-07-03 09:28:22 +0200139#ifdef CONFIG_SYS_ICS8N3QV01_I2C
Dirk Eibachcad3e712011-04-06 13:53:43 +0200140
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200141static unsigned int ics8n3qv01_get_fout_calc(unsigned index)
Dirk Eibachcad3e712011-04-06 13:53:43 +0200142{
143 unsigned long long n;
144 unsigned long long mint;
145 unsigned long long mfrac;
146 u8 reg_a, reg_b, reg_c, reg_d, reg_f;
147 unsigned long long fout_calc;
148
149 if (index > 3)
150 return 0;
151
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200152 reg_a = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 0 + index);
153 reg_b = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 4 + index);
154 reg_c = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 8 + index);
155 reg_d = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 12 + index);
156 reg_f = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 20 + index);
Dirk Eibachcad3e712011-04-06 13:53:43 +0200157
158 mint = ((reg_a >> 1) & 0x1f) | (reg_f & 0x20);
159 mfrac = ((reg_a & 0x01) << 17) | (reg_b << 9) | (reg_c << 1)
160 | (reg_d >> 7);
161 n = reg_d & 0x7f;
162
163 fout_calc = (mint * ICS8N3QV01_FREF_LL
164 + mfrac * ICS8N3QV01_FREF_LL / 262144LL
165 + ICS8N3QV01_FREF_LL / 524288LL
166 + n / 2)
167 / n
168 * 1000000
169 / (1000000 - 100);
170
171 return fout_calc;
172}
173
174
Dirk Eibach81b37932011-01-21 09:31:21 +0100175static void ics8n3qv01_calc_parameters(unsigned int fout,
176 unsigned int *_mint, unsigned int *_mfrac,
177 unsigned int *_n)
178{
179 unsigned int n;
180 unsigned int foutiic;
181 unsigned int fvcoiic;
182 unsigned int mint;
183 unsigned long long mfrac;
184
Dirk Eibachcad3e712011-04-06 13:53:43 +0200185 n = (2215000000U + fout / 2) / fout;
Dirk Eibach81b37932011-01-21 09:31:21 +0100186 if ((n & 1) && (n > 5))
187 n -= 1;
188
189 foutiic = fout - (fout / 10000);
190 fvcoiic = foutiic * n;
191
192 mint = fvcoiic / 114285000;
193 if ((mint < 17) || (mint > 63))
194 printf("ics8n3qv01_calc_parameters: cannot determine mint\n");
195
196 mfrac = ((unsigned long long)fvcoiic % 114285000LL) * 262144LL
197 / 114285000LL;
198
199 *_mint = mint;
200 *_mfrac = mfrac;
201 *_n = n;
202}
203
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200204static void ics8n3qv01_set(unsigned int fout)
Dirk Eibach81b37932011-01-21 09:31:21 +0100205{
206 unsigned int n;
207 unsigned int mint;
208 unsigned int mfrac;
Dirk Eibachcad3e712011-04-06 13:53:43 +0200209 unsigned int fout_calc;
210 unsigned long long fout_prog;
211 long long off_ppm;
Dirk Eibach81b37932011-01-21 09:31:21 +0100212 u8 reg0, reg4, reg8, reg12, reg18, reg20;
213
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200214 fout_calc = ics8n3qv01_get_fout_calc(1);
Dirk Eibachcad3e712011-04-06 13:53:43 +0200215 off_ppm = (fout_calc - ICS8N3QV01_F_DEFAULT_1) * 1000000
216 / ICS8N3QV01_F_DEFAULT_1;
217 printf(" PLL is off by %lld ppm\n", off_ppm);
218 fout_prog = (unsigned long long)fout * (unsigned long long)fout_calc
219 / ICS8N3QV01_F_DEFAULT_1;
220 ics8n3qv01_calc_parameters(fout_prog, &mint, &mfrac, &n);
Dirk Eibach81b37932011-01-21 09:31:21 +0100221
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200222 reg0 = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 0) & 0xc0;
Dirk Eibach81b37932011-01-21 09:31:21 +0100223 reg0 |= (mint & 0x1f) << 1;
224 reg0 |= (mfrac >> 17) & 0x01;
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200225 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 0, reg0);
Dirk Eibach81b37932011-01-21 09:31:21 +0100226
227 reg4 = mfrac >> 9;
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200228 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 4, reg4);
Dirk Eibach81b37932011-01-21 09:31:21 +0100229
230 reg8 = mfrac >> 1;
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200231 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 8, reg8);
Dirk Eibach81b37932011-01-21 09:31:21 +0100232
233 reg12 = mfrac << 7;
234 reg12 |= n & 0x7f;
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200235 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 12, reg12);
Dirk Eibach81b37932011-01-21 09:31:21 +0100236
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200237 reg18 = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 18) & 0x03;
Dirk Eibach81b37932011-01-21 09:31:21 +0100238 reg18 |= 0x20;
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200239 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 18, reg18);
Dirk Eibach81b37932011-01-21 09:31:21 +0100240
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200241 reg20 = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 20) & 0x1f;
Dirk Eibach81b37932011-01-21 09:31:21 +0100242 reg20 |= mint & (1 << 5);
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200243 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 20, reg20);
Dirk Eibach9a13d812010-10-21 10:50:05 +0200244}
Dirk Eibach81b37932011-01-21 09:31:21 +0100245#endif
Dirk Eibach9a13d812010-10-21 10:50:05 +0200246
Dirk Eibach81b37932011-01-21 09:31:21 +0100247static int osd_write_videomem(unsigned screen, unsigned offset,
248 u16 *data, size_t charcount)
Dirk Eibach9a13d812010-10-21 10:50:05 +0200249{
250 unsigned int k;
251
252 for (k = 0; k < charcount; ++k) {
Dirk Eibachc0033c32013-06-26 16:04:30 +0200253 if (offset + k >= bufsize)
Dirk Eibach9a13d812010-10-21 10:50:05 +0200254 return -1;
Dirk Eibach981bacd2015-10-28 11:46:35 +0100255#ifdef CONFIG_SYS_OSD_DH
256 if (screen >= OSD_DH_BASE)
257 FPGA_SET_REG(screen - OSD_DH_BASE,
258 videomem1[offset + k], data[k]);
259 else
260 FPGA_SET_REG(screen, videomem0[offset + k], data[k]);
261#else
262 FPGA_SET_REG(screen, videomem0[offset + k], data[k]);
263#endif
Dirk Eibach9a13d812010-10-21 10:50:05 +0200264 }
265
266 return charcount;
267}
268
269static int osd_print(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
270{
Dirk Eibach81b37932011-01-21 09:31:21 +0100271 unsigned screen;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200272
Dirk Eibach981bacd2015-10-28 11:46:35 +0100273 if (argc < 5) {
274 cmd_usage(cmdtp);
275 return 1;
276 }
277
278 for (screen = 0; screen < MAX_OSD_SCREEN; ++screen) {
Dirk Eibach81b37932011-01-21 09:31:21 +0100279 unsigned x;
280 unsigned y;
281 unsigned charcount;
282 unsigned len;
283 u8 color;
284 unsigned int k;
Dirk Eibach81b37932011-01-21 09:31:21 +0100285 char *text;
286 int res;
287
Dirk Eibach981bacd2015-10-28 11:46:35 +0100288 if (!(osd_screen_mask & (1 << screen)))
289 continue;
Dirk Eibach81b37932011-01-21 09:31:21 +0100290
291 x = simple_strtoul(argv[1], NULL, 16);
292 y = simple_strtoul(argv[2], NULL, 16);
293 color = simple_strtoul(argv[3], NULL, 16);
294 text = argv[4];
295 charcount = strlen(text);
Dirk Eibachc0033c32013-06-26 16:04:30 +0200296 len = (charcount > bufsize) ? bufsize : charcount;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200297
Dirk Eibach81b37932011-01-21 09:31:21 +0100298 for (k = 0; k < len; ++k)
299 buf[k] = (text[k] << 8) | color;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200300
Dirk Eibachc0033c32013-06-26 16:04:30 +0200301 res = osd_write_videomem(screen, y * base_width + x, buf, len);
Dirk Eibach81b37932011-01-21 09:31:21 +0100302 if (res < 0)
303 return res;
304 }
Dirk Eibach9a13d812010-10-21 10:50:05 +0200305
Dirk Eibach81b37932011-01-21 09:31:21 +0100306 return 0;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200307}
308
Dirk Eibach81b37932011-01-21 09:31:21 +0100309int osd_probe(unsigned screen)
Dirk Eibach9a13d812010-10-21 10:50:05 +0200310{
Dirk Eibach20614a22013-06-26 16:04:26 +0200311 u16 version;
312 u16 features;
Dirk Eibach437145e2013-07-25 19:28:13 +0200313 int old_bus = i2c_get_bus_num();
Dirk Eibachca185b02014-07-03 09:28:22 +0200314 bool pixclock_present = false;
315 bool output_driver_present = false;
Dirk Eibach981bacd2015-10-28 11:46:35 +0100316#ifdef CONFIG_SYS_DP501_I2C
317#ifdef CONFIG_SYS_DP501_BASE
318 uint8_t dp501_addr = dp501_base[screen];
319#else
320 uint8_t dp501_addr = DP501_I2C_ADDR;
321#endif
322#endif
Dirk Eibach9a13d812010-10-21 10:50:05 +0200323
Dirk Eibach981bacd2015-10-28 11:46:35 +0100324 OSD_GET_REG(0, version, &version);
325 OSD_GET_REG(0, features, &features);
Dirk Eibach20614a22013-06-26 16:04:26 +0200326
Dirk Eibachc0033c32013-06-26 16:04:30 +0200327 base_width = ((features & 0x3f00) >> 8) + 1;
328 base_height = (features & 0x001f) + 1;
329 bufsize = base_width * base_height;
330 buf = malloc(sizeof(u16) * bufsize);
331 if (!buf)
332 return -1;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200333
Dirk Eibach981bacd2015-10-28 11:46:35 +0100334#ifdef CONFIG_SYS_OSD_DH
335 printf("OSD%d-%d: Digital-OSD version %01d.%02d, %d" "x%d characters\n",
336 (screen >= OSD_DH_BASE) ? (screen - OSD_DH_BASE) : screen,
337 (screen > 3) ? 1 : 0, version/100, version%100, base_width,
338 base_height);
339#else
Dirk Eibach81b37932011-01-21 09:31:21 +0100340 printf("OSD%d: Digital-OSD version %01d.%02d, %d" "x%d characters\n",
Dirk Eibach981bacd2015-10-28 11:46:35 +0100341 screen, version/100, version%100, base_width, base_height);
342#endif
Dirk Eibachca185b02014-07-03 09:28:22 +0200343 /* setup pixclock */
Dirk Eibach9a13d812010-10-21 10:50:05 +0200344
Dirk Eibach81b37932011-01-21 09:31:21 +0100345#ifdef CONFIG_SYS_MPC92469AC
Dirk Eibachca185b02014-07-03 09:28:22 +0200346 pixclock_present = true;
Dirk Eibach81b37932011-01-21 09:31:21 +0100347 mpc92469ac_set(screen, PIXCLK_640_480_60);
348#endif
Dirk Eibach9a13d812010-10-21 10:50:05 +0200349
Dirk Eibachca185b02014-07-03 09:28:22 +0200350#ifdef CONFIG_SYS_ICS8N3QV01_I2C
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200351 i2c_set_bus_num(ics8n3qv01_i2c[screen]);
Dirk Eibachca185b02014-07-03 09:28:22 +0200352 if (!i2c_probe(ICS8N3QV01_I2C_ADDR)) {
353 ics8n3qv01_set(PIXCLK_640_480_60);
354 pixclock_present = true;
355 }
Dirk Eibach81b37932011-01-21 09:31:21 +0100356#endif
357
Dirk Eibachca185b02014-07-03 09:28:22 +0200358 if (!pixclock_present)
359 printf(" no pixelclock found\n");
360
361 /* setup output driver */
362
363#ifdef CONFIG_SYS_CH7301_I2C
Dirk Eibachb355f172015-10-28 11:46:32 +0100364 if (!ch7301_probe(screen, true))
365 output_driver_present = true;
Dirk Eibachca185b02014-07-03 09:28:22 +0200366#endif
367
368#ifdef CONFIG_SYS_SIL1178_I2C
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200369 i2c_set_bus_num(sil1178_i2c[screen]);
Dirk Eibachca185b02014-07-03 09:28:22 +0200370 if (!i2c_probe(SIL1178_SLAVE_I2C_ADDRESS)) {
Dirk Eibachfffbb2f2014-11-13 19:21:15 +0100371 if (i2c_reg_read(SIL1178_SLAVE_I2C_ADDRESS, 0x02) == 0x06) {
Dirk Eibachca185b02014-07-03 09:28:22 +0200372 /*
373 * magic initialization sequence,
374 * adapted from datasheet
375 */
376 i2c_reg_write(SIL1178_SLAVE_I2C_ADDRESS, 0x08, 0x36);
377 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0f, 0x44);
378 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0f, 0x4c);
379 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0e, 0x10);
380 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0a, 0x80);
381 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x09, 0x30);
382 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0c, 0x89);
383 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0d, 0x60);
384 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x08, 0x36);
385 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x08, 0x37);
386 output_driver_present = true;
387 }
388 }
389#endif
390
391#ifdef CONFIG_SYS_DP501_I2C
392 i2c_set_bus_num(dp501_i2c[screen]);
Dirk Eibach981bacd2015-10-28 11:46:35 +0100393 if (!i2c_probe(dp501_addr)) {
394 dp501_powerup(dp501_addr);
Dirk Eibachca185b02014-07-03 09:28:22 +0200395 output_driver_present = true;
Dirk Eibach81b37932011-01-21 09:31:21 +0100396 }
Dirk Eibach81b37932011-01-21 09:31:21 +0100397#endif
398
Dirk Eibachca185b02014-07-03 09:28:22 +0200399 if (!output_driver_present)
400 printf(" no output driver found\n");
401
Dirk Eibach981bacd2015-10-28 11:46:35 +0100402 OSD_SET_REG(screen, control, 0x0049);
Dirk Eibach20614a22013-06-26 16:04:26 +0200403
Dirk Eibach981bacd2015-10-28 11:46:35 +0100404 OSD_SET_REG(screen, xy_size, ((32 - 1) << 8) | (16 - 1));
405 OSD_SET_REG(screen, x_pos, 0x007f);
406 OSD_SET_REG(screen, y_pos, 0x005f);
Dirk Eibach81b37932011-01-21 09:31:21 +0100407
Dirk Eibach981bacd2015-10-28 11:46:35 +0100408 if (pixclock_present && output_driver_present)
409 osd_screen_mask |= 1 << screen;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200410
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200411 i2c_set_bus_num(old_bus);
412
Dirk Eibach9a13d812010-10-21 10:50:05 +0200413 return 0;
414}
415
416int osd_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
417{
Dirk Eibach81b37932011-01-21 09:31:21 +0100418 unsigned screen;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200419
Dirk Eibach981bacd2015-10-28 11:46:35 +0100420 if ((argc < 4) || (strlen(argv[3]) % 4)) {
421 cmd_usage(cmdtp);
422 return 1;
423 }
424
425 for (screen = 0; screen < MAX_OSD_SCREEN; ++screen) {
Dirk Eibach81b37932011-01-21 09:31:21 +0100426 unsigned x;
427 unsigned y;
428 unsigned k;
Dirk Eibachc0033c32013-06-26 16:04:30 +0200429 u16 buffer[base_width];
Dirk Eibach81b37932011-01-21 09:31:21 +0100430 char *rp;
431 u16 *wp = buffer;
432 unsigned count = (argc > 4) ?
433 simple_strtoul(argv[4], NULL, 16) : 1;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200434
Dirk Eibach981bacd2015-10-28 11:46:35 +0100435 if (!(osd_screen_mask & (1 << screen)))
436 continue;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200437
Dirk Eibach81b37932011-01-21 09:31:21 +0100438 x = simple_strtoul(argv[1], NULL, 16);
439 y = simple_strtoul(argv[2], NULL, 16);
440 rp = argv[3];
Dirk Eibach9a13d812010-10-21 10:50:05 +0200441
Dirk Eibach9a13d812010-10-21 10:50:05 +0200442
Dirk Eibach81b37932011-01-21 09:31:21 +0100443 while (*rp) {
444 char substr[5];
Dirk Eibach9a13d812010-10-21 10:50:05 +0200445
Dirk Eibach81b37932011-01-21 09:31:21 +0100446 memcpy(substr, rp, 4);
447 substr[4] = 0;
448 *wp = simple_strtoul(substr, NULL, 16);
449
450 rp += 4;
451 wp++;
Dirk Eibachc0033c32013-06-26 16:04:30 +0200452 if (wp - buffer > base_width)
Dirk Eibach81b37932011-01-21 09:31:21 +0100453 break;
454 }
Dirk Eibach9a13d812010-10-21 10:50:05 +0200455
Dirk Eibach81b37932011-01-21 09:31:21 +0100456 for (k = 0; k < count; ++k) {
457 unsigned offset =
Dirk Eibachc0033c32013-06-26 16:04:30 +0200458 y * base_width + x + k * (wp - buffer);
Dirk Eibach81b37932011-01-21 09:31:21 +0100459 osd_write_videomem(screen, offset, buffer,
460 wp - buffer);
461 }
Dirk Eibach9a13d812010-10-21 10:50:05 +0200462 }
463
464 return 0;
465}
466
467U_BOOT_CMD(
468 osdw, 5, 0, osd_write,
469 "write 16-bit hex encoded buffer to osd memory",
470 "pos_x pos_y buffer count\n"
471);
472
473U_BOOT_CMD(
474 osdp, 5, 0, osd_print,
475 "write ASCII buffer to osd memory",
476 "pos_x pos_y color text\n"
477);