platform.c 6.0 KB

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