Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
platform.c
Go to the documentation of this file.
1 /*
2  * Copyright 2011, Netlogic Microsystems.
3  * Copyright 2004, Matt Porter <[email protected]>
4  *
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.
8  */
9 
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>
18 
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>
23 
24 unsigned int nlm_xlr_uart_in(struct uart_port *p, int offset)
25 {
26  uint64_t uartbase;
27  unsigned int value;
28 
29  /* sign extend to 64 bits, if needed */
30  uartbase = (uint64_t)(long)p->membase;
31  value = nlm_read_reg(uartbase, offset);
32 
33  /* See XLR/XLS errata */
34  if (offset == UART_MSR)
35  value ^= 0xF0;
36  else if (offset == UART_MCR)
37  value ^= 0x3;
38 
39  return value;
40 }
41 
42 void nlm_xlr_uart_out(struct uart_port *p, int offset, int value)
43 {
44  uint64_t uartbase;
45 
46  /* sign extend to 64 bits, if needed */
47  uartbase = (uint64_t)(long)p->membase;
48 
49  /* See XLR/XLS errata */
50  if (offset == UART_MSR)
51  value ^= 0xF0;
52  else if (offset == UART_MCR)
53  value ^= 0x3;
54 
55  nlm_write_reg(uartbase, offset, value);
56 }
57 
58 #define PORT(_irq) \
59  { \
60  .irq = _irq, \
61  .regshift = 2, \
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, \
69  }
70 
71 static struct plat_serial8250_port xlr_uart_data[] = {
74  {},
75 };
76 
77 static struct platform_device uart_device = {
78  .name = "serial8250",
80  .dev = {
81  .platform_data = xlr_uart_data,
82  },
83 };
84 
85 static int __init nlm_uart_init(void)
86 {
87  unsigned long uartbase;
88 
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);
92 
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);
96 
97  return platform_device_register(&uart_device);
98 }
99 
100 arch_initcall(nlm_uart_init);
101 
102 #ifdef CONFIG_USB
103 /* Platform USB devices, only on XLS chips */
104 static u64 xls_usb_dmamask = ~(u32)0;
105 #define USB_PLATFORM_DEV(n, i, irq) \
106  { \
107  .name = n, \
108  .id = i, \
109  .num_resources = 2, \
110  .dev = { \
111  .dma_mask = &xls_usb_dmamask, \
112  .coherent_dma_mask = 0xffffffff, \
113  }, \
114  .resource = (struct resource[]) { \
115  { \
116  .flags = IORESOURCE_MEM, \
117  }, \
118  { \
119  .start = irq, \
120  .end = irq, \
121  .flags = IORESOURCE_IRQ, \
122  }, \
123  }, \
124  }
125 
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);
132 
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,
137 };
138 
139 int xls_platform_usb_init(void)
140 {
141  uint64_t usb_mmio, gpio_mmio;
142  unsigned long memres;
143  uint32_t val;
144 
145  if (!nlm_chip_is_xls())
146  return 0;
147 
148  gpio_mmio = nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET);
149  usb_mmio = nlm_mmio_base(NETLOGIC_IO_USB_1_OFFSET);
150 
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);
155 
156  /* Enable ports */
157  nlm_write_reg(usb_mmio, 1, 0x07000500);
158 
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);
163  return 0;
164  }
165 
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);
169 
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;
175 
176  memres += 0x400;
177  xls_usb_ohci_device_0.resource[0].start = memres;
178  xls_usb_ohci_device_0.resource[0].end = memres + 0x400 - 1;
179 
180  memres += 0x400;
181  xls_usb_ohci_device_1.resource[0].start = memres;
182  xls_usb_ohci_device_1.resource[0].end = memres + 0x400 - 1;
183 
184  return platform_add_devices(xls_platform_devices,
185  ARRAY_SIZE(xls_platform_devices));
186 }
187 
188 arch_initcall(xls_platform_usb_init);
189 #endif
190 
191 #ifdef CONFIG_I2C
192 static struct i2c_board_info nlm_i2c_board_info1[] __initdata = {
193  /* All XLR boards have this RTC and Max6657 Temp Chip */
194  [0] = {
195  .type = "ds1374",
196  .addr = 0x68
197  },
198  [1] = {
199  .type = "lm90",
200  .addr = 0x4c
201  },
202 };
203 
204 static struct resource i2c_resources[] = {
205  [0] = {
206  .start = 0, /* filled at init */
207  .end = 0,
208  .flags = IORESOURCE_MEM,
209  },
210 };
211 
212 static struct platform_device nlm_xlr_i2c_1 = {
213  .name = "xlr-i2cbus",
214  .id = 1,
215  .num_resources = 1,
216  .resource = i2c_resources,
217 };
218 
219 static int __init nlm_i2c_init(void)
220 {
221  int err = 0;
222  unsigned int offset;
223 
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;
228 
229  platform_device_register(&nlm_xlr_i2c_1);
230 
231  err = i2c_register_board_info(1, nlm_i2c_board_info1,
232  ARRAY_SIZE(nlm_i2c_board_info1));
233  if (err < 0)
234  pr_err("nlm-i2c: cannot register board I2C devices\n");
235  return err;
236 }
237 
238 arch_initcall(nlm_i2c_init);
239 #endif