phy3250.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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/device.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 AMBA_AHB_DEVICE(lpc32xx_clcd, "dev:clcd", 0,
  136. LPC32XX_LCD_BASE, { IRQ_LPC32XX_LCD }, &lpc32xx_clcd_data);
  137. /*
  138. * AMBA SSP (SPI)
  139. */
  140. static void phy3250_spi_cs_set(u32 control)
  141. {
  142. gpio_set_value(SPI0_CS_GPIO, (int) control);
  143. }
  144. static struct pl022_config_chip spi0_chip_info = {
  145. .com_mode = INTERRUPT_TRANSFER,
  146. .iface = SSP_INTERFACE_MOTOROLA_SPI,
  147. .hierarchy = SSP_MASTER,
  148. .slave_tx_disable = 0,
  149. .rx_lev_trig = SSP_RX_4_OR_MORE_ELEM,
  150. .tx_lev_trig = SSP_TX_4_OR_MORE_EMPTY_LOC,
  151. .ctrl_len = SSP_BITS_8,
  152. .wait_state = SSP_MWIRE_WAIT_ZERO,
  153. .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX,
  154. .cs_control = phy3250_spi_cs_set,
  155. };
  156. static struct pl022_ssp_controller lpc32xx_ssp0_data = {
  157. .bus_id = 0,
  158. .num_chipselect = 1,
  159. .enable_dma = 0,
  160. };
  161. static AMBA_APB_DEVICE(lpc32xx_ssp0, "dev:ssp0", 0,
  162. LPC32XX_SSP0_BASE, { IRQ_LPC32XX_SSP0 }, &lpc32xx_ssp0_data);
  163. /* AT25 driver registration */
  164. static int __init phy3250_spi_board_register(void)
  165. {
  166. #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
  167. static struct spi_board_info info[] = {
  168. {
  169. .modalias = "spidev",
  170. .max_speed_hz = 5000000,
  171. .bus_num = 0,
  172. .chip_select = 0,
  173. .controller_data = &spi0_chip_info,
  174. },
  175. };
  176. #else
  177. static struct spi_eeprom eeprom = {
  178. .name = "at25256a",
  179. .byte_len = 0x8000,
  180. .page_size = 64,
  181. .flags = EE_ADDR2,
  182. };
  183. static struct spi_board_info info[] = {
  184. {
  185. .modalias = "at25",
  186. .max_speed_hz = 5000000,
  187. .bus_num = 0,
  188. .chip_select = 0,
  189. .mode = SPI_MODE_0,
  190. .platform_data = &eeprom,
  191. .controller_data = &spi0_chip_info,
  192. },
  193. };
  194. #endif
  195. return spi_register_board_info(info, ARRAY_SIZE(info));
  196. }
  197. arch_initcall(phy3250_spi_board_register);
  198. static struct i2c_board_info __initdata phy3250_i2c_board_info[] = {
  199. {
  200. I2C_BOARD_INFO("pcf8563", 0x51),
  201. },
  202. };
  203. static struct gpio_led phy_leds[] = {
  204. {
  205. .name = "led0",
  206. .gpio = LED_GPIO,
  207. .active_low = 1,
  208. .default_trigger = "heartbeat",
  209. },
  210. };
  211. static struct gpio_led_platform_data led_data = {
  212. .leds = phy_leds,
  213. .num_leds = ARRAY_SIZE(phy_leds),
  214. };
  215. static struct platform_device lpc32xx_gpio_led_device = {
  216. .name = "leds-gpio",
  217. .id = -1,
  218. .dev.platform_data = &led_data,
  219. };
  220. static struct platform_device *phy3250_devs[] __initdata = {
  221. &lpc32xx_i2c0_device,
  222. &lpc32xx_i2c1_device,
  223. &lpc32xx_i2c2_device,
  224. &lpc32xx_watchdog_device,
  225. &lpc32xx_gpio_led_device,
  226. };
  227. static struct amba_device *amba_devs[] __initdata = {
  228. &lpc32xx_clcd_device,
  229. &lpc32xx_ssp0_device,
  230. };
  231. /*
  232. * Board specific functions
  233. */
  234. static void __init phy3250_board_init(void)
  235. {
  236. u32 tmp;
  237. int i;
  238. lpc32xx_gpio_init();
  239. /* Register GPIOs used on this board */
  240. if (gpio_request(SPI0_CS_GPIO, "spi0 cs"))
  241. printk(KERN_ERR "Error requesting gpio %u",
  242. SPI0_CS_GPIO);
  243. else if (gpio_direction_output(SPI0_CS_GPIO, 1))
  244. printk(KERN_ERR "Error setting gpio %u to output",
  245. SPI0_CS_GPIO);
  246. /* Setup network interface for RMII mode */
  247. tmp = __raw_readl(LPC32XX_CLKPWR_MACCLK_CTRL);
  248. tmp &= ~LPC32XX_CLKPWR_MACCTRL_PINS_MSK;
  249. tmp |= LPC32XX_CLKPWR_MACCTRL_USE_RMII_PINS;
  250. __raw_writel(tmp, LPC32XX_CLKPWR_MACCLK_CTRL);
  251. /* Setup SLC NAND controller muxing */
  252. __raw_writel(LPC32XX_CLKPWR_NANDCLK_SEL_SLC,
  253. LPC32XX_CLKPWR_NAND_CLK_CTRL);
  254. /* Setup LCD muxing to RGB565 */
  255. tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL) &
  256. ~(LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_MSK |
  257. LPC32XX_CLKPWR_LCDCTRL_PSCALE_MSK);
  258. tmp |= LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_TFT16;
  259. __raw_writel(tmp, LPC32XX_CLKPWR_LCDCLK_CTRL);
  260. /* Set up I2C pull levels */
  261. tmp = __raw_readl(LPC32XX_CLKPWR_I2C_CLK_CTRL);
  262. tmp |= LPC32XX_CLKPWR_I2CCLK_USBI2CHI_DRIVE |
  263. LPC32XX_CLKPWR_I2CCLK_I2C2HI_DRIVE;
  264. __raw_writel(tmp, LPC32XX_CLKPWR_I2C_CLK_CTRL);
  265. /* Disable IrDA pulsing support on UART6 */
  266. tmp = __raw_readl(LPC32XX_UARTCTL_CTRL);
  267. tmp |= LPC32XX_UART_UART6_IRDAMOD_BYPASS;
  268. __raw_writel(tmp, LPC32XX_UARTCTL_CTRL);
  269. /* Enable DMA for I2S1 channel */
  270. tmp = __raw_readl(LPC32XX_CLKPWR_I2S_CLK_CTRL);
  271. tmp = LPC32XX_CLKPWR_I2SCTRL_I2S1_USE_DMA;
  272. __raw_writel(tmp, LPC32XX_CLKPWR_I2S_CLK_CTRL);
  273. lpc32xx_serial_init();
  274. /*
  275. * AMBA peripheral clocks need to be enabled prior to AMBA device
  276. * detection or a data fault will occur, so enable the clocks
  277. * here. However, we don't want to enable them if the peripheral
  278. * isn't included in the image
  279. */
  280. #ifdef CONFIG_FB_ARMCLCD
  281. tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL);
  282. __raw_writel((tmp | LPC32XX_CLKPWR_LCDCTRL_CLK_EN),
  283. LPC32XX_CLKPWR_LCDCLK_CTRL);
  284. #endif
  285. #ifdef CONFIG_SPI_PL022
  286. tmp = __raw_readl(LPC32XX_CLKPWR_SSP_CLK_CTRL);
  287. __raw_writel((tmp | LPC32XX_CLKPWR_SSPCTRL_SSPCLK0_EN),
  288. LPC32XX_CLKPWR_SSP_CLK_CTRL);
  289. #endif
  290. platform_add_devices(phy3250_devs, ARRAY_SIZE(phy3250_devs));
  291. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  292. struct amba_device *d = amba_devs[i];
  293. amba_device_register(d, &iomem_resource);
  294. }
  295. /* Test clock needed for UDA1380 initial init */
  296. __raw_writel(LPC32XX_CLKPWR_TESTCLK2_SEL_MOSC |
  297. LPC32XX_CLKPWR_TESTCLK_TESTCLK2_EN,
  298. LPC32XX_CLKPWR_TEST_CLK_SEL);
  299. i2c_register_board_info(0, phy3250_i2c_board_info,
  300. ARRAY_SIZE(phy3250_i2c_board_info));
  301. }
  302. static int __init lpc32xx_display_uid(void)
  303. {
  304. u32 uid[4];
  305. lpc32xx_get_uid(uid);
  306. printk(KERN_INFO "LPC32XX unique ID: %08x%08x%08x%08x\n",
  307. uid[3], uid[2], uid[1], uid[0]);
  308. return 1;
  309. }
  310. arch_initcall(lpc32xx_display_uid);
  311. MACHINE_START(PHY3250, "Phytec 3250 board with the LPC3250 Microcontroller")
  312. /* Maintainer: Kevin Wells, NXP Semiconductors */
  313. .atag_offset = 0x100,
  314. .map_io = lpc32xx_map_io,
  315. .init_irq = lpc32xx_init_irq,
  316. .timer = &lpc32xx_timer,
  317. .init_machine = phy3250_board_init,
  318. .restart = lpc23xx_restart,
  319. MACHINE_END