mrmt.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /*
  2. * Board-specific setup code for Remote Media Terminal 1 (RMT1)
  3. * add-on board for the ATNGW100 Network Gateway
  4. *
  5. * Copyright (C) 2008 Mediama Technologies
  6. * Based on ATNGW100 Network Gateway (Copyright (C) Atmel)
  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 version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/gpio.h>
  13. #include <linux/init.h>
  14. #include <linux/irq.h>
  15. #include <linux/linkage.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/types.h>
  18. #include <linux/fb.h>
  19. #include <linux/leds.h>
  20. #include <linux/input.h>
  21. #include <linux/gpio_keys.h>
  22. #include <linux/atmel_serial.h>
  23. #include <linux/spi/spi.h>
  24. #include <linux/spi/ads7846.h>
  25. #include <video/atmel_lcdc.h>
  26. #include <sound/atmel-ac97c.h>
  27. #include <asm/delay.h>
  28. #include <asm/io.h>
  29. #include <asm/setup.h>
  30. #include <mach/at32ap700x.h>
  31. #include <mach/board.h>
  32. #include <mach/init.h>
  33. #include <mach/portmux.h>
  34. /* Define board-specifoic GPIO assignments */
  35. #define PIN_LCD_BL GPIO_PIN_PA(28)
  36. #define PWM_CH_BL 0 /* Must match with GPIO pin definition */
  37. #define PIN_LCD_DISP GPIO_PIN_PA(31)
  38. #define PIN_AC97_RST_N GPIO_PIN_PA(30)
  39. #define PB_EXTINT_BASE 25
  40. #define TS_IRQ 0
  41. #define PIN_TS_EXTINT GPIO_PIN_PB(PB_EXTINT_BASE+TS_IRQ)
  42. #define PIN_PB_LEFT GPIO_PIN_PB(11)
  43. #define PIN_PB_RIGHT GPIO_PIN_PB(12)
  44. #define PIN_PWR_SW_N GPIO_PIN_PB(14)
  45. #define PIN_PWR_ON GPIO_PIN_PB(13)
  46. #define PIN_ZB_RST_N GPIO_PIN_PA(21)
  47. #define PIN_BT_RST GPIO_PIN_PA(22)
  48. #define PIN_LED_SYS GPIO_PIN_PA(16)
  49. #define PIN_LED_A GPIO_PIN_PA(19)
  50. #define PIN_LED_B GPIO_PIN_PE(19)
  51. #ifdef CONFIG_BOARD_MRMT_LCD_LQ043T3DX0X
  52. /* Sharp LQ043T3DX0x (or compatible) panel */
  53. static struct fb_videomode __initdata lcd_fb_modes[] = {
  54. {
  55. .name = "480x272 @ 59.94Hz",
  56. .refresh = 59.94,
  57. .xres = 480, .yres = 272,
  58. .pixclock = KHZ2PICOS(9000),
  59. .left_margin = 2, .right_margin = 2,
  60. .upper_margin = 3, .lower_margin = 9,
  61. .hsync_len = 41, .vsync_len = 1,
  62. .sync = 0,
  63. .vmode = FB_VMODE_NONINTERLACED,
  64. },
  65. };
  66. static struct fb_monspecs __initdata lcd_fb_default_monspecs = {
  67. .manufacturer = "SHA",
  68. .monitor = "LQ043T3DX02",
  69. .modedb = lcd_fb_modes,
  70. .modedb_len = ARRAY_SIZE(lcd_fb_modes),
  71. .hfmin = 14915,
  72. .hfmax = 17638,
  73. .vfmin = 53,
  74. .vfmax = 61,
  75. .dclkmax = 9260000,
  76. };
  77. static struct atmel_lcdfb_info __initdata rmt_lcdc_data = {
  78. .default_bpp = 24,
  79. .default_dmacon = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN,
  80. .default_lcdcon2 = (ATMEL_LCDC_DISTYPE_TFT
  81. | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE
  82. | ATMEL_LCDC_INVCLK_NORMAL
  83. | ATMEL_LCDC_MEMOR_BIG),
  84. .lcd_wiring_mode = ATMEL_LCDC_WIRING_RGB,
  85. .default_monspecs = &lcd_fb_default_monspecs,
  86. .guard_time = 2,
  87. };
  88. #endif
  89. #ifdef CONFIG_BOARD_MRMT_LCD_KWH043GM08
  90. /* Sharp KWH043GM08-Fxx (or compatible) panel */
  91. static struct fb_videomode __initdata lcd_fb_modes[] = {
  92. {
  93. .name = "480x272 @ 59.94Hz",
  94. .refresh = 59.94,
  95. .xres = 480, .yres = 272,
  96. .pixclock = KHZ2PICOS(9000),
  97. .left_margin = 2, .right_margin = 2,
  98. .upper_margin = 3, .lower_margin = 9,
  99. .hsync_len = 41, .vsync_len = 1,
  100. .sync = 0,
  101. .vmode = FB_VMODE_NONINTERLACED,
  102. },
  103. };
  104. static struct fb_monspecs __initdata lcd_fb_default_monspecs = {
  105. .manufacturer = "FOR",
  106. .monitor = "KWH043GM08",
  107. .modedb = lcd_fb_modes,
  108. .modedb_len = ARRAY_SIZE(lcd_fb_modes),
  109. .hfmin = 14915,
  110. .hfmax = 17638,
  111. .vfmin = 53,
  112. .vfmax = 61,
  113. .dclkmax = 9260000,
  114. };
  115. static struct atmel_lcdfb_info __initdata rmt_lcdc_data = {
  116. .default_bpp = 24,
  117. .default_dmacon = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN,
  118. .default_lcdcon2 = (ATMEL_LCDC_DISTYPE_TFT
  119. | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE
  120. | ATMEL_LCDC_INVCLK_INVERTED
  121. | ATMEL_LCDC_MEMOR_BIG),
  122. .lcd_wiring_mode = ATMEL_LCDC_WIRING_RGB,
  123. .default_monspecs = &lcd_fb_default_monspecs,
  124. .guard_time = 2,
  125. };
  126. #endif
  127. #ifdef CONFIG_BOARD_MRMT_AC97
  128. static struct ac97c_platform_data __initdata ac97c0_data = {
  129. .reset_pin = PIN_AC97_RST_N,
  130. };
  131. #endif
  132. #ifdef CONFIG_BOARD_MRMT_UCB1400_TS
  133. /* NOTE: IRQ assignment relies on kernel module parameter */
  134. static struct platform_device rmt_ts_device = {
  135. .name = "ucb1400_ts",
  136. .id = -1,
  137. }
  138. };
  139. #endif
  140. #ifdef CONFIG_BOARD_MRMT_BL_PWM
  141. /* PWM LEDs: LCD Backlight, etc */
  142. static struct gpio_led rmt_pwm_led[] = {
  143. /* here the "gpio" is actually a PWM channel */
  144. { .name = "backlight", .gpio = PWM_CH_BL, },
  145. };
  146. static struct gpio_led_platform_data rmt_pwm_led_data = {
  147. .num_leds = ARRAY_SIZE(rmt_pwm_led),
  148. .leds = rmt_pwm_led,
  149. };
  150. static struct platform_device rmt_pwm_led_dev = {
  151. .name = "leds-atmel-pwm",
  152. .id = -1,
  153. .dev = {
  154. .platform_data = &rmt_pwm_led_data,
  155. },
  156. };
  157. #endif
  158. #ifdef CONFIG_BOARD_MRMT_ADS7846_TS
  159. static int ads7846_pendown_state(void)
  160. {
  161. return !gpio_get_value( PIN_TS_EXTINT ); /* PENIRQ.*/
  162. }
  163. static struct ads7846_platform_data ads_info = {
  164. .model = 7846,
  165. .keep_vref_on = 0, /* Use external VREF pin */
  166. .vref_delay_usecs = 0,
  167. .vref_mv = 3300, /* VREF = 3.3V */
  168. .settle_delay_usecs = 800,
  169. .penirq_recheck_delay_usecs = 800,
  170. .x_plate_ohms = 750,
  171. .y_plate_ohms = 300,
  172. .pressure_max = 4096,
  173. .debounce_max = 1,
  174. .debounce_rep = 0,
  175. .debounce_tol = (~0),
  176. .get_pendown_state = ads7846_pendown_state,
  177. .filter = NULL,
  178. .filter_init = NULL,
  179. };
  180. static struct spi_board_info spi01_board_info[] __initdata = {
  181. {
  182. .modalias = "ads7846",
  183. .max_speed_hz = 31250*26,
  184. .bus_num = 0,
  185. .chip_select = 1,
  186. .platform_data = &ads_info,
  187. .irq = AT32_EXTINT(TS_IRQ),
  188. },
  189. };
  190. #endif
  191. /* GPIO Keys: left, right, power, etc */
  192. static const struct gpio_keys_button rmt_gpio_keys_buttons[] = {
  193. [0] = {
  194. .type = EV_KEY,
  195. .code = KEY_POWER,
  196. .gpio = PIN_PWR_SW_N,
  197. .active_low = 1,
  198. .desc = "power button",
  199. },
  200. [1] = {
  201. .type = EV_KEY,
  202. .code = KEY_LEFT,
  203. .gpio = PIN_PB_LEFT,
  204. .active_low = 1,
  205. .desc = "left button",
  206. },
  207. [2] = {
  208. .type = EV_KEY,
  209. .code = KEY_RIGHT,
  210. .gpio = PIN_PB_RIGHT,
  211. .active_low = 1,
  212. .desc = "right button",
  213. },
  214. };
  215. static const struct gpio_keys_platform_data rmt_gpio_keys_data = {
  216. .nbuttons = ARRAY_SIZE(rmt_gpio_keys_buttons),
  217. .buttons = (void *) rmt_gpio_keys_buttons,
  218. };
  219. static struct platform_device rmt_gpio_keys = {
  220. .name = "gpio-keys",
  221. .id = -1,
  222. .dev = {
  223. .platform_data = (void *) &rmt_gpio_keys_data,
  224. }
  225. };
  226. #ifdef CONFIG_BOARD_MRMT_RTC_I2C
  227. static struct i2c_board_info __initdata mrmt1_i2c_rtc = {
  228. I2C_BOARD_INFO("s35390a", 0x30),
  229. .irq = 0,
  230. };
  231. #endif
  232. static void mrmt_power_off(void)
  233. {
  234. /* PWR_ON=0 will force power off */
  235. gpio_set_value( PIN_PWR_ON, 0 );
  236. }
  237. static int __init mrmt1_init(void)
  238. {
  239. gpio_set_value( PIN_PWR_ON, 1 ); /* Ensure PWR_ON is enabled */
  240. pm_power_off = mrmt_power_off;
  241. /* Setup USARTS (other than console) */
  242. at32_map_usart(2, 1, 0); /* USART 2: /dev/ttyS1, RMT1:DB9M */
  243. at32_map_usart(3, 2, ATMEL_USART_RTS | ATMEL_USART_CTS);
  244. /* USART 3: /dev/ttyS2, RMT1:Wireless, w/ RTS/CTS */
  245. at32_add_device_usart(1);
  246. at32_add_device_usart(2);
  247. /* Select GPIO Key pins */
  248. at32_select_gpio( PIN_PWR_SW_N, AT32_GPIOF_DEGLITCH);
  249. at32_select_gpio( PIN_PB_LEFT, AT32_GPIOF_DEGLITCH);
  250. at32_select_gpio( PIN_PB_RIGHT, AT32_GPIOF_DEGLITCH);
  251. platform_device_register(&rmt_gpio_keys);
  252. #ifdef CONFIG_BOARD_MRMT_RTC_I2C
  253. i2c_register_board_info(0, &mrmt1_i2c_rtc, 1);
  254. #endif
  255. #ifndef CONFIG_BOARD_MRMT_LCD_DISABLE
  256. /* User "alternate" LCDC inferface on Port E & D */
  257. /* NB: exclude LCDC_CC pin, as NGW100 reserves it for other use */
  258. at32_add_device_lcdc(0, &rmt_lcdc_data,
  259. fbmem_start, fbmem_size,
  260. (ATMEL_LCDC_ALT_24BIT | ATMEL_LCDC_PE_DVAL ) );
  261. #endif
  262. #ifdef CONFIG_BOARD_MRMT_AC97
  263. at32_add_device_ac97c(0, &ac97c0_data, AC97C_BOTH);
  264. #endif
  265. #ifdef CONFIG_BOARD_MRMT_ADS7846_TS
  266. /* Select the Touchscreen interrupt pin mode */
  267. at32_select_periph( GPIO_PIOB_BASE, 1 << (PB_EXTINT_BASE+TS_IRQ),
  268. GPIO_PERIPH_A, AT32_GPIOF_DEGLITCH);
  269. irq_set_irq_type(AT32_EXTINT(TS_IRQ), IRQ_TYPE_EDGE_FALLING);
  270. at32_spi_setup_slaves(0,spi01_board_info,ARRAY_SIZE(spi01_board_info));
  271. spi_register_board_info(spi01_board_info,ARRAY_SIZE(spi01_board_info));
  272. #endif
  273. #ifdef CONFIG_BOARD_MRMT_UCB1400_TS
  274. /* Select the Touchscreen interrupt pin mode */
  275. at32_select_periph( GPIO_PIOB_BASE, 1 << (PB_EXTINT_BASE+TS_IRQ),
  276. GPIO_PERIPH_A, AT32_GPIOF_DEGLITCH);
  277. platform_device_register(&rmt_ts_device);
  278. #endif
  279. at32_select_gpio( PIN_LCD_DISP, AT32_GPIOF_OUTPUT );
  280. gpio_request( PIN_LCD_DISP, "LCD_DISP" );
  281. gpio_direction_output( PIN_LCD_DISP, 0 ); /* LCD DISP */
  282. #ifdef CONFIG_BOARD_MRMT_LCD_DISABLE
  283. /* Keep Backlight and DISP off */
  284. at32_select_gpio( PIN_LCD_BL, AT32_GPIOF_OUTPUT );
  285. gpio_request( PIN_LCD_BL, "LCD_BL" );
  286. gpio_direction_output( PIN_LCD_BL, 0 ); /* Backlight */
  287. #else
  288. gpio_set_value( PIN_LCD_DISP, 1 ); /* DISP asserted first */
  289. #ifdef CONFIG_BOARD_MRMT_BL_PWM
  290. /* Use PWM for Backlight controls */
  291. at32_add_device_pwm(1 << PWM_CH_BL);
  292. platform_device_register(&rmt_pwm_led_dev);
  293. #else
  294. /* Backlight always on */
  295. udelay( 1 );
  296. at32_select_gpio( PIN_LCD_BL, AT32_GPIOF_OUTPUT );
  297. gpio_request( PIN_LCD_BL, "LCD_BL" );
  298. gpio_direction_output( PIN_LCD_BL, 1 );
  299. #endif
  300. #endif
  301. /* Make sure BT and Zigbee modules in reset */
  302. at32_select_gpio( PIN_BT_RST, AT32_GPIOF_OUTPUT );
  303. gpio_request( PIN_BT_RST, "BT_RST" );
  304. gpio_direction_output( PIN_BT_RST, 1 );
  305. /* BT Module in Reset */
  306. at32_select_gpio( PIN_ZB_RST_N, AT32_GPIOF_OUTPUT );
  307. gpio_request( PIN_ZB_RST_N, "ZB_RST_N" );
  308. gpio_direction_output( PIN_ZB_RST_N, 0 );
  309. /* XBee Module in Reset */
  310. #ifdef CONFIG_BOARD_MRMT_WIRELESS_ZB
  311. udelay( 1000 );
  312. /* Unreset the XBee Module */
  313. gpio_set_value( PIN_ZB_RST_N, 1 );
  314. #endif
  315. #ifdef CONFIG_BOARD_MRMT_WIRELESS_BT
  316. udelay( 1000 );
  317. /* Unreset the BT Module */
  318. gpio_set_value( PIN_BT_RST, 0 );
  319. #endif
  320. return 0;
  321. }
  322. arch_initcall(mrmt1_init);
  323. static int __init mrmt1_early_init(void)
  324. {
  325. /* To maintain power-on signal in case boot loader did not already */
  326. at32_select_gpio( PIN_PWR_ON, AT32_GPIOF_OUTPUT );
  327. gpio_request( PIN_PWR_ON, "PIN_PWR_ON" );
  328. gpio_direction_output( PIN_PWR_ON, 1 );
  329. return 0;
  330. }
  331. core_initcall(mrmt1_early_init);