blob: 7444bee129fe21db7ed4a7b74a6516bb0dbace67 [file] [log] [blame]
Dirk Eibacha605ea72010-10-21 10:50:05 +02001/*
2 * (C) Copyright 2010
3 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Dirk Eibacha605ea72010-10-21 10:50:05 +02006 */
7
8#include <common.h>
Dirk Eibachaba27ac2013-06-26 16:04:26 +02009#include <i2c.h>
Dirk Eibache50e8962013-07-25 19:28:13 +020010#include <malloc.h>
Dirk Eibacha605ea72010-10-21 10:50:05 +020011
Dirk Eibacha3f9d6c2015-10-28 11:46:32 +010012#include "ch7301.h"
Dirk Eibach3a990bf2014-07-03 09:28:22 +020013#include "dp501.h"
Dirk Eibach2da0fc02011-01-21 09:31:21 +010014#include <gdsys_fpga.h>
Dirk Eibacha605ea72010-10-21 10:50:05 +020015
Dirk Eibach2da0fc02011-01-21 09:31:21 +010016#define ICS8N3QV01_I2C_ADDR 0x6E
Dirk Eibach6853cc42011-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 Eibach2da0fc02011-01-21 09:31:21 +010023
24#define SIL1178_MASTER_I2C_ADDRESS 0x38
25#define SIL1178_SLAVE_I2C_ADDRESS 0x39
26
Dirk Eibach3a990bf2014-07-03 09:28:22 +020027#define DP501_I2C_ADDR 0x08
28
Dirk Eibacha605ea72010-10-21 10:50:05 +020029#define PIXCLK_640_480_60 25180000
Dirk Eibachda4833c2015-10-28 11:46:37 +010030#define MAX_X_CHARS 53
31#define MAX_Y_CHARS 26
Dirk Eibacha605ea72010-10-21 10:50:05 +020032
Dirk Eibach7ed45d32015-10-28 11:46:35 +010033#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 Eibach0f0c1022013-06-26 16:04:30 +020066unsigned int base_width;
67unsigned int base_height;
68size_t bufsize;
69u16 *buf;
70
Dirk Eibach7ed45d32015-10-28 11:46:35 +010071unsigned int osd_screen_mask = 0;
Dirk Eibache50e8962013-07-25 19:28:13 +020072
Dirk Eibach3a990bf2014-07-03 09:28:22 +020073#ifdef CONFIG_SYS_ICS8N3QV01_I2C
Dirk Eibachedfe9fe2014-07-03 09:28:17 +020074int ics8n3qv01_i2c[] = CONFIG_SYS_ICS8N3QV01_I2C;
75#endif
Dirk Eibach2da0fc02011-01-21 09:31:21 +010076
Dirk Eibach3a990bf2014-07-03 09:28:22 +020077#ifdef CONFIG_SYS_SIL1178_I2C
Dirk Eibachedfe9fe2014-07-03 09:28:17 +020078int sil1178_i2c[] = CONFIG_SYS_SIL1178_I2C;
Dirk Eibach2da0fc02011-01-21 09:31:21 +010079#endif
80
Dirk Eibach3a990bf2014-07-03 09:28:22 +020081#ifdef CONFIG_SYS_DP501_I2C
82int dp501_i2c[] = CONFIG_SYS_DP501_I2C;
83#endif
84
Dirk Eibach7ed45d32015-10-28 11:46:35 +010085#ifdef CONFIG_SYS_DP501_BASE
86int dp501_base[] = CONFIG_SYS_DP501_BASE;
87#endif
Dirk Eibach3a990bf2014-07-03 09:28:22 +020088
Dirk Eibach2da0fc02011-01-21 09:31:21 +010089#ifdef CONFIG_SYS_MPC92469AC
Dirk Eibacha605ea72010-10-21 10:50:05 +020090static 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 Eibach2da0fc02011-01-21 09:31:21 +0100115static void mpc92469ac_set(unsigned screen, unsigned int fout)
Dirk Eibacha605ea72010-10-21 10:50:05 +0200116{
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 Eibachaba27ac2013-06-26 16:04:26 +0200137 FPGA_SET_REG(screen, mpc3w_control, (bitval << 9) | m);
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100138}
139#endif
140
Dirk Eibach3a990bf2014-07-03 09:28:22 +0200141#ifdef CONFIG_SYS_ICS8N3QV01_I2C
Dirk Eibach6853cc42011-04-06 13:53:43 +0200142
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200143static unsigned int ics8n3qv01_get_fout_calc(unsigned index)
Dirk Eibach6853cc42011-04-06 13:53:43 +0200144{
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 Eibachedfe9fe2014-07-03 09:28:17 +0200154 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 Eibach6853cc42011-04-06 13:53:43 +0200159
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 Eibach2da0fc02011-01-21 09:31:21 +0100177static 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 Eibach6853cc42011-04-06 13:53:43 +0200187 n = (2215000000U + fout / 2) / fout;
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100188 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;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200204}
205
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200206static void ics8n3qv01_set(unsigned int fout)
Dirk Eibacha605ea72010-10-21 10:50:05 +0200207{
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100208 unsigned int n;
209 unsigned int mint;
210 unsigned int mfrac;
Dirk Eibach6853cc42011-04-06 13:53:43 +0200211 unsigned int fout_calc;
212 unsigned long long fout_prog;
213 long long off_ppm;
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100214 u8 reg0, reg4, reg8, reg12, reg18, reg20;
215
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200216 fout_calc = ics8n3qv01_get_fout_calc(1);
Dirk Eibach6853cc42011-04-06 13:53:43 +0200217 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 Eibach2da0fc02011-01-21 09:31:21 +0100223
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200224 reg0 = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 0) & 0xc0;
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100225 reg0 |= (mint & 0x1f) << 1;
226 reg0 |= (mfrac >> 17) & 0x01;
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200227 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 0, reg0);
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100228
229 reg4 = mfrac >> 9;
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200230 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 4, reg4);
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100231
232 reg8 = mfrac >> 1;
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200233 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 8, reg8);
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100234
235 reg12 = mfrac << 7;
236 reg12 |= n & 0x7f;
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200237 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 12, reg12);
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100238
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200239 reg18 = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 18) & 0x03;
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100240 reg18 |= 0x20;
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200241 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 18, reg18);
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100242
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200243 reg20 = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 20) & 0x1f;
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100244 reg20 |= mint & (1 << 5);
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200245 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 20, reg20);
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100246}
247#endif
248
249static int osd_write_videomem(unsigned screen, unsigned offset,
250 u16 *data, size_t charcount)
251{
Dirk Eibacha605ea72010-10-21 10:50:05 +0200252 unsigned int k;
253
254 for (k = 0; k < charcount; ++k) {
Dirk Eibach0f0c1022013-06-26 16:04:30 +0200255 if (offset + k >= bufsize)
Dirk Eibacha605ea72010-10-21 10:50:05 +0200256 return -1;
Dirk Eibach7ed45d32015-10-28 11:46:35 +0100257#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 Eibacha605ea72010-10-21 10:50:05 +0200266 }
267
268 return charcount;
269}
270
271static int osd_print(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
272{
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100273 unsigned screen;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200274
Dirk Eibach7ed45d32015-10-28 11:46:35 +0100275 if (argc < 5) {
276 cmd_usage(cmdtp);
277 return 1;
278 }
279
280 for (screen = 0; screen < MAX_OSD_SCREEN; ++screen) {
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100281 unsigned x;
282 unsigned y;
283 unsigned charcount;
284 unsigned len;
285 u8 color;
286 unsigned int k;
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100287 char *text;
288 int res;
289
Dirk Eibach7ed45d32015-10-28 11:46:35 +0100290 if (!(osd_screen_mask & (1 << screen)))
291 continue;
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100292
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 Eibach0f0c1022013-06-26 16:04:30 +0200298 len = (charcount > bufsize) ? bufsize : charcount;
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100299
300 for (k = 0; k < len; ++k)
301 buf[k] = (text[k] << 8) | color;
302
Dirk Eibach0f0c1022013-06-26 16:04:30 +0200303 res = osd_write_videomem(screen, y * base_width + x, buf, len);
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100304 if (res < 0)
305 return res;
Dirk Eibachacff73f2015-10-28 11:46:38 +0100306
307 OSD_SET_REG(screen, control, 0x0049);
Dirk Eibacha605ea72010-10-21 10:50:05 +0200308 }
309
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100310 return 0;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200311}
312
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100313int osd_probe(unsigned screen)
Dirk Eibacha605ea72010-10-21 10:50:05 +0200314{
Dirk Eibachaba27ac2013-06-26 16:04:26 +0200315 u16 version;
316 u16 features;
Dirk Eibache50e8962013-07-25 19:28:13 +0200317 int old_bus = i2c_get_bus_num();
Dirk Eibach3a990bf2014-07-03 09:28:22 +0200318 bool pixclock_present = false;
319 bool output_driver_present = false;
Dirk Eibach7ed45d32015-10-28 11:46:35 +0100320#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 Eibacha605ea72010-10-21 10:50:05 +0200327
Dirk Eibach7ed45d32015-10-28 11:46:35 +0100328 OSD_GET_REG(0, version, &version);
329 OSD_GET_REG(0, features, &features);
Dirk Eibachaba27ac2013-06-26 16:04:26 +0200330
Dirk Eibach0f0c1022013-06-26 16:04:30 +0200331 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 Eibacha605ea72010-10-21 10:50:05 +0200337
Dirk Eibach7ed45d32015-10-28 11:46:35 +0100338#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 Eibach2da0fc02011-01-21 09:31:21 +0100344 printf("OSD%d: Digital-OSD version %01d.%02d, %d" "x%d characters\n",
Dirk Eibach7ed45d32015-10-28 11:46:35 +0100345 screen, version/100, version%100, base_width, base_height);
346#endif
Dirk Eibach3a990bf2014-07-03 09:28:22 +0200347 /* setup pixclock */
Dirk Eibacha605ea72010-10-21 10:50:05 +0200348
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100349#ifdef CONFIG_SYS_MPC92469AC
Dirk Eibach3a990bf2014-07-03 09:28:22 +0200350 pixclock_present = true;
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100351 mpc92469ac_set(screen, PIXCLK_640_480_60);
352#endif
Dirk Eibacha605ea72010-10-21 10:50:05 +0200353
Dirk Eibach3a990bf2014-07-03 09:28:22 +0200354#ifdef CONFIG_SYS_ICS8N3QV01_I2C
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200355 i2c_set_bus_num(ics8n3qv01_i2c[screen]);
Dirk Eibach3a990bf2014-07-03 09:28:22 +0200356 if (!i2c_probe(ICS8N3QV01_I2C_ADDR)) {
357 ics8n3qv01_set(PIXCLK_640_480_60);
358 pixclock_present = true;
359 }
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100360#endif
361
Dirk Eibach3a990bf2014-07-03 09:28:22 +0200362 if (!pixclock_present)
363 printf(" no pixelclock found\n");
364
365 /* setup output driver */
366
367#ifdef CONFIG_SYS_CH7301_I2C
Dirk Eibacha3f9d6c2015-10-28 11:46:32 +0100368 if (!ch7301_probe(screen, true))
369 output_driver_present = true;
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100370#endif
371
Dirk Eibach3a990bf2014-07-03 09:28:22 +0200372#ifdef CONFIG_SYS_SIL1178_I2C
373 i2c_set_bus_num(sil1178_i2c[screen]);
374 if (!i2c_probe(SIL1178_SLAVE_I2C_ADDRESS)) {
Dirk Eibacha61762d2014-11-13 19:21:15 +0100375 if (i2c_reg_read(SIL1178_SLAVE_I2C_ADDRESS, 0x02) == 0x06) {
Dirk Eibach3a990bf2014-07-03 09:28:22 +0200376 /*
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 Eibach7ed45d32015-10-28 11:46:35 +0100397 if (!i2c_probe(dp501_addr)) {
398 dp501_powerup(dp501_addr);
Dirk Eibach3a990bf2014-07-03 09:28:22 +0200399 output_driver_present = true;
400 }
401#endif
402
403 if (!output_driver_present)
404 printf(" no output driver found\n");
405
Dirk Eibach7ed45d32015-10-28 11:46:35 +0100406 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 Eibachaba27ac2013-06-26 16:04:26 +0200409
Dirk Eibach7ed45d32015-10-28 11:46:35 +0100410 if (pixclock_present && output_driver_present)
411 osd_screen_mask |= 1 << screen;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200412
Dirk Eibachedfe9fe2014-07-03 09:28:17 +0200413 i2c_set_bus_num(old_bus);
414
Dirk Eibacha605ea72010-10-21 10:50:05 +0200415 return 0;
416}
417
418int osd_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
419{
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100420 unsigned screen;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200421
Dirk Eibach7ed45d32015-10-28 11:46:35 +0100422 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 Eibach2da0fc02011-01-21 09:31:21 +0100428 unsigned x;
429 unsigned y;
430 unsigned k;
Dirk Eibach0f0c1022013-06-26 16:04:30 +0200431 u16 buffer[base_width];
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100432 char *rp;
433 u16 *wp = buffer;
434 unsigned count = (argc > 4) ?
435 simple_strtoul(argv[4], NULL, 16) : 1;
Dirk Eibacha605ea72010-10-21 10:50:05 +0200436
Dirk Eibach7ed45d32015-10-28 11:46:35 +0100437 if (!(osd_screen_mask & (1 << screen)))
438 continue;
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100439
440 x = simple_strtoul(argv[1], NULL, 16);
441 y = simple_strtoul(argv[2], NULL, 16);
442 rp = argv[3];
Dirk Eibacha605ea72010-10-21 10:50:05 +0200443
444
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100445 while (*rp) {
446 char substr[5];
Dirk Eibacha605ea72010-10-21 10:50:05 +0200447
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100448 memcpy(substr, rp, 4);
449 substr[4] = 0;
450 *wp = simple_strtoul(substr, NULL, 16);
Dirk Eibacha605ea72010-10-21 10:50:05 +0200451
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100452 rp += 4;
453 wp++;
Dirk Eibach0f0c1022013-06-26 16:04:30 +0200454 if (wp - buffer > base_width)
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100455 break;
456 }
Dirk Eibacha605ea72010-10-21 10:50:05 +0200457
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100458 for (k = 0; k < count; ++k) {
459 unsigned offset =
Dirk Eibach0f0c1022013-06-26 16:04:30 +0200460 y * base_width + x + k * (wp - buffer);
Dirk Eibach2da0fc02011-01-21 09:31:21 +0100461 osd_write_videomem(screen, offset, buffer,
462 wp - buffer);
463 }
Dirk Eibachacff73f2015-10-28 11:46:38 +0100464
465 OSD_SET_REG(screen, control, 0x0049);
Dirk Eibacha605ea72010-10-21 10:50:05 +0200466 }
467
468 return 0;
469}
470
Dirk Eibachda4833c2015-10-28 11:46:37 +0100471int 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 Eibacha605ea72010-10-21 10:50:05 +0200500U_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
506U_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 Eibachda4833c2015-10-28 11:46:37 +0100511
512U_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);