intel-mid.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. * 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/scatterlist.h>
  18. #include <linux/sfi.h>
  19. #include <linux/irq.h>
  20. #include <linux/module.h>
  21. #include <linux/notifier.h>
  22. #include <asm/setup.h>
  23. #include <asm/mpspec_def.h>
  24. #include <asm/hw_irq.h>
  25. #include <asm/apic.h>
  26. #include <asm/io_apic.h>
  27. #include <asm/intel-mid.h>
  28. #include <asm/intel_mid_vrtc.h>
  29. #include <asm/io.h>
  30. #include <asm/i8259.h>
  31. #include <asm/intel_scu_ipc.h>
  32. #include <asm/apb_timer.h>
  33. #include <asm/reboot.h>
  34. /*
  35. * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
  36. * cmdline option x86_intel_mid_timer can be used to override the configuration
  37. * to prefer one or the other.
  38. * at runtime, there are basically three timer configurations:
  39. * 1. per cpu apbt clock only
  40. * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
  41. * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
  42. *
  43. * by default (without cmdline option), platform code first detects cpu type
  44. * to see if we are on lincroft or penwell, then set up both lapic or apbt
  45. * clocks accordingly.
  46. * i.e. by default, medfield uses configuration #2, moorestown uses #1.
  47. * config #3 is supported but not recommended on medfield.
  48. *
  49. * rating and feature summary:
  50. * lapic (with C3STOP) --------- 100
  51. * apbt (always-on) ------------ 110
  52. * lapic (always-on,ARAT) ------ 150
  53. */
  54. enum intel_mid_timer_options intel_mid_timer_options;
  55. enum intel_mid_cpu_type __intel_mid_cpu_chip;
  56. EXPORT_SYMBOL_GPL(__intel_mid_cpu_chip);
  57. static void intel_mid_power_off(void)
  58. {
  59. }
  60. static void intel_mid_reboot(void)
  61. {
  62. intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
  63. }
  64. static unsigned long __init intel_mid_calibrate_tsc(void)
  65. {
  66. unsigned long fast_calibrate;
  67. u32 lo, hi, ratio, fsb;
  68. rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
  69. pr_debug("IA32 perf status is 0x%x, 0x%0x\n", lo, hi);
  70. ratio = (hi >> 8) & 0x1f;
  71. pr_debug("ratio is %d\n", ratio);
  72. if (!ratio) {
  73. pr_err("read a zero ratio, should be incorrect!\n");
  74. pr_err("force tsc ratio to 16 ...\n");
  75. ratio = 16;
  76. }
  77. rdmsr(MSR_FSB_FREQ, lo, hi);
  78. if ((lo & 0x7) == 0x7)
  79. fsb = PENWELL_FSB_FREQ_83SKU;
  80. else
  81. fsb = PENWELL_FSB_FREQ_100SKU;
  82. fast_calibrate = ratio * fsb;
  83. pr_debug("read penwell tsc %lu khz\n", fast_calibrate);
  84. lapic_timer_frequency = fsb * 1000 / HZ;
  85. /* mark tsc clocksource as reliable */
  86. set_cpu_cap(&boot_cpu_data, X86_FEATURE_TSC_RELIABLE);
  87. if (fast_calibrate)
  88. return fast_calibrate;
  89. return 0;
  90. }
  91. static void __init intel_mid_time_init(void)
  92. {
  93. sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
  94. switch (intel_mid_timer_options) {
  95. case INTEL_MID_TIMER_APBT_ONLY:
  96. break;
  97. case INTEL_MID_TIMER_LAPIC_APBT:
  98. x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
  99. x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
  100. break;
  101. default:
  102. if (!boot_cpu_has(X86_FEATURE_ARAT))
  103. break;
  104. x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
  105. x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
  106. return;
  107. }
  108. /* we need at least one APB timer */
  109. pre_init_apic_IRQ0();
  110. apbt_time_init();
  111. }
  112. static void intel_mid_arch_setup(void)
  113. {
  114. if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
  115. __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
  116. else {
  117. pr_err("Unknown Intel MID CPU (%d:%d), default to Penwell\n",
  118. boot_cpu_data.x86, boot_cpu_data.x86_model);
  119. __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
  120. }
  121. }
  122. /* MID systems don't have i8042 controller */
  123. static int intel_mid_i8042_detect(void)
  124. {
  125. return 0;
  126. }
  127. /*
  128. * Moorestown does not have external NMI source nor port 0x61 to report
  129. * NMI status. The possible NMI sources are from pmu as a result of NMI
  130. * watchdog or lock debug. Reading io port 0x61 results in 0xff which
  131. * misled NMI handler.
  132. */
  133. static unsigned char intel_mid_get_nmi_reason(void)
  134. {
  135. return 0;
  136. }
  137. /*
  138. * Moorestown specific x86_init function overrides and early setup
  139. * calls.
  140. */
  141. void __init x86_intel_mid_early_setup(void)
  142. {
  143. x86_init.resources.probe_roms = x86_init_noop;
  144. x86_init.resources.reserve_resources = x86_init_noop;
  145. x86_init.timers.timer_init = intel_mid_time_init;
  146. x86_init.timers.setup_percpu_clockev = x86_init_noop;
  147. x86_init.irqs.pre_vector_init = x86_init_noop;
  148. x86_init.oem.arch_setup = intel_mid_arch_setup;
  149. x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
  150. x86_platform.calibrate_tsc = intel_mid_calibrate_tsc;
  151. x86_platform.i8042_detect = intel_mid_i8042_detect;
  152. x86_init.timers.wallclock_init = intel_mid_rtc_init;
  153. x86_platform.get_nmi_reason = intel_mid_get_nmi_reason;
  154. x86_init.pci.init = intel_mid_pci_init;
  155. x86_init.pci.fixup_irqs = x86_init_noop;
  156. legacy_pic = &null_legacy_pic;
  157. pm_power_off = intel_mid_power_off;
  158. machine_ops.emergency_restart = intel_mid_reboot;
  159. /* Avoid searching for BIOS MP tables */
  160. x86_init.mpparse.find_smp_config = x86_init_noop;
  161. x86_init.mpparse.get_smp_config = x86_init_uint_noop;
  162. set_bit(MP_BUS_ISA, mp_bus_not_pci);
  163. }
  164. /*
  165. * if user does not want to use per CPU apb timer, just give it a lower rating
  166. * than local apic timer and skip the late per cpu timer init.
  167. */
  168. static inline int __init setup_x86_intel_mid_timer(char *arg)
  169. {
  170. if (!arg)
  171. return -EINVAL;
  172. if (strcmp("apbt_only", arg) == 0)
  173. intel_mid_timer_options = INTEL_MID_TIMER_APBT_ONLY;
  174. else if (strcmp("lapic_and_apbt", arg) == 0)
  175. intel_mid_timer_options = INTEL_MID_TIMER_LAPIC_APBT;
  176. else {
  177. pr_warn("X86 INTEL_MID timer option %s not recognised"
  178. " use x86_intel_mid_timer=apbt_only or lapic_and_apbt\n",
  179. arg);
  180. return -EINVAL;
  181. }
  182. return 0;
  183. }
  184. __setup("x86_intel_mid_timer=", setup_x86_intel_mid_timer);