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