Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ACPI support for Intel Lynxpoint LPSS. |
| 3 | * |
Andy Shevchenko | 6c17ee4 | 2014-11-05 18:34:47 +0200 | [diff] [blame] | 4 | * Copyright (C) 2013, 2014, 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> |
| 14 | #include <linux/clk.h> |
| 15 | #include <linux/clkdev.h> |
| 16 | #include <linux/clk-provider.h> |
| 17 | #include <linux/err.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/platform_data/clk-lpss.h> |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 21 | #include <linux/pm_runtime.h> |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 22 | #include <linux/delay.h> |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 23 | |
| 24 | #include "internal.h" |
| 25 | |
| 26 | ACPI_MODULE_NAME("acpi_lpss"); |
| 27 | |
Rafael J. Wysocki | d6ddaaa | 2014-05-30 14:34:05 +0200 | [diff] [blame] | 28 | #ifdef CONFIG_X86_INTEL_LPSS |
| 29 | |
| 30 | #define LPSS_ADDR(desc) ((unsigned long)&desc) |
| 31 | |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 32 | #define LPSS_CLK_SIZE 0x04 |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 33 | #define LPSS_LTR_SIZE 0x18 |
| 34 | |
| 35 | /* Offsets relative to LPSS_PRIVATE_OFFSET */ |
Heikki Krogerus | ed3a872 | 2014-05-19 14:42:07 +0300 | [diff] [blame] | 36 | #define LPSS_CLK_DIVIDER_DEF_MASK (BIT(1) | BIT(16)) |
Mika Westerberg | 765bdd4 | 2014-06-17 14:33:39 +0300 | [diff] [blame] | 37 | #define LPSS_RESETS 0x04 |
| 38 | #define LPSS_RESETS_RESET_FUNC BIT(0) |
| 39 | #define LPSS_RESETS_RESET_APB BIT(1) |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 40 | #define LPSS_GENERAL 0x08 |
| 41 | #define LPSS_GENERAL_LTR_MODE_SW BIT(2) |
Heikki Krogerus | 088f1fd | 2013-10-09 09:49:20 +0300 | [diff] [blame] | 42 | #define LPSS_GENERAL_UART_RTS_OVRD BIT(3) |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 43 | #define LPSS_SW_LTR 0x10 |
| 44 | #define LPSS_AUTO_LTR 0x14 |
Rafael J. Wysocki | 1a8f835 | 2014-02-11 00:35:53 +0100 | [diff] [blame] | 45 | #define LPSS_LTR_SNOOP_REQ BIT(15) |
| 46 | #define LPSS_LTR_SNOOP_MASK 0x0000FFFF |
| 47 | #define LPSS_LTR_SNOOP_LAT_1US 0x800 |
| 48 | #define LPSS_LTR_SNOOP_LAT_32US 0xC00 |
| 49 | #define LPSS_LTR_SNOOP_LAT_SHIFT 5 |
| 50 | #define LPSS_LTR_SNOOP_LAT_CUTOFF 3000 |
| 51 | #define LPSS_LTR_MAX_VAL 0x3FF |
Heikki Krogerus | 06d8641 | 2013-06-17 13:25:46 +0300 | [diff] [blame] | 52 | #define LPSS_TX_INT 0x20 |
| 53 | #define LPSS_TX_INT_MASK BIT(1) |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 54 | |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 55 | #define LPSS_PRV_REG_COUNT 9 |
| 56 | |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 57 | /* LPSS Flags */ |
| 58 | #define LPSS_CLK BIT(0) |
| 59 | #define LPSS_CLK_GATE BIT(1) |
| 60 | #define LPSS_CLK_DIVIDER BIT(2) |
| 61 | #define LPSS_LTR BIT(3) |
| 62 | #define LPSS_SAVE_CTX BIT(4) |
Andy Shevchenko | 6c17ee4 | 2014-11-05 18:34:47 +0200 | [diff] [blame] | 63 | #define LPSS_DEV_PROXY BIT(5) |
| 64 | #define LPSS_PROXY_REQ BIT(6) |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 65 | |
Heikki Krogerus | 06d8641 | 2013-06-17 13:25:46 +0300 | [diff] [blame] | 66 | struct lpss_private_data; |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 67 | |
| 68 | struct lpss_device_desc { |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 69 | unsigned int flags; |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 70 | unsigned int prv_offset; |
Mika Westerberg | 958c4eb | 2013-06-18 16:51:35 +0300 | [diff] [blame] | 71 | size_t prv_size_override; |
Heikki Krogerus | 06d8641 | 2013-06-17 13:25:46 +0300 | [diff] [blame] | 72 | void (*setup)(struct lpss_private_data *pdata); |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 73 | }; |
| 74 | |
Andy Shevchenko | 6c17ee4 | 2014-11-05 18:34:47 +0200 | [diff] [blame] | 75 | static struct device *proxy_device; |
| 76 | |
Rafael J. Wysocki | b59cc20 | 2013-05-08 11:55:49 +0300 | [diff] [blame] | 77 | static struct lpss_device_desc lpss_dma_desc = { |
Andy Shevchenko | 6c17ee4 | 2014-11-05 18:34:47 +0200 | [diff] [blame] | 78 | .flags = LPSS_CLK | LPSS_PROXY_REQ, |
Rafael J. Wysocki | b59cc20 | 2013-05-08 11:55:49 +0300 | [diff] [blame] | 79 | }; |
| 80 | |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 81 | struct lpss_private_data { |
| 82 | void __iomem *mmio_base; |
| 83 | resource_size_t mmio_size; |
Heikki Krogerus | 03f09f7 | 2014-09-02 10:55:09 +0300 | [diff] [blame] | 84 | unsigned int fixed_clk_rate; |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 85 | struct clk *clk; |
| 86 | const struct lpss_device_desc *dev_desc; |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 87 | u32 prv_reg_ctx[LPSS_PRV_REG_COUNT]; |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
Heikki Krogerus | 1f47a77 | 2014-09-11 15:19:33 +0300 | [diff] [blame] | 90 | /* UART Component Parameter Register */ |
| 91 | #define LPSS_UART_CPR 0xF4 |
| 92 | #define LPSS_UART_CPR_AFCE BIT(4) |
| 93 | |
Heikki Krogerus | 06d8641 | 2013-06-17 13:25:46 +0300 | [diff] [blame] | 94 | static void lpss_uart_setup(struct lpss_private_data *pdata) |
| 95 | { |
Heikki Krogerus | 088f1fd | 2013-10-09 09:49:20 +0300 | [diff] [blame] | 96 | unsigned int offset; |
Heikki Krogerus | 1f47a77 | 2014-09-11 15:19:33 +0300 | [diff] [blame] | 97 | u32 val; |
Heikki Krogerus | 06d8641 | 2013-06-17 13:25:46 +0300 | [diff] [blame] | 98 | |
Heikki Krogerus | 088f1fd | 2013-10-09 09:49:20 +0300 | [diff] [blame] | 99 | offset = pdata->dev_desc->prv_offset + LPSS_TX_INT; |
Heikki Krogerus | 1f47a77 | 2014-09-11 15:19:33 +0300 | [diff] [blame] | 100 | val = readl(pdata->mmio_base + offset); |
| 101 | writel(val | LPSS_TX_INT_MASK, pdata->mmio_base + offset); |
Heikki Krogerus | 088f1fd | 2013-10-09 09:49:20 +0300 | [diff] [blame] | 102 | |
Heikki Krogerus | 1f47a77 | 2014-09-11 15:19:33 +0300 | [diff] [blame] | 103 | val = readl(pdata->mmio_base + LPSS_UART_CPR); |
| 104 | if (!(val & LPSS_UART_CPR_AFCE)) { |
| 105 | offset = pdata->dev_desc->prv_offset + LPSS_GENERAL; |
| 106 | val = readl(pdata->mmio_base + offset); |
| 107 | val |= LPSS_GENERAL_UART_RTS_OVRD; |
| 108 | writel(val, pdata->mmio_base + offset); |
| 109 | } |
Heikki Krogerus | 06d8641 | 2013-06-17 13:25:46 +0300 | [diff] [blame] | 110 | } |
| 111 | |
Heikki Krogerus | 03f09f7 | 2014-09-02 10:55:09 +0300 | [diff] [blame] | 112 | static void byt_i2c_setup(struct lpss_private_data *pdata) |
Mika Westerberg | 765bdd4 | 2014-06-17 14:33:39 +0300 | [diff] [blame] | 113 | { |
| 114 | unsigned int offset; |
| 115 | u32 val; |
| 116 | |
| 117 | offset = pdata->dev_desc->prv_offset + LPSS_RESETS; |
| 118 | val = readl(pdata->mmio_base + offset); |
| 119 | val |= LPSS_RESETS_RESET_APB | LPSS_RESETS_RESET_FUNC; |
| 120 | writel(val, pdata->mmio_base + offset); |
Heikki Krogerus | 03f09f7 | 2014-09-02 10:55:09 +0300 | [diff] [blame] | 121 | |
| 122 | if (readl(pdata->mmio_base + pdata->dev_desc->prv_offset)) |
| 123 | pdata->fixed_clk_rate = 133000000; |
Mika Westerberg | 765bdd4 | 2014-06-17 14:33:39 +0300 | [diff] [blame] | 124 | } |
| 125 | |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 126 | static struct lpss_device_desc lpt_dev_desc = { |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 127 | .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR, |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 128 | .prv_offset = 0x800, |
Heikki Krogerus | ed3a872 | 2014-05-19 14:42:07 +0300 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | static struct lpss_device_desc lpt_i2c_dev_desc = { |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 132 | .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_LTR, |
Heikki Krogerus | ed3a872 | 2014-05-19 14:42:07 +0300 | [diff] [blame] | 133 | .prv_offset = 0x800, |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 134 | }; |
| 135 | |
Heikki Krogerus | 06d8641 | 2013-06-17 13:25:46 +0300 | [diff] [blame] | 136 | static struct lpss_device_desc lpt_uart_dev_desc = { |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 137 | .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR, |
Heikki Krogerus | 06d8641 | 2013-06-17 13:25:46 +0300 | [diff] [blame] | 138 | .prv_offset = 0x800, |
Heikki Krogerus | 06d8641 | 2013-06-17 13:25:46 +0300 | [diff] [blame] | 139 | .setup = lpss_uart_setup, |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | static struct lpss_device_desc lpt_sdio_dev_desc = { |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 143 | .flags = LPSS_LTR, |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 144 | .prv_offset = 0x1000, |
Mika Westerberg | 958c4eb | 2013-06-18 16:51:35 +0300 | [diff] [blame] | 145 | .prv_size_override = 0x1018, |
Chew, Chiau Ee | e1c7481 | 2014-02-19 02:24:29 +0800 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | static struct lpss_device_desc byt_pwm_dev_desc = { |
Heikki Krogerus | 3f56bf3 | 2014-09-02 10:55:10 +0300 | [diff] [blame] | 149 | .flags = LPSS_SAVE_CTX, |
Chew, Chiau Ee | e1c7481 | 2014-02-19 02:24:29 +0800 | [diff] [blame] | 150 | }; |
| 151 | |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 152 | static struct lpss_device_desc byt_uart_dev_desc = { |
Andy Shevchenko | 6c17ee4 | 2014-11-05 18:34:47 +0200 | [diff] [blame] | 153 | .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX | |
| 154 | LPSS_DEV_PROXY, |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 155 | .prv_offset = 0x800, |
Heikki Krogerus | 06d8641 | 2013-06-17 13:25:46 +0300 | [diff] [blame] | 156 | .setup = lpss_uart_setup, |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 159 | static struct lpss_device_desc byt_spi_dev_desc = { |
Andy Shevchenko | 6c17ee4 | 2014-11-05 18:34:47 +0200 | [diff] [blame] | 160 | .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX | |
| 161 | LPSS_DEV_PROXY, |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 162 | .prv_offset = 0x400, |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | static struct lpss_device_desc byt_sdio_dev_desc = { |
Andy Shevchenko | 6c17ee4 | 2014-11-05 18:34:47 +0200 | [diff] [blame] | 166 | .flags = LPSS_CLK | LPSS_DEV_PROXY, |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | static struct lpss_device_desc byt_i2c_dev_desc = { |
Andy Shevchenko | 6c17ee4 | 2014-11-05 18:34:47 +0200 | [diff] [blame] | 170 | .flags = LPSS_CLK | LPSS_SAVE_CTX | LPSS_DEV_PROXY, |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 171 | .prv_offset = 0x800, |
Heikki Krogerus | 03f09f7 | 2014-09-02 10:55:09 +0300 | [diff] [blame] | 172 | .setup = byt_i2c_setup, |
Alan Cox | 1bfbd8e | 2014-08-19 15:55:22 +0300 | [diff] [blame] | 173 | }; |
| 174 | |
Rafael J. Wysocki | d6ddaaa | 2014-05-30 14:34:05 +0200 | [diff] [blame] | 175 | #else |
| 176 | |
| 177 | #define LPSS_ADDR(desc) (0UL) |
| 178 | |
| 179 | #endif /* CONFIG_X86_INTEL_LPSS */ |
| 180 | |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 181 | static const struct acpi_device_id acpi_lpss_device_ids[] = { |
Rafael J. Wysocki | b59cc20 | 2013-05-08 11:55:49 +0300 | [diff] [blame] | 182 | /* Generic LPSS devices */ |
Rafael J. Wysocki | d6ddaaa | 2014-05-30 14:34:05 +0200 | [diff] [blame] | 183 | { "INTL9C60", LPSS_ADDR(lpss_dma_desc) }, |
Rafael J. Wysocki | b59cc20 | 2013-05-08 11:55:49 +0300 | [diff] [blame] | 184 | |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 185 | /* Lynxpoint LPSS devices */ |
Rafael J. Wysocki | d6ddaaa | 2014-05-30 14:34:05 +0200 | [diff] [blame] | 186 | { "INT33C0", LPSS_ADDR(lpt_dev_desc) }, |
| 187 | { "INT33C1", LPSS_ADDR(lpt_dev_desc) }, |
| 188 | { "INT33C2", LPSS_ADDR(lpt_i2c_dev_desc) }, |
| 189 | { "INT33C3", LPSS_ADDR(lpt_i2c_dev_desc) }, |
| 190 | { "INT33C4", LPSS_ADDR(lpt_uart_dev_desc) }, |
| 191 | { "INT33C5", LPSS_ADDR(lpt_uart_dev_desc) }, |
| 192 | { "INT33C6", LPSS_ADDR(lpt_sdio_dev_desc) }, |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 193 | { "INT33C7", }, |
| 194 | |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 195 | /* BayTrail LPSS devices */ |
Rafael J. Wysocki | d6ddaaa | 2014-05-30 14:34:05 +0200 | [diff] [blame] | 196 | { "80860F09", LPSS_ADDR(byt_pwm_dev_desc) }, |
| 197 | { "80860F0A", LPSS_ADDR(byt_uart_dev_desc) }, |
| 198 | { "80860F0E", LPSS_ADDR(byt_spi_dev_desc) }, |
| 199 | { "80860F14", LPSS_ADDR(byt_sdio_dev_desc) }, |
| 200 | { "80860F41", LPSS_ADDR(byt_i2c_dev_desc) }, |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 201 | { "INT33B2", }, |
Jin Yao | 20482d3 | 2014-05-15 18:28:46 +0300 | [diff] [blame] | 202 | { "INT33FC", }, |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 203 | |
Alan Cox | 1bfbd8e | 2014-08-19 15:55:22 +0300 | [diff] [blame] | 204 | /* Braswell LPSS devices */ |
Heikki Krogerus | 3f56bf3 | 2014-09-02 10:55:10 +0300 | [diff] [blame] | 205 | { "80862288", LPSS_ADDR(byt_pwm_dev_desc) }, |
Alan Cox | 1bfbd8e | 2014-08-19 15:55:22 +0300 | [diff] [blame] | 206 | { "8086228A", LPSS_ADDR(byt_uart_dev_desc) }, |
| 207 | { "8086228E", LPSS_ADDR(byt_spi_dev_desc) }, |
| 208 | { "808622C1", LPSS_ADDR(byt_i2c_dev_desc) }, |
| 209 | |
Rafael J. Wysocki | d6ddaaa | 2014-05-30 14:34:05 +0200 | [diff] [blame] | 210 | { "INT3430", LPSS_ADDR(lpt_dev_desc) }, |
| 211 | { "INT3431", LPSS_ADDR(lpt_dev_desc) }, |
| 212 | { "INT3432", LPSS_ADDR(lpt_i2c_dev_desc) }, |
| 213 | { "INT3433", LPSS_ADDR(lpt_i2c_dev_desc) }, |
| 214 | { "INT3434", LPSS_ADDR(lpt_uart_dev_desc) }, |
| 215 | { "INT3435", LPSS_ADDR(lpt_uart_dev_desc) }, |
| 216 | { "INT3436", LPSS_ADDR(lpt_sdio_dev_desc) }, |
Mika Westerberg | a4d9753 | 2013-11-12 11:48:19 +0200 | [diff] [blame] | 217 | { "INT3437", }, |
| 218 | |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 219 | /* Wildcat Point LPSS devices */ |
| 220 | { "INT3438", LPSS_ADDR(lpt_dev_desc) }, |
Jie Yang | 43218a1 | 2014-08-01 09:06:35 +0800 | [diff] [blame] | 221 | |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 222 | { } |
| 223 | }; |
| 224 | |
Rafael J. Wysocki | d6ddaaa | 2014-05-30 14:34:05 +0200 | [diff] [blame] | 225 | #ifdef CONFIG_X86_INTEL_LPSS |
| 226 | |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 227 | static int is_memory(struct acpi_resource *res, void *not_used) |
| 228 | { |
| 229 | struct resource r; |
| 230 | return !acpi_dev_resource_memory(res, &r); |
| 231 | } |
| 232 | |
| 233 | /* LPSS main clock device. */ |
| 234 | static struct platform_device *lpss_clk_dev; |
| 235 | |
| 236 | static inline void lpt_register_clock_device(void) |
| 237 | { |
| 238 | lpss_clk_dev = platform_device_register_simple("clk-lpt", -1, NULL, 0); |
| 239 | } |
| 240 | |
| 241 | static int register_device_clock(struct acpi_device *adev, |
| 242 | struct lpss_private_data *pdata) |
| 243 | { |
| 244 | const struct lpss_device_desc *dev_desc = pdata->dev_desc; |
Heikki Krogerus | ed3a872 | 2014-05-19 14:42:07 +0300 | [diff] [blame] | 245 | const char *devname = dev_name(&adev->dev); |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 246 | struct clk *clk = ERR_PTR(-ENODEV); |
Rafael J. Wysocki | b59cc20 | 2013-05-08 11:55:49 +0300 | [diff] [blame] | 247 | struct lpss_clk_data *clk_data; |
Heikki Krogerus | ed3a872 | 2014-05-19 14:42:07 +0300 | [diff] [blame] | 248 | const char *parent, *clk_name; |
| 249 | void __iomem *prv_base; |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 250 | |
| 251 | if (!lpss_clk_dev) |
| 252 | lpt_register_clock_device(); |
| 253 | |
Rafael J. Wysocki | b59cc20 | 2013-05-08 11:55:49 +0300 | [diff] [blame] | 254 | clk_data = platform_get_drvdata(lpss_clk_dev); |
| 255 | if (!clk_data) |
| 256 | return -ENODEV; |
Heikki Krogerus | b0d00f8 | 2014-09-02 10:55:08 +0300 | [diff] [blame] | 257 | clk = clk_data->clk; |
Rafael J. Wysocki | b59cc20 | 2013-05-08 11:55:49 +0300 | [diff] [blame] | 258 | |
| 259 | if (!pdata->mmio_base |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 260 | || pdata->mmio_size < dev_desc->prv_offset + LPSS_CLK_SIZE) |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 261 | return -ENODATA; |
| 262 | |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 263 | parent = clk_data->name; |
Heikki Krogerus | ed3a872 | 2014-05-19 14:42:07 +0300 | [diff] [blame] | 264 | prv_base = pdata->mmio_base + dev_desc->prv_offset; |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 265 | |
Heikki Krogerus | 03f09f7 | 2014-09-02 10:55:09 +0300 | [diff] [blame] | 266 | if (pdata->fixed_clk_rate) { |
| 267 | clk = clk_register_fixed_rate(NULL, devname, parent, 0, |
| 268 | pdata->fixed_clk_rate); |
| 269 | goto out; |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 272 | if (dev_desc->flags & LPSS_CLK_GATE) { |
Heikki Krogerus | ed3a872 | 2014-05-19 14:42:07 +0300 | [diff] [blame] | 273 | clk = clk_register_gate(NULL, devname, parent, 0, |
| 274 | prv_base, 0, 0, NULL); |
| 275 | parent = devname; |
| 276 | } |
| 277 | |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 278 | if (dev_desc->flags & LPSS_CLK_DIVIDER) { |
Heikki Krogerus | ed3a872 | 2014-05-19 14:42:07 +0300 | [diff] [blame] | 279 | /* Prevent division by zero */ |
| 280 | if (!readl(prv_base)) |
| 281 | writel(LPSS_CLK_DIVIDER_DEF_MASK, prv_base); |
| 282 | |
| 283 | clk_name = kasprintf(GFP_KERNEL, "%s-div", devname); |
| 284 | if (!clk_name) |
| 285 | return -ENOMEM; |
| 286 | clk = clk_register_fractional_divider(NULL, clk_name, parent, |
| 287 | 0, prv_base, |
| 288 | 1, 15, 16, 15, 0, NULL); |
| 289 | parent = clk_name; |
| 290 | |
| 291 | clk_name = kasprintf(GFP_KERNEL, "%s-update", devname); |
| 292 | if (!clk_name) { |
| 293 | kfree(parent); |
| 294 | return -ENOMEM; |
| 295 | } |
| 296 | clk = clk_register_gate(NULL, clk_name, parent, |
| 297 | CLK_SET_RATE_PARENT | CLK_SET_RATE_GATE, |
| 298 | prv_base, 31, 0, NULL); |
| 299 | kfree(parent); |
| 300 | kfree(clk_name); |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 301 | } |
Heikki Krogerus | 03f09f7 | 2014-09-02 10:55:09 +0300 | [diff] [blame] | 302 | out: |
Mika Westerberg | f627217 | 2013-05-13 12:42:44 +0000 | [diff] [blame] | 303 | if (IS_ERR(clk)) |
| 304 | return PTR_ERR(clk); |
| 305 | |
Heikki Krogerus | ed3a872 | 2014-05-19 14:42:07 +0300 | [diff] [blame] | 306 | pdata->clk = clk; |
| 307 | clk_register_clkdev(clk, NULL, devname); |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static int acpi_lpss_create_device(struct acpi_device *adev, |
| 312 | const struct acpi_device_id *id) |
| 313 | { |
| 314 | struct lpss_device_desc *dev_desc; |
| 315 | struct lpss_private_data *pdata; |
| 316 | struct resource_list_entry *rentry; |
| 317 | struct list_head resource_list; |
Rafael J. Wysocki | 8ce62f8 | 2014-05-25 14:38:52 +0200 | [diff] [blame] | 318 | struct platform_device *pdev; |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 319 | int ret; |
| 320 | |
| 321 | dev_desc = (struct lpss_device_desc *)id->driver_data; |
Rafael J. Wysocki | 8ce62f8 | 2014-05-25 14:38:52 +0200 | [diff] [blame] | 322 | if (!dev_desc) { |
| 323 | pdev = acpi_create_platform_device(adev); |
| 324 | return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1; |
| 325 | } |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 326 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); |
| 327 | if (!pdata) |
| 328 | return -ENOMEM; |
| 329 | |
| 330 | INIT_LIST_HEAD(&resource_list); |
| 331 | ret = acpi_dev_get_resources(adev, &resource_list, is_memory, NULL); |
| 332 | if (ret < 0) |
| 333 | goto err_out; |
| 334 | |
| 335 | list_for_each_entry(rentry, &resource_list, node) |
| 336 | if (resource_type(&rentry->res) == IORESOURCE_MEM) { |
Mika Westerberg | 958c4eb | 2013-06-18 16:51:35 +0300 | [diff] [blame] | 337 | if (dev_desc->prv_size_override) |
| 338 | pdata->mmio_size = dev_desc->prv_size_override; |
| 339 | else |
| 340 | pdata->mmio_size = resource_size(&rentry->res); |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 341 | pdata->mmio_base = ioremap(rentry->res.start, |
| 342 | pdata->mmio_size); |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 343 | break; |
| 344 | } |
| 345 | |
| 346 | acpi_dev_free_resource_list(&resource_list); |
| 347 | |
Mika Westerberg | af65cfe | 2013-09-02 13:30:25 +0300 | [diff] [blame] | 348 | pdata->dev_desc = dev_desc; |
| 349 | |
Heikki Krogerus | 03f09f7 | 2014-09-02 10:55:09 +0300 | [diff] [blame] | 350 | if (dev_desc->setup) |
| 351 | dev_desc->setup(pdata); |
| 352 | |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 353 | if (dev_desc->flags & LPSS_CLK) { |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 354 | ret = register_device_clock(adev, pdata); |
| 355 | if (ret) { |
Rafael J. Wysocki | b9e95fc | 2013-06-19 00:45:34 +0200 | [diff] [blame] | 356 | /* Skip the device, but continue the namespace scan. */ |
| 357 | ret = 0; |
| 358 | goto err_out; |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
Rafael J. Wysocki | b9e95fc | 2013-06-19 00:45:34 +0200 | [diff] [blame] | 362 | /* |
| 363 | * This works around a known issue in ACPI tables where LPSS devices |
| 364 | * have _PS0 and _PS3 without _PSC (and no power resources), so |
| 365 | * acpi_bus_init_power() will assume that the BIOS has put them into D0. |
| 366 | */ |
| 367 | ret = acpi_device_fix_up_power(adev); |
| 368 | if (ret) { |
| 369 | /* Skip the device, but continue the namespace scan. */ |
| 370 | ret = 0; |
| 371 | goto err_out; |
| 372 | } |
| 373 | |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 374 | adev->driver_data = pdata; |
Rafael J. Wysocki | 8ce62f8 | 2014-05-25 14:38:52 +0200 | [diff] [blame] | 375 | pdev = acpi_create_platform_device(adev); |
| 376 | if (!IS_ERR_OR_NULL(pdev)) { |
Andy Shevchenko | 6c17ee4 | 2014-11-05 18:34:47 +0200 | [diff] [blame] | 377 | if (!proxy_device && dev_desc->flags & LPSS_DEV_PROXY) |
| 378 | proxy_device = &pdev->dev; |
Rafael J. Wysocki | 8ce62f8 | 2014-05-25 14:38:52 +0200 | [diff] [blame] | 379 | return 1; |
| 380 | } |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 381 | |
Rafael J. Wysocki | 8ce62f8 | 2014-05-25 14:38:52 +0200 | [diff] [blame] | 382 | ret = PTR_ERR(pdev); |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 383 | adev->driver_data = NULL; |
| 384 | |
| 385 | err_out: |
| 386 | kfree(pdata); |
| 387 | return ret; |
| 388 | } |
| 389 | |
Rafael J. Wysocki | 1a8f835 | 2014-02-11 00:35:53 +0100 | [diff] [blame] | 390 | static u32 __lpss_reg_read(struct lpss_private_data *pdata, unsigned int reg) |
| 391 | { |
| 392 | return readl(pdata->mmio_base + pdata->dev_desc->prv_offset + reg); |
| 393 | } |
| 394 | |
| 395 | static void __lpss_reg_write(u32 val, struct lpss_private_data *pdata, |
| 396 | unsigned int reg) |
| 397 | { |
| 398 | writel(val, pdata->mmio_base + pdata->dev_desc->prv_offset + reg); |
| 399 | } |
| 400 | |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 401 | static int lpss_reg_read(struct device *dev, unsigned int reg, u32 *val) |
| 402 | { |
| 403 | struct acpi_device *adev; |
| 404 | struct lpss_private_data *pdata; |
| 405 | unsigned long flags; |
| 406 | int ret; |
| 407 | |
| 408 | ret = acpi_bus_get_device(ACPI_HANDLE(dev), &adev); |
| 409 | if (WARN_ON(ret)) |
| 410 | return ret; |
| 411 | |
| 412 | spin_lock_irqsave(&dev->power.lock, flags); |
| 413 | if (pm_runtime_suspended(dev)) { |
| 414 | ret = -EAGAIN; |
| 415 | goto out; |
| 416 | } |
| 417 | pdata = acpi_driver_data(adev); |
| 418 | if (WARN_ON(!pdata || !pdata->mmio_base)) { |
| 419 | ret = -ENODEV; |
| 420 | goto out; |
| 421 | } |
Rafael J. Wysocki | 1a8f835 | 2014-02-11 00:35:53 +0100 | [diff] [blame] | 422 | *val = __lpss_reg_read(pdata, reg); |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 423 | |
| 424 | out: |
| 425 | spin_unlock_irqrestore(&dev->power.lock, flags); |
| 426 | return ret; |
| 427 | } |
| 428 | |
| 429 | static ssize_t lpss_ltr_show(struct device *dev, struct device_attribute *attr, |
| 430 | char *buf) |
| 431 | { |
| 432 | u32 ltr_value = 0; |
| 433 | unsigned int reg; |
| 434 | int ret; |
| 435 | |
| 436 | reg = strcmp(attr->attr.name, "auto_ltr") ? LPSS_SW_LTR : LPSS_AUTO_LTR; |
| 437 | ret = lpss_reg_read(dev, reg, <r_value); |
| 438 | if (ret) |
| 439 | return ret; |
| 440 | |
| 441 | return snprintf(buf, PAGE_SIZE, "%08x\n", ltr_value); |
| 442 | } |
| 443 | |
| 444 | static ssize_t lpss_ltr_mode_show(struct device *dev, |
| 445 | struct device_attribute *attr, char *buf) |
| 446 | { |
| 447 | u32 ltr_mode = 0; |
| 448 | char *outstr; |
| 449 | int ret; |
| 450 | |
| 451 | ret = lpss_reg_read(dev, LPSS_GENERAL, <r_mode); |
| 452 | if (ret) |
| 453 | return ret; |
| 454 | |
| 455 | outstr = (ltr_mode & LPSS_GENERAL_LTR_MODE_SW) ? "sw" : "auto"; |
| 456 | return sprintf(buf, "%s\n", outstr); |
| 457 | } |
| 458 | |
| 459 | static DEVICE_ATTR(auto_ltr, S_IRUSR, lpss_ltr_show, NULL); |
| 460 | static DEVICE_ATTR(sw_ltr, S_IRUSR, lpss_ltr_show, NULL); |
| 461 | static DEVICE_ATTR(ltr_mode, S_IRUSR, lpss_ltr_mode_show, NULL); |
| 462 | |
| 463 | static struct attribute *lpss_attrs[] = { |
| 464 | &dev_attr_auto_ltr.attr, |
| 465 | &dev_attr_sw_ltr.attr, |
| 466 | &dev_attr_ltr_mode.attr, |
| 467 | NULL, |
| 468 | }; |
| 469 | |
| 470 | static struct attribute_group lpss_attr_group = { |
| 471 | .attrs = lpss_attrs, |
| 472 | .name = "lpss_ltr", |
| 473 | }; |
| 474 | |
Rafael J. Wysocki | 1a8f835 | 2014-02-11 00:35:53 +0100 | [diff] [blame] | 475 | static void acpi_lpss_set_ltr(struct device *dev, s32 val) |
| 476 | { |
| 477 | struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev)); |
| 478 | u32 ltr_mode, ltr_val; |
| 479 | |
| 480 | ltr_mode = __lpss_reg_read(pdata, LPSS_GENERAL); |
| 481 | if (val < 0) { |
| 482 | if (ltr_mode & LPSS_GENERAL_LTR_MODE_SW) { |
| 483 | ltr_mode &= ~LPSS_GENERAL_LTR_MODE_SW; |
| 484 | __lpss_reg_write(ltr_mode, pdata, LPSS_GENERAL); |
| 485 | } |
| 486 | return; |
| 487 | } |
| 488 | ltr_val = __lpss_reg_read(pdata, LPSS_SW_LTR) & ~LPSS_LTR_SNOOP_MASK; |
| 489 | if (val >= LPSS_LTR_SNOOP_LAT_CUTOFF) { |
| 490 | ltr_val |= LPSS_LTR_SNOOP_LAT_32US; |
| 491 | val = LPSS_LTR_MAX_VAL; |
| 492 | } else if (val > LPSS_LTR_MAX_VAL) { |
| 493 | ltr_val |= LPSS_LTR_SNOOP_LAT_32US | LPSS_LTR_SNOOP_REQ; |
| 494 | val >>= LPSS_LTR_SNOOP_LAT_SHIFT; |
| 495 | } else { |
| 496 | ltr_val |= LPSS_LTR_SNOOP_LAT_1US | LPSS_LTR_SNOOP_REQ; |
| 497 | } |
| 498 | ltr_val |= val; |
| 499 | __lpss_reg_write(ltr_val, pdata, LPSS_SW_LTR); |
| 500 | if (!(ltr_mode & LPSS_GENERAL_LTR_MODE_SW)) { |
| 501 | ltr_mode |= LPSS_GENERAL_LTR_MODE_SW; |
| 502 | __lpss_reg_write(ltr_mode, pdata, LPSS_GENERAL); |
| 503 | } |
| 504 | } |
| 505 | |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 506 | #ifdef CONFIG_PM |
| 507 | /** |
| 508 | * acpi_lpss_save_ctx() - Save the private registers of LPSS device |
| 509 | * @dev: LPSS device |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 510 | * @pdata: pointer to the private data of the LPSS device |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 511 | * |
| 512 | * Most LPSS devices have private registers which may loose their context when |
| 513 | * the device is powered down. acpi_lpss_save_ctx() saves those registers into |
| 514 | * prv_reg_ctx array. |
| 515 | */ |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 516 | static void acpi_lpss_save_ctx(struct device *dev, |
| 517 | struct lpss_private_data *pdata) |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 518 | { |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 519 | unsigned int i; |
| 520 | |
| 521 | for (i = 0; i < LPSS_PRV_REG_COUNT; i++) { |
| 522 | unsigned long offset = i * sizeof(u32); |
| 523 | |
| 524 | pdata->prv_reg_ctx[i] = __lpss_reg_read(pdata, offset); |
| 525 | dev_dbg(dev, "saving 0x%08x from LPSS reg at offset 0x%02lx\n", |
| 526 | pdata->prv_reg_ctx[i], offset); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * acpi_lpss_restore_ctx() - Restore the private registers of LPSS device |
| 532 | * @dev: LPSS device |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 533 | * @pdata: pointer to the private data of the LPSS device |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 534 | * |
| 535 | * Restores the registers that were previously stored with acpi_lpss_save_ctx(). |
| 536 | */ |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 537 | static void acpi_lpss_restore_ctx(struct device *dev, |
| 538 | struct lpss_private_data *pdata) |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 539 | { |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 540 | unsigned int i; |
| 541 | |
| 542 | /* |
| 543 | * The following delay is needed or the subsequent write operations may |
| 544 | * fail. The LPSS devices are actually PCI devices and the PCI spec |
| 545 | * expects 10ms delay before the device can be accessed after D3 to D0 |
| 546 | * transition. |
| 547 | */ |
| 548 | msleep(10); |
| 549 | |
| 550 | for (i = 0; i < LPSS_PRV_REG_COUNT; i++) { |
| 551 | unsigned long offset = i * sizeof(u32); |
| 552 | |
| 553 | __lpss_reg_write(pdata->prv_reg_ctx[i], pdata, offset); |
| 554 | dev_dbg(dev, "restoring 0x%08x to LPSS reg at offset 0x%02lx\n", |
| 555 | pdata->prv_reg_ctx[i], offset); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | #ifdef CONFIG_PM_SLEEP |
| 560 | static int acpi_lpss_suspend_late(struct device *dev) |
| 561 | { |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 562 | struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev)); |
| 563 | int ret; |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 564 | |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 565 | ret = pm_generic_suspend_late(dev); |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 566 | if (ret) |
| 567 | return ret; |
| 568 | |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 569 | if (pdata->dev_desc->flags & LPSS_SAVE_CTX) |
| 570 | acpi_lpss_save_ctx(dev, pdata); |
| 571 | |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 572 | return acpi_dev_suspend_late(dev); |
| 573 | } |
| 574 | |
Fu Zhonghui | f4168b6 | 2014-09-09 16:30:06 +0200 | [diff] [blame] | 575 | static int acpi_lpss_resume_early(struct device *dev) |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 576 | { |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 577 | struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev)); |
| 578 | int ret; |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 579 | |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 580 | ret = acpi_dev_resume_early(dev); |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 581 | if (ret) |
| 582 | return ret; |
| 583 | |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 584 | if (pdata->dev_desc->flags & LPSS_SAVE_CTX) |
| 585 | acpi_lpss_restore_ctx(dev, pdata); |
| 586 | |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 587 | return pm_generic_resume_early(dev); |
| 588 | } |
| 589 | #endif /* CONFIG_PM_SLEEP */ |
| 590 | |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 591 | static int acpi_lpss_runtime_suspend(struct device *dev) |
| 592 | { |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 593 | struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev)); |
| 594 | int ret; |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 595 | |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 596 | ret = pm_generic_runtime_suspend(dev); |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 597 | if (ret) |
| 598 | return ret; |
| 599 | |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 600 | if (pdata->dev_desc->flags & LPSS_SAVE_CTX) |
| 601 | acpi_lpss_save_ctx(dev, pdata); |
| 602 | |
Andy Shevchenko | 6c17ee4 | 2014-11-05 18:34:47 +0200 | [diff] [blame] | 603 | ret = acpi_dev_runtime_suspend(dev); |
| 604 | if (ret) |
| 605 | return ret; |
| 606 | |
| 607 | if (pdata->dev_desc->flags & LPSS_PROXY_REQ && proxy_device) |
| 608 | return pm_runtime_put_sync_suspend(proxy_device); |
| 609 | |
| 610 | return 0; |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | static int acpi_lpss_runtime_resume(struct device *dev) |
| 614 | { |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 615 | struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev)); |
| 616 | int ret; |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 617 | |
Andy Shevchenko | 6c17ee4 | 2014-11-05 18:34:47 +0200 | [diff] [blame] | 618 | if (pdata->dev_desc->flags & LPSS_PROXY_REQ && proxy_device) { |
| 619 | ret = pm_runtime_get_sync(proxy_device); |
| 620 | if (ret) |
| 621 | return ret; |
| 622 | } |
| 623 | |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 624 | ret = acpi_dev_runtime_resume(dev); |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 625 | if (ret) |
| 626 | return ret; |
| 627 | |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 628 | if (pdata->dev_desc->flags & LPSS_SAVE_CTX) |
| 629 | acpi_lpss_restore_ctx(dev, pdata); |
| 630 | |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 631 | return pm_generic_runtime_resume(dev); |
| 632 | } |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 633 | #endif /* CONFIG_PM */ |
| 634 | |
| 635 | static struct dev_pm_domain acpi_lpss_pm_domain = { |
| 636 | .ops = { |
Rafael J. Wysocki | 5de21bb9 | 2014-11-27 22:38:23 +0100 | [diff] [blame] | 637 | #ifdef CONFIG_PM |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 638 | #ifdef CONFIG_PM_SLEEP |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 639 | .prepare = acpi_subsys_prepare, |
| 640 | .complete = acpi_subsys_complete, |
| 641 | .suspend = acpi_subsys_suspend, |
Fu Zhonghui | f4168b6 | 2014-09-09 16:30:06 +0200 | [diff] [blame] | 642 | .suspend_late = acpi_lpss_suspend_late, |
| 643 | .resume_early = acpi_lpss_resume_early, |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 644 | .freeze = acpi_subsys_freeze, |
| 645 | .poweroff = acpi_subsys_suspend, |
Fu Zhonghui | f4168b6 | 2014-09-09 16:30:06 +0200 | [diff] [blame] | 646 | .poweroff_late = acpi_lpss_suspend_late, |
| 647 | .restore_early = acpi_lpss_resume_early, |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 648 | #endif |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 649 | .runtime_suspend = acpi_lpss_runtime_suspend, |
| 650 | .runtime_resume = acpi_lpss_runtime_resume, |
| 651 | #endif |
| 652 | }, |
| 653 | }; |
| 654 | |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 655 | static int acpi_lpss_platform_notify(struct notifier_block *nb, |
| 656 | unsigned long action, void *data) |
| 657 | { |
| 658 | struct platform_device *pdev = to_platform_device(data); |
| 659 | struct lpss_private_data *pdata; |
| 660 | struct acpi_device *adev; |
| 661 | const struct acpi_device_id *id; |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 662 | |
| 663 | id = acpi_match_device(acpi_lpss_device_ids, &pdev->dev); |
| 664 | if (!id || !id->driver_data) |
| 665 | return 0; |
| 666 | |
| 667 | if (acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev)) |
| 668 | return 0; |
| 669 | |
| 670 | pdata = acpi_driver_data(adev); |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 671 | if (!pdata) |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 672 | return 0; |
| 673 | |
Andy Shevchenko | cb39dcd | 2014-11-05 18:34:45 +0200 | [diff] [blame] | 674 | if (pdata->mmio_base && |
| 675 | pdata->mmio_size < pdata->dev_desc->prv_offset + LPSS_LTR_SIZE) { |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 676 | dev_err(&pdev->dev, "MMIO size insufficient to access LTR\n"); |
| 677 | return 0; |
| 678 | } |
| 679 | |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 680 | switch (action) { |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 681 | case BUS_NOTIFY_ADD_DEVICE: |
Andy Shevchenko | 01ac170 | 2014-11-05 18:34:46 +0200 | [diff] [blame] | 682 | pdev->dev.pm_domain = &acpi_lpss_pm_domain; |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 683 | if (pdata->dev_desc->flags & LPSS_LTR) |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 684 | return sysfs_create_group(&pdev->dev.kobj, |
| 685 | &lpss_attr_group); |
Andy Shevchenko | 01ac170 | 2014-11-05 18:34:46 +0200 | [diff] [blame] | 686 | break; |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 687 | case BUS_NOTIFY_DEL_DEVICE: |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 688 | if (pdata->dev_desc->flags & LPSS_LTR) |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 689 | sysfs_remove_group(&pdev->dev.kobj, &lpss_attr_group); |
Andy Shevchenko | 01ac170 | 2014-11-05 18:34:46 +0200 | [diff] [blame] | 690 | pdev->dev.pm_domain = NULL; |
| 691 | break; |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 692 | default: |
| 693 | break; |
| 694 | } |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 695 | |
Heikki Krogerus | c78b083 | 2014-05-23 16:15:09 +0300 | [diff] [blame] | 696 | return 0; |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | static struct notifier_block acpi_lpss_nb = { |
| 700 | .notifier_call = acpi_lpss_platform_notify, |
| 701 | }; |
| 702 | |
Rafael J. Wysocki | 1a8f835 | 2014-02-11 00:35:53 +0100 | [diff] [blame] | 703 | static void acpi_lpss_bind(struct device *dev) |
| 704 | { |
| 705 | struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev)); |
| 706 | |
Heikki Krogerus | ff8c1af | 2014-09-02 10:55:07 +0300 | [diff] [blame] | 707 | if (!pdata || !pdata->mmio_base || !(pdata->dev_desc->flags & LPSS_LTR)) |
Rafael J. Wysocki | 1a8f835 | 2014-02-11 00:35:53 +0100 | [diff] [blame] | 708 | return; |
| 709 | |
| 710 | if (pdata->mmio_size >= pdata->dev_desc->prv_offset + LPSS_LTR_SIZE) |
| 711 | dev->power.set_latency_tolerance = acpi_lpss_set_ltr; |
| 712 | else |
| 713 | dev_err(dev, "MMIO size insufficient to access LTR\n"); |
| 714 | } |
| 715 | |
| 716 | static void acpi_lpss_unbind(struct device *dev) |
| 717 | { |
| 718 | dev->power.set_latency_tolerance = NULL; |
| 719 | } |
| 720 | |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 721 | static struct acpi_scan_handler lpss_handler = { |
| 722 | .ids = acpi_lpss_device_ids, |
| 723 | .attach = acpi_lpss_create_device, |
Rafael J. Wysocki | 1a8f835 | 2014-02-11 00:35:53 +0100 | [diff] [blame] | 724 | .bind = acpi_lpss_bind, |
| 725 | .unbind = acpi_lpss_unbind, |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 726 | }; |
| 727 | |
| 728 | void __init acpi_lpss_init(void) |
| 729 | { |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 730 | if (!lpt_clk_init()) { |
| 731 | bus_register_notifier(&platform_bus_type, &acpi_lpss_nb); |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 732 | acpi_scan_add_handler(&lpss_handler); |
Rafael J. Wysocki | 2e0f882 | 2013-03-06 23:46:28 +0100 | [diff] [blame] | 733 | } |
Rafael J. Wysocki | f58b082 | 2013-03-06 23:46:20 +0100 | [diff] [blame] | 734 | } |
Rafael J. Wysocki | d6ddaaa | 2014-05-30 14:34:05 +0200 | [diff] [blame] | 735 | |
| 736 | #else |
| 737 | |
| 738 | static struct acpi_scan_handler lpss_handler = { |
| 739 | .ids = acpi_lpss_device_ids, |
| 740 | }; |
| 741 | |
| 742 | void __init acpi_lpss_init(void) |
| 743 | { |
| 744 | acpi_scan_add_handler(&lpss_handler); |
| 745 | } |
| 746 | |
| 747 | #endif /* CONFIG_X86_INTEL_LPSS */ |