intel-mid.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /*
  2. * intel-mid.c: Intel MID platform setup code
  3. *
  4. * (C) Copyright 2008, 2012 Intel Corporation
  5. * Author: Jacob Pan (jacob.jun.pan@intel.com)
  6. * Author: Sathyanarayanan Kuppuswamy <sathyanarayanan.kuppuswamy@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; version 2
  11. * of the License.
  12. */
  13. #define pr_fmt(fmt) "intel_mid: " fmt
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/scatterlist.h>
  18. #include <linux/sfi.h>
  19. #include <linux/irq.h>
  20. #include <linux/module.h>
  21. #include <linux/notifier.h>
  22. #include <asm/setup.h>
  23. #include <asm/mpspec_def.h>
  24. #include <asm/hw_irq.h>
  25. #include <asm/apic.h>
  26. #include <asm/io_apic.h>
  27. #include <asm/intel-mid.h>
  28. #include <asm/intel_mid_vrtc.h>
  29. #include <asm/io.h>
  30. #include <asm/i8259.h>
  31. #include <asm/intel_scu_ipc.h>
  32. #include <asm/apb_timer.h>
  33. #include <asm/reboot.h>
  34. /*
  35. * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
  36. * cmdline option x86_intel_mid_timer can be used to override the configuration
  37. * to prefer one or the other.
  38. * at runtime, there are basically three timer configurations:
  39. * 1. per cpu apbt clock only
  40. * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
  41. * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
  42. *
  43. * by default (without cmdline option), platform code first detects cpu type
  44. * to see if we are on lincroft or penwell, then set up both lapic or apbt
  45. * clocks accordingly.
  46. * i.e. by default, medfield uses configuration #2, moorestown uses #1.
  47. * config #3 is supported but not recommended on medfield.
  48. *
  49. * rating and feature summary:
  50. * lapic (with C3STOP) --------- 100
  51. * apbt (always-on) ------------ 110
  52. * lapic (always-on,ARAT) ------ 150
  53. */
  54. enum intel_mid_timer_options intel_mid_timer_options;
  55. enum intel_mid_cpu_type __intel_mid_cpu_chip;
  56. EXPORT_SYMBOL_GPL(__intel_mid_cpu_chip);
  57. static void __init ipc_device_handler(struct sfi_device_table_entry *pentry,
  58. struct devs_id *dev);
  59. static void intel_mid_power_off(void)
  60. {
  61. }
  62. static void intel_mid_reboot(void)
  63. {
  64. intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
  65. }
  66. static unsigned long __init intel_mid_calibrate_tsc(void)
  67. {
  68. unsigned long fast_calibrate;
  69. u32 lo, hi, ratio, fsb;
  70. rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
  71. pr_debug("IA32 perf status is 0x%x, 0x%0x\n", lo, hi);
  72. ratio = (hi >> 8) & 0x1f;
  73. pr_debug("ratio is %d\n", ratio);
  74. if (!ratio) {
  75. pr_err("read a zero ratio, should be incorrect!\n");
  76. pr_err("force tsc ratio to 16 ...\n");
  77. ratio = 16;
  78. }
  79. rdmsr(MSR_FSB_FREQ, lo, hi);
  80. if ((lo & 0x7) == 0x7)
  81. fsb = PENWELL_FSB_FREQ_83SKU;
  82. else
  83. fsb = PENWELL_FSB_FREQ_100SKU;
  84. fast_calibrate = ratio * fsb;
  85. pr_debug("read penwell tsc %lu khz\n", fast_calibrate);
  86. lapic_timer_frequency = fsb * 1000 / HZ;
  87. /* mark tsc clocksource as reliable */
  88. set_cpu_cap(&boot_cpu_data, X86_FEATURE_TSC_RELIABLE);
  89. if (fast_calibrate)
  90. return fast_calibrate;
  91. return 0;
  92. }
  93. static void __init intel_mid_time_init(void)
  94. {
  95. sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
  96. switch (intel_mid_timer_options) {
  97. case INTEL_MID_TIMER_APBT_ONLY:
  98. break;
  99. case INTEL_MID_TIMER_LAPIC_APBT:
  100. x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
  101. x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
  102. break;
  103. default:
  104. if (!boot_cpu_has(X86_FEATURE_ARAT))
  105. break;
  106. x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
  107. x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
  108. return;
  109. }
  110. /* we need at least one APB timer */
  111. pre_init_apic_IRQ0();
  112. apbt_time_init();
  113. }
  114. static void __cpuinit intel_mid_arch_setup(void)
  115. {
  116. if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
  117. __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
  118. else {
  119. pr_err("Unknown Intel MID CPU (%d:%d), default to Penwell\n",
  120. boot_cpu_data.x86, boot_cpu_data.x86_model);
  121. __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
  122. }
  123. }
  124. /* MID systems don't have i8042 controller */
  125. static int intel_mid_i8042_detect(void)
  126. {
  127. return 0;
  128. }
  129. /*
  130. * Moorestown does not have external NMI source nor port 0x61 to report
  131. * NMI status. The possible NMI sources are from pmu as a result of NMI
  132. * watchdog or lock debug. Reading io port 0x61 results in 0xff which
  133. * misled NMI handler.
  134. */
  135. static unsigned char intel_mid_get_nmi_reason(void)
  136. {
  137. return 0;
  138. }
  139. /*
  140. * Moorestown specific x86_init function overrides and early setup
  141. * calls.
  142. */
  143. void __init x86_intel_mid_early_setup(void)
  144. {
  145. x86_init.resources.probe_roms = x86_init_noop;
  146. x86_init.resources.reserve_resources = x86_init_noop;
  147. x86_init.timers.timer_init = intel_mid_time_init;
  148. x86_init.timers.setup_percpu_clockev = x86_init_noop;
  149. x86_init.irqs.pre_vector_init = x86_init_noop;
  150. x86_init.oem.arch_setup = intel_mid_arch_setup;
  151. x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
  152. x86_platform.calibrate_tsc = intel_mid_calibrate_tsc;
  153. x86_platform.i8042_detect = intel_mid_i8042_detect;
  154. x86_init.timers.wallclock_init = intel_mid_rtc_init;
  155. x86_platform.get_nmi_reason = intel_mid_get_nmi_reason;
  156. x86_init.pci.init = intel_mid_pci_init;
  157. x86_init.pci.fixup_irqs = x86_init_noop;
  158. legacy_pic = &null_legacy_pic;
  159. pm_power_off = intel_mid_power_off;
  160. machine_ops.emergency_restart = intel_mid_reboot;
  161. /* Avoid searching for BIOS MP tables */
  162. x86_init.mpparse.find_smp_config = x86_init_noop;
  163. x86_init.mpparse.get_smp_config = x86_init_uint_noop;
  164. set_bit(MP_BUS_ISA, mp_bus_not_pci);
  165. }
  166. /*
  167. * if user does not want to use per CPU apb timer, just give it a lower rating
  168. * than local apic timer and skip the late per cpu timer init.
  169. */
  170. static inline int __init setup_x86_intel_mid_timer(char *arg)
  171. {
  172. if (!arg)
  173. return -EINVAL;
  174. if (strcmp("apbt_only", arg) == 0)
  175. intel_mid_timer_options = INTEL_MID_TIMER_APBT_ONLY;
  176. else if (strcmp("lapic_and_apbt", arg) == 0)
  177. intel_mid_timer_options = INTEL_MID_TIMER_LAPIC_APBT;
  178. else {
  179. pr_warn("X86 INTEL_MID timer option %s not recognised"
  180. " use x86_intel_mid_timer=apbt_only or lapic_and_apbt\n",
  181. arg);
  182. return -EINVAL;
  183. }
  184. return 0;
  185. }
  186. __setup("x86_intel_mid_timer=", setup_x86_intel_mid_timer);
  187. /* the offset for the mapping of global gpio pin to irq */
  188. #define INTEL_MID_IRQ_OFFSET 0x100
  189. static void __init *pmic_gpio_platform_data(void *info)
  190. {
  191. static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
  192. int gpio_base = get_gpio_by_name("pmic_gpio_base");
  193. if (gpio_base == -1)
  194. gpio_base = 64;
  195. pmic_gpio_pdata.gpio_base = gpio_base;
  196. pmic_gpio_pdata.irq_base = gpio_base + INTEL_MID_IRQ_OFFSET;
  197. pmic_gpio_pdata.gpiointr = 0xffffeff8;
  198. return &pmic_gpio_pdata;
  199. }
  200. static void __init *max3111_platform_data(void *info)
  201. {
  202. struct spi_board_info *spi_info = info;
  203. int intr = get_gpio_by_name("max3111_int");
  204. spi_info->mode = SPI_MODE_0;
  205. if (intr == -1)
  206. return NULL;
  207. spi_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  208. return NULL;
  209. }
  210. /* we have multiple max7315 on the board ... */
  211. #define MAX7315_NUM 2
  212. static void __init *max7315_platform_data(void *info)
  213. {
  214. static struct pca953x_platform_data max7315_pdata[MAX7315_NUM];
  215. static int nr;
  216. struct pca953x_platform_data *max7315 = &max7315_pdata[nr];
  217. struct i2c_board_info *i2c_info = info;
  218. int gpio_base, intr;
  219. char base_pin_name[SFI_NAME_LEN + 1];
  220. char intr_pin_name[SFI_NAME_LEN + 1];
  221. if (nr == MAX7315_NUM) {
  222. pr_err("too many max7315s, we only support %d\n",
  223. MAX7315_NUM);
  224. return NULL;
  225. }
  226. /* we have several max7315 on the board, we only need load several
  227. * instances of the same pca953x driver to cover them
  228. */
  229. strcpy(i2c_info->type, "max7315");
  230. if (nr++) {
  231. sprintf(base_pin_name, "max7315_%d_base", nr);
  232. sprintf(intr_pin_name, "max7315_%d_int", nr);
  233. } else {
  234. strcpy(base_pin_name, "max7315_base");
  235. strcpy(intr_pin_name, "max7315_int");
  236. }
  237. gpio_base = get_gpio_by_name(base_pin_name);
  238. intr = get_gpio_by_name(intr_pin_name);
  239. if (gpio_base == -1)
  240. return NULL;
  241. max7315->gpio_base = gpio_base;
  242. if (intr != -1) {
  243. i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  244. max7315->irq_base = gpio_base + INTEL_MID_IRQ_OFFSET;
  245. } else {
  246. i2c_info->irq = -1;
  247. max7315->irq_base = -1;
  248. }
  249. return max7315;
  250. }
  251. static void *tca6416_platform_data(void *info)
  252. {
  253. static struct pca953x_platform_data tca6416;
  254. struct i2c_board_info *i2c_info = info;
  255. int gpio_base, intr;
  256. char base_pin_name[SFI_NAME_LEN + 1];
  257. char intr_pin_name[SFI_NAME_LEN + 1];
  258. strcpy(i2c_info->type, "tca6416");
  259. strcpy(base_pin_name, "tca6416_base");
  260. strcpy(intr_pin_name, "tca6416_int");
  261. gpio_base = get_gpio_by_name(base_pin_name);
  262. intr = get_gpio_by_name(intr_pin_name);
  263. if (gpio_base == -1)
  264. return NULL;
  265. tca6416.gpio_base = gpio_base;
  266. if (intr != -1) {
  267. i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  268. tca6416.irq_base = gpio_base + INTEL_MID_IRQ_OFFSET;
  269. } else {
  270. i2c_info->irq = -1;
  271. tca6416.irq_base = -1;
  272. }
  273. return &tca6416;
  274. }
  275. static void *mpu3050_platform_data(void *info)
  276. {
  277. struct i2c_board_info *i2c_info = info;
  278. int intr = get_gpio_by_name("mpu3050_int");
  279. if (intr == -1)
  280. return NULL;
  281. i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  282. return NULL;
  283. }
  284. static void __init *emc1403_platform_data(void *info)
  285. {
  286. static short intr2nd_pdata;
  287. struct i2c_board_info *i2c_info = info;
  288. int intr = get_gpio_by_name("thermal_int");
  289. int intr2nd = get_gpio_by_name("thermal_alert");
  290. if (intr == -1 || intr2nd == -1)
  291. return NULL;
  292. i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  293. intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;
  294. return &intr2nd_pdata;
  295. }
  296. static void __init *lis331dl_platform_data(void *info)
  297. {
  298. static short intr2nd_pdata;
  299. struct i2c_board_info *i2c_info = info;
  300. int intr = get_gpio_by_name("accel_int");
  301. int intr2nd = get_gpio_by_name("accel_2");
  302. if (intr == -1 || intr2nd == -1)
  303. return NULL;
  304. i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  305. intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;
  306. return &intr2nd_pdata;
  307. }
  308. static void __init *no_platform_data(void *info)
  309. {
  310. return NULL;
  311. }
  312. static struct resource msic_resources[] = {
  313. {
  314. .start = INTEL_MSIC_IRQ_PHYS_BASE,
  315. .end = INTEL_MSIC_IRQ_PHYS_BASE + 64 - 1,
  316. .flags = IORESOURCE_MEM,
  317. },
  318. };
  319. static struct intel_msic_platform_data msic_pdata;
  320. static struct platform_device msic_device = {
  321. .name = "intel_msic",
  322. .id = -1,
  323. .dev = {
  324. .platform_data = &msic_pdata,
  325. },
  326. .num_resources = ARRAY_SIZE(msic_resources),
  327. .resource = msic_resources,
  328. };
  329. static inline bool intel_mid_has_msic(void)
  330. {
  331. return intel_mid_identify_cpu() == INTEL_MID_CPU_CHIP_PENWELL;
  332. }
  333. static int msic_scu_status_change(struct notifier_block *nb,
  334. unsigned long code, void *data)
  335. {
  336. if (code == SCU_DOWN) {
  337. platform_device_unregister(&msic_device);
  338. return 0;
  339. }
  340. return platform_device_register(&msic_device);
  341. }
  342. static int __init msic_init(void)
  343. {
  344. static struct notifier_block msic_scu_notifier = {
  345. .notifier_call = msic_scu_status_change,
  346. };
  347. /*
  348. * We need to be sure that the SCU IPC is ready before MSIC device
  349. * can be registered.
  350. */
  351. if (intel_mid_has_msic())
  352. intel_scu_notifier_add(&msic_scu_notifier);
  353. return 0;
  354. }
  355. arch_initcall(msic_init);
  356. /*
  357. * msic_generic_platform_data - sets generic platform data for the block
  358. * @info: pointer to the SFI device table entry for this block
  359. * @block: MSIC block
  360. *
  361. * Function sets IRQ number from the SFI table entry for given device to
  362. * the MSIC platform data.
  363. */
  364. static void *msic_generic_platform_data(void *info, enum intel_msic_block block)
  365. {
  366. struct sfi_device_table_entry *entry = info;
  367. BUG_ON(block < 0 || block >= INTEL_MSIC_BLOCK_LAST);
  368. msic_pdata.irq[block] = entry->irq;
  369. return no_platform_data(info);
  370. }
  371. static void *msic_battery_platform_data(void *info)
  372. {
  373. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_BATTERY);
  374. }
  375. static void *msic_gpio_platform_data(void *info)
  376. {
  377. static struct intel_msic_gpio_pdata pdata;
  378. int gpio = get_gpio_by_name("msic_gpio_base");
  379. if (gpio < 0)
  380. return NULL;
  381. pdata.gpio_base = gpio;
  382. msic_pdata.gpio = &pdata;
  383. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_GPIO);
  384. }
  385. static void *msic_audio_platform_data(void *info)
  386. {
  387. struct platform_device *pdev;
  388. pdev = platform_device_register_simple("sst-platform", -1, NULL, 0);
  389. if (IS_ERR(pdev)) {
  390. pr_err("failed to create audio platform device\n");
  391. return NULL;
  392. }
  393. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_AUDIO);
  394. }
  395. static void *msic_power_btn_platform_data(void *info)
  396. {
  397. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_POWER_BTN);
  398. }
  399. static void *msic_ocd_platform_data(void *info)
  400. {
  401. static struct intel_msic_ocd_pdata pdata;
  402. int gpio = get_gpio_by_name("ocd_gpio");
  403. if (gpio < 0)
  404. return NULL;
  405. pdata.gpio = gpio;
  406. msic_pdata.ocd = &pdata;
  407. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_OCD);
  408. }
  409. static void *msic_thermal_platform_data(void *info)
  410. {
  411. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_THERMAL);
  412. }
  413. /* tc35876x DSI-LVDS bridge chip and panel platform data */
  414. static void *tc35876x_platform_data(void *data)
  415. {
  416. static struct tc35876x_platform_data pdata;
  417. /* gpio pins set to -1 will not be used by the driver */
  418. pdata.gpio_bridge_reset = get_gpio_by_name("LCMB_RXEN");
  419. pdata.gpio_panel_bl_en = get_gpio_by_name("6S6P_BL_EN");
  420. pdata.gpio_panel_vadd = get_gpio_by_name("EN_VREG_LCD_V3P3");
  421. return &pdata;
  422. }
  423. static const struct devs_id __initconst device_ids[] = {
  424. {"bma023", SFI_DEV_TYPE_I2C, 1, &no_platform_data, NULL},
  425. {"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data, NULL},
  426. {"pmic_gpio", SFI_DEV_TYPE_IPC, 1, &pmic_gpio_platform_data, &ipc_device_handler},
  427. {"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data, NULL},
  428. {"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data, NULL},
  429. {"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data, NULL},
  430. {"tca6416", SFI_DEV_TYPE_I2C, 1, &tca6416_platform_data, NULL},
  431. {"emc1403", SFI_DEV_TYPE_I2C, 1, &emc1403_platform_data, NULL},
  432. {"i2c_accel", SFI_DEV_TYPE_I2C, 0, &lis331dl_platform_data, NULL},
  433. {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data, &ipc_device_handler},
  434. {"mpu3050", SFI_DEV_TYPE_I2C, 1, &mpu3050_platform_data, NULL},
  435. {"i2c_disp_brig", SFI_DEV_TYPE_I2C, 0, &tc35876x_platform_data, NULL},
  436. /* MSIC subdevices */
  437. {"msic_battery", SFI_DEV_TYPE_IPC, 1, &msic_battery_platform_data, &ipc_device_handler},
  438. {"msic_gpio", SFI_DEV_TYPE_IPC, 1, &msic_gpio_platform_data, &ipc_device_handler},
  439. {"msic_audio", SFI_DEV_TYPE_IPC, 1, &msic_audio_platform_data, &ipc_device_handler},
  440. {"msic_power_btn", SFI_DEV_TYPE_IPC, 1, &msic_power_btn_platform_data, &ipc_device_handler},
  441. {"msic_ocd", SFI_DEV_TYPE_IPC, 1, &msic_ocd_platform_data, &ipc_device_handler},
  442. {"msic_thermal", SFI_DEV_TYPE_IPC, 1, &msic_thermal_platform_data, &ipc_device_handler},
  443. { 0 }
  444. };
  445. static void __init ipc_device_handler(struct sfi_device_table_entry *pentry,
  446. struct devs_id *dev)
  447. {
  448. struct platform_device *pdev;
  449. void *pdata = NULL;
  450. static struct resource res __initdata = {
  451. .name = "IRQ",
  452. .flags = IORESOURCE_IRQ,
  453. };
  454. pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
  455. pentry->name, pentry->irq);
  456. /*
  457. * We need to call platform init of IPC devices to fill misc_pdata
  458. * structure. It will be used in msic_init for initialization.
  459. */
  460. if (dev != NULL)
  461. pdata = dev->get_platform_data(pentry);
  462. /*
  463. * On Medfield the platform device creation is handled by the MSIC
  464. * MFD driver so we don't need to do it here.
  465. */
  466. if (intel_mid_has_msic())
  467. return;
  468. pdev = platform_device_alloc(pentry->name, 0);
  469. if (pdev == NULL) {
  470. pr_err("out of memory for SFI platform device '%s'.\n",
  471. pentry->name);
  472. return;
  473. }
  474. res.start = pentry->irq;
  475. platform_device_add_resources(pdev, &res, 1);
  476. pdev->dev.platform_data = pdata;
  477. intel_scu_device_register(pdev);
  478. }
  479. /*
  480. * we will search these buttons in SFI GPIO table (by name)
  481. * and register them dynamically. Please add all possible
  482. * buttons here, we will shrink them if no GPIO found.
  483. */
  484. static struct gpio_keys_button gpio_button[] = {
  485. {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
  486. {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
  487. {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
  488. {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
  489. {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
  490. {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
  491. {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
  492. {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
  493. {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
  494. {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
  495. };
  496. static struct gpio_keys_platform_data intel_mid_gpio_keys = {
  497. .buttons = gpio_button,
  498. .rep = 1,
  499. .nbuttons = -1, /* will fill it after search */
  500. };
  501. static struct platform_device pb_device = {
  502. .name = "gpio-keys",
  503. .id = -1,
  504. .dev = {
  505. .platform_data = &intel_mid_gpio_keys,
  506. },
  507. };
  508. /*
  509. * Shrink the non-existent buttons, register the gpio button
  510. * device if there is some
  511. */
  512. static int __init pb_keys_init(void)
  513. {
  514. struct gpio_keys_button *gb = gpio_button;
  515. int i, num, good = 0;
  516. num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
  517. for (i = 0; i < num; i++) {
  518. gb[i].gpio = get_gpio_by_name(gb[i].desc);
  519. pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc,
  520. gb[i].gpio);
  521. if (gb[i].gpio == -1)
  522. continue;
  523. if (i != good)
  524. gb[good] = gb[i];
  525. good++;
  526. }
  527. if (good) {
  528. intel_mid_gpio_keys.nbuttons = good;
  529. return platform_device_register(&pb_device);
  530. }
  531. return 0;
  532. }
  533. late_initcall(pb_keys_init);