mrst.c 22 KB

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