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>
31 #include <linux/gpio.h>
32 #include <linux/i2c/tc35876x.h>
34 #include <asm/setup.h>
35 #include <asm/mpspec_def.h>
36 #include <asm/hw_irq.h>
38 #include <asm/io_apic.h>
40 #include <asm/mrst-vrtc.h>
42 #include <asm/i8259.h>
43 #include <asm/intel_scu_ipc.h>
44 #include <asm/apb_timer.h>
45 #include <asm/reboot.h>
48 * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
49 * cmdline option x86_mrst_timer can be used to override the configuration
50 * to prefer one or the other.
51 * at runtime, there are basically three timer configurations:
52 * 1. per cpu apbt clock only
53 * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
54 * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
56 * by default (without cmdline option), platform code first detects cpu type
57 * to see if we are on lincroft or penwell, then set up both lapic or apbt
59 * i.e. by default, medfield uses configuration #2, moorestown uses #1.
60 * config #3 is supported but not recommended on medfield.
62 * rating and feature summary:
63 * lapic (with C3STOP) --------- 100
64 * apbt (always-on) ------------ 110
65 * lapic (always-on,ARAT) ------ 150
68 __cpuinitdata enum mrst_timer_options mrst_timer_options;
70 static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
71 static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
72 enum mrst_cpu_type __mrst_cpu_chip;
73 EXPORT_SYMBOL_GPL(__mrst_cpu_chip);
77 struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
78 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
81 static void mrst_power_off(void)
83 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
84 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
87 static void mrst_reboot(void)
89 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
90 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
92 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
95 /* parse all the mtimer info to a static mtimer array */
96 static int __init sfi_parse_mtmr(struct sfi_table_header *table)
98 struct sfi_table_simple *sb;
99 struct sfi_timer_table_entry *pentry;
100 struct mpc_intsrc mp_irq;
103 sb = (struct sfi_table_simple *)table;
104 if (!sfi_mtimer_num) {
105 sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
106 struct sfi_timer_table_entry);
107 pentry = (struct sfi_timer_table_entry *) sb->pentry;
108 totallen = sfi_mtimer_num * sizeof(*pentry);
109 memcpy(sfi_mtimer_array, pentry, totallen);
112 pr_debug("SFI MTIMER info (num = %d):\n", sfi_mtimer_num);
113 pentry = sfi_mtimer_array;
114 for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
115 pr_debug("timer[%d]: paddr = 0x%08x, freq = %dHz,"
116 " irq = %d\n", totallen, (u32)pentry->phys_addr,
117 pentry->freq_hz, pentry->irq);
120 mp_irq.type = MP_INTSRC;
121 mp_irq.irqtype = mp_INT;
122 /* triggering mode edge bit 2-3, active high polarity bit 0-1 */
124 mp_irq.srcbus = MP_BUS_ISA;
125 mp_irq.srcbusirq = pentry->irq; /* IRQ */
126 mp_irq.dstapic = MP_APIC_ALL;
127 mp_irq.dstirq = pentry->irq;
128 mp_save_irq(&mp_irq);
134 struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
137 if (hint < sfi_mtimer_num) {
138 if (!sfi_mtimer_usage[hint]) {
139 pr_debug("hint taken for timer %d irq %d\n",\
140 hint, sfi_mtimer_array[hint].irq);
141 sfi_mtimer_usage[hint] = 1;
142 return &sfi_mtimer_array[hint];
145 /* take the first timer available */
146 for (i = 0; i < sfi_mtimer_num;) {
147 if (!sfi_mtimer_usage[i]) {
148 sfi_mtimer_usage[i] = 1;
149 return &sfi_mtimer_array[i];
156 void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
159 for (i = 0; i < sfi_mtimer_num;) {
160 if (mtmr->irq == sfi_mtimer_array[i].irq) {
161 sfi_mtimer_usage[i] = 0;
168 /* parse all the mrtc info to a global mrtc array */
169 int __init sfi_parse_mrtc(struct sfi_table_header *table)
171 struct sfi_table_simple *sb;
172 struct sfi_rtc_table_entry *pentry;
173 struct mpc_intsrc mp_irq;
177 sb = (struct sfi_table_simple *)table;
179 sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb,
180 struct sfi_rtc_table_entry);
181 pentry = (struct sfi_rtc_table_entry *)sb->pentry;
182 totallen = sfi_mrtc_num * sizeof(*pentry);
183 memcpy(sfi_mrtc_array, pentry, totallen);
186 pr_debug("SFI RTC info (num = %d):\n", sfi_mrtc_num);
187 pentry = sfi_mrtc_array;
188 for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
189 pr_debug("RTC[%d]: paddr = 0x%08x, irq = %d\n",
190 totallen, (u32)pentry->phys_addr, pentry->irq);
191 mp_irq.type = MP_INTSRC;
192 mp_irq.irqtype = mp_INT;
193 mp_irq.irqflag = 0xf; /* level trigger and active low */
194 mp_irq.srcbus = MP_BUS_ISA;
195 mp_irq.srcbusirq = pentry->irq; /* IRQ */
196 mp_irq.dstapic = MP_APIC_ALL;
197 mp_irq.dstirq = pentry->irq;
198 mp_save_irq(&mp_irq);
203 static unsigned long __init mrst_calibrate_tsc(void)
205 unsigned long flags, fast_calibrate;
206 if (__mrst_cpu_chip == MRST_CPU_CHIP_PENWELL) {
207 u32 lo, hi, ratio, fsb;
209 rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
210 pr_debug("IA32 perf status is 0x%x, 0x%0x\n", lo, hi);
211 ratio = (hi >> 8) & 0x1f;
212 pr_debug("ratio is %d\n", ratio);
214 pr_err("read a zero ratio, should be incorrect!\n");
215 pr_err("force tsc ratio to 16 ...\n");
218 rdmsr(MSR_FSB_FREQ, lo, hi);
219 if ((lo & 0x7) == 0x7)
220 fsb = PENWELL_FSB_FREQ_83SKU;
222 fsb = PENWELL_FSB_FREQ_100SKU;
223 fast_calibrate = ratio * fsb;
224 pr_debug("read penwell tsc %lu khz\n", fast_calibrate);
225 lapic_timer_frequency = fsb * 1000 / HZ;
226 /* mark tsc clocksource as reliable */
227 set_cpu_cap(&boot_cpu_data, X86_FEATURE_TSC_RELIABLE);
229 local_irq_save(flags);
230 fast_calibrate = apbt_quick_calibrate();
231 local_irq_restore(flags);
235 return fast_calibrate;
240 static void __init mrst_time_init(void)
242 sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
243 switch (mrst_timer_options) {
244 case MRST_TIMER_APBT_ONLY:
246 case MRST_TIMER_LAPIC_APBT:
247 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
248 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
251 if (!boot_cpu_has(X86_FEATURE_ARAT))
253 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
254 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
257 /* we need at least one APB timer */
258 pre_init_apic_IRQ0();
262 static void __cpuinit mrst_arch_setup(void)
264 if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
265 __mrst_cpu_chip = MRST_CPU_CHIP_PENWELL;
266 else if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x26)
267 __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
269 pr_err("Unknown Moorestown CPU (%d:%d), default to Lincroft\n",
270 boot_cpu_data.x86, boot_cpu_data.x86_model);
271 __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
273 pr_debug("Moorestown CPU %s identified\n",
274 (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT) ?
275 "Lincroft" : "Penwell");
278 /* MID systems don't have i8042 controller */
279 static int mrst_i8042_detect(void)
285 * Moorestown does not have external NMI source nor port 0x61 to report
286 * NMI status. The possible NMI sources are from pmu as a result of NMI
287 * watchdog or lock debug. Reading io port 0x61 results in 0xff which
288 * misled NMI handler.
290 static unsigned char mrst_get_nmi_reason(void)
296 * Moorestown specific x86_init function overrides and early setup
299 void __init x86_mrst_early_setup(void)
301 x86_init.resources.probe_roms = x86_init_noop;
302 x86_init.resources.reserve_resources = x86_init_noop;
304 x86_init.timers.timer_init = mrst_time_init;
305 x86_init.timers.setup_percpu_clockev = x86_init_noop;
307 x86_init.irqs.pre_vector_init = x86_init_noop;
309 x86_init.oem.arch_setup = mrst_arch_setup;
311 x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
313 x86_platform.calibrate_tsc = mrst_calibrate_tsc;
314 x86_platform.i8042_detect = mrst_i8042_detect;
315 x86_init.timers.wallclock_init = mrst_rtc_init;
316 x86_platform.get_nmi_reason = mrst_get_nmi_reason;
318 x86_init.pci.init = pci_mrst_init;
319 x86_init.pci.fixup_irqs = x86_init_noop;
321 legacy_pic = &null_legacy_pic;
323 /* Moorestown specific power_off/restart method */
324 pm_power_off = mrst_power_off;
325 machine_ops.emergency_restart = mrst_reboot;
327 /* Avoid searching for BIOS MP tables */
328 x86_init.mpparse.find_smp_config = x86_init_noop;
329 x86_init.mpparse.get_smp_config = x86_init_uint_noop;
330 set_bit(MP_BUS_ISA, mp_bus_not_pci);
334 * if user does not want to use per CPU apb timer, just give it a lower rating
335 * than local apic timer and skip the late per cpu timer init.
337 static inline int __init setup_x86_mrst_timer(char *arg)
342 if (strcmp("apbt_only", arg) == 0)
343 mrst_timer_options = MRST_TIMER_APBT_ONLY;
344 else if (strcmp("lapic_and_apbt", arg) == 0)
345 mrst_timer_options = MRST_TIMER_LAPIC_APBT;
347 pr_warning("X86 MRST timer option %s not recognised"
348 " use x86_mrst_timer=apbt_only or lapic_and_apbt\n",
354 __setup("x86_mrst_timer=", setup_x86_mrst_timer);
357 * Parsing GPIO table first, since the DEVS table will need this table
358 * to map the pin name to the actual pin.
360 static struct sfi_gpio_table_entry *gpio_table;
361 static int gpio_num_entry;
363 static int __init sfi_parse_gpio(struct sfi_table_header *table)
365 struct sfi_table_simple *sb;
366 struct sfi_gpio_table_entry *pentry;
371 sb = (struct sfi_table_simple *)table;
372 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
373 pentry = (struct sfi_gpio_table_entry *)sb->pentry;
375 gpio_table = (struct sfi_gpio_table_entry *)
376 kmalloc(num * sizeof(*pentry), GFP_KERNEL);
379 memcpy(gpio_table, pentry, num * sizeof(*pentry));
380 gpio_num_entry = num;
382 pr_debug("GPIO pin info:\n");
383 for (i = 0; i < num; i++, pentry++)
384 pr_debug("info[%2d]: controller = %16.16s, pin_name = %16.16s,"
386 pentry->controller_name,
392 static int get_gpio_by_name(const char *name)
394 struct sfi_gpio_table_entry *pentry = gpio_table;
399 for (i = 0; i < gpio_num_entry; i++, pentry++) {
400 if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
401 return pentry->pin_no;
407 * Here defines the array of devices platform data that IAFW would export
408 * through SFI "DEVS" table, we use name and type to match the device and
412 char name[SFI_NAME_LEN + 1];
415 void *(*get_platform_data)(void *info);
418 /* the offset for the mapping of global gpio pin to irq */
419 #define MRST_IRQ_OFFSET 0x100
421 static void __init *pmic_gpio_platform_data(void *info)
423 static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
424 int gpio_base = get_gpio_by_name("pmic_gpio_base");
428 pmic_gpio_pdata.gpio_base = gpio_base;
429 pmic_gpio_pdata.irq_base = gpio_base + MRST_IRQ_OFFSET;
430 pmic_gpio_pdata.gpiointr = 0xffffeff8;
432 return &pmic_gpio_pdata;
435 static void __init *max3111_platform_data(void *info)
437 struct spi_board_info *spi_info = info;
438 int intr = get_gpio_by_name("max3111_int");
440 spi_info->mode = SPI_MODE_0;
443 spi_info->irq = intr + MRST_IRQ_OFFSET;
447 /* we have multiple max7315 on the board ... */
448 #define MAX7315_NUM 2
449 static void __init *max7315_platform_data(void *info)
451 static struct pca953x_platform_data max7315_pdata[MAX7315_NUM];
453 struct pca953x_platform_data *max7315 = &max7315_pdata[nr];
454 struct i2c_board_info *i2c_info = info;
456 char base_pin_name[SFI_NAME_LEN + 1];
457 char intr_pin_name[SFI_NAME_LEN + 1];
459 if (nr == MAX7315_NUM) {
460 pr_err("too many max7315s, we only support %d\n",
464 /* we have several max7315 on the board, we only need load several
465 * instances of the same pca953x driver to cover them
467 strcpy(i2c_info->type, "max7315");
469 sprintf(base_pin_name, "max7315_%d_base", nr);
470 sprintf(intr_pin_name, "max7315_%d_int", nr);
472 strcpy(base_pin_name, "max7315_base");
473 strcpy(intr_pin_name, "max7315_int");
476 gpio_base = get_gpio_by_name(base_pin_name);
477 intr = get_gpio_by_name(intr_pin_name);
481 max7315->gpio_base = gpio_base;
483 i2c_info->irq = intr + MRST_IRQ_OFFSET;
484 max7315->irq_base = gpio_base + MRST_IRQ_OFFSET;
487 max7315->irq_base = -1;
492 static void *tca6416_platform_data(void *info)
494 static struct pca953x_platform_data tca6416;
495 struct i2c_board_info *i2c_info = info;
497 char base_pin_name[SFI_NAME_LEN + 1];
498 char intr_pin_name[SFI_NAME_LEN + 1];
500 strcpy(i2c_info->type, "tca6416");
501 strcpy(base_pin_name, "tca6416_base");
502 strcpy(intr_pin_name, "tca6416_int");
504 gpio_base = get_gpio_by_name(base_pin_name);
505 intr = get_gpio_by_name(intr_pin_name);
509 tca6416.gpio_base = gpio_base;
511 i2c_info->irq = intr + MRST_IRQ_OFFSET;
512 tca6416.irq_base = gpio_base + MRST_IRQ_OFFSET;
515 tca6416.irq_base = -1;
520 static void *mpu3050_platform_data(void *info)
522 struct i2c_board_info *i2c_info = info;
523 int intr = get_gpio_by_name("mpu3050_int");
528 i2c_info->irq = intr + MRST_IRQ_OFFSET;
532 static void __init *emc1403_platform_data(void *info)
534 static short intr2nd_pdata;
535 struct i2c_board_info *i2c_info = info;
536 int intr = get_gpio_by_name("thermal_int");
537 int intr2nd = get_gpio_by_name("thermal_alert");
539 if (intr == -1 || intr2nd == -1)
542 i2c_info->irq = intr + MRST_IRQ_OFFSET;
543 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
545 return &intr2nd_pdata;
548 static void __init *lis331dl_platform_data(void *info)
550 static short intr2nd_pdata;
551 struct i2c_board_info *i2c_info = info;
552 int intr = get_gpio_by_name("accel_int");
553 int intr2nd = get_gpio_by_name("accel_2");
555 if (intr == -1 || intr2nd == -1)
558 i2c_info->irq = intr + MRST_IRQ_OFFSET;
559 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
561 return &intr2nd_pdata;
564 static void __init *no_platform_data(void *info)
569 static struct resource msic_resources[] = {
571 .start = INTEL_MSIC_IRQ_PHYS_BASE,
572 .end = INTEL_MSIC_IRQ_PHYS_BASE + 64 - 1,
573 .flags = IORESOURCE_MEM,
577 static struct intel_msic_platform_data msic_pdata;
579 static struct platform_device msic_device = {
580 .name = "intel_msic",
583 .platform_data = &msic_pdata,
585 .num_resources = ARRAY_SIZE(msic_resources),
586 .resource = msic_resources,
589 static inline bool mrst_has_msic(void)
591 return mrst_identify_cpu() == MRST_CPU_CHIP_PENWELL;
594 static int msic_scu_status_change(struct notifier_block *nb,
595 unsigned long code, void *data)
597 if (code == SCU_DOWN) {
598 platform_device_unregister(&msic_device);
602 return platform_device_register(&msic_device);
605 static int __init msic_init(void)
607 static struct notifier_block msic_scu_notifier = {
608 .notifier_call = msic_scu_status_change,
612 * We need to be sure that the SCU IPC is ready before MSIC device
616 intel_scu_notifier_add(&msic_scu_notifier);
620 arch_initcall(msic_init);
623 * msic_generic_platform_data - sets generic platform data for the block
624 * @info: pointer to the SFI device table entry for this block
627 * Function sets IRQ number from the SFI table entry for given device to
628 * the MSIC platform data.
630 static void *msic_generic_platform_data(void *info, enum intel_msic_block block)
632 struct sfi_device_table_entry *entry = info;
634 BUG_ON(block < 0 || block >= INTEL_MSIC_BLOCK_LAST);
635 msic_pdata.irq[block] = entry->irq;
637 return no_platform_data(info);
640 static void *msic_battery_platform_data(void *info)
642 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_BATTERY);
645 static void *msic_gpio_platform_data(void *info)
647 static struct intel_msic_gpio_pdata pdata;
648 int gpio = get_gpio_by_name("msic_gpio_base");
653 pdata.gpio_base = gpio;
654 msic_pdata.gpio = &pdata;
656 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_GPIO);
659 static void *msic_audio_platform_data(void *info)
661 struct platform_device *pdev;
663 pdev = platform_device_register_simple("sst-platform", -1, NULL, 0);
665 pr_err("failed to create audio platform device\n");
669 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_AUDIO);
672 static void *msic_power_btn_platform_data(void *info)
674 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_POWER_BTN);
677 static void *msic_ocd_platform_data(void *info)
679 static struct intel_msic_ocd_pdata pdata;
680 int gpio = get_gpio_by_name("ocd_gpio");
686 msic_pdata.ocd = &pdata;
688 return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_OCD);
691 /* tc35876x DSI-LVDS bridge chip and panel platform data */
692 static void *tc35876x_platform_data(void *data)
694 static struct tc35876x_platform_data pdata;
696 /* gpio pins set to -1 will not be used by the driver */
697 pdata.gpio_bridge_reset = get_gpio_by_name("LCMB_RXEN");
698 pdata.gpio_panel_bl_en = get_gpio_by_name("6S6P_BL_EN");
699 pdata.gpio_panel_vadd = get_gpio_by_name("EN_VREG_LCD_V3P3");
704 static const struct devs_id __initconst device_ids[] = {
705 {"bma023", SFI_DEV_TYPE_I2C, 1, &no_platform_data},
706 {"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data},
707 {"pmic_gpio", SFI_DEV_TYPE_IPC, 1, &pmic_gpio_platform_data},
708 {"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data},
709 {"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
710 {"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
711 {"tca6416", SFI_DEV_TYPE_I2C, 1, &tca6416_platform_data},
712 {"emc1403", SFI_DEV_TYPE_I2C, 1, &emc1403_platform_data},
713 {"i2c_accel", SFI_DEV_TYPE_I2C, 0, &lis331dl_platform_data},
714 {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
715 {"mpu3050", SFI_DEV_TYPE_I2C, 1, &mpu3050_platform_data},
716 {"i2c_disp_brig", SFI_DEV_TYPE_I2C, 0, &tc35876x_platform_data},
718 /* MSIC subdevices */
719 {"msic_battery", SFI_DEV_TYPE_IPC, 1, &msic_battery_platform_data},
720 {"msic_gpio", SFI_DEV_TYPE_IPC, 1, &msic_gpio_platform_data},
721 {"msic_audio", SFI_DEV_TYPE_IPC, 1, &msic_audio_platform_data},
722 {"msic_power_btn", SFI_DEV_TYPE_IPC, 1, &msic_power_btn_platform_data},
723 {"msic_ocd", SFI_DEV_TYPE_IPC, 1, &msic_ocd_platform_data},
728 #define MAX_IPCDEVS 24
729 static struct platform_device *ipc_devs[MAX_IPCDEVS];
730 static int ipc_next_dev;
732 #define MAX_SCU_SPI 24
733 static struct spi_board_info *spi_devs[MAX_SCU_SPI];
734 static int spi_next_dev;
736 #define MAX_SCU_I2C 24
737 static struct i2c_board_info *i2c_devs[MAX_SCU_I2C];
738 static int i2c_bus[MAX_SCU_I2C];
739 static int i2c_next_dev;
741 static void __init intel_scu_device_register(struct platform_device *pdev)
743 if(ipc_next_dev == MAX_IPCDEVS)
744 pr_err("too many SCU IPC devices");
746 ipc_devs[ipc_next_dev++] = pdev;
749 static void __init intel_scu_spi_device_register(struct spi_board_info *sdev)
751 struct spi_board_info *new_dev;
753 if (spi_next_dev == MAX_SCU_SPI) {
754 pr_err("too many SCU SPI devices");
758 new_dev = kzalloc(sizeof(*sdev), GFP_KERNEL);
760 pr_err("failed to alloc mem for delayed spi dev %s\n",
764 memcpy(new_dev, sdev, sizeof(*sdev));
766 spi_devs[spi_next_dev++] = new_dev;
769 static void __init intel_scu_i2c_device_register(int bus,
770 struct i2c_board_info *idev)
772 struct i2c_board_info *new_dev;
774 if (i2c_next_dev == MAX_SCU_I2C) {
775 pr_err("too many SCU I2C devices");
779 new_dev = kzalloc(sizeof(*idev), GFP_KERNEL);
781 pr_err("failed to alloc mem for delayed i2c dev %s\n",
785 memcpy(new_dev, idev, sizeof(*idev));
787 i2c_bus[i2c_next_dev] = bus;
788 i2c_devs[i2c_next_dev++] = new_dev;
791 BLOCKING_NOTIFIER_HEAD(intel_scu_notifier);
792 EXPORT_SYMBOL_GPL(intel_scu_notifier);
794 /* Called by IPC driver */
795 void intel_scu_devices_create(void)
799 for (i = 0; i < ipc_next_dev; i++)
800 platform_device_add(ipc_devs[i]);
802 for (i = 0; i < spi_next_dev; i++)
803 spi_register_board_info(spi_devs[i], 1);
805 for (i = 0; i < i2c_next_dev; i++) {
806 struct i2c_adapter *adapter;
807 struct i2c_client *client;
809 adapter = i2c_get_adapter(i2c_bus[i]);
811 client = i2c_new_device(adapter, i2c_devs[i]);
813 pr_err("can't create i2c device %s\n",
816 i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1);
818 intel_scu_notifier_post(SCU_AVAILABLE, 0L);
820 EXPORT_SYMBOL_GPL(intel_scu_devices_create);
822 /* Called by IPC driver */
823 void intel_scu_devices_destroy(void)
827 intel_scu_notifier_post(SCU_DOWN, 0L);
829 for (i = 0; i < ipc_next_dev; i++)
830 platform_device_del(ipc_devs[i]);
832 EXPORT_SYMBOL_GPL(intel_scu_devices_destroy);
834 static void __init install_irq_resource(struct platform_device *pdev, int irq)
836 /* Single threaded */
837 static struct resource __initdata res = {
839 .flags = IORESOURCE_IRQ,
842 platform_device_add_resources(pdev, &res, 1);
845 static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *entry)
847 const struct devs_id *dev = device_ids;
848 struct platform_device *pdev;
851 while (dev->name[0]) {
852 if (dev->type == SFI_DEV_TYPE_IPC &&
853 !strncmp(dev->name, entry->name, SFI_NAME_LEN)) {
854 pdata = dev->get_platform_data(entry);
861 * On Medfield the platform device creation is handled by the MSIC
862 * MFD driver so we don't need to do it here.
867 pdev = platform_device_alloc(entry->name, 0);
869 pr_err("out of memory for SFI platform device '%s'.\n",
873 install_irq_resource(pdev, entry->irq);
875 pdev->dev.platform_data = pdata;
876 intel_scu_device_register(pdev);
879 static void __init sfi_handle_spi_dev(struct spi_board_info *spi_info)
881 const struct devs_id *dev = device_ids;
884 while (dev->name[0]) {
885 if (dev->type == SFI_DEV_TYPE_SPI &&
886 !strncmp(dev->name, spi_info->modalias, SFI_NAME_LEN)) {
887 pdata = dev->get_platform_data(spi_info);
892 spi_info->platform_data = pdata;
894 intel_scu_spi_device_register(spi_info);
896 spi_register_board_info(spi_info, 1);
899 static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info)
901 const struct devs_id *dev = device_ids;
904 while (dev->name[0]) {
905 if (dev->type == SFI_DEV_TYPE_I2C &&
906 !strncmp(dev->name, i2c_info->type, SFI_NAME_LEN)) {
907 pdata = dev->get_platform_data(i2c_info);
912 i2c_info->platform_data = pdata;
915 intel_scu_i2c_device_register(bus, i2c_info);
917 i2c_register_board_info(bus, i2c_info, 1);
921 static int __init sfi_parse_devs(struct sfi_table_header *table)
923 struct sfi_table_simple *sb;
924 struct sfi_device_table_entry *pentry;
925 struct spi_board_info spi_info;
926 struct i2c_board_info i2c_info;
929 struct io_apic_irq_attr irq_attr;
931 sb = (struct sfi_table_simple *)table;
932 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_device_table_entry);
933 pentry = (struct sfi_device_table_entry *)sb->pentry;
935 for (i = 0; i < num; i++, pentry++) {
936 int irq = pentry->irq;
938 if (irq != (u8)0xff) { /* native RTE case */
939 /* these SPI2 devices are not exposed to system as PCI
940 * devices, but they have separate RTE entry in IOAPIC
941 * so we have to enable them one by one here
943 ioapic = mp_find_ioapic(irq);
944 irq_attr.ioapic = ioapic;
945 irq_attr.ioapic_pin = irq;
946 irq_attr.trigger = 1;
947 irq_attr.polarity = 1;
948 io_apic_set_pci_routing(NULL, irq, &irq_attr);
950 irq = 0; /* No irq */
952 switch (pentry->type) {
953 case SFI_DEV_TYPE_IPC:
954 pr_debug("info[%2d]: IPC bus, name = %16.16s, "
955 "irq = 0x%2x\n", i, pentry->name, pentry->irq);
956 sfi_handle_ipc_dev(pentry);
958 case SFI_DEV_TYPE_SPI:
959 memset(&spi_info, 0, sizeof(spi_info));
960 strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
962 spi_info.bus_num = pentry->host_num;
963 spi_info.chip_select = pentry->addr;
964 spi_info.max_speed_hz = pentry->max_freq;
965 pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, "
966 "irq = 0x%2x, max_freq = %d, cs = %d\n", i,
970 spi_info.max_speed_hz,
971 spi_info.chip_select);
972 sfi_handle_spi_dev(&spi_info);
974 case SFI_DEV_TYPE_I2C:
975 memset(&i2c_info, 0, sizeof(i2c_info));
976 bus = pentry->host_num;
977 strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
979 i2c_info.addr = pentry->addr;
980 pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, "
981 "irq = 0x%2x, addr = 0x%x\n", i, bus,
985 sfi_handle_i2c_dev(bus, &i2c_info);
987 case SFI_DEV_TYPE_UART:
988 case SFI_DEV_TYPE_HSI:
996 static int __init mrst_platform_init(void)
998 sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
999 sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
1002 arch_initcall(mrst_platform_init);
1005 * we will search these buttons in SFI GPIO table (by name)
1006 * and register them dynamically. Please add all possible
1007 * buttons here, we will shrink them if no GPIO found.
1009 static struct gpio_keys_button gpio_button[] = {
1010 {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
1011 {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
1012 {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
1013 {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
1014 {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
1015 {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
1016 {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
1017 {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
1018 {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
1019 {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
1022 static struct gpio_keys_platform_data mrst_gpio_keys = {
1023 .buttons = gpio_button,
1025 .nbuttons = -1, /* will fill it after search */
1028 static struct platform_device pb_device = {
1029 .name = "gpio-keys",
1032 .platform_data = &mrst_gpio_keys,
1037 * Shrink the non-existent buttons, register the gpio button
1038 * device if there is some
1040 static int __init pb_keys_init(void)
1042 struct gpio_keys_button *gb = gpio_button;
1043 int i, num, good = 0;
1045 num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
1046 for (i = 0; i < num; i++) {
1047 gb[i].gpio = get_gpio_by_name(gb[i].desc);
1048 pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc, gb[i].gpio);
1049 if (gb[i].gpio == -1)
1058 mrst_gpio_keys.nbuttons = good;
1059 return platform_device_register(&pb_device);
1063 late_initcall(pb_keys_init);