phy3250.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 <asm/setup.h>
  40. #include <asm/mach-types.h>
  41. #include <asm/mach/arch.h>
  42. #include <mach/hardware.h>
  43. #include <mach/platform.h>
  44. #include <mach/board.h>
  45. #include <mach/gpio-lpc32xx.h>
  46. #include "common.h"
  47. /*
  48. * Mapped GPIOLIB GPIOs
  49. */
  50. #define LCD_POWER_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 0)
  51. #define BKL_POWER_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 4)
  52. #define MMC_PWR_ENABLE_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 5)
  53. /*
  54. * AMBA LCD controller
  55. */
  56. static struct clcd_panel conn_lcd_panel = {
  57. .mode = {
  58. .name = "QVGA portrait",
  59. .refresh = 60,
  60. .xres = 240,
  61. .yres = 320,
  62. .pixclock = 191828,
  63. .left_margin = 22,
  64. .right_margin = 11,
  65. .upper_margin = 2,
  66. .lower_margin = 1,
  67. .hsync_len = 5,
  68. .vsync_len = 2,
  69. .sync = 0,
  70. .vmode = FB_VMODE_NONINTERLACED,
  71. },
  72. .width = -1,
  73. .height = -1,
  74. .tim2 = (TIM2_IVS | TIM2_IHS),
  75. .cntl = (CNTL_BGR | CNTL_LCDTFT | CNTL_LCDVCOMP(1) |
  76. CNTL_LCDBPP16_565),
  77. .bpp = 16,
  78. };
  79. #define PANEL_SIZE (3 * SZ_64K)
  80. static int lpc32xx_clcd_setup(struct clcd_fb *fb)
  81. {
  82. dma_addr_t dma;
  83. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev,
  84. PANEL_SIZE, &dma, GFP_KERNEL);
  85. if (!fb->fb.screen_base) {
  86. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  87. return -ENOMEM;
  88. }
  89. fb->fb.fix.smem_start = dma;
  90. fb->fb.fix.smem_len = PANEL_SIZE;
  91. fb->panel = &conn_lcd_panel;
  92. if (gpio_request(LCD_POWER_GPIO, "LCD power"))
  93. printk(KERN_ERR "Error requesting gpio %u",
  94. LCD_POWER_GPIO);
  95. else if (gpio_direction_output(LCD_POWER_GPIO, 1))
  96. printk(KERN_ERR "Error setting gpio %u to output",
  97. LCD_POWER_GPIO);
  98. if (gpio_request(BKL_POWER_GPIO, "LCD backlight power"))
  99. printk(KERN_ERR "Error requesting gpio %u",
  100. BKL_POWER_GPIO);
  101. else if (gpio_direction_output(BKL_POWER_GPIO, 1))
  102. printk(KERN_ERR "Error setting gpio %u to output",
  103. BKL_POWER_GPIO);
  104. return 0;
  105. }
  106. static int lpc32xx_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  107. {
  108. return dma_mmap_writecombine(&fb->dev->dev, vma,
  109. fb->fb.screen_base, fb->fb.fix.smem_start,
  110. fb->fb.fix.smem_len);
  111. }
  112. static void lpc32xx_clcd_remove(struct clcd_fb *fb)
  113. {
  114. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  115. fb->fb.screen_base, fb->fb.fix.smem_start);
  116. }
  117. /*
  118. * On some early LCD modules (1307.0), the backlight logic is inverted.
  119. * For those board variants, swap the disable and enable states for
  120. * BKL_POWER_GPIO.
  121. */
  122. static void clcd_disable(struct clcd_fb *fb)
  123. {
  124. gpio_set_value(BKL_POWER_GPIO, 0);
  125. gpio_set_value(LCD_POWER_GPIO, 0);
  126. }
  127. static void clcd_enable(struct clcd_fb *fb)
  128. {
  129. gpio_set_value(BKL_POWER_GPIO, 1);
  130. gpio_set_value(LCD_POWER_GPIO, 1);
  131. }
  132. static struct clcd_board lpc32xx_clcd_data = {
  133. .name = "Phytec LCD",
  134. .check = clcdfb_check,
  135. .decode = clcdfb_decode,
  136. .disable = clcd_disable,
  137. .enable = clcd_enable,
  138. .setup = lpc32xx_clcd_setup,
  139. .mmap = lpc32xx_clcd_mmap,
  140. .remove = lpc32xx_clcd_remove,
  141. };
  142. /*
  143. * AMBA SSP (SPI)
  144. */
  145. static struct pl022_ssp_controller lpc32xx_ssp0_data = {
  146. .bus_id = 0,
  147. .num_chipselect = 1,
  148. .enable_dma = 0,
  149. };
  150. static struct pl022_ssp_controller lpc32xx_ssp1_data = {
  151. .bus_id = 1,
  152. .num_chipselect = 1,
  153. .enable_dma = 0,
  154. };
  155. static struct pl08x_channel_data pl08x_slave_channels[] = {
  156. {
  157. .bus_id = "nand-slc",
  158. .min_signal = 1, /* SLC NAND Flash */
  159. .max_signal = 1,
  160. .periph_buses = PL08X_AHB1,
  161. },
  162. {
  163. .bus_id = "nand-mlc",
  164. .min_signal = 12, /* MLC NAND Flash */
  165. .max_signal = 12,
  166. .periph_buses = PL08X_AHB1,
  167. },
  168. };
  169. static int pl08x_get_signal(const struct pl08x_channel_data *cd)
  170. {
  171. return cd->min_signal;
  172. }
  173. static void pl08x_put_signal(const struct pl08x_channel_data *cd, int ch)
  174. {
  175. }
  176. static struct pl08x_platform_data pl08x_pd = {
  177. .slave_channels = &pl08x_slave_channels[0],
  178. .num_slave_channels = ARRAY_SIZE(pl08x_slave_channels),
  179. .get_signal = pl08x_get_signal,
  180. .put_signal = pl08x_put_signal,
  181. .lli_buses = PL08X_AHB1,
  182. .mem_buses = PL08X_AHB1,
  183. };
  184. static int mmc_handle_ios(struct device *dev, struct mmc_ios *ios)
  185. {
  186. /* Only on and off are supported */
  187. if (ios->power_mode == MMC_POWER_OFF)
  188. gpio_set_value(MMC_PWR_ENABLE_GPIO, 0);
  189. else
  190. gpio_set_value(MMC_PWR_ENABLE_GPIO, 1);
  191. return 0;
  192. }
  193. static struct mmci_platform_data lpc32xx_mmci_data = {
  194. .ocr_mask = MMC_VDD_30_31 | MMC_VDD_31_32 |
  195. MMC_VDD_32_33 | MMC_VDD_33_34,
  196. .ios_handler = mmc_handle_ios,
  197. .dma_filter = NULL,
  198. /* No DMA for now since AMBA PL080 dmaengine driver only does scatter
  199. * gather, and the MMCI driver doesn't do it this way */
  200. };
  201. static const struct of_dev_auxdata lpc32xx_auxdata_lookup[] __initconst = {
  202. OF_DEV_AUXDATA("arm,pl022", 0x20084000, "dev:ssp0", &lpc32xx_ssp0_data),
  203. OF_DEV_AUXDATA("arm,pl022", 0x2008C000, "dev:ssp1", &lpc32xx_ssp1_data),
  204. OF_DEV_AUXDATA("arm,pl110", 0x31040000, "dev:clcd", &lpc32xx_clcd_data),
  205. OF_DEV_AUXDATA("arm,pl080", 0x31000000, "pl08xdmac", &pl08x_pd),
  206. OF_DEV_AUXDATA("arm,pl18x", 0x20098000, "20098000.sd",
  207. &lpc32xx_mmci_data),
  208. { }
  209. };
  210. static void __init lpc3250_machine_init(void)
  211. {
  212. u32 tmp;
  213. /* Setup LCD muxing to RGB565 */
  214. tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL) &
  215. ~(LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_MSK |
  216. LPC32XX_CLKPWR_LCDCTRL_PSCALE_MSK);
  217. tmp |= LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_TFT16;
  218. __raw_writel(tmp, LPC32XX_CLKPWR_LCDCLK_CTRL);
  219. lpc32xx_serial_init();
  220. /* Test clock needed for UDA1380 initial init */
  221. __raw_writel(LPC32XX_CLKPWR_TESTCLK2_SEL_MOSC |
  222. LPC32XX_CLKPWR_TESTCLK_TESTCLK2_EN,
  223. LPC32XX_CLKPWR_TEST_CLK_SEL);
  224. of_platform_populate(NULL, of_default_bus_match_table,
  225. lpc32xx_auxdata_lookup, NULL);
  226. /* Register GPIOs used on this board */
  227. if (gpio_request(MMC_PWR_ENABLE_GPIO, "mmc_power_en"))
  228. pr_err("Error requesting gpio %u", MMC_PWR_ENABLE_GPIO);
  229. else if (gpio_direction_output(MMC_PWR_ENABLE_GPIO, 1))
  230. pr_err("Error setting gpio %u to output", MMC_PWR_ENABLE_GPIO);
  231. }
  232. static char const *lpc32xx_dt_compat[] __initdata = {
  233. "nxp,lpc3220",
  234. "nxp,lpc3230",
  235. "nxp,lpc3240",
  236. "nxp,lpc3250",
  237. NULL
  238. };
  239. DT_MACHINE_START(LPC32XX_DT, "LPC32XX SoC (Flattened Device Tree)")
  240. .atag_offset = 0x100,
  241. .map_io = lpc32xx_map_io,
  242. .init_irq = lpc32xx_init_irq,
  243. .timer = &lpc32xx_timer,
  244. .init_machine = lpc3250_machine_init,
  245. .dt_compat = lpc32xx_dt_compat,
  246. .restart = lpc23xx_restart,
  247. MACHINE_END