SCU/PMC/PUNIT Inter-Processor Communication(IPC) driver cleanup
Subsystems (9)
v8 cover SCU/PMC/PUNIT Inter-Processor Communication(IPC) driver cleanup
From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9/[email protected]>
Hi All,
Currently intel_pmc_ipc.c, intel_punit_ipc.c, intel_scu_ipc.c drivers implements the same IPC features. This code duplication could be avoided if we implement the IPC driver as a generic library and let custom device drivers use API provided by generic driver. This patchset mainly addresses this issue.
Along with above code duplication issue, This patchset also addresses following issues in intel_pmc_ipc and intel_punit_ipc drivers.
1. Intel_pmc_ipc.c driver does not use any resource managed (devm_*) calls.
2. In Intel_pmc_ipc.c driver, dependent devices like PUNIT, Telemetry and iTCO are created manually and uses lot of redundant buffer code.
3. Global variable is used to store the IPC device structure and it is used across all functions in intel_pmc_ipc.c and intel_punit_ipc.c.
More info on Intel IPC device library:
-------------------------------------
A generic Intel IPC class driver has been implemented and all common IPC helper functions has been moved to this driver. It exposes APIs to create IPC device channel, send raw IPC command and simple IPC commands. It also creates device attribute to send IPC command from user space.
API for creating a new IPC channel device is,
struct intel_ipc_dev *devm_intel_ipc_dev_create(struct device *dev, const char *devname, struct intel_ipc_dev_cfg *cfg, struct intel_ipc_dev_ops *ops)
The IPC channel drivers (PUNIT/PMC/SCU) when creating a new device can configure their device params like register mapping, irq, irq-mode, channel type,etc using intel_ipc_dev_cfg and intel_ipc_dev_ops arguments. After a new IPC channel device is created, IPC users can use the generic APIs to make IPC calls.
For example, after using this new model, IPC call to PMC device will look like,
pmc_ipc_dev = intel_ipc_dev_get(INTEL_PMC_IPC_DEV); ipc_dev_raw_cmd(pmc_ipc_dev, ipc_raw_cmd); intel_ipc_dev_put(pmc_ipc_dev);
I am still testing the driver in different products. But posted it to get some early comments. I also welcome any PMC/PUNIT driver users to check these patches in their product.
Changes since v7:
* Fixed checkpatch errors/warnings.
Changes since v6:
* First two patches of v6 patch set has already been approved, So removed it from the list.
* Rebased rest of the patches on top of testing branch.
* Fixed some style issues.
Changes since v5:
* Added intel_ipc_cmd and intel_ipc_raw_cmd structures.
* Fixed some minor style issues.
* Rebased "intel_pmc_ipc: Use devm_* calls in driver probe function" patch on top of 4.14-rc5 kernel.
Changes since v4:
* Pushed "platform/x86: intel_pmc_ipc: Use spin_lock to protect GCR update" patch to the top of the patch list. Also its rebased on top of Andy's review branch.
Changes since v3:
* Rebased on top of Andy's review branch.
* Fixed resource ioremap warning in intel_punit_ipc.c.
* Divided "platform/x86: intel_pmc_ipc: Use regmap calls for GCR updates" patch into two patches. One fixing the existing issue and another to add regmap support.
* Fixed error in resource initalization logic in ipc_create_punit_device.
* Changed PLATFORM_DEVID_AUTO to PLATFORM_DEVID_NONE in mfd device creation.
* Added unique name to PUNIT BIOS, GTD, & ISP regmaps.
* Fixed NULL pointer exception in intel_ipc_dev_get().
* In intel_ipc_dev.c,
* Fixed error in check for duplicate intel_ipc_dev.
* Added custom interrupt handler support.
* Used char array for error string conversion.
* Added put dev support.
Changes since v2:
* Refactored intel_scu_ipc.c to use generic IPC device APIs.
* Fixed intel_pmc_ipc.c to use pcim_* device managed functions.
Changes since v1:
* Merged devm_* changes in pmc_plat_probe and pmc_pci_probe functions into a single patch.
* Addressed Andy's comment about keeping the library generic by not implementing the low level reg access calls in intel_ipc_dev.c. This version will start using the regmap pointer provided by channel drivers instead of fixed memory map.
* Removed custom IPC APIs in intel_pmc_ipc.c and intel_punit_ipc.c.
* Cleaned up IPC driver users to use APIs provided by generic library (intel_ipc_dev.c).
Kuppuswamy Sathyanarayanan (7):
platform/x86: intel_punit_ipc: Fix resource ioremap warning platform/x86: intel_pmc_ipc: Use MFD framework to create dependent
devices
platform/x86: intel_pmc_ipc: Use regmap calls for GCR updates
platform: x86: Add generic Intel IPC driver platform/x86: intel_punit_ipc: Use generic intel ipc device calls platform/x86: intel_pmc_ipc: Use generic Intel IPC device calls platform/x86: intel_scu_ipc: Use generic Intel IPC device calls
MAINTAINERS | 7 + arch/x86/include/asm/intel_pmc_ipc.h | 31 +- arch/x86/include/asm/intel_punit_ipc.h | 125 ++-- arch/x86/include/asm/intel_scu_ipc.h | 10 +- arch/x86/platform/intel-mid/intel-mid.c | 15 +- drivers/mfd/intel_soc_pmic_bxtwc.c | 37 +- drivers/platform/x86/Kconfig | 11 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_ipc_dev.c | 563 +++++++++++++++ drivers/platform/x86/intel_pmc_ipc.c | 886 +++++++++--------------- drivers/platform/x86/intel_punit_ipc.c | 307 +++----- drivers/platform/x86/intel_scu_ipc.c | 488 ++++++------- drivers/platform/x86/intel_telemetry_pltdrv.c | 229 +++--- drivers/rtc/rtc-mrst.c | 16 +- drivers/watchdog/intel-mid_wdt.c | 18 +- drivers/watchdog/intel_scu_watchdog.c | 23 +- include/linux/mfd/intel_soc_pmic.h | 2 + include/linux/platform_data/x86/intel_ipc_dev.h | 246 +++++++ 18 files changed, 1741 insertions(+), 1274 deletions(-) create mode 100644 drivers/platform/x86/intel_ipc_dev.c create mode 100644 include/linux/platform_data/x86/intel_ipc_dev.h
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC v8 1/7 platform/x86: intel_punit_ipc: Fix resource ioremap warning
From: Kuppuswamy Sathyanarayanan <[email protected]>
For PUNIT device, ISPDRIVER_IPC and GTDDRIVER_IPC resources are not mandatory. So when PMC IPC driver creates a PUNIT device, if these resources are not available then it creates dummy resource entries for these missing resources. But during PUNIT device probe, doing ioremap on these dummy resources generates following warning messages.
intel_punit_ipc: can't request region for resource [mem 0x00000000]intel_punit_ipc: can't request region for resource [mem 0x00000000]intel_punit_ipc: can't request region for resource [mem 0x00000000]intel_punit_ipc: can't request region for resource [mem 0x00000000]
This patch fixes this issue by adding extra check for resource size before performing ioremap operation.
--- drivers/platform/x86/intel_punit_ipc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Changes since v7:
* None
Changes since v6:
* None
Changes since v5:
* None
Changes since v4:
* None
drivers/platform/x86/intel_punit_ipc.c +4 -4
@@ -252,28 +252,28 @@ static int intel_punit_get_bars(struct platform_device *pdev)* - GTDRIVER_IPC BASE_IFACE */ res =platform_get_resource (pdev,IORESOURCE_MEM ,2 ); -if (res) { +if (res &&resource_size (res) >1 ) { addr =devm_ioremap_resource (&pdev->dev, res);if (!IS_ERR (addr)) punit_ipcdev->base[ISPDRIVER_IPC ][BASE_DATA ] = addr; } res =platform_get_resource (pdev,IORESOURCE_MEM ,3 ); -if (res) { +if (res &&resource_size (res) >1 ) { addr =devm_ioremap_resource (&pdev->dev, res);if (!IS_ERR (addr)) punit_ipcdev->base[ISPDRIVER_IPC ][BASE_IFACE ] = addr; } res =platform_get_resource (pdev,IORESOURCE_MEM ,4 ); -if (res) { +if (res &&resource_size (res) >1 ) { addr =devm_ioremap_resource (&pdev->dev, res);if (!IS_ERR (addr)) punit_ipcdev->base[GTDRIVER_IPC ][BASE_DATA ] = addr; } res =platform_get_resource (pdev,IORESOURCE_MEM ,5 ); -if (res) { +if (res &&resource_size (res) >1 ) { addr =devm_ioremap_resource (&pdev->dev, res);if (!IS_ERR (addr)) punit_ipcdev->base[GTDRIVER_IPC ][BASE_IFACE ] = addr;
Signature · 1 line
2.7.4
Re: [RFC v8 1/7] platform/x86: intel_punit_ipc: Fix resource ioremap warning
Quoted 8 lines · On Sun, Oct 29, 2017 at 11:49 AM, <[email protected]>…
From: Kuppuswamy Sathyanarayanan <[email protected]>
For PUNIT device,
ISPDRIVER_IPCandGTDDRIVER_IPCresources are not mandatory. So when PMC IPC driver creates a PUNIT device, if these resources are not available then it creates dummy resource entries for these missing resources. But during PUNIT device probe, doing ioremap on these dummy resources generates following warning messages.
Quoted 7 lines
intel_punit_ipc: can't request region for resource [mem0x00000000]intel_punit_ipc: can't request region for resource [mem0x00000000]intel_punit_ipc: can't request region for resource [mem0x00000000]intel_punit_ipc: can't request region for resource [mem0x00000000]This patch fixes this issue by adding extra check for resource size before performing ioremap operation.
I think I already told that this one had been pushed to my review and testing queue, thanks!
Quoted 59 lines
Signed-off-by Kuppuswamy Sathyanarayanan <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/platform/x86/intel_punit_ipc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)Changes since v7:
* NoneChanges since v6:
* NoneChanges since v5:
* NoneChanges since v4:
* Nonedrivers/platform/x86/intel_punit_ipc.c +4
-5@@ -252,28 +252,28 @@ static int intel_punit_get_bars(struct platform_device *pdev)* - GTDRIVER_IPC BASE_IFACE */ res =platform_get_resource (pdev,IORESOURCE_MEM ,2 ); -if (res) { +if (res &&resource_size (res) >1 ) { addr =devm_ioremap_resource (&pdev->dev, res);if (!IS_ERR (addr)) punit_ipcdev->base[ISPDRIVER_IPC ][BASE_DATA ] = addr; } res =platform_get_resource (pdev,IORESOURCE_MEM ,3 ); -if (res) { +if (res &&resource_size (res) >1 ) { addr =devm_ioremap_resource (&pdev->dev, res);if (!IS_ERR (addr)) punit_ipcdev->base[ISPDRIVER_IPC ][BASE_IFACE ] = addr; } res =platform_get_resource (pdev,IORESOURCE_MEM ,4 ); -if (res) { +if (res &&resource_size (res) >1 ) { addr =devm_ioremap_resource (&pdev->dev, res);if (!IS_ERR (addr)) punit_ipcdev->base[GTDRIVER_IPC ][BASE_DATA ] = addr; } res =platform_get_resource (pdev,IORESOURCE_MEM ,5 ); -if (res) { +if (res &&resource_size (res) >1 ) { addr =devm_ioremap_resource (&pdev->dev, res);if (!IS_ERR (addr)) punit_ipcdev->base[GTDRIVER_IPC ][BASE_IFACE ] = addr; --2.7.4
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFC v8 1/7] platform/x86: intel_punit_ipc: Fix resource ioremap warning
Hi Andy,
Quoted 2 lines · Andy Shevchenko
I think I already told that this one had been pushed to my review and testing queue, thanks!
I thought you specifically asked me to include this patch in next set. Following is your previous comment. Patch 3 in your reply points to this patch.
Quoted 3 lines
Quoted 3 lines
I have applied this patch with some modifications to my review-andy branch. Please, take it from there (and probably patch 3) and resend new version of the series based on our testing branch.
Signature · 3 lines
- Sathyanarayan Kuppuswamy Linux kernel developer
RFC v8 2/7 platform/x86: intel_pmc_ipc: Use MFD framework to create dependent devices
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
Currently, we have lot of repetitive code in dependent device resource allocation and device creation handling code. This logic can be improved if we use MFD framework for dependent device creation. This patch adds this support.
--- drivers/platform/x86/intel_pmc_ipc.c | 398 ++++++++++++----------------------- 1 file changed, 139 insertions(+), 259 deletions(-)
Changes since v7:
* Fixed style issues.
Changes since v6:
* Fixed style issues.
* Used Andy's modified version.
Changes since v5:
* Changed the order of patches in this patchlist.
Changes since v4:
* Changed the order of patches in this patchlist.
Changes since v3:
* Changed PLATFORM_DEVID_AUTO to PLATFORM_DEVID_NONE in mfd device creation.
* Fixed error in resource initalization logic in ipc_create_punit_device.
* Removed mfd cell id initialization.
drivers/platform/x86/intel_pmc_ipc.c +139 -259
@@ -20,6 +20,7 @@#include <linux/errno.h> #include <linux/init.h> #include <linux/device.h> +#include <linux/mfd/core.h> #include <linux/pm.h> #include <linux/pci.h> #include <linux/platform_device.h>
@@ -88,6 +89,7 @@#define PLAT_RESOURCE_ISP_IFACE_INDEX 5#define PLAT_RESOURCE_GTD_DATA_INDEX 6#define PLAT_RESOURCE_GTD_IFACE_INDEX 7 +#define PLAT_RESOURCE_MEM_MAX_INDEX 8#define PLAT_RESOURCE_ACPI_IO_INDEX 0/*
@@ -106,8 +108,6 @@#define TELEM_SSRAM_SIZE 240#define TELEM_PMC_SSRAM_OFFSET 0x1B00#define TELEM_PUNIT_SSRAM_OFFSET 0x1A00 -#define TCO_PMC_OFFSET 0x8 -#define TCO_PMC_SIZE 0x4/* PMC register bit definitions */
@@ -124,26 +124,10 @@ static struct intel_pmc_ipc_dev {int cmd;struct completion cmd_complete; -/* 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; - -/* 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 char *ipc_err_sources[] = {
@@ -508,7 +492,7 @@ static int ipc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) ret =devm_request_irq (&pdev->dev, pdev->irq, ioc,0 ,"intel_pmc_ipc" , pmc);if (ret) { -dev_err (&pdev->dev,"Failed to request irq\n" ); +dev_err (&pdev->dev,"Failed to request IRQ\n" );return ret; }
@@ -593,44 +577,6 @@ static const struct attribute_group intel_ipc_group = { .attrs = intel_ipc_attrs, }; -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 ,
@@ -638,234 +584,177 @@ static struct itco_wdt_platform_data tco_info = { .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 ) +static int ipc_create_punit_device (struct platform_device *pdev) { -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 =ARRAY_SIZE (punit_res_array), +struct resource punit_res[PLAT_RESOURCE_MEM_MAX_INDEX ]; +struct mfd_cell punit_cell; +struct resource *res; +int mindex, pindex =0 ; + +for (mindex =0 ; mindex <=PLAT_RESOURCE_MEM_MAX_INDEX ; mindex++) { + + res =platform_get_resource (pdev,IORESOURCE_MEM , mindex); + +switch (mindex) { +/* Get PUNIT resources */ +case PLAT_RESOURCE_BIOS_DATA_INDEX : +case PLAT_RESOURCE_BIOS_IFACE_INDEX : +/* BIOS resources are required, so return error if not +* available +*/ +if (!res) { +dev_err (&pdev->dev, +"Failed to get PUNIT MEM resource %d\n" , + pindex); +return -ENXIO ; + } +case PLAT_RESOURCE_ISP_DATA_INDEX : +case PLAT_RESOURCE_ISP_IFACE_INDEX : +case PLAT_RESOURCE_GTD_DATA_INDEX : +case PLAT_RESOURCE_GTD_IFACE_INDEX : +/* if valid resource found, copy the resource to PUNIT +* resource +*/ +if (res) +memcpy (&punit_res[pindex], res,sizeof (*res)); + punit_res[pindex].flags =IORESOURCE_MEM ; +dev_dbg (&pdev->dev,"PUNIT memory res: %pR\n" , + &punit_res[pindex]); + pindex++; +break ; }; + } - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.punit_dev = pdev; +/* Create PUNIT IPC MFD cell */ + punit_cell.name =PUNIT_DEVICE_NAME ; + punit_cell.num_resources =ARRAY_SIZE (punit_res); + punit_cell.resources = punit_res; + punit_cell.ignore_resource_conflicts =1 ; -return 0 ; +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , + &punit_cell,1 ,NULL ,0 ,NULL ); } -static int ipc_create_tco_device (void ) +static int ipc_create_wdt_device (struct platform_device *pdev) { -struct platform_device *pdev; +static struct resource wdt_ipc_res[2 ];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), - }; +static struct mfd_cell wdt_cell; - res = tco_res +TCO_RESOURCE_ACPI_IO ; - res->start = ipcdev.acpi_io_base +TCO_BASE_OFFSET ; - res->end = res->start +TCO_REGS_SIZE -1 ; +/* If we have ACPI based watchdog use that instead, othewise create +* a MFD cell for iTCO watchdog +*/ +if (acpi_has_watchdog ()) +return 0 ; - 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 ; +/* Get iTCO watchdog resources */ + res =platform_get_resource (pdev,IORESOURCE_IO , +PLAT_RESOURCE_ACPI_IO_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get WDT resource\n" ); +return -ENXIO ; + } - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); + wdt_ipc_res[0 ].start = res->start +TCO_BASE_OFFSET ; + wdt_ipc_res[0 ].end = res->start + +TCO_BASE_OFFSET +TCO_REGS_SIZE -1 ; + wdt_ipc_res[0 ].flags =IORESOURCE_IO ; + wdt_ipc_res[1 ].start = res->start +SMI_EN_OFFSET ; + wdt_ipc_res[1 ].end = res->start + +SMI_EN_OFFSET +SMI_EN_SIZE -1 ; + wdt_ipc_res[1 ].flags =IORESOURCE_IO ; - ipcdev.tco_dev = pdev; +dev_dbg (&pdev->dev,"watchdog res 0: %pR\n" , &wdt_ipc_res[0 ]); +dev_dbg (&pdev->dev,"watchdog res 1: %pR\n" , &wdt_ipc_res[1 ]); -return 0 ; + wdt_cell.name =TCO_DEVICE_NAME ; + wdt_cell.platform_data = &tco_info; + wdt_cell.pdata_size =sizeof (tco_info); + wdt_cell.num_resources =ARRAY_SIZE (wdt_ipc_res); + wdt_cell.resources = wdt_ipc_res; + wdt_cell.ignore_resource_conflicts =1 ; + +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , + &wdt_cell,1 ,NULL ,0 ,NULL ); } -static int ipc_create_telemetry_device (void ) +static int ipc_create_telemetry_device (struct platform_device *pdev) { -struct platform_device *pdev; +struct resource telemetry_ipc_res[2 ]; +struct mfd_cell telemetry_cell;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 ; +/* Get telemetry resources */ + res =platform_get_resource (pdev,IORESOURCE_MEM , +PLAT_RESOURCE_TELEM_SSRAM_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get telemetry resource\n" ); +return -ENXIO ; + } - res = telemetry_res +TELEMETRY_RESOURCE_PMC_SSRAM ; - res->start = ipcdev.telem_pmc_ssram_base; - res->end = res->start + ipcdev.telem_pmc_ssram_size -1 ; + telemetry_ipc_res[0 ].start = res->start +TELEM_PUNIT_SSRAM_OFFSET ; + telemetry_ipc_res[0 ].end = res->start + +TELEM_PUNIT_SSRAM_OFFSET +TELEM_SSRAM_SIZE -1 ; + telemetry_ipc_res[0 ].flags =IORESOURCE_MEM ; + telemetry_ipc_res[1 ].start = res->start +TELEM_PMC_SSRAM_OFFSET ; + telemetry_ipc_res[1 ].end = res->start + +TELEM_PMC_SSRAM_OFFSET +TELEM_SSRAM_SIZE -1 ; + telemetry_ipc_res[1 ].flags =IORESOURCE_MEM ; - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +dev_dbg (&pdev->dev,"Telemetry res 0: %pR\n" , &telemetry_ipc_res[0 ]); +dev_dbg (&pdev->dev,"Telemetry res 1: %pR\n" , &telemetry_ipc_res[1 ]); - ipcdev.telemetry_dev = pdev; + telemetry_cell.name =TELEMETRY_DEVICE_NAME ; + telemetry_cell.num_resources =ARRAY_SIZE (telemetry_ipc_res); + telemetry_cell.resources = telemetry_ipc_res; + telemetry_cell.ignore_resource_conflicts =1 ; -return 0 ; +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , + &telemetry_cell,1 ,NULL ,0 ,NULL ); } -static int ipc_create_pmc_devices (void ) +static int ipc_create_pmc_devices (struct platform_device *pdev) {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 (pdev); +if (ret <0 ) +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); - } + ret =ipc_create_wdt_device (pdev); +if (ret <0 ) +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" ); - } + ret =ipc_create_telemetry_device (pdev); +if (ret <0 ) +return ret; -return ret; +return 0 ; }static int ipc_plat_get_res (struct platform_device *pdev) { -struct resource *res, *punit_res; +struct resource *res;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); - - punit_res = punit_res_array; -/* 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 = *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 = *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 ); - ++punit_res; -if (res) { - *punit_res = *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 ); - ++punit_res; -if (res) { - *punit_res = *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 ); - ++punit_res; -if (res) { - *punit_res = *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 ); - ++punit_res; -if (res) { - *punit_res = *res; -dev_info (&pdev->dev,"punit GTD interface res: %pR\n" , res); - } +/* Get IPC resources */ res =platform_get_resource (pdev,IORESOURCE_MEM ,PLAT_RESOURCE_IPC_INDEX );if (!res) { -dev_err (&pdev->dev,"Failed to get ipc resource\n" ); +dev_err (&pdev->dev,"Failed to get IPC resources\n" );return -ENXIO ; } - size =PLAT_RESOURCE_IPC_SIZE +PLAT_RESOURCE_GCR_SIZE ; - res->end = res->start + size -1 ; + + res->end = res->start + +PLAT_RESOURCE_IPC_SIZE +PLAT_RESOURCE_GCR_SIZE -1 ; addr =devm_ioremap_resource (&pdev->dev, res);if (IS_ERR (addr))return PTR_ERR (addr); ipcdev.ipc_base = addr; - ipcdev.gcr_mem_base = addr +PLAT_RESOURCE_GCR_OFFSET ; -dev_info (&pdev->dev,"ipc res: %pR\n" , res); - - 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); - } +dev_dbg (&pdev->dev,"PMC IPC resource %pR\n" , res);return 0 ; }
@@ -911,7 +800,7 @@ static int ipc_plat_probe(struct platform_device *pdev) ipcdev.irq =platform_get_irq (pdev,0 );if (ipcdev.irq <0 ) { -dev_err (&pdev->dev,"Failed to get irq\n" ); +dev_err (&pdev->dev,"Failed to get IRQ\n" );return -EINVAL ; }
@@ -921,47 +810,38 @@ static int ipc_plat_probe(struct platform_device *pdev)return ret; } - ret =ipc_create_pmc_devices (); + ret =ipc_create_pmc_devices (pdev);if (ret) { -dev_err (&pdev->dev,"Failed to create pmc devices\n" ); +dev_err (&pdev->dev,"Failed to create PMC devices\n" );return ret; } -if (devm_request_irq (&pdev->dev, ipcdev.irq, ioc,IRQF_NO_SUSPEND , -"intel_pmc_ipc" , &ipcdev)) { -dev_err (&pdev->dev,"Failed to request irq\n" ); - ret = -EBUSY ; - goto err_irq; + ret =devm_request_irq (&pdev->dev, ipcdev.irq, ioc,IRQF_NO_SUSPEND , +"intel_pmc_ipc" , &ipcdev); +if (ret) { +dev_err (&pdev->dev,"Failed to request IRQ\n" ); +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_sys; +devm_free_irq (&pdev->dev, ipcdev.irq, &ipcdev); +return ret; } ipcdev.has_gcr_regs = true;return 0 ; -err_sys: -devm_free_irq (&pdev->dev, ipcdev.irq, &ipcdev); -err_irq: -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);devm_free_irq (&pdev->dev, ipcdev.irq, &ipcdev); -platform_device_unregister (ipcdev.tco_dev); -platform_device_unregister (ipcdev.punit_dev); -platform_device_unregister (ipcdev.telemetry_dev); ipcdev.dev =NULL ; +return 0 ; }
@@ -980,12 +860,12 @@ static int __init intel_pmc_ipc_init(void) ret =platform_driver_register (&ipc_plat_driver);if (ret) { -pr_err ("Failed to register PMC ipc platform driver\n" ); +pr_err ("Failed to register PMC IPC platform driver\n" );return ret; } ret =pci_register_driver (&ipc_pci_driver);if (ret) { -pr_err ("Failed to register PMC ipc pci driver\n" ); +pr_err ("Failed to register PMC IPC PCI driver\n" );platform_driver_unregister (&ipc_plat_driver);return ret; }
Signature · 1 line
2.7.4
Re: [RFC v8 2/7] platform/x86: intel_pmc_ipc: Use MFD framework to create dependent devices
Hi,
Quoted 160 lines · On Sun, Oct 29, 2017 at 02:49:55AM -0700…
From: Kuppuswamy Sathyanarayanan <[email protected]>
Currently, we have lot of repetitive code in dependent device resource allocation and device creation handling code. This logic can be improved if we use MFD framework for dependent device creation. This patch adds this support.
Signed-off-by Kuppuswamy Sathyanarayanan <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/platform/x86/intel_pmc_ipc.c | 398 ++++++++++++----------------------- 1 file changed, 139 insertions(+), 259 deletions(-)Changes since v7:
* Fixed style issues.Changes since v6:
* Fixed style issues.
* Used Andy's modified version.Changes since v5:
* Changed the order of patches in this patchlist.Changes since v4:
* Changed the order of patches in this patchlist.Changes since v3:
* ChangedPLATFORM_DEVID_AUTOtoPLATFORM_DEVID_NONEin mfd device creation.
* Fixed error in resource initalization logic inipc_create_punit_device.
* Removed mfd cell id initialization.drivers/platform/x86/intel_pmc_ipc.c +4
-70@@ -20,6 +20,7 @@#include <linux/errno.h> #include <linux/init.h> #include <linux/device.h> +#include <linux/mfd/core.h> #include <linux/pm.h> #include <linux/pci.h> #include <linux/platform_device.h> @@ -88,6 +89,7 @@#define PLAT_RESOURCE_ISP_IFACE_INDEX 5#define PLAT_RESOURCE_GTD_DATA_INDEX 6#define PLAT_RESOURCE_GTD_IFACE_INDEX 7 +#define PLAT_RESOURCE_MEM_MAX_INDEX 8#define PLAT_RESOURCE_ACPI_IO_INDEX 0/* @@ -106,8 +108,6 @@#define TELEM_SSRAM_SIZE 240#define TELEM_PMC_SSRAM_OFFSET 0x1B00#define TELEM_PUNIT_SSRAM_OFFSET 0x1A00 -#define TCO_PMC_OFFSET 0x8 -#define TCO_PMC_SIZE 0x4/* PMC register bit definitions */ @@ -124,26 +124,10 @@ static struct intel_pmc_ipc_dev {int cmd;struct completion cmd_complete; -/* 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; - -/* 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 char *ipc_err_sources[] = {@@ -508,7 +492,7 @@ static int ipc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) ret =devm_request_irq (&pdev->dev, pdev->irq, ioc,0 ,"intel_pmc_ipc" , pmc);if (ret) { -dev_err (&pdev->dev,"Failed to request irq\n" ); +dev_err (&pdev->dev,"Failed to request IRQ\n" );return ret; }@@ -593,44 +577,6 @@ static const struct attribute_group intel_ipc_group = { .attrs = intel_ipc_attrs, }; -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 ,@@ -638,234 +584,177 @@ static struct itco_wdt_platform_data tco_info = { .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 ) +static int ipc_create_punit_device (struct platform_device *pdev) {
drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 591
Quoted 10 lines
drivers/platform/x86/intel_pmc_ipc.c +3
-7-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 =ARRAY_SIZE (punit_res_array), +struct resource punit_res[PLAT_RESOURCE_MEM_MAX_INDEX ]; +struct mfd_cell punit_cell; +struct resource *res;
That's where you have the bug I reported earlier. You would need to introduce those structures as static struct..
But instead of fixing those, drop them and introduce the resources and the cells out side of these functions:
static struct resource punit_resources[PLAT_RESOURCE_MEM_MAX_INDEX]; static struct resource telemetry_resources[2];
static struct resource wdt_resources[2];
static struct mfd_cell pmc_cell[] = {
{
.name = "intel_punit_ipc", .resources = punit_resources, .num_resources = PLAT_RESOURCE_MEM_MAX_INDEX, .ignore_resource_conflicts = true,
},
{
.name = "intel_telemetry", .resources = telemetry_resources, .num_resources = 2, .ignore_resource_conflicts = true,
},
{
.name = "iTCO_wdt",
.resources = wdt_resources, .num_resources = 2, .ignore_resource_conflicts = true, .platform_data = &tco_info, .pdata_size = sizeof(tco_info),
},
};
Note that I'm not using the definitions for the name strings on purpose. Please get rid of those definitions while at it.
Use these functions - ipc_create_punit/wdt/telemetry_device() - to just collect the resources. Then you call devm_mfd_add_devices() only ones in ipc_create_pmc_devices(). That should make this driver a bit more easier to read and understand.
Quoted 21 lines
drivers/platform/x86/intel_pmc_ipc.c +21
-0+int mindex, pindex =0 ; + +for (mindex =0 ; mindex <=PLAT_RESOURCE_MEM_MAX_INDEX ; mindex++) { + + res =platform_get_resource (pdev,IORESOURCE_MEM , mindex); + +switch (mindex) { +/* Get PUNIT resources */ +case PLAT_RESOURCE_BIOS_DATA_INDEX : +case PLAT_RESOURCE_BIOS_IFACE_INDEX : +/* BIOS resources are required, so return error if not +* available +*/ +if (!res) { +dev_err (&pdev->dev, +"Failed to get PUNIT MEM resource %d\n" , + pindex); +return -ENXIO ; + } +case PLAT_RESOURCE_ISP_DATA_INDEX : +case PLAT_RESOURCE_ISP_IFACE_INDEX :
drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 622
Quoted 10 lines
drivers/platform/x86/intel_pmc_ipc.c +10
-0+case PLAT_RESOURCE_GTD_DATA_INDEX : +case PLAT_RESOURCE_GTD_IFACE_INDEX : +/* if valid resource found, copy the resource to PUNIT +* resource +*/ +if (res) +memcpy (&punit_res[pindex], res,sizeof (*res)); + punit_res[pindex].flags =IORESOURCE_MEM ; +dev_dbg (&pdev->dev,"PUNIT memory res: %pR\n" , + &punit_res[pindex]);
I don't see how is that useful information?
Quoted 63 lines
drivers/platform/x86/intel_pmc_ipc.c +27
-26+ pindex++; +break ; }; + } - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.punit_dev = pdev; +/* Create PUNIT IPC MFD cell */ + punit_cell.name =PUNIT_DEVICE_NAME ; + punit_cell.num_resources =ARRAY_SIZE (punit_res); + punit_cell.resources = punit_res; + punit_cell.ignore_resource_conflicts =1 ; -return 0 ; +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , + &punit_cell,1 ,NULL ,0 ,NULL ); } -static int ipc_create_tco_device (void ) +static int ipc_create_wdt_device (struct platform_device *pdev) { -struct platform_device *pdev; +static struct resource wdt_ipc_res[2 ];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), - }; +static struct mfd_cell wdt_cell; - res = tco_res +TCO_RESOURCE_ACPI_IO ; - res->start = ipcdev.acpi_io_base +TCO_BASE_OFFSET ; - res->end = res->start +TCO_REGS_SIZE -1 ; +/* If we have ACPI based watchdog use that instead, othewise create +* a MFD cell for iTCO watchdog +*/ +if (acpi_has_watchdog ()) +return 0 ; - 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 ; +/* Get iTCO watchdog resources */ + res =platform_get_resource (pdev,IORESOURCE_IO , +PLAT_RESOURCE_ACPI_IO_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get WDT resource\n" ); +return -ENXIO ; + } - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); + wdt_ipc_res[0 ].start = res->start +TCO_BASE_OFFSET ; + wdt_ipc_res[0].end = res->start +
drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 668
Quoted 10 lines
drivers/platform/x86/intel_pmc_ipc.c +8
-1+TCO_BASE_OFFSET +TCO_REGS_SIZE -1 ; + wdt_ipc_res[0 ].flags =IORESOURCE_IO ; + wdt_ipc_res[1 ].start = res->start +SMI_EN_OFFSET ; + wdt_ipc_res[1 ].end = res->start + +SMI_EN_OFFSET +SMI_EN_SIZE -1 ; + wdt_ipc_res[1 ].flags =IORESOURCE_IO ; - ipcdev.tco_dev = pdev; +dev_dbg (&pdev->dev,"watchdog res 0: %pR\n" , &wdt_ipc_res[0 ]); +dev_dbg (&pdev->dev,"watchdog res 1: %pR\n" , &wdt_ipc_res[1 ]);
That definitely is not useful information. Please drop all dev_dbg calls from these patches.
Quoted 8 lines
drivers/platform/x86/intel_pmc_ipc.c +7
-1-return 0 ; + wdt_cell.name =TCO_DEVICE_NAME ; + wdt_cell.platform_data = &tco_info; + wdt_cell.pdata_size =sizeof (tco_info); + wdt_cell.num_resources =ARRAY_SIZE (wdt_ipc_res); + wdt_cell.resources = wdt_ipc_res; + wdt_cell.ignore_resource_conflicts =1 ; +
drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 683
Quoted 10 lines
drivers/platform/x86/intel_pmc_ipc.c +5
-2+return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , + &wdt_cell,1 ,NULL ,0 ,NULL ); } -static int ipc_create_telemetry_device (void ) +static int ipc_create_telemetry_device (struct platform_device *pdev) { -struct platform_device *pdev; +struct resource telemetry_ipc_res[2 ]; +struct mfd_cell telemetry_cell;
This is also broken. I'm attaching a diff with the changes to this patch I used when I tested this on my Broxton board.
Thanks,
Signature · 1 line
heikki
drivers/platform/x86/intel_pmc_ipc.c +57 -65
@@ -584,10 +584,35 @@ static struct itco_wdt_platform_data tco_info = { .update_no_reboot_bit = update_no_reboot_bit, }; -static int ipc_create_punit_device (struct platform_device *pdev) +static struct resource punit_resources[PLAT_RESOURCE_MEM_MAX_INDEX ]; +static struct resource telemetry_resources[2 ]; +static struct resource wdt_resources[2 ]; + +static struct mfd_cell pmc_cell[] = { + { + .name ="intel_punit_ipc" , + .resources = punit_resources, + .num_resources =PLAT_RESOURCE_MEM_MAX_INDEX , + .ignore_resource_conflicts = true, + }, + { + .name ="intel_telemetry" , + .resources = telemetry_resources, + .num_resources =2 , + .ignore_resource_conflicts = true, + }, + { + .name ="iTCO_wdt" , + .resources = wdt_resources, + .num_resources =2 , + .ignore_resource_conflicts = true, + .platform_data = &tco_info, + .pdata_size =sizeof (tco_info), + }, +}; + +static int ipc_get_punit_resources (struct platform_device *pdev) { -struct resource punit_res[PLAT_RESOURCE_MEM_MAX_INDEX ]; -struct mfd_cell punit_cell;struct resource *res;int mindex, pindex =0 ;
@@ -616,30 +641,20 @@ static int ipc_create_punit_device(struct platform_device *pdev)* resource */ if (res) -memcpy (&punit_res[pindex], res,sizeof (*res)); - punit_res[pindex].flags =IORESOURCE_MEM ; -dev_dbg (&pdev->dev,"PUNIT memory res: %pR\n" , - &punit_res[pindex]); +memcpy (&punit_resources[pindex], res, +sizeof (*res)); + punit_resources[pindex].flags =IORESOURCE_MEM ; pindex++;break ; }; } -/* Create PUNIT IPC MFD cell */ - punit_cell.name =PUNIT_DEVICE_NAME ; - punit_cell.num_resources =ARRAY_SIZE (punit_res); - punit_cell.resources = punit_res; - punit_cell.ignore_resource_conflicts =1 ; - -return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , - &punit_cell,1 ,NULL ,0 ,NULL ); +return 0 ; } -static int ipc_create_wdt_device (struct platform_device *pdev) +static int ipc_get_wdt_resources (struct platform_device *pdev) { -static struct resource wdt_ipc_res[2 ];struct resource *res; -static struct mfd_cell wdt_cell;/* If we have ACPI based watchdog use that instead, othewise create * a MFD cell for iTCO watchdog
@@ -655,33 +670,18 @@ static int ipc_create_wdt_device(struct platform_device *pdev)return -ENXIO ; } - wdt_ipc_res[0 ].start = res->start +TCO_BASE_OFFSET ; - wdt_ipc_res[0 ].end = res->start + -TCO_BASE_OFFSET +TCO_REGS_SIZE -1 ; - wdt_ipc_res[0 ].flags =IORESOURCE_IO ; - wdt_ipc_res[1 ].start = res->start +SMI_EN_OFFSET ; - wdt_ipc_res[1 ].end = res->start + -SMI_EN_OFFSET +SMI_EN_SIZE -1 ; - wdt_ipc_res[1 ].flags =IORESOURCE_IO ; - -dev_dbg (&pdev->dev,"watchdog res 0: %pR\n" , &wdt_ipc_res[0 ]); -dev_dbg (&pdev->dev,"watchdog res 1: %pR\n" , &wdt_ipc_res[1 ]); - - wdt_cell.name =TCO_DEVICE_NAME ; - wdt_cell.platform_data = &tco_info; - wdt_cell.pdata_size =sizeof (tco_info); - wdt_cell.num_resources =ARRAY_SIZE (wdt_ipc_res); - wdt_cell.resources = wdt_ipc_res; - wdt_cell.ignore_resource_conflicts =1 ; - -return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , - &wdt_cell,1 ,NULL ,0 ,NULL ); + wdt_resources[0 ].start = res->start +TCO_BASE_OFFSET ; + wdt_resources[0 ].end = res->start +TCO_BASE_OFFSET +TCO_REGS_SIZE -1 ; + wdt_resources[0 ].flags =IORESOURCE_IO ; + wdt_resources[1 ].start = res->start +SMI_EN_OFFSET ; + wdt_resources[1 ].end = res->start +SMI_EN_OFFSET +SMI_EN_SIZE -1 ; + wdt_resources[1 ].flags =IORESOURCE_IO ; + +return 0 ; } -static int ipc_create_telemetry_device (struct platform_device *pdev) +static int ipc_get_telemetry_resources (struct platform_device *pdev) { -struct resource telemetry_ipc_res[2 ]; -struct mfd_cell telemetry_cell;struct resource *res;/* Get telemetry resources */
@@ -692,44 +692,36 @@ static int ipc_create_telemetry_device(struct platform_device *pdev)return -ENXIO ; } - telemetry_ipc_res[0 ].start = res->start +TELEM_PUNIT_SSRAM_OFFSET ; - telemetry_ipc_res[0 ].end = res->start + -TELEM_PUNIT_SSRAM_OFFSET +TELEM_SSRAM_SIZE -1 ; - telemetry_ipc_res[0 ].flags =IORESOURCE_MEM ; - telemetry_ipc_res[1 ].start = res->start +TELEM_PMC_SSRAM_OFFSET ; - telemetry_ipc_res[1 ].end = res->start + -TELEM_PMC_SSRAM_OFFSET +TELEM_SSRAM_SIZE -1 ; - telemetry_ipc_res[1 ].flags =IORESOURCE_MEM ; - -dev_dbg (&pdev->dev,"Telemetry res 0: %pR\n" , &telemetry_ipc_res[0 ]); -dev_dbg (&pdev->dev,"Telemetry res 1: %pR\n" , &telemetry_ipc_res[1 ]); - - telemetry_cell.name =TELEMETRY_DEVICE_NAME ; - telemetry_cell.num_resources =ARRAY_SIZE (telemetry_ipc_res); - telemetry_cell.resources = telemetry_ipc_res; - telemetry_cell.ignore_resource_conflicts =1 ; - -return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , - &telemetry_cell,1 ,NULL ,0 ,NULL ); + telemetry_resources[0 ].start = res->start +TELEM_PUNIT_SSRAM_OFFSET ; + telemetry_resources[0 ].end = res->start +TELEM_PUNIT_SSRAM_OFFSET + +TELEM_SSRAM_SIZE -1 ; + telemetry_resources[0 ].flags =IORESOURCE_MEM ; + telemetry_resources[1 ].start = res->start +TELEM_PMC_SSRAM_OFFSET ; + telemetry_resources[1 ].end = res->start +TELEM_PMC_SSRAM_OFFSET + +TELEM_SSRAM_SIZE -1 ; + telemetry_resources[1 ].flags =IORESOURCE_MEM ; + +return 0 ; }static int ipc_create_pmc_devices (struct platform_device *pdev) {int ret; - ret =ipc_create_punit_device (pdev); + ret =ipc_get_wdt_resources (pdev);if (ret <0 )return ret; - ret =ipc_create_wdt_device (pdev); + ret =ipc_get_punit_resources (pdev);if (ret <0 )return ret; - ret =ipc_create_telemetry_device (pdev); + ret =ipc_get_telemetry_resources (pdev);if (ret <0 )return ret; -return 0 ; +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , pmc_cell, +ARRAY_SIZE (pmc_cell),NULL ,0 ,NULL ); }static int ipc_plat_get_res (struct platform_device *pdev)
Guenter Roeck
maintainerRe: [RFC v8 2/7] platform/x86: intel_pmc_ipc: Use MFD framework to create dependent devices
Quoted 326 lines · Heikki Krogerus
Hi,
Quoted 160 lines · On Sun, Oct 29, 2017 at 02:49:55AM -0700…
From: Kuppuswamy Sathyanarayanan <[email protected]>
Currently, we have lot of repetitive code in dependent device resource allocation and device creation handling code. This logic can be improved if we use MFD framework for dependent device creation. This patch adds this support.
Signed-off-by Kuppuswamy Sathyanarayanan <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/platform/x86/intel_pmc_ipc.c | 398 ++++++++++++----------------------- 1 file changed, 139 insertions(+), 259 deletions(-)Changes since v7:
* Fixed style issues.Changes since v6:
* Fixed style issues.
* Used Andy's modified version.Changes since v5:
* Changed the order of patches in this patchlist.Changes since v4:
* Changed the order of patches in this patchlist.Changes since v3:
* ChangedPLATFORM_DEVID_AUTOtoPLATFORM_DEVID_NONEin mfd device creation.
* Fixed error in resource initalization logic inipc_create_punit_device.
* Removed mfd cell id initialization.drivers/platform/x86/intel_pmc_ipc.c +4
-70@@ -20,6 +20,7 @@#include <linux/errno.h> #include <linux/init.h> #include <linux/device.h> +#include <linux/mfd/core.h> #include <linux/pm.h> #include <linux/pci.h> #include <linux/platform_device.h> @@ -88,6 +89,7 @@#define PLAT_RESOURCE_ISP_IFACE_INDEX 5#define PLAT_RESOURCE_GTD_DATA_INDEX 6#define PLAT_RESOURCE_GTD_IFACE_INDEX 7 +#define PLAT_RESOURCE_MEM_MAX_INDEX 8#define PLAT_RESOURCE_ACPI_IO_INDEX 0/* @@ -106,8 +108,6 @@#define TELEM_SSRAM_SIZE 240#define TELEM_PMC_SSRAM_OFFSET 0x1B00#define TELEM_PUNIT_SSRAM_OFFSET 0x1A00 -#define TCO_PMC_OFFSET 0x8 -#define TCO_PMC_SIZE 0x4/* PMC register bit definitions */ @@ -124,26 +124,10 @@ static struct intel_pmc_ipc_dev {int cmd;struct completion cmd_complete; -/* 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; - -/* 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 char *ipc_err_sources[] = {@@ -508,7 +492,7 @@ static int ipc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) ret =devm_request_irq (&pdev->dev, pdev->irq, ioc,0 ,"intel_pmc_ipc" , pmc);if (ret) { -dev_err (&pdev->dev,"Failed to request irq\n" ); +dev_err (&pdev->dev,"Failed to request IRQ\n" );return ret; }@@ -593,44 +577,6 @@ static const struct attribute_group intel_ipc_group = { .attrs = intel_ipc_attrs, }; -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 ,@@ -638,234 +584,177 @@ static struct itco_wdt_platform_data tco_info = { .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 ) +static int ipc_create_punit_device (struct platform_device *pdev) {drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 591
Quoted 10 lines
drivers/platform/x86/intel_pmc_ipc.c +3
-7-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 =ARRAY_SIZE (punit_res_array), +struct resource punit_res[PLAT_RESOURCE_MEM_MAX_INDEX ]; +struct mfd_cell punit_cell; +struct resource *res;That's where you have the bug I reported earlier. You would need to introduce those structures as static struct..
But instead of fixing those, drop them and introduce the resources and the cells out side of these functions:
static struct resource punit_resources[PLAT_RESOURCE_MEM_MAX_INDEX]; static struct resource telemetry_resources[2];
static struct resource wdt_resources[2];static struct
mfd_cellpmc_cell[] = {
{
.name = "intel_punit_ipc", .resources =punit_resources, .num_resources =PLAT_RESOURCE_MEM_MAX_INDEX, .ignore_resource_conflicts = true,
},
{
.name = "intel_telemetry", .resources =telemetry_resources, .num_resources = 2, .ignore_resource_conflicts = true,
},
{
.name = "iTCO_wdt",
.resources =wdt_resources, .num_resources = 2, .ignore_resource_conflicts = true, .platform_data =&tco_info, .pdata_size =sizeof(tco_info),
},
};Note that I'm not using the definitions for the name strings on purpose. Please get rid of those definitions while at it.
Use these functions - ipc_create_punit/wdt/telemetry_device() - to just collect the resources. Then you call
devm_mfd_add_devices()only ones inipc_create_pmc_devices(). That should make this driver a bit more easier to read and understand.Quoted 21 lines
drivers/platform/x86/intel_pmc_ipc.c +21
-0+int mindex, pindex =0 ; + +for (mindex =0 ; mindex <=PLAT_RESOURCE_MEM_MAX_INDEX ; mindex++) { + + res =platform_get_resource (pdev,IORESOURCE_MEM , mindex); + +switch (mindex) { +/* Get PUNIT resources */ +case PLAT_RESOURCE_BIOS_DATA_INDEX : +case PLAT_RESOURCE_BIOS_IFACE_INDEX : +/* BIOS resources are required, so return error if not +* available +*/ +if (!res) { +dev_err (&pdev->dev, +"Failed to get PUNIT MEM resource %d\n" , + pindex); +return -ENXIO ; + } +case PLAT_RESOURCE_ISP_DATA_INDEX : +case PLAT_RESOURCE_ISP_IFACE_INDEX :drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 622
Quoted 10 lines
drivers/platform/x86/intel_pmc_ipc.c +10
-0+case PLAT_RESOURCE_GTD_DATA_INDEX : +case PLAT_RESOURCE_GTD_IFACE_INDEX : +/* if valid resource found, copy the resource to PUNIT +* resource +*/ +if (res) +memcpy (&punit_res[pindex], res,sizeof (*res)); + punit_res[pindex].flags =IORESOURCE_MEM ; +dev_dbg (&pdev->dev,"PUNIT memory res: %pR\n" , + &punit_res[pindex]);I don't see how is that useful information?
Quoted 63 lines
drivers/platform/x86/intel_pmc_ipc.c +27
-26+ pindex++; +break ; }; + } - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.punit_dev = pdev; +/* Create PUNIT IPC MFD cell */ + punit_cell.name =PUNIT_DEVICE_NAME ; + punit_cell.num_resources =ARRAY_SIZE (punit_res); + punit_cell.resources = punit_res; + punit_cell.ignore_resource_conflicts =1 ; -return 0 ; +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , + &punit_cell,1 ,NULL ,0 ,NULL ); } -static int ipc_create_tco_device (void ) +static int ipc_create_wdt_device (struct platform_device *pdev) { -struct platform_device *pdev; +static struct resource wdt_ipc_res[2 ];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), - }; +static struct mfd_cell wdt_cell; - res = tco_res +TCO_RESOURCE_ACPI_IO ; - res->start = ipcdev.acpi_io_base +TCO_BASE_OFFSET ; - res->end = res->start +TCO_REGS_SIZE -1 ; +/* If we have ACPI based watchdog use that instead, othewise create +* a MFD cell for iTCO watchdog +*/ +if (acpi_has_watchdog ()) +return 0 ; - 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 ; +/* Get iTCO watchdog resources */ + res =platform_get_resource (pdev,IORESOURCE_IO , +PLAT_RESOURCE_ACPI_IO_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get WDT resource\n" ); +return -ENXIO ; + } - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); + wdt_ipc_res[0 ].start = res->start +TCO_BASE_OFFSET ; + wdt_ipc_res[0].end = res->start +drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 668
Quoted 10 lines
drivers/platform/x86/intel_pmc_ipc.c +8
-1+TCO_BASE_OFFSET +TCO_REGS_SIZE -1 ; + wdt_ipc_res[0 ].flags =IORESOURCE_IO ; + wdt_ipc_res[1 ].start = res->start +SMI_EN_OFFSET ; + wdt_ipc_res[1 ].end = res->start + +SMI_EN_OFFSET +SMI_EN_SIZE -1 ; + wdt_ipc_res[1 ].flags =IORESOURCE_IO ; - ipcdev.tco_dev = pdev; +dev_dbg (&pdev->dev,"watchdog res 0: %pR\n" , &wdt_ipc_res[0 ]); +dev_dbg (&pdev->dev,"watchdog res 1: %pR\n" , &wdt_ipc_res[1 ]);That definitely is not useful information. Please drop all
dev_dbgcalls from these patches.
Quoted 10 lines
drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 677
Quoted 10 lines
drivers/platform/x86/intel_pmc_ipc.c +9
-1-return 0 ; + wdt_cell.name =TCO_DEVICE_NAME ; + wdt_cell.platform_data = &tco_info; + wdt_cell.pdata_size =sizeof (tco_info); + wdt_cell.num_resources =ARRAY_SIZE (wdt_ipc_res); + wdt_cell.resources = wdt_ipc_res; + wdt_cell.ignore_resource_conflicts =1 ; + +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , + &wdt_cell,1 ,NULL ,0 ,NULL );
Whatever you do, don't tell the mfd maintainer that you are doing this. You are not supposed to call mfd functions from outside the mfd directory.
Guenter
Quoted 15 lines
drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 683
Quoted 8 lines
drivers/platform/x86/intel_pmc_ipc.c +3
-2} -static int ipc_create_telemetry_device (void ) +static int ipc_create_telemetry_device (struct platform_device *pdev) { -struct platform_device *pdev; +struct resource telemetry_ipc_res[2 ]; +struct mfd_cell telemetry_cell;This is also broken. I'm attaching a diff with the changes to this patch I used when I tested this on my Broxton board.
Thanks,
Re: [RFC v8 2/7] platform/x86: intel_pmc_ipc: Use MFD framework to create dependent devices
In reply to Heikki KrogerusHi Heikki,
Thanks for the review.
Quoted 167 lines · Heikki Krogerus
Hi,
Quoted 164 lines · On Sun, Oct 29, 2017 at 02:49:55AM -0700…
From: Kuppuswamy Sathyanarayanan <[email protected]>
Currently, we have lot of repetitive code in dependent device resource allocation and device creation handling code. This logic can be improved if we use MFD framework for dependent device creation. This patch adds this support.
Signed-off-by Kuppuswamy Sathyanarayanan <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/platform/x86/intel_pmc_ipc.c | 398 ++++++++++++----------------------- 1 file changed, 139 insertions(+), 259 deletions(-)Changes since v7:
* Fixed style issues.Changes since v6:
* Fixed style issues.
* Used Andy's modified version.Changes since v5:
* Changed the order of patches in this patchlist.Changes since v4:
* Changed the order of patches in this patchlist.Changes since v3:
* ChangedPLATFORM_DEVID_AUTOtoPLATFORM_DEVID_NONEin mfd device creation.
* Fixed error in resource initalization logic inipc_create_punit_device.
* Removed mfd cell id initialization.drivers/platform/x86/intel_pmc_ipc.c +4
-74@@ -20,6 +20,7 @@#include <linux/errno.h> #include <linux/init.h> #include <linux/device.h> +#include <linux/mfd/core.h> #include <linux/pm.h> #include <linux/pci.h> #include <linux/platform_device.h> @@ -88,6 +89,7 @@#define PLAT_RESOURCE_ISP_IFACE_INDEX 5#define PLAT_RESOURCE_GTD_DATA_INDEX 6#define PLAT_RESOURCE_GTD_IFACE_INDEX 7 +#define PLAT_RESOURCE_MEM_MAX_INDEX 8#define PLAT_RESOURCE_ACPI_IO_INDEX 0/* @@ -106,8 +108,6 @@#define TELEM_SSRAM_SIZE 240#define TELEM_PMC_SSRAM_OFFSET 0x1B00#define TELEM_PUNIT_SSRAM_OFFSET 0x1A00 -#define TCO_PMC_OFFSET 0x8 -#define TCO_PMC_SIZE 0x4/* PMC register bit definitions */ @@ -124,26 +124,10 @@ static struct intel_pmc_ipc_dev {int cmd;struct completion cmd_complete; -/* 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; - -/* 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 char *ipc_err_sources[] = {@@ -508,7 +492,7 @@ static int ipc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) ret =devm_request_irq (&pdev->dev, pdev->irq, ioc,0 ,"intel_pmc_ipc" , pmc);if (ret) { -dev_err (&pdev->dev,"Failed to request irq\n" ); +dev_err (&pdev->dev,"Failed to request IRQ\n" );return ret; }@@ -593,44 +577,6 @@ static const struct attribute_group intel_ipc_group = { .attrs = intel_ipc_attrs, }; -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 ,@@ -638,234 +584,177 @@ static struct itco_wdt_platform_data tco_info = { .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 ) +static int ipc_create_punit_device (struct platform_device *pdev) { -struct platform_device *pdev; -const struct platform_device_info pdevinfo = { - .parent = ipcdev.dev, - .name =PUNIT_DEVICE_NAME ,
Quoted 8 lines
drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 591
Quoted 6 lines
drivers/platform/x86/intel_pmc_ipc.c +3
-3- .id = -1, - .res = punit_res_array, - .num_res = ARRAY_SIZE(punit_res_array), +struct resource punit_res[PLAT_RESOURCE_MEM_MAX_INDEX ]; +struct mfd_cell punit_cell; +struct resource *res;That's where you have the bug I reported earlier. You would need to introduce those structures as static struct..
May be I missed the bug message. Can you please send me the link?
Quoted 31 lines
But instead of fixing those, drop them and introduce the resources and the cells out side of these functions:
static struct resource punit_resources[PLAT_RESOURCE_MEM_MAX_INDEX]; static struct resource telemetry_resources[2];
static struct resource wdt_resources[2];static struct
mfd_cellpmc_cell[] = {
{
.name = "intel_punit_ipc", .resources =punit_resources, .num_resources =PLAT_RESOURCE_MEM_MAX_INDEX, .ignore_resource_conflicts = true,
},
{
.name = "intel_telemetry", .resources =telemetry_resources, .num_resources = 2, .ignore_resource_conflicts = true,
},
{
.name = "iTCO_wdt",
.resources =wdt_resources, .num_resources = 2, .ignore_resource_conflicts = true, .platform_data =&tco_info, .pdata_size =sizeof(tco_info),
},
};
Quoted 5 lines
Note that I'm not using the definitions for the name strings on purpose. Please get rid of those definitions while at it.
Use these functions - ipc_create_punit/wdt/telemetry_device() - to just collect the resources. Then you call
devm_mfd_add_devices()only ones
There are certain cases where we should skip device enumeration for some of these devices. For example,
1. If we get any issues when extracting the resource information.
2. In case of itco_wdt, we should skip device creation if acpi driver handles the watchdog.
So using single array and creating all these devices in one shot is not feasible. Please let me know if I missed anything.
Quoted 27 lines
in
ipc_create_pmc_devices(). That should make this driver a bit more easier to read and understand..Quoted 24 lines
drivers/platform/x86/intel_pmc_ipc.c +24
-0+int mindex, pindex =0 ; + +for (mindex =0 ; mindex <=PLAT_RESOURCE_MEM_MAX_INDEX ; mindex++) { + + res =platform_get_resource (pdev,IORESOURCE_MEM , mindex); + +switch (mindex) { +/* Get PUNIT resources */ +case PLAT_RESOURCE_BIOS_DATA_INDEX : +case PLAT_RESOURCE_BIOS_IFACE_INDEX : +/* BIOS resources are required, so return error if not +* available +*/ +if (!res) { +dev_err (&pdev->dev, +"Failed to get PUNIT MEM resource %d\n" , + pindex); +return -ENXIO ; + } +case PLAT_RESOURCE_ISP_DATA_INDEX : +case PLAT_RESOURCE_ISP_IFACE_INDEX : +case PLAT_RESOURCE_GTD_DATA_INDEX : +case PLAT_RESOURCE_GTD_IFACE_INDEX : +/* if valid resource found, copy the resource to PUNIT
Quoted 8 lines
drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 622
Quoted 7 lines
drivers/platform/x86/intel_pmc_ipc.c +7
-0+* resource +*/ +if (res) +memcpy (&punit_res[pindex], res,sizeof (*res)); + punit_res[pindex].flags =IORESOURCE_MEM ; +dev_dbg (&pdev->dev,"PUNIT memory res: %pR\n" , + &punit_res[pindex]);I don't see how is that useful information?
ISP and GTD related resources are optional. So I added a debug message to know the details if these resources exist.
Quoted 71 lines
Quoted 71 lines
drivers/platform/x86/intel_pmc_ipc.c +33
-26+ pindex++; +break ; }; + } - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.punit_dev = pdev; +/* Create PUNIT IPC MFD cell */ + punit_cell.name =PUNIT_DEVICE_NAME ; + punit_cell.num_resources =ARRAY_SIZE (punit_res); + punit_cell.resources = punit_res; + punit_cell.ignore_resource_conflicts =1 ; -return 0 ; +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , + &punit_cell,1 ,NULL ,0 ,NULL ); } -static int ipc_create_tco_device (void ) +static int ipc_create_wdt_device (struct platform_device *pdev) { -struct platform_device *pdev; +static struct resource wdt_ipc_res[2 ];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), - }; +static struct mfd_cell wdt_cell; - res = tco_res +TCO_RESOURCE_ACPI_IO ; - res->start = ipcdev.acpi_io_base +TCO_BASE_OFFSET ; - res->end = res->start +TCO_REGS_SIZE -1 ; +/* If we have ACPI based watchdog use that instead, othewise create +* a MFD cell for iTCO watchdog +*/ +if (acpi_has_watchdog ()) +return 0 ; - 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 ; +/* Get iTCO watchdog resources */ + res =platform_get_resource (pdev,IORESOURCE_IO , +PLAT_RESOURCE_ACPI_IO_INDEX ); +if (!res) { +dev_err (&pdev->dev,"Failed to get WDT resource\n" ); +return -ENXIO ; + } - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); + wdt_ipc_res[0 ].start = res->start +TCO_BASE_OFFSET ; + wdt_ipc_res[0 ].end = res->start + +TCO_BASE_OFFSET +TCO_REGS_SIZE -1 ; + wdt_ipc_res[0 ].flags =IORESOURCE_IO ; + wdt_ipc_res[1 ].start = res->start +SMI_EN_OFFSET ; + wdt_ipc_res[1 ].end = res->start + +SMI_EN_OFFSET +SMI_EN_SIZE -1 ; + wdt_ipc_res[1 ].flags =IORESOURCE_IO ;
Quoted 5 lines
drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 668
Quoted 3 lines
drivers/platform/x86/intel_pmc_ipc.c +2
-1- ipcdev.tco_dev = pdev; +dev_dbg (&pdev->dev,"watchdog res 0: %pR\n" , &wdt_ipc_res[0 ]); +dev_dbg (&pdev->dev,"watchdog res 1: %pR\n" , &wdt_ipc_res[1 ]);That definitely is not useful information. Please drop all
dev_dbgcalls from these patches.
I can remove them.
Quoted 13 lines
Quoted 13 lines
drivers/platform/x86/intel_pmc_ipc.c +9
-1-return 0 ; + wdt_cell.name =TCO_DEVICE_NAME ; + wdt_cell.platform_data = &tco_info; + wdt_cell.pdata_size =sizeof (tco_info); + wdt_cell.num_resources =ARRAY_SIZE (wdt_ipc_res); + wdt_cell.resources = wdt_ipc_res; + wdt_cell.ignore_resource_conflicts =1 ; + +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_NONE , + &wdt_cell,1 ,NULL ,0 ,NULL ); }
Quoted 8 lines
drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 683
Quoted 6 lines
drivers/platform/x86/intel_pmc_ipc.c +3
-2-static int ipc_create_telemetry_device (void ) +static int ipc_create_telemetry_device (struct platform_device *pdev) { -struct platform_device *pdev; +struct resource telemetry_ipc_res[2 ]; +struct mfd_cell telemetry_cell;This is also broken. I'm attaching a diff with the changes to this patch I used when I tested this on my Broxton board.
Thanks let me go over it.
Quoted 4 lines
Thanks,
RFC v8 3/7 platform/x86: intel_pmc_ipc: Use regmap calls for GCR updates
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
This patch adds support for regmap based implementation for GCR read/write/update APIs.
--- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_pmc_ipc.c | 122 +++++++++++++---------------------- 2 files changed, 46 insertions(+), 77 deletions(-)
Changes since v7:
* Fixed style issues.
Changes since v6:
* None
Changes since v5:
* None
Changes since v4:
* None
drivers/platform/x86/Kconfig +1 -0
@@ -1054,6 +1054,7 @@ config PVPANIC config INTEL_PMC_IPC tristate "Intel PMC IPC Driver" depends on ACPI + select REGMAP_MMIO ---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 +45 -77
207 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC v8 3/7] platform/x86: intel_pmc_ipc: Use regmap calls for GCR updates
Quoted 40 lines · On Sun, Oct 29, 2017 at 02:49:56AM -0700…
From: Kuppuswamy Sathyanarayanan <[email protected]>
This patch adds support for regmap based implementation for GCR read/write/update APIs.
Signed-off-by Kuppuswamy Sathyanarayanan <[email protected]>--- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_pmc_ipc.c | 122 +++++++++++++---------------------- 2 files changed, 46 insertions(+), 77 deletions(-)Changes since v7:
* Fixed style issues.Changes since v6:
* NoneChanges since v5:
* NoneChanges since v4:
* Nonedrivers/platform/x86/Kconfig +1
-0@@ -1054,6 +1054,7 @@ config PVPANIC config INTEL_PMC_IPC tristate "Intel PMC IPC Driver" depends on ACPI + select REGMAP_MMIO ---help--- This driver provides support for PMC control on some Intel platforms. The PMC is an ARC processor which defines IPC commands for communicationdrivers/platform/x86/intel_pmc_ipc.c +0
-0
drivers/platform/x86/intel_pmc_ipc.c line 38
Quoted 4 lines
drivers/platform/x86/intel_pmc_ipc.c +1
-0@@ -35,6 +35,8 @@#include <linux/acpi.h> #include <linux/io-64-nonatomic-lo-hi.h> #include <linux/spinlock.h> +#include <linux/mfd/core.h>
You already included that in the previous patch.
Thanks,
Signature · 1 line
heikki
RFC v8 4/7 platform: x86: Add generic Intel IPC driver
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
Currently intel_scu_ipc.c, intel_pmc_ipc.c and intel_punit_ipc.c redundantly implements the same IPC features and has lot of code duplication between them. This driver addresses this issue by grouping the common IPC functionalities under the same driver.
--- MAINTAINERS | 7 + drivers/platform/x86/Kconfig | 8 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_ipc_dev.c | 563 ++++++++++++++++++++++++ include/linux/platform_data/x86/intel_ipc_dev.h | 246 +++++++++++ 5 files changed, 825 insertions(+) create mode 100644 drivers/platform/x86/intel_ipc_dev.c create mode 100644 include/linux/platform_data/x86/intel_ipc_dev.h
Changes since v7:
* Fixed style issues.
* Added MAINTAINER info.
Changes since v6:
* None
Changes since v5:
* Added structures to group intel_ipc_cmd() intel_ipc_raw_cmd() arguments.
Changes since v4:
* None
Changes since v3:
* Fixed NULL pointer exception in intel_ipc_dev_get().
* Fixed error in check for duplicate intel_ipc_dev.
* Added custom interrupt handler support.
* Used char array for error string conversion.
* Added put dev support.
* Added devm_* variant of intel_ipc_dev_get().
Changes since v2:
* Added ipc_dev_cmd API support.
MAINTAINERS +7 -0
@@ -6970,6 +6970,13 @@ R: Dan Williams <[email protected]> S: Odd fixes F: drivers/dma/iop-adma.c +INTEL IPC CORE DRIVER +M: Kuppuswamy Sathyanarayanan <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/intel_ipc_dev.c +F: include/linux/platform_data/x86/intel_ipc_dev.h + INTEL IXP4XX QMGR, NPE, ETHERNET and HSS SUPPORT M: Krzysztof Halasa <[email protected]> S: Maintained
drivers/platform/x86/Kconfig +8 -0
@@ -1140,6 +1140,14 @@ config SILEAD_DMI with the OS-image for the device. This option supplies the missing information. Enable this for x86 tablets with Silead touchscreens. +config INTEL_IPC_DEV + bool "Intel IPC Device Driver" + depends on X86_64 + ---help--- + This driver implements core features of Intel IPC device. Devices + like PMC, SCU, PUNIT, etc can use interfaces provided by this + driver to implement IPC protocol of their respective device. + endif # X86_PLATFORM_DEVICES config PMC_ATOM
drivers/platform/x86/Makefile +1 -0
@@ -83,3 +83,4 @@ obj-$(CONFIG_PMC_ATOM) += pmc_atom.o obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o obj-$(CONFIG_MLX_CPLD_PLATFORM) += mlxcpld-hotplug.o obj-$(CONFIG_INTEL_TURBO_MAX_3) += intel_turbo_max_3.o +obj-$(CONFIG_INTEL_IPC_DEV) += intel_ipc_dev.o
drivers/platform/x86/intel_ipc_dev.c new file +563 -0
563 lines not on this page · raw message
include/linux/platform_data/x86/intel_ipc_dev.h new file +246 -0
246 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC v8 4/7] platform: x86: Add generic Intel IPC driver
Hi,
Quoted 61 lines · On Sun, Oct 29, 2017 at 02:49:57AM -0700…
drivers/platform/x86/intel_ipc_dev.c new file +61
-0+/** +* devm_intel_ipc_dev_create() - Create IPC device +* @dev : IPC parent device. +* @devname : Name of the IPC device. +* @cfg : IPC device configuration. +* @ops : IPC device ops. +* +* Resource managed API to create IPC device with +* given configuration. +* +* Return : IPC device pointer or ERR_PTR(error code). +*/ +struct intel_ipc_dev *devm_intel_ipc_dev_create (struct device *dev, +const char *devname, +struct intel_ipc_dev_cfg *cfg, +struct intel_ipc_dev_ops *ops) +{ +struct intel_ipc_dev **ptr, *ipc_dev; +int ret; + +if (!dev && !devname && !cfg) +return ERR_PTR (-EINVAL ); + +if (intel_ipc_dev_get (devname)) { +dev_err (dev,"IPC device %s already exist\n" , devname); +return ERR_PTR (-EINVAL ); + } + + ptr =devres_alloc (devm_intel_ipc_dev_release,sizeof (*ptr), +GFP_KERNEL ); +if (!ptr) +return ERR_PTR (-ENOMEM ); + + ipc_dev =kzalloc (sizeof (*ipc_dev),GFP_KERNEL ); +if (!ipc_dev) { + ret = -ENOMEM ; + goto err_dev_create; + } + + ipc_dev->dev.class = &intel_ipc_class; + ipc_dev->dev.parent = dev; + ipc_dev->dev.groups = ipc_dev_groups; + ipc_dev->cfg = cfg; + ipc_dev->ops = ops; + +mutex_init (&ipc_dev->lock); +init_completion (&ipc_dev->cmd_complete); +dev_set_drvdata (&ipc_dev->dev, ipc_dev); +dev_set_name (&ipc_dev->dev, devname); +device_initialize (&ipc_dev->dev); + + ret =device_add (&ipc_dev->dev); +if (ret <0 ) { +dev_err (&ipc_dev->dev,"%s device create failed\n" , + __func__); + ret = -ENODEV ; + goto err_dev_add; + } + +if (ipc_dev->cfg->mode ==IPC_DEV_MODE_IRQ ) { + if (devm_request_irq(&ipc_dev->dev,
drivers/platform/x86/intel_ipc_dev.c line 530
Quoted 10 lines
drivers/platform/x86/intel_ipc_dev.c new file +10
-0+ ipc_dev->cfg->irq, + ipc_dev_irq_handler, + ipc_dev->cfg->irqflags, + dev_name(&ipc_dev->dev), + ipc_dev)) { +dev_err (&ipc_dev->dev, +"Failed to request irq\n" ); + goto err_irq_request; + } + }
That looks really wrong to me. This is the class driver, so why are you handling the interrupts of the devices in it? You are clearly making assumption that the interrupt will always be used only for command completion, but that may not be the case. No assumptions.
Just define completion callbacks, and let the drivers handle the actual interrupts.
Quoted 21 lines
drivers/platform/x86/intel_ipc_dev.c new file +21
-0+ *ptr = ipc_dev; + +devres_add (dev, ptr); +return ipc_dev; + +err_irq_request: +device_del (&ipc_dev->dev); +err_dev_add: +kfree (ipc_dev); +err_dev_create: +devres_free (ptr); +return ERR_PTR (ret); +} +EXPORT_SYMBOL_GPL (devm_intel_ipc_dev_create); + +static int __init intel_ipc_init (void ) +{ +ipc_channel_lock_init (); +return class_register (&intel_ipc_class); +} +
drivers/platform/x86/intel_ipc_dev.c line 563
Quoted 10 lines
drivers/platform/x86/intel_ipc_dev.c new file +10
-0+static void __exit intel_ipc_exit(void) +{ +class_unregister (&intel_ipc_class); +} +subsys_initcall (intel_ipc_init); +module_exit (intel_ipc_exit); + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("Kuppuswamy Sathyanarayanan<[email protected]>" ); +MODULE_DESCRIPTION ("Intel IPC device class driver" );
To be honest, creating an extra logical device for the IPC hosts, and the entire class, all feel unnecessarily complex to me.
The goal of this patch should be possible to achieve in a much simpler and flexible way. IMO this patch needs to be redesigned.
Thanks,
Signature · 1 line
heikki
Re: [RFC v8 4/7] platform: x86: Add generic Intel IPC driver
Hi Heikki,
Quoted 70 lines · Heikki Krogerus
Hi,
Quoted 67 lines · On Sun, Oct 29, 2017 at 02:49:57AM -0700…
drivers/platform/x86/intel_ipc_dev.c new file +67
-0+/** +* devm_intel_ipc_dev_create() - Create IPC device +* @dev : IPC parent device. +* @devname : Name of the IPC device. +* @cfg : IPC device configuration. +* @ops : IPC device ops. +* +* Resource managed API to create IPC device with +* given configuration. +* +* Return : IPC device pointer or ERR_PTR(error code). +*/ +struct intel_ipc_dev *devm_intel_ipc_dev_create (struct device *dev, +const char *devname, +struct intel_ipc_dev_cfg *cfg, +struct intel_ipc_dev_ops *ops) +{ +struct intel_ipc_dev **ptr, *ipc_dev; +int ret; + +if (!dev && !devname && !cfg) +return ERR_PTR (-EINVAL ); + +if (intel_ipc_dev_get (devname)) { +dev_err (dev,"IPC device %s already exist\n" , devname); +return ERR_PTR (-EINVAL ); + } + + ptr =devres_alloc (devm_intel_ipc_dev_release,sizeof (*ptr), +GFP_KERNEL ); +if (!ptr) +return ERR_PTR (-ENOMEM ); + + ipc_dev =kzalloc (sizeof (*ipc_dev),GFP_KERNEL ); +if (!ipc_dev) { + ret = -ENOMEM ; + goto err_dev_create; + } + + ipc_dev->dev.class = &intel_ipc_class; + ipc_dev->dev.parent = dev; + ipc_dev->dev.groups = ipc_dev_groups; + ipc_dev->cfg = cfg; + ipc_dev->ops = ops; + +mutex_init (&ipc_dev->lock); +init_completion (&ipc_dev->cmd_complete); +dev_set_drvdata (&ipc_dev->dev, ipc_dev); +dev_set_name (&ipc_dev->dev, devname); +device_initialize (&ipc_dev->dev); + + ret =device_add (&ipc_dev->dev); +if (ret <0 ) { +dev_err (&ipc_dev->dev,"%s device create failed\n" , + __func__); + ret = -ENODEV ; + goto err_dev_add; + } + +if (ipc_dev->cfg->mode ==IPC_DEV_MODE_IRQ ) { +if (devm_request_irq (&ipc_dev->dev, + ipc_dev->cfg->irq, + ipc_dev_irq_handler, + ipc_dev->cfg->irqflags, +dev_name (&ipc_dev->dev), + ipc_dev)) { + dev_err(&ipc_dev->dev,
Quoted 8 lines
drivers/platform/x86/intel_ipc_dev.c line 530
Quoted 4 lines
drivers/platform/x86/intel_ipc_dev.c new file +4
-0+ "Failed to request irq\n"); + goto err_irq_request; + } + }That looks really wrong to me. This is the class driver, so why are you handling the interrupts of the devices in it? You are clearly making assumption that the interrupt will always be used only for command completion, but that may not be the case. No assumptions.
Yes. I only considered the current usage. But I agree with your comment. I will fix it in next version.
Quoted 29 lines
Just define completion callbacks, and let the drivers handle the actual interrupts.
Quoted 25 lines
drivers/platform/x86/intel_ipc_dev.c new file +25
-0+ *ptr = ipc_dev; + +devres_add (dev, ptr); +return ipc_dev; + +err_irq_request: +device_del (&ipc_dev->dev); +err_dev_add: +kfree (ipc_dev); +err_dev_create: +devres_free (ptr); +return ERR_PTR (ret); +} +EXPORT_SYMBOL_GPL (devm_intel_ipc_dev_create); + +static int __init intel_ipc_init (void ) +{ +ipc_channel_lock_init (); +return class_register (&intel_ipc_class); +} + +static void __exit intel_ipc_exit(void) +{ +class_unregister (&intel_ipc_class); +}
Quoted 8 lines
drivers/platform/x86/intel_ipc_dev.c line 563
Quoted 6 lines
drivers/platform/x86/intel_ipc_dev.c new file +6
-0+subsys_initcall (intel_ipc_init); +module_exit (intel_ipc_exit); + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("Kuppuswamy Sathyanarayanan<[email protected]>" ); +MODULE_DESCRIPTION ("Intel IPC device class driver" );To be honest, creating an extra logical device for the IPC hosts, and the entire class, all feel unnecessarily complex to me.
I want to avoid client drivers using different APIs to call everyone of these IPC drivers. One solution for this issue is to use name of the device to get the device pointer and then use that pointer in common API to make IPC calls. This solution is similar to whats used in extcon framework.
To implement this model either we have to use class type to group all these devices or implement a custom list to keep the references for all these devices.
I preferred to go with class based grouping, so that I can use class_find_device() API to get the device pointer.
Quoted 3 lines
The goal of this patch should be possible to achieve in a much simpler and flexible way. IMO this patch needs to be redesigned.
I am open for suggestions. I will send a separate mail to you discuss about the further details.
Quoted 4 lines
Thanks,
RFC v8 5/7 platform/x86: intel_punit_ipc: Use generic intel ipc device calls
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9/[email protected]>
Removed redundant IPC helper functions and refactored the driver to use APIs provided by generic IPC driver. This patch also cleans-up PUNIT IPC user drivers(intel_telemetry_pltdrv.c) to use APIs provided by generic IPC driver.
--- arch/x86/include/asm/intel_punit_ipc.h | 125 +++++------ drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_punit_ipc.c | 299 +++++++++----------------- drivers/platform/x86/intel_telemetry_pltdrv.c | 103 +++++---- 4 files changed, 222 insertions(+), 306 deletions(-)
Changes since v7:
* Fixed style issues.
Changes since v6:
* None
Changes since v5:
* Adapted to change in arguments of ipc_dev_cmd() and ipc_dev_raw_cmd() APIs.
Changes since v4:
* None
Changes since v2:
* Added unique name to PUNIT BIOS, GTD, & ISP regmaps.
* Added intel_ipc_dev_put() support.
Changes since v1:
* Removed custom APIs.
* Cleaned up PUNIT IPC user drivers to use APIs provided by generic IPC driver.
arch/x86/include/asm/intel_punit_ipc.h +50 -75
@@ -1,10 +1,8 @@ #ifndef _ASM_X86_INTEL_PUNIT_IPC_H_ #define _ASM_X86_INTEL_PUNIT_IPC_H_ -/* - * Three types of 8bit P-Unit IPC commands are supported, - * bit[7:6]: [00]: BIOS; [01]: GTD; [10]: ISPD. - */ +#include <linux/platform_data/x86/intel_ipc_dev.h> + typedef enum { BIOS_IPC = 0, GTDRIVER_IPC,
@@ -12,61 +10,60 @@ typedef enum {RESERVED_IPC , } IPC_TYPE; -#define IPC_TYPE_OFFSET 6 -#define IPC_PUNIT_BIOS_CMD_BASE (BIOS_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_GTD_CMD_BASE (GTDDRIVER_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_ISPD_CMD_BASE (ISPDRIVER_IPC << IPC_TYPE_OFFSET) -#define IPC_PUNIT_CMD_TYPE_MASK (RESERVED_IPC << IPC_TYPE_OFFSET) +#define PUNIT_BIOS_IPC_DEV "punit_bios_ipc" +#define PUNIT_GTD_IPC_DEV "punit_gtd_ipc" +#define PUNIT_ISP_IPC_DEV "punit_isp_ipc" +#define PUNIT_PARAM_LEN 3/* BIOS => Pcode commands */ -#define IPC_PUNIT_BIOS_ZERO (IPC_PUNIT_BIOS_CMD_BASE | 0x00) -#define IPC_PUNIT_BIOS_VR_INTERFACE (IPC_PUNIT_BIOS_CMD_BASE | 0x01) -#define IPC_PUNIT_BIOS_READ_PCS (IPC_PUNIT_BIOS_CMD_BASE | 0x02) -#define IPC_PUNIT_BIOS_WRITE_PCS (IPC_PUNIT_BIOS_CMD_BASE | 0x03) -#define IPC_PUNIT_BIOS_READ_PCU_CONFIG (IPC_PUNIT_BIOS_CMD_BASE | 0x04) -#define IPC_PUNIT_BIOS_WRITE_PCU_CONFIG (IPC_PUNIT_BIOS_CMD_BASE | 0x05) -#define IPC_PUNIT_BIOS_READ_PL1_SETTING (IPC_PUNIT_BIOS_CMD_BASE | 0x06) -#define IPC_PUNIT_BIOS_WRITE_PL1_SETTING (IPC_PUNIT_BIOS_CMD_BASE | 0x07) -#define IPC_PUNIT_BIOS_TRIGGER_VDD_RAM (IPC_PUNIT_BIOS_CMD_BASE | 0x08) -#define IPC_PUNIT_BIOS_READ_TELE_INFO (IPC_PUNIT_BIOS_CMD_BASE | 0x09) -#define IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x0a) -#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x0b) -#define IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x0c) -#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x0d) -#define IPC_PUNIT_BIOS_READ_TELE_TRACE (IPC_PUNIT_BIOS_CMD_BASE | 0x0e) -#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE (IPC_PUNIT_BIOS_CMD_BASE | 0x0f) -#define IPC_PUNIT_BIOS_READ_TELE_EVENT (IPC_PUNIT_BIOS_CMD_BASE | 0x10) -#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT (IPC_PUNIT_BIOS_CMD_BASE | 0x11) -#define IPC_PUNIT_BIOS_READ_MODULE_TEMP (IPC_PUNIT_BIOS_CMD_BASE | 0x12) -#define IPC_PUNIT_BIOS_RESERVED (IPC_PUNIT_BIOS_CMD_BASE | 0x13) -#define IPC_PUNIT_BIOS_READ_VOLTAGE_OVER (IPC_PUNIT_BIOS_CMD_BASE | 0x14) -#define IPC_PUNIT_BIOS_WRITE_VOLTAGE_OVER (IPC_PUNIT_BIOS_CMD_BASE | 0x15) -#define IPC_PUNIT_BIOS_READ_RATIO_OVER (IPC_PUNIT_BIOS_CMD_BASE | 0x16) -#define IPC_PUNIT_BIOS_WRITE_RATIO_OVER (IPC_PUNIT_BIOS_CMD_BASE | 0x17) -#define IPC_PUNIT_BIOS_READ_VF_GL_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x18) -#define IPC_PUNIT_BIOS_WRITE_VF_GL_CTRL (IPC_PUNIT_BIOS_CMD_BASE | 0x19) -#define IPC_PUNIT_BIOS_READ_FM_SOC_TEMP_THRESH (IPC_PUNIT_BIOS_CMD_BASE | 0x1a) -#define IPC_PUNIT_BIOS_WRITE_FM_SOC_TEMP_THRESH (IPC_PUNIT_BIOS_CMD_BASE | 0x1b) +#define IPC_PUNIT_BIOS_ZERO (0x00) +#define IPC_PUNIT_BIOS_VR_INTERFACE (0x01) +#define IPC_PUNIT_BIOS_READ_PCS (0x02) +#define IPC_PUNIT_BIOS_WRITE_PCS (0x03) +#define IPC_PUNIT_BIOS_READ_PCU_CONFIG (0x04) +#define IPC_PUNIT_BIOS_WRITE_PCU_CONFIG (0x05) +#define IPC_PUNIT_BIOS_READ_PL1_SETTING (0x06) +#define IPC_PUNIT_BIOS_WRITE_PL1_SETTING (0x07) +#define IPC_PUNIT_BIOS_TRIGGER_VDD_RAM (0x08) +#define IPC_PUNIT_BIOS_READ_TELE_INFO (0x09) +#define IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL (0x0a) +#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL (0x0b) +#define IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL (0x0c) +#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL (0x0d) +#define IPC_PUNIT_BIOS_READ_TELE_TRACE (0x0e) +#define IPC_PUNIT_BIOS_WRITE_TELE_TRACE (0x0f) +#define IPC_PUNIT_BIOS_READ_TELE_EVENT (0x10) +#define IPC_PUNIT_BIOS_WRITE_TELE_EVENT (0x11) +#define IPC_PUNIT_BIOS_READ_MODULE_TEMP (0x12) +#define IPC_PUNIT_BIOS_RESERVED (0x13) +#define IPC_PUNIT_BIOS_READ_VOLTAGE_OVER (0x14) +#define IPC_PUNIT_BIOS_WRITE_VOLTAGE_OVER (0x15) +#define IPC_PUNIT_BIOS_READ_RATIO_OVER (0x16) +#define IPC_PUNIT_BIOS_WRITE_RATIO_OVER (0x17) +#define IPC_PUNIT_BIOS_READ_VF_GL_CTRL (0x18) +#define IPC_PUNIT_BIOS_WRITE_VF_GL_CTRL (0x19) +#define IPC_PUNIT_BIOS_READ_FM_SOC_TEMP_THRESH (0x1a) +#define IPC_PUNIT_BIOS_WRITE_FM_SOC_TEMP_THRESH (0x1b)/* GT Driver => Pcode commands */ -#define IPC_PUNIT_GTD_ZERO (IPC_PUNIT_GTD_CMD_BASE | 0x00) -#define IPC_PUNIT_GTD_CONFIG (IPC_PUNIT_GTD_CMD_BASE | 0x01) -#define IPC_PUNIT_GTD_READ_ICCP_LIC_CDYN_SCAL (IPC_PUNIT_GTD_CMD_BASE | 0x02) -#define IPC_PUNIT_GTD_WRITE_ICCP_LIC_CDYN_SCAL (IPC_PUNIT_GTD_CMD_BASE | 0x03) -#define IPC_PUNIT_GTD_GET_WM_VAL (IPC_PUNIT_GTD_CMD_BASE | 0x06) -#define IPC_PUNIT_GTD_WRITE_CONFIG_WISHREQ (IPC_PUNIT_GTD_CMD_BASE | 0x07) -#define IPC_PUNIT_GTD_READ_REQ_DUTY_CYCLE (IPC_PUNIT_GTD_CMD_BASE | 0x16) -#define IPC_PUNIT_GTD_DIS_VOL_FREQ_CHG_REQUEST (IPC_PUNIT_GTD_CMD_BASE | 0x17) -#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_CTRL (IPC_PUNIT_GTD_CMD_BASE | 0x1a) -#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_TUNING (IPC_PUNIT_GTD_CMD_BASE | 0x1c) +#define IPC_PUNIT_GTD_ZERO (0x00) +#define IPC_PUNIT_GTD_CONFIG (0x01) +#define IPC_PUNIT_GTD_READ_ICCP_LIC_CDYN_SCAL (0x02) +#define IPC_PUNIT_GTD_WRITE_ICCP_LIC_CDYN_SCAL (0x03) +#define IPC_PUNIT_GTD_GET_WM_VAL (0x06) +#define IPC_PUNIT_GTD_WRITE_CONFIG_WISHREQ (0x07) +#define IPC_PUNIT_GTD_READ_REQ_DUTY_CYCLE (0x16) +#define IPC_PUNIT_GTD_DIS_VOL_FREQ_CHG_REQUEST (0x17) +#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_CTRL (0x1a) +#define IPC_PUNIT_GTD_DYNA_DUTY_CYCLE_TUNING (0x1c)/* ISP Driver => Pcode commands */ -#define IPC_PUNIT_ISPD_ZERO (IPC_PUNIT_ISPD_CMD_BASE | 0x00) -#define IPC_PUNIT_ISPD_CONFIG (IPC_PUNIT_ISPD_CMD_BASE | 0x01) -#define IPC_PUNIT_ISPD_GET_ISP_LTR_VAL (IPC_PUNIT_ISPD_CMD_BASE | 0x02) -#define IPC_PUNIT_ISPD_ACCESS_IU_FREQ_BOUNDS (IPC_PUNIT_ISPD_CMD_BASE | 0x03) -#define IPC_PUNIT_ISPD_READ_CDYN_LEVEL (IPC_PUNIT_ISPD_CMD_BASE | 0x04) -#define IPC_PUNIT_ISPD_WRITE_CDYN_LEVEL (IPC_PUNIT_ISPD_CMD_BASE | 0x05) +#define IPC_PUNIT_ISPD_ZERO (0x00) +#define IPC_PUNIT_ISPD_CONFIG (0x01) +#define IPC_PUNIT_ISPD_GET_ISP_LTR_VAL (0x02) +#define IPC_PUNIT_ISPD_ACCESS_IU_FREQ_BOUNDS (0x03) +#define IPC_PUNIT_ISPD_READ_CDYN_LEVEL (0x04) +#define IPC_PUNIT_ISPD_WRITE_CDYN_LEVEL (0x05)/* Error codes */ #define IPC_PUNIT_ERR_SUCCESS 0
@@ -76,26 +73,4 @@ typedef enum {#define IPC_PUNIT_ERR_CMD_LOCKED 4#define IPC_PUNIT_ERR_INVALID_VR_ID 5#define IPC_PUNIT_ERR_VR_ERR 6 - -#if IS_ENABLED (CONFIG_INTEL_PUNIT_IPC ) - -int intel_punit_ipc_simple_command (int cmd,int para1,int para2); -int intel_punit_ipc_command (u32 cmd,u32 para1,u32 para2,u32 *in,u32 *out); - -#else - -static inline int intel_punit_ipc_simple_command (int cmd, -int para1,int para2) -{ -return -ENODEV ; -} - -static inline int intel_punit_ipc_command (u32 cmd,u32 para1,u32 para2, -u32 *in,u32 *out) -{ -return -ENODEV ; -} - -#endif /* CONFIG_INTEL_PUNIT_IPC */ -#endif
drivers/platform/x86/Kconfig +1 -0
@@ -1083,6 +1083,7 @@ config SURFACE_3_BUTTON config INTEL_PUNIT_IPC tristate "Intel P-Unit IPC Driver" + select REGMAP_MMIO ---help--- This driver provides support for Intel P-Unit Mailbox IPC mechanism, which is used to bridge the communications between kernel and P-Unit.
drivers/platform/x86/intel_punit_ipc.c +106 -193
363 lines not on this page · raw message
drivers/platform/x86/intel_telemetry_pltdrv.c +65 -38
214 lines not on this page · raw message
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC v8 6/7 platform/x86: intel_pmc_ipc: Use generic Intel IPC device calls
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
Removed redundant IPC helper functions and refactored the driver to use generic IPC device driver APIs. Also, cleaned up the driver to minimize the usage of global variable ipcdev by propogating the struct intel_pmc_ipc_dev pointer or by getting it from device private data.
This patch also cleans-up PMC IPC user drivers(intel_telemetry_pltdrv.c, intel_soc_pmic_bxtwc.c) to use APIs provided by generic IPC driver.
--- arch/x86/include/asm/intel_pmc_ipc.h | 31 +-- drivers/mfd/intel_soc_pmic_bxtwc.c | 37 ++- drivers/platform/x86/intel_pmc_ipc.c | 382 ++++++++++---------------- drivers/platform/x86/intel_telemetry_pltdrv.c | 128 ++++----- include/linux/mfd/intel_soc_pmic.h | 2 + 5 files changed, 247 insertions(+), 333 deletions(-)
Changes since v7:
* Fixed style issues.
Changes since v6:
* Fixed some style and rebase issues.
Changes since v5:
* Adapted to change in arguments of ipc_dev_cmd() and ipc_dev_raw_cmd() APIs.
Changes since v4:
* None
Changes since v3:
* Added unique name to PMC regmaps.
* Added support to clear interrupt bit.
* Added intel_ipc_dev_put() support.
Changes since v1:
* Removed custom APIs.
* Cleaned up PMC IPC user drivers to use APIs provided by generic IPC driver.
arch/x86/include/asm/intel_pmc_ipc.h +7 -24
@@ -1,10 +1,15 @@#ifndef _ASM_X86_INTEL_PMC_IPC_H_#define _ASM_X86_INTEL_PMC_IPC_H_ +#include <linux/platform_data/x86/intel_ipc_dev.h> + +#define INTEL_PMC_IPC_DEV "intel_pmc_ipc" +#define PMC_PARAM_LEN 2 +/* Commands */ #define PMC_IPC_PMIC_ACCESS 0xFF -#define PMC_IPC_PMIC_ACCESS_READ 0x0 -#define PMC_IPC_PMIC_ACCESS_WRITE 0x1 +#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
@@ -30,11 +35,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, -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_write (u32 offset,u32 data);
@@ -42,23 +42,6 @@ int intel_pmc_gcr_update(u32 offset, u32 mask, u32 val);#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) -{ -return -EINVAL ; -} - -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/mfd/intel_soc_pmic_bxtwc.c +31 -6
@@ -271,6 +271,9 @@ static int regmap_ipc_byte_reg_read(void *context, unsigned int reg,u8 ipc_in[2 ];u8 ipc_out[4 ];struct intel_soc_pmic *pmic = context; +struct intel_ipc_raw_cmd ipc_raw_cmd; +u32 cmd[PMC_PARAM_LEN ] = {PMC_IPC_PMIC_ACCESS , +PMC_IPC_PMIC_ACCESS_READ };if (!pmic)return -EINVAL ;
@@ -284,9 +287,15 @@ 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 ); + + ipc_raw_cmd.cmd_list = cmd; + ipc_raw_cmd.cmdlen =PMC_PARAM_LEN ; + ipc_raw_cmd.in = ipc_in; + ipc_raw_cmd.inlen =sizeof (ipc_in); + ipc_raw_cmd.out = (u32 *)ipc_out; + ipc_raw_cmd.outlen =1 ; + + ret =ipc_dev_raw_cmd (pmic->ipc_dev, &ipc_raw_cmd);if (ret) {dev_err (pmic->dev,"Failed to read from PMIC\n" );return ret;
@@ -303,6 +312,9 @@ static int regmap_ipc_byte_reg_write(void *context, unsigned int reg,int i2c_addr;u8 ipc_in[3 ];struct intel_soc_pmic *pmic = context; +struct intel_ipc_raw_cmd ipc_raw_cmd; +u32 cmd[PMC_PARAM_LEN ] = {PMC_IPC_PMIC_ACCESS , +PMC_IPC_PMIC_ACCESS_WRITE };if (!pmic)return -EINVAL ;
@@ -317,9 +329,15 @@ 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 ); + + ipc_raw_cmd.cmd_list = cmd; + ipc_raw_cmd.cmdlen =PMC_PARAM_LEN ; + ipc_raw_cmd.in = ipc_in; + ipc_raw_cmd.inlen =sizeof (ipc_in); + ipc_raw_cmd.out =NULL ; + ipc_raw_cmd.outlen =0 ; + + ret =ipc_dev_raw_cmd (pmic->ipc_dev, &ipc_raw_cmd);if (ret) {dev_err (pmic->dev,"Failed to write to PMIC\n" );return ret;
@@ -445,6 +463,10 @@ static int bxtwc_probe(struct platform_device *pdev)if (!pmic)return -ENOMEM ; + pmic->ipc_dev =intel_ipc_dev_get (INTEL_PMC_IPC_DEV ); +if (IS_ERR_OR_NULL (pmic->ipc_dev)) +return PTR_ERR (pmic->ipc_dev); + ret =platform_get_irq (pdev,0 );if (ret <0 ) {dev_err (&pdev->dev,"Invalid IRQ\n" );
@@ -562,7 +584,10 @@ static int bxtwc_probe(struct platform_device *pdev)static int bxtwc_remove (struct platform_device *pdev) { +struct intel_soc_pmic *pmic =dev_get_drvdata (&pdev->dev); +sysfs_remove_group (&pdev->dev.kobj, &bxtwc_group); +intel_ipc_dev_put (pmic->ipc_dev);return 0 ; }
drivers/platform/x86/intel_pmc_ipc.c +142 -240
528 lines not on this page · raw message
drivers/platform/x86/intel_telemetry_pltdrv.c +65 -63
241 lines not on this page · raw message
include/linux/mfd/intel_soc_pmic.h +2 -0
@@ -20,6 +20,7 @@#define __INTEL_SOC_PMIC_H__#include <linux/regmap.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> struct intel_soc_pmic {int irq;
@@ -31,6 +32,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_ipc_dev *ipc_dev; };#endif /* __INTEL_SOC_PMIC_H__ */
Signature · 1 line
2.7.4
RFC v8 7/7 platform/x86: intel_scu_ipc: Use generic Intel IPC device calls
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
Removed redundant IPC helper functions and refactored the driver to use generic IPC device driver APIs.
This patch also cleans-up SCU IPC user drivers(rtc-mrst.c, intel-mid_wdt.c, intel-mid_wdt.c, intel-mid.c) to use APIs provided by generic IPC driver.
--- arch/x86/include/asm/intel_scu_ipc.h | 10 +- arch/x86/platform/intel-mid/intel-mid.c | 15 +- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_scu_ipc.c | 488 ++++++++++++++------------------ drivers/rtc/rtc-mrst.c | 16 +- drivers/watchdog/intel-mid_wdt.c | 18 +- drivers/watchdog/intel_scu_watchdog.c | 23 +- 7 files changed, 267 insertions(+), 304 deletions(-)
Changes since v7:
* Fixed some style issues.
Changes since v6:
* Fixed some style issues.
Changes since v5:
* Adapted to change in arguments of ipc_dev_cmd() and ipc_dev_raw_cmd() APIs.
Changes since v4:
* None
Changes since v3:
* Added intel_ipc_dev_put() support.
arch/x86/include/asm/intel_scu_ipc.h +3 -7
@@ -18,6 +18,9 @@#define IPC_CMD_VRTC_SETTIME 1/* Set time */ #define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ +#define INTEL_SCU_IPC_DEV "intel_scu_ipc" +#define SCU_PARAM_LEN 2 +/* Read single register */ int intel_scu_ipc_ioread8 (u16 addr,u8 *data);
@@ -45,13 +48,6 @@ 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); -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);
arch/x86/platform/intel-mid/intel-mid.c +13 -2
@@ -22,6 +22,7 @@#include <linux/irq.h> #include <linux/export.h> #include <linux/notifier.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> #include <asm/setup.h> #include <asm/mpspec_def.h>
@@ -70,16 +71,26 @@ EXPORT_SYMBOL_GPL(__intel_mid_cpu_chip);static void intel_mid_power_off (void ) { +struct intel_ipc_dev *ipc_dev; +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_COLD_OFF ,1 }; +/* Shut down South Complex via PWRMU */ intel_mid_pwr_power_off (); + ipc_dev =intel_ipc_dev_get (INTEL_SCU_IPC_DEV );/* Only for Tangier, the rest will ignore this command */ -intel_scu_ipc_simple_command (IPCMSG_COLD_OFF ,1 ); +ipc_dev_simple_cmd (ipc_dev, cmds,SCU_PARAM_LEN ); +intel_ipc_dev_put (ipc_dev); };static void intel_mid_reboot (void ) { -intel_scu_ipc_simple_command (IPCMSG_COLD_BOOT ,0 ); +struct intel_ipc_dev *ipc_dev; +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_COLD_BOOT ,0 }; + + ipc_dev =intel_ipc_dev_get (INTEL_SCU_IPC_DEV ); +ipc_dev_simple_cmd (ipc_dev, cmds,SCU_PARAM_LEN ); +intel_ipc_dev_put (ipc_dev); }static unsigned long __init intel_mid_calibrate_tsc (void )
drivers/platform/x86/Kconfig +1 -0
@@ -850,6 +850,7 @@ config INTEL_VBTN config INTEL_SCU_IPC bool "Intel SCU IPC Support" depends on X86_INTEL_MID + select REGMAP_MMIO default y ---help--- IPC is used to bridge the communications between kernel and SCU on
drivers/platform/x86/intel_scu_ipc.c +205 -283
603 lines not on this page · raw message
drivers/rtc/rtc-mrst.c +12 -4
@@ -36,6 +36,7 @@#include <linux/module.h> #include <linux/init.h> #include <linux/sfi.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> #include <asm/intel_scu_ipc.h> #include <asm/intel-mid.h>
@@ -46,6 +47,7 @@ struct mrst_rtc {struct device *dev;int irq;struct resource *iomem; +struct intel_ipc_dev *ipc_dev;u8 enabled_wake;u8 suspend_ctrl;
@@ -110,10 +112,11 @@ static int mrst_read_time(struct device *dev, struct rtc_time *time)static int mrst_set_time (struct device *dev,struct rtc_time *time) { -int ret;unsigned long flags;unsigned char mon, day, hrs, min, sec;unsigned int yrs; +struct mrst_rtc *mrst =dev_get_drvdata (dev); +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_VRTC ,IPC_CMD_VRTC_SETTIME }; yrs = time->tm_year; mon = time->tm_mon +1 ;/* tm_mon starts at zero */
@@ -137,8 +140,7 @@ static int mrst_set_time(struct device *dev, struct rtc_time *time)spin_unlock_irqrestore (&rtc_lock, flags); - ret =intel_scu_ipc_simple_command (IPCMSG_VRTC ,IPC_CMD_VRTC_SETTIME ); -return ret; +return ipc_dev_simple_cmd (mrst->ipc_dev, cmds,SCU_PARAM_LEN ); }static int mrst_read_alarm (struct device *dev,struct rtc_wkalrm *t)
@@ -210,6 +212,7 @@ static int mrst_set_alarm(struct device *dev, struct rtc_wkalrm *t)struct mrst_rtc *mrst =dev_get_drvdata (dev);unsigned char hrs, min, sec;int ret =0 ; +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_VRTC ,IPC_CMD_VRTC_SETALARM };if (!mrst->irq)return -EIO ;
@@ -229,7 +232,7 @@ static int mrst_set_alarm(struct device *dev, struct rtc_wkalrm *t)spin_unlock_irq (&rtc_lock); - ret =intel_scu_ipc_simple_command (IPCMSG_VRTC ,IPC_CMD_VRTC_SETALARM ); + ret =ipc_dev_simple_cmd (mrst->ipc_dev, cmds,SCU_PARAM_LEN );if (ret)return ret;
@@ -329,6 +332,10 @@ static int vrtc_mrst_do_probe(struct device *dev, struct resource *iomem,if (!iomem)return -ENODEV ; + mrst_rtc.ipc_dev =intel_ipc_dev_get (INTEL_SCU_IPC_DEV ); +if (IS_ERR_OR_NULL (mrst_rtc.ipc_dev)) +return PTR_ERR (mrst_rtc.ipc_dev); + iomem =request_mem_region (iomem->start,resource_size (iomem), driver_name);if (!iomem) {
@@ -394,6 +401,7 @@ static void rtc_mrst_do_remove(struct device *dev)rtc_mrst_do_shutdown (); +intel_ipc_dev_put (mrst->ipc_dev);if (mrst->irq)free_irq (mrst->irq, mrst->rtc);
drivers/watchdog/intel-mid_wdt.c +17 -1
@@ -18,6 +18,7 @@#include <linux/platform_device.h> #include <linux/watchdog.h> #include <linux/platform_data/intel-mid_wdt.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> #include <asm/intel_scu_ipc.h> #include <asm/intel-mid.h>
@@ -29,6 +30,8 @@#define MID_WDT_TIMEOUT_MAX 170#define MID_WDT_DEFAULT_TIMEOUT 90 +static struct intel_ipc_dev *scu_ipc_dev; +/* SCU watchdog messages */ enum {SCU_WATCHDOG_START =0 ,
@@ -38,7 +41,16 @@ enum {static inline int wdt_command (int sub,u32 *in,int inlen) { -return intel_scu_ipc_command (IPC_WATCHDOG , sub, in, inlen,NULL ,0 ); +u32 cmds[SCU_PARAM_LEN ] = {IPC_WATCHDOG , sub}; +struct intel_ipc_cmd ipc_cmd = {0 }; + + ipc_cmd.cmd_list = cmds; + ipc_cmd.cmdlen =SCU_PARAM_LEN ; + ipc_cmd.in = in; + ipc_cmd.out =NULL ; + ipc_cmd.inlen = inlen; + +return ipc_dev_cmd (scu_ipc_dev, &ipc_cmd); }static int wdt_start (struct watchdog_device *wd)
@@ -129,6 +141,10 @@ static int mid_wdt_probe(struct platform_device *pdev)if (!wdt_dev)return -ENOMEM ; + scu_ipc_dev =devm_intel_ipc_dev_get (&pdev->dev,INTEL_SCU_IPC_DEV ); +if (IS_ERR_OR_NULL (scu_ipc_dev)) +return PTR_ERR (scu_ipc_dev); + wdt_dev->info = &mid_wdt_info; wdt_dev->ops = &mid_wdt_ops; wdt_dev->min_timeout =MID_WDT_TIMEOUT_MIN ;
drivers/watchdog/intel_scu_watchdog.c +16 -7
@@ -49,6 +49,7 @@#include <asm/intel_scu_ipc.h> #include <asm/apb_timer.h> #include <asm/intel-mid.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> #include "intel_scu_watchdog.h"
@@ -94,6 +95,8 @@ MODULE_PARM_DESC(force_boot,static struct intel_scu_watchdog_dev watchdog_device; +static struct intel_ipc_dev *scu_ipc_dev; +/* Forces restart, if force_reboot is set */ static void watchdog_fire (void ) {
@@ -128,19 +131,20 @@ static int watchdog_set_ipc(int soft_threshold, int threshold)u32 *ipc_wbuf;u8 cbuf[16 ] = {'\0' };int ipc_ret =0 ; +u32 cmds[SCU_PARAM_LEN ] = {IPC_SET_WATCHDOG_TIMER ,0 }; +struct intel_ipc_cmd ipc_cmd; ipc_wbuf = (u32 *)&cbuf; ipc_wbuf[0 ] = soft_threshold; ipc_wbuf[1 ] = threshold; - ipc_ret =intel_scu_ipc_command ( -IPC_SET_WATCHDOG_TIMER , -0 , - ipc_wbuf, -2 , -NULL , -0 ); + ipc_cmd.cmd_list = cmds; + ipc_cmd.cmdlen =SCU_PARAM_LEN ; + ipc_cmd.in = ipc_wbuf; + ipc_cmd.inlen =2 ; + ipc_cmd.out =NULL ; + ipc_ret =ipc_dev_cmd (scu_ipc_dev, &ipc_cmd);if (ipc_ret !=0 )pr_err ("Error setting SCU watchdog timer: %x\n" , ipc_ret);
@@ -460,6 +464,10 @@ static int __init intel_scu_watchdog_init(void)if (check_timer_margin (timer_margin))return -EINVAL ; + scu_ipc_dev =intel_ipc_dev_get (INTEL_SCU_IPC_DEV ); +if (IS_ERR_OR_NULL (scu_ipc_dev)) +return PTR_ERR (scu_ipc_dev); + watchdog_device.timer_tbl_ptr =sfi_get_mtmr (sfi_mtimer_num-1 );if (watchdog_device.timer_tbl_ptr ==NULL ) {
@@ -550,6 +558,7 @@ static void __exit intel_scu_watchdog_exit(void) {misc_deregister (&watchdog_device.miscdev); +intel_ipc_dev_put (scu_ipc_dev);unregister_reboot_notifier (&watchdog_device.intel_scu_notifier);/* disable the timer */ iowrite32 (0x00000002 , watchdog_device.timer_control_addr);
Signature · 1 line
2.7.4
Hi,
Quoted 5 lines · On Sun, Oct 29, 2017 at 02:49:53AM -0700…
Currently
intel_pmc_ipc.c,intel_punit_ipc.c,intel_scu_ipc.cdrivers implements the same IPC features. This code duplication could be avoided if we implement the IPC driver as a generic library and let custom device drivers use API provided by generic driver. This patchset mainly addresses this issue.
Quoted 8 lines
Along with above code duplication issue, This patchset also addresses following issues in
intel_pmc_ipcandintel_punit_ipcdrivers.1.
Intel_pmc_ipc.cdriver does not use any resource managed (devm_*) calls.
2. InIntel_pmc_ipc.cdriver, dependent devices like PUNIT, Telemetry and iTCO are created manually and uses lot of redundant buffer code.
3. Global variable is used to store the IPC device structure and it is used across all functions inintel_pmc_ipc.candintel_punit_ipc.c.
I think those changes are definitely welcome. On top of those, I want to have regmap for using the IPC. It does not make any sense that the drivers for the devices attached to for example the PMC, like the WhiskeyCove PMIC, have to implement their own regmaps.
But a class for the IPC library does feel like overkill to me.
Thanks,
Signature · 5 lines
heikki -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html