platform.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright 2011, Netlogic Microsystems.
  3. * Copyright 2004, Matt Porter <mporter@kernel.crashing.org>
  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. #include <linux/device.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/resource.h>
  14. #include <linux/serial_8250.h>
  15. #include <linux/serial_reg.h>
  16. #include <linux/i2c.h>
  17. #include <linux/usb/ehci_pdriver.h>
  18. #include <linux/usb/ohci_pdriver.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>
  23. static unsigned int nlm_xlr_uart_in(struct uart_port *p, int offset)
  24. {
  25. uint64_t uartbase;
  26. unsigned int value;
  27. /* sign extend to 64 bits, if needed */
  28. uartbase = (uint64_t)(long)p->membase;
  29. value = nlm_read_reg(uartbase, offset);
  30. /* See XLR/XLS errata */
  31. if (offset == UART_MSR)
  32. value ^= 0xF0;
  33. else if (offset == UART_MCR)
  34. value ^= 0x3;
  35. return value;
  36. }
  37. static void nlm_xlr_uart_out(struct uart_port *p, int offset, int value)
  38. {
  39. uint64_t uartbase;
  40. /* sign extend to 64 bits, if needed */
  41. uartbase = (uint64_t)(long)p->membase;
  42. /* See XLR/XLS errata */
  43. if (offset == UART_MSR)
  44. value ^= 0xF0;
  45. else if (offset == UART_MCR)
  46. value ^= 0x3;
  47. nlm_write_reg(uartbase, offset, value);
  48. }
  49. #define PORT(_irq) \
  50. { \
  51. .irq = _irq, \
  52. .regshift = 2, \
  53. .iotype = UPIO_MEM32, \
  54. .flags = (UPF_SKIP_TEST | \
  55. UPF_FIXED_TYPE | UPF_BOOT_AUTOCONF),\
  56. .uartclk = PIC_CLK_HZ, \
  57. .type = PORT_16550A, \
  58. .serial_in = nlm_xlr_uart_in, \
  59. .serial_out = nlm_xlr_uart_out, \
  60. }
  61. static struct plat_serial8250_port xlr_uart_data[] = {
  62. PORT(PIC_UART_0_IRQ),
  63. PORT(PIC_UART_1_IRQ),
  64. {},
  65. };
  66. static struct platform_device uart_device = {
  67. .name = "serial8250",
  68. .id = PLAT8250_DEV_PLATFORM,
  69. .dev = {
  70. .platform_data = xlr_uart_data,
  71. },
  72. };
  73. static int __init nlm_uart_init(void)
  74. {
  75. unsigned long uartbase;
  76. uartbase = (unsigned long)nlm_mmio_base(NETLOGIC_IO_UART_0_OFFSET);
  77. xlr_uart_data[0].membase = (void __iomem *)uartbase;
  78. xlr_uart_data[0].mapbase = CPHYSADDR(uartbase);
  79. uartbase = (unsigned long)nlm_mmio_base(NETLOGIC_IO_UART_1_OFFSET);
  80. xlr_uart_data[1].membase = (void __iomem *)uartbase;
  81. xlr_uart_data[1].mapbase = CPHYSADDR(uartbase);
  82. return platform_device_register(&uart_device);
  83. }
  84. arch_initcall(nlm_uart_init);
  85. #ifdef CONFIG_USB
  86. /* Platform USB devices, only on XLS chips */
  87. static u64 xls_usb_dmamask = ~(u32)0;
  88. #define USB_PLATFORM_DEV(n, i, irq) \
  89. { \
  90. .name = n, \
  91. .id = i, \
  92. .num_resources = 2, \
  93. .dev = { \
  94. .dma_mask = &xls_usb_dmamask, \
  95. .coherent_dma_mask = 0xffffffff, \
  96. }, \
  97. .resource = (struct resource[]) { \
  98. { \
  99. .flags = IORESOURCE_MEM, \
  100. }, \
  101. { \
  102. .start = irq, \
  103. .end = irq, \
  104. .flags = IORESOURCE_IRQ, \
  105. }, \
  106. }, \
  107. }
  108. static struct usb_ehci_pdata xls_usb_ehci_pdata = {
  109. .caps_offset = 0,
  110. };
  111. static struct usb_ohci_pdata xls_usb_ohci_pdata;
  112. static struct platform_device xls_usb_ehci_device =
  113. USB_PLATFORM_DEV("ehci-platform", 0, PIC_USB_IRQ);
  114. static struct platform_device xls_usb_ohci_device_0 =
  115. USB_PLATFORM_DEV("ohci-platform", 1, PIC_USB_IRQ);
  116. static struct platform_device xls_usb_ohci_device_1 =
  117. USB_PLATFORM_DEV("ohci-platform", 2, PIC_USB_IRQ);
  118. static struct platform_device *xls_platform_devices[] = {
  119. &xls_usb_ehci_device,
  120. &xls_usb_ohci_device_0,
  121. &xls_usb_ohci_device_1,
  122. };
  123. int xls_platform_usb_init(void)
  124. {
  125. uint64_t usb_mmio, gpio_mmio;
  126. unsigned long memres;
  127. uint32_t val;
  128. if (!nlm_chip_is_xls())
  129. return 0;
  130. gpio_mmio = nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET);
  131. usb_mmio = nlm_mmio_base(NETLOGIC_IO_USB_1_OFFSET);
  132. /* Clear Rogue Phy INTs */
  133. nlm_write_reg(usb_mmio, 49, 0x10000000);
  134. /* Enable all interrupts */
  135. nlm_write_reg(usb_mmio, 50, 0x1f000000);
  136. /* Enable ports */
  137. nlm_write_reg(usb_mmio, 1, 0x07000500);
  138. val = nlm_read_reg(gpio_mmio, 21);
  139. if (((val >> 22) & 0x01) == 0) {
  140. pr_info("Detected USB Device mode - Not supported!\n");
  141. nlm_write_reg(usb_mmio, 0, 0x01000000);
  142. return 0;
  143. }
  144. pr_info("Detected USB Host mode - Adding XLS USB devices.\n");
  145. /* Clear reset, host mode */
  146. nlm_write_reg(usb_mmio, 0, 0x02000000);
  147. /* Memory resource for various XLS usb ports */
  148. usb_mmio = nlm_mmio_base(NETLOGIC_IO_USB_0_OFFSET);
  149. memres = CPHYSADDR((unsigned long)usb_mmio);
  150. xls_usb_ehci_device.resource[0].start = memres;
  151. xls_usb_ehci_device.resource[0].end = memres + 0x400 - 1;
  152. xls_usb_ehci_device.dev.platform_data = &xls_usb_ehci_pdata;
  153. memres += 0x400;
  154. xls_usb_ohci_device_0.resource[0].start = memres;
  155. xls_usb_ohci_device_0.resource[0].end = memres + 0x400 - 1;
  156. xls_usb_ohci_device_0.dev.platform_data = &xls_usb_ohci_pdata;
  157. memres += 0x400;
  158. xls_usb_ohci_device_1.resource[0].start = memres;
  159. xls_usb_ohci_device_1.resource[0].end = memres + 0x400 - 1;
  160. xls_usb_ohci_device_1.dev.platform_data = &xls_usb_ohci_pdata;
  161. return platform_add_devices(xls_platform_devices,
  162. ARRAY_SIZE(xls_platform_devices));
  163. }
  164. arch_initcall(xls_platform_usb_init);
  165. #endif
  166. #ifdef CONFIG_I2C
  167. static struct i2c_board_info nlm_i2c_board_info1[] __initdata = {
  168. /* All XLR boards have this RTC and Max6657 Temp Chip */
  169. [0] = {
  170. .type = "ds1374",
  171. .addr = 0x68
  172. },
  173. [1] = {
  174. .type = "lm90",
  175. .addr = 0x4c
  176. },
  177. };
  178. static struct resource i2c_resources[] = {
  179. [0] = {
  180. .start = 0, /* filled at init */
  181. .end = 0,
  182. .flags = IORESOURCE_MEM,
  183. },
  184. };
  185. static struct platform_device nlm_xlr_i2c_1 = {
  186. .name = "xlr-i2cbus",
  187. .id = 1,
  188. .num_resources = 1,
  189. .resource = i2c_resources,
  190. };
  191. static int __init nlm_i2c_init(void)
  192. {
  193. int err = 0;
  194. unsigned int offset;
  195. /* I2C bus 0 does not have any useful devices, configure only bus 1 */
  196. offset = NETLOGIC_IO_I2C_1_OFFSET;
  197. nlm_xlr_i2c_1.resource[0].start = CPHYSADDR(nlm_mmio_base(offset));
  198. nlm_xlr_i2c_1.resource[0].end = nlm_xlr_i2c_1.resource[0].start + 0xfff;
  199. platform_device_register(&nlm_xlr_i2c_1);
  200. err = i2c_register_board_info(1, nlm_i2c_board_info1,
  201. ARRAY_SIZE(nlm_i2c_board_info1));
  202. if (err < 0)
  203. pr_err("nlm-i2c: cannot register board I2C devices\n");
  204. return err;
  205. }
  206. arch_initcall(nlm_i2c_init);
  207. #endif