1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2011-2016 Zhang, Keguang <keguang.zhang@gmail.com>
7 #include <linux/dma-mapping.h>
9 #include <linux/mtd/partitions.h>
10 #include <linux/sizes.h>
11 #include <linux/phy.h>
12 #include <linux/serial_8250.h>
13 #include <linux/stmmac.h>
14 #include <linux/usb/ehci_pdriver.h>
17 #include <loongson1.h>
22 /* 8250/16550 compatible UART */
23 #define LS1X_UART(_id) \
25 .mapbase = LS1X_UART ## _id ## _BASE, \
26 .irq = LS1X_UART ## _id ## _IRQ, \
28 .flags = UPF_IOREMAP | UPF_FIXED_TYPE, \
29 .type = PORT_16550A, \
32 static struct plat_serial8250_port ls1x_serial8250_pdata
[] = {
40 struct platform_device ls1x_uart_pdev
= {
42 .id
= PLAT8250_DEV_PLATFORM
,
44 .platform_data
= ls1x_serial8250_pdata
,
48 void __init
ls1x_serial_set_uartclk(struct platform_device
*pdev
)
51 struct plat_serial8250_port
*p
;
53 clk
= clk_get(&pdev
->dev
, pdev
->name
);
55 pr_err("unable to get %s clock, err=%ld",
56 pdev
->name
, PTR_ERR(clk
));
59 clk_prepare_enable(clk
);
61 for (p
= pdev
->dev
.platform_data
; p
->flags
!= 0; ++p
)
62 p
->uartclk
= clk_get_rate(clk
);
66 static struct plat_ls1x_cpufreq ls1x_cpufreq_pdata
= {
67 .clk_name
= "cpu_clk",
68 .osc_clk_name
= "osc_clk",
69 .max_freq
= 266 * 1000,
70 .min_freq
= 33 * 1000,
73 struct platform_device ls1x_cpufreq_pdev
= {
74 .name
= "ls1x-cpufreq",
76 .platform_data
= &ls1x_cpufreq_pdata
,
80 /* Synopsys Ethernet GMAC */
81 static struct stmmac_mdio_bus_data ls1x_mdio_bus_data
= {
85 static struct stmmac_dma_cfg ls1x_eth_dma_cfg
= {
89 int ls1x_eth_mux_init(struct platform_device
*pdev
, void *priv
)
91 struct plat_stmmacenet_data
*plat_dat
= NULL
;
94 val
= __raw_readl(LS1X_MUX_CTRL1
);
96 #if defined(CONFIG_LOONGSON1_LS1B)
97 plat_dat
= dev_get_platdata(&pdev
->dev
);
98 if (plat_dat
->bus_id
) {
99 __raw_writel(__raw_readl(LS1X_MUX_CTRL0
) | GMAC1_USE_UART1
|
100 GMAC1_USE_UART0
, LS1X_MUX_CTRL0
);
101 switch (plat_dat
->interface
) {
102 case PHY_INTERFACE_MODE_RGMII
:
103 val
&= ~(GMAC1_USE_TXCLK
| GMAC1_USE_PWM23
);
105 case PHY_INTERFACE_MODE_MII
:
106 val
|= (GMAC1_USE_TXCLK
| GMAC1_USE_PWM23
);
109 pr_err("unsupported mii mode %d\n",
110 plat_dat
->interface
);
115 switch (plat_dat
->interface
) {
116 case PHY_INTERFACE_MODE_RGMII
:
117 val
&= ~(GMAC0_USE_TXCLK
| GMAC0_USE_PWM01
);
119 case PHY_INTERFACE_MODE_MII
:
120 val
|= (GMAC0_USE_TXCLK
| GMAC0_USE_PWM01
);
123 pr_err("unsupported mii mode %d\n",
124 plat_dat
->interface
);
129 __raw_writel(val
, LS1X_MUX_CTRL1
);
130 #elif defined(CONFIG_LOONGSON1_LS1C)
131 plat_dat
= dev_get_platdata(&pdev
->dev
);
133 val
&= ~PHY_INTF_SELI
;
134 if (plat_dat
->interface
== PHY_INTERFACE_MODE_RMII
)
135 val
|= 0x4 << PHY_INTF_SELI_SHIFT
;
136 __raw_writel(val
, LS1X_MUX_CTRL1
);
138 val
= __raw_readl(LS1X_MUX_CTRL0
);
139 __raw_writel(val
& (~GMAC_SHUT
), LS1X_MUX_CTRL0
);
145 static struct plat_stmmacenet_data ls1x_eth0_pdata
= {
148 #if defined(CONFIG_LOONGSON1_LS1B)
149 .interface
= PHY_INTERFACE_MODE_MII
,
150 #elif defined(CONFIG_LOONGSON1_LS1C)
151 .interface
= PHY_INTERFACE_MODE_RMII
,
153 .mdio_bus_data
= &ls1x_mdio_bus_data
,
154 .dma_cfg
= &ls1x_eth_dma_cfg
,
157 .rx_queues_to_use
= 1,
158 .tx_queues_to_use
= 1,
159 .init
= ls1x_eth_mux_init
,
162 static struct resource ls1x_eth0_resources
[] = {
164 .start
= LS1X_GMAC0_BASE
,
165 .end
= LS1X_GMAC0_BASE
+ SZ_64K
- 1,
166 .flags
= IORESOURCE_MEM
,
170 .start
= LS1X_GMAC0_IRQ
,
171 .flags
= IORESOURCE_IRQ
,
175 struct platform_device ls1x_eth0_pdev
= {
178 .num_resources
= ARRAY_SIZE(ls1x_eth0_resources
),
179 .resource
= ls1x_eth0_resources
,
181 .platform_data
= &ls1x_eth0_pdata
,
185 #ifdef CONFIG_LOONGSON1_LS1B
186 static struct plat_stmmacenet_data ls1x_eth1_pdata
= {
189 .interface
= PHY_INTERFACE_MODE_MII
,
190 .mdio_bus_data
= &ls1x_mdio_bus_data
,
191 .dma_cfg
= &ls1x_eth_dma_cfg
,
194 .rx_queues_to_use
= 1,
195 .tx_queues_to_use
= 1,
196 .init
= ls1x_eth_mux_init
,
199 static struct resource ls1x_eth1_resources
[] = {
201 .start
= LS1X_GMAC1_BASE
,
202 .end
= LS1X_GMAC1_BASE
+ SZ_64K
- 1,
203 .flags
= IORESOURCE_MEM
,
207 .start
= LS1X_GMAC1_IRQ
,
208 .flags
= IORESOURCE_IRQ
,
212 struct platform_device ls1x_eth1_pdev
= {
215 .num_resources
= ARRAY_SIZE(ls1x_eth1_resources
),
216 .resource
= ls1x_eth1_resources
,
218 .platform_data
= &ls1x_eth1_pdata
,
221 #endif /* CONFIG_LOONGSON1_LS1B */
224 static struct resource ls1x_gpio0_resources
[] = {
226 .start
= LS1X_GPIO0_BASE
,
227 .end
= LS1X_GPIO0_BASE
+ SZ_4
- 1,
228 .flags
= IORESOURCE_MEM
,
232 struct platform_device ls1x_gpio0_pdev
= {
235 .num_resources
= ARRAY_SIZE(ls1x_gpio0_resources
),
236 .resource
= ls1x_gpio0_resources
,
239 static struct resource ls1x_gpio1_resources
[] = {
241 .start
= LS1X_GPIO1_BASE
,
242 .end
= LS1X_GPIO1_BASE
+ SZ_4
- 1,
243 .flags
= IORESOURCE_MEM
,
247 struct platform_device ls1x_gpio1_pdev
= {
250 .num_resources
= ARRAY_SIZE(ls1x_gpio1_resources
),
251 .resource
= ls1x_gpio1_resources
,
255 static u64 ls1x_ehci_dmamask
= DMA_BIT_MASK(32);
257 static struct resource ls1x_ehci_resources
[] = {
259 .start
= LS1X_EHCI_BASE
,
260 .end
= LS1X_EHCI_BASE
+ SZ_32K
- 1,
261 .flags
= IORESOURCE_MEM
,
264 .start
= LS1X_EHCI_IRQ
,
265 .flags
= IORESOURCE_IRQ
,
269 static struct usb_ehci_pdata ls1x_ehci_pdata
= {
272 struct platform_device ls1x_ehci_pdev
= {
273 .name
= "ehci-platform",
275 .num_resources
= ARRAY_SIZE(ls1x_ehci_resources
),
276 .resource
= ls1x_ehci_resources
,
278 .dma_mask
= &ls1x_ehci_dmamask
,
279 .platform_data
= &ls1x_ehci_pdata
,
283 /* Real Time Clock */
284 void __init
ls1x_rtc_set_extclk(struct platform_device
*pdev
)
286 u32 val
= __raw_readl(LS1X_RTC_CTRL
);
288 if (!(val
& RTC_EXTCLK_OK
))
289 __raw_writel(val
| RTC_EXTCLK_EN
, LS1X_RTC_CTRL
);
292 struct platform_device ls1x_rtc_pdev
= {
298 static struct resource ls1x_wdt_resources
[] = {
300 .start
= LS1X_WDT_BASE
,
301 .end
= LS1X_WDT_BASE
+ SZ_16
- 1,
302 .flags
= IORESOURCE_MEM
,
306 struct platform_device ls1x_wdt_pdev
= {
309 .num_resources
= ARRAY_SIZE(ls1x_wdt_resources
),
310 .resource
= ls1x_wdt_resources
,