devices.c 7.6 KB

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