n2100.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * arch/arm/mach-iop32x/n2100.c
  4. *
  5. * Board support code for the Thecus N2100 platform.
  6. *
  7. * Author: Rory Bolt <[email protected]>
  8. * Copyright (C) 2002 Rory Bolt
  9. * Copyright 2003 (c) MontaVista, Software, Inc.
  10. * Copyright (C) 2004 Intel Corp.
  11. */
  12. #include <linux/mm.h>
  13. #include <linux/init.h>
  14. #include <linux/f75375s.h>
  15. #include <linux/leds-pca9532.h>
  16. #include <linux/delay.h>
  17. #include <linux/kernel.h>
  18. #include <linux/pci.h>
  19. #include <linux/pm.h>
  20. #include <linux/string.h>
  21. #include <linux/serial_core.h>
  22. #include <linux/serial_8250.h>
  23. #include <linux/mtd/physmap.h>
  24. #include <linux/i2c.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/reboot.h>
  27. #include <linux/io.h>
  28. #include <linux/gpio.h>
  29. #include <linux/gpio/machine.h>
  30. #include <asm/irq.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/mach/map.h>
  33. #include <asm/mach/pci.h>
  34. #include <asm/mach/time.h>
  35. #include <asm/mach-types.h>
  36. #include <asm/page.h>
  37. #include "hardware.h"
  38. #include "irqs.h"
  39. #include "gpio-iop32x.h"
  40. /*
  41. * N2100 timer tick configuration.
  42. */
  43. static void __init n2100_timer_init(void)
  44. {
  45. /* 33.000 MHz crystal. */
  46. iop_init_time(198000000);
  47. }
  48. /*
  49. * N2100 I/O.
  50. */
  51. static struct map_desc n2100_io_desc[] __initdata = {
  52. { /* on-board devices */
  53. .virtual = N2100_UART,
  54. .pfn = __phys_to_pfn(N2100_UART),
  55. .length = 0x00100000,
  56. .type = MT_DEVICE
  57. },
  58. };
  59. void __init n2100_map_io(void)
  60. {
  61. iop3xx_map_io();
  62. iotable_init(n2100_io_desc, ARRAY_SIZE(n2100_io_desc));
  63. }
  64. /*
  65. * N2100 PCI.
  66. */
  67. static int n2100_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  68. {
  69. int irq;
  70. if (PCI_SLOT(dev->devfn) == 1) {
  71. /* RTL8110SB #1 */
  72. irq = IRQ_IOP32X_XINT0;
  73. } else if (PCI_SLOT(dev->devfn) == 2) {
  74. /* RTL8110SB #2 */
  75. irq = IRQ_IOP32X_XINT3;
  76. } else if (PCI_SLOT(dev->devfn) == 3) {
  77. /* Sil3512 */
  78. irq = IRQ_IOP32X_XINT2;
  79. } else if (PCI_SLOT(dev->devfn) == 4 && pin == 1) {
  80. /* VT6212 INTA */
  81. irq = IRQ_IOP32X_XINT1;
  82. } else if (PCI_SLOT(dev->devfn) == 4 && pin == 2) {
  83. /* VT6212 INTB */
  84. irq = IRQ_IOP32X_XINT0;
  85. } else if (PCI_SLOT(dev->devfn) == 4 && pin == 3) {
  86. /* VT6212 INTC */
  87. irq = IRQ_IOP32X_XINT2;
  88. } else if (PCI_SLOT(dev->devfn) == 5) {
  89. /* Mini-PCI slot */
  90. irq = IRQ_IOP32X_XINT3;
  91. } else {
  92. printk(KERN_ERR "n2100_pci_map_irq() called for unknown "
  93. "device PCI:%d:%d:%d\n", dev->bus->number,
  94. PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
  95. irq = -1;
  96. }
  97. return irq;
  98. }
  99. static struct hw_pci n2100_pci __initdata = {
  100. .nr_controllers = 1,
  101. .ops = &iop3xx_ops,
  102. .setup = iop3xx_pci_setup,
  103. .preinit = iop3xx_pci_preinit,
  104. .map_irq = n2100_pci_map_irq,
  105. };
  106. /*
  107. * Both r8169 chips on the n2100 exhibit PCI parity problems. Turn
  108. * off parity reporting for both ports so we don't get error interrupts
  109. * for them.
  110. */
  111. static void n2100_fixup_r8169(struct pci_dev *dev)
  112. {
  113. if (dev->bus->number == 0 &&
  114. (dev->devfn == PCI_DEVFN(1, 0) ||
  115. dev->devfn == PCI_DEVFN(2, 0)))
  116. pci_disable_parity(dev);
  117. }
  118. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, PCI_ANY_ID, n2100_fixup_r8169);
  119. static int __init n2100_pci_init(void)
  120. {
  121. if (machine_is_n2100())
  122. pci_common_init(&n2100_pci);
  123. return 0;
  124. }
  125. subsys_initcall(n2100_pci_init);
  126. /*
  127. * N2100 machine initialisation.
  128. */
  129. static struct physmap_flash_data n2100_flash_data = {
  130. .width = 2,
  131. };
  132. static struct resource n2100_flash_resource = {
  133. .start = 0xf0000000,
  134. .end = 0xf0ffffff,
  135. .flags = IORESOURCE_MEM,
  136. };
  137. static struct platform_device n2100_flash_device = {
  138. .name = "physmap-flash",
  139. .id = 0,
  140. .dev = {
  141. .platform_data = &n2100_flash_data,
  142. },
  143. .num_resources = 1,
  144. .resource = &n2100_flash_resource,
  145. };
  146. static struct plat_serial8250_port n2100_serial_port[] = {
  147. {
  148. .mapbase = N2100_UART,
  149. .membase = (char *)N2100_UART,
  150. .irq = 0,
  151. .flags = UPF_SKIP_TEST | UPF_AUTO_IRQ | UPF_SHARE_IRQ,
  152. .iotype = UPIO_MEM,
  153. .regshift = 0,
  154. .uartclk = 1843200,
  155. },
  156. { },
  157. };
  158. static struct resource n2100_uart_resource = {
  159. .start = N2100_UART,
  160. .end = N2100_UART + 7,
  161. .flags = IORESOURCE_MEM,
  162. };
  163. static struct platform_device n2100_serial_device = {
  164. .name = "serial8250",
  165. .id = PLAT8250_DEV_PLATFORM,
  166. .dev = {
  167. .platform_data = n2100_serial_port,
  168. },
  169. .num_resources = 1,
  170. .resource = &n2100_uart_resource,
  171. };
  172. static struct f75375s_platform_data n2100_f75375s = {
  173. .pwm = { 255, 255 },
  174. .pwm_enable = { 0, 0 },
  175. };
  176. static struct pca9532_platform_data n2100_leds = {
  177. .leds = {
  178. { .name = "n2100:red:satafail0",
  179. .state = PCA9532_OFF,
  180. .type = PCA9532_TYPE_LED,
  181. },
  182. { .name = "n2100:red:satafail1",
  183. .state = PCA9532_OFF,
  184. .type = PCA9532_TYPE_LED,
  185. },
  186. { .name = "n2100:blue:usb",
  187. .state = PCA9532_OFF,
  188. .type = PCA9532_TYPE_LED,
  189. },
  190. { .type = PCA9532_TYPE_NONE },
  191. { .type = PCA9532_TYPE_NONE },
  192. { .type = PCA9532_TYPE_NONE },
  193. { .type = PCA9532_TYPE_NONE },
  194. { .name = "n2100:red:usb",
  195. .state = PCA9532_OFF,
  196. .type = PCA9532_TYPE_LED,
  197. },
  198. { .type = PCA9532_TYPE_NONE }, /* power OFF gpio */
  199. { .type = PCA9532_TYPE_NONE }, /* reset gpio */
  200. { .type = PCA9532_TYPE_NONE },
  201. { .type = PCA9532_TYPE_NONE },
  202. { .type = PCA9532_TYPE_NONE },
  203. { .name = "n2100:orange:system",
  204. .state = PCA9532_OFF,
  205. .type = PCA9532_TYPE_LED,
  206. },
  207. { .name = "n2100:red:system",
  208. .state = PCA9532_OFF,
  209. .type = PCA9532_TYPE_LED,
  210. },
  211. { .name = "N2100 beeper" ,
  212. .state = PCA9532_OFF,
  213. .type = PCA9532_TYPE_N2100_BEEP,
  214. },
  215. },
  216. .psc = { 0, 0 },
  217. .pwm = { 0, 0 },
  218. };
  219. static struct i2c_board_info __initdata n2100_i2c_devices[] = {
  220. {
  221. I2C_BOARD_INFO("rs5c372b", 0x32),
  222. },
  223. {
  224. I2C_BOARD_INFO("f75375", 0x2e),
  225. .platform_data = &n2100_f75375s,
  226. },
  227. {
  228. I2C_BOARD_INFO("pca9532", 0x60),
  229. .platform_data = &n2100_leds,
  230. },
  231. };
  232. /*
  233. * Pull PCA9532 GPIO #8 low to power off the machine.
  234. */
  235. static void n2100_power_off(void)
  236. {
  237. local_irq_disable();
  238. /* Start condition, I2C address of PCA9532, write transaction. */
  239. *IOP3XX_IDBR0 = 0xc0;
  240. *IOP3XX_ICR0 = 0xe9;
  241. mdelay(1);
  242. /* Write address 0x08. */
  243. *IOP3XX_IDBR0 = 0x08;
  244. *IOP3XX_ICR0 = 0xe8;
  245. mdelay(1);
  246. /* Write data 0x01, stop condition. */
  247. *IOP3XX_IDBR0 = 0x01;
  248. *IOP3XX_ICR0 = 0xea;
  249. while (1)
  250. ;
  251. }
  252. static void n2100_restart(enum reboot_mode mode, const char *cmd)
  253. {
  254. int ret;
  255. ret = gpio_direction_output(N2100_HARDWARE_RESET, 0);
  256. if (ret) {
  257. pr_crit("could not drive reset GPIO low\n");
  258. return;
  259. }
  260. /* Wait for reset to happen */
  261. while (1)
  262. ;
  263. }
  264. static struct timer_list power_button_poll_timer;
  265. static void power_button_poll(struct timer_list *unused)
  266. {
  267. if (gpio_get_value(N2100_POWER_BUTTON) == 0) {
  268. ctrl_alt_del();
  269. return;
  270. }
  271. power_button_poll_timer.expires = jiffies + (HZ / 10);
  272. add_timer(&power_button_poll_timer);
  273. }
  274. static int __init n2100_request_gpios(void)
  275. {
  276. int ret;
  277. if (!machine_is_n2100())
  278. return 0;
  279. ret = gpio_request(N2100_HARDWARE_RESET, "reset");
  280. if (ret)
  281. pr_err("could not request reset GPIO\n");
  282. ret = gpio_request(N2100_POWER_BUTTON, "power");
  283. if (ret)
  284. pr_err("could not request power GPIO\n");
  285. else {
  286. ret = gpio_direction_input(N2100_POWER_BUTTON);
  287. if (ret)
  288. pr_err("could not set power GPIO as input\n");
  289. }
  290. /* Set up power button poll timer */
  291. timer_setup(&power_button_poll_timer, power_button_poll, 0);
  292. power_button_poll_timer.expires = jiffies + (HZ / 10);
  293. add_timer(&power_button_poll_timer);
  294. return 0;
  295. }
  296. device_initcall(n2100_request_gpios);
  297. static void __init n2100_init_machine(void)
  298. {
  299. register_iop32x_gpio();
  300. gpiod_add_lookup_table(&iop3xx_i2c0_gpio_lookup);
  301. platform_device_register(&iop3xx_i2c0_device);
  302. platform_device_register(&n2100_flash_device);
  303. platform_device_register(&n2100_serial_device);
  304. platform_device_register(&iop3xx_dma_0_channel);
  305. platform_device_register(&iop3xx_dma_1_channel);
  306. i2c_register_board_info(0, n2100_i2c_devices,
  307. ARRAY_SIZE(n2100_i2c_devices));
  308. pm_power_off = n2100_power_off;
  309. }
  310. MACHINE_START(N2100, "Thecus N2100")
  311. /* Maintainer: Lennert Buytenhek <[email protected]> */
  312. .atag_offset = 0x100,
  313. .nr_irqs = IOP32X_NR_IRQS,
  314. .map_io = n2100_map_io,
  315. .init_irq = iop32x_init_irq,
  316. .init_time = n2100_timer_init,
  317. .init_machine = n2100_init_machine,
  318. .restart = n2100_restart,
  319. MACHINE_END