1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012-2015 Panasonic Corporation
4 * Copyright (C) 2015-2020 Socionext Inc.
5 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
9 #include <fdt_support.h>
10 #include <linux/ctype.h>
11 #include <linux/delay.h>
13 #include <asm/global_data.h>
15 #include "micro-support-card.h"
17 #define SMC911X_OFFSET 0x00000
18 #define LED_OFFSET 0x90000
19 #define NS16550A_OFFSET 0xb0000
20 #define MICRO_SUPPORT_CARD_RESET 0xd0034
21 #define MICRO_SUPPORT_CARD_REVISION 0xd00e0
23 static bool support_card_found;
24 static void __iomem *support_card_base;
26 static void support_card_detect(void)
28 DECLARE_GLOBAL_DATA_PTR;
29 const void *fdt = gd->fdt_blob;
33 offset = fdt_node_offset_by_compatible(fdt, 0, "smsc,lan9118");
37 addr = fdt_get_base_address(fdt, offset);
38 if (addr == OF_BAD_ADDR)
40 addr -= SMC911X_OFFSET;
42 offset = fdt_node_offset_by_compatible(fdt, 0, "ns16550a");
46 addr2 = fdt_get_base_address(fdt, offset);
47 if (addr2 == OF_BAD_ADDR)
49 addr2 -= NS16550A_OFFSET;
55 support_card_base = ioremap(addr, 0x100000);
57 support_card_found = true;
61 * 0: reset deassert, 1: reset
63 * bit[0]: LAN, I2C, LED
66 static void support_card_reset_deassert(void)
68 writel(0x00010000, support_card_base + MICRO_SUPPORT_CARD_RESET);
71 static void support_card_reset(void)
73 writel(0x00020003, support_card_base + MICRO_SUPPORT_CARD_RESET);
76 static int support_card_show_revision(void)
80 revision = readl(support_card_base + MICRO_SUPPORT_CARD_REVISION);
83 /* revision 3.6.x card changed the revision format */
84 printf("SC: Micro Support Card (CPLD version %s%d.%d)\n",
85 revision >> 4 == 6 ? "3." : "",
86 revision >> 4, revision & 0xf);
91 void support_card_init(void)
96 /* The system bus must be initialized for access to the support card. */
97 ret = uclass_get_device_by_driver(UCLASS_SIMPLE_BUS,
98 DM_DRIVER_GET(uniphier_system_bus_driver),
103 /* Check DT to see if this board has the support card. */
104 support_card_detect();
106 if (!support_card_found)
109 support_card_reset();
111 * After power on, we need to keep the LAN controller in reset state
112 * for a while. (200 usec)
115 support_card_reset_deassert();
117 support_card_show_revision();
120 static const u8 ledval_num[] = {
133 static const u8 ledval_alpha[] = {
162 static u8 char2ledval(char c)
165 return ledval_num[c - '0'];
167 return ledval_alpha[toupper(c) - 'A'];
172 void led_puts(const char *s)
177 if (!support_card_found)
183 for (i = 0; i < 4; i++) {
185 val |= char2ledval(*s);
190 writel(~val, support_card_base + LED_OFFSET);