mrst.c 28 KB

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