dev.c 9.7 KB

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