intel-mid.c 6.2 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 19
#include <linux/interrupt.h>
#include <linux/scatterlist.h>
20 21
#include <linux/sfi.h>
#include <linux/irq.h>
22
#include <linux/module.h>
23
#include <linux/notifier.h>
24 25

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

38 39
#include "intel_mid_weak_decls.h"

40 41
/*
 * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
42
 * cmdline option x86_intel_mid_timer can be used to override the configuration
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
 * 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
 */

61
enum intel_mid_timer_options intel_mid_timer_options;
62

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

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

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

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

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

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

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

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

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

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

	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]();
141
		pr_info("ARCH: Unknown SoC, assuming PENWELL!\n");
142 143 144 145 146
	}

out:
	if (intel_mid_ops->arch_setup)
		intel_mid_ops->arch_setup();
J
Jacob Pan 已提交
147
}
J
Jacob Pan 已提交
148

149
/* MID systems don't have i8042 controller */
150
static int intel_mid_i8042_detect(void)
151 152 153 154
{
	return 0;
}

155 156 157 158 159 160
/*
 * 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.
 */
161
static unsigned char intel_mid_get_nmi_reason(void)
162 163 164 165
{
	return 0;
}

166 167 168 169
/*
 * Moorestown specific x86_init function overrides and early setup
 * calls.
 */
170
void __init x86_intel_mid_early_setup(void)
171 172 173
{
	x86_init.resources.probe_roms = x86_init_noop;
	x86_init.resources.reserve_resources = x86_init_noop;
174

175
	x86_init.timers.timer_init = intel_mid_time_init;
176
	x86_init.timers.setup_percpu_clockev = x86_init_noop;
J
Jacob Pan 已提交
177 178 179

	x86_init.irqs.pre_vector_init = x86_init_noop;

180
	x86_init.oem.arch_setup = intel_mid_arch_setup;
J
Jacob Pan 已提交
181

182
	x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
J
Jacob Pan 已提交
183

184 185 186 187
	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;
188

189
	x86_init.pci.init = intel_mid_pci_init;
190 191
	x86_init.pci.fixup_irqs = x86_init_noop;

192
	legacy_pic = &null_legacy_pic;
193

194 195
	pm_power_off = intel_mid_power_off;
	machine_ops.emergency_restart  = intel_mid_reboot;
196

197 198 199
	/* 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;
200
	set_bit(MP_BUS_ISA, mp_bus_not_pci);
201
}
202 203 204 205 206

/*
 * 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.
 */
207
static inline int __init setup_x86_intel_mid_timer(char *arg)
208 209 210 211 212
{
	if (!arg)
		return -EINVAL;

	if (strcmp("apbt_only", arg) == 0)
213
		intel_mid_timer_options = INTEL_MID_TIMER_APBT_ONLY;
214
	else if (strcmp("lapic_and_apbt", arg) == 0)
215
		intel_mid_timer_options = INTEL_MID_TIMER_LAPIC_APBT;
216
	else {
217 218
		pr_warn("X86 INTEL_MID timer option %s not recognised"
			   " use x86_intel_mid_timer=apbt_only or lapic_and_apbt\n",
219 220 221 222 223
			   arg);
		return -EINVAL;
	}
	return 0;
}
224
__setup("x86_intel_mid_timer=", setup_x86_intel_mid_timer);
225