blob: d37cbd1cf58cc18c9ce9707472b254dca7c8b5f3 [file] [log] [blame]
Andy Shevchenkoad51f282018-09-26 18:27:40 +03001// SPDX-License-Identifier: GPL-2.0
qipeng.zha0a8b8352015-06-27 00:32:15 +08002/*
Andy Shevchenkoad51f282018-09-26 18:27:40 +03003 * Driver for the Intel PMC IPC mechanism
qipeng.zha0a8b8352015-06-27 00:32:15 +08004 *
5 * (C) Copyright 2014-2015 Intel Corporation
6 *
Andy Shevchenkoad51f282018-09-26 18:27:40 +03007 * This driver is based on Intel SCU IPC driver(intel_scu_ipc.c) by
qipeng.zha0a8b8352015-06-27 00:32:15 +08008 * Sreedhara DS <sreedhara.ds@intel.com>
9 *
qipeng.zha0a8b8352015-06-27 00:32:15 +080010 * PMC running in ARC processor communicates with other entity running in IA
11 * core through IPC mechanism which in turn messaging between IA core ad PMC.
12 */
13
Andy Shevchenko90881772018-09-26 18:27:14 +030014#include <linux/acpi.h>
15#include <linux/atomic.h>
16#include <linux/bitops.h>
qipeng.zha0a8b8352015-06-27 00:32:15 +080017#include <linux/delay.h>
qipeng.zha0a8b8352015-06-27 00:32:15 +080018#include <linux/device.h>
Andy Shevchenko90881772018-09-26 18:27:14 +030019#include <linux/errno.h>
20#include <linux/interrupt.h>
21#include <linux/io-64-nonatomic-lo-hi.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/notifier.h>
qipeng.zha0a8b8352015-06-27 00:32:15 +080025#include <linux/pci.h>
26#include <linux/platform_device.h>
Andy Shevchenko90881772018-09-26 18:27:14 +030027#include <linux/pm.h>
qipeng.zha0a8b8352015-06-27 00:32:15 +080028#include <linux/pm_qos.h>
qipeng.zha0a8b8352015-06-27 00:32:15 +080029#include <linux/sched.h>
Kuppuswamy Sathyanarayanan6687aeb2017-10-07 15:19:51 -070030#include <linux/spinlock.h>
Andy Shevchenko90881772018-09-26 18:27:14 +030031#include <linux/suspend.h>
Shanth Murthy76062b42017-02-13 04:02:52 -080032
qipeng.zha0a8b8352015-06-27 00:32:15 +080033#include <asm/intel_pmc_ipc.h>
Shanth Murthy76062b42017-02-13 04:02:52 -080034
Matt Fleming420b54d2015-08-06 13:46:24 +010035#include <linux/platform_data/itco_wdt.h>
qipeng.zha0a8b8352015-06-27 00:32:15 +080036
37/*
38 * IPC registers
39 * The IA write to IPC_CMD command register triggers an interrupt to the ARC,
40 * The ARC handles the interrupt and services it, writing optional data to
41 * the IPC1 registers, updates the IPC_STS response register with the status.
42 */
43#define IPC_CMD 0x0
44#define IPC_CMD_MSI 0x100
45#define IPC_CMD_SIZE 16
46#define IPC_CMD_SUBCMD 12
47#define IPC_STATUS 0x04
48#define IPC_STATUS_IRQ 0x4
49#define IPC_STATUS_ERR 0x2
50#define IPC_STATUS_BUSY 0x1
51#define IPC_SPTR 0x08
52#define IPC_DPTR 0x0C
53#define IPC_WRITE_BUFFER 0x80
54#define IPC_READ_BUFFER 0x90
55
Shanth Murthy76062b42017-02-13 04:02:52 -080056/* Residency with clock rate at 19.2MHz to usecs */
57#define S0IX_RESIDENCY_IN_USECS(d, s) \
58({ \
59 u64 result = 10ull * ((d) + (s)); \
60 do_div(result, 192); \
61 result; \
62})
63
qipeng.zha0a8b8352015-06-27 00:32:15 +080064/*
65 * 16-byte buffer for sending data associated with IPC command.
66 */
67#define IPC_DATA_BUFFER_SIZE 16
68
69#define IPC_LOOP_CNT 3000000
70#define IPC_MAX_SEC 3
71
72#define IPC_TRIGGER_MODE_IRQ true
73
74/* exported resources from IFWI */
75#define PLAT_RESOURCE_IPC_INDEX 0
76#define PLAT_RESOURCE_IPC_SIZE 0x1000
Kuppuswamy Sathyanarayanane6749c82017-04-09 15:00:16 -070077#define PLAT_RESOURCE_GCR_OFFSET 0x1000
Shanth Murthy76062b42017-02-13 04:02:52 -080078#define PLAT_RESOURCE_GCR_SIZE 0x1000
Qipeng Zha8cc7fb42015-12-11 22:44:59 +080079#define PLAT_RESOURCE_BIOS_DATA_INDEX 1
80#define PLAT_RESOURCE_BIOS_IFACE_INDEX 2
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +053081#define PLAT_RESOURCE_TELEM_SSRAM_INDEX 3
Qipeng Zha8cc7fb42015-12-11 22:44:59 +080082#define PLAT_RESOURCE_ISP_DATA_INDEX 4
83#define PLAT_RESOURCE_ISP_IFACE_INDEX 5
84#define PLAT_RESOURCE_GTD_DATA_INDEX 6
85#define PLAT_RESOURCE_GTD_IFACE_INDEX 7
qipeng.zha0a8b8352015-06-27 00:32:15 +080086#define PLAT_RESOURCE_ACPI_IO_INDEX 0
87
88/*
89 * BIOS does not create an ACPI device for each PMC function,
90 * but exports multiple resources from one ACPI device(IPC) for
91 * multiple functions. This driver is responsible to create a
92 * platform device and to export resources for those functions.
93 */
94#define TCO_DEVICE_NAME "iTCO_wdt"
Yong, Jonathan334da2d2016-06-17 00:33:32 +000095#define SMI_EN_OFFSET 0x40
qipeng.zha0a8b8352015-06-27 00:32:15 +080096#define SMI_EN_SIZE 4
97#define TCO_BASE_OFFSET 0x60
98#define TCO_REGS_SIZE 16
99#define PUNIT_DEVICE_NAME "intel_punit_ipc"
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530100#define TELEMETRY_DEVICE_NAME "intel_telemetry"
101#define TELEM_SSRAM_SIZE 240
102#define TELEM_PMC_SSRAM_OFFSET 0x1B00
103#define TELEM_PUNIT_SSRAM_OFFSET 0x1A00
Yong, Jonathan334da2d2016-06-17 00:33:32 +0000104#define TCO_PMC_OFFSET 0x8
105#define TCO_PMC_SIZE 0x4
qipeng.zha0a8b8352015-06-27 00:32:15 +0800106
Kuppuswamy Sathyanarayanan9d855d42017-04-09 15:00:20 -0700107/* PMC register bit definitions */
108
109/* PMC_CFG_REG bit masks */
110#define PMC_CFG_NO_REBOOT_MASK (1 << 4)
111#define PMC_CFG_NO_REBOOT_EN (1 << 4)
112#define PMC_CFG_NO_REBOOT_DIS (0 << 4)
113
qipeng.zha0a8b8352015-06-27 00:32:15 +0800114static struct intel_pmc_ipc_dev {
115 struct device *dev;
116 void __iomem *ipc_base;
117 bool irq_mode;
118 int irq;
119 int cmd;
120 struct completion cmd_complete;
121
122 /* The following PMC BARs share the same ACPI device with the IPC */
qipeng.zhab78fb512015-07-07 00:04:45 +0800123 resource_size_t acpi_io_base;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800124 int acpi_io_size;
125 struct platform_device *tco_dev;
126
127 /* gcr */
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700128 void __iomem *gcr_mem_base;
Shanth Murthy76062b42017-02-13 04:02:52 -0800129 bool has_gcr_regs;
Kuppuswamy Sathyanarayanan6687aeb2017-10-07 15:19:51 -0700130 spinlock_t gcr_lock;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800131
132 /* punit */
qipeng.zha0a8b8352015-06-27 00:32:15 +0800133 struct platform_device *punit_dev;
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530134
135 /* Telemetry */
136 resource_size_t telem_pmc_ssram_base;
137 resource_size_t telem_punit_ssram_base;
138 int telem_pmc_ssram_size;
139 int telem_punit_ssram_size;
140 u8 telem_res_inval;
141 struct platform_device *telemetry_dev;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800142} ipcdev;
143
144static char *ipc_err_sources[] = {
145 [IPC_ERR_NONE] =
146 "no error",
147 [IPC_ERR_CMD_NOT_SUPPORTED] =
148 "command not supported",
149 [IPC_ERR_CMD_NOT_SERVICED] =
150 "command not serviced",
151 [IPC_ERR_UNABLE_TO_SERVICE] =
152 "unable to service",
153 [IPC_ERR_CMD_INVALID] =
154 "command invalid",
155 [IPC_ERR_CMD_FAILED] =
156 "command failed",
157 [IPC_ERR_EMSECURITY] =
158 "Invalid Battery",
159 [IPC_ERR_UNSIGNEDKERNEL] =
160 "Unsigned kernel",
161};
162
163/* Prevent concurrent calls to the PMC */
164static DEFINE_MUTEX(ipclock);
165
166static inline void ipc_send_command(u32 cmd)
167{
168 ipcdev.cmd = cmd;
169 if (ipcdev.irq_mode) {
170 reinit_completion(&ipcdev.cmd_complete);
171 cmd |= IPC_CMD_MSI;
172 }
173 writel(cmd, ipcdev.ipc_base + IPC_CMD);
174}
175
176static inline u32 ipc_read_status(void)
177{
178 return readl(ipcdev.ipc_base + IPC_STATUS);
179}
180
181static inline void ipc_data_writel(u32 data, u32 offset)
182{
183 writel(data, ipcdev.ipc_base + IPC_WRITE_BUFFER + offset);
184}
185
Matthias Kaehlcke6bee1af2017-05-25 15:15:10 -0700186static inline u8 __maybe_unused ipc_data_readb(u32 offset)
qipeng.zha0a8b8352015-06-27 00:32:15 +0800187{
188 return readb(ipcdev.ipc_base + IPC_READ_BUFFER + offset);
189}
190
191static inline u32 ipc_data_readl(u32 offset)
192{
193 return readl(ipcdev.ipc_base + IPC_READ_BUFFER + offset);
194}
195
Shanth Murthy76062b42017-02-13 04:02:52 -0800196static inline u64 gcr_data_readq(u32 offset)
197{
Kuppuswamy Sathyanarayanan62a7b9c2017-04-09 15:00:21 -0700198 return readq(ipcdev.gcr_mem_base + offset);
Shanth Murthy76062b42017-02-13 04:02:52 -0800199}
200
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700201static inline int is_gcr_valid(u32 offset)
202{
203 if (!ipcdev.has_gcr_regs)
204 return -EACCES;
205
206 if (offset > PLAT_RESOURCE_GCR_SIZE)
207 return -EINVAL;
208
209 return 0;
210}
211
212/**
Chakravarty, Souvik K9c916542017-11-24 19:04:41 +0530213 * intel_pmc_gcr_read() - Read a 32-bit PMC GCR register
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700214 * @offset: offset of GCR register from GCR address base
215 * @data: data pointer for storing the register output
216 *
Chakravarty, Souvik K9c916542017-11-24 19:04:41 +0530217 * Reads the 32-bit PMC GCR register at given offset.
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700218 *
219 * Return: negative value on error or 0 on success.
220 */
221int intel_pmc_gcr_read(u32 offset, u32 *data)
222{
223 int ret;
224
Kuppuswamy Sathyanarayanan6687aeb2017-10-07 15:19:51 -0700225 spin_lock(&ipcdev.gcr_lock);
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700226
227 ret = is_gcr_valid(offset);
228 if (ret < 0) {
Kuppuswamy Sathyanarayanan6687aeb2017-10-07 15:19:51 -0700229 spin_unlock(&ipcdev.gcr_lock);
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700230 return ret;
231 }
232
233 *data = readl(ipcdev.gcr_mem_base + offset);
234
Kuppuswamy Sathyanarayanan6687aeb2017-10-07 15:19:51 -0700235 spin_unlock(&ipcdev.gcr_lock);
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700236
237 return 0;
238}
239EXPORT_SYMBOL_GPL(intel_pmc_gcr_read);
240
241/**
Chakravarty, Souvik K9c916542017-11-24 19:04:41 +0530242 * intel_pmc_gcr_read64() - Read a 64-bit PMC GCR register
243 * @offset: offset of GCR register from GCR address base
244 * @data: data pointer for storing the register output
245 *
246 * Reads the 64-bit PMC GCR register at given offset.
247 *
248 * Return: negative value on error or 0 on success.
249 */
250int intel_pmc_gcr_read64(u32 offset, u64 *data)
251{
252 int ret;
253
254 spin_lock(&ipcdev.gcr_lock);
255
256 ret = is_gcr_valid(offset);
257 if (ret < 0) {
258 spin_unlock(&ipcdev.gcr_lock);
259 return ret;
260 }
261
262 *data = readq(ipcdev.gcr_mem_base + offset);
263
264 spin_unlock(&ipcdev.gcr_lock);
265
266 return 0;
267}
268EXPORT_SYMBOL_GPL(intel_pmc_gcr_read64);
269
270/**
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700271 * intel_pmc_gcr_write() - Write PMC GCR register
272 * @offset: offset of GCR register from GCR address base
273 * @data: register update value
274 *
275 * Writes the PMC GCR register of given offset with given
276 * value.
277 *
278 * Return: negative value on error or 0 on success.
279 */
280int intel_pmc_gcr_write(u32 offset, u32 data)
281{
282 int ret;
283
Kuppuswamy Sathyanarayanan6687aeb2017-10-07 15:19:51 -0700284 spin_lock(&ipcdev.gcr_lock);
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700285
286 ret = is_gcr_valid(offset);
287 if (ret < 0) {
Kuppuswamy Sathyanarayanan6687aeb2017-10-07 15:19:51 -0700288 spin_unlock(&ipcdev.gcr_lock);
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700289 return ret;
290 }
291
292 writel(data, ipcdev.gcr_mem_base + offset);
293
Kuppuswamy Sathyanarayanan6687aeb2017-10-07 15:19:51 -0700294 spin_unlock(&ipcdev.gcr_lock);
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700295
296 return 0;
297}
298EXPORT_SYMBOL_GPL(intel_pmc_gcr_write);
299
300/**
301 * intel_pmc_gcr_update() - Update PMC GCR register bits
302 * @offset: offset of GCR register from GCR address base
303 * @mask: bit mask for update operation
304 * @val: update value
305 *
306 * Updates the bits of given GCR register as specified by
307 * @mask and @val.
308 *
309 * Return: negative value on error or 0 on success.
310 */
311int intel_pmc_gcr_update(u32 offset, u32 mask, u32 val)
312{
313 u32 new_val;
314 int ret = 0;
315
Kuppuswamy Sathyanarayanan6687aeb2017-10-07 15:19:51 -0700316 spin_lock(&ipcdev.gcr_lock);
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700317
318 ret = is_gcr_valid(offset);
319 if (ret < 0)
320 goto gcr_ipc_unlock;
321
322 new_val = readl(ipcdev.gcr_mem_base + offset);
323
324 new_val &= ~mask;
325 new_val |= val & mask;
326
327 writel(new_val, ipcdev.gcr_mem_base + offset);
328
329 new_val = readl(ipcdev.gcr_mem_base + offset);
330
331 /* check whether the bit update is successful */
332 if ((new_val & mask) != (val & mask)) {
333 ret = -EIO;
334 goto gcr_ipc_unlock;
335 }
336
337gcr_ipc_unlock:
Kuppuswamy Sathyanarayanan6687aeb2017-10-07 15:19:51 -0700338 spin_unlock(&ipcdev.gcr_lock);
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700339 return ret;
340}
341EXPORT_SYMBOL_GPL(intel_pmc_gcr_update);
342
Kuppuswamy Sathyanarayanan9d855d42017-04-09 15:00:20 -0700343static int update_no_reboot_bit(void *priv, bool set)
344{
345 u32 value = set ? PMC_CFG_NO_REBOOT_EN : PMC_CFG_NO_REBOOT_DIS;
346
347 return intel_pmc_gcr_update(PMC_GCR_PMC_CFG_REG,
348 PMC_CFG_NO_REBOOT_MASK, value);
349}
350
qipeng.zha0a8b8352015-06-27 00:32:15 +0800351static int intel_pmc_ipc_check_status(void)
352{
353 int status;
354 int ret = 0;
355
356 if (ipcdev.irq_mode) {
357 if (0 == wait_for_completion_timeout(
358 &ipcdev.cmd_complete, IPC_MAX_SEC * HZ))
359 ret = -ETIMEDOUT;
360 } else {
361 int loop_count = IPC_LOOP_CNT;
362
363 while ((ipc_read_status() & IPC_STATUS_BUSY) && --loop_count)
364 udelay(1);
365 if (loop_count == 0)
366 ret = -ETIMEDOUT;
367 }
368
369 status = ipc_read_status();
370 if (ret == -ETIMEDOUT) {
371 dev_err(ipcdev.dev,
372 "IPC timed out, TS=0x%x, CMD=0x%x\n",
373 status, ipcdev.cmd);
374 return ret;
375 }
376
377 if (status & IPC_STATUS_ERR) {
378 int i;
379
380 ret = -EIO;
381 i = (status >> IPC_CMD_SIZE) & 0xFF;
382 if (i < ARRAY_SIZE(ipc_err_sources))
383 dev_err(ipcdev.dev,
384 "IPC failed: %s, STS=0x%x, CMD=0x%x\n",
385 ipc_err_sources[i], status, ipcdev.cmd);
386 else
387 dev_err(ipcdev.dev,
388 "IPC failed: unknown, STS=0x%x, CMD=0x%x\n",
389 status, ipcdev.cmd);
390 if ((i == IPC_ERR_UNSIGNEDKERNEL) || (i == IPC_ERR_EMSECURITY))
391 ret = -EACCES;
392 }
393
394 return ret;
395}
396
qipeng.zha02941002015-07-09 00:14:15 +0800397/**
398 * intel_pmc_ipc_simple_command() - Simple IPC command
399 * @cmd: IPC command code.
400 * @sub: IPC command sub type.
401 *
402 * Send a simple IPC command to PMC when don't need to specify
403 * input/output data and source/dest pointers.
404 *
405 * Return: an IPC error code or 0 on success.
qipeng.zha0a8b8352015-06-27 00:32:15 +0800406 */
407int intel_pmc_ipc_simple_command(int cmd, int sub)
408{
409 int ret;
410
411 mutex_lock(&ipclock);
412 if (ipcdev.dev == NULL) {
413 mutex_unlock(&ipclock);
414 return -ENODEV;
415 }
416 ipc_send_command(sub << IPC_CMD_SUBCMD | cmd);
417 ret = intel_pmc_ipc_check_status();
418 mutex_unlock(&ipclock);
419
420 return ret;
421}
422EXPORT_SYMBOL_GPL(intel_pmc_ipc_simple_command);
423
qipeng.zha02941002015-07-09 00:14:15 +0800424/**
425 * intel_pmc_ipc_raw_cmd() - IPC command with data and pointers
426 * @cmd: IPC command code.
427 * @sub: IPC command sub type.
428 * @in: input data of this IPC command.
429 * @inlen: input data length in bytes.
430 * @out: output data of this IPC command.
431 * @outlen: output data length in dwords.
432 * @sptr: data writing to SPTR register.
433 * @dptr: data writing to DPTR register.
434 *
435 * Send an IPC command to PMC with input/output data and source/dest pointers.
436 *
437 * Return: an IPC error code or 0 on success.
qipeng.zha0a8b8352015-06-27 00:32:15 +0800438 */
439int intel_pmc_ipc_raw_cmd(u32 cmd, u32 sub, u8 *in, u32 inlen, u32 *out,
440 u32 outlen, u32 dptr, u32 sptr)
441{
442 u32 wbuf[4] = { 0 };
443 int ret;
444 int i;
445
446 if (inlen > IPC_DATA_BUFFER_SIZE || outlen > IPC_DATA_BUFFER_SIZE / 4)
447 return -EINVAL;
448
449 mutex_lock(&ipclock);
450 if (ipcdev.dev == NULL) {
451 mutex_unlock(&ipclock);
452 return -ENODEV;
453 }
454 memcpy(wbuf, in, inlen);
455 writel(dptr, ipcdev.ipc_base + IPC_DPTR);
456 writel(sptr, ipcdev.ipc_base + IPC_SPTR);
457 /* The input data register is 32bit register and inlen is in Byte */
458 for (i = 0; i < ((inlen + 3) / 4); i++)
459 ipc_data_writel(wbuf[i], 4 * i);
460 ipc_send_command((inlen << IPC_CMD_SIZE) |
461 (sub << IPC_CMD_SUBCMD) | cmd);
462 ret = intel_pmc_ipc_check_status();
463 if (!ret) {
464 /* out is read from 32bit register and outlen is in 32bit */
465 for (i = 0; i < outlen; i++)
466 *out++ = ipc_data_readl(4 * i);
467 }
468 mutex_unlock(&ipclock);
469
470 return ret;
471}
472EXPORT_SYMBOL_GPL(intel_pmc_ipc_raw_cmd);
473
qipeng.zha02941002015-07-09 00:14:15 +0800474/**
475 * intel_pmc_ipc_command() - IPC command with input/output data
476 * @cmd: IPC command code.
477 * @sub: IPC command sub type.
478 * @in: input data of this IPC command.
479 * @inlen: input data length in bytes.
480 * @out: output data of this IPC command.
481 * @outlen: output data length in dwords.
482 *
483 * Send an IPC command to PMC with input/output data.
484 *
485 * Return: an IPC error code or 0 on success.
qipeng.zha0a8b8352015-06-27 00:32:15 +0800486 */
487int intel_pmc_ipc_command(u32 cmd, u32 sub, u8 *in, u32 inlen,
488 u32 *out, u32 outlen)
489{
490 return intel_pmc_ipc_raw_cmd(cmd, sub, in, inlen, out, outlen, 0, 0);
491}
492EXPORT_SYMBOL_GPL(intel_pmc_ipc_command);
493
494static irqreturn_t ioc(int irq, void *dev_id)
495{
496 int status;
497
498 if (ipcdev.irq_mode) {
499 status = ipc_read_status();
500 writel(status | IPC_STATUS_IRQ, ipcdev.ipc_base + IPC_STATUS);
501 }
502 complete(&ipcdev.cmd_complete);
503
504 return IRQ_HANDLED;
505}
506
507static int ipc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
508{
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700509 struct intel_pmc_ipc_dev *pmc = &ipcdev;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800510 int ret;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800511
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700512 /* Only one PMC is supported */
513 if (pmc->dev)
qipeng.zha0a8b8352015-06-27 00:32:15 +0800514 return -EBUSY;
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700515
516 pmc->irq_mode = IPC_TRIGGER_MODE_IRQ;
517
Kuppuswamy Sathyanarayanan6687aeb2017-10-07 15:19:51 -0700518 spin_lock_init(&ipcdev.gcr_lock);
519
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700520 ret = pcim_enable_device(pdev);
521 if (ret)
522 return ret;
523
524 ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
525 if (ret)
526 return ret;
527
528 init_completion(&pmc->cmd_complete);
529
530 pmc->ipc_base = pcim_iomap_table(pdev)[0];
531
532 ret = devm_request_irq(&pdev->dev, pdev->irq, ioc, 0, "intel_pmc_ipc",
533 pmc);
534 if (ret) {
535 dev_err(&pdev->dev, "Failed to request irq\n");
536 return ret;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800537 }
538
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700539 pmc->dev = &pdev->dev;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800540
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700541 pci_set_drvdata(pdev, pmc);
qipeng.zha0a8b8352015-06-27 00:32:15 +0800542
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700543 return 0;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800544}
545
546static const struct pci_device_id ipc_pci_ids[] = {
547 {PCI_VDEVICE(INTEL, 0x0a94), 0},
548 {PCI_VDEVICE(INTEL, 0x1a94), 0},
Rajneesh Bhardwaj23e775d2017-02-13 16:11:47 +0530549 {PCI_VDEVICE(INTEL, 0x5a94), 0},
qipeng.zha0a8b8352015-06-27 00:32:15 +0800550 { 0,}
551};
552MODULE_DEVICE_TABLE(pci, ipc_pci_ids);
553
554static struct pci_driver ipc_pci_driver = {
555 .name = "intel_pmc_ipc",
556 .id_table = ipc_pci_ids,
557 .probe = ipc_pci_probe,
qipeng.zha0a8b8352015-06-27 00:32:15 +0800558};
559
560static ssize_t intel_pmc_ipc_simple_cmd_store(struct device *dev,
561 struct device_attribute *attr,
562 const char *buf, size_t count)
563{
564 int subcmd;
565 int cmd;
566 int ret;
567
568 ret = sscanf(buf, "%d %d", &cmd, &subcmd);
569 if (ret != 2) {
570 dev_err(dev, "Error args\n");
571 return -EINVAL;
572 }
573
574 ret = intel_pmc_ipc_simple_command(cmd, subcmd);
575 if (ret) {
576 dev_err(dev, "command %d error with %d\n", cmd, ret);
577 return ret;
578 }
579 return (ssize_t)count;
580}
581
582static ssize_t intel_pmc_ipc_northpeak_store(struct device *dev,
583 struct device_attribute *attr,
584 const char *buf, size_t count)
585{
586 unsigned long val;
587 int subcmd;
588 int ret;
589
590 if (kstrtoul(buf, 0, &val))
591 return -EINVAL;
592
593 if (val)
594 subcmd = 1;
595 else
596 subcmd = 0;
597 ret = intel_pmc_ipc_simple_command(PMC_IPC_NORTHPEAK_CTRL, subcmd);
598 if (ret) {
599 dev_err(dev, "command north %d error with %d\n", subcmd, ret);
600 return ret;
601 }
602 return (ssize_t)count;
603}
604
605static DEVICE_ATTR(simplecmd, S_IWUSR,
606 NULL, intel_pmc_ipc_simple_cmd_store);
607static DEVICE_ATTR(northpeak, S_IWUSR,
608 NULL, intel_pmc_ipc_northpeak_store);
609
610static struct attribute *intel_ipc_attrs[] = {
611 &dev_attr_northpeak.attr,
612 &dev_attr_simplecmd.attr,
613 NULL
614};
615
616static const struct attribute_group intel_ipc_group = {
617 .attrs = intel_ipc_attrs,
618};
619
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800620static struct resource punit_res_array[] = {
621 /* Punit BIOS */
622 {
623 .flags = IORESOURCE_MEM,
624 },
625 {
626 .flags = IORESOURCE_MEM,
627 },
628 /* Punit ISP */
629 {
630 .flags = IORESOURCE_MEM,
631 },
632 {
633 .flags = IORESOURCE_MEM,
634 },
635 /* Punit GTD */
qipeng.zha0a8b8352015-06-27 00:32:15 +0800636 {
637 .flags = IORESOURCE_MEM,
638 },
639 {
640 .flags = IORESOURCE_MEM,
641 },
642};
643
644#define TCO_RESOURCE_ACPI_IO 0
645#define TCO_RESOURCE_SMI_EN_IO 1
646#define TCO_RESOURCE_GCR_MEM 2
647static struct resource tco_res[] = {
648 /* ACPI - TCO */
649 {
650 .flags = IORESOURCE_IO,
651 },
652 /* ACPI - SMI */
653 {
654 .flags = IORESOURCE_IO,
655 },
qipeng.zha0a8b8352015-06-27 00:32:15 +0800656};
657
Matt Fleming420b54d2015-08-06 13:46:24 +0100658static struct itco_wdt_platform_data tco_info = {
qipeng.zha0a8b8352015-06-27 00:32:15 +0800659 .name = "Apollo Lake SoC",
Yong, Jonathan334da2d2016-06-17 00:33:32 +0000660 .version = 5,
Kuppuswamy Sathyanarayanan9d855d42017-04-09 15:00:20 -0700661 .no_reboot_priv = &ipcdev,
662 .update_no_reboot_bit = update_no_reboot_bit,
qipeng.zha0a8b8352015-06-27 00:32:15 +0800663};
664
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530665#define TELEMETRY_RESOURCE_PUNIT_SSRAM 0
666#define TELEMETRY_RESOURCE_PMC_SSRAM 1
667static struct resource telemetry_res[] = {
668 /*Telemetry*/
669 {
670 .flags = IORESOURCE_MEM,
671 },
672 {
673 .flags = IORESOURCE_MEM,
674 },
675};
676
qipeng.zha0a8b8352015-06-27 00:32:15 +0800677static int ipc_create_punit_device(void)
678{
679 struct platform_device *pdev;
Axel Linea1a76b2016-09-24 11:54:08 +0800680 const struct platform_device_info pdevinfo = {
681 .parent = ipcdev.dev,
682 .name = PUNIT_DEVICE_NAME,
683 .id = -1,
684 .res = punit_res_array,
685 .num_res = ARRAY_SIZE(punit_res_array),
686 };
qipeng.zha0a8b8352015-06-27 00:32:15 +0800687
Axel Linea1a76b2016-09-24 11:54:08 +0800688 pdev = platform_device_register_full(&pdevinfo);
689 if (IS_ERR(pdev))
690 return PTR_ERR(pdev);
qipeng.zha0a8b8352015-06-27 00:32:15 +0800691
qipeng.zha0a8b8352015-06-27 00:32:15 +0800692 ipcdev.punit_dev = pdev;
693
694 return 0;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800695}
696
697static int ipc_create_tco_device(void)
698{
699 struct platform_device *pdev;
700 struct resource *res;
Axel Linea1a76b2016-09-24 11:54:08 +0800701 const struct platform_device_info pdevinfo = {
702 .parent = ipcdev.dev,
703 .name = TCO_DEVICE_NAME,
704 .id = -1,
705 .res = tco_res,
706 .num_res = ARRAY_SIZE(tco_res),
707 .data = &tco_info,
708 .size_data = sizeof(tco_info),
709 };
qipeng.zha0a8b8352015-06-27 00:32:15 +0800710
711 res = tco_res + TCO_RESOURCE_ACPI_IO;
qipeng.zhab78fb512015-07-07 00:04:45 +0800712 res->start = ipcdev.acpi_io_base + TCO_BASE_OFFSET;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800713 res->end = res->start + TCO_REGS_SIZE - 1;
714
715 res = tco_res + TCO_RESOURCE_SMI_EN_IO;
qipeng.zhab78fb512015-07-07 00:04:45 +0800716 res->start = ipcdev.acpi_io_base + SMI_EN_OFFSET;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800717 res->end = res->start + SMI_EN_SIZE - 1;
718
Axel Linea1a76b2016-09-24 11:54:08 +0800719 pdev = platform_device_register_full(&pdevinfo);
720 if (IS_ERR(pdev))
721 return PTR_ERR(pdev);
qipeng.zha0a8b8352015-06-27 00:32:15 +0800722
qipeng.zha0a8b8352015-06-27 00:32:15 +0800723 ipcdev.tco_dev = pdev;
724
725 return 0;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800726}
727
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530728static int ipc_create_telemetry_device(void)
729{
730 struct platform_device *pdev;
731 struct resource *res;
Axel Linea1a76b2016-09-24 11:54:08 +0800732 const struct platform_device_info pdevinfo = {
733 .parent = ipcdev.dev,
734 .name = TELEMETRY_DEVICE_NAME,
735 .id = -1,
736 .res = telemetry_res,
737 .num_res = ARRAY_SIZE(telemetry_res),
738 };
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530739
740 res = telemetry_res + TELEMETRY_RESOURCE_PUNIT_SSRAM;
741 res->start = ipcdev.telem_punit_ssram_base;
742 res->end = res->start + ipcdev.telem_punit_ssram_size - 1;
743
744 res = telemetry_res + TELEMETRY_RESOURCE_PMC_SSRAM;
745 res->start = ipcdev.telem_pmc_ssram_base;
746 res->end = res->start + ipcdev.telem_pmc_ssram_size - 1;
747
Axel Linea1a76b2016-09-24 11:54:08 +0800748 pdev = platform_device_register_full(&pdevinfo);
749 if (IS_ERR(pdev))
750 return PTR_ERR(pdev);
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530751
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530752 ipcdev.telemetry_dev = pdev;
753
754 return 0;
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530755}
756
qipeng.zha0a8b8352015-06-27 00:32:15 +0800757static int ipc_create_pmc_devices(void)
758{
759 int ret;
760
Mika Westerbergbba65292016-09-20 15:30:54 +0300761 /* If we have ACPI based watchdog use that instead */
762 if (!acpi_has_watchdog()) {
763 ret = ipc_create_tco_device();
764 if (ret) {
765 dev_err(ipcdev.dev, "Failed to add tco platform device\n");
766 return ret;
767 }
qipeng.zha0a8b8352015-06-27 00:32:15 +0800768 }
Mika Westerbergbba65292016-09-20 15:30:54 +0300769
qipeng.zha0a8b8352015-06-27 00:32:15 +0800770 ret = ipc_create_punit_device();
771 if (ret) {
772 dev_err(ipcdev.dev, "Failed to add punit platform device\n");
773 platform_device_unregister(ipcdev.tco_dev);
Junxiao Change61985d2019-04-08 17:40:22 +0800774 return ret;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800775 }
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530776
777 if (!ipcdev.telem_res_inval) {
778 ret = ipc_create_telemetry_device();
Junxiao Change61985d2019-04-08 17:40:22 +0800779 if (ret) {
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530780 dev_warn(ipcdev.dev,
781 "Failed to add telemetry platform device\n");
Junxiao Change61985d2019-04-08 17:40:22 +0800782 platform_device_unregister(ipcdev.punit_dev);
783 platform_device_unregister(ipcdev.tco_dev);
784 }
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530785 }
786
qipeng.zha0a8b8352015-06-27 00:32:15 +0800787 return ret;
788}
789
790static int ipc_plat_get_res(struct platform_device *pdev)
791{
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800792 struct resource *res, *punit_res;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800793 void __iomem *addr;
794 int size;
795
796 res = platform_get_resource(pdev, IORESOURCE_IO,
797 PLAT_RESOURCE_ACPI_IO_INDEX);
798 if (!res) {
799 dev_err(&pdev->dev, "Failed to get io resource\n");
800 return -ENXIO;
801 }
802 size = resource_size(res);
qipeng.zhab78fb512015-07-07 00:04:45 +0800803 ipcdev.acpi_io_base = res->start;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800804 ipcdev.acpi_io_size = size;
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800805 dev_info(&pdev->dev, "io res: %pR\n", res);
qipeng.zha0a8b8352015-06-27 00:32:15 +0800806
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800807 punit_res = punit_res_array;
Aubrey Li5d071632016-03-31 14:28:09 -0500808 /* This is index 0 to cover BIOS data register */
qipeng.zha0a8b8352015-06-27 00:32:15 +0800809 res = platform_get_resource(pdev, IORESOURCE_MEM,
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800810 PLAT_RESOURCE_BIOS_DATA_INDEX);
qipeng.zha0a8b8352015-06-27 00:32:15 +0800811 if (!res) {
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800812 dev_err(&pdev->dev, "Failed to get res of punit BIOS data\n");
qipeng.zha0a8b8352015-06-27 00:32:15 +0800813 return -ENXIO;
814 }
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800815 *punit_res = *res;
816 dev_info(&pdev->dev, "punit BIOS data res: %pR\n", res);
qipeng.zha0a8b8352015-06-27 00:32:15 +0800817
Aubrey Li5d071632016-03-31 14:28:09 -0500818 /* This is index 1 to cover BIOS interface register */
qipeng.zha0a8b8352015-06-27 00:32:15 +0800819 res = platform_get_resource(pdev, IORESOURCE_MEM,
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800820 PLAT_RESOURCE_BIOS_IFACE_INDEX);
qipeng.zha0a8b8352015-06-27 00:32:15 +0800821 if (!res) {
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800822 dev_err(&pdev->dev, "Failed to get res of punit BIOS iface\n");
qipeng.zha0a8b8352015-06-27 00:32:15 +0800823 return -ENXIO;
824 }
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800825 *++punit_res = *res;
826 dev_info(&pdev->dev, "punit BIOS interface res: %pR\n", res);
827
Aubrey Li5d071632016-03-31 14:28:09 -0500828 /* This is index 2 to cover ISP data register, optional */
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800829 res = platform_get_resource(pdev, IORESOURCE_MEM,
830 PLAT_RESOURCE_ISP_DATA_INDEX);
Aubrey Li5d071632016-03-31 14:28:09 -0500831 ++punit_res;
832 if (res) {
833 *punit_res = *res;
834 dev_info(&pdev->dev, "punit ISP data res: %pR\n", res);
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800835 }
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800836
Aubrey Li5d071632016-03-31 14:28:09 -0500837 /* This is index 3 to cover ISP interface register, optional */
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800838 res = platform_get_resource(pdev, IORESOURCE_MEM,
839 PLAT_RESOURCE_ISP_IFACE_INDEX);
Aubrey Li5d071632016-03-31 14:28:09 -0500840 ++punit_res;
841 if (res) {
842 *punit_res = *res;
843 dev_info(&pdev->dev, "punit ISP interface res: %pR\n", res);
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800844 }
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800845
Aubrey Li5d071632016-03-31 14:28:09 -0500846 /* This is index 4 to cover GTD data register, optional */
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800847 res = platform_get_resource(pdev, IORESOURCE_MEM,
848 PLAT_RESOURCE_GTD_DATA_INDEX);
Aubrey Li5d071632016-03-31 14:28:09 -0500849 ++punit_res;
850 if (res) {
851 *punit_res = *res;
852 dev_info(&pdev->dev, "punit GTD data res: %pR\n", res);
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800853 }
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800854
Aubrey Li5d071632016-03-31 14:28:09 -0500855 /* This is index 5 to cover GTD interface register, optional */
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800856 res = platform_get_resource(pdev, IORESOURCE_MEM,
857 PLAT_RESOURCE_GTD_IFACE_INDEX);
Aubrey Li5d071632016-03-31 14:28:09 -0500858 ++punit_res;
859 if (res) {
860 *punit_res = *res;
861 dev_info(&pdev->dev, "punit GTD interface res: %pR\n", res);
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800862 }
qipeng.zha0a8b8352015-06-27 00:32:15 +0800863
864 res = platform_get_resource(pdev, IORESOURCE_MEM,
865 PLAT_RESOURCE_IPC_INDEX);
866 if (!res) {
867 dev_err(&pdev->dev, "Failed to get ipc resource\n");
868 return -ENXIO;
869 }
Shanth Murthy76062b42017-02-13 04:02:52 -0800870 size = PLAT_RESOURCE_IPC_SIZE + PLAT_RESOURCE_GCR_SIZE;
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700871 res->end = res->start + size - 1;
Shanth Murthy76062b42017-02-13 04:02:52 -0800872
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700873 addr = devm_ioremap_resource(&pdev->dev, res);
874 if (IS_ERR(addr))
875 return PTR_ERR(addr);
876
qipeng.zha0a8b8352015-06-27 00:32:15 +0800877 ipcdev.ipc_base = addr;
878
Kuppuswamy Sathyanarayanan49670202017-04-09 15:00:17 -0700879 ipcdev.gcr_mem_base = addr + PLAT_RESOURCE_GCR_OFFSET;
Qipeng Zha8cc7fb42015-12-11 22:44:59 +0800880 dev_info(&pdev->dev, "ipc res: %pR\n", res);
qipeng.zha0a8b8352015-06-27 00:32:15 +0800881
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530882 ipcdev.telem_res_inval = 0;
883 res = platform_get_resource(pdev, IORESOURCE_MEM,
884 PLAT_RESOURCE_TELEM_SSRAM_INDEX);
885 if (!res) {
886 dev_err(&pdev->dev, "Failed to get telemetry ssram resource\n");
887 ipcdev.telem_res_inval = 1;
888 } else {
889 ipcdev.telem_punit_ssram_base = res->start +
890 TELEM_PUNIT_SSRAM_OFFSET;
891 ipcdev.telem_punit_ssram_size = TELEM_SSRAM_SIZE;
892 ipcdev.telem_pmc_ssram_base = res->start +
893 TELEM_PMC_SSRAM_OFFSET;
894 ipcdev.telem_pmc_ssram_size = TELEM_SSRAM_SIZE;
895 dev_info(&pdev->dev, "telemetry ssram res: %pR\n", res);
896 }
897
qipeng.zha0a8b8352015-06-27 00:32:15 +0800898 return 0;
899}
900
Shanth Murthy76062b42017-02-13 04:02:52 -0800901/**
902 * intel_pmc_s0ix_counter_read() - Read S0ix residency.
903 * @data: Out param that contains current S0ix residency count.
904 *
905 * Return: an error code or 0 on success.
906 */
907int intel_pmc_s0ix_counter_read(u64 *data)
908{
909 u64 deep, shlw;
910
911 if (!ipcdev.has_gcr_regs)
912 return -EACCES;
913
Kuppuswamy Sathyanarayanan62a7b9c2017-04-09 15:00:21 -0700914 deep = gcr_data_readq(PMC_GCR_TELEM_DEEP_S0IX_REG);
915 shlw = gcr_data_readq(PMC_GCR_TELEM_SHLW_S0IX_REG);
Shanth Murthy76062b42017-02-13 04:02:52 -0800916
917 *data = S0IX_RESIDENCY_IN_USECS(deep, shlw);
918
919 return 0;
920}
921EXPORT_SYMBOL_GPL(intel_pmc_s0ix_counter_read);
922
qipeng.zha0a8b8352015-06-27 00:32:15 +0800923#ifdef CONFIG_ACPI
924static const struct acpi_device_id ipc_acpi_ids[] = {
925 { "INT34D2", 0},
926 { }
927};
928MODULE_DEVICE_TABLE(acpi, ipc_acpi_ids);
929#endif
930
931static int ipc_plat_probe(struct platform_device *pdev)
932{
qipeng.zha0a8b8352015-06-27 00:32:15 +0800933 int ret;
934
935 ipcdev.dev = &pdev->dev;
936 ipcdev.irq_mode = IPC_TRIGGER_MODE_IRQ;
937 init_completion(&ipcdev.cmd_complete);
Kuppuswamy Sathyanarayanan6687aeb2017-10-07 15:19:51 -0700938 spin_lock_init(&ipcdev.gcr_lock);
qipeng.zha0a8b8352015-06-27 00:32:15 +0800939
940 ipcdev.irq = platform_get_irq(pdev, 0);
941 if (ipcdev.irq < 0) {
942 dev_err(&pdev->dev, "Failed to get irq\n");
943 return -EINVAL;
944 }
945
946 ret = ipc_plat_get_res(pdev);
947 if (ret) {
948 dev_err(&pdev->dev, "Failed to request resource\n");
949 return ret;
950 }
951
952 ret = ipc_create_pmc_devices();
953 if (ret) {
954 dev_err(&pdev->dev, "Failed to create pmc devices\n");
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700955 return ret;
qipeng.zha0a8b8352015-06-27 00:32:15 +0800956 }
957
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700958 if (devm_request_irq(&pdev->dev, ipcdev.irq, ioc, IRQF_NO_SUSPEND,
959 "intel_pmc_ipc", &ipcdev)) {
qipeng.zha0a8b8352015-06-27 00:32:15 +0800960 dev_err(&pdev->dev, "Failed to request irq\n");
961 ret = -EBUSY;
962 goto err_irq;
963 }
964
965 ret = sysfs_create_group(&pdev->dev.kobj, &intel_ipc_group);
966 if (ret) {
967 dev_err(&pdev->dev, "Failed to create sysfs group %d\n",
968 ret);
969 goto err_sys;
970 }
971
Shanth Murthy76062b42017-02-13 04:02:52 -0800972 ipcdev.has_gcr_regs = true;
973
qipeng.zha0a8b8352015-06-27 00:32:15 +0800974 return 0;
975err_sys:
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700976 devm_free_irq(&pdev->dev, ipcdev.irq, &ipcdev);
qipeng.zha0a8b8352015-06-27 00:32:15 +0800977err_irq:
978 platform_device_unregister(ipcdev.tco_dev);
979 platform_device_unregister(ipcdev.punit_dev);
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530980 platform_device_unregister(ipcdev.telemetry_dev);
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700981
qipeng.zha0a8b8352015-06-27 00:32:15 +0800982 return ret;
983}
984
985static int ipc_plat_remove(struct platform_device *pdev)
986{
qipeng.zha0a8b8352015-06-27 00:32:15 +0800987 sysfs_remove_group(&pdev->dev.kobj, &intel_ipc_group);
Kuppuswamy Sathyanarayanan83beee5c2017-09-04 22:37:21 -0700988 devm_free_irq(&pdev->dev, ipcdev.irq, &ipcdev);
qipeng.zha0a8b8352015-06-27 00:32:15 +0800989 platform_device_unregister(ipcdev.tco_dev);
990 platform_device_unregister(ipcdev.punit_dev);
Souvik Kumar Chakravarty48c19172016-01-12 16:02:54 +0530991 platform_device_unregister(ipcdev.telemetry_dev);
qipeng.zha0a8b8352015-06-27 00:32:15 +0800992 ipcdev.dev = NULL;
993 return 0;
994}
995
996static struct platform_driver ipc_plat_driver = {
997 .remove = ipc_plat_remove,
998 .probe = ipc_plat_probe,
999 .driver = {
1000 .name = "pmc-ipc-plat",
1001 .acpi_match_table = ACPI_PTR(ipc_acpi_ids),
1002 },
1003};
1004
1005static int __init intel_pmc_ipc_init(void)
1006{
1007 int ret;
1008
1009 ret = platform_driver_register(&ipc_plat_driver);
1010 if (ret) {
1011 pr_err("Failed to register PMC ipc platform driver\n");
1012 return ret;
1013 }
1014 ret = pci_register_driver(&ipc_pci_driver);
1015 if (ret) {
1016 pr_err("Failed to register PMC ipc pci driver\n");
1017 platform_driver_unregister(&ipc_plat_driver);
1018 return ret;
1019 }
1020 return ret;
1021}
1022
1023static void __exit intel_pmc_ipc_exit(void)
1024{
1025 pci_unregister_driver(&ipc_pci_driver);
1026 platform_driver_unregister(&ipc_plat_driver);
1027}
1028
1029MODULE_AUTHOR("Zha Qipeng <qipeng.zha@intel.com>");
1030MODULE_DESCRIPTION("Intel PMC IPC driver");
Andy Shevchenkoad51f282018-09-26 18:27:40 +03001031MODULE_LICENSE("GPL v2");
qipeng.zha0a8b8352015-06-27 00:32:15 +08001032
1033/* Some modules are dependent on this, so init earlier */
1034fs_initcall(intel_pmc_ipc_init);
1035module_exit(intel_pmc_ipc_exit);