palmte2.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Hardware definitions for Palm Tungsten|E2
  4. *
  5. * Author:
  6. * Carlos Eduardo Medaglia Dyonisio <[email protected]>
  7. *
  8. * Rewrite for mainline:
  9. * Marek Vasut <[email protected]>
  10. *
  11. * (find more info at www.hackndev.com)
  12. */
  13. #include <linux/platform_device.h>
  14. #include <linux/delay.h>
  15. #include <linux/irq.h>
  16. #include <linux/gpio_keys.h>
  17. #include <linux/gpio/machine.h>
  18. #include <linux/input.h>
  19. #include <linux/pda_power.h>
  20. #include <linux/pwm.h>
  21. #include <linux/pwm_backlight.h>
  22. #include <linux/gpio.h>
  23. #include <linux/wm97xx.h>
  24. #include <linux/power_supply.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/mach/arch.h>
  27. #include <asm/mach/map.h>
  28. #include "pxa25x.h"
  29. #include <linux/platform_data/asoc-pxa.h>
  30. #include "palmte2.h"
  31. #include <linux/platform_data/mmc-pxamci.h>
  32. #include <linux/platform_data/video-pxafb.h>
  33. #include <linux/platform_data/irda-pxaficp.h>
  34. #include "udc.h"
  35. #include <linux/platform_data/asoc-palm27x.h>
  36. #include "generic.h"
  37. #include "devices.h"
  38. /******************************************************************************
  39. * Pin configuration
  40. ******************************************************************************/
  41. static unsigned long palmte2_pin_config[] __initdata = {
  42. /* MMC */
  43. GPIO6_MMC_CLK,
  44. GPIO8_MMC_CS0,
  45. GPIO10_GPIO, /* SD detect */
  46. GPIO55_GPIO, /* SD power */
  47. GPIO51_GPIO, /* SD r/o switch */
  48. /* AC97 */
  49. GPIO28_AC97_BITCLK,
  50. GPIO29_AC97_SDATA_IN_0,
  51. GPIO30_AC97_SDATA_OUT,
  52. GPIO31_AC97_SYNC,
  53. /* PWM */
  54. GPIO16_PWM0_OUT,
  55. /* USB */
  56. GPIO15_GPIO, /* usb detect */
  57. GPIO53_GPIO, /* usb power */
  58. /* IrDA */
  59. GPIO48_GPIO, /* ir disable */
  60. GPIO46_FICP_RXD,
  61. GPIO47_FICP_TXD,
  62. /* LCD */
  63. GPIOxx_LCD_TFT_16BPP,
  64. /* GPIO KEYS */
  65. GPIO5_GPIO, /* notes */
  66. GPIO7_GPIO, /* tasks */
  67. GPIO11_GPIO, /* calendar */
  68. GPIO13_GPIO, /* contacts */
  69. GPIO14_GPIO, /* center */
  70. GPIO19_GPIO, /* left */
  71. GPIO20_GPIO, /* right */
  72. GPIO21_GPIO, /* down */
  73. GPIO22_GPIO, /* up */
  74. /* MISC */
  75. GPIO1_RST, /* reset */
  76. GPIO4_GPIO, /* Hotsync button */
  77. GPIO9_GPIO, /* power detect */
  78. GPIO15_GPIO, /* earphone detect */
  79. GPIO37_GPIO, /* LCD power */
  80. GPIO56_GPIO, /* Backlight power */
  81. };
  82. /******************************************************************************
  83. * SD/MMC card controller
  84. ******************************************************************************/
  85. static struct pxamci_platform_data palmte2_mci_platform_data = {
  86. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  87. };
  88. static struct gpiod_lookup_table palmte2_mci_gpio_table = {
  89. .dev_id = "pxa2xx-mci.0",
  90. .table = {
  91. GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTE2_SD_DETECT_N,
  92. "cd", GPIO_ACTIVE_LOW),
  93. GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTE2_SD_READONLY,
  94. "wp", GPIO_ACTIVE_LOW),
  95. GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTE2_SD_POWER,
  96. "power", GPIO_ACTIVE_HIGH),
  97. { },
  98. },
  99. };
  100. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  101. /******************************************************************************
  102. * GPIO keys
  103. ******************************************************************************/
  104. static struct gpio_keys_button palmte2_pxa_buttons[] = {
  105. {KEY_F1, GPIO_NR_PALMTE2_KEY_CONTACTS, 1, "Contacts" },
  106. {KEY_F2, GPIO_NR_PALMTE2_KEY_CALENDAR, 1, "Calendar" },
  107. {KEY_F3, GPIO_NR_PALMTE2_KEY_TASKS, 1, "Tasks" },
  108. {KEY_F4, GPIO_NR_PALMTE2_KEY_NOTES, 1, "Notes" },
  109. {KEY_ENTER, GPIO_NR_PALMTE2_KEY_CENTER, 1, "Center" },
  110. {KEY_LEFT, GPIO_NR_PALMTE2_KEY_LEFT, 1, "Left" },
  111. {KEY_RIGHT, GPIO_NR_PALMTE2_KEY_RIGHT, 1, "Right" },
  112. {KEY_DOWN, GPIO_NR_PALMTE2_KEY_DOWN, 1, "Down" },
  113. {KEY_UP, GPIO_NR_PALMTE2_KEY_UP, 1, "Up" },
  114. };
  115. static struct gpio_keys_platform_data palmte2_pxa_keys_data = {
  116. .buttons = palmte2_pxa_buttons,
  117. .nbuttons = ARRAY_SIZE(palmte2_pxa_buttons),
  118. };
  119. static struct platform_device palmte2_pxa_keys = {
  120. .name = "gpio-keys",
  121. .id = -1,
  122. .dev = {
  123. .platform_data = &palmte2_pxa_keys_data,
  124. },
  125. };
  126. #endif
  127. /******************************************************************************
  128. * Backlight
  129. ******************************************************************************/
  130. static struct pwm_lookup palmte2_pwm_lookup[] = {
  131. PWM_LOOKUP("pxa25x-pwm.0", 0, "pwm-backlight.0", NULL,
  132. PALMTE2_PERIOD_NS, PWM_POLARITY_NORMAL),
  133. };
  134. static struct gpio palmte_bl_gpios[] = {
  135. { GPIO_NR_PALMTE2_BL_POWER, GPIOF_INIT_LOW, "Backlight power" },
  136. { GPIO_NR_PALMTE2_LCD_POWER, GPIOF_INIT_LOW, "LCD power" },
  137. };
  138. static int palmte2_backlight_init(struct device *dev)
  139. {
  140. return gpio_request_array(ARRAY_AND_SIZE(palmte_bl_gpios));
  141. }
  142. static int palmte2_backlight_notify(struct device *dev, int brightness)
  143. {
  144. gpio_set_value(GPIO_NR_PALMTE2_BL_POWER, brightness);
  145. gpio_set_value(GPIO_NR_PALMTE2_LCD_POWER, brightness);
  146. return brightness;
  147. }
  148. static void palmte2_backlight_exit(struct device *dev)
  149. {
  150. gpio_free_array(ARRAY_AND_SIZE(palmte_bl_gpios));
  151. }
  152. static struct platform_pwm_backlight_data palmte2_backlight_data = {
  153. .max_brightness = PALMTE2_MAX_INTENSITY,
  154. .dft_brightness = PALMTE2_MAX_INTENSITY,
  155. .init = palmte2_backlight_init,
  156. .notify = palmte2_backlight_notify,
  157. .exit = palmte2_backlight_exit,
  158. };
  159. static struct platform_device palmte2_backlight = {
  160. .name = "pwm-backlight",
  161. .dev = {
  162. .parent = &pxa25x_device_pwm0.dev,
  163. .platform_data = &palmte2_backlight_data,
  164. },
  165. };
  166. /******************************************************************************
  167. * IrDA
  168. ******************************************************************************/
  169. static struct pxaficp_platform_data palmte2_ficp_platform_data = {
  170. .gpio_pwdown = GPIO_NR_PALMTE2_IR_DISABLE,
  171. .transceiver_cap = IR_SIRMODE | IR_OFF,
  172. };
  173. /******************************************************************************
  174. * UDC
  175. ******************************************************************************/
  176. static struct gpiod_lookup_table palmte2_udc_gpiod_table = {
  177. .dev_id = "gpio-vbus",
  178. .table = {
  179. GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTE2_USB_DETECT_N,
  180. "vbus", GPIO_ACTIVE_LOW),
  181. GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTE2_USB_PULLUP,
  182. "pullup", GPIO_ACTIVE_HIGH),
  183. { },
  184. },
  185. };
  186. static struct platform_device palmte2_gpio_vbus = {
  187. .name = "gpio-vbus",
  188. .id = -1,
  189. };
  190. /******************************************************************************
  191. * Power supply
  192. ******************************************************************************/
  193. static int power_supply_init(struct device *dev)
  194. {
  195. int ret;
  196. ret = gpio_request(GPIO_NR_PALMTE2_POWER_DETECT, "CABLE_STATE_AC");
  197. if (ret)
  198. goto err1;
  199. ret = gpio_direction_input(GPIO_NR_PALMTE2_POWER_DETECT);
  200. if (ret)
  201. goto err2;
  202. return 0;
  203. err2:
  204. gpio_free(GPIO_NR_PALMTE2_POWER_DETECT);
  205. err1:
  206. return ret;
  207. }
  208. static int palmte2_is_ac_online(void)
  209. {
  210. return gpio_get_value(GPIO_NR_PALMTE2_POWER_DETECT);
  211. }
  212. static void power_supply_exit(struct device *dev)
  213. {
  214. gpio_free(GPIO_NR_PALMTE2_POWER_DETECT);
  215. }
  216. static char *palmte2_supplicants[] = {
  217. "main-battery",
  218. };
  219. static struct pda_power_pdata power_supply_info = {
  220. .init = power_supply_init,
  221. .is_ac_online = palmte2_is_ac_online,
  222. .exit = power_supply_exit,
  223. .supplied_to = palmte2_supplicants,
  224. .num_supplicants = ARRAY_SIZE(palmte2_supplicants),
  225. };
  226. static struct platform_device power_supply = {
  227. .name = "pda-power",
  228. .id = -1,
  229. .dev = {
  230. .platform_data = &power_supply_info,
  231. },
  232. };
  233. /******************************************************************************
  234. * WM97xx audio, battery
  235. ******************************************************************************/
  236. static struct wm97xx_batt_pdata palmte2_batt_pdata = {
  237. .batt_aux = WM97XX_AUX_ID3,
  238. .temp_aux = WM97XX_AUX_ID2,
  239. .max_voltage = PALMTE2_BAT_MAX_VOLTAGE,
  240. .min_voltage = PALMTE2_BAT_MIN_VOLTAGE,
  241. .batt_mult = 1000,
  242. .batt_div = 414,
  243. .temp_mult = 1,
  244. .temp_div = 1,
  245. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
  246. .batt_name = "main-batt",
  247. };
  248. static struct wm97xx_pdata palmte2_wm97xx_pdata = {
  249. .batt_pdata = &palmte2_batt_pdata,
  250. };
  251. static pxa2xx_audio_ops_t palmte2_ac97_pdata = {
  252. .codec_pdata = { &palmte2_wm97xx_pdata, },
  253. };
  254. static struct palm27x_asoc_info palmte2_asoc_pdata = {
  255. .jack_gpio = GPIO_NR_PALMTE2_EARPHONE_DETECT,
  256. };
  257. static struct platform_device palmte2_asoc = {
  258. .name = "palm27x-asoc",
  259. .id = -1,
  260. .dev = {
  261. .platform_data = &palmte2_asoc_pdata,
  262. },
  263. };
  264. /******************************************************************************
  265. * Framebuffer
  266. ******************************************************************************/
  267. static struct pxafb_mode_info palmte2_lcd_modes[] = {
  268. {
  269. .pixclock = 77757,
  270. .xres = 320,
  271. .yres = 320,
  272. .bpp = 16,
  273. .left_margin = 28,
  274. .right_margin = 7,
  275. .upper_margin = 7,
  276. .lower_margin = 5,
  277. .hsync_len = 4,
  278. .vsync_len = 1,
  279. },
  280. };
  281. static struct pxafb_mach_info palmte2_lcd_screen = {
  282. .modes = palmte2_lcd_modes,
  283. .num_modes = ARRAY_SIZE(palmte2_lcd_modes),
  284. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  285. };
  286. /******************************************************************************
  287. * Machine init
  288. ******************************************************************************/
  289. static struct platform_device *devices[] __initdata = {
  290. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  291. &palmte2_pxa_keys,
  292. #endif
  293. &palmte2_backlight,
  294. &power_supply,
  295. &palmte2_asoc,
  296. &palmte2_gpio_vbus,
  297. };
  298. /* setup udc GPIOs initial state */
  299. static void __init palmte2_udc_init(void)
  300. {
  301. if (!gpio_request(GPIO_NR_PALMTE2_USB_PULLUP, "UDC Vbus")) {
  302. gpio_direction_output(GPIO_NR_PALMTE2_USB_PULLUP, 1);
  303. gpio_free(GPIO_NR_PALMTE2_USB_PULLUP);
  304. }
  305. }
  306. static void __init palmte2_init(void)
  307. {
  308. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmte2_pin_config));
  309. pxa_set_ffuart_info(NULL);
  310. pxa_set_btuart_info(NULL);
  311. pxa_set_stuart_info(NULL);
  312. pxa_set_fb_info(NULL, &palmte2_lcd_screen);
  313. gpiod_add_lookup_table(&palmte2_mci_gpio_table);
  314. pxa_set_mci_info(&palmte2_mci_platform_data);
  315. palmte2_udc_init();
  316. pxa_set_ac97_info(&palmte2_ac97_pdata);
  317. pxa_set_ficp_info(&palmte2_ficp_platform_data);
  318. pwm_add_table(palmte2_pwm_lookup, ARRAY_SIZE(palmte2_pwm_lookup));
  319. gpiod_add_lookup_table(&palmte2_udc_gpiod_table);
  320. platform_add_devices(devices, ARRAY_SIZE(devices));
  321. }
  322. MACHINE_START(PALMTE2, "Palm Tungsten|E2")
  323. .atag_offset = 0x100,
  324. .map_io = pxa25x_map_io,
  325. .nr_irqs = PXA_NR_IRQS,
  326. .init_irq = pxa25x_init_irq,
  327. .handle_irq = pxa25x_handle_irq,
  328. .init_time = pxa_timer_init,
  329. .init_machine = palmte2_init,
  330. .restart = pxa_restart,
  331. MACHINE_END