phy3250.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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 void phy3250_spi_cs_set(u32 control)
  149. {
  150. gpio_set_value(SPI0_CS_GPIO, (int) control);
  151. }
  152. static struct pl022_config_chip spi0_chip_info = {
  153. .com_mode = INTERRUPT_TRANSFER,
  154. .iface = SSP_INTERFACE_MOTOROLA_SPI,
  155. .hierarchy = SSP_MASTER,
  156. .slave_tx_disable = 0,
  157. .rx_lev_trig = SSP_RX_4_OR_MORE_ELEM,
  158. .tx_lev_trig = SSP_TX_4_OR_MORE_EMPTY_LOC,
  159. .ctrl_len = SSP_BITS_8,
  160. .wait_state = SSP_MWIRE_WAIT_ZERO,
  161. .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX,
  162. .cs_control = phy3250_spi_cs_set,
  163. };
  164. static struct pl022_ssp_controller lpc32xx_ssp0_data = {
  165. .bus_id = 0,
  166. .num_chipselect = 1,
  167. .enable_dma = 0,
  168. };
  169. static struct pl022_ssp_controller lpc32xx_ssp1_data = {
  170. .bus_id = 1,
  171. .num_chipselect = 1,
  172. .enable_dma = 0,
  173. };
  174. /* AT25 driver registration */
  175. static int __init phy3250_spi_board_register(void)
  176. {
  177. #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
  178. static struct spi_board_info info[] = {
  179. {
  180. .modalias = "spidev",
  181. .max_speed_hz = 5000000,
  182. .bus_num = 0,
  183. .chip_select = 0,
  184. .controller_data = &spi0_chip_info,
  185. },
  186. };
  187. #else
  188. static struct spi_eeprom eeprom = {
  189. .name = "at25256a",
  190. .byte_len = 0x8000,
  191. .page_size = 64,
  192. .flags = EE_ADDR2,
  193. };
  194. static struct spi_board_info info[] = {
  195. {
  196. .modalias = "at25",
  197. .max_speed_hz = 5000000,
  198. .bus_num = 0,
  199. .chip_select = 0,
  200. .mode = SPI_MODE_0,
  201. .platform_data = &eeprom,
  202. .controller_data = &spi0_chip_info,
  203. },
  204. };
  205. #endif
  206. return spi_register_board_info(info, ARRAY_SIZE(info));
  207. }
  208. arch_initcall(phy3250_spi_board_register);
  209. static struct pl08x_channel_data pl08x_slave_channels[] = {
  210. {
  211. .bus_id = "nand-slc",
  212. .min_signal = 1, /* SLC NAND Flash */
  213. .max_signal = 1,
  214. .periph_buses = PL08X_AHB1,
  215. },
  216. {
  217. .bus_id = "nand-mlc",
  218. .min_signal = 12, /* MLC NAND Flash */
  219. .max_signal = 12,
  220. .periph_buses = PL08X_AHB1,
  221. },
  222. };
  223. /* NOTE: These will change, according to RMK */
  224. static int pl08x_get_signal(struct pl08x_dma_chan *ch)
  225. {
  226. return ch->cd->min_signal;
  227. }
  228. static void pl08x_put_signal(struct pl08x_dma_chan *ch)
  229. {
  230. }
  231. static struct pl08x_platform_data pl08x_pd = {
  232. .slave_channels = &pl08x_slave_channels[0],
  233. .num_slave_channels = ARRAY_SIZE(pl08x_slave_channels),
  234. .get_signal = pl08x_get_signal,
  235. .put_signal = pl08x_put_signal,
  236. .lli_buses = PL08X_AHB1,
  237. .mem_buses = PL08X_AHB1,
  238. };
  239. static int mmc_handle_ios(struct device *dev, struct mmc_ios *ios)
  240. {
  241. /* Only on and off are supported */
  242. if (ios->power_mode == MMC_POWER_OFF)
  243. gpio_set_value(MMC_PWR_ENABLE_GPIO, 0);
  244. else
  245. gpio_set_value(MMC_PWR_ENABLE_GPIO, 1);
  246. return 0;
  247. }
  248. static struct mmci_platform_data lpc32xx_mmci_data = {
  249. .ocr_mask = MMC_VDD_30_31 | MMC_VDD_31_32 |
  250. MMC_VDD_32_33 | MMC_VDD_33_34,
  251. .ios_handler = mmc_handle_ios,
  252. .dma_filter = NULL,
  253. /* No DMA for now since AMBA PL080 dmaengine driver only does scatter
  254. * gather, and the MMCI driver doesn't do it this way */
  255. };
  256. static const struct of_dev_auxdata lpc32xx_auxdata_lookup[] __initconst = {
  257. OF_DEV_AUXDATA("arm,pl022", 0x20084000, "dev:ssp0", &lpc32xx_ssp0_data),
  258. OF_DEV_AUXDATA("arm,pl022", 0x2008C000, "dev:ssp1", &lpc32xx_ssp1_data),
  259. OF_DEV_AUXDATA("arm,pl110", 0x31040000, "dev:clcd", &lpc32xx_clcd_data),
  260. OF_DEV_AUXDATA("arm,pl080", 0x31000000, "pl08xdmac", &pl08x_pd),
  261. OF_DEV_AUXDATA("arm,pl18x", 0x20098000, "20098000.sd",
  262. &lpc32xx_mmci_data),
  263. { }
  264. };
  265. static void __init lpc3250_machine_init(void)
  266. {
  267. u32 tmp;
  268. /* Setup LCD muxing to RGB565 */
  269. tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL) &
  270. ~(LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_MSK |
  271. LPC32XX_CLKPWR_LCDCTRL_PSCALE_MSK);
  272. tmp |= LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_TFT16;
  273. __raw_writel(tmp, LPC32XX_CLKPWR_LCDCLK_CTRL);
  274. /* Set up USB power */
  275. tmp = __raw_readl(LPC32XX_CLKPWR_USB_CTRL);
  276. tmp |= LPC32XX_CLKPWR_USBCTRL_HCLK_EN |
  277. LPC32XX_CLKPWR_USBCTRL_USBI2C_EN;
  278. __raw_writel(tmp, LPC32XX_CLKPWR_USB_CTRL);
  279. /* Set up I2C pull levels */
  280. tmp = __raw_readl(LPC32XX_CLKPWR_I2C_CLK_CTRL);
  281. tmp |= LPC32XX_CLKPWR_I2CCLK_USBI2CHI_DRIVE |
  282. LPC32XX_CLKPWR_I2CCLK_I2C2HI_DRIVE;
  283. __raw_writel(tmp, LPC32XX_CLKPWR_I2C_CLK_CTRL);
  284. /* Disable IrDA pulsing support on UART6 */
  285. tmp = __raw_readl(LPC32XX_UARTCTL_CTRL);
  286. tmp |= LPC32XX_UART_UART6_IRDAMOD_BYPASS;
  287. __raw_writel(tmp, LPC32XX_UARTCTL_CTRL);
  288. /* Enable DMA for I2S1 channel */
  289. tmp = __raw_readl(LPC32XX_CLKPWR_I2S_CLK_CTRL);
  290. tmp = LPC32XX_CLKPWR_I2SCTRL_I2S1_USE_DMA;
  291. __raw_writel(tmp, LPC32XX_CLKPWR_I2S_CLK_CTRL);
  292. lpc32xx_serial_init();
  293. /*
  294. * AMBA peripheral clocks need to be enabled prior to AMBA device
  295. * detection or a data fault will occur, so enable the clocks
  296. * here.
  297. */
  298. tmp = __raw_readl(LPC32XX_CLKPWR_MS_CTRL);
  299. tmp |= LPC32XX_CLKPWR_MSCARD_SDCARD_EN |
  300. LPC32XX_CLKPWR_MSCARD_MSDIO_PU_EN;
  301. __raw_writel(tmp, LPC32XX_CLKPWR_MS_CTRL);
  302. tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL);
  303. __raw_writel((tmp | LPC32XX_CLKPWR_LCDCTRL_CLK_EN),
  304. LPC32XX_CLKPWR_LCDCLK_CTRL);
  305. tmp = __raw_readl(LPC32XX_CLKPWR_SSP_CLK_CTRL);
  306. __raw_writel((tmp | LPC32XX_CLKPWR_SSPCTRL_SSPCLK0_EN),
  307. LPC32XX_CLKPWR_SSP_CLK_CTRL);
  308. tmp = __raw_readl(LPC32XX_CLKPWR_DMA_CLK_CTRL);
  309. __raw_writel((tmp | LPC32XX_CLKPWR_DMACLKCTRL_CLK_EN),
  310. LPC32XX_CLKPWR_DMA_CLK_CTRL);
  311. /* Test clock needed for UDA1380 initial init */
  312. __raw_writel(LPC32XX_CLKPWR_TESTCLK2_SEL_MOSC |
  313. LPC32XX_CLKPWR_TESTCLK_TESTCLK2_EN,
  314. LPC32XX_CLKPWR_TEST_CLK_SEL);
  315. of_platform_populate(NULL, of_default_bus_match_table,
  316. lpc32xx_auxdata_lookup, NULL);
  317. /* Register GPIOs used on this board */
  318. if (gpio_request(MMC_PWR_ENABLE_GPIO, "mmc_power_en"))
  319. pr_err("Error requesting gpio %u", MMC_PWR_ENABLE_GPIO);
  320. else if (gpio_direction_output(MMC_PWR_ENABLE_GPIO, 1))
  321. pr_err("Error setting gpio %u to output", MMC_PWR_ENABLE_GPIO);
  322. }
  323. static char const *lpc32xx_dt_compat[] __initdata = {
  324. "nxp,lpc3220",
  325. "nxp,lpc3230",
  326. "nxp,lpc3240",
  327. "nxp,lpc3250",
  328. NULL
  329. };
  330. DT_MACHINE_START(LPC32XX_DT, "LPC32XX SoC (Flattened Device Tree)")
  331. .atag_offset = 0x100,
  332. .map_io = lpc32xx_map_io,
  333. .init_irq = lpc32xx_init_irq,
  334. .timer = &lpc32xx_timer,
  335. .init_machine = lpc3250_machine_init,
  336. .dt_compat = lpc32xx_dt_compat,
  337. .restart = lpc23xx_restart,
  338. MACHINE_END