mioa701.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. /*
  2. * Handles the Mitac Mio A701 Board
  3. *
  4. * Copyright (C) 2008 Robert Jarzmik
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/sysdev.h>
  25. #include <linux/input.h>
  26. #include <linux/delay.h>
  27. #include <linux/gpio_keys.h>
  28. #include <linux/pwm_backlight.h>
  29. #include <linux/rtc.h>
  30. #include <linux/leds.h>
  31. #include <linux/gpio.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/irq.h>
  34. #include <linux/pda_power.h>
  35. #include <linux/power_supply.h>
  36. #include <linux/wm97xx_batt.h>
  37. #include <linux/mtd/physmap.h>
  38. #include <asm/mach-types.h>
  39. #include <asm/mach/arch.h>
  40. #include <mach/mfp-pxa27x.h>
  41. #include <mach/pxa27x_keypad.h>
  42. #include <mach/pxafb.h>
  43. #include <mach/pxa2xx-regs.h>
  44. #include <mach/mmc.h>
  45. #include <mach/udc.h>
  46. #include <mach/pxa27x-udc.h>
  47. #include <mach/i2c.h>
  48. #include <mach/camera.h>
  49. #include <media/soc_camera.h>
  50. #include <mach/mioa701.h>
  51. #include "generic.h"
  52. #include "devices.h"
  53. static unsigned long mioa701_pin_config[] = {
  54. /* Mio global */
  55. MIO_CFG_OUT(GPIO9_CHARGE_EN, AF0, DRIVE_LOW),
  56. MIO_CFG_OUT(GPIO18_POWEROFF, AF0, DRIVE_LOW),
  57. MFP_CFG_OUT(GPIO3, AF0, DRIVE_HIGH),
  58. MFP_CFG_OUT(GPIO4, AF0, DRIVE_HIGH),
  59. MIO_CFG_IN(GPIO80_MAYBE_CHARGE_VDROP, AF0),
  60. /* Backlight PWM 0 */
  61. GPIO16_PWM0_OUT,
  62. /* MMC */
  63. GPIO32_MMC_CLK,
  64. GPIO92_MMC_DAT_0,
  65. GPIO109_MMC_DAT_1,
  66. GPIO110_MMC_DAT_2,
  67. GPIO111_MMC_DAT_3,
  68. GPIO112_MMC_CMD,
  69. MIO_CFG_IN(GPIO78_SDIO_RO, AF0),
  70. MIO_CFG_IN(GPIO15_SDIO_INSERT, AF0),
  71. MIO_CFG_OUT(GPIO91_SDIO_EN, AF0, DRIVE_LOW),
  72. /* USB */
  73. MIO_CFG_IN(GPIO13_nUSB_DETECT, AF0),
  74. MIO_CFG_OUT(GPIO22_USB_ENABLE, AF0, DRIVE_LOW),
  75. /* LCD */
  76. GPIO58_LCD_LDD_0,
  77. GPIO59_LCD_LDD_1,
  78. GPIO60_LCD_LDD_2,
  79. GPIO61_LCD_LDD_3,
  80. GPIO62_LCD_LDD_4,
  81. GPIO63_LCD_LDD_5,
  82. GPIO64_LCD_LDD_6,
  83. GPIO65_LCD_LDD_7,
  84. GPIO66_LCD_LDD_8,
  85. GPIO67_LCD_LDD_9,
  86. GPIO68_LCD_LDD_10,
  87. GPIO69_LCD_LDD_11,
  88. GPIO70_LCD_LDD_12,
  89. GPIO71_LCD_LDD_13,
  90. GPIO72_LCD_LDD_14,
  91. GPIO73_LCD_LDD_15,
  92. GPIO74_LCD_FCLK,
  93. GPIO75_LCD_LCLK,
  94. GPIO76_LCD_PCLK,
  95. /* QCI */
  96. GPIO12_CIF_DD_7,
  97. GPIO17_CIF_DD_6,
  98. GPIO50_CIF_DD_3,
  99. GPIO51_CIF_DD_2,
  100. GPIO52_CIF_DD_4,
  101. GPIO53_CIF_MCLK,
  102. GPIO54_CIF_PCLK,
  103. GPIO55_CIF_DD_1,
  104. GPIO81_CIF_DD_0,
  105. GPIO82_CIF_DD_5,
  106. GPIO84_CIF_FV,
  107. GPIO85_CIF_LV,
  108. /* Bluetooth */
  109. MIO_CFG_IN(GPIO14_BT_nACTIVITY, AF0),
  110. GPIO44_BTUART_CTS,
  111. GPIO42_BTUART_RXD,
  112. GPIO45_BTUART_RTS,
  113. GPIO43_BTUART_TXD,
  114. MIO_CFG_OUT(GPIO83_BT_ON, AF0, DRIVE_LOW),
  115. MIO_CFG_OUT(GPIO77_BT_UNKNOWN1, AF0, DRIVE_HIGH),
  116. MIO_CFG_OUT(GPIO86_BT_MAYBE_nRESET, AF0, DRIVE_HIGH),
  117. /* GPS */
  118. MIO_CFG_OUT(GPIO23_GPS_UNKNOWN1, AF0, DRIVE_LOW),
  119. MIO_CFG_OUT(GPIO26_GPS_ON, AF0, DRIVE_LOW),
  120. MIO_CFG_OUT(GPIO27_GPS_RESET, AF0, DRIVE_LOW),
  121. MIO_CFG_OUT(GPIO106_GPS_UNKNOWN2, AF0, DRIVE_LOW),
  122. MIO_CFG_OUT(GPIO107_GPS_UNKNOWN3, AF0, DRIVE_LOW),
  123. GPIO46_STUART_RXD,
  124. GPIO47_STUART_TXD,
  125. /* GSM */
  126. MIO_CFG_OUT(GPIO24_GSM_MOD_RESET_CMD, AF0, DRIVE_LOW),
  127. MIO_CFG_OUT(GPIO88_GSM_nMOD_ON_CMD, AF0, DRIVE_HIGH),
  128. MIO_CFG_OUT(GPIO90_GSM_nMOD_OFF_CMD, AF0, DRIVE_HIGH),
  129. MIO_CFG_OUT(GPIO114_GSM_nMOD_DTE_UART_STATE, AF0, DRIVE_HIGH),
  130. MIO_CFG_IN(GPIO25_GSM_MOD_ON_STATE, AF0),
  131. MIO_CFG_IN(GPIO113_GSM_EVENT, AF0) | WAKEUP_ON_EDGE_BOTH,
  132. GPIO34_FFUART_RXD,
  133. GPIO35_FFUART_CTS,
  134. GPIO36_FFUART_DCD,
  135. GPIO37_FFUART_DSR,
  136. GPIO39_FFUART_TXD,
  137. GPIO40_FFUART_DTR,
  138. GPIO41_FFUART_RTS,
  139. /* Sound */
  140. GPIO89_AC97_SYSCLK,
  141. MIO_CFG_IN(GPIO12_HPJACK_INSERT, AF0),
  142. /* Leds */
  143. MIO_CFG_OUT(GPIO10_LED_nCharging, AF0, DRIVE_HIGH),
  144. MIO_CFG_OUT(GPIO97_LED_nBlue, AF0, DRIVE_HIGH),
  145. MIO_CFG_OUT(GPIO98_LED_nOrange, AF0, DRIVE_HIGH),
  146. MIO_CFG_OUT(GPIO82_LED_nVibra, AF0, DRIVE_HIGH),
  147. MIO_CFG_OUT(GPIO115_LED_nKeyboard, AF0, DRIVE_HIGH),
  148. /* Keyboard */
  149. MIO_CFG_IN(GPIO0_KEY_POWER, AF0) | WAKEUP_ON_EDGE_BOTH,
  150. MIO_CFG_IN(GPIO93_KEY_VOLUME_UP, AF0),
  151. MIO_CFG_IN(GPIO94_KEY_VOLUME_DOWN, AF0),
  152. GPIO100_KP_MKIN_0,
  153. GPIO101_KP_MKIN_1,
  154. GPIO102_KP_MKIN_2,
  155. GPIO103_KP_MKOUT_0,
  156. GPIO104_KP_MKOUT_1,
  157. GPIO105_KP_MKOUT_2,
  158. /* I2C */
  159. GPIO117_I2C_SCL,
  160. GPIO118_I2C_SDA,
  161. /* Unknown */
  162. MFP_CFG_IN(GPIO20, AF0),
  163. MFP_CFG_IN(GPIO21, AF0),
  164. MFP_CFG_IN(GPIO33, AF0),
  165. MFP_CFG_OUT(GPIO49, AF0, DRIVE_HIGH),
  166. MFP_CFG_OUT(GPIO57, AF0, DRIVE_HIGH),
  167. MFP_CFG_IN(GPIO96, AF0),
  168. MFP_CFG_OUT(GPIO116, AF0, DRIVE_HIGH),
  169. };
  170. #define MIO_GPIO_IN(num, _desc) \
  171. { .gpio = (num), .dir = 0, .desc = (_desc) }
  172. #define MIO_GPIO_OUT(num, _init, _desc) \
  173. { .gpio = (num), .dir = 1, .init = (_init), .desc = (_desc) }
  174. struct gpio_ress {
  175. unsigned gpio : 8;
  176. unsigned dir : 1;
  177. unsigned init : 1;
  178. char *desc;
  179. };
  180. static int mio_gpio_request(struct gpio_ress *gpios, int size)
  181. {
  182. int i, rc = 0;
  183. int gpio;
  184. int dir;
  185. for (i = 0; (!rc) && (i < size); i++) {
  186. gpio = gpios[i].gpio;
  187. dir = gpios[i].dir;
  188. rc = gpio_request(gpio, gpios[i].desc);
  189. if (rc) {
  190. printk(KERN_ERR "Error requesting GPIO %d(%s) : %d\n",
  191. gpio, gpios[i].desc, rc);
  192. continue;
  193. }
  194. if (dir)
  195. gpio_direction_output(gpio, gpios[i].init);
  196. else
  197. gpio_direction_input(gpio);
  198. }
  199. while ((rc) && (--i >= 0))
  200. gpio_free(gpios[i].gpio);
  201. return rc;
  202. }
  203. static void mio_gpio_free(struct gpio_ress *gpios, int size)
  204. {
  205. int i;
  206. for (i = 0; i < size; i++)
  207. gpio_free(gpios[i].gpio);
  208. }
  209. /* LCD Screen and Backlight */
  210. static struct platform_pwm_backlight_data mioa701_backlight_data = {
  211. .pwm_id = 0,
  212. .max_brightness = 100,
  213. .dft_brightness = 50,
  214. .pwm_period_ns = 4000 * 1024, /* Fl = 250kHz */
  215. };
  216. /*
  217. * LTM0305A776C LCD panel timings
  218. *
  219. * see:
  220. * - the LTM0305A776C datasheet,
  221. * - and the PXA27x Programmers' manual
  222. */
  223. static struct pxafb_mode_info mioa701_ltm0305a776c = {
  224. .pixclock = 220000, /* CLK=4.545 MHz */
  225. .xres = 240,
  226. .yres = 320,
  227. .bpp = 16,
  228. .hsync_len = 4,
  229. .vsync_len = 2,
  230. .left_margin = 6,
  231. .right_margin = 4,
  232. .upper_margin = 5,
  233. .lower_margin = 3,
  234. };
  235. static void mioa701_lcd_power(int on, struct fb_var_screeninfo *si)
  236. {
  237. gpio_set_value(GPIO87_LCD_POWER, on);
  238. }
  239. static struct pxafb_mach_info mioa701_pxafb_info = {
  240. .modes = &mioa701_ltm0305a776c,
  241. .num_modes = 1,
  242. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  243. .pxafb_lcd_power = mioa701_lcd_power,
  244. };
  245. /*
  246. * Keyboard configuration
  247. */
  248. static unsigned int mioa701_matrix_keys[] = {
  249. KEY(0, 0, KEY_UP),
  250. KEY(0, 1, KEY_RIGHT),
  251. KEY(0, 2, KEY_MEDIA),
  252. KEY(1, 0, KEY_DOWN),
  253. KEY(1, 1, KEY_ENTER),
  254. KEY(1, 2, KEY_CONNECT), /* GPS key */
  255. KEY(2, 0, KEY_LEFT),
  256. KEY(2, 1, KEY_PHONE), /* Phone Green key */
  257. KEY(2, 2, KEY_CAMERA) /* Camera key */
  258. };
  259. static struct pxa27x_keypad_platform_data mioa701_keypad_info = {
  260. .matrix_key_rows = 3,
  261. .matrix_key_cols = 3,
  262. .matrix_key_map = mioa701_matrix_keys,
  263. .matrix_key_map_size = ARRAY_SIZE(mioa701_matrix_keys),
  264. };
  265. /*
  266. * GPIO Key Configuration
  267. */
  268. #define MIO_KEY(key, _gpio, _desc, _wakeup) \
  269. { .code = (key), .gpio = (_gpio), .active_low = 0, \
  270. .desc = (_desc), .type = EV_KEY, .wakeup = (_wakeup) }
  271. static struct gpio_keys_button mioa701_button_table[] = {
  272. MIO_KEY(KEY_EXIT, GPIO0_KEY_POWER, "Power button", 1),
  273. MIO_KEY(KEY_VOLUMEUP, GPIO93_KEY_VOLUME_UP, "Volume up", 0),
  274. MIO_KEY(KEY_VOLUMEDOWN, GPIO94_KEY_VOLUME_DOWN, "Volume down", 0),
  275. MIO_KEY(KEY_HP, GPIO12_HPJACK_INSERT, "HP jack detect", 0)
  276. };
  277. static struct gpio_keys_platform_data mioa701_gpio_keys_data = {
  278. .buttons = mioa701_button_table,
  279. .nbuttons = ARRAY_SIZE(mioa701_button_table),
  280. };
  281. /*
  282. * Leds and vibrator
  283. */
  284. #define ONE_LED(_gpio, _name) \
  285. { .gpio = (_gpio), .name = (_name), .active_low = true }
  286. static struct gpio_led gpio_leds[] = {
  287. ONE_LED(GPIO10_LED_nCharging, "mioa701:charging"),
  288. ONE_LED(GPIO97_LED_nBlue, "mioa701:blue"),
  289. ONE_LED(GPIO98_LED_nOrange, "mioa701:orange"),
  290. ONE_LED(GPIO82_LED_nVibra, "mioa701:vibra"),
  291. ONE_LED(GPIO115_LED_nKeyboard, "mioa701:keyboard")
  292. };
  293. static struct gpio_led_platform_data gpio_led_info = {
  294. .leds = gpio_leds,
  295. .num_leds = ARRAY_SIZE(gpio_leds),
  296. };
  297. /*
  298. * GSM Sagem XS200 chip
  299. *
  300. * GSM handling was purged from kernel. For history, this is the way to go :
  301. * - init : GPIO24_GSM_MOD_RESET_CMD = 0, GPIO114_GSM_nMOD_DTE_UART_STATE = 1
  302. * GPIO88_GSM_nMOD_ON_CMD = 1, GPIO90_GSM_nMOD_OFF_CMD = 1
  303. * - reset : GPIO24_GSM_MOD_RESET_CMD = 1, msleep(100),
  304. * GPIO24_GSM_MOD_RESET_CMD = 0
  305. * - turn on : GPIO88_GSM_nMOD_ON_CMD = 0, msleep(1000),
  306. * GPIO88_GSM_nMOD_ON_CMD = 1
  307. * - turn off : GPIO90_GSM_nMOD_OFF_CMD = 0, msleep(1000),
  308. * GPIO90_GSM_nMOD_OFF_CMD = 1
  309. */
  310. static int is_gsm_on(void)
  311. {
  312. int is_on;
  313. is_on = !!gpio_get_value(GPIO25_GSM_MOD_ON_STATE);
  314. return is_on;
  315. }
  316. irqreturn_t gsm_on_irq(int irq, void *p)
  317. {
  318. printk(KERN_DEBUG "Mioa701: GSM status changed to %s\n",
  319. is_gsm_on() ? "on" : "off");
  320. return IRQ_HANDLED;
  321. }
  322. struct gpio_ress gsm_gpios[] = {
  323. MIO_GPIO_IN(GPIO25_GSM_MOD_ON_STATE, "GSM state"),
  324. MIO_GPIO_IN(GPIO113_GSM_EVENT, "GSM event"),
  325. };
  326. static int __init gsm_init(void)
  327. {
  328. int rc;
  329. rc = mio_gpio_request(ARRAY_AND_SIZE(gsm_gpios));
  330. if (rc)
  331. goto err_gpio;
  332. rc = request_irq(gpio_to_irq(GPIO25_GSM_MOD_ON_STATE), gsm_on_irq,
  333. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  334. "GSM XS200 Power Irq", NULL);
  335. if (rc)
  336. goto err_irq;
  337. gpio_set_wake(GPIO113_GSM_EVENT, 1);
  338. return 0;
  339. err_irq:
  340. printk(KERN_ERR "Mioa701: Can't request GSM_ON irq\n");
  341. mio_gpio_free(ARRAY_AND_SIZE(gsm_gpios));
  342. err_gpio:
  343. printk(KERN_ERR "Mioa701: gsm not available\n");
  344. return rc;
  345. }
  346. static void gsm_exit(void)
  347. {
  348. free_irq(gpio_to_irq(GPIO25_GSM_MOD_ON_STATE), NULL);
  349. mio_gpio_free(ARRAY_AND_SIZE(gsm_gpios));
  350. }
  351. /*
  352. * Bluetooth BRF6150 chip
  353. *
  354. * BT handling was purged from kernel. For history, this is the way to go :
  355. * - turn on : GPIO83_BT_ON = 1
  356. * - turn off : GPIO83_BT_ON = 0
  357. */
  358. /*
  359. * GPS Sirf Star III chip
  360. *
  361. * GPS handling was purged from kernel. For history, this is the way to go :
  362. * - init : GPIO23_GPS_UNKNOWN1 = 1, GPIO26_GPS_ON = 0, GPIO27_GPS_RESET = 0
  363. * GPIO106_GPS_UNKNOWN2 = 0, GPIO107_GPS_UNKNOWN3 = 0
  364. * - turn on : GPIO27_GPS_RESET = 1, GPIO26_GPS_ON = 1
  365. * - turn off : GPIO26_GPS_ON = 0, GPIO27_GPS_RESET = 0
  366. */
  367. /*
  368. * USB UDC
  369. */
  370. static void udc_power_command(int cmd)
  371. {
  372. switch (cmd) {
  373. case PXA2XX_UDC_CMD_DISCONNECT:
  374. gpio_set_value(GPIO22_USB_ENABLE, 0);
  375. break;
  376. case PXA2XX_UDC_CMD_CONNECT:
  377. gpio_set_value(GPIO22_USB_ENABLE, 1);
  378. break;
  379. default:
  380. printk(KERN_INFO "udc_control: unknown command (0x%x)!\n", cmd);
  381. break;
  382. }
  383. }
  384. static int is_usb_connected(void)
  385. {
  386. return !gpio_get_value(GPIO13_nUSB_DETECT);
  387. }
  388. static struct pxa2xx_udc_mach_info mioa701_udc_info = {
  389. .udc_is_connected = is_usb_connected,
  390. .udc_command = udc_power_command,
  391. };
  392. struct gpio_ress udc_gpios[] = {
  393. MIO_GPIO_OUT(GPIO22_USB_ENABLE, 0, "USB Vbus enable")
  394. };
  395. static int __init udc_init(void)
  396. {
  397. pxa_set_udc_info(&mioa701_udc_info);
  398. return mio_gpio_request(ARRAY_AND_SIZE(udc_gpios));
  399. }
  400. static void udc_exit(void)
  401. {
  402. mio_gpio_free(ARRAY_AND_SIZE(udc_gpios));
  403. }
  404. /*
  405. * SDIO/MMC Card controller
  406. */
  407. static void mci_setpower(struct device *dev, unsigned int vdd)
  408. {
  409. struct pxamci_platform_data *p_d = dev->platform_data;
  410. if ((1 << vdd) & p_d->ocr_mask)
  411. gpio_set_value(GPIO91_SDIO_EN, 1); /* enable SDIO power */
  412. else
  413. gpio_set_value(GPIO91_SDIO_EN, 0); /* disable SDIO power */
  414. }
  415. static int mci_get_ro(struct device *dev)
  416. {
  417. return gpio_get_value(GPIO78_SDIO_RO);
  418. }
  419. struct gpio_ress mci_gpios[] = {
  420. MIO_GPIO_IN(GPIO78_SDIO_RO, "SDIO readonly detect"),
  421. MIO_GPIO_IN(GPIO15_SDIO_INSERT, "SDIO insertion detect"),
  422. MIO_GPIO_OUT(GPIO91_SDIO_EN, 0, "SDIO power enable")
  423. };
  424. static void mci_exit(struct device *dev, void *data)
  425. {
  426. mio_gpio_free(ARRAY_AND_SIZE(mci_gpios));
  427. free_irq(gpio_to_irq(GPIO15_SDIO_INSERT), data);
  428. }
  429. static struct pxamci_platform_data mioa701_mci_info;
  430. /**
  431. * The card detect interrupt isn't debounced so we delay it by 250ms
  432. * to give the card a chance to fully insert/eject.
  433. */
  434. static int mci_init(struct device *dev, irq_handler_t detect_int, void *data)
  435. {
  436. int rc;
  437. int irq = gpio_to_irq(GPIO15_SDIO_INSERT);
  438. rc = mio_gpio_request(ARRAY_AND_SIZE(mci_gpios));
  439. if (rc)
  440. goto err_gpio;
  441. /* enable RE/FE interrupt on card insertion and removal */
  442. rc = request_irq(irq, detect_int,
  443. IRQF_DISABLED | IRQF_TRIGGER_RISING |
  444. IRQF_TRIGGER_FALLING,
  445. "MMC card detect", data);
  446. if (rc)
  447. goto err_irq;
  448. mioa701_mci_info.detect_delay = msecs_to_jiffies(250);
  449. return 0;
  450. err_irq:
  451. dev_err(dev, "mioa701_mci_init: MMC/SD:"
  452. " can't request MMC card detect IRQ\n");
  453. mio_gpio_free(ARRAY_AND_SIZE(mci_gpios));
  454. err_gpio:
  455. return rc;
  456. }
  457. static struct pxamci_platform_data mioa701_mci_info = {
  458. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  459. .init = mci_init,
  460. .get_ro = mci_get_ro,
  461. .setpower = mci_setpower,
  462. .exit = mci_exit,
  463. };
  464. /* FlashRAM */
  465. static struct resource strataflash_resource = {
  466. .start = PXA_CS0_PHYS,
  467. .end = PXA_CS0_PHYS + SZ_64M - 1,
  468. .flags = IORESOURCE_MEM,
  469. };
  470. static struct physmap_flash_data strataflash_data = {
  471. .width = 2,
  472. /* .set_vpp = mioa701_set_vpp, */
  473. };
  474. static struct platform_device strataflash = {
  475. .name = "physmap-flash",
  476. .id = -1,
  477. .resource = &strataflash_resource,
  478. .num_resources = 1,
  479. .dev = {
  480. .platform_data = &strataflash_data,
  481. },
  482. };
  483. /*
  484. * Suspend/Resume bootstrap management
  485. *
  486. * MIO A701 reboot sequence is highly ROM dependant. From the one dissassembled,
  487. * this sequence is as follows :
  488. * - disables interrupts
  489. * - initialize SDRAM (self refresh RAM into active RAM)
  490. * - initialize GPIOs (depends on value at 0xa020b020)
  491. * - initialize coprossessors
  492. * - if edge detect on PWR_SCL(GPIO3), then proceed to cold start
  493. * - or if value at 0xa020b000 not equal to 0x0f0f0f0f, proceed to cold start
  494. * - else do a resume, ie. jump to addr 0xa0100000
  495. */
  496. #define RESUME_ENABLE_ADDR 0xa020b000
  497. #define RESUME_ENABLE_VAL 0x0f0f0f0f
  498. #define RESUME_BT_ADDR 0xa020b020
  499. #define RESUME_UNKNOWN_ADDR 0xa020b024
  500. #define RESUME_VECTOR_ADDR 0xa0100000
  501. #define BOOTSTRAP_WORDS mioa701_bootstrap_lg/4
  502. static u32 *save_buffer;
  503. static void install_bootstrap(void)
  504. {
  505. int i;
  506. u32 *rom_bootstrap = phys_to_virt(RESUME_VECTOR_ADDR);
  507. u32 *src = &mioa701_bootstrap;
  508. for (i = 0; i < BOOTSTRAP_WORDS; i++)
  509. rom_bootstrap[i] = src[i];
  510. }
  511. static int mioa701_sys_suspend(struct sys_device *sysdev, pm_message_t state)
  512. {
  513. int i = 0, is_bt_on;
  514. u32 *mem_resume_vector = phys_to_virt(RESUME_VECTOR_ADDR);
  515. u32 *mem_resume_enabler = phys_to_virt(RESUME_ENABLE_ADDR);
  516. u32 *mem_resume_bt = phys_to_virt(RESUME_BT_ADDR);
  517. u32 *mem_resume_unknown = phys_to_virt(RESUME_UNKNOWN_ADDR);
  518. /* Devices prepare suspend */
  519. is_bt_on = !!gpio_get_value(GPIO83_BT_ON);
  520. pxa2xx_mfp_set_lpm(GPIO83_BT_ON,
  521. is_bt_on ? MFP_LPM_DRIVE_HIGH : MFP_LPM_DRIVE_LOW);
  522. for (i = 0; i < BOOTSTRAP_WORDS; i++)
  523. save_buffer[i] = mem_resume_vector[i];
  524. save_buffer[i++] = *mem_resume_enabler;
  525. save_buffer[i++] = *mem_resume_bt;
  526. save_buffer[i++] = *mem_resume_unknown;
  527. *mem_resume_enabler = RESUME_ENABLE_VAL;
  528. *mem_resume_bt = is_bt_on;
  529. install_bootstrap();
  530. return 0;
  531. }
  532. static int mioa701_sys_resume(struct sys_device *sysdev)
  533. {
  534. int i = 0;
  535. u32 *mem_resume_vector = phys_to_virt(RESUME_VECTOR_ADDR);
  536. u32 *mem_resume_enabler = phys_to_virt(RESUME_ENABLE_ADDR);
  537. u32 *mem_resume_bt = phys_to_virt(RESUME_BT_ADDR);
  538. u32 *mem_resume_unknown = phys_to_virt(RESUME_UNKNOWN_ADDR);
  539. for (i = 0; i < BOOTSTRAP_WORDS; i++)
  540. mem_resume_vector[i] = save_buffer[i];
  541. *mem_resume_enabler = save_buffer[i++];
  542. *mem_resume_bt = save_buffer[i++];
  543. *mem_resume_unknown = save_buffer[i++];
  544. return 0;
  545. }
  546. static struct sysdev_class mioa701_sysclass = {
  547. .name = "mioa701",
  548. };
  549. static struct sys_device sysdev_bootstrap = {
  550. .cls = &mioa701_sysclass,
  551. };
  552. static struct sysdev_driver driver_bootstrap = {
  553. .suspend = &mioa701_sys_suspend,
  554. .resume = &mioa701_sys_resume,
  555. };
  556. static int __init bootstrap_init(void)
  557. {
  558. int rc;
  559. int save_size = mioa701_bootstrap_lg + (sizeof(u32) * 3);
  560. rc = sysdev_class_register(&mioa701_sysclass);
  561. if (rc) {
  562. printk(KERN_ERR "Failed registering mioa701 sys class\n");
  563. return -ENODEV;
  564. }
  565. rc = sysdev_register(&sysdev_bootstrap);
  566. if (rc) {
  567. printk(KERN_ERR "Failed registering mioa701 sys device\n");
  568. return -ENODEV;
  569. }
  570. rc = sysdev_driver_register(&mioa701_sysclass, &driver_bootstrap);
  571. if (rc) {
  572. printk(KERN_ERR "Failed registering PMU sys driver\n");
  573. return -ENODEV;
  574. }
  575. save_buffer = kmalloc(save_size, GFP_KERNEL);
  576. if (!save_buffer)
  577. return -ENOMEM;
  578. printk(KERN_INFO "MioA701: allocated %d bytes for bootstrap\n",
  579. save_size);
  580. return 0;
  581. }
  582. static void bootstrap_exit(void)
  583. {
  584. kfree(save_buffer);
  585. sysdev_driver_unregister(&mioa701_sysclass, &driver_bootstrap);
  586. sysdev_unregister(&sysdev_bootstrap);
  587. sysdev_class_unregister(&mioa701_sysclass);
  588. printk(KERN_CRIT "Unregistering mioa701 suspend will hang next"
  589. "resume !!!\n");
  590. }
  591. /*
  592. * Power Supply
  593. */
  594. static char *supplicants[] = {
  595. "mioa701_battery"
  596. };
  597. static int is_ac_connected(void)
  598. {
  599. return gpio_get_value(GPIO96_AC_DETECT);
  600. }
  601. static void mioa701_set_charge(int flags)
  602. {
  603. gpio_set_value(GPIO9_CHARGE_EN, (flags == PDA_POWER_CHARGE_USB));
  604. }
  605. static struct pda_power_pdata power_pdata = {
  606. .is_ac_online = is_ac_connected,
  607. .is_usb_online = is_usb_connected,
  608. .set_charge = mioa701_set_charge,
  609. .supplied_to = supplicants,
  610. .num_supplicants = ARRAY_SIZE(supplicants),
  611. };
  612. static struct resource power_resources[] = {
  613. [0] = {
  614. .name = "ac",
  615. .start = gpio_to_irq(GPIO96_AC_DETECT),
  616. .end = gpio_to_irq(GPIO96_AC_DETECT),
  617. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
  618. IORESOURCE_IRQ_LOWEDGE,
  619. },
  620. [1] = {
  621. .name = "usb",
  622. .start = gpio_to_irq(GPIO13_nUSB_DETECT),
  623. .end = gpio_to_irq(GPIO13_nUSB_DETECT),
  624. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
  625. IORESOURCE_IRQ_LOWEDGE,
  626. },
  627. };
  628. static struct platform_device power_dev = {
  629. .name = "pda-power",
  630. .id = -1,
  631. .resource = power_resources,
  632. .num_resources = ARRAY_SIZE(power_resources),
  633. .dev = {
  634. .platform_data = &power_pdata,
  635. },
  636. };
  637. static struct wm97xx_batt_info mioa701_battery_data = {
  638. .batt_aux = WM97XX_AUX_ID1,
  639. .temp_aux = -1,
  640. .charge_gpio = -1,
  641. .min_voltage = 0xc00,
  642. .max_voltage = 0xfc0,
  643. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LION,
  644. .batt_div = 1,
  645. .batt_mult = 1,
  646. .batt_name = "mioa701_battery",
  647. };
  648. /*
  649. * Camera interface
  650. */
  651. struct pxacamera_platform_data mioa701_pxacamera_platform_data = {
  652. .flags = PXA_CAMERA_MASTER | PXA_CAMERA_DATAWIDTH_8 |
  653. PXA_CAMERA_PCLK_EN | PXA_CAMERA_MCLK_EN,
  654. .mclk_10khz = 5000,
  655. };
  656. static struct soc_camera_link iclink = {
  657. .bus_id = 0, /* Must match id in pxa27x_device_camera in device.c */
  658. };
  659. /* Board I2C devices. */
  660. static struct i2c_board_info __initdata mioa701_i2c_devices[] = {
  661. {
  662. /* Must initialize before the camera(s) */
  663. I2C_BOARD_INFO("mt9m111", 0x5d),
  664. .platform_data = &iclink,
  665. },
  666. };
  667. struct i2c_pxa_platform_data i2c_pdata = {
  668. .fast_mode = 1,
  669. };
  670. /*
  671. * Mio global
  672. */
  673. /* Devices */
  674. #define MIO_PARENT_DEV(var, strname, tparent, pdata) \
  675. static struct platform_device var = { \
  676. .name = strname, \
  677. .id = -1, \
  678. .dev = { \
  679. .platform_data = pdata, \
  680. .parent = tparent, \
  681. }, \
  682. };
  683. #define MIO_SIMPLE_DEV(var, strname, pdata) \
  684. MIO_PARENT_DEV(var, strname, NULL, pdata)
  685. MIO_SIMPLE_DEV(mioa701_gpio_keys, "gpio-keys", &mioa701_gpio_keys_data)
  686. MIO_PARENT_DEV(mioa701_backlight, "pwm-backlight", &pxa27x_device_pwm0.dev,
  687. &mioa701_backlight_data);
  688. MIO_SIMPLE_DEV(mioa701_led, "leds-gpio", &gpio_led_info)
  689. MIO_SIMPLE_DEV(pxa2xx_pcm, "pxa2xx-pcm", NULL)
  690. MIO_SIMPLE_DEV(pxa2xx_ac97, "pxa2xx-ac97", NULL)
  691. MIO_PARENT_DEV(mio_wm9713_codec, "wm9713-codec", &pxa2xx_ac97.dev, NULL)
  692. MIO_SIMPLE_DEV(mioa701_sound, "mioa701-wm9713", NULL)
  693. MIO_SIMPLE_DEV(mioa701_board, "mioa701-board", NULL)
  694. static struct platform_device *devices[] __initdata = {
  695. &mioa701_gpio_keys,
  696. &mioa701_backlight,
  697. &mioa701_led,
  698. &pxa2xx_pcm,
  699. &pxa2xx_ac97,
  700. &mio_wm9713_codec,
  701. &mioa701_sound,
  702. &power_dev,
  703. &strataflash,
  704. &mioa701_board
  705. };
  706. static void mioa701_machine_exit(void);
  707. static void mioa701_poweroff(void)
  708. {
  709. mioa701_machine_exit();
  710. arm_machine_restart('s');
  711. }
  712. static void mioa701_restart(char c)
  713. {
  714. mioa701_machine_exit();
  715. arm_machine_restart('s');
  716. }
  717. struct gpio_ress global_gpios[] = {
  718. MIO_GPIO_OUT(GPIO9_CHARGE_EN, 1, "Charger enable"),
  719. MIO_GPIO_OUT(GPIO18_POWEROFF, 0, "Power Off"),
  720. MIO_GPIO_OUT(GPIO87_LCD_POWER, 0, "LCD Power")
  721. };
  722. static void __init mioa701_machine_init(void)
  723. {
  724. PSLR = 0xff100000; /* SYSDEL=125ms, PWRDEL=125ms, PSLR_SL_ROD=1 */
  725. PCFR = PCFR_DC_EN | PCFR_GPR_EN | PCFR_OPDE;
  726. RTTR = 32768 - 1; /* Reset crazy WinCE value */
  727. UP2OCR = UP2OCR_HXOE;
  728. pxa2xx_mfp_config(ARRAY_AND_SIZE(mioa701_pin_config));
  729. mio_gpio_request(ARRAY_AND_SIZE(global_gpios));
  730. bootstrap_init();
  731. set_pxa_fb_info(&mioa701_pxafb_info);
  732. pxa_set_mci_info(&mioa701_mci_info);
  733. pxa_set_keypad_info(&mioa701_keypad_info);
  734. wm97xx_bat_set_pdata(&mioa701_battery_data);
  735. udc_init();
  736. pm_power_off = mioa701_poweroff;
  737. arm_pm_restart = mioa701_restart;
  738. platform_add_devices(devices, ARRAY_SIZE(devices));
  739. gsm_init();
  740. pxa_set_i2c_info(&i2c_pdata);
  741. pxa_set_camera_info(&mioa701_pxacamera_platform_data);
  742. i2c_register_board_info(0, ARRAY_AND_SIZE(mioa701_i2c_devices));
  743. }
  744. static void mioa701_machine_exit(void)
  745. {
  746. udc_exit();
  747. bootstrap_exit();
  748. gsm_exit();
  749. }
  750. MACHINE_START(MIOA701, "MIO A701")
  751. .phys_io = 0x40000000,
  752. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  753. .boot_params = 0xa0000100,
  754. .map_io = &pxa_map_io,
  755. .init_irq = &pxa27x_init_irq,
  756. .init_machine = mioa701_machine_init,
  757. .timer = &pxa_timer,
  758. MACHINE_END