x86/mrst: Add platform data for Max3110 devices
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86 / platform / mrst / mrst.c
blobb8da1b9689985b9d97963b499501650338005685
1 /*
2 * mrst.c: Intel Moorestown platform specific setup code
4 * (C) Copyright 2008 Intel Corporation
5 * Author: Jacob Pan (jacob.jun.pan@intel.com)
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.
13 #define pr_fmt(fmt) "mrst: " fmt
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/interrupt.h>
18 #include <linux/scatterlist.h>
19 #include <linux/sfi.h>
20 #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>
27 #include <linux/irq.h>
28 #include <linux/module.h>
30 #include <asm/setup.h>
31 #include <asm/mpspec_def.h>
32 #include <asm/hw_irq.h>
33 #include <asm/apic.h>
34 #include <asm/io_apic.h>
35 #include <asm/mrst.h>
36 #include <asm/mrst-vrtc.h>
37 #include <asm/io.h>
38 #include <asm/i8259.h>
39 #include <asm/intel_scu_ipc.h>
40 #include <asm/apb_timer.h>
41 #include <asm/reboot.h>
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.
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.
58 * rating and feature summary:
59 * lapic (with C3STOP) --------- 100
60 * apbt (always-on) ------------ 110
61 * lapic (always-on,ARAT) ------ 150
64 __cpuinitdata enum mrst_timer_options mrst_timer_options;
66 static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
67 static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
68 enum mrst_cpu_type __mrst_cpu_chip;
69 EXPORT_SYMBOL_GPL(__mrst_cpu_chip);
71 int sfi_mtimer_num;
73 struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
74 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
75 int sfi_mrtc_num;
77 /* parse all the mtimer info to a static mtimer array */
78 static int __init sfi_parse_mtmr(struct sfi_table_header *table)
80 struct sfi_table_simple *sb;
81 struct sfi_timer_table_entry *pentry;
82 struct mpc_intsrc mp_irq;
83 int totallen;
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);
94 pr_debug("SFI MTIMER info (num = %d):\n", sfi_mtimer_num);
95 pentry = sfi_mtimer_array;
96 for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
97 pr_debug("timer[%d]: paddr = 0x%08x, freq = %dHz,"
98 " irq = %d\n", totallen, (u32)pentry->phys_addr,
99 pentry->freq_hz, pentry->irq);
100 if (!pentry->irq)
101 continue;
102 mp_irq.type = MP_INTSRC;
103 mp_irq.irqtype = mp_INT;
104 /* triggering mode edge bit 2-3, active high polarity bit 0-1 */
105 mp_irq.irqflag = 5;
106 mp_irq.srcbus = MP_BUS_ISA;
107 mp_irq.srcbusirq = pentry->irq; /* IRQ */
108 mp_irq.dstapic = MP_APIC_ALL;
109 mp_irq.dstirq = pentry->irq;
110 mp_save_irq(&mp_irq);
113 return 0;
116 struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
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];
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];
133 i++;
135 return NULL;
138 void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
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;
146 i++;
150 /* parse all the mrtc info to a global mrtc array */
151 int __init sfi_parse_mrtc(struct sfi_table_header *table)
153 struct sfi_table_simple *sb;
154 struct sfi_rtc_table_entry *pentry;
155 struct mpc_intsrc mp_irq;
157 int totallen;
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);
168 pr_debug("SFI RTC info (num = %d):\n", sfi_mrtc_num);
169 pentry = sfi_mrtc_array;
170 for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
171 pr_debug("RTC[%d]: paddr = 0x%08x, irq = %d\n",
172 totallen, (u32)pentry->phys_addr, pentry->irq);
173 mp_irq.type = MP_INTSRC;
174 mp_irq.irqtype = mp_INT;
175 mp_irq.irqflag = 0xf; /* level trigger and active low */
176 mp_irq.srcbus = MP_BUS_ISA;
177 mp_irq.srcbusirq = pentry->irq; /* IRQ */
178 mp_irq.dstapic = MP_APIC_ALL;
179 mp_irq.dstirq = pentry->irq;
180 mp_save_irq(&mp_irq);
182 return 0;
185 static unsigned long __init mrst_calibrate_tsc(void)
187 unsigned long flags, fast_calibrate;
189 local_irq_save(flags);
190 fast_calibrate = apbt_quick_calibrate();
191 local_irq_restore(flags);
193 if (fast_calibrate)
194 return fast_calibrate;
196 return 0;
199 static void __init mrst_time_init(void)
201 sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
202 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;
216 /* we need at least one APB timer */
217 pre_init_apic_IRQ0();
218 apbt_time_init();
221 static void __cpuinit mrst_arch_setup(void)
223 if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
224 __mrst_cpu_chip = MRST_CPU_CHIP_PENWELL;
225 else if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x26)
226 __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
227 else {
228 pr_err("Unknown Moorestown CPU (%d:%d), default to Lincroft\n",
229 boot_cpu_data.x86, boot_cpu_data.x86_model);
230 __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
232 pr_debug("Moorestown CPU %s identified\n",
233 (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT) ?
234 "Lincroft" : "Penwell");
237 /* MID systems don't have i8042 controller */
238 static int mrst_i8042_detect(void)
240 return 0;
243 /* Reboot and power off are handled by the SCU on a MID device */
244 static void mrst_power_off(void)
246 intel_scu_ipc_simple_command(0xf1, 1);
249 static void mrst_reboot(void)
251 intel_scu_ipc_simple_command(0xf1, 0);
255 * Moorestown specific x86_init function overrides and early setup
256 * calls.
258 void __init x86_mrst_early_setup(void)
260 x86_init.resources.probe_roms = x86_init_noop;
261 x86_init.resources.reserve_resources = x86_init_noop;
263 x86_init.timers.timer_init = mrst_time_init;
264 x86_init.timers.setup_percpu_clockev = x86_init_noop;
266 x86_init.irqs.pre_vector_init = x86_init_noop;
268 x86_init.oem.arch_setup = mrst_arch_setup;
270 x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
272 x86_platform.calibrate_tsc = mrst_calibrate_tsc;
273 x86_platform.i8042_detect = mrst_i8042_detect;
274 x86_init.timers.wallclock_init = mrst_rtc_init;
275 x86_init.pci.init = pci_mrst_init;
276 x86_init.pci.fixup_irqs = x86_init_noop;
278 legacy_pic = &null_legacy_pic;
280 /* Moorestown specific power_off/restart method */
281 pm_power_off = mrst_power_off;
282 machine_ops.emergency_restart = mrst_reboot;
284 /* 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;
287 set_bit(MP_BUS_ISA, mp_bus_not_pci);
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.
294 static inline int __init setup_x86_mrst_timer(char *arg)
296 if (!arg)
297 return -EINVAL;
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;
309 return 0;
311 __setup("x86_mrst_timer=", setup_x86_mrst_timer);
314 * Parsing GPIO table first, since the DEVS table will need this table
315 * to map the pin name to the actual pin.
317 static struct sfi_gpio_table_entry *gpio_table;
318 static int gpio_num_entry;
320 static int __init sfi_parse_gpio(struct sfi_table_header *table)
322 struct sfi_table_simple *sb;
323 struct sfi_gpio_table_entry *pentry;
324 int num, i;
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;
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;
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;
349 static int get_gpio_by_name(const char *name)
351 struct sfi_gpio_table_entry *pentry = gpio_table;
352 int i;
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;
360 return -1;
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.
368 struct devs_id {
369 char name[SFI_NAME_LEN + 1];
370 u8 type;
371 u8 delay;
372 void *(*get_platform_data)(void *info);
375 /* the offset for the mapping of global gpio pin to irq */
376 #define MRST_IRQ_OFFSET 0x100
378 static void __init *pmic_gpio_platform_data(void *info)
380 static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
381 int gpio_base = get_gpio_by_name("pmic_gpio_base");
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;
389 return &pmic_gpio_pdata;
392 static void __init *max3111_platform_data(void *info)
394 struct spi_board_info *spi_info = info;
395 int intr = get_gpio_by_name("max3111_int");
397 spi_info->mode = SPI_MODE_0;
398 if (intr == -1)
399 return NULL;
400 spi_info->irq = intr + MRST_IRQ_OFFSET;
401 return NULL;
404 /* we have multiple max7315 on the board ... */
405 #define MAX7315_NUM 2
406 static void __init *max7315_platform_data(void *info)
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];
416 if (nr == MAX7315_NUM) {
417 pr_err("too many max7315s, we only support %d\n",
418 MAX7315_NUM);
419 return NULL;
421 /* we have several max7315 on the board, we only need load several
422 * instances of the same pca953x driver to cover them
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");
433 gpio_base = get_gpio_by_name(base_pin_name);
434 intr = get_gpio_by_name(intr_pin_name);
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;
446 return max7315;
449 static void __init *emc1403_platform_data(void *info)
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");
456 if (intr == -1 || intr2nd == -1)
457 return NULL;
459 i2c_info->irq = intr + MRST_IRQ_OFFSET;
460 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
462 return &intr2nd_pdata;
465 static void __init *lis331dl_platform_data(void *info)
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");
472 if (intr == -1 || intr2nd == -1)
473 return NULL;
475 i2c_info->irq = intr + MRST_IRQ_OFFSET;
476 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
478 return &intr2nd_pdata;
481 static void __init *no_platform_data(void *info)
483 return NULL;
486 static 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},
493 {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
494 {"msic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
498 #define MAX_IPCDEVS 24
499 static struct platform_device *ipc_devs[MAX_IPCDEVS];
500 static int ipc_next_dev;
502 #define MAX_SCU_SPI 24
503 static struct spi_board_info *spi_devs[MAX_SCU_SPI];
504 static int spi_next_dev;
506 #define MAX_SCU_I2C 24
507 static struct i2c_board_info *i2c_devs[MAX_SCU_I2C];
508 static int i2c_bus[MAX_SCU_I2C];
509 static int i2c_next_dev;
511 static void __init intel_scu_device_register(struct platform_device *pdev)
513 if(ipc_next_dev == MAX_IPCDEVS)
514 pr_err("too many SCU IPC devices");
515 else
516 ipc_devs[ipc_next_dev++] = pdev;
519 static void __init intel_scu_spi_device_register(struct spi_board_info *sdev)
521 struct spi_board_info *new_dev;
523 if (spi_next_dev == MAX_SCU_SPI) {
524 pr_err("too many SCU SPI devices");
525 return;
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;
534 memcpy(new_dev, sdev, sizeof(*sdev));
536 spi_devs[spi_next_dev++] = new_dev;
539 static void __init intel_scu_i2c_device_register(int bus,
540 struct i2c_board_info *idev)
542 struct i2c_board_info *new_dev;
544 if (i2c_next_dev == MAX_SCU_I2C) {
545 pr_err("too many SCU I2C devices");
546 return;
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;
555 memcpy(new_dev, idev, sizeof(*idev));
557 i2c_bus[i2c_next_dev] = bus;
558 i2c_devs[i2c_next_dev++] = new_dev;
561 /* Called by IPC driver */
562 void intel_scu_devices_create(void)
564 int i;
566 for (i = 0; i < ipc_next_dev; i++)
567 platform_device_add(ipc_devs[i]);
569 for (i = 0; i < spi_next_dev; i++)
570 spi_register_board_info(spi_devs[i], 1);
572 for (i = 0; i < i2c_next_dev; i++) {
573 struct i2c_adapter *adapter;
574 struct i2c_client *client;
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);
586 EXPORT_SYMBOL_GPL(intel_scu_devices_create);
588 /* Called by IPC driver */
589 void intel_scu_devices_destroy(void)
591 int i;
593 for (i = 0; i < ipc_next_dev; i++)
594 platform_device_del(ipc_devs[i]);
596 EXPORT_SYMBOL_GPL(intel_scu_devices_destroy);
598 static void __init install_irq_resource(struct platform_device *pdev, int irq)
600 /* Single threaded */
601 static struct resource __initdata res = {
602 .name = "IRQ",
603 .flags = IORESOURCE_IRQ,
605 res.start = irq;
606 platform_device_add_resources(pdev, &res, 1);
609 static void __init sfi_handle_ipc_dev(struct platform_device *pdev)
611 const struct devs_id *dev = device_ids;
612 void *pdata = NULL;
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;
620 dev++;
622 pdev->dev.platform_data = pdata;
623 intel_scu_device_register(pdev);
626 static void __init sfi_handle_spi_dev(struct spi_board_info *spi_info)
628 const struct devs_id *dev = device_ids;
629 void *pdata = NULL;
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;
637 dev++;
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);
646 static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info)
648 const struct devs_id *dev = device_ids;
649 void *pdata = NULL;
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;
657 dev++;
659 i2c_info->platform_data = pdata;
661 if (dev->delay)
662 intel_scu_i2c_device_register(bus, i2c_info);
663 else
664 i2c_register_board_info(bus, i2c_info, 1);
668 static int __init sfi_parse_devs(struct sfi_table_header *table)
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;
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;
683 for (i = 0; i < num; i++, pentry++) {
684 if (pentry->irq != (u8)0xff) { /* native RTE case */
685 /* these SPI2 devices are not exposed to system as PCI
686 * devices, but they have separate RTE entry in IOAPIC
687 * so we have to enable them one by one here
689 ioapic = mp_find_ioapic(pentry->irq);
690 irq_attr.ioapic = ioapic;
691 irq_attr.ioapic_pin = pentry->irq;
692 irq_attr.trigger = 1;
693 irq_attr.polarity = 1;
694 io_apic_set_pci_routing(NULL, pentry->irq, &irq_attr);
696 switch (pentry->type) {
697 case SFI_DEV_TYPE_IPC:
698 /* ID as IRQ is a hack that will go away */
699 pdev = platform_device_alloc(pentry->name, pentry->irq);
700 if (pdev == NULL) {
701 pr_err("out of memory for SFI platform device '%s'.\n",
702 pentry->name);
703 continue;
705 install_irq_resource(pdev, pentry->irq);
706 pr_debug("info[%2d]: IPC bus, name = %16.16s, "
707 "irq = 0x%2x\n", i, pentry->name, pentry->irq);
708 sfi_handle_ipc_dev(pdev);
709 break;
710 case SFI_DEV_TYPE_SPI:
711 memset(&spi_info, 0, sizeof(spi_info));
712 strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
713 spi_info.irq = pentry->irq;
714 spi_info.bus_num = pentry->host_num;
715 spi_info.chip_select = pentry->addr;
716 spi_info.max_speed_hz = pentry->max_freq;
717 pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, "
718 "irq = 0x%2x, max_freq = %d, cs = %d\n", i,
719 spi_info.bus_num,
720 spi_info.modalias,
721 spi_info.irq,
722 spi_info.max_speed_hz,
723 spi_info.chip_select);
724 sfi_handle_spi_dev(&spi_info);
725 break;
726 case SFI_DEV_TYPE_I2C:
727 memset(&i2c_info, 0, sizeof(i2c_info));
728 bus = pentry->host_num;
729 strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
730 i2c_info.irq = pentry->irq;
731 i2c_info.addr = pentry->addr;
732 pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, "
733 "irq = 0x%2x, addr = 0x%x\n", i, bus,
734 i2c_info.type,
735 i2c_info.irq,
736 i2c_info.addr);
737 sfi_handle_i2c_dev(bus, &i2c_info);
738 break;
739 case SFI_DEV_TYPE_UART:
740 case SFI_DEV_TYPE_HSI:
741 default:
745 return 0;
748 static int __init mrst_platform_init(void)
750 sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
751 sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
752 return 0;
754 arch_initcall(mrst_platform_init);
757 * we will search these buttons in SFI GPIO table (by name)
758 * and register them dynamically. Please add all possible
759 * buttons here, we will shrink them if no GPIO found.
761 static struct gpio_keys_button gpio_button[] = {
762 {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
763 {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
764 {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
765 {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
766 {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
767 {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
768 {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
769 {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
770 {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
771 {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
774 static struct gpio_keys_platform_data mrst_gpio_keys = {
775 .buttons = gpio_button,
776 .rep = 1,
777 .nbuttons = -1, /* will fill it after search */
780 static struct platform_device pb_device = {
781 .name = "gpio-keys",
782 .id = -1,
783 .dev = {
784 .platform_data = &mrst_gpio_keys,
789 * Shrink the non-existent buttons, register the gpio button
790 * device if there is some
792 static int __init pb_keys_init(void)
794 struct gpio_keys_button *gb = gpio_button;
795 int i, num, good = 0;
797 num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
798 for (i = 0; i < num; i++) {
799 gb[i].gpio = get_gpio_by_name(gb[i].desc);
800 if (gb[i].gpio == -1)
801 continue;
803 if (i != good)
804 gb[good] = gb[i];
805 good++;
808 if (good) {
809 mrst_gpio_keys.nbuttons = good;
810 return platform_device_register(&pb_device);
812 return 0;
814 late_initcall(pb_keys_init);