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