intel-mid.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * intel-mid.c: Intel MID platform setup code
  3. *
  4. * (C) Copyright 2008, 2012 Intel Corporation
  5. * Author: Jacob Pan ([email protected])
  6. * Author: Sathyanarayanan Kuppuswamy <[email protected]>
  7. *
  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. */
  13. #define pr_fmt(fmt) "intel_mid: " fmt
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/regulator/machine.h>
  18. #include <linux/scatterlist.h>
  19. #include <linux/sfi.h>
  20. #include <linux/irq.h>
  21. #include <linux/export.h>
  22. #include <linux/notifier.h>
  23. #include <asm/setup.h>
  24. #include <asm/mpspec_def.h>
  25. #include <asm/hw_irq.h>
  26. #include <asm/apic.h>
  27. #include <asm/io_apic.h>
  28. #include <asm/intel-mid.h>
  29. #include <asm/intel_mid_vrtc.h>
  30. #include <asm/io.h>
  31. #include <asm/i8259.h>
  32. #include <asm/intel_scu_ipc.h>
  33. #include <asm/apb_timer.h>
  34. #include <asm/reboot.h>
  35. #include "intel_mid_weak_decls.h"
  36. /*
  37. * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
  38. * cmdline option x86_intel_mid_timer can be used to override the configuration
  39. * to prefer one or the other.
  40. * at runtime, there are basically three timer configurations:
  41. * 1. per cpu apbt clock only
  42. * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
  43. * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
  44. *
  45. * by default (without cmdline option), platform code first detects cpu type
  46. * to see if we are on lincroft or penwell, then set up both lapic or apbt
  47. * clocks accordingly.
  48. * i.e. by default, medfield uses configuration #2, moorestown uses #1.
  49. * config #3 is supported but not recommended on medfield.
  50. *
  51. * rating and feature summary:
  52. * lapic (with C3STOP) --------- 100
  53. * apbt (always-on) ------------ 110
  54. * lapic (always-on,ARAT) ------ 150
  55. */
  56. enum intel_mid_timer_options intel_mid_timer_options;
  57. /* intel_mid_ops to store sub arch ops */
  58. static struct intel_mid_ops *intel_mid_ops;
  59. /* getter function for sub arch ops*/
  60. static void *(*get_intel_mid_ops[])(void) = INTEL_MID_OPS_INIT;
  61. enum intel_mid_cpu_type __intel_mid_cpu_chip;
  62. EXPORT_SYMBOL_GPL(__intel_mid_cpu_chip);
  63. static void intel_mid_power_off(void)
  64. {
  65. /* Shut down South Complex via PWRMU */
  66. intel_mid_pwr_power_off();
  67. /* Only for Tangier, the rest will ignore this command */
  68. intel_scu_ipc_simple_command(IPCMSG_COLD_OFF, 1);
  69. };
  70. static void intel_mid_reboot(void)
  71. {
  72. intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
  73. }
  74. static unsigned long __init intel_mid_calibrate_tsc(void)
  75. {
  76. return 0;
  77. }
  78. static void __init intel_mid_setup_bp_timer(void)
  79. {
  80. apbt_time_init();
  81. setup_boot_APIC_clock();
  82. }
  83. static void __init intel_mid_time_init(void)
  84. {
  85. sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
  86. switch (intel_mid_timer_options) {
  87. case INTEL_MID_TIMER_APBT_ONLY:
  88. break;
  89. case INTEL_MID_TIMER_LAPIC_APBT:
  90. /* Use apbt and local apic */
  91. x86_init.timers.setup_percpu_clockev = intel_mid_setup_bp_timer;
  92. x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
  93. return;
  94. default:
  95. if (!boot_cpu_has(X86_FEATURE_ARAT))
  96. break;
  97. /* Lapic only, no apbt */
  98. x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
  99. x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
  100. return;
  101. }
  102. x86_init.timers.setup_percpu_clockev = apbt_time_init;
  103. }
  104. static void intel_mid_arch_setup(void)
  105. {
  106. if (boot_cpu_data.x86 != 6) {
  107. pr_err("Unknown Intel MID CPU (%d:%d), default to Penwell\n",
  108. boot_cpu_data.x86, boot_cpu_data.x86_model);
  109. __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
  110. goto out;
  111. }
  112. switch (boot_cpu_data.x86_model) {
  113. case 0x35:
  114. __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_CLOVERVIEW;
  115. break;
  116. case 0x3C:
  117. case 0x4A:
  118. __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_TANGIER;
  119. break;
  120. case 0x27:
  121. default:
  122. __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
  123. break;
  124. }
  125. if (__intel_mid_cpu_chip < MAX_CPU_OPS(get_intel_mid_ops))
  126. intel_mid_ops = get_intel_mid_ops[__intel_mid_cpu_chip]();
  127. else {
  128. intel_mid_ops = get_intel_mid_ops[INTEL_MID_CPU_CHIP_PENWELL]();
  129. pr_info("ARCH: Unknown SoC, assuming Penwell!\n");
  130. }
  131. out:
  132. if (intel_mid_ops->arch_setup)
  133. intel_mid_ops->arch_setup();
  134. /*
  135. * Intel MID platforms are using explicitly defined regulators.
  136. *
  137. * Let the regulator core know that we do not have any additional
  138. * regulators left. This lets it substitute unprovided regulators with
  139. * dummy ones:
  140. */
  141. regulator_has_full_constraints();
  142. }
  143. /* MID systems don't have i8042 controller */
  144. static int intel_mid_i8042_detect(void)
  145. {
  146. return 0;
  147. }
  148. /*
  149. * Moorestown does not have external NMI source nor port 0x61 to report
  150. * NMI status. The possible NMI sources are from pmu as a result of NMI
  151. * watchdog or lock debug. Reading io port 0x61 results in 0xff which
  152. * misled NMI handler.
  153. */
  154. static unsigned char intel_mid_get_nmi_reason(void)
  155. {
  156. return 0;
  157. }
  158. /*
  159. * Moorestown specific x86_init function overrides and early setup
  160. * calls.
  161. */
  162. void __init x86_intel_mid_early_setup(void)
  163. {
  164. x86_init.resources.probe_roms = x86_init_noop;
  165. x86_init.resources.reserve_resources = x86_init_noop;
  166. x86_init.timers.timer_init = intel_mid_time_init;
  167. x86_init.timers.setup_percpu_clockev = x86_init_noop;
  168. x86_init.irqs.pre_vector_init = x86_init_noop;
  169. x86_init.oem.arch_setup = intel_mid_arch_setup;
  170. x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
  171. x86_platform.calibrate_tsc = intel_mid_calibrate_tsc;
  172. x86_platform.i8042_detect = intel_mid_i8042_detect;
  173. x86_init.timers.wallclock_init = intel_mid_rtc_init;
  174. x86_platform.get_nmi_reason = intel_mid_get_nmi_reason;
  175. x86_init.pci.init = intel_mid_pci_init;
  176. x86_init.pci.fixup_irqs = x86_init_noop;
  177. legacy_pic = &null_legacy_pic;
  178. pm_power_off = intel_mid_power_off;
  179. machine_ops.emergency_restart = intel_mid_reboot;
  180. /* Avoid searching for BIOS MP tables */
  181. x86_init.mpparse.find_smp_config = x86_init_noop;
  182. x86_init.mpparse.get_smp_config = x86_init_uint_noop;
  183. set_bit(MP_BUS_ISA, mp_bus_not_pci);
  184. }
  185. /*
  186. * if user does not want to use per CPU apb timer, just give it a lower rating
  187. * than local apic timer and skip the late per cpu timer init.
  188. */
  189. static inline int __init setup_x86_intel_mid_timer(char *arg)
  190. {
  191. if (!arg)
  192. return -EINVAL;
  193. if (strcmp("apbt_only", arg) == 0)
  194. intel_mid_timer_options = INTEL_MID_TIMER_APBT_ONLY;
  195. else if (strcmp("lapic_and_apbt", arg) == 0)
  196. intel_mid_timer_options = INTEL_MID_TIMER_LAPIC_APBT;
  197. else {
  198. pr_warn("X86 INTEL_MID timer option %s not recognised use x86_intel_mid_timer=apbt_only or lapic_and_apbt\n",
  199. arg);
  200. return -EINVAL;
  201. }
  202. return 0;
  203. }
  204. __setup("x86_intel_mid_timer=", setup_x86_intel_mid_timer);