mrst.c 26 KB

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