blob: ea6529e93c6fb2389282a78b78e739551a8f26eb [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>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020027
28#include <asm/setup.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080029#include <asm/mpspec_def.h>
30#include <asm/hw_irq.h>
31#include <asm/apic.h>
32#include <asm/io_apic.h>
Jacob Pan5b78b672010-02-12 02:29:11 -080033#include <asm/mrst.h>
34#include <asm/io.h>
35#include <asm/i8259.h>
Feng Tang1da4b1c2010-11-09 11:22:58 +000036#include <asm/intel_scu_ipc.h>
Jacob Pan3746c6b2010-02-12 05:01:12 -080037#include <asm/apb_timer.h>
Alek Ducfb505a2010-11-10 16:50:08 +000038#include <asm/reboot.h>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020039
Jacob Pana875c012010-05-19 12:01:25 -070040/*
41 * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
42 * cmdline option x86_mrst_timer can be used to override the configuration
43 * to prefer one or the other.
44 * at runtime, there are basically three timer configurations:
45 * 1. per cpu apbt clock only
46 * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
47 * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
48 *
49 * by default (without cmdline option), platform code first detects cpu type
50 * to see if we are on lincroft or penwell, then set up both lapic or apbt
51 * clocks accordingly.
52 * i.e. by default, medfield uses configuration #2, moorestown uses #1.
53 * config #3 is supported but not recommended on medfield.
54 *
55 * rating and feature summary:
56 * lapic (with C3STOP) --------- 100
57 * apbt (always-on) ------------ 110
58 * lapic (always-on,ARAT) ------ 150
59 */
60
H. Peter Anvin14671382010-05-19 14:37:40 -070061__cpuinitdata enum mrst_timer_options mrst_timer_options;
Jacob Pana875c012010-05-19 12:01:25 -070062
Jacob Pan16ab5392010-02-12 03:08:30 -080063static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
64static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
H. Peter Anvina75af582010-05-19 13:40:14 -070065enum mrst_cpu_type __mrst_cpu_chip;
66EXPORT_SYMBOL_GPL(__mrst_cpu_chip);
Jacob Pana0c173b2010-05-19 12:01:24 -070067
Jacob Pan16ab5392010-02-12 03:08:30 -080068int sfi_mtimer_num;
69
Feng Tangcf089452010-02-12 03:37:38 -080070struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
71EXPORT_SYMBOL_GPL(sfi_mrtc_array);
72int sfi_mrtc_num;
73
Jacob Pan16ab5392010-02-12 03:08:30 -080074/* parse all the mtimer info to a static mtimer array */
75static int __init sfi_parse_mtmr(struct sfi_table_header *table)
76{
77 struct sfi_table_simple *sb;
78 struct sfi_timer_table_entry *pentry;
79 struct mpc_intsrc mp_irq;
80 int totallen;
81
82 sb = (struct sfi_table_simple *)table;
83 if (!sfi_mtimer_num) {
84 sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
85 struct sfi_timer_table_entry);
86 pentry = (struct sfi_timer_table_entry *) sb->pentry;
87 totallen = sfi_mtimer_num * sizeof(*pentry);
88 memcpy(sfi_mtimer_array, pentry, totallen);
89 }
90
Feng Tang1da4b1c2010-11-09 11:22:58 +000091 pr_debug("SFI MTIMER info (num = %d):\n", sfi_mtimer_num);
Jacob Pan16ab5392010-02-12 03:08:30 -080092 pentry = sfi_mtimer_array;
93 for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
Feng Tang1da4b1c2010-11-09 11:22:58 +000094 pr_debug("timer[%d]: paddr = 0x%08x, freq = %dHz,"
Jacob Pan16ab5392010-02-12 03:08:30 -080095 " irq = %d\n", totallen, (u32)pentry->phys_addr,
96 pentry->freq_hz, pentry->irq);
97 if (!pentry->irq)
98 continue;
99 mp_irq.type = MP_IOAPIC;
100 mp_irq.irqtype = mp_INT;
101/* triggering mode edge bit 2-3, active high polarity bit 0-1 */
102 mp_irq.irqflag = 5;
103 mp_irq.srcbus = 0;
104 mp_irq.srcbusirq = pentry->irq; /* IRQ */
105 mp_irq.dstapic = MP_APIC_ALL;
106 mp_irq.dstirq = pentry->irq;
Feng Tang2d8009b2010-11-19 11:33:35 +0800107 mp_save_irq(&mp_irq);
Jacob Pan16ab5392010-02-12 03:08:30 -0800108 }
109
110 return 0;
111}
112
113struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
114{
115 int i;
116 if (hint < sfi_mtimer_num) {
117 if (!sfi_mtimer_usage[hint]) {
118 pr_debug("hint taken for timer %d irq %d\n",\
119 hint, sfi_mtimer_array[hint].irq);
120 sfi_mtimer_usage[hint] = 1;
121 return &sfi_mtimer_array[hint];
122 }
123 }
124 /* take the first timer available */
125 for (i = 0; i < sfi_mtimer_num;) {
126 if (!sfi_mtimer_usage[i]) {
127 sfi_mtimer_usage[i] = 1;
128 return &sfi_mtimer_array[i];
129 }
130 i++;
131 }
132 return NULL;
133}
134
135void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
136{
137 int i;
138 for (i = 0; i < sfi_mtimer_num;) {
139 if (mtmr->irq == sfi_mtimer_array[i].irq) {
140 sfi_mtimer_usage[i] = 0;
141 return;
142 }
143 i++;
144 }
145}
146
Feng Tangcf089452010-02-12 03:37:38 -0800147/* parse all the mrtc info to a global mrtc array */
148int __init sfi_parse_mrtc(struct sfi_table_header *table)
149{
150 struct sfi_table_simple *sb;
151 struct sfi_rtc_table_entry *pentry;
152 struct mpc_intsrc mp_irq;
153
154 int totallen;
155
156 sb = (struct sfi_table_simple *)table;
157 if (!sfi_mrtc_num) {
158 sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb,
159 struct sfi_rtc_table_entry);
160 pentry = (struct sfi_rtc_table_entry *)sb->pentry;
161 totallen = sfi_mrtc_num * sizeof(*pentry);
162 memcpy(sfi_mrtc_array, pentry, totallen);
163 }
164
Feng Tang1da4b1c2010-11-09 11:22:58 +0000165 pr_debug("SFI RTC info (num = %d):\n", sfi_mrtc_num);
Feng Tangcf089452010-02-12 03:37:38 -0800166 pentry = sfi_mrtc_array;
167 for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
Feng Tang1da4b1c2010-11-09 11:22:58 +0000168 pr_debug("RTC[%d]: paddr = 0x%08x, irq = %d\n",
Feng Tangcf089452010-02-12 03:37:38 -0800169 totallen, (u32)pentry->phys_addr, pentry->irq);
170 mp_irq.type = MP_IOAPIC;
171 mp_irq.irqtype = mp_INT;
Feng Tang6f207e92010-11-11 15:50:50 +0000172 mp_irq.irqflag = 0xf; /* level trigger and active low */
Feng Tangcf089452010-02-12 03:37:38 -0800173 mp_irq.srcbus = 0;
174 mp_irq.srcbusirq = pentry->irq; /* IRQ */
175 mp_irq.dstapic = MP_APIC_ALL;
176 mp_irq.dstirq = pentry->irq;
Feng Tang2d8009b2010-11-19 11:33:35 +0800177 mp_save_irq(&mp_irq);
Feng Tangcf089452010-02-12 03:37:38 -0800178 }
179 return 0;
180}
181
Jacob Pan3746c6b2010-02-12 05:01:12 -0800182static unsigned long __init mrst_calibrate_tsc(void)
183{
184 unsigned long flags, fast_calibrate;
185
186 local_irq_save(flags);
187 fast_calibrate = apbt_quick_calibrate();
188 local_irq_restore(flags);
189
190 if (fast_calibrate)
191 return fast_calibrate;
192
193 return 0;
194}
195
196void __init mrst_time_init(void)
197{
Jacob Pan7f05dec2010-11-09 11:28:43 +0000198 sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
Jacob Pana875c012010-05-19 12:01:25 -0700199 switch (mrst_timer_options) {
200 case MRST_TIMER_APBT_ONLY:
201 break;
202 case MRST_TIMER_LAPIC_APBT:
203 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
204 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
205 break;
206 default:
207 if (!boot_cpu_has(X86_FEATURE_ARAT))
208 break;
209 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
210 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
211 return;
212 }
213 /* we need at least one APB timer */
Jacob Pan3746c6b2010-02-12 05:01:12 -0800214 pre_init_apic_IRQ0();
215 apbt_time_init();
216}
217
Jacob Pana0c173b2010-05-19 12:01:24 -0700218void __cpuinit mrst_arch_setup(void)
Jacob Pan3746c6b2010-02-12 05:01:12 -0800219{
Jacob Pana0c173b2010-05-19 12:01:24 -0700220 if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
H. Peter Anvina75af582010-05-19 13:40:14 -0700221 __mrst_cpu_chip = MRST_CPU_CHIP_PENWELL;
Jacob Pana0c173b2010-05-19 12:01:24 -0700222 else if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x26)
H. Peter Anvina75af582010-05-19 13:40:14 -0700223 __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
Jacob Pana0c173b2010-05-19 12:01:24 -0700224 else {
225 pr_err("Unknown Moorestown CPU (%d:%d), default to Lincroft\n",
226 boot_cpu_data.x86, boot_cpu_data.x86_model);
H. Peter Anvina75af582010-05-19 13:40:14 -0700227 __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
Jacob Pana0c173b2010-05-19 12:01:24 -0700228 }
229 pr_debug("Moorestown CPU %s identified\n",
H. Peter Anvina75af582010-05-19 13:40:14 -0700230 (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT) ?
Jacob Pana0c173b2010-05-19 12:01:24 -0700231 "Lincroft" : "Penwell");
232}
Jacob Pan3746c6b2010-02-12 05:01:12 -0800233
Feng Tang6d2cce62010-07-05 23:03:19 +0800234/* MID systems don't have i8042 controller */
235static int mrst_i8042_detect(void)
236{
237 return 0;
238}
239
Alek Ducfb505a2010-11-10 16:50:08 +0000240/* Reboot and power off are handled by the SCU on a MID device */
241static void mrst_power_off(void)
242{
243 intel_scu_ipc_simple_command(0xf1, 1);
244}
245
246static void mrst_reboot(void)
247{
248 intel_scu_ipc_simple_command(0xf1, 0);
249}
250
Jacob Pan3746c6b2010-02-12 05:01:12 -0800251/*
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200252 * Moorestown specific x86_init function overrides and early setup
253 * calls.
254 */
255void __init x86_mrst_early_setup(void)
256{
257 x86_init.resources.probe_roms = x86_init_noop;
258 x86_init.resources.reserve_resources = x86_init_noop;
Jacob Pan5b78b672010-02-12 02:29:11 -0800259
Jacob Pan3746c6b2010-02-12 05:01:12 -0800260 x86_init.timers.timer_init = mrst_time_init;
Jacob Pana875c012010-05-19 12:01:25 -0700261 x86_init.timers.setup_percpu_clockev = x86_init_noop;
Jacob Pan3746c6b2010-02-12 05:01:12 -0800262
263 x86_init.irqs.pre_vector_init = x86_init_noop;
264
Jacob Pana0c173b2010-05-19 12:01:24 -0700265 x86_init.oem.arch_setup = mrst_arch_setup;
266
Jacob Pana875c012010-05-19 12:01:25 -0700267 x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
Jacob Pan3746c6b2010-02-12 05:01:12 -0800268
269 x86_platform.calibrate_tsc = mrst_calibrate_tsc;
Feng Tang6d2cce62010-07-05 23:03:19 +0800270 x86_platform.i8042_detect = mrst_i8042_detect;
Jacob Panaf2730f2010-02-12 10:31:47 -0800271 x86_init.pci.init = pci_mrst_init;
272 x86_init.pci.fixup_irqs = x86_init_noop;
273
Jacob Pan5b78b672010-02-12 02:29:11 -0800274 legacy_pic = &null_legacy_pic;
Jacob Panfea24e22010-05-14 14:41:20 -0700275
Alek Ducfb505a2010-11-10 16:50:08 +0000276 /* Moorestown specific power_off/restart method */
277 pm_power_off = mrst_power_off;
278 machine_ops.emergency_restart = mrst_reboot;
279
Jacob Panfea24e22010-05-14 14:41:20 -0700280 /* Avoid searching for BIOS MP tables */
281 x86_init.mpparse.find_smp_config = x86_init_noop;
282 x86_init.mpparse.get_smp_config = x86_init_uint_noop;
283
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200284}
Jacob Pana875c012010-05-19 12:01:25 -0700285
286/*
287 * if user does not want to use per CPU apb timer, just give it a lower rating
288 * than local apic timer and skip the late per cpu timer init.
289 */
290static inline int __init setup_x86_mrst_timer(char *arg)
291{
292 if (!arg)
293 return -EINVAL;
294
295 if (strcmp("apbt_only", arg) == 0)
296 mrst_timer_options = MRST_TIMER_APBT_ONLY;
297 else if (strcmp("lapic_and_apbt", arg) == 0)
298 mrst_timer_options = MRST_TIMER_LAPIC_APBT;
299 else {
300 pr_warning("X86 MRST timer option %s not recognised"
301 " use x86_mrst_timer=apbt_only or lapic_and_apbt\n",
302 arg);
303 return -EINVAL;
304 }
305 return 0;
306}
307__setup("x86_mrst_timer=", setup_x86_mrst_timer);
Feng Tang1da4b1c2010-11-09 11:22:58 +0000308
309/*
310 * Parsing GPIO table first, since the DEVS table will need this table
311 * to map the pin name to the actual pin.
312 */
313static struct sfi_gpio_table_entry *gpio_table;
314static int gpio_num_entry;
315
316static int __init sfi_parse_gpio(struct sfi_table_header *table)
317{
318 struct sfi_table_simple *sb;
319 struct sfi_gpio_table_entry *pentry;
320 int num, i;
321
322 if (gpio_table)
323 return 0;
324 sb = (struct sfi_table_simple *)table;
325 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
326 pentry = (struct sfi_gpio_table_entry *)sb->pentry;
327
328 gpio_table = (struct sfi_gpio_table_entry *)
329 kmalloc(num * sizeof(*pentry), GFP_KERNEL);
330 if (!gpio_table)
331 return -1;
332 memcpy(gpio_table, pentry, num * sizeof(*pentry));
333 gpio_num_entry = num;
334
335 pr_debug("GPIO pin info:\n");
336 for (i = 0; i < num; i++, pentry++)
337 pr_debug("info[%2d]: controller = %16.16s, pin_name = %16.16s,"
338 " pin = %d\n", i,
339 pentry->controller_name,
340 pentry->pin_name,
341 pentry->pin_no);
342 return 0;
343}
344
345static int get_gpio_by_name(const char *name)
346{
347 struct sfi_gpio_table_entry *pentry = gpio_table;
348 int i;
349
350 if (!pentry)
351 return -1;
352 for (i = 0; i < gpio_num_entry; i++, pentry++) {
353 if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
354 return pentry->pin_no;
355 }
356 return -1;
357}
358
359/*
360 * Here defines the array of devices platform data that IAFW would export
361 * through SFI "DEVS" table, we use name and type to match the device and
362 * its platform data.
363 */
364struct devs_id {
365 char name[SFI_NAME_LEN + 1];
366 u8 type;
367 u8 delay;
368 void *(*get_platform_data)(void *info);
369};
370
371/* the offset for the mapping of global gpio pin to irq */
372#define MRST_IRQ_OFFSET 0x100
373
374static void __init *pmic_gpio_platform_data(void *info)
375{
376 static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
377 int gpio_base = get_gpio_by_name("pmic_gpio_base");
378
379 if (gpio_base == -1)
380 gpio_base = 64;
381 pmic_gpio_pdata.gpio_base = gpio_base;
382 pmic_gpio_pdata.irq_base = gpio_base + MRST_IRQ_OFFSET;
383 pmic_gpio_pdata.gpiointr = 0xffffeff8;
384
385 return &pmic_gpio_pdata;
386}
387
388static void __init *max3111_platform_data(void *info)
389{
390 struct spi_board_info *spi_info = info;
391 int intr = get_gpio_by_name("max3111_int");
392
393 if (intr == -1)
394 return NULL;
395 spi_info->irq = intr + MRST_IRQ_OFFSET;
396 return NULL;
397}
398
399/* we have multiple max7315 on the board ... */
400#define MAX7315_NUM 2
401static void __init *max7315_platform_data(void *info)
402{
403 static struct pca953x_platform_data max7315_pdata[MAX7315_NUM];
404 static int nr;
405 struct pca953x_platform_data *max7315 = &max7315_pdata[nr];
406 struct i2c_board_info *i2c_info = info;
407 int gpio_base, intr;
408 char base_pin_name[SFI_NAME_LEN + 1];
409 char intr_pin_name[SFI_NAME_LEN + 1];
410
411 if (nr == MAX7315_NUM) {
412 pr_err("too many max7315s, we only support %d\n",
413 MAX7315_NUM);
414 return NULL;
415 }
416 /* we have several max7315 on the board, we only need load several
417 * instances of the same pca953x driver to cover them
418 */
419 strcpy(i2c_info->type, "max7315");
420 if (nr++) {
421 sprintf(base_pin_name, "max7315_%d_base", nr);
422 sprintf(intr_pin_name, "max7315_%d_int", nr);
423 } else {
424 strcpy(base_pin_name, "max7315_base");
425 strcpy(intr_pin_name, "max7315_int");
426 }
427
428 gpio_base = get_gpio_by_name(base_pin_name);
429 intr = get_gpio_by_name(intr_pin_name);
430
431 if (gpio_base == -1)
432 return NULL;
433 max7315->gpio_base = gpio_base;
434 if (intr != -1) {
435 i2c_info->irq = intr + MRST_IRQ_OFFSET;
436 max7315->irq_base = gpio_base + MRST_IRQ_OFFSET;
437 } else {
438 i2c_info->irq = -1;
439 max7315->irq_base = -1;
440 }
441 return max7315;
442}
443
444static void __init *emc1403_platform_data(void *info)
445{
446 static short intr2nd_pdata;
447 struct i2c_board_info *i2c_info = info;
448 int intr = get_gpio_by_name("thermal_int");
449 int intr2nd = get_gpio_by_name("thermal_alert");
450
451 if (intr == -1 || intr2nd == -1)
452 return NULL;
453
454 i2c_info->irq = intr + MRST_IRQ_OFFSET;
455 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
456
457 return &intr2nd_pdata;
458}
459
460static void __init *lis331dl_platform_data(void *info)
461{
462 static short intr2nd_pdata;
463 struct i2c_board_info *i2c_info = info;
464 int intr = get_gpio_by_name("accel_int");
465 int intr2nd = get_gpio_by_name("accel_2");
466
467 if (intr == -1 || intr2nd == -1)
468 return NULL;
469
470 i2c_info->irq = intr + MRST_IRQ_OFFSET;
471 intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
472
473 return &intr2nd_pdata;
474}
475
Vinod Koul86071532010-11-10 17:40:48 +0000476static void __init *no_platform_data(void *info)
477{
478 return NULL;
479}
480
Feng Tang1da4b1c2010-11-09 11:22:58 +0000481static const struct devs_id __initconst device_ids[] = {
482 {"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data},
483 {"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data},
484 {"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
485 {"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
486 {"emc1403", SFI_DEV_TYPE_I2C, 1, &emc1403_platform_data},
487 {"i2c_accel", SFI_DEV_TYPE_I2C, 0, &lis331dl_platform_data},
Vinod Koul86071532010-11-10 17:40:48 +0000488 {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
489 {"msic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
Feng Tang1da4b1c2010-11-09 11:22:58 +0000490 {},
491};
492
493#define MAX_IPCDEVS 24
494static struct platform_device *ipc_devs[MAX_IPCDEVS];
495static int ipc_next_dev;
496
497#define MAX_SCU_SPI 24
498static struct spi_board_info *spi_devs[MAX_SCU_SPI];
499static int spi_next_dev;
500
501#define MAX_SCU_I2C 24
502static struct i2c_board_info *i2c_devs[MAX_SCU_I2C];
503static int i2c_bus[MAX_SCU_I2C];
504static int i2c_next_dev;
505
506static void __init intel_scu_device_register(struct platform_device *pdev)
507{
508 if(ipc_next_dev == MAX_IPCDEVS)
509 pr_err("too many SCU IPC devices");
510 else
511 ipc_devs[ipc_next_dev++] = pdev;
512}
513
514static void __init intel_scu_spi_device_register(struct spi_board_info *sdev)
515{
516 struct spi_board_info *new_dev;
517
518 if (spi_next_dev == MAX_SCU_SPI) {
519 pr_err("too many SCU SPI devices");
520 return;
521 }
522
523 new_dev = kzalloc(sizeof(*sdev), GFP_KERNEL);
524 if (!new_dev) {
525 pr_err("failed to alloc mem for delayed spi dev %s\n",
526 sdev->modalias);
527 return;
528 }
529 memcpy(new_dev, sdev, sizeof(*sdev));
530
531 spi_devs[spi_next_dev++] = new_dev;
532}
533
534static void __init intel_scu_i2c_device_register(int bus,
535 struct i2c_board_info *idev)
536{
537 struct i2c_board_info *new_dev;
538
539 if (i2c_next_dev == MAX_SCU_I2C) {
540 pr_err("too many SCU I2C devices");
541 return;
542 }
543
544 new_dev = kzalloc(sizeof(*idev), GFP_KERNEL);
545 if (!new_dev) {
546 pr_err("failed to alloc mem for delayed i2c dev %s\n",
547 idev->type);
548 return;
549 }
550 memcpy(new_dev, idev, sizeof(*idev));
551
552 i2c_bus[i2c_next_dev] = bus;
553 i2c_devs[i2c_next_dev++] = new_dev;
554}
555
556/* Called by IPC driver */
557void intel_scu_devices_create(void)
558{
559 int i;
560
561 for (i = 0; i < ipc_next_dev; i++)
562 platform_device_add(ipc_devs[i]);
563
564 for (i = 0; i < spi_next_dev; i++)
565 spi_register_board_info(spi_devs[i], 1);
566
567 for (i = 0; i < i2c_next_dev; i++) {
568 struct i2c_adapter *adapter;
569 struct i2c_client *client;
570
571 adapter = i2c_get_adapter(i2c_bus[i]);
572 if (adapter) {
573 client = i2c_new_device(adapter, i2c_devs[i]);
574 if (!client)
575 pr_err("can't create i2c device %s\n",
576 i2c_devs[i]->type);
577 } else
578 i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1);
579 }
580}
581EXPORT_SYMBOL_GPL(intel_scu_devices_create);
582
583/* Called by IPC driver */
584void intel_scu_devices_destroy(void)
585{
586 int i;
587
588 for (i = 0; i < ipc_next_dev; i++)
589 platform_device_del(ipc_devs[i]);
590}
591EXPORT_SYMBOL_GPL(intel_scu_devices_destroy);
592
593static void __init install_irq_resource(struct platform_device *pdev, int irq)
594{
595 /* Single threaded */
596 static struct resource __initdata res = {
597 .name = "IRQ",
598 .flags = IORESOURCE_IRQ,
599 };
600 res.start = irq;
601 platform_device_add_resources(pdev, &res, 1);
602}
603
604static void __init sfi_handle_ipc_dev(struct platform_device *pdev)
605{
606 const struct devs_id *dev = device_ids;
607 void *pdata = NULL;
608
609 while (dev->name[0]) {
610 if (dev->type == SFI_DEV_TYPE_IPC &&
611 !strncmp(dev->name, pdev->name, SFI_NAME_LEN)) {
612 pdata = dev->get_platform_data(pdev);
613 break;
614 }
615 dev++;
616 }
617 pdev->dev.platform_data = pdata;
618 intel_scu_device_register(pdev);
619}
620
621static void __init sfi_handle_spi_dev(struct spi_board_info *spi_info)
622{
623 const struct devs_id *dev = device_ids;
624 void *pdata = NULL;
625
626 while (dev->name[0]) {
627 if (dev->type == SFI_DEV_TYPE_SPI &&
628 !strncmp(dev->name, spi_info->modalias, SFI_NAME_LEN)) {
629 pdata = dev->get_platform_data(spi_info);
630 break;
631 }
632 dev++;
633 }
634 spi_info->platform_data = pdata;
635 if (dev->delay)
636 intel_scu_spi_device_register(spi_info);
637 else
638 spi_register_board_info(spi_info, 1);
639}
640
641static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info)
642{
643 const struct devs_id *dev = device_ids;
644 void *pdata = NULL;
645
646 while (dev->name[0]) {
647 if (dev->type == SFI_DEV_TYPE_I2C &&
648 !strncmp(dev->name, i2c_info->type, SFI_NAME_LEN)) {
649 pdata = dev->get_platform_data(i2c_info);
650 break;
651 }
652 dev++;
653 }
654 i2c_info->platform_data = pdata;
655
656 if (dev->delay)
657 intel_scu_i2c_device_register(bus, i2c_info);
658 else
659 i2c_register_board_info(bus, i2c_info, 1);
660 }
661
662
663static int __init sfi_parse_devs(struct sfi_table_header *table)
664{
665 struct sfi_table_simple *sb;
666 struct sfi_device_table_entry *pentry;
667 struct spi_board_info spi_info;
668 struct i2c_board_info i2c_info;
669 struct platform_device *pdev;
670 int num, i, bus;
671 int ioapic;
672 struct io_apic_irq_attr irq_attr;
673
674 sb = (struct sfi_table_simple *)table;
675 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_device_table_entry);
676 pentry = (struct sfi_device_table_entry *)sb->pentry;
677
678 for (i = 0; i < num; i++, pentry++) {
679 if (pentry->irq != (u8)0xff) { /* native RTE case */
680 /* these SPI2 devices are not exposed to system as PCI
681 * devices, but they have separate RTE entry in IOAPIC
682 * so we have to enable them one by one here
683 */
684 ioapic = mp_find_ioapic(pentry->irq);
685 irq_attr.ioapic = ioapic;
686 irq_attr.ioapic_pin = pentry->irq;
687 irq_attr.trigger = 1;
688 irq_attr.polarity = 1;
689 io_apic_set_pci_routing(NULL, pentry->irq, &irq_attr);
690 }
691 switch (pentry->type) {
692 case SFI_DEV_TYPE_IPC:
693 /* ID as IRQ is a hack that will go away */
694 pdev = platform_device_alloc(pentry->name, pentry->irq);
695 if (pdev == NULL) {
696 pr_err("out of memory for SFI platform device '%s'.\n",
697 pentry->name);
698 continue;
699 }
700 install_irq_resource(pdev, pentry->irq);
701 pr_debug("info[%2d]: IPC bus, name = %16.16s, "
702 "irq = 0x%2x\n", i, pentry->name, pentry->irq);
703 sfi_handle_ipc_dev(pdev);
704 break;
705 case SFI_DEV_TYPE_SPI:
706 memset(&spi_info, 0, sizeof(spi_info));
707 strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
708 spi_info.irq = pentry->irq;
709 spi_info.bus_num = pentry->host_num;
710 spi_info.chip_select = pentry->addr;
711 spi_info.max_speed_hz = pentry->max_freq;
712 pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, "
713 "irq = 0x%2x, max_freq = %d, cs = %d\n", i,
714 spi_info.bus_num,
715 spi_info.modalias,
716 spi_info.irq,
717 spi_info.max_speed_hz,
718 spi_info.chip_select);
719 sfi_handle_spi_dev(&spi_info);
720 break;
721 case SFI_DEV_TYPE_I2C:
722 memset(&i2c_info, 0, sizeof(i2c_info));
723 bus = pentry->host_num;
724 strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
725 i2c_info.irq = pentry->irq;
726 i2c_info.addr = pentry->addr;
727 pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, "
728 "irq = 0x%2x, addr = 0x%x\n", i, bus,
729 i2c_info.type,
730 i2c_info.irq,
731 i2c_info.addr);
732 sfi_handle_i2c_dev(bus, &i2c_info);
733 break;
734 case SFI_DEV_TYPE_UART:
735 case SFI_DEV_TYPE_HSI:
736 default:
737 ;
738 }
739 }
740 return 0;
741}
742
743static int __init mrst_platform_init(void)
744{
745 sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
746 sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
747 return 0;
748}
749arch_initcall(mrst_platform_init);
750
751/*
752 * we will search these buttons in SFI GPIO table (by name)
753 * and register them dynamically. Please add all possible
754 * buttons here, we will shrink them if no GPIO found.
755 */
756static struct gpio_keys_button gpio_button[] = {
757 {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
758 {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
759 {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
760 {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
761 {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
762 {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
763 {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
764 {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
765 {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
766 {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
767};
768
769static struct gpio_keys_platform_data mrst_gpio_keys = {
770 .buttons = gpio_button,
771 .rep = 1,
772 .nbuttons = -1, /* will fill it after search */
773};
774
775static struct platform_device pb_device = {
776 .name = "gpio-keys",
777 .id = -1,
778 .dev = {
779 .platform_data = &mrst_gpio_keys,
780 },
781};
782
783/*
784 * Shrink the non-existent buttons, register the gpio button
785 * device if there is some
786 */
787static int __init pb_keys_init(void)
788{
789 struct gpio_keys_button *gb = gpio_button;
790 int i, num, good = 0;
791
792 num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
793 for (i = 0; i < num; i++) {
794 gb[i].gpio = get_gpio_by_name(gb[i].desc);
795 if (gb[i].gpio == -1)
796 continue;
797
798 if (i != good)
799 gb[good] = gb[i];
800 good++;
801 }
802
803 if (good) {
804 mrst_gpio_keys.nbuttons = good;
805 return platform_device_register(&pb_device);
806 }
807 return 0;
808}
809late_initcall(pb_keys_init);