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