em-x270.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * Support for CompuLab EM-x270 platform
  3. *
  4. * Copyright (C) 2007 CompuLab, Ltd.
  5. * Author: Mike Rapoport <mike@compulab.co.il>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/irq.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/dm9000.h>
  14. #include <linux/rtc-v3020.h>
  15. #include <linux/mtd/nand.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <asm/mach-types.h>
  18. #include <asm/mach/arch.h>
  19. #include <asm/arch/pxa-regs.h>
  20. #include <asm/arch/pxa2xx-gpio.h>
  21. #include <asm/arch/pxa27x-udc.h>
  22. #include <asm/arch/audio.h>
  23. #include <asm/arch/pxafb.h>
  24. #include <asm/arch/ohci.h>
  25. #include <asm/arch/mmc.h>
  26. #include <asm/arch/bitfield.h>
  27. #include "generic.h"
  28. /* GPIO IRQ usage */
  29. #define EM_X270_MMC_PD (105)
  30. #define EM_X270_ETHIRQ IRQ_GPIO(41)
  31. #define EM_X270_MMC_IRQ IRQ_GPIO(13)
  32. static struct resource em_x270_dm9k_resource[] = {
  33. [0] = {
  34. .start = PXA_CS2_PHYS,
  35. .end = PXA_CS2_PHYS + 3,
  36. .flags = IORESOURCE_MEM,
  37. },
  38. [1] = {
  39. .start = PXA_CS2_PHYS + 8,
  40. .end = PXA_CS2_PHYS + 8 + 0x3f,
  41. .flags = IORESOURCE_MEM,
  42. },
  43. [2] = {
  44. .start = EM_X270_ETHIRQ,
  45. .end = EM_X270_ETHIRQ,
  46. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  47. }
  48. };
  49. /* for the moment we limit ourselves to 32bit IO until some
  50. * better IO routines can be written and tested
  51. */
  52. static struct dm9000_plat_data em_x270_dm9k_platdata = {
  53. .flags = DM9000_PLATF_32BITONLY,
  54. };
  55. /* Ethernet device */
  56. static struct platform_device em_x270_dm9k = {
  57. .name = "dm9000",
  58. .id = 0,
  59. .num_resources = ARRAY_SIZE(em_x270_dm9k_resource),
  60. .resource = em_x270_dm9k_resource,
  61. .dev = {
  62. .platform_data = &em_x270_dm9k_platdata,
  63. }
  64. };
  65. /* WM9712 touchscreen controller. Hopefully the driver will make it to
  66. * the mainstream sometime */
  67. static struct platform_device em_x270_ts = {
  68. .name = "wm97xx-ts",
  69. .id = -1,
  70. };
  71. /* RTC */
  72. static struct resource em_x270_v3020_resource[] = {
  73. [0] = {
  74. .start = PXA_CS4_PHYS,
  75. .end = PXA_CS4_PHYS + 3,
  76. .flags = IORESOURCE_MEM,
  77. },
  78. };
  79. static struct v3020_platform_data em_x270_v3020_platdata = {
  80. .leftshift = 0,
  81. };
  82. static struct platform_device em_x270_rtc = {
  83. .name = "v3020",
  84. .num_resources = ARRAY_SIZE(em_x270_v3020_resource),
  85. .resource = em_x270_v3020_resource,
  86. .id = -1,
  87. .dev = {
  88. .platform_data = &em_x270_v3020_platdata,
  89. }
  90. };
  91. /* NAND flash */
  92. #define GPIO_NAND_CS (11)
  93. #define GPIO_NAND_RB (56)
  94. static inline void nand_cs_on(void)
  95. {
  96. GPCR(GPIO_NAND_CS) = GPIO_bit(GPIO_NAND_CS);
  97. }
  98. static void nand_cs_off(void)
  99. {
  100. dsb();
  101. GPSR(GPIO_NAND_CS) = GPIO_bit(GPIO_NAND_CS);
  102. }
  103. /* hardware specific access to control-lines */
  104. static void em_x270_nand_cmd_ctl(struct mtd_info *mtd, int dat,
  105. unsigned int ctrl)
  106. {
  107. struct nand_chip *this = mtd->priv;
  108. unsigned long nandaddr = (unsigned long)this->IO_ADDR_W;
  109. dsb();
  110. if (ctrl & NAND_CTRL_CHANGE) {
  111. if (ctrl & NAND_ALE)
  112. nandaddr |= (1 << 3);
  113. else
  114. nandaddr &= ~(1 << 3);
  115. if (ctrl & NAND_CLE)
  116. nandaddr |= (1 << 2);
  117. else
  118. nandaddr &= ~(1 << 2);
  119. if (ctrl & NAND_NCE)
  120. nand_cs_on();
  121. else
  122. nand_cs_off();
  123. }
  124. dsb();
  125. this->IO_ADDR_W = (void __iomem *)nandaddr;
  126. if (dat != NAND_CMD_NONE)
  127. writel(dat, this->IO_ADDR_W);
  128. dsb();
  129. }
  130. /* read device ready pin */
  131. static int em_x270_nand_device_ready(struct mtd_info *mtd)
  132. {
  133. dsb();
  134. return GPLR(GPIO_NAND_RB) & GPIO_bit(GPIO_NAND_RB);
  135. }
  136. static struct mtd_partition em_x270_partition_info[] = {
  137. [0] = {
  138. .name = "em_x270-0",
  139. .offset = 0,
  140. .size = SZ_4M,
  141. },
  142. [1] = {
  143. .name = "em_x270-1",
  144. .offset = MTDPART_OFS_APPEND,
  145. .size = MTDPART_SIZ_FULL
  146. },
  147. };
  148. static const char *em_x270_part_probes[] = { "cmdlinepart", NULL };
  149. struct platform_nand_data em_x270_nand_platdata = {
  150. .chip = {
  151. .nr_chips = 1,
  152. .chip_offset = 0,
  153. .nr_partitions = ARRAY_SIZE(em_x270_partition_info),
  154. .partitions = em_x270_partition_info,
  155. .chip_delay = 20,
  156. .part_probe_types = em_x270_part_probes,
  157. },
  158. .ctrl = {
  159. .hwcontrol = 0,
  160. .dev_ready = em_x270_nand_device_ready,
  161. .select_chip = 0,
  162. .cmd_ctrl = em_x270_nand_cmd_ctl,
  163. },
  164. };
  165. static struct resource em_x270_nand_resource[] = {
  166. [0] = {
  167. .start = PXA_CS1_PHYS,
  168. .end = PXA_CS1_PHYS + 12,
  169. .flags = IORESOURCE_MEM,
  170. },
  171. };
  172. static struct platform_device em_x270_nand = {
  173. .name = "gen_nand",
  174. .num_resources = ARRAY_SIZE(em_x270_nand_resource),
  175. .resource = em_x270_nand_resource,
  176. .id = -1,
  177. .dev = {
  178. .platform_data = &em_x270_nand_platdata,
  179. }
  180. };
  181. /* platform devices */
  182. static struct platform_device *platform_devices[] __initdata = {
  183. &em_x270_dm9k,
  184. &em_x270_ts,
  185. &em_x270_rtc,
  186. &em_x270_nand,
  187. };
  188. /* PXA27x OHCI controller setup */
  189. static int em_x270_ohci_init(struct device *dev)
  190. {
  191. /* Set the Power Control Polarity Low */
  192. UHCHR = (UHCHR | UHCHR_PCPL) &
  193. ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE);
  194. /* enable port 2 transiever */
  195. UP2OCR = UP2OCR_HXS | UP2OCR_HXOE;
  196. return 0;
  197. }
  198. static struct pxaohci_platform_data em_x270_ohci_platform_data = {
  199. .port_mode = PMM_PERPORT_MODE,
  200. .init = em_x270_ohci_init,
  201. };
  202. static int em_x270_mci_init(struct device *dev,
  203. irq_handler_t em_x270_detect_int,
  204. void *data)
  205. {
  206. int err;
  207. /* setup GPIO for PXA27x MMC controller */
  208. pxa_gpio_mode(GPIO32_MMCCLK_MD);
  209. pxa_gpio_mode(GPIO112_MMCCMD_MD);
  210. pxa_gpio_mode(GPIO92_MMCDAT0_MD);
  211. pxa_gpio_mode(GPIO109_MMCDAT1_MD);
  212. pxa_gpio_mode(GPIO110_MMCDAT2_MD);
  213. pxa_gpio_mode(GPIO111_MMCDAT3_MD);
  214. /* EM-X270 uses GPIO13 as SD power enable */
  215. pxa_gpio_mode(EM_X270_MMC_PD | GPIO_OUT);
  216. err = request_irq(EM_X270_MMC_IRQ, em_x270_detect_int,
  217. IRQF_DISABLED | IRQF_TRIGGER_FALLING,
  218. "MMC card detect", data);
  219. if (err) {
  220. printk(KERN_ERR "%s: can't request MMC card detect IRQ: %d\n",
  221. __func__, err);
  222. return err;
  223. }
  224. return 0;
  225. }
  226. static void em_x270_mci_setpower(struct device *dev, unsigned int vdd)
  227. {
  228. /*
  229. FIXME: current hardware implementation does not allow to
  230. enable/disable MMC power. This will be fixed in next HW releases,
  231. and we'll need to add implmentation here.
  232. */
  233. return;
  234. }
  235. static void em_x270_mci_exit(struct device *dev, void *data)
  236. {
  237. free_irq(EM_X270_MMC_IRQ, data);
  238. }
  239. static struct pxamci_platform_data em_x270_mci_platform_data = {
  240. .ocr_mask = MMC_VDD_28_29|MMC_VDD_29_30|MMC_VDD_30_31,
  241. .init = em_x270_mci_init,
  242. .setpower = em_x270_mci_setpower,
  243. .exit = em_x270_mci_exit,
  244. };
  245. /* LCD 480x640 */
  246. static struct pxafb_mode_info em_x270_lcd_mode = {
  247. .pixclock = 50000,
  248. .bpp = 16,
  249. .xres = 480,
  250. .yres = 640,
  251. .hsync_len = 8,
  252. .vsync_len = 2,
  253. .left_margin = 8,
  254. .upper_margin = 0,
  255. .right_margin = 24,
  256. .lower_margin = 4,
  257. .cmap_greyscale = 0,
  258. };
  259. static struct pxafb_mach_info em_x270_lcd = {
  260. .modes = &em_x270_lcd_mode,
  261. .num_modes = 1,
  262. .cmap_inverse = 0,
  263. .cmap_static = 0,
  264. .lccr0 = LCCR0_PAS,
  265. .lccr3 = LCCR3_PixClkDiv(0x01) | LCCR3_Acb(0xff),
  266. };
  267. static void __init em_x270_init(void)
  268. {
  269. /* setup LCD */
  270. set_pxa_fb_info(&em_x270_lcd);
  271. /* register EM-X270 platform devices */
  272. platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  273. pxa_set_ac97_info(NULL);
  274. /* set MCI and OHCI platform parameters */
  275. pxa_set_mci_info(&em_x270_mci_platform_data);
  276. pxa_set_ohci_info(&em_x270_ohci_platform_data);
  277. /* setup STUART GPIOs */
  278. pxa_gpio_mode(GPIO46_STRXD_MD);
  279. pxa_gpio_mode(GPIO47_STTXD_MD);
  280. /* setup BTUART GPIOs */
  281. pxa_gpio_mode(GPIO42_BTRXD_MD);
  282. pxa_gpio_mode(GPIO43_BTTXD_MD);
  283. pxa_gpio_mode(GPIO44_BTCTS_MD);
  284. pxa_gpio_mode(GPIO45_BTRTS_MD);
  285. /* Setup interrupt for dm9000 */
  286. set_irq_type(EM_X270_ETHIRQ, IRQT_RISING);
  287. }
  288. MACHINE_START(EM_X270, "Compulab EM-x270")
  289. .boot_params = 0xa0000100,
  290. .phys_io = 0x40000000,
  291. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  292. .map_io = pxa_map_io,
  293. .init_irq = pxa27x_init_irq,
  294. .timer = &pxa_timer,
  295. .init_machine = em_x270_init,
  296. MACHINE_END