dev.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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 <mach/regs-ldm.h>
  35. #include <mach/w90p910_keypad.h>
  36. #include "cpu.h"
  37. /*NUC900 evb norflash driver data */
  38. #define NUC900_FLASH_BASE 0xA0000000
  39. #define NUC900_FLASH_SIZE 0x400000
  40. #define SPIOFFSET 0x200
  41. #define SPIOREG_SIZE 0x100
  42. static struct mtd_partition nuc900_flash_partitions[] = {
  43. {
  44. .name = "NOR Partition 1 for kernel (960K)",
  45. .size = 0xF0000,
  46. .offset = 0x10000,
  47. },
  48. {
  49. .name = "NOR Partition 2 for image (1M)",
  50. .size = 0x100000,
  51. .offset = 0x100000,
  52. },
  53. {
  54. .name = "NOR Partition 3 for user (2M)",
  55. .size = 0x200000,
  56. .offset = 0x00200000,
  57. }
  58. };
  59. static struct physmap_flash_data nuc900_flash_data = {
  60. .width = 2,
  61. .parts = nuc900_flash_partitions,
  62. .nr_parts = ARRAY_SIZE(nuc900_flash_partitions),
  63. };
  64. static struct resource nuc900_flash_resources[] = {
  65. {
  66. .start = NUC900_FLASH_BASE,
  67. .end = NUC900_FLASH_BASE + NUC900_FLASH_SIZE - 1,
  68. .flags = IORESOURCE_MEM,
  69. }
  70. };
  71. static struct platform_device nuc900_flash_device = {
  72. .name = "physmap-flash",
  73. .id = 0,
  74. .dev = {
  75. .platform_data = &nuc900_flash_data,
  76. },
  77. .resource = nuc900_flash_resources,
  78. .num_resources = ARRAY_SIZE(nuc900_flash_resources),
  79. };
  80. /* USB EHCI Host Controller */
  81. static struct resource nuc900_usb_ehci_resource[] = {
  82. [0] = {
  83. .start = W90X900_PA_USBEHCIHOST,
  84. .end = W90X900_PA_USBEHCIHOST + W90X900_SZ_USBEHCIHOST - 1,
  85. .flags = IORESOURCE_MEM,
  86. },
  87. [1] = {
  88. .start = IRQ_USBH,
  89. .end = IRQ_USBH,
  90. .flags = IORESOURCE_IRQ,
  91. }
  92. };
  93. static u64 nuc900_device_usb_ehci_dmamask = 0xffffffffUL;
  94. static struct platform_device nuc900_device_usb_ehci = {
  95. .name = "nuc900-ehci",
  96. .id = -1,
  97. .num_resources = ARRAY_SIZE(nuc900_usb_ehci_resource),
  98. .resource = nuc900_usb_ehci_resource,
  99. .dev = {
  100. .dma_mask = &nuc900_device_usb_ehci_dmamask,
  101. .coherent_dma_mask = 0xffffffffUL
  102. }
  103. };
  104. /* USB OHCI Host Controller */
  105. static struct resource nuc900_usb_ohci_resource[] = {
  106. [0] = {
  107. .start = W90X900_PA_USBOHCIHOST,
  108. .end = W90X900_PA_USBOHCIHOST + W90X900_SZ_USBOHCIHOST - 1,
  109. .flags = IORESOURCE_MEM,
  110. },
  111. [1] = {
  112. .start = IRQ_USBH,
  113. .end = IRQ_USBH,
  114. .flags = IORESOURCE_IRQ,
  115. }
  116. };
  117. static u64 nuc900_device_usb_ohci_dmamask = 0xffffffffUL;
  118. static struct platform_device nuc900_device_usb_ohci = {
  119. .name = "nuc900-ohci",
  120. .id = -1,
  121. .num_resources = ARRAY_SIZE(nuc900_usb_ohci_resource),
  122. .resource = nuc900_usb_ohci_resource,
  123. .dev = {
  124. .dma_mask = &nuc900_device_usb_ohci_dmamask,
  125. .coherent_dma_mask = 0xffffffffUL
  126. }
  127. };
  128. /* USB Device (Gadget)*/
  129. static struct resource nuc900_usbgadget_resource[] = {
  130. [0] = {
  131. .start = W90X900_PA_USBDEV,
  132. .end = W90X900_PA_USBDEV + W90X900_SZ_USBDEV - 1,
  133. .flags = IORESOURCE_MEM,
  134. },
  135. [1] = {
  136. .start = IRQ_USBD,
  137. .end = IRQ_USBD,
  138. .flags = IORESOURCE_IRQ,
  139. }
  140. };
  141. static struct platform_device nuc900_device_usbgadget = {
  142. .name = "nuc900-usbgadget",
  143. .id = -1,
  144. .num_resources = ARRAY_SIZE(nuc900_usbgadget_resource),
  145. .resource = nuc900_usbgadget_resource,
  146. };
  147. /* MAC device */
  148. static struct resource nuc900_emc_resource[] = {
  149. [0] = {
  150. .start = W90X900_PA_EMC,
  151. .end = W90X900_PA_EMC + W90X900_SZ_EMC - 1,
  152. .flags = IORESOURCE_MEM,
  153. },
  154. [1] = {
  155. .start = IRQ_EMCTX,
  156. .end = IRQ_EMCTX,
  157. .flags = IORESOURCE_IRQ,
  158. },
  159. [2] = {
  160. .start = IRQ_EMCRX,
  161. .end = IRQ_EMCRX,
  162. .flags = IORESOURCE_IRQ,
  163. }
  164. };
  165. static u64 nuc900_device_emc_dmamask = 0xffffffffUL;
  166. static struct platform_device nuc900_device_emc = {
  167. .name = "nuc900-emc",
  168. .id = -1,
  169. .num_resources = ARRAY_SIZE(nuc900_emc_resource),
  170. .resource = nuc900_emc_resource,
  171. .dev = {
  172. .dma_mask = &nuc900_device_emc_dmamask,
  173. .coherent_dma_mask = 0xffffffffUL
  174. }
  175. };
  176. /* SPI device */
  177. static struct nuc900_spi_info nuc900_spiflash_data = {
  178. .num_cs = 1,
  179. .lsb = 0,
  180. .txneg = 1,
  181. .rxneg = 0,
  182. .divider = 24,
  183. .sleep = 0,
  184. .txnum = 0,
  185. .txbitlen = 8,
  186. .bus_num = 0,
  187. };
  188. static struct resource nuc900_spi_resource[] = {
  189. [0] = {
  190. .start = W90X900_PA_I2C + SPIOFFSET,
  191. .end = W90X900_PA_I2C + SPIOFFSET + SPIOREG_SIZE - 1,
  192. .flags = IORESOURCE_MEM,
  193. },
  194. [1] = {
  195. .start = IRQ_SSP,
  196. .end = IRQ_SSP,
  197. .flags = IORESOURCE_IRQ,
  198. }
  199. };
  200. static struct platform_device nuc900_device_spi = {
  201. .name = "nuc900-spi",
  202. .id = -1,
  203. .num_resources = ARRAY_SIZE(nuc900_spi_resource),
  204. .resource = nuc900_spi_resource,
  205. .dev = {
  206. .platform_data = &nuc900_spiflash_data,
  207. }
  208. };
  209. /* spi device, spi flash info */
  210. static struct mtd_partition nuc900_spi_flash_partitions[] = {
  211. {
  212. .name = "bootloader(spi)",
  213. .size = 0x0100000,
  214. .offset = 0,
  215. },
  216. };
  217. static struct flash_platform_data nuc900_spi_flash_data = {
  218. .name = "m25p80",
  219. .parts = nuc900_spi_flash_partitions,
  220. .nr_parts = ARRAY_SIZE(nuc900_spi_flash_partitions),
  221. .type = "w25x16",
  222. };
  223. static struct spi_board_info nuc900_spi_board_info[] __initdata = {
  224. {
  225. .modalias = "m25p80",
  226. .max_speed_hz = 20000000,
  227. .bus_num = 0,
  228. .chip_select = 0,
  229. .platform_data = &nuc900_spi_flash_data,
  230. .mode = SPI_MODE_0,
  231. },
  232. };
  233. /* WDT Device */
  234. static struct resource nuc900_wdt_resource[] = {
  235. [0] = {
  236. .start = W90X900_PA_TIMER,
  237. .end = W90X900_PA_TIMER + W90X900_SZ_TIMER - 1,
  238. .flags = IORESOURCE_MEM,
  239. },
  240. [1] = {
  241. .start = IRQ_WDT,
  242. .end = IRQ_WDT,
  243. .flags = IORESOURCE_IRQ,
  244. }
  245. };
  246. static struct platform_device nuc900_device_wdt = {
  247. .name = "nuc900-wdt",
  248. .id = -1,
  249. .num_resources = ARRAY_SIZE(nuc900_wdt_resource),
  250. .resource = nuc900_wdt_resource,
  251. };
  252. /*
  253. * public device definition between 910 and 920, or 910
  254. * and 950 or 950 and 960...,their dev platform register
  255. * should be in specific file such as nuc950, nuc960 c
  256. * files rather than the public dev.c file here. so the
  257. * corresponding platform_device definition should not be
  258. * static.
  259. */
  260. /* RTC controller*/
  261. static struct resource nuc900_rtc_resource[] = {
  262. [0] = {
  263. .start = W90X900_PA_RTC,
  264. .end = W90X900_PA_RTC + 0xff,
  265. .flags = IORESOURCE_MEM,
  266. },
  267. [1] = {
  268. .start = IRQ_RTC,
  269. .end = IRQ_RTC,
  270. .flags = IORESOURCE_IRQ,
  271. },
  272. };
  273. struct platform_device nuc900_device_rtc = {
  274. .name = "nuc900-rtc",
  275. .id = -1,
  276. .num_resources = ARRAY_SIZE(nuc900_rtc_resource),
  277. .resource = nuc900_rtc_resource,
  278. };
  279. /*TouchScreen controller*/
  280. static struct resource nuc900_ts_resource[] = {
  281. [0] = {
  282. .start = W90X900_PA_ADC,
  283. .end = W90X900_PA_ADC + W90X900_SZ_ADC-1,
  284. .flags = IORESOURCE_MEM,
  285. },
  286. [1] = {
  287. .start = IRQ_ADC,
  288. .end = IRQ_ADC,
  289. .flags = IORESOURCE_IRQ,
  290. },
  291. };
  292. struct platform_device nuc900_device_ts = {
  293. .name = "nuc900-ts",
  294. .id = -1,
  295. .resource = nuc900_ts_resource,
  296. .num_resources = ARRAY_SIZE(nuc900_ts_resource),
  297. };
  298. /* FMI Device */
  299. static struct resource nuc900_fmi_resource[] = {
  300. [0] = {
  301. .start = W90X900_PA_FMI,
  302. .end = W90X900_PA_FMI + W90X900_SZ_FMI - 1,
  303. .flags = IORESOURCE_MEM,
  304. },
  305. [1] = {
  306. .start = IRQ_FMI,
  307. .end = IRQ_FMI,
  308. .flags = IORESOURCE_IRQ,
  309. }
  310. };
  311. struct platform_device nuc900_device_fmi = {
  312. .name = "nuc900-fmi",
  313. .id = -1,
  314. .num_resources = ARRAY_SIZE(nuc900_fmi_resource),
  315. .resource = nuc900_fmi_resource,
  316. };
  317. /* KPI controller*/
  318. static int nuc900_keymap[] = {
  319. KEY(0, 0, KEY_A),
  320. KEY(0, 1, KEY_B),
  321. KEY(0, 2, KEY_C),
  322. KEY(0, 3, KEY_D),
  323. KEY(1, 0, KEY_E),
  324. KEY(1, 1, KEY_F),
  325. KEY(1, 2, KEY_G),
  326. KEY(1, 3, KEY_H),
  327. KEY(2, 0, KEY_I),
  328. KEY(2, 1, KEY_J),
  329. KEY(2, 2, KEY_K),
  330. KEY(2, 3, KEY_L),
  331. KEY(3, 0, KEY_M),
  332. KEY(3, 1, KEY_N),
  333. KEY(3, 2, KEY_O),
  334. KEY(3, 3, KEY_P),
  335. };
  336. static struct matrix_keymap_data nuc900_map_data = {
  337. .keymap = nuc900_keymap,
  338. .keymap_size = ARRAY_SIZE(nuc900_keymap),
  339. };
  340. struct w90p910_keypad_platform_data nuc900_keypad_info = {
  341. .keymap_data = &nuc900_map_data,
  342. .prescale = 0xfa,
  343. .debounce = 0x50,
  344. };
  345. static struct resource nuc900_kpi_resource[] = {
  346. [0] = {
  347. .start = W90X900_PA_KPI,
  348. .end = W90X900_PA_KPI + W90X900_SZ_KPI - 1,
  349. .flags = IORESOURCE_MEM,
  350. },
  351. [1] = {
  352. .start = IRQ_KPI,
  353. .end = IRQ_KPI,
  354. .flags = IORESOURCE_IRQ,
  355. }
  356. };
  357. struct platform_device nuc900_device_kpi = {
  358. .name = "nuc900-kpi",
  359. .id = -1,
  360. .num_resources = ARRAY_SIZE(nuc900_kpi_resource),
  361. .resource = nuc900_kpi_resource,
  362. .dev = {
  363. .platform_data = &nuc900_keypad_info,
  364. }
  365. };
  366. /* LCD controller*/
  367. static struct nuc900fb_display __initdata nuc900_lcd_info[] = {
  368. /* Giantplus Technology GPM1040A0 320x240 Color TFT LCD */
  369. [0] = {
  370. .type = LCM_DCCS_VA_SRC_RGB565,
  371. .width = 320,
  372. .height = 240,
  373. .xres = 320,
  374. .yres = 240,
  375. .bpp = 16,
  376. .pixclock = 200000,
  377. .left_margin = 34,
  378. .right_margin = 54,
  379. .hsync_len = 10,
  380. .upper_margin = 18,
  381. .lower_margin = 4,
  382. .vsync_len = 1,
  383. .dccs = 0x8e00041a,
  384. .devctl = 0x060800c0,
  385. .fbctrl = 0x00a000a0,
  386. .scale = 0x04000400,
  387. },
  388. };
  389. static struct nuc900fb_mach_info nuc900_fb_info __initdata = {
  390. #if defined(CONFIG_GPM1040A0_320X240)
  391. .displays = &nuc900_lcd_info[0],
  392. #else
  393. .displays = nuc900_lcd_info,
  394. #endif
  395. .num_displays = ARRAY_SIZE(nuc900_lcd_info),
  396. .default_display = 0,
  397. .gpio_dir = 0x00000004,
  398. .gpio_dir_mask = 0xFFFFFFFD,
  399. .gpio_data = 0x00000004,
  400. .gpio_data_mask = 0xFFFFFFFD,
  401. };
  402. static struct resource nuc900_lcd_resource[] = {
  403. [0] = {
  404. .start = W90X900_PA_LCD,
  405. .end = W90X900_PA_LCD + W90X900_SZ_LCD - 1,
  406. .flags = IORESOURCE_MEM,
  407. },
  408. [1] = {
  409. .start = IRQ_LCD,
  410. .end = IRQ_LCD,
  411. .flags = IORESOURCE_IRQ,
  412. }
  413. };
  414. static u64 nuc900_device_lcd_dmamask = -1;
  415. struct platform_device nuc900_device_lcd = {
  416. .name = "nuc900-lcd",
  417. .id = -1,
  418. .num_resources = ARRAY_SIZE(nuc900_lcd_resource),
  419. .resource = nuc900_lcd_resource,
  420. .dev = {
  421. .dma_mask = &nuc900_device_lcd_dmamask,
  422. .coherent_dma_mask = -1,
  423. .platform_data = &nuc900_fb_info,
  424. }
  425. };
  426. /* AUDIO controller*/
  427. static u64 nuc900_device_audio_dmamask = -1;
  428. static struct resource nuc900_ac97_resource[] = {
  429. [0] = {
  430. .start = W90X900_PA_ACTL,
  431. .end = W90X900_PA_ACTL + W90X900_SZ_ACTL - 1,
  432. .flags = IORESOURCE_MEM,
  433. },
  434. [1] = {
  435. .start = IRQ_ACTL,
  436. .end = IRQ_ACTL,
  437. .flags = IORESOURCE_IRQ,
  438. }
  439. };
  440. struct platform_device nuc900_device_audio = {
  441. .name = "nuc900-audio",
  442. .id = -1,
  443. .num_resources = ARRAY_SIZE(nuc900_ac97_resource),
  444. .resource = nuc900_ac97_resource,
  445. .dev = {
  446. .dma_mask = &nuc900_device_audio_dmamask,
  447. .coherent_dma_mask = -1,
  448. }
  449. };
  450. /*Here should be your evb resourse,such as LCD*/
  451. static struct platform_device *nuc900_public_dev[] __initdata = {
  452. &nuc900_serial_device,
  453. &nuc900_flash_device,
  454. &nuc900_device_usb_ehci,
  455. &nuc900_device_usb_ohci,
  456. &nuc900_device_usbgadget,
  457. &nuc900_device_emc,
  458. &nuc900_device_spi,
  459. &nuc900_device_wdt,
  460. &nuc900_device_audio,
  461. };
  462. /* Provide adding specific CPU platform devices API */
  463. void __init nuc900_board_init(struct platform_device **device, int size)
  464. {
  465. platform_add_devices(device, size);
  466. platform_add_devices(nuc900_public_dev, ARRAY_SIZE(nuc900_public_dev));
  467. spi_register_board_info(nuc900_spi_board_info,
  468. ARRAY_SIZE(nuc900_spi_board_info));
  469. }