blob: 915b733547f48f71b8bfe7406be7cc430e919770 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dirk Eibach9a13d812010-10-21 10:50:05 +02002/*
3 * (C) Copyright 2010
Mario Sixb4893582018-03-06 08:04:58 +01004 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
Dirk Eibach9a13d812010-10-21 10:50:05 +02005 */
6
Mario Six78510212019-03-29 10:18:10 +01007#ifdef CONFIG_GDSYS_LEGACY_DRIVERS
8
Simon Glassed38aef2020-05-10 11:40:03 -06009#include <command.h>
Dirk Eibach20614a22013-06-26 16:04:26 +020010#include <i2c.h>
Dirk Eibach437145e2013-07-25 19:28:13 +020011#include <malloc.h>
Simon Glassfb64e362020-05-10 11:40:09 -060012#include <linux/stringify.h>
Dirk Eibach9a13d812010-10-21 10:50:05 +020013
Dirk Eibachb355f172015-10-28 11:46:32 +010014#include "ch7301.h"
Dirk Eibachca185b02014-07-03 09:28:22 +020015#include "dp501.h"
Dirk Eibach81b37932011-01-21 09:31:21 +010016#include <gdsys_fpga.h>
Dirk Eibach9a13d812010-10-21 10:50:05 +020017
Dirk Eibach81b37932011-01-21 09:31:21 +010018#define ICS8N3QV01_I2C_ADDR 0x6E
Dirk Eibachcad3e712011-04-06 13:53:43 +020019#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 Eibach81b37932011-01-21 09:31:21 +010025
26#define SIL1178_MASTER_I2C_ADDRESS 0x38
27#define SIL1178_SLAVE_I2C_ADDRESS 0x39
28
Dirk Eibach9a13d812010-10-21 10:50:05 +020029#define PIXCLK_640_480_60 25180000
Dirk Eibachec2a3a62015-10-28 11:46:37 +010030#define MAX_X_CHARS 53
31#define MAX_Y_CHARS 26
Dirk Eibach9a13d812010-10-21 10:50:05 +020032
Dirk Eibach981bacd2015-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 Eibachc0033c32013-06-26 16:04:30 +020066unsigned int base_width;
67unsigned int base_height;
68size_t bufsize;
69u16 *buf;
70
Dirk Eibach981bacd2015-10-28 11:46:35 +010071unsigned int osd_screen_mask = 0;
Dirk Eibach437145e2013-07-25 19:28:13 +020072
Dirk Eibachca185b02014-07-03 09:28:22 +020073#ifdef CONFIG_SYS_ICS8N3QV01_I2C
74int ics8n3qv01_i2c[] = CONFIG_SYS_ICS8N3QV01_I2C;
Dirk Eibach437145e2013-07-25 19:28:13 +020075#endif
76
Dirk Eibachca185b02014-07-03 09:28:22 +020077#ifdef CONFIG_SYS_SIL1178_I2C
Dirk Eibach4a3eae12014-07-03 09:28:17 +020078int sil1178_i2c[] = CONFIG_SYS_SIL1178_I2C;
Dirk Eibach81b37932011-01-21 09:31:21 +010079#endif
80
81#ifdef CONFIG_SYS_MPC92469AC
Dirk Eibach9a13d812010-10-21 10:50:05 +020082static 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 Eibach81b37932011-01-21 09:31:21 +0100107static void mpc92469ac_set(unsigned screen, unsigned int fout)
Dirk Eibach9a13d812010-10-21 10:50:05 +0200108{
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 Eibach20614a22013-06-26 16:04:26 +0200129 FPGA_SET_REG(screen, mpc3w_control, (bitval << 9) | m);
Dirk Eibach81b37932011-01-21 09:31:21 +0100130}
131#endif
132
Dirk Eibachca185b02014-07-03 09:28:22 +0200133#ifdef CONFIG_SYS_ICS8N3QV01_I2C
Dirk Eibachcad3e712011-04-06 13:53:43 +0200134
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200135static unsigned int ics8n3qv01_get_fout_calc(unsigned index)
Dirk Eibachcad3e712011-04-06 13:53:43 +0200136{
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 Eibach4a3eae12014-07-03 09:28:17 +0200146 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 Eibachcad3e712011-04-06 13:53:43 +0200151
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
Dirk Eibach81b37932011-01-21 09:31:21 +0100168static void ics8n3qv01_calc_parameters(unsigned int fout,
169 unsigned int *_mint, unsigned int *_mfrac,
170 unsigned int *_n)
171{
172 unsigned int n;
173 unsigned int foutiic;
174 unsigned int fvcoiic;
175 unsigned int mint;
176 unsigned long long mfrac;
177
Dirk Eibachcad3e712011-04-06 13:53:43 +0200178 n = (2215000000U + fout / 2) / fout;
Dirk Eibach81b37932011-01-21 09:31:21 +0100179 if ((n & 1) && (n > 5))
180 n -= 1;
181
182 foutiic = fout - (fout / 10000);
183 fvcoiic = foutiic * n;
184
185 mint = fvcoiic / 114285000;
186 if ((mint < 17) || (mint > 63))
187 printf("ics8n3qv01_calc_parameters: cannot determine mint\n");
188
189 mfrac = ((unsigned long long)fvcoiic % 114285000LL) * 262144LL
190 / 114285000LL;
191
192 *_mint = mint;
193 *_mfrac = mfrac;
194 *_n = n;
195}
196
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200197static void ics8n3qv01_set(unsigned int fout)
Dirk Eibach81b37932011-01-21 09:31:21 +0100198{
199 unsigned int n;
200 unsigned int mint;
201 unsigned int mfrac;
Dirk Eibachcad3e712011-04-06 13:53:43 +0200202 unsigned int fout_calc;
203 unsigned long long fout_prog;
204 long long off_ppm;
Dirk Eibach81b37932011-01-21 09:31:21 +0100205 u8 reg0, reg4, reg8, reg12, reg18, reg20;
206
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200207 fout_calc = ics8n3qv01_get_fout_calc(1);
Dirk Eibachcad3e712011-04-06 13:53:43 +0200208 off_ppm = (fout_calc - ICS8N3QV01_F_DEFAULT_1) * 1000000
209 / ICS8N3QV01_F_DEFAULT_1;
210 printf(" PLL is off by %lld ppm\n", off_ppm);
211 fout_prog = (unsigned long long)fout * (unsigned long long)fout_calc
212 / ICS8N3QV01_F_DEFAULT_1;
213 ics8n3qv01_calc_parameters(fout_prog, &mint, &mfrac, &n);
Dirk Eibach81b37932011-01-21 09:31:21 +0100214
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200215 reg0 = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 0) & 0xc0;
Dirk Eibach81b37932011-01-21 09:31:21 +0100216 reg0 |= (mint & 0x1f) << 1;
217 reg0 |= (mfrac >> 17) & 0x01;
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200218 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 0, reg0);
Dirk Eibach81b37932011-01-21 09:31:21 +0100219
220 reg4 = mfrac >> 9;
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200221 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 4, reg4);
Dirk Eibach81b37932011-01-21 09:31:21 +0100222
223 reg8 = mfrac >> 1;
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200224 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 8, reg8);
Dirk Eibach81b37932011-01-21 09:31:21 +0100225
226 reg12 = mfrac << 7;
227 reg12 |= n & 0x7f;
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200228 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 12, reg12);
Dirk Eibach81b37932011-01-21 09:31:21 +0100229
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200230 reg18 = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 18) & 0x03;
Dirk Eibach81b37932011-01-21 09:31:21 +0100231 reg18 |= 0x20;
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200232 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 18, reg18);
Dirk Eibach81b37932011-01-21 09:31:21 +0100233
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200234 reg20 = i2c_reg_read(ICS8N3QV01_I2C_ADDR, 20) & 0x1f;
Dirk Eibach81b37932011-01-21 09:31:21 +0100235 reg20 |= mint & (1 << 5);
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200236 i2c_reg_write(ICS8N3QV01_I2C_ADDR, 20, reg20);
Dirk Eibach9a13d812010-10-21 10:50:05 +0200237}
Dirk Eibach81b37932011-01-21 09:31:21 +0100238#endif
Dirk Eibach9a13d812010-10-21 10:50:05 +0200239
Dirk Eibach81b37932011-01-21 09:31:21 +0100240static int osd_write_videomem(unsigned screen, unsigned offset,
241 u16 *data, size_t charcount)
Dirk Eibach9a13d812010-10-21 10:50:05 +0200242{
243 unsigned int k;
244
245 for (k = 0; k < charcount; ++k) {
Dirk Eibachc0033c32013-06-26 16:04:30 +0200246 if (offset + k >= bufsize)
Dirk Eibach9a13d812010-10-21 10:50:05 +0200247 return -1;
Dirk Eibach981bacd2015-10-28 11:46:35 +0100248#ifdef CONFIG_SYS_OSD_DH
249 if (screen >= OSD_DH_BASE)
250 FPGA_SET_REG(screen - OSD_DH_BASE,
251 videomem1[offset + k], data[k]);
252 else
253 FPGA_SET_REG(screen, videomem0[offset + k], data[k]);
254#else
255 FPGA_SET_REG(screen, videomem0[offset + k], data[k]);
256#endif
Dirk Eibach9a13d812010-10-21 10:50:05 +0200257 }
258
259 return charcount;
260}
261
Simon Glassed38aef2020-05-10 11:40:03 -0600262static int osd_print(struct cmd_tbl *cmdtp, int flag, int argc,
263 char *const argv[])
Dirk Eibach9a13d812010-10-21 10:50:05 +0200264{
Dirk Eibach81b37932011-01-21 09:31:21 +0100265 unsigned screen;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200266
Dirk Eibach981bacd2015-10-28 11:46:35 +0100267 if (argc < 5) {
268 cmd_usage(cmdtp);
269 return 1;
270 }
271
272 for (screen = 0; screen < MAX_OSD_SCREEN; ++screen) {
Dirk Eibach81b37932011-01-21 09:31:21 +0100273 unsigned x;
274 unsigned y;
275 unsigned charcount;
276 unsigned len;
277 u8 color;
278 unsigned int k;
Dirk Eibach81b37932011-01-21 09:31:21 +0100279 char *text;
280 int res;
281
Dirk Eibach981bacd2015-10-28 11:46:35 +0100282 if (!(osd_screen_mask & (1 << screen)))
283 continue;
Dirk Eibach81b37932011-01-21 09:31:21 +0100284
Simon Glass3ff49ec2021-07-24 09:03:29 -0600285 x = hextoul(argv[1], NULL);
286 y = hextoul(argv[2], NULL);
287 color = hextoul(argv[3], NULL);
Dirk Eibach81b37932011-01-21 09:31:21 +0100288 text = argv[4];
289 charcount = strlen(text);
Dirk Eibachc0033c32013-06-26 16:04:30 +0200290 len = (charcount > bufsize) ? bufsize : charcount;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200291
Dirk Eibach81b37932011-01-21 09:31:21 +0100292 for (k = 0; k < len; ++k)
293 buf[k] = (text[k] << 8) | color;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200294
Dirk Eibachc0033c32013-06-26 16:04:30 +0200295 res = osd_write_videomem(screen, y * base_width + x, buf, len);
Dirk Eibach81b37932011-01-21 09:31:21 +0100296 if (res < 0)
297 return res;
Dirk Eibach65772852015-10-28 11:46:38 +0100298
299 OSD_SET_REG(screen, control, 0x0049);
Dirk Eibach81b37932011-01-21 09:31:21 +0100300 }
Dirk Eibach9a13d812010-10-21 10:50:05 +0200301
Dirk Eibach81b37932011-01-21 09:31:21 +0100302 return 0;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200303}
304
Dirk Eibach81b37932011-01-21 09:31:21 +0100305int osd_probe(unsigned screen)
Dirk Eibach9a13d812010-10-21 10:50:05 +0200306{
Dirk Eibach20614a22013-06-26 16:04:26 +0200307 u16 version;
308 u16 features;
Dirk Eibach437145e2013-07-25 19:28:13 +0200309 int old_bus = i2c_get_bus_num();
Dirk Eibachca185b02014-07-03 09:28:22 +0200310 bool pixclock_present = false;
311 bool output_driver_present = false;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200312
Dirk Eibach981bacd2015-10-28 11:46:35 +0100313 OSD_GET_REG(0, version, &version);
314 OSD_GET_REG(0, features, &features);
Dirk Eibach20614a22013-06-26 16:04:26 +0200315
Dirk Eibachc0033c32013-06-26 16:04:30 +0200316 base_width = ((features & 0x3f00) >> 8) + 1;
317 base_height = (features & 0x001f) + 1;
318 bufsize = base_width * base_height;
319 buf = malloc(sizeof(u16) * bufsize);
320 if (!buf)
321 return -1;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200322
Dirk Eibach981bacd2015-10-28 11:46:35 +0100323#ifdef CONFIG_SYS_OSD_DH
324 printf("OSD%d-%d: Digital-OSD version %01d.%02d, %d" "x%d characters\n",
325 (screen >= OSD_DH_BASE) ? (screen - OSD_DH_BASE) : screen,
326 (screen > 3) ? 1 : 0, version/100, version%100, base_width,
327 base_height);
328#else
Dirk Eibach81b37932011-01-21 09:31:21 +0100329 printf("OSD%d: Digital-OSD version %01d.%02d, %d" "x%d characters\n",
Dirk Eibach981bacd2015-10-28 11:46:35 +0100330 screen, version/100, version%100, base_width, base_height);
331#endif
Dirk Eibachca185b02014-07-03 09:28:22 +0200332 /* setup pixclock */
Dirk Eibach9a13d812010-10-21 10:50:05 +0200333
Dirk Eibach81b37932011-01-21 09:31:21 +0100334#ifdef CONFIG_SYS_MPC92469AC
Dirk Eibachca185b02014-07-03 09:28:22 +0200335 pixclock_present = true;
Dirk Eibach81b37932011-01-21 09:31:21 +0100336 mpc92469ac_set(screen, PIXCLK_640_480_60);
337#endif
Dirk Eibach9a13d812010-10-21 10:50:05 +0200338
Dirk Eibachca185b02014-07-03 09:28:22 +0200339#ifdef CONFIG_SYS_ICS8N3QV01_I2C
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200340 i2c_set_bus_num(ics8n3qv01_i2c[screen]);
Dirk Eibachca185b02014-07-03 09:28:22 +0200341 if (!i2c_probe(ICS8N3QV01_I2C_ADDR)) {
342 ics8n3qv01_set(PIXCLK_640_480_60);
343 pixclock_present = true;
344 }
Dirk Eibach81b37932011-01-21 09:31:21 +0100345#endif
346
Dirk Eibachca185b02014-07-03 09:28:22 +0200347 if (!pixclock_present)
348 printf(" no pixelclock found\n");
349
350 /* setup output driver */
351
352#ifdef CONFIG_SYS_CH7301_I2C
Dirk Eibachb355f172015-10-28 11:46:32 +0100353 if (!ch7301_probe(screen, true))
354 output_driver_present = true;
Dirk Eibachca185b02014-07-03 09:28:22 +0200355#endif
356
357#ifdef CONFIG_SYS_SIL1178_I2C
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200358 i2c_set_bus_num(sil1178_i2c[screen]);
Dirk Eibachca185b02014-07-03 09:28:22 +0200359 if (!i2c_probe(SIL1178_SLAVE_I2C_ADDRESS)) {
Dirk Eibachfffbb2f2014-11-13 19:21:15 +0100360 if (i2c_reg_read(SIL1178_SLAVE_I2C_ADDRESS, 0x02) == 0x06) {
Dirk Eibachca185b02014-07-03 09:28:22 +0200361 /*
362 * magic initialization sequence,
363 * adapted from datasheet
364 */
365 i2c_reg_write(SIL1178_SLAVE_I2C_ADDRESS, 0x08, 0x36);
366 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0f, 0x44);
367 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0f, 0x4c);
368 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0e, 0x10);
369 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0a, 0x80);
370 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x09, 0x30);
371 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0c, 0x89);
372 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x0d, 0x60);
373 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x08, 0x36);
374 i2c_reg_write(SIL1178_MASTER_I2C_ADDRESS, 0x08, 0x37);
375 output_driver_present = true;
376 }
377 }
378#endif
379
380#ifdef CONFIG_SYS_DP501_I2C
Dirk Eibache9539ed2016-03-16 09:20:11 +0100381 if (!dp501_probe(screen, true))
Dirk Eibachca185b02014-07-03 09:28:22 +0200382 output_driver_present = true;
Dirk Eibach81b37932011-01-21 09:31:21 +0100383#endif
384
Dirk Eibachca185b02014-07-03 09:28:22 +0200385 if (!output_driver_present)
386 printf(" no output driver found\n");
387
Dirk Eibach981bacd2015-10-28 11:46:35 +0100388 OSD_SET_REG(screen, xy_size, ((32 - 1) << 8) | (16 - 1));
389 OSD_SET_REG(screen, x_pos, 0x007f);
390 OSD_SET_REG(screen, y_pos, 0x005f);
Dirk Eibach81b37932011-01-21 09:31:21 +0100391
Dirk Eibach981bacd2015-10-28 11:46:35 +0100392 if (pixclock_present && output_driver_present)
393 osd_screen_mask |= 1 << screen;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200394
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200395 i2c_set_bus_num(old_bus);
396
Dirk Eibach9a13d812010-10-21 10:50:05 +0200397 return 0;
398}
399
Simon Glassed38aef2020-05-10 11:40:03 -0600400int osd_write(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Dirk Eibach9a13d812010-10-21 10:50:05 +0200401{
Dirk Eibach81b37932011-01-21 09:31:21 +0100402 unsigned screen;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200403
Dirk Eibach981bacd2015-10-28 11:46:35 +0100404 if ((argc < 4) || (strlen(argv[3]) % 4)) {
405 cmd_usage(cmdtp);
406 return 1;
407 }
408
409 for (screen = 0; screen < MAX_OSD_SCREEN; ++screen) {
Dirk Eibach81b37932011-01-21 09:31:21 +0100410 unsigned x;
411 unsigned y;
412 unsigned k;
Dirk Eibachc0033c32013-06-26 16:04:30 +0200413 u16 buffer[base_width];
Dirk Eibach81b37932011-01-21 09:31:21 +0100414 char *rp;
415 u16 *wp = buffer;
416 unsigned count = (argc > 4) ?
Simon Glass3ff49ec2021-07-24 09:03:29 -0600417 hextoul(argv[4], NULL) : 1;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200418
Dirk Eibach981bacd2015-10-28 11:46:35 +0100419 if (!(osd_screen_mask & (1 << screen)))
420 continue;
Dirk Eibach9a13d812010-10-21 10:50:05 +0200421
Simon Glass3ff49ec2021-07-24 09:03:29 -0600422 x = hextoul(argv[1], NULL);
423 y = hextoul(argv[2], NULL);
Dirk Eibach81b37932011-01-21 09:31:21 +0100424 rp = argv[3];
Dirk Eibach9a13d812010-10-21 10:50:05 +0200425
Dirk Eibach81b37932011-01-21 09:31:21 +0100426 while (*rp) {
427 char substr[5];
Dirk Eibach9a13d812010-10-21 10:50:05 +0200428
Dirk Eibach81b37932011-01-21 09:31:21 +0100429 memcpy(substr, rp, 4);
430 substr[4] = 0;
Simon Glass3ff49ec2021-07-24 09:03:29 -0600431 *wp = hextoul(substr, NULL);
Dirk Eibach81b37932011-01-21 09:31:21 +0100432
433 rp += 4;
434 wp++;
Dirk Eibachc0033c32013-06-26 16:04:30 +0200435 if (wp - buffer > base_width)
Dirk Eibach81b37932011-01-21 09:31:21 +0100436 break;
437 }
Dirk Eibach9a13d812010-10-21 10:50:05 +0200438
Dirk Eibach81b37932011-01-21 09:31:21 +0100439 for (k = 0; k < count; ++k) {
440 unsigned offset =
Dirk Eibachc0033c32013-06-26 16:04:30 +0200441 y * base_width + x + k * (wp - buffer);
Dirk Eibach81b37932011-01-21 09:31:21 +0100442 osd_write_videomem(screen, offset, buffer,
443 wp - buffer);
444 }
Dirk Eibach65772852015-10-28 11:46:38 +0100445
446 OSD_SET_REG(screen, control, 0x0049);
Dirk Eibach9a13d812010-10-21 10:50:05 +0200447 }
448
449 return 0;
450}
451
Simon Glassed38aef2020-05-10 11:40:03 -0600452int osd_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Dirk Eibachec2a3a62015-10-28 11:46:37 +0100453{
454 unsigned screen;
455 unsigned x;
456 unsigned y;
457
458 if (argc < 3) {
459 cmd_usage(cmdtp);
460 return 1;
461 }
462
Simon Glass3ff49ec2021-07-24 09:03:29 -0600463 x = hextoul(argv[1], NULL);
464 y = hextoul(argv[2], NULL);
Dirk Eibachec2a3a62015-10-28 11:46:37 +0100465
466 if (!x || (x > 64) || (x > MAX_X_CHARS) ||
467 !y || (y > 32) || (y > MAX_Y_CHARS)) {
468 cmd_usage(cmdtp);
469 return 1;
470 }
471
472 for (screen = 0; screen < MAX_OSD_SCREEN; ++screen) {
Dirk Eibachde3347f2016-06-02 09:05:40 +0200473 if (!(osd_screen_mask & (1 << screen)))
474 continue;
475
Dirk Eibachec2a3a62015-10-28 11:46:37 +0100476 OSD_SET_REG(screen, xy_size, ((x - 1) << 8) | (y - 1));
477 OSD_SET_REG(screen, x_pos, 32767 * (640 - 12 * x) / 65535);
478 OSD_SET_REG(screen, y_pos, 32767 * (480 - 18 * y) / 65535);
479 }
480
481 return 0;
482}
483
Dirk Eibach9a13d812010-10-21 10:50:05 +0200484U_BOOT_CMD(
485 osdw, 5, 0, osd_write,
486 "write 16-bit hex encoded buffer to osd memory",
487 "pos_x pos_y buffer count\n"
488);
489
490U_BOOT_CMD(
491 osdp, 5, 0, osd_print,
492 "write ASCII buffer to osd memory",
493 "pos_x pos_y color text\n"
494);
Dirk Eibachec2a3a62015-10-28 11:46:37 +0100495
496U_BOOT_CMD(
497 osdsize, 3, 0, osd_size,
498 "set OSD XY size in characters",
499 "size_x(max. " __stringify(MAX_X_CHARS)
500 ") size_y(max. " __stringify(MAX_Y_CHARS) ")\n"
501);
Mario Six78510212019-03-29 10:18:10 +0100502
Simon Glassed38aef2020-05-10 11:40:03 -0600503#endif /* CONFIG_GDSYS_LEGACY_DRIVERS */