mrst.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. /*
  2. * mrst.c: Intel Moorestown platform specific setup code
  3. *
  4. * (C) Copyright 2008 Intel Corporation
  5. * Author: Jacob Pan (jacob.jun.pan@intel.com)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; version 2
  10. * of the License.
  11. */
  12. #define pr_fmt(fmt) "mrst: " fmt
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/scatterlist.h>
  17. #include <linux/sfi.h>
  18. #include <linux/intel_pmic_gpio.h>
  19. #include <linux/spi/spi.h>
  20. #include <linux/i2c.h>
  21. #include <linux/i2c/pca953x.h>
  22. #include <linux/gpio_keys.h>
  23. #include <linux/input.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/irq.h>
  26. #include <linux/module.h>
  27. #include <linux/notifier.h>
  28. #include <linux/mfd/intel_msic.h>
  29. #include <asm/setup.h>
  30. #include <asm/mpspec_def.h>
  31. #include <asm/hw_irq.h>
  32. #include <asm/apic.h>
  33. #include <asm/io_apic.h>
  34. #include <asm/mrst.h>
  35. #include <asm/mrst-vrtc.h>
  36. #include <asm/io.h>
  37. #include <asm/i8259.h>
  38. #include <asm/intel_scu_ipc.h>
  39. #include <asm/apb_timer.h>
  40. #include <asm/reboot.h>
  41. /*
  42. * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
  43. * cmdline option x86_mrst_timer can be used to override the configuration
  44. * to prefer one or the other.
  45. * at runtime, there are basically three timer configurations:
  46. * 1. per cpu apbt clock only
  47. * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
  48. * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
  49. *
  50. * by default (without cmdline option), platform code first detects cpu type
  51. * to see if we are on lincroft or penwell, then set up both lapic or apbt
  52. * clocks accordingly.
  53. * i.e. by default, medfield uses configuration #2, moorestown uses #1.
  54. * config #3 is supported but not recommended on medfield.
  55. *
  56. * rating and feature summary:
  57. * lapic (with C3STOP) --------- 100
  58. * apbt (always-on) ------------ 110
  59. * lapic (always-on,ARAT) ------ 150
  60. */
  61. __cpuinitdata enum mrst_timer_options mrst_timer_options;
  62. static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
  63. static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
  64. enum mrst_cpu_type __mrst_cpu_chip;
  65. EXPORT_SYMBOL_GPL(__mrst_cpu_chip);
  66. int sfi_mtimer_num;
  67. struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
  68. EXPORT_SYMBOL_GPL(sfi_mrtc_array);
  69. int sfi_mrtc_num;
  70. /* parse all the mtimer info to a static mtimer array */
  71. static int __init sfi_parse_mtmr(struct sfi_table_header *table)
  72. {
  73. struct sfi_table_simple *sb;
  74. struct sfi_timer_table_entry *pentry;
  75. struct mpc_intsrc mp_irq;
  76. int totallen;
  77. sb = (struct sfi_table_simple *)table;
  78. if (!sfi_mtimer_num) {
  79. sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
  80. struct sfi_timer_table_entry);
  81. pentry = (struct sfi_timer_table_entry *) sb->pentry;
  82. totallen = sfi_mtimer_num * sizeof(*pentry);
  83. memcpy(sfi_mtimer_array, pentry, totallen);
  84. }
  85. pr_debug("SFI MTIMER info (num = %d):\n", sfi_mtimer_num);
  86. pentry = sfi_mtimer_array;
  87. for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
  88. pr_debug("timer[%d]: paddr = 0x%08x, freq = %dHz,"
  89. " irq = %d\n", totallen, (u32)pentry->phys_addr,
  90. pentry->freq_hz, pentry->irq);
  91. if (!pentry->irq)
  92. continue;
  93. mp_irq.type = MP_INTSRC;
  94. mp_irq.irqtype = mp_INT;
  95. /* triggering mode edge bit 2-3, active high polarity bit 0-1 */
  96. mp_irq.irqflag = 5;
  97. mp_irq.srcbus = MP_BUS_ISA;
  98. mp_irq.srcbusirq = pentry->irq; /* IRQ */
  99. mp_irq.dstapic = MP_APIC_ALL;
  100. mp_irq.dstirq = pentry->irq;
  101. mp_save_irq(&mp_irq);
  102. }
  103. return 0;
  104. }
  105. struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
  106. {
  107. int i;
  108. if (hint < sfi_mtimer_num) {
  109. if (!sfi_mtimer_usage[hint]) {
  110. pr_debug("hint taken for timer %d irq %d\n",\
  111. hint, sfi_mtimer_array[hint].irq);
  112. sfi_mtimer_usage[hint] = 1;
  113. return &sfi_mtimer_array[hint];
  114. }
  115. }
  116. /* take the first timer available */
  117. for (i = 0; i < sfi_mtimer_num;) {
  118. if (!sfi_mtimer_usage[i]) {
  119. sfi_mtimer_usage[i] = 1;
  120. return &sfi_mtimer_array[i];
  121. }
  122. i++;
  123. }
  124. return NULL;
  125. }
  126. void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
  127. {
  128. int i;
  129. for (i = 0; i < sfi_mtimer_num;) {
  130. if (mtmr->irq == sfi_mtimer_array[i].irq) {
  131. sfi_mtimer_usage[i] = 0;
  132. return;
  133. }
  134. i++;
  135. }
  136. }
  137. /* parse all the mrtc info to a global mrtc array */
  138. int __init sfi_parse_mrtc(struct sfi_table_header *table)
  139. {
  140. struct sfi_table_simple *sb;
  141. struct sfi_rtc_table_entry *pentry;
  142. struct mpc_intsrc mp_irq;
  143. int totallen;
  144. sb = (struct sfi_table_simple *)table;
  145. if (!sfi_mrtc_num) {
  146. sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb,
  147. struct sfi_rtc_table_entry);
  148. pentry = (struct sfi_rtc_table_entry *)sb->pentry;
  149. totallen = sfi_mrtc_num * sizeof(*pentry);
  150. memcpy(sfi_mrtc_array, pentry, totallen);
  151. }
  152. pr_debug("SFI RTC info (num = %d):\n", sfi_mrtc_num);
  153. pentry = sfi_mrtc_array;
  154. for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
  155. pr_debug("RTC[%d]: paddr = 0x%08x, irq = %d\n",
  156. totallen, (u32)pentry->phys_addr, pentry->irq);
  157. mp_irq.type = MP_INTSRC;
  158. mp_irq.irqtype = mp_INT;
  159. mp_irq.irqflag = 0xf; /* level trigger and active low */
  160. mp_irq.srcbus = MP_BUS_ISA;
  161. mp_irq.srcbusirq = pentry->irq; /* IRQ */
  162. mp_irq.dstapic = MP_APIC_ALL;
  163. mp_irq.dstirq = pentry->irq;
  164. mp_save_irq(&mp_irq);
  165. }
  166. return 0;
  167. }
  168. static unsigned long __init mrst_calibrate_tsc(void)
  169. {
  170. unsigned long flags, fast_calibrate;
  171. if (__mrst_cpu_chip == MRST_CPU_CHIP_PENWELL) {
  172. u32 lo, hi, ratio, fsb;
  173. rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
  174. pr_debug("IA32 perf status is 0x%x, 0x%0x\n", lo, hi);
  175. ratio = (hi >> 8) & 0x1f;
  176. pr_debug("ratio is %d\n", ratio);
  177. if (!ratio) {
  178. pr_err("read a zero ratio, should be incorrect!\n");
  179. pr_err("force tsc ratio to 16 ...\n");
  180. ratio = 16;
  181. }
  182. rdmsr(MSR_FSB_FREQ, lo, hi);
  183. if ((lo & 0x7) == 0x7)
  184. fsb = PENWELL_FSB_FREQ_83SKU;
  185. else
  186. fsb = PENWELL_FSB_FREQ_100SKU;
  187. fast_calibrate = ratio * fsb;
  188. pr_debug("read penwell tsc %lu khz\n", fast_calibrate);
  189. lapic_timer_frequency = fsb * 1000 / HZ;
  190. /* mark tsc clocksource as reliable */
  191. set_cpu_cap(&boot_cpu_data, X86_FEATURE_TSC_RELIABLE);
  192. } else {
  193. local_irq_save(flags);
  194. fast_calibrate = apbt_quick_calibrate();
  195. local_irq_restore(flags);
  196. }
  197. if (fast_calibrate)
  198. return fast_calibrate;
  199. return 0;
  200. }
  201. static void __init mrst_time_init(void)
  202. {
  203. sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
  204. switch (mrst_timer_options) {
  205. case MRST_TIMER_APBT_ONLY:
  206. break;
  207. case MRST_TIMER_LAPIC_APBT:
  208. x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
  209. x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
  210. break;
  211. default:
  212. if (!boot_cpu_has(X86_FEATURE_ARAT))
  213. break;
  214. x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
  215. x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
  216. return;
  217. }
  218. /* we need at least one APB timer */
  219. pre_init_apic_IRQ0();
  220. apbt_time_init();
  221. }
  222. static void __cpuinit mrst_arch_setup(void)
  223. {
  224. if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
  225. __mrst_cpu_chip = MRST_CPU_CHIP_PENWELL;
  226. else if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x26)
  227. __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
  228. else {
  229. pr_err("Unknown Moorestown CPU (%d:%d), default to Lincroft\n",
  230. boot_cpu_data.x86, boot_cpu_data.x86_model);
  231. __mrst_cpu_chip = MRST_CPU_CHIP_LINCROFT;
  232. }
  233. pr_debug("Moorestown CPU %s identified\n",
  234. (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT) ?
  235. "Lincroft" : "Penwell");
  236. }
  237. /* MID systems don't have i8042 controller */
  238. static int mrst_i8042_detect(void)
  239. {
  240. return 0;
  241. }
  242. /* Reboot and power off are handled by the SCU on a MID device */
  243. static void mrst_power_off(void)
  244. {
  245. intel_scu_ipc_simple_command(0xf1, 1);
  246. }
  247. static void mrst_reboot(void)
  248. {
  249. intel_scu_ipc_simple_command(0xf1, 0);
  250. }
  251. /*
  252. * Moorestown does not have external NMI source nor port 0x61 to report
  253. * NMI status. The possible NMI sources are from pmu as a result of NMI
  254. * watchdog or lock debug. Reading io port 0x61 results in 0xff which
  255. * misled NMI handler.
  256. */
  257. static unsigned char mrst_get_nmi_reason(void)
  258. {
  259. return 0;
  260. }
  261. /*
  262. * Moorestown specific x86_init function overrides and early setup
  263. * calls.
  264. */
  265. void __init x86_mrst_early_setup(void)
  266. {
  267. x86_init.resources.probe_roms = x86_init_noop;
  268. x86_init.resources.reserve_resources = x86_init_noop;
  269. x86_init.timers.timer_init = mrst_time_init;
  270. x86_init.timers.setup_percpu_clockev = x86_init_noop;
  271. x86_init.irqs.pre_vector_init = x86_init_noop;
  272. x86_init.oem.arch_setup = mrst_arch_setup;
  273. x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
  274. x86_platform.calibrate_tsc = mrst_calibrate_tsc;
  275. x86_platform.i8042_detect = mrst_i8042_detect;
  276. x86_init.timers.wallclock_init = mrst_rtc_init;
  277. x86_platform.get_nmi_reason = mrst_get_nmi_reason;
  278. x86_init.pci.init = pci_mrst_init;
  279. x86_init.pci.fixup_irqs = x86_init_noop;
  280. legacy_pic = &null_legacy_pic;
  281. /* Moorestown specific power_off/restart method */
  282. pm_power_off = mrst_power_off;
  283. machine_ops.emergency_restart = mrst_reboot;
  284. /* Avoid searching for BIOS MP tables */
  285. x86_init.mpparse.find_smp_config = x86_init_noop;
  286. x86_init.mpparse.get_smp_config = x86_init_uint_noop;
  287. set_bit(MP_BUS_ISA, mp_bus_not_pci);
  288. }
  289. /*
  290. * if user does not want to use per CPU apb timer, just give it a lower rating
  291. * than local apic timer and skip the late per cpu timer init.
  292. */
  293. static inline int __init setup_x86_mrst_timer(char *arg)
  294. {
  295. if (!arg)
  296. return -EINVAL;
  297. if (strcmp("apbt_only", arg) == 0)
  298. mrst_timer_options = MRST_TIMER_APBT_ONLY;
  299. else if (strcmp("lapic_and_apbt", arg) == 0)
  300. mrst_timer_options = MRST_TIMER_LAPIC_APBT;
  301. else {
  302. pr_warning("X86 MRST timer option %s not recognised"
  303. " use x86_mrst_timer=apbt_only or lapic_and_apbt\n",
  304. arg);
  305. return -EINVAL;
  306. }
  307. return 0;
  308. }
  309. __setup("x86_mrst_timer=", setup_x86_mrst_timer);
  310. /*
  311. * Parsing GPIO table first, since the DEVS table will need this table
  312. * to map the pin name to the actual pin.
  313. */
  314. static struct sfi_gpio_table_entry *gpio_table;
  315. static int gpio_num_entry;
  316. static int __init sfi_parse_gpio(struct sfi_table_header *table)
  317. {
  318. struct sfi_table_simple *sb;
  319. struct sfi_gpio_table_entry *pentry;
  320. int num, i;
  321. if (gpio_table)
  322. return 0;
  323. sb = (struct sfi_table_simple *)table;
  324. num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
  325. pentry = (struct sfi_gpio_table_entry *)sb->pentry;
  326. gpio_table = (struct sfi_gpio_table_entry *)
  327. kmalloc(num * sizeof(*pentry), GFP_KERNEL);
  328. if (!gpio_table)
  329. return -1;
  330. memcpy(gpio_table, pentry, num * sizeof(*pentry));
  331. gpio_num_entry = num;
  332. pr_debug("GPIO pin info:\n");
  333. for (i = 0; i < num; i++, pentry++)
  334. pr_debug("info[%2d]: controller = %16.16s, pin_name = %16.16s,"
  335. " pin = %d\n", i,
  336. pentry->controller_name,
  337. pentry->pin_name,
  338. pentry->pin_no);
  339. return 0;
  340. }
  341. static int get_gpio_by_name(const char *name)
  342. {
  343. struct sfi_gpio_table_entry *pentry = gpio_table;
  344. int i;
  345. if (!pentry)
  346. return -1;
  347. for (i = 0; i < gpio_num_entry; i++, pentry++) {
  348. if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
  349. return pentry->pin_no;
  350. }
  351. return -1;
  352. }
  353. /*
  354. * Here defines the array of devices platform data that IAFW would export
  355. * through SFI "DEVS" table, we use name and type to match the device and
  356. * its platform data.
  357. */
  358. struct devs_id {
  359. char name[SFI_NAME_LEN + 1];
  360. u8 type;
  361. u8 delay;
  362. void *(*get_platform_data)(void *info);
  363. };
  364. /* the offset for the mapping of global gpio pin to irq */
  365. #define MRST_IRQ_OFFSET 0x100
  366. static void __init *pmic_gpio_platform_data(void *info)
  367. {
  368. static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
  369. int gpio_base = get_gpio_by_name("pmic_gpio_base");
  370. if (gpio_base == -1)
  371. gpio_base = 64;
  372. pmic_gpio_pdata.gpio_base = gpio_base;
  373. pmic_gpio_pdata.irq_base = gpio_base + MRST_IRQ_OFFSET;
  374. pmic_gpio_pdata.gpiointr = 0xffffeff8;
  375. return &pmic_gpio_pdata;
  376. }
  377. static void __init *max3111_platform_data(void *info)
  378. {
  379. struct spi_board_info *spi_info = info;
  380. int intr = get_gpio_by_name("max3111_int");
  381. spi_info->mode = SPI_MODE_0;
  382. if (intr == -1)
  383. return NULL;
  384. spi_info->irq = intr + MRST_IRQ_OFFSET;
  385. return NULL;
  386. }
  387. /* we have multiple max7315 on the board ... */
  388. #define MAX7315_NUM 2
  389. static void __init *max7315_platform_data(void *info)
  390. {
  391. static struct pca953x_platform_data max7315_pdata[MAX7315_NUM];
  392. static int nr;
  393. struct pca953x_platform_data *max7315 = &max7315_pdata[nr];
  394. struct i2c_board_info *i2c_info = info;
  395. int gpio_base, intr;
  396. char base_pin_name[SFI_NAME_LEN + 1];
  397. char intr_pin_name[SFI_NAME_LEN + 1];
  398. if (nr == MAX7315_NUM) {
  399. pr_err("too many max7315s, we only support %d\n",
  400. MAX7315_NUM);
  401. return NULL;
  402. }
  403. /* we have several max7315 on the board, we only need load several
  404. * instances of the same pca953x driver to cover them
  405. */
  406. strcpy(i2c_info->type, "max7315");
  407. if (nr++) {
  408. sprintf(base_pin_name, "max7315_%d_base", nr);
  409. sprintf(intr_pin_name, "max7315_%d_int", nr);
  410. } else {
  411. strcpy(base_pin_name, "max7315_base");
  412. strcpy(intr_pin_name, "max7315_int");
  413. }
  414. gpio_base = get_gpio_by_name(base_pin_name);
  415. intr = get_gpio_by_name(intr_pin_name);
  416. if (gpio_base == -1)
  417. return NULL;
  418. max7315->gpio_base = gpio_base;
  419. if (intr != -1) {
  420. i2c_info->irq = intr + MRST_IRQ_OFFSET;
  421. max7315->irq_base = gpio_base + MRST_IRQ_OFFSET;
  422. } else {
  423. i2c_info->irq = -1;
  424. max7315->irq_base = -1;
  425. }
  426. return max7315;
  427. }
  428. static void __init *emc1403_platform_data(void *info)
  429. {
  430. static short intr2nd_pdata;
  431. struct i2c_board_info *i2c_info = info;
  432. int intr = get_gpio_by_name("thermal_int");
  433. int intr2nd = get_gpio_by_name("thermal_alert");
  434. if (intr == -1 || intr2nd == -1)
  435. return NULL;
  436. i2c_info->irq = intr + MRST_IRQ_OFFSET;
  437. intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
  438. return &intr2nd_pdata;
  439. }
  440. static void __init *lis331dl_platform_data(void *info)
  441. {
  442. static short intr2nd_pdata;
  443. struct i2c_board_info *i2c_info = info;
  444. int intr = get_gpio_by_name("accel_int");
  445. int intr2nd = get_gpio_by_name("accel_2");
  446. if (intr == -1 || intr2nd == -1)
  447. return NULL;
  448. i2c_info->irq = intr + MRST_IRQ_OFFSET;
  449. intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
  450. return &intr2nd_pdata;
  451. }
  452. static void __init *no_platform_data(void *info)
  453. {
  454. return NULL;
  455. }
  456. static struct resource msic_resources[] = {
  457. {
  458. .start = INTEL_MSIC_IRQ_PHYS_BASE,
  459. .end = INTEL_MSIC_IRQ_PHYS_BASE + 64 - 1,
  460. .flags = IORESOURCE_MEM,
  461. },
  462. };
  463. static struct intel_msic_platform_data msic_pdata;
  464. static struct platform_device msic_device = {
  465. .name = "intel_msic",
  466. .id = -1,
  467. .dev = {
  468. .platform_data = &msic_pdata,
  469. },
  470. .num_resources = ARRAY_SIZE(msic_resources),
  471. .resource = msic_resources,
  472. };
  473. static inline bool mrst_has_msic(void)
  474. {
  475. return mrst_identify_cpu() == MRST_CPU_CHIP_PENWELL;
  476. }
  477. static int msic_scu_status_change(struct notifier_block *nb,
  478. unsigned long code, void *data)
  479. {
  480. if (code == SCU_DOWN) {
  481. platform_device_unregister(&msic_device);
  482. return 0;
  483. }
  484. return platform_device_register(&msic_device);
  485. }
  486. static int __init msic_init(void)
  487. {
  488. static struct notifier_block msic_scu_notifier = {
  489. .notifier_call = msic_scu_status_change,
  490. };
  491. /*
  492. * We need to be sure that the SCU IPC is ready before MSIC device
  493. * can be registered.
  494. */
  495. if (mrst_has_msic())
  496. intel_scu_notifier_add(&msic_scu_notifier);
  497. return 0;
  498. }
  499. arch_initcall(msic_init);
  500. /*
  501. * msic_generic_platform_data - sets generic platform data for the block
  502. * @info: pointer to the SFI device table entry for this block
  503. * @block: MSIC block
  504. *
  505. * Function sets IRQ number from the SFI table entry for given device to
  506. * the MSIC platform data.
  507. */
  508. static void *msic_generic_platform_data(void *info, enum intel_msic_block block)
  509. {
  510. struct sfi_device_table_entry *entry = info;
  511. BUG_ON(block < 0 || block >= INTEL_MSIC_BLOCK_LAST);
  512. msic_pdata.irq[block] = entry->irq;
  513. return no_platform_data(info);
  514. }
  515. static void *msic_battery_platform_data(void *info)
  516. {
  517. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_BATTERY);
  518. }
  519. static void *msic_gpio_platform_data(void *info)
  520. {
  521. static struct intel_msic_gpio_pdata pdata;
  522. int gpio = get_gpio_by_name("msic_gpio_base");
  523. if (gpio < 0)
  524. return NULL;
  525. pdata.gpio_base = gpio;
  526. msic_pdata.gpio = &pdata;
  527. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_GPIO);
  528. }
  529. static void *msic_audio_platform_data(void *info)
  530. {
  531. struct platform_device *pdev;
  532. pdev = platform_device_register_simple("sst-platform", -1, NULL, 0);
  533. if (IS_ERR(pdev)) {
  534. pr_err("failed to create audio platform device\n");
  535. return NULL;
  536. }
  537. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_AUDIO);
  538. }
  539. static void *msic_power_btn_platform_data(void *info)
  540. {
  541. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_POWER_BTN);
  542. }
  543. static void *msic_ocd_platform_data(void *info)
  544. {
  545. static struct intel_msic_ocd_pdata pdata;
  546. int gpio = get_gpio_by_name("ocd_gpio");
  547. if (gpio < 0)
  548. return NULL;
  549. pdata.gpio = gpio;
  550. msic_pdata.ocd = &pdata;
  551. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_OCD);
  552. }
  553. static const struct devs_id __initconst device_ids[] = {
  554. {"bma023", SFI_DEV_TYPE_I2C, 1, &no_platform_data},
  555. {"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data},
  556. {"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data},
  557. {"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
  558. {"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
  559. {"emc1403", SFI_DEV_TYPE_I2C, 1, &emc1403_platform_data},
  560. {"i2c_accel", SFI_DEV_TYPE_I2C, 0, &lis331dl_platform_data},
  561. {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
  562. /* MSIC subdevices */
  563. {"msic_battery", SFI_DEV_TYPE_IPC, 1, &msic_battery_platform_data},
  564. {"msic_gpio", SFI_DEV_TYPE_IPC, 1, &msic_gpio_platform_data},
  565. {"msic_audio", SFI_DEV_TYPE_IPC, 1, &msic_audio_platform_data},
  566. {"msic_power_btn", SFI_DEV_TYPE_IPC, 1, &msic_power_btn_platform_data},
  567. {"msic_ocd", SFI_DEV_TYPE_IPC, 1, &msic_ocd_platform_data},
  568. {},
  569. };
  570. #define MAX_IPCDEVS 24
  571. static struct platform_device *ipc_devs[MAX_IPCDEVS];
  572. static int ipc_next_dev;
  573. #define MAX_SCU_SPI 24
  574. static struct spi_board_info *spi_devs[MAX_SCU_SPI];
  575. static int spi_next_dev;
  576. #define MAX_SCU_I2C 24
  577. static struct i2c_board_info *i2c_devs[MAX_SCU_I2C];
  578. static int i2c_bus[MAX_SCU_I2C];
  579. static int i2c_next_dev;
  580. static void __init intel_scu_device_register(struct platform_device *pdev)
  581. {
  582. if(ipc_next_dev == MAX_IPCDEVS)
  583. pr_err("too many SCU IPC devices");
  584. else
  585. ipc_devs[ipc_next_dev++] = pdev;
  586. }
  587. static void __init intel_scu_spi_device_register(struct spi_board_info *sdev)
  588. {
  589. struct spi_board_info *new_dev;
  590. if (spi_next_dev == MAX_SCU_SPI) {
  591. pr_err("too many SCU SPI devices");
  592. return;
  593. }
  594. new_dev = kzalloc(sizeof(*sdev), GFP_KERNEL);
  595. if (!new_dev) {
  596. pr_err("failed to alloc mem for delayed spi dev %s\n",
  597. sdev->modalias);
  598. return;
  599. }
  600. memcpy(new_dev, sdev, sizeof(*sdev));
  601. spi_devs[spi_next_dev++] = new_dev;
  602. }
  603. static void __init intel_scu_i2c_device_register(int bus,
  604. struct i2c_board_info *idev)
  605. {
  606. struct i2c_board_info *new_dev;
  607. if (i2c_next_dev == MAX_SCU_I2C) {
  608. pr_err("too many SCU I2C devices");
  609. return;
  610. }
  611. new_dev = kzalloc(sizeof(*idev), GFP_KERNEL);
  612. if (!new_dev) {
  613. pr_err("failed to alloc mem for delayed i2c dev %s\n",
  614. idev->type);
  615. return;
  616. }
  617. memcpy(new_dev, idev, sizeof(*idev));
  618. i2c_bus[i2c_next_dev] = bus;
  619. i2c_devs[i2c_next_dev++] = new_dev;
  620. }
  621. BLOCKING_NOTIFIER_HEAD(intel_scu_notifier);
  622. EXPORT_SYMBOL_GPL(intel_scu_notifier);
  623. /* Called by IPC driver */
  624. void intel_scu_devices_create(void)
  625. {
  626. int i;
  627. for (i = 0; i < ipc_next_dev; i++)
  628. platform_device_add(ipc_devs[i]);
  629. for (i = 0; i < spi_next_dev; i++)
  630. spi_register_board_info(spi_devs[i], 1);
  631. for (i = 0; i < i2c_next_dev; i++) {
  632. struct i2c_adapter *adapter;
  633. struct i2c_client *client;
  634. adapter = i2c_get_adapter(i2c_bus[i]);
  635. if (adapter) {
  636. client = i2c_new_device(adapter, i2c_devs[i]);
  637. if (!client)
  638. pr_err("can't create i2c device %s\n",
  639. i2c_devs[i]->type);
  640. } else
  641. i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1);
  642. }
  643. intel_scu_notifier_post(SCU_AVAILABLE, 0L);
  644. }
  645. EXPORT_SYMBOL_GPL(intel_scu_devices_create);
  646. /* Called by IPC driver */
  647. void intel_scu_devices_destroy(void)
  648. {
  649. int i;
  650. intel_scu_notifier_post(SCU_DOWN, 0L);
  651. for (i = 0; i < ipc_next_dev; i++)
  652. platform_device_del(ipc_devs[i]);
  653. }
  654. EXPORT_SYMBOL_GPL(intel_scu_devices_destroy);
  655. static void __init install_irq_resource(struct platform_device *pdev, int irq)
  656. {
  657. /* Single threaded */
  658. static struct resource __initdata res = {
  659. .name = "IRQ",
  660. .flags = IORESOURCE_IRQ,
  661. };
  662. res.start = irq;
  663. platform_device_add_resources(pdev, &res, 1);
  664. }
  665. static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *entry)
  666. {
  667. const struct devs_id *dev = device_ids;
  668. struct platform_device *pdev;
  669. void *pdata = NULL;
  670. while (dev->name[0]) {
  671. if (dev->type == SFI_DEV_TYPE_IPC &&
  672. !strncmp(dev->name, entry->name, SFI_NAME_LEN)) {
  673. pdata = dev->get_platform_data(entry);
  674. break;
  675. }
  676. dev++;
  677. }
  678. /*
  679. * On Medfield the platform device creation is handled by the MSIC
  680. * MFD driver so we don't need to do it here.
  681. */
  682. if (mrst_has_msic())
  683. return;
  684. pdev = platform_device_alloc(entry->name, 0);
  685. if (pdev == NULL) {
  686. pr_err("out of memory for SFI platform device '%s'.\n",
  687. entry->name);
  688. return;
  689. }
  690. install_irq_resource(pdev, entry->irq);
  691. pdev->dev.platform_data = pdata;
  692. intel_scu_device_register(pdev);
  693. }
  694. static void __init sfi_handle_spi_dev(struct spi_board_info *spi_info)
  695. {
  696. const struct devs_id *dev = device_ids;
  697. void *pdata = NULL;
  698. while (dev->name[0]) {
  699. if (dev->type == SFI_DEV_TYPE_SPI &&
  700. !strncmp(dev->name, spi_info->modalias, SFI_NAME_LEN)) {
  701. pdata = dev->get_platform_data(spi_info);
  702. break;
  703. }
  704. dev++;
  705. }
  706. spi_info->platform_data = pdata;
  707. if (dev->delay)
  708. intel_scu_spi_device_register(spi_info);
  709. else
  710. spi_register_board_info(spi_info, 1);
  711. }
  712. static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info)
  713. {
  714. const struct devs_id *dev = device_ids;
  715. void *pdata = NULL;
  716. while (dev->name[0]) {
  717. if (dev->type == SFI_DEV_TYPE_I2C &&
  718. !strncmp(dev->name, i2c_info->type, SFI_NAME_LEN)) {
  719. pdata = dev->get_platform_data(i2c_info);
  720. break;
  721. }
  722. dev++;
  723. }
  724. i2c_info->platform_data = pdata;
  725. if (dev->delay)
  726. intel_scu_i2c_device_register(bus, i2c_info);
  727. else
  728. i2c_register_board_info(bus, i2c_info, 1);
  729. }
  730. static int __init sfi_parse_devs(struct sfi_table_header *table)
  731. {
  732. struct sfi_table_simple *sb;
  733. struct sfi_device_table_entry *pentry;
  734. struct spi_board_info spi_info;
  735. struct i2c_board_info i2c_info;
  736. int num, i, bus;
  737. int ioapic;
  738. struct io_apic_irq_attr irq_attr;
  739. sb = (struct sfi_table_simple *)table;
  740. num = SFI_GET_NUM_ENTRIES(sb, struct sfi_device_table_entry);
  741. pentry = (struct sfi_device_table_entry *)sb->pentry;
  742. for (i = 0; i < num; i++, pentry++) {
  743. int irq = pentry->irq;
  744. if (irq != (u8)0xff) { /* native RTE case */
  745. /* these SPI2 devices are not exposed to system as PCI
  746. * devices, but they have separate RTE entry in IOAPIC
  747. * so we have to enable them one by one here
  748. */
  749. ioapic = mp_find_ioapic(irq);
  750. irq_attr.ioapic = ioapic;
  751. irq_attr.ioapic_pin = irq;
  752. irq_attr.trigger = 1;
  753. irq_attr.polarity = 1;
  754. io_apic_set_pci_routing(NULL, irq, &irq_attr);
  755. } else
  756. irq = 0; /* No irq */
  757. switch (pentry->type) {
  758. case SFI_DEV_TYPE_IPC:
  759. pr_debug("info[%2d]: IPC bus, name = %16.16s, "
  760. "irq = 0x%2x\n", i, pentry->name, pentry->irq);
  761. sfi_handle_ipc_dev(pentry);
  762. break;
  763. case SFI_DEV_TYPE_SPI:
  764. memset(&spi_info, 0, sizeof(spi_info));
  765. strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
  766. spi_info.irq = irq;
  767. spi_info.bus_num = pentry->host_num;
  768. spi_info.chip_select = pentry->addr;
  769. spi_info.max_speed_hz = pentry->max_freq;
  770. pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, "
  771. "irq = 0x%2x, max_freq = %d, cs = %d\n", i,
  772. spi_info.bus_num,
  773. spi_info.modalias,
  774. spi_info.irq,
  775. spi_info.max_speed_hz,
  776. spi_info.chip_select);
  777. sfi_handle_spi_dev(&spi_info);
  778. break;
  779. case SFI_DEV_TYPE_I2C:
  780. memset(&i2c_info, 0, sizeof(i2c_info));
  781. bus = pentry->host_num;
  782. strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
  783. i2c_info.irq = irq;
  784. i2c_info.addr = pentry->addr;
  785. pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, "
  786. "irq = 0x%2x, addr = 0x%x\n", i, bus,
  787. i2c_info.type,
  788. i2c_info.irq,
  789. i2c_info.addr);
  790. sfi_handle_i2c_dev(bus, &i2c_info);
  791. break;
  792. case SFI_DEV_TYPE_UART:
  793. case SFI_DEV_TYPE_HSI:
  794. default:
  795. ;
  796. }
  797. }
  798. return 0;
  799. }
  800. static int __init mrst_platform_init(void)
  801. {
  802. sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
  803. sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
  804. return 0;
  805. }
  806. arch_initcall(mrst_platform_init);
  807. /*
  808. * we will search these buttons in SFI GPIO table (by name)
  809. * and register them dynamically. Please add all possible
  810. * buttons here, we will shrink them if no GPIO found.
  811. */
  812. static struct gpio_keys_button gpio_button[] = {
  813. {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
  814. {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
  815. {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
  816. {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
  817. {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
  818. {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
  819. {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
  820. {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
  821. {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
  822. {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
  823. };
  824. static struct gpio_keys_platform_data mrst_gpio_keys = {
  825. .buttons = gpio_button,
  826. .rep = 1,
  827. .nbuttons = -1, /* will fill it after search */
  828. };
  829. static struct platform_device pb_device = {
  830. .name = "gpio-keys",
  831. .id = -1,
  832. .dev = {
  833. .platform_data = &mrst_gpio_keys,
  834. },
  835. };
  836. /*
  837. * Shrink the non-existent buttons, register the gpio button
  838. * device if there is some
  839. */
  840. static int __init pb_keys_init(void)
  841. {
  842. struct gpio_keys_button *gb = gpio_button;
  843. int i, num, good = 0;
  844. num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
  845. for (i = 0; i < num; i++) {
  846. gb[i].gpio = get_gpio_by_name(gb[i].desc);
  847. pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc, gb[i].gpio);
  848. if (gb[i].gpio == -1)
  849. continue;
  850. if (i != good)
  851. gb[good] = gb[i];
  852. good++;
  853. }
  854. if (good) {
  855. mrst_gpio_keys.nbuttons = good;
  856. return platform_device_register(&pb_device);
  857. }
  858. return 0;
  859. }
  860. late_initcall(pb_keys_init);