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