2 * intel_pmc_ipc.c: Driver for the Intel PMC IPC mechanism
4 * (C) Copyright 2014-2015 Intel Corporation
6 * This driver is based on Intel SCU IPC driver(intel_scu_opc.c) by
7 * Sreedhara DS <sreedhara.ds@intel.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; version 2
14 * PMC running in ARC processor communicates with other entity running in IA
15 * core through IPC mechanism which in turn messaging between IA core ad PMC.
18 #include <linux/module.h>
19 #include <linux/delay.h>
20 #include <linux/errno.h>
21 #include <linux/init.h>
22 #include <linux/device.h>
23 #include <linux/mfd/core.h>
25 #include <linux/pci.h>
26 #include <linux/platform_device.h>
27 #include <linux/interrupt.h>
28 #include <linux/pm_qos.h>
29 #include <linux/kernel.h>
30 #include <linux/bitops.h>
31 #include <linux/sched.h>
32 #include <linux/atomic.h>
33 #include <linux/notifier.h>
34 #include <linux/suspend.h>
35 #include <linux/acpi.h>
36 #include <linux/io-64-nonatomic-lo-hi.h>
37 #include <linux/spinlock.h>
39 #include <asm/intel_pmc_ipc.h>
41 #include <linux/platform_data/itco_wdt.h>
45 * The IA write to IPC_CMD command register triggers an interrupt to the ARC,
46 * The ARC handles the interrupt and services it, writing optional data to
47 * the IPC1 registers, updates the IPC_STS response register with the status.
50 #define IPC_CMD_MSI 0x100
51 #define IPC_CMD_SIZE 16
52 #define IPC_CMD_SUBCMD 12
53 #define IPC_STATUS 0x04
54 #define IPC_STATUS_IRQ 0x4
55 #define IPC_STATUS_ERR 0x2
56 #define IPC_STATUS_BUSY 0x1
59 #define IPC_WRITE_BUFFER 0x80
60 #define IPC_READ_BUFFER 0x90
62 /* Residency with clock rate at 19.2MHz to usecs */
63 #define S0IX_RESIDENCY_IN_USECS(d, s) \
65 u64 result = 10ull * ((d) + (s)); \
66 do_div(result, 192); \
71 * 16-byte buffer for sending data associated with IPC command.
73 #define IPC_DATA_BUFFER_SIZE 16
75 #define IPC_LOOP_CNT 3000000
78 #define IPC_TRIGGER_MODE_IRQ true
80 /* exported resources from IFWI */
81 #define PLAT_RESOURCE_IPC_INDEX 0
82 #define PLAT_RESOURCE_IPC_SIZE 0x1000
83 #define PLAT_RESOURCE_GCR_OFFSET 0x1000
84 #define PLAT_RESOURCE_GCR_SIZE 0x1000
85 #define PLAT_RESOURCE_BIOS_DATA_INDEX 1
86 #define PLAT_RESOURCE_BIOS_IFACE_INDEX 2
87 #define PLAT_RESOURCE_TELEM_SSRAM_INDEX 3
88 #define PLAT_RESOURCE_ISP_DATA_INDEX 4
89 #define PLAT_RESOURCE_ISP_IFACE_INDEX 5
90 #define PLAT_RESOURCE_GTD_DATA_INDEX 6
91 #define PLAT_RESOURCE_GTD_IFACE_INDEX 7
92 #define PLAT_RESOURCE_MEM_MAX_INDEX 8
93 #define PLAT_RESOURCE_ACPI_IO_INDEX 0
96 * BIOS does not create an ACPI device for each PMC function,
97 * but exports multiple resources from one ACPI device(IPC) for
98 * multiple functions. This driver is responsible to create a
99 * platform device and to export resources for those functions.
101 #define TCO_DEVICE_NAME "iTCO_wdt"
102 #define SMI_EN_OFFSET 0x40
103 #define SMI_EN_SIZE 4
104 #define TCO_BASE_OFFSET 0x60
105 #define TCO_REGS_SIZE 16
106 #define PUNIT_DEVICE_NAME "intel_punit_ipc"
107 #define TELEMETRY_DEVICE_NAME "intel_telemetry"
108 #define TELEM_SSRAM_SIZE 240
109 #define TELEM_PMC_SSRAM_OFFSET 0x1B00
110 #define TELEM_PUNIT_SSRAM_OFFSET 0x1A00
112 /* PMC register bit definitions */
114 /* PMC_CFG_REG bit masks */
115 #define PMC_CFG_NO_REBOOT_MASK (1 << 4)
116 #define PMC_CFG_NO_REBOOT_EN (1 << 4)
117 #define PMC_CFG_NO_REBOOT_DIS (0 << 4)
119 static struct intel_pmc_ipc_dev
{
121 void __iomem
*ipc_base
;
125 struct completion cmd_complete
;
128 void __iomem
*gcr_mem_base
;
133 static char *ipc_err_sources
[] = {
136 [IPC_ERR_CMD_NOT_SUPPORTED
] =
137 "command not supported",
138 [IPC_ERR_CMD_NOT_SERVICED
] =
139 "command not serviced",
140 [IPC_ERR_UNABLE_TO_SERVICE
] =
142 [IPC_ERR_CMD_INVALID
] =
144 [IPC_ERR_CMD_FAILED
] =
146 [IPC_ERR_EMSECURITY
] =
148 [IPC_ERR_UNSIGNEDKERNEL
] =
152 /* Prevent concurrent calls to the PMC */
153 static DEFINE_MUTEX(ipclock
);
155 static inline void ipc_send_command(u32 cmd
)
158 if (ipcdev
.irq_mode
) {
159 reinit_completion(&ipcdev
.cmd_complete
);
162 writel(cmd
, ipcdev
.ipc_base
+ IPC_CMD
);
165 static inline u32
ipc_read_status(void)
167 return readl(ipcdev
.ipc_base
+ IPC_STATUS
);
170 static inline void ipc_data_writel(u32 data
, u32 offset
)
172 writel(data
, ipcdev
.ipc_base
+ IPC_WRITE_BUFFER
+ offset
);
175 static inline u8 __maybe_unused
ipc_data_readb(u32 offset
)
177 return readb(ipcdev
.ipc_base
+ IPC_READ_BUFFER
+ offset
);
180 static inline u32
ipc_data_readl(u32 offset
)
182 return readl(ipcdev
.ipc_base
+ IPC_READ_BUFFER
+ offset
);
185 static inline u64
gcr_data_readq(u32 offset
)
187 return readq(ipcdev
.gcr_mem_base
+ offset
);
190 static inline int is_gcr_valid(u32 offset
)
192 if (!ipcdev
.has_gcr_regs
)
195 if (offset
> PLAT_RESOURCE_GCR_SIZE
)
202 * intel_pmc_gcr_read() - Read PMC GCR register
203 * @offset: offset of GCR register from GCR address base
204 * @data: data pointer for storing the register output
206 * Reads the PMC GCR register of given offset.
208 * Return: negative value on error or 0 on success.
210 int intel_pmc_gcr_read(u32 offset
, u32
*data
)
214 spin_lock(&ipcdev
.gcr_lock
);
216 ret
= is_gcr_valid(offset
);
218 spin_unlock(&ipcdev
.gcr_lock
);
222 *data
= readl(ipcdev
.gcr_mem_base
+ offset
);
224 spin_unlock(&ipcdev
.gcr_lock
);
228 EXPORT_SYMBOL_GPL(intel_pmc_gcr_read
);
231 * intel_pmc_gcr_write() - Write PMC GCR register
232 * @offset: offset of GCR register from GCR address base
233 * @data: register update value
235 * Writes the PMC GCR register of given offset with given
238 * Return: negative value on error or 0 on success.
240 int intel_pmc_gcr_write(u32 offset
, u32 data
)
244 spin_lock(&ipcdev
.gcr_lock
);
246 ret
= is_gcr_valid(offset
);
248 spin_unlock(&ipcdev
.gcr_lock
);
252 writel(data
, ipcdev
.gcr_mem_base
+ offset
);
254 spin_unlock(&ipcdev
.gcr_lock
);
258 EXPORT_SYMBOL_GPL(intel_pmc_gcr_write
);
261 * intel_pmc_gcr_update() - Update PMC GCR register bits
262 * @offset: offset of GCR register from GCR address base
263 * @mask: bit mask for update operation
266 * Updates the bits of given GCR register as specified by
269 * Return: negative value on error or 0 on success.
271 int intel_pmc_gcr_update(u32 offset
, u32 mask
, u32 val
)
276 spin_lock(&ipcdev
.gcr_lock
);
278 ret
= is_gcr_valid(offset
);
282 new_val
= readl(ipcdev
.gcr_mem_base
+ offset
);
285 new_val
|= val
& mask
;
287 writel(new_val
, ipcdev
.gcr_mem_base
+ offset
);
289 new_val
= readl(ipcdev
.gcr_mem_base
+ offset
);
291 /* check whether the bit update is successful */
292 if ((new_val
& mask
) != (val
& mask
)) {
298 spin_unlock(&ipcdev
.gcr_lock
);
301 EXPORT_SYMBOL_GPL(intel_pmc_gcr_update
);
303 static int update_no_reboot_bit(void *priv
, bool set
)
305 u32 value
= set
? PMC_CFG_NO_REBOOT_EN
: PMC_CFG_NO_REBOOT_DIS
;
307 return intel_pmc_gcr_update(PMC_GCR_PMC_CFG_REG
,
308 PMC_CFG_NO_REBOOT_MASK
, value
);
311 static int intel_pmc_ipc_check_status(void)
316 if (ipcdev
.irq_mode
) {
317 if (0 == wait_for_completion_timeout(
318 &ipcdev
.cmd_complete
, IPC_MAX_SEC
* HZ
))
321 int loop_count
= IPC_LOOP_CNT
;
323 while ((ipc_read_status() & IPC_STATUS_BUSY
) && --loop_count
)
329 status
= ipc_read_status();
330 if (ret
== -ETIMEDOUT
) {
332 "IPC timed out, TS=0x%x, CMD=0x%x\n",
337 if (status
& IPC_STATUS_ERR
) {
341 i
= (status
>> IPC_CMD_SIZE
) & 0xFF;
342 if (i
< ARRAY_SIZE(ipc_err_sources
))
344 "IPC failed: %s, STS=0x%x, CMD=0x%x\n",
345 ipc_err_sources
[i
], status
, ipcdev
.cmd
);
348 "IPC failed: unknown, STS=0x%x, CMD=0x%x\n",
350 if ((i
== IPC_ERR_UNSIGNEDKERNEL
) || (i
== IPC_ERR_EMSECURITY
))
358 * intel_pmc_ipc_simple_command() - Simple IPC command
359 * @cmd: IPC command code.
360 * @sub: IPC command sub type.
362 * Send a simple IPC command to PMC when don't need to specify
363 * input/output data and source/dest pointers.
365 * Return: an IPC error code or 0 on success.
367 int intel_pmc_ipc_simple_command(int cmd
, int sub
)
371 mutex_lock(&ipclock
);
372 if (ipcdev
.dev
== NULL
) {
373 mutex_unlock(&ipclock
);
376 ipc_send_command(sub
<< IPC_CMD_SUBCMD
| cmd
);
377 ret
= intel_pmc_ipc_check_status();
378 mutex_unlock(&ipclock
);
382 EXPORT_SYMBOL_GPL(intel_pmc_ipc_simple_command
);
385 * intel_pmc_ipc_raw_cmd() - IPC command with data and pointers
386 * @cmd: IPC command code.
387 * @sub: IPC command sub type.
388 * @in: input data of this IPC command.
389 * @inlen: input data length in bytes.
390 * @out: output data of this IPC command.
391 * @outlen: output data length in dwords.
392 * @sptr: data writing to SPTR register.
393 * @dptr: data writing to DPTR register.
395 * Send an IPC command to PMC with input/output data and source/dest pointers.
397 * Return: an IPC error code or 0 on success.
399 int intel_pmc_ipc_raw_cmd(u32 cmd
, u32 sub
, u8
*in
, u32 inlen
, u32
*out
,
400 u32 outlen
, u32 dptr
, u32 sptr
)
406 if (inlen
> IPC_DATA_BUFFER_SIZE
|| outlen
> IPC_DATA_BUFFER_SIZE
/ 4)
409 mutex_lock(&ipclock
);
410 if (ipcdev
.dev
== NULL
) {
411 mutex_unlock(&ipclock
);
414 memcpy(wbuf
, in
, inlen
);
415 writel(dptr
, ipcdev
.ipc_base
+ IPC_DPTR
);
416 writel(sptr
, ipcdev
.ipc_base
+ IPC_SPTR
);
417 /* The input data register is 32bit register and inlen is in Byte */
418 for (i
= 0; i
< ((inlen
+ 3) / 4); i
++)
419 ipc_data_writel(wbuf
[i
], 4 * i
);
420 ipc_send_command((inlen
<< IPC_CMD_SIZE
) |
421 (sub
<< IPC_CMD_SUBCMD
) | cmd
);
422 ret
= intel_pmc_ipc_check_status();
424 /* out is read from 32bit register and outlen is in 32bit */
425 for (i
= 0; i
< outlen
; i
++)
426 *out
++ = ipc_data_readl(4 * i
);
428 mutex_unlock(&ipclock
);
432 EXPORT_SYMBOL_GPL(intel_pmc_ipc_raw_cmd
);
435 * intel_pmc_ipc_command() - IPC command with input/output data
436 * @cmd: IPC command code.
437 * @sub: IPC command sub type.
438 * @in: input data of this IPC command.
439 * @inlen: input data length in bytes.
440 * @out: output data of this IPC command.
441 * @outlen: output data length in dwords.
443 * Send an IPC command to PMC with input/output data.
445 * Return: an IPC error code or 0 on success.
447 int intel_pmc_ipc_command(u32 cmd
, u32 sub
, u8
*in
, u32 inlen
,
448 u32
*out
, u32 outlen
)
450 return intel_pmc_ipc_raw_cmd(cmd
, sub
, in
, inlen
, out
, outlen
, 0, 0);
452 EXPORT_SYMBOL_GPL(intel_pmc_ipc_command
);
454 static irqreturn_t
ioc(int irq
, void *dev_id
)
458 if (ipcdev
.irq_mode
) {
459 status
= ipc_read_status();
460 writel(status
| IPC_STATUS_IRQ
, ipcdev
.ipc_base
+ IPC_STATUS
);
462 complete(&ipcdev
.cmd_complete
);
467 static int ipc_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
469 struct intel_pmc_ipc_dev
*pmc
= &ipcdev
;
472 /* Only one PMC is supported */
476 pmc
->irq_mode
= IPC_TRIGGER_MODE_IRQ
;
478 spin_lock_init(&ipcdev
.gcr_lock
);
480 ret
= pcim_enable_device(pdev
);
484 ret
= pcim_iomap_regions(pdev
, 1 << 0, pci_name(pdev
));
488 init_completion(&pmc
->cmd_complete
);
490 pmc
->ipc_base
= pcim_iomap_table(pdev
)[0];
492 ret
= devm_request_irq(&pdev
->dev
, pdev
->irq
, ioc
, 0, "intel_pmc_ipc",
495 dev_err(&pdev
->dev
, "Failed to request IRQ\n");
499 pmc
->dev
= &pdev
->dev
;
501 pci_set_drvdata(pdev
, pmc
);
506 static const struct pci_device_id ipc_pci_ids
[] = {
507 {PCI_VDEVICE(INTEL
, 0x0a94), 0},
508 {PCI_VDEVICE(INTEL
, 0x1a94), 0},
509 {PCI_VDEVICE(INTEL
, 0x5a94), 0},
512 MODULE_DEVICE_TABLE(pci
, ipc_pci_ids
);
514 static struct pci_driver ipc_pci_driver
= {
515 .name
= "intel_pmc_ipc",
516 .id_table
= ipc_pci_ids
,
517 .probe
= ipc_pci_probe
,
520 static ssize_t
intel_pmc_ipc_simple_cmd_store(struct device
*dev
,
521 struct device_attribute
*attr
,
522 const char *buf
, size_t count
)
528 ret
= sscanf(buf
, "%d %d", &cmd
, &subcmd
);
530 dev_err(dev
, "Error args\n");
534 ret
= intel_pmc_ipc_simple_command(cmd
, subcmd
);
536 dev_err(dev
, "command %d error with %d\n", cmd
, ret
);
539 return (ssize_t
)count
;
542 static ssize_t
intel_pmc_ipc_northpeak_store(struct device
*dev
,
543 struct device_attribute
*attr
,
544 const char *buf
, size_t count
)
550 if (kstrtoul(buf
, 0, &val
))
557 ret
= intel_pmc_ipc_simple_command(PMC_IPC_NORTHPEAK_CTRL
, subcmd
);
559 dev_err(dev
, "command north %d error with %d\n", subcmd
, ret
);
562 return (ssize_t
)count
;
565 static DEVICE_ATTR(simplecmd
, S_IWUSR
,
566 NULL
, intel_pmc_ipc_simple_cmd_store
);
567 static DEVICE_ATTR(northpeak
, S_IWUSR
,
568 NULL
, intel_pmc_ipc_northpeak_store
);
570 static struct attribute
*intel_ipc_attrs
[] = {
571 &dev_attr_northpeak
.attr
,
572 &dev_attr_simplecmd
.attr
,
576 static const struct attribute_group intel_ipc_group
= {
577 .attrs
= intel_ipc_attrs
,
580 static struct itco_wdt_platform_data tco_info
= {
581 .name
= "Apollo Lake SoC",
583 .no_reboot_priv
= &ipcdev
,
584 .update_no_reboot_bit
= update_no_reboot_bit
,
587 static int ipc_create_punit_device(struct platform_device
*pdev
)
589 struct resource punit_res
[PLAT_RESOURCE_MEM_MAX_INDEX
];
590 struct mfd_cell punit_cell
;
591 struct resource
*res
;
592 int mindex
, pindex
= 0;
594 for (mindex
= 0; mindex
<= PLAT_RESOURCE_MEM_MAX_INDEX
; mindex
++) {
596 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, mindex
);
599 /* Get PUNIT resources */
600 case PLAT_RESOURCE_BIOS_DATA_INDEX
:
601 case PLAT_RESOURCE_BIOS_IFACE_INDEX
:
602 /* BIOS resources are required, so return error if not
607 "Failed to get PUNIT MEM resource %d\n",
611 case PLAT_RESOURCE_ISP_DATA_INDEX
:
612 case PLAT_RESOURCE_ISP_IFACE_INDEX
:
613 case PLAT_RESOURCE_GTD_DATA_INDEX
:
614 case PLAT_RESOURCE_GTD_IFACE_INDEX
:
615 /* if valid resource found, copy the resource to PUNIT
619 memcpy(&punit_res
[pindex
], res
, sizeof(*res
));
620 punit_res
[pindex
].flags
= IORESOURCE_MEM
;
621 dev_dbg(&pdev
->dev
, "PUNIT memory res: %pR\n",
628 /* Create PUNIT IPC MFD cell */
629 punit_cell
.name
= PUNIT_DEVICE_NAME
;
630 punit_cell
.num_resources
= ARRAY_SIZE(punit_res
);
631 punit_cell
.resources
= punit_res
;
632 punit_cell
.ignore_resource_conflicts
= 1;
634 return devm_mfd_add_devices(&pdev
->dev
, PLATFORM_DEVID_NONE
,
635 &punit_cell
, 1, NULL
, 0, NULL
);
638 static int ipc_create_wdt_device(struct platform_device
*pdev
)
640 static struct resource wdt_ipc_res
[2];
641 struct resource
*res
;
642 static struct mfd_cell wdt_cell
;
644 /* If we have ACPI based watchdog use that instead, othewise create
645 * a MFD cell for iTCO watchdog
647 if (acpi_has_watchdog())
650 /* Get iTCO watchdog resources */
651 res
= platform_get_resource(pdev
, IORESOURCE_IO
,
652 PLAT_RESOURCE_ACPI_IO_INDEX
);
654 dev_err(&pdev
->dev
, "Failed to get WDT resource\n");
658 wdt_ipc_res
[0].start
= res
->start
+ TCO_BASE_OFFSET
;
659 wdt_ipc_res
[0].end
= res
->start
+
660 TCO_BASE_OFFSET
+ TCO_REGS_SIZE
- 1;
661 wdt_ipc_res
[0].flags
= IORESOURCE_IO
;
662 wdt_ipc_res
[1].start
= res
->start
+ SMI_EN_OFFSET
;
663 wdt_ipc_res
[1].end
= res
->start
+
664 SMI_EN_OFFSET
+ SMI_EN_SIZE
- 1;
665 wdt_ipc_res
[1].flags
= IORESOURCE_IO
;
667 dev_dbg(&pdev
->dev
, "watchdog res 0: %pR\n", &wdt_ipc_res
[0]);
668 dev_dbg(&pdev
->dev
, "watchdog res 1: %pR\n", &wdt_ipc_res
[1]);
670 wdt_cell
.name
= TCO_DEVICE_NAME
;
671 wdt_cell
.platform_data
= &tco_info
;
672 wdt_cell
.pdata_size
= sizeof(tco_info
);
673 wdt_cell
.num_resources
= ARRAY_SIZE(wdt_ipc_res
);
674 wdt_cell
.resources
= wdt_ipc_res
;
675 wdt_cell
.ignore_resource_conflicts
= 1;
677 return devm_mfd_add_devices(&pdev
->dev
, PLATFORM_DEVID_NONE
,
678 &wdt_cell
, 1, NULL
, 0, NULL
);
681 static int ipc_create_telemetry_device(struct platform_device
*pdev
)
683 struct resource telemetry_ipc_res
[2];
684 struct mfd_cell telemetry_cell
;
685 struct resource
*res
;
687 /* Get telemetry resources */
688 res
= platform_get_resource(pdev
, IORESOURCE_MEM
,
689 PLAT_RESOURCE_TELEM_SSRAM_INDEX
);
691 dev_err(&pdev
->dev
, "Failed to get telemetry resource\n");
695 telemetry_ipc_res
[0].start
= res
->start
+ TELEM_PUNIT_SSRAM_OFFSET
;
696 telemetry_ipc_res
[0].end
= res
->start
+
697 TELEM_PUNIT_SSRAM_OFFSET
+ TELEM_SSRAM_SIZE
- 1;
698 telemetry_ipc_res
[0].flags
= IORESOURCE_MEM
;
699 telemetry_ipc_res
[1].start
= res
->start
+ TELEM_PMC_SSRAM_OFFSET
;
700 telemetry_ipc_res
[1].end
= res
->start
+
701 TELEM_PMC_SSRAM_OFFSET
+ TELEM_SSRAM_SIZE
- 1;
702 telemetry_ipc_res
[1].flags
= IORESOURCE_MEM
;
704 dev_dbg(&pdev
->dev
, "Telemetry res 0: %pR\n", &telemetry_ipc_res
[0]);
705 dev_dbg(&pdev
->dev
, "Telemetry res 1: %pR\n", &telemetry_ipc_res
[1]);
707 telemetry_cell
.name
= TELEMETRY_DEVICE_NAME
;
708 telemetry_cell
.num_resources
= ARRAY_SIZE(telemetry_ipc_res
);
709 telemetry_cell
.resources
= telemetry_ipc_res
;
710 telemetry_cell
.ignore_resource_conflicts
= 1;
712 return devm_mfd_add_devices(&pdev
->dev
, PLATFORM_DEVID_NONE
,
713 &telemetry_cell
, 1, NULL
, 0, NULL
);
716 static int ipc_create_pmc_devices(struct platform_device
*pdev
)
720 ret
= ipc_create_punit_device(pdev
);
724 ret
= ipc_create_wdt_device(pdev
);
728 ret
= ipc_create_telemetry_device(pdev
);
735 static int ipc_plat_get_res(struct platform_device
*pdev
)
737 struct resource
*res
;
740 /* Get IPC resources */
741 res
= platform_get_resource(pdev
, IORESOURCE_MEM
,
742 PLAT_RESOURCE_IPC_INDEX
);
744 dev_err(&pdev
->dev
, "Failed to get IPC resources\n");
748 res
->end
= res
->start
+
749 PLAT_RESOURCE_IPC_SIZE
+ PLAT_RESOURCE_GCR_SIZE
- 1;
751 addr
= devm_ioremap_resource(&pdev
->dev
, res
);
753 return PTR_ERR(addr
);
755 ipcdev
.ipc_base
= addr
;
756 ipcdev
.gcr_mem_base
= addr
+ PLAT_RESOURCE_GCR_OFFSET
;
757 dev_dbg(&pdev
->dev
, "PMC IPC resource %pR\n", res
);
763 * intel_pmc_s0ix_counter_read() - Read S0ix residency.
764 * @data: Out param that contains current S0ix residency count.
766 * Return: an error code or 0 on success.
768 int intel_pmc_s0ix_counter_read(u64
*data
)
772 if (!ipcdev
.has_gcr_regs
)
775 deep
= gcr_data_readq(PMC_GCR_TELEM_DEEP_S0IX_REG
);
776 shlw
= gcr_data_readq(PMC_GCR_TELEM_SHLW_S0IX_REG
);
778 *data
= S0IX_RESIDENCY_IN_USECS(deep
, shlw
);
782 EXPORT_SYMBOL_GPL(intel_pmc_s0ix_counter_read
);
785 static const struct acpi_device_id ipc_acpi_ids
[] = {
789 MODULE_DEVICE_TABLE(acpi
, ipc_acpi_ids
);
792 static int ipc_plat_probe(struct platform_device
*pdev
)
796 ipcdev
.dev
= &pdev
->dev
;
797 ipcdev
.irq_mode
= IPC_TRIGGER_MODE_IRQ
;
798 init_completion(&ipcdev
.cmd_complete
);
799 spin_lock_init(&ipcdev
.gcr_lock
);
801 ipcdev
.irq
= platform_get_irq(pdev
, 0);
802 if (ipcdev
.irq
< 0) {
803 dev_err(&pdev
->dev
, "Failed to get IRQ\n");
807 ret
= ipc_plat_get_res(pdev
);
809 dev_err(&pdev
->dev
, "Failed to request resource\n");
813 ret
= ipc_create_pmc_devices(pdev
);
815 dev_err(&pdev
->dev
, "Failed to create PMC devices\n");
819 ret
= devm_request_irq(&pdev
->dev
, ipcdev
.irq
, ioc
, IRQF_NO_SUSPEND
,
820 "intel_pmc_ipc", &ipcdev
);
822 dev_err(&pdev
->dev
, "Failed to request IRQ\n");
826 ret
= sysfs_create_group(&pdev
->dev
.kobj
, &intel_ipc_group
);
828 dev_err(&pdev
->dev
, "Failed to create sysfs group %d\n",
830 devm_free_irq(&pdev
->dev
, ipcdev
.irq
, &ipcdev
);
834 ipcdev
.has_gcr_regs
= true;
839 static int ipc_plat_remove(struct platform_device
*pdev
)
841 sysfs_remove_group(&pdev
->dev
.kobj
, &intel_ipc_group
);
842 devm_free_irq(&pdev
->dev
, ipcdev
.irq
, &ipcdev
);
848 static struct platform_driver ipc_plat_driver
= {
849 .remove
= ipc_plat_remove
,
850 .probe
= ipc_plat_probe
,
852 .name
= "pmc-ipc-plat",
853 .acpi_match_table
= ACPI_PTR(ipc_acpi_ids
),
857 static int __init
intel_pmc_ipc_init(void)
861 ret
= platform_driver_register(&ipc_plat_driver
);
863 pr_err("Failed to register PMC IPC platform driver\n");
866 ret
= pci_register_driver(&ipc_pci_driver
);
868 pr_err("Failed to register PMC IPC PCI driver\n");
869 platform_driver_unregister(&ipc_plat_driver
);
875 static void __exit
intel_pmc_ipc_exit(void)
877 pci_unregister_driver(&ipc_pci_driver
);
878 platform_driver_unregister(&ipc_plat_driver
);
881 MODULE_AUTHOR("Zha Qipeng <qipeng.zha@intel.com>");
882 MODULE_DESCRIPTION("Intel PMC IPC driver");
883 MODULE_LICENSE("GPL");
885 /* Some modules are dependent on this, so init earlier */
886 fs_initcall(intel_pmc_ipc_init
);
887 module_exit(intel_pmc_ipc_exit
);