2 * Copyright 2011, Netlogic Microsystems.
3 * Copyright 2004, Matt Porter <mporter@kernel.crashing.org>
5 * This file is licensed under the terms of the GNU General Public
6 * License version 2. This program is licensed "as is" without any
7 * warranty of any kind, whether express or implied.
10 #include <linux/device.h>
11 #include <linux/platform_device.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/resource.h>
15 #include <linux/serial_8250.h>
16 #include <linux/serial_reg.h>
17 #include <linux/i2c.h>
19 #include <asm/netlogic/haldefs.h>
20 #include <asm/netlogic/xlr/iomap.h>
21 #include <asm/netlogic/xlr/pic.h>
22 #include <asm/netlogic/xlr/xlr.h>
24 unsigned int nlm_xlr_uart_in(struct uart_port *p, int offset)
29 /* sign extend to 64 bits, if needed */
30 uartbase = (uint64_t)(long)p->membase;
31 value = nlm_read_reg(uartbase, offset);
33 /* See XLR/XLS errata */
34 if (offset == UART_MSR)
36 else if (offset == UART_MCR)
42 void nlm_xlr_uart_out(struct uart_port *p, int offset, int value)
46 /* sign extend to 64 bits, if needed */
47 uartbase = (uint64_t)(long)p->membase;
49 /* See XLR/XLS errata */
50 if (offset == UART_MSR)
52 else if (offset == UART_MCR)
55 nlm_write_reg(uartbase, offset, value);
62 .iotype = UPIO_MEM32, \
63 .flags = (UPF_SKIP_TEST | \
64 UPF_FIXED_TYPE | UPF_BOOT_AUTOCONF),\
65 .uartclk = PIC_CLKS_PER_SEC, \
66 .type = PORT_16550A, \
67 .serial_in = nlm_xlr_uart_in, \
68 .serial_out = nlm_xlr_uart_out, \
71 static struct plat_serial8250_port xlr_uart_data[] = {
77 static struct platform_device uart_device = {
79 .id = PLAT8250_DEV_PLATFORM,
81 .platform_data = xlr_uart_data,
85 static int __init nlm_uart_init(void)
87 unsigned long uartbase;
89 uartbase = (unsigned long)nlm_mmio_base(NETLOGIC_IO_UART_0_OFFSET);
90 xlr_uart_data[0].membase = (void __iomem *)uartbase;
91 xlr_uart_data[0].mapbase = CPHYSADDR(uartbase);
93 uartbase = (unsigned long)nlm_mmio_base(NETLOGIC_IO_UART_1_OFFSET);
94 xlr_uart_data[1].membase = (void __iomem *)uartbase;
95 xlr_uart_data[1].mapbase = CPHYSADDR(uartbase);
97 return platform_device_register(&uart_device);
100 arch_initcall(nlm_uart_init);
103 /* Platform USB devices, only on XLS chips */
104 static u64 xls_usb_dmamask = ~(u32)0;
105 #define USB_PLATFORM_DEV(n, i, irq) \
109 .num_resources = 2, \
111 .dma_mask = &xls_usb_dmamask, \
112 .coherent_dma_mask = 0xffffffff, \
114 .resource = (struct resource[]) { \
116 .flags = IORESOURCE_MEM, \
121 .flags = IORESOURCE_IRQ, \
126 static struct platform_device xls_usb_ehci_device =
127 USB_PLATFORM_DEV("ehci-xls", 0, PIC_USB_IRQ);
128 static struct platform_device xls_usb_ohci_device_0 =
129 USB_PLATFORM_DEV("ohci-xls-0", 1, PIC_USB_IRQ);
130 static struct platform_device xls_usb_ohci_device_1 =
131 USB_PLATFORM_DEV("ohci-xls-1", 2, PIC_USB_IRQ);
133 static struct platform_device *xls_platform_devices[] = {
134 &xls_usb_ehci_device,
135 &xls_usb_ohci_device_0,
136 &xls_usb_ohci_device_1,
139 int xls_platform_usb_init(void)
141 uint64_t usb_mmio, gpio_mmio;
142 unsigned long memres;
145 if (!nlm_chip_is_xls())
148 gpio_mmio = nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET);
149 usb_mmio = nlm_mmio_base(NETLOGIC_IO_USB_1_OFFSET);
151 /* Clear Rogue Phy INTs */
152 nlm_write_reg(usb_mmio, 49, 0x10000000);
153 /* Enable all interrupts */
154 nlm_write_reg(usb_mmio, 50, 0x1f000000);
157 nlm_write_reg(usb_mmio, 1, 0x07000500);
159 val = nlm_read_reg(gpio_mmio, 21);
160 if (((val >> 22) & 0x01) == 0) {
161 pr_info("Detected USB Device mode - Not supported!\n");
162 nlm_write_reg(usb_mmio, 0, 0x01000000);
166 pr_info("Detected USB Host mode - Adding XLS USB devices.\n");
167 /* Clear reset, host mode */
168 nlm_write_reg(usb_mmio, 0, 0x02000000);
170 /* Memory resource for various XLS usb ports */
171 usb_mmio = nlm_mmio_base(NETLOGIC_IO_USB_0_OFFSET);
172 memres = CPHYSADDR((unsigned long)usb_mmio);
173 xls_usb_ehci_device.resource[0].start = memres;
174 xls_usb_ehci_device.resource[0].end = memres + 0x400 - 1;
177 xls_usb_ohci_device_0.resource[0].start = memres;
178 xls_usb_ohci_device_0.resource[0].end = memres + 0x400 - 1;
181 xls_usb_ohci_device_1.resource[0].start = memres;
182 xls_usb_ohci_device_1.resource[0].end = memres + 0x400 - 1;
184 return platform_add_devices(xls_platform_devices,
185 ARRAY_SIZE(xls_platform_devices));
188 arch_initcall(xls_platform_usb_init);
192 static struct i2c_board_info nlm_i2c_board_info1[] __initdata = {
193 /* All XLR boards have this RTC and Max6657 Temp Chip */
204 static struct resource i2c_resources[] = {
206 .start = 0, /* filled at init */
208 .flags = IORESOURCE_MEM,
212 static struct platform_device nlm_xlr_i2c_1 = {
213 .name = "xlr-i2cbus",
216 .resource = i2c_resources,
219 static int __init nlm_i2c_init(void)
224 /* I2C bus 0 does not have any useful devices, configure only bus 1 */
225 offset = NETLOGIC_IO_I2C_1_OFFSET;
226 nlm_xlr_i2c_1.resource[0].start = CPHYSADDR(nlm_mmio_base(offset));
227 nlm_xlr_i2c_1.resource[0].end = nlm_xlr_i2c_1.resource[0].start + 0xfff;
229 platform_device_register(&nlm_xlr_i2c_1);
231 err = i2c_register_board_info(1, nlm_i2c_board_info1,
232 ARRAY_SIZE(nlm_i2c_board_info1));
234 pr_err("nlm-i2c: cannot register board I2C devices\n");
238 arch_initcall(nlm_i2c_init);