2 * Copyright (c) 2011 Zhang, Keguang <keguang.zhang@gmail.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
10 #include <linux/clk.h>
11 #include <linux/dma-mapping.h>
12 #include <linux/err.h>
13 #include <linux/phy.h>
14 #include <linux/serial_8250.h>
15 #include <linux/stmmac.h>
16 #include <linux/usb/ehci_pdriver.h>
17 #include <asm-generic/sizes.h>
20 #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_setup(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_33m_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 plat_dat
= dev_get_platdata(&pdev
->dev
);
97 if (plat_dat
->bus_id
) {
98 __raw_writel(__raw_readl(LS1X_MUX_CTRL0
) | GMAC1_USE_UART1
|
99 GMAC1_USE_UART0
, LS1X_MUX_CTRL0
);
100 switch (plat_dat
->interface
) {
101 case PHY_INTERFACE_MODE_RGMII
:
102 val
&= ~(GMAC1_USE_TXCLK
| GMAC1_USE_PWM23
);
104 case PHY_INTERFACE_MODE_MII
:
105 val
|= (GMAC1_USE_TXCLK
| GMAC1_USE_PWM23
);
108 pr_err("unsupported mii mode %d\n",
109 plat_dat
->interface
);
114 switch (plat_dat
->interface
) {
115 case PHY_INTERFACE_MODE_RGMII
:
116 val
&= ~(GMAC0_USE_TXCLK
| GMAC0_USE_PWM01
);
118 case PHY_INTERFACE_MODE_MII
:
119 val
|= (GMAC0_USE_TXCLK
| GMAC0_USE_PWM01
);
122 pr_err("unsupported mii mode %d\n",
123 plat_dat
->interface
);
128 __raw_writel(val
, LS1X_MUX_CTRL1
);
133 static struct plat_stmmacenet_data ls1x_eth0_pdata
= {
136 .interface
= PHY_INTERFACE_MODE_MII
,
137 .mdio_bus_data
= &ls1x_mdio_bus_data
,
138 .dma_cfg
= &ls1x_eth_dma_cfg
,
141 .init
= ls1x_eth_mux_init
,
144 static struct resource ls1x_eth0_resources
[] = {
146 .start
= LS1X_GMAC0_BASE
,
147 .end
= LS1X_GMAC0_BASE
+ SZ_64K
- 1,
148 .flags
= IORESOURCE_MEM
,
152 .start
= LS1X_GMAC0_IRQ
,
153 .flags
= IORESOURCE_IRQ
,
157 struct platform_device ls1x_eth0_pdev
= {
160 .num_resources
= ARRAY_SIZE(ls1x_eth0_resources
),
161 .resource
= ls1x_eth0_resources
,
163 .platform_data
= &ls1x_eth0_pdata
,
167 static struct plat_stmmacenet_data ls1x_eth1_pdata
= {
170 .interface
= PHY_INTERFACE_MODE_MII
,
171 .mdio_bus_data
= &ls1x_mdio_bus_data
,
172 .dma_cfg
= &ls1x_eth_dma_cfg
,
175 .init
= ls1x_eth_mux_init
,
178 static struct resource ls1x_eth1_resources
[] = {
180 .start
= LS1X_GMAC1_BASE
,
181 .end
= LS1X_GMAC1_BASE
+ SZ_64K
- 1,
182 .flags
= IORESOURCE_MEM
,
186 .start
= LS1X_GMAC1_IRQ
,
187 .flags
= IORESOURCE_IRQ
,
191 struct platform_device ls1x_eth1_pdev
= {
194 .num_resources
= ARRAY_SIZE(ls1x_eth1_resources
),
195 .resource
= ls1x_eth1_resources
,
197 .platform_data
= &ls1x_eth1_pdata
,
202 static u64 ls1x_ehci_dmamask
= DMA_BIT_MASK(32);
204 static struct resource ls1x_ehci_resources
[] = {
206 .start
= LS1X_EHCI_BASE
,
207 .end
= LS1X_EHCI_BASE
+ SZ_32K
- 1,
208 .flags
= IORESOURCE_MEM
,
211 .start
= LS1X_EHCI_IRQ
,
212 .flags
= IORESOURCE_IRQ
,
216 static struct usb_ehci_pdata ls1x_ehci_pdata
= {
219 struct platform_device ls1x_ehci_pdev
= {
220 .name
= "ehci-platform",
222 .num_resources
= ARRAY_SIZE(ls1x_ehci_resources
),
223 .resource
= ls1x_ehci_resources
,
225 .dma_mask
= &ls1x_ehci_dmamask
,
226 .platform_data
= &ls1x_ehci_pdata
,
230 /* Real Time Clock */
231 struct platform_device ls1x_rtc_pdev
= {