blob: c1aacd1458b10117fe61c28e868e19b1f301dad3 [file] [log] [blame]
Sebastian Reichel7cab6fe2020-09-02 19:31:46 +02001/*
2 * GE B105v2, B125v2, B155v2
3 *
4 * Copyright 2018-2020 GE Inc.
5 * Copyright 2018-2020 Collabora Ltd.
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <asm/arch/clock.h>
11#include <asm/arch/crm_regs.h>
12#include <asm/arch/imx-regs.h>
13#include <asm/arch/iomux.h>
14#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Sebastian Reichel7cab6fe2020-09-02 19:31:46 +020016#include <asm/gpio.h>
17#include <asm/io.h>
18#include <asm/mach-imx/video.h>
19#include <command.h>
Sebastian Reichel7cab6fe2020-09-02 19:31:46 +020020#include <i2c.h>
21#include <input.h>
22#include <ipu_pixfmt.h>
23#include <linux/delay.h>
24#include <linux/fb.h>
25#include <malloc.h>
26#include <miiphy.h>
27#include <micrel.h>
28#include <netdev.h>
29#include <panel.h>
30#include <rtc.h>
31#include <spi_flash.h>
Pali Rohárba87ddf2021-08-02 15:18:31 +020032#include <version_string.h>
Sebastian Reichel7cab6fe2020-09-02 19:31:46 +020033
34#include "../common/vpd_reader.h"
35
36DECLARE_GLOBAL_DATA_PTR;
37
Simon Glass49c24a82024-09-29 19:49:47 -060038#ifndef CONFIG_XPL_BUILD
Sebastian Reichel7cab6fe2020-09-02 19:31:46 +020039
40#define B1X5V2_GE_VPD_OFFSET 0x0100000
41#define B1X5V2_GE_VPD_SIZE 1022
42
43#define VPD_TYPE_INVALID 0x00
44#define VPD_BLOCK_NETWORK 0x20
45#define VPD_BLOCK_HWID 0x44
46#define VPD_MAC_ADDRESS_LENGTH 6
47
48#define VPD_FLAG_VALID_MAC BIT(1)
49
50#define AR8035_PHY_ID 0x004dd072
51#define AR8035_PHY_DEBUG_ADDR_REG 0x1d
52#define AR8035_PHY_DEBUG_DATA_REG 0x1e
53#define AR8035_HIB_CTRL_REG 0xb
54#define AR8035_HIBERNATE_EN (1 << 15)
55
56static struct vpd_cache {
57 bool is_read;
58 u8 product_id;
59 unsigned char mac[VPD_MAC_ADDRESS_LENGTH];
60 u32 flags;
61} vpd;
62
63enum product_type {
64 PRODUCT_TYPE_B105V2 = 6,
65 PRODUCT_TYPE_B105PV2 = 7,
66 PRODUCT_TYPE_B125V2 = 8,
67 PRODUCT_TYPE_B125PV2 = 9,
68 PRODUCT_TYPE_B155V2 = 10,
69
70 PRODUCT_TYPE_INVALID = 0,
71};
72
73int dram_init(void) {
74 gd->ram_size = imx_ddr_size();
75 return 0;
76}
77
78int power_init_board(void)
79{
80 /* all required PMIC configuration happens via DT */
81 return 0;
82}
83
84static int disable_phy_hibernation(struct phy_device *phydev)
85{
86 unsigned short val;
87
88 if (phydev->drv->uid == AR8035_PHY_ID) {
89 /* Disable hibernation, other configuration has been done by PHY driver */
90 phy_write(phydev, MDIO_DEVAD_NONE, AR8035_PHY_DEBUG_ADDR_REG, AR8035_HIB_CTRL_REG);
91 val = phy_read(phydev, MDIO_DEVAD_NONE, AR8035_PHY_DEBUG_DATA_REG);
92 val &= ~AR8035_HIBERNATE_EN;
93 phy_write(phydev, MDIO_DEVAD_NONE, AR8035_PHY_DEBUG_DATA_REG, val);
94 } else {
95 printf("Unknown PHY: %08x\n", phydev->drv->uid);
96 }
97
98 return 0;
99}
100
101int board_phy_config(struct phy_device *phydev)
102{
103 if (phydev->drv->config)
104 phydev->drv->config(phydev);
105
106 disable_phy_hibernation(phydev);
107
108 return 0;
109}
110
111static int auo_g101evn01_detect(const struct display_info_t *info)
112{
113 char *dev = env_get("devicetype");
114 return !strcmp(dev, "B105v2") || !strcmp(dev, "B105Pv2");
115}
116
117static int auo_g121ean01_detect(const struct display_info_t *info)
118{
119 char *dev = env_get("devicetype");
120 return !strcmp(dev, "B125v2") || !strcmp(dev, "B125Pv2");;
121}
122
123static int auo_g156xtn01_detect(const struct display_info_t *info)
124{
125 char *dev = env_get("devicetype");
126 return !strcmp(dev, "B155v2");
127}
128
129static void b1x5v2_backlight_enable(int percent)
130{
131 struct udevice *panel;
132 int ret;
133
134 ret = uclass_get_device(UCLASS_PANEL, 0, &panel);
135 if (ret) {
136 printf("Could not find panel: %d\n", ret);
137 return;
138 }
139
140 panel_set_backlight(panel, percent);
141 panel_enable_backlight(panel);
142
143}
144
145static void lcd_enable(const struct display_info_t *info)
146{
147 printf("Enable backlight...\n");
148 b1x5v2_backlight_enable(100);
149}
150
151struct display_info_t const displays[] = {
152{
153 .di = 0,
154 .bus = -1,
155 .addr = -1,
156 .pixfmt = IPU_PIX_FMT_RGB24,
157 .detect = auo_g156xtn01_detect,
158 .enable = lcd_enable,
159 .mode = {
160 .name = "AUO G156XTN01",
161 .refresh = 60,
162 .xres = 1368, /* because of i.MX6 limitation, actually 1366 */
163 .yres = 768,
164 .pixclock = 13158, /* 76 MHz in ps */
165 .left_margin = 33,
166 .right_margin = 67,
167 .upper_margin = 4,
168 .lower_margin = 4,
169 .hsync_len = 94,
170 .vsync_len = 30,
171 .sync = FB_SYNC_EXT,
172 .vmode = FB_VMODE_NONINTERLACED
173 }
174},
175{
176 .di = 0,
177 .bus = -1,
178 .addr = -1,
179 .pixfmt = IPU_PIX_FMT_RGB24,
180 .detect = auo_g121ean01_detect,
181 .enable = lcd_enable,
182 .mode = {
183 .name = "AUO G121EAN01.4",
184 .refresh = 60,
185 .xres = 1280,
186 .yres = 800,
187 .pixclock = 14992, /* 66.7 MHz in ps */
188 .left_margin = 8,
189 .right_margin = 58,
190 .upper_margin = 6,
191 .lower_margin = 4,
192 .hsync_len = 70,
193 .vsync_len = 10,
194 .sync = FB_SYNC_EXT,
195 .vmode = FB_VMODE_NONINTERLACED
196 }
197},
198{
199 .di = 0,
200 .bus = -1,
201 .addr = -1,
202 .pixfmt = IPU_PIX_FMT_RGB24,
203 .detect = auo_g101evn01_detect,
204 .enable = lcd_enable,
205 .mode = {
206 .name = "AUO G101EVN01.3",
207 .refresh = 60,
208 .xres = 1280,
209 .yres = 800,
210 .pixclock = 14992, /* 66.7 MHz in ps */
211 .left_margin = 8,
212 .right_margin = 58,
213 .upper_margin = 6,
214 .lower_margin = 4,
215 .hsync_len = 70,
216 .vsync_len = 10,
217 .sync = FB_SYNC_EXT,
218 .vmode = FB_VMODE_NONINTERLACED
219 }
220}
221};
222size_t display_count = ARRAY_SIZE(displays);
223
224static void enable_videopll(void)
225{
226 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
227 s32 timeout = 100000;
228
229 setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
230
231 /* PLL_VIDEO 455MHz (24MHz * (37+11/12) / 2)
232 * |
233 * PLL5
234 * |
235 * CS2CDR[LDB_DI0_CLK_SEL]
236 * |
237 * +----> LDB_DI0_SERIAL_CLK_ROOT
238 * |
239 * +--> CSCMR2[LDB_DI0_IPU_DIV] --> LDB_DI0_IPU 455 / 7 = 65 MHz
240 */
241
242 clrsetbits_le32(&ccm->analog_pll_video,
243 BM_ANADIG_PLL_VIDEO_DIV_SELECT |
244 BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT,
245 BF_ANADIG_PLL_VIDEO_DIV_SELECT(37) |
246 BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1));
247
248 writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num);
249 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom);
250
251 clrbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
252
253 while (timeout--)
254 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
255 break;
256
257 if (timeout < 0)
258 printf("Warning: video pll lock timeout!\n");
259
260 clrsetbits_le32(&ccm->analog_pll_video,
261 BM_ANADIG_PLL_VIDEO_BYPASS,
262 BM_ANADIG_PLL_VIDEO_ENABLE);
263}
264
265static void setup_display(void)
266{
267 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
268 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
269
270 enable_videopll();
271
272 /* When a reset/reboot is performed the display power needs to be turned
273 * off for atleast 500ms. The boot time is ~300ms, we need to wait for
274 * an additional 200ms here. Unfortunately we use external PMIC for
275 * doing the reset, so can not differentiate between POR vs soft reset
276 */
277 mdelay(200);
278
279 /* CCM_CSCMR2 -> ldb_di0_ipu_div [IMX6SDLRM page 839] */
280 /* divide IPU clock by 7 */
281 setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
282
283 /* CCM_CHSCCDR -> ipu1_di0_clk_sel [IMX6SDLRM page 849] */
284 /* Set LDB_DI0 as clock source for IPU_DI0 */
285 clrsetbits_le32(&mxc_ccm->chsccdr,
286 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK,
287 (CHSCCDR_CLK_SEL_LDB_DI0 <<
288 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET));
289
290 /* Turn on IPU LDB DI0 clocks */
291 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
292
293 enable_ipu_clock();
294
295 /* IOMUXC_GPR2 [IMX6SDLRM page 2049] */
296 /* Set LDB Channel 0 in SPWG 24 Bit mode */
297 writel(IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_HIGH |
298 IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
299 IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
300 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0,
301 &iomux->gpr[2]);
302
303 /* IOMUXC_GPR3 [IMX6SDLRM page 2051] */
304 /* LVDS0 is connected to IPU DI0 */
305 clrsetbits_le32(&iomux->gpr[3],
306 IOMUXC_GPR3_LVDS0_MUX_CTL_MASK,
307 (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 <<
308 IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET));
309}
310
311/*
312 * Do not overwrite the console
313 * Use always serial for U-Boot console
314 */
315int overwrite_console(void)
316{
317 return 1;
318}
319
320int board_early_init_f(void)
321{
322 select_ldb_di_clock_source(MXC_PLL5_CLK);
323
324 return 0;
325}
326
327static int eeti_touch_get_model(struct udevice *dev, char *result) {
328 u8 query[68] = {0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'E', 0x00, 0x00, 0x00};
329 struct i2c_msg qmsg = {
330 .addr = 0x2a,
331 .flags = 0,
332 .len = sizeof(query),
333 .buf = query,
334 };
335 u8 reply[66] = {0};
336 struct i2c_msg rmsg = {
337 .addr = 0x2a,
338 .flags = I2C_M_RD,
339 .len = sizeof(reply),
340 .buf = reply,
341 };
342 int err;
343
344 err = dm_i2c_xfer(dev, &qmsg, 1);
345 if (err)
346 return err;
347
348 /*
349 * device sends IRQ when its ok to read. To keep the code
350 * simple we just wait an arbitrary, long enough time period.
351 */
352 mdelay(10);
353
354 err = dm_i2c_xfer(dev, &rmsg, 1);
355 if (err)
356 return err;
357
358 if (reply[0] != 0x42 || reply[1] != 0x00 ||
359 reply[2] != 0x03 || reply[4] != 'E')
360 return -EPROTO;
361
362 memcpy(result, reply+5, 10);
363 return 0;
364}
365
366static bool b1x5v2_board_is_p_model(void)
367{
368 struct udevice *bus = NULL;
369 struct udevice *dev = NULL;
370 int err;
371
372 err = uclass_get_device_by_name(UCLASS_I2C, "i2c@21a0000", &bus);
373 if (err || !bus) {
374 printf("Could not get I2C bus: %d\n", err);
375 return true;
376 }
377
378 /* The P models do not have this port expander */
379 err = dm_i2c_probe(bus, 0x21, 0, &dev);
380 if (err || !dev) {
381 return true;
382 }
383
384 return false;
385}
386
387static enum product_type b1x5v2_board_type(void)
388{
389 struct udevice *bus = NULL;
390 struct udevice *dev = NULL;
391 char model[11] = {0};
392 int err;
393 int retry;
394
395 err = uclass_get_device_by_name(UCLASS_I2C, "i2c@21a8000", &bus);
396 if (err) {
397 printf("Could not get I2C bus: %d\n", err);
398 return PRODUCT_TYPE_INVALID;
399 }
400
401 err = dm_i2c_probe(bus, 0x41, 0, &dev);
402 if (!err && dev) { /* Ilitek Touchscreen */
403 if (b1x5v2_board_is_p_model()) {
404 return PRODUCT_TYPE_B105PV2;
405 } else {
406 return PRODUCT_TYPE_B105V2;
407 }
408 }
409
410 err = dm_i2c_probe(bus, 0x2a, 0, &dev);
411 if (err || !dev) {
412 printf("Could not find touchscreen: %d\n", err);
413 return PRODUCT_TYPE_INVALID;
414 }
415
416 for (retry = 0; retry < 3; ++retry) {
417 err = eeti_touch_get_model(dev, model);
418 if (!err)
419 break;
420 printf("Retry %d read EETI touchscreen model: %d\n", retry + 1, err);
421 }
422 if (err) {
423 printf("Could not read EETI touchscreen model: %d\n", err);
424 return PRODUCT_TYPE_INVALID;
425 }
426
427 if (!strcmp(model, "Orion_1320")) { /* EETI EXC80H60 */
428 if (b1x5v2_board_is_p_model()) {
429 return PRODUCT_TYPE_B125PV2;
430 } else {
431 return PRODUCT_TYPE_B125V2;
432 }
433 } else if (!strcmp(model, "Orion_1343")) { /* EETI EXC80H84 */
434 return PRODUCT_TYPE_B155V2;
435 }
436
437 printf("Unknown EETI touchscreen model: %s\n", model);
438 return PRODUCT_TYPE_INVALID;
439}
440
441static void set_env_per_board_type(enum product_type type)
442{
443 switch (type) {
444 case PRODUCT_TYPE_B105V2:
445 env_set("resolution", "1280x800");
446 env_set("devicetype", "B105v2");
447 env_set("fdtfile", "imx6dl-b105v2.dtb");
448 break;
449 case PRODUCT_TYPE_B105PV2:
450 env_set("resolution", "1280x800");
451 env_set("devicetype", "B105Pv2");
452 env_set("fdtfile", "imx6dl-b105pv2.dtb");
453 break;
454 case PRODUCT_TYPE_B125V2:
455 env_set("resolution", "1280x800");
456 env_set("devicetype", "B125v2");
457 env_set("fdtfile", "imx6dl-b125v2.dtb");
458 break;
459 case PRODUCT_TYPE_B125PV2:
460 env_set("resolution", "1280x800");
461 env_set("devicetype", "B125Pv2");
462 env_set("fdtfile", "imx6dl-b125pv2.dtb");
463 break;
464 case PRODUCT_TYPE_B155V2:
465 env_set("resolution", "1366x768");
466 env_set("devicetype", "B155v2");
467 env_set("fdtfile", "imx6dl-b155v2.dtb");
468 break;
469 default:
470 break;
471 }
472}
473
474static int b1x5v2_board_type_autodetect(void)
475{
476 enum product_type product = b1x5v2_board_type();
477 if (product != PRODUCT_TYPE_INVALID) {
478 set_env_per_board_type(product);
479 return 0;
480 }
481 return -1;
482}
483
484/*
485 * Extracts MAC and product information from the VPD.
486 */
487static int vpd_callback(struct vpd_cache *vpd, u8 id, u8 version, u8 type,
488 size_t size, u8 const *data)
489{
490 if (type == VPD_TYPE_INVALID)
491 return 0;
492
493 if (id == VPD_BLOCK_HWID && version == 1 && size >= 1) {
494 vpd->product_id = data[0];
495 } else if (id == VPD_BLOCK_NETWORK && version == 1) {
496 if (size >= VPD_MAC_ADDRESS_LENGTH) {
497 memcpy(vpd->mac, data, VPD_MAC_ADDRESS_LENGTH);
498 vpd->flags |= VPD_FLAG_VALID_MAC;
499 }
500 }
501
502 return 0;
503}
504
505static int read_spi_vpd(struct vpd_cache *cache,
506 int (*process_block)(struct vpd_cache *, u8 id, u8 version,
507 u8 type, size_t size, u8 const *data))
508{
509 static const int size = B1X5V2_GE_VPD_SIZE;
510 struct udevice *dev;
511 int ret;
512 u8 *data;
513
514 ret = uclass_get_device_by_name(UCLASS_SPI_FLASH, "m25p80@0", &dev);
515 if (ret)
516 return ret;
517
518 data = malloc(size);
519 if (!data)
520 return -ENOMEM;
521
522 ret = spi_flash_read_dm(dev, B1X5V2_GE_VPD_OFFSET, size, data);
523 if (ret) {
524 free(data);
525 return ret;
526 }
527
528 ret = vpd_reader(size, data, cache, process_block);
529
530 free(data);
531
532 return ret;
533}
534
535int board_init(void)
536{
537 if (!read_spi_vpd(&vpd, vpd_callback)) {
538 vpd.is_read = true;
539 }
540
541 /* address of boot parameters */
542 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
543 setup_display();
544
545 return 0;
546}
547
548static void init_bootcause(void)
549{
550 const char *cause;
551
552 /* We care about WDOG only, treating everything else as
553 * a power-on-reset.
554 */
555 if (get_imx_reset_cause() & 0x0010)
556 cause = "WDOG";
557 else
558 cause = "POR";
559
560 env_set("bootcause", cause);
561}
562
563int misc_init_r(void)
564{
565 init_bootcause();
566
567 return 0;
568}
569
570#define M41T62_REG_FLAGS 0xf
571#define M41T62_FLAGS_OF (1 << 2)
572static void check_time(void)
573{
574 struct udevice *rtc = NULL;
575 struct rtc_time tm;
576 u8 val;
577 int ret;
578
579 ret = uclass_get_device_by_name(UCLASS_RTC, "m41t62@68", &rtc);
580 if (ret) {
581 printf("Could not get RTC: %d\n", ret);
582 env_set("rtc_status", "FAIL");
583 return;
584 }
585
586 ret = dm_i2c_read(rtc, M41T62_REG_FLAGS, &val, sizeof(val));
587 if (ret) {
588 printf("Could not read RTC register: %d\n", ret);
589 env_set("rtc_status", "FAIL");
590 return;
591 }
592
593 ret = dm_rtc_reset(rtc);
594 if (ret) {
595 printf("Could not reset RTC: %d\n", ret);
596 env_set("rtc_status", "FAIL");
597 return;
598 }
599
600 if (val & M41T62_FLAGS_OF) {
601 env_set("rtc_status", "STOP");
602 return;
603 }
604
605 ret = dm_rtc_get(rtc, &tm);
606 if (ret) {
607 printf("Could not read RTC: %d\n", ret);
608 env_set("rtc_status", "FAIL");
609 return;
610 }
611
612 if (tm.tm_year > 2037) {
613 tm.tm_sec = 0;
614 tm.tm_min = 0;
615 tm.tm_hour = 0;
616 tm.tm_mday = 1;
617 tm.tm_wday = 2;
618 tm.tm_mon = 1;
619 tm.tm_year = 2036;
620
621 ret = dm_rtc_set(rtc, &tm);
622 if (ret) {
623 printf("Could not update RTC: %d\n", ret);
624 env_set("rtc_status", "FAIL");
625 return;
626 }
627
628 printf("RTC behind 2037, capped to 2036 for userspace handling\n");
629 env_set("rtc_status", "2038");
630 return;
631 }
632
633 env_set("rtc_status", "OK");
634}
635
636static void process_vpd(struct vpd_cache *vpd)
637{
638 if (!vpd->is_read) {
639 printf("VPD wasn't read\n");
640 return;
641 }
642
643 if (vpd->flags & VPD_FLAG_VALID_MAC) {
644 eth_env_set_enetaddr_by_index("eth", 0, vpd->mac);
645 env_set("ethact", "eth0");
646 }
647}
648
649int board_late_init(void)
650{
651 process_vpd(&vpd);
652
653 if (vpd.product_id >= PRODUCT_TYPE_B105V2 &&
654 vpd.product_id <= PRODUCT_TYPE_B155V2) {
655 set_env_per_board_type((enum product_type)vpd.product_id);
656 } else {
657 b1x5v2_board_type_autodetect();
658 }
659
660 printf("Board: GE %s\n", env_get("devicetype"));
661
662 check_time();
663
664 return 0;
665}
666
667#ifdef CONFIG_OF_BOARD_SETUP
668int ft_board_setup(void *blob, struct bd_info *bd)
669{
670 char *rtc_status = env_get("rtc_status");
671
672 fdt_setprop(blob, 0, "ge,boot-ver", version_string,
673 strlen(version_string) + 1);
674 fdt_setprop(blob, 0, "ge,rtc-status", rtc_status,
675 strlen(rtc_status) + 1);
676
677 return 0;
678}
679#endif
680
681static int do_b1x5v2_autodetect(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
682{
683 int err;
684
685 err = b1x5v2_board_type_autodetect();
686 if (!err)
687 printf("Identified %s\n", env_get("devicetype"));
688
689 return 0;
690}
691
692U_BOOT_CMD(
693 autodetect_devtype, 1, 1, do_b1x5v2_autodetect,
694 "autodetect b1x5v2 device type",
695 ""
696);
697
Simon Glass49c24a82024-09-29 19:49:47 -0600698#endif // CONFIG_XPL_BUILD