devices.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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/init.h>
  19. #include <linux/ctype.h>
  20. #include <linux/string.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/mtd/nand.h>
  23. #include <linux/mtd/mtd.h>
  24. #include <linux/mtd/partitions.h>
  25. #include <linux/gpio_keys.h>
  26. #include <linux/input.h>
  27. #include <linux/serial_8250.h>
  28. #include <asm/bootinfo.h>
  29. #include <asm/mach-rc32434/rc32434.h>
  30. #include <asm/mach-rc32434/dma.h>
  31. #include <asm/mach-rc32434/dma_v.h>
  32. #include <asm/mach-rc32434/eth.h>
  33. #include <asm/mach-rc32434/rb.h>
  34. #include <asm/mach-rc32434/integ.h>
  35. #include <asm/mach-rc32434/gpio.h>
  36. #include <asm/mach-rc32434/irq.h>
  37. #define ETH0_RX_DMA_ADDR (DMA0_BASE_ADDR + 0 * DMA_CHAN_OFFSET)
  38. #define ETH0_TX_DMA_ADDR (DMA0_BASE_ADDR + 1 * DMA_CHAN_OFFSET)
  39. extern unsigned int idt_cpu_freq;
  40. static struct mpmc_device dev3;
  41. void set_latch_u5(unsigned char or_mask, unsigned char nand_mask)
  42. {
  43. unsigned long flags;
  44. spin_lock_irqsave(&dev3.lock, flags);
  45. dev3.state = (dev3.state | or_mask) & ~nand_mask;
  46. writeb(dev3.state, dev3.base);
  47. spin_unlock_irqrestore(&dev3.lock, flags);
  48. }
  49. EXPORT_SYMBOL(set_latch_u5);
  50. unsigned char get_latch_u5(void)
  51. {
  52. return dev3.state;
  53. }
  54. EXPORT_SYMBOL(get_latch_u5);
  55. static struct resource rb532_dev3_ctl_res[] = {
  56. {
  57. .name = "dev3_ctl",
  58. .flags = IORESOURCE_MEM,
  59. }
  60. };
  61. static struct resource korina_dev0_res[] = {
  62. {
  63. .name = "korina_regs",
  64. .start = ETH0_BASE_ADDR,
  65. .end = ETH0_BASE_ADDR + sizeof(struct eth_regs),
  66. .flags = IORESOURCE_MEM,
  67. }, {
  68. .name = "korina_rx",
  69. .start = ETH0_DMA_RX_IRQ,
  70. .end = ETH0_DMA_RX_IRQ,
  71. .flags = IORESOURCE_IRQ
  72. }, {
  73. .name = "korina_tx",
  74. .start = ETH0_DMA_TX_IRQ,
  75. .end = ETH0_DMA_TX_IRQ,
  76. .flags = IORESOURCE_IRQ
  77. }, {
  78. .name = "korina_ovr",
  79. .start = ETH0_RX_OVR_IRQ,
  80. .end = ETH0_RX_OVR_IRQ,
  81. .flags = IORESOURCE_IRQ
  82. }, {
  83. .name = "korina_und",
  84. .start = ETH0_TX_UND_IRQ,
  85. .end = ETH0_TX_UND_IRQ,
  86. .flags = IORESOURCE_IRQ
  87. }, {
  88. .name = "korina_dma_rx",
  89. .start = ETH0_RX_DMA_ADDR,
  90. .end = ETH0_RX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
  91. .flags = IORESOURCE_MEM,
  92. }, {
  93. .name = "korina_dma_tx",
  94. .start = ETH0_TX_DMA_ADDR,
  95. .end = ETH0_TX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
  96. .flags = IORESOURCE_MEM,
  97. }
  98. };
  99. static struct korina_device korina_dev0_data = {
  100. .name = "korina0",
  101. .mac = {0xde, 0xca, 0xff, 0xc0, 0xff, 0xee}
  102. };
  103. static struct platform_device korina_dev0 = {
  104. .id = -1,
  105. .name = "korina",
  106. .dev.driver_data = &korina_dev0_data,
  107. .resource = korina_dev0_res,
  108. .num_resources = ARRAY_SIZE(korina_dev0_res),
  109. };
  110. static struct resource cf_slot0_res[] = {
  111. {
  112. .name = "cf_membase",
  113. .flags = IORESOURCE_MEM
  114. }, {
  115. .name = "cf_irq",
  116. .start = (8 + 4 * 32 + CF_GPIO_NUM), /* 149 */
  117. .end = (8 + 4 * 32 + CF_GPIO_NUM),
  118. .flags = IORESOURCE_IRQ
  119. }
  120. };
  121. static struct cf_device cf_slot0_data = {
  122. .gpio_pin = CF_GPIO_NUM
  123. };
  124. static struct platform_device cf_slot0 = {
  125. .id = -1,
  126. .name = "pata-rb532-cf",
  127. .dev.platform_data = &cf_slot0_data,
  128. .resource = cf_slot0_res,
  129. .num_resources = ARRAY_SIZE(cf_slot0_res),
  130. };
  131. /* Resources and device for NAND */
  132. static int rb532_dev_ready(struct mtd_info *mtd)
  133. {
  134. return gpio_get_value(GPIO_RDY);
  135. }
  136. static void rb532_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  137. {
  138. struct nand_chip *chip = mtd->priv;
  139. unsigned char orbits, nandbits;
  140. if (ctrl & NAND_CTRL_CHANGE) {
  141. orbits = (ctrl & NAND_CLE) << 1;
  142. orbits |= (ctrl & NAND_ALE) >> 1;
  143. nandbits = (~ctrl & NAND_CLE) << 1;
  144. nandbits |= (~ctrl & NAND_ALE) >> 1;
  145. set_latch_u5(orbits, nandbits);
  146. }
  147. if (cmd != NAND_CMD_NONE)
  148. writeb(cmd, chip->IO_ADDR_W);
  149. }
  150. static struct resource nand_slot0_res[] = {
  151. [0] = {
  152. .name = "nand_membase",
  153. .flags = IORESOURCE_MEM
  154. }
  155. };
  156. static struct platform_nand_data rb532_nand_data = {
  157. .ctrl.dev_ready = rb532_dev_ready,
  158. .ctrl.cmd_ctrl = rb532_cmd_ctrl,
  159. };
  160. static struct platform_device nand_slot0 = {
  161. .name = "gen_nand",
  162. .id = -1,
  163. .resource = nand_slot0_res,
  164. .num_resources = ARRAY_SIZE(nand_slot0_res),
  165. .dev.platform_data = &rb532_nand_data,
  166. };
  167. static struct mtd_partition rb532_partition_info[] = {
  168. {
  169. .name = "Routerboard NAND boot",
  170. .offset = 0,
  171. .size = 4 * 1024 * 1024,
  172. }, {
  173. .name = "rootfs",
  174. .offset = MTDPART_OFS_NXTBLK,
  175. .size = MTDPART_SIZ_FULL,
  176. }
  177. };
  178. static struct platform_device rb532_led = {
  179. .name = "rb532-led",
  180. .id = -1,
  181. };
  182. static struct gpio_keys_button rb532_gpio_btn[] = {
  183. {
  184. .gpio = 1,
  185. .code = BTN_0,
  186. .desc = "S1",
  187. .active_low = 1,
  188. }
  189. };
  190. static struct gpio_keys_platform_data rb532_gpio_btn_data = {
  191. .buttons = rb532_gpio_btn,
  192. .nbuttons = ARRAY_SIZE(rb532_gpio_btn),
  193. };
  194. static struct platform_device rb532_button = {
  195. .name = "gpio-keys",
  196. .id = -1,
  197. .dev = {
  198. .platform_data = &rb532_gpio_btn_data,
  199. }
  200. };
  201. static struct resource rb532_wdt_res[] = {
  202. {
  203. .name = "rb532_wdt_res",
  204. .start = INTEG0_BASE_ADDR,
  205. .end = INTEG0_BASE_ADDR + sizeof(struct integ),
  206. .flags = IORESOURCE_MEM,
  207. }
  208. };
  209. static struct platform_device rb532_wdt = {
  210. .name = "rc32434_wdt",
  211. .id = -1,
  212. .resource = rb532_wdt_res,
  213. .num_resources = ARRAY_SIZE(rb532_wdt_res),
  214. };
  215. static struct plat_serial8250_port rb532_uart_res[] = {
  216. {
  217. .membase = (char *)KSEG1ADDR(REGBASE + UART0BASE),
  218. .irq = UART0_IRQ,
  219. .regshift = 2,
  220. .iotype = UPIO_MEM,
  221. .flags = UPF_BOOT_AUTOCONF,
  222. },
  223. {
  224. .flags = 0,
  225. }
  226. };
  227. static struct platform_device rb532_uart = {
  228. .name = "serial8250",
  229. .id = PLAT8250_DEV_PLATFORM,
  230. .dev.platform_data = &rb532_uart_res,
  231. };
  232. static struct platform_device *rb532_devs[] = {
  233. &korina_dev0,
  234. &nand_slot0,
  235. &cf_slot0,
  236. &rb532_led,
  237. &rb532_button,
  238. &rb532_uart,
  239. &rb532_wdt
  240. };
  241. static void __init parse_mac_addr(char *macstr)
  242. {
  243. int i, j;
  244. unsigned char result, value;
  245. for (i = 0; i < 6; i++) {
  246. result = 0;
  247. if (i != 5 && *(macstr + 2) != ':')
  248. return;
  249. for (j = 0; j < 2; j++) {
  250. if (isxdigit(*macstr)
  251. && (value =
  252. isdigit(*macstr) ? *macstr -
  253. '0' : toupper(*macstr) - 'A' + 10) < 16) {
  254. result = result * 16 + value;
  255. macstr++;
  256. } else
  257. return;
  258. }
  259. macstr++;
  260. korina_dev0_data.mac[i] = result;
  261. }
  262. }
  263. /* NAND definitions */
  264. #define NAND_CHIP_DELAY 25
  265. static void __init rb532_nand_setup(void)
  266. {
  267. switch (mips_machtype) {
  268. case MACH_MIKROTIK_RB532A:
  269. set_latch_u5(LO_FOFF | LO_CEX,
  270. LO_ULED | LO_ALE | LO_CLE | LO_WPX);
  271. break;
  272. default:
  273. set_latch_u5(LO_WPX | LO_FOFF | LO_CEX,
  274. LO_ULED | LO_ALE | LO_CLE);
  275. break;
  276. }
  277. /* Setup NAND specific settings */
  278. rb532_nand_data.chip.nr_chips = 1;
  279. rb532_nand_data.chip.nr_partitions = ARRAY_SIZE(rb532_partition_info);
  280. rb532_nand_data.chip.partitions = rb532_partition_info;
  281. rb532_nand_data.chip.chip_delay = NAND_CHIP_DELAY;
  282. rb532_nand_data.chip.options = NAND_NO_AUTOINCR;
  283. }
  284. static int __init plat_setup_devices(void)
  285. {
  286. /* Look for the CF card reader */
  287. if (!readl(IDT434_REG_BASE + DEV1MASK))
  288. rb532_devs[2] = NULL; /* disable cf_slot0 at index 2 */
  289. else {
  290. cf_slot0_res[0].start =
  291. readl(IDT434_REG_BASE + DEV1BASE);
  292. cf_slot0_res[0].end = cf_slot0_res[0].start + 0x1000;
  293. }
  294. /* Read the NAND resources from the device controller */
  295. nand_slot0_res[0].start = readl(IDT434_REG_BASE + DEV2BASE);
  296. nand_slot0_res[0].end = nand_slot0_res[0].start + 0x1000;
  297. /* Read the third (multi purpose) resources from the DC */
  298. rb532_dev3_ctl_res[0].start = readl(IDT434_REG_BASE + DEV3BASE);
  299. rb532_dev3_ctl_res[0].end = rb532_dev3_ctl_res[0].start + 0x1000;
  300. dev3.base = ioremap_nocache(rb532_dev3_ctl_res[0].start, 0x1000);
  301. if (!dev3.base) {
  302. printk(KERN_ERR "rb532: cannot remap device controller 3\n");
  303. return -ENXIO;
  304. }
  305. /* Initialise the NAND device */
  306. rb532_nand_setup();
  307. /* set the uart clock to the current cpu frequency */
  308. rb532_uart_res[0].uartclk = idt_cpu_freq;
  309. return platform_add_devices(rb532_devs, ARRAY_SIZE(rb532_devs));
  310. }
  311. static int __init setup_kmac(char *s)
  312. {
  313. printk(KERN_INFO "korina mac = %s\n", s);
  314. parse_mac_addr(s);
  315. return 0;
  316. }
  317. __setup("kmac=", setup_kmac);
  318. arch_initcall(plat_setup_devices);