mrst.c 27 KB

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