mrst.c 21 KB

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