blob: 5edfd9c4904458ae6b30eb844be451aa81f38bca [file] [log] [blame]
Rafael J. Wysockif58b0822013-03-06 23:46:20 +01001/*
2 * ACPI support for Intel Lynxpoint LPSS.
3 *
Rafael J. Wysocki3df2da92015-02-03 14:29:43 +01004 * Copyright (C) 2013, Intel Corporation
Rafael J. Wysockif58b0822013-03-06 23:46:20 +01005 * 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
13#include <linux/acpi.h>
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010014#include <linux/clkdev.h>
15#include <linux/clk-provider.h>
16#include <linux/err.h>
17#include <linux/io.h>
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +010018#include <linux/mutex.h>
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010019#include <linux/platform_device.h>
20#include <linux/platform_data/clk-lpss.h>
Irina Tirdea80a75812017-01-23 12:07:43 -060021#include <linux/platform_data/x86/pmc_atom.h>
Tomeu Vizoso989561d2016-01-07 16:46:13 +010022#include <linux/pm_domain.h>
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +010023#include <linux/pm_runtime.h>
Hans de Goedebf7696a2017-01-22 17:14:09 +010024#include <linux/pwm.h>
Heikki Krogerusc78b0832014-05-23 16:15:09 +030025#include <linux/delay.h>
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010026
27#include "internal.h"
28
29ACPI_MODULE_NAME("acpi_lpss");
30
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +020031#ifdef CONFIG_X86_INTEL_LPSS
32
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +010033#include <asm/cpu_device_id.h>
Dave Hansen4626d842016-06-02 17:19:46 -070034#include <asm/intel-family.h>
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +010035#include <asm/iosf_mbi.h>
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +010036
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +020037#define LPSS_ADDR(desc) ((unsigned long)&desc)
38
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010039#define LPSS_CLK_SIZE 0x04
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +010040#define LPSS_LTR_SIZE 0x18
41
42/* Offsets relative to LPSS_PRIVATE_OFFSET */
Heikki Krogerused3a8722014-05-19 14:42:07 +030043#define LPSS_CLK_DIVIDER_DEF_MASK (BIT(1) | BIT(16))
Mika Westerberg765bdd42014-06-17 14:33:39 +030044#define LPSS_RESETS 0x04
45#define LPSS_RESETS_RESET_FUNC BIT(0)
46#define LPSS_RESETS_RESET_APB BIT(1)
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +010047#define LPSS_GENERAL 0x08
48#define LPSS_GENERAL_LTR_MODE_SW BIT(2)
Heikki Krogerus088f1fd2013-10-09 09:49:20 +030049#define LPSS_GENERAL_UART_RTS_OVRD BIT(3)
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +010050#define LPSS_SW_LTR 0x10
51#define LPSS_AUTO_LTR 0x14
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +010052#define LPSS_LTR_SNOOP_REQ BIT(15)
53#define LPSS_LTR_SNOOP_MASK 0x0000FFFF
54#define LPSS_LTR_SNOOP_LAT_1US 0x800
55#define LPSS_LTR_SNOOP_LAT_32US 0xC00
56#define LPSS_LTR_SNOOP_LAT_SHIFT 5
57#define LPSS_LTR_SNOOP_LAT_CUTOFF 3000
58#define LPSS_LTR_MAX_VAL 0x3FF
Heikki Krogerus06d86412013-06-17 13:25:46 +030059#define LPSS_TX_INT 0x20
60#define LPSS_TX_INT_MASK BIT(1)
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010061
Heikki Krogerusc78b0832014-05-23 16:15:09 +030062#define LPSS_PRV_REG_COUNT 9
63
Heikki Krogerusff8c1af2014-09-02 10:55:07 +030064/* LPSS Flags */
65#define LPSS_CLK BIT(0)
66#define LPSS_CLK_GATE BIT(1)
67#define LPSS_CLK_DIVIDER BIT(2)
68#define LPSS_LTR BIT(3)
69#define LPSS_SAVE_CTX BIT(4)
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +053070#define LPSS_NO_D3_DELAY BIT(5)
Mika Westerbergf6272172013-05-13 12:42:44 +000071
Heikki Krogerus06d86412013-06-17 13:25:46 +030072struct lpss_private_data;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010073
74struct lpss_device_desc {
Heikki Krogerusff8c1af2014-09-02 10:55:07 +030075 unsigned int flags;
Heikki Krogerusfcf07892015-03-06 15:48:38 +020076 const char *clk_con_id;
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +010077 unsigned int prv_offset;
Mika Westerberg958c4eb2013-06-18 16:51:35 +030078 size_t prv_size_override;
Heikki Krogerusa5565cf2016-08-23 11:33:27 +030079 struct property_entry *properties;
Heikki Krogerus06d86412013-06-17 13:25:46 +030080 void (*setup)(struct lpss_private_data *pdata);
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010081};
82
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +010083static const struct lpss_device_desc lpss_dma_desc = {
Rafael J. Wysocki3df2da92015-02-03 14:29:43 +010084 .flags = LPSS_CLK,
Rafael J. Wysockib59cc202013-05-08 11:55:49 +030085};
86
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010087struct lpss_private_data {
88 void __iomem *mmio_base;
89 resource_size_t mmio_size;
Heikki Krogerus03f09f72014-09-02 10:55:09 +030090 unsigned int fixed_clk_rate;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010091 struct clk *clk;
92 const struct lpss_device_desc *dev_desc;
Heikki Krogerusc78b0832014-05-23 16:15:09 +030093 u32 prv_reg_ctx[LPSS_PRV_REG_COUNT];
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010094};
95
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +010096/* LPSS run time quirks */
97static unsigned int lpss_quirks;
98
99/*
100 * LPSS_QUIRK_ALWAYS_POWER_ON: override power state for LPSS DMA device.
101 *
Andy Shevchenkofa9e93b2015-12-21 22:31:09 +0200102 * The LPSS DMA controller has neither _PS0 nor _PS3 method. Moreover
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100103 * it can be powered off automatically whenever the last LPSS device goes down.
104 * In case of no power any access to the DMA controller will hang the system.
105 * The behaviour is reproduced on some HP laptops based on Intel BayTrail as
106 * well as on ASuS T100TA transformer.
107 *
108 * This quirk overrides power state of entire LPSS island to keep DMA powered
109 * on whenever we have at least one other device in use.
110 */
111#define LPSS_QUIRK_ALWAYS_POWER_ON BIT(0)
112
Heikki Krogerus1f47a772014-09-11 15:19:33 +0300113/* UART Component Parameter Register */
114#define LPSS_UART_CPR 0xF4
115#define LPSS_UART_CPR_AFCE BIT(4)
116
Heikki Krogerus06d86412013-06-17 13:25:46 +0300117static void lpss_uart_setup(struct lpss_private_data *pdata)
118{
Heikki Krogerus088f1fd2013-10-09 09:49:20 +0300119 unsigned int offset;
Heikki Krogerus1f47a772014-09-11 15:19:33 +0300120 u32 val;
Heikki Krogerus06d86412013-06-17 13:25:46 +0300121
Heikki Krogerus088f1fd2013-10-09 09:49:20 +0300122 offset = pdata->dev_desc->prv_offset + LPSS_TX_INT;
Heikki Krogerus1f47a772014-09-11 15:19:33 +0300123 val = readl(pdata->mmio_base + offset);
124 writel(val | LPSS_TX_INT_MASK, pdata->mmio_base + offset);
Heikki Krogerus088f1fd2013-10-09 09:49:20 +0300125
Heikki Krogerus1f47a772014-09-11 15:19:33 +0300126 val = readl(pdata->mmio_base + LPSS_UART_CPR);
127 if (!(val & LPSS_UART_CPR_AFCE)) {
128 offset = pdata->dev_desc->prv_offset + LPSS_GENERAL;
129 val = readl(pdata->mmio_base + offset);
130 val |= LPSS_GENERAL_UART_RTS_OVRD;
131 writel(val, pdata->mmio_base + offset);
132 }
Heikki Krogerus06d86412013-06-17 13:25:46 +0300133}
134
Mika Westerberg30957942015-02-18 13:50:17 +0200135static void lpss_deassert_reset(struct lpss_private_data *pdata)
Mika Westerberg765bdd42014-06-17 14:33:39 +0300136{
137 unsigned int offset;
138 u32 val;
139
140 offset = pdata->dev_desc->prv_offset + LPSS_RESETS;
141 val = readl(pdata->mmio_base + offset);
142 val |= LPSS_RESETS_RESET_APB | LPSS_RESETS_RESET_FUNC;
143 writel(val, pdata->mmio_base + offset);
Mika Westerberg30957942015-02-18 13:50:17 +0200144}
145
146#define LPSS_I2C_ENABLE 0x6c
147
148static void byt_i2c_setup(struct lpss_private_data *pdata)
149{
150 lpss_deassert_reset(pdata);
Heikki Krogerus03f09f72014-09-02 10:55:09 +0300151
152 if (readl(pdata->mmio_base + pdata->dev_desc->prv_offset))
153 pdata->fixed_clk_rate = 133000000;
Mika Westerberg3293c7b2015-02-18 13:50:16 +0200154
155 writel(0, pdata->mmio_base + LPSS_I2C_ENABLE);
Mika Westerberg765bdd42014-06-17 14:33:39 +0300156}
157
Hans de Goedebf7696a2017-01-22 17:14:09 +0100158/* BSW PWM used for backlight control by the i915 driver */
159static struct pwm_lookup bsw_pwm_lookup[] = {
160 PWM_LOOKUP_WITH_MODULE("80862288:00", 0, "0000:00:02.0",
161 "pwm_backlight", 0, PWM_POLARITY_NORMAL,
162 "pwm-lpss-platform"),
163};
164
165static void bsw_pwm_setup(struct lpss_private_data *pdata)
166{
167 pwm_add_table(bsw_pwm_lookup, ARRAY_SIZE(bsw_pwm_lookup));
168}
169
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200170static const struct lpss_device_desc lpt_dev_desc = {
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300171 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100172 .prv_offset = 0x800,
Heikki Krogerused3a8722014-05-19 14:42:07 +0300173};
174
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200175static const struct lpss_device_desc lpt_i2c_dev_desc = {
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300176 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_LTR,
Heikki Krogerused3a8722014-05-19 14:42:07 +0300177 .prv_offset = 0x800,
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100178};
179
Heikki Krogerusa5565cf2016-08-23 11:33:27 +0300180static struct property_entry uart_properties[] = {
181 PROPERTY_ENTRY_U32("reg-io-width", 4),
182 PROPERTY_ENTRY_U32("reg-shift", 2),
183 PROPERTY_ENTRY_BOOL("snps,uart-16550-compatible"),
184 { },
185};
186
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200187static const struct lpss_device_desc lpt_uart_dev_desc = {
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300188 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
Heikki Krogerusfcf07892015-03-06 15:48:38 +0200189 .clk_con_id = "baudclk",
Heikki Krogerus06d86412013-06-17 13:25:46 +0300190 .prv_offset = 0x800,
Heikki Krogerus06d86412013-06-17 13:25:46 +0300191 .setup = lpss_uart_setup,
Heikki Krogerusa5565cf2016-08-23 11:33:27 +0300192 .properties = uart_properties,
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100193};
194
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200195static const struct lpss_device_desc lpt_sdio_dev_desc = {
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300196 .flags = LPSS_LTR,
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100197 .prv_offset = 0x1000,
Mika Westerberg958c4eb2013-06-18 16:51:35 +0300198 .prv_size_override = 0x1018,
Chew, Chiau Eee1c74812014-02-19 02:24:29 +0800199};
200
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200201static const struct lpss_device_desc byt_pwm_dev_desc = {
Heikki Krogerus3f56bf32014-09-02 10:55:10 +0300202 .flags = LPSS_SAVE_CTX,
Chew, Chiau Eee1c74812014-02-19 02:24:29 +0800203};
204
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530205static const struct lpss_device_desc bsw_pwm_dev_desc = {
206 .flags = LPSS_SAVE_CTX | LPSS_NO_D3_DELAY,
Hans de Goedebf7696a2017-01-22 17:14:09 +0100207 .setup = bsw_pwm_setup,
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530208};
209
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200210static const struct lpss_device_desc byt_uart_dev_desc = {
Rafael J. Wysocki3df2da92015-02-03 14:29:43 +0100211 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX,
Heikki Krogerusfcf07892015-03-06 15:48:38 +0200212 .clk_con_id = "baudclk",
Mika Westerbergf6272172013-05-13 12:42:44 +0000213 .prv_offset = 0x800,
Heikki Krogerus06d86412013-06-17 13:25:46 +0300214 .setup = lpss_uart_setup,
Heikki Krogerusa5565cf2016-08-23 11:33:27 +0300215 .properties = uart_properties,
Mika Westerbergf6272172013-05-13 12:42:44 +0000216};
217
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530218static const struct lpss_device_desc bsw_uart_dev_desc = {
219 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX
220 | LPSS_NO_D3_DELAY,
221 .clk_con_id = "baudclk",
222 .prv_offset = 0x800,
223 .setup = lpss_uart_setup,
Heikki Krogerusa5565cf2016-08-23 11:33:27 +0300224 .properties = uart_properties,
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530225};
226
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200227static const struct lpss_device_desc byt_spi_dev_desc = {
Rafael J. Wysocki3df2da92015-02-03 14:29:43 +0100228 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX,
Mika Westerbergf6272172013-05-13 12:42:44 +0000229 .prv_offset = 0x400,
Mika Westerbergf6272172013-05-13 12:42:44 +0000230};
231
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200232static const struct lpss_device_desc byt_sdio_dev_desc = {
Rafael J. Wysocki3df2da92015-02-03 14:29:43 +0100233 .flags = LPSS_CLK,
Mika Westerbergf6272172013-05-13 12:42:44 +0000234};
235
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200236static const struct lpss_device_desc byt_i2c_dev_desc = {
Rafael J. Wysocki3df2da92015-02-03 14:29:43 +0100237 .flags = LPSS_CLK | LPSS_SAVE_CTX,
Mika Westerbergf6272172013-05-13 12:42:44 +0000238 .prv_offset = 0x800,
Heikki Krogerus03f09f72014-09-02 10:55:09 +0300239 .setup = byt_i2c_setup,
Alan Cox1bfbd8e2014-08-19 15:55:22 +0300240};
241
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530242static const struct lpss_device_desc bsw_i2c_dev_desc = {
243 .flags = LPSS_CLK | LPSS_SAVE_CTX | LPSS_NO_D3_DELAY,
244 .prv_offset = 0x800,
245 .setup = byt_i2c_setup,
246};
247
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100248static const struct lpss_device_desc bsw_spi_dev_desc = {
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530249 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX
250 | LPSS_NO_D3_DELAY,
Mika Westerberg30957942015-02-18 13:50:17 +0200251 .prv_offset = 0x400,
252 .setup = lpss_deassert_reset,
253};
254
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100255#define ICPU(model) { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, }
256
257static const struct x86_cpu_id lpss_cpu_ids[] = {
Dave Hansen4626d842016-06-02 17:19:46 -0700258 ICPU(INTEL_FAM6_ATOM_SILVERMONT1), /* Valleyview, Bay Trail */
259 ICPU(INTEL_FAM6_ATOM_AIRMONT), /* Braswell, Cherry Trail */
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100260 {}
261};
262
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200263#else
264
265#define LPSS_ADDR(desc) (0UL)
266
267#endif /* CONFIG_X86_INTEL_LPSS */
268
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100269static const struct acpi_device_id acpi_lpss_device_ids[] = {
Rafael J. Wysockib59cc202013-05-08 11:55:49 +0300270 /* Generic LPSS devices */
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200271 { "INTL9C60", LPSS_ADDR(lpss_dma_desc) },
Rafael J. Wysockib59cc202013-05-08 11:55:49 +0300272
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100273 /* Lynxpoint LPSS devices */
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200274 { "INT33C0", LPSS_ADDR(lpt_dev_desc) },
275 { "INT33C1", LPSS_ADDR(lpt_dev_desc) },
276 { "INT33C2", LPSS_ADDR(lpt_i2c_dev_desc) },
277 { "INT33C3", LPSS_ADDR(lpt_i2c_dev_desc) },
278 { "INT33C4", LPSS_ADDR(lpt_uart_dev_desc) },
279 { "INT33C5", LPSS_ADDR(lpt_uart_dev_desc) },
280 { "INT33C6", LPSS_ADDR(lpt_sdio_dev_desc) },
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100281 { "INT33C7", },
282
Mika Westerbergf6272172013-05-13 12:42:44 +0000283 /* BayTrail LPSS devices */
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200284 { "80860F09", LPSS_ADDR(byt_pwm_dev_desc) },
285 { "80860F0A", LPSS_ADDR(byt_uart_dev_desc) },
286 { "80860F0E", LPSS_ADDR(byt_spi_dev_desc) },
287 { "80860F14", LPSS_ADDR(byt_sdio_dev_desc) },
288 { "80860F41", LPSS_ADDR(byt_i2c_dev_desc) },
Mika Westerbergf6272172013-05-13 12:42:44 +0000289 { "INT33B2", },
Jin Yao20482d32014-05-15 18:28:46 +0300290 { "INT33FC", },
Mika Westerbergf6272172013-05-13 12:42:44 +0000291
Alan Cox1bfbd8e2014-08-19 15:55:22 +0300292 /* Braswell LPSS devices */
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530293 { "80862288", LPSS_ADDR(bsw_pwm_dev_desc) },
294 { "8086228A", LPSS_ADDR(bsw_uart_dev_desc) },
Mika Westerberg30957942015-02-18 13:50:17 +0200295 { "8086228E", LPSS_ADDR(bsw_spi_dev_desc) },
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530296 { "808622C1", LPSS_ADDR(bsw_i2c_dev_desc) },
Alan Cox1bfbd8e2014-08-19 15:55:22 +0300297
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530298 /* Broadwell LPSS devices */
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200299 { "INT3430", LPSS_ADDR(lpt_dev_desc) },
300 { "INT3431", LPSS_ADDR(lpt_dev_desc) },
301 { "INT3432", LPSS_ADDR(lpt_i2c_dev_desc) },
302 { "INT3433", LPSS_ADDR(lpt_i2c_dev_desc) },
303 { "INT3434", LPSS_ADDR(lpt_uart_dev_desc) },
304 { "INT3435", LPSS_ADDR(lpt_uart_dev_desc) },
305 { "INT3436", LPSS_ADDR(lpt_sdio_dev_desc) },
Mika Westerberga4d97532013-11-12 11:48:19 +0200306 { "INT3437", },
307
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300308 /* Wildcat Point LPSS devices */
309 { "INT3438", LPSS_ADDR(lpt_dev_desc) },
Jie Yang43218a12014-08-01 09:06:35 +0800310
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100311 { }
312};
313
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200314#ifdef CONFIG_X86_INTEL_LPSS
315
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100316static int is_memory(struct acpi_resource *res, void *not_used)
317{
318 struct resource r;
319 return !acpi_dev_resource_memory(res, &r);
320}
321
322/* LPSS main clock device. */
323static struct platform_device *lpss_clk_dev;
324
325static inline void lpt_register_clock_device(void)
326{
327 lpss_clk_dev = platform_device_register_simple("clk-lpt", -1, NULL, 0);
328}
329
330static int register_device_clock(struct acpi_device *adev,
331 struct lpss_private_data *pdata)
332{
333 const struct lpss_device_desc *dev_desc = pdata->dev_desc;
Heikki Krogerused3a8722014-05-19 14:42:07 +0300334 const char *devname = dev_name(&adev->dev);
Mika Westerbergf6272172013-05-13 12:42:44 +0000335 struct clk *clk = ERR_PTR(-ENODEV);
Rafael J. Wysockib59cc202013-05-08 11:55:49 +0300336 struct lpss_clk_data *clk_data;
Heikki Krogerused3a8722014-05-19 14:42:07 +0300337 const char *parent, *clk_name;
338 void __iomem *prv_base;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100339
340 if (!lpss_clk_dev)
341 lpt_register_clock_device();
342
Rafael J. Wysockib59cc202013-05-08 11:55:49 +0300343 clk_data = platform_get_drvdata(lpss_clk_dev);
344 if (!clk_data)
345 return -ENODEV;
Heikki Krogerusb0d00f82014-09-02 10:55:08 +0300346 clk = clk_data->clk;
Rafael J. Wysockib59cc202013-05-08 11:55:49 +0300347
348 if (!pdata->mmio_base
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100349 || pdata->mmio_size < dev_desc->prv_offset + LPSS_CLK_SIZE)
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100350 return -ENODATA;
351
Mika Westerbergf6272172013-05-13 12:42:44 +0000352 parent = clk_data->name;
Heikki Krogerused3a8722014-05-19 14:42:07 +0300353 prv_base = pdata->mmio_base + dev_desc->prv_offset;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100354
Heikki Krogerus03f09f72014-09-02 10:55:09 +0300355 if (pdata->fixed_clk_rate) {
356 clk = clk_register_fixed_rate(NULL, devname, parent, 0,
357 pdata->fixed_clk_rate);
358 goto out;
Mika Westerbergf6272172013-05-13 12:42:44 +0000359 }
360
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300361 if (dev_desc->flags & LPSS_CLK_GATE) {
Heikki Krogerused3a8722014-05-19 14:42:07 +0300362 clk = clk_register_gate(NULL, devname, parent, 0,
363 prv_base, 0, 0, NULL);
364 parent = devname;
365 }
366
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300367 if (dev_desc->flags & LPSS_CLK_DIVIDER) {
Heikki Krogerused3a8722014-05-19 14:42:07 +0300368 /* Prevent division by zero */
369 if (!readl(prv_base))
370 writel(LPSS_CLK_DIVIDER_DEF_MASK, prv_base);
371
372 clk_name = kasprintf(GFP_KERNEL, "%s-div", devname);
373 if (!clk_name)
374 return -ENOMEM;
375 clk = clk_register_fractional_divider(NULL, clk_name, parent,
376 0, prv_base,
377 1, 15, 16, 15, 0, NULL);
378 parent = clk_name;
379
380 clk_name = kasprintf(GFP_KERNEL, "%s-update", devname);
381 if (!clk_name) {
382 kfree(parent);
383 return -ENOMEM;
384 }
385 clk = clk_register_gate(NULL, clk_name, parent,
386 CLK_SET_RATE_PARENT | CLK_SET_RATE_GATE,
387 prv_base, 31, 0, NULL);
388 kfree(parent);
389 kfree(clk_name);
Mika Westerbergf6272172013-05-13 12:42:44 +0000390 }
Heikki Krogerus03f09f72014-09-02 10:55:09 +0300391out:
Mika Westerbergf6272172013-05-13 12:42:44 +0000392 if (IS_ERR(clk))
393 return PTR_ERR(clk);
394
Heikki Krogerused3a8722014-05-19 14:42:07 +0300395 pdata->clk = clk;
Heikki Krogerusfcf07892015-03-06 15:48:38 +0200396 clk_register_clkdev(clk, dev_desc->clk_con_id, devname);
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100397 return 0;
398}
399
400static int acpi_lpss_create_device(struct acpi_device *adev,
401 const struct acpi_device_id *id)
402{
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200403 const struct lpss_device_desc *dev_desc;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100404 struct lpss_private_data *pdata;
Jiang Liu90e97822015-02-05 13:44:43 +0800405 struct resource_entry *rentry;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100406 struct list_head resource_list;
Rafael J. Wysocki8ce62f82014-05-25 14:38:52 +0200407 struct platform_device *pdev;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100408 int ret;
409
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200410 dev_desc = (const struct lpss_device_desc *)id->driver_data;
Rafael J. Wysocki8ce62f82014-05-25 14:38:52 +0200411 if (!dev_desc) {
Heikki Krogerus15718752016-11-03 16:21:26 +0200412 pdev = acpi_create_platform_device(adev, NULL);
Rafael J. Wysocki8ce62f82014-05-25 14:38:52 +0200413 return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
414 }
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100415 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
416 if (!pdata)
417 return -ENOMEM;
418
419 INIT_LIST_HEAD(&resource_list);
420 ret = acpi_dev_get_resources(adev, &resource_list, is_memory, NULL);
421 if (ret < 0)
422 goto err_out;
423
424 list_for_each_entry(rentry, &resource_list, node)
Jiang Liu90e97822015-02-05 13:44:43 +0800425 if (resource_type(rentry->res) == IORESOURCE_MEM) {
Mika Westerberg958c4eb2013-06-18 16:51:35 +0300426 if (dev_desc->prv_size_override)
427 pdata->mmio_size = dev_desc->prv_size_override;
428 else
Jiang Liu90e97822015-02-05 13:44:43 +0800429 pdata->mmio_size = resource_size(rentry->res);
430 pdata->mmio_base = ioremap(rentry->res->start,
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100431 pdata->mmio_size);
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100432 break;
433 }
434
435 acpi_dev_free_resource_list(&resource_list);
436
Rafael J. Wysockid3e13ff2015-07-07 00:31:47 +0200437 if (!pdata->mmio_base) {
438 ret = -ENOMEM;
439 goto err_out;
440 }
441
Mika Westerbergaf65cfe2013-09-02 13:30:25 +0300442 pdata->dev_desc = dev_desc;
443
Heikki Krogerus03f09f72014-09-02 10:55:09 +0300444 if (dev_desc->setup)
445 dev_desc->setup(pdata);
446
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300447 if (dev_desc->flags & LPSS_CLK) {
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100448 ret = register_device_clock(adev, pdata);
449 if (ret) {
Rafael J. Wysockib9e95fc2013-06-19 00:45:34 +0200450 /* Skip the device, but continue the namespace scan. */
451 ret = 0;
452 goto err_out;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100453 }
454 }
455
Rafael J. Wysockib9e95fc2013-06-19 00:45:34 +0200456 /*
457 * This works around a known issue in ACPI tables where LPSS devices
458 * have _PS0 and _PS3 without _PSC (and no power resources), so
459 * acpi_bus_init_power() will assume that the BIOS has put them into D0.
460 */
461 ret = acpi_device_fix_up_power(adev);
462 if (ret) {
463 /* Skip the device, but continue the namespace scan. */
464 ret = 0;
465 goto err_out;
466 }
467
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100468 adev->driver_data = pdata;
Heikki Krogerus15718752016-11-03 16:21:26 +0200469 pdev = acpi_create_platform_device(adev, dev_desc->properties);
Rafael J. Wysocki8ce62f82014-05-25 14:38:52 +0200470 if (!IS_ERR_OR_NULL(pdev)) {
Rafael J. Wysocki8ce62f82014-05-25 14:38:52 +0200471 return 1;
472 }
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100473
Rafael J. Wysocki8ce62f82014-05-25 14:38:52 +0200474 ret = PTR_ERR(pdev);
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100475 adev->driver_data = NULL;
476
477 err_out:
478 kfree(pdata);
479 return ret;
480}
481
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +0100482static u32 __lpss_reg_read(struct lpss_private_data *pdata, unsigned int reg)
483{
484 return readl(pdata->mmio_base + pdata->dev_desc->prv_offset + reg);
485}
486
487static void __lpss_reg_write(u32 val, struct lpss_private_data *pdata,
488 unsigned int reg)
489{
490 writel(val, pdata->mmio_base + pdata->dev_desc->prv_offset + reg);
491}
492
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100493static int lpss_reg_read(struct device *dev, unsigned int reg, u32 *val)
494{
495 struct acpi_device *adev;
496 struct lpss_private_data *pdata;
497 unsigned long flags;
498 int ret;
499
500 ret = acpi_bus_get_device(ACPI_HANDLE(dev), &adev);
501 if (WARN_ON(ret))
502 return ret;
503
504 spin_lock_irqsave(&dev->power.lock, flags);
505 if (pm_runtime_suspended(dev)) {
506 ret = -EAGAIN;
507 goto out;
508 }
509 pdata = acpi_driver_data(adev);
510 if (WARN_ON(!pdata || !pdata->mmio_base)) {
511 ret = -ENODEV;
512 goto out;
513 }
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +0100514 *val = __lpss_reg_read(pdata, reg);
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100515
516 out:
517 spin_unlock_irqrestore(&dev->power.lock, flags);
518 return ret;
519}
520
521static ssize_t lpss_ltr_show(struct device *dev, struct device_attribute *attr,
522 char *buf)
523{
524 u32 ltr_value = 0;
525 unsigned int reg;
526 int ret;
527
528 reg = strcmp(attr->attr.name, "auto_ltr") ? LPSS_SW_LTR : LPSS_AUTO_LTR;
529 ret = lpss_reg_read(dev, reg, &ltr_value);
530 if (ret)
531 return ret;
532
533 return snprintf(buf, PAGE_SIZE, "%08x\n", ltr_value);
534}
535
536static ssize_t lpss_ltr_mode_show(struct device *dev,
537 struct device_attribute *attr, char *buf)
538{
539 u32 ltr_mode = 0;
540 char *outstr;
541 int ret;
542
543 ret = lpss_reg_read(dev, LPSS_GENERAL, &ltr_mode);
544 if (ret)
545 return ret;
546
547 outstr = (ltr_mode & LPSS_GENERAL_LTR_MODE_SW) ? "sw" : "auto";
548 return sprintf(buf, "%s\n", outstr);
549}
550
551static DEVICE_ATTR(auto_ltr, S_IRUSR, lpss_ltr_show, NULL);
552static DEVICE_ATTR(sw_ltr, S_IRUSR, lpss_ltr_show, NULL);
553static DEVICE_ATTR(ltr_mode, S_IRUSR, lpss_ltr_mode_show, NULL);
554
555static struct attribute *lpss_attrs[] = {
556 &dev_attr_auto_ltr.attr,
557 &dev_attr_sw_ltr.attr,
558 &dev_attr_ltr_mode.attr,
559 NULL,
560};
561
562static struct attribute_group lpss_attr_group = {
563 .attrs = lpss_attrs,
564 .name = "lpss_ltr",
565};
566
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +0100567static void acpi_lpss_set_ltr(struct device *dev, s32 val)
568{
569 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
570 u32 ltr_mode, ltr_val;
571
572 ltr_mode = __lpss_reg_read(pdata, LPSS_GENERAL);
573 if (val < 0) {
574 if (ltr_mode & LPSS_GENERAL_LTR_MODE_SW) {
575 ltr_mode &= ~LPSS_GENERAL_LTR_MODE_SW;
576 __lpss_reg_write(ltr_mode, pdata, LPSS_GENERAL);
577 }
578 return;
579 }
580 ltr_val = __lpss_reg_read(pdata, LPSS_SW_LTR) & ~LPSS_LTR_SNOOP_MASK;
581 if (val >= LPSS_LTR_SNOOP_LAT_CUTOFF) {
582 ltr_val |= LPSS_LTR_SNOOP_LAT_32US;
583 val = LPSS_LTR_MAX_VAL;
584 } else if (val > LPSS_LTR_MAX_VAL) {
585 ltr_val |= LPSS_LTR_SNOOP_LAT_32US | LPSS_LTR_SNOOP_REQ;
586 val >>= LPSS_LTR_SNOOP_LAT_SHIFT;
587 } else {
588 ltr_val |= LPSS_LTR_SNOOP_LAT_1US | LPSS_LTR_SNOOP_REQ;
589 }
590 ltr_val |= val;
591 __lpss_reg_write(ltr_val, pdata, LPSS_SW_LTR);
592 if (!(ltr_mode & LPSS_GENERAL_LTR_MODE_SW)) {
593 ltr_mode |= LPSS_GENERAL_LTR_MODE_SW;
594 __lpss_reg_write(ltr_mode, pdata, LPSS_GENERAL);
595 }
596}
597
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300598#ifdef CONFIG_PM
599/**
600 * acpi_lpss_save_ctx() - Save the private registers of LPSS device
601 * @dev: LPSS device
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200602 * @pdata: pointer to the private data of the LPSS device
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300603 *
604 * Most LPSS devices have private registers which may loose their context when
605 * the device is powered down. acpi_lpss_save_ctx() saves those registers into
606 * prv_reg_ctx array.
607 */
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200608static void acpi_lpss_save_ctx(struct device *dev,
609 struct lpss_private_data *pdata)
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300610{
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300611 unsigned int i;
612
613 for (i = 0; i < LPSS_PRV_REG_COUNT; i++) {
614 unsigned long offset = i * sizeof(u32);
615
616 pdata->prv_reg_ctx[i] = __lpss_reg_read(pdata, offset);
617 dev_dbg(dev, "saving 0x%08x from LPSS reg at offset 0x%02lx\n",
618 pdata->prv_reg_ctx[i], offset);
619 }
620}
621
622/**
623 * acpi_lpss_restore_ctx() - Restore the private registers of LPSS device
624 * @dev: LPSS device
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200625 * @pdata: pointer to the private data of the LPSS device
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300626 *
627 * Restores the registers that were previously stored with acpi_lpss_save_ctx().
628 */
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200629static void acpi_lpss_restore_ctx(struct device *dev,
630 struct lpss_private_data *pdata)
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300631{
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300632 unsigned int i;
633
Andy Shevchenko02b98542015-12-04 23:49:21 +0200634 for (i = 0; i < LPSS_PRV_REG_COUNT; i++) {
635 unsigned long offset = i * sizeof(u32);
636
637 __lpss_reg_write(pdata->prv_reg_ctx[i], pdata, offset);
638 dev_dbg(dev, "restoring 0x%08x to LPSS reg at offset 0x%02lx\n",
639 pdata->prv_reg_ctx[i], offset);
640 }
641}
642
643static void acpi_lpss_d3_to_d0_delay(struct lpss_private_data *pdata)
644{
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300645 /*
646 * The following delay is needed or the subsequent write operations may
647 * fail. The LPSS devices are actually PCI devices and the PCI spec
648 * expects 10ms delay before the device can be accessed after D3 to D0
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530649 * transition. However some platforms like BSW does not need this delay.
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300650 */
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530651 unsigned int delay = 10; /* default 10ms delay */
652
653 if (pdata->dev_desc->flags & LPSS_NO_D3_DELAY)
654 delay = 0;
655
656 msleep(delay);
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300657}
658
Andy Shevchenkoc3a49cf2015-12-04 23:49:20 +0200659static int acpi_lpss_activate(struct device *dev)
660{
661 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
662 int ret;
663
664 ret = acpi_dev_runtime_resume(dev);
665 if (ret)
666 return ret;
667
668 acpi_lpss_d3_to_d0_delay(pdata);
669
670 /*
671 * This is called only on ->probe() stage where a device is either in
672 * known state defined by BIOS or most likely powered off. Due to this
673 * we have to deassert reset line to be sure that ->probe() will
674 * recognize the device.
675 */
676 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
677 lpss_deassert_reset(pdata);
678
679 return 0;
680}
681
682static void acpi_lpss_dismiss(struct device *dev)
683{
684 acpi_dev_runtime_suspend(dev);
685}
686
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300687#ifdef CONFIG_PM_SLEEP
688static int acpi_lpss_suspend_late(struct device *dev)
689{
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200690 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
691 int ret;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300692
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200693 ret = pm_generic_suspend_late(dev);
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300694 if (ret)
695 return ret;
696
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200697 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
698 acpi_lpss_save_ctx(dev, pdata);
699
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300700 return acpi_dev_suspend_late(dev);
701}
702
Fu Zhonghuif4168b62014-09-09 16:30:06 +0200703static int acpi_lpss_resume_early(struct device *dev)
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300704{
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200705 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
706 int ret;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300707
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200708 ret = acpi_dev_resume_early(dev);
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300709 if (ret)
710 return ret;
711
Andy Shevchenko02b98542015-12-04 23:49:21 +0200712 acpi_lpss_d3_to_d0_delay(pdata);
713
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200714 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
715 acpi_lpss_restore_ctx(dev, pdata);
716
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300717 return pm_generic_resume_early(dev);
718}
719#endif /* CONFIG_PM_SLEEP */
720
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100721/* IOSF SB for LPSS island */
722#define LPSS_IOSF_UNIT_LPIOEP 0xA0
723#define LPSS_IOSF_UNIT_LPIO1 0xAB
724#define LPSS_IOSF_UNIT_LPIO2 0xAC
725
726#define LPSS_IOSF_PMCSR 0x84
727#define LPSS_PMCSR_D0 0
728#define LPSS_PMCSR_D3hot 3
729#define LPSS_PMCSR_Dx_MASK GENMASK(1, 0)
730
731#define LPSS_IOSF_GPIODEF0 0x154
732#define LPSS_GPIODEF0_DMA1_D3 BIT(2)
733#define LPSS_GPIODEF0_DMA2_D3 BIT(3)
734#define LPSS_GPIODEF0_DMA_D3_MASK GENMASK(3, 2)
Andy Shevchenkod132d6d2016-11-17 16:30:06 +0200735#define LPSS_GPIODEF0_DMA_LLP BIT(13)
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100736
737static DEFINE_MUTEX(lpss_iosf_mutex);
738
739static void lpss_iosf_enter_d3_state(void)
740{
741 u32 value1 = 0;
Andy Shevchenkod132d6d2016-11-17 16:30:06 +0200742 u32 mask1 = LPSS_GPIODEF0_DMA_D3_MASK | LPSS_GPIODEF0_DMA_LLP;
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100743 u32 value2 = LPSS_PMCSR_D3hot;
744 u32 mask2 = LPSS_PMCSR_Dx_MASK;
745 /*
746 * PMC provides an information about actual status of the LPSS devices.
747 * Here we read the values related to LPSS power island, i.e. LPSS
748 * devices, excluding both LPSS DMA controllers, along with SCC domain.
749 */
750 u32 func_dis, d3_sts_0, pmc_status, pmc_mask = 0xfe000ffe;
751 int ret;
752
753 ret = pmc_atom_read(PMC_FUNC_DIS, &func_dis);
754 if (ret)
755 return;
756
757 mutex_lock(&lpss_iosf_mutex);
758
759 ret = pmc_atom_read(PMC_D3_STS_0, &d3_sts_0);
760 if (ret)
761 goto exit;
762
763 /*
764 * Get the status of entire LPSS power island per device basis.
765 * Shutdown both LPSS DMA controllers if and only if all other devices
766 * are already in D3hot.
767 */
768 pmc_status = (~(d3_sts_0 | func_dis)) & pmc_mask;
769 if (pmc_status)
770 goto exit;
771
772 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO1, MBI_CFG_WRITE,
773 LPSS_IOSF_PMCSR, value2, mask2);
774
775 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO2, MBI_CFG_WRITE,
776 LPSS_IOSF_PMCSR, value2, mask2);
777
778 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIOEP, MBI_CR_WRITE,
779 LPSS_IOSF_GPIODEF0, value1, mask1);
780exit:
781 mutex_unlock(&lpss_iosf_mutex);
782}
783
784static void lpss_iosf_exit_d3_state(void)
785{
Andy Shevchenkod132d6d2016-11-17 16:30:06 +0200786 u32 value1 = LPSS_GPIODEF0_DMA1_D3 | LPSS_GPIODEF0_DMA2_D3 |
787 LPSS_GPIODEF0_DMA_LLP;
788 u32 mask1 = LPSS_GPIODEF0_DMA_D3_MASK | LPSS_GPIODEF0_DMA_LLP;
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100789 u32 value2 = LPSS_PMCSR_D0;
790 u32 mask2 = LPSS_PMCSR_Dx_MASK;
791
792 mutex_lock(&lpss_iosf_mutex);
793
794 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIOEP, MBI_CR_WRITE,
795 LPSS_IOSF_GPIODEF0, value1, mask1);
796
797 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO2, MBI_CFG_WRITE,
798 LPSS_IOSF_PMCSR, value2, mask2);
799
800 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO1, MBI_CFG_WRITE,
801 LPSS_IOSF_PMCSR, value2, mask2);
802
803 mutex_unlock(&lpss_iosf_mutex);
804}
805
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300806static int acpi_lpss_runtime_suspend(struct device *dev)
807{
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200808 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
809 int ret;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300810
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200811 ret = pm_generic_runtime_suspend(dev);
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300812 if (ret)
813 return ret;
814
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200815 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
816 acpi_lpss_save_ctx(dev, pdata);
817
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100818 ret = acpi_dev_runtime_suspend(dev);
819
820 /*
821 * This call must be last in the sequence, otherwise PMC will return
822 * wrong status for devices being about to be powered off. See
823 * lpss_iosf_enter_d3_state() for further information.
824 */
825 if (lpss_quirks & LPSS_QUIRK_ALWAYS_POWER_ON && iosf_mbi_available())
826 lpss_iosf_enter_d3_state();
827
828 return ret;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300829}
830
831static int acpi_lpss_runtime_resume(struct device *dev)
832{
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200833 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
834 int ret;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300835
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100836 /*
837 * This call is kept first to be in symmetry with
838 * acpi_lpss_runtime_suspend() one.
839 */
840 if (lpss_quirks & LPSS_QUIRK_ALWAYS_POWER_ON && iosf_mbi_available())
841 lpss_iosf_exit_d3_state();
842
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200843 ret = acpi_dev_runtime_resume(dev);
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300844 if (ret)
845 return ret;
846
Andy Shevchenko02b98542015-12-04 23:49:21 +0200847 acpi_lpss_d3_to_d0_delay(pdata);
848
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200849 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
850 acpi_lpss_restore_ctx(dev, pdata);
851
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300852 return pm_generic_runtime_resume(dev);
853}
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300854#endif /* CONFIG_PM */
855
856static struct dev_pm_domain acpi_lpss_pm_domain = {
Andy Shevchenkoc3a49cf2015-12-04 23:49:20 +0200857#ifdef CONFIG_PM
858 .activate = acpi_lpss_activate,
859 .dismiss = acpi_lpss_dismiss,
860#endif
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300861 .ops = {
Rafael J. Wysocki5de21bb92014-11-27 22:38:23 +0100862#ifdef CONFIG_PM
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300863#ifdef CONFIG_PM_SLEEP
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300864 .prepare = acpi_subsys_prepare,
Rafael J. Wysocki58a1fbb2015-10-07 00:50:24 +0200865 .complete = pm_complete_with_resume_check,
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300866 .suspend = acpi_subsys_suspend,
Fu Zhonghuif4168b62014-09-09 16:30:06 +0200867 .suspend_late = acpi_lpss_suspend_late,
868 .resume_early = acpi_lpss_resume_early,
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300869 .freeze = acpi_subsys_freeze,
870 .poweroff = acpi_subsys_suspend,
Fu Zhonghuif4168b62014-09-09 16:30:06 +0200871 .poweroff_late = acpi_lpss_suspend_late,
872 .restore_early = acpi_lpss_resume_early,
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300873#endif
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300874 .runtime_suspend = acpi_lpss_runtime_suspend,
875 .runtime_resume = acpi_lpss_runtime_resume,
876#endif
877 },
878};
879
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100880static int acpi_lpss_platform_notify(struct notifier_block *nb,
881 unsigned long action, void *data)
882{
883 struct platform_device *pdev = to_platform_device(data);
884 struct lpss_private_data *pdata;
885 struct acpi_device *adev;
886 const struct acpi_device_id *id;
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100887
888 id = acpi_match_device(acpi_lpss_device_ids, &pdev->dev);
889 if (!id || !id->driver_data)
890 return 0;
891
892 if (acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev))
893 return 0;
894
895 pdata = acpi_driver_data(adev);
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200896 if (!pdata)
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100897 return 0;
898
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200899 if (pdata->mmio_base &&
900 pdata->mmio_size < pdata->dev_desc->prv_offset + LPSS_LTR_SIZE) {
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100901 dev_err(&pdev->dev, "MMIO size insufficient to access LTR\n");
902 return 0;
903 }
904
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300905 switch (action) {
Andy Shevchenkode16d552015-12-04 23:49:19 +0200906 case BUS_NOTIFY_BIND_DRIVER:
Tomeu Vizoso989561d2016-01-07 16:46:13 +0100907 dev_pm_domain_set(&pdev->dev, &acpi_lpss_pm_domain);
Andy Shevchenkob5f88dd2015-12-04 23:49:18 +0200908 break;
Andy Shevchenkode16d552015-12-04 23:49:19 +0200909 case BUS_NOTIFY_DRIVER_NOT_BOUND:
Andy Shevchenkob5f88dd2015-12-04 23:49:18 +0200910 case BUS_NOTIFY_UNBOUND_DRIVER:
Andy Shevchenko5be6ada2016-02-01 16:17:38 +0200911 dev_pm_domain_set(&pdev->dev, NULL);
Andy Shevchenkob5f88dd2015-12-04 23:49:18 +0200912 break;
913 case BUS_NOTIFY_ADD_DEVICE:
Tomeu Vizoso989561d2016-01-07 16:46:13 +0100914 dev_pm_domain_set(&pdev->dev, &acpi_lpss_pm_domain);
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300915 if (pdata->dev_desc->flags & LPSS_LTR)
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300916 return sysfs_create_group(&pdev->dev.kobj,
917 &lpss_attr_group);
Andy Shevchenko01ac1702014-11-05 18:34:46 +0200918 break;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300919 case BUS_NOTIFY_DEL_DEVICE:
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300920 if (pdata->dev_desc->flags & LPSS_LTR)
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300921 sysfs_remove_group(&pdev->dev.kobj, &lpss_attr_group);
Tomeu Vizoso989561d2016-01-07 16:46:13 +0100922 dev_pm_domain_set(&pdev->dev, NULL);
Andy Shevchenko01ac1702014-11-05 18:34:46 +0200923 break;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300924 default:
925 break;
926 }
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100927
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300928 return 0;
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100929}
930
931static struct notifier_block acpi_lpss_nb = {
932 .notifier_call = acpi_lpss_platform_notify,
933};
934
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +0100935static void acpi_lpss_bind(struct device *dev)
936{
937 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
938
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300939 if (!pdata || !pdata->mmio_base || !(pdata->dev_desc->flags & LPSS_LTR))
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +0100940 return;
941
942 if (pdata->mmio_size >= pdata->dev_desc->prv_offset + LPSS_LTR_SIZE)
943 dev->power.set_latency_tolerance = acpi_lpss_set_ltr;
944 else
945 dev_err(dev, "MMIO size insufficient to access LTR\n");
946}
947
948static void acpi_lpss_unbind(struct device *dev)
949{
950 dev->power.set_latency_tolerance = NULL;
951}
952
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100953static struct acpi_scan_handler lpss_handler = {
954 .ids = acpi_lpss_device_ids,
955 .attach = acpi_lpss_create_device,
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +0100956 .bind = acpi_lpss_bind,
957 .unbind = acpi_lpss_unbind,
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100958};
959
960void __init acpi_lpss_init(void)
961{
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100962 const struct x86_cpu_id *id;
963 int ret;
964
965 ret = lpt_clk_init();
966 if (ret)
967 return;
968
969 id = x86_match_cpu(lpss_cpu_ids);
970 if (id)
971 lpss_quirks |= LPSS_QUIRK_ALWAYS_POWER_ON;
972
973 bus_register_notifier(&platform_bus_type, &acpi_lpss_nb);
974 acpi_scan_add_handler(&lpss_handler);
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100975}
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200976
977#else
978
979static struct acpi_scan_handler lpss_handler = {
980 .ids = acpi_lpss_device_ids,
981};
982
983void __init acpi_lpss_init(void)
984{
985 acpi_scan_add_handler(&lpss_handler);
986}
987
988#endif /* CONFIG_X86_INTEL_LPSS */