mrst.c 25 KB

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