phy3250.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * Platform support for LPC32xx SoC
  3. *
  4. * Author: Kevin Wells <kevin.wells@nxp.com>
  5. *
  6. * Copyright (C) 2012 Roland Stigge <stigge@antcom.de>
  7. * Copyright (C) 2010 NXP Semiconductors
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #include <linux/init.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/device.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/irq.h>
  24. #include <linux/dma-mapping.h>
  25. #include <linux/device.h>
  26. #include <linux/spi/spi.h>
  27. #include <linux/spi/eeprom.h>
  28. #include <linux/gpio.h>
  29. #include <linux/amba/bus.h>
  30. #include <linux/amba/clcd.h>
  31. #include <linux/amba/pl022.h>
  32. #include <linux/amba/pl08x.h>
  33. #include <linux/amba/mmci.h>
  34. #include <linux/of.h>
  35. #include <linux/of_address.h>
  36. #include <linux/of_irq.h>
  37. #include <linux/of_platform.h>
  38. #include <linux/clk.h>
  39. #include <linux/mtd/lpc32xx_slc.h>
  40. #include <linux/mtd/lpc32xx_mlc.h>
  41. #include <asm/setup.h>
  42. #include <asm/mach-types.h>
  43. #include <asm/mach/arch.h>
  44. #include <mach/hardware.h>
  45. #include <mach/platform.h>
  46. #include <mach/board.h>
  47. #include <mach/gpio-lpc32xx.h>
  48. #include "common.h"
  49. /*
  50. * Mapped GPIOLIB GPIOs
  51. */
  52. #define LCD_POWER_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 0)
  53. #define BKL_POWER_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 4)
  54. #define MMC_PWR_ENABLE_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 5)
  55. /*
  56. * AMBA LCD controller
  57. */
  58. static struct clcd_panel conn_lcd_panel = {
  59. .mode = {
  60. .name = "QVGA portrait",
  61. .refresh = 60,
  62. .xres = 240,
  63. .yres = 320,
  64. .pixclock = 191828,
  65. .left_margin = 22,
  66. .right_margin = 11,
  67. .upper_margin = 2,
  68. .lower_margin = 1,
  69. .hsync_len = 5,
  70. .vsync_len = 2,
  71. .sync = 0,
  72. .vmode = FB_VMODE_NONINTERLACED,
  73. },
  74. .width = -1,
  75. .height = -1,
  76. .tim2 = (TIM2_IVS | TIM2_IHS),
  77. .cntl = (CNTL_BGR | CNTL_LCDTFT | CNTL_LCDVCOMP(1) |
  78. CNTL_LCDBPP16_565),
  79. .bpp = 16,
  80. };
  81. #define PANEL_SIZE (3 * SZ_64K)
  82. static int lpc32xx_clcd_setup(struct clcd_fb *fb)
  83. {
  84. dma_addr_t dma;
  85. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev,
  86. PANEL_SIZE, &dma, GFP_KERNEL);
  87. if (!fb->fb.screen_base) {
  88. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  89. return -ENOMEM;
  90. }
  91. fb->fb.fix.smem_start = dma;
  92. fb->fb.fix.smem_len = PANEL_SIZE;
  93. fb->panel = &conn_lcd_panel;
  94. if (gpio_request(LCD_POWER_GPIO, "LCD power"))
  95. printk(KERN_ERR "Error requesting gpio %u",
  96. LCD_POWER_GPIO);
  97. else if (gpio_direction_output(LCD_POWER_GPIO, 1))
  98. printk(KERN_ERR "Error setting gpio %u to output",
  99. LCD_POWER_GPIO);
  100. if (gpio_request(BKL_POWER_GPIO, "LCD backlight power"))
  101. printk(KERN_ERR "Error requesting gpio %u",
  102. BKL_POWER_GPIO);
  103. else if (gpio_direction_output(BKL_POWER_GPIO, 1))
  104. printk(KERN_ERR "Error setting gpio %u to output",
  105. BKL_POWER_GPIO);
  106. return 0;
  107. }
  108. static int lpc32xx_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  109. {
  110. return dma_mmap_writecombine(&fb->dev->dev, vma,
  111. fb->fb.screen_base, fb->fb.fix.smem_start,
  112. fb->fb.fix.smem_len);
  113. }
  114. static void lpc32xx_clcd_remove(struct clcd_fb *fb)
  115. {
  116. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  117. fb->fb.screen_base, fb->fb.fix.smem_start);
  118. }
  119. /*
  120. * On some early LCD modules (1307.0), the backlight logic is inverted.
  121. * For those board variants, swap the disable and enable states for
  122. * BKL_POWER_GPIO.
  123. */
  124. static void clcd_disable(struct clcd_fb *fb)
  125. {
  126. gpio_set_value(BKL_POWER_GPIO, 0);
  127. gpio_set_value(LCD_POWER_GPIO, 0);
  128. }
  129. static void clcd_enable(struct clcd_fb *fb)
  130. {
  131. gpio_set_value(BKL_POWER_GPIO, 1);
  132. gpio_set_value(LCD_POWER_GPIO, 1);
  133. }
  134. static struct clcd_board lpc32xx_clcd_data = {
  135. .name = "Phytec LCD",
  136. .check = clcdfb_check,
  137. .decode = clcdfb_decode,
  138. .disable = clcd_disable,
  139. .enable = clcd_enable,
  140. .setup = lpc32xx_clcd_setup,
  141. .mmap = lpc32xx_clcd_mmap,
  142. .remove = lpc32xx_clcd_remove,
  143. };
  144. /*
  145. * AMBA SSP (SPI)
  146. */
  147. static struct pl022_ssp_controller lpc32xx_ssp0_data = {
  148. .bus_id = 0,
  149. .num_chipselect = 1,
  150. .enable_dma = 0,
  151. };
  152. static struct pl022_ssp_controller lpc32xx_ssp1_data = {
  153. .bus_id = 1,
  154. .num_chipselect = 1,
  155. .enable_dma = 0,
  156. };
  157. static struct pl08x_channel_data pl08x_slave_channels[] = {
  158. {
  159. .bus_id = "nand-slc",
  160. .min_signal = 1, /* SLC NAND Flash */
  161. .max_signal = 1,
  162. .periph_buses = PL08X_AHB1,
  163. },
  164. {
  165. .bus_id = "nand-mlc",
  166. .min_signal = 12, /* MLC NAND Flash */
  167. .max_signal = 12,
  168. .periph_buses = PL08X_AHB1,
  169. },
  170. };
  171. static int pl08x_get_signal(const struct pl08x_channel_data *cd)
  172. {
  173. return cd->min_signal;
  174. }
  175. static void pl08x_put_signal(const struct pl08x_channel_data *cd, int ch)
  176. {
  177. }
  178. static struct pl08x_platform_data pl08x_pd = {
  179. .slave_channels = &pl08x_slave_channels[0],
  180. .num_slave_channels = ARRAY_SIZE(pl08x_slave_channels),
  181. .get_signal = pl08x_get_signal,
  182. .put_signal = pl08x_put_signal,
  183. .lli_buses = PL08X_AHB1,
  184. .mem_buses = PL08X_AHB1,
  185. };
  186. static int mmc_handle_ios(struct device *dev, struct mmc_ios *ios)
  187. {
  188. /* Only on and off are supported */
  189. if (ios->power_mode == MMC_POWER_OFF)
  190. gpio_set_value(MMC_PWR_ENABLE_GPIO, 0);
  191. else
  192. gpio_set_value(MMC_PWR_ENABLE_GPIO, 1);
  193. return 0;
  194. }
  195. static struct mmci_platform_data lpc32xx_mmci_data = {
  196. .ocr_mask = MMC_VDD_30_31 | MMC_VDD_31_32 |
  197. MMC_VDD_32_33 | MMC_VDD_33_34,
  198. .ios_handler = mmc_handle_ios,
  199. .dma_filter = NULL,
  200. /* No DMA for now since AMBA PL080 dmaengine driver only does scatter
  201. * gather, and the MMCI driver doesn't do it this way */
  202. };
  203. static struct lpc32xx_slc_platform_data lpc32xx_slc_data = {
  204. .dma_filter = pl08x_filter_id,
  205. };
  206. static struct lpc32xx_mlc_platform_data lpc32xx_mlc_data = {
  207. .dma_filter = pl08x_filter_id,
  208. };
  209. static const struct of_dev_auxdata lpc32xx_auxdata_lookup[] __initconst = {
  210. OF_DEV_AUXDATA("arm,pl022", 0x20084000, "dev:ssp0", &lpc32xx_ssp0_data),
  211. OF_DEV_AUXDATA("arm,pl022", 0x2008C000, "dev:ssp1", &lpc32xx_ssp1_data),
  212. OF_DEV_AUXDATA("arm,pl110", 0x31040000, "dev:clcd", &lpc32xx_clcd_data),
  213. OF_DEV_AUXDATA("arm,pl080", 0x31000000, "pl08xdmac", &pl08x_pd),
  214. OF_DEV_AUXDATA("arm,pl18x", 0x20098000, "20098000.sd",
  215. &lpc32xx_mmci_data),
  216. OF_DEV_AUXDATA("nxp,lpc3220-slc", 0x20020000, "20020000.flash",
  217. &lpc32xx_slc_data),
  218. OF_DEV_AUXDATA("nxp,lpc3220-mlc", 0x200a8000, "200a8000.flash",
  219. &lpc32xx_mlc_data),
  220. { }
  221. };
  222. static void __init lpc3250_machine_init(void)
  223. {
  224. u32 tmp;
  225. /* Setup LCD muxing to RGB565 */
  226. tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL) &
  227. ~(LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_MSK |
  228. LPC32XX_CLKPWR_LCDCTRL_PSCALE_MSK);
  229. tmp |= LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_TFT16;
  230. __raw_writel(tmp, LPC32XX_CLKPWR_LCDCLK_CTRL);
  231. lpc32xx_serial_init();
  232. /* Test clock needed for UDA1380 initial init */
  233. __raw_writel(LPC32XX_CLKPWR_TESTCLK2_SEL_MOSC |
  234. LPC32XX_CLKPWR_TESTCLK_TESTCLK2_EN,
  235. LPC32XX_CLKPWR_TEST_CLK_SEL);
  236. of_platform_populate(NULL, of_default_bus_match_table,
  237. lpc32xx_auxdata_lookup, NULL);
  238. /* Register GPIOs used on this board */
  239. if (gpio_request(MMC_PWR_ENABLE_GPIO, "mmc_power_en"))
  240. pr_err("Error requesting gpio %u", MMC_PWR_ENABLE_GPIO);
  241. else if (gpio_direction_output(MMC_PWR_ENABLE_GPIO, 1))
  242. pr_err("Error setting gpio %u to output", MMC_PWR_ENABLE_GPIO);
  243. }
  244. static char const *lpc32xx_dt_compat[] __initdata = {
  245. "nxp,lpc3220",
  246. "nxp,lpc3230",
  247. "nxp,lpc3240",
  248. "nxp,lpc3250",
  249. NULL
  250. };
  251. DT_MACHINE_START(LPC32XX_DT, "LPC32XX SoC (Flattened Device Tree)")
  252. .atag_offset = 0x100,
  253. .map_io = lpc32xx_map_io,
  254. .init_irq = lpc32xx_init_irq,
  255. .timer = &lpc32xx_timer,
  256. .init_machine = lpc3250_machine_init,
  257. .dt_compat = lpc32xx_dt_compat,
  258. .restart = lpc23xx_restart,
  259. MACHINE_END