xref: /linux/arch/x86/platform/intel-mid/intel-mid.c (revision 41afb1dfad4d6af0c716746f6a15f3230482955c)
105454c26SKuppuswamy Sathyanarayanan /*
205454c26SKuppuswamy Sathyanarayanan  * intel-mid.c: Intel MID platform setup code
305454c26SKuppuswamy Sathyanarayanan  *
405454c26SKuppuswamy Sathyanarayanan  * (C) Copyright 2008, 2012 Intel Corporation
505454c26SKuppuswamy Sathyanarayanan  * Author: Jacob Pan (jacob.jun.pan@intel.com)
605454c26SKuppuswamy Sathyanarayanan  * Author: Sathyanarayanan Kuppuswamy <sathyanarayanan.kuppuswamy@intel.com>
705454c26SKuppuswamy Sathyanarayanan  *
805454c26SKuppuswamy Sathyanarayanan  * This program is free software; you can redistribute it and/or
905454c26SKuppuswamy Sathyanarayanan  * modify it under the terms of the GNU General Public License
1005454c26SKuppuswamy Sathyanarayanan  * as published by the Free Software Foundation; version 2
1105454c26SKuppuswamy Sathyanarayanan  * of the License.
1205454c26SKuppuswamy Sathyanarayanan  */
1305454c26SKuppuswamy Sathyanarayanan 
14712b6aa8SKuppuswamy Sathyanarayanan #define pr_fmt(fmt) "intel_mid: " fmt
1505454c26SKuppuswamy Sathyanarayanan 
1605454c26SKuppuswamy Sathyanarayanan #include <linux/init.h>
1705454c26SKuppuswamy Sathyanarayanan #include <linux/kernel.h>
1805454c26SKuppuswamy Sathyanarayanan #include <linux/interrupt.h>
19a11836faSAndy Shevchenko #include <linux/regulator/machine.h>
2005454c26SKuppuswamy Sathyanarayanan #include <linux/scatterlist.h>
2105454c26SKuppuswamy Sathyanarayanan #include <linux/sfi.h>
2205454c26SKuppuswamy Sathyanarayanan #include <linux/irq.h>
23cc3ae7b0SPaul Gortmaker #include <linux/export.h>
2405454c26SKuppuswamy Sathyanarayanan #include <linux/notifier.h>
2505454c26SKuppuswamy Sathyanarayanan 
2605454c26SKuppuswamy Sathyanarayanan #include <asm/setup.h>
2705454c26SKuppuswamy Sathyanarayanan #include <asm/mpspec_def.h>
2805454c26SKuppuswamy Sathyanarayanan #include <asm/hw_irq.h>
2905454c26SKuppuswamy Sathyanarayanan #include <asm/apic.h>
3005454c26SKuppuswamy Sathyanarayanan #include <asm/io_apic.h>
3105454c26SKuppuswamy Sathyanarayanan #include <asm/intel-mid.h>
3205454c26SKuppuswamy Sathyanarayanan #include <asm/intel_mid_vrtc.h>
3305454c26SKuppuswamy Sathyanarayanan #include <asm/io.h>
3405454c26SKuppuswamy Sathyanarayanan #include <asm/i8259.h>
3505454c26SKuppuswamy Sathyanarayanan #include <asm/intel_scu_ipc.h>
3605454c26SKuppuswamy Sathyanarayanan #include <asm/apb_timer.h>
3705454c26SKuppuswamy Sathyanarayanan #include <asm/reboot.h>
3805454c26SKuppuswamy Sathyanarayanan 
3905454c26SKuppuswamy Sathyanarayanan /*
4005454c26SKuppuswamy Sathyanarayanan  * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
41712b6aa8SKuppuswamy Sathyanarayanan  * cmdline option x86_intel_mid_timer can be used to override the configuration
4205454c26SKuppuswamy Sathyanarayanan  * to prefer one or the other.
4305454c26SKuppuswamy Sathyanarayanan  * at runtime, there are basically three timer configurations:
4405454c26SKuppuswamy Sathyanarayanan  * 1. per cpu apbt clock only
4505454c26SKuppuswamy Sathyanarayanan  * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
4605454c26SKuppuswamy Sathyanarayanan  * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
4705454c26SKuppuswamy Sathyanarayanan  *
4805454c26SKuppuswamy Sathyanarayanan  * by default (without cmdline option), platform code first detects cpu type
4905454c26SKuppuswamy Sathyanarayanan  * to see if we are on lincroft or penwell, then set up both lapic or apbt
5005454c26SKuppuswamy Sathyanarayanan  * clocks accordingly.
5105454c26SKuppuswamy Sathyanarayanan  * i.e. by default, medfield uses configuration #2, moorestown uses #1.
5205454c26SKuppuswamy Sathyanarayanan  * config #3 is supported but not recommended on medfield.
5305454c26SKuppuswamy Sathyanarayanan  *
5405454c26SKuppuswamy Sathyanarayanan  * rating and feature summary:
5505454c26SKuppuswamy Sathyanarayanan  * lapic (with C3STOP) --------- 100
5605454c26SKuppuswamy Sathyanarayanan  * apbt (always-on) ------------ 110
5705454c26SKuppuswamy Sathyanarayanan  * lapic (always-on,ARAT) ------ 150
5805454c26SKuppuswamy Sathyanarayanan  */
5905454c26SKuppuswamy Sathyanarayanan 
60712b6aa8SKuppuswamy Sathyanarayanan enum intel_mid_timer_options intel_mid_timer_options;
6105454c26SKuppuswamy Sathyanarayanan 
62712b6aa8SKuppuswamy Sathyanarayanan enum intel_mid_cpu_type __intel_mid_cpu_chip;
63712b6aa8SKuppuswamy Sathyanarayanan EXPORT_SYMBOL_GPL(__intel_mid_cpu_chip);
6405454c26SKuppuswamy Sathyanarayanan 
6585611e3fSKuppuswamy Sathyanarayanan static void intel_mid_power_off(void)
6685611e3fSKuppuswamy Sathyanarayanan {
67bda7b072SAndy Shevchenko 	/* Shut down South Complex via PWRMU */
68bda7b072SAndy Shevchenko 	intel_mid_pwr_power_off();
69bda7b072SAndy Shevchenko 
70bda7b072SAndy Shevchenko 	/* Only for Tangier, the rest will ignore this command */
71bda7b072SAndy Shevchenko 	intel_scu_ipc_simple_command(IPCMSG_COLD_OFF, 1);
7285611e3fSKuppuswamy Sathyanarayanan };
7385611e3fSKuppuswamy Sathyanarayanan 
74712b6aa8SKuppuswamy Sathyanarayanan static void intel_mid_reboot(void)
7505454c26SKuppuswamy Sathyanarayanan {
76028091f8SSebastian Panceac 	intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
7705454c26SKuppuswamy Sathyanarayanan }
7805454c26SKuppuswamy Sathyanarayanan 
796648d1b4SThomas Gleixner static void __init intel_mid_setup_bp_timer(void)
806648d1b4SThomas Gleixner {
816648d1b4SThomas Gleixner 	apbt_time_init();
826648d1b4SThomas Gleixner 	setup_boot_APIC_clock();
836648d1b4SThomas Gleixner }
846648d1b4SThomas Gleixner 
85712b6aa8SKuppuswamy Sathyanarayanan static void __init intel_mid_time_init(void)
8605454c26SKuppuswamy Sathyanarayanan {
8705454c26SKuppuswamy Sathyanarayanan 	sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
886648d1b4SThomas Gleixner 
89712b6aa8SKuppuswamy Sathyanarayanan 	switch (intel_mid_timer_options) {
90712b6aa8SKuppuswamy Sathyanarayanan 	case INTEL_MID_TIMER_APBT_ONLY:
9105454c26SKuppuswamy Sathyanarayanan 		break;
92712b6aa8SKuppuswamy Sathyanarayanan 	case INTEL_MID_TIMER_LAPIC_APBT:
936648d1b4SThomas Gleixner 		/* Use apbt and local apic */
946648d1b4SThomas Gleixner 		x86_init.timers.setup_percpu_clockev = intel_mid_setup_bp_timer;
9505454c26SKuppuswamy Sathyanarayanan 		x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
966648d1b4SThomas Gleixner 		return;
9705454c26SKuppuswamy Sathyanarayanan 	default:
9805454c26SKuppuswamy Sathyanarayanan 		if (!boot_cpu_has(X86_FEATURE_ARAT))
9905454c26SKuppuswamy Sathyanarayanan 			break;
1006648d1b4SThomas Gleixner 		/* Lapic only, no apbt */
10105454c26SKuppuswamy Sathyanarayanan 		x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
10205454c26SKuppuswamy Sathyanarayanan 		x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
10305454c26SKuppuswamy Sathyanarayanan 		return;
10405454c26SKuppuswamy Sathyanarayanan 	}
1056648d1b4SThomas Gleixner 
1066648d1b4SThomas Gleixner 	x86_init.timers.setup_percpu_clockev = apbt_time_init;
10705454c26SKuppuswamy Sathyanarayanan }
10805454c26SKuppuswamy Sathyanarayanan 
109aeeca404SPaul Gortmaker static void intel_mid_arch_setup(void)
11005454c26SKuppuswamy Sathyanarayanan {
11185611e3fSKuppuswamy Sathyanarayanan 	if (boot_cpu_data.x86 != 6) {
11205454c26SKuppuswamy Sathyanarayanan 		pr_err("Unknown Intel MID CPU (%d:%d), default to Penwell\n",
11305454c26SKuppuswamy Sathyanarayanan 			boot_cpu_data.x86, boot_cpu_data.x86_model);
114712b6aa8SKuppuswamy Sathyanarayanan 		__intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
11585611e3fSKuppuswamy Sathyanarayanan 		goto out;
11605454c26SKuppuswamy Sathyanarayanan 	}
11785611e3fSKuppuswamy Sathyanarayanan 
11885611e3fSKuppuswamy Sathyanarayanan 	switch (boot_cpu_data.x86_model) {
11985611e3fSKuppuswamy Sathyanarayanan 	case 0x35:
12085611e3fSKuppuswamy Sathyanarayanan 		__intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_CLOVERVIEW;
12185611e3fSKuppuswamy Sathyanarayanan 		break;
122bc20aa48SDavid Cohen 	case 0x3C:
123bc20aa48SDavid Cohen 	case 0x4A:
124bc20aa48SDavid Cohen 		__intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_TANGIER;
125*41afb1dfSAndy Shevchenko 		x86_platform.legacy.rtc = 1;
126bc20aa48SDavid Cohen 		break;
12785611e3fSKuppuswamy Sathyanarayanan 	case 0x27:
12885611e3fSKuppuswamy Sathyanarayanan 	default:
12985611e3fSKuppuswamy Sathyanarayanan 		__intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
13085611e3fSKuppuswamy Sathyanarayanan 		break;
13185611e3fSKuppuswamy Sathyanarayanan 	}
13285611e3fSKuppuswamy Sathyanarayanan 
13385611e3fSKuppuswamy Sathyanarayanan out:
134a11836faSAndy Shevchenko 	/*
135a11836faSAndy Shevchenko 	 * Intel MID platforms are using explicitly defined regulators.
136a11836faSAndy Shevchenko 	 *
137a11836faSAndy Shevchenko 	 * Let the regulator core know that we do not have any additional
138a11836faSAndy Shevchenko 	 * regulators left. This lets it substitute unprovided regulators with
139a11836faSAndy Shevchenko 	 * dummy ones:
140a11836faSAndy Shevchenko 	 */
141a11836faSAndy Shevchenko 	regulator_has_full_constraints();
14205454c26SKuppuswamy Sathyanarayanan }
14305454c26SKuppuswamy Sathyanarayanan 
14405454c26SKuppuswamy Sathyanarayanan /*
14505454c26SKuppuswamy Sathyanarayanan  * Moorestown does not have external NMI source nor port 0x61 to report
14605454c26SKuppuswamy Sathyanarayanan  * NMI status. The possible NMI sources are from pmu as a result of NMI
14705454c26SKuppuswamy Sathyanarayanan  * watchdog or lock debug. Reading io port 0x61 results in 0xff which
14805454c26SKuppuswamy Sathyanarayanan  * misled NMI handler.
14905454c26SKuppuswamy Sathyanarayanan  */
150712b6aa8SKuppuswamy Sathyanarayanan static unsigned char intel_mid_get_nmi_reason(void)
15105454c26SKuppuswamy Sathyanarayanan {
15205454c26SKuppuswamy Sathyanarayanan 	return 0;
15305454c26SKuppuswamy Sathyanarayanan }
15405454c26SKuppuswamy Sathyanarayanan 
15505454c26SKuppuswamy Sathyanarayanan /*
15605454c26SKuppuswamy Sathyanarayanan  * Moorestown specific x86_init function overrides and early setup
15705454c26SKuppuswamy Sathyanarayanan  * calls.
15805454c26SKuppuswamy Sathyanarayanan  */
159712b6aa8SKuppuswamy Sathyanarayanan void __init x86_intel_mid_early_setup(void)
16005454c26SKuppuswamy Sathyanarayanan {
16105454c26SKuppuswamy Sathyanarayanan 	x86_init.resources.probe_roms = x86_init_noop;
16205454c26SKuppuswamy Sathyanarayanan 	x86_init.resources.reserve_resources = x86_init_noop;
16305454c26SKuppuswamy Sathyanarayanan 
164712b6aa8SKuppuswamy Sathyanarayanan 	x86_init.timers.timer_init = intel_mid_time_init;
16505454c26SKuppuswamy Sathyanarayanan 	x86_init.timers.setup_percpu_clockev = x86_init_noop;
166b0ee9effSAndy Shevchenko 	x86_init.timers.wallclock_init = intel_mid_rtc_init;
16705454c26SKuppuswamy Sathyanarayanan 
16805454c26SKuppuswamy Sathyanarayanan 	x86_init.irqs.pre_vector_init = x86_init_noop;
16905454c26SKuppuswamy Sathyanarayanan 
170712b6aa8SKuppuswamy Sathyanarayanan 	x86_init.oem.arch_setup = intel_mid_arch_setup;
17105454c26SKuppuswamy Sathyanarayanan 
17205454c26SKuppuswamy Sathyanarayanan 	x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
17305454c26SKuppuswamy Sathyanarayanan 
174712b6aa8SKuppuswamy Sathyanarayanan 	x86_platform.get_nmi_reason = intel_mid_get_nmi_reason;
17505454c26SKuppuswamy Sathyanarayanan 
176a912a758SAndy Shevchenko 	x86_init.pci.arch_init = intel_mid_pci_init;
17705454c26SKuppuswamy Sathyanarayanan 	x86_init.pci.fixup_irqs = x86_init_noop;
17805454c26SKuppuswamy Sathyanarayanan 
17905454c26SKuppuswamy Sathyanarayanan 	legacy_pic = &null_legacy_pic;
18005454c26SKuppuswamy Sathyanarayanan 
18102428742SAndy Shevchenko 	/*
18202428742SAndy Shevchenko 	 * Do nothing for now as everything needed done in
18302428742SAndy Shevchenko 	 * x86_intel_mid_early_setup() below.
18402428742SAndy Shevchenko 	 */
18502428742SAndy Shevchenko 	x86_init.acpi.reduced_hw_early_init = x86_init_noop;
18602428742SAndy Shevchenko 
187712b6aa8SKuppuswamy Sathyanarayanan 	pm_power_off = intel_mid_power_off;
188712b6aa8SKuppuswamy Sathyanarayanan 	machine_ops.emergency_restart  = intel_mid_reboot;
18905454c26SKuppuswamy Sathyanarayanan 
19005454c26SKuppuswamy Sathyanarayanan 	/* Avoid searching for BIOS MP tables */
19105454c26SKuppuswamy Sathyanarayanan 	x86_init.mpparse.find_smp_config = x86_init_noop;
19205454c26SKuppuswamy Sathyanarayanan 	x86_init.mpparse.get_smp_config = x86_init_uint_noop;
19305454c26SKuppuswamy Sathyanarayanan 	set_bit(MP_BUS_ISA, mp_bus_not_pci);
19405454c26SKuppuswamy Sathyanarayanan }
19505454c26SKuppuswamy Sathyanarayanan 
19605454c26SKuppuswamy Sathyanarayanan /*
19705454c26SKuppuswamy Sathyanarayanan  * if user does not want to use per CPU apb timer, just give it a lower rating
19805454c26SKuppuswamy Sathyanarayanan  * than local apic timer and skip the late per cpu timer init.
19905454c26SKuppuswamy Sathyanarayanan  */
200712b6aa8SKuppuswamy Sathyanarayanan static inline int __init setup_x86_intel_mid_timer(char *arg)
20105454c26SKuppuswamy Sathyanarayanan {
20205454c26SKuppuswamy Sathyanarayanan 	if (!arg)
20305454c26SKuppuswamy Sathyanarayanan 		return -EINVAL;
20405454c26SKuppuswamy Sathyanarayanan 
20505454c26SKuppuswamy Sathyanarayanan 	if (strcmp("apbt_only", arg) == 0)
206712b6aa8SKuppuswamy Sathyanarayanan 		intel_mid_timer_options = INTEL_MID_TIMER_APBT_ONLY;
20705454c26SKuppuswamy Sathyanarayanan 	else if (strcmp("lapic_and_apbt", arg) == 0)
208712b6aa8SKuppuswamy Sathyanarayanan 		intel_mid_timer_options = INTEL_MID_TIMER_LAPIC_APBT;
20905454c26SKuppuswamy Sathyanarayanan 	else {
210b000de58SAndy Shevchenko 		pr_warn("X86 INTEL_MID timer option %s not recognised use x86_intel_mid_timer=apbt_only or lapic_and_apbt\n",
21105454c26SKuppuswamy Sathyanarayanan 			arg);
21205454c26SKuppuswamy Sathyanarayanan 		return -EINVAL;
21305454c26SKuppuswamy Sathyanarayanan 	}
21405454c26SKuppuswamy Sathyanarayanan 	return 0;
21505454c26SKuppuswamy Sathyanarayanan }
216712b6aa8SKuppuswamy Sathyanarayanan __setup("x86_intel_mid_timer=", setup_x86_intel_mid_timer);
217