blob: 7e6d7b204a05f9098590fffce70de4c6e15e231f [file] [log] [blame]
Thomas Gleixner3f4110a2009-08-29 14:54:20 +02001/*
Kuppuswamy Sathyanarayanan05454c22013-10-17 15:35:27 -07002 * intel-mid.c: Intel MID platform setup code
Thomas Gleixner3f4110a2009-08-29 14:54:20 +02003 *
Kuppuswamy Sathyanarayanan05454c22013-10-17 15:35:27 -07004 * (C) Copyright 2008, 2012 Intel Corporation
Thomas Gleixner3f4110a2009-08-29 14:54:20 +02005 * Author: Jacob Pan (jacob.jun.pan@intel.com)
Kuppuswamy Sathyanarayanan05454c22013-10-17 15:35:27 -07006 * Author: Sathyanarayanan Kuppuswamy <sathyanarayanan.kuppuswamy@intel.com>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +02007 *
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 */
Feng Tang1da4b1c2010-11-09 11:22:58 +000013
14#define pr_fmt(fmt) "mrst: " fmt
15
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020016#include <linux/init.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080017#include <linux/kernel.h>
Feng Tangefe3ed92011-08-26 11:25:14 +010018#include <linux/interrupt.h>
19#include <linux/scatterlist.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080020#include <linux/sfi.h>
Feng Tang1da4b1c2010-11-09 11:22:58 +000021#include <linux/intel_pmic_gpio.h>
22#include <linux/spi/spi.h>
23#include <linux/i2c.h>
Vivien Didelot58774572013-08-29 15:24:14 -040024#include <linux/platform_data/pca953x.h>
Feng Tang1da4b1c2010-11-09 11:22:58 +000025#include <linux/gpio_keys.h>
26#include <linux/input.h>
27#include <linux/platform_device.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080028#include <linux/irq.h>
Feng Tangcf089452010-02-12 03:37:38 -080029#include <linux/module.h>
Alan Cox42c25442011-09-07 16:06:51 +030030#include <linux/notifier.h>
Mika Westerberg360545c2011-10-18 12:41:22 +030031#include <linux/mfd/intel_msic.h>
Kirill A. Shutemov026abc32012-03-08 16:02:20 +000032#include <linux/gpio.h>
33#include <linux/i2c/tc35876x.h>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020034
35#include <asm/setup.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080036#include <asm/mpspec_def.h>
37#include <asm/hw_irq.h>
38#include <asm/apic.h>
39#include <asm/io_apic.h>
Kuppuswamy Sathyanarayanan05454c22013-10-17 15:35:27 -070040#include <asm/intel-mid.h>
41#include <asm/intel_mid_vrtc.h>
Jacob Pan5b78b672010-02-12 02:29:11 -080042#include <asm/io.h>
43#include <asm/i8259.h>
Feng Tang1da4b1c2010-11-09 11:22:58 +000044#include <asm/intel_scu_ipc.h>
Jacob Pan3746c6b2010-02-12 05:01:12 -080045#include <asm/apb_timer.h>
Alek Ducfb505a2010-11-10 16:50:08 +000046#include <asm/reboot.h>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020047
Jacob Pana875c012010-05-19 12:01:25 -070048/*
49 * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
50 * cmdline option x86_mrst_timer can be used to override the configuration
51 * to prefer one or the other.
52 * at runtime, there are basically three timer configurations:
53 * 1. per cpu apbt clock only
54 * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
55 * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
56 *
57 * by default (without cmdline option), platform code first detects cpu type
58 * to see if we are on lincroft or penwell, then set up both lapic or apbt
59 * clocks accordingly.
60 * i.e. by default, medfield uses configuration #2, moorestown uses #1.
61 * config #3 is supported but not recommended on medfield.
62 *
63 * rating and feature summary:
64 * lapic (with C3STOP) --------- 100
65 * apbt (always-on) ------------ 110
66 * lapic (always-on,ARAT) ------ 150
67 */
68
Paul Gortmaker148f9bb2013-06-18 18:23:59 -040069enum mrst_timer_options mrst_timer_options;
Jacob Pana875c012010-05-19 12:01:25 -070070
Jacob Pan16ab5392010-02-12 03:08:30 -080071static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
72static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
H. Peter Anvina75af582010-05-19 13:40:14 -070073enum mrst_cpu_type __mrst_cpu_chip;
74EXPORT_SYMBOL_GPL(__mrst_cpu_chip);
Jacob Pana0c173b2010-05-19 12:01:24 -070075
Jacob Pan16ab5392010-02-12 03:08:30 -080076int sfi_mtimer_num;
77
Feng Tangcf089452010-02-12 03:37:38 -080078struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
79EXPORT_SYMBOL_GPL(sfi_mrtc_array);
80int sfi_mrtc_num;
81
Jacob Pan48bc5562011-11-16 16:07:22 +000082static void mrst_power_off(void)
83{
Jacob Pan48bc5562011-11-16 16:07:22 +000084}
85
86static void mrst_reboot(void)
87{
Alan Cox1a8359e2012-01-26 17:33:30 +000088 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
Jacob Pan48bc5562011-11-16 16:07:22 +000089}
90
Jacob Pan16ab5392010-02-12 03:08:30 -080091/* parse all the mtimer info to a static mtimer array */
92static int __init sfi_parse_mtmr(struct sfi_table_header *table)
93{
94 struct sfi_table_simple *sb;
95 struct sfi_timer_table_entry *pentry;
96 struct mpc_intsrc mp_irq;
97 int totallen;
98
99 sb = (struct sfi_table_simple *)table;
100 if (!sfi_mtimer_num) {
101 sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
102 struct sfi_timer_table_entry);
103 pentry = (struct sfi_timer_table_entry *) sb->pentry;
104 totallen = sfi_mtimer_num * sizeof(*pentry);
105 memcpy(sfi_mtimer_array, pentry, totallen);
106 }
107
Feng Tang1da4b1c2010-11-09 11:22:58 +0000108 pr_debug("SFI MTIMER info (num = %d):\n", sfi_mtimer_num);
Jacob Pan16ab5392010-02-12 03:08:30 -0800109 pentry = sfi_mtimer_array;
110 for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
Feng Tang1da4b1c2010-11-09 11:22:58 +0000111 pr_debug("timer[%d]: paddr = 0x%08x, freq = %dHz,"
Jacob Pan16ab5392010-02-12 03:08:30 -0800112 " irq = %d\n", totallen, (u32)pentry->phys_addr,
113 pentry->freq_hz, pentry->irq);
114 if (!pentry->irq)
115 continue;
Jacob Pan9d90e492011-04-08 11:23:00 -0700116 mp_irq.type = MP_INTSRC;
Jacob Pan16ab5392010-02-12 03:08:30 -0800117 mp_irq.irqtype = mp_INT;
118/* triggering mode edge bit 2-3, active high polarity bit 0-1 */
119 mp_irq.irqflag = 5;
Jacob Pan9d90e492011-04-08 11:23:00 -0700120 mp_irq.srcbus = MP_BUS_ISA;
Jacob Pan16ab5392010-02-12 03:08:30 -0800121 mp_irq.srcbusirq = pentry->irq; /* IRQ */
122 mp_irq.dstapic = MP_APIC_ALL;
123 mp_irq.dstirq = pentry->irq;
Feng Tang2d8009b2010-11-19 11:33:35 +0800124 mp_save_irq(&mp_irq);
Jacob Pan16ab5392010-02-12 03:08:30 -0800125 }
126
127 return 0;
128}
129
130struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
131{
132 int i;
133 if (hint < sfi_mtimer_num) {
134 if (!sfi_mtimer_usage[hint]) {
Kuppuswamy Sathyanarayanand8059302013-10-17 15:35:26 -0700135 pr_debug("hint taken for timer %d irq %d\n",
Jacob Pan16ab5392010-02-12 03:08:30 -0800136 hint, sfi_mtimer_array[hint].irq);
137 sfi_mtimer_usage[hint] = 1;
138 return &sfi_mtimer_array[hint];
139 }
140 }
141 /* take the first timer available */
142 for (i = 0; i < sfi_mtimer_num;) {
143 if (!sfi_mtimer_usage[i]) {
144 sfi_mtimer_usage[i] = 1;
145 return &sfi_mtimer_array[i];
146 }
147 i++;
148 }
149 return NULL;
150}
151
152void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
153{
154 int i;
155 for (i = 0; i < sfi_mtimer_num;) {
156 if (mtmr->irq == sfi_mtimer_array[i].irq) {
157 sfi_mtimer_usage[i] = 0;
158 return;
159 }
160 i++;
161 }
162}
163
Feng Tangcf089452010-02-12 03:37:38 -0800164/* parse all the mrtc info to a global mrtc array */
165int __init sfi_parse_mrtc(struct sfi_table_header *table)
166{
167 struct sfi_table_simple *sb;
168 struct sfi_rtc_table_entry *pentry;
169 struct mpc_intsrc mp_irq;
170
171 int totallen;
172
173 sb = (struct sfi_table_simple *)table;
174 if (!sfi_mrtc_num) {
175 sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb,
176 struct sfi_rtc_table_entry);
177 pentry = (struct sfi_rtc_table_entry *)sb->pentry;
178 totallen = sfi_mrtc_num * sizeof(*pentry);
179 memcpy(sfi_mrtc_array, pentry, totallen);
180 }
181
Feng Tang1da4b1c2010-11-09 11:22:58 +0000182 pr_debug("SFI RTC info (num = %d):\n", sfi_mrtc_num);
Feng Tangcf089452010-02-12 03:37:38 -0800183 pentry = sfi_mrtc_array;
184 for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
Feng Tang1da4b1c2010-11-09 11:22:58 +0000185 pr_debug("RTC[%d]: paddr = 0x%08x, irq = %d\n",
Feng Tangcf089452010-02-12 03:37:38 -0800186 totallen, (u32)pentry->phys_addr, pentry->irq);
Jacob Pan9d90e492011-04-08 11:23:00 -0700187 mp_irq.type = MP_INTSRC;
Feng Tangcf089452010-02-12 03:37:38 -0800188 mp_irq.irqtype = mp_INT;
Feng Tang6f207e92010-11-11 15:50:50 +0000189 mp_irq.irqflag = 0xf; /* level trigger and active low */
Jacob Pan9d90e492011-04-08 11:23:00 -0700190 mp_irq.srcbus = MP_BUS_ISA;
Feng Tangcf089452010-02-12 03:37:38 -0800191 mp_irq.srcbusirq = pentry->irq; /* IRQ */
192 mp_irq.dstapic = MP_APIC_ALL;
193 mp_irq.dstirq = pentry->irq;
Feng Tang2d8009b2010-11-19 11:33:35 +0800194 mp_save_irq(&mp_irq);
Feng Tangcf089452010-02-12 03:37:38 -0800195 }
196 return 0;
197}
198
Jacob Pan3746c6b2010-02-12 05:01:12 -0800199static unsigned long __init mrst_calibrate_tsc(void)
200{
Alan Cox1a8359e2012-01-26 17:33:30 +0000201 unsigned long fast_calibrate;
202 u32 lo, hi, ratio, fsb;
Jacob Pan3746c6b2010-02-12 05:01:12 -0800203
Alan Cox1a8359e2012-01-26 17:33:30 +0000204 rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
205 pr_debug("IA32 perf status is 0x%x, 0x%0x\n", lo, hi);
206 ratio = (hi >> 8) & 0x1f;
207 pr_debug("ratio is %d\n", ratio);
208 if (!ratio) {
209 pr_err("read a zero ratio, should be incorrect!\n");
210 pr_err("force tsc ratio to 16 ...\n");
211 ratio = 16;
Dirk Brandewie0a915322011-11-10 13:42:53 +0000212 }
Alan Cox1a8359e2012-01-26 17:33:30 +0000213 rdmsr(MSR_FSB_FREQ, lo, hi);
214 if ((lo & 0x7) == 0x7)
215 fsb = PENWELL_FSB_FREQ_83SKU;
216 else
217 fsb = PENWELL_FSB_FREQ_100SKU;
218 fast_calibrate = ratio * fsb;
219 pr_debug("read penwell tsc %lu khz\n", fast_calibrate);
220 lapic_timer_frequency = fsb * 1000 / HZ;
221 /* mark tsc clocksource as reliable */
222 set_cpu_cap(&boot_cpu_data, X86_FEATURE_TSC_RELIABLE);
Kuppuswamy Sathyanarayanan05454c22013-10-17 15:35:27 -0700223
Jacob Pan3746c6b2010-02-12 05:01:12 -0800224 if (fast_calibrate)
225 return fast_calibrate;
226
227 return 0;
228}
229
Luis R. Rodriguez8fab6af2011-05-06 15:00:09 -0700230static void __init mrst_time_init(void)
Jacob Pan3746c6b2010-02-12 05:01:12 -0800231{
Jacob Pan7f05dec2010-11-09 11:28:43 +0000232 sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
Jacob Pana875c012010-05-19 12:01:25 -0700233 switch (mrst_timer_options) {
234 case MRST_TIMER_APBT_ONLY:
235 break;
236 case MRST_TIMER_LAPIC_APBT:
237 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
238 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
239 break;
240 default:
241 if (!boot_cpu_has(X86_FEATURE_ARAT))
242 break;
243 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
244 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
245 return;
246 }
247 /* we need at least one APB timer */
Jacob Pan3746c6b2010-02-12 05:01:12 -0800248 pre_init_apic_IRQ0();
249 apbt_time_init();
250}
251
Paul Gortmaker148f9bb2013-06-18 18:23:59 -0400252static void mrst_arch_setup(void)
Jacob Pan3746c6b2010-02-12 05:01:12 -0800253{
Jacob Pana0c173b2010-05-19 12:01:24 -0700254 if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
H. Peter Anvina75af582010-05-19 13:40:14 -0700255 __mrst_cpu_chip = MRST_CPU_CHIP_PENWELL;
Jacob Pana0c173b2010-05-19 12:01:24 -0700256 else {
Alan Cox1a8359e2012-01-26 17:33:30 +0000257 pr_err("Unknown Intel MID CPU (%d:%d), default to Penwell\n",
Jacob Pana0c173b2010-05-19 12:01:24 -0700258 boot_cpu_data.x86, boot_cpu_data.x86_model);
Alan Cox1a8359e2012-01-26 17:33:30 +0000259 __mrst_cpu_chip = MRST_CPU_CHIP_PENWELL;
Jacob Pana0c173b2010-05-19 12:01:24 -0700260 }
Jacob Pana0c173b2010-05-19 12:01:24 -0700261}
Jacob Pan3746c6b2010-02-12 05:01:12 -0800262
Feng Tang6d2cce62010-07-05 23:03:19 +0800263/* MID systems don't have i8042 controller */
264static int mrst_i8042_detect(void)
265{
266 return 0;
267}
268
Jacob Pan3746c6b2010-02-12 05:01:12 -0800269/*
Jacob Pan064a59b2011-11-10 13:43:05 +0000270 * Moorestown does not have external NMI source nor port 0x61 to report
271 * NMI status. The possible NMI sources are from pmu as a result of NMI
272 * watchdog or lock debug. Reading io port 0x61 results in 0xff which
273 * misled NMI handler.
274 */
275static unsigned char mrst_get_nmi_reason(void)
276{
277 return 0;
278}
279
280/*
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200281 * Moorestown specific x86_init function overrides and early setup
282 * calls.
283 */
284void __init x86_mrst_early_setup(void)
285{
286 x86_init.resources.probe_roms = x86_init_noop;
287 x86_init.resources.reserve_resources = x86_init_noop;
Jacob Pan5b78b672010-02-12 02:29:11 -0800288
Jacob Pan3746c6b2010-02-12 05:01:12 -0800289 x86_init.timers.timer_init = mrst_time_init;
Jacob Pana875c012010-05-19 12:01:25 -0700290 x86_init.timers.setup_percpu_clockev = x86_init_noop;
Jacob Pan3746c6b2010-02-12 05:01:12 -0800291
292 x86_init.irqs.pre_vector_init = x86_init_noop;
293
Jacob Pana0c173b2010-05-19 12:01:24 -0700294 x86_init.oem.arch_setup = mrst_arch_setup;
295
Jacob Pana875c012010-05-19 12:01:25 -0700296 x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
Jacob Pan3746c6b2010-02-12 05:01:12 -0800297
298 x86_platform.calibrate_tsc = mrst_calibrate_tsc;
Feng Tang6d2cce62010-07-05 23:03:19 +0800299 x86_platform.i8042_detect = mrst_i8042_detect;
Feng Tang168202c2011-02-15 00:13:32 +0800300 x86_init.timers.wallclock_init = mrst_rtc_init;
Jacob Pan064a59b2011-11-10 13:43:05 +0000301 x86_platform.get_nmi_reason = mrst_get_nmi_reason;
302
Jacob Panaf2730f2010-02-12 10:31:47 -0800303 x86_init.pci.init = pci_mrst_init;
304 x86_init.pci.fixup_irqs = x86_init_noop;
305
Jacob Pan5b78b672010-02-12 02:29:11 -0800306 legacy_pic = &null_legacy_pic;
Jacob Panfea24e22010-05-14 14:41:20 -0700307
Alek Ducfb505a2010-11-10 16:50:08 +0000308 /* Moorestown specific power_off/restart method */
309 pm_power_off = mrst_power_off;
310 machine_ops.emergency_restart = mrst_reboot;
311
Jacob Panfea24e22010-05-14 14:41:20 -0700312 /* Avoid searching for BIOS MP tables */
313 x86_init.mpparse.find_smp_config = x86_init_noop;
314 x86_init.mpparse.get_smp_config = x86_init_uint_noop;
Jacob Pan9d90e492011-04-08 11:23:00 -0700315 set_bit(MP_BUS_ISA, mp_bus_not_pci);
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200316}
Jacob Pana875c012010-05-19 12:01:25 -0700317
318/*
319 * if user does not want to use per CPU apb timer, just give it a lower rating
320 * than local apic timer and skip the late per cpu timer init.
321 */
322static inline int __init setup_x86_mrst_timer(char *arg)
323{
324 if (!arg)
325 return -EINVAL;
326
327 if (strcmp("apbt_only", arg) == 0)
328 mrst_timer_options = MRST_TIMER_APBT_ONLY;
329 else if (strcmp("lapic_and_apbt", arg) == 0)
330 mrst_timer_options = MRST_TIMER_LAPIC_APBT;
331 else {
Kuppuswamy Sathyanarayanan001d4c72013-10-17 15:35:25 -0700332 pr_warn("X86 MRST timer option %s not recognised"
Jacob Pana875c012010-05-19 12:01:25 -0700333 " use x86_mrst_timer=apbt_only or lapic_and_apbt\n",
334 arg);
335 return -EINVAL;
336 }
337 return 0;
338}
339__setup("x86_mrst_timer=", setup_x86_mrst_timer);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000340
341/*
342 * Parsing GPIO table first, since the DEVS table will need this table
343 * to map the pin name to the actual pin.
344 */
345static struct sfi_gpio_table_entry *gpio_table;
346static int gpio_num_entry;
347
348static int __init sfi_parse_gpio(struct sfi_table_header *table)
349{
350 struct sfi_table_simple *sb;
351 struct sfi_gpio_table_entry *pentry;
352 int num, i;
353
354 if (gpio_table)
355 return 0;
356 sb = (struct sfi_table_simple *)table;
357 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
358 pentry = (struct sfi_gpio_table_entry *)sb->pentry;
359
Zhang Yanfeiad0304c2013-03-12 12:58:02 +0800360 gpio_table = kmalloc(num * sizeof(*pentry), GFP_KERNEL);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000361 if (!gpio_table)
362 return -1;
363 memcpy(gpio_table, pentry, num * sizeof(*pentry));
364 gpio_num_entry = num;
365
366 pr_debug("GPIO pin info:\n");
367 for (i = 0; i < num; i++, pentry++)
368 pr_debug("info[%2d]: controller = %16.16s, pin_name = %16.16s,"
369 " pin = %d\n", i,
370 pentry->controller_name,
371 pentry->pin_name,
372 pentry->pin_no);
373 return 0;
374}
375
376static int get_gpio_by_name(const char *name)
377{
378 struct sfi_gpio_table_entry *pentry = gpio_table;
379 int i;
380
381 if (!pentry)
382 return -1;
383 for (i = 0; i < gpio_num_entry; i++, pentry++) {
384 if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
385 return pentry->pin_no;
386 }
387 return -1;
388}
389
390/*
391 * Here defines the array of devices platform data that IAFW would export
392 * through SFI "DEVS" table, we use name and type to match the device and
393 * its platform data.
394 */
395struct devs_id {
396 char name[SFI_NAME_LEN + 1];
397 u8 type;
398 u8 delay;
399 void *(*get_platform_data)(void *info);
400};
401
402/* the offset for the mapping of global gpio pin to irq */
403#define MRST_IRQ_OFFSET 0x100
404
405static void __init *pmic_gpio_platform_data(void *info)
406{
407 static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
408 int gpio_base = get_gpio_by_name("pmic_gpio_base");
409
410 if (gpio_base == -1)
411 gpio_base = 64;
412 pmic_gpio_pdata.gpio_base = gpio_base;
413 pmic_gpio_pdata.irq_base = gpio_base + MRST_IRQ_OFFSET;
414 pmic_gpio_pdata.gpiointr = 0xffffeff8;
415
416 return &pmic_gpio_pdata;
417}
418
419static void __init *max3111_platform_data(void *info)
420{
421 struct spi_board_info *spi_info = info;
422 int intr = get_gpio_by_name("max3111_int");
423
Feng Tangefe3ed92011-08-26 11:25:14 +0100424 spi_info->mode = SPI_MODE_0;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000425 if (intr == -1)
426 return NULL;
427 spi_info->irq = intr + MRST_IRQ_OFFSET;
428 return NULL;
429}
430
431/* we have multiple max7315 on the board ... */
432#define MAX7315_NUM 2
433static void __init *max7315_platform_data(void *info)
434{
435 static struct pca953x_platform_data max7315_pdata[MAX7315_NUM];
436 static int nr;
437 struct pca953x_platform_data *max7315 = &max7315_pdata[nr];
438 struct i2c_board_info *i2c_info = info;
439 int gpio_base, intr;
440 char base_pin_name[SFI_NAME_LEN + 1];
441 char intr_pin_name[SFI_NAME_LEN + 1];
442
443 if (nr == MAX7315_NUM) {
444 pr_err("too many max7315s, we only support %d\n",
445 MAX7315_NUM);
446 return NULL;
447 }
448 /* we have several max7315 on the board, we only need load several
449 * instances of the same pca953x driver to cover them
450 */
451 strcpy(i2c_info->type, "max7315");
452 if (nr++) {
453 sprintf(base_pin_name, "max7315_%d_base", nr);
454 sprintf(intr_pin_name, "max7315_%d_int", nr);
455 } else {
456 strcpy(base_pin_name, "max7315_base");
457 strcpy(intr_pin_name, "max7315_int");
458 }
459
460 gpio_base = get_gpio_by_name(base_pin_name);
461 intr = get_gpio_by_name(intr_pin_name);
462
463 if (gpio_base == -1)
464 return NULL;
465 max7315->gpio_base = gpio_base;
466 if (intr != -1) {
467 i2c_info->irq = intr + MRST_IRQ_OFFSET;
468 max7315->irq_base = gpio_base + MRST_IRQ_OFFSET;
469 } else {
470 i2c_info->irq = -1;
471 max7315->irq_base = -1;
472 }
473 return max7315;
474}
475
Jekyll Lai28744b32011-11-16 18:01:20 +0000476static void *tca6416_platform_data(void *info)
477{
478 static struct pca953x_platform_data tca6416;
479 struct i2c_board_info *i2c_info = info;
480 int gpio_base, intr;
481 char base_pin_name[SFI_NAME_LEN + 1];
482 char intr_pin_name[SFI_NAME_LEN + 1];
483
484 strcpy(i2c_info->type, "tca6416");
485 strcpy(base_pin_name, "tca6416_base");
486 strcpy(intr_pin_name, "tca6416_int");
487
488 gpio_base = get_gpio_by_name(base_pin_name);
489 intr = get_gpio_by_name(intr_pin_name);
490
491 if (gpio_base == -1)
492 return NULL;
493 tca6416.gpio_base = gpio_base;
494 if (intr != -1) {
495 i2c_info->irq = intr + MRST_IRQ_OFFSET;
496 tca6416.irq_base = gpio_base + MRST_IRQ_OFFSET;
497 } else {
498 i2c_info->irq = -1;
499 tca6416.irq_base = -1;
500 }
501 return &tca6416;
502}
503
504static void *mpu3050_platform_data(void *info)
505{
506 struct i2c_board_info *i2c_info = info;
507 int intr = get_gpio_by_name("mpu3050_int");
508
509 if (intr == -1)
510 return NULL;
511
512 i2c_info->irq = intr + MRST_IRQ_OFFSET;
513 return NULL;
514}
515
Feng Tang1da4b1c2010-11-09 11:22:58 +0000516static void __init *emc1403_platform_data(void *info)
517{
518 static short intr2nd_pdata;
519 struct i2c_board_info *i2c_info = info;
520 int intr = get_gpio_by_name("thermal_int");
521 int intr2nd = get_gpio_by_name("thermal_alert");
522
523 if (intr == -1 || intr2nd == -1)
524 return NULL;
525
526 i2c_info->irq = intr + MRST_IRQ_OFFSET;
527 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
528
529 return &intr2nd_pdata;
530}
531
532static void __init *lis331dl_platform_data(void *info)
533{
534 static short intr2nd_pdata;
535 struct i2c_board_info *i2c_info = info;
536 int intr = get_gpio_by_name("accel_int");
537 int intr2nd = get_gpio_by_name("accel_2");
538
539 if (intr == -1 || intr2nd == -1)
540 return NULL;
541
542 i2c_info->irq = intr + MRST_IRQ_OFFSET;
543 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
544
545 return &intr2nd_pdata;
546}
547
Vinod Koul86071532010-11-10 17:40:48 +0000548static void __init *no_platform_data(void *info)
549{
550 return NULL;
551}
552
Mika Westerberg360545c2011-10-18 12:41:22 +0300553static struct resource msic_resources[] = {
554 {
555 .start = INTEL_MSIC_IRQ_PHYS_BASE,
556 .end = INTEL_MSIC_IRQ_PHYS_BASE + 64 - 1,
557 .flags = IORESOURCE_MEM,
558 },
559};
560
561static struct intel_msic_platform_data msic_pdata;
562
563static struct platform_device msic_device = {
564 .name = "intel_msic",
565 .id = -1,
566 .dev = {
567 .platform_data = &msic_pdata,
568 },
569 .num_resources = ARRAY_SIZE(msic_resources),
570 .resource = msic_resources,
571};
572
573static inline bool mrst_has_msic(void)
574{
575 return mrst_identify_cpu() == MRST_CPU_CHIP_PENWELL;
576}
577
578static int msic_scu_status_change(struct notifier_block *nb,
579 unsigned long code, void *data)
580{
581 if (code == SCU_DOWN) {
582 platform_device_unregister(&msic_device);
583 return 0;
584 }
585
586 return platform_device_register(&msic_device);
587}
588
589static int __init msic_init(void)
590{
591 static struct notifier_block msic_scu_notifier = {
592 .notifier_call = msic_scu_status_change,
593 };
594
595 /*
596 * We need to be sure that the SCU IPC is ready before MSIC device
597 * can be registered.
598 */
599 if (mrst_has_msic())
600 intel_scu_notifier_add(&msic_scu_notifier);
601
602 return 0;
603}
604arch_initcall(msic_init);
605
606/*
607 * msic_generic_platform_data - sets generic platform data for the block
608 * @info: pointer to the SFI device table entry for this block
609 * @block: MSIC block
610 *
611 * Function sets IRQ number from the SFI table entry for given device to
612 * the MSIC platform data.
613 */
614static void *msic_generic_platform_data(void *info, enum intel_msic_block block)
615{
616 struct sfi_device_table_entry *entry = info;
617
618 BUG_ON(block < 0 || block >= INTEL_MSIC_BLOCK_LAST);
619 msic_pdata.irq[block] = entry->irq;
620
621 return no_platform_data(info);
622}
623
624static void *msic_battery_platform_data(void *info)
625{
626 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_BATTERY);
627}
628
629static void *msic_gpio_platform_data(void *info)
630{
631 static struct intel_msic_gpio_pdata pdata;
632 int gpio = get_gpio_by_name("msic_gpio_base");
633
634 if (gpio < 0)
635 return NULL;
636
637 pdata.gpio_base = gpio;
638 msic_pdata.gpio = &pdata;
639
640 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_GPIO);
641}
642
643static void *msic_audio_platform_data(void *info)
644{
645 struct platform_device *pdev;
646
647 pdev = platform_device_register_simple("sst-platform", -1, NULL, 0);
648 if (IS_ERR(pdev)) {
649 pr_err("failed to create audio platform device\n");
650 return NULL;
651 }
652
653 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_AUDIO);
654}
655
656static void *msic_power_btn_platform_data(void *info)
657{
658 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_POWER_BTN);
659}
660
661static void *msic_ocd_platform_data(void *info)
662{
663 static struct intel_msic_ocd_pdata pdata;
664 int gpio = get_gpio_by_name("ocd_gpio");
665
666 if (gpio < 0)
667 return NULL;
668
669 pdata.gpio = gpio;
670 msic_pdata.ocd = &pdata;
671
672 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_OCD);
673}
674
Mika Westerbergecfdb0a2012-01-26 17:36:08 +0000675static void *msic_thermal_platform_data(void *info)
676{
677 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_THERMAL);
678}
679
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000680/* tc35876x DSI-LVDS bridge chip and panel platform data */
681static void *tc35876x_platform_data(void *data)
682{
Kuppuswamy Sathyanarayanand8059302013-10-17 15:35:26 -0700683 static struct tc35876x_platform_data pdata;
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000684
Kuppuswamy Sathyanarayanand8059302013-10-17 15:35:26 -0700685 /* gpio pins set to -1 will not be used by the driver */
686 pdata.gpio_bridge_reset = get_gpio_by_name("LCMB_RXEN");
687 pdata.gpio_panel_bl_en = get_gpio_by_name("6S6P_BL_EN");
688 pdata.gpio_panel_vadd = get_gpio_by_name("EN_VREG_LCD_V3P3");
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000689
Kuppuswamy Sathyanarayanand8059302013-10-17 15:35:26 -0700690 return &pdata;
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000691}
692
Feng Tang1da4b1c2010-11-09 11:22:58 +0000693static const struct devs_id __initconst device_ids[] = {
William Douglas9f80d8b2011-11-10 13:50:38 +0000694 {"bma023", SFI_DEV_TYPE_I2C, 1, &no_platform_data},
Feng Tang1da4b1c2010-11-09 11:22:58 +0000695 {"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data},
Feng Tangefa22122011-11-16 18:32:34 +0000696 {"pmic_gpio", SFI_DEV_TYPE_IPC, 1, &pmic_gpio_platform_data},
Feng Tang1da4b1c2010-11-09 11:22:58 +0000697 {"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data},
698 {"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
699 {"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
Jekyll Lai28744b32011-11-16 18:01:20 +0000700 {"tca6416", SFI_DEV_TYPE_I2C, 1, &tca6416_platform_data},
Feng Tang1da4b1c2010-11-09 11:22:58 +0000701 {"emc1403", SFI_DEV_TYPE_I2C, 1, &emc1403_platform_data},
702 {"i2c_accel", SFI_DEV_TYPE_I2C, 0, &lis331dl_platform_data},
Vinod Koul86071532010-11-10 17:40:48 +0000703 {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
Jekyll Lai28744b32011-11-16 18:01:20 +0000704 {"mpu3050", SFI_DEV_TYPE_I2C, 1, &mpu3050_platform_data},
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000705 {"i2c_disp_brig", SFI_DEV_TYPE_I2C, 0, &tc35876x_platform_data},
Mika Westerberg360545c2011-10-18 12:41:22 +0300706
707 /* MSIC subdevices */
708 {"msic_battery", SFI_DEV_TYPE_IPC, 1, &msic_battery_platform_data},
709 {"msic_gpio", SFI_DEV_TYPE_IPC, 1, &msic_gpio_platform_data},
710 {"msic_audio", SFI_DEV_TYPE_IPC, 1, &msic_audio_platform_data},
711 {"msic_power_btn", SFI_DEV_TYPE_IPC, 1, &msic_power_btn_platform_data},
712 {"msic_ocd", SFI_DEV_TYPE_IPC, 1, &msic_ocd_platform_data},
Mika Westerbergecfdb0a2012-01-26 17:36:08 +0000713 {"msic_thermal", SFI_DEV_TYPE_IPC, 1, &msic_thermal_platform_data},
Mika Westerberg360545c2011-10-18 12:41:22 +0300714
Feng Tang1da4b1c2010-11-09 11:22:58 +0000715 {},
716};
717
718#define MAX_IPCDEVS 24
719static struct platform_device *ipc_devs[MAX_IPCDEVS];
720static int ipc_next_dev;
721
722#define MAX_SCU_SPI 24
723static struct spi_board_info *spi_devs[MAX_SCU_SPI];
724static int spi_next_dev;
725
726#define MAX_SCU_I2C 24
727static struct i2c_board_info *i2c_devs[MAX_SCU_I2C];
728static int i2c_bus[MAX_SCU_I2C];
729static int i2c_next_dev;
730
731static void __init intel_scu_device_register(struct platform_device *pdev)
732{
Kuppuswamy Sathyanarayanand8059302013-10-17 15:35:26 -0700733 if (ipc_next_dev == MAX_IPCDEVS)
Feng Tang1da4b1c2010-11-09 11:22:58 +0000734 pr_err("too many SCU IPC devices");
735 else
736 ipc_devs[ipc_next_dev++] = pdev;
737}
738
739static void __init intel_scu_spi_device_register(struct spi_board_info *sdev)
740{
741 struct spi_board_info *new_dev;
742
743 if (spi_next_dev == MAX_SCU_SPI) {
744 pr_err("too many SCU SPI devices");
745 return;
746 }
747
748 new_dev = kzalloc(sizeof(*sdev), GFP_KERNEL);
749 if (!new_dev) {
750 pr_err("failed to alloc mem for delayed spi dev %s\n",
751 sdev->modalias);
752 return;
753 }
754 memcpy(new_dev, sdev, sizeof(*sdev));
755
756 spi_devs[spi_next_dev++] = new_dev;
757}
758
759static void __init intel_scu_i2c_device_register(int bus,
760 struct i2c_board_info *idev)
761{
762 struct i2c_board_info *new_dev;
763
764 if (i2c_next_dev == MAX_SCU_I2C) {
765 pr_err("too many SCU I2C devices");
766 return;
767 }
768
769 new_dev = kzalloc(sizeof(*idev), GFP_KERNEL);
770 if (!new_dev) {
771 pr_err("failed to alloc mem for delayed i2c dev %s\n",
772 idev->type);
773 return;
774 }
775 memcpy(new_dev, idev, sizeof(*idev));
776
777 i2c_bus[i2c_next_dev] = bus;
778 i2c_devs[i2c_next_dev++] = new_dev;
779}
780
Alan Cox42c25442011-09-07 16:06:51 +0300781BLOCKING_NOTIFIER_HEAD(intel_scu_notifier);
782EXPORT_SYMBOL_GPL(intel_scu_notifier);
783
Feng Tang1da4b1c2010-11-09 11:22:58 +0000784/* Called by IPC driver */
Greg Kroah-Hartmana18e3692012-12-21 14:02:53 -0800785void intel_scu_devices_create(void)
Feng Tang1da4b1c2010-11-09 11:22:58 +0000786{
787 int i;
788
789 for (i = 0; i < ipc_next_dev; i++)
790 platform_device_add(ipc_devs[i]);
791
792 for (i = 0; i < spi_next_dev; i++)
793 spi_register_board_info(spi_devs[i], 1);
794
795 for (i = 0; i < i2c_next_dev; i++) {
796 struct i2c_adapter *adapter;
797 struct i2c_client *client;
798
799 adapter = i2c_get_adapter(i2c_bus[i]);
800 if (adapter) {
801 client = i2c_new_device(adapter, i2c_devs[i]);
802 if (!client)
803 pr_err("can't create i2c device %s\n",
804 i2c_devs[i]->type);
805 } else
806 i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1);
807 }
H Hartley Sweetend0d3bc62012-04-24 15:00:53 -0700808 intel_scu_notifier_post(SCU_AVAILABLE, NULL);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000809}
810EXPORT_SYMBOL_GPL(intel_scu_devices_create);
811
812/* Called by IPC driver */
813void intel_scu_devices_destroy(void)
814{
815 int i;
816
H Hartley Sweetend0d3bc62012-04-24 15:00:53 -0700817 intel_scu_notifier_post(SCU_DOWN, NULL);
Alan Cox42c25442011-09-07 16:06:51 +0300818
Feng Tang1da4b1c2010-11-09 11:22:58 +0000819 for (i = 0; i < ipc_next_dev; i++)
820 platform_device_del(ipc_devs[i]);
821}
822EXPORT_SYMBOL_GPL(intel_scu_devices_destroy);
823
824static void __init install_irq_resource(struct platform_device *pdev, int irq)
825{
826 /* Single threaded */
827 static struct resource __initdata res = {
828 .name = "IRQ",
829 .flags = IORESOURCE_IRQ,
830 };
831 res.start = irq;
832 platform_device_add_resources(pdev, &res, 1);
833}
834
Mika Westerberg360545c2011-10-18 12:41:22 +0300835static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *entry)
Feng Tang1da4b1c2010-11-09 11:22:58 +0000836{
837 const struct devs_id *dev = device_ids;
Mika Westerberg360545c2011-10-18 12:41:22 +0300838 struct platform_device *pdev;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000839 void *pdata = NULL;
840
841 while (dev->name[0]) {
842 if (dev->type == SFI_DEV_TYPE_IPC &&
Mika Westerberg360545c2011-10-18 12:41:22 +0300843 !strncmp(dev->name, entry->name, SFI_NAME_LEN)) {
844 pdata = dev->get_platform_data(entry);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000845 break;
846 }
847 dev++;
848 }
Mika Westerberg360545c2011-10-18 12:41:22 +0300849
850 /*
851 * On Medfield the platform device creation is handled by the MSIC
852 * MFD driver so we don't need to do it here.
853 */
854 if (mrst_has_msic())
855 return;
856
Alan Cox54b02642011-11-16 18:17:40 +0000857 pdev = platform_device_alloc(entry->name, 0);
Mika Westerberg360545c2011-10-18 12:41:22 +0300858 if (pdev == NULL) {
859 pr_err("out of memory for SFI platform device '%s'.\n",
860 entry->name);
861 return;
862 }
863 install_irq_resource(pdev, entry->irq);
864
Feng Tang1da4b1c2010-11-09 11:22:58 +0000865 pdev->dev.platform_data = pdata;
866 intel_scu_device_register(pdev);
867}
868
869static void __init sfi_handle_spi_dev(struct spi_board_info *spi_info)
870{
871 const struct devs_id *dev = device_ids;
872 void *pdata = NULL;
873
874 while (dev->name[0]) {
875 if (dev->type == SFI_DEV_TYPE_SPI &&
Kuppuswamy Sathyanarayanand8059302013-10-17 15:35:26 -0700876 !strncmp(dev->name, spi_info->modalias,
877 SFI_NAME_LEN)) {
Feng Tang1da4b1c2010-11-09 11:22:58 +0000878 pdata = dev->get_platform_data(spi_info);
879 break;
880 }
881 dev++;
882 }
883 spi_info->platform_data = pdata;
884 if (dev->delay)
885 intel_scu_spi_device_register(spi_info);
886 else
887 spi_register_board_info(spi_info, 1);
888}
889
890static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info)
891{
892 const struct devs_id *dev = device_ids;
893 void *pdata = NULL;
894
895 while (dev->name[0]) {
896 if (dev->type == SFI_DEV_TYPE_I2C &&
897 !strncmp(dev->name, i2c_info->type, SFI_NAME_LEN)) {
898 pdata = dev->get_platform_data(i2c_info);
899 break;
900 }
901 dev++;
902 }
903 i2c_info->platform_data = pdata;
904
905 if (dev->delay)
906 intel_scu_i2c_device_register(bus, i2c_info);
907 else
908 i2c_register_board_info(bus, i2c_info, 1);
Kuppuswamy Sathyanarayanand8059302013-10-17 15:35:26 -0700909}
Feng Tang1da4b1c2010-11-09 11:22:58 +0000910
911
912static int __init sfi_parse_devs(struct sfi_table_header *table)
913{
914 struct sfi_table_simple *sb;
915 struct sfi_device_table_entry *pentry;
916 struct spi_board_info spi_info;
917 struct i2c_board_info i2c_info;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000918 int num, i, bus;
919 int ioapic;
920 struct io_apic_irq_attr irq_attr;
921
922 sb = (struct sfi_table_simple *)table;
923 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_device_table_entry);
924 pentry = (struct sfi_device_table_entry *)sb->pentry;
925
926 for (i = 0; i < num; i++, pentry++) {
Mika Westerberg153b19a2011-10-13 12:04:20 +0300927 int irq = pentry->irq;
928
929 if (irq != (u8)0xff) { /* native RTE case */
Feng Tang1da4b1c2010-11-09 11:22:58 +0000930 /* these SPI2 devices are not exposed to system as PCI
931 * devices, but they have separate RTE entry in IOAPIC
932 * so we have to enable them one by one here
933 */
Mika Westerberg153b19a2011-10-13 12:04:20 +0300934 ioapic = mp_find_ioapic(irq);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000935 irq_attr.ioapic = ioapic;
Mika Westerberg153b19a2011-10-13 12:04:20 +0300936 irq_attr.ioapic_pin = irq;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000937 irq_attr.trigger = 1;
938 irq_attr.polarity = 1;
Mika Westerberg153b19a2011-10-13 12:04:20 +0300939 io_apic_set_pci_routing(NULL, irq, &irq_attr);
Kirill A. Shutemova94cc4e2011-08-26 12:20:59 +0100940 } else
Mika Westerberg153b19a2011-10-13 12:04:20 +0300941 irq = 0; /* No irq */
Kirill A. Shutemova94cc4e2011-08-26 12:20:59 +0100942
Feng Tang1da4b1c2010-11-09 11:22:58 +0000943 switch (pentry->type) {
944 case SFI_DEV_TYPE_IPC:
Feng Tang1da4b1c2010-11-09 11:22:58 +0000945 pr_debug("info[%2d]: IPC bus, name = %16.16s, "
Mika Westerberg360545c2011-10-18 12:41:22 +0300946 "irq = 0x%2x\n", i, pentry->name, pentry->irq);
947 sfi_handle_ipc_dev(pentry);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000948 break;
949 case SFI_DEV_TYPE_SPI:
950 memset(&spi_info, 0, sizeof(spi_info));
951 strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
Mika Westerberg153b19a2011-10-13 12:04:20 +0300952 spi_info.irq = irq;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000953 spi_info.bus_num = pentry->host_num;
954 spi_info.chip_select = pentry->addr;
955 spi_info.max_speed_hz = pentry->max_freq;
956 pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, "
957 "irq = 0x%2x, max_freq = %d, cs = %d\n", i,
958 spi_info.bus_num,
959 spi_info.modalias,
960 spi_info.irq,
961 spi_info.max_speed_hz,
962 spi_info.chip_select);
963 sfi_handle_spi_dev(&spi_info);
964 break;
965 case SFI_DEV_TYPE_I2C:
966 memset(&i2c_info, 0, sizeof(i2c_info));
967 bus = pentry->host_num;
968 strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
Mika Westerberg153b19a2011-10-13 12:04:20 +0300969 i2c_info.irq = irq;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000970 i2c_info.addr = pentry->addr;
971 pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, "
972 "irq = 0x%2x, addr = 0x%x\n", i, bus,
973 i2c_info.type,
974 i2c_info.irq,
975 i2c_info.addr);
976 sfi_handle_i2c_dev(bus, &i2c_info);
977 break;
978 case SFI_DEV_TYPE_UART:
979 case SFI_DEV_TYPE_HSI:
980 default:
981 ;
982 }
983 }
984 return 0;
985}
986
987static int __init mrst_platform_init(void)
988{
989 sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
990 sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
991 return 0;
992}
993arch_initcall(mrst_platform_init);
994
995/*
996 * we will search these buttons in SFI GPIO table (by name)
997 * and register them dynamically. Please add all possible
998 * buttons here, we will shrink them if no GPIO found.
999 */
1000static struct gpio_keys_button gpio_button[] = {
1001 {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
1002 {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
1003 {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
1004 {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
1005 {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
1006 {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
1007 {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
1008 {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
1009 {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
1010 {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
1011};
1012
1013static struct gpio_keys_platform_data mrst_gpio_keys = {
1014 .buttons = gpio_button,
1015 .rep = 1,
1016 .nbuttons = -1, /* will fill it after search */
1017};
1018
1019static struct platform_device pb_device = {
1020 .name = "gpio-keys",
1021 .id = -1,
1022 .dev = {
1023 .platform_data = &mrst_gpio_keys,
1024 },
1025};
1026
1027/*
1028 * Shrink the non-existent buttons, register the gpio button
1029 * device if there is some
1030 */
1031static int __init pb_keys_init(void)
1032{
1033 struct gpio_keys_button *gb = gpio_button;
1034 int i, num, good = 0;
1035
1036 num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
1037 for (i = 0; i < num; i++) {
1038 gb[i].gpio = get_gpio_by_name(gb[i].desc);
Kuppuswamy Sathyanarayanand8059302013-10-17 15:35:26 -07001039 pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc,
1040 gb[i].gpio);
Feng Tang1da4b1c2010-11-09 11:22:58 +00001041 if (gb[i].gpio == -1)
1042 continue;
1043
1044 if (i != good)
1045 gb[good] = gb[i];
1046 good++;
1047 }
1048
1049 if (good) {
1050 mrst_gpio_keys.nbuttons = good;
1051 return platform_device_register(&pb_device);
1052 }
1053 return 0;
1054}
1055late_initcall(pb_keys_init);