mrst.c 21 KB

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