1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for the Intel PMC IPC mechanism
5 * (C) Copyright 2014-2015 Intel Corporation
7 * This driver is based on Intel SCU IPC driver(intel_scu_ipc.c) by
8 * Sreedhara DS <sreedhara.ds@intel.com>
10 * 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.
14 #include <linux/acpi.h>
15 #include <linux/delay.h>
16 #include <linux/errno.h>
17 #include <linux/interrupt.h>
18 #include <linux/io-64-nonatomic-lo-hi.h>
19 #include <linux/module.h>
20 #include <linux/pci.h>
21 #include <linux/platform_device.h>
23 #include <asm/intel_pmc_ipc.h>
25 #include <linux/platform_data/itco_wdt.h>
29 * The IA write to IPC_CMD command register triggers an interrupt to the ARC,
30 * The ARC handles the interrupt and services it, writing optional data to
31 * the IPC1 registers, updates the IPC_STS response register with the status.
34 #define IPC_CMD_MSI BIT(8)
35 #define IPC_CMD_SIZE 16
36 #define IPC_CMD_SUBCMD 12
37 #define IPC_STATUS 0x04
38 #define IPC_STATUS_IRQ BIT(2)
39 #define IPC_STATUS_ERR BIT(1)
40 #define IPC_STATUS_BUSY BIT(0)
43 #define IPC_WRITE_BUFFER 0x80
44 #define IPC_READ_BUFFER 0x90
46 /* Residency with clock rate at 19.2MHz to usecs */
47 #define S0IX_RESIDENCY_IN_USECS(d, s) \
49 u64 result = 10ull * ((d) + (s)); \
50 do_div(result, 192); \
55 * 16-byte buffer for sending data associated with IPC command.
57 #define IPC_DATA_BUFFER_SIZE 16
59 #define IPC_LOOP_CNT 3000000
62 #define IPC_TRIGGER_MODE_IRQ true
64 /* exported resources from IFWI */
65 #define PLAT_RESOURCE_IPC_INDEX 0
66 #define PLAT_RESOURCE_IPC_SIZE 0x1000
67 #define PLAT_RESOURCE_GCR_OFFSET 0x1000
68 #define PLAT_RESOURCE_GCR_SIZE 0x1000
69 #define PLAT_RESOURCE_BIOS_DATA_INDEX 1
70 #define PLAT_RESOURCE_BIOS_IFACE_INDEX 2
71 #define PLAT_RESOURCE_TELEM_SSRAM_INDEX 3
72 #define PLAT_RESOURCE_ISP_DATA_INDEX 4
73 #define PLAT_RESOURCE_ISP_IFACE_INDEX 5
74 #define PLAT_RESOURCE_GTD_DATA_INDEX 6
75 #define PLAT_RESOURCE_GTD_IFACE_INDEX 7
76 #define PLAT_RESOURCE_ACPI_IO_INDEX 0
79 * BIOS does not create an ACPI device for each PMC function,
80 * but exports multiple resources from one ACPI device(IPC) for
81 * multiple functions. This driver is responsible to create a
82 * platform device and to export resources for those functions.
84 #define TCO_DEVICE_NAME "iTCO_wdt"
85 #define SMI_EN_OFFSET 0x40
87 #define TCO_BASE_OFFSET 0x60
88 #define TCO_REGS_SIZE 16
89 #define PUNIT_DEVICE_NAME "intel_punit_ipc"
90 #define TELEMETRY_DEVICE_NAME "intel_telemetry"
91 #define TELEM_SSRAM_SIZE 240
92 #define TELEM_PMC_SSRAM_OFFSET 0x1B00
93 #define TELEM_PUNIT_SSRAM_OFFSET 0x1A00
94 #define TCO_PMC_OFFSET 0x08
95 #define TCO_PMC_SIZE 0x04
97 /* PMC register bit definitions */
99 /* PMC_CFG_REG bit masks */
100 #define PMC_CFG_NO_REBOOT_MASK BIT_MASK(4)
101 #define PMC_CFG_NO_REBOOT_EN (1 << 4)
102 #define PMC_CFG_NO_REBOOT_DIS (0 << 4)
104 static struct intel_pmc_ipc_dev
{
106 void __iomem
*ipc_base
;
110 struct completion cmd_complete
;
112 /* The following PMC BARs share the same ACPI device with the IPC */
113 resource_size_t acpi_io_base
;
115 struct platform_device
*tco_dev
;
118 void __iomem
*gcr_mem_base
;
123 struct platform_device
*punit_dev
;
124 unsigned int punit_res_count
;
127 resource_size_t telem_pmc_ssram_base
;
128 resource_size_t telem_punit_ssram_base
;
129 int telem_pmc_ssram_size
;
130 int telem_punit_ssram_size
;
132 struct platform_device
*telemetry_dev
;
135 static char *ipc_err_sources
[] = {
138 [IPC_ERR_CMD_NOT_SUPPORTED
] =
139 "command not supported",
140 [IPC_ERR_CMD_NOT_SERVICED
] =
141 "command not serviced",
142 [IPC_ERR_UNABLE_TO_SERVICE
] =
144 [IPC_ERR_CMD_INVALID
] =
146 [IPC_ERR_CMD_FAILED
] =
148 [IPC_ERR_EMSECURITY
] =
150 [IPC_ERR_UNSIGNEDKERNEL
] =
154 /* Prevent concurrent calls to the PMC */
155 static DEFINE_MUTEX(ipclock
);
157 static inline void ipc_send_command(u32 cmd
)
160 if (ipcdev
.irq_mode
) {
161 reinit_completion(&ipcdev
.cmd_complete
);
164 writel(cmd
, ipcdev
.ipc_base
+ IPC_CMD
);
167 static inline u32
ipc_read_status(void)
169 return readl(ipcdev
.ipc_base
+ IPC_STATUS
);
172 static inline void ipc_data_writel(u32 data
, u32 offset
)
174 writel(data
, ipcdev
.ipc_base
+ IPC_WRITE_BUFFER
+ offset
);
177 static inline u32
ipc_data_readl(u32 offset
)
179 return readl(ipcdev
.ipc_base
+ IPC_READ_BUFFER
+ offset
);
182 static inline u64
gcr_data_readq(u32 offset
)
184 return readq(ipcdev
.gcr_mem_base
+ offset
);
187 static inline int is_gcr_valid(u32 offset
)
189 if (!ipcdev
.has_gcr_regs
)
192 if (offset
> PLAT_RESOURCE_GCR_SIZE
)
199 * intel_pmc_gcr_read64() - Read a 64-bit PMC GCR register
200 * @offset: offset of GCR register from GCR address base
201 * @data: data pointer for storing the register output
203 * Reads the 64-bit PMC GCR register at given offset.
205 * Return: negative value on error or 0 on success.
207 int intel_pmc_gcr_read64(u32 offset
, u64
*data
)
211 spin_lock(&ipcdev
.gcr_lock
);
213 ret
= is_gcr_valid(offset
);
215 spin_unlock(&ipcdev
.gcr_lock
);
219 *data
= readq(ipcdev
.gcr_mem_base
+ offset
);
221 spin_unlock(&ipcdev
.gcr_lock
);
225 EXPORT_SYMBOL_GPL(intel_pmc_gcr_read64
);
228 * intel_pmc_gcr_update() - Update PMC GCR register bits
229 * @offset: offset of GCR register from GCR address base
230 * @mask: bit mask for update operation
233 * Updates the bits of given GCR register as specified by
236 * Return: negative value on error or 0 on success.
238 static int intel_pmc_gcr_update(u32 offset
, u32 mask
, u32 val
)
243 spin_lock(&ipcdev
.gcr_lock
);
245 ret
= is_gcr_valid(offset
);
249 new_val
= readl(ipcdev
.gcr_mem_base
+ offset
);
252 new_val
|= val
& mask
;
254 writel(new_val
, ipcdev
.gcr_mem_base
+ offset
);
256 new_val
= readl(ipcdev
.gcr_mem_base
+ offset
);
258 /* check whether the bit update is successful */
259 if ((new_val
& mask
) != (val
& mask
)) {
265 spin_unlock(&ipcdev
.gcr_lock
);
269 static int update_no_reboot_bit(void *priv
, bool set
)
271 u32 value
= set
? PMC_CFG_NO_REBOOT_EN
: PMC_CFG_NO_REBOOT_DIS
;
273 return intel_pmc_gcr_update(PMC_GCR_PMC_CFG_REG
,
274 PMC_CFG_NO_REBOOT_MASK
, value
);
277 static int intel_pmc_ipc_check_status(void)
282 if (ipcdev
.irq_mode
) {
283 if (0 == wait_for_completion_timeout(
284 &ipcdev
.cmd_complete
, IPC_MAX_SEC
* HZ
))
287 int loop_count
= IPC_LOOP_CNT
;
289 while ((ipc_read_status() & IPC_STATUS_BUSY
) && --loop_count
)
295 status
= ipc_read_status();
296 if (ret
== -ETIMEDOUT
) {
298 "IPC timed out, TS=0x%x, CMD=0x%x\n",
303 if (status
& IPC_STATUS_ERR
) {
307 i
= (status
>> IPC_CMD_SIZE
) & 0xFF;
308 if (i
< ARRAY_SIZE(ipc_err_sources
))
310 "IPC failed: %s, STS=0x%x, CMD=0x%x\n",
311 ipc_err_sources
[i
], status
, ipcdev
.cmd
);
314 "IPC failed: unknown, STS=0x%x, CMD=0x%x\n",
316 if ((i
== IPC_ERR_UNSIGNEDKERNEL
) || (i
== IPC_ERR_EMSECURITY
))
324 * intel_pmc_ipc_simple_command() - Simple IPC command
325 * @cmd: IPC command code.
326 * @sub: IPC command sub type.
328 * Send a simple IPC command to PMC when don't need to specify
329 * input/output data and source/dest pointers.
331 * Return: an IPC error code or 0 on success.
333 static int intel_pmc_ipc_simple_command(int cmd
, int sub
)
337 mutex_lock(&ipclock
);
338 if (ipcdev
.dev
== NULL
) {
339 mutex_unlock(&ipclock
);
342 ipc_send_command(sub
<< IPC_CMD_SUBCMD
| cmd
);
343 ret
= intel_pmc_ipc_check_status();
344 mutex_unlock(&ipclock
);
350 * intel_pmc_ipc_raw_cmd() - IPC command with data and pointers
351 * @cmd: IPC command code.
352 * @sub: IPC command sub type.
353 * @in: input data of this IPC command.
354 * @inlen: input data length in bytes.
355 * @out: output data of this IPC command.
356 * @outlen: output data length in dwords.
357 * @sptr: data writing to SPTR register.
358 * @dptr: data writing to DPTR register.
360 * Send an IPC command to PMC with input/output data and source/dest pointers.
362 * Return: an IPC error code or 0 on success.
364 static int intel_pmc_ipc_raw_cmd(u32 cmd
, u32 sub
, u8
*in
, u32 inlen
, u32
*out
,
365 u32 outlen
, u32 dptr
, u32 sptr
)
371 if (inlen
> IPC_DATA_BUFFER_SIZE
|| outlen
> IPC_DATA_BUFFER_SIZE
/ 4)
374 mutex_lock(&ipclock
);
375 if (ipcdev
.dev
== NULL
) {
376 mutex_unlock(&ipclock
);
379 memcpy(wbuf
, in
, inlen
);
380 writel(dptr
, ipcdev
.ipc_base
+ IPC_DPTR
);
381 writel(sptr
, ipcdev
.ipc_base
+ IPC_SPTR
);
382 /* The input data register is 32bit register and inlen is in Byte */
383 for (i
= 0; i
< ((inlen
+ 3) / 4); i
++)
384 ipc_data_writel(wbuf
[i
], 4 * i
);
385 ipc_send_command((inlen
<< IPC_CMD_SIZE
) |
386 (sub
<< IPC_CMD_SUBCMD
) | cmd
);
387 ret
= intel_pmc_ipc_check_status();
389 /* out is read from 32bit register and outlen is in 32bit */
390 for (i
= 0; i
< outlen
; i
++)
391 *out
++ = ipc_data_readl(4 * i
);
393 mutex_unlock(&ipclock
);
399 * intel_pmc_ipc_command() - IPC command with input/output data
400 * @cmd: IPC command code.
401 * @sub: IPC command sub type.
402 * @in: input data of this IPC command.
403 * @inlen: input data length in bytes.
404 * @out: output data of this IPC command.
405 * @outlen: output data length in dwords.
407 * Send an IPC command to PMC with input/output data.
409 * Return: an IPC error code or 0 on success.
411 int intel_pmc_ipc_command(u32 cmd
, u32 sub
, u8
*in
, u32 inlen
,
412 u32
*out
, u32 outlen
)
414 return intel_pmc_ipc_raw_cmd(cmd
, sub
, in
, inlen
, out
, outlen
, 0, 0);
416 EXPORT_SYMBOL_GPL(intel_pmc_ipc_command
);
418 static irqreturn_t
ioc(int irq
, void *dev_id
)
422 if (ipcdev
.irq_mode
) {
423 status
= ipc_read_status();
424 writel(status
| IPC_STATUS_IRQ
, ipcdev
.ipc_base
+ IPC_STATUS
);
426 complete(&ipcdev
.cmd_complete
);
431 static int ipc_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
433 struct intel_pmc_ipc_dev
*pmc
= &ipcdev
;
436 /* Only one PMC is supported */
440 pmc
->irq_mode
= IPC_TRIGGER_MODE_IRQ
;
442 spin_lock_init(&ipcdev
.gcr_lock
);
444 ret
= pcim_enable_device(pdev
);
448 ret
= pcim_iomap_regions(pdev
, 1 << 0, pci_name(pdev
));
452 init_completion(&pmc
->cmd_complete
);
454 pmc
->ipc_base
= pcim_iomap_table(pdev
)[0];
456 ret
= devm_request_irq(&pdev
->dev
, pdev
->irq
, ioc
, 0, "intel_pmc_ipc",
459 dev_err(&pdev
->dev
, "Failed to request irq\n");
463 pmc
->dev
= &pdev
->dev
;
465 pci_set_drvdata(pdev
, pmc
);
470 static const struct pci_device_id ipc_pci_ids
[] = {
471 {PCI_VDEVICE(INTEL
, 0x0a94), 0},
472 {PCI_VDEVICE(INTEL
, 0x1a94), 0},
473 {PCI_VDEVICE(INTEL
, 0x5a94), 0},
476 MODULE_DEVICE_TABLE(pci
, ipc_pci_ids
);
478 static struct pci_driver ipc_pci_driver
= {
479 .name
= "intel_pmc_ipc",
480 .id_table
= ipc_pci_ids
,
481 .probe
= ipc_pci_probe
,
484 static ssize_t
intel_pmc_ipc_simple_cmd_store(struct device
*dev
,
485 struct device_attribute
*attr
,
486 const char *buf
, size_t count
)
492 ret
= sscanf(buf
, "%d %d", &cmd
, &subcmd
);
494 dev_err(dev
, "Error args\n");
498 ret
= intel_pmc_ipc_simple_command(cmd
, subcmd
);
500 dev_err(dev
, "command %d error with %d\n", cmd
, ret
);
503 return (ssize_t
)count
;
505 static DEVICE_ATTR(simplecmd
, 0200, NULL
, intel_pmc_ipc_simple_cmd_store
);
507 static ssize_t
intel_pmc_ipc_northpeak_store(struct device
*dev
,
508 struct device_attribute
*attr
,
509 const char *buf
, size_t count
)
515 ret
= kstrtoul(buf
, 0, &val
);
523 ret
= intel_pmc_ipc_simple_command(PMC_IPC_NORTHPEAK_CTRL
, subcmd
);
525 dev_err(dev
, "command north %d error with %d\n", subcmd
, ret
);
528 return (ssize_t
)count
;
530 static DEVICE_ATTR(northpeak
, 0200, NULL
, intel_pmc_ipc_northpeak_store
);
532 static struct attribute
*intel_ipc_attrs
[] = {
533 &dev_attr_northpeak
.attr
,
534 &dev_attr_simplecmd
.attr
,
538 static const struct attribute_group intel_ipc_group
= {
539 .attrs
= intel_ipc_attrs
,
542 static const struct attribute_group
*intel_ipc_groups
[] = {
547 static struct resource punit_res_array
[] = {
550 .flags
= IORESOURCE_MEM
,
553 .flags
= IORESOURCE_MEM
,
557 .flags
= IORESOURCE_MEM
,
560 .flags
= IORESOURCE_MEM
,
564 .flags
= IORESOURCE_MEM
,
567 .flags
= IORESOURCE_MEM
,
571 #define TCO_RESOURCE_ACPI_IO 0
572 #define TCO_RESOURCE_SMI_EN_IO 1
573 #define TCO_RESOURCE_GCR_MEM 2
574 static struct resource tco_res
[] = {
577 .flags
= IORESOURCE_IO
,
581 .flags
= IORESOURCE_IO
,
585 static struct itco_wdt_platform_data tco_info
= {
586 .name
= "Apollo Lake SoC",
588 .no_reboot_priv
= &ipcdev
,
589 .update_no_reboot_bit
= update_no_reboot_bit
,
592 #define TELEMETRY_RESOURCE_PUNIT_SSRAM 0
593 #define TELEMETRY_RESOURCE_PMC_SSRAM 1
594 static struct resource telemetry_res
[] = {
597 .flags
= IORESOURCE_MEM
,
600 .flags
= IORESOURCE_MEM
,
604 static int ipc_create_punit_device(void)
606 struct platform_device
*pdev
;
607 const struct platform_device_info pdevinfo
= {
608 .parent
= ipcdev
.dev
,
609 .name
= PUNIT_DEVICE_NAME
,
611 .res
= punit_res_array
,
612 .num_res
= ipcdev
.punit_res_count
,
615 pdev
= platform_device_register_full(&pdevinfo
);
617 return PTR_ERR(pdev
);
619 ipcdev
.punit_dev
= pdev
;
624 static int ipc_create_tco_device(void)
626 struct platform_device
*pdev
;
627 struct resource
*res
;
628 const struct platform_device_info pdevinfo
= {
629 .parent
= ipcdev
.dev
,
630 .name
= TCO_DEVICE_NAME
,
633 .num_res
= ARRAY_SIZE(tco_res
),
635 .size_data
= sizeof(tco_info
),
638 res
= tco_res
+ TCO_RESOURCE_ACPI_IO
;
639 res
->start
= ipcdev
.acpi_io_base
+ TCO_BASE_OFFSET
;
640 res
->end
= res
->start
+ TCO_REGS_SIZE
- 1;
642 res
= tco_res
+ TCO_RESOURCE_SMI_EN_IO
;
643 res
->start
= ipcdev
.acpi_io_base
+ SMI_EN_OFFSET
;
644 res
->end
= res
->start
+ SMI_EN_SIZE
- 1;
646 pdev
= platform_device_register_full(&pdevinfo
);
648 return PTR_ERR(pdev
);
650 ipcdev
.tco_dev
= pdev
;
655 static int ipc_create_telemetry_device(void)
657 struct platform_device
*pdev
;
658 struct resource
*res
;
659 const struct platform_device_info pdevinfo
= {
660 .parent
= ipcdev
.dev
,
661 .name
= TELEMETRY_DEVICE_NAME
,
663 .res
= telemetry_res
,
664 .num_res
= ARRAY_SIZE(telemetry_res
),
667 res
= telemetry_res
+ TELEMETRY_RESOURCE_PUNIT_SSRAM
;
668 res
->start
= ipcdev
.telem_punit_ssram_base
;
669 res
->end
= res
->start
+ ipcdev
.telem_punit_ssram_size
- 1;
671 res
= telemetry_res
+ TELEMETRY_RESOURCE_PMC_SSRAM
;
672 res
->start
= ipcdev
.telem_pmc_ssram_base
;
673 res
->end
= res
->start
+ ipcdev
.telem_pmc_ssram_size
- 1;
675 pdev
= platform_device_register_full(&pdevinfo
);
677 return PTR_ERR(pdev
);
679 ipcdev
.telemetry_dev
= pdev
;
684 static int ipc_create_pmc_devices(void)
688 /* If we have ACPI based watchdog use that instead */
689 if (!acpi_has_watchdog()) {
690 ret
= ipc_create_tco_device();
692 dev_err(ipcdev
.dev
, "Failed to add tco platform device\n");
697 ret
= ipc_create_punit_device();
699 dev_err(ipcdev
.dev
, "Failed to add punit platform device\n");
700 platform_device_unregister(ipcdev
.tco_dev
);
704 if (!ipcdev
.telem_res_inval
) {
705 ret
= ipc_create_telemetry_device();
708 "Failed to add telemetry platform device\n");
709 platform_device_unregister(ipcdev
.punit_dev
);
710 platform_device_unregister(ipcdev
.tco_dev
);
717 static int ipc_plat_get_res(struct platform_device
*pdev
)
719 struct resource
*res
, *punit_res
= punit_res_array
;
723 res
= platform_get_resource(pdev
, IORESOURCE_IO
,
724 PLAT_RESOURCE_ACPI_IO_INDEX
);
726 dev_err(&pdev
->dev
, "Failed to get io resource\n");
729 size
= resource_size(res
);
730 ipcdev
.acpi_io_base
= res
->start
;
731 ipcdev
.acpi_io_size
= size
;
732 dev_info(&pdev
->dev
, "io res: %pR\n", res
);
734 ipcdev
.punit_res_count
= 0;
736 /* This is index 0 to cover BIOS data register */
737 res
= platform_get_resource(pdev
, IORESOURCE_MEM
,
738 PLAT_RESOURCE_BIOS_DATA_INDEX
);
740 dev_err(&pdev
->dev
, "Failed to get res of punit BIOS data\n");
743 punit_res
[ipcdev
.punit_res_count
++] = *res
;
744 dev_info(&pdev
->dev
, "punit BIOS data res: %pR\n", res
);
746 /* This is index 1 to cover BIOS interface register */
747 res
= platform_get_resource(pdev
, IORESOURCE_MEM
,
748 PLAT_RESOURCE_BIOS_IFACE_INDEX
);
750 dev_err(&pdev
->dev
, "Failed to get res of punit BIOS iface\n");
753 punit_res
[ipcdev
.punit_res_count
++] = *res
;
754 dev_info(&pdev
->dev
, "punit BIOS interface res: %pR\n", res
);
756 /* This is index 2 to cover ISP data register, optional */
757 res
= platform_get_resource(pdev
, IORESOURCE_MEM
,
758 PLAT_RESOURCE_ISP_DATA_INDEX
);
760 punit_res
[ipcdev
.punit_res_count
++] = *res
;
761 dev_info(&pdev
->dev
, "punit ISP data res: %pR\n", res
);
764 /* This is index 3 to cover ISP interface register, optional */
765 res
= platform_get_resource(pdev
, IORESOURCE_MEM
,
766 PLAT_RESOURCE_ISP_IFACE_INDEX
);
768 punit_res
[ipcdev
.punit_res_count
++] = *res
;
769 dev_info(&pdev
->dev
, "punit ISP interface res: %pR\n", res
);
772 /* This is index 4 to cover GTD data register, optional */
773 res
= platform_get_resource(pdev
, IORESOURCE_MEM
,
774 PLAT_RESOURCE_GTD_DATA_INDEX
);
776 punit_res
[ipcdev
.punit_res_count
++] = *res
;
777 dev_info(&pdev
->dev
, "punit GTD data res: %pR\n", res
);
780 /* This is index 5 to cover GTD interface register, optional */
781 res
= platform_get_resource(pdev
, IORESOURCE_MEM
,
782 PLAT_RESOURCE_GTD_IFACE_INDEX
);
784 punit_res
[ipcdev
.punit_res_count
++] = *res
;
785 dev_info(&pdev
->dev
, "punit GTD interface res: %pR\n", res
);
788 res
= platform_get_resource(pdev
, IORESOURCE_MEM
,
789 PLAT_RESOURCE_IPC_INDEX
);
791 dev_err(&pdev
->dev
, "Failed to get ipc resource\n");
794 size
= PLAT_RESOURCE_IPC_SIZE
+ PLAT_RESOURCE_GCR_SIZE
;
795 res
->end
= res
->start
+ size
- 1;
797 addr
= devm_ioremap_resource(&pdev
->dev
, res
);
799 return PTR_ERR(addr
);
801 ipcdev
.ipc_base
= addr
;
803 ipcdev
.gcr_mem_base
= addr
+ PLAT_RESOURCE_GCR_OFFSET
;
804 dev_info(&pdev
->dev
, "ipc res: %pR\n", res
);
806 ipcdev
.telem_res_inval
= 0;
807 res
= platform_get_resource(pdev
, IORESOURCE_MEM
,
808 PLAT_RESOURCE_TELEM_SSRAM_INDEX
);
810 dev_err(&pdev
->dev
, "Failed to get telemetry ssram resource\n");
811 ipcdev
.telem_res_inval
= 1;
813 ipcdev
.telem_punit_ssram_base
= res
->start
+
814 TELEM_PUNIT_SSRAM_OFFSET
;
815 ipcdev
.telem_punit_ssram_size
= TELEM_SSRAM_SIZE
;
816 ipcdev
.telem_pmc_ssram_base
= res
->start
+
817 TELEM_PMC_SSRAM_OFFSET
;
818 ipcdev
.telem_pmc_ssram_size
= TELEM_SSRAM_SIZE
;
819 dev_info(&pdev
->dev
, "telemetry ssram res: %pR\n", res
);
826 * intel_pmc_s0ix_counter_read() - Read S0ix residency.
827 * @data: Out param that contains current S0ix residency count.
829 * Return: an error code or 0 on success.
831 int intel_pmc_s0ix_counter_read(u64
*data
)
835 if (!ipcdev
.has_gcr_regs
)
838 deep
= gcr_data_readq(PMC_GCR_TELEM_DEEP_S0IX_REG
);
839 shlw
= gcr_data_readq(PMC_GCR_TELEM_SHLW_S0IX_REG
);
841 *data
= S0IX_RESIDENCY_IN_USECS(deep
, shlw
);
845 EXPORT_SYMBOL_GPL(intel_pmc_s0ix_counter_read
);
848 static const struct acpi_device_id ipc_acpi_ids
[] = {
852 MODULE_DEVICE_TABLE(acpi
, ipc_acpi_ids
);
855 static int ipc_plat_probe(struct platform_device
*pdev
)
859 ipcdev
.dev
= &pdev
->dev
;
860 ipcdev
.irq_mode
= IPC_TRIGGER_MODE_IRQ
;
861 init_completion(&ipcdev
.cmd_complete
);
862 spin_lock_init(&ipcdev
.gcr_lock
);
864 ipcdev
.irq
= platform_get_irq(pdev
, 0);
868 ret
= ipc_plat_get_res(pdev
);
870 dev_err(&pdev
->dev
, "Failed to request resource\n");
874 ret
= ipc_create_pmc_devices();
876 dev_err(&pdev
->dev
, "Failed to create pmc devices\n");
880 if (devm_request_irq(&pdev
->dev
, ipcdev
.irq
, ioc
, IRQF_NO_SUSPEND
,
881 "intel_pmc_ipc", &ipcdev
)) {
882 dev_err(&pdev
->dev
, "Failed to request irq\n");
887 ipcdev
.has_gcr_regs
= true;
892 platform_device_unregister(ipcdev
.tco_dev
);
893 platform_device_unregister(ipcdev
.punit_dev
);
894 platform_device_unregister(ipcdev
.telemetry_dev
);
899 static int ipc_plat_remove(struct platform_device
*pdev
)
901 devm_free_irq(&pdev
->dev
, ipcdev
.irq
, &ipcdev
);
902 platform_device_unregister(ipcdev
.tco_dev
);
903 platform_device_unregister(ipcdev
.punit_dev
);
904 platform_device_unregister(ipcdev
.telemetry_dev
);
909 static struct platform_driver ipc_plat_driver
= {
910 .remove
= ipc_plat_remove
,
911 .probe
= ipc_plat_probe
,
913 .name
= "pmc-ipc-plat",
914 .acpi_match_table
= ACPI_PTR(ipc_acpi_ids
),
915 .dev_groups
= intel_ipc_groups
,
919 static int __init
intel_pmc_ipc_init(void)
923 ret
= platform_driver_register(&ipc_plat_driver
);
925 pr_err("Failed to register PMC ipc platform driver\n");
928 ret
= pci_register_driver(&ipc_pci_driver
);
930 pr_err("Failed to register PMC ipc pci driver\n");
931 platform_driver_unregister(&ipc_plat_driver
);
937 static void __exit
intel_pmc_ipc_exit(void)
939 pci_unregister_driver(&ipc_pci_driver
);
940 platform_driver_unregister(&ipc_plat_driver
);
943 MODULE_AUTHOR("Zha Qipeng <qipeng.zha@intel.com>");
944 MODULE_DESCRIPTION("Intel PMC IPC driver");
945 MODULE_LICENSE("GPL v2");
947 /* Some modules are dependent on this, so init earlier */
948 fs_initcall(intel_pmc_ipc_init
);
949 module_exit(intel_pmc_ipc_exit
);