mrst.c 21 KB

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