phy3250.c 8.1 KB

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