blob: 51ec016c20d6c9bd007aa2b82e0fa376ca095bb8 [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>
17#include <linux/sfi.h>
Feng Tang1da4b1c2010-11-09 11:22:58 +000018#include <linux/intel_pmic_gpio.h>
19#include <linux/spi/spi.h>
20#include <linux/i2c.h>
21#include <linux/i2c/pca953x.h>
22#include <linux/gpio_keys.h>
23#include <linux/input.h>
24#include <linux/platform_device.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080025#include <linux/irq.h>
Feng Tangcf089452010-02-12 03:37:38 -080026#include <linux/module.h>
Alan Cox42c25442011-09-07 16:06:51 +030027#include <linux/notifier.h>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020028
29#include <asm/setup.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080030#include <asm/mpspec_def.h>
31#include <asm/hw_irq.h>
32#include <asm/apic.h>
33#include <asm/io_apic.h>
Jacob Pan5b78b672010-02-12 02:29:11 -080034#include <asm/mrst.h>
Feng Tang168202c2011-02-15 00:13:32 +080035#include <asm/mrst-vrtc.h>
Jacob Pan5b78b672010-02-12 02:29:11 -080036#include <asm/io.h>
37#include <asm/i8259.h>
Feng Tang1da4b1c2010-11-09 11:22:58 +000038#include <asm/intel_scu_ipc.h>
Jacob Pan3746c6b2010-02-12 05:01:12 -080039#include <asm/apb_timer.h>
Alek Ducfb505a2010-11-10 16:50:08 +000040#include <asm/reboot.h>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020041
Jacob Pana875c012010-05-19 12:01:25 -070042/*
43 * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
44 * cmdline option x86_mrst_timer can be used to override the configuration
45 * to prefer one or the other.
46 * at runtime, there are basically three timer configurations:
47 * 1. per cpu apbt clock only
48 * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
49 * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
50 *
51 * by default (without cmdline option), platform code first detects cpu type
52 * to see if we are on lincroft or penwell, then set up both lapic or apbt
53 * clocks accordingly.
54 * i.e. by default, medfield uses configuration #2, moorestown uses #1.
55 * config #3 is supported but not recommended on medfield.
56 *
57 * rating and feature summary:
58 * lapic (with C3STOP) --------- 100
59 * apbt (always-on) ------------ 110
60 * lapic (always-on,ARAT) ------ 150
61 */
62
H. Peter Anvin14671382010-05-19 14:37:40 -070063__cpuinitdata enum mrst_timer_options mrst_timer_options;
Jacob Pana875c012010-05-19 12:01:25 -070064
Jacob Pan16ab5392010-02-12 03:08:30 -080065static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
66static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
H. Peter Anvina75af582010-05-19 13:40:14 -070067enum mrst_cpu_type __mrst_cpu_chip;
68EXPORT_SYMBOL_GPL(__mrst_cpu_chip);
Jacob Pana0c173b2010-05-19 12:01:24 -070069
Jacob Pan16ab5392010-02-12 03:08:30 -080070int sfi_mtimer_num;
71
Feng Tangcf089452010-02-12 03:37:38 -080072struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
73EXPORT_SYMBOL_GPL(sfi_mrtc_array);
74int sfi_mrtc_num;
75
Jacob Pan16ab5392010-02-12 03:08:30 -080076/* parse all the mtimer info to a static mtimer array */
77static int __init sfi_parse_mtmr(struct sfi_table_header *table)
78{
79 struct sfi_table_simple *sb;
80 struct sfi_timer_table_entry *pentry;
81 struct mpc_intsrc mp_irq;
82 int totallen;
83
84 sb = (struct sfi_table_simple *)table;
85 if (!sfi_mtimer_num) {
86 sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
87 struct sfi_timer_table_entry);
88 pentry = (struct sfi_timer_table_entry *) sb->pentry;
89 totallen = sfi_mtimer_num * sizeof(*pentry);
90 memcpy(sfi_mtimer_array, pentry, totallen);
91 }
92
Feng Tang1da4b1c2010-11-09 11:22:58 +000093 pr_debug("SFI MTIMER info (num = %d):\n", sfi_mtimer_num);
Jacob Pan16ab5392010-02-12 03:08:30 -080094 pentry = sfi_mtimer_array;
95 for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
Feng Tang1da4b1c2010-11-09 11:22:58 +000096 pr_debug("timer[%d]: paddr = 0x%08x, freq = %dHz,"
Jacob Pan16ab5392010-02-12 03:08:30 -080097 " irq = %d\n", totallen, (u32)pentry->phys_addr,
98 pentry->freq_hz, pentry->irq);
99 if (!pentry->irq)
100 continue;
Jacob Pan9d90e492011-04-08 11:23:00 -0700101 mp_irq.type = MP_INTSRC;
Jacob Pan16ab5392010-02-12 03:08:30 -0800102 mp_irq.irqtype = mp_INT;
103/* triggering mode edge bit 2-3, active high polarity bit 0-1 */
104 mp_irq.irqflag = 5;
Jacob Pan9d90e492011-04-08 11:23:00 -0700105 mp_irq.srcbus = MP_BUS_ISA;
Jacob Pan16ab5392010-02-12 03:08:30 -0800106 mp_irq.srcbusirq = pentry->irq; /* IRQ */
107 mp_irq.dstapic = MP_APIC_ALL;
108 mp_irq.dstirq = pentry->irq;
Feng Tang2d8009b2010-11-19 11:33:35 +0800109 mp_save_irq(&mp_irq);
Jacob Pan16ab5392010-02-12 03:08:30 -0800110 }
111
112 return 0;
113}
114
115struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
116{
117 int i;
118 if (hint < sfi_mtimer_num) {
119 if (!sfi_mtimer_usage[hint]) {
120 pr_debug("hint taken for timer %d irq %d\n",\
121 hint, sfi_mtimer_array[hint].irq);
122 sfi_mtimer_usage[hint] = 1;
123 return &sfi_mtimer_array[hint];
124 }
125 }
126 /* take the first timer available */
127 for (i = 0; i < sfi_mtimer_num;) {
128 if (!sfi_mtimer_usage[i]) {
129 sfi_mtimer_usage[i] = 1;
130 return &sfi_mtimer_array[i];
131 }
132 i++;
133 }
134 return NULL;
135}
136
137void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
138{
139 int i;
140 for (i = 0; i < sfi_mtimer_num;) {
141 if (mtmr->irq == sfi_mtimer_array[i].irq) {
142 sfi_mtimer_usage[i] = 0;
143 return;
144 }
145 i++;
146 }
147}
148
Feng Tangcf089452010-02-12 03:37:38 -0800149/* parse all the mrtc info to a global mrtc array */
150int __init sfi_parse_mrtc(struct sfi_table_header *table)
151{
152 struct sfi_table_simple *sb;
153 struct sfi_rtc_table_entry *pentry;
154 struct mpc_intsrc mp_irq;
155
156 int totallen;
157
158 sb = (struct sfi_table_simple *)table;
159 if (!sfi_mrtc_num) {
160 sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb,
161 struct sfi_rtc_table_entry);
162 pentry = (struct sfi_rtc_table_entry *)sb->pentry;
163 totallen = sfi_mrtc_num * sizeof(*pentry);
164 memcpy(sfi_mrtc_array, pentry, totallen);
165 }
166
Feng Tang1da4b1c2010-11-09 11:22:58 +0000167 pr_debug("SFI RTC info (num = %d):\n", sfi_mrtc_num);
Feng Tangcf089452010-02-12 03:37:38 -0800168 pentry = sfi_mrtc_array;
169 for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
Feng Tang1da4b1c2010-11-09 11:22:58 +0000170 pr_debug("RTC[%d]: paddr = 0x%08x, irq = %d\n",
Feng Tangcf089452010-02-12 03:37:38 -0800171 totallen, (u32)pentry->phys_addr, pentry->irq);
Jacob Pan9d90e492011-04-08 11:23:00 -0700172 mp_irq.type = MP_INTSRC;
Feng Tangcf089452010-02-12 03:37:38 -0800173 mp_irq.irqtype = mp_INT;
Feng Tang6f207e92010-11-11 15:50:50 +0000174 mp_irq.irqflag = 0xf; /* level trigger and active low */
Jacob Pan9d90e492011-04-08 11:23:00 -0700175 mp_irq.srcbus = MP_BUS_ISA;
Feng Tangcf089452010-02-12 03:37:38 -0800176 mp_irq.srcbusirq = pentry->irq; /* IRQ */
177 mp_irq.dstapic = MP_APIC_ALL;
178 mp_irq.dstirq = pentry->irq;
Feng Tang2d8009b2010-11-19 11:33:35 +0800179 mp_save_irq(&mp_irq);
Feng Tangcf089452010-02-12 03:37:38 -0800180 }
181 return 0;
182}
183
Jacob Pan3746c6b2010-02-12 05:01:12 -0800184static unsigned long __init mrst_calibrate_tsc(void)
185{
186 unsigned long flags, fast_calibrate;
187
188 local_irq_save(flags);
189 fast_calibrate = apbt_quick_calibrate();
190 local_irq_restore(flags);
191
192 if (fast_calibrate)
193 return fast_calibrate;
194
195 return 0;
196}
197
Luis R. Rodriguez8fab6af2011-05-06 15:00:09 -0700198static void __init mrst_time_init(void)
Jacob Pan3746c6b2010-02-12 05:01:12 -0800199{
Jacob Pan7f05dec2010-11-09 11:28:43 +0000200 sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
Jacob Pana875c012010-05-19 12:01:25 -0700201 switch (mrst_timer_options) {
202 case MRST_TIMER_APBT_ONLY:
203 break;
204 case MRST_TIMER_LAPIC_APBT:
205 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
206 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
207 break;
208 default:
209 if (!boot_cpu_has(X86_FEATURE_ARAT))
210 break;
211 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
212 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
213 return;
214 }
215 /* we need at least one APB timer */
Jacob Pan3746c6b2010-02-12 05:01:12 -0800216 pre_init_apic_IRQ0();
217 apbt_time_init();
218}
219
Luis R. Rodriguez8fab6af2011-05-06 15:00:09 -0700220static void __cpuinit mrst_arch_setup(void)
Jacob Pan3746c6b2010-02-12 05:01:12 -0800221{
Jacob Pana0c173b2010-05-19 12:01:24 -0700222 if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
H. Peter Anvina75af582010-05-19 13:40:14 -0700223 __mrst_cpu_chip = MRST_CPU_CHIP_PENWELL;
Jacob Pana0c173b2010-05-19 12:01:24 -0700224 else if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x26)
H. Peter Anvina75af582010-05-19 13:40:14 -0700225 __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
Jacob Pana0c173b2010-05-19 12:01:24 -0700226 else {
227 pr_err("Unknown Moorestown CPU (%d:%d), default to Lincroft\n",
228 boot_cpu_data.x86, boot_cpu_data.x86_model);
H. Peter Anvina75af582010-05-19 13:40:14 -0700229 __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
Jacob Pana0c173b2010-05-19 12:01:24 -0700230 }
231 pr_debug("Moorestown CPU %s identified\n",
H. Peter Anvina75af582010-05-19 13:40:14 -0700232 (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT) ?
Jacob Pana0c173b2010-05-19 12:01:24 -0700233 "Lincroft" : "Penwell");
234}
Jacob Pan3746c6b2010-02-12 05:01:12 -0800235
Feng Tang6d2cce62010-07-05 23:03:19 +0800236/* MID systems don't have i8042 controller */
237static int mrst_i8042_detect(void)
238{
239 return 0;
240}
241
Alek Ducfb505a2010-11-10 16:50:08 +0000242/* Reboot and power off are handled by the SCU on a MID device */
243static void mrst_power_off(void)
244{
245 intel_scu_ipc_simple_command(0xf1, 1);
246}
247
248static void mrst_reboot(void)
249{
250 intel_scu_ipc_simple_command(0xf1, 0);
251}
252
Jacob Pan3746c6b2010-02-12 05:01:12 -0800253/*
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200254 * Moorestown specific x86_init function overrides and early setup
255 * calls.
256 */
257void __init x86_mrst_early_setup(void)
258{
259 x86_init.resources.probe_roms = x86_init_noop;
260 x86_init.resources.reserve_resources = x86_init_noop;
Jacob Pan5b78b672010-02-12 02:29:11 -0800261
Jacob Pan3746c6b2010-02-12 05:01:12 -0800262 x86_init.timers.timer_init = mrst_time_init;
Jacob Pana875c012010-05-19 12:01:25 -0700263 x86_init.timers.setup_percpu_clockev = x86_init_noop;
Jacob Pan3746c6b2010-02-12 05:01:12 -0800264
265 x86_init.irqs.pre_vector_init = x86_init_noop;
266
Jacob Pana0c173b2010-05-19 12:01:24 -0700267 x86_init.oem.arch_setup = mrst_arch_setup;
268
Jacob Pana875c012010-05-19 12:01:25 -0700269 x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
Jacob Pan3746c6b2010-02-12 05:01:12 -0800270
271 x86_platform.calibrate_tsc = mrst_calibrate_tsc;
Feng Tang6d2cce62010-07-05 23:03:19 +0800272 x86_platform.i8042_detect = mrst_i8042_detect;
Feng Tang168202c2011-02-15 00:13:32 +0800273 x86_init.timers.wallclock_init = mrst_rtc_init;
Jacob Panaf2730f2010-02-12 10:31:47 -0800274 x86_init.pci.init = pci_mrst_init;
275 x86_init.pci.fixup_irqs = x86_init_noop;
276
Jacob Pan5b78b672010-02-12 02:29:11 -0800277 legacy_pic = &null_legacy_pic;
Jacob Panfea24e22010-05-14 14:41:20 -0700278
Alek Ducfb505a2010-11-10 16:50:08 +0000279 /* Moorestown specific power_off/restart method */
280 pm_power_off = mrst_power_off;
281 machine_ops.emergency_restart = mrst_reboot;
282
Jacob Panfea24e22010-05-14 14:41:20 -0700283 /* Avoid searching for BIOS MP tables */
284 x86_init.mpparse.find_smp_config = x86_init_noop;
285 x86_init.mpparse.get_smp_config = x86_init_uint_noop;
Jacob Pan9d90e492011-04-08 11:23:00 -0700286 set_bit(MP_BUS_ISA, mp_bus_not_pci);
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200287}
Jacob Pana875c012010-05-19 12:01:25 -0700288
289/*
290 * if user does not want to use per CPU apb timer, just give it a lower rating
291 * than local apic timer and skip the late per cpu timer init.
292 */
293static inline int __init setup_x86_mrst_timer(char *arg)
294{
295 if (!arg)
296 return -EINVAL;
297
298 if (strcmp("apbt_only", arg) == 0)
299 mrst_timer_options = MRST_TIMER_APBT_ONLY;
300 else if (strcmp("lapic_and_apbt", arg) == 0)
301 mrst_timer_options = MRST_TIMER_LAPIC_APBT;
302 else {
303 pr_warning("X86 MRST timer option %s not recognised"
304 " use x86_mrst_timer=apbt_only or lapic_and_apbt\n",
305 arg);
306 return -EINVAL;
307 }
308 return 0;
309}
310__setup("x86_mrst_timer=", setup_x86_mrst_timer);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000311
312/*
313 * Parsing GPIO table first, since the DEVS table will need this table
314 * to map the pin name to the actual pin.
315 */
316static struct sfi_gpio_table_entry *gpio_table;
317static int gpio_num_entry;
318
319static int __init sfi_parse_gpio(struct sfi_table_header *table)
320{
321 struct sfi_table_simple *sb;
322 struct sfi_gpio_table_entry *pentry;
323 int num, i;
324
325 if (gpio_table)
326 return 0;
327 sb = (struct sfi_table_simple *)table;
328 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
329 pentry = (struct sfi_gpio_table_entry *)sb->pentry;
330
331 gpio_table = (struct sfi_gpio_table_entry *)
332 kmalloc(num * sizeof(*pentry), GFP_KERNEL);
333 if (!gpio_table)
334 return -1;
335 memcpy(gpio_table, pentry, num * sizeof(*pentry));
336 gpio_num_entry = num;
337
338 pr_debug("GPIO pin info:\n");
339 for (i = 0; i < num; i++, pentry++)
340 pr_debug("info[%2d]: controller = %16.16s, pin_name = %16.16s,"
341 " pin = %d\n", i,
342 pentry->controller_name,
343 pentry->pin_name,
344 pentry->pin_no);
345 return 0;
346}
347
348static int get_gpio_by_name(const char *name)
349{
350 struct sfi_gpio_table_entry *pentry = gpio_table;
351 int i;
352
353 if (!pentry)
354 return -1;
355 for (i = 0; i < gpio_num_entry; i++, pentry++) {
356 if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
357 return pentry->pin_no;
358 }
359 return -1;
360}
361
362/*
363 * Here defines the array of devices platform data that IAFW would export
364 * through SFI "DEVS" table, we use name and type to match the device and
365 * its platform data.
366 */
367struct devs_id {
368 char name[SFI_NAME_LEN + 1];
369 u8 type;
370 u8 delay;
371 void *(*get_platform_data)(void *info);
372};
373
374/* the offset for the mapping of global gpio pin to irq */
375#define MRST_IRQ_OFFSET 0x100
376
377static void __init *pmic_gpio_platform_data(void *info)
378{
379 static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
380 int gpio_base = get_gpio_by_name("pmic_gpio_base");
381
382 if (gpio_base == -1)
383 gpio_base = 64;
384 pmic_gpio_pdata.gpio_base = gpio_base;
385 pmic_gpio_pdata.irq_base = gpio_base + MRST_IRQ_OFFSET;
386 pmic_gpio_pdata.gpiointr = 0xffffeff8;
387
388 return &pmic_gpio_pdata;
389}
390
391static void __init *max3111_platform_data(void *info)
392{
393 struct spi_board_info *spi_info = info;
394 int intr = get_gpio_by_name("max3111_int");
395
396 if (intr == -1)
397 return NULL;
398 spi_info->irq = intr + MRST_IRQ_OFFSET;
399 return NULL;
400}
401
402/* we have multiple max7315 on the board ... */
403#define MAX7315_NUM 2
404static void __init *max7315_platform_data(void *info)
405{
406 static struct pca953x_platform_data max7315_pdata[MAX7315_NUM];
407 static int nr;
408 struct pca953x_platform_data *max7315 = &max7315_pdata[nr];
409 struct i2c_board_info *i2c_info = info;
410 int gpio_base, intr;
411 char base_pin_name[SFI_NAME_LEN + 1];
412 char intr_pin_name[SFI_NAME_LEN + 1];
413
414 if (nr == MAX7315_NUM) {
415 pr_err("too many max7315s, we only support %d\n",
416 MAX7315_NUM);
417 return NULL;
418 }
419 /* we have several max7315 on the board, we only need load several
420 * instances of the same pca953x driver to cover them
421 */
422 strcpy(i2c_info->type, "max7315");
423 if (nr++) {
424 sprintf(base_pin_name, "max7315_%d_base", nr);
425 sprintf(intr_pin_name, "max7315_%d_int", nr);
426 } else {
427 strcpy(base_pin_name, "max7315_base");
428 strcpy(intr_pin_name, "max7315_int");
429 }
430
431 gpio_base = get_gpio_by_name(base_pin_name);
432 intr = get_gpio_by_name(intr_pin_name);
433
434 if (gpio_base == -1)
435 return NULL;
436 max7315->gpio_base = gpio_base;
437 if (intr != -1) {
438 i2c_info->irq = intr + MRST_IRQ_OFFSET;
439 max7315->irq_base = gpio_base + MRST_IRQ_OFFSET;
440 } else {
441 i2c_info->irq = -1;
442 max7315->irq_base = -1;
443 }
444 return max7315;
445}
446
447static void __init *emc1403_platform_data(void *info)
448{
449 static short intr2nd_pdata;
450 struct i2c_board_info *i2c_info = info;
451 int intr = get_gpio_by_name("thermal_int");
452 int intr2nd = get_gpio_by_name("thermal_alert");
453
454 if (intr == -1 || intr2nd == -1)
455 return NULL;
456
457 i2c_info->irq = intr + MRST_IRQ_OFFSET;
458 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
459
460 return &intr2nd_pdata;
461}
462
463static void __init *lis331dl_platform_data(void *info)
464{
465 static short intr2nd_pdata;
466 struct i2c_board_info *i2c_info = info;
467 int intr = get_gpio_by_name("accel_int");
468 int intr2nd = get_gpio_by_name("accel_2");
469
470 if (intr == -1 || intr2nd == -1)
471 return NULL;
472
473 i2c_info->irq = intr + MRST_IRQ_OFFSET;
474 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
475
476 return &intr2nd_pdata;
477}
478
Vinod Koul86071532010-11-10 17:40:48 +0000479static void __init *no_platform_data(void *info)
480{
481 return NULL;
482}
483
Feng Tang1da4b1c2010-11-09 11:22:58 +0000484static const struct devs_id __initconst device_ids[] = {
485 {"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data},
486 {"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data},
487 {"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
488 {"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
489 {"emc1403", SFI_DEV_TYPE_I2C, 1, &emc1403_platform_data},
490 {"i2c_accel", SFI_DEV_TYPE_I2C, 0, &lis331dl_platform_data},
Vinod Koul86071532010-11-10 17:40:48 +0000491 {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
492 {"msic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
Feng Tang1da4b1c2010-11-09 11:22:58 +0000493 {},
494};
495
496#define MAX_IPCDEVS 24
497static struct platform_device *ipc_devs[MAX_IPCDEVS];
498static int ipc_next_dev;
499
500#define MAX_SCU_SPI 24
501static struct spi_board_info *spi_devs[MAX_SCU_SPI];
502static int spi_next_dev;
503
504#define MAX_SCU_I2C 24
505static struct i2c_board_info *i2c_devs[MAX_SCU_I2C];
506static int i2c_bus[MAX_SCU_I2C];
507static int i2c_next_dev;
508
509static void __init intel_scu_device_register(struct platform_device *pdev)
510{
511 if(ipc_next_dev == MAX_IPCDEVS)
512 pr_err("too many SCU IPC devices");
513 else
514 ipc_devs[ipc_next_dev++] = pdev;
515}
516
517static void __init intel_scu_spi_device_register(struct spi_board_info *sdev)
518{
519 struct spi_board_info *new_dev;
520
521 if (spi_next_dev == MAX_SCU_SPI) {
522 pr_err("too many SCU SPI devices");
523 return;
524 }
525
526 new_dev = kzalloc(sizeof(*sdev), GFP_KERNEL);
527 if (!new_dev) {
528 pr_err("failed to alloc mem for delayed spi dev %s\n",
529 sdev->modalias);
530 return;
531 }
532 memcpy(new_dev, sdev, sizeof(*sdev));
533
534 spi_devs[spi_next_dev++] = new_dev;
535}
536
537static void __init intel_scu_i2c_device_register(int bus,
538 struct i2c_board_info *idev)
539{
540 struct i2c_board_info *new_dev;
541
542 if (i2c_next_dev == MAX_SCU_I2C) {
543 pr_err("too many SCU I2C devices");
544 return;
545 }
546
547 new_dev = kzalloc(sizeof(*idev), GFP_KERNEL);
548 if (!new_dev) {
549 pr_err("failed to alloc mem for delayed i2c dev %s\n",
550 idev->type);
551 return;
552 }
553 memcpy(new_dev, idev, sizeof(*idev));
554
555 i2c_bus[i2c_next_dev] = bus;
556 i2c_devs[i2c_next_dev++] = new_dev;
557}
558
Alan Cox42c25442011-09-07 16:06:51 +0300559BLOCKING_NOTIFIER_HEAD(intel_scu_notifier);
560EXPORT_SYMBOL_GPL(intel_scu_notifier);
561
Feng Tang1da4b1c2010-11-09 11:22:58 +0000562/* Called by IPC driver */
563void intel_scu_devices_create(void)
564{
565 int i;
566
567 for (i = 0; i < ipc_next_dev; i++)
568 platform_device_add(ipc_devs[i]);
569
570 for (i = 0; i < spi_next_dev; i++)
571 spi_register_board_info(spi_devs[i], 1);
572
573 for (i = 0; i < i2c_next_dev; i++) {
574 struct i2c_adapter *adapter;
575 struct i2c_client *client;
576
577 adapter = i2c_get_adapter(i2c_bus[i]);
578 if (adapter) {
579 client = i2c_new_device(adapter, i2c_devs[i]);
580 if (!client)
581 pr_err("can't create i2c device %s\n",
582 i2c_devs[i]->type);
583 } else
584 i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1);
585 }
Alan Cox42c25442011-09-07 16:06:51 +0300586 intel_scu_notifier_post(SCU_AVAILABLE, 0L);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000587}
588EXPORT_SYMBOL_GPL(intel_scu_devices_create);
589
590/* Called by IPC driver */
591void intel_scu_devices_destroy(void)
592{
593 int i;
594
Alan Cox42c25442011-09-07 16:06:51 +0300595 intel_scu_notifier_post(SCU_DOWN, 0L);
596
Feng Tang1da4b1c2010-11-09 11:22:58 +0000597 for (i = 0; i < ipc_next_dev; i++)
598 platform_device_del(ipc_devs[i]);
599}
600EXPORT_SYMBOL_GPL(intel_scu_devices_destroy);
601
602static void __init install_irq_resource(struct platform_device *pdev, int irq)
603{
604 /* Single threaded */
605 static struct resource __initdata res = {
606 .name = "IRQ",
607 .flags = IORESOURCE_IRQ,
608 };
609 res.start = irq;
610 platform_device_add_resources(pdev, &res, 1);
611}
612
613static void __init sfi_handle_ipc_dev(struct platform_device *pdev)
614{
615 const struct devs_id *dev = device_ids;
616 void *pdata = NULL;
617
618 while (dev->name[0]) {
619 if (dev->type == SFI_DEV_TYPE_IPC &&
620 !strncmp(dev->name, pdev->name, SFI_NAME_LEN)) {
621 pdata = dev->get_platform_data(pdev);
622 break;
623 }
624 dev++;
625 }
626 pdev->dev.platform_data = pdata;
627 intel_scu_device_register(pdev);
628}
629
630static void __init sfi_handle_spi_dev(struct spi_board_info *spi_info)
631{
632 const struct devs_id *dev = device_ids;
633 void *pdata = NULL;
634
635 while (dev->name[0]) {
636 if (dev->type == SFI_DEV_TYPE_SPI &&
637 !strncmp(dev->name, spi_info->modalias, SFI_NAME_LEN)) {
638 pdata = dev->get_platform_data(spi_info);
639 break;
640 }
641 dev++;
642 }
643 spi_info->platform_data = pdata;
644 if (dev->delay)
645 intel_scu_spi_device_register(spi_info);
646 else
647 spi_register_board_info(spi_info, 1);
648}
649
650static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info)
651{
652 const struct devs_id *dev = device_ids;
653 void *pdata = NULL;
654
655 while (dev->name[0]) {
656 if (dev->type == SFI_DEV_TYPE_I2C &&
657 !strncmp(dev->name, i2c_info->type, SFI_NAME_LEN)) {
658 pdata = dev->get_platform_data(i2c_info);
659 break;
660 }
661 dev++;
662 }
663 i2c_info->platform_data = pdata;
664
665 if (dev->delay)
666 intel_scu_i2c_device_register(bus, i2c_info);
667 else
668 i2c_register_board_info(bus, i2c_info, 1);
669 }
670
671
672static int __init sfi_parse_devs(struct sfi_table_header *table)
673{
674 struct sfi_table_simple *sb;
675 struct sfi_device_table_entry *pentry;
676 struct spi_board_info spi_info;
677 struct i2c_board_info i2c_info;
678 struct platform_device *pdev;
679 int num, i, bus;
680 int ioapic;
681 struct io_apic_irq_attr irq_attr;
682
683 sb = (struct sfi_table_simple *)table;
684 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_device_table_entry);
685 pentry = (struct sfi_device_table_entry *)sb->pentry;
686
687 for (i = 0; i < num; i++, pentry++) {
Mika Westerberg153b19a2011-10-13 12:04:20 +0300688 int irq = pentry->irq;
689
690 if (irq != (u8)0xff) { /* native RTE case */
Feng Tang1da4b1c2010-11-09 11:22:58 +0000691 /* these SPI2 devices are not exposed to system as PCI
692 * devices, but they have separate RTE entry in IOAPIC
693 * so we have to enable them one by one here
694 */
Mika Westerberg153b19a2011-10-13 12:04:20 +0300695 ioapic = mp_find_ioapic(irq);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000696 irq_attr.ioapic = ioapic;
Mika Westerberg153b19a2011-10-13 12:04:20 +0300697 irq_attr.ioapic_pin = irq;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000698 irq_attr.trigger = 1;
699 irq_attr.polarity = 1;
Mika Westerberg153b19a2011-10-13 12:04:20 +0300700 io_apic_set_pci_routing(NULL, irq, &irq_attr);
Kirill A. Shutemova94cc4e2011-08-26 12:20:59 +0100701 } else
Mika Westerberg153b19a2011-10-13 12:04:20 +0300702 irq = 0; /* No irq */
Kirill A. Shutemova94cc4e2011-08-26 12:20:59 +0100703
Feng Tang1da4b1c2010-11-09 11:22:58 +0000704 switch (pentry->type) {
705 case SFI_DEV_TYPE_IPC:
706 /* ID as IRQ is a hack that will go away */
Mika Westerberg153b19a2011-10-13 12:04:20 +0300707 pdev = platform_device_alloc(pentry->name, irq);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000708 if (pdev == NULL) {
709 pr_err("out of memory for SFI platform device '%s'.\n",
710 pentry->name);
711 continue;
712 }
Mika Westerberg153b19a2011-10-13 12:04:20 +0300713 install_irq_resource(pdev, irq);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000714 pr_debug("info[%2d]: IPC bus, name = %16.16s, "
Mika Westerberg153b19a2011-10-13 12:04:20 +0300715 "irq = 0x%2x\n", i, pentry->name, irq);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000716 sfi_handle_ipc_dev(pdev);
717 break;
718 case SFI_DEV_TYPE_SPI:
719 memset(&spi_info, 0, sizeof(spi_info));
720 strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
Mika Westerberg153b19a2011-10-13 12:04:20 +0300721 spi_info.irq = irq;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000722 spi_info.bus_num = pentry->host_num;
723 spi_info.chip_select = pentry->addr;
724 spi_info.max_speed_hz = pentry->max_freq;
725 pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, "
726 "irq = 0x%2x, max_freq = %d, cs = %d\n", i,
727 spi_info.bus_num,
728 spi_info.modalias,
729 spi_info.irq,
730 spi_info.max_speed_hz,
731 spi_info.chip_select);
732 sfi_handle_spi_dev(&spi_info);
733 break;
734 case SFI_DEV_TYPE_I2C:
735 memset(&i2c_info, 0, sizeof(i2c_info));
736 bus = pentry->host_num;
737 strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
Mika Westerberg153b19a2011-10-13 12:04:20 +0300738 i2c_info.irq = irq;
Feng Tang1da4b1c2010-11-09 11:22:58 +0000739 i2c_info.addr = pentry->addr;
740 pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, "
741 "irq = 0x%2x, addr = 0x%x\n", i, bus,
742 i2c_info.type,
743 i2c_info.irq,
744 i2c_info.addr);
745 sfi_handle_i2c_dev(bus, &i2c_info);
746 break;
747 case SFI_DEV_TYPE_UART:
748 case SFI_DEV_TYPE_HSI:
749 default:
750 ;
751 }
752 }
753 return 0;
754}
755
756static int __init mrst_platform_init(void)
757{
758 sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
759 sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
760 return 0;
761}
762arch_initcall(mrst_platform_init);
763
764/*
765 * we will search these buttons in SFI GPIO table (by name)
766 * and register them dynamically. Please add all possible
767 * buttons here, we will shrink them if no GPIO found.
768 */
769static struct gpio_keys_button gpio_button[] = {
770 {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
771 {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
772 {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
773 {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
774 {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
775 {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
776 {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
777 {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
778 {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
779 {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
780};
781
782static struct gpio_keys_platform_data mrst_gpio_keys = {
783 .buttons = gpio_button,
784 .rep = 1,
785 .nbuttons = -1, /* will fill it after search */
786};
787
788static struct platform_device pb_device = {
789 .name = "gpio-keys",
790 .id = -1,
791 .dev = {
792 .platform_data = &mrst_gpio_keys,
793 },
794};
795
796/*
797 * Shrink the non-existent buttons, register the gpio button
798 * device if there is some
799 */
800static int __init pb_keys_init(void)
801{
802 struct gpio_keys_button *gb = gpio_button;
803 int i, num, good = 0;
804
805 num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
806 for (i = 0; i < num; i++) {
807 gb[i].gpio = get_gpio_by_name(gb[i].desc);
808 if (gb[i].gpio == -1)
809 continue;
810
811 if (i != good)
812 gb[good] = gb[i];
813 good++;
814 }
815
816 if (good) {
817 mrst_gpio_keys.nbuttons = good;
818 return platform_device_register(&pb_device);
819 }
820 return 0;
821}
822late_initcall(pb_keys_init);