devices.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. * RouterBoard 500 Platform devices
  3. *
  4. * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  5. * Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/export.h>
  19. #include <linux/init.h>
  20. #include <linux/ctype.h>
  21. #include <linux/string.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/mtd/nand.h>
  24. #include <linux/mtd/mtd.h>
  25. #include <linux/mtd/partitions.h>
  26. #include <linux/gpio.h>
  27. #include <linux/gpio_keys.h>
  28. #include <linux/input.h>
  29. #include <linux/serial_8250.h>
  30. #include <asm/bootinfo.h>
  31. #include <asm/mach-rc32434/rc32434.h>
  32. #include <asm/mach-rc32434/dma.h>
  33. #include <asm/mach-rc32434/dma_v.h>
  34. #include <asm/mach-rc32434/eth.h>
  35. #include <asm/mach-rc32434/rb.h>
  36. #include <asm/mach-rc32434/integ.h>
  37. #include <asm/mach-rc32434/gpio.h>
  38. #include <asm/mach-rc32434/irq.h>
  39. #define ETH0_RX_DMA_ADDR (DMA0_BASE_ADDR + 0 * DMA_CHAN_OFFSET)
  40. #define ETH0_TX_DMA_ADDR (DMA0_BASE_ADDR + 1 * DMA_CHAN_OFFSET)
  41. extern unsigned int idt_cpu_freq;
  42. static struct mpmc_device dev3;
  43. void set_latch_u5(unsigned char or_mask, unsigned char nand_mask)
  44. {
  45. unsigned long flags;
  46. spin_lock_irqsave(&dev3.lock, flags);
  47. dev3.state = (dev3.state | or_mask) & ~nand_mask;
  48. writeb(dev3.state, dev3.base);
  49. spin_unlock_irqrestore(&dev3.lock, flags);
  50. }
  51. EXPORT_SYMBOL(set_latch_u5);
  52. unsigned char get_latch_u5(void)
  53. {
  54. return dev3.state;
  55. }
  56. EXPORT_SYMBOL(get_latch_u5);
  57. static struct resource korina_dev0_res[] = {
  58. {
  59. .name = "korina_regs",
  60. .start = ETH0_BASE_ADDR,
  61. .end = ETH0_BASE_ADDR + sizeof(struct eth_regs),
  62. .flags = IORESOURCE_MEM,
  63. }, {
  64. .name = "korina_rx",
  65. .start = ETH0_DMA_RX_IRQ,
  66. .end = ETH0_DMA_RX_IRQ,
  67. .flags = IORESOURCE_IRQ
  68. }, {
  69. .name = "korina_tx",
  70. .start = ETH0_DMA_TX_IRQ,
  71. .end = ETH0_DMA_TX_IRQ,
  72. .flags = IORESOURCE_IRQ
  73. }, {
  74. .name = "korina_ovr",
  75. .start = ETH0_RX_OVR_IRQ,
  76. .end = ETH0_RX_OVR_IRQ,
  77. .flags = IORESOURCE_IRQ
  78. }, {
  79. .name = "korina_und",
  80. .start = ETH0_TX_UND_IRQ,
  81. .end = ETH0_TX_UND_IRQ,
  82. .flags = IORESOURCE_IRQ
  83. }, {
  84. .name = "korina_dma_rx",
  85. .start = ETH0_RX_DMA_ADDR,
  86. .end = ETH0_RX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
  87. .flags = IORESOURCE_MEM,
  88. }, {
  89. .name = "korina_dma_tx",
  90. .start = ETH0_TX_DMA_ADDR,
  91. .end = ETH0_TX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
  92. .flags = IORESOURCE_MEM,
  93. }
  94. };
  95. static struct korina_device korina_dev0_data = {
  96. .name = "korina0",
  97. .mac = {0xde, 0xca, 0xff, 0xc0, 0xff, 0xee}
  98. };
  99. static struct platform_device korina_dev0 = {
  100. .id = -1,
  101. .name = "korina",
  102. .resource = korina_dev0_res,
  103. .num_resources = ARRAY_SIZE(korina_dev0_res),
  104. };
  105. static struct resource cf_slot0_res[] = {
  106. {
  107. .name = "cf_membase",
  108. .flags = IORESOURCE_MEM
  109. }, {
  110. .name = "cf_irq",
  111. .start = (8 + 4 * 32 + CF_GPIO_NUM), /* 149 */
  112. .end = (8 + 4 * 32 + CF_GPIO_NUM),
  113. .flags = IORESOURCE_IRQ
  114. }
  115. };
  116. static struct cf_device cf_slot0_data = {
  117. .gpio_pin = CF_GPIO_NUM
  118. };
  119. static struct platform_device cf_slot0 = {
  120. .id = -1,
  121. .name = "pata-rb532-cf",
  122. .dev.platform_data = &cf_slot0_data,
  123. .resource = cf_slot0_res,
  124. .num_resources = ARRAY_SIZE(cf_slot0_res),
  125. };
  126. /* Resources and device for NAND */
  127. static int rb532_dev_ready(struct mtd_info *mtd)
  128. {
  129. return gpio_get_value(GPIO_RDY);
  130. }
  131. static void rb532_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  132. {
  133. struct nand_chip *chip = mtd_to_nand(mtd);
  134. unsigned char orbits, nandbits;
  135. if (ctrl & NAND_CTRL_CHANGE) {
  136. orbits = (ctrl & NAND_CLE) << 1;
  137. orbits |= (ctrl & NAND_ALE) >> 1;
  138. nandbits = (~ctrl & NAND_CLE) << 1;
  139. nandbits |= (~ctrl & NAND_ALE) >> 1;
  140. set_latch_u5(orbits, nandbits);
  141. }
  142. if (cmd != NAND_CMD_NONE)
  143. writeb(cmd, chip->IO_ADDR_W);
  144. }
  145. static struct resource nand_slot0_res[] = {
  146. [0] = {
  147. .name = "nand_membase",
  148. .flags = IORESOURCE_MEM
  149. }
  150. };
  151. static struct platform_nand_data rb532_nand_data = {
  152. .ctrl.dev_ready = rb532_dev_ready,
  153. .ctrl.cmd_ctrl = rb532_cmd_ctrl,
  154. };
  155. static struct platform_device nand_slot0 = {
  156. .name = "gen_nand",
  157. .id = -1,
  158. .resource = nand_slot0_res,
  159. .num_resources = ARRAY_SIZE(nand_slot0_res),
  160. .dev.platform_data = &rb532_nand_data,
  161. };
  162. static struct mtd_partition rb532_partition_info[] = {
  163. {
  164. .name = "Routerboard NAND boot",
  165. .offset = 0,
  166. .size = 4 * 1024 * 1024,
  167. }, {
  168. .name = "rootfs",
  169. .offset = MTDPART_OFS_NXTBLK,
  170. .size = MTDPART_SIZ_FULL,
  171. }
  172. };
  173. static struct platform_device rb532_led = {
  174. .name = "rb532-led",
  175. .id = -1,
  176. };
  177. static struct platform_device rb532_button = {
  178. .name = "rb532-button",
  179. .id = -1,
  180. };
  181. static struct resource rb532_wdt_res[] = {
  182. {
  183. .name = "rb532_wdt_res",
  184. .start = INTEG0_BASE_ADDR,
  185. .end = INTEG0_BASE_ADDR + sizeof(struct integ),
  186. .flags = IORESOURCE_MEM,
  187. }
  188. };
  189. static struct platform_device rb532_wdt = {
  190. .name = "rc32434_wdt",
  191. .id = -1,
  192. .resource = rb532_wdt_res,
  193. .num_resources = ARRAY_SIZE(rb532_wdt_res),
  194. };
  195. static struct plat_serial8250_port rb532_uart_res[] = {
  196. {
  197. .type = PORT_16550A,
  198. .membase = (char *)KSEG1ADDR(REGBASE + UART0BASE),
  199. .irq = UART0_IRQ,
  200. .regshift = 2,
  201. .iotype = UPIO_MEM,
  202. .flags = UPF_BOOT_AUTOCONF,
  203. },
  204. {
  205. .flags = 0,
  206. }
  207. };
  208. static struct platform_device rb532_uart = {
  209. .name = "serial8250",
  210. .id = PLAT8250_DEV_PLATFORM,
  211. .dev.platform_data = &rb532_uart_res,
  212. };
  213. static struct platform_device *rb532_devs[] = {
  214. &korina_dev0,
  215. &nand_slot0,
  216. &cf_slot0,
  217. &rb532_led,
  218. &rb532_button,
  219. &rb532_uart,
  220. &rb532_wdt
  221. };
  222. /* NAND definitions */
  223. #define NAND_CHIP_DELAY 25
  224. static void __init rb532_nand_setup(void)
  225. {
  226. switch (mips_machtype) {
  227. case MACH_MIKROTIK_RB532A:
  228. set_latch_u5(LO_FOFF | LO_CEX,
  229. LO_ULED | LO_ALE | LO_CLE | LO_WPX);
  230. break;
  231. default:
  232. set_latch_u5(LO_WPX | LO_FOFF | LO_CEX,
  233. LO_ULED | LO_ALE | LO_CLE);
  234. break;
  235. }
  236. /* Setup NAND specific settings */
  237. rb532_nand_data.chip.nr_chips = 1;
  238. rb532_nand_data.chip.nr_partitions = ARRAY_SIZE(rb532_partition_info);
  239. rb532_nand_data.chip.partitions = rb532_partition_info;
  240. rb532_nand_data.chip.chip_delay = NAND_CHIP_DELAY;
  241. }
  242. static int __init plat_setup_devices(void)
  243. {
  244. /* Look for the CF card reader */
  245. if (!readl(IDT434_REG_BASE + DEV1MASK))
  246. rb532_devs[2] = NULL; /* disable cf_slot0 at index 2 */
  247. else {
  248. cf_slot0_res[0].start =
  249. readl(IDT434_REG_BASE + DEV1BASE);
  250. cf_slot0_res[0].end = cf_slot0_res[0].start + 0x1000;
  251. }
  252. /* Read the NAND resources from the device controller */
  253. nand_slot0_res[0].start = readl(IDT434_REG_BASE + DEV2BASE);
  254. nand_slot0_res[0].end = nand_slot0_res[0].start + 0x1000;
  255. /* Read and map device controller 3 */
  256. dev3.base = ioremap_nocache(readl(IDT434_REG_BASE + DEV3BASE), 1);
  257. if (!dev3.base) {
  258. printk(KERN_ERR "rb532: cannot remap device controller 3\n");
  259. return -ENXIO;
  260. }
  261. /* Initialise the NAND device */
  262. rb532_nand_setup();
  263. /* set the uart clock to the current cpu frequency */
  264. rb532_uart_res[0].uartclk = idt_cpu_freq;
  265. dev_set_drvdata(&korina_dev0.dev, &korina_dev0_data);
  266. return platform_add_devices(rb532_devs, ARRAY_SIZE(rb532_devs));
  267. }
  268. static int __init setup_kmac(char *s)
  269. {
  270. printk(KERN_INFO "korina mac = %s\n", s);
  271. if (!mac_pton(s, korina_dev0_data.mac)) {
  272. printk(KERN_ERR "Invalid mac\n");
  273. return -EINVAL;
  274. }
  275. return 0;
  276. }
  277. __setup("kmac=", setup_kmac);
  278. arch_initcall(plat_setup_devices);