goramo_mlr.c 12 KB

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