dev.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. * linux/arch/arm/mach-w90x900/dev.c
  3. *
  4. * Copyright (C) 2009 Nuvoton corporation.
  5. *
  6. * Wan ZongShun <mcuos.com@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation;version 2 of the License.
  11. *
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/list.h>
  17. #include <linux/timer.h>
  18. #include <linux/init.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/mtd/physmap.h>
  21. #include <linux/mtd/mtd.h>
  22. #include <linux/mtd/partitions.h>
  23. #include <linux/spi/spi.h>
  24. #include <linux/spi/flash.h>
  25. #include <asm/mach/arch.h>
  26. #include <asm/mach/map.h>
  27. #include <asm/mach/irq.h>
  28. #include <asm/mach-types.h>
  29. #include <mach/regs-serial.h>
  30. #include <mach/nuc900_spi.h>
  31. #include <mach/map.h>
  32. #include <mach/fb.h>
  33. #include "cpu.h"
  34. /*NUC900 evb norflash driver data */
  35. #define NUC900_FLASH_BASE 0xA0000000
  36. #define NUC900_FLASH_SIZE 0x400000
  37. #define SPIOFFSET 0x200
  38. #define SPIOREG_SIZE 0x100
  39. static struct mtd_partition nuc900_flash_partitions[] = {
  40. {
  41. .name = "NOR Partition 1 for kernel (960K)",
  42. .size = 0xF0000,
  43. .offset = 0x10000,
  44. },
  45. {
  46. .name = "NOR Partition 2 for image (1M)",
  47. .size = 0x100000,
  48. .offset = 0x100000,
  49. },
  50. {
  51. .name = "NOR Partition 3 for user (2M)",
  52. .size = 0x200000,
  53. .offset = 0x00200000,
  54. }
  55. };
  56. static struct physmap_flash_data nuc900_flash_data = {
  57. .width = 2,
  58. .parts = nuc900_flash_partitions,
  59. .nr_parts = ARRAY_SIZE(nuc900_flash_partitions),
  60. };
  61. static struct resource nuc900_flash_resources[] = {
  62. {
  63. .start = NUC900_FLASH_BASE,
  64. .end = NUC900_FLASH_BASE + NUC900_FLASH_SIZE - 1,
  65. .flags = IORESOURCE_MEM,
  66. }
  67. };
  68. static struct platform_device nuc900_flash_device = {
  69. .name = "physmap-flash",
  70. .id = 0,
  71. .dev = {
  72. .platform_data = &nuc900_flash_data,
  73. },
  74. .resource = nuc900_flash_resources,
  75. .num_resources = ARRAY_SIZE(nuc900_flash_resources),
  76. };
  77. /* USB EHCI Host Controller */
  78. static struct resource nuc900_usb_ehci_resource[] = {
  79. [0] = {
  80. .start = W90X900_PA_USBEHCIHOST,
  81. .end = W90X900_PA_USBEHCIHOST + W90X900_SZ_USBEHCIHOST - 1,
  82. .flags = IORESOURCE_MEM,
  83. },
  84. [1] = {
  85. .start = IRQ_USBH,
  86. .end = IRQ_USBH,
  87. .flags = IORESOURCE_IRQ,
  88. }
  89. };
  90. static u64 nuc900_device_usb_ehci_dmamask = 0xffffffffUL;
  91. static struct platform_device nuc900_device_usb_ehci = {
  92. .name = "nuc900-ehci",
  93. .id = -1,
  94. .num_resources = ARRAY_SIZE(nuc900_usb_ehci_resource),
  95. .resource = nuc900_usb_ehci_resource,
  96. .dev = {
  97. .dma_mask = &nuc900_device_usb_ehci_dmamask,
  98. .coherent_dma_mask = 0xffffffffUL
  99. }
  100. };
  101. /* USB OHCI Host Controller */
  102. static struct resource nuc900_usb_ohci_resource[] = {
  103. [0] = {
  104. .start = W90X900_PA_USBOHCIHOST,
  105. .end = W90X900_PA_USBOHCIHOST + W90X900_SZ_USBOHCIHOST - 1,
  106. .flags = IORESOURCE_MEM,
  107. },
  108. [1] = {
  109. .start = IRQ_USBH,
  110. .end = IRQ_USBH,
  111. .flags = IORESOURCE_IRQ,
  112. }
  113. };
  114. static u64 nuc900_device_usb_ohci_dmamask = 0xffffffffUL;
  115. static struct platform_device nuc900_device_usb_ohci = {
  116. .name = "nuc900-ohci",
  117. .id = -1,
  118. .num_resources = ARRAY_SIZE(nuc900_usb_ohci_resource),
  119. .resource = nuc900_usb_ohci_resource,
  120. .dev = {
  121. .dma_mask = &nuc900_device_usb_ohci_dmamask,
  122. .coherent_dma_mask = 0xffffffffUL
  123. }
  124. };
  125. /* USB Device (Gadget)*/
  126. static struct resource nuc900_usbgadget_resource[] = {
  127. [0] = {
  128. .start = W90X900_PA_USBDEV,
  129. .end = W90X900_PA_USBDEV + W90X900_SZ_USBDEV - 1,
  130. .flags = IORESOURCE_MEM,
  131. },
  132. [1] = {
  133. .start = IRQ_USBD,
  134. .end = IRQ_USBD,
  135. .flags = IORESOURCE_IRQ,
  136. }
  137. };
  138. static struct platform_device nuc900_device_usbgadget = {
  139. .name = "nuc900-usbgadget",
  140. .id = -1,
  141. .num_resources = ARRAY_SIZE(nuc900_usbgadget_resource),
  142. .resource = nuc900_usbgadget_resource,
  143. };
  144. /* MAC device */
  145. static struct resource nuc900_emc_resource[] = {
  146. [0] = {
  147. .start = W90X900_PA_EMC,
  148. .end = W90X900_PA_EMC + W90X900_SZ_EMC - 1,
  149. .flags = IORESOURCE_MEM,
  150. },
  151. [1] = {
  152. .start = IRQ_EMCTX,
  153. .end = IRQ_EMCTX,
  154. .flags = IORESOURCE_IRQ,
  155. },
  156. [2] = {
  157. .start = IRQ_EMCRX,
  158. .end = IRQ_EMCRX,
  159. .flags = IORESOURCE_IRQ,
  160. }
  161. };
  162. static u64 nuc900_device_emc_dmamask = 0xffffffffUL;
  163. static struct platform_device nuc900_device_emc = {
  164. .name = "nuc900-emc",
  165. .id = -1,
  166. .num_resources = ARRAY_SIZE(nuc900_emc_resource),
  167. .resource = nuc900_emc_resource,
  168. .dev = {
  169. .dma_mask = &nuc900_device_emc_dmamask,
  170. .coherent_dma_mask = 0xffffffffUL
  171. }
  172. };
  173. /* SPI device */
  174. static struct nuc900_spi_info nuc900_spiflash_data = {
  175. .num_cs = 1,
  176. .lsb = 0,
  177. .txneg = 1,
  178. .rxneg = 0,
  179. .divider = 24,
  180. .sleep = 0,
  181. .txnum = 0,
  182. .txbitlen = 1,
  183. .bus_num = 0,
  184. };
  185. static struct resource nuc900_spi_resource[] = {
  186. [0] = {
  187. .start = W90X900_PA_I2C + SPIOFFSET,
  188. .end = W90X900_PA_I2C + SPIOFFSET + SPIOREG_SIZE - 1,
  189. .flags = IORESOURCE_MEM,
  190. },
  191. [1] = {
  192. .start = IRQ_SSP,
  193. .end = IRQ_SSP,
  194. .flags = IORESOURCE_IRQ,
  195. }
  196. };
  197. static struct platform_device nuc900_device_spi = {
  198. .name = "nuc900-spi",
  199. .id = -1,
  200. .num_resources = ARRAY_SIZE(nuc900_spi_resource),
  201. .resource = nuc900_spi_resource,
  202. .dev = {
  203. .platform_data = &nuc900_spiflash_data,
  204. }
  205. };
  206. /* spi device, spi flash info */
  207. static struct mtd_partition nuc900_spi_flash_partitions[] = {
  208. {
  209. .name = "bootloader(spi)",
  210. .size = 0x0100000,
  211. .offset = 0,
  212. },
  213. };
  214. static struct flash_platform_data nuc900_spi_flash_data = {
  215. .name = "m25p80",
  216. .parts = nuc900_spi_flash_partitions,
  217. .nr_parts = ARRAY_SIZE(nuc900_spi_flash_partitions),
  218. .type = "w25x16",
  219. };
  220. static struct spi_board_info nuc900_spi_board_info[] __initdata = {
  221. {
  222. .modalias = "m25p80",
  223. .max_speed_hz = 20000000,
  224. .bus_num = 0,
  225. .chip_select = 1,
  226. .platform_data = &nuc900_spi_flash_data,
  227. .mode = SPI_MODE_0,
  228. },
  229. };
  230. /* WDT Device */
  231. static struct resource nuc900_wdt_resource[] = {
  232. [0] = {
  233. .start = W90X900_PA_TIMER,
  234. .end = W90X900_PA_TIMER + W90X900_SZ_TIMER - 1,
  235. .flags = IORESOURCE_MEM,
  236. },
  237. [1] = {
  238. .start = IRQ_WDT,
  239. .end = IRQ_WDT,
  240. .flags = IORESOURCE_IRQ,
  241. }
  242. };
  243. static struct platform_device nuc900_device_wdt = {
  244. .name = "nuc900-wdt",
  245. .id = -1,
  246. .num_resources = ARRAY_SIZE(nuc900_wdt_resource),
  247. .resource = nuc900_wdt_resource,
  248. };
  249. /*
  250. * public device definition between 910 and 920, or 910
  251. * and 950 or 950 and 960...,their dev platform register
  252. * should be in specific file such as nuc950, nuc960 c
  253. * files rather than the public dev.c file here. so the
  254. * corresponding platform_device definition should not be
  255. * static.
  256. */
  257. /* RTC controller*/
  258. static struct resource nuc900_rtc_resource[] = {
  259. [0] = {
  260. .start = W90X900_PA_RTC,
  261. .end = W90X900_PA_RTC + 0xff,
  262. .flags = IORESOURCE_MEM,
  263. },
  264. [1] = {
  265. .start = IRQ_RTC,
  266. .end = IRQ_RTC,
  267. .flags = IORESOURCE_IRQ,
  268. },
  269. };
  270. struct platform_device nuc900_device_rtc = {
  271. .name = "nuc900-rtc",
  272. .id = -1,
  273. .num_resources = ARRAY_SIZE(nuc900_rtc_resource),
  274. .resource = nuc900_rtc_resource,
  275. };
  276. /*TouchScreen controller*/
  277. static struct resource nuc900_ts_resource[] = {
  278. [0] = {
  279. .start = W90X900_PA_ADC,
  280. .end = W90X900_PA_ADC + W90X900_SZ_ADC-1,
  281. .flags = IORESOURCE_MEM,
  282. },
  283. [1] = {
  284. .start = IRQ_ADC,
  285. .end = IRQ_ADC,
  286. .flags = IORESOURCE_IRQ,
  287. },
  288. };
  289. struct platform_device nuc900_device_ts = {
  290. .name = "nuc900-ts",
  291. .id = -1,
  292. .resource = nuc900_ts_resource,
  293. .num_resources = ARRAY_SIZE(nuc900_ts_resource),
  294. };
  295. /* FMI Device */
  296. static struct resource nuc900_fmi_resource[] = {
  297. [0] = {
  298. .start = W90X900_PA_FMI,
  299. .end = W90X900_PA_FMI + W90X900_SZ_FMI - 1,
  300. .flags = IORESOURCE_MEM,
  301. },
  302. [1] = {
  303. .start = IRQ_FMI,
  304. .end = IRQ_FMI,
  305. .flags = IORESOURCE_IRQ,
  306. }
  307. };
  308. struct platform_device nuc900_device_fmi = {
  309. .name = "nuc900-fmi",
  310. .id = -1,
  311. .num_resources = ARRAY_SIZE(nuc900_fmi_resource),
  312. .resource = nuc900_fmi_resource,
  313. };
  314. /* KPI controller*/
  315. static struct resource nuc900_kpi_resource[] = {
  316. [0] = {
  317. .start = W90X900_PA_KPI,
  318. .end = W90X900_PA_KPI + W90X900_SZ_KPI - 1,
  319. .flags = IORESOURCE_MEM,
  320. },
  321. [1] = {
  322. .start = IRQ_KPI,
  323. .end = IRQ_KPI,
  324. .flags = IORESOURCE_IRQ,
  325. }
  326. };
  327. struct platform_device nuc900_device_kpi = {
  328. .name = "nuc900-kpi",
  329. .id = -1,
  330. .num_resources = ARRAY_SIZE(nuc900_kpi_resource),
  331. .resource = nuc900_kpi_resource,
  332. };
  333. #ifdef CONFIG_FB_NUC900
  334. static struct resource nuc900_lcd_resource[] = {
  335. [0] = {
  336. .start = W90X900_PA_LCD,
  337. .end = W90X900_PA_LCD + W90X900_SZ_LCD - 1,
  338. .flags = IORESOURCE_MEM,
  339. },
  340. [1] = {
  341. .start = IRQ_LCD,
  342. .end = IRQ_LCD,
  343. .flags = IORESOURCE_IRQ,
  344. }
  345. };
  346. static u64 nuc900_device_lcd_dmamask = -1;
  347. struct platform_device nuc900_device_lcd = {
  348. .name = "nuc900-lcd",
  349. .id = -1,
  350. .num_resources = ARRAY_SIZE(nuc900_lcd_resource),
  351. .resource = nuc900_lcd_resource,
  352. .dev = {
  353. .dma_mask = &nuc900_device_lcd_dmamask,
  354. .coherent_dma_mask = -1,
  355. }
  356. };
  357. void nuc900_fb_set_platdata(struct nuc900fb_mach_info *pd)
  358. {
  359. struct nuc900fb_mach_info *npd;
  360. npd = kmalloc(sizeof(*npd), GFP_KERNEL);
  361. if (npd) {
  362. memcpy(npd, pd, sizeof(*npd));
  363. nuc900_device_lcd.dev.platform_data = npd;
  364. } else {
  365. printk(KERN_ERR "no memory for LCD platform data\n");
  366. }
  367. }
  368. #endif
  369. /*Here should be your evb resourse,such as LCD*/
  370. static struct platform_device *nuc900_public_dev[] __initdata = {
  371. &nuc900_serial_device,
  372. &nuc900_flash_device,
  373. &nuc900_device_usb_ehci,
  374. &nuc900_device_usb_ohci,
  375. &nuc900_device_usbgadget,
  376. &nuc900_device_emc,
  377. &nuc900_device_spi,
  378. &nuc900_device_wdt,
  379. };
  380. /* Provide adding specific CPU platform devices API */
  381. void __init nuc900_board_init(struct platform_device **device, int size)
  382. {
  383. platform_add_devices(device, size);
  384. platform_add_devices(nuc900_public_dev, ARRAY_SIZE(nuc900_public_dev));
  385. spi_register_board_info(nuc900_spi_board_info,
  386. ARRAY_SIZE(nuc900_spi_board_info));
  387. }