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
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>
24 #include <linux/pci.h>
25 #include <linux/platform_device.h>
26 #include <linux/interrupt.h>
27 #include <linux/pm_qos.h>
28 #include <linux/kernel.h>
29 #include <linux/bitops.h>
30 #include <linux/sched.h>
31 #include <linux/atomic.h>
32 #include <linux/notifier.h>
33 #include <linux/suspend.h>
34 #include <linux/acpi.h>
35 #include <linux/io-64-nonatomic-lo-hi.h>
37 #include <asm/intel_pmc_ipc.h>
39 #include <linux/platform_data/itco_wdt.h>
43 * The IA write to IPC_CMD command register triggers an interrupt to the ARC,
44 * The ARC handles the interrupt and services it, writing optional data to
45 * the IPC1 registers, updates the IPC_STS response register with the status.
48 #define IPC_CMD_MSI 0x100
49 #define IPC_CMD_SIZE 16
50 #define IPC_CMD_SUBCMD 12
51 #define IPC_STATUS 0x04
52 #define IPC_STATUS_IRQ 0x4
53 #define IPC_STATUS_ERR 0x2
54 #define IPC_STATUS_BUSY 0x1
57 #define IPC_WRITE_BUFFER 0x80
58 #define IPC_READ_BUFFER 0x90
60 /* Residency with clock rate at 19.2MHz to usecs */
61 #define S0IX_RESIDENCY_IN_USECS(d, s) \
63 u64 result = 10ull * ((d) + (s)); \
64 do_div(result, 192); \
69 * 16-byte buffer for sending data associated with IPC command.
71 #define IPC_DATA_BUFFER_SIZE 16
73 #define IPC_LOOP_CNT 3000000
76 #define IPC_TRIGGER_MODE_IRQ true
78 /* exported resources from IFWI */
79 #define PLAT_RESOURCE_IPC_INDEX 0
80 #define PLAT_RESOURCE_IPC_SIZE 0x1000
81 #define PLAT_RESOURCE_GCR_OFFSET 0x1000
82 #define PLAT_RESOURCE_GCR_SIZE 0x1000
83 #define PLAT_RESOURCE_BIOS_DATA_INDEX 1
84 #define PLAT_RESOURCE_BIOS_IFACE_INDEX 2
85 #define PLAT_RESOURCE_TELEM_SSRAM_INDEX 3
86 #define PLAT_RESOURCE_ISP_DATA_INDEX 4
87 #define PLAT_RESOURCE_ISP_IFACE_INDEX 5
88 #define PLAT_RESOURCE_GTD_DATA_INDEX 6
89 #define PLAT_RESOURCE_GTD_IFACE_INDEX 7
90 #define PLAT_RESOURCE_ACPI_IO_INDEX 0
93 * BIOS does not create an ACPI device for each PMC function,
94 * but exports multiple resources from one ACPI device(IPC) for
95 * multiple functions. This driver is responsible to create a
96 * platform device and to export resources for those functions.
98 #define TCO_DEVICE_NAME "iTCO_wdt"
99 #define SMI_EN_OFFSET 0x40
100 #define SMI_EN_SIZE 4
101 #define TCO_BASE_OFFSET 0x60
102 #define TCO_REGS_SIZE 16
103 #define PUNIT_DEVICE_NAME "intel_punit_ipc"
104 #define TELEMETRY_DEVICE_NAME "intel_telemetry"
105 #define TELEM_SSRAM_SIZE 240
106 #define TELEM_PMC_SSRAM_OFFSET 0x1B00
107 #define TELEM_PUNIT_SSRAM_OFFSET 0x1A00
108 #define TCO_PMC_OFFSET 0x8
109 #define TCO_PMC_SIZE 0x4
111 /* PMC register bit definitions */
113 /* PMC_CFG_REG bit masks */
114 #define PMC_CFG_NO_REBOOT_MASK (1 << 4)
115 #define PMC_CFG_NO_REBOOT_EN (1 << 4)
116 #define PMC_CFG_NO_REBOOT_DIS (0 << 4)
118 static struct intel_pmc_ipc_dev {
120 void __iomem *ipc_base;
124 struct completion cmd_complete;
126 /* The following PMC BARs share the same ACPI device with the IPC */
127 resource_size_t acpi_io_base;
129 struct platform_device *tco_dev;
132 void __iomem *gcr_mem_base;
136 struct platform_device *punit_dev;
139 resource_size_t telem_pmc_ssram_base;
140 resource_size_t telem_punit_ssram_base;
141 int telem_pmc_ssram_size;
142 int telem_punit_ssram_size;
144 struct platform_device *telemetry_dev;
147 static char *ipc_err_sources[] = {
150 [IPC_ERR_CMD_NOT_SUPPORTED] =
151 "command not supported",
152 [IPC_ERR_CMD_NOT_SERVICED] =
153 "command not serviced",
154 [IPC_ERR_UNABLE_TO_SERVICE] =
156 [IPC_ERR_CMD_INVALID] =
158 [IPC_ERR_CMD_FAILED] =
160 [IPC_ERR_EMSECURITY] =
162 [IPC_ERR_UNSIGNEDKERNEL] =
166 /* Prevent concurrent calls to the PMC */
167 static DEFINE_MUTEX(ipclock);
169 static inline void ipc_send_command(u32 cmd)
172 if (ipcdev.irq_mode) {
173 reinit_completion(&ipcdev.cmd_complete);
176 writel(cmd, ipcdev.ipc_base + IPC_CMD);
179 static inline u32 ipc_read_status(void)
181 return readl(ipcdev.ipc_base + IPC_STATUS);
184 static inline void ipc_data_writel(u32 data, u32 offset)
186 writel(data, ipcdev.ipc_base + IPC_WRITE_BUFFER + offset);
189 static inline u8 __maybe_unused ipc_data_readb(u32 offset)
191 return readb(ipcdev.ipc_base + IPC_READ_BUFFER + offset);
194 static inline u32 ipc_data_readl(u32 offset)
196 return readl(ipcdev.ipc_base + IPC_READ_BUFFER + offset);
199 static inline u64 gcr_data_readq(u32 offset)
201 return readq(ipcdev.gcr_mem_base + offset);
204 static inline int is_gcr_valid(u32 offset)
206 if (!ipcdev.has_gcr_regs)
209 if (offset > PLAT_RESOURCE_GCR_SIZE)
216 * intel_pmc_gcr_read() - Read PMC GCR register
217 * @offset: offset of GCR register from GCR address base
218 * @data: data pointer for storing the register output
220 * Reads the PMC GCR register of given offset.
222 * Return: negative value on error or 0 on success.
224 int intel_pmc_gcr_read(u32 offset, u32 *data)
228 mutex_lock(&ipclock);
230 ret = is_gcr_valid(offset);
232 mutex_unlock(&ipclock);
236 *data = readl(ipcdev.gcr_mem_base + offset);
238 mutex_unlock(&ipclock);
242 EXPORT_SYMBOL_GPL(intel_pmc_gcr_read);
245 * intel_pmc_gcr_write() - Write PMC GCR register
246 * @offset: offset of GCR register from GCR address base
247 * @data: register update value
249 * Writes the PMC GCR register of given offset with given
252 * Return: negative value on error or 0 on success.
254 int intel_pmc_gcr_write(u32 offset, u32 data)
258 mutex_lock(&ipclock);
260 ret = is_gcr_valid(offset);
262 mutex_unlock(&ipclock);
266 writel(data, ipcdev.gcr_mem_base + offset);
268 mutex_unlock(&ipclock);
272 EXPORT_SYMBOL_GPL(intel_pmc_gcr_write);
275 * intel_pmc_gcr_update() - Update PMC GCR register bits
276 * @offset: offset of GCR register from GCR address base
277 * @mask: bit mask for update operation
280 * Updates the bits of given GCR register as specified by
283 * Return: negative value on error or 0 on success.
285 int intel_pmc_gcr_update(u32 offset, u32 mask, u32 val)
290 mutex_lock(&ipclock);
292 ret = is_gcr_valid(offset);
296 new_val = readl(ipcdev.gcr_mem_base + offset);
299 new_val |= val & mask;
301 writel(new_val, ipcdev.gcr_mem_base + offset);
303 new_val = readl(ipcdev.gcr_mem_base + offset);
305 /* check whether the bit update is successful */
306 if ((new_val & mask) != (val & mask)) {
312 mutex_unlock(&ipclock);
315 EXPORT_SYMBOL_GPL(intel_pmc_gcr_update);
317 static int update_no_reboot_bit(void *priv, bool set)
319 u32 value = set ? PMC_CFG_NO_REBOOT_EN : PMC_CFG_NO_REBOOT_DIS;
321 return intel_pmc_gcr_update(PMC_GCR_PMC_CFG_REG,
322 PMC_CFG_NO_REBOOT_MASK, value);
325 static int intel_pmc_ipc_check_status(void)
330 if (ipcdev.irq_mode) {
331 if (0 == wait_for_completion_timeout(
332 &ipcdev.cmd_complete, IPC_MAX_SEC * HZ))
335 int loop_count = IPC_LOOP_CNT;
337 while ((ipc_read_status() & IPC_STATUS_BUSY) && --loop_count)
343 status = ipc_read_status();
344 if (ret == -ETIMEDOUT) {
346 "IPC timed out, TS=0x%x, CMD=0x%x\n",
351 if (status & IPC_STATUS_ERR) {
355 i = (status >> IPC_CMD_SIZE) & 0xFF;
356 if (i < ARRAY_SIZE(ipc_err_sources))
358 "IPC failed: %s, STS=0x%x, CMD=0x%x\n",
359 ipc_err_sources[i], status, ipcdev.cmd);
362 "IPC failed: unknown, STS=0x%x, CMD=0x%x\n",
364 if ((i == IPC_ERR_UNSIGNEDKERNEL) || (i == IPC_ERR_EMSECURITY))
372 * intel_pmc_ipc_simple_command() - Simple IPC command
373 * @cmd: IPC command code.
374 * @sub: IPC command sub type.
376 * Send a simple IPC command to PMC when don't need to specify
377 * input/output data and source/dest pointers.
379 * Return: an IPC error code or 0 on success.
381 int intel_pmc_ipc_simple_command(int cmd, int sub)
385 mutex_lock(&ipclock);
386 if (ipcdev.dev == NULL) {
387 mutex_unlock(&ipclock);
390 ipc_send_command(sub << IPC_CMD_SUBCMD | cmd);
391 ret = intel_pmc_ipc_check_status();
392 mutex_unlock(&ipclock);
396 EXPORT_SYMBOL_GPL(intel_pmc_ipc_simple_command);
399 * intel_pmc_ipc_raw_cmd() - IPC command with data and pointers
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.
406 * @sptr: data writing to SPTR register.
407 * @dptr: data writing to DPTR register.
409 * Send an IPC command to PMC with input/output data and source/dest pointers.
411 * Return: an IPC error code or 0 on success.
413 int intel_pmc_ipc_raw_cmd(u32 cmd, u32 sub, u8 *in, u32 inlen, u32 *out,
414 u32 outlen, u32 dptr, u32 sptr)
420 if (inlen > IPC_DATA_BUFFER_SIZE || outlen > IPC_DATA_BUFFER_SIZE / 4)
423 mutex_lock(&ipclock);
424 if (ipcdev.dev == NULL) {
425 mutex_unlock(&ipclock);
428 memcpy(wbuf, in, inlen);
429 writel(dptr, ipcdev.ipc_base + IPC_DPTR);
430 writel(sptr, ipcdev.ipc_base + IPC_SPTR);
431 /* The input data register is 32bit register and inlen is in Byte */
432 for (i = 0; i < ((inlen + 3) / 4); i++)
433 ipc_data_writel(wbuf[i], 4 * i);
434 ipc_send_command((inlen << IPC_CMD_SIZE) |
435 (sub << IPC_CMD_SUBCMD) | cmd);
436 ret = intel_pmc_ipc_check_status();
438 /* out is read from 32bit register and outlen is in 32bit */
439 for (i = 0; i < outlen; i++)
440 *out++ = ipc_data_readl(4 * i);
442 mutex_unlock(&ipclock);
446 EXPORT_SYMBOL_GPL(intel_pmc_ipc_raw_cmd);
449 * intel_pmc_ipc_command() - IPC command with input/output data
450 * @cmd: IPC command code.
451 * @sub: IPC command sub type.
452 * @in: input data of this IPC command.
453 * @inlen: input data length in bytes.
454 * @out: output data of this IPC command.
455 * @outlen: output data length in dwords.
457 * Send an IPC command to PMC with input/output data.
459 * Return: an IPC error code or 0 on success.
461 int intel_pmc_ipc_command(u32 cmd, u32 sub, u8 *in, u32 inlen,
462 u32 *out, u32 outlen)
464 return intel_pmc_ipc_raw_cmd(cmd, sub, in, inlen, out, outlen, 0, 0);
466 EXPORT_SYMBOL_GPL(intel_pmc_ipc_command);
468 static irqreturn_t ioc(int irq, void *dev_id)
472 if (ipcdev.irq_mode) {
473 status = ipc_read_status();
474 writel(status | IPC_STATUS_IRQ, ipcdev.ipc_base + IPC_STATUS);
476 complete(&ipcdev.cmd_complete);
481 static int ipc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
483 resource_size_t pci_resource;
487 ipcdev.dev = &pci_dev_get(pdev)->dev;
488 ipcdev.irq_mode = IPC_TRIGGER_MODE_IRQ;
490 ret = pci_enable_device(pdev);
494 ret = pci_request_regions(pdev, "intel_pmc_ipc");
498 pci_resource = pci_resource_start(pdev, 0);
499 len = pci_resource_len(pdev, 0);
500 if (!pci_resource || !len) {
501 dev_err(&pdev->dev, "Failed to get resource\n");
505 init_completion(&ipcdev.cmd_complete);
507 if (request_irq(pdev->irq, ioc, 0, "intel_pmc_ipc", &ipcdev)) {
508 dev_err(&pdev->dev, "Failed to request irq\n");
512 ipcdev.ipc_base = ioremap_nocache(pci_resource, len);
513 if (!ipcdev.ipc_base) {
514 dev_err(&pdev->dev, "Failed to ioremap ipc base\n");
515 free_irq(pdev->irq, &ipcdev);
522 static void ipc_pci_remove(struct pci_dev *pdev)
524 free_irq(pdev->irq, &ipcdev);
525 pci_release_regions(pdev);
527 iounmap(ipcdev.ipc_base);
531 static const struct pci_device_id ipc_pci_ids[] = {
532 {PCI_VDEVICE(INTEL, 0x0a94), 0},
533 {PCI_VDEVICE(INTEL, 0x1a94), 0},
534 {PCI_VDEVICE(INTEL, 0x5a94), 0},
537 MODULE_DEVICE_TABLE(pci, ipc_pci_ids);
539 static struct pci_driver ipc_pci_driver = {
540 .name = "intel_pmc_ipc",
541 .id_table = ipc_pci_ids,
542 .probe = ipc_pci_probe,
543 .remove = ipc_pci_remove,
546 static ssize_t intel_pmc_ipc_simple_cmd_store(struct device *dev,
547 struct device_attribute *attr,
548 const char *buf, size_t count)
554 ret = sscanf(buf, "%d %d", &cmd, &subcmd);
556 dev_err(dev, "Error args\n");
560 ret = intel_pmc_ipc_simple_command(cmd, subcmd);
562 dev_err(dev, "command %d error with %d\n", cmd, ret);
565 return (ssize_t)count;
568 static ssize_t intel_pmc_ipc_northpeak_store(struct device *dev,
569 struct device_attribute *attr,
570 const char *buf, size_t count)
576 if (kstrtoul(buf, 0, &val))
583 ret = intel_pmc_ipc_simple_command(PMC_IPC_NORTHPEAK_CTRL, subcmd);
585 dev_err(dev, "command north %d error with %d\n", subcmd, ret);
588 return (ssize_t)count;
591 static DEVICE_ATTR(simplecmd, S_IWUSR,
592 NULL, intel_pmc_ipc_simple_cmd_store);
593 static DEVICE_ATTR(northpeak, S_IWUSR,
594 NULL, intel_pmc_ipc_northpeak_store);
596 static struct attribute *intel_ipc_attrs[] = {
597 &dev_attr_northpeak.attr,
598 &dev_attr_simplecmd.attr,
602 static const struct attribute_group intel_ipc_group = {
603 .attrs = intel_ipc_attrs,
606 static struct resource punit_res_array[] = {
609 .flags = IORESOURCE_MEM,
612 .flags = IORESOURCE_MEM,
616 .flags = IORESOURCE_MEM,
619 .flags = IORESOURCE_MEM,
623 .flags = IORESOURCE_MEM,
626 .flags = IORESOURCE_MEM,
630 #define TCO_RESOURCE_ACPI_IO 0
631 #define TCO_RESOURCE_SMI_EN_IO 1
632 #define TCO_RESOURCE_GCR_MEM 2
633 static struct resource tco_res[] = {
636 .flags = IORESOURCE_IO,
640 .flags = IORESOURCE_IO,
644 static struct itco_wdt_platform_data tco_info = {
645 .name = "Apollo Lake SoC",
647 .no_reboot_priv = &ipcdev,
648 .update_no_reboot_bit = update_no_reboot_bit,
651 #define TELEMETRY_RESOURCE_PUNIT_SSRAM 0
652 #define TELEMETRY_RESOURCE_PMC_SSRAM 1
653 static struct resource telemetry_res[] = {
656 .flags = IORESOURCE_MEM,
659 .flags = IORESOURCE_MEM,
663 static int ipc_create_punit_device(void)
665 struct platform_device *pdev;
666 const struct platform_device_info pdevinfo = {
667 .parent = ipcdev.dev,
668 .name = PUNIT_DEVICE_NAME,
670 .res = punit_res_array,
671 .num_res = ARRAY_SIZE(punit_res_array),
674 pdev = platform_device_register_full(&pdevinfo);
676 return PTR_ERR(pdev);
678 ipcdev.punit_dev = pdev;
683 static int ipc_create_tco_device(void)
685 struct platform_device *pdev;
686 struct resource *res;
687 const struct platform_device_info pdevinfo = {
688 .parent = ipcdev.dev,
689 .name = TCO_DEVICE_NAME,
692 .num_res = ARRAY_SIZE(tco_res),
694 .size_data = sizeof(tco_info),
697 res = tco_res + TCO_RESOURCE_ACPI_IO;
698 res->start = ipcdev.acpi_io_base + TCO_BASE_OFFSET;
699 res->end = res->start + TCO_REGS_SIZE - 1;
701 res = tco_res + TCO_RESOURCE_SMI_EN_IO;
702 res->start = ipcdev.acpi_io_base + SMI_EN_OFFSET;
703 res->end = res->start + SMI_EN_SIZE - 1;
705 pdev = platform_device_register_full(&pdevinfo);
707 return PTR_ERR(pdev);
709 ipcdev.tco_dev = pdev;
714 static int ipc_create_telemetry_device(void)
716 struct platform_device *pdev;
717 struct resource *res;
718 const struct platform_device_info pdevinfo = {
719 .parent = ipcdev.dev,
720 .name = TELEMETRY_DEVICE_NAME,
722 .res = telemetry_res,
723 .num_res = ARRAY_SIZE(telemetry_res),
726 res = telemetry_res + TELEMETRY_RESOURCE_PUNIT_SSRAM;
727 res->start = ipcdev.telem_punit_ssram_base;
728 res->end = res->start + ipcdev.telem_punit_ssram_size - 1;
730 res = telemetry_res + TELEMETRY_RESOURCE_PMC_SSRAM;
731 res->start = ipcdev.telem_pmc_ssram_base;
732 res->end = res->start + ipcdev.telem_pmc_ssram_size - 1;
734 pdev = platform_device_register_full(&pdevinfo);
736 return PTR_ERR(pdev);
738 ipcdev.telemetry_dev = pdev;
743 static int ipc_create_pmc_devices(void)
747 /* If we have ACPI based watchdog use that instead */
748 if (!acpi_has_watchdog()) {
749 ret = ipc_create_tco_device();
751 dev_err(ipcdev.dev, "Failed to add tco platform device\n");
756 ret = ipc_create_punit_device();
758 dev_err(ipcdev.dev, "Failed to add punit platform device\n");
759 platform_device_unregister(ipcdev.tco_dev);
762 if (!ipcdev.telem_res_inval) {
763 ret = ipc_create_telemetry_device();
766 "Failed to add telemetry platform device\n");
772 static int ipc_plat_get_res(struct platform_device *pdev)
774 struct resource *res, *punit_res;
778 res = platform_get_resource(pdev, IORESOURCE_IO,
779 PLAT_RESOURCE_ACPI_IO_INDEX);
781 dev_err(&pdev->dev, "Failed to get io resource\n");
784 size = resource_size(res);
785 ipcdev.acpi_io_base = res->start;
786 ipcdev.acpi_io_size = size;
787 dev_info(&pdev->dev, "io res: %pR\n", res);
789 punit_res = punit_res_array;
790 /* This is index 0 to cover BIOS data register */
791 res = platform_get_resource(pdev, IORESOURCE_MEM,
792 PLAT_RESOURCE_BIOS_DATA_INDEX);
794 dev_err(&pdev->dev, "Failed to get res of punit BIOS data\n");
798 dev_info(&pdev->dev, "punit BIOS data res: %pR\n", res);
800 /* This is index 1 to cover BIOS interface register */
801 res = platform_get_resource(pdev, IORESOURCE_MEM,
802 PLAT_RESOURCE_BIOS_IFACE_INDEX);
804 dev_err(&pdev->dev, "Failed to get res of punit BIOS iface\n");
808 dev_info(&pdev->dev, "punit BIOS interface res: %pR\n", res);
810 /* This is index 2 to cover ISP data register, optional */
811 res = platform_get_resource(pdev, IORESOURCE_MEM,
812 PLAT_RESOURCE_ISP_DATA_INDEX);
816 dev_info(&pdev->dev, "punit ISP data res: %pR\n", res);
819 /* This is index 3 to cover ISP interface register, optional */
820 res = platform_get_resource(pdev, IORESOURCE_MEM,
821 PLAT_RESOURCE_ISP_IFACE_INDEX);
825 dev_info(&pdev->dev, "punit ISP interface res: %pR\n", res);
828 /* This is index 4 to cover GTD data register, optional */
829 res = platform_get_resource(pdev, IORESOURCE_MEM,
830 PLAT_RESOURCE_GTD_DATA_INDEX);
834 dev_info(&pdev->dev, "punit GTD data res: %pR\n", res);
837 /* This is index 5 to cover GTD interface register, optional */
838 res = platform_get_resource(pdev, IORESOURCE_MEM,
839 PLAT_RESOURCE_GTD_IFACE_INDEX);
843 dev_info(&pdev->dev, "punit GTD interface res: %pR\n", res);
846 res = platform_get_resource(pdev, IORESOURCE_MEM,
847 PLAT_RESOURCE_IPC_INDEX);
849 dev_err(&pdev->dev, "Failed to get ipc resource\n");
852 size = PLAT_RESOURCE_IPC_SIZE + PLAT_RESOURCE_GCR_SIZE;
854 if (!request_mem_region(res->start, size, pdev->name)) {
855 dev_err(&pdev->dev, "Failed to request ipc resource\n");
858 addr = ioremap_nocache(res->start, size);
860 dev_err(&pdev->dev, "I/O memory remapping failed\n");
861 release_mem_region(res->start, size);
864 ipcdev.ipc_base = addr;
866 ipcdev.gcr_mem_base = addr + PLAT_RESOURCE_GCR_OFFSET;
867 dev_info(&pdev->dev, "ipc res: %pR\n", res);
869 ipcdev.telem_res_inval = 0;
870 res = platform_get_resource(pdev, IORESOURCE_MEM,
871 PLAT_RESOURCE_TELEM_SSRAM_INDEX);
873 dev_err(&pdev->dev, "Failed to get telemetry ssram resource\n");
874 ipcdev.telem_res_inval = 1;
876 ipcdev.telem_punit_ssram_base = res->start +
877 TELEM_PUNIT_SSRAM_OFFSET;
878 ipcdev.telem_punit_ssram_size = TELEM_SSRAM_SIZE;
879 ipcdev.telem_pmc_ssram_base = res->start +
880 TELEM_PMC_SSRAM_OFFSET;
881 ipcdev.telem_pmc_ssram_size = TELEM_SSRAM_SIZE;
882 dev_info(&pdev->dev, "telemetry ssram res: %pR\n", res);
889 * intel_pmc_s0ix_counter_read() - Read S0ix residency.
890 * @data: Out param that contains current S0ix residency count.
892 * Return: an error code or 0 on success.
894 int intel_pmc_s0ix_counter_read(u64 *data)
898 if (!ipcdev.has_gcr_regs)
901 deep = gcr_data_readq(PMC_GCR_TELEM_DEEP_S0IX_REG);
902 shlw = gcr_data_readq(PMC_GCR_TELEM_SHLW_S0IX_REG);
904 *data = S0IX_RESIDENCY_IN_USECS(deep, shlw);
908 EXPORT_SYMBOL_GPL(intel_pmc_s0ix_counter_read);
911 static const struct acpi_device_id ipc_acpi_ids[] = {
915 MODULE_DEVICE_TABLE(acpi, ipc_acpi_ids);
918 static int ipc_plat_probe(struct platform_device *pdev)
920 struct resource *res;
923 ipcdev.dev = &pdev->dev;
924 ipcdev.irq_mode = IPC_TRIGGER_MODE_IRQ;
925 init_completion(&ipcdev.cmd_complete);
927 ipcdev.irq = platform_get_irq(pdev, 0);
928 if (ipcdev.irq < 0) {
929 dev_err(&pdev->dev, "Failed to get irq\n");
933 ret = ipc_plat_get_res(pdev);
935 dev_err(&pdev->dev, "Failed to request resource\n");
939 ret = ipc_create_pmc_devices();
941 dev_err(&pdev->dev, "Failed to create pmc devices\n");
945 if (request_irq(ipcdev.irq, ioc, IRQF_NO_SUSPEND,
946 "intel_pmc_ipc", &ipcdev)) {
947 dev_err(&pdev->dev, "Failed to request irq\n");
952 ret = sysfs_create_group(&pdev->dev.kobj, &intel_ipc_group);
954 dev_err(&pdev->dev, "Failed to create sysfs group %d\n",
959 ipcdev.has_gcr_regs = true;
963 free_irq(ipcdev.irq, &ipcdev);
965 platform_device_unregister(ipcdev.tco_dev);
966 platform_device_unregister(ipcdev.punit_dev);
967 platform_device_unregister(ipcdev.telemetry_dev);
969 iounmap(ipcdev.ipc_base);
970 res = platform_get_resource(pdev, IORESOURCE_MEM,
971 PLAT_RESOURCE_IPC_INDEX);
973 release_mem_region(res->start,
974 PLAT_RESOURCE_IPC_SIZE +
975 PLAT_RESOURCE_GCR_SIZE);
980 static int ipc_plat_remove(struct platform_device *pdev)
982 struct resource *res;
984 sysfs_remove_group(&pdev->dev.kobj, &intel_ipc_group);
985 free_irq(ipcdev.irq, &ipcdev);
986 platform_device_unregister(ipcdev.tco_dev);
987 platform_device_unregister(ipcdev.punit_dev);
988 platform_device_unregister(ipcdev.telemetry_dev);
989 iounmap(ipcdev.ipc_base);
990 res = platform_get_resource(pdev, IORESOURCE_MEM,
991 PLAT_RESOURCE_IPC_INDEX);
993 release_mem_region(res->start,
994 PLAT_RESOURCE_IPC_SIZE +
995 PLAT_RESOURCE_GCR_SIZE);
1001 static struct platform_driver ipc_plat_driver = {
1002 .remove = ipc_plat_remove,
1003 .probe = ipc_plat_probe,
1005 .name = "pmc-ipc-plat",
1006 .acpi_match_table = ACPI_PTR(ipc_acpi_ids),
1010 static int __init intel_pmc_ipc_init(void)
1014 ret = platform_driver_register(&ipc_plat_driver);
1016 pr_err("Failed to register PMC ipc platform driver\n");
1019 ret = pci_register_driver(&ipc_pci_driver);
1021 pr_err("Failed to register PMC ipc pci driver\n");
1022 platform_driver_unregister(&ipc_plat_driver);
1028 static void __exit intel_pmc_ipc_exit(void)
1030 pci_unregister_driver(&ipc_pci_driver);
1031 platform_driver_unregister(&ipc_plat_driver);
1035 MODULE_DESCRIPTION("Intel PMC IPC driver");
1036 MODULE_LICENSE("GPL");
1038 /* Some modules are dependent on this, so init earlier */
1039 fs_initcall(intel_pmc_ipc_init);
1040 module_exit(intel_pmc_ipc_exit);