intel-mid.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. /*
  2. * intel-mid.c: Intel MID platform setup code
  3. *
  4. * (C) Copyright 2008, 2012 Intel Corporation
  5. * Author: Jacob Pan (jacob.jun.pan@intel.com)
  6. * Author: Sathyanarayanan Kuppuswamy <sathyanarayanan.kuppuswamy@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; version 2
  11. * of the License.
  12. */
  13. #define pr_fmt(fmt) "intel_mid: " fmt
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/scatterlist.h>
  18. #include <linux/sfi.h>
  19. #include <linux/intel_pmic_gpio.h>
  20. #include <linux/spi/spi.h>
  21. #include <linux/i2c.h>
  22. #include <linux/platform_data/pca953x.h>
  23. #include <linux/gpio_keys.h>
  24. #include <linux/input.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/irq.h>
  27. #include <linux/module.h>
  28. #include <linux/notifier.h>
  29. #include <linux/mfd/intel_msic.h>
  30. #include <linux/gpio.h>
  31. #include <linux/i2c/tc35876x.h>
  32. #include <asm/setup.h>
  33. #include <asm/mpspec_def.h>
  34. #include <asm/hw_irq.h>
  35. #include <asm/apic.h>
  36. #include <asm/io_apic.h>
  37. #include <asm/intel-mid.h>
  38. #include <asm/intel_mid_vrtc.h>
  39. #include <asm/io.h>
  40. #include <asm/i8259.h>
  41. #include <asm/intel_scu_ipc.h>
  42. #include <asm/apb_timer.h>
  43. #include <asm/reboot.h>
  44. /*
  45. * the clockevent devices on Moorestown/Medfield can be APBT or LAPIC clock,
  46. * cmdline option x86_intel_mid_timer can be used to override the configuration
  47. * to prefer one or the other.
  48. * at runtime, there are basically three timer configurations:
  49. * 1. per cpu apbt clock only
  50. * 2. per cpu always-on lapic clocks only, this is Penwell/Medfield only
  51. * 3. per cpu lapic clock (C3STOP) and one apbt clock, with broadcast.
  52. *
  53. * by default (without cmdline option), platform code first detects cpu type
  54. * to see if we are on lincroft or penwell, then set up both lapic or apbt
  55. * clocks accordingly.
  56. * i.e. by default, medfield uses configuration #2, moorestown uses #1.
  57. * config #3 is supported but not recommended on medfield.
  58. *
  59. * rating and feature summary:
  60. * lapic (with C3STOP) --------- 100
  61. * apbt (always-on) ------------ 110
  62. * lapic (always-on,ARAT) ------ 150
  63. */
  64. enum intel_mid_timer_options intel_mid_timer_options;
  65. static u32 sfi_mtimer_usage[SFI_MTMR_MAX_NUM];
  66. static struct sfi_timer_table_entry sfi_mtimer_array[SFI_MTMR_MAX_NUM];
  67. enum intel_mid_cpu_type __intel_mid_cpu_chip;
  68. EXPORT_SYMBOL_GPL(__intel_mid_cpu_chip);
  69. int sfi_mtimer_num;
  70. struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
  71. EXPORT_SYMBOL_GPL(sfi_mrtc_array);
  72. int sfi_mrtc_num;
  73. static void intel_mid_power_off(void)
  74. {
  75. }
  76. static void intel_mid_reboot(void)
  77. {
  78. intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
  79. }
  80. /* parse all the mtimer info to a static mtimer array */
  81. static int __init sfi_parse_mtmr(struct sfi_table_header *table)
  82. {
  83. struct sfi_table_simple *sb;
  84. struct sfi_timer_table_entry *pentry;
  85. struct mpc_intsrc mp_irq;
  86. int totallen;
  87. sb = (struct sfi_table_simple *)table;
  88. if (!sfi_mtimer_num) {
  89. sfi_mtimer_num = SFI_GET_NUM_ENTRIES(sb,
  90. struct sfi_timer_table_entry);
  91. pentry = (struct sfi_timer_table_entry *) sb->pentry;
  92. totallen = sfi_mtimer_num * sizeof(*pentry);
  93. memcpy(sfi_mtimer_array, pentry, totallen);
  94. }
  95. pr_debug("SFI MTIMER info (num = %d):\n", sfi_mtimer_num);
  96. pentry = sfi_mtimer_array;
  97. for (totallen = 0; totallen < sfi_mtimer_num; totallen++, pentry++) {
  98. pr_debug("timer[%d]: paddr = 0x%08x, freq = %dHz,"
  99. " irq = %d\n", totallen, (u32)pentry->phys_addr,
  100. pentry->freq_hz, pentry->irq);
  101. if (!pentry->irq)
  102. continue;
  103. mp_irq.type = MP_INTSRC;
  104. mp_irq.irqtype = mp_INT;
  105. /* triggering mode edge bit 2-3, active high polarity bit 0-1 */
  106. mp_irq.irqflag = 5;
  107. mp_irq.srcbus = MP_BUS_ISA;
  108. mp_irq.srcbusirq = pentry->irq; /* IRQ */
  109. mp_irq.dstapic = MP_APIC_ALL;
  110. mp_irq.dstirq = pentry->irq;
  111. mp_save_irq(&mp_irq);
  112. }
  113. return 0;
  114. }
  115. struct sfi_timer_table_entry *sfi_get_mtmr(int hint)
  116. {
  117. int i;
  118. if (hint < sfi_mtimer_num) {
  119. if (!sfi_mtimer_usage[hint]) {
  120. pr_debug("hint taken for timer %d irq %d\n",
  121. hint, sfi_mtimer_array[hint].irq);
  122. sfi_mtimer_usage[hint] = 1;
  123. return &sfi_mtimer_array[hint];
  124. }
  125. }
  126. /* take the first timer available */
  127. for (i = 0; i < sfi_mtimer_num;) {
  128. if (!sfi_mtimer_usage[i]) {
  129. sfi_mtimer_usage[i] = 1;
  130. return &sfi_mtimer_array[i];
  131. }
  132. i++;
  133. }
  134. return NULL;
  135. }
  136. void sfi_free_mtmr(struct sfi_timer_table_entry *mtmr)
  137. {
  138. int i;
  139. for (i = 0; i < sfi_mtimer_num;) {
  140. if (mtmr->irq == sfi_mtimer_array[i].irq) {
  141. sfi_mtimer_usage[i] = 0;
  142. return;
  143. }
  144. i++;
  145. }
  146. }
  147. /* parse all the mrtc info to a global mrtc array */
  148. int __init sfi_parse_mrtc(struct sfi_table_header *table)
  149. {
  150. struct sfi_table_simple *sb;
  151. struct sfi_rtc_table_entry *pentry;
  152. struct mpc_intsrc mp_irq;
  153. int totallen;
  154. sb = (struct sfi_table_simple *)table;
  155. if (!sfi_mrtc_num) {
  156. sfi_mrtc_num = SFI_GET_NUM_ENTRIES(sb,
  157. struct sfi_rtc_table_entry);
  158. pentry = (struct sfi_rtc_table_entry *)sb->pentry;
  159. totallen = sfi_mrtc_num * sizeof(*pentry);
  160. memcpy(sfi_mrtc_array, pentry, totallen);
  161. }
  162. pr_debug("SFI RTC info (num = %d):\n", sfi_mrtc_num);
  163. pentry = sfi_mrtc_array;
  164. for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) {
  165. pr_debug("RTC[%d]: paddr = 0x%08x, irq = %d\n",
  166. totallen, (u32)pentry->phys_addr, pentry->irq);
  167. mp_irq.type = MP_INTSRC;
  168. mp_irq.irqtype = mp_INT;
  169. mp_irq.irqflag = 0xf; /* level trigger and active low */
  170. mp_irq.srcbus = MP_BUS_ISA;
  171. mp_irq.srcbusirq = pentry->irq; /* IRQ */
  172. mp_irq.dstapic = MP_APIC_ALL;
  173. mp_irq.dstirq = pentry->irq;
  174. mp_save_irq(&mp_irq);
  175. }
  176. return 0;
  177. }
  178. static unsigned long __init intel_mid_calibrate_tsc(void)
  179. {
  180. unsigned long fast_calibrate;
  181. u32 lo, hi, ratio, fsb;
  182. rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
  183. pr_debug("IA32 perf status is 0x%x, 0x%0x\n", lo, hi);
  184. ratio = (hi >> 8) & 0x1f;
  185. pr_debug("ratio is %d\n", ratio);
  186. if (!ratio) {
  187. pr_err("read a zero ratio, should be incorrect!\n");
  188. pr_err("force tsc ratio to 16 ...\n");
  189. ratio = 16;
  190. }
  191. rdmsr(MSR_FSB_FREQ, lo, hi);
  192. if ((lo & 0x7) == 0x7)
  193. fsb = PENWELL_FSB_FREQ_83SKU;
  194. else
  195. fsb = PENWELL_FSB_FREQ_100SKU;
  196. fast_calibrate = ratio * fsb;
  197. pr_debug("read penwell tsc %lu khz\n", fast_calibrate);
  198. lapic_timer_frequency = fsb * 1000 / HZ;
  199. /* mark tsc clocksource as reliable */
  200. set_cpu_cap(&boot_cpu_data, X86_FEATURE_TSC_RELIABLE);
  201. if (fast_calibrate)
  202. return fast_calibrate;
  203. return 0;
  204. }
  205. static void __init intel_mid_time_init(void)
  206. {
  207. sfi_table_parse(SFI_SIG_MTMR, NULL, NULL, sfi_parse_mtmr);
  208. switch (intel_mid_timer_options) {
  209. case INTEL_MID_TIMER_APBT_ONLY:
  210. break;
  211. case INTEL_MID_TIMER_LAPIC_APBT:
  212. x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
  213. x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
  214. break;
  215. default:
  216. if (!boot_cpu_has(X86_FEATURE_ARAT))
  217. break;
  218. x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
  219. x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
  220. return;
  221. }
  222. /* we need at least one APB timer */
  223. pre_init_apic_IRQ0();
  224. apbt_time_init();
  225. }
  226. static void __cpuinit intel_mid_arch_setup(void)
  227. {
  228. if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x27)
  229. __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
  230. else {
  231. pr_err("Unknown Intel MID CPU (%d:%d), default to Penwell\n",
  232. boot_cpu_data.x86, boot_cpu_data.x86_model);
  233. __intel_mid_cpu_chip = INTEL_MID_CPU_CHIP_PENWELL;
  234. }
  235. }
  236. /* MID systems don't have i8042 controller */
  237. static int intel_mid_i8042_detect(void)
  238. {
  239. return 0;
  240. }
  241. /*
  242. * Moorestown does not have external NMI source nor port 0x61 to report
  243. * NMI status. The possible NMI sources are from pmu as a result of NMI
  244. * watchdog or lock debug. Reading io port 0x61 results in 0xff which
  245. * misled NMI handler.
  246. */
  247. static unsigned char intel_mid_get_nmi_reason(void)
  248. {
  249. return 0;
  250. }
  251. /*
  252. * Moorestown specific x86_init function overrides and early setup
  253. * calls.
  254. */
  255. void __init x86_intel_mid_early_setup(void)
  256. {
  257. x86_init.resources.probe_roms = x86_init_noop;
  258. x86_init.resources.reserve_resources = x86_init_noop;
  259. x86_init.timers.timer_init = intel_mid_time_init;
  260. x86_init.timers.setup_percpu_clockev = x86_init_noop;
  261. x86_init.irqs.pre_vector_init = x86_init_noop;
  262. x86_init.oem.arch_setup = intel_mid_arch_setup;
  263. x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
  264. x86_platform.calibrate_tsc = intel_mid_calibrate_tsc;
  265. x86_platform.i8042_detect = intel_mid_i8042_detect;
  266. x86_init.timers.wallclock_init = intel_mid_rtc_init;
  267. x86_platform.get_nmi_reason = intel_mid_get_nmi_reason;
  268. x86_init.pci.init = intel_mid_pci_init;
  269. x86_init.pci.fixup_irqs = x86_init_noop;
  270. legacy_pic = &null_legacy_pic;
  271. pm_power_off = intel_mid_power_off;
  272. machine_ops.emergency_restart = intel_mid_reboot;
  273. /* Avoid searching for BIOS MP tables */
  274. x86_init.mpparse.find_smp_config = x86_init_noop;
  275. x86_init.mpparse.get_smp_config = x86_init_uint_noop;
  276. set_bit(MP_BUS_ISA, mp_bus_not_pci);
  277. }
  278. /*
  279. * if user does not want to use per CPU apb timer, just give it a lower rating
  280. * than local apic timer and skip the late per cpu timer init.
  281. */
  282. static inline int __init setup_x86_intel_mid_timer(char *arg)
  283. {
  284. if (!arg)
  285. return -EINVAL;
  286. if (strcmp("apbt_only", arg) == 0)
  287. intel_mid_timer_options = INTEL_MID_TIMER_APBT_ONLY;
  288. else if (strcmp("lapic_and_apbt", arg) == 0)
  289. intel_mid_timer_options = INTEL_MID_TIMER_LAPIC_APBT;
  290. else {
  291. pr_warn("X86 INTEL_MID timer option %s not recognised"
  292. " use x86_intel_mid_timer=apbt_only or lapic_and_apbt\n",
  293. arg);
  294. return -EINVAL;
  295. }
  296. return 0;
  297. }
  298. __setup("x86_intel_mid_timer=", setup_x86_intel_mid_timer);
  299. /*
  300. * Parsing GPIO table first, since the DEVS table will need this table
  301. * to map the pin name to the actual pin.
  302. */
  303. static struct sfi_gpio_table_entry *gpio_table;
  304. static int gpio_num_entry;
  305. static int __init sfi_parse_gpio(struct sfi_table_header *table)
  306. {
  307. struct sfi_table_simple *sb;
  308. struct sfi_gpio_table_entry *pentry;
  309. int num, i;
  310. if (gpio_table)
  311. return 0;
  312. sb = (struct sfi_table_simple *)table;
  313. num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
  314. pentry = (struct sfi_gpio_table_entry *)sb->pentry;
  315. gpio_table = kmalloc(num * sizeof(*pentry), GFP_KERNEL);
  316. if (!gpio_table)
  317. return -1;
  318. memcpy(gpio_table, pentry, num * sizeof(*pentry));
  319. gpio_num_entry = num;
  320. pr_debug("GPIO pin info:\n");
  321. for (i = 0; i < num; i++, pentry++)
  322. pr_debug("info[%2d]: controller = %16.16s, pin_name = %16.16s,"
  323. " pin = %d\n", i,
  324. pentry->controller_name,
  325. pentry->pin_name,
  326. pentry->pin_no);
  327. return 0;
  328. }
  329. static int get_gpio_by_name(const char *name)
  330. {
  331. struct sfi_gpio_table_entry *pentry = gpio_table;
  332. int i;
  333. if (!pentry)
  334. return -1;
  335. for (i = 0; i < gpio_num_entry; i++, pentry++) {
  336. if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
  337. return pentry->pin_no;
  338. }
  339. return -1;
  340. }
  341. /*
  342. * Here defines the array of devices platform data that IAFW would export
  343. * through SFI "DEVS" table, we use name and type to match the device and
  344. * its platform data.
  345. */
  346. struct devs_id {
  347. char name[SFI_NAME_LEN + 1];
  348. u8 type;
  349. u8 delay;
  350. void *(*get_platform_data)(void *info);
  351. };
  352. /* the offset for the mapping of global gpio pin to irq */
  353. #define INTEL_MID_IRQ_OFFSET 0x100
  354. static void __init *pmic_gpio_platform_data(void *info)
  355. {
  356. static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
  357. int gpio_base = get_gpio_by_name("pmic_gpio_base");
  358. if (gpio_base == -1)
  359. gpio_base = 64;
  360. pmic_gpio_pdata.gpio_base = gpio_base;
  361. pmic_gpio_pdata.irq_base = gpio_base + INTEL_MID_IRQ_OFFSET;
  362. pmic_gpio_pdata.gpiointr = 0xffffeff8;
  363. return &pmic_gpio_pdata;
  364. }
  365. static void __init *max3111_platform_data(void *info)
  366. {
  367. struct spi_board_info *spi_info = info;
  368. int intr = get_gpio_by_name("max3111_int");
  369. spi_info->mode = SPI_MODE_0;
  370. if (intr == -1)
  371. return NULL;
  372. spi_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  373. return NULL;
  374. }
  375. /* we have multiple max7315 on the board ... */
  376. #define MAX7315_NUM 2
  377. static void __init *max7315_platform_data(void *info)
  378. {
  379. static struct pca953x_platform_data max7315_pdata[MAX7315_NUM];
  380. static int nr;
  381. struct pca953x_platform_data *max7315 = &max7315_pdata[nr];
  382. struct i2c_board_info *i2c_info = info;
  383. int gpio_base, intr;
  384. char base_pin_name[SFI_NAME_LEN + 1];
  385. char intr_pin_name[SFI_NAME_LEN + 1];
  386. if (nr == MAX7315_NUM) {
  387. pr_err("too many max7315s, we only support %d\n",
  388. MAX7315_NUM);
  389. return NULL;
  390. }
  391. /* we have several max7315 on the board, we only need load several
  392. * instances of the same pca953x driver to cover them
  393. */
  394. strcpy(i2c_info->type, "max7315");
  395. if (nr++) {
  396. sprintf(base_pin_name, "max7315_%d_base", nr);
  397. sprintf(intr_pin_name, "max7315_%d_int", nr);
  398. } else {
  399. strcpy(base_pin_name, "max7315_base");
  400. strcpy(intr_pin_name, "max7315_int");
  401. }
  402. gpio_base = get_gpio_by_name(base_pin_name);
  403. intr = get_gpio_by_name(intr_pin_name);
  404. if (gpio_base == -1)
  405. return NULL;
  406. max7315->gpio_base = gpio_base;
  407. if (intr != -1) {
  408. i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  409. max7315->irq_base = gpio_base + INTEL_MID_IRQ_OFFSET;
  410. } else {
  411. i2c_info->irq = -1;
  412. max7315->irq_base = -1;
  413. }
  414. return max7315;
  415. }
  416. static void *tca6416_platform_data(void *info)
  417. {
  418. static struct pca953x_platform_data tca6416;
  419. struct i2c_board_info *i2c_info = info;
  420. int gpio_base, intr;
  421. char base_pin_name[SFI_NAME_LEN + 1];
  422. char intr_pin_name[SFI_NAME_LEN + 1];
  423. strcpy(i2c_info->type, "tca6416");
  424. strcpy(base_pin_name, "tca6416_base");
  425. strcpy(intr_pin_name, "tca6416_int");
  426. gpio_base = get_gpio_by_name(base_pin_name);
  427. intr = get_gpio_by_name(intr_pin_name);
  428. if (gpio_base == -1)
  429. return NULL;
  430. tca6416.gpio_base = gpio_base;
  431. if (intr != -1) {
  432. i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  433. tca6416.irq_base = gpio_base + INTEL_MID_IRQ_OFFSET;
  434. } else {
  435. i2c_info->irq = -1;
  436. tca6416.irq_base = -1;
  437. }
  438. return &tca6416;
  439. }
  440. static void *mpu3050_platform_data(void *info)
  441. {
  442. struct i2c_board_info *i2c_info = info;
  443. int intr = get_gpio_by_name("mpu3050_int");
  444. if (intr == -1)
  445. return NULL;
  446. i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  447. return NULL;
  448. }
  449. static void __init *emc1403_platform_data(void *info)
  450. {
  451. static short intr2nd_pdata;
  452. struct i2c_board_info *i2c_info = info;
  453. int intr = get_gpio_by_name("thermal_int");
  454. int intr2nd = get_gpio_by_name("thermal_alert");
  455. if (intr == -1 || intr2nd == -1)
  456. return NULL;
  457. i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  458. intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;
  459. return &intr2nd_pdata;
  460. }
  461. static void __init *lis331dl_platform_data(void *info)
  462. {
  463. static short intr2nd_pdata;
  464. struct i2c_board_info *i2c_info = info;
  465. int intr = get_gpio_by_name("accel_int");
  466. int intr2nd = get_gpio_by_name("accel_2");
  467. if (intr == -1 || intr2nd == -1)
  468. return NULL;
  469. i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  470. intr2nd_pdata = intr2nd + INTEL_MID_IRQ_OFFSET;
  471. return &intr2nd_pdata;
  472. }
  473. static void __init *no_platform_data(void *info)
  474. {
  475. return NULL;
  476. }
  477. static struct resource msic_resources[] = {
  478. {
  479. .start = INTEL_MSIC_IRQ_PHYS_BASE,
  480. .end = INTEL_MSIC_IRQ_PHYS_BASE + 64 - 1,
  481. .flags = IORESOURCE_MEM,
  482. },
  483. };
  484. static struct intel_msic_platform_data msic_pdata;
  485. static struct platform_device msic_device = {
  486. .name = "intel_msic",
  487. .id = -1,
  488. .dev = {
  489. .platform_data = &msic_pdata,
  490. },
  491. .num_resources = ARRAY_SIZE(msic_resources),
  492. .resource = msic_resources,
  493. };
  494. static inline bool intel_mid_has_msic(void)
  495. {
  496. return intel_mid_identify_cpu() == INTEL_MID_CPU_CHIP_PENWELL;
  497. }
  498. static int msic_scu_status_change(struct notifier_block *nb,
  499. unsigned long code, void *data)
  500. {
  501. if (code == SCU_DOWN) {
  502. platform_device_unregister(&msic_device);
  503. return 0;
  504. }
  505. return platform_device_register(&msic_device);
  506. }
  507. static int __init msic_init(void)
  508. {
  509. static struct notifier_block msic_scu_notifier = {
  510. .notifier_call = msic_scu_status_change,
  511. };
  512. /*
  513. * We need to be sure that the SCU IPC is ready before MSIC device
  514. * can be registered.
  515. */
  516. if (intel_mid_has_msic())
  517. intel_scu_notifier_add(&msic_scu_notifier);
  518. return 0;
  519. }
  520. arch_initcall(msic_init);
  521. /*
  522. * msic_generic_platform_data - sets generic platform data for the block
  523. * @info: pointer to the SFI device table entry for this block
  524. * @block: MSIC block
  525. *
  526. * Function sets IRQ number from the SFI table entry for given device to
  527. * the MSIC platform data.
  528. */
  529. static void *msic_generic_platform_data(void *info, enum intel_msic_block block)
  530. {
  531. struct sfi_device_table_entry *entry = info;
  532. BUG_ON(block < 0 || block >= INTEL_MSIC_BLOCK_LAST);
  533. msic_pdata.irq[block] = entry->irq;
  534. return no_platform_data(info);
  535. }
  536. static void *msic_battery_platform_data(void *info)
  537. {
  538. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_BATTERY);
  539. }
  540. static void *msic_gpio_platform_data(void *info)
  541. {
  542. static struct intel_msic_gpio_pdata pdata;
  543. int gpio = get_gpio_by_name("msic_gpio_base");
  544. if (gpio < 0)
  545. return NULL;
  546. pdata.gpio_base = gpio;
  547. msic_pdata.gpio = &pdata;
  548. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_GPIO);
  549. }
  550. static void *msic_audio_platform_data(void *info)
  551. {
  552. struct platform_device *pdev;
  553. pdev = platform_device_register_simple("sst-platform", -1, NULL, 0);
  554. if (IS_ERR(pdev)) {
  555. pr_err("failed to create audio platform device\n");
  556. return NULL;
  557. }
  558. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_AUDIO);
  559. }
  560. static void *msic_power_btn_platform_data(void *info)
  561. {
  562. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_POWER_BTN);
  563. }
  564. static void *msic_ocd_platform_data(void *info)
  565. {
  566. static struct intel_msic_ocd_pdata pdata;
  567. int gpio = get_gpio_by_name("ocd_gpio");
  568. if (gpio < 0)
  569. return NULL;
  570. pdata.gpio = gpio;
  571. msic_pdata.ocd = &pdata;
  572. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_OCD);
  573. }
  574. static void *msic_thermal_platform_data(void *info)
  575. {
  576. return msic_generic_platform_data(info, INTEL_MSIC_BLOCK_THERMAL);
  577. }
  578. /* tc35876x DSI-LVDS bridge chip and panel platform data */
  579. static void *tc35876x_platform_data(void *data)
  580. {
  581. static struct tc35876x_platform_data pdata;
  582. /* gpio pins set to -1 will not be used by the driver */
  583. pdata.gpio_bridge_reset = get_gpio_by_name("LCMB_RXEN");
  584. pdata.gpio_panel_bl_en = get_gpio_by_name("6S6P_BL_EN");
  585. pdata.gpio_panel_vadd = get_gpio_by_name("EN_VREG_LCD_V3P3");
  586. return &pdata;
  587. }
  588. static const struct devs_id __initconst device_ids[] = {
  589. {"bma023", SFI_DEV_TYPE_I2C, 1, &no_platform_data},
  590. {"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data},
  591. {"pmic_gpio", SFI_DEV_TYPE_IPC, 1, &pmic_gpio_platform_data},
  592. {"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data},
  593. {"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
  594. {"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
  595. {"tca6416", SFI_DEV_TYPE_I2C, 1, &tca6416_platform_data},
  596. {"emc1403", SFI_DEV_TYPE_I2C, 1, &emc1403_platform_data},
  597. {"i2c_accel", SFI_DEV_TYPE_I2C, 0, &lis331dl_platform_data},
  598. {"pmic_audio", SFI_DEV_TYPE_IPC, 1, &no_platform_data},
  599. {"mpu3050", SFI_DEV_TYPE_I2C, 1, &mpu3050_platform_data},
  600. {"i2c_disp_brig", SFI_DEV_TYPE_I2C, 0, &tc35876x_platform_data},
  601. /* MSIC subdevices */
  602. {"msic_battery", SFI_DEV_TYPE_IPC, 1, &msic_battery_platform_data},
  603. {"msic_gpio", SFI_DEV_TYPE_IPC, 1, &msic_gpio_platform_data},
  604. {"msic_audio", SFI_DEV_TYPE_IPC, 1, &msic_audio_platform_data},
  605. {"msic_power_btn", SFI_DEV_TYPE_IPC, 1, &msic_power_btn_platform_data},
  606. {"msic_ocd", SFI_DEV_TYPE_IPC, 1, &msic_ocd_platform_data},
  607. {"msic_thermal", SFI_DEV_TYPE_IPC, 1, &msic_thermal_platform_data},
  608. {},
  609. };
  610. #define MAX_IPCDEVS 24
  611. static struct platform_device *ipc_devs[MAX_IPCDEVS];
  612. static int ipc_next_dev;
  613. #define MAX_SCU_SPI 24
  614. static struct spi_board_info *spi_devs[MAX_SCU_SPI];
  615. static int spi_next_dev;
  616. #define MAX_SCU_I2C 24
  617. static struct i2c_board_info *i2c_devs[MAX_SCU_I2C];
  618. static int i2c_bus[MAX_SCU_I2C];
  619. static int i2c_next_dev;
  620. static void __init intel_scu_device_register(struct platform_device *pdev)
  621. {
  622. if (ipc_next_dev == MAX_IPCDEVS)
  623. pr_err("too many SCU IPC devices");
  624. else
  625. ipc_devs[ipc_next_dev++] = pdev;
  626. }
  627. static void __init intel_scu_spi_device_register(struct spi_board_info *sdev)
  628. {
  629. struct spi_board_info *new_dev;
  630. if (spi_next_dev == MAX_SCU_SPI) {
  631. pr_err("too many SCU SPI devices");
  632. return;
  633. }
  634. new_dev = kzalloc(sizeof(*sdev), GFP_KERNEL);
  635. if (!new_dev) {
  636. pr_err("failed to alloc mem for delayed spi dev %s\n",
  637. sdev->modalias);
  638. return;
  639. }
  640. memcpy(new_dev, sdev, sizeof(*sdev));
  641. spi_devs[spi_next_dev++] = new_dev;
  642. }
  643. static void __init intel_scu_i2c_device_register(int bus,
  644. struct i2c_board_info *idev)
  645. {
  646. struct i2c_board_info *new_dev;
  647. if (i2c_next_dev == MAX_SCU_I2C) {
  648. pr_err("too many SCU I2C devices");
  649. return;
  650. }
  651. new_dev = kzalloc(sizeof(*idev), GFP_KERNEL);
  652. if (!new_dev) {
  653. pr_err("failed to alloc mem for delayed i2c dev %s\n",
  654. idev->type);
  655. return;
  656. }
  657. memcpy(new_dev, idev, sizeof(*idev));
  658. i2c_bus[i2c_next_dev] = bus;
  659. i2c_devs[i2c_next_dev++] = new_dev;
  660. }
  661. BLOCKING_NOTIFIER_HEAD(intel_scu_notifier);
  662. EXPORT_SYMBOL_GPL(intel_scu_notifier);
  663. /* Called by IPC driver */
  664. void intel_scu_devices_create(void)
  665. {
  666. int i;
  667. for (i = 0; i < ipc_next_dev; i++)
  668. platform_device_add(ipc_devs[i]);
  669. for (i = 0; i < spi_next_dev; i++)
  670. spi_register_board_info(spi_devs[i], 1);
  671. for (i = 0; i < i2c_next_dev; i++) {
  672. struct i2c_adapter *adapter;
  673. struct i2c_client *client;
  674. adapter = i2c_get_adapter(i2c_bus[i]);
  675. if (adapter) {
  676. client = i2c_new_device(adapter, i2c_devs[i]);
  677. if (!client)
  678. pr_err("can't create i2c device %s\n",
  679. i2c_devs[i]->type);
  680. } else
  681. i2c_register_board_info(i2c_bus[i], i2c_devs[i], 1);
  682. }
  683. intel_scu_notifier_post(SCU_AVAILABLE, NULL);
  684. }
  685. EXPORT_SYMBOL_GPL(intel_scu_devices_create);
  686. /* Called by IPC driver */
  687. void intel_scu_devices_destroy(void)
  688. {
  689. int i;
  690. intel_scu_notifier_post(SCU_DOWN, NULL);
  691. for (i = 0; i < ipc_next_dev; i++)
  692. platform_device_del(ipc_devs[i]);
  693. }
  694. EXPORT_SYMBOL_GPL(intel_scu_devices_destroy);
  695. static void __init install_irq_resource(struct platform_device *pdev, int irq)
  696. {
  697. /* Single threaded */
  698. static struct resource __initdata res = {
  699. .name = "IRQ",
  700. .flags = IORESOURCE_IRQ,
  701. };
  702. res.start = irq;
  703. platform_device_add_resources(pdev, &res, 1);
  704. }
  705. static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *entry)
  706. {
  707. const struct devs_id *dev = device_ids;
  708. struct platform_device *pdev;
  709. void *pdata = NULL;
  710. while (dev->name[0]) {
  711. if (dev->type == SFI_DEV_TYPE_IPC &&
  712. !strncmp(dev->name, entry->name, SFI_NAME_LEN)) {
  713. pdata = dev->get_platform_data(entry);
  714. break;
  715. }
  716. dev++;
  717. }
  718. /*
  719. * On Medfield the platform device creation is handled by the MSIC
  720. * MFD driver so we don't need to do it here.
  721. */
  722. if (intel_mid_has_msic())
  723. return;
  724. pdev = platform_device_alloc(entry->name, 0);
  725. if (pdev == NULL) {
  726. pr_err("out of memory for SFI platform device '%s'.\n",
  727. entry->name);
  728. return;
  729. }
  730. install_irq_resource(pdev, entry->irq);
  731. pdev->dev.platform_data = pdata;
  732. intel_scu_device_register(pdev);
  733. }
  734. static void __init sfi_handle_spi_dev(struct spi_board_info *spi_info)
  735. {
  736. const struct devs_id *dev = device_ids;
  737. void *pdata = NULL;
  738. while (dev->name[0]) {
  739. if (dev->type == SFI_DEV_TYPE_SPI &&
  740. !strncmp(dev->name, spi_info->modalias,
  741. SFI_NAME_LEN)) {
  742. pdata = dev->get_platform_data(spi_info);
  743. break;
  744. }
  745. dev++;
  746. }
  747. spi_info->platform_data = pdata;
  748. if (dev->delay)
  749. intel_scu_spi_device_register(spi_info);
  750. else
  751. spi_register_board_info(spi_info, 1);
  752. }
  753. static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info)
  754. {
  755. const struct devs_id *dev = device_ids;
  756. void *pdata = NULL;
  757. while (dev->name[0]) {
  758. if (dev->type == SFI_DEV_TYPE_I2C &&
  759. !strncmp(dev->name, i2c_info->type, SFI_NAME_LEN)) {
  760. pdata = dev->get_platform_data(i2c_info);
  761. break;
  762. }
  763. dev++;
  764. }
  765. i2c_info->platform_data = pdata;
  766. if (dev->delay)
  767. intel_scu_i2c_device_register(bus, i2c_info);
  768. else
  769. i2c_register_board_info(bus, i2c_info, 1);
  770. }
  771. static int __init sfi_parse_devs(struct sfi_table_header *table)
  772. {
  773. struct sfi_table_simple *sb;
  774. struct sfi_device_table_entry *pentry;
  775. struct spi_board_info spi_info;
  776. struct i2c_board_info i2c_info;
  777. int num, i, bus;
  778. int ioapic;
  779. struct io_apic_irq_attr irq_attr;
  780. sb = (struct sfi_table_simple *)table;
  781. num = SFI_GET_NUM_ENTRIES(sb, struct sfi_device_table_entry);
  782. pentry = (struct sfi_device_table_entry *)sb->pentry;
  783. for (i = 0; i < num; i++, pentry++) {
  784. int irq = pentry->irq;
  785. if (irq != (u8)0xff) { /* native RTE case */
  786. /* these SPI2 devices are not exposed to system as PCI
  787. * devices, but they have separate RTE entry in IOAPIC
  788. * so we have to enable them one by one here
  789. */
  790. ioapic = mp_find_ioapic(irq);
  791. irq_attr.ioapic = ioapic;
  792. irq_attr.ioapic_pin = irq;
  793. irq_attr.trigger = 1;
  794. irq_attr.polarity = 1;
  795. io_apic_set_pci_routing(NULL, irq, &irq_attr);
  796. } else
  797. irq = 0; /* No irq */
  798. switch (pentry->type) {
  799. case SFI_DEV_TYPE_IPC:
  800. pr_debug("info[%2d]: IPC bus, name = %16.16s, "
  801. "irq = 0x%2x\n", i, pentry->name, pentry->irq);
  802. sfi_handle_ipc_dev(pentry);
  803. break;
  804. case SFI_DEV_TYPE_SPI:
  805. memset(&spi_info, 0, sizeof(spi_info));
  806. strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
  807. spi_info.irq = irq;
  808. spi_info.bus_num = pentry->host_num;
  809. spi_info.chip_select = pentry->addr;
  810. spi_info.max_speed_hz = pentry->max_freq;
  811. pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, "
  812. "irq = 0x%2x, max_freq = %d, cs = %d\n", i,
  813. spi_info.bus_num,
  814. spi_info.modalias,
  815. spi_info.irq,
  816. spi_info.max_speed_hz,
  817. spi_info.chip_select);
  818. sfi_handle_spi_dev(&spi_info);
  819. break;
  820. case SFI_DEV_TYPE_I2C:
  821. memset(&i2c_info, 0, sizeof(i2c_info));
  822. bus = pentry->host_num;
  823. strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
  824. i2c_info.irq = irq;
  825. i2c_info.addr = pentry->addr;
  826. pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, "
  827. "irq = 0x%2x, addr = 0x%x\n", i, bus,
  828. i2c_info.type,
  829. i2c_info.irq,
  830. i2c_info.addr);
  831. sfi_handle_i2c_dev(bus, &i2c_info);
  832. break;
  833. case SFI_DEV_TYPE_UART:
  834. case SFI_DEV_TYPE_HSI:
  835. default:
  836. ;
  837. }
  838. }
  839. return 0;
  840. }
  841. static int __init intel_mid_platform_init(void)
  842. {
  843. sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
  844. sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
  845. return 0;
  846. }
  847. arch_initcall(intel_mid_platform_init);
  848. /*
  849. * we will search these buttons in SFI GPIO table (by name)
  850. * and register them dynamically. Please add all possible
  851. * buttons here, we will shrink them if no GPIO found.
  852. */
  853. static struct gpio_keys_button gpio_button[] = {
  854. {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
  855. {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
  856. {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
  857. {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
  858. {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
  859. {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
  860. {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
  861. {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
  862. {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
  863. {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
  864. };
  865. static struct gpio_keys_platform_data intel_mid_gpio_keys = {
  866. .buttons = gpio_button,
  867. .rep = 1,
  868. .nbuttons = -1, /* will fill it after search */
  869. };
  870. static struct platform_device pb_device = {
  871. .name = "gpio-keys",
  872. .id = -1,
  873. .dev = {
  874. .platform_data = &intel_mid_gpio_keys,
  875. },
  876. };
  877. /*
  878. * Shrink the non-existent buttons, register the gpio button
  879. * device if there is some
  880. */
  881. static int __init pb_keys_init(void)
  882. {
  883. struct gpio_keys_button *gb = gpio_button;
  884. int i, num, good = 0;
  885. num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
  886. for (i = 0; i < num; i++) {
  887. gb[i].gpio = get_gpio_by_name(gb[i].desc);
  888. pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc,
  889. gb[i].gpio);
  890. if (gb[i].gpio == -1)
  891. continue;
  892. if (i != good)
  893. gb[good] = gb[i];
  894. good++;
  895. }
  896. if (good) {
  897. intel_mid_gpio_keys.nbuttons = good;
  898. return platform_device_register(&pb_device);
  899. }
  900. return 0;
  901. }
  902. late_initcall(pb_keys_init);