platform/x86: Rework intel_scu_ipc and intel_pmc_ipc drivers
Subsystems (11)
Mika Westerberg
maintainerv4 cover platform/x86: Rework intel_scu_ipc and intel_pmc_ipc drivers
Hi,
Currently both intel_scu_ipc.c and intel_pmc_ipc.c implement the same SCU IPC communications with minor differences. This duplication does not make much sense so this series reworks the two drivers so that there is only a single implementation of the SCU IPC. In addition to that the API will be updated to take SCU instance pointer as an argument, and most of the callers will be converted to this new API. The old API is left there but the plan is to get rid the callers and then the old API as well (this is something we are working with Andy Shevchenko).
The intel_pmc_ipc.c is then moved under MFD which suits better for this kind of a driver that pretty much sets up the SCU IPC and then creates a bunch of platform devices for the things sitting behind the PMC. The driver is renamed to intel_pmc_bxt.c which should follow the existing conventions under drivers/mfd (and it is only meant for Intel Broxton derivatives).
Previous version of the series:
v3: https://www.spinics.net/lists/platform-driver-x86/msg20583.html
v2: https://www.spinics.net/lists/platform-driver-x86/msg20446.html
v1: https://www.spinics.net/lists/platform-driver-x86/msg20359.html
Changes from v3:
* Rename intel_scu_ipc_probe() to intel_scu_ipc_register() and _remove() to _unregister() accordingly.
* Make intel_scu_ipc_register() to perform handle resource request and ioremap itself.
* Add devm_intel_scu_ipc_register().
* Improve kernel-docs of struct intel_soc_pmic.
* Add Documentation/ABI/obsolete/sysfs-driver-intel_pmc_bxt to document the two sysfs attributes the driver exposes.
* Fix typos in the MFD driver
* Drop gcr_data_readq() wrapper
* No need to check for !pmcdev.gcr_mem_base in the MFD accessors
* Allocate PMC instance dynamically and pass this from the callers (telemetry) as well
* Take the lock in intel_pmc_s0ix_counter_read() to be consistent with other register accessors (and serialize them).
* Use kstrtoul() return value directly (new patch)
* Use static const MFD cell and resources where possible. Take a copy of these before they get populated and passed to the MFD code.
* Use module_platform_driver() in the MFD driver
* Drop dev_dbg() prints.
* Return -EINVAL instead of -ENXIO when platform_get_resource() for mandatory resources.
* Clarify "residency" in intel_pmc_s0ix_counter_read().
Did not convert to use regmap because register access is 64-bit and it looks like regmap read/write API does not support this.
I also dropped Andy's reviewed-by tag from the MFD patch (37/38) because it changed quite much from the previous version.
Changes from v2:
* Added review tags from Andy
* Patch 12: Put intel_scu_ipc_probe() prototype and implementation in one line
* Patch 12: Correct wording in Kconfig description.
* Patch 12: Put devm_request_irq() in one line.
* Patch 14: Add blank line before intel_scu_ipc_dev_update() in header.
* Patch 14: intel_scu_ipc_dev_update() move 'u8 data' to the next line in header.
* Patch 14: Drop outlen check in intel_scu_ipc_dev_command_with_size().
* Patch 16: Added Guenter's ack.
* Patch 25: Put intel_scu_ipc_dev_command() call in one line.
* Patch 25: Put intel_scu_ipc_dev_simple_command() call in one line.
* Patch 32: Drop X86_INTEL_MID dependency from INTEL_SCU_PCI.
* Patch 34: Split MFD_INTEL_PMC_BXT dependencies one per line.
* Patch 35: Reorder to happen before patch 34.
* Patch 35: Drop comma from terminating line.
Changes from v1:
* Update changelog of patch 16 according to what the patch actually does.
* Add kernel-doc for struct intel_soc_pmic.
* Move octal permission patch to be before MFD conversion.
* Convert the intel_pmc_bxt.c to MFD APIs whilst it is being moved under drivers/mfd.
I would prefer this to be merged through platform/x86 or MFD trees assuming there are no objections.
I have tested this on Intel Edison (Merrifield) and Joule (Broxton-M).
Mika Westerberg (38):
platform/x86: intel_mid_powerbtn: Take a copy of ddata platform/x86: intel_scu_ipcutil: Remove default y from Kconfig platform/x86: intel_scu_ipc: Add constants for register offsets platform/x86: intel_scu_ipc: Remove Lincroft support
platform/x86: intel_scu_ipc: Drop intel_scu_ipc_i2c_cntrl() platform/x86: intel_scu_ipc: Fix interrupt support
platform/x86: intel_scu_ipc: Sleeping is fine when polling platform/x86: intel_scu_ipc: Drop unused prototype intel_scu_ipc_fw_update() platform/x86: intel_scu_ipc: Drop unused macros
platform/x86: intel_scu_ipc: Drop intel_scu_ipc_io[read|write][8|16]() platform/x86: intel_scu_ipc: Drop intel_scu_ipc_raw_command() platform/x86: intel_scu_ipc: Split out SCU IPC functionality from the SCU driver platform/x86: intel_scu_ipc: Reformat kernel-doc comments of exported functions platform/x86: intel_scu_ipc: Introduce new SCU IPC API platform/x86: intel_mid_powerbtn: Convert to use new SCU IPC API
watchdog: intel-mid_wdt: Convert to use new SCU IPC API platform/x86: intel_scu_ipcutil: Convert to use new SCU IPC API platform/x86: intel_pmc_ipc: Make intel_pmc_gcr_update() static platform/x86: intel_pmc_ipc: Make intel_pmc_ipc_simple_command() static platform/x86: intel_pmc_ipc: Make intel_pmc_ipc_raw_cmd() static platform/x86: intel_pmc_ipc: Drop intel_pmc_gcr_read() and intel_pmc_gcr_write() platform/x86: intel_pmc_ipc: Drop ipc_data_readb()
platform/x86: intel_pmc_ipc: Get rid of unnecessary includes platform/x86: intel_scu_ipc: Add managed function to register SCU IPC platform/x86: intel_pmc_ipc: Start using SCU IPC
mfd: intel_soc_pmic: Add SCU IPC member to struct intel_soc_pmic
mfd: intel_soc_pmic_bxtwc: Convert to use new SCU IPC API
mfd: intel_soc_pmic_mrfld: Convert to use new SCU IPC API platform/x86: intel_telemetry: Convert to use new SCU IPC API platform/x86: intel_pmc_ipc: Drop intel_pmc_ipc_command() x86/platform/intel-mid: Add empty stubs for intel_scu_devices_[create|destroy]() platform/x86: intel_pmc_ipc: Move PCI IDs to intel_scu_pcidrv.c platform/x86: intel_pmc_ipc: Use octal permissions in sysfs attributes platform/x86: intel_pmc_ipc: Propagate error from kstrtoul() platform/x86: intel_pmc_ipc: Switch to use driver->dev_groups platform/x86: intel_telemetry: Add telemetry_get_pltdata() platform/x86: intel_pmc_ipc: Convert to MFD
MAINTAINERS: Update entry for Intel Broxton PMC driver
.../ABI/obsolete/sysfs-driver-intel_pmc_bxt | 22 + MAINTAINERS | 13 +- arch/x86/Kconfig | 2 +- arch/x86/include/asm/intel-mid.h | 9 +- arch/x86/include/asm/intel_pmc_ipc.h | 91 -- arch/x86/include/asm/intel_scu_ipc.h | 107 +- arch/x86/include/asm/intel_scu_ipc_legacy.h | 76 ++ arch/x86/include/asm/intel_telemetry.h | 5 + drivers/mfd/Kconfig | 20 +- drivers/mfd/Makefile | 1 + drivers/mfd/intel_pmc_bxt.c | 496 ++++++++ drivers/mfd/intel_soc_pmic_bxtwc.c | 22 +- drivers/mfd/intel_soc_pmic_mrfld.c | 10 +- drivers/platform/x86/Kconfig | 49 +- drivers/platform/x86/Makefile | 2 +- drivers/platform/x86/intel_mid_powerbtn.c | 20 +- drivers/platform/x86/intel_pmc_ipc.c | 1031 ----------------- drivers/platform/x86/intel_scu_ipc.c | 732 ++++++------ drivers/platform/x86/intel_scu_ipcutil.c | 43 +- drivers/platform/x86/intel_scu_pcidrv.c | 68 ++ drivers/platform/x86/intel_telemetry_core.c | 12 + .../platform/x86/intel_telemetry_debugfs.c | 12 +- drivers/platform/x86/intel_telemetry_pltdrv.c | 103 +- drivers/usb/typec/tcpm/Kconfig | 2 +- drivers/watchdog/intel-mid_wdt.c | 53 +- include/linux/mfd/intel_pmc_bxt.h | 21 + include/linux/mfd/intel_soc_pmic.h | 15 + 27 files changed, 1348 insertions(+), 1689 deletions(-) create mode 100644 Documentation/ABI/obsolete/sysfs-driver-intel_pmc_bxt delete mode 100644 arch/x86/include/asm/intel_pmc_ipc.h create mode 100644 arch/x86/include/asm/intel_scu_ipc_legacy.h create mode 100644 drivers/mfd/intel_pmc_bxt.c delete mode 100644 drivers/platform/x86/intel_pmc_ipc.c create mode 100644 drivers/platform/x86/intel_scu_pcidrv.c create mode 100644 include/linux/mfd/intel_pmc_bxt.h
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 1/38 platform/x86: intel_mid_powerbtn: Take a copy of ddata
The driver gets driver_data from memory that is marked as const (which is probably put to read-only memory) and it then modifies it. This likely causes some sort of fault to happen.
Fix this by taking a copy of the structure.
--- drivers/platform/x86/intel_mid_powerbtn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/x86/intel_mid_powerbtn.c +3 -2
@@ -146,9 +146,10 @@ static int mid_pb_probe(struct platform_device *pdev)input_set_capability (input,EV_KEY ,KEY_POWER ); - ddata = (struct mid_pb_ddata *)id->driver_data; + ddata =devm_kmemdup (&pdev->dev, (void *)id->driver_data, +sizeof (*ddata),GFP_KERNEL );if (!ddata) -return -ENODATA ; +return -ENOMEM ; ddata->dev = &pdev->dev; ddata->irq = irq;
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 2/38 platform/x86: intel_scu_ipcutil: Remove default y from Kconfig
In reply to Mika WesterbergThis driver is by no means essential for system to boot up so remove default y from it.
--- drivers/platform/x86/Kconfig | 1 - 1 file changed, 1 deletion(-)
drivers/platform/x86/Kconfig +0 -1
@@ -997,7 +997,6 @@ config INTEL_SCU_IPC config INTEL_SCU_IPC_UTIL tristate "Intel SCU IPC utility driver" depends on INTEL_SCU_IPC - default y ---help--- The IPC Util driver provides an interface with the SCU enabling low level access for debug work and updating the firmware. Say
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 3/38 platform/x86: intel_scu_ipc: Add constants for register offsets
In reply to Mika WesterbergThis makes the code more readable. These are taken from intel_pmc_ipc.c which implements the same thing.
--- drivers/platform/x86/intel_scu_ipc.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
drivers/platform/x86/intel_scu_ipc.c +13 -9
@@ -99,11 +99,15 @@ struct intel_scu_ipc_dev {static struct intel_scu_ipc_dev ipcdev;/* Only one for now */ +#define IPC_STATUS 0x04 +#define IPC_STATUS_ERR BIT(1) +#define IPC_STATUS_BUSY BIT(0) +/* -* IPC Read Buffer (Read Only): -* 16 byte buffer for receiving data from SCU, if IPC command -* processing results in response data +* IPC Write/Read Buffers: +* 16 byte buffer for sending and receiving data to and from SCU. */ +#define IPC_WRITE_BUFFER 0x80#define IPC_READ_BUFFER 0x90#define IPC_I2C_CNTRL_ADDR 0
@@ -135,7 +139,7 @@ static inline void ipc_command(struct intel_scu_ipc_dev *scu, u32 cmd)*/ static inline void ipc_data_writel (struct intel_scu_ipc_dev *scu,u32 data,u32 offset) { -writel (data, scu->ipc_base +0x80 + offset); +writel (data, scu->ipc_base +IPC_WRITE_BUFFER + offset); }/*
@@ -147,7 +151,7 @@ static inline void ipc_data_writel(struct intel_scu_ipc_dev *scu, u32 data, u32*/ static inline u8 ipc_read_status (struct intel_scu_ipc_dev *scu) { -return __raw_readl (scu->ipc_base +0x04 ); +return __raw_readl (scu->ipc_base +IPC_STATUS ); }/* Read ipc byte data */
@@ -169,17 +173,17 @@ static inline int busy_loop(struct intel_scu_ipc_dev *scu)u32 loop_count =100000 ;/* break if scu doesn't reset busy bit after huge retry */ -while ((status &BIT (0 )) && --loop_count) { +while ((status &IPC_STATUS_BUSY ) && --loop_count) {udelay (1 );/* scu processing time is in few u secods */ status =ipc_read_status (scu); } -if (status &BIT (0 )) { +if (status &IPC_STATUS_BUSY ) {dev_err (scu->dev,"IPC timed out" );return -ETIMEDOUT ; } -if (status &BIT (1 )) +if (status &IPC_STATUS_ERR )return -EIO ;return 0 ;
@@ -196,7 +200,7 @@ static inline int ipc_wait_for_interrupt(struct intel_scu_ipc_dev *scu) } status =ipc_read_status (scu); -if (status &BIT (1 )) +if (status &IPC_STATUS_ERR )return -EIO ;return 0 ;
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 4/38 platform/x86: intel_scu_ipc: Remove Lincroft support
In reply to Mika WesterbergMoorestown support was removed years ago with by the commit 1a8359e411eb ("x86/mid: Remove Intel Moorestown"). Lincroft is the CPU side chip of Moorestown and not supported anymore so remove the code from the driver.
--- drivers/platform/x86/intel_scu_ipc.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/platform/x86/intel_scu_ipc.c +0 -8
@@ -58,7 +58,6 @@#define IPC_RWBUF_SIZE 20/* IPC Read buffer Size */ #define IPC_IOC 0x100/* IPC command register IOC bit */ -#define PCI_DEVICE_ID_LINCROFT 0x082a#define PCI_DEVICE_ID_PENWELL 0x080e#define PCI_DEVICE_ID_CLOVERVIEW 0x08ea#define PCI_DEVICE_ID_TANGIER 0x11a0
@@ -70,12 +69,6 @@ struct intel_scu_ipc_pdata_t {u8 irq_mode; }; -static const struct intel_scu_ipc_pdata_t intel_scu_ipc_lincroft_pdata = { - .i2c_base =0xff12b000 , - .i2c_len =0x10 , - .irq_mode =0 , -}; -/* Penwell and Cloverview */ static const struct intel_scu_ipc_pdata_t intel_scu_ipc_penwell_pdata = { .i2c_base =0xff12b000 ,
@@ -677,7 +670,6 @@ static int ipc_probe(struct pci_dev *pdev, const struct pci_device_id *id)#define SCU_DEVICE (id, pdata) {PCI_VDEVICE(INTEL, id), (kernel_ulong_t)&pdata}static const struct pci_device_id pci_ids[] = { -SCU_DEVICE (PCI_DEVICE_ID_LINCROFT , intel_scu_ipc_lincroft_pdata),SCU_DEVICE (PCI_DEVICE_ID_PENWELL , intel_scu_ipc_penwell_pdata),SCU_DEVICE (PCI_DEVICE_ID_CLOVERVIEW , intel_scu_ipc_penwell_pdata),SCU_DEVICE (PCI_DEVICE_ID_TANGIER , intel_scu_ipc_tangier_pdata),
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 5/38 platform/x86: intel_scu_ipc: Drop intel_scu_ipc_i2c_cntrl()
In reply to Mika WesterbergThere are no existing users for this functionality so drop it from the driver completely.
--- arch/x86/include/asm/intel_scu_ipc.h | 3 -- drivers/platform/x86/intel_scu_ipc.c | 62 ---------------------------- 2 files changed, 65 deletions(-)
arch/x86/include/asm/intel_scu_ipc.h +0 -3
@@ -53,9 +53,6 @@ int intel_scu_ipc_command(int cmd, int sub, u32 *in, int inlen,int intel_scu_ipc_raw_command (int cmd,int sub,u8 *in,int inlen,u32 *out,int outlen,u32 dptr,u32 sptr); -/* I2C control api */ -int intel_scu_ipc_i2c_cntrl (u32 addr,u32 *data); -/* Update FW version */ int intel_scu_ipc_fw_update (u8 *buffer,u32 length);
drivers/platform/x86/intel_scu_ipc.c +0 -62
101 lines not on this page · raw message
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 6/38 platform/x86: intel_scu_ipc: Fix interrupt support
In reply to Mika WesterbergCurrently the driver has disabled interrupt support for Tangier but actually interrupt works just fine if the command is not written twice in a row. Also we need to ack the interrupt in the handler.
--- drivers/platform/x86/intel_scu_ipc.c | 48 ++++++---------------------- 1 file changed, 10 insertions(+), 38 deletions(-)
drivers/platform/x86/intel_scu_ipc.c +10 -38
@@ -58,24 +58,6 @@#define IPC_RWBUF_SIZE 20/* IPC Read buffer Size */ #define IPC_IOC 0x100/* IPC command register IOC bit */ -#define PCI_DEVICE_ID_PENWELL 0x080e -#define PCI_DEVICE_ID_CLOVERVIEW 0x08ea -#define PCI_DEVICE_ID_TANGIER 0x11a0 - -/* intel scu ipc driver data */ -struct intel_scu_ipc_pdata_t { -u8 irq_mode; -}; - -/* Penwell and Cloverview */ -static const struct intel_scu_ipc_pdata_t intel_scu_ipc_penwell_pdata = { - .irq_mode =1 , -}; - -static const struct intel_scu_ipc_pdata_t intel_scu_ipc_tangier_pdata = { - .irq_mode =0 , -}; -struct intel_scu_ipc_dev {struct device *dev;void __iomem *ipc_base;
@@ -86,6 +68,7 @@ struct intel_scu_ipc_dev {static struct intel_scu_ipc_dev ipcdev;/* Only one for now */ #define IPC_STATUS 0x04 +#define IPC_STATUS_IRQ BIT(2)#define IPC_STATUS_ERR BIT(1)#define IPC_STATUS_BUSY BIT(0)
@@ -107,11 +90,8 @@ static DEFINE_MUTEX(ipclock); /* lock used to prevent multiple call to SCU */*/ static inline void ipc_command (struct intel_scu_ipc_dev *scu,u32 cmd) { -if (scu->irq_mode) { -reinit_completion (&scu->cmd_complete); -writel (cmd |IPC_IOC , scu->ipc_base); - } -writel (cmd, scu->ipc_base); +reinit_completion (&scu->cmd_complete); +writel (cmd |IPC_IOC , scu->ipc_base); }/*
@@ -549,9 +529,10 @@ EXPORT_SYMBOL_GPL(intel_scu_ipc_raw_command);static irqreturn_t ioc (int irq,void *dev_id) {struct intel_scu_ipc_dev *scu = dev_id; +int status =ipc_read_status (scu); -if (scu->irq_mode) -complete (&scu->cmd_complete); +writel (status |IPC_STATUS_IRQ , scu->ipc_base +IPC_STATUS ); +complete (&scu->cmd_complete);return IRQ_HANDLED ; }
@@ -568,17 +549,10 @@ static int ipc_probe(struct pci_dev *pdev, const struct pci_device_id *id) {int err;struct intel_scu_ipc_dev *scu = &ipcdev; -struct intel_scu_ipc_pdata_t *pdata;if (scu->dev)/* We support only one SCU */ return -EBUSY ; - pdata = (struct intel_scu_ipc_pdata_t *)id->driver_data; -if (!pdata) -return -ENODEV ; - - scu->irq_mode = pdata->irq_mode; - err =pcim_enable_device (pdev);if (err)return err;
@@ -605,13 +579,11 @@ static int ipc_probe(struct pci_dev *pdev, const struct pci_device_id *id)return 0 ; } -#define SCU_DEVICE (id, pdata) {PCI_VDEVICE(INTEL, id), (kernel_ulong_t)&pdata} -static const struct pci_device_id pci_ids[] = { -SCU_DEVICE (PCI_DEVICE_ID_PENWELL , intel_scu_ipc_penwell_pdata), -SCU_DEVICE (PCI_DEVICE_ID_CLOVERVIEW , intel_scu_ipc_penwell_pdata), -SCU_DEVICE (PCI_DEVICE_ID_TANGIER , intel_scu_ipc_tangier_pdata), - {} + {PCI_VDEVICE (INTEL ,0x080e ) }, + {PCI_VDEVICE (INTEL ,0x08ea ) }, + {PCI_VDEVICE (INTEL ,0x11a0 ) }, + { } };static struct pci_driver ipc_driver = {
Signature · 1 line
2.24.1
Greg Kroah-Hartman
maintainerRe: [PATCH v4 06/38] platform/x86: intel_scu_ipc: Fix interrupt support
Quoted 6 lines · Mika Westerberg
Currently the driver has disabled interrupt support for Tangier but actually interrupt works just fine if the command is not written twice in a row. Also we need to ack the interrupt in the handler.
Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>
Why isn't this patch 1 of the series and cc:ed to stable?
thanks,
greg k-h
Mika Westerberg
maintainerRe: [PATCH v4 06/38] platform/x86: intel_scu_ipc: Fix interrupt support
Quoted 9 lines · Greg Kroah-Hartman
Quoted 6 lines · Mika Westerberg
Currently the driver has disabled interrupt support for Tangier but actually interrupt works just fine if the command is not written twice in a row. Also we need to ack the interrupt in the handler.
Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Why isn't this patch 1 of the series and cc:ed to stable?
My mistake, sorry about that. I'll move it to be first and add stable tag.
Mika Westerberg
maintainerPATCH v4 7/38 platform/x86: intel_scu_ipc: Sleeping is fine when polling
In reply to Mika WesterbergThere is no reason why the driver would need to block other threads from running the CPU while it is waiting for the SCU IPC to complete its work. For this reason switch the driver to use usleep_range() instead with a bit more relaxed polling loop.
Also add constant for the timeout and use the same value for both polling and interrupt modes.
--- drivers/platform/x86/intel_scu_ipc.c | 29 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/platform/x86/intel_scu_ipc.c +14 -15
@@ -79,6 +79,9 @@ static struct intel_scu_ipc_dev ipcdev; /* Only one for now */#define IPC_WRITE_BUFFER 0x80#define IPC_READ_BUFFER 0x90 +/* Timeout in jiffies */ +#define IPC_TIMEOUT (3 * HZ) +static DEFINE_MUTEX (ipclock);/* lock used to prevent multiple call to SCU */ /*
@@ -132,24 +135,20 @@ static inline u32 ipc_data_readl(struct intel_scu_ipc_dev *scu, u32 offset)/* Wait till scu status is busy */ static inline int busy_loop (struct intel_scu_ipc_dev *scu) { -u32 status =ipc_read_status (scu); -u32 loop_count =100000 ; +unsigned long end = jiffies +msecs_to_jiffies (IPC_TIMEOUT ); -/* break if scu doesn't reset busy bit after huge retry */ -while ((status &IPC_STATUS_BUSY ) && --loop_count) { -udelay (1 );/* scu processing time is in few u secods */ - status =ipc_read_status (scu); - } +do { +u32 status; -if (status &IPC_STATUS_BUSY ) { -dev_err (scu->dev,"IPC timed out" ); -return -ETIMEDOUT ; - } + status =ipc_read_status (scu); +if (!(status &IPC_STATUS_BUSY )) +return (status &IPC_STATUS_ERR ) ? -EIO :0 ; -if (status &IPC_STATUS_ERR ) -return -EIO ; +usleep_range (50 ,100 ); + }while (time_before (jiffies, end)); -return 0 ; +dev_err (scu->dev,"IPC timed out" ); +return -ETIMEDOUT ; }/* Wait till ipc ioc interrupt is received or timeout in 3 HZ */
@@ -157,7 +156,7 @@ static inline int ipc_wait_for_interrupt(struct intel_scu_ipc_dev *scu) {int status; -if (!wait_for_completion_timeout (&scu->cmd_complete,3 *HZ )) { +if (!wait_for_completion_timeout (&scu->cmd_complete,IPC_TIMEOUT )) {dev_err (scu->dev,"IPC timed out\n" );return -ETIMEDOUT ; }
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 8/38 platform/x86: intel_scu_ipc: Drop unused prototype intel_scu_ipc_fw_update()
In reply to Mika WesterbergThere is no implementation for that anymore so drop the prototype.
--- arch/x86/include/asm/intel_scu_ipc.h | 3 --- 1 file changed, 3 deletions(-)
arch/x86/include/asm/intel_scu_ipc.h +0 -3
@@ -53,9 +53,6 @@ int intel_scu_ipc_command(int cmd, int sub, u32 *in, int inlen,int intel_scu_ipc_raw_command (int cmd,int sub,u8 *in,int inlen,u32 *out,int outlen,u32 dptr,u32 sptr); -/* Update FW version */ -int intel_scu_ipc_fw_update (u8 *buffer,u32 length); -extern struct blocking_notifier_head intel_scu_notifier;static inline void intel_scu_notifier_add (struct notifier_block *nb)
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 9/38 platform/x86: intel_scu_ipc: Drop unused macros
In reply to Mika WesterbergThese macros are not used anywhere in the driver so drop them.
--- drivers/platform/x86/intel_scu_ipc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/platform/x86/intel_scu_ipc.c +1 -5
@@ -26,11 +26,7 @@#include <asm/intel_scu_ipc.h> /* IPC defines the following message types */ -#define IPCMSG_WATCHDOG_TIMER 0xF8/* Set Kernel Watchdog Threshold */ -#define IPCMSG_BATTERY 0xEF/* Coulomb Counter Accumulator */ -#define IPCMSG_FW_UPDATE 0xFE/* Firmware update */ -#define IPCMSG_PCNTRL 0xFF/* Power controller unit read/write */ -#define IPCMSG_FW_REVISION 0xF4/* Get firmware revision */ +#define IPCMSG_PCNTRL 0xff/* Power controller unit read/write */ /* Command id associated with message IPCMSG_PCNTRL */ #define IPC_CMD_PCNTRL_W 0/* Register write */
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 10/38 platform/x86: intel_scu_ipc: Drop intel_scu_ipc_io[read|write][8|16]()
In reply to Mika WesterbergThere are no users for these so we can remove them.
--- arch/x86/include/asm/intel_scu_ipc.h | 12 ----- drivers/platform/x86/intel_scu_ipc.c | 68 ---------------------------- 2 files changed, 80 deletions(-)
arch/x86/include/asm/intel_scu_ipc.h +0 -12
@@ -22,24 +22,12 @@/* Read single register */ int intel_scu_ipc_ioread8 (u16 addr,u8 *data); -/* Read two sequential registers */ -int intel_scu_ipc_ioread16 (u16 addr,u16 *data); - -/* Read four sequential registers */ -int intel_scu_ipc_ioread32 (u16 addr,u32 *data); -/* Read a vector */ int intel_scu_ipc_readv (u16 *addr,u8 *data,int len);/* Write single register */ int intel_scu_ipc_iowrite8 (u16 addr,u8 data); -/* Write two sequential registers */ -int intel_scu_ipc_iowrite16 (u16 addr,u16 data); - -/* Write four sequential registers */ -int intel_scu_ipc_iowrite32 (u16 addr,u32 data); -/* Write a vector */ int intel_scu_ipc_writev (u16 *addr,u8 *data,int len);
drivers/platform/x86/intel_scu_ipc.c +0 -68
80 lines not on this page · raw message
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 11/38 platform/x86: intel_scu_ipc: Drop intel_scu_ipc_raw_command()
In reply to Mika WesterbergThere is no user for this function so we can drop it from the driver.
--- arch/x86/include/asm/intel_scu_ipc.h | 2 - drivers/platform/x86/intel_scu_ipc.c | 63 ---------------------------- 2 files changed, 65 deletions(-)
arch/x86/include/asm/intel_scu_ipc.h +0 -2
@@ -38,8 +38,6 @@ int intel_scu_ipc_update_register(u16 addr, u8 data, u8 mask);int intel_scu_ipc_simple_command (int cmd,int sub);int intel_scu_ipc_command (int cmd,int sub,u32 *in,int inlen,u32 *out,int outlen); -int intel_scu_ipc_raw_command (int cmd,int sub,u8 *in,int inlen, -u32 *out,int outlen,u32 dptr,u32 sptr);extern struct blocking_notifier_head intel_scu_notifier;
drivers/platform/x86/intel_scu_ipc.c +0 -63
69 lines not on this page · raw message
Signature · 1 line
2.24.1
Greg Kroah-Hartman
maintainerRe: [PATCH v4 11/38] platform/x86: intel_scu_ipc: Drop intel_scu_ipc_raw_command()
Quoted 8 lines · Mika Westerberg
There is no user for this function so we can drop it from the driver.
Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- arch/x86/include/asm/intel_scu_ipc.h | 2 - drivers/platform/x86/intel_scu_ipc.c | 63 ---------------------------- 2 files changed, 65 deletions(-)
These first 11 patches are fine, why didn't you just submit them as cleanups/fixes and then build on them with the rest? Having to wade through 38-patch series is a pain...
thanks,
greg k-h
Mika Westerberg
maintainerRe: [PATCH v4 11/38] platform/x86: intel_scu_ipc: Drop intel_scu_ipc_raw_command()
Quoted 10 lines · Greg Kroah-Hartman
Quoted 8 lines · Mika Westerberg
There is no user for this function so we can drop it from the driver.
Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- arch/x86/include/asm/intel_scu_ipc.h | 2 - drivers/platform/x86/intel_scu_ipc.c | 63 ---------------------------- 2 files changed, 65 deletions(-)
Quoted 3 lines
These first 11 patches are fine, why didn't you just submit them as cleanups/fixes and then build on them with the rest? Having to wade through 38-patch series is a pain...
OK, I'll submit the first cleanup patches separately so they can be applied first and then rework rest of the series on top.
Mika Westerberg
maintainerPATCH v4 12/38 platform/x86: intel_scu_ipc: Split out SCU IPC functionality from the SCU driver
In reply to Mika WesterbergThe SCU IPC functionality is usable outside of Intel MID devices. For example modern Intel CPUs include the same thing but now it is called PMC (Power Management Controller) instead of SCU. To make the IPC available for those split the driver into library part (intel_scu_ipc.c) and the SCU PCI driver part (intel_scu_pcidrv.c) which then calls the former before it goes and creates rest of the SCU devices.
We also split the Kconfig symbols so that INTEL_SCU_IPC enables the SCU IPC library and INTEL_SCU_PCI the SCU driver and convert the users accordingly. While there remove default y from the INTEL_SCU_PCI symbol as it is already selected by X86_INTEL_MID.
--- arch/x86/Kconfig | 2 +- arch/x86/include/asm/intel_scu_ipc.h | 16 +++++ drivers/mfd/Kconfig | 4 +- drivers/platform/x86/Kconfig | 26 ++++--- drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_scu_ipc.c | 90 ++++++++++++------------- drivers/platform/x86/intel_scu_pcidrv.c | 54 +++++++++++++++ 7 files changed, 135 insertions(+), 58 deletions(-) create mode 100644 drivers/platform/x86/intel_scu_pcidrv.c
arch/x86/Kconfig +1 -1
@@ -594,7 +594,7 @@ config X86_INTEL_MID select I2C select DW_APB_TIMER select APB_TIMER - select INTEL_SCU_IPC + select INTEL_SCU_PCI select MFD_INTEL_MSIC ---help--- Select to build a kernel capable of supporting Intel MID (Mobile
arch/x86/include/asm/intel_scu_ipc.h +16 -0
@@ -2,6 +2,7 @@#ifndef _ASM_X86_INTEL_SCU_IPC_H_#define _ASM_X86_INTEL_SCU_IPC_H_ +#include <linux/ioport.h> #include <linux/notifier.h> #define IPCMSG_INDIRECT_READ 0x02
@@ -19,6 +20,21 @@#define IPC_CMD_VRTC_SETTIME 1/* Set time */ #define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ +struct device ; + +/** +* struct intel_scu_ipc_pdata - Platform data for SCU IPC +* @mem: Base address of SCU IPC MMIO registers +* @irq: The IRQ number used for SCU (optional) +*/ +struct intel_scu_ipc_pdata { +struct resource mem; +int irq; +}; + +int intel_scu_ipc_register (struct device *dev, +const struct intel_scu_ipc_pdata *pdata); +/* Read single register */ int intel_scu_ipc_ioread8 (u16 addr,u8 *data);
drivers/mfd/Kconfig +2 -2
@@ -593,7 +593,7 @@ config INTEL_SOC_PMIC_MRFLD tristate "Support for Intel Merrifield Basin Cove PMIC" depends on GPIOLIB depends on ACPI - depends on INTEL_SCU_IPC + depends on INTEL_SCU select MFD_CORE select REGMAP_IRQ help
@@ -625,7 +625,7 @@ config MFD_INTEL_LPSS_PCI config MFD_INTEL_MSIC bool "Intel MSIC" - depends on INTEL_SCU_IPC + depends on INTEL_SCU select MFD_CORE help Select this option to enable access to Intel MSIC (Avatele
drivers/platform/x86/Kconfig +17 -9
@@ -986,25 +986,33 @@ config INTEL_VBTN be called intel_vbtn. config INTEL_SCU_IPC - bool "Intel SCU IPC Support" + bool + +config INTEL_SCU + bool + select INTEL_SCU_IPC + +config INTEL_SCU_PCI + bool "Intel SCU PCI driver" depends on X86_INTEL_MID - default y - ---help--- - IPC is used to bridge the communications between kernel and SCU on - some embedded Intel x86 platforms. This is not needed for PC-type - machines. + select INTEL_SCU + help + This driver is used to bridge the communications between kernel + and SCU on some embedded Intel x86 platforms. It also creates + devices that are connected to the SoC through the SCU. This is + not needed for PC-type machines. config INTEL_SCU_IPC_UTIL tristate "Intel SCU IPC utility driver" - depends on INTEL_SCU_IPC - ---help--- + depends on INTEL_SCU + help The IPC Util driver provides an interface with the SCU enabling low level access for debug work and updating the firmware. Say N unless you will be doing this on an Intel MID platform. config INTEL_MID_POWER_BUTTON tristate "power button driver for Intel MID platforms" - depends on INTEL_SCU_IPC && INPUT + depends on INTEL_SCU && INPUT help This driver handles the power button on the Intel MID platforms.
drivers/platform/x86/Makefile +1 -0
@@ -68,6 +68,7 @@ intel_cht_int33fe-objs := intel_cht_int33fe_common.o \ obj-$(CONFIG_INTEL_INT0002_VGPIO) += intel_int0002_vgpio.o obj-$(CONFIG_INTEL_HID_EVENT) += intel-hid.o obj-$(CONFIG_INTEL_VBTN) += intel-vbtn.o +obj-$(CONFIG_INTEL_SCU_PCI) += intel_scu_pcidrv.o obj-$(CONFIG_INTEL_SCU_IPC) += intel_scu_ipc.o obj-$(CONFIG_INTEL_SCU_IPC_UTIL) += intel_scu_ipcutil.o obj-$(CONFIG_INTEL_MFLD_THERMAL) += intel_mid_thermal.o
drivers/platform/x86/intel_scu_ipc.c +44 -46
131 lines not on this page · raw message
drivers/platform/x86/intel_scu_pcidrv.c new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.24.1
Greg Kroah-Hartman
maintainerRe: [PATCH v4 12/38] platform/x86: intel_scu_ipc: Split out SCU IPC functionality from the SCU driver
Quoted 200 lines · Mika Westerberg
The SCU IPC functionality is usable outside of Intel MID devices. For example modern Intel CPUs include the same thing but now it is called PMC (Power Management Controller) instead of SCU. To make the IPC available for those split the driver into library part (
intel_scu_ipc.c) and the SCU PCI driver part (intel_scu_pcidrv.c) which then calls the former before it goes and creates rest of the SCU devices.We also split the
Kconfigsymbols so thatINTEL_SCU_IPCenables the SCU IPC library andINTEL_SCU_PCIthe SCU driver and convert the users accordingly. While there remove default y from theINTEL_SCU_PCIsymbol as it is already selected byX86_INTEL_MID.Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- arch/x86/Kconfig | 2 +- arch/x86/include/asm/intel_scu_ipc.h | 16 +++++ drivers/mfd/Kconfig | 4 +- drivers/platform/x86/Kconfig | 26 ++++--- drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_scu_ipc.c | 90 ++++++++++++------------- drivers/platform/x86/intel_scu_pcidrv.c | 54 +++++++++++++++ 7 files changed, 135 insertions(+), 58 deletions(-) create mode 100644 drivers/platform/x86/intel_scu_pcidrv.carch/x86/Kconfig +1
-1@@ -594,7 +594,7 @@ config X86_INTEL_MID select I2C select DW_APB_TIMER select APB_TIMER - select INTEL_SCU_IPC + select INTEL_SCU_PCI select MFD_INTEL_MSIC ---help--- Select to build a kernel capable of supporting Intel MID (Mobilearch/x86/include/asm/intel_scu_ipc.h +16
-0@@ -2,6 +2,7 @@#ifndef _ASM_X86_INTEL_SCU_IPC_H_#define _ASM_X86_INTEL_SCU_IPC_H_ +#include <linux/ioport.h> #include <linux/notifier.h> #define IPCMSG_INDIRECT_READ 0x02@@ -19,6 +20,21 @@#define IPC_CMD_VRTC_SETTIME 1/* Set time */ #define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ +struct device ; + +/** +* struct intel_scu_ipc_pdata - Platform data for SCU IPC +* @mem: Base address of SCU IPC MMIO registers +* @irq: The IRQ number used for SCU (optional) +*/ +struct intel_scu_ipc_pdata { +struct resource mem; +int irq; +}; + +int intel_scu_ipc_register (struct device *dev, +const struct intel_scu_ipc_pdata *pdata); +/* Read single register */ int intel_scu_ipc_ioread8 (u16 addr,u8 *data);drivers/mfd/Kconfig +2
-2@@ -593,7 +593,7 @@ config INTEL_SOC_PMIC_MRFLD tristate "Support for Intel Merrifield Basin Cove PMIC" depends on GPIOLIB depends on ACPI - depends on INTEL_SCU_IPC + depends on INTEL_SCU select MFD_CORE select REGMAP_IRQ help@@ -625,7 +625,7 @@ config MFD_INTEL_LPSS_PCI config MFD_INTEL_MSIC bool "Intel MSIC" - depends on INTEL_SCU_IPC + depends on INTEL_SCU select MFD_CORE help Select this option to enable access to Intel MSIC (Avateledrivers/platform/x86/Kconfig +17
-9@@ -986,25 +986,33 @@ config INTEL_VBTN be called intel_vbtn. config INTEL_SCU_IPC - bool "Intel SCU IPC Support" + bool + +config INTEL_SCU + bool + select INTEL_SCU_IPC + +config INTEL_SCU_PCI + bool "Intel SCU PCI driver" depends on X86_INTEL_MID - default y - ---help--- - IPC is used to bridge the communications between kernel and SCU on - some embedded Intel x86 platforms. This is not needed for PC-type - machines. + select INTEL_SCU + help + This driver is used to bridge the communications between kernel + and SCU on some embedded Intel x86 platforms. It also creates + devices that are connected to the SoC through the SCU. This is + not needed for PC-type machines. config INTEL_SCU_IPC_UTIL tristate "Intel SCU IPC utility driver" - depends on INTEL_SCU_IPC - ---help--- + depends on INTEL_SCU + help The IPC Util driver provides an interface with the SCU enabling low level access for debug work and updating the firmware. Say N unless you will be doing this on an Intel MID platform. config INTEL_MID_POWER_BUTTON tristate "power button driver for Intel MID platforms" - depends on INTEL_SCU_IPC && INPUT + depends on INTEL_SCU && INPUT help This driver handles the power button on the Intel MID platforms.drivers/platform/x86/Makefile +1
-0@@ -68,6 +68,7 @@ intel_cht_int33fe-objs := intel_cht_int33fe_common.o \ obj-$(CONFIG_INTEL_INT0002_VGPIO) += intel_int0002_vgpio.o obj-$(CONFIG_INTEL_HID_EVENT) += intel-hid.o obj-$(CONFIG_INTEL_VBTN) += intel-vbtn.o +obj-$(CONFIG_INTEL_SCU_PCI) += intel_scu_pcidrv.o obj-$(CONFIG_INTEL_SCU_IPC) += intel_scu_ipc.o obj-$(CONFIG_INTEL_SCU_IPC_UTIL) += intel_scu_ipcutil.o obj-$(CONFIG_INTEL_MFLD_THERMAL) += intel_mid_thermal.odrivers/platform/x86/intel_scu_ipc.c +6
-9@@ -18,11 +18,8 @@#include <linux/errno.h> #include <linux/init.h> #include <linux/interrupt.h> -#include <linux/pci.h> -#include <linux/pm.h> -#include <linux/sfi.h> +#include <linux/io.h> -#include <asm/intel-mid.h> #include <asm/intel_scu_ipc.h> /* IPC defines the following message types */ @@ -56,9 +53,10 @@struct intel_scu_ipc_dev {struct device *dev; +struct resource mem; +int irq;void __iomem *ipc_base;struct completion cmd_complete; -u8 irq_mode; };static struct intel_scu_ipc_dev ipcdev;/* Only one for now */ @@ -166,7 +164,7 @@ static inline int ipc_wait_for_interrupt(struct intel_scu_ipc_dev *scu)static int intel_scu_ipc_check_status (struct intel_scu_ipc_dev *scu) { -return scu->irq_mode ?ipc_wait_for_interrupt (scu) :busy_loop (scu); +return scu->irq >0 ?ipc_wait_for_interrupt (scu) :busy_loop (scu); }/* Read/Write power control(PMIC in Langwell, MSIC in PenWell) registers */ @@ -402,60 +400,60 @@ static irqreturn_t ioc(int irq, void *dev_id) }/** -* ipc_probe - probe an Intel SCU IPC -* @pdev: the PCI device matching -* @id: entry in the match table +* intel_scu_ipc_register() - Register SCU IPC mechanism +* @dev: SCU device
drivers/platform/x86/intel_scu_ipc.c static irqreturn_t ioc(int irq, void *dev_id) · line 411
Quoted 10 lines
drivers/platform/x86/intel_scu_ipc.c +4
-3+* @pdata: Platform specific data * -* Enable and install an intel SCU IPC. This appears in the PCI space -* but uses some hard coded addresses as well. +* Call this function to initialize SCU IPC mechanism for @dev. */ -static int ipc_probe (struct pci_dev *pdev,const struct pci_device_id *id) +int intel_scu_ipc_register (struct device *dev, +const struct intel_scu_ipc_pdata *pdata) {
How do you "know" that dev really is a SCU device?
If you are "registering" something, shouldn't you have set it up properly? You are saying that any random struct device has these attributes. Now that's fine as you "know" this, but usually you would create a child device that really is a SCU functionality, i.e. a class device.
So how about making the SCU stuff a class as that is what is then made a child of the struct device as it is how it talks to this class of devices, right?
As it is, this "register" really feels odd to me in the scheme of how the whole driver model works.
Not to mention I didn't see any reference counting increment happening here, as you are passing a pointer that is then saved off, right?
Quoted 41 lines
drivers/platform/x86/intel_scu_ipc.c +19
-14int err;struct intel_scu_ipc_dev *scu = &ipcdev; -if (scu->dev)/* We support only one SCU */ -return -EBUSY ; +mutex_lock (&ipclock); +/* We support only one IPC */ +if (scu->dev) { + err = -EBUSY ; + goto err_unlock; + } - err =pcim_enable_device (pdev); -if (err) -return err; +if (!request_mem_region (pdata->mem.start,resource_size (&pdata->mem), +"intel_scu_ipc" )) { + err = -EBUSY ; + goto err_unlock; + } - err =pcim_iomap_regions (pdev,1 <<0 ,pci_name (pdev)); -if (err) -return err; + scu->ipc_base =ioremap (pdata->mem.start,resource_size (&pdata->mem)); +if (!scu->ipc_base) { + err = -ENOMEM ; + goto err_release; + } + scu->mem = pdata->mem; + scu->irq = pdata->irq;init_completion (&scu->cmd_complete); - scu->ipc_base =pcim_iomap_table (pdev)[0 ]; - - err =devm_request_irq (&pdev->dev, pdev->irq, ioc,0 ,"intel_scu_ipc" , - scu); -if (err) -return err; +if (scu->irq >0 ) {
drivers/platform/x86/intel_scu_ipc.c static irqreturn_t ioc(int irq, void *dev_id) · line 445
Quoted 10 lines
drivers/platform/x86/intel_scu_ipc.c +5
-3+ err =request_irq (scu->irq, ioc,0 ,"intel_scu_ipc" , scu); +if (err) + goto err_unmap; + }/* Assign device at last */ - scu->dev = &pdev->dev; - -intel_scu_devices_create (); + scu->dev = dev;
Look ma, a reference count mess!
Ick.
Please make this a class.
thanks,
greg k-h
Mika Westerberg
maintainerRe: [PATCH v4 12/38] platform/x86: intel_scu_ipc: Split out SCU IPC functionality from the SCU driver
Quoted 205 lines · Greg Kroah-Hartman
Quoted 204 lines · Mika Westerberg
The SCU IPC functionality is usable outside of Intel MID devices. For example modern Intel CPUs include the same thing but now it is called PMC (Power Management Controller) instead of SCU. To make the IPC available for those split the driver into library part (
intel_scu_ipc.c) and the SCU PCI driver part (intel_scu_pcidrv.c) which then calls the former before it goes and creates rest of the SCU devices.We also split the
Kconfigsymbols so thatINTEL_SCU_IPCenables the SCU IPC library andINTEL_SCU_PCIthe SCU driver and convert the users accordingly. While there remove default y from theINTEL_SCU_PCIsymbol as it is already selected byX86_INTEL_MID.Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- arch/x86/Kconfig | 2 +- arch/x86/include/asm/intel_scu_ipc.h | 16 +++++ drivers/mfd/Kconfig | 4 +- drivers/platform/x86/Kconfig | 26 ++++--- drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_scu_ipc.c | 90 ++++++++++++------------- drivers/platform/x86/intel_scu_pcidrv.c | 54 +++++++++++++++ 7 files changed, 135 insertions(+), 58 deletions(-) create mode 100644 drivers/platform/x86/intel_scu_pcidrv.carch/x86/Kconfig +1
-1@@ -594,7 +594,7 @@ config X86_INTEL_MID select I2C select DW_APB_TIMER select APB_TIMER - select INTEL_SCU_IPC + select INTEL_SCU_PCI select MFD_INTEL_MSIC ---help--- Select to build a kernel capable of supporting Intel MID (Mobilearch/x86/include/asm/intel_scu_ipc.h +16
-0@@ -2,6 +2,7 @@#ifndef _ASM_X86_INTEL_SCU_IPC_H_#define _ASM_X86_INTEL_SCU_IPC_H_ +#include <linux/ioport.h> #include <linux/notifier.h> #define IPCMSG_INDIRECT_READ 0x02@@ -19,6 +20,21 @@#define IPC_CMD_VRTC_SETTIME 1/* Set time */ #define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ +struct device ; + +/** +* struct intel_scu_ipc_pdata - Platform data for SCU IPC +* @mem: Base address of SCU IPC MMIO registers +* @irq: The IRQ number used for SCU (optional) +*/ +struct intel_scu_ipc_pdata { +struct resource mem; +int irq; +}; + +int intel_scu_ipc_register (struct device *dev, +const struct intel_scu_ipc_pdata *pdata); +/* Read single register */ int intel_scu_ipc_ioread8 (u16 addr,u8 *data);drivers/mfd/Kconfig +2
-2@@ -593,7 +593,7 @@ config INTEL_SOC_PMIC_MRFLD tristate "Support for Intel Merrifield Basin Cove PMIC" depends on GPIOLIB depends on ACPI - depends on INTEL_SCU_IPC + depends on INTEL_SCU select MFD_CORE select REGMAP_IRQ help@@ -625,7 +625,7 @@ config MFD_INTEL_LPSS_PCI config MFD_INTEL_MSIC bool "Intel MSIC" - depends on INTEL_SCU_IPC + depends on INTEL_SCU select MFD_CORE help Select this option to enable access to Intel MSIC (Avateledrivers/platform/x86/Kconfig +17
-9@@ -986,25 +986,33 @@ config INTEL_VBTN be called intel_vbtn. config INTEL_SCU_IPC - bool "Intel SCU IPC Support" + bool + +config INTEL_SCU + bool + select INTEL_SCU_IPC + +config INTEL_SCU_PCI + bool "Intel SCU PCI driver" depends on X86_INTEL_MID - default y - ---help--- - IPC is used to bridge the communications between kernel and SCU on - some embedded Intel x86 platforms. This is not needed for PC-type - machines. + select INTEL_SCU + help + This driver is used to bridge the communications between kernel + and SCU on some embedded Intel x86 platforms. It also creates + devices that are connected to the SoC through the SCU. This is + not needed for PC-type machines. config INTEL_SCU_IPC_UTIL tristate "Intel SCU IPC utility driver" - depends on INTEL_SCU_IPC - ---help--- + depends on INTEL_SCU + help The IPC Util driver provides an interface with the SCU enabling low level access for debug work and updating the firmware. Say N unless you will be doing this on an Intel MID platform. config INTEL_MID_POWER_BUTTON tristate "power button driver for Intel MID platforms" - depends on INTEL_SCU_IPC && INPUT + depends on INTEL_SCU && INPUT help This driver handles the power button on the Intel MID platforms.drivers/platform/x86/Makefile +1
-0@@ -68,6 +68,7 @@ intel_cht_int33fe-objs := intel_cht_int33fe_common.o \ obj-$(CONFIG_INTEL_INT0002_VGPIO) += intel_int0002_vgpio.o obj-$(CONFIG_INTEL_HID_EVENT) += intel-hid.o obj-$(CONFIG_INTEL_VBTN) += intel-vbtn.o +obj-$(CONFIG_INTEL_SCU_PCI) += intel_scu_pcidrv.o obj-$(CONFIG_INTEL_SCU_IPC) += intel_scu_ipc.o obj-$(CONFIG_INTEL_SCU_IPC_UTIL) += intel_scu_ipcutil.o obj-$(CONFIG_INTEL_MFLD_THERMAL) += intel_mid_thermal.odrivers/platform/x86/intel_scu_ipc.c +7
-11@@ -18,11 +18,8 @@#include <linux/errno.h> #include <linux/init.h> #include <linux/interrupt.h> -#include <linux/pci.h> -#include <linux/pm.h> -#include <linux/sfi.h> +#include <linux/io.h> -#include <asm/intel-mid.h> #include <asm/intel_scu_ipc.h> /* IPC defines the following message types */ @@ -56,9 +53,10 @@struct intel_scu_ipc_dev {struct device *dev; +struct resource mem; +int irq;void __iomem *ipc_base;struct completion cmd_complete; -u8 irq_mode; };static struct intel_scu_ipc_dev ipcdev;/* Only one for now */ @@ -166,7 +164,7 @@ static inline int ipc_wait_for_interrupt(struct intel_scu_ipc_dev *scu)static int intel_scu_ipc_check_status (struct intel_scu_ipc_dev *scu) { -return scu->irq_mode ?ipc_wait_for_interrupt (scu) :busy_loop (scu); +return scu->irq >0 ?ipc_wait_for_interrupt (scu) :busy_loop (scu); }/* Read/Write power control(PMIC in Langwell, MSIC in PenWell) registers */ @@ -402,60 +400,60 @@ static irqreturn_t ioc(int irq, void *dev_id) }/** -* ipc_probe - probe an Intel SCU IPC -* @pdev: the PCI device matching -* @id: entry in the match table +* intel_scu_ipc_register() - Register SCU IPC mechanism +* @dev: SCU device +* @pdata: Platform specific data * -* Enable and install an intel SCU IPC. This appears in the PCI space -* but uses some hard coded addresses as well.
Quoted 8 lines
drivers/platform/x86/intel_scu_ipc.c static irqreturn_t ioc(int irq, void *dev_id) · line 411
Quoted 6 lines
drivers/platform/x86/intel_scu_ipc.c +3
-1+* Call this function to initialize SCU IPC mechanism for @dev. */ -static int ipc_probe (struct pci_dev *pdev,const struct pci_device_id *id) +int intel_scu_ipc_register (struct device *dev, +const struct intel_scu_ipc_pdata *pdata) {How do you "know" that dev really is a SCU device?
Well this expects the caller to know that.
Quoted 9 lines
If you are "registering" something, shouldn't you have set it up properly? You are saying that any random struct device has these attributes. Now that's fine as you "know" this, but usually you would create a child device that really is a SCU functionality, i.e. a class device.
So how about making the SCU stuff a class as that is what is then made a child of the struct device as it is how it talks to this class of devices, right?
That's a good idea. I'll look into this.
Quoted 5 lines
As it is, this "register" really feels odd to me in the scheme of how the whole driver model works.
Not to mention I didn't see any reference counting increment happening here, as you are passing a pointer that is then saved off, right?
Right.
Quoted 54 lines
Quoted 41 lines
drivers/platform/x86/intel_scu_ipc.c +19
-14int err;struct intel_scu_ipc_dev *scu = &ipcdev; -if (scu->dev)/* We support only one SCU */ -return -EBUSY ; +mutex_lock (&ipclock); +/* We support only one IPC */ +if (scu->dev) { + err = -EBUSY ; + goto err_unlock; + } - err =pcim_enable_device (pdev); -if (err) -return err; +if (!request_mem_region (pdata->mem.start,resource_size (&pdata->mem), +"intel_scu_ipc" )) { + err = -EBUSY ; + goto err_unlock; + } - err =pcim_iomap_regions (pdev,1 <<0 ,pci_name (pdev)); -if (err) -return err; + scu->ipc_base =ioremap (pdata->mem.start,resource_size (&pdata->mem)); +if (!scu->ipc_base) { + err = -ENOMEM ; + goto err_release; + } + scu->mem = pdata->mem; + scu->irq = pdata->irq;init_completion (&scu->cmd_complete); - scu->ipc_base =pcim_iomap_table (pdev)[0 ]; - - err =devm_request_irq (&pdev->dev, pdev->irq, ioc,0 ,"intel_scu_ipc" , - scu); -if (err) -return err; +if (scu->irq >0 ) {drivers/platform/x86/intel_scu_ipc.c static irqreturn_t ioc(int irq, void *dev_id) · line 445
Quoted 10 lines
drivers/platform/x86/intel_scu_ipc.c +5
-3+ err =request_irq (scu->irq, ioc,0 ,"intel_scu_ipc" , scu); +if (err) + goto err_unmap; + }/* Assign device at last */ - scu->dev = &pdev->dev; - -intel_scu_devices_create (); + scu->dev = dev;Look ma, a reference count mess!
Quoted 3 lines
Ick.
Please make this a class.
I will, thanks!
Mika Westerberg
maintainerPATCH v4 13/38 platform/x86: intel_scu_ipc: Reformat kernel-doc comments of exported functions
In reply to Mika WesterbergFormat kernel-doc comments of the exported functions to follow the typical format that does not have tab indentation. Also capitalize parameter descriptions and add a missing period.
No functional changes intended.
--- drivers/platform/x86/intel_scu_ipc.c | 112 +++++++++++++-------------- 1 file changed, 55 insertions(+), 57 deletions(-)
drivers/platform/x86/intel_scu_ipc.c +55 -57
@@ -220,14 +220,14 @@ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) }/** -* intel_scu_ipc_ioread8 - read a word via the SCU -* @addr: register on SCU -* @data: return pointer for read byte +* intel_scu_ipc_ioread8 - read a word via the SCU +* @addr: Register on SCU +* @data: Return pointer for read byte * -* Read a single register. Returns 0 on success or an error code. All -* locking between SCU accesses is handled for the caller. +* Read a single register. Returns %0 on success or an error code. All +* locking between SCU accesses is handled for the caller. * -* This function may sleep. +* This function may sleep. */ int intel_scu_ipc_ioread8 (u16 addr,u8 *data) {
@@ -236,14 +236,14 @@ int intel_scu_ipc_ioread8(u16 addr, u8 *data)EXPORT_SYMBOL (intel_scu_ipc_ioread8);/** -* intel_scu_ipc_iowrite8 - write a byte via the SCU -* @addr: register on SCU -* @data: byte to write +* intel_scu_ipc_iowrite8 - write a byte via the SCU +* @addr: Register on SCU +* @data: Byte to write * -* Write a single register. Returns 0 on success or an error code. All -* locking between SCU accesses is handled for the caller. +* Write a single register. Returns %0 on success or an error code. All +* locking between SCU accesses is handled for the caller. * -* This function may sleep. +* This function may sleep. */ int intel_scu_ipc_iowrite8 (u16 addr,u8 data) {
@@ -252,17 +252,17 @@ int intel_scu_ipc_iowrite8(u16 addr, u8 data)EXPORT_SYMBOL (intel_scu_ipc_iowrite8);/** -* intel_scu_ipc_readvv - read a set of registers -* @addr: register list -* @data: bytes to return -* @len: length of array +* intel_scu_ipc_readvv - read a set of registers +* @addr: Register list +* @data: Bytes to return +* @len: Length of array * -* Read registers. Returns 0 on success or an error code. All -* locking between SCU accesses is handled for the caller. +* Read registers. Returns %0 on success or an error code. All locking +* between SCU accesses is handled for the caller. * -* The largest array length permitted by the hardware is 5 items. +* The largest array length permitted by the hardware is 5 items. * -* This function may sleep. +* This function may sleep. */ int intel_scu_ipc_readv (u16 *addr,u8 *data,int len) {
@@ -271,18 +271,17 @@ int intel_scu_ipc_readv(u16 *addr, u8 *data, int len)EXPORT_SYMBOL (intel_scu_ipc_readv);/** -* intel_scu_ipc_writev - write a set of registers -* @addr: register list -* @data: bytes to write -* @len: length of array +* intel_scu_ipc_writev - write a set of registers +* @addr: Register list +* @data: Bytes to write +* @len: Length of array * -* Write registers. Returns 0 on success or an error code. All -* locking between SCU accesses is handled for the caller. +* Write registers. Returns %0 on success or an error code. All locking +* between SCU accesses is handled for the caller. * -* The largest array length permitted by the hardware is 5 items. -* -* This function may sleep. +* The largest array length permitted by the hardware is 5 items. * +* This function may sleep. */ int intel_scu_ipc_writev (u16 *addr,u8 *data,int len) {
@@ -291,19 +290,18 @@ int intel_scu_ipc_writev(u16 *addr, u8 *data, int len)EXPORT_SYMBOL (intel_scu_ipc_writev);/** -* intel_scu_ipc_update_register - r/m/w a register -* @addr: register address -* @bits: bits to update -* @mask: mask of bits to update +* intel_scu_ipc_update_register - r/m/w a register +* @addr: Register address +* @bits: Bits to update +* @mask: Mask of bits to update * -* Read-modify-write power control unit register. The first data argument -* must be register value and second is mask value -* mask is a bitmap that indicates which bits to update. -* 0 = masked. Don't modify this bit, 1 = modify this bit. -* returns 0 on success or an error code. +* Read-modify-write power control unit register. The first data argument +* must be register value and second is mask value mask is a bitmap that +* indicates which bits to update. %0 = masked. Don't modify this bit, %1 = +* modify this bit. returns %0 on success or an error code. * -* This function may sleep. Locking between SCU accesses is handled -* for the caller. +* This function may sleep. Locking between SCU accesses is handled +* for the caller. */ int intel_scu_ipc_update_register (u16 addr,u8 bits,u8 mask) {
@@ -313,16 +311,16 @@ int intel_scu_ipc_update_register(u16 addr, u8 bits, u8 mask)EXPORT_SYMBOL (intel_scu_ipc_update_register);/** -* intel_scu_ipc_simple_command - send a simple command -* @cmd: command -* @sub: sub type +* intel_scu_ipc_simple_command - send a simple command +* @cmd: Command +* @sub: Sub type * -* Issue a simple command to the SCU. Do not use this interface if -* you must then access data as any data values may be overwritten -* by another SCU access by the time this function returns. +* Issue a simple command to the SCU. Do not use this interface if you must +* then access data as any data values may be overwritten by another SCU +* access by the time this function returns. * -* This function may sleep. Locking for SCU accesses is handled for -* the caller. +* This function may sleep. Locking for SCU accesses is handled for the +* caller. */ int intel_scu_ipc_simple_command (int cmd,int sub) {
@@ -342,16 +340,16 @@ int intel_scu_ipc_simple_command(int cmd, int sub)EXPORT_SYMBOL (intel_scu_ipc_simple_command);/** -* intel_scu_ipc_command - command with data -* @cmd: command -* @sub: sub type -* @in: input data -* @inlen: input length in dwords -* @out: output data -* @outlein: output length in dwords +* intel_scu_ipc_command - command with data +* @cmd: Command +* @sub: Sub type +* @in: Input data +* @inlen: Input length in dwords +* @out: Output data +* @outlen: Output length in dwords * -* Issue a command to the SCU which involves data transfers. Do the -* data copies under the lock but leave it for the caller to interpret +* Issue a command to the SCU which involves data transfers. Do the +* data copies under the lock but leave it for the caller to interpret. */ int intel_scu_ipc_command (int cmd,int sub,u32 *in,int inlen,u32 *out,int outlen)
Signature · 1 line
2.24.1
Greg Kroah-Hartman
maintainerRe: [PATCH v4 13/38] platform/x86: intel_scu_ipc: Reformat kernel-doc comments of exported functions
Quoted 3 lines · Mika Westerberg
Format kernel-doc comments of the exported functions to follow the typical format that does not have tab indentation. Also capitalize parameter descriptions and add a missing period.
This should go in the first set of "cleanup" patches, right?
thanks,
greg k-h
Mika Westerberg
maintainerRe: [PATCH v4 13/38] platform/x86: intel_scu_ipc: Reformat kernel-doc comments of exported functions
Quoted 6 lines · Greg Kroah-Hartman
Quoted 3 lines · Mika Westerberg
Format kernel-doc comments of the exported functions to follow the typical format that does not have tab indentation. Also capitalize parameter descriptions and add a missing period.
This should go in the first set of "cleanup" patches, right?
Right. I'll move it to be part of the cleanup patch series.
Mika Westerberg
maintainerPATCH v4 14/38 platform/x86: intel_scu_ipc: Introduce new SCU IPC API
In reply to Mika WesterbergThe current SCU IPC API has been operating on a single instance and there has been no way to pin the providing module in place when the SCU IPC is in use.
This implements a new API that takes the SCU IPC instance as first parameter (NULL means the single instance is being used). The SCU IPC instance can be retrieved by calling new function intel_scu_ipc_dev_get() that take care of pinning the providing module in place as long as intel_scu_ipc_dev_put() is not called.
The old API is left there to support existing users which cannot be converted easily but it is put to a separate header that is subject to be removed eventually. Subsequent patches will convert most of the users to the new API.
--- arch/x86/include/asm/intel_scu_ipc.h | 74 +++---- arch/x86/include/asm/intel_scu_ipc_legacy.h | 76 +++++++ drivers/platform/x86/intel_scu_ipc.c | 219 ++++++++++++++++---- drivers/platform/x86/intel_scu_pcidrv.c | 7 +- 4 files changed, 287 insertions(+), 89 deletions(-) create mode 100644 arch/x86/include/asm/intel_scu_ipc_legacy.h
arch/x86/include/asm/intel_scu_ipc.h +33 -41
@@ -1,9 +1,8 @@/* SPDX-License-Identifier: GPL-2.0 */ #ifndef _ASM_X86_INTEL_SCU_IPC_H_ -#define _ASM_X86_INTEL_SCU_IPC_H_ +#define _ASM_X86_INTEL_SCU_IPC_H_#include <linux/ioport.h> -#include <linux/notifier.h> #define IPCMSG_INDIRECT_READ 0x02#define IPCMSG_INDIRECT_WRITE 0x05
@@ -21,6 +20,7 @@#define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ struct device ; +struct intel_scu_ipc_dev ;/** * struct intel_scu_ipc_pdata - Platform data for SCU IPC
@@ -32,47 +32,39 @@ struct intel_scu_ipc_pdata {int irq; }; -int intel_scu_ipc_register (struct device *dev, -const struct intel_scu_ipc_pdata *pdata); - -/* Read single register */ -int intel_scu_ipc_ioread8 (u16 addr,u8 *data); - -/* Read a vector */ -int intel_scu_ipc_readv (u16 *addr,u8 *data,int len); - -/* Write single register */ -int intel_scu_ipc_iowrite8 (u16 addr,u8 data); - -/* Write a vector */ -int intel_scu_ipc_writev (u16 *addr,u8 *data,int len); - -/* Update single register based on the mask */ -int intel_scu_ipc_update_register (u16 addr,u8 data,u8 mask); - -/* Issue commands to the SCU with or without data */ -int intel_scu_ipc_simple_command (int cmd,int sub); -int intel_scu_ipc_command (int cmd,int sub,u32 *in,int inlen, -u32 *out,int outlen); - -extern struct blocking_notifier_head intel_scu_notifier; - -static inline void intel_scu_notifier_add (struct notifier_block *nb) -{ -blocking_notifier_chain_register (&intel_scu_notifier, nb); -} - -static inline void intel_scu_notifier_remove (struct notifier_block *nb) -{ -blocking_notifier_chain_unregister (&intel_scu_notifier, nb); -} - -static inline int intel_scu_notifier_post (unsigned long v,void *p) +struct intel_scu_ipc_dev * +intel_scu_ipc_register (struct device *dev,const struct intel_scu_ipc_pdata *pdata); + +struct intel_scu_ipc_dev *intel_scu_ipc_dev_get (void ); +void intel_scu_ipc_dev_put (struct intel_scu_ipc_dev *scu); +struct intel_scu_ipc_dev *devm_intel_scu_ipc_dev_get (struct device *dev); + +int intel_scu_ipc_dev_ioread8 (struct intel_scu_ipc_dev *scu,u16 addr, +u8 *data); +int intel_scu_ipc_dev_iowrite8 (struct intel_scu_ipc_dev *scu,u16 addr, +u8 data); +int intel_scu_ipc_dev_readv (struct intel_scu_ipc_dev *scu,u16 *addr, +u8 *data,size_t len); +int intel_scu_ipc_dev_writev (struct intel_scu_ipc_dev *scu,u16 *addr, +u8 *data,size_t len); + +int intel_scu_ipc_dev_update (struct intel_scu_ipc_dev *scu,u16 addr, +u8 data,u8 mask); + +int intel_scu_ipc_dev_simple_command (struct intel_scu_ipc_dev *scu,int cmd, +int sub); +int intel_scu_ipc_dev_command_with_size (struct intel_scu_ipc_dev *scu,int cmd, +int sub,const void *in,size_t inlen, +size_t size,void *out,size_t outlen); + +static inline int intel_scu_ipc_dev_command (struct intel_scu_ipc_dev *scu,int cmd, +int sub,const void *in,size_t inlen, +void *out,size_t outlen) { -return blocking_notifier_call_chain (&intel_scu_notifier, v, p); +return intel_scu_ipc_dev_command_with_size (scu, cmd, sub, in, inlen, + inlen, out, outlen); } -#define SCU_AVAILABLE 1 -#define SCU_DOWN 2 +#include <asm/intel_scu_ipc_legacy.h> #endif
arch/x86/include/asm/intel_scu_ipc_legacy.h new file +76 -0
76 lines not on this page · raw message
drivers/platform/x86/intel_scu_ipc.c +174 -45
362 lines not on this page · raw message
drivers/platform/x86/intel_scu_pcidrv.c +4 -3
@@ -18,6 +18,7 @@ static int intel_scu_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) {struct intel_scu_ipc_pdata pdata = {}; +struct intel_scu_ipc_dev *scu;int ret; ret =pcim_enable_device (pdev);
@@ -27,9 +28,9 @@ static int intel_scu_pci_probe(struct pci_dev *pdev, pdata.mem = pdev->resource[0 ]; pdata.irq = pdev->irq; - ret =intel_scu_ipc_register (&pdev->dev, &pdata); -if (ret) -return ret; + scu =intel_scu_ipc_register (&pdev->dev, &pdata); +if (IS_ERR (scu)) +return PTR_ERR (scu);intel_scu_devices_create ();return 0 ;
Signature · 1 line
2.24.1
Greg Kroah-Hartman
maintainerRe: [PATCH v4 14/38] platform/x86: intel_scu_ipc: Introduce new SCU IPC API
Quoted 30 lines · Mika Westerberg
The current SCU IPC API has been operating on a single instance and there has been no way to pin the providing module in place when the SCU IPC is in use.
This implements a new API that takes the SCU IPC instance as first parameter (NULL means the single instance is being used). The SCU IPC instance can be retrieved by calling new function
intel_scu_ipc_dev_get()that take care of pinning the providing module in place as long asintel_scu_ipc_dev_put()is not called.The old API is left there to support existing users which cannot be converted easily but it is put to a separate header that is subject to be removed eventually. Subsequent patches will convert most of the users to the new API.
Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- arch/x86/include/asm/intel_scu_ipc.h | 74 +++---- arch/x86/include/asm/intel_scu_ipc_legacy.h | 76 +++++++ drivers/platform/x86/intel_scu_ipc.c | 219 ++++++++++++++++---- drivers/platform/x86/intel_scu_pcidrv.c | 7 +- 4 files changed, 287 insertions(+), 89 deletions(-) create mode 100644 arch/x86/include/asm/intel_scu_ipc_legacy.harch/x86/include/asm/intel_scu_ipc.h +0
-0
arch/x86/include/asm/intel_scu_ipc.h line 3
Quoted 4 lines
arch/x86/include/asm/intel_scu_ipc.h +1
-1@@ -1,9 +1,8 @@/* SPDX-License-Identifier: GPL-2.0 */ #ifndef _ASM_X86_INTEL_SCU_IPC_H_ -#define _ASM_X86_INTEL_SCU_IPC_H_ +#define _ASM_X86_INTEL_SCU_IPC_H_
gratuitous change :(
Quoted 203 lines
arch/x86/include/asm/intel_scu_ipc.h +32
-40#include <linux/ioport.h> -#include <linux/notifier.h> #define IPCMSG_INDIRECT_READ 0x02#define IPCMSG_INDIRECT_WRITE 0x05@@ -21,6 +20,7 @@#define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ struct device ; +struct intel_scu_ipc_dev ;/** * struct intel_scu_ipc_pdata - Platform data for SCU IPC @@ -32,47 +32,39 @@ struct intel_scu_ipc_pdata {int irq; }; -int intel_scu_ipc_register (struct device *dev, -const struct intel_scu_ipc_pdata *pdata); - -/* Read single register */ -int intel_scu_ipc_ioread8 (u16 addr,u8 *data); - -/* Read a vector */ -int intel_scu_ipc_readv (u16 *addr,u8 *data,int len); - -/* Write single register */ -int intel_scu_ipc_iowrite8 (u16 addr,u8 data); - -/* Write a vector */ -int intel_scu_ipc_writev (u16 *addr,u8 *data,int len); - -/* Update single register based on the mask */ -int intel_scu_ipc_update_register (u16 addr,u8 data,u8 mask); - -/* Issue commands to the SCU with or without data */ -int intel_scu_ipc_simple_command (int cmd,int sub); -int intel_scu_ipc_command (int cmd,int sub,u32 *in,int inlen, -u32 *out,int outlen); - -extern struct blocking_notifier_head intel_scu_notifier; - -static inline void intel_scu_notifier_add (struct notifier_block *nb) -{ -blocking_notifier_chain_register (&intel_scu_notifier, nb); -} - -static inline void intel_scu_notifier_remove (struct notifier_block *nb) -{ -blocking_notifier_chain_unregister (&intel_scu_notifier, nb); -} - -static inline int intel_scu_notifier_post (unsigned long v,void *p) +struct intel_scu_ipc_dev * +intel_scu_ipc_register (struct device *dev,const struct intel_scu_ipc_pdata *pdata); + +struct intel_scu_ipc_dev *intel_scu_ipc_dev_get (void ); +void intel_scu_ipc_dev_put (struct intel_scu_ipc_dev *scu); +struct intel_scu_ipc_dev *devm_intel_scu_ipc_dev_get (struct device *dev); + +int intel_scu_ipc_dev_ioread8 (struct intel_scu_ipc_dev *scu,u16 addr, +u8 *data); +int intel_scu_ipc_dev_iowrite8 (struct intel_scu_ipc_dev *scu,u16 addr, +u8 data); +int intel_scu_ipc_dev_readv (struct intel_scu_ipc_dev *scu,u16 *addr, +u8 *data,size_t len); +int intel_scu_ipc_dev_writev (struct intel_scu_ipc_dev *scu,u16 *addr, +u8 *data,size_t len); + +int intel_scu_ipc_dev_update (struct intel_scu_ipc_dev *scu,u16 addr, +u8 data,u8 mask); + +int intel_scu_ipc_dev_simple_command (struct intel_scu_ipc_dev *scu,int cmd, +int sub); +int intel_scu_ipc_dev_command_with_size (struct intel_scu_ipc_dev *scu,int cmd, +int sub,const void *in,size_t inlen, +size_t size,void *out,size_t outlen); + +static inline int intel_scu_ipc_dev_command (struct intel_scu_ipc_dev *scu,int cmd, +int sub,const void *in,size_t inlen, +void *out,size_t outlen) { -return blocking_notifier_call_chain (&intel_scu_notifier, v, p); +return intel_scu_ipc_dev_command_with_size (scu, cmd, sub, in, inlen, + inlen, out, outlen); } -#define SCU_AVAILABLE 1 -#define SCU_DOWN 2 +#include <asm/intel_scu_ipc_legacy.h> #endif arch/x86/include/asm/intel_scu_ipc_legacy.h new file +76
-0@@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_INTEL_SCU_IPC_LEGACY_H_ +#define _ASM_X86_INTEL_SCU_IPC_LEGACY_H_ + +#include <linux/notifier.h> + +/* Don't call these in new code - they will be removed eventually */ + +/* Read single register */ +static inline int intel_scu_ipc_ioread8 (u16 addr,u8 *data) +{ +return intel_scu_ipc_dev_ioread8 (NULL , addr, data); +} + +/* Read a vector */ +static inline int intel_scu_ipc_readv (u16 *addr,u8 *data,int len) +{ +return intel_scu_ipc_dev_readv (NULL , addr, data, len); +} + +/* Write single register */ +static inline int intel_scu_ipc_iowrite8 (u16 addr,u8 data) +{ +return intel_scu_ipc_dev_iowrite8 (NULL , addr, data); +} + +/* Write a vector */ +static inline int intel_scu_ipc_writev (u16 *addr,u8 *data,int len) +{ +return intel_scu_ipc_dev_writev (NULL , addr, data, len); +} + +/* Update single register based on the mask */ +static inline int intel_scu_ipc_update_register (u16 addr,u8 data,u8 mask) +{ +return intel_scu_ipc_dev_update (NULL , addr, data, mask); +} + +/* Issue commands to the SCU with or without data */ +static inline int intel_scu_ipc_simple_command (int cmd,int sub) +{ +return intel_scu_ipc_dev_simple_command (NULL , cmd, sub); +} + +static inline int intel_scu_ipc_command (int cmd,int sub,u32 *in,int inlen, +u32 *out,int outlen) +{ +/* New API takes both inlen and outlen as bytes so convert here */ +size_t inbytes = inlen *sizeof (u32); +size_t outbytes = outlen *sizeof (u32); + +return intel_scu_ipc_dev_command_with_size (NULL , cmd, sub, in, inbytes, + inlen, out, outbytes); +} + +extern struct blocking_notifier_head intel_scu_notifier; + +static inline void intel_scu_notifier_add (struct notifier_block *nb) +{ +blocking_notifier_chain_register (&intel_scu_notifier, nb); +} + +static inline void intel_scu_notifier_remove (struct notifier_block *nb) +{ +blocking_notifier_chain_unregister (&intel_scu_notifier, nb); +} + +static inline int intel_scu_notifier_post (unsigned long v,void *p) +{ +return blocking_notifier_call_chain (&intel_scu_notifier, v, p); +} + +#define SCU_AVAILABLE 1 +#define SCU_DOWN 2 + +#endif drivers/platform/x86/intel_scu_ipc.c +14
-0@@ -19,6 +19,7 @@#include <linux/init.h> #include <linux/interrupt.h> #include <linux/io.h> +#include <linux/module.h> #include <asm/intel_scu_ipc.h> @@ -78,6 +79,99 @@ static struct intel_scu_ipc_dev ipcdev; /* Only one for now */static DEFINE_MUTEX (ipclock);/* lock used to prevent multiple call to SCU */ +/** +* intel_scu_ipc_dev_get() - Get SCU IPC instance +* +* The recommended new API takes SCU IPC instance as parameter and this +* function can be called by driver to get the instance. This also makes +* sure the driver providing the IPC functionality cannot be unloaded +* while the caller has the intance. +* +* Call intel_scu_ipc_dev_put() to release the instance. +* +* Returns %NULL if SCU IPC is not currently available. +*/ +struct intel_scu_ipc_dev *intel_scu_ipc_dev_get (void )
drivers/platform/x86/intel_scu_ipc.c static struct intel_scu_ipc_dev ipcdev; /* Only one for now */ · line 104
Quoted 10 lines
drivers/platform/x86/intel_scu_ipc.c +10
-0+{ +struct intel_scu_ipc_dev *scu = &ipcdev; + +mutex_lock (&ipclock); +if (!scu->dev) + goto err_unlock; +if (!try_module_get (scu->dev->driver->owner)) + goto err_unlock; +mutex_unlock (&ipclock); +return scu;
NO REFERENCE COUNT INCREMENT???
You owe me 5 recitations of the "Data Structures" of Documentation/process/coding-style.rst
And some whisky to get me through the next round of code reviews of this mess...
greg k-h
Mika Westerberg
maintainerRe: [PATCH v4 14/38] platform/x86: intel_scu_ipc: Introduce new SCU IPC API
Quoted 26 lines · Greg Kroah-Hartman
Quoted 25 lines · Mika Westerberg
The current SCU IPC API has been operating on a single instance and there has been no way to pin the providing module in place when the SCU IPC is in use.
This implements a new API that takes the SCU IPC instance as first parameter (NULL means the single instance is being used). The SCU IPC instance can be retrieved by calling new function
intel_scu_ipc_dev_get()that take care of pinning the providing module in place as long asintel_scu_ipc_dev_put()is not called.The old API is left there to support existing users which cannot be converted easily but it is put to a separate header that is subject to be removed eventually. Subsequent patches will convert most of the users to the new API.
Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- arch/x86/include/asm/intel_scu_ipc.h | 74 +++---- arch/x86/include/asm/intel_scu_ipc_legacy.h | 76 +++++++ drivers/platform/x86/intel_scu_ipc.c | 219 ++++++++++++++++---- drivers/platform/x86/intel_scu_pcidrv.c | 7 +- 4 files changed, 287 insertions(+), 89 deletions(-) create mode 100644 arch/x86/include/asm/intel_scu_ipc_legacy.h
Quoted 11 lines
arch/x86/include/asm/intel_scu_ipc.h line 3
Quoted 9 lines
arch/x86/include/asm/intel_scu_ipc.h +1
-1@@ -1,9 +1,8 @@/* SPDX-License-Identifier: GPL-2.0 */ #ifndef _ASM_X86_INTEL_SCU_IPC_H_ -#define _ASM_X86_INTEL_SCU_IPC_H_ +#define _ASM_X86_INTEL_SCU_IPC_H_gratuitous change :(
Oops.
Quoted 207 lines
Quoted 207 lines
arch/x86/include/asm/intel_scu_ipc.h +32
-40#include <linux/ioport.h> -#include <linux/notifier.h> #define IPCMSG_INDIRECT_READ 0x02#define IPCMSG_INDIRECT_WRITE 0x05@@ -21,6 +20,7 @@#define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ struct device ; +struct intel_scu_ipc_dev ;/** * struct intel_scu_ipc_pdata - Platform data for SCU IPC @@ -32,47 +32,39 @@ struct intel_scu_ipc_pdata {int irq; }; -int intel_scu_ipc_register (struct device *dev, -const struct intel_scu_ipc_pdata *pdata); - -/* Read single register */ -int intel_scu_ipc_ioread8 (u16 addr,u8 *data); - -/* Read a vector */ -int intel_scu_ipc_readv (u16 *addr,u8 *data,int len); - -/* Write single register */ -int intel_scu_ipc_iowrite8 (u16 addr,u8 data); - -/* Write a vector */ -int intel_scu_ipc_writev (u16 *addr,u8 *data,int len); - -/* Update single register based on the mask */ -int intel_scu_ipc_update_register (u16 addr,u8 data,u8 mask); - -/* Issue commands to the SCU with or without data */ -int intel_scu_ipc_simple_command (int cmd,int sub); -int intel_scu_ipc_command (int cmd,int sub,u32 *in,int inlen, -u32 *out,int outlen); - -extern struct blocking_notifier_head intel_scu_notifier; - -static inline void intel_scu_notifier_add (struct notifier_block *nb) -{ -blocking_notifier_chain_register (&intel_scu_notifier, nb); -} - -static inline void intel_scu_notifier_remove (struct notifier_block *nb) -{ -blocking_notifier_chain_unregister (&intel_scu_notifier, nb); -} - -static inline int intel_scu_notifier_post (unsigned long v,void *p) +struct intel_scu_ipc_dev * +intel_scu_ipc_register (struct device *dev,const struct intel_scu_ipc_pdata *pdata); + +struct intel_scu_ipc_dev *intel_scu_ipc_dev_get (void ); +void intel_scu_ipc_dev_put (struct intel_scu_ipc_dev *scu); +struct intel_scu_ipc_dev *devm_intel_scu_ipc_dev_get (struct device *dev); + +int intel_scu_ipc_dev_ioread8 (struct intel_scu_ipc_dev *scu,u16 addr, +u8 *data); +int intel_scu_ipc_dev_iowrite8 (struct intel_scu_ipc_dev *scu,u16 addr, +u8 data); +int intel_scu_ipc_dev_readv (struct intel_scu_ipc_dev *scu,u16 *addr, +u8 *data,size_t len); +int intel_scu_ipc_dev_writev (struct intel_scu_ipc_dev *scu,u16 *addr, +u8 *data,size_t len); + +int intel_scu_ipc_dev_update (struct intel_scu_ipc_dev *scu,u16 addr, +u8 data,u8 mask); + +int intel_scu_ipc_dev_simple_command (struct intel_scu_ipc_dev *scu,int cmd, +int sub); +int intel_scu_ipc_dev_command_with_size (struct intel_scu_ipc_dev *scu,int cmd, +int sub,const void *in,size_t inlen, +size_t size,void *out,size_t outlen); + +static inline int intel_scu_ipc_dev_command (struct intel_scu_ipc_dev *scu,int cmd, +int sub,const void *in,size_t inlen, +void *out,size_t outlen) { -return blocking_notifier_call_chain (&intel_scu_notifier, v, p); +return intel_scu_ipc_dev_command_with_size (scu, cmd, sub, in, inlen, + inlen, out, outlen); } -#define SCU_AVAILABLE 1 -#define SCU_DOWN 2 +#include <asm/intel_scu_ipc_legacy.h> #endif arch/x86/include/asm/intel_scu_ipc_legacy.h new file +76
-0@@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_INTEL_SCU_IPC_LEGACY_H_ +#define _ASM_X86_INTEL_SCU_IPC_LEGACY_H_ + +#include <linux/notifier.h> + +/* Don't call these in new code - they will be removed eventually */ + +/* Read single register */ +static inline int intel_scu_ipc_ioread8 (u16 addr,u8 *data) +{ +return intel_scu_ipc_dev_ioread8 (NULL , addr, data); +} + +/* Read a vector */ +static inline int intel_scu_ipc_readv (u16 *addr,u8 *data,int len) +{ +return intel_scu_ipc_dev_readv (NULL , addr, data, len); +} + +/* Write single register */ +static inline int intel_scu_ipc_iowrite8 (u16 addr,u8 data) +{ +return intel_scu_ipc_dev_iowrite8 (NULL , addr, data); +} + +/* Write a vector */ +static inline int intel_scu_ipc_writev (u16 *addr,u8 *data,int len) +{ +return intel_scu_ipc_dev_writev (NULL , addr, data, len); +} + +/* Update single register based on the mask */ +static inline int intel_scu_ipc_update_register (u16 addr,u8 data,u8 mask) +{ +return intel_scu_ipc_dev_update (NULL , addr, data, mask); +} + +/* Issue commands to the SCU with or without data */ +static inline int intel_scu_ipc_simple_command (int cmd,int sub) +{ +return intel_scu_ipc_dev_simple_command (NULL , cmd, sub); +} + +static inline int intel_scu_ipc_command (int cmd,int sub,u32 *in,int inlen, +u32 *out,int outlen) +{ +/* New API takes both inlen and outlen as bytes so convert here */ +size_t inbytes = inlen *sizeof (u32); +size_t outbytes = outlen *sizeof (u32); + +return intel_scu_ipc_dev_command_with_size (NULL , cmd, sub, in, inbytes, + inlen, out, outbytes); +} + +extern struct blocking_notifier_head intel_scu_notifier; + +static inline void intel_scu_notifier_add (struct notifier_block *nb) +{ +blocking_notifier_chain_register (&intel_scu_notifier, nb); +} + +static inline void intel_scu_notifier_remove (struct notifier_block *nb) +{ +blocking_notifier_chain_unregister (&intel_scu_notifier, nb); +} + +static inline int intel_scu_notifier_post (unsigned long v,void *p) +{ +return blocking_notifier_call_chain (&intel_scu_notifier, v, p); +} + +#define SCU_AVAILABLE 1 +#define SCU_DOWN 2 + +#endif drivers/platform/x86/intel_scu_ipc.c +18
-0@@ -19,6 +19,7 @@#include <linux/init.h> #include <linux/interrupt.h> #include <linux/io.h> +#include <linux/module.h> #include <asm/intel_scu_ipc.h> @@ -78,6 +79,99 @@ static struct intel_scu_ipc_dev ipcdev; /* Only one for now */static DEFINE_MUTEX (ipclock);/* lock used to prevent multiple call to SCU */ +/** +* intel_scu_ipc_dev_get() - Get SCU IPC instance +* +* The recommended new API takes SCU IPC instance as parameter and this +* function can be called by driver to get the instance. This also makes +* sure the driver providing the IPC functionality cannot be unloaded +* while the caller has the intance. +* +* Call intel_scu_ipc_dev_put() to release the instance. +* +* Returns %NULL if SCU IPC is not currently available. +*/ +struct intel_scu_ipc_dev *intel_scu_ipc_dev_get (void ) +{ +struct intel_scu_ipc_dev *scu = &ipcdev; + +mutex_lock (&ipclock);
Quoted 8 lines
drivers/platform/x86/intel_scu_ipc.c static struct intel_scu_ipc_dev ipcdev; /* Only one for now */ · line 104
Quoted 6 lines
drivers/platform/x86/intel_scu_ipc.c +6
-0+if (!scu->dev) + goto err_unlock; +if (!try_module_get (scu->dev->driver->owner)) + goto err_unlock; +mutex_unlock (&ipclock); +return scu;NO REFERENCE COUNT INCREMENT???
You mean increment the scu->dev reference count? I kind of thought that the try_module_get() should make sure the thing stays there as long as the caller has not called _put() but now when I think about it bit more we would need to do device_get() here as well.
Sorry about this.
Quoted 5 lines
You owe me 5 recitations of the "Data Structures" of
Documentation/process/coding-style.rstAnd some whisky to get me through the next round of code reviews of this mess...
Sure :)
Greg Kroah-Hartman
maintainerRe: [PATCH v4 14/38] platform/x86: intel_scu_ipc: Introduce new SCU IPC API
Quoted 10 lines · Mika Westerberg
Quoted 8 lines · Greg Kroah-Hartman
drivers/platform/x86/intel_scu_ipc.c static struct intel_scu_ipc_dev ipcdev; /* Only one for now */ · line 104
Quoted 6 lines
drivers/platform/x86/intel_scu_ipc.c +6
-0+if (!scu->dev) + goto err_unlock; +if (!try_module_get (scu->dev->driver->owner)) + goto err_unlock; +mutex_unlock (&ipclock); +return scu;NO REFERENCE COUNT INCREMENT???
Quoted 4 lines
You mean increment the
scu->devreference count? I kind of thought that thetry_module_get()should make sure the thing stays there as long as the caller has not called_put()but now when I think about it bit more we would need to dodevice_get()here as well.
module reference counts handle _code_ while structure reference counts handle _data_.
You should almost never need to worry about module reference counts if your code is structured properly, only handle the reference counts on the pointers you throw around.
The fact that you are even calling try_module_get() is a huge flag that something is wrong here.
thanks,
greg k-h
Mika Westerberg
maintainerRe: [PATCH v4 14/38] platform/x86: intel_scu_ipc: Introduce new SCU IPC API
Quoted 19 lines · Greg Kroah-Hartman
Quoted 10 lines · Mika Westerberg
Quoted 8 lines · Greg Kroah-Hartman
drivers/platform/x86/intel_scu_ipc.c static struct intel_scu_ipc_dev ipcdev; /* Only one for now */ · line 104
Quoted 6 lines
drivers/platform/x86/intel_scu_ipc.c +6
-0+if (!scu->dev) + goto err_unlock; +if (!try_module_get (scu->dev->driver->owner)) + goto err_unlock; +mutex_unlock (&ipclock); +return scu;NO REFERENCE COUNT INCREMENT???
Quoted 4 lines
You mean increment the
scu->devreference count? I kind of thought that thetry_module_get()should make sure the thing stays there as long as the caller has not called_put()but now when I think about it bit more we would need to dodevice_get()here as well.module reference counts handle _code_ while structure reference counts handle _data_.
Quoted 6 lines
You should almost never need to worry about module reference counts if your code is structured properly, only handle the reference counts on the pointers you throw around.
The fact that you are even calling
try_module_get()is a huge flag that something is wrong here.
Thanks for the explanation! I'll keep this in mind and make sure the next version has reference counting done accordingly.
Mika Westerberg
maintainerPATCH v4 15/38 platform/x86: intel_mid_powerbtn: Convert to use new SCU IPC API
In reply to Mika WesterbergThis converts the power button driver to use the new SCU IPC API where the SCU IPC instance is passed to the functions.
--- drivers/platform/x86/intel_mid_powerbtn.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/platform/x86/intel_mid_powerbtn.c +11 -4
@@ -46,6 +46,7 @@ struct mid_pb_ddata {unsigned short mirqlvl1_addr;unsigned short pbstat_addr;u8 pbstat_mask; +struct intel_scu_ipc_dev *scu;int (*setup)(struct mid_pb_ddata *ddata); };
@@ -55,7 +56,8 @@ static int mid_pbstat(struct mid_pb_ddata *ddata, int *value)int ret;u8 pbstat; - ret =intel_scu_ipc_ioread8 (ddata->pbstat_addr, &pbstat); + ret =intel_scu_ipc_dev_ioread8 (ddata->scu, ddata->pbstat_addr, + &pbstat);if (ret)return ret;
@@ -67,14 +69,15 @@ static int mid_pbstat(struct mid_pb_ddata *ddata, int *value)static int mid_irq_ack (struct mid_pb_ddata *ddata) { -return intel_scu_ipc_update_register (ddata->mirqlvl1_addr,0 ,MSIC_PWRBTNM ); +return intel_scu_ipc_dev_update (ddata->scu, ddata->mirqlvl1_addr,0 , +MSIC_PWRBTNM ); }static int mrfld_setup (struct mid_pb_ddata *ddata) {/* Unmask the PBIRQ and MPBIRQ on Tangier */ -intel_scu_ipc_update_register (BCOVE_PBIRQ ,0 ,MSIC_PWRBTNM ); -intel_scu_ipc_update_register (BCOVE_PBIRQMASK ,0 ,MSIC_PWRBTNM ); +intel_scu_ipc_dev_update (ddata->scu,BCOVE_PBIRQ ,0 ,MSIC_PWRBTNM ); +intel_scu_ipc_dev_update (ddata->scu,BCOVE_PBIRQMASK ,0 ,MSIC_PWRBTNM );return 0 ; }
@@ -161,6 +164,10 @@ static int mid_pb_probe(struct platform_device *pdev)return error; } + ddata->scu =devm_intel_scu_ipc_dev_get (&pdev->dev); +if (!ddata->scu) +return -EPROBE_DEFER ; + error =devm_request_threaded_irq (&pdev->dev, irq,NULL , mid_pb_isr,IRQF_ONESHOT ,DRIVER_NAME , ddata);if (error) {
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 16/38 watchdog: intel-mid_wdt: Convert to use new SCU IPC API
In reply to Mika WesterbergThis converts the Intel MID watchdog driver over the new SCU IPC API where the SCU IPC instance is passed to the functions.
--- drivers/watchdog/intel-mid_wdt.c | 53 ++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 16 deletions(-)
drivers/watchdog/intel-mid_wdt.c +37 -16
@@ -33,14 +33,24 @@ enum { SCU_WATCHDOG_KEEPALIVE, }; -static inline int wdt_command (int sub,u32 *in,int inlen) +struct mid_wdt { +struct watchdog_device wd; +struct device *dev; +struct intel_scu_ipc_dev *scu; +}; + +static inline int +wdt_command (struct mid_wdt *mid,int sub,const void *in,size_t inlen,size_t size) { -return intel_scu_ipc_command (IPC_WATCHDOG , sub, in, inlen,NULL ,0 ); +struct intel_scu_ipc_dev *scu = mid->scu; + +return intel_scu_ipc_dev_command_with_size (scu,IPC_WATCHDOG , sub, in, + inlen, size,NULL ,0 ); }static int wdt_start (struct watchdog_device *wd) { -struct device *dev =watchdog_get_drvdata (wd); +struct mid_wdt *mid =watchdog_get_drvdata (wd);int ret, in_size;int timeout = wd->timeout; struct ipc_wd_start {
@@ -49,38 +59,41 @@ static int wdt_start(struct watchdog_device *wd) } ipc_wd_start = { timeout - MID_WDT_PRETIMEOUT, timeout };/* -* SCU expects the input size for watchdog IPC to -* be based on 4 bytes +* SCU expects the input size for watchdog IPC to be 2 which is the +* size of the structure in dwords. SCU IPC normally takes bytes +* but this is a special case where we specify size to be different +* than inlen. */ in_size =DIV_ROUND_UP (sizeof (ipc_wd_start),4 ); - ret =wdt_command (SCU_WATCHDOG_START , (u32 *)&ipc_wd_start, in_size); + ret =wdt_command (mid,SCU_WATCHDOG_START , &ipc_wd_start, +sizeof (ipc_wd_start), in_size);if (ret) -dev_crit (dev,"error starting watchdog: %d\n" , ret); +dev_crit (mid->dev,"error starting watchdog: %d\n" , ret);return ret; }static int wdt_ping (struct watchdog_device *wd) { -struct device *dev =watchdog_get_drvdata (wd); +struct mid_wdt *mid =watchdog_get_drvdata (wd);int ret; - ret =wdt_command (SCU_WATCHDOG_KEEPALIVE ,NULL ,0 ); + ret =wdt_command (mid,SCU_WATCHDOG_KEEPALIVE ,NULL ,0 ,0 );if (ret) -dev_crit (dev,"Error executing keepalive: %d\n" , ret); +dev_crit (mid->dev,"Error executing keepalive: %d\n" , ret);return ret; }static int wdt_stop (struct watchdog_device *wd) { -struct device *dev =watchdog_get_drvdata (wd); +struct mid_wdt *mid =watchdog_get_drvdata (wd);int ret; - ret =wdt_command (SCU_WATCHDOG_STOP ,NULL ,0 ); + ret =wdt_command (mid,SCU_WATCHDOG_STOP ,NULL ,0 ,0 );if (ret) -dev_crit (dev,"Error stopping watchdog: %d\n" , ret); +dev_crit (mid->dev,"Error stopping watchdog: %d\n" , ret);return ret; }
@@ -110,6 +123,7 @@ static int mid_wdt_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct watchdog_device *wdt_dev;struct intel_mid_wdt_pdata *pdata = dev->platform_data; +struct mid_wdt *mid;int ret;if (!pdata) {
@@ -123,10 +137,13 @@ static int mid_wdt_probe(struct platform_device *pdev)return ret; } - wdt_dev =devm_kzalloc (dev,sizeof (*wdt_dev),GFP_KERNEL ); -if (!wdt_dev) + mid =devm_kzalloc (dev,sizeof (*mid),GFP_KERNEL ); +if (!mid)return -ENOMEM ; + mid->dev = dev; + wdt_dev = &mid->wd; + wdt_dev->info = &mid_wdt_info; wdt_dev->ops = &mid_wdt_ops; wdt_dev->min_timeout =MID_WDT_TIMEOUT_MIN ;
@@ -135,7 +152,7 @@ static int mid_wdt_probe(struct platform_device *pdev) wdt_dev->parent = dev;watchdog_set_nowayout (wdt_dev,WATCHDOG_NOWAYOUT ); -watchdog_set_drvdata (wdt_dev, dev); +watchdog_set_drvdata (wdt_dev, mid); ret = devm_request_irq(dev, pdata->irq, mid_wdt_irq, IRQF_SHARED | IRQF_NO_SUSPEND, "watchdog",
@@ -145,6 +162,10 @@ static int mid_wdt_probe(struct platform_device *pdev)return ret; } + mid->scu =devm_intel_scu_ipc_dev_get (dev); +if (!mid->scu) +return -EPROBE_DEFER ; +/* * The firmware followed by U-Boot leaves the watchdog running * with the default threshold which may vary. When we get here
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 17/38 platform/x86: intel_scu_ipcutil: Convert to use new SCU IPC API
In reply to Mika WesterbergConvert the IPC util to use the new SCU IPC API where the SCU IPC instance is passed to the functions.
--- drivers/platform/x86/intel_scu_ipcutil.c | 43 +++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-)
drivers/platform/x86/intel_scu_ipcutil.c +39 -4
@@ -22,6 +22,9 @@static int major; +struct intel_scu_ipc_dev *scu; +static DEFINE_MUTEX (scu_lock); +/* IOCTL commands */ #define INTE_SCU_IPC_REGISTER_READ 0#define INTE_SCU_IPC_REGISTER_WRITE 1
@@ -52,12 +55,12 @@ static int scu_reg_access(u32 cmd, struct scu_ipc_data *data)switch (cmd) {case INTE_SCU_IPC_REGISTER_READ : -return intel_scu_ipc_readv (data->addr, data->data, count); +return intel_scu_ipc_dev_readv (scu, data->addr, data->data, count);case INTE_SCU_IPC_REGISTER_WRITE : -return intel_scu_ipc_writev (data->addr, data->data, count); +return intel_scu_ipc_dev_writev (scu, data->addr, data->data, count);case INTE_SCU_IPC_REGISTER_UPDATE : -return intel_scu_ipc_update_register (data->addr[0 ], - data->data[0 ], data->mask); +return intel_scu_ipc_dev_update (scu, data->addr[0 ], data->data[0 ], + data->mask);default :return -ENOTTY ; }
@@ -91,8 +94,40 @@ static long scu_ipc_ioctl(struct file *fp, unsigned int cmd,return 0 ; } +static int scu_ipc_open (struct inode *inode,struct file *file) +{ +int ret =0 ; + +/* Only single open at the time */ +mutex_lock (&scu_lock); +if (scu) { + ret = -EBUSY ; + goto unlock; + } + + scu =intel_scu_ipc_dev_get (); +if (!scu) + ret = -ENODEV ; + +unlock: +mutex_unlock (&scu_lock); +return ret; +} + +static int scu_ipc_release (struct inode *inode,struct file *file) +{ +mutex_lock (&scu_lock); +intel_scu_ipc_dev_put (scu); + scu =NULL ; +mutex_unlock (&scu_lock); + +return 0 ; +} +static const struct file_operations scu_ipc_fops = { .unlocked_ioctl = scu_ipc_ioctl, + .open = scu_ipc_open, + .release = scu_ipc_release, };static int __init ipc_module_init (void )
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 18/38 platform/x86: intel_pmc_ipc: Make intel_pmc_gcr_update() static
In reply to Mika WesterbergThis function is not called outside of intel_pmc_ipc.c so we can make it static instead.
--- arch/x86/include/asm/intel_pmc_ipc.h | 6 ------ drivers/platform/x86/intel_pmc_ipc.c | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-)
arch/x86/include/asm/intel_pmc_ipc.h +0 -6
@@ -40,7 +40,6 @@ int intel_pmc_s0ix_counter_read(u64 *data);int intel_pmc_gcr_read (u32 offset,u32 *data);int intel_pmc_gcr_read64 (u32 offset,u64 *data);int intel_pmc_gcr_write (u32 offset,u32 data); -int intel_pmc_gcr_update (u32 offset,u32 mask,u32 val);#else
@@ -81,11 +80,6 @@ static inline int intel_pmc_gcr_write(u32 offset, u32 data)return -EINVAL ; } -static inline int intel_pmc_gcr_update (u32 offset,u32 mask,u32 val) -{ -return -EINVAL ; -} -#endif /*CONFIG_INTEL_PMC_IPC*/ #endif
drivers/platform/x86/intel_pmc_ipc.c +1 -2
@@ -309,7 +309,7 @@ EXPORT_SYMBOL_GPL(intel_pmc_gcr_write);* * Return: negative value on error or 0 on success. */ -int intel_pmc_gcr_update (u32 offset,u32 mask,u32 val) +static int intel_pmc_gcr_update (u32 offset,u32 mask,u32 val) {u32 new_val;int ret =0 ;
@@ -339,7 +339,6 @@ int intel_pmc_gcr_update(u32 offset, u32 mask, u32 val)spin_unlock (&ipcdev.gcr_lock);return ret; } -EXPORT_SYMBOL_GPL (intel_pmc_gcr_update);static int update_no_reboot_bit (void *priv,bool set) {
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 19/38 platform/x86: intel_pmc_ipc: Make intel_pmc_ipc_simple_command() static
In reply to Mika WesterbergThis function is not called outside of intel_pmc_ipc.c so we can make it static instead.
--- arch/x86/include/asm/intel_pmc_ipc.h | 6 ------ drivers/platform/x86/intel_pmc_ipc.c | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-)
arch/x86/include/asm/intel_pmc_ipc.h +0 -6
@@ -31,7 +31,6 @@#if IS_ENABLED (CONFIG_INTEL_PMC_IPC ) -int intel_pmc_ipc_simple_command (int cmd,int sub);int intel_pmc_ipc_raw_cmd (u32 cmd,u32 sub,u8 *in,u32 inlen,u32 *out,u32 outlen,u32 dptr,u32 sptr); int intel_pmc_ipc_command(u32 cmd, u32 sub, u8 *in, u32 inlen,
@@ -43,11 +42,6 @@ int intel_pmc_gcr_write(u32 offset, u32 data);#else -static inline int intel_pmc_ipc_simple_command (int cmd,int sub) -{ -return -EINVAL ; -} -static inline int intel_pmc_ipc_raw_cmd (u32 cmd,u32 sub,u8 *in,u32 inlen,u32 *out,u32 outlen,u32 dptr,u32 sptr) {
drivers/platform/x86/intel_pmc_ipc.c +1 -2
@@ -404,7 +404,7 @@ static int intel_pmc_ipc_check_status(void)* * Return: an IPC error code or 0 on success. */ -int intel_pmc_ipc_simple_command (int cmd,int sub) +static int intel_pmc_ipc_simple_command (int cmd,int sub) {int ret;
@@ -419,7 +419,6 @@ int intel_pmc_ipc_simple_command(int cmd, int sub)return ret; } -EXPORT_SYMBOL_GPL (intel_pmc_ipc_simple_command);/** * intel_pmc_ipc_raw_cmd() - IPC command with data and pointers
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 20/38 platform/x86: intel_pmc_ipc: Make intel_pmc_ipc_raw_cmd() static
In reply to Mika WesterbergThis function is not called outside of intel_pmc_ipc.c so we can make it static instead.
--- arch/x86/include/asm/intel_pmc_ipc.h | 8 -------- drivers/platform/x86/intel_pmc_ipc.c | 5 ++--- 2 files changed, 2 insertions(+), 11 deletions(-)
arch/x86/include/asm/intel_pmc_ipc.h +0 -8
@@ -31,8 +31,6 @@#if IS_ENABLED (CONFIG_INTEL_PMC_IPC ) -int intel_pmc_ipc_raw_cmd (u32 cmd,u32 sub,u8 *in,u32 inlen, -u32 *out,u32 outlen,u32 dptr,u32 sptr);int intel_pmc_ipc_command (u32 cmd,u32 sub,u8 *in,u32 inlen,u32 *out,u32 outlen);int intel_pmc_s0ix_counter_read (u64 *data);
@@ -42,12 +40,6 @@ int intel_pmc_gcr_write(u32 offset, u32 data);#else -static inline int intel_pmc_ipc_raw_cmd (u32 cmd,u32 sub,u8 *in,u32 inlen, -u32 *out,u32 outlen,u32 dptr,u32 sptr) -{ -return -EINVAL ; -} -static inline int intel_pmc_ipc_command (u32 cmd,u32 sub,u8 *in,u32 inlen,u32 *out,u32 outlen) {
drivers/platform/x86/intel_pmc_ipc.c +2 -3
@@ -435,8 +435,8 @@ static int intel_pmc_ipc_simple_command(int cmd, int sub)* * Return: an IPC error code or 0 on success. */ -int intel_pmc_ipc_raw_cmd (u32 cmd,u32 sub,u8 *in,u32 inlen,u32 *out, -u32 outlen,u32 dptr,u32 sptr) +static int intel_pmc_ipc_raw_cmd (u32 cmd,u32 sub,u8 *in,u32 inlen,u32 *out, +u32 outlen,u32 dptr,u32 sptr) {u32 wbuf[4 ] = {0 };int ret;
@@ -468,7 +468,6 @@ int intel_pmc_ipc_raw_cmd(u32 cmd, u32 sub, u8 *in, u32 inlen, u32 *out,return ret; } -EXPORT_SYMBOL_GPL (intel_pmc_ipc_raw_cmd);/** * intel_pmc_ipc_command() - IPC command with input/output data
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 21/38 platform/x86: intel_pmc_ipc: Drop intel_pmc_gcr_read() and intel_pmc_gcr_write()
In reply to Mika WesterbergThese functions are not used anywhere so drop them completely.
--- arch/x86/include/asm/intel_pmc_ipc.h | 12 ------ drivers/platform/x86/intel_pmc_ipc.c | 59 ---------------------------- 2 files changed, 71 deletions(-)
arch/x86/include/asm/intel_pmc_ipc.h +0 -12
@@ -34,9 +34,7 @@int intel_pmc_ipc_command (u32 cmd,u32 sub,u8 *in,u32 inlen,u32 *out,u32 outlen);int intel_pmc_s0ix_counter_read (u64 *data); -int intel_pmc_gcr_read (u32 offset,u32 *data);int intel_pmc_gcr_read64 (u32 offset,u64 *data); -int intel_pmc_gcr_write (u32 offset,u32 data);#else
@@ -51,21 +49,11 @@ static inline int intel_pmc_s0ix_counter_read(u64 *data)return -EINVAL ; } -static inline int intel_pmc_gcr_read (u32 offset,u32 *data) -{ -return -EINVAL ; -} -static inline int intel_pmc_gcr_read64 (u32 offset,u64 *data) {return -EINVAL ; } -static inline int intel_pmc_gcr_write (u32 offset,u32 data) -{ -return -EINVAL ; -} -#endif /*CONFIG_INTEL_PMC_IPC*/ #endif
drivers/platform/x86/intel_pmc_ipc.c +0 -59
71 lines not on this page · raw message
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 22/38 platform/x86: intel_pmc_ipc: Drop ipc_data_readb()
In reply to Mika WesterbergThis function is not used anywhere so drop it completely.
--- drivers/platform/x86/intel_pmc_ipc.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/platform/x86/intel_pmc_ipc.c +0 -5
@@ -184,11 +184,6 @@ static inline void ipc_data_writel(u32 data, u32 offset)writel (data, ipcdev.ipc_base +IPC_WRITE_BUFFER + offset); } -static inline u8 __maybe_unused ipc_data_readb (u32 offset) -{ -return readb (ipcdev.ipc_base +IPC_READ_BUFFER + offset); -} -static inline u32 ipc_data_readl (u32 offset) {return readl (ipcdev.ipc_base +IPC_READ_BUFFER + offset);
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 23/38 platform/x86: intel_pmc_ipc: Get rid of unnecessary includes
In reply to Mika WesterbergThere is no point including headers that are not needed in the driver so drop them.
--- drivers/platform/x86/intel_pmc_ipc.c | 10 ---------- 1 file changed, 10 deletions(-)
drivers/platform/x86/intel_pmc_ipc.c +0 -10
@@ -12,23 +12,13 @@*/ #include <linux/acpi.h> -#include <linux/atomic.h> -#include <linux/bitops.h> #include <linux/delay.h> -#include <linux/device.h> #include <linux/errno.h> #include <linux/interrupt.h> #include <linux/io-64-nonatomic-lo-hi.h> -#include <linux/kernel.h> #include <linux/module.h> -#include <linux/notifier.h> #include <linux/pci.h> #include <linux/platform_device.h> -#include <linux/pm.h> -#include <linux/pm_qos.h> -#include <linux/sched.h> -#include <linux/spinlock.h> -#include <linux/suspend.h> #include <asm/intel_pmc_ipc.h>
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 24/38 platform/x86: intel_scu_ipc: Add managed function to register SCU IPC
In reply to Mika WesterbergDrivers such as intel_pmc_ipc.c can be unloaded as well so in order to support those in this driver add a new function that can be called to unregister the SCU IPC when it is not needed anymore.
We also add a managed version of the intel_scu_ipc_register() that takes care of calling intel_scu_ipc_unregister() automatically when the driver is unbound.
--- arch/x86/include/asm/intel_scu_ipc.h | 3 ++ drivers/platform/x86/intel_scu_ipc.c | 63 ++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+)
arch/x86/include/asm/intel_scu_ipc.h +3 -0
@@ -34,6 +34,9 @@ struct intel_scu_ipc_pdata {struct intel_scu_ipc_dev *intel_scu_ipc_register (struct device *dev,const struct intel_scu_ipc_pdata *pdata); +void intel_scu_ipc_unregister (struct intel_scu_ipc_dev *scu); +struct intel_scu_ipc_dev * +devm_intel_scu_ipc_register (struct device *dev,const struct intel_scu_ipc_pdata *pdata);struct intel_scu_ipc_dev *intel_scu_ipc_dev_get (void );void intel_scu_ipc_dev_put (struct intel_scu_ipc_dev *scu);
drivers/platform/x86/intel_scu_ipc.c +63 -0
66 lines not on this page · raw message
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 25/38 platform/x86: intel_pmc_ipc: Start using SCU IPC
In reply to Mika WesterbergSCU IPC is pretty much the same IPC implemented in the intel_pmc_ipc driver so drop the duplicate implementation and call directly the SCU IPC.
--- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_pmc_ipc.c | 303 ++++----------------------- 2 files changed, 43 insertions(+), 261 deletions(-)
drivers/platform/x86/Kconfig +1 -0
@@ -1193,6 +1193,7 @@ config INTEL_SMARTCONNECT config INTEL_PMC_IPC tristate "Intel PMC IPC Driver" depends on ACPI && PCI + select INTEL_SCU_IPC ---help--- This driver provides support for PMC control on some Intel platforms. The PMC is an ARC processor which defines IPC commands for communication
drivers/platform/x86/intel_pmc_ipc.c +42 -261
445 lines not on this page · raw message
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 26/38 mfd: intel_soc_pmic: Add SCU IPC member to struct intel_soc_pmic
In reply to Mika WesterbergBoth PMIC drivers (intel_soc_pmic_mrfld and intel_soc_pmic_bxtwc) will be using this field going forward to access the SCU IPC instance.
While there add kernel-doc for the intel_soc_pmic structure.
--- include/linux/mfd/intel_soc_pmic.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
include/linux/mfd/intel_soc_pmic.h +15 -0
@@ -13,6 +13,20 @@#include <linux/regmap.h> +/** +* struct intel_soc_pmic - Intel SoC PMIC data +* @irq: Master interrupt number of the parent PMIC device +* @regmap: Pointer to the parent PMIC device regmap structure +* @irq_chip_data: IRQ chip data for the PMIC itself +* @irq_chip_data_pwrbtn: Chained IRQ chip data for the power button +* @irq_chip_data_tmu: Chained IRQ chip data for the time management unit +* @irq_chip_data_bcu: Chained IRQ chip data for the burst control unit +* @irq_chip_data_adc: Chained IRQ chip data for the general purpose ADC +* @irq_chip_data_chgr: Chained IRQ chip data for the external charger +* @irq_chip_data_crit: Chained IRQ chip data for the critical event handler +* @dev: Pointer to the parent PMIC device +* @scu: Pointer to the SCU IPC device data structure +*/ struct intel_soc_pmic {int irq;struct regmap *regmap;
@@ -24,6 +38,7 @@ struct intel_soc_pmic {struct regmap_irq_chip_data *irq_chip_data_chgr;struct regmap_irq_chip_data *irq_chip_data_crit;struct device *dev; +struct intel_scu_ipc_dev *scu; }; int intel_soc_pmic_exec_mipi_pmic_seq_element(u16 i2c_address, u32 reg_address,
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 27/38 mfd: intel_soc_pmic_bxtwc: Convert to use new SCU IPC API
In reply to Mika WesterbergConvert the Intel Broxton Whiskey Cover PMIC driver to use the new SCU IPC API. This allows us to get rid of the PMC IPC implementation which is now covered in SCU IPC driver.
Also move PMIC specific IPC message constants to the PMIC driver from the intel_pmc_ipc.h header.
--- arch/x86/include/asm/intel_pmc_ipc.h | 3 --- drivers/mfd/intel_soc_pmic_bxtwc.c | 22 +++++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-)
arch/x86/include/asm/intel_pmc_ipc.h +0 -3
@@ -3,9 +3,6 @@#define _ASM_X86_INTEL_PMC_IPC_H_/* Commands */ -#define PMC_IPC_PMIC_ACCESS 0xFF -#define PMC_IPC_PMIC_ACCESS_READ 0x0 -#define PMC_IPC_PMIC_ACCESS_WRITE 0x1#define PMC_IPC_USB_PWR_CTRL 0xF0#define PMC_IPC_PMIC_BLACKLIST_SEL 0xEF#define PMC_IPC_PHY_CONFIG 0xEE
drivers/mfd/intel_soc_pmic_bxtwc.c +15 -7
@@ -15,7 +15,7 @@#include <linux/mfd/intel_soc_pmic_bxtwc.h> #include <linux/module.h> -#include <asm/intel_pmc_ipc.h> +#include <asm/intel_scu_ipc.h> /* PMIC device registers */ #define REG_ADDR_MASK 0xFF00
@@ -58,6 +58,10 @@/* Whiskey Cove PMIC share same ACPI ID between different platforms */ #define BROXTON_PMIC_WC_HRV 4 +#define PMC_PMIC_ACCESS 0xFF +#define PMC_PMIC_READ 0x0 +#define PMC_PMIC_WRITE 0x1 +enum bxtwc_irqs {BXTWC_PWRBTN_LVL1_IRQ =0 ,BXTWC_TMU_LVL1_IRQ ,
@@ -288,9 +292,9 @@ static int regmap_ipc_byte_reg_read(void *context, unsigned int reg, ipc_in[0 ] = reg; ipc_in[1 ] = i2c_addr; - ret =intel_pmc_ipc_command (PMC_IPC_PMIC_ACCESS , -PMC_IPC_PMIC_ACCESS_READ , - ipc_in,sizeof (ipc_in), (u32 *)ipc_out,1 ); + ret =intel_scu_ipc_dev_command (pmic->scu,PMC_PMIC_ACCESS , +PMC_PMIC_READ , ipc_in,sizeof (ipc_in), + ipc_out,sizeof (ipc_out));if (ret) {dev_err (pmic->dev,"Failed to read from PMIC\n" );return ret;
@@ -321,9 +325,9 @@ static int regmap_ipc_byte_reg_write(void *context, unsigned int reg, ipc_in[0 ] = reg; ipc_in[1 ] = i2c_addr; ipc_in[2 ] = val; - ret =intel_pmc_ipc_command (PMC_IPC_PMIC_ACCESS , -PMC_IPC_PMIC_ACCESS_WRITE , - ipc_in,sizeof (ipc_in),NULL ,0 ); + ret =intel_scu_ipc_dev_command (pmic->scu,PMC_PMIC_ACCESS , +PMC_PMIC_WRITE , ipc_in,sizeof (ipc_in), +NULL ,0 );if (ret) {dev_err (pmic->dev,"Failed to write to PMIC\n" );return ret;
@@ -457,6 +461,10 @@ static int bxtwc_probe(struct platform_device *pdev)dev_set_drvdata (&pdev->dev, pmic); pmic->dev = &pdev->dev; + pmic->scu =devm_intel_scu_ipc_dev_get (&pdev->dev); +if (!pmic->scu) +return -EPROBE_DEFER ; + pmic->regmap =devm_regmap_init (&pdev->dev,NULL , pmic, &bxtwc_regmap_config);if (IS_ERR (pmic->regmap)) {
Signature · 1 line
2.24.1
Greg Kroah-Hartman
maintainerRe: [PATCH v4 27/38] mfd: intel_soc_pmic_bxtwc: Convert to use new SCU IPC API
Quoted 54 lines · Mika Westerberg
Convert the Intel Broxton Whiskey Cover PMIC driver to use the new SCU IPC API. This allows us to get rid of the PMC IPC implementation which is now covered in SCU IPC driver.
Also move PMIC specific IPC message constants to the PMIC driver from the
intel_pmc_ipc.hheader.Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- arch/x86/include/asm/intel_pmc_ipc.h | 3 --- drivers/mfd/intel_soc_pmic_bxtwc.c | 22 +++++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-)arch/x86/include/asm/intel_pmc_ipc.h +0
-3@@ -3,9 +3,6 @@#define _ASM_X86_INTEL_PMC_IPC_H_/* Commands */ -#define PMC_IPC_PMIC_ACCESS 0xFF -#define PMC_IPC_PMIC_ACCESS_READ 0x0 -#define PMC_IPC_PMIC_ACCESS_WRITE 0x1#define PMC_IPC_USB_PWR_CTRL 0xF0#define PMC_IPC_PMIC_BLACKLIST_SEL 0xEF#define PMC_IPC_PHY_CONFIG 0xEEdrivers/mfd/intel_soc_pmic_bxtwc.c +5
-1@@ -15,7 +15,7 @@#include <linux/mfd/intel_soc_pmic_bxtwc.h> #include <linux/module.h> -#include <asm/intel_pmc_ipc.h> +#include <asm/intel_scu_ipc.h> /* PMIC device registers */ #define REG_ADDR_MASK 0xFF00@@ -58,6 +58,10 @@/* Whiskey Cove PMIC share same ACPI ID between different platforms */ #define BROXTON_PMIC_WC_HRV 4 +#define PMC_PMIC_ACCESS 0xFF +#define PMC_PMIC_READ 0x0 +#define PMC_PMIC_WRITE 0x1 +enum bxtwc_irqs {BXTWC_PWRBTN_LVL1_IRQ =0 ,BXTWC_TMU_LVL1_IRQ ,@@ -288,9 +292,9 @@ static int regmap_ipc_byte_reg_read(void *context, unsigned int reg,
drivers/mfd/intel_soc_pmic_bxtwc.c static int regmap_ipc_byte_reg_read(void *context, unsigned int reg, · line 299
Quoted 10 lines
drivers/mfd/intel_soc_pmic_bxtwc.c +3
-3ipc_in[0 ] = reg; ipc_in[1 ] = i2c_addr; - ret =intel_pmc_ipc_command (PMC_IPC_PMIC_ACCESS , -PMC_IPC_PMIC_ACCESS_READ , - ipc_in,sizeof (ipc_in), (u32 *)ipc_out,1 ); + ret =intel_scu_ipc_dev_command (pmic->scu,PMC_PMIC_ACCESS , +PMC_PMIC_READ , ipc_in,sizeof (ipc_in), + ipc_out,sizeof (ipc_out));if (ret) {dev_err (pmic->dev,"Failed to read from PMIC\n" );
Meta-comment, the call should be the thing making that error message, do not force all callers to log it again, or in some other way. That just makes for a larger mess.
thanks,
greg k-h
Mika Westerberg
maintainerRe: [PATCH v4 27/38] mfd: intel_soc_pmic_bxtwc: Convert to use new SCU IPC API
Quoted 6 lines · Greg Kroah-Hartman
drivers/mfd/intel_soc_pmic_bxtwc.c static int regmap_ipc_byte_reg_read(void *context, unsigned int reg, · line 299
Quoted 2 lines
drivers/mfd/intel_soc_pmic_bxtwc.c +0
-0if (ret) {dev_err (pmic->dev,"Failed to read from PMIC\n" );Meta-comment, the call should be the thing making that error message, do not force all callers to log it again, or in some other way. That just makes for a larger mess.
OK, I'll do that.
Mika Westerberg
maintainerPATCH v4 28/38 mfd: intel_soc_pmic_mrfld: Convert to use new SCU IPC API
In reply to Mika WesterbergThis converts the Intel Merrifield PMIC driver over the new SCU IPC API where the SCU IPC instance is passed to the functions.
--- drivers/mfd/intel_soc_pmic_mrfld.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/mfd/intel_soc_pmic_mrfld.c +8 -2
@@ -74,10 +74,11 @@ static const struct mfd_cell bcove_dev[] = {static int bcove_ipc_byte_reg_read (void *context,unsigned int reg,unsigned int *val) { +struct intel_soc_pmic *pmic = context;u8 ipc_out;int ret; - ret =intel_scu_ipc_ioread8 (reg, &ipc_out); + ret =intel_scu_ipc_dev_ioread8 (pmic->scu, reg, &ipc_out);if (ret)return ret;
@@ -88,10 +89,11 @@ static int bcove_ipc_byte_reg_read(void *context, unsigned int reg,static int bcove_ipc_byte_reg_write (void *context,unsigned int reg,unsigned int val) { +struct intel_soc_pmic *pmic = context;u8 ipc_in = val;int ret; - ret =intel_scu_ipc_iowrite8 (reg, ipc_in); + ret =intel_scu_ipc_dev_iowrite8 (pmic->scu, reg, ipc_in);if (ret)return ret;
@@ -117,6 +119,10 @@ static int bcove_probe(struct platform_device *pdev)if (!pmic)return -ENOMEM ; + pmic->scu =devm_intel_scu_ipc_dev_get (dev); +if (!pmic->scu) +return -ENOMEM ; +platform_set_drvdata (pdev, pmic); pmic->dev = &pdev->dev;
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 29/38 platform/x86: intel_telemetry: Convert to use new SCU IPC API
In reply to Mika WesterbergConvert the Intel Apollo Lake telemetry driver to use the new SCU IPC API. This allows us to get rid of the duplicate PMC IPC implementation which is now covered in SCU IPC driver.
Also move telemetry specific IPC message constant to the telemetry driver where it belongs.
--- arch/x86/include/asm/intel_pmc_ipc.h | 1 - arch/x86/include/asm/intel_telemetry.h | 3 + drivers/platform/x86/intel_telemetry_pltdrv.c | 101 +++++++++--------- 3 files changed, 55 insertions(+), 50 deletions(-)
arch/x86/include/asm/intel_pmc_ipc.h +0 -1
@@ -8,7 +8,6 @@#define PMC_IPC_PHY_CONFIG 0xEE#define PMC_IPC_NORTHPEAK_CTRL 0xED#define PMC_IPC_PM_DEBUG 0xEC -#define PMC_IPC_PMC_TELEMTRY 0xEB#define PMC_IPC_PMC_FW_MSG_CTRL 0xEA/* IPC return code */
arch/x86/include/asm/intel_telemetry.h +3 -0
@@ -10,6 +10,8 @@#define TELEM_MAX_EVENTS_SRAM 28#define TELEM_MAX_OS_ALLOCATED_EVENTS 20 +#include <asm/intel_scu_ipc.h> +enum telemetry_unit {TELEM_PSS =0 ,TELEM_IOSS ,
@@ -54,6 +56,7 @@ struct telemetry_plt_config {struct telemetry_unit_config ioss_config;struct mutex telem_trace_lock;struct mutex telem_lock; +struct intel_scu_ipc_dev *scu;bool telem_in_use; };
drivers/platform/x86/intel_telemetry_pltdrv.c +52 -49
237 lines not on this page · raw message
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 30/38 platform/x86: intel_pmc_ipc: Drop intel_pmc_ipc_command()
In reply to Mika WesterbergNow that all callers have been converted over to the SCU IPC API we can drop intel_pmc_ipc_command().
--- arch/x86/include/asm/intel_pmc_ipc.h | 8 -------- drivers/platform/x86/intel_pmc_ipc.c | 20 -------------------- 2 files changed, 28 deletions(-)
arch/x86/include/asm/intel_pmc_ipc.h +0 -8
@@ -27,19 +27,11 @@#if IS_ENABLED (CONFIG_INTEL_PMC_IPC ) -int intel_pmc_ipc_command (u32 cmd,u32 sub,u8 *in,u32 inlen, -u32 *out,u32 outlen);int intel_pmc_s0ix_counter_read (u64 *data);int intel_pmc_gcr_read64 (u32 offset,u64 *data);#else -static inline int intel_pmc_ipc_command (u32 cmd,u32 sub,u8 *in,u32 inlen, -u32 *out,u32 outlen) -{ -return -EINVAL ; -} -static inline int intel_pmc_s0ix_counter_read (u64 *data) {return -EINVAL ;
drivers/platform/x86/intel_pmc_ipc.c +0 -20
@@ -194,26 +194,6 @@ static int update_no_reboot_bit(void *priv, bool set) PMC_CFG_NO_REBOOT_MASK, value); } -/** -* intel_pmc_ipc_command() - IPC command with input/output data -* @cmd: IPC command code. -* @sub: IPC command sub type. -* @in: input data of this IPC command. -* @inlen: input data length in bytes. -* @out: output data of this IPC command. -* @outlen: output data length in dwords. -* -* Send an IPC command to PMC with input/output data. -* -* Return: an IPC error code or 0 on success. -*/ -int intel_pmc_ipc_command (u32 cmd,u32 sub,u8 *in,u32 inlen, -u32 *out,u32 outlen) -{ -return intel_scu_ipc_dev_command (NULL , cmd, sub, in, inlen, out, outlen); -} -EXPORT_SYMBOL_GPL (intel_pmc_ipc_command); -static int ipc_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) {struct intel_pmc_ipc_dev *pmc = &ipcdev;
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 31/38 x86/platform/intel-mid: Add empty stubs for intel_scu_devices_[create|destroy]()
In reply to Mika WesterbergThis allows to call the functions even when CONFIG_X86_INTEL_MID is not enabled.
--- arch/x86/include/asm/intel-mid.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/include/asm/intel-mid.h +6 -3
@@ -88,11 +88,17 @@ static inline bool intel_mid_has_msic(void)return (intel_mid_identify_cpu () ==INTEL_MID_CPU_CHIP_PENWELL ); } +extern void intel_scu_devices_create (void ); +extern void intel_scu_devices_destroy (void ); +#else /* !CONFIG_X86_INTEL_MID */ #define intel_mid_identify_cpu () 0#define intel_mid_has_msic () 0 +static inline void intel_scu_devices_create (void ) { } +static inline void intel_scu_devices_destroy (void ) { } +#endif /* !CONFIG_X86_INTEL_MID */ enum intel_mid_timer_options {
@@ -115,9 +121,6 @@ extern enum intel_mid_timer_options intel_mid_timer_options;#define SFI_MTMR_MAX_NUM 8#define SFI_MRTC_MAX 8 -extern void intel_scu_devices_create (void ); -extern void intel_scu_devices_destroy (void ); -/* VRTC timer */ #define MRST_VRTC_MAP_SZ 1024/* #define MRST_VRTC_PGOFFSET 0xc00 */
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 32/38 platform/x86: intel_pmc_ipc: Move PCI IDs to intel_scu_pcidrv.c
In reply to Mika WesterbergThe PCI probe driver in intel_pmc_ipc.c is a duplicate of what we already have in intel_scu_pcidrv.c with the exception that the later also creates SCU specific devices. Move the PCI IDs from the intel_pmc_ipc.c to intel_scu.c and use driver_data to detect whether SCU devices need to be created or not.
Also update Kconfig entry to mention all platforms supported by the Intel SCU PCI driver and change dependency from X86_INTEL_MID to PCI which is more generic.
--- drivers/platform/x86/Kconfig | 13 ++++-- drivers/platform/x86/intel_pmc_ipc.c | 61 +------------------------ drivers/platform/x86/intel_scu_pcidrv.c | 21 +++++++-- 3 files changed, 27 insertions(+), 68 deletions(-)
drivers/platform/x86/Kconfig +9 -4
@@ -994,13 +994,18 @@ config INTEL_SCU config INTEL_SCU_PCI bool "Intel SCU PCI driver" - depends on X86_INTEL_MID + depends on PCI select INTEL_SCU help This driver is used to bridge the communications between kernel and SCU on some embedded Intel x86 platforms. It also creates - devices that are connected to the SoC through the SCU. This is - not needed for PC-type machines. + devices that are connected to the SoC through the SCU. + Platforms supported: + Medfield + Clovertrail + Merrifield + Broxton + Apollo Lake config INTEL_SCU_IPC_UTIL tristate "Intel SCU IPC utility driver"
@@ -1192,7 +1197,7 @@ config INTEL_SMARTCONNECT config INTEL_PMC_IPC tristate "Intel PMC IPC Driver" - depends on ACPI && PCI + depends on ACPI select INTEL_SCU_IPC ---help--- This driver provides support for PMC control on some Intel platforms.
drivers/platform/x86/intel_pmc_ipc.c +1 -60
83 lines not on this page · raw message
drivers/platform/x86/intel_scu_pcidrv.c +17 -4
@@ -17,6 +17,7 @@static int intel_scu_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) { +void (*setup_fn)(void ) = (void (*)(void ))id->driver_data;struct intel_scu_ipc_pdata pdata = {};struct intel_scu_ipc_dev *scu;int ret;
@@ -32,14 +33,26 @@ static int intel_scu_pci_probe(struct pci_dev *pdev,if (IS_ERR (scu))return PTR_ERR (scu); -intel_scu_devices_create (); +if (setup_fn) +setup_fn ();return 0 ; } +static void intel_mid_scu_setup (void ) +{ +intel_scu_devices_create (); +} +static const struct pci_device_id pci_ids[] = { - {PCI_VDEVICE (INTEL ,0x080e ) }, - {PCI_VDEVICE (INTEL ,0x08ea ) }, - {PCI_VDEVICE (INTEL ,0x11a0 ) }, + {PCI_VDEVICE (INTEL ,0x080e ), + .driver_data = (kernel_ulong_t )intel_mid_scu_setup }, + {PCI_VDEVICE (INTEL ,0x08ea ), + .driver_data = (kernel_ulong_t )intel_mid_scu_setup }, + {PCI_VDEVICE (INTEL ,0x0a94 ) }, + {PCI_VDEVICE (INTEL ,0x11a0 ), + .driver_data = (kernel_ulong_t )intel_mid_scu_setup }, + {PCI_VDEVICE (INTEL ,0x1a94 ) }, + {PCI_VDEVICE (INTEL ,0x5a94 ) }, {} };
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 33/38 platform/x86: intel_pmc_ipc: Use octal permissions in sysfs attributes
In reply to Mika WesterbergThis is the current preferred way so replace the S_IWUSR with the corresponding octal value. While there move the attributes to follow directly their store functions.
--- drivers/platform/x86/intel_pmc_ipc.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/platform/x86/intel_pmc_ipc.c +2 -5
@@ -215,6 +215,7 @@ static ssize_t intel_pmc_ipc_simple_cmd_store(struct device *dev, }return (ssize_t )count; } +static DEVICE_ATTR(simplecmd, 0200, NULL, intel_pmc_ipc_simple_cmd_store); static ssize_t intel_pmc_ipc_northpeak_store(struct device *dev, struct device_attribute *attr,
@@ -239,11 +240,7 @@ static ssize_t intel_pmc_ipc_northpeak_store(struct device *dev, }return (ssize_t )count; } - -static DEVICE_ATTR(simplecmd, S_IWUSR, - NULL, intel_pmc_ipc_simple_cmd_store); -static DEVICE_ATTR(northpeak, S_IWUSR, - NULL, intel_pmc_ipc_northpeak_store); +static DEVICE_ATTR(northpeak, 0200, NULL, intel_pmc_ipc_northpeak_store);static struct attribute *intel_ipc_attrs[] = { &dev_attr_northpeak.attr,
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 34/38 platform/x86: intel_pmc_ipc: Propagate error from kstrtoul()
In reply to Mika Westerbergkstrtoul() already returns negative error if the input was not valid so return it directly.
--- drivers/platform/x86/intel_pmc_ipc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/x86/intel_pmc_ipc.c +3 -2
@@ -226,8 +226,9 @@ static ssize_t intel_pmc_ipc_northpeak_store(struct device *dev,int subcmd;int ret; -if (kstrtoul (buf,0 , &val)) -return -EINVAL ; + ret =kstrtoul (buf,0 , &val); +if (ret) +return ret;if (val) subcmd =1 ;
Signature · 1 line
2.24.1
Re: [PATCH v4 34/38] platform/x86: intel_pmc_ipc: Propagate error from kstrtoul()
Quoted 2 lines · Mika Westerberg
kstrtoul()already returns negative error if the input was not valid so return it directly.
Quoted 24 lines
Signed-off-by Mika Westerberg <[email protected]>--- drivers/platform/x86/intel_pmc_ipc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/platform/x86/intel_pmc_ipc.c +3
-2@@ -226,8 +226,9 @@ static ssize_t intel_pmc_ipc_northpeak_store(struct device *dev,int subcmd;int ret; -if (kstrtoul (buf,0 , &val)) -return -EINVAL ; + ret =kstrtoul (buf,0 , &val); +if (ret) +return ret;if (val) subcmd =1 ;Signature · 1 line
2.24.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Mika Westerberg
maintainerPATCH v4 35/38 platform/x86: intel_pmc_ipc: Switch to use driver->dev_groups
In reply to Mika WesterbergThe driver core provides support for adding additional attributes for devices via new ->dev_groups member of struct device_driver. Convert the driver to use that instead of adding the attributes manually.
--- drivers/platform/x86/intel_pmc_ipc.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
drivers/platform/x86/intel_pmc_ipc.c +6 -15
@@ -253,6 +253,11 @@ static const struct attribute_group intel_ipc_group = { .attrs = intel_ipc_attrs, }; +static const struct attribute_group *intel_ipc_groups[] = { + &intel_ipc_group, +NULL +}; +static struct resource punit_res_array[] = {/* Punit BIOS */ {
@@ -597,28 +602,13 @@ static int ipc_plat_probe(struct platform_device *pdev)return ret; } - ret =sysfs_create_group (&pdev->dev.kobj, &intel_ipc_group); -if (ret) { -dev_err (&pdev->dev,"Failed to create sysfs group %d\n" , - ret); - goto err_devs; - } - ipcdev.has_gcr_regs = true;return 0 ; - -err_devs: -platform_device_unregister (ipcdev.tco_dev); -platform_device_unregister (ipcdev.punit_dev); -platform_device_unregister (ipcdev.telemetry_dev); - -return ret; }static int ipc_plat_remove (struct platform_device *pdev) { -sysfs_remove_group (&pdev->dev.kobj, &intel_ipc_group);platform_device_unregister (ipcdev.tco_dev);platform_device_unregister (ipcdev.punit_dev);platform_device_unregister (ipcdev.telemetry_dev);
@@ -632,6 +622,7 @@ static struct platform_driver ipc_plat_driver = { .driver = { .name = "pmc-ipc-plat", .acpi_match_table = ACPI_PTR(ipc_acpi_ids), + .dev_groups = intel_ipc_groups, }, };
Signature · 1 line
2.24.1
Mika Westerberg
maintainerPATCH v4 36/38 platform/x86: intel_telemetry: Add telemetry_get_pltdata()
In reply to Mika WesterbergAdd new function that allows telemetry modules to get pointer to the platform specific configuration. This is needed to allow the telemetry debugfs module to fetch PMC IPC instance in the subsequent patch.
--- arch/x86/include/asm/intel_telemetry.h | 1 + drivers/platform/x86/intel_telemetry_core.c | 12 ++++++++++++ 2 files changed, 13 insertions(+)
arch/x86/include/asm/intel_telemetry.h +1 -0
@@ -99,6 +99,7 @@ int telemetry_set_pltdata(const struct telemetry_core_ops *ops,int telemetry_clear_pltdata (void );int telemetry_pltconfig_valid (void ); +struct telemetry_plt_config *telemetry_get_pltdata (void );int telemetry_get_evtname (enum telemetry_unit telem_unit,const char **name,int len);
drivers/platform/x86/intel_telemetry_core.c +12 -0
@@ -369,6 +369,18 @@ int telemetry_pltconfig_valid(void) }EXPORT_SYMBOL_GPL (telemetry_pltconfig_valid); +/** +* telemetry_get_pltdata() - Return telemetry platform config +* +* May be used by other telemetry modules to get platform specific +* configuration. +*/ +struct telemetry_plt_config *telemetry_get_pltdata (void ) +{ +return telm_core_conf.plt_config; +} +EXPORT_SYMBOL_GPL (telemetry_get_pltdata); +static inline int telemetry_get_pssevtname (enum telemetry_unit telem_unit,const char **name,int len) {
Signature · 1 line
2.24.1
Re: [PATCH v4 36/38] platform/x86: intel_telemetry: Add telemetry_get_pltdata()
Quoted 3 lines · Mika Westerberg
Add new function that allows telemetry modules to get pointer to the platform specific configuration. This is needed to allow the telemetry debugfs module to fetch PMC IPC instance in the subsequent patch.
One comment below.
After addressing,
Quoted 28 lines
Signed-off-by Mika Westerberg <[email protected]>--- arch/x86/include/asm/intel_telemetry.h | 1 + drivers/platform/x86/intel_telemetry_core.c | 12 ++++++++++++ 2 files changed, 13 insertions(+)arch/x86/include/asm/intel_telemetry.h +1
-0@@ -99,6 +99,7 @@ int telemetry_set_pltdata(const struct telemetry_core_ops *ops,int telemetry_clear_pltdata (void );int telemetry_pltconfig_valid (void ); +struct telemetry_plt_config *telemetry_get_pltdata (void );int telemetry_get_evtname (enum telemetry_unit telem_unit,const char **name,int len);drivers/platform/x86/intel_telemetry_core.c +1
-0@@ -369,6 +369,18 @@ int telemetry_pltconfig_valid(void) }EXPORT_SYMBOL_GPL (telemetry_pltconfig_valid); +/**
drivers/platform/x86/intel_telemetry_core.c int telemetry_pltconfig_valid(void) · line 382
Quoted 10 lines
drivers/platform/x86/intel_telemetry_core.c +10
-0+* telemetry_get_pltdata() - Return telemetry platform config +* +* May be used by other telemetry modules to get platform specific +* configuration. +*/ +struct telemetry_plt_config *telemetry_get_pltdata (void ) +{ +return telm_core_conf.plt_config; +} +EXPORT_SYMBOL_GPL (telemetry_get_pltdata);
Effectively this may replace telemetry_pltconfig_valid().
Quoted 7 lines
drivers/platform/x86/intel_telemetry_core.c +1
-0+static inline int telemetry_get_pssevtname (enum telemetry_unit telem_unit,const char **name,int len) {Signature · 1 line
2.24.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Mika Westerberg
maintainerPATCH v4 37/38 platform/x86: intel_pmc_ipc: Convert to MFD
In reply to Mika WesterbergThis driver only creates a bunch of platform devices sharing resources belonging to the PMC device. This is pretty much what MFD subsystem is for so move the driver there, renaming it to intel_pmc_bxt.c which should be more clear what it is.
MFD subsystem provides nice helper APIs for subdevice creation so convert the driver to use those. Unfortunately the ACPI device includes separate resources for most of the subdevices so we cannot simply call mfd_add_devices() to create all of them but instead we need to call it separately for each device.
The new MFD driver continues to expose two sysfs attributes that allow userspace to send IPC commands to the PMC/SCU to avoid breaking any existing applications that may use these. Generally this is bad idea so document this in the ABI documentation.
--- .../ABI/obsolete/sysfs-driver-intel_pmc_bxt | 22 + arch/x86/include/asm/intel_pmc_ipc.h | 47 -- arch/x86/include/asm/intel_telemetry.h | 1 + drivers/mfd/Kconfig | 16 +- drivers/mfd/Makefile | 1 + drivers/mfd/intel_pmc_bxt.c | 496 ++++++++++++++ drivers/platform/x86/Kconfig | 16 +- drivers/platform/x86/Makefile | 1 - drivers/platform/x86/intel_pmc_ipc.c | 645 ------------------ .../platform/x86/intel_telemetry_debugfs.c | 12 +- drivers/platform/x86/intel_telemetry_pltdrv.c | 2 + drivers/usb/typec/tcpm/Kconfig | 2 +- include/linux/mfd/intel_pmc_bxt.h | 21 + 13 files changed, 572 insertions(+), 710 deletions(-) create mode 100644 Documentation/ABI/obsolete/sysfs-driver-intel_pmc_bxt delete mode 100644 arch/x86/include/asm/intel_pmc_ipc.h create mode 100644 drivers/mfd/intel_pmc_bxt.c delete mode 100644 drivers/platform/x86/intel_pmc_ipc.c create mode 100644 include/linux/mfd/intel_pmc_bxt.h
Documentation/ABI/obsolete/sysfs-driver-intel_pmc_bxt new file +22 -0
@@ -0,0 +1,22 @@ +These files allow sending arbitrary IPC commands to the PMC/SCU which +may be dangerous. These will be removed eventually and should not be +used in any new applications. + +What: /sys/bus/platform/devices/INT34D2:00/simplecmd +Date: Jun 2015 +KernelVersion: 4.1 +Contact: Mika Westerberg <[email protected]> +Description: This interface allows userspace to send an arbitrary + IPC command to the PMC/SCU. + + Format: %d %d where first number is command and + second number is subcommand. + +What: /sys/bus/platform/devices/INT34D2:00/northpeak +Date: Jun 2015 +KernelVersion: 4.1 +Contact: Mika Westerberg <[email protected]> +Description: This interface allows userspace to send an arbitrary + command to the Northpeak through the PMC/SCU. + + Format: %u.
arch/x86/include/asm/intel_pmc_ipc.h deleted +0 -47
47 lines not on this page · raw message
arch/x86/include/asm/intel_telemetry.h +1 -0
@@ -56,6 +56,7 @@ struct telemetry_plt_config {struct telemetry_unit_config ioss_config;struct mutex telem_trace_lock;struct mutex telem_lock; +struct intel_pmc_dev *pmc;struct intel_scu_ipc_dev *scu;bool telem_in_use; };
drivers/mfd/Kconfig +15 -1
@@ -551,7 +551,7 @@ config INTEL_SOC_PMIC config INTEL_SOC_PMIC_BXTWC tristate "Support for Intel Broxton Whiskey Cove PMIC" - depends on INTEL_PMC_IPC + depends on MFD_INTEL_PMC_BXT select MFD_CORE select REGMAP_IRQ help
@@ -632,6 +632,20 @@ config MFD_INTEL_MSIC Passage) chip. This chip embeds audio, battery, GPIO, etc. devices used in Intel Medfield platforms. +config MFD_INTEL_PMC_BXT + tristate "Intel PMC Driver for Broxton" + depends on X86 + depends on X86_PLATFORM_DEVICES + depends on ACPI + select INTEL_SCU_IPC + select MFD_CORE + help + This driver provides support for the PMC (Power Management + Controller) on Intel Broxton and Apollo Lake. The PMC is a + multi-function device that exposes IPC, General Control + Register and P-unit access. In addition this creates devices + for iTCO watchdog and telemetry that are part of the PMC. + config MFD_IPAQ_MICRO bool "Atmel Micro ASIC (iPAQ h3100/h3600/h3700) Support" depends on SA1100_H3100 || SA1100_H3600
drivers/mfd/Makefile +1 -0
@@ -211,6 +211,7 @@ obj-$(CONFIG_MFD_INTEL_LPSS) += intel-lpss.o obj-$(CONFIG_MFD_INTEL_LPSS_PCI) += intel-lpss-pci.o obj-$(CONFIG_MFD_INTEL_LPSS_ACPI) += intel-lpss-acpi.o obj-$(CONFIG_MFD_INTEL_MSIC) += intel_msic.o +obj-$(CONFIG_MFD_INTEL_PMC_BXT) += intel_pmc_bxt.o obj-$(CONFIG_MFD_PALMAS) += palmas.o obj-$(CONFIG_MFD_VIPERBOARD) += viperboard.o obj-$(CONFIG_MFD_RC5T583) += rc5t583.o rc5t583-irq.o
drivers/mfd/intel_pmc_bxt.c new file +496 -0
496 lines not on this page · raw message
drivers/platform/x86/Kconfig +5 -11
@@ -1195,19 +1195,11 @@ config INTEL_SMARTCONNECT This driver checks to determine whether the device has Intel Smart Connect enabled, and if so disables it. -config INTEL_PMC_IPC - tristate "Intel PMC IPC Driver" - depends on ACPI - select INTEL_SCU_IPC - ---help--- - This driver provides support for PMC control on some Intel platforms. - The PMC is an ARC processor which defines IPC commands for communication - with other entities in the CPU. - config INTEL_BXTWC_PMIC_TMU tristate "Intel BXT Whiskey Cove TMU Driver" depends on REGMAP - depends on INTEL_SOC_PMIC_BXTWC && INTEL_PMC_IPC + depends on MFD_INTEL_PMC_BXT + depends on INTEL_SOC_PMIC_BXTWC ---help--- Select this driver to use Intel BXT Whiskey Cove PMIC TMU feature. This driver enables the alarm wakeup functionality in the TMU unit
@@ -1233,7 +1225,9 @@ config INTEL_PUNIT_IPC config INTEL_TELEMETRY tristate "Intel SoC Telemetry Driver" - depends on INTEL_PMC_IPC && INTEL_PUNIT_IPC && X86_64 + depends on X86_64 + depends on MFD_INTEL_PMC_BXT + depends on INTEL_PUNIT_IPC ---help--- This driver provides interfaces to configure and use telemetry for INTEL SoC from APL onwards. It is also
drivers/platform/x86/Makefile +0 -1
@@ -86,7 +86,6 @@ obj-$(CONFIG_INTEL_RST) += intel-rst.o obj-$(CONFIG_INTEL_SMARTCONNECT) += intel-smartconnect.o obj-$(CONFIG_ALIENWARE_WMI) += alienware-wmi.o -obj-$(CONFIG_INTEL_PMC_IPC) += intel_pmc_ipc.o obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o obj-$(CONFIG_SURFACE_PRO3_BUTTON) += surfacepro3_button.o obj-$(CONFIG_SURFACE_3_BUTTON) += surface3_button.o
drivers/platform/x86/intel_pmc_ipc.c deleted +0 -645
645 lines not on this page · raw message
drivers/platform/x86/intel_telemetry_debugfs.c +8 -4
@@ -16,13 +16,13 @@#include <linux/debugfs.h> #include <linux/device.h> #include <linux/module.h> +#include <linux/mfd/intel_pmc_bxt.h> #include <linux/pci.h> #include <linux/seq_file.h> #include <linux/suspend.h> #include <asm/cpu_device_id.h> #include <asm/intel-family.h> -#include <asm/intel_pmc_ipc.h> #include <asm/intel_telemetry.h> #define DRIVER_NAME "telemetry_soc_debugfs"
@@ -648,10 +648,11 @@ DEFINE_SHOW_ATTRIBUTE(telem_soc_states);static int telem_s0ix_res_get (void *data,u64 *val) { +struct telemetry_plt_config *plt_config =telemetry_get_pltdata ();u64 s0ix_total_res;int ret; - ret =intel_pmc_s0ix_counter_read (&s0ix_total_res); + ret =intel_pmc_s0ix_counter_read (plt_config->pmc, &s0ix_total_res);if (ret) {pr_err ("Failed to read S0ix residency" );return ret;
@@ -836,12 +837,15 @@ static int pm_suspend_exit_cb(void)*/ if (suspend_shlw_ctr_exit == suspend_shlw_ctr_temp && suspend_deep_ctr_exit == suspend_deep_ctr_temp) { - ret =intel_pmc_gcr_read64 (PMC_GCR_TELEM_SHLW_S0IX_REG , +struct telemetry_plt_config *plt_config =telemetry_get_pltdata (); +struct intel_pmc_dev *pmc = plt_config->pmc; + + ret =intel_pmc_gcr_read64 (pmc,PMC_GCR_TELEM_SHLW_S0IX_REG , &suspend_shlw_res_exit);if (ret <0 ) goto out; - ret =intel_pmc_gcr_read64 (PMC_GCR_TELEM_DEEP_S0IX_REG , + ret =intel_pmc_gcr_read64 (pmc,PMC_GCR_TELEM_DEEP_S0IX_REG , &suspend_deep_res_exit);if (ret <0 ) goto out;
drivers/platform/x86/intel_telemetry_pltdrv.c +2 -0
@@ -1118,6 +1118,8 @@ static int telemetry_pltdrv_probe(struct platform_device *pdev) telm_conf = (struct telemetry_plt_config *)id->driver_data; + telm_conf->pmc =dev_get_drvdata (pdev->dev.parent); + res0 =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res0) { ret = -EINVAL ;
drivers/usb/typec/tcpm/Kconfig +1 -1
@@ -41,8 +41,8 @@ config TYPEC_FUSB302 config TYPEC_WCOVE tristate "Intel WhiskeyCove PMIC USB Type-C PHY driver" depends on ACPI + depends on MFD_INTEL_PMC_BXT depends on INTEL_SOC_PMIC - depends on INTEL_PMC_IPC depends on BXT_WC_PMIC_OPREGION help This driver adds support for USB Type-C on Intel Broxton platforms
include/linux/mfd/intel_pmc_bxt.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef MFD_INTEL_PMC_BXT_H +#define MFD_INTEL_PMC_BXT_H + +#include <linux/types.h> + +/* GCR reg offsets from GCR base */ +#define PMC_GCR_PMC_CFG_REG 0x08 +#define PMC_GCR_TELEM_DEEP_S0IX_REG 0x78 +#define PMC_GCR_TELEM_SHLW_S0IX_REG 0x80 + +/* +* Pointer to the PMC device can be obtained by calling +* dev_get_drvdata() to the parent MFD device. +*/ +struct intel_pmc_dev ; + +int intel_pmc_s0ix_counter_read (struct intel_pmc_dev *pmc,u64 *data); +int intel_pmc_gcr_read64 (struct intel_pmc_dev *pmc,u32 offset,u64 *data); + +#endif /* MFD_INTEL_PMC_BXT_H */
Signature · 1 line
2.24.1
Re: [PATCH v4 37/38] platform/x86: intel_pmc_ipc: Convert to MFD
Quoted 11 lines · Mika Westerberg
This driver only creates a bunch of platform devices sharing resources belonging to the PMC device. This is pretty much what MFD subsystem is for so move the driver there, renaming it to
intel_pmc_bxt.cwhich should be more clear what it is.MFD subsystem provides nice helper APIs for subdevice creation so convert the driver to use those. Unfortunately the ACPI device includes separate resources for most of the subdevices so we cannot simply call
mfd_add_devices()to create all of them but instead we need to call it separately for each device.
Quoted 4 lines
The new MFD driver continues to expose two sysfs attributes that allow userspace to send IPC commands to the PMC/SCU to avoid breaking any existing applications that may use these. Generally this is bad idea so document this in the ABI documentation.
Thanks for an update!
My comments below.
Quoted 168 lines
Signed-off-by Mika Westerberg <[email protected]>--- .../ABI/obsolete/sysfs-driver-intel_pmc_bxt | 22 + arch/x86/include/asm/intel_pmc_ipc.h | 47 -- arch/x86/include/asm/intel_telemetry.h | 1 + drivers/mfd/Kconfig | 16 +- drivers/mfd/Makefile | 1 + drivers/mfd/intel_pmc_bxt.c | 496 ++++++++++++++ drivers/platform/x86/Kconfig | 16 +- drivers/platform/x86/Makefile | 1 - drivers/platform/x86/intel_pmc_ipc.c | 645 ------------------ .../platform/x86/intel_telemetry_debugfs.c | 12 +- drivers/platform/x86/intel_telemetry_pltdrv.c | 2 + drivers/usb/typec/tcpm/Kconfig | 2 +- include/linux/mfd/intel_pmc_bxt.h | 21 + 13 files changed, 572 insertions(+), 710 deletions(-) create mode 100644 Documentation/ABI/obsolete/sysfs-driver-intel_pmc_bxt delete mode 100644 arch/x86/include/asm/intel_pmc_ipc.h create mode 100644 drivers/mfd/intel_pmc_bxt.c delete mode 100644 drivers/platform/x86/intel_pmc_ipc.c create mode 100644 include/linux/mfd/intel_pmc_bxt.hDocumentation/ABI/obsolete/sysfs-driver-intel_pmc_bxt new file +22
-0@@ -0,0 +1,22 @@ +These files allow sending arbitrary IPC commands to the PMC/SCU which +may be dangerous. These will be removed eventually and should not be +used in any new applications. + +What: /sys/bus/platform/devices/INT34D2:00/simplecmd +Date: Jun 2015 +KernelVersion: 4.1 +Contact: Mika Westerberg <[email protected]> +Description: This interface allows userspace to send an arbitrary + IPC command to the PMC/SCU. + + Format: %d %d where first number is command and + second number is subcommand. + +What: /sys/bus/platform/devices/INT34D2:00/northpeak +Date: Jun 2015 +KernelVersion: 4.1 +Contact: Mika Westerberg <[email protected]> +Description: This interface allows userspace to send an arbitrary + command to the Northpeak through the PMC/SCU. + + Format: %u.arch/x86/include/asm/intel_pmc_ipc.h deleted +0
-47@@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ASM_X86_INTEL_PMC_IPC_H_ -#define _ASM_X86_INTEL_PMC_IPC_H_ - -/* Commands */ -#define PMC_IPC_USB_PWR_CTRL 0xF0 -#define PMC_IPC_PMIC_BLACKLIST_SEL 0xEF -#define PMC_IPC_PHY_CONFIG 0xEE -#define PMC_IPC_NORTHPEAK_CTRL 0xED -#define PMC_IPC_PM_DEBUG 0xEC -#define PMC_IPC_PMC_FW_MSG_CTRL 0xEA - -/* IPC return code */ -#define IPC_ERR_NONE 0 -#define IPC_ERR_CMD_NOT_SUPPORTED 1 -#define IPC_ERR_CMD_NOT_SERVICED 2 -#define IPC_ERR_UNABLE_TO_SERVICE 3 -#define IPC_ERR_CMD_INVALID 4 -#define IPC_ERR_CMD_FAILED 5 -#define IPC_ERR_EMSECURITY 6 -#define IPC_ERR_UNSIGNEDKERNEL 7 - -/* GCR reg offsets from gcr base*/ -#define PMC_GCR_PMC_CFG_REG 0x08 -#define PMC_GCR_TELEM_DEEP_S0IX_REG 0x78 -#define PMC_GCR_TELEM_SHLW_S0IX_REG 0x80 - -#if IS_ENABLED (CONFIG_INTEL_PMC_IPC ) - -int intel_pmc_s0ix_counter_read (u64 *data); -int intel_pmc_gcr_read64 (u32 offset,u64 *data); - -#else - -static inline int intel_pmc_s0ix_counter_read (u64 *data) -{ -return -EINVAL ; -} - -static inline int intel_pmc_gcr_read64 (u32 offset,u64 *data) -{ -return -EINVAL ; -} - -#endif /*CONFIG_INTEL_PMC_IPC*/ - -#endif arch/x86/include/asm/intel_telemetry.h +1
-0@@ -56,6 +56,7 @@ struct telemetry_plt_config {struct telemetry_unit_config ioss_config;struct mutex telem_trace_lock;struct mutex telem_lock; +struct intel_pmc_dev *pmc;struct intel_scu_ipc_dev *scu;bool telem_in_use; };drivers/mfd/Kconfig +15
-1@@ -551,7 +551,7 @@ config INTEL_SOC_PMIC config INTEL_SOC_PMIC_BXTWC tristate "Support for Intel Broxton Whiskey Cove PMIC" - depends on INTEL_PMC_IPC + depends on MFD_INTEL_PMC_BXT select MFD_CORE select REGMAP_IRQ help@@ -632,6 +632,20 @@ config MFD_INTEL_MSIC Passage) chip. This chip embeds audio, battery, GPIO, etc. devices used in Intel Medfield platforms. +config MFD_INTEL_PMC_BXT + tristate "Intel PMC Driver for Broxton" + depends on X86 + depends on X86_PLATFORM_DEVICES + depends on ACPI + select INTEL_SCU_IPC + select MFD_CORE + help + This driver provides support for the PMC (Power Management + Controller) on Intel Broxton and Apollo Lake. The PMC is a + multi-function device that exposes IPC, General Control + Register and P-unit access. In addition this creates devices + for iTCO watchdog and telemetry that are part of the PMC. + config MFD_IPAQ_MICRO bool "Atmel Micro ASIC (iPAQ h3100/h3600/h3700) Support" depends on SA1100_H3100 || SA1100_H3600drivers/mfd/Makefile +1
-0@@ -211,6 +211,7 @@ obj-$(CONFIG_MFD_INTEL_LPSS) += intel-lpss.o obj-$(CONFIG_MFD_INTEL_LPSS_PCI) += intel-lpss-pci.o obj-$(CONFIG_MFD_INTEL_LPSS_ACPI) += intel-lpss-acpi.o obj-$(CONFIG_MFD_INTEL_MSIC) += intel_msic.o +obj-$(CONFIG_MFD_INTEL_PMC_BXT) += intel_pmc_bxt.o obj-$(CONFIG_MFD_PALMAS) += palmas.o obj-$(CONFIG_MFD_VIPERBOARD) += viperboard.o obj-$(CONFIG_MFD_RC5T583) += rc5t583.o rc5t583-irq.odrivers/mfd/intel_pmc_bxt.c new file +0
-0
drivers/mfd/intel_pmc_bxt.c line 7
Quoted 8 lines
drivers/mfd/intel_pmc_bxt.c new file +7
-0@@ -0,0 +1,496 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for the Intel Broxton PMC +* +* (C) Copyright 2014 - 2020 Intel Corporation +* +* This driver is based on Intel SCU IPC driver(intel_scu_ipc.c) by
Perhaps space before (.
Quoted 8 lines
+ * Sreedhara DS <[email protected]>
+ *
+ * The PMC running on the ARC processor communicates with another entity
+ * running in the IA core through an IPC mechanism which in turn sends
+ * messages between the IA and the PMC.
+ */drivers/mfd/intel_pmc_bxt.c new file +2
-0+ +#include <linux/acpi.h>
drivers/mfd/intel_pmc_bxt.c line 24
Quoted 10 lines
drivers/mfd/intel_pmc_bxt.c new file +9
-0+#include <linux/delay.h> +#include <linux/errno.h> +#include <linux/interrupt.h> +#include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/mfd/core.h> +#include <linux/mfd/intel_pmc_bxt.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/platform_data/itco_wdt.h>
Perhaps preserve alphabetical order?
Quoted 18 lines
drivers/mfd/intel_pmc_bxt.c new file +18
-0+ +#include <asm/intel_scu_ipc.h> + +/* Residency with clock rate at 19.2MHz to usecs */ +#define S0IX_RESIDENCY_IN_USECS (d, s) \ +({ \ + u64 result = 10ull * ((d) + (s)); \ + do_div(result, 192); \ + result; \ +}) + +/* Resources exported from IFWI */ +#define PLAT_RESOURCE_IPC_INDEX 0 +#define PLAT_RESOURCE_IPC_SIZE 0x1000 +#define PLAT_RESOURCE_GCR_OFFSET 0x1000 +#define PLAT_RESOURCE_GCR_SIZE 0x1000 +#define PLAT_RESOURCE_BIOS_DATA_INDEX 1 +#define PLAT_RESOURCE_BIOS_IFACE_INDEX 2
drivers/mfd/intel_pmc_bxt.c line 52
Quoted 10 lines
drivers/mfd/intel_pmc_bxt.c new file +10
-0+#define PLAT_RESOURCE_TELEM_SSRAM_INDEX 3 +#define PLAT_RESOURCE_ISP_DATA_INDEX 4 +#define PLAT_RESOURCE_ISP_IFACE_INDEX 5 +#define PLAT_RESOURCE_GTD_DATA_INDEX 6 +#define PLAT_RESOURCE_GTD_IFACE_INDEX 7 +#define PLAT_RESOURCE_ACPI_IO_INDEX 0 + +/* +* BIOS does not create an ACPI device for each PMC function, but +* exports multiple resources from one ACPI device(IPC) for multiple
Space before ( ?
Quoted 84 lines
+ * functions. This driver is responsible for creating a child device and
+ * to export resources for those functions.
+ */drivers/mfd/intel_pmc_bxt.c new file +81
-0+#define TCO_DEVICE_NAME "iTCO_wdt" +#define SMI_EN_OFFSET 0x40 +#define SMI_EN_SIZE 4 +#define TCO_BASE_OFFSET 0x60 +#define TCO_REGS_SIZE 16 +#define PUNIT_DEVICE_NAME "intel_punit_ipc" +#define TELEMETRY_DEVICE_NAME "intel_telemetry" +#define TELEM_SSRAM_SIZE 240 +#define TELEM_PMC_SSRAM_OFFSET 0x1B00 +#define TELEM_PUNIT_SSRAM_OFFSET 0x1A00 + +/* Commands */ +#define PMC_NORTHPEAK_CTRL 0xED + +/* PMC_CFG_REG bit masks */ +#define PMC_CFG_NO_REBOOT_EN BIT(4) + +/* Index to cells array in below struct */ +enum { +PMC_TCO , +PMC_PUNIT , +PMC_TELEM , +}; + +struct intel_pmc_dev { +struct device *dev; +struct intel_scu_ipc_dev *scu; + +struct mfd_cell cells[PMC_TELEM +1 ]; + +void __iomem *gcr_mem_base; +spinlock_t gcr_lock; + +struct resource *telem_base; +}; + +static inline bool is_gcr_valid (u32 offset) +{ +return offset <PLAT_RESOURCE_GCR_SIZE ; +} + +/** +* intel_pmc_gcr_read64() - Read a 64-bit PMC GCR register +* @pmc: PMC device pointer +* @offset: offset of GCR register from GCR address base +* @data: data pointer for storing the register output +* +* Reads the 64-bit PMC GCR register at given offset. +* +* Return: Negative value on error or 0 on success. +*/ +int intel_pmc_gcr_read64 (struct intel_pmc_dev *pmc,u32 offset,u64 *data) +{ +if (!is_gcr_valid (offset)) +return -EINVAL ; + +spin_lock (&pmc->gcr_lock); + *data =readq (pmc->gcr_mem_base + offset); +spin_unlock (&pmc->gcr_lock); + +return 0 ; +} +EXPORT_SYMBOL_GPL (intel_pmc_gcr_read64); + +/** +* intel_pmc_s0ix_counter_read() - Read S0ix residency. +* @pmc: PMC device pointer +* @data: Out param that contains current S0ix residency count. +* +* Writes to @data how many usecs the system has been in low-power S0ix +* state. +* +* Return: An error code or 0 on success. +*/ +int intel_pmc_s0ix_counter_read (struct intel_pmc_dev *pmc,u64 *data) +{ +u64 deep, shlw; + +spin_lock (&pmc->gcr_lock); + deep =readq (pmc->gcr_mem_base +PMC_GCR_TELEM_DEEP_S0IX_REG ); + shlw =readq (pmc->gcr_mem_base +PMC_GCR_TELEM_SHLW_S0IX_REG );
drivers/mfd/intel_pmc_bxt.c line 145
Quoted 10 lines
drivers/mfd/intel_pmc_bxt.c new file +9
-0+spin_unlock (&pmc->gcr_lock); + + *data =S0IX_RESIDENCY_IN_USECS (deep, shlw); +return 0 ; +} +EXPORT_SYMBOL_GPL (intel_pmc_s0ix_counter_read); + +/** +* intel_pmc_gcr_update() - Update PMC GCR register bits
I guess this function would be closer to _read64() one, since they are doing similar stuff.
Quoted 15 lines
+ * @pmc: PMC device pointer
+ * @offset: offset of GCR register from GCR address base
+ * @mask: bit mask for update operation
+ * @val: update value
+ *
+ * Updates the bits of given GCR register as specified by
+ * @mask and @val.
+ *
+ * Return: Negative value on error or 0 on success.
+ */drivers/mfd/intel_pmc_bxt.c new file +5
-0+static int intel_pmc_gcr_update (struct intel_pmc_dev *pmc,u32 offset,u32 mask, +u32 val) +{ +u32 new_val; +int ret =0 ;
drivers/mfd/intel_pmc_bxt.c line 169
Quoted 10 lines
drivers/mfd/intel_pmc_bxt.c new file +9
-0+ +if (!is_gcr_valid (offset)) +return -EINVAL ; + +spin_lock (&pmc->gcr_lock); + new_val =readl (pmc->gcr_mem_base + offset); + + new_val &= ~mask; + new_val |= val & mask;
Perhaps standard pattern, i.e.
new_val = (new_val & ~mask) | (val & mask);
?
drivers/mfd/intel_pmc_bxt.c line 177
Quoted 9 lines
drivers/mfd/intel_pmc_bxt.c new file +8
-0+ +writel (new_val, pmc->gcr_mem_base + offset); + + new_val =readl (pmc->gcr_mem_base + offset); + +/* check whether the bit update is successful */ +if ((new_val & mask) != (val & mask)) + ret = -EIO ;
I'm not sure why this is under lock. All variables are local. If we move out we may drop ret variable completely.
Quoted 74 lines
drivers/mfd/intel_pmc_bxt.c new file +74
-0+ +spin_unlock (&pmc->gcr_lock); +return ret; +} + +static ssize_t intel_pmc_simple_cmd_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct intel_pmc_dev *pmc =dev_get_drvdata (dev); +struct intel_scu_ipc_dev *scu = pmc->scu; +int subcmd; +int cmd; +int ret; + + ret =sscanf (buf,"%d %d" , &cmd, &subcmd); +if (ret !=2 ) { +dev_err (dev,"Invalid values, expected: cmd subcmd\n" ); +return -EINVAL ; + } + + ret =intel_scu_ipc_dev_simple_command (scu, cmd, subcmd); +if (ret) { +dev_err (dev,"Command %d failed with %d\n" , cmd, ret); +return ret; + } + +return count; +} +static DEVICE_ATTR(simplecmd, 0200, NULL, intel_pmc_simple_cmd_store); + +static ssize_t intel_pmc_northpeak_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct intel_pmc_dev *pmc =dev_get_drvdata (dev); +struct intel_scu_ipc_dev *scu = pmc->scu; +unsigned long val; +int subcmd; +int ret; + + ret =kstrtoul (buf,0 , &val); +if (ret) +return ret; + +if (val) + subcmd =1 ; +else + subcmd =0 ; + + ret =intel_scu_ipc_dev_simple_command (scu,PMC_NORTHPEAK_CTRL , subcmd); +if (ret) { +dev_err (dev,"Command north %d failed with %d\n" , subcmd, ret); +return ret; + } + +return count; +} +static DEVICE_ATTR(northpeak, 0200, NULL, intel_pmc_northpeak_store); + +static struct attribute *intel_pmc_attrs[] = { + &dev_attr_northpeak.attr, + &dev_attr_simplecmd.attr, +NULL +}; + +static const struct attribute_group intel_pmc_group = { + .attrs = intel_pmc_attrs, +}; + +static const struct attribute_group *intel_pmc_groups[] = { + &intel_pmc_group, +NULL +};
drivers/mfd/intel_pmc_bxt.c line 261
Quoted 10 lines
drivers/mfd/intel_pmc_bxt.c new file +10
-0+ +/* Templates used to construct MFD cells */ + +static const struct mfd_cell punit = { + .name =PUNIT_DEVICE_NAME , +}; + +static int update_no_reboot_bit (void *priv,bool set) +{ +u32 value = set ?PMC_CFG_NO_REBOOT_EN :0 ;
Perhaps
u32 bits = PMC_CFG_NO_REBOOT_EN; u32 value = set ? bits : 0; ...
drivers/mfd/intel_pmc_bxt.c line 265
Quoted 4 lines
drivers/mfd/intel_pmc_bxt.c new file +4
-0+struct intel_pmc_dev *pmc = priv; + +return intel_pmc_gcr_update (pmc,PMC_GCR_PMC_CFG_REG , +PMC_CFG_NO_REBOOT_EN , value);
return intel_pmc_gcr_update(pmc, PMC_GCR_PMC_CFG_REG, bits, value);
?
Quoted 24 lines
drivers/mfd/intel_pmc_bxt.c new file +24
-0+} + +static const struct itco_wdt_platform_data tco_pdata = { + .name ="Apollo Lake SoC" , + .version =5 , + .update_no_reboot_bit = update_no_reboot_bit, +}; + +static const struct mfd_cell tco = { + .name =TCO_DEVICE_NAME , + .ignore_resource_conflicts = true, +}; + +static const struct resource telem_res[] = { +DEFINE_RES_MEM (TELEM_PUNIT_SSRAM_OFFSET ,TELEM_SSRAM_SIZE ), +DEFINE_RES_MEM (TELEM_PMC_SSRAM_OFFSET ,TELEM_SSRAM_SIZE ), +}; + +static const struct mfd_cell telem = { + .name =TELEMETRY_DEVICE_NAME , + .resources = telem_res, + .num_resources =ARRAY_SIZE (telem_res), +}; +
drivers/mfd/intel_pmc_bxt.c line 298
Quoted 10 lines
drivers/mfd/intel_pmc_bxt.c new file +9
-0+static int intel_pmc_get_resources (struct platform_device *pdev, +struct intel_pmc_dev *pmc, +struct intel_scu_ipc_pdata *pdata) +{ +struct resource *res, *punit_res; +struct resource gcr_res; +size_t npunit_res =0 ; + + pdata->irq =platform_get_irq (pdev,0 );
Is this optional resource?
If yes, use _optional() version of API, otherwise error check should be added.
Quoted 31 lines
drivers/mfd/intel_pmc_bxt.c new file +31
-0+ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_IPC_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get IPC resource\n" ); +return -EINVAL ; + } + +/* IPC registers */ + pdata->mem.flags = res->flags; + pdata->mem.start = res->start; + pdata->mem.end = res->start +PLAT_RESOURCE_IPC_SIZE -1 ; + +/* GCR registers */ + gcr_res.flags = res->flags; + gcr_res.start = res->start +PLAT_RESOURCE_GCR_OFFSET ; + gcr_res.end = gcr_res.start +PLAT_RESOURCE_GCR_SIZE -1 ; + + pmc->gcr_mem_base =devm_ioremap_resource (&pdev->dev, &gcr_res); +if (IS_ERR (pmc->gcr_mem_base)) +return PTR_ERR (pmc->gcr_mem_base); + + pmc->cells[PMC_TCO ] = tco; + pmc->cells[PMC_PUNIT ] = punit; + pmc->cells[PMC_TELEM ] = telem; + +/* iTCO watchdog only if there is no WDAT ACPI table */ +if (!acpi_has_watchdog ()) { +struct itco_wdt_platform_data *pdata; +struct resource *tco_res; +
drivers/mfd/intel_pmc_bxt.c line 338
Quoted 10 lines
drivers/mfd/intel_pmc_bxt.c new file +9
-0+ res =platform_get_resource (pdev,IORESOURCE_IO , +PLAT_RESOURCE_ACPI_IO_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get IO resource\n" ); +return -EINVAL ; + } + + tco_res =devm_kcalloc (&pdev->dev,2 ,sizeof (tco_res[0 ]), +GFP_KERNEL );
Hmm... Perhaps sizeof(*tco_res) ?
Quoted 6 lines
drivers/mfd/intel_pmc_bxt.c new file +6
-0+if (!tco_res) +return -ENOMEM ; + + tco_res[0 ].flags =IORESOURCE_IO ; + tco_res[0 ].start = res->start +TCO_BASE_OFFSET ; + tco_res[0 ].end = tco_res[0 ].start +TCO_REGS_SIZE -1 ;
drivers/mfd/intel_pmc_bxt.c line 353
Quoted 10 lines
drivers/mfd/intel_pmc_bxt.c new file +9
-0+ tco_res[1 ].flags =IORESOURCE_IO ; + tco_res[1 ].start = res->start +SMI_EN_OFFSET ; + tco_res[1 ].end = tco_res[1 ].start +SMI_EN_SIZE -1 ; + + pmc->cells[PMC_TCO ].resources = tco_res; + pmc->cells[PMC_TCO ].num_resources =2 ; + + pdata =devm_kmemdup (&pdev->dev, &tco_pdata,sizeof (tco_pdata), +GFP_KERNEL );
sizeof(*pdata) ?
drivers/mfd/intel_pmc_bxt.c line 360
Quoted 7 lines
drivers/mfd/intel_pmc_bxt.c new file +7
-0+if (!pdata) +return -ENOMEM ; + + pdata->no_reboot_priv = pmc; + + pmc->cells[PMC_TCO ].platform_data = pdata; + pmc->cells[PMC_TCO ].pdata_size =sizeof (*pdata);
Can it be (this condition body) rather helper?
drivers/mfd/intel_pmc_bxt.c line 363
Quoted 3 lines
drivers/mfd/intel_pmc_bxt.c new file +3
-0+ } + + punit_res =devm_kcalloc (&pdev->dev,6 ,sizeof (punit_res[0 ]),GFP_KERNEL );
sizeof(*punit_res) ?
Quoted 838 lines
drivers/mfd/intel_pmc_bxt.c new file +133
-0+if (!punit_res) +return -ENOMEM ; + +/* This is index 0 to cover BIOS data register */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_BIOS_DATA_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get res of P-unit BIOS data\n" ); +return -EINVAL ; + } + punit_res[npunit_res++] = *res; + +/* This is index 1 to cover BIOS interface register */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_BIOS_IFACE_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get res of P-unit BIOS iface\n" ); +return -EINVAL ; + } + punit_res[npunit_res++] = *res; + +/* This is index 2 to cover ISP data register, optional */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_ISP_DATA_INDEX ); +if (res) + punit_res[npunit_res++] = *res; + +/* This is index 3 to cover ISP interface register, optional */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_ISP_IFACE_INDEX ); +if (res) + punit_res[npunit_res++] = *res; + +/* This is index 4 to cover GTD data register, optional */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_GTD_DATA_INDEX ); +if (res) + punit_res[npunit_res++] = *res; + +/* This is index 5 to cover GTD interface register, optional */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_GTD_IFACE_INDEX ); +if (res) + punit_res[npunit_res++] = *res; + + pmc->cells[PMC_PUNIT ].resources = punit_res; + pmc->cells[PMC_PUNIT ].num_resources = npunit_res; + +/* Telemetry SSRAM is optional */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_TELEM_SSRAM_INDEX ); +if (res) + pmc->telem_base = res; + +return 0 ; +} + +static int intel_pmc_create_devices (struct intel_pmc_dev *pmc) +{ +int ret; + +if (pmc->cells[PMC_TCO ].num_resources) { + ret =devm_mfd_add_devices (pmc->dev,PLATFORM_DEVID_AUTO , + &pmc->cells[PMC_TCO ],1 ,NULL ,0 ,NULL ); +if (ret) +return ret; + } + + ret =devm_mfd_add_devices (pmc->dev,PLATFORM_DEVID_AUTO , + &pmc->cells[PMC_PUNIT ],1 ,NULL ,0 ,NULL ); +if (ret) +return ret; + +if (!pmc->telem_base) +return 0 ; + +return devm_mfd_add_devices (pmc->dev,PLATFORM_DEVID_AUTO , + &pmc->cells[PMC_TELEM ],1 , + pmc->telem_base,0 ,NULL ); +} + +static const struct acpi_device_id intel_pmc_acpi_ids[] = { + {"INT34D2" }, + { } +}; +MODULE_DEVICE_TABLE (acpi, intel_pmc_acpi_ids); + +static int intel_pmc_probe (struct platform_device *pdev) +{ +struct intel_scu_ipc_pdata pdata = {}; +struct intel_pmc_dev *pmc; +int ret; + + pmc =devm_kzalloc (&pdev->dev,sizeof (*pmc),GFP_KERNEL ); +if (!pmc) +return -ENOMEM ; + + pmc->dev = &pdev->dev; +spin_lock_init (&pmc->gcr_lock); + + ret =intel_pmc_get_resources (pdev, pmc, &pdata); +if (ret) { +dev_err (&pdev->dev,"Failed to request resources\n" ); +return ret; + } + + pmc->scu =devm_intel_scu_ipc_register (&pdev->dev, &pdata); +if (IS_ERR (pmc->scu)) +return PTR_ERR (pmc->scu); + +platform_set_drvdata (pdev, pmc); + + ret =intel_pmc_create_devices (pmc); +if (ret) +dev_err (&pdev->dev,"Failed to create PMC devices\n" ); + +return ret; +} + +static struct platform_driver intel_pmc_driver = { + .probe = intel_pmc_probe, + .driver = { + .name ="intel_pmc_bxt" , + .acpi_match_table = intel_pmc_acpi_ids, + .dev_groups = intel_pmc_groups, + }, +}; + +module_platform_driver (intel_pmc_driver); + +MODULE_AUTHOR ("Zha Qipeng <[email protected]>" ); +MODULE_DESCRIPTION ("Intel Broxton PMC driver" ); +MODULE_LICENSE ("GPL v2" );drivers/platform/x86/Kconfig +5
-11@@ -1195,19 +1195,11 @@ config INTEL_SMARTCONNECT This driver checks to determine whether the device has Intel Smart Connect enabled, and if so disables it. -config INTEL_PMC_IPC - tristate "Intel PMC IPC Driver" - depends on ACPI - select INTEL_SCU_IPC - ---help--- - This driver provides support for PMC control on some Intel platforms. - The PMC is an ARC processor which defines IPC commands for communication - with other entities in the CPU. - config INTEL_BXTWC_PMIC_TMU tristate "Intel BXT Whiskey Cove TMU Driver" depends on REGMAP - depends on INTEL_SOC_PMIC_BXTWC && INTEL_PMC_IPC + depends on MFD_INTEL_PMC_BXT + depends on INTEL_SOC_PMIC_BXTWC ---help--- Select this driver to use Intel BXT Whiskey Cove PMIC TMU feature. This driver enables the alarm wakeup functionality in the TMU unit@@ -1233,7 +1225,9 @@ config INTEL_PUNIT_IPC config INTEL_TELEMETRY tristate "Intel SoC Telemetry Driver" - depends on INTEL_PMC_IPC && INTEL_PUNIT_IPC && X86_64 + depends on X86_64 + depends on MFD_INTEL_PMC_BXT + depends on INTEL_PUNIT_IPC ---help--- This driver provides interfaces to configure and use telemetry for INTEL SoC from APL onwards. It is alsodrivers/platform/x86/Makefile +0
-1@@ -86,7 +86,6 @@ obj-$(CONFIG_INTEL_RST) += intel-rst.o obj-$(CONFIG_INTEL_SMARTCONNECT) += intel-smartconnect.o obj-$(CONFIG_ALIENWARE_WMI) += alienware-wmi.o -obj-$(CONFIG_INTEL_PMC_IPC) += intel_pmc_ipc.o obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o obj-$(CONFIG_SURFACE_PRO3_BUTTON) += surfacepro3_button.o obj-$(CONFIG_SURFACE_3_BUTTON) += surface3_button.odrivers/platform/x86/intel_pmc_ipc.c deleted +0
-645@@ -1,645 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* Driver for the Intel PMC IPC mechanism -* -* (C) Copyright 2014-2015 Intel Corporation -* -* This driver is based on Intel SCU IPC driver(intel_scu_ipc.c) by -* Sreedhara DS <[email protected]> -* -* PMC running in ARC processor communicates with other entity running in IA -* core through IPC mechanism which in turn messaging between IA core ad PMC. -*/ - -#include <linux/acpi.h> -#include <linux/delay.h> -#include <linux/errno.h> -#include <linux/interrupt.h> -#include <linux/io-64-nonatomic-lo-hi.h> -#include <linux/module.h> -#include <linux/platform_device.h> - -#include <asm/intel_pmc_ipc.h> -#include <asm/intel_scu_ipc.h> - -#include <linux/platform_data/itco_wdt.h> - -/* Residency with clock rate at 19.2MHz to usecs */ -#define S0IX_RESIDENCY_IN_USECS (d, s) \ -({ \ - u64 result = 10ull * ((d) + (s)); \ - do_div(result, 192); \ - result; \ -}) - -/* exported resources from IFWI */ -#define PLAT_RESOURCE_IPC_INDEX 0 -#define PLAT_RESOURCE_IPC_SIZE 0x1000 -#define PLAT_RESOURCE_GCR_OFFSET 0x1000 -#define PLAT_RESOURCE_GCR_SIZE 0x1000 -#define PLAT_RESOURCE_BIOS_DATA_INDEX 1 -#define PLAT_RESOURCE_BIOS_IFACE_INDEX 2 -#define PLAT_RESOURCE_TELEM_SSRAM_INDEX 3 -#define PLAT_RESOURCE_ISP_DATA_INDEX 4 -#define PLAT_RESOURCE_ISP_IFACE_INDEX 5 -#define PLAT_RESOURCE_GTD_DATA_INDEX 6 -#define PLAT_RESOURCE_GTD_IFACE_INDEX 7 -#define PLAT_RESOURCE_ACPI_IO_INDEX 0 - -/* -* BIOS does not create an ACPI device for each PMC function, -* but exports multiple resources from one ACPI device(IPC) for -* multiple functions. This driver is responsible to create a -* platform device and to export resources for those functions. -*/ -#define TCO_DEVICE_NAME "iTCO_wdt" -#define SMI_EN_OFFSET 0x40 -#define SMI_EN_SIZE 4 -#define TCO_BASE_OFFSET 0x60 -#define TCO_REGS_SIZE 16 -#define PUNIT_DEVICE_NAME "intel_punit_ipc" -#define TELEMETRY_DEVICE_NAME "intel_telemetry" -#define TELEM_SSRAM_SIZE 240 -#define TELEM_PMC_SSRAM_OFFSET 0x1B00 -#define TELEM_PUNIT_SSRAM_OFFSET 0x1A00 -#define TCO_PMC_OFFSET 0x08 -#define TCO_PMC_SIZE 0x04 - -/* PMC register bit definitions */ - -/* PMC_CFG_REG bit masks */ -#define PMC_CFG_NO_REBOOT_MASK BIT_MASK(4) -#define PMC_CFG_NO_REBOOT_EN (1 << 4) -#define PMC_CFG_NO_REBOOT_DIS (0 << 4) - -static struct intel_pmc_ipc_dev { -struct device *dev; - -/* The following PMC BARs share the same ACPI device with the IPC */ -resource_size_t acpi_io_base; -int acpi_io_size; -struct platform_device *tco_dev; - -/* gcr */ -void __iomem *gcr_mem_base; -bool has_gcr_regs; -spinlock_t gcr_lock; - -/* punit */ -struct platform_device *punit_dev; -unsigned int punit_res_count; - -/* Telemetry */ -resource_size_t telem_pmc_ssram_base; -resource_size_t telem_punit_ssram_base; -int telem_pmc_ssram_size; -int telem_punit_ssram_size; -u8 telem_res_inval; -struct platform_device *telemetry_dev; -} ipcdev; - -static inline u64 gcr_data_readq (u32 offset) -{ -return readq (ipcdev.gcr_mem_base + offset); -} - -static inline int is_gcr_valid (u32 offset) -{ -if (!ipcdev.has_gcr_regs) -return -EACCES ; - -if (offset >PLAT_RESOURCE_GCR_SIZE ) -return -EINVAL ; - -return 0 ; -} - -/** -* intel_pmc_gcr_read64() - Read a 64-bit PMC GCR register -* @offset: offset of GCR register from GCR address base -* @data: data pointer for storing the register output -* -* Reads the 64-bit PMC GCR register at given offset. -* -* Return: negative value on error or 0 on success. -*/ -int intel_pmc_gcr_read64 (u32 offset,u64 *data) -{ -int ret; - -spin_lock (&ipcdev.gcr_lock); - - ret =is_gcr_valid (offset); -if (ret <0 ) { -spin_unlock (&ipcdev.gcr_lock); -return ret; - } - - *data =readq (ipcdev.gcr_mem_base + offset); - -spin_unlock (&ipcdev.gcr_lock); - -return 0 ; -} -EXPORT_SYMBOL_GPL (intel_pmc_gcr_read64); - -/** -* intel_pmc_gcr_update() - Update PMC GCR register bits -* @offset: offset of GCR register from GCR address base -* @mask: bit mask for update operation -* @val: update value -* -* Updates the bits of given GCR register as specified by -* @mask and @val. -* -* Return: negative value on error or 0 on success. -*/ -static int intel_pmc_gcr_update (u32 offset,u32 mask,u32 val) -{ -u32 new_val; -int ret =0 ; - -spin_lock (&ipcdev.gcr_lock); - - ret =is_gcr_valid (offset); -if (ret <0 ) - goto gcr_ipc_unlock; - - new_val =readl (ipcdev.gcr_mem_base + offset); - - new_val &= ~mask; - new_val |= val & mask; - -writel (new_val, ipcdev.gcr_mem_base + offset); - - new_val =readl (ipcdev.gcr_mem_base + offset); - -/* check whether the bit update is successful */ -if ((new_val & mask) != (val & mask)) { - ret = -EIO ; - goto gcr_ipc_unlock; - } - -gcr_ipc_unlock: -spin_unlock (&ipcdev.gcr_lock); -return ret; -} - -static int update_no_reboot_bit (void *priv,bool set) -{ -u32 value = set ?PMC_CFG_NO_REBOOT_EN :PMC_CFG_NO_REBOOT_DIS ; - -return intel_pmc_gcr_update (PMC_GCR_PMC_CFG_REG , -PMC_CFG_NO_REBOOT_MASK , value); -} - -static ssize_t intel_pmc_ipc_simple_cmd_store (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -struct intel_scu_ipc_dev *scu =dev_get_drvdata (dev); -int subcmd; -int cmd; -int ret; - - ret =sscanf (buf,"%d %d" , &cmd, &subcmd); -if (ret !=2 ) { -dev_err (dev,"Error args\n" ); -return -EINVAL ; - } - - ret =intel_scu_ipc_dev_simple_command (scu, cmd, subcmd); -if (ret) { -dev_err (dev,"command %d error with %d\n" , cmd, ret); -return ret; - } -return (ssize_t )count; -} -static DEVICE_ATTR(simplecmd, 0200, NULL, intel_pmc_ipc_simple_cmd_store); - -static ssize_t intel_pmc_ipc_northpeak_store (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -struct intel_scu_ipc_dev *scu =dev_get_drvdata (dev); -unsigned long val; -int subcmd; -int ret; - - ret =kstrtoul (buf,0 , &val); -if (ret) -return ret; - -if (val) - subcmd =1 ; -else - subcmd =0 ; - ret =intel_scu_ipc_dev_simple_command (scu,PMC_IPC_NORTHPEAK_CTRL , subcmd); -if (ret) { -dev_err (dev,"command north %d error with %d\n" , subcmd, ret); -return ret; - } -return (ssize_t )count; -} -static DEVICE_ATTR(northpeak, 0200, NULL, intel_pmc_ipc_northpeak_store); - -static struct attribute *intel_ipc_attrs[] = { - &dev_attr_northpeak.attr, - &dev_attr_simplecmd.attr, -NULL -}; - -static const struct attribute_group intel_ipc_group = { - .attrs = intel_ipc_attrs, -}; - -static const struct attribute_group *intel_ipc_groups[] = { - &intel_ipc_group, -NULL -}; - -static struct resource punit_res_array[] = { -/* Punit BIOS */ - { - .flags =IORESOURCE_MEM , - }, - { - .flags =IORESOURCE_MEM , - }, -/* Punit ISP */ - { - .flags =IORESOURCE_MEM , - }, - { - .flags =IORESOURCE_MEM , - }, -/* Punit GTD */ - { - .flags =IORESOURCE_MEM , - }, - { - .flags =IORESOURCE_MEM , - }, -}; - -#define TCO_RESOURCE_ACPI_IO 0 -#define TCO_RESOURCE_SMI_EN_IO 1 -#define TCO_RESOURCE_GCR_MEM 2 -static struct resource tco_res[] = { -/* ACPI - TCO */ - { - .flags =IORESOURCE_IO , - }, -/* ACPI - SMI */ - { - .flags =IORESOURCE_IO , - }, -}; - -static struct itco_wdt_platform_data tco_info = { - .name ="Apollo Lake SoC" , - .version =5 , - .no_reboot_priv = &ipcdev, - .update_no_reboot_bit = update_no_reboot_bit, -}; - -#define TELEMETRY_RESOURCE_PUNIT_SSRAM 0 -#define TELEMETRY_RESOURCE_PMC_SSRAM 1 -static struct resource telemetry_res[] = { -/*Telemetry*/ - { - .flags =IORESOURCE_MEM , - }, - { - .flags =IORESOURCE_MEM , - }, -}; - -static int ipc_create_punit_device (void ) -{ -struct platform_device *pdev; -const struct platform_device_info pdevinfo = { - .parent = ipcdev.dev, - .name =PUNIT_DEVICE_NAME , - .id =-1 , - .res = punit_res_array, - .num_res = ipcdev.punit_res_count, - }; - - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.punit_dev = pdev; - -return 0 ; -} - -static int ipc_create_tco_device (void ) -{ -struct platform_device *pdev; -struct resource *res; -const struct platform_device_info pdevinfo = { - .parent = ipcdev.dev, - .name =TCO_DEVICE_NAME , - .id =-1 , - .res = tco_res, - .num_res =ARRAY_SIZE (tco_res), - .data = &tco_info, - .size_data =sizeof (tco_info), - }; - - res = tco_res +TCO_RESOURCE_ACPI_IO ; - res->start = ipcdev.acpi_io_base +TCO_BASE_OFFSET ; - res->end = res->start +TCO_REGS_SIZE -1 ; - - res = tco_res +TCO_RESOURCE_SMI_EN_IO ; - res->start = ipcdev.acpi_io_base +SMI_EN_OFFSET ; - res->end = res->start +SMI_EN_SIZE -1 ; - - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.tco_dev = pdev; - -return 0 ; -} - -static int ipc_create_telemetry_device (void ) -{ -struct platform_device *pdev; -struct resource *res; -const struct platform_device_info pdevinfo = { - .parent = ipcdev.dev, - .name =TELEMETRY_DEVICE_NAME , - .id =-1 , - .res = telemetry_res, - .num_res =ARRAY_SIZE (telemetry_res), - }; - - res = telemetry_res +TELEMETRY_RESOURCE_PUNIT_SSRAM ; - res->start = ipcdev.telem_punit_ssram_base; - res->end = res->start + ipcdev.telem_punit_ssram_size -1 ; - - res = telemetry_res +TELEMETRY_RESOURCE_PMC_SSRAM ; - res->start = ipcdev.telem_pmc_ssram_base; - res->end = res->start + ipcdev.telem_pmc_ssram_size -1 ; - - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.telemetry_dev = pdev; - -return 0 ; -} - -static int ipc_create_pmc_devices (void ) -{ -int ret; - -/* If we have ACPI based watchdog use that instead */ -if (!acpi_has_watchdog ()) { - ret =ipc_create_tco_device (); -if (ret) { -dev_err (ipcdev.dev,"Failed to add tco platform device\n" ); -return ret; - } - } - - ret =ipc_create_punit_device (); -if (ret) { -dev_err (ipcdev.dev,"Failed to add punit platform device\n" ); -platform_device_unregister (ipcdev.tco_dev); -return ret; - } - -if (!ipcdev.telem_res_inval) { - ret =ipc_create_telemetry_device (); -if (ret) { -dev_warn (ipcdev.dev, -"Failed to add telemetry platform device\n" ); -platform_device_unregister (ipcdev.punit_dev); -platform_device_unregister (ipcdev.tco_dev); - } - } - -return ret; -} - -static int ipc_plat_get_res (struct platform_device *pdev, -struct intel_scu_ipc_pdata *pdata) -{ -struct resource *res, *punit_res = punit_res_array; -resource_size_t start; -void __iomem *addr; -int size; - - res =platform_get_resource (pdev,IORESOURCE_IO , -PLAT_RESOURCE_ACPI_IO_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get io resource\n" ); -return -ENXIO ; - } - size =resource_size (res); - ipcdev.acpi_io_base = res->start; - ipcdev.acpi_io_size = size; -dev_info (&pdev->dev,"io res: %pR\n" , res); - - ipcdev.punit_res_count =0 ; - -/* This is index 0 to cover BIOS data register */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_BIOS_DATA_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get res of punit BIOS data\n" ); -return -ENXIO ; - } - punit_res[ipcdev.punit_res_count++] = *res; -dev_info (&pdev->dev,"punit BIOS data res: %pR\n" , res); - -/* This is index 1 to cover BIOS interface register */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_BIOS_IFACE_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get res of punit BIOS iface\n" ); -return -ENXIO ; - } - punit_res[ipcdev.punit_res_count++] = *res; -dev_info (&pdev->dev,"punit BIOS interface res: %pR\n" , res); - -/* This is index 2 to cover ISP data register, optional */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_ISP_DATA_INDEX ); -if (res) { - punit_res[ipcdev.punit_res_count++] = *res; -dev_info (&pdev->dev,"punit ISP data res: %pR\n" , res); - } - -/* This is index 3 to cover ISP interface register, optional */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_ISP_IFACE_INDEX ); -if (res) { - punit_res[ipcdev.punit_res_count++] = *res; -dev_info (&pdev->dev,"punit ISP interface res: %pR\n" , res); - } - -/* This is index 4 to cover GTD data register, optional */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_GTD_DATA_INDEX ); -if (res) { - punit_res[ipcdev.punit_res_count++] = *res; -dev_info (&pdev->dev,"punit GTD data res: %pR\n" , res); - } - -/* This is index 5 to cover GTD interface register, optional */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_GTD_IFACE_INDEX ); -if (res) { - punit_res[ipcdev.punit_res_count++] = *res; -dev_info (&pdev->dev,"punit GTD interface res: %pR\n" , res); - } - - pdata->irq =platform_get_irq (pdev,0 ); - - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_IPC_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get ipc resource\n" ); -return -ENXIO ; - } -dev_info (&pdev->dev,"ipc res: %pR\n" , res); - - pdata->mem.flags = res->flags; - pdata->mem.start = res->start; - pdata->mem.end = res->start +PLAT_RESOURCE_IPC_SIZE -1 ; - - start = res->start +PLAT_RESOURCE_GCR_OFFSET ; -if (!devm_request_mem_region (&pdev->dev, start,PLAT_RESOURCE_GCR_SIZE , -"pmc_ipc_plat" )) -return -EBUSY ; - - addr =devm_ioremap (&pdev->dev, start,PLAT_RESOURCE_GCR_SIZE ); -if (!addr) -return -ENOMEM ; - - ipcdev.gcr_mem_base = addr; - - ipcdev.telem_res_inval =0 ; - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_TELEM_SSRAM_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get telemetry ssram resource\n" ); - ipcdev.telem_res_inval =1 ; - }else { - ipcdev.telem_punit_ssram_base = res->start + -TELEM_PUNIT_SSRAM_OFFSET ; - ipcdev.telem_punit_ssram_size =TELEM_SSRAM_SIZE ; - ipcdev.telem_pmc_ssram_base = res->start + -TELEM_PMC_SSRAM_OFFSET ; - ipcdev.telem_pmc_ssram_size =TELEM_SSRAM_SIZE ; -dev_info (&pdev->dev,"telemetry ssram res: %pR\n" , res); - } - -return 0 ; -} - -/** -* intel_pmc_s0ix_counter_read() - Read S0ix residency. -* @data: Out param that contains current S0ix residency count. -* -* Return: an error code or 0 on success. -*/ -int intel_pmc_s0ix_counter_read (u64 *data) -{ -u64 deep, shlw; - -if (!ipcdev.has_gcr_regs) -return -EACCES ; - - deep =gcr_data_readq (PMC_GCR_TELEM_DEEP_S0IX_REG ); - shlw =gcr_data_readq (PMC_GCR_TELEM_SHLW_S0IX_REG ); - - *data =S0IX_RESIDENCY_IN_USECS (deep, shlw); - -return 0 ; -} -EXPORT_SYMBOL_GPL (intel_pmc_s0ix_counter_read); - -#ifdef CONFIG_ACPI -static const struct acpi_device_id ipc_acpi_ids[] = { - {"INT34D2" ,0 }, - { } -}; -MODULE_DEVICE_TABLE (acpi, ipc_acpi_ids); -#endif - -static int ipc_plat_probe (struct platform_device *pdev) -{ -struct intel_scu_ipc_pdata pdata = {}; -struct intel_scu_ipc_dev *scu; -int ret; - - ipcdev.dev = &pdev->dev; -spin_lock_init (&ipcdev.gcr_lock); - - ret =ipc_plat_get_res (pdev, &pdata); -if (ret) { -dev_err (&pdev->dev,"Failed to request resource\n" ); -return ret; - } - - scu =devm_intel_scu_ipc_register (&pdev->dev, &pdata); -if (IS_ERR (scu)) -return PTR_ERR (scu); - -platform_set_drvdata (pdev, scu); - - ret =ipc_create_pmc_devices (); -if (ret) { -dev_err (&pdev->dev,"Failed to create pmc devices\n" ); -return ret; - } - - ipcdev.has_gcr_regs = true; - -return 0 ; -} - -static int ipc_plat_remove (struct platform_device *pdev) -{ -platform_device_unregister (ipcdev.tco_dev); -platform_device_unregister (ipcdev.punit_dev); -platform_device_unregister (ipcdev.telemetry_dev); - ipcdev.dev =NULL ; -return 0 ; -} - -static struct platform_driver ipc_plat_driver = { - .remove = ipc_plat_remove, - .probe = ipc_plat_probe, - .driver = { - .name ="pmc-ipc-plat" , - .acpi_match_table =ACPI_PTR (ipc_acpi_ids), - .dev_groups = intel_ipc_groups, - }, -}; - -static int __init intel_pmc_ipc_init (void ) -{ -return platform_driver_register (&ipc_plat_driver); -} - -static void __exit intel_pmc_ipc_exit(void) -{ -platform_driver_unregister (&ipc_plat_driver); -} - -MODULE_AUTHOR ("Zha Qipeng <[email protected]>" ); -MODULE_DESCRIPTION ("Intel PMC IPC driver" ); -MODULE_LICENSE ("GPL v2" ); - -/* Some modules are dependent on this, so init earlier */ -fs_initcall (intel_pmc_ipc_init); -module_exit (intel_pmc_ipc_exit);drivers/platform/x86/intel_telemetry_debugfs.c +0
-0
drivers/platform/x86/intel_telemetry_debugfs.c line 20
Quoted 5 lines
drivers/platform/x86/intel_telemetry_debugfs.c +1
-0@@ -16,13 +16,13 @@#include <linux/debugfs.h> #include <linux/device.h> #include <linux/module.h> +#include <linux/mfd/intel_pmc_bxt.h>
Alphabetical order?
Quoted 98 lines
drivers/platform/x86/intel_telemetry_debugfs.c +0
-1#include <linux/pci.h> #include <linux/seq_file.h> #include <linux/suspend.h> #include <asm/cpu_device_id.h> #include <asm/intel-family.h> -#include <asm/intel_pmc_ipc.h> #include <asm/intel_telemetry.h> #define
DRIVER_NAME"telemetry_soc_debugfs"drivers/platform/x86/intel_telemetry_debugfs.c +7
-3@@ -648,10 +648,11 @@ DEFINE_SHOW_ATTRIBUTE(telem_soc_states);static int telem_s0ix_res_get (void *data,u64 *val) { +struct telemetry_plt_config *plt_config =telemetry_get_pltdata ();u64 s0ix_total_res;int ret; - ret =intel_pmc_s0ix_counter_read (&s0ix_total_res); + ret =intel_pmc_s0ix_counter_read (plt_config->pmc, &s0ix_total_res);if (ret) {pr_err ("Failed to read S0ix residency" );return ret;@@ -836,12 +837,15 @@ static int pm_suspend_exit_cb(void)*/ if (suspend_shlw_ctr_exit == suspend_shlw_ctr_temp && suspend_deep_ctr_exit == suspend_deep_ctr_temp) { - ret =intel_pmc_gcr_read64 (PMC_GCR_TELEM_SHLW_S0IX_REG , +struct telemetry_plt_config *plt_config =telemetry_get_pltdata (); +struct intel_pmc_dev *pmc = plt_config->pmc; + + ret =intel_pmc_gcr_read64 (pmc,PMC_GCR_TELEM_SHLW_S0IX_REG , &suspend_shlw_res_exit);if (ret <0 ) goto out; - ret =intel_pmc_gcr_read64 (PMC_GCR_TELEM_DEEP_S0IX_REG , + ret =intel_pmc_gcr_read64 (pmc,PMC_GCR_TELEM_DEEP_S0IX_REG , &suspend_deep_res_exit);if (ret <0 ) goto out;drivers/platform/x86/intel_telemetry_pltdrv.c +2
-0@@ -1118,6 +1118,8 @@ static int telemetry_pltdrv_probe(struct platform_device *pdev) telm_conf = (struct telemetry_plt_config *)id->driver_data; + telm_conf->pmc =dev_get_drvdata (pdev->dev.parent); + res0 =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res0) { ret = -EINVAL ;drivers/usb/typec/tcpm/Kconfig +1
-1@@ -41,8 +41,8 @@ config TYPEC_FUSB302 config TYPEC_WCOVE tristate "Intel WhiskeyCove PMIC USB Type-C PHY driver" depends on ACPI + depends on MFD_INTEL_PMC_BXT depends on INTEL_SOC_PMIC - depends on INTEL_PMC_IPC depends on BXT_WC_PMIC_OPREGION help This driver adds support for USB Type-C on Intel Broxton platformsinclude/linux/mfd/intel_pmc_bxt.h new file +21
-0@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef MFD_INTEL_PMC_BXT_H +#define MFD_INTEL_PMC_BXT_H + +#include <linux/types.h> + +/* GCR reg offsets from GCR base */ +#define PMC_GCR_PMC_CFG_REG 0x08 +#define PMC_GCR_TELEM_DEEP_S0IX_REG 0x78 +#define PMC_GCR_TELEM_SHLW_S0IX_REG 0x80 + +/* +* Pointer to the PMC device can be obtained by calling +* dev_get_drvdata() to the parent MFD device. +*/ +struct intel_pmc_dev ; + +int intel_pmc_s0ix_counter_read (struct intel_pmc_dev *pmc,u64 *data); +int intel_pmc_gcr_read64 (struct intel_pmc_dev *pmc,u32 offset,u64 *data); + +#endif /* MFD_INTEL_PMC_BXT_H */ Signature · 1 line
2.24.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Mika Westerberg
maintainerRe: [PATCH v4 37/38] platform/x86: intel_pmc_ipc: Convert to MFD
Quoted 195 lines · Andy Shevchenko
Quoted 11 lines · Mika Westerberg
This driver only creates a bunch of platform devices sharing resources belonging to the PMC device. This is pretty much what MFD subsystem is for so move the driver there, renaming it to
intel_pmc_bxt.cwhich should be more clear what it is.MFD subsystem provides nice helper APIs for subdevice creation so convert the driver to use those. Unfortunately the ACPI device includes separate resources for most of the subdevices so we cannot simply call
mfd_add_devices()to create all of them but instead we need to call it separately for each device.Quoted 4 lines
The new MFD driver continues to expose two sysfs attributes that allow userspace to send IPC commands to the PMC/SCU to avoid breaking any existing applications that may use these. Generally this is bad idea so document this in the ABI documentation.
Thanks for an update!
My comments below.Quoted 174 lines
Signed-off-by Mika Westerberg <[email protected]>--- .../ABI/obsolete/sysfs-driver-intel_pmc_bxt | 22 + arch/x86/include/asm/intel_pmc_ipc.h | 47 -- arch/x86/include/asm/intel_telemetry.h | 1 + drivers/mfd/Kconfig | 16 +- drivers/mfd/Makefile | 1 + drivers/mfd/intel_pmc_bxt.c | 496 ++++++++++++++ drivers/platform/x86/Kconfig | 16 +- drivers/platform/x86/Makefile | 1 - drivers/platform/x86/intel_pmc_ipc.c | 645 ------------------ .../platform/x86/intel_telemetry_debugfs.c | 12 +- drivers/platform/x86/intel_telemetry_pltdrv.c | 2 + drivers/usb/typec/tcpm/Kconfig | 2 +- include/linux/mfd/intel_pmc_bxt.h | 21 + 13 files changed, 572 insertions(+), 710 deletions(-) create mode 100644 Documentation/ABI/obsolete/sysfs-driver-intel_pmc_bxt delete mode 100644 arch/x86/include/asm/intel_pmc_ipc.h create mode 100644 drivers/mfd/intel_pmc_bxt.c delete mode 100644 drivers/platform/x86/intel_pmc_ipc.c create mode 100644 include/linux/mfd/intel_pmc_bxt.hDocumentation/ABI/obsolete/sysfs-driver-intel_pmc_bxt new file +22
-0@@ -0,0 +1,22 @@ +These files allow sending arbitrary IPC commands to the PMC/SCU which +may be dangerous. These will be removed eventually and should not be +used in any new applications. + +What: /sys/bus/platform/devices/INT34D2:00/simplecmd +Date: Jun 2015 +KernelVersion: 4.1 +Contact: Mika Westerberg <[email protected]> +Description: This interface allows userspace to send an arbitrary + IPC command to the PMC/SCU. + + Format: %d %d where first number is command and + second number is subcommand. + +What: /sys/bus/platform/devices/INT34D2:00/northpeak +Date: Jun 2015 +KernelVersion: 4.1 +Contact: Mika Westerberg <[email protected]> +Description: This interface allows userspace to send an arbitrary + command to the Northpeak through the PMC/SCU. + + Format: %u.arch/x86/include/asm/intel_pmc_ipc.h deleted +0
-47@@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ASM_X86_INTEL_PMC_IPC_H_ -#define _ASM_X86_INTEL_PMC_IPC_H_ - -/* Commands */ -#define PMC_IPC_USB_PWR_CTRL 0xF0 -#define PMC_IPC_PMIC_BLACKLIST_SEL 0xEF -#define PMC_IPC_PHY_CONFIG 0xEE -#define PMC_IPC_NORTHPEAK_CTRL 0xED -#define PMC_IPC_PM_DEBUG 0xEC -#define PMC_IPC_PMC_FW_MSG_CTRL 0xEA - -/* IPC return code */ -#define IPC_ERR_NONE 0 -#define IPC_ERR_CMD_NOT_SUPPORTED 1 -#define IPC_ERR_CMD_NOT_SERVICED 2 -#define IPC_ERR_UNABLE_TO_SERVICE 3 -#define IPC_ERR_CMD_INVALID 4 -#define IPC_ERR_CMD_FAILED 5 -#define IPC_ERR_EMSECURITY 6 -#define IPC_ERR_UNSIGNEDKERNEL 7 - -/* GCR reg offsets from gcr base*/ -#define PMC_GCR_PMC_CFG_REG 0x08 -#define PMC_GCR_TELEM_DEEP_S0IX_REG 0x78 -#define PMC_GCR_TELEM_SHLW_S0IX_REG 0x80 - -#if IS_ENABLED (CONFIG_INTEL_PMC_IPC ) - -int intel_pmc_s0ix_counter_read (u64 *data); -int intel_pmc_gcr_read64 (u32 offset,u64 *data); - -#else - -static inline int intel_pmc_s0ix_counter_read (u64 *data) -{ -return -EINVAL ; -} - -static inline int intel_pmc_gcr_read64 (u32 offset,u64 *data) -{ -return -EINVAL ; -} - -#endif /*CONFIG_INTEL_PMC_IPC*/ - -#endif arch/x86/include/asm/intel_telemetry.h +1
-0@@ -56,6 +56,7 @@ struct telemetry_plt_config {struct telemetry_unit_config ioss_config;struct mutex telem_trace_lock;struct mutex telem_lock; +struct intel_pmc_dev *pmc;struct intel_scu_ipc_dev *scu;bool telem_in_use; };drivers/mfd/Kconfig +15
-1@@ -551,7 +551,7 @@ config INTEL_SOC_PMIC config INTEL_SOC_PMIC_BXTWC tristate "Support for Intel Broxton Whiskey Cove PMIC" - depends on INTEL_PMC_IPC + depends on MFD_INTEL_PMC_BXT select MFD_CORE select REGMAP_IRQ help@@ -632,6 +632,20 @@ config MFD_INTEL_MSIC Passage) chip. This chip embeds audio, battery, GPIO, etc. devices used in Intel Medfield platforms. +config MFD_INTEL_PMC_BXT + tristate "Intel PMC Driver for Broxton" + depends on X86 + depends on X86_PLATFORM_DEVICES + depends on ACPI + select INTEL_SCU_IPC + select MFD_CORE + help + This driver provides support for the PMC (Power Management + Controller) on Intel Broxton and Apollo Lake. The PMC is a + multi-function device that exposes IPC, General Control + Register and P-unit access. In addition this creates devices + for iTCO watchdog and telemetry that are part of the PMC. + config MFD_IPAQ_MICRO bool "Atmel Micro ASIC (iPAQ h3100/h3600/h3700) Support" depends on SA1100_H3100 || SA1100_H3600drivers/mfd/Makefile +1
-0@@ -211,6 +211,7 @@ obj-$(CONFIG_MFD_INTEL_LPSS) += intel-lpss.o obj-$(CONFIG_MFD_INTEL_LPSS_PCI) += intel-lpss-pci.o obj-$(CONFIG_MFD_INTEL_LPSS_ACPI) += intel-lpss-acpi.o obj-$(CONFIG_MFD_INTEL_MSIC) += intel_msic.o +obj-$(CONFIG_MFD_INTEL_PMC_BXT) += intel_pmc_bxt.o obj-$(CONFIG_MFD_PALMAS) += palmas.o obj-$(CONFIG_MFD_VIPERBOARD) += viperboard.o obj-$(CONFIG_MFD_RC5T583) += rc5t583.o rc5t583-irq.odrivers/mfd/intel_pmc_bxt.c new file +6
-0@@ -0,0 +1,496 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for the Intel Broxton PMC +* +* (C) Copyright 2014 - 2020 Intel Corporation +*
Quoted 3 lines
drivers/mfd/intel_pmc_bxt.c line 7
Quoted 1 line
drivers/mfd/intel_pmc_bxt.c new file +1
-0+* This driver is based on Intel SCU IPC driver(intel_scu_ipc.c) by Perhaps space before (.
OK
Quoted 16 lines
Quoted 15 lines
drivers/mfd/intel_pmc_bxt.c new file +15
-0+* Sreedhara DS <[email protected]> +* +* The PMC running on the ARC processor communicates with another entity +* running in the IA core through an IPC mechanism which in turn sends +* messages between the IA and the PMC. +*/ + +#include <linux/acpi.h> +#include <linux/delay.h> +#include <linux/errno.h> +#include <linux/interrupt.h> +#include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/mfd/core.h> +#include <linux/mfd/intel_pmc_bxt.h> +#include <linux/module.h>
Quoted 4 lines
drivers/mfd/intel_pmc_bxt.c line 24
Quoted 2 lines
drivers/mfd/intel_pmc_bxt.c new file +2
-0+#include <linux/platform_device.h> +#include <linux/platform_data/itco_wdt.h> Perhaps preserve alphabetical order?
I'm not really a fan of this "sort headers alphabetically" practise. I think the above looks fine but no strong feelings, though :)
Quoted 22 lines
Quoted 22 lines
drivers/mfd/intel_pmc_bxt.c new file +22
-0+ +#include <asm/intel_scu_ipc.h> + +/* Residency with clock rate at 19.2MHz to usecs */ +#define S0IX_RESIDENCY_IN_USECS (d, s) \ +({ \ + u64 result = 10ull * ((d) + (s)); \ + do_div(result, 192); \ + result; \ +}) + +/* Resources exported from IFWI */ +#define PLAT_RESOURCE_IPC_INDEX 0 +#define PLAT_RESOURCE_IPC_SIZE 0x1000 +#define PLAT_RESOURCE_GCR_OFFSET 0x1000 +#define PLAT_RESOURCE_GCR_SIZE 0x1000 +#define PLAT_RESOURCE_BIOS_DATA_INDEX 1 +#define PLAT_RESOURCE_BIOS_IFACE_INDEX 2 +#define PLAT_RESOURCE_TELEM_SSRAM_INDEX 3 +#define PLAT_RESOURCE_ISP_DATA_INDEX 4 +#define PLAT_RESOURCE_ISP_IFACE_INDEX 5 +#define PLAT_RESOURCE_GTD_DATA_INDEX 6
Quoted 8 lines
drivers/mfd/intel_pmc_bxt.c line 52
Quoted 6 lines
drivers/mfd/intel_pmc_bxt.c new file +6
-0+#define PLAT_RESOURCE_GTD_IFACE_INDEX 7 +#define PLAT_RESOURCE_ACPI_IO_INDEX 0 + +/* +* BIOS does not create an ACPI device for each PMC function, but +* exports multiple resources from one ACPI device(IPC) for multiple Space before ( ?
OK
Quoted 92 lines
Quoted 91 lines
drivers/mfd/intel_pmc_bxt.c new file +91
-0+* functions. This driver is responsible for creating a child device and +* to export resources for those functions. +*/ +#define TCO_DEVICE_NAME "iTCO_wdt" +#define SMI_EN_OFFSET 0x40 +#define SMI_EN_SIZE 4 +#define TCO_BASE_OFFSET 0x60 +#define TCO_REGS_SIZE 16 +#define PUNIT_DEVICE_NAME "intel_punit_ipc" +#define TELEMETRY_DEVICE_NAME "intel_telemetry" +#define TELEM_SSRAM_SIZE 240 +#define TELEM_PMC_SSRAM_OFFSET 0x1B00 +#define TELEM_PUNIT_SSRAM_OFFSET 0x1A00 + +/* Commands */ +#define PMC_NORTHPEAK_CTRL 0xED + +/* PMC_CFG_REG bit masks */ +#define PMC_CFG_NO_REBOOT_EN BIT(4) + +/* Index to cells array in below struct */ +enum { +PMC_TCO , +PMC_PUNIT , +PMC_TELEM , +}; + +struct intel_pmc_dev { +struct device *dev; +struct intel_scu_ipc_dev *scu; + +struct mfd_cell cells[PMC_TELEM +1 ]; + +void __iomem *gcr_mem_base; +spinlock_t gcr_lock; + +struct resource *telem_base; +}; + +static inline bool is_gcr_valid (u32 offset) +{ +return offset <PLAT_RESOURCE_GCR_SIZE ; +} + +/** +* intel_pmc_gcr_read64() - Read a 64-bit PMC GCR register +* @pmc: PMC device pointer +* @offset: offset of GCR register from GCR address base +* @data: data pointer for storing the register output +* +* Reads the 64-bit PMC GCR register at given offset. +* +* Return: Negative value on error or 0 on success. +*/ +int intel_pmc_gcr_read64 (struct intel_pmc_dev *pmc,u32 offset,u64 *data) +{ +if (!is_gcr_valid (offset)) +return -EINVAL ; + +spin_lock (&pmc->gcr_lock); + *data =readq (pmc->gcr_mem_base + offset); +spin_unlock (&pmc->gcr_lock); + +return 0 ; +} +EXPORT_SYMBOL_GPL (intel_pmc_gcr_read64); + +/** +* intel_pmc_s0ix_counter_read() - Read S0ix residency. +* @pmc: PMC device pointer +* @data: Out param that contains current S0ix residency count. +* +* Writes to @data how many usecs the system has been in low-power S0ix +* state. +* +* Return: An error code or 0 on success. +*/ +int intel_pmc_s0ix_counter_read (struct intel_pmc_dev *pmc,u64 *data) +{ +u64 deep, shlw; + +spin_lock (&pmc->gcr_lock); + deep =readq (pmc->gcr_mem_base +PMC_GCR_TELEM_DEEP_S0IX_REG ); + shlw =readq (pmc->gcr_mem_base +PMC_GCR_TELEM_SHLW_S0IX_REG ); +spin_unlock (&pmc->gcr_lock); + + *data =S0IX_RESIDENCY_IN_USECS (deep, shlw); +return 0 ; +} +EXPORT_SYMBOL_GPL (intel_pmc_s0ix_counter_read); +
Quoted 5 lines
drivers/mfd/intel_pmc_bxt.c line 145
Quoted 2 lines
drivers/mfd/intel_pmc_bxt.c new file +2
-0+/** +* intel_pmc_gcr_update() - Update PMC GCR register bits I guess this function would be closer to
_read64()one, since they are doing similar stuff.
OK, I'll move it closer.
Quoted 23 lines
Quoted 22 lines
drivers/mfd/intel_pmc_bxt.c new file +22
-0+* @pmc: PMC device pointer +* @offset: offset of GCR register from GCR address base +* @mask: bit mask for update operation +* @val: update value +* +* Updates the bits of given GCR register as specified by +* @mask and @val. +* +* Return: Negative value on error or 0 on success. +*/ +static int intel_pmc_gcr_update (struct intel_pmc_dev *pmc,u32 offset,u32 mask, +u32 val) +{ +u32 new_val; +int ret =0 ; + +if (!is_gcr_valid (offset)) +return -EINVAL ; + +spin_lock (&pmc->gcr_lock); + new_val =readl (pmc->gcr_mem_base + offset); +
Quoted 6 lines
drivers/mfd/intel_pmc_bxt.c line 169
Quoted 2 lines
drivers/mfd/intel_pmc_bxt.c new file +2
-0+ new_val &= ~mask; + new_val |= val & mask;Perhaps standard pattern, i.e.
new_val = (new_val & ~mask) | (val & mask);?
Yup, works for me.
Quoted 6 lines
Quoted 5 lines
drivers/mfd/intel_pmc_bxt.c new file +5
-0+ +writel (new_val, pmc->gcr_mem_base + offset); + + new_val =readl (pmc->gcr_mem_base + offset); +
Quoted 6 lines
drivers/mfd/intel_pmc_bxt.c line 177
Quoted 3 lines
drivers/mfd/intel_pmc_bxt.c new file +3
-0+/* check whether the bit update is successful */ +if ((new_val & mask) != (val & mask)) + ret = -EIO ;I'm not sure why this is under lock. All variables are local. If we move out we may drop ret variable completely.
Indeed good point. I'll do that.
Quoted 92 lines
Quoted 74 lines
drivers/mfd/intel_pmc_bxt.c new file +74
-0+ +spin_unlock (&pmc->gcr_lock); +return ret; +} + +static ssize_t intel_pmc_simple_cmd_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct intel_pmc_dev *pmc =dev_get_drvdata (dev); +struct intel_scu_ipc_dev *scu = pmc->scu; +int subcmd; +int cmd; +int ret; + + ret =sscanf (buf,"%d %d" , &cmd, &subcmd); +if (ret !=2 ) { +dev_err (dev,"Invalid values, expected: cmd subcmd\n" ); +return -EINVAL ; + } + + ret =intel_scu_ipc_dev_simple_command (scu, cmd, subcmd); +if (ret) { +dev_err (dev,"Command %d failed with %d\n" , cmd, ret); +return ret; + } + +return count; +} +static DEVICE_ATTR(simplecmd, 0200, NULL, intel_pmc_simple_cmd_store); + +static ssize_t intel_pmc_northpeak_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct intel_pmc_dev *pmc =dev_get_drvdata (dev); +struct intel_scu_ipc_dev *scu = pmc->scu; +unsigned long val; +int subcmd; +int ret; + + ret =kstrtoul (buf,0 , &val); +if (ret) +return ret; + +if (val) + subcmd =1 ; +else + subcmd =0 ; + + ret =intel_scu_ipc_dev_simple_command (scu,PMC_NORTHPEAK_CTRL , subcmd); +if (ret) { +dev_err (dev,"Command north %d failed with %d\n" , subcmd, ret); +return ret; + } + +return count; +} +static DEVICE_ATTR(northpeak, 0200, NULL, intel_pmc_northpeak_store); + +static struct attribute *intel_pmc_attrs[] = { + &dev_attr_northpeak.attr, + &dev_attr_simplecmd.attr, +NULL +}; + +static const struct attribute_group intel_pmc_group = { + .attrs = intel_pmc_attrs, +}; + +static const struct attribute_group *intel_pmc_groups[] = { + &intel_pmc_group, +NULL +};drivers/mfd/intel_pmc_bxt.c line 261
Quoted 10 lines
drivers/mfd/intel_pmc_bxt.c new file +10
-0+ +/* Templates used to construct MFD cells */ + +static const struct mfd_cell punit = { + .name =PUNIT_DEVICE_NAME , +}; + +static int update_no_reboot_bit (void *priv,bool set) +{ +u32 value = set ?PMC_CFG_NO_REBOOT_EN :0 ;Perhaps
u32 bits = PMC_CFG_NO_REBOOT_EN; u32 value = set ? bits : 0; ...
Quoted 8 lines
drivers/mfd/intel_pmc_bxt.c line 265
Quoted 4 lines
drivers/mfd/intel_pmc_bxt.c new file +4
-0+struct intel_pmc_dev *pmc = priv; + +return intel_pmc_gcr_update (pmc,PMC_GCR_PMC_CFG_REG , +PMC_CFG_NO_REBOOT_EN , value);return intel_pmc_gcr_update(pmc, PMC_GCR_PMC_CFG_REG, bits, value);?
Agree, this one looks better.
Quoted 33 lines
Quoted 32 lines
drivers/mfd/intel_pmc_bxt.c new file +32
-0+} + +static const struct itco_wdt_platform_data tco_pdata = { + .name ="Apollo Lake SoC" , + .version =5 , + .update_no_reboot_bit = update_no_reboot_bit, +}; + +static const struct mfd_cell tco = { + .name =TCO_DEVICE_NAME , + .ignore_resource_conflicts = true, +}; + +static const struct resource telem_res[] = { +DEFINE_RES_MEM (TELEM_PUNIT_SSRAM_OFFSET ,TELEM_SSRAM_SIZE ), +DEFINE_RES_MEM (TELEM_PMC_SSRAM_OFFSET ,TELEM_SSRAM_SIZE ), +}; + +static const struct mfd_cell telem = { + .name =TELEMETRY_DEVICE_NAME , + .resources = telem_res, + .num_resources =ARRAY_SIZE (telem_res), +}; + +static int intel_pmc_get_resources (struct platform_device *pdev, +struct intel_pmc_dev *pmc, +struct intel_scu_ipc_pdata *pdata) +{ +struct resource *res, *punit_res; +struct resource gcr_res; +size_t npunit_res =0 ; +
Quoted 4 lines
drivers/mfd/intel_pmc_bxt.c line 298
Quoted 1 line
drivers/mfd/intel_pmc_bxt.c new file +1
-0+ pdata->irq =platform_get_irq (pdev,0 );Is this optional resource?
If yes, use_optional()version of API, otherwise error check should be added.
Oh, we have platform_get_irq_optional()? I did not know about that. I'll use that instead.
Quoted 39 lines
Quoted 38 lines
drivers/mfd/intel_pmc_bxt.c new file +38
-0+ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_IPC_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get IPC resource\n" ); +return -EINVAL ; + } + +/* IPC registers */ + pdata->mem.flags = res->flags; + pdata->mem.start = res->start; + pdata->mem.end = res->start +PLAT_RESOURCE_IPC_SIZE -1 ; + +/* GCR registers */ + gcr_res.flags = res->flags; + gcr_res.start = res->start +PLAT_RESOURCE_GCR_OFFSET ; + gcr_res.end = gcr_res.start +PLAT_RESOURCE_GCR_SIZE -1 ; + + pmc->gcr_mem_base =devm_ioremap_resource (&pdev->dev, &gcr_res); +if (IS_ERR (pmc->gcr_mem_base)) +return PTR_ERR (pmc->gcr_mem_base); + + pmc->cells[PMC_TCO ] = tco; + pmc->cells[PMC_PUNIT ] = punit; + pmc->cells[PMC_TELEM ] = telem; + +/* iTCO watchdog only if there is no WDAT ACPI table */ +if (!acpi_has_watchdog ()) { +struct itco_wdt_platform_data *pdata; +struct resource *tco_res; + + res =platform_get_resource (pdev,IORESOURCE_IO , +PLAT_RESOURCE_ACPI_IO_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get IO resource\n" ); +return -EINVAL ; + } +
Quoted 4 lines
drivers/mfd/intel_pmc_bxt.c line 338
Quoted 2 lines
drivers/mfd/intel_pmc_bxt.c new file +2
-0+ tco_res =devm_kcalloc (&pdev->dev,2 ,sizeof (tco_res[0 ]), +GFP_KERNEL );Hmm... Perhaps
sizeof(*tco_res)?
OK
Quoted 14 lines
Quoted 13 lines
drivers/mfd/intel_pmc_bxt.c new file +13
-0+if (!tco_res) +return -ENOMEM ; + + tco_res[0 ].flags =IORESOURCE_IO ; + tco_res[0 ].start = res->start +TCO_BASE_OFFSET ; + tco_res[0 ].end = tco_res[0 ].start +TCO_REGS_SIZE -1 ; + tco_res[1 ].flags =IORESOURCE_IO ; + tco_res[1 ].start = res->start +SMI_EN_OFFSET ; + tco_res[1 ].end = tco_res[1 ].start +SMI_EN_SIZE -1 ; + + pmc->cells[PMC_TCO ].resources = tco_res; + pmc->cells[PMC_TCO ].num_resources =2 ; +
Quoted 4 lines
drivers/mfd/intel_pmc_bxt.c line 353
Quoted 2 lines
drivers/mfd/intel_pmc_bxt.c new file +2
-0+ pdata =devm_kmemdup (&pdev->dev, &tco_pdata,sizeof (tco_pdata), +GFP_KERNEL );
sizeof(*pdata)?
OK
Quoted 9 lines
drivers/mfd/intel_pmc_bxt.c line 360
Quoted 7 lines
drivers/mfd/intel_pmc_bxt.c new file +7
-0+if (!pdata) +return -ENOMEM ; + + pdata->no_reboot_priv = pmc; + + pmc->cells[PMC_TCO ].platform_data = pdata; + pmc->cells[PMC_TCO ].pdata_size =sizeof (*pdata);Can it be (this condition body) rather helper?
You mean can it be put to a helper function?
Quoted 5 lines
drivers/mfd/intel_pmc_bxt.c line 363
Quoted 3 lines
drivers/mfd/intel_pmc_bxt.c new file +3
-0+ } + + punit_res =devm_kcalloc (&pdev->dev,6 ,sizeof (punit_res[0 ]),GFP_KERNEL );
sizeof(*punit_res)?
OK
Quoted 841 lines
Quoted 840 lines
drivers/mfd/intel_pmc_bxt.c new file +133
-0+if (!punit_res) +return -ENOMEM ; + +/* This is index 0 to cover BIOS data register */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_BIOS_DATA_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get res of P-unit BIOS data\n" ); +return -EINVAL ; + } + punit_res[npunit_res++] = *res; + +/* This is index 1 to cover BIOS interface register */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_BIOS_IFACE_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get res of P-unit BIOS iface\n" ); +return -EINVAL ; + } + punit_res[npunit_res++] = *res; + +/* This is index 2 to cover ISP data register, optional */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_ISP_DATA_INDEX ); +if (res) + punit_res[npunit_res++] = *res; + +/* This is index 3 to cover ISP interface register, optional */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_ISP_IFACE_INDEX ); +if (res) + punit_res[npunit_res++] = *res; + +/* This is index 4 to cover GTD data register, optional */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_GTD_DATA_INDEX ); +if (res) + punit_res[npunit_res++] = *res; + +/* This is index 5 to cover GTD interface register, optional */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_GTD_IFACE_INDEX ); +if (res) + punit_res[npunit_res++] = *res; + + pmc->cells[PMC_PUNIT ].resources = punit_res; + pmc->cells[PMC_PUNIT ].num_resources = npunit_res; + +/* Telemetry SSRAM is optional */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_TELEM_SSRAM_INDEX ); +if (res) + pmc->telem_base = res; + +return 0 ; +} + +static int intel_pmc_create_devices (struct intel_pmc_dev *pmc) +{ +int ret; + +if (pmc->cells[PMC_TCO ].num_resources) { + ret =devm_mfd_add_devices (pmc->dev,PLATFORM_DEVID_AUTO , + &pmc->cells[PMC_TCO ],1 ,NULL ,0 ,NULL ); +if (ret) +return ret; + } + + ret =devm_mfd_add_devices (pmc->dev,PLATFORM_DEVID_AUTO , + &pmc->cells[PMC_PUNIT ],1 ,NULL ,0 ,NULL ); +if (ret) +return ret; + +if (!pmc->telem_base) +return 0 ; + +return devm_mfd_add_devices (pmc->dev,PLATFORM_DEVID_AUTO , + &pmc->cells[PMC_TELEM ],1 , + pmc->telem_base,0 ,NULL ); +} + +static const struct acpi_device_id intel_pmc_acpi_ids[] = { + {"INT34D2" }, + { } +}; +MODULE_DEVICE_TABLE (acpi, intel_pmc_acpi_ids); + +static int intel_pmc_probe (struct platform_device *pdev) +{ +struct intel_scu_ipc_pdata pdata = {}; +struct intel_pmc_dev *pmc; +int ret; + + pmc =devm_kzalloc (&pdev->dev,sizeof (*pmc),GFP_KERNEL ); +if (!pmc) +return -ENOMEM ; + + pmc->dev = &pdev->dev; +spin_lock_init (&pmc->gcr_lock); + + ret =intel_pmc_get_resources (pdev, pmc, &pdata); +if (ret) { +dev_err (&pdev->dev,"Failed to request resources\n" ); +return ret; + } + + pmc->scu =devm_intel_scu_ipc_register (&pdev->dev, &pdata); +if (IS_ERR (pmc->scu)) +return PTR_ERR (pmc->scu); + +platform_set_drvdata (pdev, pmc); + + ret =intel_pmc_create_devices (pmc); +if (ret) +dev_err (&pdev->dev,"Failed to create PMC devices\n" ); + +return ret; +} + +static struct platform_driver intel_pmc_driver = { + .probe = intel_pmc_probe, + .driver = { + .name ="intel_pmc_bxt" , + .acpi_match_table = intel_pmc_acpi_ids, + .dev_groups = intel_pmc_groups, + }, +}; + +module_platform_driver (intel_pmc_driver); + +MODULE_AUTHOR ("Zha Qipeng <[email protected]>" ); +MODULE_DESCRIPTION ("Intel Broxton PMC driver" ); +MODULE_LICENSE ("GPL v2" );drivers/platform/x86/Kconfig +5
-11@@ -1195,19 +1195,11 @@ config INTEL_SMARTCONNECT This driver checks to determine whether the device has Intel Smart Connect enabled, and if so disables it. -config INTEL_PMC_IPC - tristate "Intel PMC IPC Driver" - depends on ACPI - select INTEL_SCU_IPC - ---help--- - This driver provides support for PMC control on some Intel platforms. - The PMC is an ARC processor which defines IPC commands for communication - with other entities in the CPU. - config INTEL_BXTWC_PMIC_TMU tristate "Intel BXT Whiskey Cove TMU Driver" depends on REGMAP - depends on INTEL_SOC_PMIC_BXTWC && INTEL_PMC_IPC + depends on MFD_INTEL_PMC_BXT + depends on INTEL_SOC_PMIC_BXTWC ---help--- Select this driver to use Intel BXT Whiskey Cove PMIC TMU feature. This driver enables the alarm wakeup functionality in the TMU unit@@ -1233,7 +1225,9 @@ config INTEL_PUNIT_IPC config INTEL_TELEMETRY tristate "Intel SoC Telemetry Driver" - depends on INTEL_PMC_IPC && INTEL_PUNIT_IPC && X86_64 + depends on X86_64 + depends on MFD_INTEL_PMC_BXT + depends on INTEL_PUNIT_IPC ---help--- This driver provides interfaces to configure and use telemetry for INTEL SoC from APL onwards. It is alsodrivers/platform/x86/Makefile +0
-1@@ -86,7 +86,6 @@ obj-$(CONFIG_INTEL_RST) += intel-rst.o obj-$(CONFIG_INTEL_SMARTCONNECT) += intel-smartconnect.o obj-$(CONFIG_ALIENWARE_WMI) += alienware-wmi.o -obj-$(CONFIG_INTEL_PMC_IPC) += intel_pmc_ipc.o obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o obj-$(CONFIG_SURFACE_PRO3_BUTTON) += surfacepro3_button.o obj-$(CONFIG_SURFACE_3_BUTTON) += surface3_button.odrivers/platform/x86/intel_pmc_ipc.c deleted +0
-645@@ -1,645 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* Driver for the Intel PMC IPC mechanism -* -* (C) Copyright 2014-2015 Intel Corporation -* -* This driver is based on Intel SCU IPC driver(intel_scu_ipc.c) by -* Sreedhara DS <[email protected]> -* -* PMC running in ARC processor communicates with other entity running in IA -* core through IPC mechanism which in turn messaging between IA core ad PMC. -*/ - -#include <linux/acpi.h> -#include <linux/delay.h> -#include <linux/errno.h> -#include <linux/interrupt.h> -#include <linux/io-64-nonatomic-lo-hi.h> -#include <linux/module.h> -#include <linux/platform_device.h> - -#include <asm/intel_pmc_ipc.h> -#include <asm/intel_scu_ipc.h> - -#include <linux/platform_data/itco_wdt.h> - -/* Residency with clock rate at 19.2MHz to usecs */ -#define S0IX_RESIDENCY_IN_USECS (d, s) \ -({ \ - u64 result = 10ull * ((d) + (s)); \ - do_div(result, 192); \ - result; \ -}) - -/* exported resources from IFWI */ -#define PLAT_RESOURCE_IPC_INDEX 0 -#define PLAT_RESOURCE_IPC_SIZE 0x1000 -#define PLAT_RESOURCE_GCR_OFFSET 0x1000 -#define PLAT_RESOURCE_GCR_SIZE 0x1000 -#define PLAT_RESOURCE_BIOS_DATA_INDEX 1 -#define PLAT_RESOURCE_BIOS_IFACE_INDEX 2 -#define PLAT_RESOURCE_TELEM_SSRAM_INDEX 3 -#define PLAT_RESOURCE_ISP_DATA_INDEX 4 -#define PLAT_RESOURCE_ISP_IFACE_INDEX 5 -#define PLAT_RESOURCE_GTD_DATA_INDEX 6 -#define PLAT_RESOURCE_GTD_IFACE_INDEX 7 -#define PLAT_RESOURCE_ACPI_IO_INDEX 0 - -/* -* BIOS does not create an ACPI device for each PMC function, -* but exports multiple resources from one ACPI device(IPC) for -* multiple functions. This driver is responsible to create a -* platform device and to export resources for those functions. -*/ -#define TCO_DEVICE_NAME "iTCO_wdt" -#define SMI_EN_OFFSET 0x40 -#define SMI_EN_SIZE 4 -#define TCO_BASE_OFFSET 0x60 -#define TCO_REGS_SIZE 16 -#define PUNIT_DEVICE_NAME "intel_punit_ipc" -#define TELEMETRY_DEVICE_NAME "intel_telemetry" -#define TELEM_SSRAM_SIZE 240 -#define TELEM_PMC_SSRAM_OFFSET 0x1B00 -#define TELEM_PUNIT_SSRAM_OFFSET 0x1A00 -#define TCO_PMC_OFFSET 0x08 -#define TCO_PMC_SIZE 0x04 - -/* PMC register bit definitions */ - -/* PMC_CFG_REG bit masks */ -#define PMC_CFG_NO_REBOOT_MASK BIT_MASK(4) -#define PMC_CFG_NO_REBOOT_EN (1 << 4) -#define PMC_CFG_NO_REBOOT_DIS (0 << 4) - -static struct intel_pmc_ipc_dev { -struct device *dev; - -/* The following PMC BARs share the same ACPI device with the IPC */ -resource_size_t acpi_io_base; -int acpi_io_size; -struct platform_device *tco_dev; - -/* gcr */ -void __iomem *gcr_mem_base; -bool has_gcr_regs; -spinlock_t gcr_lock; - -/* punit */ -struct platform_device *punit_dev; -unsigned int punit_res_count; - -/* Telemetry */ -resource_size_t telem_pmc_ssram_base; -resource_size_t telem_punit_ssram_base; -int telem_pmc_ssram_size; -int telem_punit_ssram_size; -u8 telem_res_inval; -struct platform_device *telemetry_dev; -} ipcdev; - -static inline u64 gcr_data_readq (u32 offset) -{ -return readq (ipcdev.gcr_mem_base + offset); -} - -static inline int is_gcr_valid (u32 offset) -{ -if (!ipcdev.has_gcr_regs) -return -EACCES ; - -if (offset >PLAT_RESOURCE_GCR_SIZE ) -return -EINVAL ; - -return 0 ; -} - -/** -* intel_pmc_gcr_read64() - Read a 64-bit PMC GCR register -* @offset: offset of GCR register from GCR address base -* @data: data pointer for storing the register output -* -* Reads the 64-bit PMC GCR register at given offset. -* -* Return: negative value on error or 0 on success. -*/ -int intel_pmc_gcr_read64 (u32 offset,u64 *data) -{ -int ret; - -spin_lock (&ipcdev.gcr_lock); - - ret =is_gcr_valid (offset); -if (ret <0 ) { -spin_unlock (&ipcdev.gcr_lock); -return ret; - } - - *data =readq (ipcdev.gcr_mem_base + offset); - -spin_unlock (&ipcdev.gcr_lock); - -return 0 ; -} -EXPORT_SYMBOL_GPL (intel_pmc_gcr_read64); - -/** -* intel_pmc_gcr_update() - Update PMC GCR register bits -* @offset: offset of GCR register from GCR address base -* @mask: bit mask for update operation -* @val: update value -* -* Updates the bits of given GCR register as specified by -* @mask and @val. -* -* Return: negative value on error or 0 on success. -*/ -static int intel_pmc_gcr_update (u32 offset,u32 mask,u32 val) -{ -u32 new_val; -int ret =0 ; - -spin_lock (&ipcdev.gcr_lock); - - ret =is_gcr_valid (offset); -if (ret <0 ) - goto gcr_ipc_unlock; - - new_val =readl (ipcdev.gcr_mem_base + offset); - - new_val &= ~mask; - new_val |= val & mask; - -writel (new_val, ipcdev.gcr_mem_base + offset); - - new_val =readl (ipcdev.gcr_mem_base + offset); - -/* check whether the bit update is successful */ -if ((new_val & mask) != (val & mask)) { - ret = -EIO ; - goto gcr_ipc_unlock; - } - -gcr_ipc_unlock: -spin_unlock (&ipcdev.gcr_lock); -return ret; -} - -static int update_no_reboot_bit (void *priv,bool set) -{ -u32 value = set ?PMC_CFG_NO_REBOOT_EN :PMC_CFG_NO_REBOOT_DIS ; - -return intel_pmc_gcr_update (PMC_GCR_PMC_CFG_REG , -PMC_CFG_NO_REBOOT_MASK , value); -} - -static ssize_t intel_pmc_ipc_simple_cmd_store (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -struct intel_scu_ipc_dev *scu =dev_get_drvdata (dev); -int subcmd; -int cmd; -int ret; - - ret =sscanf (buf,"%d %d" , &cmd, &subcmd); -if (ret !=2 ) { -dev_err (dev,"Error args\n" ); -return -EINVAL ; - } - - ret =intel_scu_ipc_dev_simple_command (scu, cmd, subcmd); -if (ret) { -dev_err (dev,"command %d error with %d\n" , cmd, ret); -return ret; - } -return (ssize_t )count; -} -static DEVICE_ATTR(simplecmd, 0200, NULL, intel_pmc_ipc_simple_cmd_store); - -static ssize_t intel_pmc_ipc_northpeak_store (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t count) -{ -struct intel_scu_ipc_dev *scu =dev_get_drvdata (dev); -unsigned long val; -int subcmd; -int ret; - - ret =kstrtoul (buf,0 , &val); -if (ret) -return ret; - -if (val) - subcmd =1 ; -else - subcmd =0 ; - ret =intel_scu_ipc_dev_simple_command (scu,PMC_IPC_NORTHPEAK_CTRL , subcmd); -if (ret) { -dev_err (dev,"command north %d error with %d\n" , subcmd, ret); -return ret; - } -return (ssize_t )count; -} -static DEVICE_ATTR(northpeak, 0200, NULL, intel_pmc_ipc_northpeak_store); - -static struct attribute *intel_ipc_attrs[] = { - &dev_attr_northpeak.attr, - &dev_attr_simplecmd.attr, -NULL -}; - -static const struct attribute_group intel_ipc_group = { - .attrs = intel_ipc_attrs, -}; - -static const struct attribute_group *intel_ipc_groups[] = { - &intel_ipc_group, -NULL -}; - -static struct resource punit_res_array[] = { -/* Punit BIOS */ - { - .flags =IORESOURCE_MEM , - }, - { - .flags =IORESOURCE_MEM , - }, -/* Punit ISP */ - { - .flags =IORESOURCE_MEM , - }, - { - .flags =IORESOURCE_MEM , - }, -/* Punit GTD */ - { - .flags =IORESOURCE_MEM , - }, - { - .flags =IORESOURCE_MEM , - }, -}; - -#define TCO_RESOURCE_ACPI_IO 0 -#define TCO_RESOURCE_SMI_EN_IO 1 -#define TCO_RESOURCE_GCR_MEM 2 -static struct resource tco_res[] = { -/* ACPI - TCO */ - { - .flags =IORESOURCE_IO , - }, -/* ACPI - SMI */ - { - .flags =IORESOURCE_IO , - }, -}; - -static struct itco_wdt_platform_data tco_info = { - .name ="Apollo Lake SoC" , - .version =5 , - .no_reboot_priv = &ipcdev, - .update_no_reboot_bit = update_no_reboot_bit, -}; - -#define TELEMETRY_RESOURCE_PUNIT_SSRAM 0 -#define TELEMETRY_RESOURCE_PMC_SSRAM 1 -static struct resource telemetry_res[] = { -/*Telemetry*/ - { - .flags =IORESOURCE_MEM , - }, - { - .flags =IORESOURCE_MEM , - }, -}; - -static int ipc_create_punit_device (void ) -{ -struct platform_device *pdev; -const struct platform_device_info pdevinfo = { - .parent = ipcdev.dev, - .name =PUNIT_DEVICE_NAME , - .id =-1 , - .res = punit_res_array, - .num_res = ipcdev.punit_res_count, - }; - - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.punit_dev = pdev; - -return 0 ; -} - -static int ipc_create_tco_device (void ) -{ -struct platform_device *pdev; -struct resource *res; -const struct platform_device_info pdevinfo = { - .parent = ipcdev.dev, - .name =TCO_DEVICE_NAME , - .id =-1 , - .res = tco_res, - .num_res =ARRAY_SIZE (tco_res), - .data = &tco_info, - .size_data =sizeof (tco_info), - }; - - res = tco_res +TCO_RESOURCE_ACPI_IO ; - res->start = ipcdev.acpi_io_base +TCO_BASE_OFFSET ; - res->end = res->start +TCO_REGS_SIZE -1 ; - - res = tco_res +TCO_RESOURCE_SMI_EN_IO ; - res->start = ipcdev.acpi_io_base +SMI_EN_OFFSET ; - res->end = res->start +SMI_EN_SIZE -1 ; - - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.tco_dev = pdev; - -return 0 ; -} - -static int ipc_create_telemetry_device (void ) -{ -struct platform_device *pdev; -struct resource *res; -const struct platform_device_info pdevinfo = { - .parent = ipcdev.dev, - .name =TELEMETRY_DEVICE_NAME , - .id =-1 , - .res = telemetry_res, - .num_res =ARRAY_SIZE (telemetry_res), - }; - - res = telemetry_res +TELEMETRY_RESOURCE_PUNIT_SSRAM ; - res->start = ipcdev.telem_punit_ssram_base; - res->end = res->start + ipcdev.telem_punit_ssram_size -1 ; - - res = telemetry_res +TELEMETRY_RESOURCE_PMC_SSRAM ; - res->start = ipcdev.telem_pmc_ssram_base; - res->end = res->start + ipcdev.telem_pmc_ssram_size -1 ; - - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.telemetry_dev = pdev; - -return 0 ; -} - -static int ipc_create_pmc_devices (void ) -{ -int ret; - -/* If we have ACPI based watchdog use that instead */ -if (!acpi_has_watchdog ()) { - ret =ipc_create_tco_device (); -if (ret) { -dev_err (ipcdev.dev,"Failed to add tco platform device\n" ); -return ret; - } - } - - ret =ipc_create_punit_device (); -if (ret) { -dev_err (ipcdev.dev,"Failed to add punit platform device\n" ); -platform_device_unregister (ipcdev.tco_dev); -return ret; - } - -if (!ipcdev.telem_res_inval) { - ret =ipc_create_telemetry_device (); -if (ret) { -dev_warn (ipcdev.dev, -"Failed to add telemetry platform device\n" ); -platform_device_unregister (ipcdev.punit_dev); -platform_device_unregister (ipcdev.tco_dev); - } - } - -return ret; -} - -static int ipc_plat_get_res (struct platform_device *pdev, -struct intel_scu_ipc_pdata *pdata) -{ -struct resource *res, *punit_res = punit_res_array; -resource_size_t start; -void __iomem *addr; -int size; - - res =platform_get_resource (pdev,IORESOURCE_IO , -PLAT_RESOURCE_ACPI_IO_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get io resource\n" ); -return -ENXIO ; - } - size =resource_size (res); - ipcdev.acpi_io_base = res->start; - ipcdev.acpi_io_size = size; -dev_info (&pdev->dev,"io res: %pR\n" , res); - - ipcdev.punit_res_count =0 ; - -/* This is index 0 to cover BIOS data register */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_BIOS_DATA_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get res of punit BIOS data\n" ); -return -ENXIO ; - } - punit_res[ipcdev.punit_res_count++] = *res; -dev_info (&pdev->dev,"punit BIOS data res: %pR\n" , res); - -/* This is index 1 to cover BIOS interface register */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_BIOS_IFACE_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get res of punit BIOS iface\n" ); -return -ENXIO ; - } - punit_res[ipcdev.punit_res_count++] = *res; -dev_info (&pdev->dev,"punit BIOS interface res: %pR\n" , res); - -/* This is index 2 to cover ISP data register, optional */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_ISP_DATA_INDEX ); -if (res) { - punit_res[ipcdev.punit_res_count++] = *res; -dev_info (&pdev->dev,"punit ISP data res: %pR\n" , res); - } - -/* This is index 3 to cover ISP interface register, optional */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_ISP_IFACE_INDEX ); -if (res) { - punit_res[ipcdev.punit_res_count++] = *res; -dev_info (&pdev->dev,"punit ISP interface res: %pR\n" , res); - } - -/* This is index 4 to cover GTD data register, optional */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_GTD_DATA_INDEX ); -if (res) { - punit_res[ipcdev.punit_res_count++] = *res; -dev_info (&pdev->dev,"punit GTD data res: %pR\n" , res); - } - -/* This is index 5 to cover GTD interface register, optional */ - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_GTD_IFACE_INDEX ); -if (res) { - punit_res[ipcdev.punit_res_count++] = *res; -dev_info (&pdev->dev,"punit GTD interface res: %pR\n" , res); - } - - pdata->irq =platform_get_irq (pdev,0 ); - - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_IPC_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get ipc resource\n" ); -return -ENXIO ; - } -dev_info (&pdev->dev,"ipc res: %pR\n" , res); - - pdata->mem.flags = res->flags; - pdata->mem.start = res->start; - pdata->mem.end = res->start +PLAT_RESOURCE_IPC_SIZE -1 ; - - start = res->start +PLAT_RESOURCE_GCR_OFFSET ; -if (!devm_request_mem_region (&pdev->dev, start,PLAT_RESOURCE_GCR_SIZE , -"pmc_ipc_plat" )) -return -EBUSY ; - - addr =devm_ioremap (&pdev->dev, start,PLAT_RESOURCE_GCR_SIZE ); -if (!addr) -return -ENOMEM ; - - ipcdev.gcr_mem_base = addr; - - ipcdev.telem_res_inval =0 ; - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_TELEM_SSRAM_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get telemetry ssram resource\n" ); - ipcdev.telem_res_inval =1 ; - }else { - ipcdev.telem_punit_ssram_base = res->start + -TELEM_PUNIT_SSRAM_OFFSET ; - ipcdev.telem_punit_ssram_size =TELEM_SSRAM_SIZE ; - ipcdev.telem_pmc_ssram_base = res->start + -TELEM_PMC_SSRAM_OFFSET ; - ipcdev.telem_pmc_ssram_size =TELEM_SSRAM_SIZE ; -dev_info (&pdev->dev,"telemetry ssram res: %pR\n" , res); - } - -return 0 ; -} - -/** -* intel_pmc_s0ix_counter_read() - Read S0ix residency. -* @data: Out param that contains current S0ix residency count. -* -* Return: an error code or 0 on success. -*/ -int intel_pmc_s0ix_counter_read (u64 *data) -{ -u64 deep, shlw; - -if (!ipcdev.has_gcr_regs) -return -EACCES ; - - deep =gcr_data_readq (PMC_GCR_TELEM_DEEP_S0IX_REG ); - shlw =gcr_data_readq (PMC_GCR_TELEM_SHLW_S0IX_REG ); - - *data =S0IX_RESIDENCY_IN_USECS (deep, shlw); - -return 0 ; -} -EXPORT_SYMBOL_GPL (intel_pmc_s0ix_counter_read); - -#ifdef CONFIG_ACPI -static const struct acpi_device_id ipc_acpi_ids[] = { - {"INT34D2" ,0 }, - { } -}; -MODULE_DEVICE_TABLE (acpi, ipc_acpi_ids); -#endif - -static int ipc_plat_probe (struct platform_device *pdev) -{ -struct intel_scu_ipc_pdata pdata = {}; -struct intel_scu_ipc_dev *scu; -int ret; - - ipcdev.dev = &pdev->dev; -spin_lock_init (&ipcdev.gcr_lock); - - ret =ipc_plat_get_res (pdev, &pdata); -if (ret) { -dev_err (&pdev->dev,"Failed to request resource\n" ); -return ret; - } - - scu =devm_intel_scu_ipc_register (&pdev->dev, &pdata); -if (IS_ERR (scu)) -return PTR_ERR (scu); - -platform_set_drvdata (pdev, scu); - - ret =ipc_create_pmc_devices (); -if (ret) { -dev_err (&pdev->dev,"Failed to create pmc devices\n" ); -return ret; - } - - ipcdev.has_gcr_regs = true; - -return 0 ; -} - -static int ipc_plat_remove (struct platform_device *pdev) -{ -platform_device_unregister (ipcdev.tco_dev); -platform_device_unregister (ipcdev.punit_dev); -platform_device_unregister (ipcdev.telemetry_dev); - ipcdev.dev =NULL ; -return 0 ; -} - -static struct platform_driver ipc_plat_driver = { - .remove = ipc_plat_remove, - .probe = ipc_plat_probe, - .driver = { - .name ="pmc-ipc-plat" , - .acpi_match_table =ACPI_PTR (ipc_acpi_ids), - .dev_groups = intel_ipc_groups, - }, -}; - -static int __init intel_pmc_ipc_init (void ) -{ -return platform_driver_register (&ipc_plat_driver); -} - -static void __exit intel_pmc_ipc_exit(void) -{ -platform_driver_unregister (&ipc_plat_driver); -} - -MODULE_AUTHOR ("Zha Qipeng <[email protected]>" ); -MODULE_DESCRIPTION ("Intel PMC IPC driver" ); -MODULE_LICENSE ("GPL v2" ); - -/* Some modules are dependent on this, so init earlier */ -fs_initcall (intel_pmc_ipc_init); -module_exit (intel_pmc_ipc_exit);drivers/platform/x86/intel_telemetry_debugfs.c +0
-0@@ -16,13 +16,13 @@#include <linux/debugfs.h> #include <linux/device.h>
Quoted 4 lines
drivers/platform/x86/intel_telemetry_debugfs.c line 19
Quoted 2 lines
drivers/platform/x86/intel_telemetry_debugfs.c +1
-0#include <linux/module.h> +#include <linux/mfd/intel_pmc_bxt.h> Alphabetical order?
Same answer here than the other alphabetical ordering comment ;-)
Thanks for the review!
Re: [PATCH v4 37/38] platform/x86: intel_pmc_ipc: Convert to MFD
In reply to Mika WesterbergQuoted 37 lines · Mika Westerberg
This driver only creates a bunch of platform devices sharing resources belonging to the PMC device. This is pretty much what MFD subsystem is for so move the driver there, renaming it to
intel_pmc_bxt.cwhich should be more clear what it is.MFD subsystem provides nice helper APIs for subdevice creation so convert the driver to use those. Unfortunately the ACPI device includes separate resources for most of the subdevices so we cannot simply call
mfd_add_devices()to create all of them but instead we need to call it separately for each device.The new MFD driver continues to expose two sysfs attributes that allow userspace to send IPC commands to the PMC/SCU to avoid breaking any existing applications that may use these. Generally this is bad idea so document this in the ABI documentation.
Signed-off-by Mika Westerberg <[email protected]>--- .../ABI/obsolete/sysfs-driver-intel_pmc_bxt | 22 + arch/x86/include/asm/intel_pmc_ipc.h | 47 -- arch/x86/include/asm/intel_telemetry.h | 1 + drivers/mfd/Kconfig | 16 +- drivers/mfd/Makefile | 1 + drivers/mfd/intel_pmc_bxt.c | 496 ++++++++++++++ drivers/platform/x86/Kconfig | 16 +- drivers/platform/x86/Makefile | 1 - drivers/platform/x86/intel_pmc_ipc.c | 645 ------------------ .../platform/x86/intel_telemetry_debugfs.c | 12 +- drivers/platform/x86/intel_telemetry_pltdrv.c | 2 + drivers/usb/typec/tcpm/Kconfig | 2 +- include/linux/mfd/intel_pmc_bxt.h | 21 + 13 files changed, 572 insertions(+), 710 deletions(-) create mode 100644 Documentation/ABI/obsolete/sysfs-driver-intel_pmc_bxt delete mode 100644 arch/x86/include/asm/intel_pmc_ipc.h create mode 100644 drivers/mfd/intel_pmc_bxt.c delete mode 100644 drivers/platform/x86/intel_pmc_ipc.c create mode 100644 include/linux/mfd/intel_pmc_bxt.h
[...]
Quoted 12 lines
drivers/mfd/intel_pmc_bxt.c new file +12
-0+static int intel_pmc_probe (struct platform_device *pdev) +{ +struct intel_scu_ipc_pdata pdata = {}; +struct intel_pmc_dev *pmc; +int ret; + + pmc =devm_kzalloc (&pdev->dev,sizeof (*pmc),GFP_KERNEL ); +if (!pmc) +return -ENOMEM ; + + pmc->dev = &pdev->dev; +spin_lock_init (&pmc->gcr_lock);
drivers/mfd/intel_pmc_bxt.c line 472
Quoted 10 lines
drivers/mfd/intel_pmc_bxt.c new file +10
-0+ + ret =intel_pmc_get_resources (pdev, pmc, &pdata); +if (ret) { +dev_err (&pdev->dev,"Failed to request resources\n" ); +return ret; + } + + pmc->scu =devm_intel_scu_ipc_register (&pdev->dev, &pdata); +if (IS_ERR (pmc->scu)) +return PTR_ERR (pmc->scu);
*_register is better than *_probe. If it was called that (or maybe *_init) initially I may have missed the issue altogether ...
However, I still think it the SCU IPC *device* needs to be a device driver and abide by the rules, ensuring it uses the device driver model/API. As such, it should be registered and probed as a device.
If you require something from it you should call into it (perhaps using a register function like above), but that should be done *after* the device has been bound and probed.
Quoted 8 lines
drivers/mfd/intel_pmc_bxt.c new file +8
-0+platform_set_drvdata (pdev, pmc); + + ret =intel_pmc_create_devices (pmc); +if (ret) +dev_err (&pdev->dev,"Failed to create PMC devices\n" ); + +return ret; +}
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Mika Westerberg
maintainerRe: [PATCH v4 37/38] platform/x86: intel_pmc_ipc: Convert to MFD
Quoted 26 lines · Lee Jones
Quoted 12 lines
drivers/mfd/intel_pmc_bxt.c new file +12
-0+static int intel_pmc_probe (struct platform_device *pdev) +{ +struct intel_scu_ipc_pdata pdata = {}; +struct intel_pmc_dev *pmc; +int ret; + + pmc =devm_kzalloc (&pdev->dev,sizeof (*pmc),GFP_KERNEL ); +if (!pmc) +return -ENOMEM ; + + pmc->dev = &pdev->dev; +spin_lock_init (&pmc->gcr_lock);drivers/mfd/intel_pmc_bxt.c line 472
Quoted 10 lines
drivers/mfd/intel_pmc_bxt.c new file +10
-0+ + ret =intel_pmc_get_resources (pdev, pmc, &pdata); +if (ret) { +dev_err (&pdev->dev,"Failed to request resources\n" ); +return ret; + } + + pmc->scu =devm_intel_scu_ipc_register (&pdev->dev, &pdata); +if (IS_ERR (pmc->scu)) +return PTR_ERR (pmc->scu);
*_registeris better than*_probe. If it was called that (or maybe*_init) initially I may have missed the issue altogether ...
Quoted 3 lines
However, I still think it the SCU IPC *device* needs to be a device driver and abide by the rules, ensuring it uses the device driver model/API. As such, it should be registered and probed as a device.
Which type of device you suggest here? And which bus it should be registered to? I think we can make this create a platform_device but then we would need to do that from the PCI driver as well which seems unnecessary since we already have the struct pci_dev.
For instance in drivers/mfd/intel-lpss* we use similar approach (the core part is library that gets called by probe drivers (ACPI, PCI). We don't create any additional platform_devices.
There is another twist. Ideally we would like to see the SCU IPC probed and intialized before the MFD children so that we know the SCU IPC is ready by the time the children devices are created. I guess we could work it around by returning -EPROBE_DEFER but that does not feel right to be honest.
Thanks!
Re: [PATCH v4 37/38] platform/x86: intel_pmc_ipc: Convert to MFD
Quoted 27 lines · Mika Westerberg
Quoted 26 lines · Lee Jones
Quoted 12 lines
drivers/mfd/intel_pmc_bxt.c new file +12
-0+static int intel_pmc_probe (struct platform_device *pdev) +{ +struct intel_scu_ipc_pdata pdata = {}; +struct intel_pmc_dev *pmc; +int ret; + + pmc =devm_kzalloc (&pdev->dev,sizeof (*pmc),GFP_KERNEL ); +if (!pmc) +return -ENOMEM ; + + pmc->dev = &pdev->dev; +spin_lock_init (&pmc->gcr_lock);drivers/mfd/intel_pmc_bxt.c line 472
Quoted 10 lines
drivers/mfd/intel_pmc_bxt.c new file +10
-0+ + ret =intel_pmc_get_resources (pdev, pmc, &pdata); +if (ret) { +dev_err (&pdev->dev,"Failed to request resources\n" ); +return ret; + } + + pmc->scu =devm_intel_scu_ipc_register (&pdev->dev, &pdata); +if (IS_ERR (pmc->scu)) +return PTR_ERR (pmc->scu);
*_registeris better than*_probe. If it was called that (or maybe*_init) initially I may have missed the issue altogether ...
Quoted 8 lines
Quoted 3 lines
However, I still think it the SCU IPC *device* needs to be a device driver and abide by the rules, ensuring it uses the device driver model/API. As such, it should be registered and probed as a device.
Which type of device you suggest here? And which bus it should be registered to? I think we can make this create a
platform_devicebut then we would need to do that from the PCI driver as well which seems unnecessary since we already have the structpci_dev.
What kind of device is it?
Refrain from using platform device, unless it is one please.
Quoted 3 lines
For instance in
drivers/mfd/intel-lpss*we use similar approach (the core part is library that gets called by probe drivers (ACPI, PCI). We don't create any additionalplatform_devices.
That's different. Here the *-acpi.c and *-pci.c are only used as registration hooks into the same device. The semantics we're discussing are seemingly used to probe/init a different device in a separate subsystem.
Quoted 5 lines
There is another twist. Ideally we would like to see the SCU IPC probed and intialized before the MFD children so that we know the SCU IPC is ready by the time the children devices are created. I guess we could work it around by returning -EPROBE_DEFER but that does not feel right to be honest.
That's precisely what -EPROBE_DEFER was designed for.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Mika Westerberg
maintainerRe: [PATCH v4 37/38] platform/x86: intel_pmc_ipc: Convert to MFD
Quoted 6 lines · Lee Jones
Quoted 4 lines
Which type of device you suggest here? And which bus it should be registered to? I think we can make this create a
platform_devicebut then we would need to do that from the PCI driver as well which seems unnecessary since we already have the structpci_dev.What kind of device is it?
It is either part of an ACPI device (platform_device) or a PCI device depending on the platform.
Quoted 1 line
Refrain from using platform device, unless it is one please.
OK.
Greg suggested making the SCU IPC functionality a class and I think it fits here nicely so I'm going to try that next if nobody objects. I'll send the first cleanup patches separately.
Re: [PATCH v4 37/38] platform/x86: intel_pmc_ipc: Convert to MFD
Quoted 11 lines · Mika Westerberg
Quoted 6 lines · Lee Jones
Quoted 4 lines
Which type of device you suggest here? And which bus it should be registered to? I think we can make this create a
platform_devicebut then we would need to do that from the PCI driver as well which seems unnecessary since we already have the structpci_dev.What kind of device is it?
It is either part of an ACPI device (
platform_device) or a PCI device depending on the platform.
Quoted 7 lines
Quoted 1 line
Refrain from using platform device, unless it is one please.
OK.
Greg suggested making the SCU IPC functionality a class and I think it fits here nicely so I'm going to try that next if nobody objects. I'll send the first cleanup patches separately.
Sounds good.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Mika Westerberg
maintainerRe: [PATCH v4 37/38] platform/x86: intel_pmc_ipc: Convert to MFD
Quoted 15 lines · Lee Jones
Quoted 13 lines · Mika Westerberg
Quoted 6 lines · Lee Jones
Quoted 4 lines
Which type of device you suggest here? And which bus it should be registered to? I think we can make this create a
platform_devicebut then we would need to do that from the PCI driver as well which seems unnecessary since we already have the structpci_dev.What kind of device is it?
It is either part of an ACPI device (
platform_device) or a PCI device depending on the platform.Quoted 1 line
Refrain from using platform device, unless it is one please.
Quoted 7 lines
Quoted 5 lines
OK.
Greg suggested making the SCU IPC functionality a class and I think it fits here nicely so I'm going to try that next if nobody objects. I'll send the first cleanup patches separately.
Sounds good.
FYI, I the cleanup patch series can be found here:
https://www.spinics.net/lists/platform-driver-x86/msg20728.html
https://www.spinics.net/lists/platform-driver-x86/msg20729.html
https://www.spinics.net/lists/platform-driver-x86/msg20734.html
https://www.spinics.net/lists/platform-driver-x86/msg20750.html
Mika Westerberg
maintainerPATCH v4 38/38 MAINTAINERS: Update entry for Intel Broxton PMC driver
In reply to Mika WesterbergThe driver lives now under MFD so split the current entry into two parts and add me as co-maintainer of the Intel Broxton PMC driver. While there correct formatting of Zha Qipeng's email address.
--- MAINTAINERS | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
MAINTAINERS +9 -4
@@ -8280,6 +8280,13 @@ L: [email protected] S: Maintained F: drivers/platform/x86/intel_atomisp2_pm.c +INTEL BROXTON PMC DRIVER +M: Mika Westerberg <[email protected]> +M: Zha Qipeng <[email protected]> +S: Maintained +F: drivers/mfd/intel_pmc_bxt.c +F: include/linux/mfd/intel_pmc_bxt.h + INTEL C600 SERIES SAS CONTROLLER DRIVER M: Intel SCU Linux support <[email protected]> M: Artur Paszkiewicz <[email protected]>
@@ -8488,13 +8495,11 @@ L: [email protected] S: Maintained F: drivers/platform/x86/intel_pmc_core* -INTEL PMC/P-Unit IPC DRIVER -M: Zha Qipeng<[email protected]> +INTEL P-Unit IPC DRIVER +M: Zha Qipeng <[email protected]> L: [email protected] S: Maintained -F: drivers/platform/x86/intel_pmc_ipc.c F: drivers/platform/x86/intel_punit_ipc.c -F: arch/x86/include/asm/intel_pmc_ipc.h F: arch/x86/include/asm/intel_punit_ipc.h INTEL PMIC GPIO DRIVERS
Signature · 1 line
2.24.1
Quoted 4 lines · Mika Westerberg
Currently both
intel_scu_ipc.candintel_pmc_ipc.cimplement the same SCU IPC communications with minor differences. This duplication does not make much sense so this series reworks the two drivers so that there is only a single implementation of the SCU IPC. In addition to that the API will be
This is a 40 (!) patch series and looking at the subjects and diffstat I can't tell if there's something in particular that you're looking for me to review?
Mika Westerberg
maintainerQuoted 10 lines · Mark Brown
Quoted 4 lines · Mika Westerberg
Currently both
intel_scu_ipc.candintel_pmc_ipc.cimplement the same SCU IPC communications with minor differences. This duplication does not make much sense so this series reworks the two drivers so that there is only a single implementation of the SCU IPC. In addition to that the API will beThis is a 40 (!) patch series and looking at the subjects and diffstat I can't tell if there's something in particular that you're looking for me to review?
Sorry about that. I included you because there was suggestion from Lee to convert the MFD driver in patch 37 to use regmap but the registers are all 64-bit and it was not clear whether regmap supports that:
https://www.spinics.net/lists/platform-driver-x86/msg20652.html
Looking at the regmap API it seems to deal mostly with "unsigned int" which does not work well with the 64-bit MMIO registers but I may be missing something.
Quoted 9 lines · Mika Westerberg
Sorry about that. I included you because there was suggestion from Lee to convert the MFD driver in patch 37 to use regmap but the registers are all 64-bit and it was not clear whether regmap supports that:
https://www.spinics.net/lists/platform-driver-x86/msg20652.html
Looking at the regmap API it seems to deal mostly with "unsigned int" which does not work well with the 64-bit MMIO registers but I may be missing something.
It should work fine on architectures with 64 bit ints but otherwise it's not supported (and doing so would hurt the API pretty badly so I'm not sure it would make sense but patches welcome).
Mika Westerberg
maintainerQuoted 8 lines · Mark Brown
Quoted 5 lines · Mika Westerberg
Sorry about that. I included you because there was suggestion from Lee to convert the MFD driver in patch 37 to use regmap but the registers are all 64-bit and it was not clear whether regmap supports that:
https://www.spinics.net/lists/platform-driver-x86/msg20652.html
Quoted 7 lines
Quoted 3 lines
Looking at the regmap API it seems to deal mostly with "unsigned int" which does not work well with the 64-bit MMIO registers but I may be missing something.
It should work fine on architectures with 64 bit ints but otherwise it's not supported (and doing so would hurt the API pretty badly so I'm not sure it would make sense but patches welcome).
OK, thanks for the clarification. I guess in this case we can probably just live without using it, if that's fine for Lee and others. The new MFD driver itself is ~500 lines so not sure how much regmap would help there, and we only expose two simple functions for the subdevices both dealing with 64-bit registers.
Quoted 5 lines · Mika Westerberg
OK, thanks for the clarification. I guess in this case we can probably just live without using it, if that's fine for Lee and others. The new MFD driver itself is ~500 lines so not sure how much regmap would help there, and we only expose two simple functions for the subdevices both dealing with 64-bit registers.
The usual motivation is all the diagnostic infrastructure you get with regmap - tracepoints for I/O and the ability to dump the register map in debugfs mainly.
Mika Westerberg
maintainerQuoted 11 lines · Mark Brown
Quoted 5 lines · Mika Westerberg
OK, thanks for the clarification. I guess in this case we can probably just live without using it, if that's fine for Lee and others. The new MFD driver itself is ~500 lines so not sure how much regmap would help there, and we only expose two simple functions for the subdevices both dealing with 64-bit registers.
The usual motivation is all the diagnostic infrastructure you get with regmap - tracepoints for I/O and the ability to dump the register map in debugfs mainly.
Right.
Here we are talking about a "map" of two registers so probably not worth the added trouble ;-)