mrmt.c 10 KB

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