dev.c 12 KB

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