acpi_lpss.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. /*
  2. * ACPI support for Intel Lynxpoint LPSS.
  3. *
  4. * Copyright (C) 2013, Intel Corporation
  5. * Authors: Mika Westerberg <mika.westerberg@linux.intel.com>
  6. * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/acpi.h>
  13. #include <linux/clkdev.h>
  14. #include <linux/clk-provider.h>
  15. #include <linux/err.h>
  16. #include <linux/io.h>
  17. #include <linux/mutex.h>
  18. #include <linux/pci.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/platform_data/clk-lpss.h>
  21. #include <linux/platform_data/x86/pmc_atom.h>
  22. #include <linux/pm_domain.h>
  23. #include <linux/pm_runtime.h>
  24. #include <linux/pwm.h>
  25. #include <linux/suspend.h>
  26. #include <linux/delay.h>
  27. #include "internal.h"
  28. ACPI_MODULE_NAME("acpi_lpss");
  29. #ifdef CONFIG_X86_INTEL_LPSS
  30. #include <asm/cpu_device_id.h>
  31. #include <asm/intel-family.h>
  32. #include <asm/iosf_mbi.h>
  33. #define LPSS_ADDR(desc) ((unsigned long)&desc)
  34. #define LPSS_CLK_SIZE 0x04
  35. #define LPSS_LTR_SIZE 0x18
  36. /* Offsets relative to LPSS_PRIVATE_OFFSET */
  37. #define LPSS_CLK_DIVIDER_DEF_MASK (BIT(1) | BIT(16))
  38. #define LPSS_RESETS 0x04
  39. #define LPSS_RESETS_RESET_FUNC BIT(0)
  40. #define LPSS_RESETS_RESET_APB BIT(1)
  41. #define LPSS_GENERAL 0x08
  42. #define LPSS_GENERAL_LTR_MODE_SW BIT(2)
  43. #define LPSS_GENERAL_UART_RTS_OVRD BIT(3)
  44. #define LPSS_SW_LTR 0x10
  45. #define LPSS_AUTO_LTR 0x14
  46. #define LPSS_LTR_SNOOP_REQ BIT(15)
  47. #define LPSS_LTR_SNOOP_MASK 0x0000FFFF
  48. #define LPSS_LTR_SNOOP_LAT_1US 0x800
  49. #define LPSS_LTR_SNOOP_LAT_32US 0xC00
  50. #define LPSS_LTR_SNOOP_LAT_SHIFT 5
  51. #define LPSS_LTR_SNOOP_LAT_CUTOFF 3000
  52. #define LPSS_LTR_MAX_VAL 0x3FF
  53. #define LPSS_TX_INT 0x20
  54. #define LPSS_TX_INT_MASK BIT(1)
  55. #define LPSS_PRV_REG_COUNT 9
  56. /* LPSS Flags */
  57. #define LPSS_CLK BIT(0)
  58. #define LPSS_CLK_GATE BIT(1)
  59. #define LPSS_CLK_DIVIDER BIT(2)
  60. #define LPSS_LTR BIT(3)
  61. #define LPSS_SAVE_CTX BIT(4)
  62. #define LPSS_NO_D3_DELAY BIT(5)
  63. /* Crystal Cove PMIC shares same ACPI ID between different platforms */
  64. #define BYT_CRC_HRV 2
  65. #define CHT_CRC_HRV 3
  66. struct lpss_private_data;
  67. struct lpss_device_desc {
  68. unsigned int flags;
  69. const char *clk_con_id;
  70. unsigned int prv_offset;
  71. size_t prv_size_override;
  72. struct property_entry *properties;
  73. void (*setup)(struct lpss_private_data *pdata);
  74. bool resume_from_noirq;
  75. };
  76. static const struct lpss_device_desc lpss_dma_desc = {
  77. .flags = LPSS_CLK,
  78. };
  79. struct lpss_private_data {
  80. struct acpi_device *adev;
  81. void __iomem *mmio_base;
  82. resource_size_t mmio_size;
  83. unsigned int fixed_clk_rate;
  84. struct clk *clk;
  85. const struct lpss_device_desc *dev_desc;
  86. u32 prv_reg_ctx[LPSS_PRV_REG_COUNT];
  87. };
  88. /* Devices which need to be in D3 before lpss_iosf_enter_d3_state() proceeds */
  89. static u32 pmc_atom_d3_mask = 0xfe000ffe;
  90. /* LPSS run time quirks */
  91. static unsigned int lpss_quirks;
  92. /*
  93. * LPSS_QUIRK_ALWAYS_POWER_ON: override power state for LPSS DMA device.
  94. *
  95. * The LPSS DMA controller has neither _PS0 nor _PS3 method. Moreover
  96. * it can be powered off automatically whenever the last LPSS device goes down.
  97. * In case of no power any access to the DMA controller will hang the system.
  98. * The behaviour is reproduced on some HP laptops based on Intel BayTrail as
  99. * well as on ASuS T100TA transformer.
  100. *
  101. * This quirk overrides power state of entire LPSS island to keep DMA powered
  102. * on whenever we have at least one other device in use.
  103. */
  104. #define LPSS_QUIRK_ALWAYS_POWER_ON BIT(0)
  105. /* UART Component Parameter Register */
  106. #define LPSS_UART_CPR 0xF4
  107. #define LPSS_UART_CPR_AFCE BIT(4)
  108. static void lpss_uart_setup(struct lpss_private_data *pdata)
  109. {
  110. unsigned int offset;
  111. u32 val;
  112. offset = pdata->dev_desc->prv_offset + LPSS_TX_INT;
  113. val = readl(pdata->mmio_base + offset);
  114. writel(val | LPSS_TX_INT_MASK, pdata->mmio_base + offset);
  115. val = readl(pdata->mmio_base + LPSS_UART_CPR);
  116. if (!(val & LPSS_UART_CPR_AFCE)) {
  117. offset = pdata->dev_desc->prv_offset + LPSS_GENERAL;
  118. val = readl(pdata->mmio_base + offset);
  119. val |= LPSS_GENERAL_UART_RTS_OVRD;
  120. writel(val, pdata->mmio_base + offset);
  121. }
  122. }
  123. static void lpss_deassert_reset(struct lpss_private_data *pdata)
  124. {
  125. unsigned int offset;
  126. u32 val;
  127. offset = pdata->dev_desc->prv_offset + LPSS_RESETS;
  128. val = readl(pdata->mmio_base + offset);
  129. val |= LPSS_RESETS_RESET_APB | LPSS_RESETS_RESET_FUNC;
  130. writel(val, pdata->mmio_base + offset);
  131. }
  132. /*
  133. * BYT PWM used for backlight control by the i915 driver on systems without
  134. * the Crystal Cove PMIC.
  135. */
  136. static struct pwm_lookup byt_pwm_lookup[] = {
  137. PWM_LOOKUP_WITH_MODULE("80860F09:00", 0, "0000:00:02.0",
  138. "pwm_backlight", 0, PWM_POLARITY_NORMAL,
  139. "pwm-lpss-platform"),
  140. };
  141. static void byt_pwm_setup(struct lpss_private_data *pdata)
  142. {
  143. struct acpi_device *adev = pdata->adev;
  144. /* Only call pwm_add_table for the first PWM controller */
  145. if (!adev->pnp.unique_id || strcmp(adev->pnp.unique_id, "1"))
  146. return;
  147. if (!acpi_dev_present("INT33FD", NULL, BYT_CRC_HRV))
  148. pwm_add_table(byt_pwm_lookup, ARRAY_SIZE(byt_pwm_lookup));
  149. }
  150. #define LPSS_I2C_ENABLE 0x6c
  151. static void byt_i2c_setup(struct lpss_private_data *pdata)
  152. {
  153. const char *uid_str = acpi_device_uid(pdata->adev);
  154. acpi_handle handle = pdata->adev->handle;
  155. unsigned long long shared_host = 0;
  156. acpi_status status;
  157. long uid = 0;
  158. /* Expected to always be true, but better safe then sorry */
  159. if (uid_str)
  160. uid = simple_strtol(uid_str, NULL, 10);
  161. /* Detect I2C bus shared with PUNIT and ignore its d3 status */
  162. status = acpi_evaluate_integer(handle, "_SEM", NULL, &shared_host);
  163. if (ACPI_SUCCESS(status) && shared_host && uid)
  164. pmc_atom_d3_mask &= ~(BIT_LPSS2_F1_I2C1 << (uid - 1));
  165. lpss_deassert_reset(pdata);
  166. if (readl(pdata->mmio_base + pdata->dev_desc->prv_offset))
  167. pdata->fixed_clk_rate = 133000000;
  168. writel(0, pdata->mmio_base + LPSS_I2C_ENABLE);
  169. }
  170. /* BSW PWM used for backlight control by the i915 driver */
  171. static struct pwm_lookup bsw_pwm_lookup[] = {
  172. PWM_LOOKUP_WITH_MODULE("80862288:00", 0, "0000:00:02.0",
  173. "pwm_backlight", 0, PWM_POLARITY_NORMAL,
  174. "pwm-lpss-platform"),
  175. };
  176. static void bsw_pwm_setup(struct lpss_private_data *pdata)
  177. {
  178. struct acpi_device *adev = pdata->adev;
  179. /* Only call pwm_add_table for the first PWM controller */
  180. if (!adev->pnp.unique_id || strcmp(adev->pnp.unique_id, "1"))
  181. return;
  182. pwm_add_table(bsw_pwm_lookup, ARRAY_SIZE(bsw_pwm_lookup));
  183. }
  184. static const struct lpss_device_desc lpt_dev_desc = {
  185. .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
  186. .prv_offset = 0x800,
  187. };
  188. static const struct lpss_device_desc lpt_i2c_dev_desc = {
  189. .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_LTR,
  190. .prv_offset = 0x800,
  191. };
  192. static struct property_entry uart_properties[] = {
  193. PROPERTY_ENTRY_U32("reg-io-width", 4),
  194. PROPERTY_ENTRY_U32("reg-shift", 2),
  195. PROPERTY_ENTRY_BOOL("snps,uart-16550-compatible"),
  196. { },
  197. };
  198. static const struct lpss_device_desc lpt_uart_dev_desc = {
  199. .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
  200. .clk_con_id = "baudclk",
  201. .prv_offset = 0x800,
  202. .setup = lpss_uart_setup,
  203. .properties = uart_properties,
  204. };
  205. static const struct lpss_device_desc lpt_sdio_dev_desc = {
  206. .flags = LPSS_LTR,
  207. .prv_offset = 0x1000,
  208. .prv_size_override = 0x1018,
  209. };
  210. static const struct lpss_device_desc byt_pwm_dev_desc = {
  211. .flags = LPSS_SAVE_CTX,
  212. .prv_offset = 0x800,
  213. .setup = byt_pwm_setup,
  214. };
  215. static const struct lpss_device_desc bsw_pwm_dev_desc = {
  216. .flags = LPSS_SAVE_CTX | LPSS_NO_D3_DELAY,
  217. .prv_offset = 0x800,
  218. .setup = bsw_pwm_setup,
  219. };
  220. static const struct lpss_device_desc byt_uart_dev_desc = {
  221. .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX,
  222. .clk_con_id = "baudclk",
  223. .prv_offset = 0x800,
  224. .setup = lpss_uart_setup,
  225. .properties = uart_properties,
  226. };
  227. static const struct lpss_device_desc bsw_uart_dev_desc = {
  228. .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX
  229. | LPSS_NO_D3_DELAY,
  230. .clk_con_id = "baudclk",
  231. .prv_offset = 0x800,
  232. .setup = lpss_uart_setup,
  233. .properties = uart_properties,
  234. };
  235. static const struct lpss_device_desc byt_spi_dev_desc = {
  236. .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX,
  237. .prv_offset = 0x400,
  238. };
  239. static const struct lpss_device_desc byt_sdio_dev_desc = {
  240. .flags = LPSS_CLK,
  241. };
  242. static const struct lpss_device_desc byt_i2c_dev_desc = {
  243. .flags = LPSS_CLK | LPSS_SAVE_CTX,
  244. .prv_offset = 0x800,
  245. .setup = byt_i2c_setup,
  246. .resume_from_noirq = true,
  247. };
  248. static const struct lpss_device_desc bsw_i2c_dev_desc = {
  249. .flags = LPSS_CLK | LPSS_SAVE_CTX | LPSS_NO_D3_DELAY,
  250. .prv_offset = 0x800,
  251. .setup = byt_i2c_setup,
  252. .resume_from_noirq = true,
  253. };
  254. static const struct lpss_device_desc bsw_spi_dev_desc = {
  255. .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX
  256. | LPSS_NO_D3_DELAY,
  257. .prv_offset = 0x400,
  258. .setup = lpss_deassert_reset,
  259. };
  260. #define ICPU(model) { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, }
  261. static const struct x86_cpu_id lpss_cpu_ids[] = {
  262. ICPU(INTEL_FAM6_ATOM_SILVERMONT), /* Valleyview, Bay Trail */
  263. ICPU(INTEL_FAM6_ATOM_AIRMONT), /* Braswell, Cherry Trail */
  264. {}
  265. };
  266. #else
  267. #define LPSS_ADDR(desc) (0UL)
  268. #endif /* CONFIG_X86_INTEL_LPSS */
  269. static const struct acpi_device_id acpi_lpss_device_ids[] = {
  270. /* Generic LPSS devices */
  271. { "INTL9C60", LPSS_ADDR(lpss_dma_desc) },
  272. /* Lynxpoint LPSS devices */
  273. { "INT33C0", LPSS_ADDR(lpt_dev_desc) },
  274. { "INT33C1", LPSS_ADDR(lpt_dev_desc) },
  275. { "INT33C2", LPSS_ADDR(lpt_i2c_dev_desc) },
  276. { "INT33C3", LPSS_ADDR(lpt_i2c_dev_desc) },
  277. { "INT33C4", LPSS_ADDR(lpt_uart_dev_desc) },
  278. { "INT33C5", LPSS_ADDR(lpt_uart_dev_desc) },
  279. { "INT33C6", LPSS_ADDR(lpt_sdio_dev_desc) },
  280. { "INT33C7", },
  281. /* BayTrail LPSS devices */
  282. { "80860F09", LPSS_ADDR(byt_pwm_dev_desc) },
  283. { "80860F0A", LPSS_ADDR(byt_uart_dev_desc) },
  284. { "80860F0E", LPSS_ADDR(byt_spi_dev_desc) },
  285. { "80860F14", LPSS_ADDR(byt_sdio_dev_desc) },
  286. { "80860F41", LPSS_ADDR(byt_i2c_dev_desc) },
  287. { "INT33B2", },
  288. { "INT33FC", },
  289. /* Braswell LPSS devices */
  290. { "80862286", LPSS_ADDR(lpss_dma_desc) },
  291. { "80862288", LPSS_ADDR(bsw_pwm_dev_desc) },
  292. { "8086228A", LPSS_ADDR(bsw_uart_dev_desc) },
  293. { "8086228E", LPSS_ADDR(bsw_spi_dev_desc) },
  294. { "808622C0", LPSS_ADDR(lpss_dma_desc) },
  295. { "808622C1", LPSS_ADDR(bsw_i2c_dev_desc) },
  296. /* Broadwell LPSS devices */
  297. { "INT3430", LPSS_ADDR(lpt_dev_desc) },
  298. { "INT3431", LPSS_ADDR(lpt_dev_desc) },
  299. { "INT3432", LPSS_ADDR(lpt_i2c_dev_desc) },
  300. { "INT3433", LPSS_ADDR(lpt_i2c_dev_desc) },
  301. { "INT3434", LPSS_ADDR(lpt_uart_dev_desc) },
  302. { "INT3435", LPSS_ADDR(lpt_uart_dev_desc) },
  303. { "INT3436", LPSS_ADDR(lpt_sdio_dev_desc) },
  304. { "INT3437", },
  305. /* Wildcat Point LPSS devices */
  306. { "INT3438", LPSS_ADDR(lpt_dev_desc) },
  307. { }
  308. };
  309. #ifdef CONFIG_X86_INTEL_LPSS
  310. static int is_memory(struct acpi_resource *res, void *not_used)
  311. {
  312. struct resource r;
  313. return !acpi_dev_resource_memory(res, &r);
  314. }
  315. /* LPSS main clock device. */
  316. static struct platform_device *lpss_clk_dev;
  317. static inline void lpt_register_clock_device(void)
  318. {
  319. lpss_clk_dev = platform_device_register_simple("clk-lpt", -1, NULL, 0);
  320. }
  321. static int register_device_clock(struct acpi_device *adev,
  322. struct lpss_private_data *pdata)
  323. {
  324. const struct lpss_device_desc *dev_desc = pdata->dev_desc;
  325. const char *devname = dev_name(&adev->dev);
  326. struct clk *clk;
  327. struct lpss_clk_data *clk_data;
  328. const char *parent, *clk_name;
  329. void __iomem *prv_base;
  330. if (!lpss_clk_dev)
  331. lpt_register_clock_device();
  332. clk_data = platform_get_drvdata(lpss_clk_dev);
  333. if (!clk_data)
  334. return -ENODEV;
  335. clk = clk_data->clk;
  336. if (!pdata->mmio_base
  337. || pdata->mmio_size < dev_desc->prv_offset + LPSS_CLK_SIZE)
  338. return -ENODATA;
  339. parent = clk_data->name;
  340. prv_base = pdata->mmio_base + dev_desc->prv_offset;
  341. if (pdata->fixed_clk_rate) {
  342. clk = clk_register_fixed_rate(NULL, devname, parent, 0,
  343. pdata->fixed_clk_rate);
  344. goto out;
  345. }
  346. if (dev_desc->flags & LPSS_CLK_GATE) {
  347. clk = clk_register_gate(NULL, devname, parent, 0,
  348. prv_base, 0, 0, NULL);
  349. parent = devname;
  350. }
  351. if (dev_desc->flags & LPSS_CLK_DIVIDER) {
  352. /* Prevent division by zero */
  353. if (!readl(prv_base))
  354. writel(LPSS_CLK_DIVIDER_DEF_MASK, prv_base);
  355. clk_name = kasprintf(GFP_KERNEL, "%s-div", devname);
  356. if (!clk_name)
  357. return -ENOMEM;
  358. clk = clk_register_fractional_divider(NULL, clk_name, parent,
  359. 0, prv_base,
  360. 1, 15, 16, 15, 0, NULL);
  361. parent = clk_name;
  362. clk_name = kasprintf(GFP_KERNEL, "%s-update", devname);
  363. if (!clk_name) {
  364. kfree(parent);
  365. return -ENOMEM;
  366. }
  367. clk = clk_register_gate(NULL, clk_name, parent,
  368. CLK_SET_RATE_PARENT | CLK_SET_RATE_GATE,
  369. prv_base, 31, 0, NULL);
  370. kfree(parent);
  371. kfree(clk_name);
  372. }
  373. out:
  374. if (IS_ERR(clk))
  375. return PTR_ERR(clk);
  376. pdata->clk = clk;
  377. clk_register_clkdev(clk, dev_desc->clk_con_id, devname);
  378. return 0;
  379. }
  380. struct lpss_device_links {
  381. const char *supplier_hid;
  382. const char *supplier_uid;
  383. const char *consumer_hid;
  384. const char *consumer_uid;
  385. u32 flags;
  386. };
  387. /*
  388. * The _DEP method is used to identify dependencies but instead of creating
  389. * device links for every handle in _DEP, only links in the following list are
  390. * created. That is necessary because, in the general case, _DEP can refer to
  391. * devices that might not have drivers, or that are on different buses, or where
  392. * the supplier is not enumerated until after the consumer is probed.
  393. */
  394. static const struct lpss_device_links lpss_device_links[] = {
  395. {"808622C1", "7", "80860F14", "3", DL_FLAG_PM_RUNTIME},
  396. {"808622C1", "7", "LNXVIDEO", NULL, DL_FLAG_PM_RUNTIME},
  397. {"80860F41", "5", "LNXVIDEO", NULL, DL_FLAG_PM_RUNTIME},
  398. };
  399. static bool hid_uid_match(struct acpi_device *adev,
  400. const char *hid2, const char *uid2)
  401. {
  402. const char *hid1 = acpi_device_hid(adev);
  403. const char *uid1 = acpi_device_uid(adev);
  404. if (strcmp(hid1, hid2))
  405. return false;
  406. if (!uid2)
  407. return true;
  408. return uid1 && !strcmp(uid1, uid2);
  409. }
  410. static bool acpi_lpss_is_supplier(struct acpi_device *adev,
  411. const struct lpss_device_links *link)
  412. {
  413. return hid_uid_match(adev, link->supplier_hid, link->supplier_uid);
  414. }
  415. static bool acpi_lpss_is_consumer(struct acpi_device *adev,
  416. const struct lpss_device_links *link)
  417. {
  418. return hid_uid_match(adev, link->consumer_hid, link->consumer_uid);
  419. }
  420. struct hid_uid {
  421. const char *hid;
  422. const char *uid;
  423. };
  424. static int match_hid_uid(struct device *dev, void *data)
  425. {
  426. struct acpi_device *adev = ACPI_COMPANION(dev);
  427. struct hid_uid *id = data;
  428. if (!adev)
  429. return 0;
  430. return hid_uid_match(adev, id->hid, id->uid);
  431. }
  432. static struct device *acpi_lpss_find_device(const char *hid, const char *uid)
  433. {
  434. struct device *dev;
  435. struct hid_uid data = {
  436. .hid = hid,
  437. .uid = uid,
  438. };
  439. dev = bus_find_device(&platform_bus_type, NULL, &data, match_hid_uid);
  440. if (dev)
  441. return dev;
  442. return bus_find_device(&pci_bus_type, NULL, &data, match_hid_uid);
  443. }
  444. static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
  445. {
  446. struct acpi_handle_list dep_devices;
  447. acpi_status status;
  448. int i;
  449. if (!acpi_has_method(adev->handle, "_DEP"))
  450. return false;
  451. status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
  452. &dep_devices);
  453. if (ACPI_FAILURE(status)) {
  454. dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
  455. return false;
  456. }
  457. for (i = 0; i < dep_devices.count; i++) {
  458. if (dep_devices.handles[i] == handle)
  459. return true;
  460. }
  461. return false;
  462. }
  463. static void acpi_lpss_link_consumer(struct device *dev1,
  464. const struct lpss_device_links *link)
  465. {
  466. struct device *dev2;
  467. dev2 = acpi_lpss_find_device(link->consumer_hid, link->consumer_uid);
  468. if (!dev2)
  469. return;
  470. if (acpi_lpss_dep(ACPI_COMPANION(dev2), ACPI_HANDLE(dev1)))
  471. device_link_add(dev2, dev1, link->flags);
  472. put_device(dev2);
  473. }
  474. static void acpi_lpss_link_supplier(struct device *dev1,
  475. const struct lpss_device_links *link)
  476. {
  477. struct device *dev2;
  478. dev2 = acpi_lpss_find_device(link->supplier_hid, link->supplier_uid);
  479. if (!dev2)
  480. return;
  481. if (acpi_lpss_dep(ACPI_COMPANION(dev1), ACPI_HANDLE(dev2)))
  482. device_link_add(dev1, dev2, link->flags);
  483. put_device(dev2);
  484. }
  485. static void acpi_lpss_create_device_links(struct acpi_device *adev,
  486. struct platform_device *pdev)
  487. {
  488. int i;
  489. for (i = 0; i < ARRAY_SIZE(lpss_device_links); i++) {
  490. const struct lpss_device_links *link = &lpss_device_links[i];
  491. if (acpi_lpss_is_supplier(adev, link))
  492. acpi_lpss_link_consumer(&pdev->dev, link);
  493. if (acpi_lpss_is_consumer(adev, link))
  494. acpi_lpss_link_supplier(&pdev->dev, link);
  495. }
  496. }
  497. static int acpi_lpss_create_device(struct acpi_device *adev,
  498. const struct acpi_device_id *id)
  499. {
  500. const struct lpss_device_desc *dev_desc;
  501. struct lpss_private_data *pdata;
  502. struct resource_entry *rentry;
  503. struct list_head resource_list;
  504. struct platform_device *pdev;
  505. int ret;
  506. dev_desc = (const struct lpss_device_desc *)id->driver_data;
  507. if (!dev_desc) {
  508. pdev = acpi_create_platform_device(adev, NULL);
  509. return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
  510. }
  511. pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  512. if (!pdata)
  513. return -ENOMEM;
  514. INIT_LIST_HEAD(&resource_list);
  515. ret = acpi_dev_get_resources(adev, &resource_list, is_memory, NULL);
  516. if (ret < 0)
  517. goto err_out;
  518. list_for_each_entry(rentry, &resource_list, node)
  519. if (resource_type(rentry->res) == IORESOURCE_MEM) {
  520. if (dev_desc->prv_size_override)
  521. pdata->mmio_size = dev_desc->prv_size_override;
  522. else
  523. pdata->mmio_size = resource_size(rentry->res);
  524. pdata->mmio_base = ioremap(rentry->res->start,
  525. pdata->mmio_size);
  526. break;
  527. }
  528. acpi_dev_free_resource_list(&resource_list);
  529. if (!pdata->mmio_base) {
  530. /* Avoid acpi_bus_attach() instantiating a pdev for this dev. */
  531. adev->pnp.type.platform_id = 0;
  532. /* Skip the device, but continue the namespace scan. */
  533. ret = 0;
  534. goto err_out;
  535. }
  536. pdata->adev = adev;
  537. pdata->dev_desc = dev_desc;
  538. if (dev_desc->setup)
  539. dev_desc->setup(pdata);
  540. if (dev_desc->flags & LPSS_CLK) {
  541. ret = register_device_clock(adev, pdata);
  542. if (ret) {
  543. /* Skip the device, but continue the namespace scan. */
  544. ret = 0;
  545. goto err_out;
  546. }
  547. }
  548. /*
  549. * This works around a known issue in ACPI tables where LPSS devices
  550. * have _PS0 and _PS3 without _PSC (and no power resources), so
  551. * acpi_bus_init_power() will assume that the BIOS has put them into D0.
  552. */
  553. ret = acpi_device_fix_up_power(adev);
  554. if (ret) {
  555. /* Skip the device, but continue the namespace scan. */
  556. ret = 0;
  557. goto err_out;
  558. }
  559. adev->driver_data = pdata;
  560. pdev = acpi_create_platform_device(adev, dev_desc->properties);
  561. if (!IS_ERR_OR_NULL(pdev)) {
  562. acpi_lpss_create_device_links(adev, pdev);
  563. return 1;
  564. }
  565. ret = PTR_ERR(pdev);
  566. adev->driver_data = NULL;
  567. err_out:
  568. kfree(pdata);
  569. return ret;
  570. }
  571. static u32 __lpss_reg_read(struct lpss_private_data *pdata, unsigned int reg)
  572. {
  573. return readl(pdata->mmio_base + pdata->dev_desc->prv_offset + reg);
  574. }
  575. static void __lpss_reg_write(u32 val, struct lpss_private_data *pdata,
  576. unsigned int reg)
  577. {
  578. writel(val, pdata->mmio_base + pdata->dev_desc->prv_offset + reg);
  579. }
  580. static int lpss_reg_read(struct device *dev, unsigned int reg, u32 *val)
  581. {
  582. struct acpi_device *adev;
  583. struct lpss_private_data *pdata;
  584. unsigned long flags;
  585. int ret;
  586. ret = acpi_bus_get_device(ACPI_HANDLE(dev), &adev);
  587. if (WARN_ON(ret))
  588. return ret;
  589. spin_lock_irqsave(&dev->power.lock, flags);
  590. if (pm_runtime_suspended(dev)) {
  591. ret = -EAGAIN;
  592. goto out;
  593. }
  594. pdata = acpi_driver_data(adev);
  595. if (WARN_ON(!pdata || !pdata->mmio_base)) {
  596. ret = -ENODEV;
  597. goto out;
  598. }
  599. *val = __lpss_reg_read(pdata, reg);
  600. out:
  601. spin_unlock_irqrestore(&dev->power.lock, flags);
  602. return ret;
  603. }
  604. static ssize_t lpss_ltr_show(struct device *dev, struct device_attribute *attr,
  605. char *buf)
  606. {
  607. u32 ltr_value = 0;
  608. unsigned int reg;
  609. int ret;
  610. reg = strcmp(attr->attr.name, "auto_ltr") ? LPSS_SW_LTR : LPSS_AUTO_LTR;
  611. ret = lpss_reg_read(dev, reg, &ltr_value);
  612. if (ret)
  613. return ret;
  614. return snprintf(buf, PAGE_SIZE, "%08x\n", ltr_value);
  615. }
  616. static ssize_t lpss_ltr_mode_show(struct device *dev,
  617. struct device_attribute *attr, char *buf)
  618. {
  619. u32 ltr_mode = 0;
  620. char *outstr;
  621. int ret;
  622. ret = lpss_reg_read(dev, LPSS_GENERAL, &ltr_mode);
  623. if (ret)
  624. return ret;
  625. outstr = (ltr_mode & LPSS_GENERAL_LTR_MODE_SW) ? "sw" : "auto";
  626. return sprintf(buf, "%s\n", outstr);
  627. }
  628. static DEVICE_ATTR(auto_ltr, S_IRUSR, lpss_ltr_show, NULL);
  629. static DEVICE_ATTR(sw_ltr, S_IRUSR, lpss_ltr_show, NULL);
  630. static DEVICE_ATTR(ltr_mode, S_IRUSR, lpss_ltr_mode_show, NULL);
  631. static struct attribute *lpss_attrs[] = {
  632. &dev_attr_auto_ltr.attr,
  633. &dev_attr_sw_ltr.attr,
  634. &dev_attr_ltr_mode.attr,
  635. NULL,
  636. };
  637. static const struct attribute_group lpss_attr_group = {
  638. .attrs = lpss_attrs,
  639. .name = "lpss_ltr",
  640. };
  641. static void acpi_lpss_set_ltr(struct device *dev, s32 val)
  642. {
  643. struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
  644. u32 ltr_mode, ltr_val;
  645. ltr_mode = __lpss_reg_read(pdata, LPSS_GENERAL);
  646. if (val < 0) {
  647. if (ltr_mode & LPSS_GENERAL_LTR_MODE_SW) {
  648. ltr_mode &= ~LPSS_GENERAL_LTR_MODE_SW;
  649. __lpss_reg_write(ltr_mode, pdata, LPSS_GENERAL);
  650. }
  651. return;
  652. }
  653. ltr_val = __lpss_reg_read(pdata, LPSS_SW_LTR) & ~LPSS_LTR_SNOOP_MASK;
  654. if (val >= LPSS_LTR_SNOOP_LAT_CUTOFF) {
  655. ltr_val |= LPSS_LTR_SNOOP_LAT_32US;
  656. val = LPSS_LTR_MAX_VAL;
  657. } else if (val > LPSS_LTR_MAX_VAL) {
  658. ltr_val |= LPSS_LTR_SNOOP_LAT_32US | LPSS_LTR_SNOOP_REQ;
  659. val >>= LPSS_LTR_SNOOP_LAT_SHIFT;
  660. } else {
  661. ltr_val |= LPSS_LTR_SNOOP_LAT_1US | LPSS_LTR_SNOOP_REQ;
  662. }
  663. ltr_val |= val;
  664. __lpss_reg_write(ltr_val, pdata, LPSS_SW_LTR);
  665. if (!(ltr_mode & LPSS_GENERAL_LTR_MODE_SW)) {
  666. ltr_mode |= LPSS_GENERAL_LTR_MODE_SW;
  667. __lpss_reg_write(ltr_mode, pdata, LPSS_GENERAL);
  668. }
  669. }
  670. #ifdef CONFIG_PM
  671. /**
  672. * acpi_lpss_save_ctx() - Save the private registers of LPSS device
  673. * @dev: LPSS device
  674. * @pdata: pointer to the private data of the LPSS device
  675. *
  676. * Most LPSS devices have private registers which may loose their context when
  677. * the device is powered down. acpi_lpss_save_ctx() saves those registers into
  678. * prv_reg_ctx array.
  679. */
  680. static void acpi_lpss_save_ctx(struct device *dev,
  681. struct lpss_private_data *pdata)
  682. {
  683. unsigned int i;
  684. for (i = 0; i < LPSS_PRV_REG_COUNT; i++) {
  685. unsigned long offset = i * sizeof(u32);
  686. pdata->prv_reg_ctx[i] = __lpss_reg_read(pdata, offset);
  687. dev_dbg(dev, "saving 0x%08x from LPSS reg at offset 0x%02lx\n",
  688. pdata->prv_reg_ctx[i], offset);
  689. }
  690. }
  691. /**
  692. * acpi_lpss_restore_ctx() - Restore the private registers of LPSS device
  693. * @dev: LPSS device
  694. * @pdata: pointer to the private data of the LPSS device
  695. *
  696. * Restores the registers that were previously stored with acpi_lpss_save_ctx().
  697. */
  698. static void acpi_lpss_restore_ctx(struct device *dev,
  699. struct lpss_private_data *pdata)
  700. {
  701. unsigned int i;
  702. for (i = 0; i < LPSS_PRV_REG_COUNT; i++) {
  703. unsigned long offset = i * sizeof(u32);
  704. __lpss_reg_write(pdata->prv_reg_ctx[i], pdata, offset);
  705. dev_dbg(dev, "restoring 0x%08x to LPSS reg at offset 0x%02lx\n",
  706. pdata->prv_reg_ctx[i], offset);
  707. }
  708. }
  709. static void acpi_lpss_d3_to_d0_delay(struct lpss_private_data *pdata)
  710. {
  711. /*
  712. * The following delay is needed or the subsequent write operations may
  713. * fail. The LPSS devices are actually PCI devices and the PCI spec
  714. * expects 10ms delay before the device can be accessed after D3 to D0
  715. * transition. However some platforms like BSW does not need this delay.
  716. */
  717. unsigned int delay = 10; /* default 10ms delay */
  718. if (pdata->dev_desc->flags & LPSS_NO_D3_DELAY)
  719. delay = 0;
  720. msleep(delay);
  721. }
  722. static int acpi_lpss_activate(struct device *dev)
  723. {
  724. struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
  725. int ret;
  726. ret = acpi_dev_resume(dev);
  727. if (ret)
  728. return ret;
  729. acpi_lpss_d3_to_d0_delay(pdata);
  730. /*
  731. * This is called only on ->probe() stage where a device is either in
  732. * known state defined by BIOS or most likely powered off. Due to this
  733. * we have to deassert reset line to be sure that ->probe() will
  734. * recognize the device.
  735. */
  736. if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
  737. lpss_deassert_reset(pdata);
  738. return 0;
  739. }
  740. static void acpi_lpss_dismiss(struct device *dev)
  741. {
  742. acpi_dev_suspend(dev, false);
  743. }
  744. /* IOSF SB for LPSS island */
  745. #define LPSS_IOSF_UNIT_LPIOEP 0xA0
  746. #define LPSS_IOSF_UNIT_LPIO1 0xAB
  747. #define LPSS_IOSF_UNIT_LPIO2 0xAC
  748. #define LPSS_IOSF_PMCSR 0x84
  749. #define LPSS_PMCSR_D0 0
  750. #define LPSS_PMCSR_D3hot 3
  751. #define LPSS_PMCSR_Dx_MASK GENMASK(1, 0)
  752. #define LPSS_IOSF_GPIODEF0 0x154
  753. #define LPSS_GPIODEF0_DMA1_D3 BIT(2)
  754. #define LPSS_GPIODEF0_DMA2_D3 BIT(3)
  755. #define LPSS_GPIODEF0_DMA_D3_MASK GENMASK(3, 2)
  756. #define LPSS_GPIODEF0_DMA_LLP BIT(13)
  757. static DEFINE_MUTEX(lpss_iosf_mutex);
  758. static bool lpss_iosf_d3_entered = true;
  759. static void lpss_iosf_enter_d3_state(void)
  760. {
  761. u32 value1 = 0;
  762. u32 mask1 = LPSS_GPIODEF0_DMA_D3_MASK | LPSS_GPIODEF0_DMA_LLP;
  763. u32 value2 = LPSS_PMCSR_D3hot;
  764. u32 mask2 = LPSS_PMCSR_Dx_MASK;
  765. /*
  766. * PMC provides an information about actual status of the LPSS devices.
  767. * Here we read the values related to LPSS power island, i.e. LPSS
  768. * devices, excluding both LPSS DMA controllers, along with SCC domain.
  769. */
  770. u32 func_dis, d3_sts_0, pmc_status;
  771. int ret;
  772. ret = pmc_atom_read(PMC_FUNC_DIS, &func_dis);
  773. if (ret)
  774. return;
  775. mutex_lock(&lpss_iosf_mutex);
  776. ret = pmc_atom_read(PMC_D3_STS_0, &d3_sts_0);
  777. if (ret)
  778. goto exit;
  779. /*
  780. * Get the status of entire LPSS power island per device basis.
  781. * Shutdown both LPSS DMA controllers if and only if all other devices
  782. * are already in D3hot.
  783. */
  784. pmc_status = (~(d3_sts_0 | func_dis)) & pmc_atom_d3_mask;
  785. if (pmc_status)
  786. goto exit;
  787. iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO1, MBI_CFG_WRITE,
  788. LPSS_IOSF_PMCSR, value2, mask2);
  789. iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO2, MBI_CFG_WRITE,
  790. LPSS_IOSF_PMCSR, value2, mask2);
  791. iosf_mbi_modify(LPSS_IOSF_UNIT_LPIOEP, MBI_CR_WRITE,
  792. LPSS_IOSF_GPIODEF0, value1, mask1);
  793. lpss_iosf_d3_entered = true;
  794. exit:
  795. mutex_unlock(&lpss_iosf_mutex);
  796. }
  797. static void lpss_iosf_exit_d3_state(void)
  798. {
  799. u32 value1 = LPSS_GPIODEF0_DMA1_D3 | LPSS_GPIODEF0_DMA2_D3 |
  800. LPSS_GPIODEF0_DMA_LLP;
  801. u32 mask1 = LPSS_GPIODEF0_DMA_D3_MASK | LPSS_GPIODEF0_DMA_LLP;
  802. u32 value2 = LPSS_PMCSR_D0;
  803. u32 mask2 = LPSS_PMCSR_Dx_MASK;
  804. mutex_lock(&lpss_iosf_mutex);
  805. if (!lpss_iosf_d3_entered)
  806. goto exit;
  807. lpss_iosf_d3_entered = false;
  808. iosf_mbi_modify(LPSS_IOSF_UNIT_LPIOEP, MBI_CR_WRITE,
  809. LPSS_IOSF_GPIODEF0, value1, mask1);
  810. iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO2, MBI_CFG_WRITE,
  811. LPSS_IOSF_PMCSR, value2, mask2);
  812. iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO1, MBI_CFG_WRITE,
  813. LPSS_IOSF_PMCSR, value2, mask2);
  814. exit:
  815. mutex_unlock(&lpss_iosf_mutex);
  816. }
  817. static int acpi_lpss_suspend(struct device *dev, bool wakeup)
  818. {
  819. struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
  820. int ret;
  821. if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
  822. acpi_lpss_save_ctx(dev, pdata);
  823. ret = acpi_dev_suspend(dev, wakeup);
  824. /*
  825. * This call must be last in the sequence, otherwise PMC will return
  826. * wrong status for devices being about to be powered off. See
  827. * lpss_iosf_enter_d3_state() for further information.
  828. */
  829. if (acpi_target_system_state() == ACPI_STATE_S0 &&
  830. lpss_quirks & LPSS_QUIRK_ALWAYS_POWER_ON && iosf_mbi_available())
  831. lpss_iosf_enter_d3_state();
  832. return ret;
  833. }
  834. static int acpi_lpss_resume(struct device *dev)
  835. {
  836. struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
  837. int ret;
  838. /*
  839. * This call is kept first to be in symmetry with
  840. * acpi_lpss_runtime_suspend() one.
  841. */
  842. if (lpss_quirks & LPSS_QUIRK_ALWAYS_POWER_ON && iosf_mbi_available())
  843. lpss_iosf_exit_d3_state();
  844. ret = acpi_dev_resume(dev);
  845. if (ret)
  846. return ret;
  847. acpi_lpss_d3_to_d0_delay(pdata);
  848. if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
  849. acpi_lpss_restore_ctx(dev, pdata);
  850. return 0;
  851. }
  852. #ifdef CONFIG_PM_SLEEP
  853. static int acpi_lpss_do_suspend_late(struct device *dev)
  854. {
  855. int ret;
  856. if (dev_pm_smart_suspend_and_suspended(dev))
  857. return 0;
  858. ret = pm_generic_suspend_late(dev);
  859. return ret ? ret : acpi_lpss_suspend(dev, device_may_wakeup(dev));
  860. }
  861. static int acpi_lpss_suspend_late(struct device *dev)
  862. {
  863. struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
  864. if (pdata->dev_desc->resume_from_noirq)
  865. return 0;
  866. return acpi_lpss_do_suspend_late(dev);
  867. }
  868. static int acpi_lpss_suspend_noirq(struct device *dev)
  869. {
  870. struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
  871. int ret;
  872. if (pdata->dev_desc->resume_from_noirq) {
  873. ret = acpi_lpss_do_suspend_late(dev);
  874. if (ret)
  875. return ret;
  876. }
  877. return acpi_subsys_suspend_noirq(dev);
  878. }
  879. static int acpi_lpss_do_resume_early(struct device *dev)
  880. {
  881. int ret = acpi_lpss_resume(dev);
  882. return ret ? ret : pm_generic_resume_early(dev);
  883. }
  884. static int acpi_lpss_resume_early(struct device *dev)
  885. {
  886. struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
  887. if (pdata->dev_desc->resume_from_noirq)
  888. return 0;
  889. return acpi_lpss_do_resume_early(dev);
  890. }
  891. static int acpi_lpss_resume_noirq(struct device *dev)
  892. {
  893. struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
  894. int ret;
  895. ret = acpi_subsys_resume_noirq(dev);
  896. if (ret)
  897. return ret;
  898. if (!dev_pm_may_skip_resume(dev) && pdata->dev_desc->resume_from_noirq)
  899. ret = acpi_lpss_do_resume_early(dev);
  900. return ret;
  901. }
  902. #endif /* CONFIG_PM_SLEEP */
  903. static int acpi_lpss_runtime_suspend(struct device *dev)
  904. {
  905. int ret = pm_generic_runtime_suspend(dev);
  906. return ret ? ret : acpi_lpss_suspend(dev, true);
  907. }
  908. static int acpi_lpss_runtime_resume(struct device *dev)
  909. {
  910. int ret = acpi_lpss_resume(dev);
  911. return ret ? ret : pm_generic_runtime_resume(dev);
  912. }
  913. #endif /* CONFIG_PM */
  914. static struct dev_pm_domain acpi_lpss_pm_domain = {
  915. #ifdef CONFIG_PM
  916. .activate = acpi_lpss_activate,
  917. .dismiss = acpi_lpss_dismiss,
  918. #endif
  919. .ops = {
  920. #ifdef CONFIG_PM
  921. #ifdef CONFIG_PM_SLEEP
  922. .prepare = acpi_subsys_prepare,
  923. .complete = acpi_subsys_complete,
  924. .suspend = acpi_subsys_suspend,
  925. .suspend_late = acpi_lpss_suspend_late,
  926. .suspend_noirq = acpi_lpss_suspend_noirq,
  927. .resume_noirq = acpi_lpss_resume_noirq,
  928. .resume_early = acpi_lpss_resume_early,
  929. .freeze = acpi_subsys_freeze,
  930. .freeze_late = acpi_subsys_freeze_late,
  931. .freeze_noirq = acpi_subsys_freeze_noirq,
  932. .thaw_noirq = acpi_subsys_thaw_noirq,
  933. .poweroff = acpi_subsys_suspend,
  934. .poweroff_late = acpi_lpss_suspend_late,
  935. .poweroff_noirq = acpi_subsys_suspend_noirq,
  936. .restore_noirq = acpi_subsys_resume_noirq,
  937. .restore_early = acpi_lpss_resume_early,
  938. #endif
  939. .runtime_suspend = acpi_lpss_runtime_suspend,
  940. .runtime_resume = acpi_lpss_runtime_resume,
  941. #endif
  942. },
  943. };
  944. static int acpi_lpss_platform_notify(struct notifier_block *nb,
  945. unsigned long action, void *data)
  946. {
  947. struct platform_device *pdev = to_platform_device(data);
  948. struct lpss_private_data *pdata;
  949. struct acpi_device *adev;
  950. const struct acpi_device_id *id;
  951. id = acpi_match_device(acpi_lpss_device_ids, &pdev->dev);
  952. if (!id || !id->driver_data)
  953. return 0;
  954. if (acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev))
  955. return 0;
  956. pdata = acpi_driver_data(adev);
  957. if (!pdata)
  958. return 0;
  959. if (pdata->mmio_base &&
  960. pdata->mmio_size < pdata->dev_desc->prv_offset + LPSS_LTR_SIZE) {
  961. dev_err(&pdev->dev, "MMIO size insufficient to access LTR\n");
  962. return 0;
  963. }
  964. switch (action) {
  965. case BUS_NOTIFY_BIND_DRIVER:
  966. dev_pm_domain_set(&pdev->dev, &acpi_lpss_pm_domain);
  967. break;
  968. case BUS_NOTIFY_DRIVER_NOT_BOUND:
  969. case BUS_NOTIFY_UNBOUND_DRIVER:
  970. dev_pm_domain_set(&pdev->dev, NULL);
  971. break;
  972. case BUS_NOTIFY_ADD_DEVICE:
  973. dev_pm_domain_set(&pdev->dev, &acpi_lpss_pm_domain);
  974. if (pdata->dev_desc->flags & LPSS_LTR)
  975. return sysfs_create_group(&pdev->dev.kobj,
  976. &lpss_attr_group);
  977. break;
  978. case BUS_NOTIFY_DEL_DEVICE:
  979. if (pdata->dev_desc->flags & LPSS_LTR)
  980. sysfs_remove_group(&pdev->dev.kobj, &lpss_attr_group);
  981. dev_pm_domain_set(&pdev->dev, NULL);
  982. break;
  983. default:
  984. break;
  985. }
  986. return 0;
  987. }
  988. static struct notifier_block acpi_lpss_nb = {
  989. .notifier_call = acpi_lpss_platform_notify,
  990. };
  991. static void acpi_lpss_bind(struct device *dev)
  992. {
  993. struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
  994. if (!pdata || !pdata->mmio_base || !(pdata->dev_desc->flags & LPSS_LTR))
  995. return;
  996. if (pdata->mmio_size >= pdata->dev_desc->prv_offset + LPSS_LTR_SIZE)
  997. dev->power.set_latency_tolerance = acpi_lpss_set_ltr;
  998. else
  999. dev_err(dev, "MMIO size insufficient to access LTR\n");
  1000. }
  1001. static void acpi_lpss_unbind(struct device *dev)
  1002. {
  1003. dev->power.set_latency_tolerance = NULL;
  1004. }
  1005. static struct acpi_scan_handler lpss_handler = {
  1006. .ids = acpi_lpss_device_ids,
  1007. .attach = acpi_lpss_create_device,
  1008. .bind = acpi_lpss_bind,
  1009. .unbind = acpi_lpss_unbind,
  1010. };
  1011. void __init acpi_lpss_init(void)
  1012. {
  1013. const struct x86_cpu_id *id;
  1014. int ret;
  1015. ret = lpt_clk_init();
  1016. if (ret)
  1017. return;
  1018. id = x86_match_cpu(lpss_cpu_ids);
  1019. if (id)
  1020. lpss_quirks |= LPSS_QUIRK_ALWAYS_POWER_ON;
  1021. bus_register_notifier(&platform_bus_type, &acpi_lpss_nb);
  1022. acpi_scan_add_handler(&lpss_handler);
  1023. }
  1024. #else
  1025. static struct acpi_scan_handler lpss_handler = {
  1026. .ids = acpi_lpss_device_ids,
  1027. };
  1028. void __init acpi_lpss_init(void)
  1029. {
  1030. acpi_scan_add_handler(&lpss_handler);
  1031. }
  1032. #endif /* CONFIG_X86_INTEL_LPSS */