mrst.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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_IOAPIC;
  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 = 0;
  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_IOAPIC;
  154. mp_irq.irqtype = mp_INT;
  155. mp_irq.irqflag = 0xf; /* level trigger and active low */
  156. mp_irq.srcbus = 0;
  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. 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. 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. }
  250. /*
  251. * if user does not want to use per CPU apb timer, just give it a lower rating
  252. * than local apic timer and skip the late per cpu timer init.
  253. */
  254. static inline int __init setup_x86_mrst_timer(char *arg)
  255. {
  256. if (!arg)
  257. return -EINVAL;
  258. if (strcmp("apbt_only", arg) == 0)
  259. mrst_timer_options = MRST_TIMER_APBT_ONLY;
  260. else if (strcmp("lapic_and_apbt", arg) == 0)
  261. mrst_timer_options = MRST_TIMER_LAPIC_APBT;
  262. else {
  263. pr_warning("X86 MRST timer option %s not recognised"
  264. " use x86_mrst_timer=apbt_only or lapic_and_apbt\n",
  265. arg);
  266. return -EINVAL;
  267. }
  268. return 0;
  269. }
  270. __setup("x86_mrst_timer=", setup_x86_mrst_timer);
  271. /*
  272. * Parsing GPIO table first, since the DEVS table will need this table
  273. * to map the pin name to the actual pin.
  274. */
  275. static struct sfi_gpio_table_entry *gpio_table;
  276. static int gpio_num_entry;
  277. static int __init sfi_parse_gpio(struct sfi_table_header *table)
  278. {
  279. struct sfi_table_simple *sb;
  280. struct sfi_gpio_table_entry *pentry;
  281. int num, i;
  282. if (gpio_table)
  283. return 0;
  284. sb = (struct sfi_table_simple *)table;
  285. num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
  286. pentry = (struct sfi_gpio_table_entry *)sb->pentry;
  287. gpio_table = (struct sfi_gpio_table_entry *)
  288. kmalloc(num * sizeof(*pentry), GFP_KERNEL);
  289. if (!gpio_table)
  290. return -1;
  291. memcpy(gpio_table, pentry, num * sizeof(*pentry));
  292. gpio_num_entry = num;
  293. pr_debug("GPIO pin info:\n");
  294. for (i = 0; i < num; i++, pentry++)
  295. pr_debug("info[%2d]: controller = %16.16s, pin_name = %16.16s,"
  296. " pin = %d\n", i,
  297. pentry->controller_name,
  298. pentry->pin_name,
  299. pentry->pin_no);
  300. return 0;
  301. }
  302. static int get_gpio_by_name(const char *name)
  303. {
  304. struct sfi_gpio_table_entry *pentry = gpio_table;
  305. int i;
  306. if (!pentry)
  307. return -1;
  308. for (i = 0; i < gpio_num_entry; i++, pentry++) {
  309. if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
  310. return pentry->pin_no;
  311. }
  312. return -1;
  313. }
  314. /*
  315. * Here defines the array of devices platform data that IAFW would export
  316. * through SFI "DEVS" table, we use name and type to match the device and
  317. * its platform data.
  318. */
  319. struct devs_id {
  320. char name[SFI_NAME_LEN + 1];
  321. u8 type;
  322. u8 delay;
  323. void *(*get_platform_data)(void *info);
  324. };
  325. /* the offset for the mapping of global gpio pin to irq */
  326. #define MRST_IRQ_OFFSET 0x100
  327. static void __init *pmic_gpio_platform_data(void *info)
  328. {
  329. static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
  330. int gpio_base = get_gpio_by_name("pmic_gpio_base");
  331. if (gpio_base == -1)
  332. gpio_base = 64;
  333. pmic_gpio_pdata.gpio_base = gpio_base;
  334. pmic_gpio_pdata.irq_base = gpio_base + MRST_IRQ_OFFSET;
  335. pmic_gpio_pdata.gpiointr = 0xffffeff8;
  336. return &pmic_gpio_pdata;
  337. }
  338. static void __init *max3111_platform_data(void *info)
  339. {
  340. struct spi_board_info *spi_info = info;
  341. int intr = get_gpio_by_name("max3111_int");
  342. if (intr == -1)
  343. return NULL;
  344. spi_info->irq = intr + MRST_IRQ_OFFSET;
  345. return NULL;
  346. }
  347. /* we have multiple max7315 on the board ... */
  348. #define MAX7315_NUM 2
  349. static void __init *max7315_platform_data(void *info)
  350. {
  351. static struct pca953x_platform_data max7315_pdata[MAX7315_NUM];
  352. static int nr;
  353. struct pca953x_platform_data *max7315 = &max7315_pdata[nr];
  354. struct i2c_board_info *i2c_info = info;
  355. int gpio_base, intr;
  356. char base_pin_name[SFI_NAME_LEN + 1];
  357. char intr_pin_name[SFI_NAME_LEN + 1];
  358. if (nr == MAX7315_NUM) {
  359. pr_err("too many max7315s, we only support %d\n",
  360. MAX7315_NUM);
  361. return NULL;
  362. }
  363. /* we have several max7315 on the board, we only need load several
  364. * instances of the same pca953x driver to cover them
  365. */
  366. strcpy(i2c_info->type, "max7315");
  367. if (nr++) {
  368. sprintf(base_pin_name, "max7315_%d_base", nr);
  369. sprintf(intr_pin_name, "max7315_%d_int", nr);
  370. } else {
  371. strcpy(base_pin_name, "max7315_base");
  372. strcpy(intr_pin_name, "max7315_int");
  373. }
  374. gpio_base = get_gpio_by_name(base_pin_name);
  375. intr = get_gpio_by_name(intr_pin_name);
  376. if (gpio_base == -1)
  377. return NULL;
  378. max7315->gpio_base = gpio_base;
  379. if (intr != -1) {
  380. i2c_info->irq = intr + MRST_IRQ_OFFSET;
  381. max7315->irq_base = gpio_base + MRST_IRQ_OFFSET;
  382. } else {
  383. i2c_info->irq = -1;
  384. max7315->irq_base = -1;
  385. }
  386. return max7315;
  387. }
  388. static void __init *emc1403_platform_data(void *info)
  389. {
  390. static short intr2nd_pdata;
  391. struct i2c_board_info *i2c_info = info;
  392. int intr = get_gpio_by_name("thermal_int");
  393. int intr2nd = get_gpio_by_name("thermal_alert");
  394. if (intr == -1 || intr2nd == -1)
  395. return NULL;
  396. i2c_info->irq = intr + MRST_IRQ_OFFSET;
  397. intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
  398. return &intr2nd_pdata;
  399. }
  400. static void __init *lis331dl_platform_data(void *info)
  401. {
  402. static short intr2nd_pdata;
  403. struct i2c_board_info *i2c_info = info;
  404. int intr = get_gpio_by_name("accel_int");
  405. int intr2nd = get_gpio_by_name("accel_2");
  406. if (intr == -1 || intr2nd == -1)
  407. return NULL;
  408. i2c_info->irq = intr + MRST_IRQ_OFFSET;
  409. intr2nd_pdata = intr2nd + MRST_IRQ_OFFSET;
  410. return &intr2nd_pdata;
  411. }
  412. static void __init *no_platform_data(void *info)
  413. {
  414. return NULL;
  415. }
  416. static const struct devs_id __initconst device_ids[] = {
  417. {"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data},
  418. {"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data},
  419. {"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
  420. {"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
  421. {"emc1403", SFI_DEV_TYPE_I2C, 1, &emc1403_platform_data},
  422. {"i2c_accel", SFI_DEV_TYPE_I2C, 0, &lis331dl_platform_data},
  423. {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
  424. {"msic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
  425. {},
  426. };
  427. #define MAX_IPCDEVS 24
  428. static struct platform_device *ipc_devs[MAX_IPCDEVS];
  429. static int ipc_next_dev;
  430. #define MAX_SCU_SPI 24
  431. static struct spi_board_info *spi_devs[MAX_SCU_SPI];
  432. static int spi_next_dev;
  433. #define MAX_SCU_I2C 24
  434. static struct i2c_board_info *i2c_devs[MAX_SCU_I2C];
  435. static int i2c_bus[MAX_SCU_I2C];
  436. static int i2c_next_dev;
  437. static void __init intel_scu_device_register(struct platform_device *pdev)
  438. {
  439. if(ipc_next_dev == MAX_IPCDEVS)
  440. pr_err("too many SCU IPC devices");
  441. else
  442. ipc_devs[ipc_next_dev++] = pdev;
  443. }
  444. static void __init intel_scu_spi_device_register(struct spi_board_info *sdev)
  445. {
  446. struct spi_board_info *new_dev;
  447. if (spi_next_dev == MAX_SCU_SPI) {
  448. pr_err("too many SCU SPI devices");
  449. return;
  450. }
  451. new_dev = kzalloc(sizeof(*sdev), GFP_KERNEL);
  452. if (!new_dev) {
  453. pr_err("failed to alloc mem for delayed spi dev %s\n",
  454. sdev->modalias);
  455. return;
  456. }
  457. memcpy(new_dev, sdev, sizeof(*sdev));
  458. spi_devs[spi_next_dev++] = new_dev;
  459. }
  460. static void __init intel_scu_i2c_device_register(int bus,
  461. struct i2c_board_info *idev)
  462. {
  463. struct i2c_board_info *new_dev;
  464. if (i2c_next_dev == MAX_SCU_I2C) {
  465. pr_err("too many SCU I2C devices");
  466. return;
  467. }
  468. new_dev = kzalloc(sizeof(*idev), GFP_KERNEL);
  469. if (!new_dev) {
  470. pr_err("failed to alloc mem for delayed i2c dev %s\n",
  471. idev->type);
  472. return;
  473. }
  474. memcpy(new_dev, idev, sizeof(*idev));
  475. i2c_bus[i2c_next_dev] = bus;
  476. i2c_devs[i2c_next_dev++] = new_dev;
  477. }
  478. /* Called by IPC driver */
  479. void intel_scu_devices_create(void)
  480. {
  481. int i;
  482. for (i = 0; i < ipc_next_dev; i++)
  483. platform_device_add(ipc_devs[i]);
  484. for (i = 0; i < spi_next_dev; i++)
  485. spi_register_board_info(spi_devs[i], 1);
  486. for (i = 0; i < i2c_next_dev; i++) {
  487. struct i2c_adapter *adapter;
  488. struct i2c_client *client;
  489. adapter = i2c_get_adapter(i2c_bus[i]);
  490. if (adapter) {
  491. client = i2c_new_device(adapter, i2c_devs[i]);
  492. if (!client)
  493. pr_err("can't create i2c device %s\n",
  494. i2c_devs[i]->type);
  495. } else
  496. i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1);
  497. }
  498. }
  499. EXPORT_SYMBOL_GPL(intel_scu_devices_create);
  500. /* Called by IPC driver */
  501. void intel_scu_devices_destroy(void)
  502. {
  503. int i;
  504. for (i = 0; i < ipc_next_dev; i++)
  505. platform_device_del(ipc_devs[i]);
  506. }
  507. EXPORT_SYMBOL_GPL(intel_scu_devices_destroy);
  508. static void __init install_irq_resource(struct platform_device *pdev, int irq)
  509. {
  510. /* Single threaded */
  511. static struct resource __initdata res = {
  512. .name = "IRQ",
  513. .flags = IORESOURCE_IRQ,
  514. };
  515. res.start = irq;
  516. platform_device_add_resources(pdev, &res, 1);
  517. }
  518. static void __init sfi_handle_ipc_dev(struct platform_device *pdev)
  519. {
  520. const struct devs_id *dev = device_ids;
  521. void *pdata = NULL;
  522. while (dev->name[0]) {
  523. if (dev->type == SFI_DEV_TYPE_IPC &&
  524. !strncmp(dev->name, pdev->name, SFI_NAME_LEN)) {
  525. pdata = dev->get_platform_data(pdev);
  526. break;
  527. }
  528. dev++;
  529. }
  530. pdev->dev.platform_data = pdata;
  531. intel_scu_device_register(pdev);
  532. }
  533. static void __init sfi_handle_spi_dev(struct spi_board_info *spi_info)
  534. {
  535. const struct devs_id *dev = device_ids;
  536. void *pdata = NULL;
  537. while (dev->name[0]) {
  538. if (dev->type == SFI_DEV_TYPE_SPI &&
  539. !strncmp(dev->name, spi_info->modalias, SFI_NAME_LEN)) {
  540. pdata = dev->get_platform_data(spi_info);
  541. break;
  542. }
  543. dev++;
  544. }
  545. spi_info->platform_data = pdata;
  546. if (dev->delay)
  547. intel_scu_spi_device_register(spi_info);
  548. else
  549. spi_register_board_info(spi_info, 1);
  550. }
  551. static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info)
  552. {
  553. const struct devs_id *dev = device_ids;
  554. void *pdata = NULL;
  555. while (dev->name[0]) {
  556. if (dev->type == SFI_DEV_TYPE_I2C &&
  557. !strncmp(dev->name, i2c_info->type, SFI_NAME_LEN)) {
  558. pdata = dev->get_platform_data(i2c_info);
  559. break;
  560. }
  561. dev++;
  562. }
  563. i2c_info->platform_data = pdata;
  564. if (dev->delay)
  565. intel_scu_i2c_device_register(bus, i2c_info);
  566. else
  567. i2c_register_board_info(bus, i2c_info, 1);
  568. }
  569. static int __init sfi_parse_devs(struct sfi_table_header *table)
  570. {
  571. struct sfi_table_simple *sb;
  572. struct sfi_device_table_entry *pentry;
  573. struct spi_board_info spi_info;
  574. struct i2c_board_info i2c_info;
  575. struct platform_device *pdev;
  576. int num, i, bus;
  577. int ioapic;
  578. struct io_apic_irq_attr irq_attr;
  579. sb = (struct sfi_table_simple *)table;
  580. num = SFI_GET_NUM_ENTRIES(sb, struct sfi_device_table_entry);
  581. pentry = (struct sfi_device_table_entry *)sb->pentry;
  582. for (i = 0; i < num; i++, pentry++) {
  583. if (pentry->irq != (u8)0xff) { /* native RTE case */
  584. /* these SPI2 devices are not exposed to system as PCI
  585. * devices, but they have separate RTE entry in IOAPIC
  586. * so we have to enable them one by one here
  587. */
  588. ioapic = mp_find_ioapic(pentry->irq);
  589. irq_attr.ioapic = ioapic;
  590. irq_attr.ioapic_pin = pentry->irq;
  591. irq_attr.trigger = 1;
  592. irq_attr.polarity = 1;
  593. io_apic_set_pci_routing(NULL, pentry->irq, &irq_attr);
  594. }
  595. switch (pentry->type) {
  596. case SFI_DEV_TYPE_IPC:
  597. /* ID as IRQ is a hack that will go away */
  598. pdev = platform_device_alloc(pentry->name, pentry->irq);
  599. if (pdev == NULL) {
  600. pr_err("out of memory for SFI platform device '%s'.\n",
  601. pentry->name);
  602. continue;
  603. }
  604. install_irq_resource(pdev, pentry->irq);
  605. pr_debug("info[%2d]: IPC bus, name = %16.16s, "
  606. "irq = 0x%2x\n", i, pentry->name, pentry->irq);
  607. sfi_handle_ipc_dev(pdev);
  608. break;
  609. case SFI_DEV_TYPE_SPI:
  610. memset(&spi_info, 0, sizeof(spi_info));
  611. strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
  612. spi_info.irq = pentry->irq;
  613. spi_info.bus_num = pentry->host_num;
  614. spi_info.chip_select = pentry->addr;
  615. spi_info.max_speed_hz = pentry->max_freq;
  616. pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, "
  617. "irq = 0x%2x, max_freq = %d, cs = %d\n", i,
  618. spi_info.bus_num,
  619. spi_info.modalias,
  620. spi_info.irq,
  621. spi_info.max_speed_hz,
  622. spi_info.chip_select);
  623. sfi_handle_spi_dev(&spi_info);
  624. break;
  625. case SFI_DEV_TYPE_I2C:
  626. memset(&i2c_info, 0, sizeof(i2c_info));
  627. bus = pentry->host_num;
  628. strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
  629. i2c_info.irq = pentry->irq;
  630. i2c_info.addr = pentry->addr;
  631. pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, "
  632. "irq = 0x%2x, addr = 0x%x\n", i, bus,
  633. i2c_info.type,
  634. i2c_info.irq,
  635. i2c_info.addr);
  636. sfi_handle_i2c_dev(bus, &i2c_info);
  637. break;
  638. case SFI_DEV_TYPE_UART:
  639. case SFI_DEV_TYPE_HSI:
  640. default:
  641. ;
  642. }
  643. }
  644. return 0;
  645. }
  646. static int __init mrst_platform_init(void)
  647. {
  648. sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
  649. sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
  650. return 0;
  651. }
  652. arch_initcall(mrst_platform_init);
  653. /*
  654. * we will search these buttons in SFI GPIO table (by name)
  655. * and register them dynamically. Please add all possible
  656. * buttons here, we will shrink them if no GPIO found.
  657. */
  658. static struct gpio_keys_button gpio_button[] = {
  659. {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
  660. {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
  661. {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
  662. {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
  663. {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
  664. {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
  665. {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
  666. {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
  667. {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
  668. {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
  669. };
  670. static struct gpio_keys_platform_data mrst_gpio_keys = {
  671. .buttons = gpio_button,
  672. .rep = 1,
  673. .nbuttons = -1, /* will fill it after search */
  674. };
  675. static struct platform_device pb_device = {
  676. .name = "gpio-keys",
  677. .id = -1,
  678. .dev = {
  679. .platform_data = &mrst_gpio_keys,
  680. },
  681. };
  682. /*
  683. * Shrink the non-existent buttons, register the gpio button
  684. * device if there is some
  685. */
  686. static int __init pb_keys_init(void)
  687. {
  688. struct gpio_keys_button *gb = gpio_button;
  689. int i, num, good = 0;
  690. num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
  691. for (i = 0; i < num; i++) {
  692. gb[i].gpio = get_gpio_by_name(gb[i].desc);
  693. if (gb[i].gpio == -1)
  694. continue;
  695. if (i != good)
  696. gb[good] = gb[i];
  697. good++;
  698. }
  699. if (good) {
  700. mrst_gpio_keys.nbuttons = good;
  701. return platform_device_register(&pb_device);
  702. }
  703. return 0;
  704. }
  705. late_initcall(pb_keys_init);