phy3250.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /*
  2. * arch/arm/mach-lpc32xx/phy3250.c
  3. *
  4. * Author: Kevin Wells <kevin.wells@nxp.com>
  5. *
  6. * Copyright (C) 2010 NXP Semiconductors
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/init.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/sysdev.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/irq.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/device.h>
  25. #include <linux/spi/spi.h>
  26. #include <linux/spi/eeprom.h>
  27. #include <linux/leds.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 <asm/setup.h>
  33. #include <asm/mach-types.h>
  34. #include <asm/mach/arch.h>
  35. #include <mach/hardware.h>
  36. #include <mach/platform.h>
  37. #include "common.h"
  38. /*
  39. * Mapped GPIOLIB GPIOs
  40. */
  41. #define SPI0_CS_GPIO LPC32XX_GPIO(LPC32XX_GPIO_P3_GRP, 5)
  42. #define LCD_POWER_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 0)
  43. #define BKL_POWER_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 4)
  44. #define LED_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 1)
  45. /*
  46. * AMBA LCD controller
  47. */
  48. static struct clcd_panel conn_lcd_panel = {
  49. .mode = {
  50. .name = "QVGA portrait",
  51. .refresh = 60,
  52. .xres = 240,
  53. .yres = 320,
  54. .pixclock = 191828,
  55. .left_margin = 22,
  56. .right_margin = 11,
  57. .upper_margin = 2,
  58. .lower_margin = 1,
  59. .hsync_len = 5,
  60. .vsync_len = 2,
  61. .sync = 0,
  62. .vmode = FB_VMODE_NONINTERLACED,
  63. },
  64. .width = -1,
  65. .height = -1,
  66. .tim2 = (TIM2_IVS | TIM2_IHS),
  67. .cntl = (CNTL_BGR | CNTL_LCDTFT | CNTL_LCDVCOMP(1) |
  68. CNTL_LCDBPP16_565),
  69. .bpp = 16,
  70. };
  71. #define PANEL_SIZE (3 * SZ_64K)
  72. static int lpc32xx_clcd_setup(struct clcd_fb *fb)
  73. {
  74. dma_addr_t dma;
  75. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev,
  76. PANEL_SIZE, &dma, GFP_KERNEL);
  77. if (!fb->fb.screen_base) {
  78. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  79. return -ENOMEM;
  80. }
  81. fb->fb.fix.smem_start = dma;
  82. fb->fb.fix.smem_len = PANEL_SIZE;
  83. fb->panel = &conn_lcd_panel;
  84. if (gpio_request(LCD_POWER_GPIO, "LCD power"))
  85. printk(KERN_ERR "Error requesting gpio %u",
  86. LCD_POWER_GPIO);
  87. else if (gpio_direction_output(LCD_POWER_GPIO, 1))
  88. printk(KERN_ERR "Error setting gpio %u to output",
  89. LCD_POWER_GPIO);
  90. if (gpio_request(BKL_POWER_GPIO, "LCD backlight power"))
  91. printk(KERN_ERR "Error requesting gpio %u",
  92. BKL_POWER_GPIO);
  93. else if (gpio_direction_output(BKL_POWER_GPIO, 1))
  94. printk(KERN_ERR "Error setting gpio %u to output",
  95. BKL_POWER_GPIO);
  96. return 0;
  97. }
  98. static int lpc32xx_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  99. {
  100. return dma_mmap_writecombine(&fb->dev->dev, vma,
  101. fb->fb.screen_base, fb->fb.fix.smem_start,
  102. fb->fb.fix.smem_len);
  103. }
  104. static void lpc32xx_clcd_remove(struct clcd_fb *fb)
  105. {
  106. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  107. fb->fb.screen_base, fb->fb.fix.smem_start);
  108. }
  109. /*
  110. * On some early LCD modules (1307.0), the backlight logic is inverted.
  111. * For those board variants, swap the disable and enable states for
  112. * BKL_POWER_GPIO.
  113. */
  114. static void clcd_disable(struct clcd_fb *fb)
  115. {
  116. gpio_set_value(BKL_POWER_GPIO, 0);
  117. gpio_set_value(LCD_POWER_GPIO, 0);
  118. }
  119. static void clcd_enable(struct clcd_fb *fb)
  120. {
  121. gpio_set_value(BKL_POWER_GPIO, 1);
  122. gpio_set_value(LCD_POWER_GPIO, 1);
  123. }
  124. static struct clcd_board lpc32xx_clcd_data = {
  125. .name = "Phytec LCD",
  126. .check = clcdfb_check,
  127. .decode = clcdfb_decode,
  128. .disable = clcd_disable,
  129. .enable = clcd_enable,
  130. .setup = lpc32xx_clcd_setup,
  131. .mmap = lpc32xx_clcd_mmap,
  132. .remove = lpc32xx_clcd_remove,
  133. };
  134. static struct amba_device lpc32xx_clcd_device = {
  135. .dev = {
  136. .coherent_dma_mask = ~0,
  137. .init_name = "dev:clcd",
  138. .platform_data = &lpc32xx_clcd_data,
  139. },
  140. .res = {
  141. .start = LPC32XX_LCD_BASE,
  142. .end = (LPC32XX_LCD_BASE + SZ_4K - 1),
  143. .flags = IORESOURCE_MEM,
  144. },
  145. .dma_mask = ~0,
  146. .irq = {IRQ_LPC32XX_LCD, NO_IRQ},
  147. };
  148. /*
  149. * AMBA SSP (SPI)
  150. */
  151. static void phy3250_spi_cs_set(u32 control)
  152. {
  153. gpio_set_value(SPI0_CS_GPIO, (int) control);
  154. }
  155. static struct pl022_config_chip spi0_chip_info = {
  156. .com_mode = INTERRUPT_TRANSFER,
  157. .iface = SSP_INTERFACE_MOTOROLA_SPI,
  158. .hierarchy = SSP_MASTER,
  159. .slave_tx_disable = 0,
  160. .rx_lev_trig = SSP_RX_4_OR_MORE_ELEM,
  161. .tx_lev_trig = SSP_TX_4_OR_MORE_EMPTY_LOC,
  162. .ctrl_len = SSP_BITS_8,
  163. .wait_state = SSP_MWIRE_WAIT_ZERO,
  164. .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX,
  165. .cs_control = phy3250_spi_cs_set,
  166. };
  167. static struct pl022_ssp_controller lpc32xx_ssp0_data = {
  168. .bus_id = 0,
  169. .num_chipselect = 1,
  170. .enable_dma = 0,
  171. };
  172. static struct amba_device lpc32xx_ssp0_device = {
  173. .dev = {
  174. .coherent_dma_mask = ~0,
  175. .init_name = "dev:ssp0",
  176. .platform_data = &lpc32xx_ssp0_data,
  177. },
  178. .res = {
  179. .start = LPC32XX_SSP0_BASE,
  180. .end = (LPC32XX_SSP0_BASE + SZ_4K - 1),
  181. .flags = IORESOURCE_MEM,
  182. },
  183. .dma_mask = ~0,
  184. .irq = {IRQ_LPC32XX_SSP0, NO_IRQ},
  185. };
  186. /* AT25 driver registration */
  187. static int __init phy3250_spi_board_register(void)
  188. {
  189. #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
  190. static struct spi_board_info info[] = {
  191. {
  192. .modalias = "spidev",
  193. .max_speed_hz = 5000000,
  194. .bus_num = 0,
  195. .chip_select = 0,
  196. .controller_data = &spi0_chip_info,
  197. },
  198. };
  199. #else
  200. static struct spi_eeprom eeprom = {
  201. .name = "at25256a",
  202. .byte_len = 0x8000,
  203. .page_size = 64,
  204. .flags = EE_ADDR2,
  205. };
  206. static struct spi_board_info info[] = {
  207. {
  208. .modalias = "at25",
  209. .max_speed_hz = 5000000,
  210. .bus_num = 0,
  211. .chip_select = 0,
  212. .mode = SPI_MODE_0,
  213. .platform_data = &eeprom,
  214. .controller_data = &spi0_chip_info,
  215. },
  216. };
  217. #endif
  218. return spi_register_board_info(info, ARRAY_SIZE(info));
  219. }
  220. arch_initcall(phy3250_spi_board_register);
  221. static struct i2c_board_info __initdata phy3250_i2c_board_info[] = {
  222. {
  223. I2C_BOARD_INFO("pcf8563", 0x51),
  224. },
  225. };
  226. static struct gpio_led phy_leds[] = {
  227. {
  228. .name = "led0",
  229. .gpio = LED_GPIO,
  230. .active_low = 1,
  231. .default_trigger = "heartbeat",
  232. },
  233. };
  234. static struct gpio_led_platform_data led_data = {
  235. .leds = phy_leds,
  236. .num_leds = ARRAY_SIZE(phy_leds),
  237. };
  238. static struct platform_device lpc32xx_gpio_led_device = {
  239. .name = "leds-gpio",
  240. .id = -1,
  241. .dev.platform_data = &led_data,
  242. };
  243. static struct platform_device *phy3250_devs[] __initdata = {
  244. &lpc32xx_i2c0_device,
  245. &lpc32xx_i2c1_device,
  246. &lpc32xx_i2c2_device,
  247. &lpc32xx_watchdog_device,
  248. &lpc32xx_gpio_led_device,
  249. };
  250. static struct amba_device *amba_devs[] __initdata = {
  251. &lpc32xx_clcd_device,
  252. &lpc32xx_ssp0_device,
  253. };
  254. /*
  255. * Board specific functions
  256. */
  257. static void __init phy3250_board_init(void)
  258. {
  259. u32 tmp;
  260. int i;
  261. lpc32xx_gpio_init();
  262. /* Register GPIOs used on this board */
  263. if (gpio_request(SPI0_CS_GPIO, "spi0 cs"))
  264. printk(KERN_ERR "Error requesting gpio %u",
  265. SPI0_CS_GPIO);
  266. else if (gpio_direction_output(SPI0_CS_GPIO, 1))
  267. printk(KERN_ERR "Error setting gpio %u to output",
  268. SPI0_CS_GPIO);
  269. /* Setup network interface for RMII mode */
  270. tmp = __raw_readl(LPC32XX_CLKPWR_MACCLK_CTRL);
  271. tmp &= ~LPC32XX_CLKPWR_MACCTRL_PINS_MSK;
  272. tmp |= LPC32XX_CLKPWR_MACCTRL_USE_RMII_PINS;
  273. __raw_writel(tmp, LPC32XX_CLKPWR_MACCLK_CTRL);
  274. /* Setup SLC NAND controller muxing */
  275. __raw_writel(LPC32XX_CLKPWR_NANDCLK_SEL_SLC,
  276. LPC32XX_CLKPWR_NAND_CLK_CTRL);
  277. /* Setup LCD muxing to RGB565 */
  278. tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL) &
  279. ~(LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_MSK |
  280. LPC32XX_CLKPWR_LCDCTRL_PSCALE_MSK);
  281. tmp |= LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_TFT16;
  282. __raw_writel(tmp, LPC32XX_CLKPWR_LCDCLK_CTRL);
  283. /* Set up I2C pull levels */
  284. tmp = __raw_readl(LPC32XX_CLKPWR_I2C_CLK_CTRL);
  285. tmp |= LPC32XX_CLKPWR_I2CCLK_USBI2CHI_DRIVE |
  286. LPC32XX_CLKPWR_I2CCLK_I2C2HI_DRIVE;
  287. __raw_writel(tmp, LPC32XX_CLKPWR_I2C_CLK_CTRL);
  288. /* Disable IrDA pulsing support on UART6 */
  289. tmp = __raw_readl(LPC32XX_UARTCTL_CTRL);
  290. tmp |= LPC32XX_UART_UART6_IRDAMOD_BYPASS;
  291. __raw_writel(tmp, LPC32XX_UARTCTL_CTRL);
  292. /* Enable DMA for I2S1 channel */
  293. tmp = __raw_readl(LPC32XX_CLKPWR_I2S_CLK_CTRL);
  294. tmp = LPC32XX_CLKPWR_I2SCTRL_I2S1_USE_DMA;
  295. __raw_writel(tmp, LPC32XX_CLKPWR_I2S_CLK_CTRL);
  296. lpc32xx_serial_init();
  297. /*
  298. * AMBA peripheral clocks need to be enabled prior to AMBA device
  299. * detection or a data fault will occur, so enable the clocks
  300. * here. However, we don't want to enable them if the peripheral
  301. * isn't included in the image
  302. */
  303. #ifdef CONFIG_FB_ARMCLCD
  304. tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL);
  305. __raw_writel((tmp | LPC32XX_CLKPWR_LCDCTRL_CLK_EN),
  306. LPC32XX_CLKPWR_LCDCLK_CTRL);
  307. #endif
  308. #ifdef CONFIG_SPI_PL022
  309. tmp = __raw_readl(LPC32XX_CLKPWR_SSP_CLK_CTRL);
  310. __raw_writel((tmp | LPC32XX_CLKPWR_SSPCTRL_SSPCLK0_EN),
  311. LPC32XX_CLKPWR_SSP_CLK_CTRL);
  312. #endif
  313. platform_add_devices(phy3250_devs, ARRAY_SIZE(phy3250_devs));
  314. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  315. struct amba_device *d = amba_devs[i];
  316. amba_device_register(d, &iomem_resource);
  317. }
  318. /* Test clock needed for UDA1380 initial init */
  319. __raw_writel(LPC32XX_CLKPWR_TESTCLK2_SEL_MOSC |
  320. LPC32XX_CLKPWR_TESTCLK_TESTCLK2_EN,
  321. LPC32XX_CLKPWR_TEST_CLK_SEL);
  322. i2c_register_board_info(0, phy3250_i2c_board_info,
  323. ARRAY_SIZE(phy3250_i2c_board_info));
  324. }
  325. static int __init lpc32xx_display_uid(void)
  326. {
  327. u32 uid[4];
  328. lpc32xx_get_uid(uid);
  329. printk(KERN_INFO "LPC32XX unique ID: %08x%08x%08x%08x\n",
  330. uid[3], uid[2], uid[1], uid[0]);
  331. return 1;
  332. }
  333. arch_initcall(lpc32xx_display_uid);
  334. MACHINE_START(PHY3250, "Phytec 3250 board with the LPC3250 Microcontroller")
  335. /* Maintainer: Kevin Wells, NXP Semiconductors */
  336. .boot_params = 0x80000100,
  337. .map_io = lpc32xx_map_io,
  338. .init_irq = lpc32xx_init_irq,
  339. .timer = &lpc32xx_timer,
  340. .init_machine = phy3250_board_init,
  341. MACHINE_END