goramo_mlr.c 12 KB

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