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