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