mrst.c 22 KB

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