blob: ce119d2ba0d00edbe9b065b8773314a5d9814874 [file] [log] [blame]
Thomas Gleixner3f4110a2009-08-29 14:54:20 +02001/*
Kuppuswamy Sathyanarayanan05454c22013-10-17 15:35:27 -07002 * intel-mid.c: Intel MID platform setup code
Thomas Gleixner3f4110a2009-08-29 14:54:20 +02003 *
Kuppuswamy Sathyanarayanan05454c22013-10-17 15:35:27 -07004 * (C) Copyright 2008, 2012 Intel Corporation
Thomas Gleixner3f4110a2009-08-29 14:54:20 +02005 * Author: Jacob Pan (jacob.jun.pan@intel.com)
Kuppuswamy Sathyanarayanan05454c22013-10-17 15:35:27 -07006 * Author: Sathyanarayanan Kuppuswamy <sathyanarayanan.kuppuswamy@intel.com>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +02007 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; version 2
11 * of the License.
12 */
Feng Tang1da4b1c2010-11-09 11:22:58 +000013
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -070014#define pr_fmt(fmt) "intel_mid: " fmt
Feng Tang1da4b1c2010-11-09 11:22:58 +000015
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020016#include <linux/init.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080017#include <linux/kernel.h>
Feng Tangefe3ed92011-08-26 11:25:14 +010018#include <linux/interrupt.h>
Andy Shevchenkoa11836f2016-07-09 16:45:29 +030019#include <linux/regulator/machine.h>
Feng Tangefe3ed92011-08-26 11:25:14 +010020#include <linux/scatterlist.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080021#include <linux/sfi.h>
22#include <linux/irq.h>
Paul Gortmakercc3ae7b2016-07-13 20:18:58 -040023#include <linux/export.h>
Alan Cox42c25442011-09-07 16:06:51 +030024#include <linux/notifier.h>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020025
26#include <asm/setup.h>
Jacob Pan16ab5392010-02-12 03:08:30 -080027#include <asm/mpspec_def.h>
28#include <asm/hw_irq.h>
29#include <asm/apic.h>
30#include <asm/io_apic.h>
Kuppuswamy Sathyanarayanan05454c22013-10-17 15:35:27 -070031#include <asm/intel-mid.h>
32#include <asm/intel_mid_vrtc.h>
Jacob Pan5b78b672010-02-12 02:29:11 -080033#include <asm/io.h>
34#include <asm/i8259.h>
Feng Tang1da4b1c2010-11-09 11:22:58 +000035#include <asm/intel_scu_ipc.h>
Jacob Pan3746c6b2010-02-12 05:01:12 -080036#include <asm/apb_timer.h>
Alek Ducfb505a2010-11-10 16:50:08 +000037#include <asm/reboot.h>
Thomas Gleixner3f4110a2009-08-29 14:54:20 +020038
David Cohenecd69102013-12-16 12:07:36 -080039#include "intel_mid_weak_decls.h"
40
Jacob Pana875c012010-05-19 12:01:25 -070041/*
42 * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -070043 * cmdline option x86_intel_mid_timer can be used to override the configuration
Jacob Pana875c012010-05-19 12:01:25 -070044 * to prefer one or the other.
45 * at runtime, there are basically three timer configurations:
46 * 1. per cpu apbt clock only
47 * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
48 * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
49 *
50 * by default (without cmdline option), platform code first detects cpu type
51 * to see if we are on lincroft or penwell, then set up both lapic or apbt
52 * clocks accordingly.
53 * i.e. by default, medfield uses configuration #2, moorestown uses #1.
54 * config #3 is supported but not recommended on medfield.
55 *
56 * rating and feature summary:
57 * lapic (with C3STOP) --------- 100
58 * apbt (always-on) ------------ 110
59 * lapic (always-on,ARAT) ------ 150
60 */
61
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -070062enum intel_mid_timer_options intel_mid_timer_options;
Jacob Pana875c012010-05-19 12:01:25 -070063
Kuppuswamy Sathyanarayanan85611e32013-12-16 12:07:37 -080064/* intel_mid_ops to store sub arch ops */
Andy Shevchenkod1f0f6c2015-10-09 17:25:41 +030065static struct intel_mid_ops *intel_mid_ops;
Kuppuswamy Sathyanarayanan85611e32013-12-16 12:07:37 -080066/* getter function for sub arch ops*/
67static void *(*get_intel_mid_ops[])(void) = INTEL_MID_OPS_INIT;
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -070068enum intel_mid_cpu_type __intel_mid_cpu_chip;
69EXPORT_SYMBOL_GPL(__intel_mid_cpu_chip);
Jacob Pana0c173b2010-05-19 12:01:24 -070070
Kuppuswamy Sathyanarayanan85611e32013-12-16 12:07:37 -080071static void intel_mid_power_off(void)
72{
73};
74
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -070075static void intel_mid_reboot(void)
Jacob Pan48bc5562011-11-16 16:07:22 +000076{
Alan Cox1a8359e2012-01-26 17:33:30 +000077 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
Jacob Pan48bc5562011-11-16 16:07:22 +000078}
79
Kuppuswamy Sathyanarayanan85611e32013-12-16 12:07:37 -080080static unsigned long __init intel_mid_calibrate_tsc(void)
81{
82 return 0;
83}
84
Thomas Gleixner6648d1b2015-04-13 14:11:51 +080085static void __init intel_mid_setup_bp_timer(void)
86{
87 apbt_time_init();
88 setup_boot_APIC_clock();
89}
90
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -070091static void __init intel_mid_time_init(void)
Jacob Pan3746c6b2010-02-12 05:01:12 -080092{
Jacob Pan7f05dec2010-11-09 11:28:43 +000093 sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
Thomas Gleixner6648d1b2015-04-13 14:11:51 +080094
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -070095 switch (intel_mid_timer_options) {
96 case INTEL_MID_TIMER_APBT_ONLY:
Jacob Pana875c012010-05-19 12:01:25 -070097 break;
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -070098 case INTEL_MID_TIMER_LAPIC_APBT:
Thomas Gleixner6648d1b2015-04-13 14:11:51 +080099 /* Use apbt and local apic */
100 x86_init.timers.setup_percpu_clockev = intel_mid_setup_bp_timer;
Jacob Pana875c012010-05-19 12:01:25 -0700101 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
Thomas Gleixner6648d1b2015-04-13 14:11:51 +0800102 return;
Jacob Pana875c012010-05-19 12:01:25 -0700103 default:
104 if (!boot_cpu_has(X86_FEATURE_ARAT))
105 break;
Thomas Gleixner6648d1b2015-04-13 14:11:51 +0800106 /* Lapic only, no apbt */
Jacob Pana875c012010-05-19 12:01:25 -0700107 x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
108 x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
109 return;
110 }
Thomas Gleixner6648d1b2015-04-13 14:11:51 +0800111
112 x86_init.timers.setup_percpu_clockev = apbt_time_init;
Jacob Pan3746c6b2010-02-12 05:01:12 -0800113}
114
Paul Gortmakeraeeca402013-11-07 13:34:50 -0500115static void intel_mid_arch_setup(void)
Jacob Pan3746c6b2010-02-12 05:01:12 -0800116{
Kuppuswamy Sathyanarayanan85611e32013-12-16 12:07:37 -0800117 if (boot_cpu_data.x86 != 6) {
Alan Cox1a8359e2012-01-26 17:33:30 +0000118 pr_err("Unknown Intel MID CPU (%d:%d), default to Penwell\n",
Jacob Pana0c173b2010-05-19 12:01:24 -0700119 boot_cpu_data.x86, boot_cpu_data.x86_model);
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700120 __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
Kuppuswamy Sathyanarayanan85611e32013-12-16 12:07:37 -0800121 goto out;
Jacob Pana0c173b2010-05-19 12:01:24 -0700122 }
Kuppuswamy Sathyanarayanan85611e32013-12-16 12:07:37 -0800123
124 switch (boot_cpu_data.x86_model) {
125 case 0x35:
126 __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_CLOVERVIEW;
127 break;
David Cohenbc20aa482013-12-16 12:07:38 -0800128 case 0x3C:
129 case 0x4A:
130 __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_TANGIER;
131 break;
Kuppuswamy Sathyanarayanan85611e32013-12-16 12:07:37 -0800132 case 0x27:
133 default:
134 __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
135 break;
136 }
137
138 if (__intel_mid_cpu_chip < MAX_CPU_OPS(get_intel_mid_ops))
139 intel_mid_ops = get_intel_mid_ops[__intel_mid_cpu_chip]();
140 else {
141 intel_mid_ops = get_intel_mid_ops[INTEL_MID_CPU_CHIP_PENWELL]();
Andy Shevchenkob000de52016-01-15 22:11:08 +0200142 pr_info("ARCH: Unknown SoC, assuming Penwell!\n");
Kuppuswamy Sathyanarayanan85611e32013-12-16 12:07:37 -0800143 }
144
145out:
146 if (intel_mid_ops->arch_setup)
147 intel_mid_ops->arch_setup();
Andy Shevchenkoa11836f2016-07-09 16:45:29 +0300148
149 /*
150 * Intel MID platforms are using explicitly defined regulators.
151 *
152 * Let the regulator core know that we do not have any additional
153 * regulators left. This lets it substitute unprovided regulators with
154 * dummy ones:
155 */
156 regulator_has_full_constraints();
Jacob Pana0c173b2010-05-19 12:01:24 -0700157}
Jacob Pan3746c6b2010-02-12 05:01:12 -0800158
Feng Tang6d2cce62010-07-05 23:03:19 +0800159/* MID systems don't have i8042 controller */
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700160static int intel_mid_i8042_detect(void)
Feng Tang6d2cce62010-07-05 23:03:19 +0800161{
162 return 0;
163}
164
Jacob Pan3746c6b2010-02-12 05:01:12 -0800165/*
Jacob Pan064a59b2011-11-10 13:43:05 +0000166 * Moorestown does not have external NMI source nor port 0x61 to report
167 * NMI status. The possible NMI sources are from pmu as a result of NMI
168 * watchdog or lock debug. Reading io port 0x61 results in 0xff which
169 * misled NMI handler.
170 */
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700171static unsigned char intel_mid_get_nmi_reason(void)
Jacob Pan064a59b2011-11-10 13:43:05 +0000172{
173 return 0;
174}
175
176/*
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200177 * Moorestown specific x86_init function overrides and early setup
178 * calls.
179 */
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700180void __init x86_intel_mid_early_setup(void)
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200181{
182 x86_init.resources.probe_roms = x86_init_noop;
183 x86_init.resources.reserve_resources = x86_init_noop;
Jacob Pan5b78b672010-02-12 02:29:11 -0800184
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700185 x86_init.timers.timer_init = intel_mid_time_init;
Jacob Pana875c012010-05-19 12:01:25 -0700186 x86_init.timers.setup_percpu_clockev = x86_init_noop;
Jacob Pan3746c6b2010-02-12 05:01:12 -0800187
188 x86_init.irqs.pre_vector_init = x86_init_noop;
189
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700190 x86_init.oem.arch_setup = intel_mid_arch_setup;
Jacob Pana0c173b2010-05-19 12:01:24 -0700191
Jacob Pana875c012010-05-19 12:01:25 -0700192 x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
Jacob Pan3746c6b2010-02-12 05:01:12 -0800193
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700194 x86_platform.calibrate_tsc = intel_mid_calibrate_tsc;
195 x86_platform.i8042_detect = intel_mid_i8042_detect;
196 x86_init.timers.wallclock_init = intel_mid_rtc_init;
197 x86_platform.get_nmi_reason = intel_mid_get_nmi_reason;
Jacob Pan064a59b2011-11-10 13:43:05 +0000198
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700199 x86_init.pci.init = intel_mid_pci_init;
Jacob Panaf2730f2010-02-12 10:31:47 -0800200 x86_init.pci.fixup_irqs = x86_init_noop;
201
Jacob Pan5b78b672010-02-12 02:29:11 -0800202 legacy_pic = &null_legacy_pic;
Jacob Panfea24e22010-05-14 14:41:20 -0700203
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700204 pm_power_off = intel_mid_power_off;
205 machine_ops.emergency_restart = intel_mid_reboot;
Alek Ducfb505a2010-11-10 16:50:08 +0000206
Jacob Panfea24e22010-05-14 14:41:20 -0700207 /* Avoid searching for BIOS MP tables */
208 x86_init.mpparse.find_smp_config = x86_init_noop;
209 x86_init.mpparse.get_smp_config = x86_init_uint_noop;
Jacob Pan9d90e492011-04-08 11:23:00 -0700210 set_bit(MP_BUS_ISA, mp_bus_not_pci);
Thomas Gleixner3f4110a2009-08-29 14:54:20 +0200211}
Jacob Pana875c012010-05-19 12:01:25 -0700212
213/*
214 * if user does not want to use per CPU apb timer, just give it a lower rating
215 * than local apic timer and skip the late per cpu timer init.
216 */
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700217static inline int __init setup_x86_intel_mid_timer(char *arg)
Jacob Pana875c012010-05-19 12:01:25 -0700218{
219 if (!arg)
220 return -EINVAL;
221
222 if (strcmp("apbt_only", arg) == 0)
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700223 intel_mid_timer_options = INTEL_MID_TIMER_APBT_ONLY;
Jacob Pana875c012010-05-19 12:01:25 -0700224 else if (strcmp("lapic_and_apbt", arg) == 0)
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700225 intel_mid_timer_options = INTEL_MID_TIMER_LAPIC_APBT;
Jacob Pana875c012010-05-19 12:01:25 -0700226 else {
Andy Shevchenkob000de52016-01-15 22:11:08 +0200227 pr_warn("X86 INTEL_MID timer option %s not recognised use x86_intel_mid_timer=apbt_only or lapic_and_apbt\n",
228 arg);
Jacob Pana875c012010-05-19 12:01:25 -0700229 return -EINVAL;
230 }
231 return 0;
232}
Kuppuswamy Sathyanarayanan712b6aa2013-10-17 15:35:29 -0700233__setup("x86_intel_mid_timer=", setup_x86_intel_mid_timer);