devices.c 7.3 KB

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