intel-mid.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  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 *pentry,
  706. struct devs_id *dev)
  707. {
  708. struct platform_device *pdev;
  709. void *pdata = NULL;
  710. pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
  711. pentry->name, pentry->irq);
  712. pdata = dev->get_platform_data(pentry);
  713. /*
  714. * On Medfield the platform device creation is handled by the MSIC
  715. * MFD driver so we don't need to do it here.
  716. */
  717. if (intel_mid_has_msic())
  718. return;
  719. pdev = platform_device_alloc(pentry->name, 0);
  720. if (pdev == NULL) {
  721. pr_err("out of memory for SFI platform device '%s'.\n",
  722. pentry->name);
  723. return;
  724. }
  725. install_irq_resource(pdev, pentry->irq);
  726. pdev->dev.platform_data = pdata;
  727. intel_scu_device_register(pdev);
  728. }
  729. static void __init sfi_handle_spi_dev(struct sfi_device_table_entry *pentry,
  730. struct devs_id *dev)
  731. {
  732. struct spi_board_info spi_info;
  733. void *pdata = NULL;
  734. memset(&spi_info, 0, sizeof(spi_info));
  735. strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
  736. spi_info.irq = ((pentry->irq == (u8)0xff) ? 0 : pentry->irq);
  737. spi_info.bus_num = pentry->host_num;
  738. spi_info.chip_select = pentry->addr;
  739. spi_info.max_speed_hz = pentry->max_freq;
  740. pr_debug("SPI bus=%d, name=%16.16s, irq=0x%2x, max_freq=%d, cs=%d\n",
  741. spi_info.bus_num,
  742. spi_info.modalias,
  743. spi_info.irq,
  744. spi_info.max_speed_hz,
  745. spi_info.chip_select);
  746. pdata = dev->get_platform_data(&spi_info);
  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(struct sfi_device_table_entry *pentry,
  754. struct devs_id *dev)
  755. {
  756. struct i2c_board_info i2c_info;
  757. void *pdata = NULL;
  758. memset(&i2c_info, 0, sizeof(i2c_info));
  759. strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
  760. i2c_info.irq = ((pentry->irq == (u8)0xff) ? 0 : pentry->irq);
  761. i2c_info.addr = pentry->addr;
  762. pr_debug("I2C bus = %d, name = %16.16s, irq = 0x%2x, addr = 0x%x\n",
  763. pentry->host_num,
  764. i2c_info.type,
  765. i2c_info.irq,
  766. i2c_info.addr);
  767. pdata = dev->get_platform_data(&i2c_info);
  768. i2c_info.platform_data = pdata;
  769. if (dev->delay)
  770. intel_scu_i2c_device_register(pentry->host_num, &i2c_info);
  771. else
  772. i2c_register_board_info(pentry->host_num, &i2c_info, 1);
  773. }
  774. static struct devs_id __init *get_device_id(u8 type, char *name)
  775. {
  776. struct devs_id *dev = device_ids;
  777. if (device_ids == NULL)
  778. return NULL;
  779. while (dev->name[0]) {
  780. if (dev->type == type &&
  781. !strncmp(dev->name, name, SFI_NAME_LEN)) {
  782. return dev;
  783. }
  784. dev++;
  785. }
  786. return NULL;
  787. }
  788. static int __init sfi_parse_devs(struct sfi_table_header *table)
  789. {
  790. struct sfi_table_simple *sb;
  791. struct sfi_device_table_entry *pentry;
  792. struct devs_id *dev = NULL;
  793. int num, i;
  794. int ioapic;
  795. struct io_apic_irq_attr irq_attr;
  796. sb = (struct sfi_table_simple *)table;
  797. num = SFI_GET_NUM_ENTRIES(sb, struct sfi_device_table_entry);
  798. pentry = (struct sfi_device_table_entry *)sb->pentry;
  799. for (i = 0; i < num; i++, pentry++) {
  800. int irq = pentry->irq;
  801. if (irq != (u8)0xff) { /* native RTE case */
  802. /* these SPI2 devices are not exposed to system as PCI
  803. * devices, but they have separate RTE entry in IOAPIC
  804. * so we have to enable them one by one here
  805. */
  806. ioapic = mp_find_ioapic(irq);
  807. irq_attr.ioapic = ioapic;
  808. irq_attr.ioapic_pin = irq;
  809. irq_attr.trigger = 1;
  810. irq_attr.polarity = 1;
  811. io_apic_set_pci_routing(NULL, irq, &irq_attr);
  812. } else
  813. irq = 0; /* No irq */
  814. dev = get_device_id(pentry->type, pentry->name);
  815. if ((dev == NULL) || (dev->get_platform_data == NULL))
  816. continue;
  817. switch (pentry->type) {
  818. case SFI_DEV_TYPE_IPC:
  819. sfi_handle_ipc_dev(pentry, dev);
  820. break;
  821. case SFI_DEV_TYPE_SPI:
  822. sfi_handle_spi_dev(pentry, dev);
  823. break;
  824. case SFI_DEV_TYPE_I2C:
  825. sfi_handle_i2c_dev(pentry, dev);
  826. break;
  827. case SFI_DEV_TYPE_UART:
  828. case SFI_DEV_TYPE_HSI:
  829. default:
  830. ;
  831. }
  832. }
  833. return 0;
  834. }
  835. static int __init intel_mid_platform_init(void)
  836. {
  837. sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
  838. sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
  839. return 0;
  840. }
  841. arch_initcall(intel_mid_platform_init);
  842. /*
  843. * we will search these buttons in SFI GPIO table (by name)
  844. * and register them dynamically. Please add all possible
  845. * buttons here, we will shrink them if no GPIO found.
  846. */
  847. static struct gpio_keys_button gpio_button[] = {
  848. {KEY_POWER, -1, 1, "power_btn", EV_KEY, 0, 3000},
  849. {KEY_PROG1, -1, 1, "prog_btn1", EV_KEY, 0, 20},
  850. {KEY_PROG2, -1, 1, "prog_btn2", EV_KEY, 0, 20},
  851. {SW_LID, -1, 1, "lid_switch", EV_SW, 0, 20},
  852. {KEY_VOLUMEUP, -1, 1, "vol_up", EV_KEY, 0, 20},
  853. {KEY_VOLUMEDOWN, -1, 1, "vol_down", EV_KEY, 0, 20},
  854. {KEY_CAMERA, -1, 1, "camera_full", EV_KEY, 0, 20},
  855. {KEY_CAMERA_FOCUS, -1, 1, "camera_half", EV_KEY, 0, 20},
  856. {SW_KEYPAD_SLIDE, -1, 1, "MagSw1", EV_SW, 0, 20},
  857. {SW_KEYPAD_SLIDE, -1, 1, "MagSw2", EV_SW, 0, 20},
  858. };
  859. static struct gpio_keys_platform_data intel_mid_gpio_keys = {
  860. .buttons = gpio_button,
  861. .rep = 1,
  862. .nbuttons = -1, /* will fill it after search */
  863. };
  864. static struct platform_device pb_device = {
  865. .name = "gpio-keys",
  866. .id = -1,
  867. .dev = {
  868. .platform_data = &intel_mid_gpio_keys,
  869. },
  870. };
  871. /*
  872. * Shrink the non-existent buttons, register the gpio button
  873. * device if there is some
  874. */
  875. static int __init pb_keys_init(void)
  876. {
  877. struct gpio_keys_button *gb = gpio_button;
  878. int i, num, good = 0;
  879. num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
  880. for (i = 0; i < num; i++) {
  881. gb[i].gpio = get_gpio_by_name(gb[i].desc);
  882. pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc,
  883. gb[i].gpio);
  884. if (gb[i].gpio == -1)
  885. continue;
  886. if (i != good)
  887. gb[good] = gb[i];
  888. good++;
  889. }
  890. if (good) {
  891. intel_mid_gpio_keys.nbuttons = good;
  892. return platform_device_register(&pb_device);
  893. }
  894. return 0;
  895. }
  896. late_initcall(pb_keys_init);