mrst.c 21 KB

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