diff options
author | Li, Aubrey <aubrey.li@linux.intel.com> | 2014-06-30 02:10:33 -0400 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2014-07-25 17:12:14 -0400 |
commit | f855911c1f481734191615a7438a396f52a915dc (patch) | |
tree | 764d50993827e33d3852773dd8511538d738cffb | |
parent | b00055cade45379fb6a51798b70ef520d7555c5f (diff) |
x86/pmc_atom: Expose PMC device state and platform sleep state
Add the following interfaces to exposes PMC device state and sleep
state residency via debugfs:
/sys/kernel/debugfs/pmc_atom/dev_state
/sys/kernel/debugfs/pmc_atom/sleep_state
Signed-off-by: Aubrey Li <aubrey.li@linux.intel.com>
Link: http://lkml.kernel.org/r/53B0FF59.8000600@linux.intel.com
Signed-off-by: Kasagar, Srinidhi <srinidhi.kasagar@intel.com>
Reviewed-by: Rudramuni, Vishwesh M <vishwesh.m.rudramuni@intel.com>
Reviewed-by: Joe Perches <joe@perches.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r-- | arch/x86/include/asm/pmc_atom.h | 55 | ||||
-rw-r--r-- | arch/x86/kernel/pmc_atom.c | 175 |
2 files changed, 230 insertions, 0 deletions
diff --git a/arch/x86/include/asm/pmc_atom.h b/arch/x86/include/asm/pmc_atom.h index 8e47e5d10e1d..fc7a17c05d35 100644 --- a/arch/x86/include/asm/pmc_atom.h +++ b/arch/x86/include/asm/pmc_atom.h | |||
@@ -25,6 +25,10 @@ | |||
25 | #define PMC_MMIO_REG_LEN 0x100 | 25 | #define PMC_MMIO_REG_LEN 0x100 |
26 | #define PMC_REG_BIT_WIDTH 32 | 26 | #define PMC_REG_BIT_WIDTH 32 |
27 | 27 | ||
28 | /* BIOS uses FUNC_DIS to disable specific function */ | ||
29 | #define PMC_FUNC_DIS 0x34 | ||
30 | #define PMC_FUNC_DIS_2 0x38 | ||
31 | |||
28 | /* S0ix wake event control */ | 32 | /* S0ix wake event control */ |
29 | #define PMC_S0IX_WAKE_EN 0x3C | 33 | #define PMC_S0IX_WAKE_EN 0x3C |
30 | 34 | ||
@@ -40,6 +44,57 @@ | |||
40 | BIT_ORED_DEDICATED_IRQ_GPSC | \ | 44 | BIT_ORED_DEDICATED_IRQ_GPSC | \ |
41 | BIT_SHARED_IRQ_GPSS) | 45 | BIT_SHARED_IRQ_GPSS) |
42 | 46 | ||
47 | /* The timers acumulate time spent in sleep state */ | ||
48 | #define PMC_S0IR_TMR 0x80 | ||
49 | #define PMC_S0I1_TMR 0x84 | ||
50 | #define PMC_S0I2_TMR 0x88 | ||
51 | #define PMC_S0I3_TMR 0x8C | ||
52 | #define PMC_S0_TMR 0x90 | ||
53 | /* Sleep state counter is in units of of 32us */ | ||
54 | #define PMC_TMR_SHIFT 5 | ||
55 | |||
56 | /* These registers reflect D3 status of functions */ | ||
57 | #define PMC_D3_STS_0 0xA0 | ||
58 | |||
59 | #define BIT_LPSS1_F0_DMA BIT(0) | ||
60 | #define BIT_LPSS1_F1_PWM1 BIT(1) | ||
61 | #define BIT_LPSS1_F2_PWM2 BIT(2) | ||
62 | #define BIT_LPSS1_F3_HSUART1 BIT(3) | ||
63 | #define BIT_LPSS1_F4_HSUART2 BIT(4) | ||
64 | #define BIT_LPSS1_F5_SPI BIT(5) | ||
65 | #define BIT_LPSS1_F6_XXX BIT(6) | ||
66 | #define BIT_LPSS1_F7_XXX BIT(7) | ||
67 | #define BIT_SCC_EMMC BIT(8) | ||
68 | #define BIT_SCC_SDIO BIT(9) | ||
69 | #define BIT_SCC_SDCARD BIT(10) | ||
70 | #define BIT_SCC_MIPI BIT(11) | ||
71 | #define BIT_HDA BIT(12) | ||
72 | #define BIT_LPE BIT(13) | ||
73 | #define BIT_OTG BIT(14) | ||
74 | #define BIT_USH BIT(15) | ||
75 | #define BIT_GBE BIT(16) | ||
76 | #define BIT_SATA BIT(17) | ||
77 | #define BIT_USB_EHCI BIT(18) | ||
78 | #define BIT_SEC BIT(19) | ||
79 | #define BIT_PCIE_PORT0 BIT(20) | ||
80 | #define BIT_PCIE_PORT1 BIT(21) | ||
81 | #define BIT_PCIE_PORT2 BIT(22) | ||
82 | #define BIT_PCIE_PORT3 BIT(23) | ||
83 | #define BIT_LPSS2_F0_DMA BIT(24) | ||
84 | #define BIT_LPSS2_F1_I2C1 BIT(25) | ||
85 | #define BIT_LPSS2_F2_I2C2 BIT(26) | ||
86 | #define BIT_LPSS2_F3_I2C3 BIT(27) | ||
87 | #define BIT_LPSS2_F4_I2C4 BIT(28) | ||
88 | #define BIT_LPSS2_F5_I2C5 BIT(29) | ||
89 | #define BIT_LPSS2_F6_I2C6 BIT(30) | ||
90 | #define BIT_LPSS2_F7_I2C7 BIT(31) | ||
91 | |||
92 | #define PMC_D3_STS_1 0xA4 | ||
93 | #define BIT_SMB BIT(0) | ||
94 | #define BIT_OTG_SS_PHY BIT(1) | ||
95 | #define BIT_USH_SS_PHY BIT(2) | ||
96 | #define BIT_DFX BIT(3) | ||
97 | |||
43 | /* PMC I/O Registers */ | 98 | /* PMC I/O Registers */ |
44 | #define ACPI_BASE_ADDR_OFFSET 0x40 | 99 | #define ACPI_BASE_ADDR_OFFSET 0x40 |
45 | #define ACPI_BASE_ADDR_MASK 0xFFFFFE00 | 100 | #define ACPI_BASE_ADDR_MASK 0xFFFFFE00 |
diff --git a/arch/x86/kernel/pmc_atom.c b/arch/x86/kernel/pmc_atom.c index d6cc0e9eee54..0d92ef6b5860 100644 --- a/arch/x86/kernel/pmc_atom.c +++ b/arch/x86/kernel/pmc_atom.c | |||
@@ -19,18 +19,69 @@ | |||
19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
20 | #include <linux/pci.h> | 20 | #include <linux/pci.h> |
21 | #include <linux/device.h> | 21 | #include <linux/device.h> |
22 | #include <linux/debugfs.h> | ||
23 | #include <linux/seq_file.h> | ||
22 | #include <linux/io.h> | 24 | #include <linux/io.h> |
23 | 25 | ||
24 | #include <asm/pmc_atom.h> | 26 | #include <asm/pmc_atom.h> |
25 | 27 | ||
28 | #define DRIVER_NAME KBUILD_MODNAME | ||
29 | |||
26 | struct pmc_dev { | 30 | struct pmc_dev { |
27 | u32 base_addr; | 31 | u32 base_addr; |
28 | void __iomem *regmap; | 32 | void __iomem *regmap; |
33 | #ifdef CONFIG_DEBUG_FS | ||
34 | struct dentry *dbgfs_dir; | ||
35 | #endif /* CONFIG_DEBUG_FS */ | ||
29 | }; | 36 | }; |
30 | 37 | ||
31 | static struct pmc_dev pmc_device; | 38 | static struct pmc_dev pmc_device; |
32 | static u32 acpi_base_addr; | 39 | static u32 acpi_base_addr; |
33 | 40 | ||
41 | struct pmc_dev_map { | ||
42 | const char *name; | ||
43 | u32 bit_mask; | ||
44 | }; | ||
45 | |||
46 | static const struct pmc_dev_map dev_map[] = { | ||
47 | {"0 - LPSS1_F0_DMA", BIT_LPSS1_F0_DMA}, | ||
48 | {"1 - LPSS1_F1_PWM1", BIT_LPSS1_F1_PWM1}, | ||
49 | {"2 - LPSS1_F2_PWM2", BIT_LPSS1_F2_PWM2}, | ||
50 | {"3 - LPSS1_F3_HSUART1", BIT_LPSS1_F3_HSUART1}, | ||
51 | {"4 - LPSS1_F4_HSUART2", BIT_LPSS1_F4_HSUART2}, | ||
52 | {"5 - LPSS1_F5_SPI", BIT_LPSS1_F5_SPI}, | ||
53 | {"6 - LPSS1_F6_Reserved", BIT_LPSS1_F6_XXX}, | ||
54 | {"7 - LPSS1_F7_Reserved", BIT_LPSS1_F7_XXX}, | ||
55 | {"8 - SCC_EMMC", BIT_SCC_EMMC}, | ||
56 | {"9 - SCC_SDIO", BIT_SCC_SDIO}, | ||
57 | {"10 - SCC_SDCARD", BIT_SCC_SDCARD}, | ||
58 | {"11 - SCC_MIPI", BIT_SCC_MIPI}, | ||
59 | {"12 - HDA", BIT_HDA}, | ||
60 | {"13 - LPE", BIT_LPE}, | ||
61 | {"14 - OTG", BIT_OTG}, | ||
62 | {"15 - USH", BIT_USH}, | ||
63 | {"16 - GBE", BIT_GBE}, | ||
64 | {"17 - SATA", BIT_SATA}, | ||
65 | {"18 - USB_EHCI", BIT_USB_EHCI}, | ||
66 | {"19 - SEC", BIT_SEC}, | ||
67 | {"20 - PCIE_PORT0", BIT_PCIE_PORT0}, | ||
68 | {"21 - PCIE_PORT1", BIT_PCIE_PORT1}, | ||
69 | {"22 - PCIE_PORT2", BIT_PCIE_PORT2}, | ||
70 | {"23 - PCIE_PORT3", BIT_PCIE_PORT3}, | ||
71 | {"24 - LPSS2_F0_DMA", BIT_LPSS2_F0_DMA}, | ||
72 | {"25 - LPSS2_F1_I2C1", BIT_LPSS2_F1_I2C1}, | ||
73 | {"26 - LPSS2_F2_I2C2", BIT_LPSS2_F2_I2C2}, | ||
74 | {"27 - LPSS2_F3_I2C3", BIT_LPSS2_F3_I2C3}, | ||
75 | {"28 - LPSS2_F3_I2C4", BIT_LPSS2_F4_I2C4}, | ||
76 | {"29 - LPSS2_F5_I2C5", BIT_LPSS2_F5_I2C5}, | ||
77 | {"30 - LPSS2_F6_I2C6", BIT_LPSS2_F6_I2C6}, | ||
78 | {"31 - LPSS2_F7_I2C7", BIT_LPSS2_F7_I2C7}, | ||
79 | {"32 - SMB", BIT_SMB}, | ||
80 | {"33 - OTG_SS_PHY", BIT_OTG_SS_PHY}, | ||
81 | {"34 - USH_SS_PHY", BIT_USH_SS_PHY}, | ||
82 | {"35 - DFX", BIT_DFX}, | ||
83 | }; | ||
84 | |||
34 | static inline u32 pmc_reg_read(struct pmc_dev *pmc, int reg_offset) | 85 | static inline u32 pmc_reg_read(struct pmc_dev *pmc, int reg_offset) |
35 | { | 86 | { |
36 | return readl(pmc->regmap + reg_offset); | 87 | return readl(pmc->regmap + reg_offset); |
@@ -71,9 +122,125 @@ static void pmc_hw_reg_setup(struct pmc_dev *pmc) | |||
71 | pmc_reg_write(pmc, PMC_S0IX_WAKE_EN, (u32)PMC_WAKE_EN_SETTING); | 122 | pmc_reg_write(pmc, PMC_S0IX_WAKE_EN, (u32)PMC_WAKE_EN_SETTING); |
72 | } | 123 | } |
73 | 124 | ||
125 | #ifdef CONFIG_DEBUG_FS | ||
126 | static int pmc_dev_state_show(struct seq_file *s, void *unused) | ||
127 | { | ||
128 | struct pmc_dev *pmc = s->private; | ||
129 | u32 func_dis, func_dis_2, func_dis_index; | ||
130 | u32 d3_sts_0, d3_sts_1, d3_sts_index; | ||
131 | int dev_num, dev_index, reg_index; | ||
132 | |||
133 | func_dis = pmc_reg_read(pmc, PMC_FUNC_DIS); | ||
134 | func_dis_2 = pmc_reg_read(pmc, PMC_FUNC_DIS_2); | ||
135 | d3_sts_0 = pmc_reg_read(pmc, PMC_D3_STS_0); | ||
136 | d3_sts_1 = pmc_reg_read(pmc, PMC_D3_STS_1); | ||
137 | |||
138 | dev_num = ARRAY_SIZE(dev_map); | ||
139 | |||
140 | for (dev_index = 0; dev_index < dev_num; dev_index++) { | ||
141 | reg_index = dev_index / PMC_REG_BIT_WIDTH; | ||
142 | if (reg_index) { | ||
143 | func_dis_index = func_dis_2; | ||
144 | d3_sts_index = d3_sts_1; | ||
145 | } else { | ||
146 | func_dis_index = func_dis; | ||
147 | d3_sts_index = d3_sts_0; | ||
148 | } | ||
149 | |||
150 | seq_printf(s, "Dev: %-32s\tState: %s [%s]\n", | ||
151 | dev_map[dev_index].name, | ||
152 | dev_map[dev_index].bit_mask & func_dis_index ? | ||
153 | "Disabled" : "Enabled ", | ||
154 | dev_map[dev_index].bit_mask & d3_sts_index ? | ||
155 | "D3" : "D0"); | ||
156 | } | ||
157 | return 0; | ||
158 | } | ||
159 | |||
160 | static int pmc_dev_state_open(struct inode *inode, struct file *file) | ||
161 | { | ||
162 | return single_open(file, pmc_dev_state_show, inode->i_private); | ||
163 | } | ||
164 | |||
165 | static const struct file_operations pmc_dev_state_ops = { | ||
166 | .open = pmc_dev_state_open, | ||
167 | .read = seq_read, | ||
168 | .llseek = seq_lseek, | ||
169 | .release = single_release, | ||
170 | }; | ||
171 | |||
172 | static int pmc_sleep_tmr_show(struct seq_file *s, void *unused) | ||
173 | { | ||
174 | struct pmc_dev *pmc = s->private; | ||
175 | u64 s0ir_tmr, s0i1_tmr, s0i2_tmr, s0i3_tmr, s0_tmr; | ||
176 | |||
177 | s0ir_tmr = pmc_reg_read(pmc, PMC_S0IR_TMR) << PMC_TMR_SHIFT; | ||
178 | s0i1_tmr = pmc_reg_read(pmc, PMC_S0I1_TMR) << PMC_TMR_SHIFT; | ||
179 | s0i2_tmr = pmc_reg_read(pmc, PMC_S0I2_TMR) << PMC_TMR_SHIFT; | ||
180 | s0i3_tmr = pmc_reg_read(pmc, PMC_S0I3_TMR) << PMC_TMR_SHIFT; | ||
181 | s0_tmr = pmc_reg_read(pmc, PMC_S0_TMR) << PMC_TMR_SHIFT; | ||
182 | |||
183 | seq_printf(s, "S0IR Residency:\t%lldus\n", s0ir_tmr); | ||
184 | seq_printf(s, "S0I1 Residency:\t%lldus\n", s0i1_tmr); | ||
185 | seq_printf(s, "S0I2 Residency:\t%lldus\n", s0i2_tmr); | ||
186 | seq_printf(s, "S0I3 Residency:\t%lldus\n", s0i3_tmr); | ||
187 | seq_printf(s, "S0 Residency:\t%lldus\n", s0_tmr); | ||
188 | return 0; | ||
189 | } | ||
190 | |||
191 | static int pmc_sleep_tmr_open(struct inode *inode, struct file *file) | ||
192 | { | ||
193 | return single_open(file, pmc_sleep_tmr_show, inode->i_private); | ||
194 | } | ||
195 | |||
196 | static const struct file_operations pmc_sleep_tmr_ops = { | ||
197 | .open = pmc_sleep_tmr_open, | ||
198 | .read = seq_read, | ||
199 | .llseek = seq_lseek, | ||
200 | .release = single_release, | ||
201 | }; | ||
202 | |||
203 | static void pmc_dbgfs_unregister(struct pmc_dev *pmc) | ||
204 | { | ||
205 | if (!pmc->dbgfs_dir) | ||
206 | return; | ||
207 | |||
208 | debugfs_remove_recursive(pmc->dbgfs_dir); | ||
209 | pmc->dbgfs_dir = NULL; | ||
210 | } | ||
211 | |||
212 | static int pmc_dbgfs_register(struct pmc_dev *pmc, struct pci_dev *pdev) | ||
213 | { | ||
214 | struct dentry *dir, *f; | ||
215 | |||
216 | dir = debugfs_create_dir("pmc_atom", NULL); | ||
217 | if (!dir) | ||
218 | return -ENOMEM; | ||
219 | |||
220 | f = debugfs_create_file("dev_state", S_IFREG | S_IRUGO, | ||
221 | dir, pmc, &pmc_dev_state_ops); | ||
222 | if (!f) { | ||
223 | dev_err(&pdev->dev, "dev_states register failed\n"); | ||
224 | goto err; | ||
225 | } | ||
226 | f = debugfs_create_file("sleep_state", S_IFREG | S_IRUGO, | ||
227 | dir, pmc, &pmc_sleep_tmr_ops); | ||
228 | if (!f) { | ||
229 | dev_err(&pdev->dev, "sleep_state register failed\n"); | ||
230 | goto err; | ||
231 | } | ||
232 | pmc->dbgfs_dir = dir; | ||
233 | return 0; | ||
234 | err: | ||
235 | pmc_dbgfs_unregister(pmc); | ||
236 | return -ENODEV; | ||
237 | } | ||
238 | #endif /* CONFIG_DEBUG_FS */ | ||
239 | |||
74 | static int pmc_setup_dev(struct pci_dev *pdev) | 240 | static int pmc_setup_dev(struct pci_dev *pdev) |
75 | { | 241 | { |
76 | struct pmc_dev *pmc = &pmc_device; | 242 | struct pmc_dev *pmc = &pmc_device; |
243 | int ret; | ||
77 | 244 | ||
78 | /* Obtain ACPI base address */ | 245 | /* Obtain ACPI base address */ |
79 | pci_read_config_dword(pdev, ACPI_BASE_ADDR_OFFSET, &acpi_base_addr); | 246 | pci_read_config_dword(pdev, ACPI_BASE_ADDR_OFFSET, &acpi_base_addr); |
@@ -94,6 +261,14 @@ static int pmc_setup_dev(struct pci_dev *pdev) | |||
94 | 261 | ||
95 | /* PMC hardware registers setup */ | 262 | /* PMC hardware registers setup */ |
96 | pmc_hw_reg_setup(pmc); | 263 | pmc_hw_reg_setup(pmc); |
264 | |||
265 | #ifdef CONFIG_DEBUG_FS | ||
266 | ret = pmc_dbgfs_register(pmc, pdev); | ||
267 | if (ret) { | ||
268 | iounmap(pmc->regmap); | ||
269 | return ret; | ||
270 | } | ||
271 | #endif /* CONFIG_DEBUG_FS */ | ||
97 | return 0; | 272 | return 0; |
98 | } | 273 | } |
99 | 274 | ||