mrmt.c 10 KB

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