phy3250.c 9.5 KB

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