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