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
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>
29 #include <linux/notifier.h>
30 #include <linux/mfd/intel_msic.h>
32 #include <asm/setup.h>
33 #include <asm/mpspec_def.h>
34 #include <asm/hw_irq.h>
36 #include <asm/io_apic.h>
38 #include <asm/mrst-vrtc.h>
40 #include <asm/i8259.h>
41 #include <asm/intel_scu_ipc.h>
42 #include <asm/apb_timer.h>
43 #include <asm/reboot.h>
46 * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
47 * cmdline option x86_mrst_timer can be used to override the configuration
48 * to prefer one or the other.
49 * at runtime, there are basically three timer configurations:
50 * 1. per cpu apbt clock only
51 * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
52 * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
54 * by default (without cmdline option), platform code first detects cpu type
55 * to see if we are on lincroft or penwell, then set up both lapic or apbt
57 * i.e. by default, medfield uses configuration #2, moorestown uses #1.
58 * config #3 is supported but not recommended on medfield.
60 * rating and feature summary:
61 * lapic (with C3STOP) --------- 100
62 * apbt (always-on) ------------ 110
63 * lapic (always-on,ARAT) ------ 150
66 __cpuinitdata enum mrst_timer_options mrst_timer_options;
68 static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
69 static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
70 enum mrst_cpu_type __mrst_cpu_chip;
71 EXPORT_SYMBOL_GPL(__mrst_cpu_chip);
75 struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
76 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
79 static void mrst_power_off(void)
83 static void mrst_reboot(void)
85 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
88 /* parse all the mtimer info to a static mtimer array */
89 static int __init sfi_parse_mtmr(struct sfi_table_header *table)
91 struct sfi_table_simple *sb;
92 struct sfi_timer_table_entry *pentry;
93 struct mpc_intsrc mp_irq;
96 sb = (struct sfi_table_simple *)table;
97 if (!sfi_mtimer_num) {
98 sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
99 struct sfi_timer_table_entry);
100 pentry = (struct sfi_timer_table_entry *) sb->pentry;
101 totallen = sfi_mtimer_num * sizeof(*pentry);
102 memcpy(sfi_mtimer_array, pentry, totallen);
105 pr_debug("SFI MTIMER info (num = %d):\n", sfi_mtimer_num);
106 pentry = sfi_mtimer_array;
107 for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
108 pr_debug("timer[%d]: paddr = 0x%08x, freq = %dHz,"
109 " irq = %d\n", totallen, (u32)pentry->phys_addr,
110 pentry->freq_hz, pentry->irq);
113 mp_irq.type = MP_INTSRC;
114 mp_irq.irqtype = mp_INT;
115 /* triggering mode edge bit 2-3, active high polarity bit 0-1 */
117 mp_irq.srcbus = MP_BUS_ISA;
118 mp_irq.srcbusirq = pentry->irq; /* IRQ */
119 mp_irq.dstapic = MP_APIC_ALL;
120 mp_irq.dstirq = pentry->irq;
121 mp_save_irq(&mp_irq);
127 struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
130 if (hint < sfi_mtimer_num) {
131 if (!sfi_mtimer_usage[hint]) {
132 pr_debug("hint taken for timer %d irq %d\n",\
133 hint, sfi_mtimer_array[hint].irq);
134 sfi_mtimer_usage[hint] = 1;
135 return &sfi_mtimer_array[hint];
138 /* take the first timer available */
139 for (i = 0; i < sfi_mtimer_num;) {
140 if (!sfi_mtimer_usage[i]) {
141 sfi_mtimer_usage[i] = 1;
142 return &sfi_mtimer_array[i];
149 void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
152 for (i = 0; i < sfi_mtimer_num;) {
153 if (mtmr->irq == sfi_mtimer_array[i].irq) {
154 sfi_mtimer_usage[i] = 0;
161 /* parse all the mrtc info to a global mrtc array */
162 int __init sfi_parse_mrtc(struct sfi_table_header *table)
164 struct sfi_table_simple *sb;
165 struct sfi_rtc_table_entry *pentry;
166 struct mpc_intsrc mp_irq;
170 sb = (struct sfi_table_simple *)table;
172 sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb,
173 struct sfi_rtc_table_entry);
174 pentry = (struct sfi_rtc_table_entry *)sb->pentry;
175 totallen = sfi_mrtc_num * sizeof(*pentry);
176 memcpy(sfi_mrtc_array, pentry, totallen);
179 pr_debug("SFI RTC info (num = %d):\n", sfi_mrtc_num);
180 pentry = sfi_mrtc_array;
181 for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
182 pr_debug("RTC[%d]: paddr = 0x%08x, irq = %d\n",
183 totallen, (u32)pentry->phys_addr, pentry->irq);
184 mp_irq.type = MP_INTSRC;
185 mp_irq.irqtype = mp_INT;
186 mp_irq.irqflag = 0xf; /* level trigger and active low */
187 mp_irq.srcbus = MP_BUS_ISA;
188 mp_irq.srcbusirq = pentry->irq; /* IRQ */
189 mp_irq.dstapic = MP_APIC_ALL;
190 mp_irq.dstirq = pentry->irq;
191 mp_save_irq(&mp_irq);
196 static unsigned long __init mrst_calibrate_tsc(void)
198 unsigned long fast_calibrate;
199 u32 lo, hi, ratio, fsb;
201 rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
202 pr_debug("IA32 perf status is 0x%x, 0x%0x\n", lo, hi);
203 ratio = (hi >> 8) & 0x1f;
204 pr_debug("ratio is %d\n", ratio);
206 pr_err("read a zero ratio, should be incorrect!\n");
207 pr_err("force tsc ratio to 16 ...\n");
210 rdmsr(MSR_FSB_FREQ, lo, hi);
211 if ((lo & 0x7) == 0x7)
212 fsb = PENWELL_FSB_FREQ_83SKU;
214 fsb = PENWELL_FSB_FREQ_100SKU;
215 fast_calibrate = ratio * fsb;
216 pr_debug("read penwell tsc %lu khz\n", fast_calibrate);
217 lapic_timer_frequency = fsb * 1000 / HZ;
218 /* mark tsc clocksource as reliable */
219 set_cpu_cap(&boot_cpu_data, X86_FEATURE_TSC_RELIABLE);
222 return fast_calibrate;
227 static void __init mrst_time_init(void)
229 sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
230 switch (mrst_timer_options) {
231 case MRST_TIMER_APBT_ONLY:
233 case MRST_TIMER_LAPIC_APBT:
234 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
235 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
238 if (!boot_cpu_has(X86_FEATURE_ARAT))
240 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
241 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
244 /* we need at least one APB timer */
245 pre_init_apic_IRQ0();
249 static void __cpuinit mrst_arch_setup(void)
251 if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
252 __mrst_cpu_chip = MRST_CPU_CHIP_PENWELL;
254 pr_err("Unknown Intel MID CPU (%d:%d), default to Penwell\n",
255 boot_cpu_data.x86, boot_cpu_data.x86_model);
256 __mrst_cpu_chip = MRST_CPU_CHIP_PENWELL;
260 /* MID systems don't have i8042 controller */
261 static int mrst_i8042_detect(void)
267 * Moorestown does not have external NMI source nor port 0x61 to report
268 * NMI status. The possible NMI sources are from pmu as a result of NMI
269 * watchdog or lock debug. Reading io port 0x61 results in 0xff which
270 * misled NMI handler.
272 static unsigned char mrst_get_nmi_reason(void)
278 * Moorestown specific x86_init function overrides and early setup
281 void __init x86_mrst_early_setup(void)
283 x86_init.resources.probe_roms = x86_init_noop;
284 x86_init.resources.reserve_resources = x86_init_noop;
286 x86_init.timers.timer_init = mrst_time_init;
287 x86_init.timers.setup_percpu_clockev = x86_init_noop;
289 x86_init.irqs.pre_vector_init = x86_init_noop;
291 x86_init.oem.arch_setup = mrst_arch_setup;
293 x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
295 x86_platform.calibrate_tsc = mrst_calibrate_tsc;
296 x86_platform.i8042_detect = mrst_i8042_detect;
297 x86_init.timers.wallclock_init = mrst_rtc_init;
298 x86_platform.get_nmi_reason = mrst_get_nmi_reason;
300 x86_init.pci.init = pci_mrst_init;
301 x86_init.pci.fixup_irqs = x86_init_noop;
303 legacy_pic = &null_legacy_pic;
305 /* Moorestown specific power_off/restart method */
306 pm_power_off = mrst_power_off;
307 machine_ops.emergency_restart = mrst_reboot;
309 /* Avoid searching for BIOS MP tables */
310 x86_init.mpparse.find_smp_config = x86_init_noop;
311 x86_init.mpparse.get_smp_config = x86_init_uint_noop;
312 set_bit(MP_BUS_ISA, mp_bus_not_pci);
316 * if user does not want to use per CPU apb timer, just give it a lower rating
317 * than local apic timer and skip the late per cpu timer init.
319 static inline int __init setup_x86_mrst_timer(char *arg)
324 if (strcmp("apbt_only", arg) == 0)
325 mrst_timer_options = MRST_TIMER_APBT_ONLY;
326 else if (strcmp("lapic_and_apbt", arg) == 0)
327 mrst_timer_options = MRST_TIMER_LAPIC_APBT;
329 pr_warning("X86 MRST timer option %s not recognised"
330 " use x86_mrst_timer=apbt_only or lapic_and_apbt\n",
336 __setup("x86_mrst_timer=", setup_x86_mrst_timer);
339 * Parsing GPIO table first, since the DEVS table will need this table
340 * to map the pin name to the actual pin.
342 static struct sfi_gpio_table_entry *gpio_table;
343 static int gpio_num_entry;
345 static int __init sfi_parse_gpio(struct sfi_table_header *table)
347 struct sfi_table_simple *sb;
348 struct sfi_gpio_table_entry *pentry;
353 sb = (struct sfi_table_simple *)table;
354 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
355 pentry = (struct sfi_gpio_table_entry *)sb->pentry;
357 gpio_table = (struct sfi_gpio_table_entry *)
358 kmalloc(num * sizeof(*pentry), GFP_KERNEL);
361 memcpy(gpio_table, pentry, num * sizeof(*pentry));
362 gpio_num_entry = num;
364 pr_debug("GPIO pin info:\n");
365 for (i = 0; i < num; i++, pentry++)
366 pr_debug("info[%2d]: controller = %16.16s, pin_name = %16.16s,"
368 pentry->controller_name,
374 static int get_gpio_by_name(const char *name)
376 struct sfi_gpio_table_entry *pentry = gpio_table;
381 for (i = 0; i < gpio_num_entry; i++, pentry++) {
382 if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
383 return pentry->pin_no;
389 * Here defines the array of devices platform data that IAFW would export
390 * through SFI "DEVS" table, we use name and type to match the device and
394 char name[SFI_NAME_LEN + 1];
397 void *(*get_platform_data)(void *info);
400 /* the offset for the mapping of global gpio pin to irq */
401 #define MRST_IRQ_OFFSET 0x100
403 static void __init *pmic_gpio_platform_data(void *info)
405 static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
406 int gpio_base = get_gpio_by_name("pmic_gpio_base");
410 pmic_gpio_pdata.gpio_base = gpio_base;
411 pmic_gpio_pdata.irq_base = gpio_base + MRST_IRQ_OFFSET;
412 pmic_gpio_pdata.gpiointr = 0xffffeff8;
414 return &pmic_gpio_pdata;
417 static void __init *max3111_platform_data(void *info)
419 struct spi_board_info *spi_info = info;
420 int intr = get_gpio_by_name("max3111_int");
422 spi_info->mode = SPI_MODE_0;
425 spi_info->irq = intr + MRST_IRQ_OFFSET;
429 /* we have multiple max7315 on the board ... */
430 #define MAX7315_NUM 2
431 static void __init *max7315_platform_data(void *info)
433 static struct pca953x_platform_data max7315_pdata[MAX7315_NUM];
435 struct pca953x_platform_data *max7315 = &max7315_pdata[nr];
436 struct i2c_board_info *i2c_info = info;
438 char base_pin_name[SFI_NAME_LEN + 1];
439 char intr_pin_name[SFI_NAME_LEN + 1];
441 if (nr == MAX7315_NUM) {
442 pr_err("too many max7315s, we only support %d\n",
446 /* we have several max7315 on the board, we only need load several
447 * instances of the same pca953x driver to cover them
449 strcpy(i2c_info->type, "max7315");
451 sprintf(base_pin_name, "max7315_%d_base", nr);
452 sprintf(intr_pin_name, "max7315_%d_int", nr);
454 strcpy(base_pin_name, "max7315_base");
455 strcpy(intr_pin_name, "max7315_int");
458 gpio_base = get_gpio_by_name(base_pin_name);
459 intr = get_gpio_by_name(intr_pin_name);
463 max7315->gpio_base = gpio_base;
465 i2c_info->irq = intr + MRST_IRQ_OFFSET;
466 max7315->irq_base = gpio_base + MRST_IRQ_OFFSET;
469 max7315->irq_base = -1;
474 static void *tca6416_platform_data(void *info)
476 static struct pca953x_platform_data tca6416;
477 struct i2c_board_info *i2c_info = info;
479 char base_pin_name[SFI_NAME_LEN + 1];
480 char intr_pin_name[SFI_NAME_LEN + 1];
482 strcpy(i2c_info->type, "tca6416");
483 strcpy(base_pin_name, "tca6416_base");
484 strcpy(intr_pin_name, "tca6416_int");
486 gpio_base = get_gpio_by_name(base_pin_name);
487 intr = get_gpio_by_name(intr_pin_name);
491 tca6416.gpio_base = gpio_base;
493 i2c_info->irq = intr + MRST_IRQ_OFFSET;
494 tca6416.irq_base = gpio_base + MRST_IRQ_OFFSET;
497 tca6416.irq_base = -1;
502 static void *mpu3050_platform_data(void *info)
504 struct i2c_board_info *i2c_info = info;
505 int intr = get_gpio_by_name("mpu3050_int");
510 i2c_info->irq = intr + MRST_IRQ_OFFSET;
514 static void __init *emc1403_platform_data(void *info)
516 static short intr2nd_pdata;
517 struct i2c_board_info *i2c_info = info;
518 int intr = get_gpio_by_name("thermal_int");
519 int intr2nd = get_gpio_by_name("thermal_alert");
521 if (intr == -1 || intr2nd == -1)
524 i2c_info->irq = intr + MRST_IRQ_OFFSET;
525 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
527 return &intr2nd_pdata;
530 static void __init *lis331dl_platform_data(void *info)
532 static short intr2nd_pdata;
533 struct i2c_board_info *i2c_info = info;
534 int intr = get_gpio_by_name("accel_int");
535 int intr2nd = get_gpio_by_name("accel_2");
537 if (intr == -1 || intr2nd == -1)
540 i2c_info->irq = intr + MRST_IRQ_OFFSET;
541 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
543 return &intr2nd_pdata;
546 static void __init *no_platform_data(void *info)
551 static struct resource msic_resources[] = {
553 .start = INTEL_MSIC_IRQ_PHYS_BASE,
554 .end = INTEL_MSIC_IRQ_PHYS_BASE + 64 - 1,
555 .flags = IORESOURCE_MEM,
559 static struct intel_msic_platform_data msic_pdata;
561 static struct platform_device msic_device = {
562 .name = "intel_msic",
565 .platform_data = &msic_pdata,
567 .num_resources = ARRAY_SIZE(msic_resources),
568 .resource = msic_resources,
571 static inline bool mrst_has_msic(void)
573 return mrst_identify_cpu() == MRST_CPU_CHIP_PENWELL;
576 static int msic_scu_status_change(struct notifier_block *nb,
577 unsigned long code, void *data)
579 if (code == SCU_DOWN) {
580 platform_device_unregister(&msic_device);
584 return platform_device_register(&msic_device);
587 static int __init msic_init(void)
589 static struct notifier_block msic_scu_notifier = {
590 .notifier_call = msic_scu_status_change,
594 * We need to be sure that the SCU IPC is ready before MSIC device
598 intel_scu_notifier_add(&msic_scu_notifier);
602 arch_initcall(msic_init);
605 * msic_generic_platform_data - sets generic platform data for the block
606 * @info: pointer to the SFI device table entry for this block
609 * Function sets IRQ number from the SFI table entry for given device to
610 * the MSIC platform data.
612 static void *msic_generic_platform_data(void *info, enum intel_msic_block block)
614 struct sfi_device_table_entry *entry = info;
616 BUG_ON(block < 0 || block >= INTEL_MSIC_BLOCK_LAST);
617 msic_pdata.irq[block] = entry->irq;
619 return no_platform_data(info);
622 static void *msic_battery_platform_data(void *info)
624 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_BATTERY);
627 static void *msic_gpio_platform_data(void *info)
629 static struct intel_msic_gpio_pdata pdata;
630 int gpio = get_gpio_by_name("msic_gpio_base");
635 pdata.gpio_base = gpio;
636 msic_pdata.gpio = &pdata;
638 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_GPIO);
641 static void *msic_audio_platform_data(void *info)
643 struct platform_device *pdev;
645 pdev = platform_device_register_simple("sst-platform", -1, NULL, 0);
647 pr_err("failed to create audio platform device\n");
651 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_AUDIO);
654 static void *msic_power_btn_platform_data(void *info)
656 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_POWER_BTN);
659 static void *msic_ocd_platform_data(void *info)
661 static struct intel_msic_ocd_pdata pdata;
662 int gpio = get_gpio_by_name("ocd_gpio");
668 msic_pdata.ocd = &pdata;
670 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_OCD);
673 static const struct devs_id __initconst device_ids[] = {
674 {"bma023", SFI_DEV_TYPE_I2C, 1, &no_platform_data},
675 {"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data},
676 {"pmic_gpio", SFI_DEV_TYPE_IPC, 1, &pmic_gpio_platform_data},
677 {"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data},
678 {"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
679 {"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
680 {"tca6416", SFI_DEV_TYPE_I2C, 1, &tca6416_platform_data},
681 {"emc1403", SFI_DEV_TYPE_I2C, 1, &emc1403_platform_data},
682 {"i2c_accel", SFI_DEV_TYPE_I2C, 0, &lis331dl_platform_data},
683 {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
684 {"mpu3050", SFI_DEV_TYPE_I2C, 1, &mpu3050_platform_data},
686 /* MSIC subdevices */
687 {"msic_battery", SFI_DEV_TYPE_IPC, 1, &msic_battery_platform_data},
688 {"msic_gpio", SFI_DEV_TYPE_IPC, 1, &msic_gpio_platform_data},
689 {"msic_audio", SFI_DEV_TYPE_IPC, 1, &msic_audio_platform_data},
690 {"msic_power_btn", SFI_DEV_TYPE_IPC, 1, &msic_power_btn_platform_data},
691 {"msic_ocd", SFI_DEV_TYPE_IPC, 1, &msic_ocd_platform_data},
696 #define MAX_IPCDEVS 24
697 static struct platform_device *ipc_devs[MAX_IPCDEVS];
698 static int ipc_next_dev;
700 #define MAX_SCU_SPI 24
701 static struct spi_board_info *spi_devs[MAX_SCU_SPI];
702 static int spi_next_dev;
704 #define MAX_SCU_I2C 24
705 static struct i2c_board_info *i2c_devs[MAX_SCU_I2C];
706 static int i2c_bus[MAX_SCU_I2C];
707 static int i2c_next_dev;
709 static void __init intel_scu_device_register(struct platform_device *pdev)
711 if(ipc_next_dev == MAX_IPCDEVS)
712 pr_err("too many SCU IPC devices");
714 ipc_devs[ipc_next_dev++] = pdev;
717 static void __init intel_scu_spi_device_register(struct spi_board_info *sdev)
719 struct spi_board_info *new_dev;
721 if (spi_next_dev == MAX_SCU_SPI) {
722 pr_err("too many SCU SPI devices");
726 new_dev = kzalloc(sizeof(*sdev), GFP_KERNEL);
728 pr_err("failed to alloc mem for delayed spi dev %s\n",
732 memcpy(new_dev, sdev, sizeof(*sdev));
734 spi_devs[spi_next_dev++] = new_dev;
737 static void __init intel_scu_i2c_device_register(int bus,
738 struct i2c_board_info *idev)
740 struct i2c_board_info *new_dev;
742 if (i2c_next_dev == MAX_SCU_I2C) {
743 pr_err("too many SCU I2C devices");
747 new_dev = kzalloc(sizeof(*idev), GFP_KERNEL);
749 pr_err("failed to alloc mem for delayed i2c dev %s\n",
753 memcpy(new_dev, idev, sizeof(*idev));
755 i2c_bus[i2c_next_dev] = bus;
756 i2c_devs[i2c_next_dev++] = new_dev;
759 BLOCKING_NOTIFIER_HEAD(intel_scu_notifier);
760 EXPORT_SYMBOL_GPL(intel_scu_notifier);
762 /* Called by IPC driver */
763 void intel_scu_devices_create(void)
767 for (i = 0; i < ipc_next_dev; i++)
768 platform_device_add(ipc_devs[i]);
770 for (i = 0; i < spi_next_dev; i++)
771 spi_register_board_info(spi_devs[i], 1);
773 for (i = 0; i < i2c_next_dev; i++) {
774 struct i2c_adapter *adapter;
775 struct i2c_client *client;
777 adapter = i2c_get_adapter(i2c_bus[i]);
779 client = i2c_new_device(adapter, i2c_devs[i]);
781 pr_err("can't create i2c device %s\n",
784 i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1);
786 intel_scu_notifier_post(SCU_AVAILABLE, 0L);
788 EXPORT_SYMBOL_GPL(intel_scu_devices_create);
790 /* Called by IPC driver */
791 void intel_scu_devices_destroy(void)
795 intel_scu_notifier_post(SCU_DOWN, 0L);
797 for (i = 0; i < ipc_next_dev; i++)
798 platform_device_del(ipc_devs[i]);
800 EXPORT_SYMBOL_GPL(intel_scu_devices_destroy);
802 static void __init install_irq_resource(struct platform_device *pdev, int irq)
804 /* Single threaded */
805 static struct resource __initdata res = {
807 .flags = IORESOURCE_IRQ,
810 platform_device_add_resources(pdev, &res, 1);
813 static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *entry)
815 const struct devs_id *dev = device_ids;
816 struct platform_device *pdev;
819 while (dev->name[0]) {
820 if (dev->type == SFI_DEV_TYPE_IPC &&
821 !strncmp(dev->name, entry->name, SFI_NAME_LEN)) {
822 pdata = dev->get_platform_data(entry);
829 * On Medfield the platform device creation is handled by the MSIC
830 * MFD driver so we don't need to do it here.
835 pdev = platform_device_alloc(entry->name, 0);
837 pr_err("out of memory for SFI platform device '%s'.\n",
841 install_irq_resource(pdev, entry->irq);
843 pdev->dev.platform_data = pdata;
844 intel_scu_device_register(pdev);
847 static void __init sfi_handle_spi_dev(struct spi_board_info *spi_info)
849 const struct devs_id *dev = device_ids;
852 while (dev->name[0]) {
853 if (dev->type == SFI_DEV_TYPE_SPI &&
854 !strncmp(dev->name, spi_info->modalias, SFI_NAME_LEN)) {
855 pdata = dev->get_platform_data(spi_info);
860 spi_info->platform_data = pdata;
862 intel_scu_spi_device_register(spi_info);
864 spi_register_board_info(spi_info, 1);
867 static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info)
869 const struct devs_id *dev = device_ids;
872 while (dev->name[0]) {
873 if (dev->type == SFI_DEV_TYPE_I2C &&
874 !strncmp(dev->name, i2c_info->type, SFI_NAME_LEN)) {
875 pdata = dev->get_platform_data(i2c_info);
880 i2c_info->platform_data = pdata;
883 intel_scu_i2c_device_register(bus, i2c_info);
885 i2c_register_board_info(bus, i2c_info, 1);
889 static int __init sfi_parse_devs(struct sfi_table_header *table)
891 struct sfi_table_simple *sb;
892 struct sfi_device_table_entry *pentry;
893 struct spi_board_info spi_info;
894 struct i2c_board_info i2c_info;
897 struct io_apic_irq_attr irq_attr;
899 sb = (struct sfi_table_simple *)table;
900 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_device_table_entry);
901 pentry = (struct sfi_device_table_entry *)sb->pentry;
903 for (i = 0; i < num; i++, pentry++) {
904 int irq = pentry->irq;
906 if (irq != (u8)0xff) { /* native RTE case */
907 /* these SPI2 devices are not exposed to system as PCI
908 * devices, but they have separate RTE entry in IOAPIC
909 * so we have to enable them one by one here
911 ioapic = mp_find_ioapic(irq);
912 irq_attr.ioapic = ioapic;
913 irq_attr.ioapic_pin = irq;
914 irq_attr.trigger = 1;
915 irq_attr.polarity = 1;
916 io_apic_set_pci_routing(NULL, irq, &irq_attr);
918 irq = 0; /* No irq */
920 switch (pentry->type) {
921 case SFI_DEV_TYPE_IPC:
922 pr_debug("info[%2d]: IPC bus, name = %16.16s, "
923 "irq = 0x%2x\n", i, pentry->name, pentry->irq);
924 sfi_handle_ipc_dev(pentry);
926 case SFI_DEV_TYPE_SPI:
927 memset(&spi_info, 0, sizeof(spi_info));
928 strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
930 spi_info.bus_num = pentry->host_num;
931 spi_info.chip_select = pentry->addr;
932 spi_info.max_speed_hz = pentry->max_freq;
933 pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, "
934 "irq = 0x%2x, max_freq = %d, cs = %d\n", i,
938 spi_info.max_speed_hz,
939 spi_info.chip_select);
940 sfi_handle_spi_dev(&spi_info);
942 case SFI_DEV_TYPE_I2C:
943 memset(&i2c_info, 0, sizeof(i2c_info));
944 bus = pentry->host_num;
945 strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
947 i2c_info.addr = pentry->addr;
948 pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, "
949 "irq = 0x%2x, addr = 0x%x\n", i, bus,
953 sfi_handle_i2c_dev(bus, &i2c_info);
955 case SFI_DEV_TYPE_UART:
956 case SFI_DEV_TYPE_HSI:
964 static int __init mrst_platform_init(void)
966 sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
967 sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
970 arch_initcall(mrst_platform_init);
973 * we will search these buttons in SFI GPIO table (by name)
974 * and register them dynamically. Please add all possible
975 * buttons here, we will shrink them if no GPIO found.
977 static struct gpio_keys_button gpio_button[] = {
978 {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
979 {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
980 {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
981 {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
982 {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
983 {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
984 {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
985 {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
986 {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
987 {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
990 static struct gpio_keys_platform_data mrst_gpio_keys = {
991 .buttons = gpio_button,
993 .nbuttons = -1, /* will fill it after search */
996 static struct platform_device pb_device = {
1000 .platform_data = &mrst_gpio_keys,
1005 * Shrink the non-existent buttons, register the gpio button
1006 * device if there is some
1008 static int __init pb_keys_init(void)
1010 struct gpio_keys_button *gb = gpio_button;
1011 int i, num, good = 0;
1013 num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
1014 for (i = 0; i < num; i++) {
1015 gb[i].gpio = get_gpio_by_name(gb[i].desc);
1016 pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc, gb[i].gpio);
1017 if (gb[i].gpio == -1)
1026 mrst_gpio_keys.nbuttons = good;
1027 return platform_device_register(&pb_device);
1031 late_initcall(pb_keys_init);