devices.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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 <asm/bootinfo.h>
  28. #include <asm/mach-rc32434/rc32434.h>
  29. #include <asm/mach-rc32434/dma.h>
  30. #include <asm/mach-rc32434/dma_v.h>
  31. #include <asm/mach-rc32434/eth.h>
  32. #include <asm/mach-rc32434/rb.h>
  33. #include <asm/mach-rc32434/integ.h>
  34. #include <asm/mach-rc32434/gpio.h>
  35. #include <asm/mach-rc32434/irq.h>
  36. #define ETH0_RX_DMA_ADDR (DMA0_BASE_ADDR + 0 * DMA_CHAN_OFFSET)
  37. #define ETH0_TX_DMA_ADDR (DMA0_BASE_ADDR + 1 * DMA_CHAN_OFFSET)
  38. static struct resource korina_dev0_res[] = {
  39. {
  40. .name = "korina_regs",
  41. .start = ETH0_BASE_ADDR,
  42. .end = ETH0_BASE_ADDR + sizeof(struct eth_regs),
  43. .flags = IORESOURCE_MEM,
  44. }, {
  45. .name = "korina_rx",
  46. .start = ETH0_DMA_RX_IRQ,
  47. .end = ETH0_DMA_RX_IRQ,
  48. .flags = IORESOURCE_IRQ
  49. }, {
  50. .name = "korina_tx",
  51. .start = ETH0_DMA_TX_IRQ,
  52. .end = ETH0_DMA_TX_IRQ,
  53. .flags = IORESOURCE_IRQ
  54. }, {
  55. .name = "korina_ovr",
  56. .start = ETH0_RX_OVR_IRQ,
  57. .end = ETH0_RX_OVR_IRQ,
  58. .flags = IORESOURCE_IRQ
  59. }, {
  60. .name = "korina_und",
  61. .start = ETH0_TX_UND_IRQ,
  62. .end = ETH0_TX_UND_IRQ,
  63. .flags = IORESOURCE_IRQ
  64. }, {
  65. .name = "korina_dma_rx",
  66. .start = ETH0_RX_DMA_ADDR,
  67. .end = ETH0_RX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
  68. .flags = IORESOURCE_MEM,
  69. }, {
  70. .name = "korina_dma_tx",
  71. .start = ETH0_TX_DMA_ADDR,
  72. .end = ETH0_TX_DMA_ADDR + DMA_CHAN_OFFSET - 1,
  73. .flags = IORESOURCE_MEM,
  74. }
  75. };
  76. static struct korina_device korina_dev0_data = {
  77. .name = "korina0",
  78. .mac = {0xde, 0xca, 0xff, 0xc0, 0xff, 0xee}
  79. };
  80. static struct platform_device korina_dev0 = {
  81. .id = -1,
  82. .name = "korina",
  83. .dev.platform_data = &korina_dev0_data,
  84. .resource = korina_dev0_res,
  85. .num_resources = ARRAY_SIZE(korina_dev0_res),
  86. };
  87. static struct resource cf_slot0_res[] = {
  88. {
  89. .name = "cf_membase",
  90. .flags = IORESOURCE_MEM
  91. }, {
  92. .name = "cf_irq",
  93. .start = (8 + 4 * 32 + CF_GPIO_NUM), /* 149 */
  94. .end = (8 + 4 * 32 + CF_GPIO_NUM),
  95. .flags = IORESOURCE_IRQ
  96. }
  97. };
  98. static struct cf_device cf_slot0_data = {
  99. .gpio_pin = CF_GPIO_NUM
  100. };
  101. static struct platform_device cf_slot0 = {
  102. .id = -1,
  103. .name = "pata-rb532-cf",
  104. .dev.platform_data = &cf_slot0_data,
  105. .resource = cf_slot0_res,
  106. .num_resources = ARRAY_SIZE(cf_slot0_res),
  107. };
  108. /* Resources and device for NAND */
  109. static int rb532_dev_ready(struct mtd_info *mtd)
  110. {
  111. return readl(IDT434_REG_BASE + GPIOD) & GPIO_RDY;
  112. }
  113. static void rb532_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  114. {
  115. struct nand_chip *chip = mtd->priv;
  116. unsigned char orbits, nandbits;
  117. if (ctrl & NAND_CTRL_CHANGE) {
  118. orbits = (ctrl & NAND_CLE) << 1;
  119. orbits |= (ctrl & NAND_ALE) >> 1;
  120. nandbits = (~ctrl & NAND_CLE) << 1;
  121. nandbits |= (~ctrl & NAND_ALE) >> 1;
  122. set_latch_u5(orbits, nandbits);
  123. }
  124. if (cmd != NAND_CMD_NONE)
  125. writeb(cmd, chip->IO_ADDR_W);
  126. }
  127. static struct resource nand_slot0_res[] = {
  128. [0] = {
  129. .name = "nand_membase",
  130. .flags = IORESOURCE_MEM
  131. }
  132. };
  133. static struct platform_nand_data rb532_nand_data = {
  134. .ctrl.dev_ready = rb532_dev_ready,
  135. .ctrl.cmd_ctrl = rb532_cmd_ctrl,
  136. };
  137. static struct platform_device nand_slot0 = {
  138. .name = "gen_nand",
  139. .id = -1,
  140. .resource = nand_slot0_res,
  141. .num_resources = ARRAY_SIZE(nand_slot0_res),
  142. .dev.platform_data = &rb532_nand_data,
  143. };
  144. static struct mtd_partition rb532_partition_info[] = {
  145. {
  146. .name = "Routerboard NAND boot",
  147. .offset = 0,
  148. .size = 4 * 1024 * 1024,
  149. }, {
  150. .name = "rootfs",
  151. .offset = MTDPART_OFS_NXTBLK,
  152. .size = MTDPART_SIZ_FULL,
  153. }
  154. };
  155. static struct platform_device rb532_led = {
  156. .name = "rb532-led",
  157. .id = -1,
  158. };
  159. static struct gpio_keys_button rb532_gpio_btn[] = {
  160. {
  161. .gpio = 1,
  162. .code = BTN_0,
  163. .desc = "S1",
  164. .active_low = 1,
  165. }
  166. };
  167. static struct gpio_keys_platform_data rb532_gpio_btn_data = {
  168. .buttons = rb532_gpio_btn,
  169. .nbuttons = ARRAY_SIZE(rb532_gpio_btn),
  170. };
  171. static struct platform_device rb532_button = {
  172. .name = "gpio-keys",
  173. .id = -1,
  174. .dev = {
  175. .platform_data = &rb532_gpio_btn_data,
  176. }
  177. };
  178. static struct resource rb532_wdt_res[] = {
  179. {
  180. .name = "rb532_wdt_res",
  181. .start = INTEG0_BASE_ADDR,
  182. .end = INTEG0_BASE_ADDR + sizeof(struct integ),
  183. .flags = IORESOURCE_MEM,
  184. }
  185. };
  186. static struct platform_device rb532_wdt = {
  187. .name = "rc32434_wdt",
  188. .id = -1,
  189. .resource = rb532_wdt_res,
  190. .num_resources = ARRAY_SIZE(rb532_wdt_res),
  191. };
  192. static struct platform_device *rb532_devs[] = {
  193. &korina_dev0,
  194. &nand_slot0,
  195. &cf_slot0,
  196. &rb532_led,
  197. &rb532_button,
  198. &rb532_wdt
  199. };
  200. static void __init parse_mac_addr(char *macstr)
  201. {
  202. int i, j;
  203. unsigned char result, value;
  204. for (i = 0; i < 6; i++) {
  205. result = 0;
  206. if (i != 5 && *(macstr + 2) != ':')
  207. return;
  208. for (j = 0; j < 2; j++) {
  209. if (isxdigit(*macstr)
  210. && (value =
  211. isdigit(*macstr) ? *macstr -
  212. '0' : toupper(*macstr) - 'A' + 10) < 16) {
  213. result = result * 16 + value;
  214. macstr++;
  215. } else
  216. return;
  217. }
  218. macstr++;
  219. korina_dev0_data.mac[i] = result;
  220. }
  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. rb532_nand_data.chip.options = NAND_NO_AUTOINCR;
  242. }
  243. static int __init plat_setup_devices(void)
  244. {
  245. /* Look for the CF card reader */
  246. if (!readl(IDT434_REG_BASE + DEV1MASK))
  247. rb532_devs[1] = NULL;
  248. else {
  249. cf_slot0_res[0].start =
  250. readl(IDT434_REG_BASE + DEV1BASE);
  251. cf_slot0_res[0].end = cf_slot0_res[0].start + 0x1000;
  252. }
  253. /* Read the NAND resources from the device controller */
  254. nand_slot0_res[0].start = readl(IDT434_REG_BASE + DEV2BASE);
  255. nand_slot0_res[0].end = nand_slot0_res[0].start + 0x1000;
  256. /* Initialise the NAND device */
  257. rb532_nand_setup();
  258. return platform_add_devices(rb532_devs, ARRAY_SIZE(rb532_devs));
  259. }
  260. static int __init setup_kmac(char *s)
  261. {
  262. printk(KERN_INFO "korina mac = %s\n", s);
  263. parse_mac_addr(s);
  264. return 0;
  265. }
  266. __setup("kmac=", setup_kmac);
  267. arch_initcall(plat_setup_devices);