mrst.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  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 = (struct sfi_gpio_table_entry *)
  316. kmalloc(num * sizeof(*pentry), GFP_KERNEL);
  317. if (!gpio_table)
  318. return -1;
  319. memcpy(gpio_table, pentry, num * sizeof(*pentry));
  320. gpio_num_entry = num;
  321. pr_debug("GPIO pin info:\n");
  322. for (i = 0; i < num; i++, pentry++)
  323. pr_debug("info[%2d]: controller = %16.16s, pin_name = %16.16s,"
  324. " pin = %d\n", i,
  325. pentry->controller_name,
  326. pentry->pin_name,
  327. pentry->pin_no);
  328. return 0;
  329. }
  330. static int get_gpio_by_name(const char *name)
  331. {
  332. struct sfi_gpio_table_entry *pentry = gpio_table;
  333. int i;
  334. if (!pentry)
  335. return -1;
  336. for (i = 0; i < gpio_num_entry; i++, pentry++) {
  337. if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
  338. return pentry->pin_no;
  339. }
  340. return -1;
  341. }
  342. /*
  343. * Here defines the array of devices platform data that IAFW would export
  344. * through SFI "DEVS" table, we use name and type to match the device and
  345. * its platform data.
  346. */
  347. struct devs_id {
  348. char name[SFI_NAME_LEN + 1];
  349. u8 type;
  350. u8 delay;
  351. void *(*get_platform_data)(void *info);
  352. };
  353. /* the offset for the mapping of global gpio pin to irq */
  354. #define MRST_IRQ_OFFSET 0x100
  355. static void __init *pmic_gpio_platform_data(void *info)
  356. {
  357. static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
  358. int gpio_base = get_gpio_by_name("pmic_gpio_base");
  359. if (gpio_base == -1)
  360. gpio_base = 64;
  361. pmic_gpio_pdata.gpio_base = gpio_base;
  362. pmic_gpio_pdata.irq_base = gpio_base + MRST_IRQ_OFFSET;
  363. pmic_gpio_pdata.gpiointr = 0xffffeff8;
  364. return &pmic_gpio_pdata;
  365. }
  366. static void __init *max3111_platform_data(void *info)
  367. {
  368. struct spi_board_info *spi_info = info;
  369. int intr = get_gpio_by_name("max3111_int");
  370. spi_info->mode = SPI_MODE_0;
  371. if (intr == -1)
  372. return NULL;
  373. spi_info->irq = intr + MRST_IRQ_OFFSET;
  374. return NULL;
  375. }
  376. /* we have multiple max7315 on the board ... */
  377. #define MAX7315_NUM 2
  378. static void __init *max7315_platform_data(void *info)
  379. {
  380. static struct pca953x_platform_data max7315_pdata[MAX7315_NUM];
  381. static int nr;
  382. struct pca953x_platform_data *max7315 = &max7315_pdata[nr];
  383. struct i2c_board_info *i2c_info = info;
  384. int gpio_base, intr;
  385. char base_pin_name[SFI_NAME_LEN + 1];
  386. char intr_pin_name[SFI_NAME_LEN + 1];
  387. if (nr == MAX7315_NUM) {
  388. pr_err("too many max7315s, we only support %d\n",
  389. MAX7315_NUM);
  390. return NULL;
  391. }
  392. /* we have several max7315 on the board, we only need load several
  393. * instances of the same pca953x driver to cover them
  394. */
  395. strcpy(i2c_info->type, "max7315");
  396. if (nr++) {
  397. sprintf(base_pin_name, "max7315_%d_base", nr);
  398. sprintf(intr_pin_name, "max7315_%d_int", nr);
  399. } else {
  400. strcpy(base_pin_name, "max7315_base");
  401. strcpy(intr_pin_name, "max7315_int");
  402. }
  403. gpio_base = get_gpio_by_name(base_pin_name);
  404. intr = get_gpio_by_name(intr_pin_name);
  405. if (gpio_base == -1)
  406. return NULL;
  407. max7315->gpio_base = gpio_base;
  408. if (intr != -1) {
  409. i2c_info->irq = intr + MRST_IRQ_OFFSET;
  410. max7315->irq_base = gpio_base + MRST_IRQ_OFFSET;
  411. } else {
  412. i2c_info->irq = -1;
  413. max7315->irq_base = -1;
  414. }
  415. return max7315;
  416. }
  417. static void *tca6416_platform_data(void *info)
  418. {
  419. static struct pca953x_platform_data tca6416;
  420. struct i2c_board_info *i2c_info = info;
  421. int gpio_base, intr;
  422. char base_pin_name[SFI_NAME_LEN + 1];
  423. char intr_pin_name[SFI_NAME_LEN + 1];
  424. strcpy(i2c_info->type, "tca6416");
  425. strcpy(base_pin_name, "tca6416_base");
  426. strcpy(intr_pin_name, "tca6416_int");
  427. gpio_base = get_gpio_by_name(base_pin_name);
  428. intr = get_gpio_by_name(intr_pin_name);
  429. if (gpio_base == -1)
  430. return NULL;
  431. tca6416.gpio_base = gpio_base;
  432. if (intr != -1) {
  433. i2c_info->irq = intr + MRST_IRQ_OFFSET;
  434. tca6416.irq_base = gpio_base + MRST_IRQ_OFFSET;
  435. } else {
  436. i2c_info->irq = -1;
  437. tca6416.irq_base = -1;
  438. }
  439. return &tca6416;
  440. }
  441. static void *mpu3050_platform_data(void *info)
  442. {
  443. struct i2c_board_info *i2c_info = info;
  444. int intr = get_gpio_by_name("mpu3050_int");
  445. if (intr == -1)
  446. return NULL;
  447. i2c_info->irq = intr + MRST_IRQ_OFFSET;
  448. return NULL;
  449. }
  450. static void __init *emc1403_platform_data(void *info)
  451. {
  452. static short intr2nd_pdata;
  453. struct i2c_board_info *i2c_info = info;
  454. int intr = get_gpio_by_name("thermal_int");
  455. int intr2nd = get_gpio_by_name("thermal_alert");
  456. if (intr == -1 || intr2nd == -1)
  457. return NULL;
  458. i2c_info->irq = intr + MRST_IRQ_OFFSET;
  459. intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
  460. return &intr2nd_pdata;
  461. }
  462. static void __init *lis331dl_platform_data(void *info)
  463. {
  464. static short intr2nd_pdata;
  465. struct i2c_board_info *i2c_info = info;
  466. int intr = get_gpio_by_name("accel_int");
  467. int intr2nd = get_gpio_by_name("accel_2");
  468. if (intr == -1 || intr2nd == -1)
  469. return NULL;
  470. i2c_info->irq = intr + MRST_IRQ_OFFSET;
  471. intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
  472. return &intr2nd_pdata;
  473. }
  474. static void __init *no_platform_data(void *info)
  475. {
  476. return NULL;
  477. }
  478. static struct resource msic_resources[] = {
  479. {
  480. .start = INTEL_MSIC_IRQ_PHYS_BASE,
  481. .end = INTEL_MSIC_IRQ_PHYS_BASE + 64 - 1,
  482. .flags = IORESOURCE_MEM,
  483. },
  484. };
  485. static struct intel_msic_platform_data msic_pdata;
  486. static struct platform_device msic_device = {
  487. .name = "intel_msic",
  488. .id = -1,
  489. .dev = {
  490. .platform_data = &msic_pdata,
  491. },
  492. .num_resources = ARRAY_SIZE(msic_resources),
  493. .resource = msic_resources,
  494. };
  495. static inline bool mrst_has_msic(void)
  496. {
  497. return mrst_identify_cpu() == MRST_CPU_CHIP_PENWELL;
  498. }
  499. static int msic_scu_status_change(struct notifier_block *nb,
  500. unsigned long code, void *data)
  501. {
  502. if (code == SCU_DOWN) {
  503. platform_device_unregister(&msic_device);
  504. return 0;
  505. }
  506. return platform_device_register(&msic_device);
  507. }
  508. static int __init msic_init(void)
  509. {
  510. static struct notifier_block msic_scu_notifier = {
  511. .notifier_call = msic_scu_status_change,
  512. };
  513. /*
  514. * We need to be sure that the SCU IPC is ready before MSIC device
  515. * can be registered.
  516. */
  517. if (mrst_has_msic())
  518. intel_scu_notifier_add(&msic_scu_notifier);
  519. return 0;
  520. }
  521. arch_initcall(msic_init);
  522. /*
  523. * msic_generic_platform_data - sets generic platform data for the block
  524. * @info: pointer to the SFI device table entry for this block
  525. * @block: MSIC block
  526. *
  527. * Function sets IRQ number from the SFI table entry for given device to
  528. * the MSIC platform data.
  529. */
  530. static void *msic_generic_platform_data(void *info, enum intel_msic_block block)
  531. {
  532. struct sfi_device_table_entry *entry = info;
  533. BUG_ON(block < 0 || block >= INTEL_MSIC_BLOCK_LAST);
  534. msic_pdata.irq[block] = entry->irq;
  535. return no_platform_data(info);
  536. }
  537. static void *msic_battery_platform_data(void *info)
  538. {
  539. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_BATTERY);
  540. }
  541. static void *msic_gpio_platform_data(void *info)
  542. {
  543. static struct intel_msic_gpio_pdata pdata;
  544. int gpio = get_gpio_by_name("msic_gpio_base");
  545. if (gpio < 0)
  546. return NULL;
  547. pdata.gpio_base = gpio;
  548. msic_pdata.gpio = &pdata;
  549. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_GPIO);
  550. }
  551. static void *msic_audio_platform_data(void *info)
  552. {
  553. struct platform_device *pdev;
  554. pdev = platform_device_register_simple("sst-platform", -1, NULL, 0);
  555. if (IS_ERR(pdev)) {
  556. pr_err("failed to create audio platform device\n");
  557. return NULL;
  558. }
  559. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_AUDIO);
  560. }
  561. static void *msic_power_btn_platform_data(void *info)
  562. {
  563. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_POWER_BTN);
  564. }
  565. static void *msic_ocd_platform_data(void *info)
  566. {
  567. static struct intel_msic_ocd_pdata pdata;
  568. int gpio = get_gpio_by_name("ocd_gpio");
  569. if (gpio < 0)
  570. return NULL;
  571. pdata.gpio = gpio;
  572. msic_pdata.ocd = &pdata;
  573. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_OCD);
  574. }
  575. static void *msic_thermal_platform_data(void *info)
  576. {
  577. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_THERMAL);
  578. }
  579. /* tc35876x DSI-LVDS bridge chip and panel platform data */
  580. static void *tc35876x_platform_data(void *data)
  581. {
  582. static struct tc35876x_platform_data pdata;
  583. /* gpio pins set to -1 will not be used by the driver */
  584. pdata.gpio_bridge_reset = get_gpio_by_name("LCMB_RXEN");
  585. pdata.gpio_panel_bl_en = get_gpio_by_name("6S6P_BL_EN");
  586. pdata.gpio_panel_vadd = get_gpio_by_name("EN_VREG_LCD_V3P3");
  587. return &pdata;
  588. }
  589. static const struct devs_id __initconst device_ids[] = {
  590. {"bma023", SFI_DEV_TYPE_I2C, 1, &no_platform_data},
  591. {"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data},
  592. {"pmic_gpio", SFI_DEV_TYPE_IPC, 1, &pmic_gpio_platform_data},
  593. {"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data},
  594. {"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
  595. {"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
  596. {"tca6416", SFI_DEV_TYPE_I2C, 1, &tca6416_platform_data},
  597. {"emc1403", SFI_DEV_TYPE_I2C, 1, &emc1403_platform_data},
  598. {"i2c_accel", SFI_DEV_TYPE_I2C, 0, &lis331dl_platform_data},
  599. {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
  600. {"mpu3050", SFI_DEV_TYPE_I2C, 1, &mpu3050_platform_data},
  601. {"i2c_disp_brig", SFI_DEV_TYPE_I2C, 0, &tc35876x_platform_data},
  602. /* MSIC subdevices */
  603. {"msic_battery", SFI_DEV_TYPE_IPC, 1, &msic_battery_platform_data},
  604. {"msic_gpio", SFI_DEV_TYPE_IPC, 1, &msic_gpio_platform_data},
  605. {"msic_audio", SFI_DEV_TYPE_IPC, 1, &msic_audio_platform_data},
  606. {"msic_power_btn", SFI_DEV_TYPE_IPC, 1, &msic_power_btn_platform_data},
  607. {"msic_ocd", SFI_DEV_TYPE_IPC, 1, &msic_ocd_platform_data},
  608. {"msic_thermal", SFI_DEV_TYPE_IPC, 1, &msic_thermal_platform_data},
  609. {},
  610. };
  611. #define MAX_IPCDEVS 24
  612. static struct platform_device *ipc_devs[MAX_IPCDEVS];
  613. static int ipc_next_dev;
  614. #define MAX_SCU_SPI 24
  615. static struct spi_board_info *spi_devs[MAX_SCU_SPI];
  616. static int spi_next_dev;
  617. #define MAX_SCU_I2C 24
  618. static struct i2c_board_info *i2c_devs[MAX_SCU_I2C];
  619. static int i2c_bus[MAX_SCU_I2C];
  620. static int i2c_next_dev;
  621. static void __init intel_scu_device_register(struct platform_device *pdev)
  622. {
  623. if(ipc_next_dev == MAX_IPCDEVS)
  624. pr_err("too many SCU IPC devices");
  625. else
  626. ipc_devs[ipc_next_dev++] = pdev;
  627. }
  628. static void __init intel_scu_spi_device_register(struct spi_board_info *sdev)
  629. {
  630. struct spi_board_info *new_dev;
  631. if (spi_next_dev == MAX_SCU_SPI) {
  632. pr_err("too many SCU SPI devices");
  633. return;
  634. }
  635. new_dev = kzalloc(sizeof(*sdev), GFP_KERNEL);
  636. if (!new_dev) {
  637. pr_err("failed to alloc mem for delayed spi dev %s\n",
  638. sdev->modalias);
  639. return;
  640. }
  641. memcpy(new_dev, sdev, sizeof(*sdev));
  642. spi_devs[spi_next_dev++] = new_dev;
  643. }
  644. static void __init intel_scu_i2c_device_register(int bus,
  645. struct i2c_board_info *idev)
  646. {
  647. struct i2c_board_info *new_dev;
  648. if (i2c_next_dev == MAX_SCU_I2C) {
  649. pr_err("too many SCU I2C devices");
  650. return;
  651. }
  652. new_dev = kzalloc(sizeof(*idev), GFP_KERNEL);
  653. if (!new_dev) {
  654. pr_err("failed to alloc mem for delayed i2c dev %s\n",
  655. idev->type);
  656. return;
  657. }
  658. memcpy(new_dev, idev, sizeof(*idev));
  659. i2c_bus[i2c_next_dev] = bus;
  660. i2c_devs[i2c_next_dev++] = new_dev;
  661. }
  662. BLOCKING_NOTIFIER_HEAD(intel_scu_notifier);
  663. EXPORT_SYMBOL_GPL(intel_scu_notifier);
  664. /* Called by IPC driver */
  665. void intel_scu_devices_create(void)
  666. {
  667. int i;
  668. for (i = 0; i < ipc_next_dev; i++)
  669. platform_device_add(ipc_devs[i]);
  670. for (i = 0; i < spi_next_dev; i++)
  671. spi_register_board_info(spi_devs[i], 1);
  672. for (i = 0; i < i2c_next_dev; i++) {
  673. struct i2c_adapter *adapter;
  674. struct i2c_client *client;
  675. adapter = i2c_get_adapter(i2c_bus[i]);
  676. if (adapter) {
  677. client = i2c_new_device(adapter, i2c_devs[i]);
  678. if (!client)
  679. pr_err("can't create i2c device %s\n",
  680. i2c_devs[i]->type);
  681. } else
  682. i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1);
  683. }
  684. intel_scu_notifier_post(SCU_AVAILABLE, NULL);
  685. }
  686. EXPORT_SYMBOL_GPL(intel_scu_devices_create);
  687. /* Called by IPC driver */
  688. void intel_scu_devices_destroy(void)
  689. {
  690. int i;
  691. intel_scu_notifier_post(SCU_DOWN, NULL);
  692. for (i = 0; i < ipc_next_dev; i++)
  693. platform_device_del(ipc_devs[i]);
  694. }
  695. EXPORT_SYMBOL_GPL(intel_scu_devices_destroy);
  696. static void __init install_irq_resource(struct platform_device *pdev, int irq)
  697. {
  698. /* Single threaded */
  699. static struct resource __initdata res = {
  700. .name = "IRQ",
  701. .flags = IORESOURCE_IRQ,
  702. };
  703. res.start = irq;
  704. platform_device_add_resources(pdev, &res, 1);
  705. }
  706. static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *entry)
  707. {
  708. const struct devs_id *dev = device_ids;
  709. struct platform_device *pdev;
  710. void *pdata = NULL;
  711. while (dev->name[0]) {
  712. if (dev->type == SFI_DEV_TYPE_IPC &&
  713. !strncmp(dev->name, entry->name, SFI_NAME_LEN)) {
  714. pdata = dev->get_platform_data(entry);
  715. break;
  716. }
  717. dev++;
  718. }
  719. /*
  720. * On Medfield the platform device creation is handled by the MSIC
  721. * MFD driver so we don't need to do it here.
  722. */
  723. if (mrst_has_msic())
  724. return;
  725. pdev = platform_device_alloc(entry->name, 0);
  726. if (pdev == NULL) {
  727. pr_err("out of memory for SFI platform device '%s'.\n",
  728. entry->name);
  729. return;
  730. }
  731. install_irq_resource(pdev, entry->irq);
  732. pdev->dev.platform_data = pdata;
  733. intel_scu_device_register(pdev);
  734. }
  735. static void __init sfi_handle_spi_dev(struct spi_board_info *spi_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_SPI &&
  741. !strncmp(dev->name, spi_info->modalias, SFI_NAME_LEN)) {
  742. pdata = dev->get_platform_data(spi_info);
  743. break;
  744. }
  745. dev++;
  746. }
  747. spi_info->platform_data = pdata;
  748. if (dev->delay)
  749. intel_scu_spi_device_register(spi_info);
  750. else
  751. spi_register_board_info(spi_info, 1);
  752. }
  753. static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info)
  754. {
  755. const struct devs_id *dev = device_ids;
  756. void *pdata = NULL;
  757. while (dev->name[0]) {
  758. if (dev->type == SFI_DEV_TYPE_I2C &&
  759. !strncmp(dev->name, i2c_info->type, SFI_NAME_LEN)) {
  760. pdata = dev->get_platform_data(i2c_info);
  761. break;
  762. }
  763. dev++;
  764. }
  765. i2c_info->platform_data = pdata;
  766. if (dev->delay)
  767. intel_scu_i2c_device_register(bus, i2c_info);
  768. else
  769. i2c_register_board_info(bus, i2c_info, 1);
  770. }
  771. static int __init sfi_parse_devs(struct sfi_table_header *table)
  772. {
  773. struct sfi_table_simple *sb;
  774. struct sfi_device_table_entry *pentry;
  775. struct spi_board_info spi_info;
  776. struct i2c_board_info i2c_info;
  777. int num, i, bus;
  778. int ioapic;
  779. struct io_apic_irq_attr irq_attr;
  780. sb = (struct sfi_table_simple *)table;
  781. num = SFI_GET_NUM_ENTRIES(sb, struct sfi_device_table_entry);
  782. pentry = (struct sfi_device_table_entry *)sb->pentry;
  783. for (i = 0; i < num; i++, pentry++) {
  784. int irq = pentry->irq;
  785. if (irq != (u8)0xff) { /* native RTE case */
  786. /* these SPI2 devices are not exposed to system as PCI
  787. * devices, but they have separate RTE entry in IOAPIC
  788. * so we have to enable them one by one here
  789. */
  790. ioapic = mp_find_ioapic(irq);
  791. irq_attr.ioapic = ioapic;
  792. irq_attr.ioapic_pin = irq;
  793. irq_attr.trigger = 1;
  794. irq_attr.polarity = 1;
  795. io_apic_set_pci_routing(NULL, irq, &irq_attr);
  796. } else
  797. irq = 0; /* No irq */
  798. switch (pentry->type) {
  799. case SFI_DEV_TYPE_IPC:
  800. pr_debug("info[%2d]: IPC bus, name = %16.16s, "
  801. "irq = 0x%2x\n", i, pentry->name, pentry->irq);
  802. sfi_handle_ipc_dev(pentry);
  803. break;
  804. case SFI_DEV_TYPE_SPI:
  805. memset(&spi_info, 0, sizeof(spi_info));
  806. strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
  807. spi_info.irq = irq;
  808. spi_info.bus_num = pentry->host_num;
  809. spi_info.chip_select = pentry->addr;
  810. spi_info.max_speed_hz = pentry->max_freq;
  811. pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, "
  812. "irq = 0x%2x, max_freq = %d, cs = %d\n", i,
  813. spi_info.bus_num,
  814. spi_info.modalias,
  815. spi_info.irq,
  816. spi_info.max_speed_hz,
  817. spi_info.chip_select);
  818. sfi_handle_spi_dev(&spi_info);
  819. break;
  820. case SFI_DEV_TYPE_I2C:
  821. memset(&i2c_info, 0, sizeof(i2c_info));
  822. bus = pentry->host_num;
  823. strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
  824. i2c_info.irq = irq;
  825. i2c_info.addr = pentry->addr;
  826. pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, "
  827. "irq = 0x%2x, addr = 0x%x\n", i, bus,
  828. i2c_info.type,
  829. i2c_info.irq,
  830. i2c_info.addr);
  831. sfi_handle_i2c_dev(bus, &i2c_info);
  832. break;
  833. case SFI_DEV_TYPE_UART:
  834. case SFI_DEV_TYPE_HSI:
  835. default:
  836. ;
  837. }
  838. }
  839. return 0;
  840. }
  841. static int __init mrst_platform_init(void)
  842. {
  843. sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
  844. sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
  845. return 0;
  846. }
  847. arch_initcall(mrst_platform_init);
  848. /*
  849. * we will search these buttons in SFI GPIO table (by name)
  850. * and register them dynamically. Please add all possible
  851. * buttons here, we will shrink them if no GPIO found.
  852. */
  853. static struct gpio_keys_button gpio_button[] = {
  854. {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
  855. {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
  856. {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
  857. {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
  858. {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
  859. {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
  860. {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
  861. {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
  862. {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
  863. {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
  864. };
  865. static struct gpio_keys_platform_data mrst_gpio_keys = {
  866. .buttons = gpio_button,
  867. .rep = 1,
  868. .nbuttons = -1, /* will fill it after search */
  869. };
  870. static struct platform_device pb_device = {
  871. .name = "gpio-keys",
  872. .id = -1,
  873. .dev = {
  874. .platform_data = &mrst_gpio_keys,
  875. },
  876. };
  877. /*
  878. * Shrink the non-existent buttons, register the gpio button
  879. * device if there is some
  880. */
  881. static int __init pb_keys_init(void)
  882. {
  883. struct gpio_keys_button *gb = gpio_button;
  884. int i, num, good = 0;
  885. num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
  886. for (i = 0; i < num; i++) {
  887. gb[i].gpio = get_gpio_by_name(gb[i].desc);
  888. pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc, gb[i].gpio);
  889. if (gb[i].gpio == -1)
  890. continue;
  891. if (i != good)
  892. gb[good] = gb[i];
  893. good++;
  894. }
  895. if (good) {
  896. mrst_gpio_keys.nbuttons = good;
  897. return platform_device_register(&pb_device);
  898. }
  899. return 0;
  900. }
  901. late_initcall(pb_keys_init);