Thomas Gleixner | 3f4110a | 2009-08-29 14:54:20 +0200 | [diff] [blame] | 1 | /* |
| 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 Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 12 | |
| 13 | #define pr_fmt(fmt) "mrst: " fmt |
| 14 | |
Thomas Gleixner | 3f4110a | 2009-08-29 14:54:20 +0200 | [diff] [blame] | 15 | #include <linux/init.h> |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 16 | #include <linux/kernel.h> |
Feng Tang | efe3ed9 | 2011-08-26 11:25:14 +0100 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/scatterlist.h> |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 19 | #include <linux/sfi.h> |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 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> |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 27 | #include <linux/irq.h> |
Feng Tang | cf08945 | 2010-02-12 03:37:38 -0800 | [diff] [blame] | 28 | #include <linux/module.h> |
Alan Cox | 42c2544 | 2011-09-07 16:06:51 +0300 | [diff] [blame] | 29 | #include <linux/notifier.h> |
Mika Westerberg | 360545c | 2011-10-18 12:41:22 +0300 | [diff] [blame] | 30 | #include <linux/mfd/intel_msic.h> |
Thomas Gleixner | 3f4110a | 2009-08-29 14:54:20 +0200 | [diff] [blame] | 31 | |
| 32 | #include <asm/setup.h> |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 33 | #include <asm/mpspec_def.h> |
| 34 | #include <asm/hw_irq.h> |
| 35 | #include <asm/apic.h> |
| 36 | #include <asm/io_apic.h> |
Jacob Pan | 5b78b67 | 2010-02-12 02:29:11 -0800 | [diff] [blame] | 37 | #include <asm/mrst.h> |
Feng Tang | 168202c | 2011-02-15 00:13:32 +0800 | [diff] [blame] | 38 | #include <asm/mrst-vrtc.h> |
Jacob Pan | 5b78b67 | 2010-02-12 02:29:11 -0800 | [diff] [blame] | 39 | #include <asm/io.h> |
| 40 | #include <asm/i8259.h> |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 41 | #include <asm/intel_scu_ipc.h> |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 42 | #include <asm/apb_timer.h> |
Alek Du | cfb505a | 2010-11-10 16:50:08 +0000 | [diff] [blame] | 43 | #include <asm/reboot.h> |
Thomas Gleixner | 3f4110a | 2009-08-29 14:54:20 +0200 | [diff] [blame] | 44 | |
Jacob Pan | a875c01 | 2010-05-19 12:01:25 -0700 | [diff] [blame] | 45 | /* |
| 46 | * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock, |
| 47 | * cmdline option x86_mrst_timer can be used to override the configuration |
| 48 | * to prefer one or the other. |
| 49 | * at runtime, there are basically three timer configurations: |
| 50 | * 1. per cpu apbt clock only |
| 51 | * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only |
| 52 | * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast. |
| 53 | * |
| 54 | * by default (without cmdline option), platform code first detects cpu type |
| 55 | * to see if we are on lincroft or penwell, then set up both lapic or apbt |
| 56 | * clocks accordingly. |
| 57 | * i.e. by default, medfield uses configuration #2, moorestown uses #1. |
| 58 | * config #3 is supported but not recommended on medfield. |
| 59 | * |
| 60 | * rating and feature summary: |
| 61 | * lapic (with C3STOP) --------- 100 |
| 62 | * apbt (always-on) ------------ 110 |
| 63 | * lapic (always-on,ARAT) ------ 150 |
| 64 | */ |
| 65 | |
H. Peter Anvin | 1467138 | 2010-05-19 14:37:40 -0700 | [diff] [blame] | 66 | __cpuinitdata enum mrst_timer_options mrst_timer_options; |
Jacob Pan | a875c01 | 2010-05-19 12:01:25 -0700 | [diff] [blame] | 67 | |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 68 | static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM]; |
| 69 | static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM]; |
H. Peter Anvin | a75af58 | 2010-05-19 13:40:14 -0700 | [diff] [blame] | 70 | enum mrst_cpu_type __mrst_cpu_chip; |
| 71 | EXPORT_SYMBOL_GPL(__mrst_cpu_chip); |
Jacob Pan | a0c173b | 2010-05-19 12:01:24 -0700 | [diff] [blame] | 72 | |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 73 | int sfi_mtimer_num; |
| 74 | |
Feng Tang | cf08945 | 2010-02-12 03:37:38 -0800 | [diff] [blame] | 75 | struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX]; |
| 76 | EXPORT_SYMBOL_GPL(sfi_mrtc_array); |
| 77 | int sfi_mrtc_num; |
| 78 | |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 79 | /* parse all the mtimer info to a static mtimer array */ |
| 80 | static int __init sfi_parse_mtmr(struct sfi_table_header *table) |
| 81 | { |
| 82 | struct sfi_table_simple *sb; |
| 83 | struct sfi_timer_table_entry *pentry; |
| 84 | struct mpc_intsrc mp_irq; |
| 85 | int totallen; |
| 86 | |
| 87 | sb = (struct sfi_table_simple *)table; |
| 88 | if (!sfi_mtimer_num) { |
| 89 | sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb, |
| 90 | struct sfi_timer_table_entry); |
| 91 | pentry = (struct sfi_timer_table_entry *) sb->pentry; |
| 92 | totallen = sfi_mtimer_num * sizeof(*pentry); |
| 93 | memcpy(sfi_mtimer_array, pentry, totallen); |
| 94 | } |
| 95 | |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 96 | pr_debug("SFI MTIMER info (num = %d):\n", sfi_mtimer_num); |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 97 | pentry = sfi_mtimer_array; |
| 98 | for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) { |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 99 | pr_debug("timer[%d]: paddr = 0x%08x, freq = %dHz," |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 100 | " irq = %d\n", totallen, (u32)pentry->phys_addr, |
| 101 | pentry->freq_hz, pentry->irq); |
| 102 | if (!pentry->irq) |
| 103 | continue; |
Jacob Pan | 9d90e49 | 2011-04-08 11:23:00 -0700 | [diff] [blame] | 104 | mp_irq.type = MP_INTSRC; |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 105 | mp_irq.irqtype = mp_INT; |
| 106 | /* triggering mode edge bit 2-3, active high polarity bit 0-1 */ |
| 107 | mp_irq.irqflag = 5; |
Jacob Pan | 9d90e49 | 2011-04-08 11:23:00 -0700 | [diff] [blame] | 108 | mp_irq.srcbus = MP_BUS_ISA; |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 109 | mp_irq.srcbusirq = pentry->irq; /* IRQ */ |
| 110 | mp_irq.dstapic = MP_APIC_ALL; |
| 111 | mp_irq.dstirq = pentry->irq; |
Feng Tang | 2d8009b | 2010-11-19 11:33:35 +0800 | [diff] [blame] | 112 | mp_save_irq(&mp_irq); |
Jacob Pan | 16ab539 | 2010-02-12 03:08:30 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | struct sfi_timer_table_entry *sfi_get_mtmr(int hint) |
| 119 | { |
| 120 | int i; |
| 121 | if (hint < sfi_mtimer_num) { |
| 122 | if (!sfi_mtimer_usage[hint]) { |
| 123 | pr_debug("hint taken for timer %d irq %d\n",\ |
| 124 | hint, sfi_mtimer_array[hint].irq); |
| 125 | sfi_mtimer_usage[hint] = 1; |
| 126 | return &sfi_mtimer_array[hint]; |
| 127 | } |
| 128 | } |
| 129 | /* take the first timer available */ |
| 130 | for (i = 0; i < sfi_mtimer_num;) { |
| 131 | if (!sfi_mtimer_usage[i]) { |
| 132 | sfi_mtimer_usage[i] = 1; |
| 133 | return &sfi_mtimer_array[i]; |
| 134 | } |
| 135 | i++; |
| 136 | } |
| 137 | return NULL; |
| 138 | } |
| 139 | |
| 140 | void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr) |
| 141 | { |
| 142 | int i; |
| 143 | for (i = 0; i < sfi_mtimer_num;) { |
| 144 | if (mtmr->irq == sfi_mtimer_array[i].irq) { |
| 145 | sfi_mtimer_usage[i] = 0; |
| 146 | return; |
| 147 | } |
| 148 | i++; |
| 149 | } |
| 150 | } |
| 151 | |
Feng Tang | cf08945 | 2010-02-12 03:37:38 -0800 | [diff] [blame] | 152 | /* parse all the mrtc info to a global mrtc array */ |
| 153 | int __init sfi_parse_mrtc(struct sfi_table_header *table) |
| 154 | { |
| 155 | struct sfi_table_simple *sb; |
| 156 | struct sfi_rtc_table_entry *pentry; |
| 157 | struct mpc_intsrc mp_irq; |
| 158 | |
| 159 | int totallen; |
| 160 | |
| 161 | sb = (struct sfi_table_simple *)table; |
| 162 | if (!sfi_mrtc_num) { |
| 163 | sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb, |
| 164 | struct sfi_rtc_table_entry); |
| 165 | pentry = (struct sfi_rtc_table_entry *)sb->pentry; |
| 166 | totallen = sfi_mrtc_num * sizeof(*pentry); |
| 167 | memcpy(sfi_mrtc_array, pentry, totallen); |
| 168 | } |
| 169 | |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 170 | pr_debug("SFI RTC info (num = %d):\n", sfi_mrtc_num); |
Feng Tang | cf08945 | 2010-02-12 03:37:38 -0800 | [diff] [blame] | 171 | pentry = sfi_mrtc_array; |
| 172 | for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) { |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 173 | pr_debug("RTC[%d]: paddr = 0x%08x, irq = %d\n", |
Feng Tang | cf08945 | 2010-02-12 03:37:38 -0800 | [diff] [blame] | 174 | totallen, (u32)pentry->phys_addr, pentry->irq); |
Jacob Pan | 9d90e49 | 2011-04-08 11:23:00 -0700 | [diff] [blame] | 175 | mp_irq.type = MP_INTSRC; |
Feng Tang | cf08945 | 2010-02-12 03:37:38 -0800 | [diff] [blame] | 176 | mp_irq.irqtype = mp_INT; |
Feng Tang | 6f207e9 | 2010-11-11 15:50:50 +0000 | [diff] [blame] | 177 | mp_irq.irqflag = 0xf; /* level trigger and active low */ |
Jacob Pan | 9d90e49 | 2011-04-08 11:23:00 -0700 | [diff] [blame] | 178 | mp_irq.srcbus = MP_BUS_ISA; |
Feng Tang | cf08945 | 2010-02-12 03:37:38 -0800 | [diff] [blame] | 179 | mp_irq.srcbusirq = pentry->irq; /* IRQ */ |
| 180 | mp_irq.dstapic = MP_APIC_ALL; |
| 181 | mp_irq.dstirq = pentry->irq; |
Feng Tang | 2d8009b | 2010-11-19 11:33:35 +0800 | [diff] [blame] | 182 | mp_save_irq(&mp_irq); |
Feng Tang | cf08945 | 2010-02-12 03:37:38 -0800 | [diff] [blame] | 183 | } |
| 184 | return 0; |
| 185 | } |
| 186 | |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 187 | static unsigned long __init mrst_calibrate_tsc(void) |
| 188 | { |
| 189 | unsigned long flags, fast_calibrate; |
Dirk Brandewie | 0a91532 | 2011-11-10 13:42:53 +0000 | [diff] [blame] | 190 | if (__mrst_cpu_chip == MRST_CPU_CHIP_PENWELL) { |
| 191 | u32 lo, hi, ratio, fsb; |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 192 | |
Dirk Brandewie | 0a91532 | 2011-11-10 13:42:53 +0000 | [diff] [blame] | 193 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); |
| 194 | pr_debug("IA32 perf status is 0x%x, 0x%0x\n", lo, hi); |
| 195 | ratio = (hi >> 8) & 0x1f; |
| 196 | pr_debug("ratio is %d\n", ratio); |
| 197 | if (!ratio) { |
| 198 | pr_err("read a zero ratio, should be incorrect!\n"); |
| 199 | pr_err("force tsc ratio to 16 ...\n"); |
| 200 | ratio = 16; |
| 201 | } |
| 202 | rdmsr(MSR_FSB_FREQ, lo, hi); |
| 203 | if ((lo & 0x7) == 0x7) |
| 204 | fsb = PENWELL_FSB_FREQ_83SKU; |
| 205 | else |
| 206 | fsb = PENWELL_FSB_FREQ_100SKU; |
| 207 | fast_calibrate = ratio * fsb; |
| 208 | pr_debug("read penwell tsc %lu khz\n", fast_calibrate); |
| 209 | lapic_timer_frequency = fsb * 1000 / HZ; |
| 210 | /* mark tsc clocksource as reliable */ |
| 211 | set_cpu_cap(&boot_cpu_data, X86_FEATURE_TSC_RELIABLE); |
| 212 | } else { |
| 213 | local_irq_save(flags); |
| 214 | fast_calibrate = apbt_quick_calibrate(); |
| 215 | local_irq_restore(flags); |
| 216 | } |
| 217 | |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 218 | if (fast_calibrate) |
| 219 | return fast_calibrate; |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
Luis R. Rodriguez | 8fab6af | 2011-05-06 15:00:09 -0700 | [diff] [blame] | 224 | static void __init mrst_time_init(void) |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 225 | { |
Jacob Pan | 7f05dec | 2010-11-09 11:28:43 +0000 | [diff] [blame] | 226 | sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr); |
Jacob Pan | a875c01 | 2010-05-19 12:01:25 -0700 | [diff] [blame] | 227 | switch (mrst_timer_options) { |
| 228 | case MRST_TIMER_APBT_ONLY: |
| 229 | break; |
| 230 | case MRST_TIMER_LAPIC_APBT: |
| 231 | x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock; |
| 232 | x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock; |
| 233 | break; |
| 234 | default: |
| 235 | if (!boot_cpu_has(X86_FEATURE_ARAT)) |
| 236 | break; |
| 237 | x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock; |
| 238 | x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock; |
| 239 | return; |
| 240 | } |
| 241 | /* we need at least one APB timer */ |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 242 | pre_init_apic_IRQ0(); |
| 243 | apbt_time_init(); |
| 244 | } |
| 245 | |
Luis R. Rodriguez | 8fab6af | 2011-05-06 15:00:09 -0700 | [diff] [blame] | 246 | static void __cpuinit mrst_arch_setup(void) |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 247 | { |
Jacob Pan | a0c173b | 2010-05-19 12:01:24 -0700 | [diff] [blame] | 248 | if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27) |
H. Peter Anvin | a75af58 | 2010-05-19 13:40:14 -0700 | [diff] [blame] | 249 | __mrst_cpu_chip = MRST_CPU_CHIP_PENWELL; |
Jacob Pan | a0c173b | 2010-05-19 12:01:24 -0700 | [diff] [blame] | 250 | else if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x26) |
H. Peter Anvin | a75af58 | 2010-05-19 13:40:14 -0700 | [diff] [blame] | 251 | __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT; |
Jacob Pan | a0c173b | 2010-05-19 12:01:24 -0700 | [diff] [blame] | 252 | else { |
| 253 | pr_err("Unknown Moorestown CPU (%d:%d), default to Lincroft\n", |
| 254 | boot_cpu_data.x86, boot_cpu_data.x86_model); |
H. Peter Anvin | a75af58 | 2010-05-19 13:40:14 -0700 | [diff] [blame] | 255 | __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT; |
Jacob Pan | a0c173b | 2010-05-19 12:01:24 -0700 | [diff] [blame] | 256 | } |
| 257 | pr_debug("Moorestown CPU %s identified\n", |
H. Peter Anvin | a75af58 | 2010-05-19 13:40:14 -0700 | [diff] [blame] | 258 | (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT) ? |
Jacob Pan | a0c173b | 2010-05-19 12:01:24 -0700 | [diff] [blame] | 259 | "Lincroft" : "Penwell"); |
| 260 | } |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 261 | |
Feng Tang | 6d2cce6 | 2010-07-05 23:03:19 +0800 | [diff] [blame] | 262 | /* MID systems don't have i8042 controller */ |
| 263 | static int mrst_i8042_detect(void) |
| 264 | { |
| 265 | return 0; |
| 266 | } |
| 267 | |
Alek Du | cfb505a | 2010-11-10 16:50:08 +0000 | [diff] [blame] | 268 | /* Reboot and power off are handled by the SCU on a MID device */ |
| 269 | static void mrst_power_off(void) |
| 270 | { |
| 271 | intel_scu_ipc_simple_command(0xf1, 1); |
| 272 | } |
| 273 | |
| 274 | static void mrst_reboot(void) |
| 275 | { |
| 276 | intel_scu_ipc_simple_command(0xf1, 0); |
| 277 | } |
| 278 | |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 279 | /* |
Jacob Pan | 064a59b | 2011-11-10 13:43:05 +0000 | [diff] [blame] | 280 | * Moorestown does not have external NMI source nor port 0x61 to report |
| 281 | * NMI status. The possible NMI sources are from pmu as a result of NMI |
| 282 | * watchdog or lock debug. Reading io port 0x61 results in 0xff which |
| 283 | * misled NMI handler. |
| 284 | */ |
| 285 | static unsigned char mrst_get_nmi_reason(void) |
| 286 | { |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | /* |
Thomas Gleixner | 3f4110a | 2009-08-29 14:54:20 +0200 | [diff] [blame] | 291 | * Moorestown specific x86_init function overrides and early setup |
| 292 | * calls. |
| 293 | */ |
| 294 | void __init x86_mrst_early_setup(void) |
| 295 | { |
| 296 | x86_init.resources.probe_roms = x86_init_noop; |
| 297 | x86_init.resources.reserve_resources = x86_init_noop; |
Jacob Pan | 5b78b67 | 2010-02-12 02:29:11 -0800 | [diff] [blame] | 298 | |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 299 | x86_init.timers.timer_init = mrst_time_init; |
Jacob Pan | a875c01 | 2010-05-19 12:01:25 -0700 | [diff] [blame] | 300 | x86_init.timers.setup_percpu_clockev = x86_init_noop; |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 301 | |
| 302 | x86_init.irqs.pre_vector_init = x86_init_noop; |
| 303 | |
Jacob Pan | a0c173b | 2010-05-19 12:01:24 -0700 | [diff] [blame] | 304 | x86_init.oem.arch_setup = mrst_arch_setup; |
| 305 | |
Jacob Pan | a875c01 | 2010-05-19 12:01:25 -0700 | [diff] [blame] | 306 | x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock; |
Jacob Pan | 3746c6b | 2010-02-12 05:01:12 -0800 | [diff] [blame] | 307 | |
| 308 | x86_platform.calibrate_tsc = mrst_calibrate_tsc; |
Feng Tang | 6d2cce6 | 2010-07-05 23:03:19 +0800 | [diff] [blame] | 309 | x86_platform.i8042_detect = mrst_i8042_detect; |
Feng Tang | 168202c | 2011-02-15 00:13:32 +0800 | [diff] [blame] | 310 | x86_init.timers.wallclock_init = mrst_rtc_init; |
Jacob Pan | 064a59b | 2011-11-10 13:43:05 +0000 | [diff] [blame] | 311 | x86_platform.get_nmi_reason = mrst_get_nmi_reason; |
| 312 | |
Jacob Pan | af2730f | 2010-02-12 10:31:47 -0800 | [diff] [blame] | 313 | x86_init.pci.init = pci_mrst_init; |
| 314 | x86_init.pci.fixup_irqs = x86_init_noop; |
| 315 | |
Jacob Pan | 5b78b67 | 2010-02-12 02:29:11 -0800 | [diff] [blame] | 316 | legacy_pic = &null_legacy_pic; |
Jacob Pan | fea24e2 | 2010-05-14 14:41:20 -0700 | [diff] [blame] | 317 | |
Alek Du | cfb505a | 2010-11-10 16:50:08 +0000 | [diff] [blame] | 318 | /* Moorestown specific power_off/restart method */ |
| 319 | pm_power_off = mrst_power_off; |
| 320 | machine_ops.emergency_restart = mrst_reboot; |
| 321 | |
Jacob Pan | fea24e2 | 2010-05-14 14:41:20 -0700 | [diff] [blame] | 322 | /* Avoid searching for BIOS MP tables */ |
| 323 | x86_init.mpparse.find_smp_config = x86_init_noop; |
| 324 | x86_init.mpparse.get_smp_config = x86_init_uint_noop; |
Jacob Pan | 9d90e49 | 2011-04-08 11:23:00 -0700 | [diff] [blame] | 325 | set_bit(MP_BUS_ISA, mp_bus_not_pci); |
Thomas Gleixner | 3f4110a | 2009-08-29 14:54:20 +0200 | [diff] [blame] | 326 | } |
Jacob Pan | a875c01 | 2010-05-19 12:01:25 -0700 | [diff] [blame] | 327 | |
| 328 | /* |
| 329 | * if user does not want to use per CPU apb timer, just give it a lower rating |
| 330 | * than local apic timer and skip the late per cpu timer init. |
| 331 | */ |
| 332 | static inline int __init setup_x86_mrst_timer(char *arg) |
| 333 | { |
| 334 | if (!arg) |
| 335 | return -EINVAL; |
| 336 | |
| 337 | if (strcmp("apbt_only", arg) == 0) |
| 338 | mrst_timer_options = MRST_TIMER_APBT_ONLY; |
| 339 | else if (strcmp("lapic_and_apbt", arg) == 0) |
| 340 | mrst_timer_options = MRST_TIMER_LAPIC_APBT; |
| 341 | else { |
| 342 | pr_warning("X86 MRST timer option %s not recognised" |
| 343 | " use x86_mrst_timer=apbt_only or lapic_and_apbt\n", |
| 344 | arg); |
| 345 | return -EINVAL; |
| 346 | } |
| 347 | return 0; |
| 348 | } |
| 349 | __setup("x86_mrst_timer=", setup_x86_mrst_timer); |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 350 | |
| 351 | /* |
| 352 | * Parsing GPIO table first, since the DEVS table will need this table |
| 353 | * to map the pin name to the actual pin. |
| 354 | */ |
| 355 | static struct sfi_gpio_table_entry *gpio_table; |
| 356 | static int gpio_num_entry; |
| 357 | |
| 358 | static int __init sfi_parse_gpio(struct sfi_table_header *table) |
| 359 | { |
| 360 | struct sfi_table_simple *sb; |
| 361 | struct sfi_gpio_table_entry *pentry; |
| 362 | int num, i; |
| 363 | |
| 364 | if (gpio_table) |
| 365 | return 0; |
| 366 | sb = (struct sfi_table_simple *)table; |
| 367 | num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry); |
| 368 | pentry = (struct sfi_gpio_table_entry *)sb->pentry; |
| 369 | |
| 370 | gpio_table = (struct sfi_gpio_table_entry *) |
| 371 | kmalloc(num * sizeof(*pentry), GFP_KERNEL); |
| 372 | if (!gpio_table) |
| 373 | return -1; |
| 374 | memcpy(gpio_table, pentry, num * sizeof(*pentry)); |
| 375 | gpio_num_entry = num; |
| 376 | |
| 377 | pr_debug("GPIO pin info:\n"); |
| 378 | for (i = 0; i < num; i++, pentry++) |
| 379 | pr_debug("info[%2d]: controller = %16.16s, pin_name = %16.16s," |
| 380 | " pin = %d\n", i, |
| 381 | pentry->controller_name, |
| 382 | pentry->pin_name, |
| 383 | pentry->pin_no); |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static int get_gpio_by_name(const char *name) |
| 388 | { |
| 389 | struct sfi_gpio_table_entry *pentry = gpio_table; |
| 390 | int i; |
| 391 | |
| 392 | if (!pentry) |
| 393 | return -1; |
| 394 | for (i = 0; i < gpio_num_entry; i++, pentry++) { |
| 395 | if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN)) |
| 396 | return pentry->pin_no; |
| 397 | } |
| 398 | return -1; |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * Here defines the array of devices platform data that IAFW would export |
| 403 | * through SFI "DEVS" table, we use name and type to match the device and |
| 404 | * its platform data. |
| 405 | */ |
| 406 | struct devs_id { |
| 407 | char name[SFI_NAME_LEN + 1]; |
| 408 | u8 type; |
| 409 | u8 delay; |
| 410 | void *(*get_platform_data)(void *info); |
| 411 | }; |
| 412 | |
| 413 | /* the offset for the mapping of global gpio pin to irq */ |
| 414 | #define MRST_IRQ_OFFSET 0x100 |
| 415 | |
| 416 | static void __init *pmic_gpio_platform_data(void *info) |
| 417 | { |
| 418 | static struct intel_pmic_gpio_platform_data pmic_gpio_pdata; |
| 419 | int gpio_base = get_gpio_by_name("pmic_gpio_base"); |
| 420 | |
| 421 | if (gpio_base == -1) |
| 422 | gpio_base = 64; |
| 423 | pmic_gpio_pdata.gpio_base = gpio_base; |
| 424 | pmic_gpio_pdata.irq_base = gpio_base + MRST_IRQ_OFFSET; |
| 425 | pmic_gpio_pdata.gpiointr = 0xffffeff8; |
| 426 | |
| 427 | return &pmic_gpio_pdata; |
| 428 | } |
| 429 | |
| 430 | static void __init *max3111_platform_data(void *info) |
| 431 | { |
| 432 | struct spi_board_info *spi_info = info; |
| 433 | int intr = get_gpio_by_name("max3111_int"); |
| 434 | |
Feng Tang | efe3ed9 | 2011-08-26 11:25:14 +0100 | [diff] [blame] | 435 | spi_info->mode = SPI_MODE_0; |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 436 | if (intr == -1) |
| 437 | return NULL; |
| 438 | spi_info->irq = intr + MRST_IRQ_OFFSET; |
| 439 | return NULL; |
| 440 | } |
| 441 | |
| 442 | /* we have multiple max7315 on the board ... */ |
| 443 | #define MAX7315_NUM 2 |
| 444 | static void __init *max7315_platform_data(void *info) |
| 445 | { |
| 446 | static struct pca953x_platform_data max7315_pdata[MAX7315_NUM]; |
| 447 | static int nr; |
| 448 | struct pca953x_platform_data *max7315 = &max7315_pdata[nr]; |
| 449 | struct i2c_board_info *i2c_info = info; |
| 450 | int gpio_base, intr; |
| 451 | char base_pin_name[SFI_NAME_LEN + 1]; |
| 452 | char intr_pin_name[SFI_NAME_LEN + 1]; |
| 453 | |
| 454 | if (nr == MAX7315_NUM) { |
| 455 | pr_err("too many max7315s, we only support %d\n", |
| 456 | MAX7315_NUM); |
| 457 | return NULL; |
| 458 | } |
| 459 | /* we have several max7315 on the board, we only need load several |
| 460 | * instances of the same pca953x driver to cover them |
| 461 | */ |
| 462 | strcpy(i2c_info->type, "max7315"); |
| 463 | if (nr++) { |
| 464 | sprintf(base_pin_name, "max7315_%d_base", nr); |
| 465 | sprintf(intr_pin_name, "max7315_%d_int", nr); |
| 466 | } else { |
| 467 | strcpy(base_pin_name, "max7315_base"); |
| 468 | strcpy(intr_pin_name, "max7315_int"); |
| 469 | } |
| 470 | |
| 471 | gpio_base = get_gpio_by_name(base_pin_name); |
| 472 | intr = get_gpio_by_name(intr_pin_name); |
| 473 | |
| 474 | if (gpio_base == -1) |
| 475 | return NULL; |
| 476 | max7315->gpio_base = gpio_base; |
| 477 | if (intr != -1) { |
| 478 | i2c_info->irq = intr + MRST_IRQ_OFFSET; |
| 479 | max7315->irq_base = gpio_base + MRST_IRQ_OFFSET; |
| 480 | } else { |
| 481 | i2c_info->irq = -1; |
| 482 | max7315->irq_base = -1; |
| 483 | } |
| 484 | return max7315; |
| 485 | } |
| 486 | |
| 487 | static void __init *emc1403_platform_data(void *info) |
| 488 | { |
| 489 | static short intr2nd_pdata; |
| 490 | struct i2c_board_info *i2c_info = info; |
| 491 | int intr = get_gpio_by_name("thermal_int"); |
| 492 | int intr2nd = get_gpio_by_name("thermal_alert"); |
| 493 | |
| 494 | if (intr == -1 || intr2nd == -1) |
| 495 | return NULL; |
| 496 | |
| 497 | i2c_info->irq = intr + MRST_IRQ_OFFSET; |
| 498 | intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET; |
| 499 | |
| 500 | return &intr2nd_pdata; |
| 501 | } |
| 502 | |
| 503 | static void __init *lis331dl_platform_data(void *info) |
| 504 | { |
| 505 | static short intr2nd_pdata; |
| 506 | struct i2c_board_info *i2c_info = info; |
| 507 | int intr = get_gpio_by_name("accel_int"); |
| 508 | int intr2nd = get_gpio_by_name("accel_2"); |
| 509 | |
| 510 | if (intr == -1 || intr2nd == -1) |
| 511 | return NULL; |
| 512 | |
| 513 | i2c_info->irq = intr + MRST_IRQ_OFFSET; |
| 514 | intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET; |
| 515 | |
| 516 | return &intr2nd_pdata; |
| 517 | } |
| 518 | |
Vinod Koul | 8607153 | 2010-11-10 17:40:48 +0000 | [diff] [blame] | 519 | static void __init *no_platform_data(void *info) |
| 520 | { |
| 521 | return NULL; |
| 522 | } |
| 523 | |
Mika Westerberg | 360545c | 2011-10-18 12:41:22 +0300 | [diff] [blame] | 524 | static struct resource msic_resources[] = { |
| 525 | { |
| 526 | .start = INTEL_MSIC_IRQ_PHYS_BASE, |
| 527 | .end = INTEL_MSIC_IRQ_PHYS_BASE + 64 - 1, |
| 528 | .flags = IORESOURCE_MEM, |
| 529 | }, |
| 530 | }; |
| 531 | |
| 532 | static struct intel_msic_platform_data msic_pdata; |
| 533 | |
| 534 | static struct platform_device msic_device = { |
| 535 | .name = "intel_msic", |
| 536 | .id = -1, |
| 537 | .dev = { |
| 538 | .platform_data = &msic_pdata, |
| 539 | }, |
| 540 | .num_resources = ARRAY_SIZE(msic_resources), |
| 541 | .resource = msic_resources, |
| 542 | }; |
| 543 | |
| 544 | static inline bool mrst_has_msic(void) |
| 545 | { |
| 546 | return mrst_identify_cpu() == MRST_CPU_CHIP_PENWELL; |
| 547 | } |
| 548 | |
| 549 | static int msic_scu_status_change(struct notifier_block *nb, |
| 550 | unsigned long code, void *data) |
| 551 | { |
| 552 | if (code == SCU_DOWN) { |
| 553 | platform_device_unregister(&msic_device); |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | return platform_device_register(&msic_device); |
| 558 | } |
| 559 | |
| 560 | static int __init msic_init(void) |
| 561 | { |
| 562 | static struct notifier_block msic_scu_notifier = { |
| 563 | .notifier_call = msic_scu_status_change, |
| 564 | }; |
| 565 | |
| 566 | /* |
| 567 | * We need to be sure that the SCU IPC is ready before MSIC device |
| 568 | * can be registered. |
| 569 | */ |
| 570 | if (mrst_has_msic()) |
| 571 | intel_scu_notifier_add(&msic_scu_notifier); |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | arch_initcall(msic_init); |
| 576 | |
| 577 | /* |
| 578 | * msic_generic_platform_data - sets generic platform data for the block |
| 579 | * @info: pointer to the SFI device table entry for this block |
| 580 | * @block: MSIC block |
| 581 | * |
| 582 | * Function sets IRQ number from the SFI table entry for given device to |
| 583 | * the MSIC platform data. |
| 584 | */ |
| 585 | static void *msic_generic_platform_data(void *info, enum intel_msic_block block) |
| 586 | { |
| 587 | struct sfi_device_table_entry *entry = info; |
| 588 | |
| 589 | BUG_ON(block < 0 || block >= INTEL_MSIC_BLOCK_LAST); |
| 590 | msic_pdata.irq[block] = entry->irq; |
| 591 | |
| 592 | return no_platform_data(info); |
| 593 | } |
| 594 | |
| 595 | static void *msic_battery_platform_data(void *info) |
| 596 | { |
| 597 | return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_BATTERY); |
| 598 | } |
| 599 | |
| 600 | static void *msic_gpio_platform_data(void *info) |
| 601 | { |
| 602 | static struct intel_msic_gpio_pdata pdata; |
| 603 | int gpio = get_gpio_by_name("msic_gpio_base"); |
| 604 | |
| 605 | if (gpio < 0) |
| 606 | return NULL; |
| 607 | |
| 608 | pdata.gpio_base = gpio; |
| 609 | msic_pdata.gpio = &pdata; |
| 610 | |
| 611 | return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_GPIO); |
| 612 | } |
| 613 | |
| 614 | static void *msic_audio_platform_data(void *info) |
| 615 | { |
| 616 | struct platform_device *pdev; |
| 617 | |
| 618 | pdev = platform_device_register_simple("sst-platform", -1, NULL, 0); |
| 619 | if (IS_ERR(pdev)) { |
| 620 | pr_err("failed to create audio platform device\n"); |
| 621 | return NULL; |
| 622 | } |
| 623 | |
| 624 | return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_AUDIO); |
| 625 | } |
| 626 | |
| 627 | static void *msic_power_btn_platform_data(void *info) |
| 628 | { |
| 629 | return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_POWER_BTN); |
| 630 | } |
| 631 | |
| 632 | static void *msic_ocd_platform_data(void *info) |
| 633 | { |
| 634 | static struct intel_msic_ocd_pdata pdata; |
| 635 | int gpio = get_gpio_by_name("ocd_gpio"); |
| 636 | |
| 637 | if (gpio < 0) |
| 638 | return NULL; |
| 639 | |
| 640 | pdata.gpio = gpio; |
| 641 | msic_pdata.ocd = &pdata; |
| 642 | |
| 643 | return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_OCD); |
| 644 | } |
| 645 | |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 646 | static const struct devs_id __initconst device_ids[] = { |
William Douglas | 9f80d8b | 2011-11-10 13:50:38 +0000 | [diff] [blame] | 647 | {"bma023", SFI_DEV_TYPE_I2C, 1, &no_platform_data}, |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 648 | {"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data}, |
| 649 | {"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data}, |
| 650 | {"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data}, |
| 651 | {"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data}, |
| 652 | {"emc1403", SFI_DEV_TYPE_I2C, 1, &emc1403_platform_data}, |
| 653 | {"i2c_accel", SFI_DEV_TYPE_I2C, 0, &lis331dl_platform_data}, |
Vinod Koul | 8607153 | 2010-11-10 17:40:48 +0000 | [diff] [blame] | 654 | {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data}, |
Mika Westerberg | 360545c | 2011-10-18 12:41:22 +0300 | [diff] [blame] | 655 | |
| 656 | /* MSIC subdevices */ |
| 657 | {"msic_battery", SFI_DEV_TYPE_IPC, 1, &msic_battery_platform_data}, |
| 658 | {"msic_gpio", SFI_DEV_TYPE_IPC, 1, &msic_gpio_platform_data}, |
| 659 | {"msic_audio", SFI_DEV_TYPE_IPC, 1, &msic_audio_platform_data}, |
| 660 | {"msic_power_btn", SFI_DEV_TYPE_IPC, 1, &msic_power_btn_platform_data}, |
| 661 | {"msic_ocd", SFI_DEV_TYPE_IPC, 1, &msic_ocd_platform_data}, |
| 662 | |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 663 | {}, |
| 664 | }; |
| 665 | |
| 666 | #define MAX_IPCDEVS 24 |
| 667 | static struct platform_device *ipc_devs[MAX_IPCDEVS]; |
| 668 | static int ipc_next_dev; |
| 669 | |
| 670 | #define MAX_SCU_SPI 24 |
| 671 | static struct spi_board_info *spi_devs[MAX_SCU_SPI]; |
| 672 | static int spi_next_dev; |
| 673 | |
| 674 | #define MAX_SCU_I2C 24 |
| 675 | static struct i2c_board_info *i2c_devs[MAX_SCU_I2C]; |
| 676 | static int i2c_bus[MAX_SCU_I2C]; |
| 677 | static int i2c_next_dev; |
| 678 | |
| 679 | static void __init intel_scu_device_register(struct platform_device *pdev) |
| 680 | { |
| 681 | if(ipc_next_dev == MAX_IPCDEVS) |
| 682 | pr_err("too many SCU IPC devices"); |
| 683 | else |
| 684 | ipc_devs[ipc_next_dev++] = pdev; |
| 685 | } |
| 686 | |
| 687 | static void __init intel_scu_spi_device_register(struct spi_board_info *sdev) |
| 688 | { |
| 689 | struct spi_board_info *new_dev; |
| 690 | |
| 691 | if (spi_next_dev == MAX_SCU_SPI) { |
| 692 | pr_err("too many SCU SPI devices"); |
| 693 | return; |
| 694 | } |
| 695 | |
| 696 | new_dev = kzalloc(sizeof(*sdev), GFP_KERNEL); |
| 697 | if (!new_dev) { |
| 698 | pr_err("failed to alloc mem for delayed spi dev %s\n", |
| 699 | sdev->modalias); |
| 700 | return; |
| 701 | } |
| 702 | memcpy(new_dev, sdev, sizeof(*sdev)); |
| 703 | |
| 704 | spi_devs[spi_next_dev++] = new_dev; |
| 705 | } |
| 706 | |
| 707 | static void __init intel_scu_i2c_device_register(int bus, |
| 708 | struct i2c_board_info *idev) |
| 709 | { |
| 710 | struct i2c_board_info *new_dev; |
| 711 | |
| 712 | if (i2c_next_dev == MAX_SCU_I2C) { |
| 713 | pr_err("too many SCU I2C devices"); |
| 714 | return; |
| 715 | } |
| 716 | |
| 717 | new_dev = kzalloc(sizeof(*idev), GFP_KERNEL); |
| 718 | if (!new_dev) { |
| 719 | pr_err("failed to alloc mem for delayed i2c dev %s\n", |
| 720 | idev->type); |
| 721 | return; |
| 722 | } |
| 723 | memcpy(new_dev, idev, sizeof(*idev)); |
| 724 | |
| 725 | i2c_bus[i2c_next_dev] = bus; |
| 726 | i2c_devs[i2c_next_dev++] = new_dev; |
| 727 | } |
| 728 | |
Alan Cox | 42c2544 | 2011-09-07 16:06:51 +0300 | [diff] [blame] | 729 | BLOCKING_NOTIFIER_HEAD(intel_scu_notifier); |
| 730 | EXPORT_SYMBOL_GPL(intel_scu_notifier); |
| 731 | |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 732 | /* Called by IPC driver */ |
| 733 | void intel_scu_devices_create(void) |
| 734 | { |
| 735 | int i; |
| 736 | |
| 737 | for (i = 0; i < ipc_next_dev; i++) |
| 738 | platform_device_add(ipc_devs[i]); |
| 739 | |
| 740 | for (i = 0; i < spi_next_dev; i++) |
| 741 | spi_register_board_info(spi_devs[i], 1); |
| 742 | |
| 743 | for (i = 0; i < i2c_next_dev; i++) { |
| 744 | struct i2c_adapter *adapter; |
| 745 | struct i2c_client *client; |
| 746 | |
| 747 | adapter = i2c_get_adapter(i2c_bus[i]); |
| 748 | if (adapter) { |
| 749 | client = i2c_new_device(adapter, i2c_devs[i]); |
| 750 | if (!client) |
| 751 | pr_err("can't create i2c device %s\n", |
| 752 | i2c_devs[i]->type); |
| 753 | } else |
| 754 | i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1); |
| 755 | } |
Alan Cox | 42c2544 | 2011-09-07 16:06:51 +0300 | [diff] [blame] | 756 | intel_scu_notifier_post(SCU_AVAILABLE, 0L); |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 757 | } |
| 758 | EXPORT_SYMBOL_GPL(intel_scu_devices_create); |
| 759 | |
| 760 | /* Called by IPC driver */ |
| 761 | void intel_scu_devices_destroy(void) |
| 762 | { |
| 763 | int i; |
| 764 | |
Alan Cox | 42c2544 | 2011-09-07 16:06:51 +0300 | [diff] [blame] | 765 | intel_scu_notifier_post(SCU_DOWN, 0L); |
| 766 | |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 767 | for (i = 0; i < ipc_next_dev; i++) |
| 768 | platform_device_del(ipc_devs[i]); |
| 769 | } |
| 770 | EXPORT_SYMBOL_GPL(intel_scu_devices_destroy); |
| 771 | |
| 772 | static void __init install_irq_resource(struct platform_device *pdev, int irq) |
| 773 | { |
| 774 | /* Single threaded */ |
| 775 | static struct resource __initdata res = { |
| 776 | .name = "IRQ", |
| 777 | .flags = IORESOURCE_IRQ, |
| 778 | }; |
| 779 | res.start = irq; |
| 780 | platform_device_add_resources(pdev, &res, 1); |
| 781 | } |
| 782 | |
Mika Westerberg | 360545c | 2011-10-18 12:41:22 +0300 | [diff] [blame] | 783 | static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *entry) |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 784 | { |
| 785 | const struct devs_id *dev = device_ids; |
Mika Westerberg | 360545c | 2011-10-18 12:41:22 +0300 | [diff] [blame] | 786 | struct platform_device *pdev; |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 787 | void *pdata = NULL; |
| 788 | |
| 789 | while (dev->name[0]) { |
| 790 | if (dev->type == SFI_DEV_TYPE_IPC && |
Mika Westerberg | 360545c | 2011-10-18 12:41:22 +0300 | [diff] [blame] | 791 | !strncmp(dev->name, entry->name, SFI_NAME_LEN)) { |
| 792 | pdata = dev->get_platform_data(entry); |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 793 | break; |
| 794 | } |
| 795 | dev++; |
| 796 | } |
Mika Westerberg | 360545c | 2011-10-18 12:41:22 +0300 | [diff] [blame] | 797 | |
| 798 | /* |
| 799 | * On Medfield the platform device creation is handled by the MSIC |
| 800 | * MFD driver so we don't need to do it here. |
| 801 | */ |
| 802 | if (mrst_has_msic()) |
| 803 | return; |
| 804 | |
Alan Cox | 54b0264 | 2011-11-16 18:17:40 +0000 | [diff] [blame^] | 805 | pdev = platform_device_alloc(entry->name, 0); |
Mika Westerberg | 360545c | 2011-10-18 12:41:22 +0300 | [diff] [blame] | 806 | if (pdev == NULL) { |
| 807 | pr_err("out of memory for SFI platform device '%s'.\n", |
| 808 | entry->name); |
| 809 | return; |
| 810 | } |
| 811 | install_irq_resource(pdev, entry->irq); |
| 812 | |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 813 | pdev->dev.platform_data = pdata; |
| 814 | intel_scu_device_register(pdev); |
| 815 | } |
| 816 | |
| 817 | static void __init sfi_handle_spi_dev(struct spi_board_info *spi_info) |
| 818 | { |
| 819 | const struct devs_id *dev = device_ids; |
| 820 | void *pdata = NULL; |
| 821 | |
| 822 | while (dev->name[0]) { |
| 823 | if (dev->type == SFI_DEV_TYPE_SPI && |
| 824 | !strncmp(dev->name, spi_info->modalias, SFI_NAME_LEN)) { |
| 825 | pdata = dev->get_platform_data(spi_info); |
| 826 | break; |
| 827 | } |
| 828 | dev++; |
| 829 | } |
| 830 | spi_info->platform_data = pdata; |
| 831 | if (dev->delay) |
| 832 | intel_scu_spi_device_register(spi_info); |
| 833 | else |
| 834 | spi_register_board_info(spi_info, 1); |
| 835 | } |
| 836 | |
| 837 | static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info) |
| 838 | { |
| 839 | const struct devs_id *dev = device_ids; |
| 840 | void *pdata = NULL; |
| 841 | |
| 842 | while (dev->name[0]) { |
| 843 | if (dev->type == SFI_DEV_TYPE_I2C && |
| 844 | !strncmp(dev->name, i2c_info->type, SFI_NAME_LEN)) { |
| 845 | pdata = dev->get_platform_data(i2c_info); |
| 846 | break; |
| 847 | } |
| 848 | dev++; |
| 849 | } |
| 850 | i2c_info->platform_data = pdata; |
| 851 | |
| 852 | if (dev->delay) |
| 853 | intel_scu_i2c_device_register(bus, i2c_info); |
| 854 | else |
| 855 | i2c_register_board_info(bus, i2c_info, 1); |
| 856 | } |
| 857 | |
| 858 | |
| 859 | static int __init sfi_parse_devs(struct sfi_table_header *table) |
| 860 | { |
| 861 | struct sfi_table_simple *sb; |
| 862 | struct sfi_device_table_entry *pentry; |
| 863 | struct spi_board_info spi_info; |
| 864 | struct i2c_board_info i2c_info; |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 865 | int num, i, bus; |
| 866 | int ioapic; |
| 867 | struct io_apic_irq_attr irq_attr; |
| 868 | |
| 869 | sb = (struct sfi_table_simple *)table; |
| 870 | num = SFI_GET_NUM_ENTRIES(sb, struct sfi_device_table_entry); |
| 871 | pentry = (struct sfi_device_table_entry *)sb->pentry; |
| 872 | |
| 873 | for (i = 0; i < num; i++, pentry++) { |
Mika Westerberg | 153b19a | 2011-10-13 12:04:20 +0300 | [diff] [blame] | 874 | int irq = pentry->irq; |
| 875 | |
| 876 | if (irq != (u8)0xff) { /* native RTE case */ |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 877 | /* these SPI2 devices are not exposed to system as PCI |
| 878 | * devices, but they have separate RTE entry in IOAPIC |
| 879 | * so we have to enable them one by one here |
| 880 | */ |
Mika Westerberg | 153b19a | 2011-10-13 12:04:20 +0300 | [diff] [blame] | 881 | ioapic = mp_find_ioapic(irq); |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 882 | irq_attr.ioapic = ioapic; |
Mika Westerberg | 153b19a | 2011-10-13 12:04:20 +0300 | [diff] [blame] | 883 | irq_attr.ioapic_pin = irq; |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 884 | irq_attr.trigger = 1; |
| 885 | irq_attr.polarity = 1; |
Mika Westerberg | 153b19a | 2011-10-13 12:04:20 +0300 | [diff] [blame] | 886 | io_apic_set_pci_routing(NULL, irq, &irq_attr); |
Kirill A. Shutemov | a94cc4e | 2011-08-26 12:20:59 +0100 | [diff] [blame] | 887 | } else |
Mika Westerberg | 153b19a | 2011-10-13 12:04:20 +0300 | [diff] [blame] | 888 | irq = 0; /* No irq */ |
Kirill A. Shutemov | a94cc4e | 2011-08-26 12:20:59 +0100 | [diff] [blame] | 889 | |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 890 | switch (pentry->type) { |
| 891 | case SFI_DEV_TYPE_IPC: |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 892 | pr_debug("info[%2d]: IPC bus, name = %16.16s, " |
Mika Westerberg | 360545c | 2011-10-18 12:41:22 +0300 | [diff] [blame] | 893 | "irq = 0x%2x\n", i, pentry->name, pentry->irq); |
| 894 | sfi_handle_ipc_dev(pentry); |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 895 | break; |
| 896 | case SFI_DEV_TYPE_SPI: |
| 897 | memset(&spi_info, 0, sizeof(spi_info)); |
| 898 | strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN); |
Mika Westerberg | 153b19a | 2011-10-13 12:04:20 +0300 | [diff] [blame] | 899 | spi_info.irq = irq; |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 900 | spi_info.bus_num = pentry->host_num; |
| 901 | spi_info.chip_select = pentry->addr; |
| 902 | spi_info.max_speed_hz = pentry->max_freq; |
| 903 | pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, " |
| 904 | "irq = 0x%2x, max_freq = %d, cs = %d\n", i, |
| 905 | spi_info.bus_num, |
| 906 | spi_info.modalias, |
| 907 | spi_info.irq, |
| 908 | spi_info.max_speed_hz, |
| 909 | spi_info.chip_select); |
| 910 | sfi_handle_spi_dev(&spi_info); |
| 911 | break; |
| 912 | case SFI_DEV_TYPE_I2C: |
| 913 | memset(&i2c_info, 0, sizeof(i2c_info)); |
| 914 | bus = pentry->host_num; |
| 915 | strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN); |
Mika Westerberg | 153b19a | 2011-10-13 12:04:20 +0300 | [diff] [blame] | 916 | i2c_info.irq = irq; |
Feng Tang | 1da4b1c | 2010-11-09 11:22:58 +0000 | [diff] [blame] | 917 | i2c_info.addr = pentry->addr; |
| 918 | pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, " |
| 919 | "irq = 0x%2x, addr = 0x%x\n", i, bus, |
| 920 | i2c_info.type, |
| 921 | i2c_info.irq, |
| 922 | i2c_info.addr); |
| 923 | sfi_handle_i2c_dev(bus, &i2c_info); |
| 924 | break; |
| 925 | case SFI_DEV_TYPE_UART: |
| 926 | case SFI_DEV_TYPE_HSI: |
| 927 | default: |
| 928 | ; |
| 929 | } |
| 930 | } |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | static int __init mrst_platform_init(void) |
| 935 | { |
| 936 | sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio); |
| 937 | sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs); |
| 938 | return 0; |
| 939 | } |
| 940 | arch_initcall(mrst_platform_init); |
| 941 | |
| 942 | /* |
| 943 | * we will search these buttons in SFI GPIO table (by name) |
| 944 | * and register them dynamically. Please add all possible |
| 945 | * buttons here, we will shrink them if no GPIO found. |
| 946 | */ |
| 947 | static struct gpio_keys_button gpio_button[] = { |
| 948 | {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000}, |
| 949 | {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20}, |
| 950 | {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20}, |
| 951 | {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20}, |
| 952 | {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20}, |
| 953 | {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20}, |
| 954 | {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20}, |
| 955 | {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20}, |
| 956 | {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20}, |
| 957 | {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20}, |
| 958 | }; |
| 959 | |
| 960 | static struct gpio_keys_platform_data mrst_gpio_keys = { |
| 961 | .buttons = gpio_button, |
| 962 | .rep = 1, |
| 963 | .nbuttons = -1, /* will fill it after search */ |
| 964 | }; |
| 965 | |
| 966 | static struct platform_device pb_device = { |
| 967 | .name = "gpio-keys", |
| 968 | .id = -1, |
| 969 | .dev = { |
| 970 | .platform_data = &mrst_gpio_keys, |
| 971 | }, |
| 972 | }; |
| 973 | |
| 974 | /* |
| 975 | * Shrink the non-existent buttons, register the gpio button |
| 976 | * device if there is some |
| 977 | */ |
| 978 | static int __init pb_keys_init(void) |
| 979 | { |
| 980 | struct gpio_keys_button *gb = gpio_button; |
| 981 | int i, num, good = 0; |
| 982 | |
| 983 | num = sizeof(gpio_button) / sizeof(struct gpio_keys_button); |
| 984 | for (i = 0; i < num; i++) { |
| 985 | gb[i].gpio = get_gpio_by_name(gb[i].desc); |
| 986 | if (gb[i].gpio == -1) |
| 987 | continue; |
| 988 | |
| 989 | if (i != good) |
| 990 | gb[good] = gb[i]; |
| 991 | good++; |
| 992 | } |
| 993 | |
| 994 | if (good) { |
| 995 | mrst_gpio_keys.nbuttons = good; |
| 996 | return platform_device_register(&pb_device); |
| 997 | } |
| 998 | return 0; |
| 999 | } |
| 1000 | late_initcall(pb_keys_init); |