platform.c 5.8 KB

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