intel-mid.c 6.4 KB
Newer Older
1
/*
2
 * intel-mid.c: Intel MID platform setup code
3
 *
4
 * (C) Copyright 2008, 2012 Intel Corporation
5
 * Author: Jacob Pan (jacob.jun.pan@intel.com)
6
 * Author: Sathyanarayanan Kuppuswamy <sathyanarayanan.kuppuswamy@intel.com>
7 8 9 10 11 12
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; version 2
 * of the License.
 */
13

14
#define pr_fmt(fmt) "intel_mid: " fmt
15

16
#include <linux/init.h>
17
#include <linux/kernel.h>
18
#include <linux/interrupt.h>
19
#include <linux/regulator/machine.h>
20
#include <linux/scatterlist.h>
21 22
#include <linux/sfi.h>
#include <linux/irq.h>
23
#include <linux/module.h>
24
#include <linux/notifier.h>
25 26

#include <asm/setup.h>
27 28 29 30
#include <asm/mpspec_def.h>
#include <asm/hw_irq.h>
#include <asm/apic.h>
#include <asm/io_apic.h>
31 32
#include <asm/intel-mid.h>
#include <asm/intel_mid_vrtc.h>
33 34
#include <asm/io.h>
#include <asm/i8259.h>
35
#include <asm/intel_scu_ipc.h>
J
Jacob Pan 已提交
36
#include <asm/apb_timer.h>
37
#include <asm/reboot.h>
38

39 40
#include "intel_mid_weak_decls.h"

41 42
/*
 * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
43
 * cmdline option x86_intel_mid_timer can be used to override the configuration
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
 * to prefer one or the other.
 * at runtime, there are basically three timer configurations:
 * 1. per cpu apbt clock only
 * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
 * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
 *
 * by default (without cmdline option), platform code first detects cpu type
 * to see if we are on lincroft or penwell, then set up both lapic or apbt
 * clocks accordingly.
 * i.e. by default, medfield uses configuration #2, moorestown uses #1.
 * config #3 is supported but not recommended on medfield.
 *
 * rating and feature summary:
 * lapic (with C3STOP) --------- 100
 * apbt (always-on) ------------ 110
 * lapic (always-on,ARAT) ------ 150
 */

62
enum intel_mid_timer_options intel_mid_timer_options;
63

64
/* intel_mid_ops to store sub arch ops */
65
static struct intel_mid_ops *intel_mid_ops;
66 67
/* getter function for sub arch ops*/
static void *(*get_intel_mid_ops[])(void) = INTEL_MID_OPS_INIT;
68 69
enum intel_mid_cpu_type __intel_mid_cpu_chip;
EXPORT_SYMBOL_GPL(__intel_mid_cpu_chip);
J
Jacob Pan 已提交
70

71 72 73 74
static void intel_mid_power_off(void)
{
};

75
static void intel_mid_reboot(void)
76
{
A
Alan Cox 已提交
77
	intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
78 79
}

80 81 82 83 84
static unsigned long __init intel_mid_calibrate_tsc(void)
{
	return 0;
}

85 86 87 88 89 90
static void __init intel_mid_setup_bp_timer(void)
{
	apbt_time_init();
	setup_boot_APIC_clock();
}

91
static void __init intel_mid_time_init(void)
J
Jacob Pan 已提交
92
{
93
	sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
94

95 96
	switch (intel_mid_timer_options) {
	case INTEL_MID_TIMER_APBT_ONLY:
97
		break;
98
	case INTEL_MID_TIMER_LAPIC_APBT:
99 100
		/* Use apbt and local apic */
		x86_init.timers.setup_percpu_clockev = intel_mid_setup_bp_timer;
101
		x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
102
		return;
103 104 105
	default:
		if (!boot_cpu_has(X86_FEATURE_ARAT))
			break;
106
		/* Lapic only, no apbt */
107 108 109 110
		x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
		x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
		return;
	}
111 112

	x86_init.timers.setup_percpu_clockev = apbt_time_init;
J
Jacob Pan 已提交
113 114
}

115
static void intel_mid_arch_setup(void)
J
Jacob Pan 已提交
116
{
117
	if (boot_cpu_data.x86 != 6) {
A
Alan Cox 已提交
118
		pr_err("Unknown Intel MID CPU (%d:%d), default to Penwell\n",
J
Jacob Pan 已提交
119
			boot_cpu_data.x86, boot_cpu_data.x86_model);
120
		__intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
121 122 123 124 125 126 127
		goto out;
	}

	switch (boot_cpu_data.x86_model) {
	case 0x35:
		__intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_CLOVERVIEW;
		break;
128 129 130 131
	case 0x3C:
	case 0x4A:
		__intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_TANGIER;
		break;
132 133 134 135
	case 0x27:
	default:
		__intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
		break;
J
Jacob Pan 已提交
136
	}
137 138 139 140 141

	if (__intel_mid_cpu_chip < MAX_CPU_OPS(get_intel_mid_ops))
		intel_mid_ops = get_intel_mid_ops[__intel_mid_cpu_chip]();
	else {
		intel_mid_ops = get_intel_mid_ops[INTEL_MID_CPU_CHIP_PENWELL]();
142
		pr_info("ARCH: Unknown SoC, assuming Penwell!\n");
143 144 145 146 147
	}

out:
	if (intel_mid_ops->arch_setup)
		intel_mid_ops->arch_setup();
148 149 150 151 152 153 154 155 156

	/*
	 * Intel MID platforms are using explicitly defined regulators.
	 *
	 * Let the regulator core know that we do not have any additional
	 * regulators left. This lets it substitute unprovided regulators with
	 * dummy ones:
	 */
	regulator_has_full_constraints();
J
Jacob Pan 已提交
157
}
J
Jacob Pan 已提交
158

159
/* MID systems don't have i8042 controller */
160
static int intel_mid_i8042_detect(void)
161 162 163 164
{
	return 0;
}

165 166 167 168 169 170
/*
 * Moorestown does not have external NMI source nor port 0x61 to report
 * NMI status. The possible NMI sources are from pmu as a result of NMI
 * watchdog or lock debug. Reading io port 0x61 results in 0xff which
 * misled NMI handler.
 */
171
static unsigned char intel_mid_get_nmi_reason(void)
172 173 174 175
{
	return 0;
}

176 177 178 179
/*
 * Moorestown specific x86_init function overrides and early setup
 * calls.
 */
180
void __init x86_intel_mid_early_setup(void)
181 182 183
{
	x86_init.resources.probe_roms = x86_init_noop;
	x86_init.resources.reserve_resources = x86_init_noop;
184

185
	x86_init.timers.timer_init = intel_mid_time_init;
186
	x86_init.timers.setup_percpu_clockev = x86_init_noop;
J
Jacob Pan 已提交
187 188 189

	x86_init.irqs.pre_vector_init = x86_init_noop;

190
	x86_init.oem.arch_setup = intel_mid_arch_setup;
J
Jacob Pan 已提交
191

192
	x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
J
Jacob Pan 已提交
193

194 195 196 197
	x86_platform.calibrate_tsc = intel_mid_calibrate_tsc;
	x86_platform.i8042_detect = intel_mid_i8042_detect;
	x86_init.timers.wallclock_init = intel_mid_rtc_init;
	x86_platform.get_nmi_reason = intel_mid_get_nmi_reason;
198

199
	x86_init.pci.init = intel_mid_pci_init;
200 201
	x86_init.pci.fixup_irqs = x86_init_noop;

202
	legacy_pic = &null_legacy_pic;
203

204 205
	pm_power_off = intel_mid_power_off;
	machine_ops.emergency_restart  = intel_mid_reboot;
206

207 208 209
	/* Avoid searching for BIOS MP tables */
	x86_init.mpparse.find_smp_config = x86_init_noop;
	x86_init.mpparse.get_smp_config = x86_init_uint_noop;
210
	set_bit(MP_BUS_ISA, mp_bus_not_pci);
211
}
212 213 214 215 216

/*
 * if user does not want to use per CPU apb timer, just give it a lower rating
 * than local apic timer and skip the late per cpu timer init.
 */
217
static inline int __init setup_x86_intel_mid_timer(char *arg)
218 219 220 221 222
{
	if (!arg)
		return -EINVAL;

	if (strcmp("apbt_only", arg) == 0)
223
		intel_mid_timer_options = INTEL_MID_TIMER_APBT_ONLY;
224
	else if (strcmp("lapic_and_apbt", arg) == 0)
225
		intel_mid_timer_options = INTEL_MID_TIMER_LAPIC_APBT;
226
	else {
227 228
		pr_warn("X86 INTEL_MID timer option %s not recognised use x86_intel_mid_timer=apbt_only or lapic_and_apbt\n",
			arg);
229 230 231 232
		return -EINVAL;
	}
	return 0;
}
233
__setup("x86_intel_mid_timer=", setup_x86_intel_mid_timer);