goramo_mlr.c 12 KB

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