blob: e6379526675ba1efd4d686d99d56358b68304564 [file] [log] [blame]
Thomas Gleixner3f4110a2009-08-29 14:54:20 +02001/*
2 * mrst.c: Intel Moorestown platform specific setup code
3 *
4 * (C) Copyright 2008 Intel Corporation
5 * Author: Jacob Pan (jacob.jun.pan@intel.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; version 2
10 * of the License.
11 */
Feng Tang1da4b1c2010-11-09 11:22:58 +000012
13#define pr_fmt(fmt) "mrst: " fmt
14
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020015#include <linux/init.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080016#include <linux/kernel.h>
Feng Tangefe3ed92011-08-26 11:25:14 +010017#include <linux/interrupt.h>
18#include <linux/scatterlist.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080019#include <linux/sfi.h>
Feng Tang1da4b1c2010-11-09 11:22:58 +000020#include <linux/intel_pmic_gpio.h>
21#include <linux/spi/spi.h>
22#include <linux/i2c.h>
23#include <linux/i2c/pca953x.h>
24#include <linux/gpio_keys.h>
25#include <linux/input.h>
26#include <linux/platform_device.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080027#include <linux/irq.h>
Feng Tangcf089452010-02-12 03:37:38 -080028#include <linux/module.h>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020029
30#include <asm/setup.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080031#include <asm/mpspec_def.h>
32#include <asm/hw_irq.h>
33#include <asm/apic.h>
34#include <asm/io_apic.h>
Jacob Pan5b78b672010-02-12 02:29:11 -080035#include <asm/mrst.h>
Feng Tang168202c2011-02-15 00:13:32 +080036#include <asm/mrst-vrtc.h>
Jacob Pan5b78b672010-02-12 02:29:11 -080037#include <asm/io.h>
38#include <asm/i8259.h>
Feng Tang1da4b1c2010-11-09 11:22:58 +000039#include <asm/intel_scu_ipc.h>
Jacob Pan3746c6b2010-02-12 05:01:12 -080040#include <asm/apb_timer.h>
Alek Ducfb505a2010-11-10 16:50:08 +000041#include <asm/reboot.h>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020042
Jacob Pana875c012010-05-19 12:01:25 -070043/*
44 * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
45 * cmdline option x86_mrst_timer can be used to override the configuration
46 * to prefer one or the other.
47 * at runtime, there are basically three timer configurations:
48 * 1. per cpu apbt clock only
49 * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
50 * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
51 *
52 * by default (without cmdline option), platform code first detects cpu type
53 * to see if we are on lincroft or penwell, then set up both lapic or apbt
54 * clocks accordingly.
55 * i.e. by default, medfield uses configuration #2, moorestown uses #1.
56 * config #3 is supported but not recommended on medfield.
57 *
58 * rating and feature summary:
59 * lapic (with C3STOP) --------- 100
60 * apbt (always-on) ------------ 110
61 * lapic (always-on,ARAT) ------ 150
62 */
63
H. Peter Anvin14671382010-05-19 14:37:40 -070064__cpuinitdata enum mrst_timer_options mrst_timer_options;
Jacob Pana875c012010-05-19 12:01:25 -070065
Jacob Pan16ab5392010-02-12 03:08:30 -080066static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
67static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
H. Peter Anvina75af582010-05-19 13:40:14 -070068enum mrst_cpu_type __mrst_cpu_chip;
69EXPORT_SYMBOL_GPL(__mrst_cpu_chip);
Jacob Pana0c173b2010-05-19 12:01:24 -070070
Jacob Pan16ab5392010-02-12 03:08:30 -080071int sfi_mtimer_num;
72
Feng Tangcf089452010-02-12 03:37:38 -080073struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
74EXPORT_SYMBOL_GPL(sfi_mrtc_array);
75int sfi_mrtc_num;
76
Jacob Pan16ab5392010-02-12 03:08:30 -080077/* parse all the mtimer info to a static mtimer array */
78static int __init sfi_parse_mtmr(struct sfi_table_header *table)
79{
80 struct sfi_table_simple *sb;
81 struct sfi_timer_table_entry *pentry;
82 struct mpc_intsrc mp_irq;
83 int totallen;
84
85 sb = (struct sfi_table_simple *)table;
86 if (!sfi_mtimer_num) {
87 sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
88 struct sfi_timer_table_entry);
89 pentry = (struct sfi_timer_table_entry *) sb->pentry;
90 totallen = sfi_mtimer_num * sizeof(*pentry);
91 memcpy(sfi_mtimer_array, pentry, totallen);
92 }
93
Feng Tang1da4b1c2010-11-09 11:22:58 +000094 pr_debug("SFI MTIMER info (num = %d):\n", sfi_mtimer_num);
Jacob Pan16ab5392010-02-12 03:08:30 -080095 pentry = sfi_mtimer_array;
96 for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
Feng Tang1da4b1c2010-11-09 11:22:58 +000097 pr_debug("timer[%d]: paddr = 0x%08x, freq = %dHz,"
Jacob Pan16ab5392010-02-12 03:08:30 -080098 " irq = %d\n", totallen, (u32)pentry->phys_addr,
99 pentry->freq_hz, pentry->irq);
100 if (!pentry->irq)
101 continue;
Jacob Pan9d90e492011-04-08 11:23:00 -0700102 mp_irq.type = MP_INTSRC;
Jacob Pan16ab5392010-02-12 03:08:30 -0800103 mp_irq.irqtype = mp_INT;
104/* triggering mode edge bit 2-3, active high polarity bit 0-1 */
105 mp_irq.irqflag = 5;
Jacob Pan9d90e492011-04-08 11:23:00 -0700106 mp_irq.srcbus = MP_BUS_ISA;
Jacob Pan16ab5392010-02-12 03:08:30 -0800107 mp_irq.srcbusirq = pentry->irq; /* IRQ */
108 mp_irq.dstapic = MP_APIC_ALL;
109 mp_irq.dstirq = pentry->irq;
Feng Tang2d8009b2010-11-19 11:33:35 +0800110 mp_save_irq(&mp_irq);
Jacob Pan16ab5392010-02-12 03:08:30 -0800111 }
112
113 return 0;
114}
115
116struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
117{
118 int i;
119 if (hint < sfi_mtimer_num) {
120 if (!sfi_mtimer_usage[hint]) {
121 pr_debug("hint taken for timer %d irq %d\n",\
122 hint, sfi_mtimer_array[hint].irq);
123 sfi_mtimer_usage[hint] = 1;
124 return &sfi_mtimer_array[hint];
125 }
126 }
127 /* take the first timer available */
128 for (i = 0; i < sfi_mtimer_num;) {
129 if (!sfi_mtimer_usage[i]) {
130 sfi_mtimer_usage[i] = 1;
131 return &sfi_mtimer_array[i];
132 }
133 i++;
134 }
135 return NULL;
136}
137
138void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
139{
140 int i;
141 for (i = 0; i < sfi_mtimer_num;) {
142 if (mtmr->irq == sfi_mtimer_array[i].irq) {
143 sfi_mtimer_usage[i] = 0;
144 return;
145 }
146 i++;
147 }
148}
149
Feng Tangcf089452010-02-12 03:37:38 -0800150/* parse all the mrtc info to a global mrtc array */
151int __init sfi_parse_mrtc(struct sfi_table_header *table)
152{
153 struct sfi_table_simple *sb;
154 struct sfi_rtc_table_entry *pentry;
155 struct mpc_intsrc mp_irq;
156
157 int totallen;
158
159 sb = (struct sfi_table_simple *)table;
160 if (!sfi_mrtc_num) {
161 sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb,
162 struct sfi_rtc_table_entry);
163 pentry = (struct sfi_rtc_table_entry *)sb->pentry;
164 totallen = sfi_mrtc_num * sizeof(*pentry);
165 memcpy(sfi_mrtc_array, pentry, totallen);
166 }
167
Feng Tang1da4b1c2010-11-09 11:22:58 +0000168 pr_debug("SFI RTC info (num = %d):\n", sfi_mrtc_num);
Feng Tangcf089452010-02-12 03:37:38 -0800169 pentry = sfi_mrtc_array;
170 for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
Feng Tang1da4b1c2010-11-09 11:22:58 +0000171 pr_debug("RTC[%d]: paddr = 0x%08x, irq = %d\n",
Feng Tangcf089452010-02-12 03:37:38 -0800172 totallen, (u32)pentry->phys_addr, pentry->irq);
Jacob Pan9d90e492011-04-08 11:23:00 -0700173 mp_irq.type = MP_INTSRC;
Feng Tangcf089452010-02-12 03:37:38 -0800174 mp_irq.irqtype = mp_INT;
Feng Tang6f207e92010-11-11 15:50:50 +0000175 mp_irq.irqflag = 0xf; /* level trigger and active low */
Jacob Pan9d90e492011-04-08 11:23:00 -0700176 mp_irq.srcbus = MP_BUS_ISA;
Feng Tangcf089452010-02-12 03:37:38 -0800177 mp_irq.srcbusirq = pentry->irq; /* IRQ */
178 mp_irq.dstapic = MP_APIC_ALL;
179 mp_irq.dstirq = pentry->irq;
Feng Tang2d8009b2010-11-19 11:33:35 +0800180 mp_save_irq(&mp_irq);
Feng Tangcf089452010-02-12 03:37:38 -0800181 }
182 return 0;
183}
184
Jacob Pan3746c6b2010-02-12 05:01:12 -0800185static unsigned long __init mrst_calibrate_tsc(void)
186{
187 unsigned long flags, fast_calibrate;
188
189 local_irq_save(flags);
190 fast_calibrate = apbt_quick_calibrate();
191 local_irq_restore(flags);
192
193 if (fast_calibrate)
194 return fast_calibrate;
195
196 return 0;
197}
198
Luis R. Rodriguez8fab6af2011-05-06 15:00:09 -0700199static void __init mrst_time_init(void)
Jacob Pan3746c6b2010-02-12 05:01:12 -0800200{
Jacob Pan7f05dec2010-11-09 11:28:43 +0000201 sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
Jacob Pana875c012010-05-19 12:01:25 -0700202 switch (mrst_timer_options) {
203 case MRST_TIMER_APBT_ONLY:
204 break;
205 case MRST_TIMER_LAPIC_APBT:
206 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
207 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
208 break;
209 default:
210 if (!boot_cpu_has(X86_FEATURE_ARAT))
211 break;
212 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
213 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
214 return;
215 }
216 /* we need at least one APB timer */
Jacob Pan3746c6b2010-02-12 05:01:12 -0800217 pre_init_apic_IRQ0();
218 apbt_time_init();
219}
220
Luis R. Rodriguez8fab6af2011-05-06 15:00:09 -0700221static void __cpuinit mrst_arch_setup(void)
Jacob Pan3746c6b2010-02-12 05:01:12 -0800222{
Jacob Pana0c173b2010-05-19 12:01:24 -0700223 if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
H. Peter Anvina75af582010-05-19 13:40:14 -0700224 __mrst_cpu_chip = MRST_CPU_CHIP_PENWELL;
Jacob Pana0c173b2010-05-19 12:01:24 -0700225 else if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x26)
H. Peter Anvina75af582010-05-19 13:40:14 -0700226 __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
Jacob Pana0c173b2010-05-19 12:01:24 -0700227 else {
228 pr_err("Unknown Moorestown CPU (%d:%d), default to Lincroft\n",
229 boot_cpu_data.x86, boot_cpu_data.x86_model);
H. Peter Anvina75af582010-05-19 13:40:14 -0700230 __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
Jacob Pana0c173b2010-05-19 12:01:24 -0700231 }
232 pr_debug("Moorestown CPU %s identified\n",
H. Peter Anvina75af582010-05-19 13:40:14 -0700233 (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT) ?
Jacob Pana0c173b2010-05-19 12:01:24 -0700234 "Lincroft" : "Penwell");
235}
Jacob Pan3746c6b2010-02-12 05:01:12 -0800236
Feng Tang6d2cce62010-07-05 23:03:19 +0800237/* MID systems don't have i8042 controller */
238static int mrst_i8042_detect(void)
239{
240 return 0;
241}
242
Alek Ducfb505a2010-11-10 16:50:08 +0000243/* Reboot and power off are handled by the SCU on a MID device */
244static void mrst_power_off(void)
245{
246 intel_scu_ipc_simple_command(0xf1, 1);
247}
248
249static void mrst_reboot(void)
250{
251 intel_scu_ipc_simple_command(0xf1, 0);
252}
253
Jacob Pan3746c6b2010-02-12 05:01:12 -0800254/*
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200255 * Moorestown specific x86_init function overrides and early setup
256 * calls.
257 */
258void __init x86_mrst_early_setup(void)
259{
260 x86_init.resources.probe_roms = x86_init_noop;
261 x86_init.resources.reserve_resources = x86_init_noop;
Jacob Pan5b78b672010-02-12 02:29:11 -0800262
Jacob Pan3746c6b2010-02-12 05:01:12 -0800263 x86_init.timers.timer_init = mrst_time_init;
Jacob Pana875c012010-05-19 12:01:25 -0700264 x86_init.timers.setup_percpu_clockev = x86_init_noop;
Jacob Pan3746c6b2010-02-12 05:01:12 -0800265
266 x86_init.irqs.pre_vector_init = x86_init_noop;
267
Jacob Pana0c173b2010-05-19 12:01:24 -0700268 x86_init.oem.arch_setup = mrst_arch_setup;
269
Jacob Pana875c012010-05-19 12:01:25 -0700270 x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
Jacob Pan3746c6b2010-02-12 05:01:12 -0800271
272 x86_platform.calibrate_tsc = mrst_calibrate_tsc;
Feng Tang6d2cce62010-07-05 23:03:19 +0800273 x86_platform.i8042_detect = mrst_i8042_detect;
Feng Tang168202c2011-02-15 00:13:32 +0800274 x86_init.timers.wallclock_init = mrst_rtc_init;
Jacob Panaf2730f2010-02-12 10:31:47 -0800275 x86_init.pci.init = pci_mrst_init;
276 x86_init.pci.fixup_irqs = x86_init_noop;
277
Jacob Pan5b78b672010-02-12 02:29:11 -0800278 legacy_pic = &null_legacy_pic;
Jacob Panfea24e22010-05-14 14:41:20 -0700279
Alek Ducfb505a2010-11-10 16:50:08 +0000280 /* Moorestown specific power_off/restart method */
281 pm_power_off = mrst_power_off;
282 machine_ops.emergency_restart = mrst_reboot;
283
Jacob Panfea24e22010-05-14 14:41:20 -0700284 /* Avoid searching for BIOS MP tables */
285 x86_init.mpparse.find_smp_config = x86_init_noop;
286 x86_init.mpparse.get_smp_config = x86_init_uint_noop;
Jacob Pan9d90e492011-04-08 11:23:00 -0700287 set_bit(MP_BUS_ISA, mp_bus_not_pci);
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200288}
Jacob Pana875c012010-05-19 12:01:25 -0700289
290/*
291 * if user does not want to use per CPU apb timer, just give it a lower rating
292 * than local apic timer and skip the late per cpu timer init.
293 */
294static inline int __init setup_x86_mrst_timer(char *arg)
295{
296 if (!arg)
297 return -EINVAL;
298
299 if (strcmp("apbt_only", arg) == 0)
300 mrst_timer_options = MRST_TIMER_APBT_ONLY;
301 else if (strcmp("lapic_and_apbt", arg) == 0)
302 mrst_timer_options = MRST_TIMER_LAPIC_APBT;
303 else {
304 pr_warning("X86 MRST timer option %s not recognised"
305 " use x86_mrst_timer=apbt_only or lapic_and_apbt\n",
306 arg);
307 return -EINVAL;
308 }
309 return 0;
310}
311__setup("x86_mrst_timer=", setup_x86_mrst_timer);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000312
313/*
314 * Parsing GPIO table first, since the DEVS table will need this table
315 * to map the pin name to the actual pin.
316 */
317static struct sfi_gpio_table_entry *gpio_table;
318static int gpio_num_entry;
319
320static int __init sfi_parse_gpio(struct sfi_table_header *table)
321{
322 struct sfi_table_simple *sb;
323 struct sfi_gpio_table_entry *pentry;
324 int num, i;
325
326 if (gpio_table)
327 return 0;
328 sb = (struct sfi_table_simple *)table;
329 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
330 pentry = (struct sfi_gpio_table_entry *)sb->pentry;
331
332 gpio_table = (struct sfi_gpio_table_entry *)
333 kmalloc(num * sizeof(*pentry), GFP_KERNEL);
334 if (!gpio_table)
335 return -1;
336 memcpy(gpio_table, pentry, num * sizeof(*pentry));
337 gpio_num_entry = num;
338
339 pr_debug("GPIO pin info:\n");
340 for (i = 0; i < num; i++, pentry++)
341 pr_debug("info[%2d]: controller = %16.16s, pin_name = %16.16s,"
342 " pin = %d\n", i,
343 pentry->controller_name,
344 pentry->pin_name,
345 pentry->pin_no);
346 return 0;
347}
348
349static int get_gpio_by_name(const char *name)
350{
351 struct sfi_gpio_table_entry *pentry = gpio_table;
352 int i;
353
354 if (!pentry)
355 return -1;
356 for (i = 0; i < gpio_num_entry; i++, pentry++) {
357 if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
358 return pentry->pin_no;
359 }
360 return -1;
361}
362
363/*
364 * Here defines the array of devices platform data that IAFW would export
365 * through SFI "DEVS" table, we use name and type to match the device and
366 * its platform data.
367 */
368struct devs_id {
369 char name[SFI_NAME_LEN + 1];
370 u8 type;
371 u8 delay;
372 void *(*get_platform_data)(void *info);
373};
374
375/* the offset for the mapping of global gpio pin to irq */
376#define MRST_IRQ_OFFSET 0x100
377
378static void __init *pmic_gpio_platform_data(void *info)
379{
380 static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
381 int gpio_base = get_gpio_by_name("pmic_gpio_base");
382
383 if (gpio_base == -1)
384 gpio_base = 64;
385 pmic_gpio_pdata.gpio_base = gpio_base;
386 pmic_gpio_pdata.irq_base = gpio_base + MRST_IRQ_OFFSET;
387 pmic_gpio_pdata.gpiointr = 0xffffeff8;
388
389 return &pmic_gpio_pdata;
390}
391
392static void __init *max3111_platform_data(void *info)
393{
394 struct spi_board_info *spi_info = info;
395 int intr = get_gpio_by_name("max3111_int");
396
Feng Tangefe3ed92011-08-26 11:25:14 +0100397 spi_info->mode = SPI_MODE_0;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000398 if (intr == -1)
399 return NULL;
400 spi_info->irq = intr + MRST_IRQ_OFFSET;
401 return NULL;
402}
403
404/* we have multiple max7315 on the board ... */
405#define MAX7315_NUM 2
406static void __init *max7315_platform_data(void *info)
407{
408 static struct pca953x_platform_data max7315_pdata[MAX7315_NUM];
409 static int nr;
410 struct pca953x_platform_data *max7315 = &max7315_pdata[nr];
411 struct i2c_board_info *i2c_info = info;
412 int gpio_base, intr;
413 char base_pin_name[SFI_NAME_LEN + 1];
414 char intr_pin_name[SFI_NAME_LEN + 1];
415
416 if (nr == MAX7315_NUM) {
417 pr_err("too many max7315s, we only support %d\n",
418 MAX7315_NUM);
419 return NULL;
420 }
421 /* we have several max7315 on the board, we only need load several
422 * instances of the same pca953x driver to cover them
423 */
424 strcpy(i2c_info->type, "max7315");
425 if (nr++) {
426 sprintf(base_pin_name, "max7315_%d_base", nr);
427 sprintf(intr_pin_name, "max7315_%d_int", nr);
428 } else {
429 strcpy(base_pin_name, "max7315_base");
430 strcpy(intr_pin_name, "max7315_int");
431 }
432
433 gpio_base = get_gpio_by_name(base_pin_name);
434 intr = get_gpio_by_name(intr_pin_name);
435
436 if (gpio_base == -1)
437 return NULL;
438 max7315->gpio_base = gpio_base;
439 if (intr != -1) {
440 i2c_info->irq = intr + MRST_IRQ_OFFSET;
441 max7315->irq_base = gpio_base + MRST_IRQ_OFFSET;
442 } else {
443 i2c_info->irq = -1;
444 max7315->irq_base = -1;
445 }
446 return max7315;
447}
448
449static void __init *emc1403_platform_data(void *info)
450{
451 static short intr2nd_pdata;
452 struct i2c_board_info *i2c_info = info;
453 int intr = get_gpio_by_name("thermal_int");
454 int intr2nd = get_gpio_by_name("thermal_alert");
455
456 if (intr == -1 || intr2nd == -1)
457 return NULL;
458
459 i2c_info->irq = intr + MRST_IRQ_OFFSET;
460 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
461
462 return &intr2nd_pdata;
463}
464
465static void __init *lis331dl_platform_data(void *info)
466{
467 static short intr2nd_pdata;
468 struct i2c_board_info *i2c_info = info;
469 int intr = get_gpio_by_name("accel_int");
470 int intr2nd = get_gpio_by_name("accel_2");
471
472 if (intr == -1 || intr2nd == -1)
473 return NULL;
474
475 i2c_info->irq = intr + MRST_IRQ_OFFSET;
476 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
477
478 return &intr2nd_pdata;
479}
480
Vinod Koul86071532010-11-10 17:40:48 +0000481static void __init *no_platform_data(void *info)
482{
483 return NULL;
484}
485
Feng Tang1da4b1c2010-11-09 11:22:58 +0000486static const struct devs_id __initconst device_ids[] = {
487 {"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data},
488 {"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data},
489 {"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
490 {"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
491 {"emc1403", SFI_DEV_TYPE_I2C, 1, &emc1403_platform_data},
492 {"i2c_accel", SFI_DEV_TYPE_I2C, 0, &lis331dl_platform_data},
Vinod Koul86071532010-11-10 17:40:48 +0000493 {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
494 {"msic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
Feng Tang1da4b1c2010-11-09 11:22:58 +0000495 {},
496};
497
498#define MAX_IPCDEVS 24
499static struct platform_device *ipc_devs[MAX_IPCDEVS];
500static int ipc_next_dev;
501
502#define MAX_SCU_SPI 24
503static struct spi_board_info *spi_devs[MAX_SCU_SPI];
504static int spi_next_dev;
505
506#define MAX_SCU_I2C 24
507static struct i2c_board_info *i2c_devs[MAX_SCU_I2C];
508static int i2c_bus[MAX_SCU_I2C];
509static int i2c_next_dev;
510
511static void __init intel_scu_device_register(struct platform_device *pdev)
512{
513 if(ipc_next_dev == MAX_IPCDEVS)
514 pr_err("too many SCU IPC devices");
515 else
516 ipc_devs[ipc_next_dev++] = pdev;
517}
518
519static void __init intel_scu_spi_device_register(struct spi_board_info *sdev)
520{
521 struct spi_board_info *new_dev;
522
523 if (spi_next_dev == MAX_SCU_SPI) {
524 pr_err("too many SCU SPI devices");
525 return;
526 }
527
528 new_dev = kzalloc(sizeof(*sdev), GFP_KERNEL);
529 if (!new_dev) {
530 pr_err("failed to alloc mem for delayed spi dev %s\n",
531 sdev->modalias);
532 return;
533 }
534 memcpy(new_dev, sdev, sizeof(*sdev));
535
536 spi_devs[spi_next_dev++] = new_dev;
537}
538
539static void __init intel_scu_i2c_device_register(int bus,
540 struct i2c_board_info *idev)
541{
542 struct i2c_board_info *new_dev;
543
544 if (i2c_next_dev == MAX_SCU_I2C) {
545 pr_err("too many SCU I2C devices");
546 return;
547 }
548
549 new_dev = kzalloc(sizeof(*idev), GFP_KERNEL);
550 if (!new_dev) {
551 pr_err("failed to alloc mem for delayed i2c dev %s\n",
552 idev->type);
553 return;
554 }
555 memcpy(new_dev, idev, sizeof(*idev));
556
557 i2c_bus[i2c_next_dev] = bus;
558 i2c_devs[i2c_next_dev++] = new_dev;
559}
560
561/* Called by IPC driver */
562void intel_scu_devices_create(void)
563{
564 int i;
565
566 for (i = 0; i < ipc_next_dev; i++)
567 platform_device_add(ipc_devs[i]);
568
569 for (i = 0; i < spi_next_dev; i++)
570 spi_register_board_info(spi_devs[i], 1);
571
572 for (i = 0; i < i2c_next_dev; i++) {
573 struct i2c_adapter *adapter;
574 struct i2c_client *client;
575
576 adapter = i2c_get_adapter(i2c_bus[i]);
577 if (adapter) {
578 client = i2c_new_device(adapter, i2c_devs[i]);
579 if (!client)
580 pr_err("can't create i2c device %s\n",
581 i2c_devs[i]->type);
582 } else
583 i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1);
584 }
585}
586EXPORT_SYMBOL_GPL(intel_scu_devices_create);
587
588/* Called by IPC driver */
589void intel_scu_devices_destroy(void)
590{
591 int i;
592
593 for (i = 0; i < ipc_next_dev; i++)
594 platform_device_del(ipc_devs[i]);
595}
596EXPORT_SYMBOL_GPL(intel_scu_devices_destroy);
597
598static void __init install_irq_resource(struct platform_device *pdev, int irq)
599{
600 /* Single threaded */
601 static struct resource __initdata res = {
602 .name = "IRQ",
603 .flags = IORESOURCE_IRQ,
604 };
605 res.start = irq;
606 platform_device_add_resources(pdev, &res, 1);
607}
608
609static void __init sfi_handle_ipc_dev(struct platform_device *pdev)
610{
611 const struct devs_id *dev = device_ids;
612 void *pdata = NULL;
613
614 while (dev->name[0]) {
615 if (dev->type == SFI_DEV_TYPE_IPC &&
616 !strncmp(dev->name, pdev->name, SFI_NAME_LEN)) {
617 pdata = dev->get_platform_data(pdev);
618 break;
619 }
620 dev++;
621 }
622 pdev->dev.platform_data = pdata;
623 intel_scu_device_register(pdev);
624}
625
626static void __init sfi_handle_spi_dev(struct spi_board_info *spi_info)
627{
628 const struct devs_id *dev = device_ids;
629 void *pdata = NULL;
630
631 while (dev->name[0]) {
632 if (dev->type == SFI_DEV_TYPE_SPI &&
633 !strncmp(dev->name, spi_info->modalias, SFI_NAME_LEN)) {
634 pdata = dev->get_platform_data(spi_info);
635 break;
636 }
637 dev++;
638 }
639 spi_info->platform_data = pdata;
640 if (dev->delay)
641 intel_scu_spi_device_register(spi_info);
642 else
643 spi_register_board_info(spi_info, 1);
644}
645
646static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info)
647{
648 const struct devs_id *dev = device_ids;
649 void *pdata = NULL;
650
651 while (dev->name[0]) {
652 if (dev->type == SFI_DEV_TYPE_I2C &&
653 !strncmp(dev->name, i2c_info->type, SFI_NAME_LEN)) {
654 pdata = dev->get_platform_data(i2c_info);
655 break;
656 }
657 dev++;
658 }
659 i2c_info->platform_data = pdata;
660
661 if (dev->delay)
662 intel_scu_i2c_device_register(bus, i2c_info);
663 else
664 i2c_register_board_info(bus, i2c_info, 1);
665 }
666
667
668static int __init sfi_parse_devs(struct sfi_table_header *table)
669{
670 struct sfi_table_simple *sb;
671 struct sfi_device_table_entry *pentry;
672 struct spi_board_info spi_info;
673 struct i2c_board_info i2c_info;
674 struct platform_device *pdev;
675 int num, i, bus;
676 int ioapic;
677 struct io_apic_irq_attr irq_attr;
678
679 sb = (struct sfi_table_simple *)table;
680 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_device_table_entry);
681 pentry = (struct sfi_device_table_entry *)sb->pentry;
682
683 for (i = 0; i < num; i++, pentry++) {
Mika Westerberg153b19a2011-10-13 12:04:20 +0300684 int irq = pentry->irq;
685
686 if (irq != (u8)0xff) { /* native RTE case */
Feng Tang1da4b1c2010-11-09 11:22:58 +0000687 /* these SPI2 devices are not exposed to system as PCI
688 * devices, but they have separate RTE entry in IOAPIC
689 * so we have to enable them one by one here
690 */
Mika Westerberg153b19a2011-10-13 12:04:20 +0300691 ioapic = mp_find_ioapic(irq);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000692 irq_attr.ioapic = ioapic;
Mika Westerberg153b19a2011-10-13 12:04:20 +0300693 irq_attr.ioapic_pin = irq;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000694 irq_attr.trigger = 1;
695 irq_attr.polarity = 1;
Mika Westerberg153b19a2011-10-13 12:04:20 +0300696 io_apic_set_pci_routing(NULL, irq, &irq_attr);
Kirill A. Shutemova94cc4e2011-08-26 12:20:59 +0100697 } else
Mika Westerberg153b19a2011-10-13 12:04:20 +0300698 irq = 0; /* No irq */
Kirill A. Shutemova94cc4e2011-08-26 12:20:59 +0100699
Feng Tang1da4b1c2010-11-09 11:22:58 +0000700 switch (pentry->type) {
701 case SFI_DEV_TYPE_IPC:
702 /* ID as IRQ is a hack that will go away */
Mika Westerberg153b19a2011-10-13 12:04:20 +0300703 pdev = platform_device_alloc(pentry->name, irq);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000704 if (pdev == NULL) {
705 pr_err("out of memory for SFI platform device '%s'.\n",
706 pentry->name);
707 continue;
708 }
Mika Westerberg153b19a2011-10-13 12:04:20 +0300709 install_irq_resource(pdev, irq);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000710 pr_debug("info[%2d]: IPC bus, name = %16.16s, "
Mika Westerberg153b19a2011-10-13 12:04:20 +0300711 "irq = 0x%2x\n", i, pentry->name, irq);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000712 sfi_handle_ipc_dev(pdev);
713 break;
714 case SFI_DEV_TYPE_SPI:
715 memset(&spi_info, 0, sizeof(spi_info));
716 strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
Mika Westerberg153b19a2011-10-13 12:04:20 +0300717 spi_info.irq = irq;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000718 spi_info.bus_num = pentry->host_num;
719 spi_info.chip_select = pentry->addr;
720 spi_info.max_speed_hz = pentry->max_freq;
721 pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, "
722 "irq = 0x%2x, max_freq = %d, cs = %d\n", i,
723 spi_info.bus_num,
724 spi_info.modalias,
725 spi_info.irq,
726 spi_info.max_speed_hz,
727 spi_info.chip_select);
728 sfi_handle_spi_dev(&spi_info);
729 break;
730 case SFI_DEV_TYPE_I2C:
731 memset(&i2c_info, 0, sizeof(i2c_info));
732 bus = pentry->host_num;
733 strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
Mika Westerberg153b19a2011-10-13 12:04:20 +0300734 i2c_info.irq = irq;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000735 i2c_info.addr = pentry->addr;
736 pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, "
737 "irq = 0x%2x, addr = 0x%x\n", i, bus,
738 i2c_info.type,
739 i2c_info.irq,
740 i2c_info.addr);
741 sfi_handle_i2c_dev(bus, &i2c_info);
742 break;
743 case SFI_DEV_TYPE_UART:
744 case SFI_DEV_TYPE_HSI:
745 default:
746 ;
747 }
748 }
749 return 0;
750}
751
752static int __init mrst_platform_init(void)
753{
754 sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
755 sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
756 return 0;
757}
758arch_initcall(mrst_platform_init);
759
760/*
761 * we will search these buttons in SFI GPIO table (by name)
762 * and register them dynamically. Please add all possible
763 * buttons here, we will shrink them if no GPIO found.
764 */
765static struct gpio_keys_button gpio_button[] = {
766 {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
767 {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
768 {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
769 {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
770 {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
771 {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
772 {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
773 {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
774 {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
775 {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
776};
777
778static struct gpio_keys_platform_data mrst_gpio_keys = {
779 .buttons = gpio_button,
780 .rep = 1,
781 .nbuttons = -1, /* will fill it after search */
782};
783
784static struct platform_device pb_device = {
785 .name = "gpio-keys",
786 .id = -1,
787 .dev = {
788 .platform_data = &mrst_gpio_keys,
789 },
790};
791
792/*
793 * Shrink the non-existent buttons, register the gpio button
794 * device if there is some
795 */
796static int __init pb_keys_init(void)
797{
798 struct gpio_keys_button *gb = gpio_button;
799 int i, num, good = 0;
800
801 num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
802 for (i = 0; i < num; i++) {
803 gb[i].gpio = get_gpio_by_name(gb[i].desc);
804 if (gb[i].gpio == -1)
805 continue;
806
807 if (i != good)
808 gb[good] = gb[i];
809 good++;
810 }
811
812 if (good) {
813 mrst_gpio_keys.nbuttons = good;
814 return platform_device_register(&pb_device);
815 }
816 return 0;
817}
818late_initcall(pb_keys_init);