blob: 84d3d90557d13b18386edca1b6549dc850cb9c11 [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>
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +010021#include <linux/pm_runtime.h>
Heikki Krogerusc78b0832014-05-23 16:15:09 +030022#include <linux/delay.h>
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010023
24#include "internal.h"
25
26ACPI_MODULE_NAME("acpi_lpss");
27
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +020028#ifdef CONFIG_X86_INTEL_LPSS
29
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +010030#include <asm/cpu_device_id.h>
31#include <asm/iosf_mbi.h>
32#include <asm/pmc_atom.h>
33
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +020034#define LPSS_ADDR(desc) ((unsigned long)&desc)
35
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010036#define LPSS_CLK_SIZE 0x04
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +010037#define LPSS_LTR_SIZE 0x18
38
39/* Offsets relative to LPSS_PRIVATE_OFFSET */
Heikki Krogerused3a8722014-05-19 14:42:07 +030040#define LPSS_CLK_DIVIDER_DEF_MASK (BIT(1) | BIT(16))
Mika Westerberg765bdd42014-06-17 14:33:39 +030041#define LPSS_RESETS 0x04
42#define LPSS_RESETS_RESET_FUNC BIT(0)
43#define LPSS_RESETS_RESET_APB BIT(1)
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +010044#define LPSS_GENERAL 0x08
45#define LPSS_GENERAL_LTR_MODE_SW BIT(2)
Heikki Krogerus088f1fd2013-10-09 09:49:20 +030046#define LPSS_GENERAL_UART_RTS_OVRD BIT(3)
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +010047#define LPSS_SW_LTR 0x10
48#define LPSS_AUTO_LTR 0x14
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +010049#define LPSS_LTR_SNOOP_REQ BIT(15)
50#define LPSS_LTR_SNOOP_MASK 0x0000FFFF
51#define LPSS_LTR_SNOOP_LAT_1US 0x800
52#define LPSS_LTR_SNOOP_LAT_32US 0xC00
53#define LPSS_LTR_SNOOP_LAT_SHIFT 5
54#define LPSS_LTR_SNOOP_LAT_CUTOFF 3000
55#define LPSS_LTR_MAX_VAL 0x3FF
Heikki Krogerus06d86412013-06-17 13:25:46 +030056#define LPSS_TX_INT 0x20
57#define LPSS_TX_INT_MASK BIT(1)
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010058
Heikki Krogerusc78b0832014-05-23 16:15:09 +030059#define LPSS_PRV_REG_COUNT 9
60
Heikki Krogerusff8c1af2014-09-02 10:55:07 +030061/* LPSS Flags */
62#define LPSS_CLK BIT(0)
63#define LPSS_CLK_GATE BIT(1)
64#define LPSS_CLK_DIVIDER BIT(2)
65#define LPSS_LTR BIT(3)
66#define LPSS_SAVE_CTX BIT(4)
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +053067#define LPSS_NO_D3_DELAY BIT(5)
Mika Westerbergf6272172013-05-13 12:42:44 +000068
Heikki Krogerus06d86412013-06-17 13:25:46 +030069struct lpss_private_data;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010070
71struct lpss_device_desc {
Heikki Krogerusff8c1af2014-09-02 10:55:07 +030072 unsigned int flags;
Heikki Krogerusfcf07892015-03-06 15:48:38 +020073 const char *clk_con_id;
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +010074 unsigned int prv_offset;
Mika Westerberg958c4eb2013-06-18 16:51:35 +030075 size_t prv_size_override;
Heikki Krogerus06d86412013-06-17 13:25:46 +030076 void (*setup)(struct lpss_private_data *pdata);
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010077};
78
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +010079static const struct lpss_device_desc lpss_dma_desc = {
Rafael J. Wysocki3df2da92015-02-03 14:29:43 +010080 .flags = LPSS_CLK,
Rafael J. Wysockib59cc202013-05-08 11:55:49 +030081};
82
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010083struct lpss_private_data {
84 void __iomem *mmio_base;
85 resource_size_t mmio_size;
Heikki Krogerus03f09f72014-09-02 10:55:09 +030086 unsigned int fixed_clk_rate;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010087 struct clk *clk;
88 const struct lpss_device_desc *dev_desc;
Heikki Krogerusc78b0832014-05-23 16:15:09 +030089 u32 prv_reg_ctx[LPSS_PRV_REG_COUNT];
Rafael J. Wysockif58b0822013-03-06 23:46:20 +010090};
91
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +010092/* LPSS run time quirks */
93static unsigned int lpss_quirks;
94
95/*
96 * LPSS_QUIRK_ALWAYS_POWER_ON: override power state for LPSS DMA device.
97 *
98 * The LPSS DMA controller does not have neither _PS0 nor _PS3 method. Moreover
99 * it can be powered off automatically whenever the last LPSS device goes down.
100 * In case of no power any access to the DMA controller will hang the system.
101 * The behaviour is reproduced on some HP laptops based on Intel BayTrail as
102 * well as on ASuS T100TA transformer.
103 *
104 * This quirk overrides power state of entire LPSS island to keep DMA powered
105 * on whenever we have at least one other device in use.
106 */
107#define LPSS_QUIRK_ALWAYS_POWER_ON BIT(0)
108
Heikki Krogerus1f47a772014-09-11 15:19:33 +0300109/* UART Component Parameter Register */
110#define LPSS_UART_CPR 0xF4
111#define LPSS_UART_CPR_AFCE BIT(4)
112
Heikki Krogerus06d86412013-06-17 13:25:46 +0300113static void lpss_uart_setup(struct lpss_private_data *pdata)
114{
Heikki Krogerus088f1fd2013-10-09 09:49:20 +0300115 unsigned int offset;
Heikki Krogerus1f47a772014-09-11 15:19:33 +0300116 u32 val;
Heikki Krogerus06d86412013-06-17 13:25:46 +0300117
Heikki Krogerus088f1fd2013-10-09 09:49:20 +0300118 offset = pdata->dev_desc->prv_offset + LPSS_TX_INT;
Heikki Krogerus1f47a772014-09-11 15:19:33 +0300119 val = readl(pdata->mmio_base + offset);
120 writel(val | LPSS_TX_INT_MASK, pdata->mmio_base + offset);
Heikki Krogerus088f1fd2013-10-09 09:49:20 +0300121
Heikki Krogerus1f47a772014-09-11 15:19:33 +0300122 val = readl(pdata->mmio_base + LPSS_UART_CPR);
123 if (!(val & LPSS_UART_CPR_AFCE)) {
124 offset = pdata->dev_desc->prv_offset + LPSS_GENERAL;
125 val = readl(pdata->mmio_base + offset);
126 val |= LPSS_GENERAL_UART_RTS_OVRD;
127 writel(val, pdata->mmio_base + offset);
128 }
Heikki Krogerus06d86412013-06-17 13:25:46 +0300129}
130
Mika Westerberg30957942015-02-18 13:50:17 +0200131static void lpss_deassert_reset(struct lpss_private_data *pdata)
Mika Westerberg765bdd42014-06-17 14:33:39 +0300132{
133 unsigned int offset;
134 u32 val;
135
136 offset = pdata->dev_desc->prv_offset + LPSS_RESETS;
137 val = readl(pdata->mmio_base + offset);
138 val |= LPSS_RESETS_RESET_APB | LPSS_RESETS_RESET_FUNC;
139 writel(val, pdata->mmio_base + offset);
Mika Westerberg30957942015-02-18 13:50:17 +0200140}
141
142#define LPSS_I2C_ENABLE 0x6c
143
144static void byt_i2c_setup(struct lpss_private_data *pdata)
145{
146 lpss_deassert_reset(pdata);
Heikki Krogerus03f09f72014-09-02 10:55:09 +0300147
148 if (readl(pdata->mmio_base + pdata->dev_desc->prv_offset))
149 pdata->fixed_clk_rate = 133000000;
Mika Westerberg3293c7b2015-02-18 13:50:16 +0200150
151 writel(0, pdata->mmio_base + LPSS_I2C_ENABLE);
Mika Westerberg765bdd42014-06-17 14:33:39 +0300152}
153
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200154static const struct lpss_device_desc lpt_dev_desc = {
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300155 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100156 .prv_offset = 0x800,
Heikki Krogerused3a8722014-05-19 14:42:07 +0300157};
158
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200159static const struct lpss_device_desc lpt_i2c_dev_desc = {
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300160 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_LTR,
Heikki Krogerused3a8722014-05-19 14:42:07 +0300161 .prv_offset = 0x800,
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100162};
163
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200164static const struct lpss_device_desc lpt_uart_dev_desc = {
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300165 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
Heikki Krogerusfcf07892015-03-06 15:48:38 +0200166 .clk_con_id = "baudclk",
Heikki Krogerus06d86412013-06-17 13:25:46 +0300167 .prv_offset = 0x800,
Heikki Krogerus06d86412013-06-17 13:25:46 +0300168 .setup = lpss_uart_setup,
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100169};
170
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200171static const struct lpss_device_desc lpt_sdio_dev_desc = {
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300172 .flags = LPSS_LTR,
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100173 .prv_offset = 0x1000,
Mika Westerberg958c4eb2013-06-18 16:51:35 +0300174 .prv_size_override = 0x1018,
Chew, Chiau Eee1c74812014-02-19 02:24:29 +0800175};
176
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200177static const struct lpss_device_desc byt_pwm_dev_desc = {
Heikki Krogerus3f56bf32014-09-02 10:55:10 +0300178 .flags = LPSS_SAVE_CTX,
Chew, Chiau Eee1c74812014-02-19 02:24:29 +0800179};
180
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530181static const struct lpss_device_desc bsw_pwm_dev_desc = {
182 .flags = LPSS_SAVE_CTX | LPSS_NO_D3_DELAY,
183};
184
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200185static const struct lpss_device_desc byt_uart_dev_desc = {
Rafael J. Wysocki3df2da92015-02-03 14:29:43 +0100186 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX,
Heikki Krogerusfcf07892015-03-06 15:48:38 +0200187 .clk_con_id = "baudclk",
Mika Westerbergf6272172013-05-13 12:42:44 +0000188 .prv_offset = 0x800,
Heikki Krogerus06d86412013-06-17 13:25:46 +0300189 .setup = lpss_uart_setup,
Mika Westerbergf6272172013-05-13 12:42:44 +0000190};
191
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530192static const struct lpss_device_desc bsw_uart_dev_desc = {
193 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX
194 | LPSS_NO_D3_DELAY,
195 .clk_con_id = "baudclk",
196 .prv_offset = 0x800,
197 .setup = lpss_uart_setup,
198};
199
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200200static const struct lpss_device_desc byt_spi_dev_desc = {
Rafael J. Wysocki3df2da92015-02-03 14:29:43 +0100201 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX,
Mika Westerbergf6272172013-05-13 12:42:44 +0000202 .prv_offset = 0x400,
Mika Westerbergf6272172013-05-13 12:42:44 +0000203};
204
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200205static const struct lpss_device_desc byt_sdio_dev_desc = {
Rafael J. Wysocki3df2da92015-02-03 14:29:43 +0100206 .flags = LPSS_CLK,
Mika Westerbergf6272172013-05-13 12:42:44 +0000207};
208
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200209static const struct lpss_device_desc byt_i2c_dev_desc = {
Rafael J. Wysocki3df2da92015-02-03 14:29:43 +0100210 .flags = LPSS_CLK | LPSS_SAVE_CTX,
Mika Westerbergf6272172013-05-13 12:42:44 +0000211 .prv_offset = 0x800,
Heikki Krogerus03f09f72014-09-02 10:55:09 +0300212 .setup = byt_i2c_setup,
Alan Cox1bfbd8e2014-08-19 15:55:22 +0300213};
214
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530215static const struct lpss_device_desc bsw_i2c_dev_desc = {
216 .flags = LPSS_CLK | LPSS_SAVE_CTX | LPSS_NO_D3_DELAY,
217 .prv_offset = 0x800,
218 .setup = byt_i2c_setup,
219};
220
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100221static const struct lpss_device_desc bsw_spi_dev_desc = {
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530222 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX
223 | LPSS_NO_D3_DELAY,
Mika Westerberg30957942015-02-18 13:50:17 +0200224 .prv_offset = 0x400,
225 .setup = lpss_deassert_reset,
226};
227
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100228#define ICPU(model) { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, }
229
230static const struct x86_cpu_id lpss_cpu_ids[] = {
231 ICPU(0x37), /* Valleyview, Bay Trail */
232 ICPU(0x4c), /* Braswell, Cherry Trail */
233 {}
234};
235
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200236#else
237
238#define LPSS_ADDR(desc) (0UL)
239
240#endif /* CONFIG_X86_INTEL_LPSS */
241
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100242static const struct acpi_device_id acpi_lpss_device_ids[] = {
Rafael J. Wysockib59cc202013-05-08 11:55:49 +0300243 /* Generic LPSS devices */
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200244 { "INTL9C60", LPSS_ADDR(lpss_dma_desc) },
Rafael J. Wysockib59cc202013-05-08 11:55:49 +0300245
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100246 /* Lynxpoint LPSS devices */
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200247 { "INT33C0", LPSS_ADDR(lpt_dev_desc) },
248 { "INT33C1", LPSS_ADDR(lpt_dev_desc) },
249 { "INT33C2", LPSS_ADDR(lpt_i2c_dev_desc) },
250 { "INT33C3", LPSS_ADDR(lpt_i2c_dev_desc) },
251 { "INT33C4", LPSS_ADDR(lpt_uart_dev_desc) },
252 { "INT33C5", LPSS_ADDR(lpt_uart_dev_desc) },
253 { "INT33C6", LPSS_ADDR(lpt_sdio_dev_desc) },
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100254 { "INT33C7", },
255
Mika Westerbergf6272172013-05-13 12:42:44 +0000256 /* BayTrail LPSS devices */
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200257 { "80860F09", LPSS_ADDR(byt_pwm_dev_desc) },
258 { "80860F0A", LPSS_ADDR(byt_uart_dev_desc) },
259 { "80860F0E", LPSS_ADDR(byt_spi_dev_desc) },
260 { "80860F14", LPSS_ADDR(byt_sdio_dev_desc) },
261 { "80860F41", LPSS_ADDR(byt_i2c_dev_desc) },
Mika Westerbergf6272172013-05-13 12:42:44 +0000262 { "INT33B2", },
Jin Yao20482d32014-05-15 18:28:46 +0300263 { "INT33FC", },
Mika Westerbergf6272172013-05-13 12:42:44 +0000264
Alan Cox1bfbd8e2014-08-19 15:55:22 +0300265 /* Braswell LPSS devices */
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530266 { "80862288", LPSS_ADDR(bsw_pwm_dev_desc) },
267 { "8086228A", LPSS_ADDR(bsw_uart_dev_desc) },
Mika Westerberg30957942015-02-18 13:50:17 +0200268 { "8086228E", LPSS_ADDR(bsw_spi_dev_desc) },
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530269 { "808622C1", LPSS_ADDR(bsw_i2c_dev_desc) },
Alan Cox1bfbd8e2014-08-19 15:55:22 +0300270
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530271 /* Broadwell LPSS devices */
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200272 { "INT3430", LPSS_ADDR(lpt_dev_desc) },
273 { "INT3431", LPSS_ADDR(lpt_dev_desc) },
274 { "INT3432", LPSS_ADDR(lpt_i2c_dev_desc) },
275 { "INT3433", LPSS_ADDR(lpt_i2c_dev_desc) },
276 { "INT3434", LPSS_ADDR(lpt_uart_dev_desc) },
277 { "INT3435", LPSS_ADDR(lpt_uart_dev_desc) },
278 { "INT3436", LPSS_ADDR(lpt_sdio_dev_desc) },
Mika Westerberga4d97532013-11-12 11:48:19 +0200279 { "INT3437", },
280
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300281 /* Wildcat Point LPSS devices */
282 { "INT3438", LPSS_ADDR(lpt_dev_desc) },
Jie Yang43218a12014-08-01 09:06:35 +0800283
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100284 { }
285};
286
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200287#ifdef CONFIG_X86_INTEL_LPSS
288
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100289static int is_memory(struct acpi_resource *res, void *not_used)
290{
291 struct resource r;
292 return !acpi_dev_resource_memory(res, &r);
293}
294
295/* LPSS main clock device. */
296static struct platform_device *lpss_clk_dev;
297
298static inline void lpt_register_clock_device(void)
299{
300 lpss_clk_dev = platform_device_register_simple("clk-lpt", -1, NULL, 0);
301}
302
303static int register_device_clock(struct acpi_device *adev,
304 struct lpss_private_data *pdata)
305{
306 const struct lpss_device_desc *dev_desc = pdata->dev_desc;
Heikki Krogerused3a8722014-05-19 14:42:07 +0300307 const char *devname = dev_name(&adev->dev);
Mika Westerbergf6272172013-05-13 12:42:44 +0000308 struct clk *clk = ERR_PTR(-ENODEV);
Rafael J. Wysockib59cc202013-05-08 11:55:49 +0300309 struct lpss_clk_data *clk_data;
Heikki Krogerused3a8722014-05-19 14:42:07 +0300310 const char *parent, *clk_name;
311 void __iomem *prv_base;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100312
313 if (!lpss_clk_dev)
314 lpt_register_clock_device();
315
Rafael J. Wysockib59cc202013-05-08 11:55:49 +0300316 clk_data = platform_get_drvdata(lpss_clk_dev);
317 if (!clk_data)
318 return -ENODEV;
Heikki Krogerusb0d00f82014-09-02 10:55:08 +0300319 clk = clk_data->clk;
Rafael J. Wysockib59cc202013-05-08 11:55:49 +0300320
321 if (!pdata->mmio_base
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100322 || pdata->mmio_size < dev_desc->prv_offset + LPSS_CLK_SIZE)
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100323 return -ENODATA;
324
Mika Westerbergf6272172013-05-13 12:42:44 +0000325 parent = clk_data->name;
Heikki Krogerused3a8722014-05-19 14:42:07 +0300326 prv_base = pdata->mmio_base + dev_desc->prv_offset;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100327
Heikki Krogerus03f09f72014-09-02 10:55:09 +0300328 if (pdata->fixed_clk_rate) {
329 clk = clk_register_fixed_rate(NULL, devname, parent, 0,
330 pdata->fixed_clk_rate);
331 goto out;
Mika Westerbergf6272172013-05-13 12:42:44 +0000332 }
333
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300334 if (dev_desc->flags & LPSS_CLK_GATE) {
Heikki Krogerused3a8722014-05-19 14:42:07 +0300335 clk = clk_register_gate(NULL, devname, parent, 0,
336 prv_base, 0, 0, NULL);
337 parent = devname;
338 }
339
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300340 if (dev_desc->flags & LPSS_CLK_DIVIDER) {
Heikki Krogerused3a8722014-05-19 14:42:07 +0300341 /* Prevent division by zero */
342 if (!readl(prv_base))
343 writel(LPSS_CLK_DIVIDER_DEF_MASK, prv_base);
344
345 clk_name = kasprintf(GFP_KERNEL, "%s-div", devname);
346 if (!clk_name)
347 return -ENOMEM;
348 clk = clk_register_fractional_divider(NULL, clk_name, parent,
349 0, prv_base,
350 1, 15, 16, 15, 0, NULL);
351 parent = clk_name;
352
353 clk_name = kasprintf(GFP_KERNEL, "%s-update", devname);
354 if (!clk_name) {
355 kfree(parent);
356 return -ENOMEM;
357 }
358 clk = clk_register_gate(NULL, clk_name, parent,
359 CLK_SET_RATE_PARENT | CLK_SET_RATE_GATE,
360 prv_base, 31, 0, NULL);
361 kfree(parent);
362 kfree(clk_name);
Mika Westerbergf6272172013-05-13 12:42:44 +0000363 }
Heikki Krogerus03f09f72014-09-02 10:55:09 +0300364out:
Mika Westerbergf6272172013-05-13 12:42:44 +0000365 if (IS_ERR(clk))
366 return PTR_ERR(clk);
367
Heikki Krogerused3a8722014-05-19 14:42:07 +0300368 pdata->clk = clk;
Heikki Krogerusfcf07892015-03-06 15:48:38 +0200369 clk_register_clkdev(clk, dev_desc->clk_con_id, devname);
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100370 return 0;
371}
372
373static int acpi_lpss_create_device(struct acpi_device *adev,
374 const struct acpi_device_id *id)
375{
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200376 const struct lpss_device_desc *dev_desc;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100377 struct lpss_private_data *pdata;
Jiang Liu90e97822015-02-05 13:44:43 +0800378 struct resource_entry *rentry;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100379 struct list_head resource_list;
Rafael J. Wysocki8ce62f82014-05-25 14:38:52 +0200380 struct platform_device *pdev;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100381 int ret;
382
Mathias Krauseb2687cd2015-06-13 14:26:50 +0200383 dev_desc = (const struct lpss_device_desc *)id->driver_data;
Rafael J. Wysocki8ce62f82014-05-25 14:38:52 +0200384 if (!dev_desc) {
385 pdev = acpi_create_platform_device(adev);
386 return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
387 }
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100388 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
389 if (!pdata)
390 return -ENOMEM;
391
392 INIT_LIST_HEAD(&resource_list);
393 ret = acpi_dev_get_resources(adev, &resource_list, is_memory, NULL);
394 if (ret < 0)
395 goto err_out;
396
397 list_for_each_entry(rentry, &resource_list, node)
Jiang Liu90e97822015-02-05 13:44:43 +0800398 if (resource_type(rentry->res) == IORESOURCE_MEM) {
Mika Westerberg958c4eb2013-06-18 16:51:35 +0300399 if (dev_desc->prv_size_override)
400 pdata->mmio_size = dev_desc->prv_size_override;
401 else
Jiang Liu90e97822015-02-05 13:44:43 +0800402 pdata->mmio_size = resource_size(rentry->res);
403 pdata->mmio_base = ioremap(rentry->res->start,
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100404 pdata->mmio_size);
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100405 break;
406 }
407
408 acpi_dev_free_resource_list(&resource_list);
409
Rafael J. Wysockid3e13ff2015-07-07 00:31:47 +0200410 if (!pdata->mmio_base) {
411 ret = -ENOMEM;
412 goto err_out;
413 }
414
Mika Westerbergaf65cfe2013-09-02 13:30:25 +0300415 pdata->dev_desc = dev_desc;
416
Heikki Krogerus03f09f72014-09-02 10:55:09 +0300417 if (dev_desc->setup)
418 dev_desc->setup(pdata);
419
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300420 if (dev_desc->flags & LPSS_CLK) {
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100421 ret = register_device_clock(adev, pdata);
422 if (ret) {
Rafael J. Wysockib9e95fc2013-06-19 00:45:34 +0200423 /* Skip the device, but continue the namespace scan. */
424 ret = 0;
425 goto err_out;
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100426 }
427 }
428
Rafael J. Wysockib9e95fc2013-06-19 00:45:34 +0200429 /*
430 * This works around a known issue in ACPI tables where LPSS devices
431 * have _PS0 and _PS3 without _PSC (and no power resources), so
432 * acpi_bus_init_power() will assume that the BIOS has put them into D0.
433 */
434 ret = acpi_device_fix_up_power(adev);
435 if (ret) {
436 /* Skip the device, but continue the namespace scan. */
437 ret = 0;
438 goto err_out;
439 }
440
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100441 adev->driver_data = pdata;
Rafael J. Wysocki8ce62f82014-05-25 14:38:52 +0200442 pdev = acpi_create_platform_device(adev);
443 if (!IS_ERR_OR_NULL(pdev)) {
Rafael J. Wysocki8ce62f82014-05-25 14:38:52 +0200444 return 1;
445 }
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100446
Rafael J. Wysocki8ce62f82014-05-25 14:38:52 +0200447 ret = PTR_ERR(pdev);
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100448 adev->driver_data = NULL;
449
450 err_out:
451 kfree(pdata);
452 return ret;
453}
454
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +0100455static u32 __lpss_reg_read(struct lpss_private_data *pdata, unsigned int reg)
456{
457 return readl(pdata->mmio_base + pdata->dev_desc->prv_offset + reg);
458}
459
460static void __lpss_reg_write(u32 val, struct lpss_private_data *pdata,
461 unsigned int reg)
462{
463 writel(val, pdata->mmio_base + pdata->dev_desc->prv_offset + reg);
464}
465
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100466static int lpss_reg_read(struct device *dev, unsigned int reg, u32 *val)
467{
468 struct acpi_device *adev;
469 struct lpss_private_data *pdata;
470 unsigned long flags;
471 int ret;
472
473 ret = acpi_bus_get_device(ACPI_HANDLE(dev), &adev);
474 if (WARN_ON(ret))
475 return ret;
476
477 spin_lock_irqsave(&dev->power.lock, flags);
478 if (pm_runtime_suspended(dev)) {
479 ret = -EAGAIN;
480 goto out;
481 }
482 pdata = acpi_driver_data(adev);
483 if (WARN_ON(!pdata || !pdata->mmio_base)) {
484 ret = -ENODEV;
485 goto out;
486 }
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +0100487 *val = __lpss_reg_read(pdata, reg);
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100488
489 out:
490 spin_unlock_irqrestore(&dev->power.lock, flags);
491 return ret;
492}
493
494static ssize_t lpss_ltr_show(struct device *dev, struct device_attribute *attr,
495 char *buf)
496{
497 u32 ltr_value = 0;
498 unsigned int reg;
499 int ret;
500
501 reg = strcmp(attr->attr.name, "auto_ltr") ? LPSS_SW_LTR : LPSS_AUTO_LTR;
502 ret = lpss_reg_read(dev, reg, &ltr_value);
503 if (ret)
504 return ret;
505
506 return snprintf(buf, PAGE_SIZE, "%08x\n", ltr_value);
507}
508
509static ssize_t lpss_ltr_mode_show(struct device *dev,
510 struct device_attribute *attr, char *buf)
511{
512 u32 ltr_mode = 0;
513 char *outstr;
514 int ret;
515
516 ret = lpss_reg_read(dev, LPSS_GENERAL, &ltr_mode);
517 if (ret)
518 return ret;
519
520 outstr = (ltr_mode & LPSS_GENERAL_LTR_MODE_SW) ? "sw" : "auto";
521 return sprintf(buf, "%s\n", outstr);
522}
523
524static DEVICE_ATTR(auto_ltr, S_IRUSR, lpss_ltr_show, NULL);
525static DEVICE_ATTR(sw_ltr, S_IRUSR, lpss_ltr_show, NULL);
526static DEVICE_ATTR(ltr_mode, S_IRUSR, lpss_ltr_mode_show, NULL);
527
528static struct attribute *lpss_attrs[] = {
529 &dev_attr_auto_ltr.attr,
530 &dev_attr_sw_ltr.attr,
531 &dev_attr_ltr_mode.attr,
532 NULL,
533};
534
535static struct attribute_group lpss_attr_group = {
536 .attrs = lpss_attrs,
537 .name = "lpss_ltr",
538};
539
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +0100540static void acpi_lpss_set_ltr(struct device *dev, s32 val)
541{
542 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
543 u32 ltr_mode, ltr_val;
544
545 ltr_mode = __lpss_reg_read(pdata, LPSS_GENERAL);
546 if (val < 0) {
547 if (ltr_mode & LPSS_GENERAL_LTR_MODE_SW) {
548 ltr_mode &= ~LPSS_GENERAL_LTR_MODE_SW;
549 __lpss_reg_write(ltr_mode, pdata, LPSS_GENERAL);
550 }
551 return;
552 }
553 ltr_val = __lpss_reg_read(pdata, LPSS_SW_LTR) & ~LPSS_LTR_SNOOP_MASK;
554 if (val >= LPSS_LTR_SNOOP_LAT_CUTOFF) {
555 ltr_val |= LPSS_LTR_SNOOP_LAT_32US;
556 val = LPSS_LTR_MAX_VAL;
557 } else if (val > LPSS_LTR_MAX_VAL) {
558 ltr_val |= LPSS_LTR_SNOOP_LAT_32US | LPSS_LTR_SNOOP_REQ;
559 val >>= LPSS_LTR_SNOOP_LAT_SHIFT;
560 } else {
561 ltr_val |= LPSS_LTR_SNOOP_LAT_1US | LPSS_LTR_SNOOP_REQ;
562 }
563 ltr_val |= val;
564 __lpss_reg_write(ltr_val, pdata, LPSS_SW_LTR);
565 if (!(ltr_mode & LPSS_GENERAL_LTR_MODE_SW)) {
566 ltr_mode |= LPSS_GENERAL_LTR_MODE_SW;
567 __lpss_reg_write(ltr_mode, pdata, LPSS_GENERAL);
568 }
569}
570
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300571#ifdef CONFIG_PM
572/**
573 * acpi_lpss_save_ctx() - Save the private registers of LPSS device
574 * @dev: LPSS device
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200575 * @pdata: pointer to the private data of the LPSS device
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300576 *
577 * Most LPSS devices have private registers which may loose their context when
578 * the device is powered down. acpi_lpss_save_ctx() saves those registers into
579 * prv_reg_ctx array.
580 */
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200581static void acpi_lpss_save_ctx(struct device *dev,
582 struct lpss_private_data *pdata)
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300583{
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300584 unsigned int i;
585
586 for (i = 0; i < LPSS_PRV_REG_COUNT; i++) {
587 unsigned long offset = i * sizeof(u32);
588
589 pdata->prv_reg_ctx[i] = __lpss_reg_read(pdata, offset);
590 dev_dbg(dev, "saving 0x%08x from LPSS reg at offset 0x%02lx\n",
591 pdata->prv_reg_ctx[i], offset);
592 }
593}
594
595/**
596 * acpi_lpss_restore_ctx() - Restore the private registers of LPSS device
597 * @dev: LPSS device
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200598 * @pdata: pointer to the private data of the LPSS device
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300599 *
600 * Restores the registers that were previously stored with acpi_lpss_save_ctx().
601 */
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200602static void acpi_lpss_restore_ctx(struct device *dev,
603 struct lpss_private_data *pdata)
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300604{
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300605 unsigned int i;
606
Andy Shevchenko02b98542015-12-04 23:49:21 +0200607 for (i = 0; i < LPSS_PRV_REG_COUNT; i++) {
608 unsigned long offset = i * sizeof(u32);
609
610 __lpss_reg_write(pdata->prv_reg_ctx[i], pdata, offset);
611 dev_dbg(dev, "restoring 0x%08x to LPSS reg at offset 0x%02lx\n",
612 pdata->prv_reg_ctx[i], offset);
613 }
614}
615
616static void acpi_lpss_d3_to_d0_delay(struct lpss_private_data *pdata)
617{
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300618 /*
619 * The following delay is needed or the subsequent write operations may
620 * fail. The LPSS devices are actually PCI devices and the PCI spec
621 * expects 10ms delay before the device can be accessed after D3 to D0
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530622 * transition. However some platforms like BSW does not need this delay.
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300623 */
Srinidhi Kasagarb00855a2015-08-27 21:30:55 +0530624 unsigned int delay = 10; /* default 10ms delay */
625
626 if (pdata->dev_desc->flags & LPSS_NO_D3_DELAY)
627 delay = 0;
628
629 msleep(delay);
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300630}
631
Andy Shevchenkoc3a49cf2015-12-04 23:49:20 +0200632static int acpi_lpss_activate(struct device *dev)
633{
634 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
635 int ret;
636
637 ret = acpi_dev_runtime_resume(dev);
638 if (ret)
639 return ret;
640
641 acpi_lpss_d3_to_d0_delay(pdata);
642
643 /*
644 * This is called only on ->probe() stage where a device is either in
645 * known state defined by BIOS or most likely powered off. Due to this
646 * we have to deassert reset line to be sure that ->probe() will
647 * recognize the device.
648 */
649 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
650 lpss_deassert_reset(pdata);
651
652 return 0;
653}
654
655static void acpi_lpss_dismiss(struct device *dev)
656{
657 acpi_dev_runtime_suspend(dev);
658}
659
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300660#ifdef CONFIG_PM_SLEEP
661static int acpi_lpss_suspend_late(struct device *dev)
662{
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200663 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
664 int ret;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300665
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200666 ret = pm_generic_suspend_late(dev);
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300667 if (ret)
668 return ret;
669
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200670 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
671 acpi_lpss_save_ctx(dev, pdata);
672
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300673 return acpi_dev_suspend_late(dev);
674}
675
Fu Zhonghuif4168b62014-09-09 16:30:06 +0200676static int acpi_lpss_resume_early(struct device *dev)
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300677{
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200678 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
679 int ret;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300680
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200681 ret = acpi_dev_resume_early(dev);
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300682 if (ret)
683 return ret;
684
Andy Shevchenko02b98542015-12-04 23:49:21 +0200685 acpi_lpss_d3_to_d0_delay(pdata);
686
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200687 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
688 acpi_lpss_restore_ctx(dev, pdata);
689
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300690 return pm_generic_resume_early(dev);
691}
692#endif /* CONFIG_PM_SLEEP */
693
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100694/* IOSF SB for LPSS island */
695#define LPSS_IOSF_UNIT_LPIOEP 0xA0
696#define LPSS_IOSF_UNIT_LPIO1 0xAB
697#define LPSS_IOSF_UNIT_LPIO2 0xAC
698
699#define LPSS_IOSF_PMCSR 0x84
700#define LPSS_PMCSR_D0 0
701#define LPSS_PMCSR_D3hot 3
702#define LPSS_PMCSR_Dx_MASK GENMASK(1, 0)
703
704#define LPSS_IOSF_GPIODEF0 0x154
705#define LPSS_GPIODEF0_DMA1_D3 BIT(2)
706#define LPSS_GPIODEF0_DMA2_D3 BIT(3)
707#define LPSS_GPIODEF0_DMA_D3_MASK GENMASK(3, 2)
708
709static DEFINE_MUTEX(lpss_iosf_mutex);
710
711static void lpss_iosf_enter_d3_state(void)
712{
713 u32 value1 = 0;
714 u32 mask1 = LPSS_GPIODEF0_DMA_D3_MASK;
715 u32 value2 = LPSS_PMCSR_D3hot;
716 u32 mask2 = LPSS_PMCSR_Dx_MASK;
717 /*
718 * PMC provides an information about actual status of the LPSS devices.
719 * Here we read the values related to LPSS power island, i.e. LPSS
720 * devices, excluding both LPSS DMA controllers, along with SCC domain.
721 */
722 u32 func_dis, d3_sts_0, pmc_status, pmc_mask = 0xfe000ffe;
723 int ret;
724
725 ret = pmc_atom_read(PMC_FUNC_DIS, &func_dis);
726 if (ret)
727 return;
728
729 mutex_lock(&lpss_iosf_mutex);
730
731 ret = pmc_atom_read(PMC_D3_STS_0, &d3_sts_0);
732 if (ret)
733 goto exit;
734
735 /*
736 * Get the status of entire LPSS power island per device basis.
737 * Shutdown both LPSS DMA controllers if and only if all other devices
738 * are already in D3hot.
739 */
740 pmc_status = (~(d3_sts_0 | func_dis)) & pmc_mask;
741 if (pmc_status)
742 goto exit;
743
744 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO1, MBI_CFG_WRITE,
745 LPSS_IOSF_PMCSR, value2, mask2);
746
747 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO2, MBI_CFG_WRITE,
748 LPSS_IOSF_PMCSR, value2, mask2);
749
750 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIOEP, MBI_CR_WRITE,
751 LPSS_IOSF_GPIODEF0, value1, mask1);
752exit:
753 mutex_unlock(&lpss_iosf_mutex);
754}
755
756static void lpss_iosf_exit_d3_state(void)
757{
758 u32 value1 = LPSS_GPIODEF0_DMA1_D3 | LPSS_GPIODEF0_DMA2_D3;
759 u32 mask1 = LPSS_GPIODEF0_DMA_D3_MASK;
760 u32 value2 = LPSS_PMCSR_D0;
761 u32 mask2 = LPSS_PMCSR_Dx_MASK;
762
763 mutex_lock(&lpss_iosf_mutex);
764
765 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIOEP, MBI_CR_WRITE,
766 LPSS_IOSF_GPIODEF0, value1, mask1);
767
768 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO2, MBI_CFG_WRITE,
769 LPSS_IOSF_PMCSR, value2, mask2);
770
771 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO1, MBI_CFG_WRITE,
772 LPSS_IOSF_PMCSR, value2, mask2);
773
774 mutex_unlock(&lpss_iosf_mutex);
775}
776
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300777static int acpi_lpss_runtime_suspend(struct device *dev)
778{
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200779 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
780 int ret;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300781
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200782 ret = pm_generic_runtime_suspend(dev);
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300783 if (ret)
784 return ret;
785
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200786 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
787 acpi_lpss_save_ctx(dev, pdata);
788
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100789 ret = acpi_dev_runtime_suspend(dev);
790
791 /*
792 * This call must be last in the sequence, otherwise PMC will return
793 * wrong status for devices being about to be powered off. See
794 * lpss_iosf_enter_d3_state() for further information.
795 */
796 if (lpss_quirks & LPSS_QUIRK_ALWAYS_POWER_ON && iosf_mbi_available())
797 lpss_iosf_enter_d3_state();
798
799 return ret;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300800}
801
802static int acpi_lpss_runtime_resume(struct device *dev)
803{
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200804 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
805 int ret;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300806
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100807 /*
808 * This call is kept first to be in symmetry with
809 * acpi_lpss_runtime_suspend() one.
810 */
811 if (lpss_quirks & LPSS_QUIRK_ALWAYS_POWER_ON && iosf_mbi_available())
812 lpss_iosf_exit_d3_state();
813
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200814 ret = acpi_dev_runtime_resume(dev);
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300815 if (ret)
816 return ret;
817
Andy Shevchenko02b98542015-12-04 23:49:21 +0200818 acpi_lpss_d3_to_d0_delay(pdata);
819
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200820 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
821 acpi_lpss_restore_ctx(dev, pdata);
822
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300823 return pm_generic_runtime_resume(dev);
824}
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300825#endif /* CONFIG_PM */
826
827static struct dev_pm_domain acpi_lpss_pm_domain = {
Andy Shevchenkoc3a49cf2015-12-04 23:49:20 +0200828#ifdef CONFIG_PM
829 .activate = acpi_lpss_activate,
830 .dismiss = acpi_lpss_dismiss,
831#endif
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300832 .ops = {
Rafael J. Wysocki5de21bb92014-11-27 22:38:23 +0100833#ifdef CONFIG_PM
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300834#ifdef CONFIG_PM_SLEEP
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300835 .prepare = acpi_subsys_prepare,
Rafael J. Wysocki58a1fbb2015-10-07 00:50:24 +0200836 .complete = pm_complete_with_resume_check,
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300837 .suspend = acpi_subsys_suspend,
Fu Zhonghuif4168b62014-09-09 16:30:06 +0200838 .suspend_late = acpi_lpss_suspend_late,
839 .resume_early = acpi_lpss_resume_early,
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300840 .freeze = acpi_subsys_freeze,
841 .poweroff = acpi_subsys_suspend,
Fu Zhonghuif4168b62014-09-09 16:30:06 +0200842 .poweroff_late = acpi_lpss_suspend_late,
843 .restore_early = acpi_lpss_resume_early,
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300844#endif
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300845 .runtime_suspend = acpi_lpss_runtime_suspend,
846 .runtime_resume = acpi_lpss_runtime_resume,
847#endif
848 },
849};
850
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100851static int acpi_lpss_platform_notify(struct notifier_block *nb,
852 unsigned long action, void *data)
853{
854 struct platform_device *pdev = to_platform_device(data);
855 struct lpss_private_data *pdata;
856 struct acpi_device *adev;
857 const struct acpi_device_id *id;
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100858
859 id = acpi_match_device(acpi_lpss_device_ids, &pdev->dev);
860 if (!id || !id->driver_data)
861 return 0;
862
863 if (acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev))
864 return 0;
865
866 pdata = acpi_driver_data(adev);
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200867 if (!pdata)
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100868 return 0;
869
Andy Shevchenkocb39dcd2014-11-05 18:34:45 +0200870 if (pdata->mmio_base &&
871 pdata->mmio_size < pdata->dev_desc->prv_offset + LPSS_LTR_SIZE) {
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100872 dev_err(&pdev->dev, "MMIO size insufficient to access LTR\n");
873 return 0;
874 }
875
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300876 switch (action) {
Andy Shevchenkode16d552015-12-04 23:49:19 +0200877 case BUS_NOTIFY_BIND_DRIVER:
Andy Shevchenko01ac1702014-11-05 18:34:46 +0200878 pdev->dev.pm_domain = &acpi_lpss_pm_domain;
Andy Shevchenkob5f88dd2015-12-04 23:49:18 +0200879 break;
Andy Shevchenkode16d552015-12-04 23:49:19 +0200880 case BUS_NOTIFY_DRIVER_NOT_BOUND:
Andy Shevchenkob5f88dd2015-12-04 23:49:18 +0200881 case BUS_NOTIFY_UNBOUND_DRIVER:
882 pdev->dev.pm_domain = NULL;
883 break;
884 case BUS_NOTIFY_ADD_DEVICE:
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300885 if (pdata->dev_desc->flags & LPSS_LTR)
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300886 return sysfs_create_group(&pdev->dev.kobj,
887 &lpss_attr_group);
Andy Shevchenko01ac1702014-11-05 18:34:46 +0200888 break;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300889 case BUS_NOTIFY_DEL_DEVICE:
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300890 if (pdata->dev_desc->flags & LPSS_LTR)
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300891 sysfs_remove_group(&pdev->dev.kobj, &lpss_attr_group);
Andy Shevchenko01ac1702014-11-05 18:34:46 +0200892 break;
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300893 default:
894 break;
895 }
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100896
Heikki Krogerusc78b0832014-05-23 16:15:09 +0300897 return 0;
Rafael J. Wysocki2e0f8822013-03-06 23:46:28 +0100898}
899
900static struct notifier_block acpi_lpss_nb = {
901 .notifier_call = acpi_lpss_platform_notify,
902};
903
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +0100904static void acpi_lpss_bind(struct device *dev)
905{
906 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
907
Heikki Krogerusff8c1af2014-09-02 10:55:07 +0300908 if (!pdata || !pdata->mmio_base || !(pdata->dev_desc->flags & LPSS_LTR))
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +0100909 return;
910
911 if (pdata->mmio_size >= pdata->dev_desc->prv_offset + LPSS_LTR_SIZE)
912 dev->power.set_latency_tolerance = acpi_lpss_set_ltr;
913 else
914 dev_err(dev, "MMIO size insufficient to access LTR\n");
915}
916
917static void acpi_lpss_unbind(struct device *dev)
918{
919 dev->power.set_latency_tolerance = NULL;
920}
921
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100922static struct acpi_scan_handler lpss_handler = {
923 .ids = acpi_lpss_device_ids,
924 .attach = acpi_lpss_create_device,
Rafael J. Wysocki1a8f8352014-02-11 00:35:53 +0100925 .bind = acpi_lpss_bind,
926 .unbind = acpi_lpss_unbind,
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100927};
928
929void __init acpi_lpss_init(void)
930{
Andy Shevchenkoeebb3e82015-12-12 02:45:06 +0100931 const struct x86_cpu_id *id;
932 int ret;
933
934 ret = lpt_clk_init();
935 if (ret)
936 return;
937
938 id = x86_match_cpu(lpss_cpu_ids);
939 if (id)
940 lpss_quirks |= LPSS_QUIRK_ALWAYS_POWER_ON;
941
942 bus_register_notifier(&platform_bus_type, &acpi_lpss_nb);
943 acpi_scan_add_handler(&lpss_handler);
Rafael J. Wysockif58b0822013-03-06 23:46:20 +0100944}
Rafael J. Wysockid6ddaaa2014-05-30 14:34:05 +0200945
946#else
947
948static struct acpi_scan_handler lpss_handler = {
949 .ids = acpi_lpss_device_ids,
950};
951
952void __init acpi_lpss_init(void)
953{
954 acpi_scan_add_handler(&lpss_handler);
955}
956
957#endif /* CONFIG_X86_INTEL_LPSS */