goramo_mlr.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Goramo MultiLink router platform code
  4. * Copyright (C) 2006-2009 Krzysztof Halasa <khc@pm.waw.pl>
  5. */
  6. #include <linux/delay.h>
  7. #include <linux/gpio.h>
  8. #include <linux/hdlc.h>
  9. #include <linux/io.h>
  10. #include <linux/irq.h>
  11. #include <linux/kernel.h>
  12. #include <linux/pci.h>
  13. #include <linux/serial_8250.h>
  14. #include <asm/mach-types.h>
  15. #include <asm/mach/arch.h>
  16. #include <asm/mach/flash.h>
  17. #include <asm/mach/pci.h>
  18. #include <asm/system_info.h>
  19. #define SLOT_ETHA 0x0B /* IDSEL = AD21 */
  20. #define SLOT_ETHB 0x0C /* IDSEL = AD20 */
  21. #define SLOT_MPCI 0x0D /* IDSEL = AD19 */
  22. #define SLOT_NEC 0x0E /* IDSEL = AD18 */
  23. /* GPIO lines */
  24. #define GPIO_SCL 0
  25. #define GPIO_SDA 1
  26. #define GPIO_STR 2
  27. #define GPIO_IRQ_NEC 3
  28. #define GPIO_IRQ_ETHA 4
  29. #define GPIO_IRQ_ETHB 5
  30. #define GPIO_HSS0_DCD_N 6
  31. #define GPIO_HSS1_DCD_N 7
  32. #define GPIO_UART0_DCD 8
  33. #define GPIO_UART1_DCD 9
  34. #define GPIO_HSS0_CTS_N 10
  35. #define GPIO_HSS1_CTS_N 11
  36. #define GPIO_IRQ_MPCI 12
  37. #define GPIO_HSS1_RTS_N 13
  38. #define GPIO_HSS0_RTS_N 14
  39. /* GPIO15 is not connected */
  40. /* Control outputs from 74HC4094 */
  41. #define CONTROL_HSS0_CLK_INT 0
  42. #define CONTROL_HSS1_CLK_INT 1
  43. #define CONTROL_HSS0_DTR_N 2
  44. #define CONTROL_HSS1_DTR_N 3
  45. #define CONTROL_EXT 4
  46. #define CONTROL_AUTO_RESET 5
  47. #define CONTROL_PCI_RESET_N 6
  48. #define CONTROL_EEPROM_WC_N 7
  49. /* offsets from start of flash ROM = 0x50000000 */
  50. #define CFG_ETH0_ADDRESS 0x40 /* 6 bytes */
  51. #define CFG_ETH1_ADDRESS 0x46 /* 6 bytes */
  52. #define CFG_REV 0x4C /* u32 */
  53. #define CFG_SDRAM_SIZE 0x50 /* u32 */
  54. #define CFG_SDRAM_CONF 0x54 /* u32 */
  55. #define CFG_SDRAM_MODE 0x58 /* u32 */
  56. #define CFG_SDRAM_REFRESH 0x5C /* u32 */
  57. #define CFG_HW_BITS 0x60 /* u32 */
  58. #define CFG_HW_USB_PORTS 0x00000007 /* 0 = no NEC chip, 1-5 = ports # */
  59. #define CFG_HW_HAS_PCI_SLOT 0x00000008
  60. #define CFG_HW_HAS_ETH0 0x00000010
  61. #define CFG_HW_HAS_ETH1 0x00000020
  62. #define CFG_HW_HAS_HSS0 0x00000040
  63. #define CFG_HW_HAS_HSS1 0x00000080
  64. #define CFG_HW_HAS_UART0 0x00000100
  65. #define CFG_HW_HAS_UART1 0x00000200
  66. #define CFG_HW_HAS_EEPROM 0x00000400
  67. #define FLASH_CMD_READ_ARRAY 0xFF
  68. #define FLASH_CMD_READ_ID 0x90
  69. #define FLASH_SER_OFF 0x102 /* 0x81 in 16-bit mode */
  70. static u32 hw_bits = 0xFFFFFFFD; /* assume all hardware present */;
  71. static u8 control_value;
  72. /*
  73. * FIXME: this is reimplementing I2C bit-bangining. Move this
  74. * over to using driver/i2c/busses/i2c-gpio.c like all other boards
  75. * and register proper I2C device(s) on the bus for this. (See
  76. * other IXP4xx boards for examples.)
  77. */
  78. static void set_scl(u8 value)
  79. {
  80. gpio_set_value(GPIO_SCL, !!value);
  81. udelay(3);
  82. }
  83. static void set_sda(u8 value)
  84. {
  85. gpio_set_value(GPIO_SDA, !!value);
  86. udelay(3);
  87. }
  88. static void set_str(u8 value)
  89. {
  90. gpio_set_value(GPIO_STR, !!value);
  91. udelay(3);
  92. }
  93. static inline void set_control(int line, int value)
  94. {
  95. if (value)
  96. control_value |= (1 << line);
  97. else
  98. control_value &= ~(1 << line);
  99. }
  100. static void output_control(void)
  101. {
  102. int i;
  103. gpio_direction_output(GPIO_SCL, 1);
  104. gpio_direction_output(GPIO_SDA, 1);
  105. for (i = 0; i < 8; i++) {
  106. set_scl(0);
  107. set_sda(control_value & (0x80 >> i)); /* MSB first */
  108. set_scl(1); /* active edge */
  109. }
  110. set_str(1);
  111. set_str(0);
  112. set_scl(0);
  113. set_sda(1); /* Be ready for START */
  114. set_scl(1);
  115. }
  116. static void (*set_carrier_cb_tab[2])(void *pdev, int carrier);
  117. static int hss_set_clock(int port, unsigned int clock_type)
  118. {
  119. int ctrl_int = port ? CONTROL_HSS1_CLK_INT : CONTROL_HSS0_CLK_INT;
  120. switch (clock_type) {
  121. case CLOCK_DEFAULT:
  122. case CLOCK_EXT:
  123. set_control(ctrl_int, 0);
  124. output_control();
  125. return CLOCK_EXT;
  126. case CLOCK_INT:
  127. set_control(ctrl_int, 1);
  128. output_control();
  129. return CLOCK_INT;
  130. default:
  131. return -EINVAL;
  132. }
  133. }
  134. static irqreturn_t hss_dcd_irq(int irq, void *pdev)
  135. {
  136. int port = (irq == IXP4XX_GPIO_IRQ(GPIO_HSS1_DCD_N));
  137. int i = gpio_get_value(port ? GPIO_HSS1_DCD_N : GPIO_HSS0_DCD_N);
  138. set_carrier_cb_tab[port](pdev, !i);
  139. return IRQ_HANDLED;
  140. }
  141. static int hss_open(int port, void *pdev,
  142. void (*set_carrier_cb)(void *pdev, int carrier))
  143. {
  144. int i, irq;
  145. if (!port)
  146. irq = IXP4XX_GPIO_IRQ(GPIO_HSS0_DCD_N);
  147. else
  148. irq = IXP4XX_GPIO_IRQ(GPIO_HSS1_DCD_N);
  149. i = gpio_get_value(port ? GPIO_HSS1_DCD_N : GPIO_HSS0_DCD_N);
  150. set_carrier_cb(pdev, !i);
  151. set_carrier_cb_tab[!!port] = set_carrier_cb;
  152. if ((i = request_irq(irq, hss_dcd_irq, 0, "IXP4xx HSS", pdev)) != 0) {
  153. printk(KERN_ERR "ixp4xx_hss: failed to request IRQ%i (%i)\n",
  154. irq, i);
  155. return i;
  156. }
  157. set_control(port ? CONTROL_HSS1_DTR_N : CONTROL_HSS0_DTR_N, 0);
  158. output_control();
  159. gpio_set_value(port ? GPIO_HSS1_RTS_N : GPIO_HSS0_RTS_N, 0);
  160. return 0;
  161. }
  162. static void hss_close(int port, void *pdev)
  163. {
  164. free_irq(port ? IXP4XX_GPIO_IRQ(GPIO_HSS1_DCD_N) :
  165. IXP4XX_GPIO_IRQ(GPIO_HSS0_DCD_N), pdev);
  166. set_carrier_cb_tab[!!port] = NULL; /* catch bugs */
  167. set_control(port ? CONTROL_HSS1_DTR_N : CONTROL_HSS0_DTR_N, 1);
  168. output_control();
  169. gpio_set_value(port ? GPIO_HSS1_RTS_N : GPIO_HSS0_RTS_N, 1);
  170. }
  171. /* Flash memory */
  172. static struct flash_platform_data flash_data = {
  173. .map_name = "cfi_probe",
  174. .width = 2,
  175. };
  176. static struct resource flash_resource = {
  177. .flags = IORESOURCE_MEM,
  178. };
  179. static struct platform_device device_flash = {
  180. .name = "IXP4XX-Flash",
  181. .id = 0,
  182. .dev = { .platform_data = &flash_data },
  183. .num_resources = 1,
  184. .resource = &flash_resource,
  185. };
  186. /* IXP425 2 UART ports */
  187. static struct resource uart_resources[] = {
  188. {
  189. .start = IXP4XX_UART1_BASE_PHYS,
  190. .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
  191. .flags = IORESOURCE_MEM,
  192. },
  193. {
  194. .start = IXP4XX_UART2_BASE_PHYS,
  195. .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
  196. .flags = IORESOURCE_MEM,
  197. }
  198. };
  199. static struct plat_serial8250_port uart_data[] = {
  200. {
  201. .mapbase = IXP4XX_UART1_BASE_PHYS,
  202. .membase = (char __iomem *)IXP4XX_UART1_BASE_VIRT +
  203. REG_OFFSET,
  204. .irq = IRQ_IXP4XX_UART1,
  205. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  206. .iotype = UPIO_MEM,
  207. .regshift = 2,
  208. .uartclk = IXP4XX_UART_XTAL,
  209. },
  210. {
  211. .mapbase = IXP4XX_UART2_BASE_PHYS,
  212. .membase = (char __iomem *)IXP4XX_UART2_BASE_VIRT +
  213. REG_OFFSET,
  214. .irq = IRQ_IXP4XX_UART2,
  215. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  216. .iotype = UPIO_MEM,
  217. .regshift = 2,
  218. .uartclk = IXP4XX_UART_XTAL,
  219. },
  220. { },
  221. };
  222. static struct platform_device device_uarts = {
  223. .name = "serial8250",
  224. .id = PLAT8250_DEV_PLATFORM,
  225. .dev.platform_data = uart_data,
  226. .num_resources = 2,
  227. .resource = uart_resources,
  228. };
  229. /* Built-in 10/100 Ethernet MAC interfaces */
  230. static struct eth_plat_info eth_plat[] = {
  231. {
  232. .phy = 0,
  233. .rxq = 3,
  234. .txreadyq = 32,
  235. }, {
  236. .phy = 1,
  237. .rxq = 4,
  238. .txreadyq = 33,
  239. }
  240. };
  241. static struct platform_device device_eth_tab[] = {
  242. {
  243. .name = "ixp4xx_eth",
  244. .id = IXP4XX_ETH_NPEB,
  245. .dev.platform_data = eth_plat,
  246. }, {
  247. .name = "ixp4xx_eth",
  248. .id = IXP4XX_ETH_NPEC,
  249. .dev.platform_data = eth_plat + 1,
  250. }
  251. };
  252. /* IXP425 2 synchronous serial ports */
  253. static struct hss_plat_info hss_plat[] = {
  254. {
  255. .set_clock = hss_set_clock,
  256. .open = hss_open,
  257. .close = hss_close,
  258. .txreadyq = 34,
  259. }, {
  260. .set_clock = hss_set_clock,
  261. .open = hss_open,
  262. .close = hss_close,
  263. .txreadyq = 35,
  264. }
  265. };
  266. static struct platform_device device_hss_tab[] = {
  267. {
  268. .name = "ixp4xx_hss",
  269. .id = 0,
  270. .dev.platform_data = hss_plat,
  271. }, {
  272. .name = "ixp4xx_hss",
  273. .id = 1,
  274. .dev.platform_data = hss_plat + 1,
  275. }
  276. };
  277. static struct platform_device *device_tab[7] __initdata = {
  278. &device_flash, /* index 0 */
  279. };
  280. static inline u8 __init flash_readb(u8 __iomem *flash, u32 addr)
  281. {
  282. #ifdef __ARMEB__
  283. return __raw_readb(flash + addr);
  284. #else
  285. return __raw_readb(flash + (addr ^ 3));
  286. #endif
  287. }
  288. static inline u16 __init flash_readw(u8 __iomem *flash, u32 addr)
  289. {
  290. #ifdef __ARMEB__
  291. return __raw_readw(flash + addr);
  292. #else
  293. return __raw_readw(flash + (addr ^ 2));
  294. #endif
  295. }
  296. static void __init gmlr_init(void)
  297. {
  298. u8 __iomem *flash;
  299. int i, devices = 1; /* flash */
  300. ixp4xx_sys_init();
  301. if ((flash = ioremap(IXP4XX_EXP_BUS_BASE_PHYS, 0x80)) == NULL)
  302. printk(KERN_ERR "goramo-mlr: unable to access system"
  303. " configuration data\n");
  304. else {
  305. system_rev = __raw_readl(flash + CFG_REV);
  306. hw_bits = __raw_readl(flash + CFG_HW_BITS);
  307. for (i = 0; i < ETH_ALEN; i++) {
  308. eth_plat[0].hwaddr[i] =
  309. flash_readb(flash, CFG_ETH0_ADDRESS + i);
  310. eth_plat[1].hwaddr[i] =
  311. flash_readb(flash, CFG_ETH1_ADDRESS + i);
  312. }
  313. __raw_writew(FLASH_CMD_READ_ID, flash);
  314. system_serial_high = flash_readw(flash, FLASH_SER_OFF);
  315. system_serial_high <<= 16;
  316. system_serial_high |= flash_readw(flash, FLASH_SER_OFF + 2);
  317. system_serial_low = flash_readw(flash, FLASH_SER_OFF + 4);
  318. system_serial_low <<= 16;
  319. system_serial_low |= flash_readw(flash, FLASH_SER_OFF + 6);
  320. __raw_writew(FLASH_CMD_READ_ARRAY, flash);
  321. iounmap(flash);
  322. }
  323. switch (hw_bits & (CFG_HW_HAS_UART0 | CFG_HW_HAS_UART1)) {
  324. case CFG_HW_HAS_UART0:
  325. memset(&uart_data[1], 0, sizeof(uart_data[1]));
  326. device_uarts.num_resources = 1;
  327. break;
  328. case CFG_HW_HAS_UART1:
  329. device_uarts.dev.platform_data = &uart_data[1];
  330. device_uarts.resource = &uart_resources[1];
  331. device_uarts.num_resources = 1;
  332. break;
  333. }
  334. if (hw_bits & (CFG_HW_HAS_UART0 | CFG_HW_HAS_UART1))
  335. device_tab[devices++] = &device_uarts; /* max index 1 */
  336. if (hw_bits & CFG_HW_HAS_ETH0)
  337. device_tab[devices++] = &device_eth_tab[0]; /* max index 2 */
  338. if (hw_bits & CFG_HW_HAS_ETH1)
  339. device_tab[devices++] = &device_eth_tab[1]; /* max index 3 */
  340. if (hw_bits & CFG_HW_HAS_HSS0)
  341. device_tab[devices++] = &device_hss_tab[0]; /* max index 4 */
  342. if (hw_bits & CFG_HW_HAS_HSS1)
  343. device_tab[devices++] = &device_hss_tab[1]; /* max index 5 */
  344. gpio_request(GPIO_SCL, "SCL/clock");
  345. gpio_request(GPIO_SDA, "SDA/data");
  346. gpio_request(GPIO_STR, "strobe");
  347. gpio_request(GPIO_HSS0_RTS_N, "HSS0 RTS");
  348. gpio_request(GPIO_HSS1_RTS_N, "HSS1 RTS");
  349. gpio_request(GPIO_HSS0_DCD_N, "HSS0 DCD");
  350. gpio_request(GPIO_HSS1_DCD_N, "HSS1 DCD");
  351. gpio_direction_output(GPIO_SCL, 1);
  352. gpio_direction_output(GPIO_SDA, 1);
  353. gpio_direction_output(GPIO_STR, 0);
  354. gpio_direction_output(GPIO_HSS0_RTS_N, 1);
  355. gpio_direction_output(GPIO_HSS1_RTS_N, 1);
  356. gpio_direction_input(GPIO_HSS0_DCD_N);
  357. gpio_direction_input(GPIO_HSS1_DCD_N);
  358. irq_set_irq_type(IXP4XX_GPIO_IRQ(GPIO_HSS0_DCD_N), IRQ_TYPE_EDGE_BOTH);
  359. irq_set_irq_type(IXP4XX_GPIO_IRQ(GPIO_HSS1_DCD_N), IRQ_TYPE_EDGE_BOTH);
  360. set_control(CONTROL_HSS0_DTR_N, 1);
  361. set_control(CONTROL_HSS1_DTR_N, 1);
  362. set_control(CONTROL_EEPROM_WC_N, 1);
  363. set_control(CONTROL_PCI_RESET_N, 1);
  364. output_control();
  365. msleep(1); /* Wait for PCI devices to initialize */
  366. flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
  367. flash_resource.end = IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
  368. platform_add_devices(device_tab, devices);
  369. }
  370. #ifdef CONFIG_PCI
  371. static void __init gmlr_pci_preinit(void)
  372. {
  373. irq_set_irq_type(IXP4XX_GPIO_IRQ(GPIO_IRQ_ETHA), IRQ_TYPE_LEVEL_LOW);
  374. irq_set_irq_type(IXP4XX_GPIO_IRQ(GPIO_IRQ_ETHB), IRQ_TYPE_LEVEL_LOW);
  375. irq_set_irq_type(IXP4XX_GPIO_IRQ(GPIO_IRQ_NEC), IRQ_TYPE_LEVEL_LOW);
  376. irq_set_irq_type(IXP4XX_GPIO_IRQ(GPIO_IRQ_MPCI), IRQ_TYPE_LEVEL_LOW);
  377. ixp4xx_pci_preinit();
  378. }
  379. static void __init gmlr_pci_postinit(void)
  380. {
  381. if ((hw_bits & CFG_HW_USB_PORTS) >= 2 &&
  382. (hw_bits & CFG_HW_USB_PORTS) < 5) {
  383. /* need to adjust number of USB ports on NEC chip */
  384. u32 value, addr = BIT(32 - SLOT_NEC) | 0xE0;
  385. if (!ixp4xx_pci_read(addr, NP_CMD_CONFIGREAD, &value)) {
  386. value &= ~7;
  387. value |= (hw_bits & CFG_HW_USB_PORTS);
  388. ixp4xx_pci_write(addr, NP_CMD_CONFIGWRITE, value);
  389. }
  390. }
  391. }
  392. static int __init gmlr_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  393. {
  394. switch(slot) {
  395. case SLOT_ETHA: return IXP4XX_GPIO_IRQ(GPIO_IRQ_ETHA);
  396. case SLOT_ETHB: return IXP4XX_GPIO_IRQ(GPIO_IRQ_ETHB);
  397. case SLOT_NEC: return IXP4XX_GPIO_IRQ(GPIO_IRQ_NEC);
  398. default: return IXP4XX_GPIO_IRQ(GPIO_IRQ_MPCI);
  399. }
  400. }
  401. static struct hw_pci gmlr_hw_pci __initdata = {
  402. .nr_controllers = 1,
  403. .ops = &ixp4xx_ops,
  404. .preinit = gmlr_pci_preinit,
  405. .postinit = gmlr_pci_postinit,
  406. .setup = ixp4xx_setup,
  407. .map_irq = gmlr_map_irq,
  408. };
  409. static int __init gmlr_pci_init(void)
  410. {
  411. if (machine_is_goramo_mlr() &&
  412. (hw_bits & (CFG_HW_USB_PORTS | CFG_HW_HAS_PCI_SLOT)))
  413. pci_common_init(&gmlr_hw_pci);
  414. return 0;
  415. }
  416. subsys_initcall(gmlr_pci_init);
  417. #endif /* CONFIG_PCI */
  418. MACHINE_START(GORAMO_MLR, "MultiLink")
  419. /* Maintainer: Krzysztof Halasa */
  420. .map_io = ixp4xx_map_io,
  421. .init_early = ixp4xx_init_early,
  422. .init_irq = ixp4xx_init_irq,
  423. .init_time = ixp4xx_timer_init,
  424. .atag_offset = 0x100,
  425. .init_machine = gmlr_init,
  426. #if defined(CONFIG_PCI)
  427. .dma_zone_size = SZ_64M,
  428. #endif
  429. .restart = ixp4xx_restart,
  430. MACHINE_END