dev.c 12 KB

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