devices.c 7.6 KB

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