blob: 77bac859342de60b3b8253addbb9998b719bf62a [file] [log] [blame]
Li, Aubrey93e5ead2014-06-30 14:08:42 +08001/*
2 * Intel Atom SOC Power Management Controller Driver
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 */
15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
Li, Aubreyf8559112014-06-30 14:10:33 +080018#include <linux/debugfs.h>
Irina Tirdea80a75812017-01-23 12:07:43 -060019#include <linux/device.h>
20#include <linux/init.h>
Li, Aubrey93e5ead2014-06-30 14:08:42 +080021#include <linux/io.h>
Irina Tirdea282a4e42017-01-23 12:07:44 -060022#include <linux/platform_data/x86/clk-pmc-atom.h>
Irina Tirdea80a75812017-01-23 12:07:43 -060023#include <linux/platform_data/x86/pmc_atom.h>
Irina Tirdea282a4e42017-01-23 12:07:44 -060024#include <linux/platform_device.h>
Irina Tirdea80a75812017-01-23 12:07:43 -060025#include <linux/pci.h>
26#include <linux/seq_file.h>
Li, Aubrey93e5ead2014-06-30 14:08:42 +080027
Andy Shevchenko940406d2015-07-06 17:29:02 +030028struct pmc_bit_map {
29 const char *name;
30 u32 bit_mask;
31};
32
33struct pmc_reg_map {
Andy Shevchenko2b8f8ed2015-07-06 17:29:03 +030034 const struct pmc_bit_map *d3_sts_0;
35 const struct pmc_bit_map *d3_sts_1;
36 const struct pmc_bit_map *func_dis;
37 const struct pmc_bit_map *func_dis_2;
Andy Shevchenko940406d2015-07-06 17:29:02 +030038 const struct pmc_bit_map *pss;
39};
40
Irina Tirdea282a4e42017-01-23 12:07:44 -060041struct pmc_data {
42 const struct pmc_reg_map *map;
43 const struct pmc_clk *clks;
44};
45
Li, Aubreyb00055c2014-06-30 14:09:38 +080046struct pmc_dev {
47 u32 base_addr;
48 void __iomem *regmap;
Andy Shevchenko940406d2015-07-06 17:29:02 +030049 const struct pmc_reg_map *map;
Li, Aubreyf8559112014-06-30 14:10:33 +080050#ifdef CONFIG_DEBUG_FS
51 struct dentry *dbgfs_dir;
52#endif /* CONFIG_DEBUG_FS */
Andy Shevchenko68872eb2015-07-06 17:29:00 +030053 bool init;
Li, Aubreyb00055c2014-06-30 14:09:38 +080054};
55
56static struct pmc_dev pmc_device;
Li, Aubrey93e5ead2014-06-30 14:08:42 +080057static u32 acpi_base_addr;
58
Irina Tirdea282a4e42017-01-23 12:07:44 -060059static const struct pmc_clk byt_clks[] = {
60 {
61 .name = "xtal",
62 .freq = 25000000,
63 .parent_name = NULL,
64 },
65 {
66 .name = "pll",
67 .freq = 19200000,
68 .parent_name = "xtal",
69 },
70 {},
71};
72
73static const struct pmc_clk cht_clks[] = {
74 {
75 .name = "xtal",
76 .freq = 19200000,
77 .parent_name = NULL,
78 },
79 {},
80};
81
Andy Shevchenko2b8f8ed2015-07-06 17:29:03 +030082static const struct pmc_bit_map d3_sts_0_map[] = {
Andy Shevchenkoc3c65aa2015-07-06 17:29:01 +030083 {"LPSS1_F0_DMA", BIT_LPSS1_F0_DMA},
84 {"LPSS1_F1_PWM1", BIT_LPSS1_F1_PWM1},
85 {"LPSS1_F2_PWM2", BIT_LPSS1_F2_PWM2},
86 {"LPSS1_F3_HSUART1", BIT_LPSS1_F3_HSUART1},
87 {"LPSS1_F4_HSUART2", BIT_LPSS1_F4_HSUART2},
88 {"LPSS1_F5_SPI", BIT_LPSS1_F5_SPI},
89 {"LPSS1_F6_Reserved", BIT_LPSS1_F6_XXX},
90 {"LPSS1_F7_Reserved", BIT_LPSS1_F7_XXX},
91 {"SCC_EMMC", BIT_SCC_EMMC},
92 {"SCC_SDIO", BIT_SCC_SDIO},
93 {"SCC_SDCARD", BIT_SCC_SDCARD},
94 {"SCC_MIPI", BIT_SCC_MIPI},
95 {"HDA", BIT_HDA},
96 {"LPE", BIT_LPE},
97 {"OTG", BIT_OTG},
98 {"USH", BIT_USH},
99 {"GBE", BIT_GBE},
100 {"SATA", BIT_SATA},
101 {"USB_EHCI", BIT_USB_EHCI},
102 {"SEC", BIT_SEC},
103 {"PCIE_PORT0", BIT_PCIE_PORT0},
104 {"PCIE_PORT1", BIT_PCIE_PORT1},
105 {"PCIE_PORT2", BIT_PCIE_PORT2},
106 {"PCIE_PORT3", BIT_PCIE_PORT3},
107 {"LPSS2_F0_DMA", BIT_LPSS2_F0_DMA},
108 {"LPSS2_F1_I2C1", BIT_LPSS2_F1_I2C1},
109 {"LPSS2_F2_I2C2", BIT_LPSS2_F2_I2C2},
110 {"LPSS2_F3_I2C3", BIT_LPSS2_F3_I2C3},
111 {"LPSS2_F3_I2C4", BIT_LPSS2_F4_I2C4},
112 {"LPSS2_F5_I2C5", BIT_LPSS2_F5_I2C5},
113 {"LPSS2_F6_I2C6", BIT_LPSS2_F6_I2C6},
114 {"LPSS2_F7_I2C7", BIT_LPSS2_F7_I2C7},
Andy Shevchenko2b8f8ed2015-07-06 17:29:03 +0300115 {},
116};
117
118static struct pmc_bit_map byt_d3_sts_1_map[] = {
Andy Shevchenkoc3c65aa2015-07-06 17:29:01 +0300119 {"SMB", BIT_SMB},
120 {"OTG_SS_PHY", BIT_OTG_SS_PHY},
121 {"USH_SS_PHY", BIT_USH_SS_PHY},
122 {"DFX", BIT_DFX},
123 {},
Li, Aubreyf8559112014-06-30 14:10:33 +0800124};
125
Andy Shevchenko2b8f8ed2015-07-06 17:29:03 +0300126static struct pmc_bit_map cht_d3_sts_1_map[] = {
127 {"SMB", BIT_SMB},
128 {"GMM", BIT_STS_GMM},
129 {"ISH", BIT_STS_ISH},
130 {},
131};
132
133static struct pmc_bit_map cht_func_dis_2_map[] = {
134 {"SMB", BIT_SMB},
135 {"GMM", BIT_FD_GMM},
136 {"ISH", BIT_FD_ISH},
137 {},
138};
139
140static const struct pmc_bit_map byt_pss_map[] = {
Andy Shevchenkoc3c65aa2015-07-06 17:29:01 +0300141 {"GBE", PMC_PSS_BIT_GBE},
142 {"SATA", PMC_PSS_BIT_SATA},
143 {"HDA", PMC_PSS_BIT_HDA},
144 {"SEC", PMC_PSS_BIT_SEC},
145 {"PCIE", PMC_PSS_BIT_PCIE},
146 {"LPSS", PMC_PSS_BIT_LPSS},
147 {"LPE", PMC_PSS_BIT_LPE},
148 {"DFX", PMC_PSS_BIT_DFX},
149 {"USH_CTRL", PMC_PSS_BIT_USH_CTRL},
150 {"USH_SUS", PMC_PSS_BIT_USH_SUS},
151 {"USH_VCCS", PMC_PSS_BIT_USH_VCCS},
152 {"USH_VCCA", PMC_PSS_BIT_USH_VCCA},
153 {"OTG_CTRL", PMC_PSS_BIT_OTG_CTRL},
154 {"OTG_VCCS", PMC_PSS_BIT_OTG_VCCS},
155 {"OTG_VCCA_CLK", PMC_PSS_BIT_OTG_VCCA_CLK},
156 {"OTG_VCCA", PMC_PSS_BIT_OTG_VCCA},
157 {"USB", PMC_PSS_BIT_USB},
158 {"USB_SUS", PMC_PSS_BIT_USB_SUS},
159 {},
Andy Shevchenko0e154022015-01-14 18:39:35 +0200160};
161
Andy Shevchenko2b8f8ed2015-07-06 17:29:03 +0300162static const struct pmc_bit_map cht_pss_map[] = {
163 {"SATA", PMC_PSS_BIT_SATA},
164 {"HDA", PMC_PSS_BIT_HDA},
165 {"SEC", PMC_PSS_BIT_SEC},
166 {"PCIE", PMC_PSS_BIT_PCIE},
167 {"LPSS", PMC_PSS_BIT_LPSS},
168 {"LPE", PMC_PSS_BIT_LPE},
169 {"UFS", PMC_PSS_BIT_CHT_UFS},
170 {"UXD", PMC_PSS_BIT_CHT_UXD},
171 {"UXD_FD", PMC_PSS_BIT_CHT_UXD_FD},
172 {"UX_ENG", PMC_PSS_BIT_CHT_UX_ENG},
173 {"USB_SUS", PMC_PSS_BIT_CHT_USB_SUS},
174 {"GMM", PMC_PSS_BIT_CHT_GMM},
175 {"ISH", PMC_PSS_BIT_CHT_ISH},
176 {"DFX_MASTER", PMC_PSS_BIT_CHT_DFX_MASTER},
177 {"DFX_CLUSTER1", PMC_PSS_BIT_CHT_DFX_CLUSTER1},
178 {"DFX_CLUSTER2", PMC_PSS_BIT_CHT_DFX_CLUSTER2},
179 {"DFX_CLUSTER3", PMC_PSS_BIT_CHT_DFX_CLUSTER3},
180 {"DFX_CLUSTER4", PMC_PSS_BIT_CHT_DFX_CLUSTER4},
181 {"DFX_CLUSTER5", PMC_PSS_BIT_CHT_DFX_CLUSTER5},
182 {},
183};
184
185static const struct pmc_reg_map byt_reg_map = {
186 .d3_sts_0 = d3_sts_0_map,
187 .d3_sts_1 = byt_d3_sts_1_map,
188 .func_dis = d3_sts_0_map,
189 .func_dis_2 = byt_d3_sts_1_map,
190 .pss = byt_pss_map,
191};
192
193static const struct pmc_reg_map cht_reg_map = {
194 .d3_sts_0 = d3_sts_0_map,
195 .d3_sts_1 = cht_d3_sts_1_map,
196 .func_dis = d3_sts_0_map,
197 .func_dis_2 = cht_func_dis_2_map,
198 .pss = cht_pss_map,
Andy Shevchenko940406d2015-07-06 17:29:02 +0300199};
200
Irina Tirdea282a4e42017-01-23 12:07:44 -0600201static const struct pmc_data byt_data = {
202 .map = &byt_reg_map,
203 .clks = byt_clks,
204};
205
206static const struct pmc_data cht_data = {
207 .map = &cht_reg_map,
208 .clks = cht_clks,
209};
210
Li, Aubreyb00055c2014-06-30 14:09:38 +0800211static inline u32 pmc_reg_read(struct pmc_dev *pmc, int reg_offset)
212{
213 return readl(pmc->regmap + reg_offset);
214}
215
216static inline void pmc_reg_write(struct pmc_dev *pmc, int reg_offset, u32 val)
217{
218 writel(val, pmc->regmap + reg_offset);
219}
220
Andy Shevchenko68872eb2015-07-06 17:29:00 +0300221int pmc_atom_read(int offset, u32 *value)
222{
223 struct pmc_dev *pmc = &pmc_device;
224
225 if (!pmc->init)
226 return -ENODEV;
227
228 *value = pmc_reg_read(pmc, offset);
229 return 0;
230}
231EXPORT_SYMBOL_GPL(pmc_atom_read);
232
233int pmc_atom_write(int offset, u32 value)
234{
235 struct pmc_dev *pmc = &pmc_device;
236
237 if (!pmc->init)
238 return -ENODEV;
239
240 pmc_reg_write(pmc, offset, value);
241 return 0;
242}
243EXPORT_SYMBOL_GPL(pmc_atom_write);
244
Li, Aubrey93e5ead2014-06-30 14:08:42 +0800245static void pmc_power_off(void)
246{
247 u16 pm1_cnt_port;
248 u32 pm1_cnt_value;
249
250 pr_info("Preparing to enter system sleep state S5\n");
251
252 pm1_cnt_port = acpi_base_addr + PM1_CNT;
253
254 pm1_cnt_value = inl(pm1_cnt_port);
255 pm1_cnt_value &= SLEEP_TYPE_MASK;
256 pm1_cnt_value |= SLEEP_TYPE_S5;
257 pm1_cnt_value |= SLEEP_ENABLE;
258
259 outl(pm1_cnt_value, pm1_cnt_port);
260}
261
Li, Aubreyb00055c2014-06-30 14:09:38 +0800262static void pmc_hw_reg_setup(struct pmc_dev *pmc)
263{
264 /*
265 * Disable PMC S0IX_WAKE_EN events coming from:
266 * - LPC clock run
267 * - GPIO_SUS ored dedicated IRQs
268 * - GPIO_SCORE ored dedicated IRQs
269 * - GPIO_SUS shared IRQ
270 * - GPIO_SCORE shared IRQ
271 */
272 pmc_reg_write(pmc, PMC_S0IX_WAKE_EN, (u32)PMC_WAKE_EN_SETTING);
273}
274
Li, Aubreyf8559112014-06-30 14:10:33 +0800275#ifdef CONFIG_DEBUG_FS
Andy Shevchenko2b8f8ed2015-07-06 17:29:03 +0300276static void pmc_dev_state_print(struct seq_file *s, int reg_index,
277 u32 sts, const struct pmc_bit_map *sts_map,
278 u32 fd, const struct pmc_bit_map *fd_map)
279{
280 int offset = PMC_REG_BIT_WIDTH * reg_index;
281 int index;
282
283 for (index = 0; sts_map[index].name; index++) {
284 seq_printf(s, "Dev: %-2d - %-32s\tState: %s [%s]\n",
285 offset + index, sts_map[index].name,
286 fd_map[index].bit_mask & fd ? "Disabled" : "Enabled ",
287 sts_map[index].bit_mask & sts ? "D3" : "D0");
288 }
289}
290
Li, Aubreyf8559112014-06-30 14:10:33 +0800291static int pmc_dev_state_show(struct seq_file *s, void *unused)
292{
293 struct pmc_dev *pmc = s->private;
Andy Shevchenko2b8f8ed2015-07-06 17:29:03 +0300294 const struct pmc_reg_map *m = pmc->map;
295 u32 func_dis, func_dis_2;
296 u32 d3_sts_0, d3_sts_1;
Li, Aubreyf8559112014-06-30 14:10:33 +0800297
298 func_dis = pmc_reg_read(pmc, PMC_FUNC_DIS);
299 func_dis_2 = pmc_reg_read(pmc, PMC_FUNC_DIS_2);
300 d3_sts_0 = pmc_reg_read(pmc, PMC_D3_STS_0);
301 d3_sts_1 = pmc_reg_read(pmc, PMC_D3_STS_1);
302
Andy Shevchenko2b8f8ed2015-07-06 17:29:03 +0300303 /* Low part */
304 pmc_dev_state_print(s, 0, d3_sts_0, m->d3_sts_0, func_dis, m->func_dis);
Li, Aubreyf8559112014-06-30 14:10:33 +0800305
Andy Shevchenko2b8f8ed2015-07-06 17:29:03 +0300306 /* High part */
307 pmc_dev_state_print(s, 1, d3_sts_1, m->d3_sts_1, func_dis_2, m->func_dis_2);
308
Li, Aubreyf8559112014-06-30 14:10:33 +0800309 return 0;
310}
311
312static int pmc_dev_state_open(struct inode *inode, struct file *file)
313{
314 return single_open(file, pmc_dev_state_show, inode->i_private);
315}
316
317static const struct file_operations pmc_dev_state_ops = {
318 .open = pmc_dev_state_open,
319 .read = seq_read,
320 .llseek = seq_lseek,
321 .release = single_release,
322};
323
Andy Shevchenko0e154022015-01-14 18:39:35 +0200324static int pmc_pss_state_show(struct seq_file *s, void *unused)
325{
326 struct pmc_dev *pmc = s->private;
Andy Shevchenko940406d2015-07-06 17:29:02 +0300327 const struct pmc_bit_map *map = pmc->map->pss;
Andy Shevchenko0e154022015-01-14 18:39:35 +0200328 u32 pss = pmc_reg_read(pmc, PMC_PSS);
Andy Shevchenko940406d2015-07-06 17:29:02 +0300329 int index;
Andy Shevchenko0e154022015-01-14 18:39:35 +0200330
Andy Shevchenko940406d2015-07-06 17:29:02 +0300331 for (index = 0; map[index].name; index++) {
Andy Shevchenkoc3c65aa2015-07-06 17:29:01 +0300332 seq_printf(s, "Island: %-2d - %-32s\tState: %s\n",
Andy Shevchenko940406d2015-07-06 17:29:02 +0300333 index, map[index].name,
334 map[index].bit_mask & pss ? "Off" : "On");
Andy Shevchenko0e154022015-01-14 18:39:35 +0200335 }
336 return 0;
337}
338
339static int pmc_pss_state_open(struct inode *inode, struct file *file)
340{
341 return single_open(file, pmc_pss_state_show, inode->i_private);
342}
343
344static const struct file_operations pmc_pss_state_ops = {
345 .open = pmc_pss_state_open,
346 .read = seq_read,
347 .llseek = seq_lseek,
348 .release = single_release,
349};
350
Li, Aubreyf8559112014-06-30 14:10:33 +0800351static int pmc_sleep_tmr_show(struct seq_file *s, void *unused)
352{
353 struct pmc_dev *pmc = s->private;
354 u64 s0ir_tmr, s0i1_tmr, s0i2_tmr, s0i3_tmr, s0_tmr;
355
Dan Carpenter4c51cb02014-08-01 11:27:15 +0300356 s0ir_tmr = (u64)pmc_reg_read(pmc, PMC_S0IR_TMR) << PMC_TMR_SHIFT;
357 s0i1_tmr = (u64)pmc_reg_read(pmc, PMC_S0I1_TMR) << PMC_TMR_SHIFT;
358 s0i2_tmr = (u64)pmc_reg_read(pmc, PMC_S0I2_TMR) << PMC_TMR_SHIFT;
359 s0i3_tmr = (u64)pmc_reg_read(pmc, PMC_S0I3_TMR) << PMC_TMR_SHIFT;
360 s0_tmr = (u64)pmc_reg_read(pmc, PMC_S0_TMR) << PMC_TMR_SHIFT;
Li, Aubreyf8559112014-06-30 14:10:33 +0800361
362 seq_printf(s, "S0IR Residency:\t%lldus\n", s0ir_tmr);
363 seq_printf(s, "S0I1 Residency:\t%lldus\n", s0i1_tmr);
364 seq_printf(s, "S0I2 Residency:\t%lldus\n", s0i2_tmr);
365 seq_printf(s, "S0I3 Residency:\t%lldus\n", s0i3_tmr);
366 seq_printf(s, "S0 Residency:\t%lldus\n", s0_tmr);
367 return 0;
368}
369
370static int pmc_sleep_tmr_open(struct inode *inode, struct file *file)
371{
372 return single_open(file, pmc_sleep_tmr_show, inode->i_private);
373}
374
375static const struct file_operations pmc_sleep_tmr_ops = {
376 .open = pmc_sleep_tmr_open,
377 .read = seq_read,
378 .llseek = seq_lseek,
379 .release = single_release,
380};
381
382static void pmc_dbgfs_unregister(struct pmc_dev *pmc)
383{
Li, Aubreyf8559112014-06-30 14:10:33 +0800384 debugfs_remove_recursive(pmc->dbgfs_dir);
Li, Aubreyf8559112014-06-30 14:10:33 +0800385}
386
Andy Shevchenko68872eb2015-07-06 17:29:00 +0300387static int pmc_dbgfs_register(struct pmc_dev *pmc)
Li, Aubreyf8559112014-06-30 14:10:33 +0800388{
389 struct dentry *dir, *f;
390
391 dir = debugfs_create_dir("pmc_atom", NULL);
392 if (!dir)
393 return -ENOMEM;
394
Andy Shevchenko1b43d712015-01-14 18:39:31 +0200395 pmc->dbgfs_dir = dir;
396
Li, Aubreyf8559112014-06-30 14:10:33 +0800397 f = debugfs_create_file("dev_state", S_IFREG | S_IRUGO,
398 dir, pmc, &pmc_dev_state_ops);
Andy Shevchenko68872eb2015-07-06 17:29:00 +0300399 if (!f)
Li, Aubreyf8559112014-06-30 14:10:33 +0800400 goto err;
Andy Shevchenko0e154022015-01-14 18:39:35 +0200401
402 f = debugfs_create_file("pss_state", S_IFREG | S_IRUGO,
403 dir, pmc, &pmc_pss_state_ops);
Andy Shevchenko68872eb2015-07-06 17:29:00 +0300404 if (!f)
Andy Shevchenko0e154022015-01-14 18:39:35 +0200405 goto err;
Andy Shevchenko0e154022015-01-14 18:39:35 +0200406
Li, Aubreyf8559112014-06-30 14:10:33 +0800407 f = debugfs_create_file("sleep_state", S_IFREG | S_IRUGO,
408 dir, pmc, &pmc_sleep_tmr_ops);
Andy Shevchenko68872eb2015-07-06 17:29:00 +0300409 if (!f)
Li, Aubreyf8559112014-06-30 14:10:33 +0800410 goto err;
Andy Shevchenko1b43d712015-01-14 18:39:31 +0200411
Li, Aubreyf8559112014-06-30 14:10:33 +0800412 return 0;
413err:
414 pmc_dbgfs_unregister(pmc);
415 return -ENODEV;
416}
Martin Kelly9575a6a2014-09-17 07:17:56 -0700417#else
Andy Shevchenko68872eb2015-07-06 17:29:00 +0300418static int pmc_dbgfs_register(struct pmc_dev *pmc)
Martin Kelly9575a6a2014-09-17 07:17:56 -0700419{
420 return 0;
421}
Li, Aubreyf8559112014-06-30 14:10:33 +0800422#endif /* CONFIG_DEBUG_FS */
423
Irina Tirdea282a4e42017-01-23 12:07:44 -0600424static int pmc_setup_clks(struct pci_dev *pdev, void __iomem *pmc_regmap,
425 const struct pmc_data *pmc_data)
426{
427 struct platform_device *clkdev;
428 struct pmc_clk_data *clk_data;
429
430 clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
431 if (!clk_data)
432 return -ENOMEM;
433
434 clk_data->base = pmc_regmap; /* offset is added by client */
435 clk_data->clks = pmc_data->clks;
436
437 clkdev = platform_device_register_data(&pdev->dev, "clk-pmc-atom",
438 PLATFORM_DEVID_NONE,
439 clk_data, sizeof(*clk_data));
440 if (IS_ERR(clkdev)) {
441 kfree(clk_data);
442 return PTR_ERR(clkdev);
443 }
444
445 kfree(clk_data);
446
447 return 0;
448}
449
Andy Shevchenko2b8f8ed2015-07-06 17:29:03 +0300450static int pmc_setup_dev(struct pci_dev *pdev, const struct pci_device_id *ent)
Li, Aubrey93e5ead2014-06-30 14:08:42 +0800451{
Li, Aubreyb00055c2014-06-30 14:09:38 +0800452 struct pmc_dev *pmc = &pmc_device;
Irina Tirdea282a4e42017-01-23 12:07:44 -0600453 const struct pmc_data *data = (struct pmc_data *)ent->driver_data;
454 const struct pmc_reg_map *map = data->map;
Li, Aubreyf8559112014-06-30 14:10:33 +0800455 int ret;
Li, Aubreyb00055c2014-06-30 14:09:38 +0800456
Li, Aubrey93e5ead2014-06-30 14:08:42 +0800457 /* Obtain ACPI base address */
458 pci_read_config_dword(pdev, ACPI_BASE_ADDR_OFFSET, &acpi_base_addr);
459 acpi_base_addr &= ACPI_BASE_ADDR_MASK;
460
461 /* Install power off function */
462 if (acpi_base_addr != 0 && pm_power_off == NULL)
463 pm_power_off = pmc_power_off;
464
Li, Aubreyb00055c2014-06-30 14:09:38 +0800465 pci_read_config_dword(pdev, PMC_BASE_ADDR_OFFSET, &pmc->base_addr);
466 pmc->base_addr &= PMC_BASE_ADDR_MASK;
467
468 pmc->regmap = ioremap_nocache(pmc->base_addr, PMC_MMIO_REG_LEN);
469 if (!pmc->regmap) {
470 dev_err(&pdev->dev, "error: ioremap failed\n");
471 return -ENOMEM;
472 }
473
Andy Shevchenko940406d2015-07-06 17:29:02 +0300474 pmc->map = map;
475
Li, Aubreyb00055c2014-06-30 14:09:38 +0800476 /* PMC hardware registers setup */
477 pmc_hw_reg_setup(pmc);
Li, Aubreyf8559112014-06-30 14:10:33 +0800478
Andy Shevchenko68872eb2015-07-06 17:29:00 +0300479 ret = pmc_dbgfs_register(pmc);
480 if (ret)
481 dev_warn(&pdev->dev, "debugfs register failed\n");
Martin Kelly9575a6a2014-09-17 07:17:56 -0700482
Irina Tirdea282a4e42017-01-23 12:07:44 -0600483 /* Register platform clocks - PMC_PLT_CLK [0..5] */
484 ret = pmc_setup_clks(pdev, pmc->regmap, data);
485 if (ret)
486 dev_warn(&pdev->dev, "platform clocks register failed: %d\n",
487 ret);
488
Andy Shevchenko68872eb2015-07-06 17:29:00 +0300489 pmc->init = true;
Martin Kelly9575a6a2014-09-17 07:17:56 -0700490 return ret;
Li, Aubrey93e5ead2014-06-30 14:08:42 +0800491}
492
493/*
494 * Data for PCI driver interface
495 *
Paul Gortmakere971aa22015-08-24 19:34:53 -0400496 * used by pci_match_id() call below.
Li, Aubrey93e5ead2014-06-30 14:08:42 +0800497 */
498static const struct pci_device_id pmc_pci_ids[] = {
Irina Tirdea282a4e42017-01-23 12:07:44 -0600499 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_VLV_PMC), (kernel_ulong_t)&byt_data },
500 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_CHT_PMC), (kernel_ulong_t)&cht_data },
Li, Aubrey93e5ead2014-06-30 14:08:42 +0800501 { 0, },
502};
503
Li, Aubrey93e5ead2014-06-30 14:08:42 +0800504static int __init pmc_atom_init(void)
505{
Li, Aubrey93e5ead2014-06-30 14:08:42 +0800506 struct pci_dev *pdev = NULL;
507 const struct pci_device_id *ent;
508
509 /* We look for our device - PCU PMC
510 * we assume that there is max. one device.
511 *
512 * We can't use plain pci_driver mechanism,
513 * as the device is really a multiple function device,
514 * main driver that binds to the pci_device is lpc_ich
515 * and have to find & bind to the device this way.
516 */
517 for_each_pci_dev(pdev) {
518 ent = pci_match_id(pmc_pci_ids, pdev);
Andy Shevchenko4b25f422015-01-14 18:39:34 +0200519 if (ent)
Andy Shevchenko2b8f8ed2015-07-06 17:29:03 +0300520 return pmc_setup_dev(pdev, ent);
Li, Aubrey93e5ead2014-06-30 14:08:42 +0800521 }
522 /* Device not found. */
Andy Shevchenko4b25f422015-01-14 18:39:34 +0200523 return -ENODEV;
Li, Aubrey93e5ead2014-06-30 14:08:42 +0800524}
525
Paul Gortmakere971aa22015-08-24 19:34:53 -0400526device_initcall(pmc_atom_init);
Li, Aubrey93e5ead2014-06-30 14:08:42 +0800527
Paul Gortmakere971aa22015-08-24 19:34:53 -0400528/*
Li, Aubrey93e5ead2014-06-30 14:08:42 +0800529MODULE_AUTHOR("Aubrey Li <aubrey.li@linux.intel.com>");
530MODULE_DESCRIPTION("Intel Atom SOC Power Management Controller Interface");
531MODULE_LICENSE("GPL v2");
Paul Gortmakere971aa22015-08-24 19:34:53 -0400532*/