PMC/PUNIT IPC driver cleanup
Subsystems (9)
v3 cover PMC/PUNIT 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, cmd, PMC_PARAM_LEN, (u32 *)ipc_in, 1, NULL, 0, 0, 0);
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 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_pmc_ipc: Use devm_* calls in driver probe function 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
arch/x86/include/asm/intel_pmc_ipc.h | 37 +- arch/x86/include/asm/intel_punit_ipc.h | 125 ++-- arch/x86/include/asm/intel_scu_ipc.h | 23 +- arch/x86/platform/intel-mid/intel-mid.c | 12 +- drivers/mfd/intel_soc_pmic_bxtwc.c | 18 +- drivers/platform/x86/Kconfig | 11 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_ipc_dev.c | 539 ++++++++++++++ drivers/platform/x86/intel_pmc_ipc.c | 948 +++++++++--------------- drivers/platform/x86/intel_punit_ipc.c | 297 +++----- drivers/platform/x86/intel_scu_ipc.c | 483 +++++------- drivers/platform/x86/intel_telemetry_pltdrv.c | 210 +++--- drivers/rtc/rtc-mrst.c | 15 +- drivers/watchdog/intel-mid_wdt.c | 12 +- drivers/watchdog/intel_scu_watchdog.c | 17 +- include/linux/mfd/intel_soc_pmic.h | 2 + include/linux/platform_data/x86/intel_ipc_dev.h | 187 +++++ 17 files changed, 1617 insertions(+), 1320 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 v3 2/7 platform/x86: intel_pmc_ipc: Use MFD framework to create dependent devices
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 | 397 +++++++++++++---------------------- 1 file changed, 142 insertions(+), 255 deletions(-)
drivers/platform/x86/intel_pmc_ipc.c +142 -255
@@ -33,6 +33,7 @@#include <linux/suspend.h> #include <linux/acpi.h> #include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/mfd/core.h> #include <asm/intel_pmc_ipc.h>
@@ -87,6 +88,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/*
@@ -105,8 +107,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 */
@@ -123,25 +123,12 @@ 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; -/* 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[] = {
@@ -589,44 +576,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 ,
@@ -634,237 +583,186 @@ 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 *res; +static struct resource punit_res[PLAT_RESOURCE_MEM_MAX_INDEX ]; +static struct mfd_cell punit_cell; +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 not valid resource, skip the rest of steps */ +if (!res) { + pindex++; +continue ; + } +memcpy (&punit_res[pindex], res,sizeof (*res)); + punit_res[pindex].flags =IORESOURCE_MEM ; +dev_info (&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.id =-1 ; + 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_AUTO , + &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), - }; - - res = tco_res +TCO_RESOURCE_ACPI_IO ; - res->start = ipcdev.acpi_io_base +TCO_BASE_OFFSET ; - res->end = res->start +TCO_REGS_SIZE -1 ; +static struct mfd_cell wdt_cell; - 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 ; +/* If we have ACPI based watchdog use that instead, othewise create +* a MFD cell for iTCO watchdog*/ +if (acpi_has_watchdog ()) +return 0 ; - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.tco_dev = pdev; +/* 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 ; + } -return 0 ; + 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_info (&pdev->dev,"watchdog res 0: %pR\n" , + &wdt_ipc_res[0 ]); +dev_info (&pdev->dev,"watchdog res 1: %pR\n" , + &wdt_ipc_res[1 ]); + + wdt_cell.name =TCO_DEVICE_NAME ; + wdt_cell.id =-1 ; + 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_AUTO , + &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; +static struct resource telemetry_ipc_res[2 ];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 ; +static struct mfd_cell telemetry_cell; - res = telemetry_res +TELEMETRY_RESOURCE_PMC_SSRAM ; - res->start = ipcdev.telem_pmc_ssram_base; - res->end = res->start + ipcdev.telem_pmc_ssram_size -1 ; - - pdev =platform_device_register_full (&pdevinfo); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - - ipcdev.telemetry_dev = pdev; +/* 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 ; + } -return 0 ; + 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_info (&pdev->dev,"Telemetry res 0: %pR\n" , + &telemetry_ipc_res[0 ]); +dev_info (&pdev->dev,"Telemetry res 1: %pR\n" , + &telemetry_ipc_res[1 ]); + + telemetry_cell.name =TELEMETRY_DEVICE_NAME ; + telemetry_cell.id =-1 ; + 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_AUTO , + &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 */ +/* Get IPC resources */ res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_BIOS_IFACE_INDEX ); +PLAT_RESOURCE_IPC_INDEX );if (!res) { -dev_err (&pdev->dev,"Failed to get res of punit BIOS iface\n" ); +dev_err (&pdev->dev,"Failed to get IPC resources\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); - } - - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_IPC_INDEX ); -if (!res) { -dev_err (&pdev->dev,"Failed to get ipc resource\n" ); -return -ENXIO ; - } res->end = (res->start +PLAT_RESOURCE_IPC_SIZE + -PLAT_RESOURCE_GCR_SIZE -1 ); +PLAT_RESOURCE_GCR_SIZE -1 ); addr =devm_ioremap_resource (&pdev->dev, res);if (IS_ERR (addr)) { -dev_err (&pdev->dev, -"PMC I/O memory remapping failed\n" ); -return PTR_ERR (addr); +dev_err (&pdev->dev,"PMC I/O memory remapping failed\n" ); +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_info (&pdev->dev,"PMC IPC resource %pR\n" , res);return 0 ; }
@@ -919,7 +817,7 @@ 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" );return ret;
@@ -928,37 +826,26 @@ static int ipc_plat_probe(struct platform_device *pdev)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 unregister_devices; +return -EBUSY ; } 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 unregister_devices; +return ret; } ipcdev.has_gcr_regs = true;return 0 ; - -unregister_devices: -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 ; }
Signature · 1 line
2.7.4
RFC v3 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.
--- drivers/platform/x86/Kconfig | 8 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_ipc_dev.c | 539 ++++++++++++++++++++++++ include/linux/platform_data/x86/intel_ipc_dev.h | 187 ++++++++ 4 files changed, 735 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 v2:
* Added ipc_dev_cmd API support.
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 +539 -0
539 lines not on this page · raw message
include/linux/platform_data/x86/intel_ipc_dev.h new file +187 -0
187 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC v3 5/7 platform/x86: intel_punit_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 APIs provided by generic IPC driver. This patch also cleans-up PUNIT IPC user drivers 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 | 297 +++++++++----------------- drivers/platform/x86/intel_telemetry_pltdrv.c | 96 +++++---- 4 files changed, 216 insertions(+), 303 deletions(-)
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 +54 -71
@@ -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
@@ -77,25 +74,11 @@ typedef enum {#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) +static inline void punit_cmd_init (u32 *cmd,u32 param1,u32 param2,u32 param3) { -return -ENODEV ; + cmd[0 ] = param1; + cmd[1 ] = param2; + cmd[2 ] = param3; } -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 +104 -193
360 lines not on this page · raw message
drivers/platform/x86/intel_telemetry_pltdrv.c +57 -39
224 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC v3 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 to use APIs provided by generic IPC driver.
--- arch/x86/include/asm/intel_scu_ipc.h | 23 +- arch/x86/platform/intel-mid/intel-mid.c | 12 +- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_scu_ipc.c | 483 +++++++++++++------------------- drivers/rtc/rtc-mrst.c | 15 +- drivers/watchdog/intel-mid_wdt.c | 12 +- drivers/watchdog/intel_scu_watchdog.c | 17 +- 7 files changed, 251 insertions(+), 312 deletions(-)
arch/x86/include/asm/intel_scu_ipc.h +13 -10
@@ -14,9 +14,19 @@#define IPCMSG_COLD_BOOT 0xF3#define IPCMSG_VRTC 0xFA/* Set vRTC device */ -/* Command id associated with message IPCMSG_VRTC */ -#define IPC_CMD_VRTC_SETTIME 1/* Set time */ -#define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ + +/* Command id associated with message IPCMSG_VRTC */ +#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 + +static inline void scu_cmd_init (u32 *cmd,u32 param1,u32 param2) +{ + cmd[0 ] = param1; + cmd[1 ] = param2; +}/* Read single register */ int intel_scu_ipc_ioread8 (u16 addr,u8 *data);
@@ -45,13 +55,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 +10 -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>
@@ -68,18 +69,23 @@ static void *(*get_intel_mid_ops[])(void) = INTEL_MID_OPS_INIT;enum intel_mid_cpu_type __intel_mid_cpu_chip;EXPORT_SYMBOL_GPL (__intel_mid_cpu_chip); +static struct intel_ipc_dev *ipc_dev; +static void intel_mid_power_off (void ) { +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_COLD_OFF ,1 };/* Shut down South Complex via PWRMU */ intel_mid_pwr_power_off ();/* 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 ); };static void intel_mid_reboot (void ) { -intel_scu_ipc_simple_command (IPCMSG_COLD_BOOT ,0 ); +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_COLD_BOOT ,0 }; + +ipc_dev_simple_cmd (ipc_dev, cmds,SCU_PARAM_LEN ); }static unsigned long __init intel_mid_calibrate_tsc (void )
@@ -206,6 +212,8 @@ void __init x86_intel_mid_early_setup(void) x86_init.mpparse.find_smp_config = x86_init_noop; x86_init.mpparse.get_smp_config = x86_init_uint_noop;set_bit (MP_BUS_ISA , mp_bus_not_pci); + + ipc_dev =intel_ipc_dev_get (INTEL_SCU_IPC_DEV ); }/*
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 +195 -288
594 lines not on this page · raw message
drivers/rtc/rtc-mrst.c +11 -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) {
drivers/watchdog/intel-mid_wdt.c +11 -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,10 @@ 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}; + +return ipc_dev_cmd (scu_ipc_dev, cmds,SCU_PARAM_LEN , in, + inlen,NULL ,0 ); }static int wdt_start (struct watchdog_device *wd)
@@ -129,6 +135,10 @@ static int mid_wdt_probe(struct platform_device *pdev)if (!wdt_dev)return -ENOMEM ; + 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); + 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 +10 -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,18 +131,14 @@ 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 }; 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_ret =ipc_dev_cmd (scu_ipc_dev, cmds,SCU_PARAM_LEN , ipc_wbuf, +2 ,NULL ,0 );if (ipc_ret !=0 )pr_err ("Error setting SCU watchdog timer: %x\n" , ipc_ret);
@@ -460,6 +459,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 ) {
Signature · 1 line
2.7.4
RFC v3 1/7 platform/x86: intel_pmc_ipc: Use devm_* calls in driver probe function
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
This patch cleans up unnecessary free/alloc calls in ipc_plat_probe(), ipc_pci_probe() and ipc_plat_get_res() functions by using devm_* calls.
This patch also adds proper error handling for failure cases in ipc_pci_probe() function.
--- drivers/platform/x86/intel_pmc_ipc.c | 104 ++++++++++++----------------------- 1 file changed, 34 insertions(+), 70 deletions(-)
Changes since v2:
* Used pcim_* device managed functions.
Changes since v1:
* Merged devm_* related changes into a single function.
* Instead of removing free_irq, use devm_free_irq function.
drivers/platform/x86/intel_pmc_ipc.c +34 -70
@@ -480,52 +480,39 @@ static irqreturn_t ioc(int irq, void *dev_id)static int ipc_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) { -resource_size_t pci_resource;int ret; -int len; +struct intel_pmc_ipc_dev *pmc = &ipcdev; - ipcdev.dev = &pci_dev_get (pdev)->dev; - ipcdev.irq_mode =IPC_TRIGGER_MODE_IRQ ; +/* Only one PMC is supported */ +if (pmc->dev) +return -EBUSY ; - ret =pci_enable_device (pdev); + pmc->irq_mode =IPC_TRIGGER_MODE_IRQ ; + + ret =pcim_enable_device (pdev);if (ret)return ret; - ret =pci_request_regions (pdev,"intel_pmc_ipc" ); + ret =pcim_iomap_regions (pdev,1 <<0 ,pci_name (pdev));if (ret)return ret; - pci_resource =pci_resource_start (pdev,0 ); - len =pci_resource_len (pdev,0 ); -if (!pci_resource || !len) { -dev_err (&pdev->dev,"Failed to get resource\n" ); -return -ENOMEM ; - } +init_completion (&pmc->cmd_complete); -init_completion (&ipcdev.cmd_complete); + pmc->ipc_base =pcim_iomap_table (pdev)[0 ]; -if (request_irq (pdev->irq, ioc,0 ,"intel_pmc_ipc" , &ipcdev)) { + 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" ); -return -EBUSY ; +return ret; } - ipcdev.ipc_base =ioremap_nocache (pci_resource, len); -if (!ipcdev.ipc_base) { -dev_err (&pdev->dev,"Failed to ioremap ipc base\n" ); -free_irq (pdev->irq, &ipcdev); - ret = -ENOMEM ; - } + pmc->dev = &pdev->dev; -return ret; -} +pci_set_drvdata (pdev, pmc); -static void ipc_pci_remove (struct pci_dev *pdev) -{ -free_irq (pdev->irq, &ipcdev); -pci_release_regions (pdev); -pci_dev_put (pdev); -iounmap (ipcdev.ipc_base); - ipcdev.dev =NULL ; +return 0 ; }static const struct pci_device_id ipc_pci_ids[] = {
@@ -540,7 +527,6 @@ static struct pci_driver ipc_pci_driver = { .name = "intel_pmc_ipc", .id_table = ipc_pci_ids, .probe = ipc_pci_probe, - .remove = ipc_pci_remove, }; static ssize_t intel_pmc_ipc_simple_cmd_store(struct device *dev,
@@ -849,18 +835,16 @@ static int ipc_plat_get_res(struct platform_device *pdev)dev_err (&pdev->dev,"Failed to get ipc resource\n" );return -ENXIO ; } - size =PLAT_RESOURCE_IPC_SIZE +PLAT_RESOURCE_GCR_SIZE ; + res->end = (res->start +PLAT_RESOURCE_IPC_SIZE + +PLAT_RESOURCE_GCR_SIZE -1 ); -if (!request_mem_region (res->start, size, pdev->name)) { -dev_err (&pdev->dev,"Failed to request ipc resource\n" ); -return -EBUSY ; - } - addr =ioremap_nocache (res->start, size); -if (!addr) { -dev_err (&pdev->dev,"I/O memory remapping failed\n" ); -release_mem_region (res->start, size); -return -ENOMEM ; + addr =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (addr)) { +dev_err (&pdev->dev, +"PMC I/O memory remapping failed\n" ); +return PTR_ERR (addr); } + ipcdev.ipc_base = addr; ipcdev.gcr_mem_base = addr +PLAT_RESOURCE_GCR_OFFSET ;
@@ -917,7 +901,6 @@ MODULE_DEVICE_TABLE(acpi, ipc_acpi_ids);static int ipc_plat_probe (struct platform_device *pdev) { -struct resource *res;int ret; ipcdev.dev = &pdev->dev;
@@ -939,61 +922,42 @@ static int ipc_plat_probe(struct platform_device *pdev) ret =ipc_create_pmc_devices ();if (ret) {dev_err (&pdev->dev,"Failed to create pmc devices\n" ); - goto err_device; +return ret; } -if (request_irq (ipcdev.irq, ioc,IRQF_NO_SUSPEND , -"intel_pmc_ipc" , &ipcdev)) { +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; + goto unregister_devices; } 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; + goto unregister_devices; } ipcdev.has_gcr_regs = true;return 0 ; -err_sys: -free_irq (ipcdev.irq, &ipcdev); -err_irq: + +unregister_devices:platform_device_unregister (ipcdev.tco_dev);platform_device_unregister (ipcdev.punit_dev);platform_device_unregister (ipcdev.telemetry_dev); -err_device: -iounmap (ipcdev.ipc_base); - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_IPC_INDEX ); -if (res) { -release_mem_region (res->start, -PLAT_RESOURCE_IPC_SIZE + -PLAT_RESOURCE_GCR_SIZE ); - } +return ret; }static int ipc_plat_remove (struct platform_device *pdev) { -struct resource *res; -sysfs_remove_group (&pdev->dev.kobj, &intel_ipc_group); -free_irq (ipcdev.irq, &ipcdev); +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); -iounmap (ipcdev.ipc_base); - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_IPC_INDEX ); -if (res) { -release_mem_region (res->start, -PLAT_RESOURCE_IPC_SIZE + -PLAT_RESOURCE_GCR_SIZE ); - } ipcdev.dev =NULL ;return 0 ; }
Signature · 1 line
2.7.4
RFC v3 3/7 platform/x86: intel_pmc_ipc: Use regmap calls for GCR updates
In reply to [email protected]From: Kuppuswamy Sathyanarayanan <[email protected]>
Currently, update_no_reboot_bit() function implemented in this driver uses mutex_lock to protect its register updates. But this function is called with in atomic context in iTCO_wdt_start() and iTCO_wdt_stop() functions in iTCO_wdt.c driver, which in turn causes "sleeping into atomic context" issue. This patch fixes this issue by refactoring the current GCR read/write/update functions with regmap APIs.
--- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_pmc_ipc.c | 115 ++++++++++++----------------------- 2 files changed, 40 insertions(+), 76 deletions(-)
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 +39 -76
187 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC v3 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 to use APIs provided by generic IPC driver.
--- arch/x86/include/asm/intel_pmc_ipc.h | 37 +-- drivers/mfd/intel_soc_pmic_bxtwc.c | 18 +- drivers/platform/x86/intel_pmc_ipc.c | 406 ++++++++++---------------- drivers/platform/x86/intel_telemetry_pltdrv.c | 118 ++++---- include/linux/mfd/intel_soc_pmic.h | 2 + 5 files changed, 238 insertions(+), 343 deletions(-)
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 +13 -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
@@ -28,13 +33,14 @@#define PMC_GCR_TELEM_DEEP_S0IX_REG 0x78#define PMC_GCR_TELEM_SHLW_S0IX_REG 0x80 +static inline void pmc_cmd_init (u32 *cmd,u32 param1,u32 param2) +{ + cmd[0 ] = param1; + cmd[1 ] = param2; +} +#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 +48,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 +12 -6
@@ -271,6 +271,8 @@ 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; +u32 cmd[PMC_PARAM_LEN ] = {PMC_IPC_PMIC_ACCESS , +PMC_IPC_PMIC_ACCESS_READ };if (!pmic)return -EINVAL ;
@@ -284,9 +286,8 @@ static int regmap_ipc_byte_reg_read(void *context, unsigned int reg, ipc_in[0 ] = reg; ipc_in[1 ] = i2c_addr; - ret =intel_pmc_ipc_command (PMC_IPC_PMIC_ACCESS , -PMC_IPC_PMIC_ACCESS_READ , - ipc_in,sizeof (ipc_in), (u32 *)ipc_out,1 ); + ret =ipc_dev_raw_cmd (pmic->ipc_dev, cmd,PMC_PARAM_LEN , ipc_in, +sizeof (ipc_in), (u32 *)ipc_out,1 ,0 ,0 );if (ret) {dev_err (pmic->dev,"Failed to read from PMIC\n" );return ret;
@@ -303,6 +304,8 @@ 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; +u32 cmd[PMC_PARAM_LEN ] = {PMC_IPC_PMIC_ACCESS , +PMC_IPC_PMIC_ACCESS_WRITE };if (!pmic)return -EINVAL ;
@@ -317,9 +320,8 @@ static int regmap_ipc_byte_reg_write(void *context, unsigned int reg, ipc_in[0 ] = reg; ipc_in[1 ] = i2c_addr; ipc_in[2 ] = val; - ret =intel_pmc_ipc_command (PMC_IPC_PMIC_ACCESS , -PMC_IPC_PMIC_ACCESS_WRITE , - ipc_in,sizeof (ipc_in),NULL ,0 ); + ret =ipc_dev_raw_cmd (pmic->ipc_dev, cmd,PMC_PARAM_LEN , ipc_in, +sizeof (ipc_in),NULL ,0 ,0 ,0 );if (ret) {dev_err (pmic->dev,"Failed to write to PMIC\n" );return ret;
@@ -445,6 +447,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" );
drivers/platform/x86/intel_pmc_ipc.c +153 -253
590 lines not on this page · raw message
drivers/platform/x86/intel_telemetry_pltdrv.c +58 -60
232 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
Re: [RFC v3 7/7] platform/x86: intel_scu_ipc: Use generic Intel IPC device calls
In reply to [email protected]Quoted 9 lines · On 04/09/2017 at 22:37:27 -0700, sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9…
From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9/[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 to use APIs provided by generic IPC driver.
For the RTC part:
Quoted 888 lines
--- arch/x86/include/asm/intel_scu_ipc.h | 23 +- arch/x86/platform/intel-mid/intel-mid.c | 12 +- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_scu_ipc.c | 483 +++++++++++++------------------- drivers/rtc/rtc-mrst.c | 15 +- drivers/watchdog/intel-mid_wdt.c | 12 +- drivers/watchdog/intel_scu_watchdog.c | 17 +- 7 files changed, 251 insertions(+), 312 deletions(-)arch/x86/include/asm/intel_scu_ipc.h +13
-10@@ -14,9 +14,19 @@#define IPCMSG_COLD_BOOT 0xF3#define IPCMSG_VRTC 0xFA/* Set vRTC device */ -/* Command id associated with message IPCMSG_VRTC */ -#define IPC_CMD_VRTC_SETTIME 1/* Set time */ -#define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ + +/* Command id associated with message IPCMSG_VRTC */ +#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 + +static inline void scu_cmd_init (u32 *cmd,u32 param1,u32 param2) +{ + cmd[0 ] = param1; + cmd[1 ] = param2; +}/* Read single register */ int intel_scu_ipc_ioread8 (u16 addr,u8 *data);@@ -45,13 +55,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 +10
-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> @@ -68,18 +69,23 @@ static void *(*get_intel_mid_ops[])(void) = INTEL_MID_OPS_INIT;enum intel_mid_cpu_type __intel_mid_cpu_chip;EXPORT_SYMBOL_GPL (__intel_mid_cpu_chip); +static struct intel_ipc_dev *ipc_dev; +static void intel_mid_power_off (void ) { +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_COLD_OFF ,1 };/* Shut down South Complex via PWRMU */ intel_mid_pwr_power_off ();/* 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 ); };static void intel_mid_reboot (void ) { -intel_scu_ipc_simple_command (IPCMSG_COLD_BOOT ,0 ); +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_COLD_BOOT ,0 }; + +ipc_dev_simple_cmd (ipc_dev, cmds,SCU_PARAM_LEN ); }static unsigned long __init intel_mid_calibrate_tsc (void )@@ -206,6 +212,8 @@ void __init x86_intel_mid_early_setup(void) x86_init.mpparse.find_smp_config = x86_init_noop; x86_init.mpparse.get_smp_config = x86_init_uint_noop;set_bit (MP_BUS_ISA , mp_bus_not_pci); + + ipc_dev =intel_ipc_dev_get (INTEL_SCU_IPC_DEV ); }/* 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 ondrivers/platform/x86/intel_scu_ipc.c +195
-288@@ -24,6 +24,8 @@#include <linux/pci.h> #include <linux/interrupt.h> #include <linux/sfi.h> +#include <linux/regmap.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> #include <asm/intel-mid.h> #include <asm/intel_scu_ipc.h> @@ -39,6 +41,25 @@#define IPC_CMD_PCNTRL_R 1/* Register read */ #define IPC_CMD_PCNTRL_M 2/* Register read-modify-write */ +/* IPC dev register offsets */ +/* +* IPC Read Buffer (Read Only): +* 16 byte buffer for receiving data from SCU, if IPC command +* processing results in response data +*/ +#define IPC_DEV_SCU_RBUF_OFFSET 0x90 +#define IPC_DEV_SCU_WRBUF_OFFSET 0x80 +#define IPC_DEV_SCU_SPTR_OFFSET 0x08 +#define IPC_DEV_SCU_DPTR_OFFSET 0x0C +#define IPC_DEV_SCU_STATUS_OFFSET 0x04 + +/* IPC dev commands */ +/* IPC command register IOC bit */ +#define IPC_DEV_SCU_CMD_MSI BIT(8) +#define IPC_DEV_SCU_CMD_STATUS_ERR BIT(1) +#define IPC_DEV_SCU_CMD_STATUS_ERR_MASK GENMASK(7, 0) +#define IPC_DEV_SCU_CMD_STATUS_BUSY BIT(0) +/* * IPC register summary * @@ -59,6 +80,11 @@#define IPC_WWBUF_SIZE 20/* IPC Write buffer Size */ #define IPC_RWBUF_SIZE 20/* IPC Read buffer Size */ #define IPC_IOC 0x100/* IPC command register IOC bit */ +#define IPC_CMD_SIZE 16 +#define IPC_CMD_SUBCMD 12 +#define IPC_RWBUF_SIZE_DWORD 5 +#define IPC_WWBUF_SIZE_DWORD 5 +#define PCI_DEVICE_ID_LINCROFT 0x082a#define PCI_DEVICE_ID_PENWELL 0x080e@@ -93,140 +119,49 @@ static struct intel_scu_ipc_pdata_t intel_scu_ipc_tangier_pdata = {struct intel_scu_ipc_dev {struct device *dev; +struct intel_ipc_dev *ipc_dev;void __iomem *ipc_base;void __iomem *i2c_base; -struct completion cmd_complete; +struct regmap *ipc_regs; +struct regmap *i2c_regs;u8 irq_mode; }; -static struct intel_scu_ipc_dev ipcdev;/* Only one for now */ +static struct regmap_config ipc_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , +}; -/* -* IPC Read Buffer (Read Only): -* 16 byte buffer for receiving data from SCU, if IPC command -* processing results in response data -*/ -#define IPC_READ_BUFFER 0x90 +static struct regmap_config i2c_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .fast_io = true, +}; + +static struct intel_scu_ipc_dev ipcdev;/* Only one for now */ #define IPC_I2C_CNTRL_ADDR 0#define I2C_DATA_ADDR 0x04 -static DEFINE_MUTEX (ipclock);/* lock used to prevent multiple call to SCU */ - -/* -* Send ipc command -* Command Register (Write Only): -* A write to this register results in an interrupt to the SCU core processor -* Format: -* |rfu2(8) | size(8) | command id(4) | rfu1(3) | ioc(1) | command(8)| -*/ -static inline void ipc_command (struct intel_scu_ipc_dev *scu,u32 cmd) -{ -if (scu->irq_mode) { -reinit_completion (&scu->cmd_complete); -writel (cmd |IPC_IOC , scu->ipc_base); - } -writel (cmd, scu->ipc_base); -} - -/* -* Write ipc data -* IPC Write Buffer (Write Only): -* 16-byte buffer for sending data associated with IPC command to -* SCU. Size of the data is specified in the IPC_COMMAND_REG register -*/ -static inline void ipc_data_writel (struct intel_scu_ipc_dev *scu,u32 data,u32 offset) -{ -writel (data, scu->ipc_base +0x80 + offset); -} - -/* -* Status Register (Read Only): -* Driver will read this register to get the ready/busy status of the IPC -* block and error status of the IPC command that was just processed by SCU -* Format: -* |rfu3(8)|error code(8)|initiator id(8)|cmd id(4)|rfu1(2)|error(1)|busy(1)| -*/ -static inline u8 ipc_read_status (struct intel_scu_ipc_dev *scu) -{ -return __raw_readl (scu->ipc_base +0x04 ); -} - -/* Read ipc byte data */ -static inline u8 ipc_data_readb (struct intel_scu_ipc_dev *scu,u32 offset) -{ -return readb (scu->ipc_base +IPC_READ_BUFFER + offset); -} - -/* Read ipc u32 data */ -static inline u32 ipc_data_readl (struct intel_scu_ipc_dev *scu,u32 offset) -{ -return readl (scu->ipc_base +IPC_READ_BUFFER + offset); -} - -/* Wait till scu status is busy */ -static inline int busy_loop (struct intel_scu_ipc_dev *scu) -{ -u32 status =ipc_read_status (scu); -u32 loop_count =100000 ; - -/* break if scu doesn't reset busy bit after huge retry */ -while ((status &BIT (0 )) && --loop_count) { -udelay (1 );/* scu processing time is in few u secods */ - status =ipc_read_status (scu); - } - -if (status &BIT (0 )) { -dev_err (scu->dev,"IPC timed out" ); -return -ETIMEDOUT ; - } - -if (status &BIT (1 )) -return -EIO ; - -return 0 ; -} - -/* Wait till ipc ioc interrupt is received or timeout in 3 HZ */ -static inline int ipc_wait_for_interrupt (struct intel_scu_ipc_dev *scu) -{ -int status; - -if (!wait_for_completion_timeout (&scu->cmd_complete,3 *HZ )) { -dev_err (scu->dev,"IPC timed out\n" ); -return -ETIMEDOUT ; - } - - status =ipc_read_status (scu); -if (status &BIT (1 )) -return -EIO ; - -return 0 ; -} - -static int intel_scu_ipc_check_status (struct intel_scu_ipc_dev *scu) -{ -return scu->irq_mode ?ipc_wait_for_interrupt (scu) :busy_loop (scu); -} -/* Read/Write power control(PMIC in Langwell, MSIC in PenWell) registers */ static int pwr_reg_rdwr (u16 *addr,u8 *data,u32 count,u32 op,u32 id) {struct intel_scu_ipc_dev *scu = &ipcdev;int nc;u32 offset =0 ; -int err; +int err = -EIO ;u8 cbuf[IPC_WWBUF_SIZE ];u32 *wbuf = (u32 *)&cbuf; +u32 cmd[SCU_PARAM_LEN ] = {0 }; +/* max rbuf size is 20 bytes */ +u8 rbuf[IPC_RWBUF_SIZE ] = {0 }; +u32 rbuflen =DIV_ROUND_UP (count,4 );memset (cbuf,0 ,sizeof (cbuf)); -mutex_lock (&ipclock); - -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } +scu_cmd_init (cmd, op, id);for (nc =0 ; nc < count; nc++, offset +=2 ) { cbuf[offset] = addr[nc];@@ -234,30 +169,30 @@ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) }if (id ==IPC_CMD_PCNTRL_R ) { -for (nc =0 , offset =0 ; nc < count; nc++, offset +=4 ) -ipc_data_writel (scu, wbuf[nc], offset); -ipc_command (scu, (count *2 ) <<16 | id <<12 |0 <<8 | op); + err =ipc_dev_raw_cmd (scu->ipc_dev, cmd,SCU_PARAM_LEN , + (u8 *)wbuf, count *2 , (u32 *)rbuf, +IPC_RWBUF_SIZE_DWORD ,0 ,0 ); }else if (id ==IPC_CMD_PCNTRL_W ) {for (nc =0 ; nc < count; nc++, offset +=1 ) cbuf[offset] = data[nc]; -for (nc =0 , offset =0 ; nc < count; nc++, offset +=4 ) -ipc_data_writel (scu, wbuf[nc], offset); -ipc_command (scu, (count *3 ) <<16 | id <<12 |0 <<8 | op); + err =ipc_dev_raw_cmd (scu->ipc_dev, cmd,SCU_PARAM_LEN , + (u8 *)wbuf, count *3 ,NULL ,0 ,0 ,0 ); + }else if (id ==IPC_CMD_PCNTRL_M ) { cbuf[offset] = data[0 ]; cbuf[offset +1 ] = data[1 ]; -ipc_data_writel (scu, wbuf[0 ],0 );/* Write wbuff */ -ipc_command (scu,4 <<16 | id <<12 |0 <<8 | op); + err =ipc_dev_raw_cmd (scu->ipc_dev, cmd,SCU_PARAM_LEN , + (u8 *)wbuf,4 ,NULL ,0 ,0 ,0 ); } - err =intel_scu_ipc_check_status (scu);if (!err && id ==IPC_CMD_PCNTRL_R ) {/* Read rbuf */ /* Workaround: values are read as 0 without memcpy_fromio */ memcpy_fromio (cbuf, scu->ipc_base +0x90 ,16 ); -for (nc =0 ; nc < count; nc++) - data[nc] =ipc_data_readb (scu, nc); +regmap_bulk_read (scu->ipc_regs,IPC_DEV_SCU_RBUF_OFFSET , + rbuf, rbuflen); +memcpy (data, rbuf, count); } -mutex_unlock (&ipclock); +return err; }@@ -422,138 +357,6 @@ int intel_scu_ipc_update_register(u16 addr, u8 bits, u8 mask) }EXPORT_SYMBOL (intel_scu_ipc_update_register); -/** -* intel_scu_ipc_simple_command - send a simple command -* @cmd: command -* @sub: sub type -* -* Issue a simple command to the SCU. Do not use this interface if -* you must then access data as any data values may be overwritten -* by another SCU access by the time this function returns. -* -* This function may sleep. Locking for SCU accesses is handled for -* the caller. -*/ -int intel_scu_ipc_simple_command (int cmd,int sub) -{ -struct intel_scu_ipc_dev *scu = &ipcdev; -int err; - -mutex_lock (&ipclock); -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } -ipc_command (scu, sub <<12 | cmd); - err =intel_scu_ipc_check_status (scu); -mutex_unlock (&ipclock); -return err; -} -EXPORT_SYMBOL (intel_scu_ipc_simple_command); - -/** -* intel_scu_ipc_command - command with data -* @cmd: command -* @sub: sub type -* @in: input data -* @inlen: input length in dwords -* @out: output data -* @outlein: output length in dwords -* -* Issue a command to the SCU which involves data transfers. Do the -* data copies under the lock but leave it for the caller to interpret -*/ -int intel_scu_ipc_command (int cmd,int sub,u32 *in,int inlen, -u32 *out,int outlen) -{ -struct intel_scu_ipc_dev *scu = &ipcdev; -int i, err; - -mutex_lock (&ipclock); -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } - -for (i =0 ; i < inlen; i++) -ipc_data_writel (scu, *in++,4 * i); - -ipc_command (scu, (inlen <<16 ) | (sub <<12 ) | cmd); - err =intel_scu_ipc_check_status (scu); - -if (!err) { -for (i =0 ; i < outlen; i++) - *out++ =ipc_data_readl (scu,4 * i); - } - -mutex_unlock (&ipclock); -return err; -} -EXPORT_SYMBOL (intel_scu_ipc_command); - -#define IPC_SPTR 0x08 -#define IPC_DPTR 0x0C - -/** -* intel_scu_ipc_raw_command() - IPC command with data and pointers -* @cmd: IPC command code. -* @sub: IPC command sub type. -* @in: input data of this IPC command. -* @inlen: input data length in dwords. -* @out: output data of this IPC command. -* @outlen: output data length in dwords. -* @sptr: data writing to SPTR register. -* @dptr: data writing to DPTR register. -* -* Send an IPC command to SCU with input/output data and source/dest pointers. -* -* Return: an IPC error code or 0 on success. -*/ -int intel_scu_ipc_raw_command (int cmd,int sub,u8 *in,int inlen, -u32 *out,int outlen,u32 dptr,u32 sptr) -{ -struct intel_scu_ipc_dev *scu = &ipcdev; -int inbuflen =DIV_ROUND_UP (inlen,4 ); -u32 inbuf[4 ]; -int i, err; - -/* Up to 16 bytes */ -if (inbuflen >4 ) -return -EINVAL ; - -mutex_lock (&ipclock); -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } - -writel (dptr, scu->ipc_base +IPC_DPTR ); -writel (sptr, scu->ipc_base +IPC_SPTR ); - -/* -* SRAM controller doesn't support 8-bit writes, it only -* supports 32-bit writes, so we have to copy input data into -* the temporary buffer, and SCU FW will use the inlen to -* determine the actual input data length in the temporary -* buffer. -*/ -memcpy (inbuf, in, inlen); - -for (i =0 ; i < inbuflen; i++) -ipc_data_writel (scu, inbuf[i],4 * i); - -ipc_command (scu, (inlen <<16 ) | (sub <<12 ) | cmd); - err =intel_scu_ipc_check_status (scu); -if (!err) { -for (i =0 ; i < outlen; i++) - *out++ =ipc_data_readl (scu,4 * i); - } - -mutex_unlock (&ipclock); -return err; -} -EXPORT_SYMBOL_GPL (intel_scu_ipc_raw_command); -/* I2C commands */ #define IPC_I2C_WRITE 1/* I2C Write command */ #define IPC_I2C_READ 2/* I2C Read command */ @@ -575,48 +378,143 @@ int intel_scu_ipc_i2c_cntrl(u32 addr, u32 *data)struct intel_scu_ipc_dev *scu = &ipcdev;u32 cmd =0 ; -mutex_lock (&ipclock); -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } cmd = (addr >>24 ) &0xFF ;if (cmd ==IPC_I2C_READ ) { -writel (addr, scu->i2c_base +IPC_I2C_CNTRL_ADDR ); +regmap_write (scu->i2c_regs,IPC_I2C_CNTRL_ADDR , addr);/* Write not getting updated without delay */ mdelay (1 ); - *data =readl (scu->i2c_base +I2C_DATA_ADDR ); +regmap_read (scu->i2c_regs,I2C_DATA_ADDR , data); }else if (cmd ==IPC_I2C_WRITE ) { -writel (*data, scu->i2c_base +I2C_DATA_ADDR ); +regmap_write (scu->i2c_regs,I2C_DATA_ADDR , *data);mdelay (1 ); -writel (addr, scu->i2c_base +IPC_I2C_CNTRL_ADDR ); +regmap_write (scu->i2c_regs,IPC_I2C_CNTRL_ADDR , addr); }else {dev_err (scu->dev,"intel_scu_ipc: I2C INVALID_CMD = 0x%x\n" , cmd); -mutex_unlock (&ipclock);return -EIO ; } -mutex_unlock (&ipclock);return 0 ; }EXPORT_SYMBOL (intel_scu_ipc_i2c_cntrl); -/* -* Interrupt handler gets called when ioc bit of IPC_COMMAND_REG set to 1 -* When ioc bit is set to 1, caller api must wait for interrupt handler called -* which in turn unlocks the caller api. Currently this is not used -* -* This is edge triggered so we need take no action to clear anything -*/ -static irqreturn_t ioc (int irq,void *dev_id) +static int pre_simple_cmd_fn (u32 *cmd_list,u32 cmdlen) { -struct intel_scu_ipc_dev *scu = dev_id; +if (!cmd_list || cmdlen !=SCU_PARAM_LEN ) +return -EINVAL ; -if (scu->irq_mode) -complete (&scu->cmd_complete); + cmd_list[0 ] |= (cmd_list[1 ] <<IPC_CMD_SUBCMD ); -return IRQ_HANDLED ; +return 0 ; +} + +static int pre_cmd_fn (u32 *cmd_list,u32 cmdlen,u32 *in,u32 inlen, +u32 *out,u32 outlen) +{ +int ret; + +if (inlen >IPC_WWBUF_SIZE_DWORD || outlen >IPC_RWBUF_SIZE_DWORD ) +return -EINVAL ; + + ret =pre_simple_cmd_fn (cmd_list, cmdlen); +if (ret <0 ) +return ret; + + cmd_list[0 ] |= (inlen <<IPC_CMD_SIZE ); + +return 0 ; +} + +static int pre_raw_cmd_fn (u32 *cmd_list,u32 cmdlen,u8 *in,u32 inlen, +u32 *out,u32 outlen,u32 dptr,u32 sptr) +{ +int ret; + +if (inlen >IPC_WWBUF_SIZE || outlen >IPC_RWBUF_SIZE_DWORD ) +return -EINVAL ; + + ret =pre_simple_cmd_fn (cmd_list, cmdlen); +if (ret <0 ) +return ret; + + cmd_list[0 ] |= (inlen <<IPC_CMD_SIZE ); + +return 0 ; +} + +static int scu_ipc_err_code (int status) +{ +if (status &IPC_DEV_SCU_CMD_STATUS_ERR ) +return (status &IPC_DEV_SCU_CMD_STATUS_ERR_MASK ); +else +return 0 ; +} + +static int scu_ipc_busy_check (int status) +{ +return status |IPC_DEV_SCU_CMD_STATUS_BUSY ; +} + +static u32 scu_ipc_enable_msi (u32 cmd) +{ +return cmd |IPC_DEV_SCU_CMD_MSI ; +} + +static struct intel_ipc_dev *intel_scu_ipc_dev_create ( +struct device *dev, +void __iomem *base, +int irq) +{ +struct intel_ipc_dev_ops *ops; +struct intel_ipc_dev_cfg *cfg; +struct regmap *ipc_regs; +struct intel_scu_ipc_dev *scu =dev_get_drvdata (dev); + + cfg =devm_kzalloc (dev,sizeof (*cfg),GFP_KERNEL ); +if (!cfg) +return ERR_PTR (-ENOMEM ); + + ops =devm_kzalloc (dev,sizeof (*ops),GFP_KERNEL ); +if (!ops) +return ERR_PTR (-ENOMEM ); + + ipc_regs =devm_regmap_init_mmio_clk (dev,NULL , base, + &ipc_regmap_config); +if (IS_ERR (ipc_regs)) { +dev_err (dev,"ipc_regs regmap init failed\n" ); +return ERR_CAST (ipc_regs);; + } + + scu->ipc_regs = ipc_regs; + +/* set IPC dev ops */ + ops->to_err_code = scu_ipc_err_code; + ops->busy_check = scu_ipc_busy_check; + ops->enable_msi = scu_ipc_enable_msi; + ops->pre_cmd_fn = pre_cmd_fn; + ops->pre_raw_cmd_fn = pre_raw_cmd_fn; + ops->pre_simple_cmd_fn = pre_simple_cmd_fn; + +/* set cfg options */ +if (scu->irq_mode) + cfg->mode =IPC_DEV_MODE_IRQ ; +else + cfg->mode =IPC_DEV_MODE_POLLING ; + + cfg->chan_type =IPC_CHANNEL_IA_SCU ; + cfg->irq = irq; + cfg->use_msi = true; + cfg->support_sptr = true; + cfg->support_dptr = true; + cfg->cmd_regs = ipc_regs; + cfg->data_regs = ipc_regs; + cfg->wrbuf_reg =IPC_DEV_SCU_WRBUF_OFFSET ; + cfg->rbuf_reg =IPC_DEV_SCU_RBUF_OFFSET ; + cfg->sptr_reg =IPC_DEV_SCU_SPTR_OFFSET ; + cfg->dptr_reg =IPC_DEV_SCU_DPTR_OFFSET ; + cfg->status_reg =IPC_DEV_SCU_STATUS_OFFSET ; + +return devm_intel_ipc_dev_create (dev,INTEL_SCU_IPC_DEV , cfg, ops); }/** @@ -650,25 +548,34 @@ static int ipc_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (err)return err; -init_completion (&scu->cmd_complete); - scu->ipc_base =pcim_iomap_table (pdev)[0 ]; - scu->i2c_base =ioremap_nocache (pdata->i2c_base, pdata->i2c_len); + scu->i2c_base =devm_ioremap_nocache (&pdev->dev, pdata->i2c_base, + pdata->i2c_len);if (!scu->i2c_base)return -ENOMEM ; - err =devm_request_irq (&pdev->dev, pdev->irq, ioc,0 ,"intel_scu_ipc" , - scu); -if (err) -return err; +pci_set_drvdata (pdev, scu); + + scu->i2c_regs =devm_regmap_init_mmio_clk (&pdev->dev,NULL , + scu->i2c_base, &i2c_regmap_config); +if (IS_ERR (scu->i2c_regs)) { +dev_err (&pdev->dev,"i2c_regs regmap init failed\n" ); +return PTR_ERR (scu->i2c_regs);; + } + + scu->ipc_dev =intel_scu_ipc_dev_create (&pdev->dev, scu->ipc_base, + pdev->irq); +if (IS_ERR (scu->ipc_dev)) { +dev_err (&pdev->dev,"Failed to create SCU IPC device\n" ); +return PTR_ERR (scu->ipc_dev); + }/* Assign device at last */ scu->dev = &pdev->dev;intel_scu_devices_create (); -pci_set_drvdata (pdev, scu);return 0 ; }drivers/rtc/rtc-mrst.c +11
-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) {drivers/watchdog/intel-mid_wdt.c +11
-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,10 @@ 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}; + +return ipc_dev_cmd (scu_ipc_dev, cmds,SCU_PARAM_LEN , in, + inlen,NULL ,0 ); }static int wdt_start (struct watchdog_device *wd)@@ -129,6 +135,10 @@ static int mid_wdt_probe(struct platform_device *pdev)if (!wdt_dev)return -ENOMEM ; + 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); + 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 +10
-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,18 +131,14 @@ 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 }; 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_ret =ipc_dev_cmd (scu_ipc_dev, cmds,SCU_PARAM_LEN , ipc_wbuf, +2 ,NULL ,0 );if (ipc_ret !=0 )pr_err ("Error setting SCU watchdog timer: %x\n" , ipc_ret);@@ -460,6 +459,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 ) {Signature · 1 line
2.7.4
Signature · 7 lines
Alexandre Belloni, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -- 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
Guenter Roeck
maintainerRe: [RFC v3 7/7] platform/x86: intel_scu_ipc: Use generic Intel IPC device calls
Quoted 6 lines · Alexandre Belloni
Quoted 5 lines · On 04/09/2017 at 22:37:27 -0700, [email protected]…
From: Kuppuswamy Sathyanarayanan <[email protected]>
Removed redundant IPC helper functions and refactored the driver to use generic IPC device driver APIs.
Quoted 17 lines
Quoted 4 lines
This patch also cleans-up SCU IPC user drivers to use APIs provided by generic IPC driver.
Signed-off-by Kuppuswamy Sathyanarayanan <[email protected]>For the RTC part:
Quoted 10 lines
--- arch/x86/include/asm/intel_scu_ipc.h | 23 +- arch/x86/platform/intel-mid/intel-mid.c | 12 +- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_scu_ipc.c | 483 +++++++++++++------------------- drivers/rtc/rtc-mrst.c | 15 +- drivers/watchdog/intel-mid_wdt.c | 12 +- drivers/watchdog/intel_scu_watchdog.c | 17 +- 7 files changed, 251 insertions(+), 312 deletions(-)
I think it would help in general to mention at least in the description which drivers are touched.
I see calls to intel_ipc_dev_get() but not associated put calls. Missing the context, it may well be that those are not necessary, but then how does the ipc code know that the device reference is no longer needed ?
Guenter
Quoted 880 lines
Quoted 879 lines
arch/x86/include/asm/intel_scu_ipc.h +13
-10@@ -14,9 +14,19 @@#define IPCMSG_COLD_BOOT 0xF3#define IPCMSG_VRTC 0xFA/* Set vRTC device */ -/* Command id associated with message IPCMSG_VRTC */ -#define IPC_CMD_VRTC_SETTIME 1/* Set time */ -#define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ + +/* Command id associated with message IPCMSG_VRTC */ +#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 + +static inline void scu_cmd_init (u32 *cmd,u32 param1,u32 param2) +{ + cmd[0 ] = param1; + cmd[1 ] = param2; +}/* Read single register */ int intel_scu_ipc_ioread8 (u16 addr,u8 *data);@@ -45,13 +55,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 +10
-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> @@ -68,18 +69,23 @@ static void *(*get_intel_mid_ops[])(void) = INTEL_MID_OPS_INIT;enum intel_mid_cpu_type __intel_mid_cpu_chip;EXPORT_SYMBOL_GPL (__intel_mid_cpu_chip); +static struct intel_ipc_dev *ipc_dev; +static void intel_mid_power_off (void ) { +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_COLD_OFF ,1 };/* Shut down South Complex via PWRMU */ intel_mid_pwr_power_off ();/* 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 ); };static void intel_mid_reboot (void ) { -intel_scu_ipc_simple_command (IPCMSG_COLD_BOOT ,0 ); +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_COLD_BOOT ,0 }; + +ipc_dev_simple_cmd (ipc_dev, cmds,SCU_PARAM_LEN ); }static unsigned long __init intel_mid_calibrate_tsc (void )@@ -206,6 +212,8 @@ void __init x86_intel_mid_early_setup(void) x86_init.mpparse.find_smp_config = x86_init_noop; x86_init.mpparse.get_smp_config = x86_init_uint_noop;set_bit (MP_BUS_ISA , mp_bus_not_pci); + + ipc_dev =intel_ipc_dev_get (INTEL_SCU_IPC_DEV ); }/* 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 ondrivers/platform/x86/intel_scu_ipc.c +195
-288@@ -24,6 +24,8 @@#include <linux/pci.h> #include <linux/interrupt.h> #include <linux/sfi.h> +#include <linux/regmap.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> #include <asm/intel-mid.h> #include <asm/intel_scu_ipc.h> @@ -39,6 +41,25 @@#define IPC_CMD_PCNTRL_R 1/* Register read */ #define IPC_CMD_PCNTRL_M 2/* Register read-modify-write */ +/* IPC dev register offsets */ +/* +* IPC Read Buffer (Read Only): +* 16 byte buffer for receiving data from SCU, if IPC command +* processing results in response data +*/ +#define IPC_DEV_SCU_RBUF_OFFSET 0x90 +#define IPC_DEV_SCU_WRBUF_OFFSET 0x80 +#define IPC_DEV_SCU_SPTR_OFFSET 0x08 +#define IPC_DEV_SCU_DPTR_OFFSET 0x0C +#define IPC_DEV_SCU_STATUS_OFFSET 0x04 + +/* IPC dev commands */ +/* IPC command register IOC bit */ +#define IPC_DEV_SCU_CMD_MSI BIT(8) +#define IPC_DEV_SCU_CMD_STATUS_ERR BIT(1) +#define IPC_DEV_SCU_CMD_STATUS_ERR_MASK GENMASK(7, 0) +#define IPC_DEV_SCU_CMD_STATUS_BUSY BIT(0) +/* * IPC register summary * @@ -59,6 +80,11 @@#define IPC_WWBUF_SIZE 20/* IPC Write buffer Size */ #define IPC_RWBUF_SIZE 20/* IPC Read buffer Size */ #define IPC_IOC 0x100/* IPC command register IOC bit */ +#define IPC_CMD_SIZE 16 +#define IPC_CMD_SUBCMD 12 +#define IPC_RWBUF_SIZE_DWORD 5 +#define IPC_WWBUF_SIZE_DWORD 5 +#define PCI_DEVICE_ID_LINCROFT 0x082a#define PCI_DEVICE_ID_PENWELL 0x080e@@ -93,140 +119,49 @@ static struct intel_scu_ipc_pdata_t intel_scu_ipc_tangier_pdata = {struct intel_scu_ipc_dev {struct device *dev; +struct intel_ipc_dev *ipc_dev;void __iomem *ipc_base;void __iomem *i2c_base; -struct completion cmd_complete; +struct regmap *ipc_regs; +struct regmap *i2c_regs;u8 irq_mode; }; -static struct intel_scu_ipc_dev ipcdev;/* Only one for now */ +static struct regmap_config ipc_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , +}; -/* -* IPC Read Buffer (Read Only): -* 16 byte buffer for receiving data from SCU, if IPC command -* processing results in response data -*/ -#define IPC_READ_BUFFER 0x90 +static struct regmap_config i2c_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .fast_io = true, +}; + +static struct intel_scu_ipc_dev ipcdev;/* Only one for now */ #define IPC_I2C_CNTRL_ADDR 0#define I2C_DATA_ADDR 0x04 -static DEFINE_MUTEX (ipclock);/* lock used to prevent multiple call to SCU */ - -/* -* Send ipc command -* Command Register (Write Only): -* A write to this register results in an interrupt to the SCU core processor -* Format: -* |rfu2(8) | size(8) | command id(4) | rfu1(3) | ioc(1) | command(8)| -*/ -static inline void ipc_command (struct intel_scu_ipc_dev *scu,u32 cmd) -{ -if (scu->irq_mode) { -reinit_completion (&scu->cmd_complete); -writel (cmd |IPC_IOC , scu->ipc_base); - } -writel (cmd, scu->ipc_base); -} - -/* -* Write ipc data -* IPC Write Buffer (Write Only): -* 16-byte buffer for sending data associated with IPC command to -* SCU. Size of the data is specified in the IPC_COMMAND_REG register -*/ -static inline void ipc_data_writel (struct intel_scu_ipc_dev *scu,u32 data,u32 offset) -{ -writel (data, scu->ipc_base +0x80 + offset); -} - -/* -* Status Register (Read Only): -* Driver will read this register to get the ready/busy status of the IPC -* block and error status of the IPC command that was just processed by SCU -* Format: -* |rfu3(8)|error code(8)|initiator id(8)|cmd id(4)|rfu1(2)|error(1)|busy(1)| -*/ -static inline u8 ipc_read_status (struct intel_scu_ipc_dev *scu) -{ -return __raw_readl (scu->ipc_base +0x04 ); -} - -/* Read ipc byte data */ -static inline u8 ipc_data_readb (struct intel_scu_ipc_dev *scu,u32 offset) -{ -return readb (scu->ipc_base +IPC_READ_BUFFER + offset); -} - -/* Read ipc u32 data */ -static inline u32 ipc_data_readl (struct intel_scu_ipc_dev *scu,u32 offset) -{ -return readl (scu->ipc_base +IPC_READ_BUFFER + offset); -} - -/* Wait till scu status is busy */ -static inline int busy_loop (struct intel_scu_ipc_dev *scu) -{ -u32 status =ipc_read_status (scu); -u32 loop_count =100000 ; - -/* break if scu doesn't reset busy bit after huge retry */ -while ((status &BIT (0 )) && --loop_count) { -udelay (1 );/* scu processing time is in few u secods */ - status =ipc_read_status (scu); - } - -if (status &BIT (0 )) { -dev_err (scu->dev,"IPC timed out" ); -return -ETIMEDOUT ; - } - -if (status &BIT (1 )) -return -EIO ; - -return 0 ; -} - -/* Wait till ipc ioc interrupt is received or timeout in 3 HZ */ -static inline int ipc_wait_for_interrupt (struct intel_scu_ipc_dev *scu) -{ -int status; - -if (!wait_for_completion_timeout (&scu->cmd_complete,3 *HZ )) { -dev_err (scu->dev,"IPC timed out\n" ); -return -ETIMEDOUT ; - } - - status =ipc_read_status (scu); -if (status &BIT (1 )) -return -EIO ; - -return 0 ; -} - -static int intel_scu_ipc_check_status (struct intel_scu_ipc_dev *scu) -{ -return scu->irq_mode ?ipc_wait_for_interrupt (scu) :busy_loop (scu); -} -/* Read/Write power control(PMIC in Langwell, MSIC in PenWell) registers */ static int pwr_reg_rdwr (u16 *addr,u8 *data,u32 count,u32 op,u32 id) {struct intel_scu_ipc_dev *scu = &ipcdev;int nc;u32 offset =0 ; -int err; +int err = -EIO ;u8 cbuf[IPC_WWBUF_SIZE ];u32 *wbuf = (u32 *)&cbuf; +u32 cmd[SCU_PARAM_LEN ] = {0 }; +/* max rbuf size is 20 bytes */ +u8 rbuf[IPC_RWBUF_SIZE ] = {0 }; +u32 rbuflen =DIV_ROUND_UP (count,4 );memset (cbuf,0 ,sizeof (cbuf)); -mutex_lock (&ipclock); - -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } +scu_cmd_init (cmd, op, id);for (nc =0 ; nc < count; nc++, offset +=2 ) { cbuf[offset] = addr[nc];@@ -234,30 +169,30 @@ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) }if (id ==IPC_CMD_PCNTRL_R ) { -for (nc =0 , offset =0 ; nc < count; nc++, offset +=4 ) -ipc_data_writel (scu, wbuf[nc], offset); -ipc_command (scu, (count *2 ) <<16 | id <<12 |0 <<8 | op); + err =ipc_dev_raw_cmd (scu->ipc_dev, cmd,SCU_PARAM_LEN , + (u8 *)wbuf, count *2 , (u32 *)rbuf, +IPC_RWBUF_SIZE_DWORD ,0 ,0 ); }else if (id ==IPC_CMD_PCNTRL_W ) {for (nc =0 ; nc < count; nc++, offset +=1 ) cbuf[offset] = data[nc]; -for (nc =0 , offset =0 ; nc < count; nc++, offset +=4 ) -ipc_data_writel (scu, wbuf[nc], offset); -ipc_command (scu, (count *3 ) <<16 | id <<12 |0 <<8 | op); + err =ipc_dev_raw_cmd (scu->ipc_dev, cmd,SCU_PARAM_LEN , + (u8 *)wbuf, count *3 ,NULL ,0 ,0 ,0 ); + }else if (id ==IPC_CMD_PCNTRL_M ) { cbuf[offset] = data[0 ]; cbuf[offset +1 ] = data[1 ]; -ipc_data_writel (scu, wbuf[0 ],0 );/* Write wbuff */ -ipc_command (scu,4 <<16 | id <<12 |0 <<8 | op); + err =ipc_dev_raw_cmd (scu->ipc_dev, cmd,SCU_PARAM_LEN , + (u8 *)wbuf,4 ,NULL ,0 ,0 ,0 ); } - err =intel_scu_ipc_check_status (scu);if (!err && id ==IPC_CMD_PCNTRL_R ) {/* Read rbuf */ /* Workaround: values are read as 0 without memcpy_fromio */ memcpy_fromio (cbuf, scu->ipc_base +0x90 ,16 ); -for (nc =0 ; nc < count; nc++) - data[nc] =ipc_data_readb (scu, nc); +regmap_bulk_read (scu->ipc_regs,IPC_DEV_SCU_RBUF_OFFSET , + rbuf, rbuflen); +memcpy (data, rbuf, count); } -mutex_unlock (&ipclock); +return err; }@@ -422,138 +357,6 @@ int intel_scu_ipc_update_register(u16 addr, u8 bits, u8 mask) }EXPORT_SYMBOL (intel_scu_ipc_update_register); -/** -* intel_scu_ipc_simple_command - send a simple command -* @cmd: command -* @sub: sub type -* -* Issue a simple command to the SCU. Do not use this interface if -* you must then access data as any data values may be overwritten -* by another SCU access by the time this function returns. -* -* This function may sleep. Locking for SCU accesses is handled for -* the caller. -*/ -int intel_scu_ipc_simple_command (int cmd,int sub) -{ -struct intel_scu_ipc_dev *scu = &ipcdev; -int err; - -mutex_lock (&ipclock); -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } -ipc_command (scu, sub <<12 | cmd); - err =intel_scu_ipc_check_status (scu); -mutex_unlock (&ipclock); -return err; -} -EXPORT_SYMBOL (intel_scu_ipc_simple_command); - -/** -* intel_scu_ipc_command - command with data -* @cmd: command -* @sub: sub type -* @in: input data -* @inlen: input length in dwords -* @out: output data -* @outlein: output length in dwords -* -* Issue a command to the SCU which involves data transfers. Do the -* data copies under the lock but leave it for the caller to interpret -*/ -int intel_scu_ipc_command (int cmd,int sub,u32 *in,int inlen, -u32 *out,int outlen) -{ -struct intel_scu_ipc_dev *scu = &ipcdev; -int i, err; - -mutex_lock (&ipclock); -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } - -for (i =0 ; i < inlen; i++) -ipc_data_writel (scu, *in++,4 * i); - -ipc_command (scu, (inlen <<16 ) | (sub <<12 ) | cmd); - err =intel_scu_ipc_check_status (scu); - -if (!err) { -for (i =0 ; i < outlen; i++) - *out++ =ipc_data_readl (scu,4 * i); - } - -mutex_unlock (&ipclock); -return err; -} -EXPORT_SYMBOL (intel_scu_ipc_command); - -#define IPC_SPTR 0x08 -#define IPC_DPTR 0x0C - -/** -* intel_scu_ipc_raw_command() - IPC command with data and pointers -* @cmd: IPC command code. -* @sub: IPC command sub type. -* @in: input data of this IPC command. -* @inlen: input data length in dwords. -* @out: output data of this IPC command. -* @outlen: output data length in dwords. -* @sptr: data writing to SPTR register. -* @dptr: data writing to DPTR register. -* -* Send an IPC command to SCU with input/output data and source/dest pointers. -* -* Return: an IPC error code or 0 on success. -*/ -int intel_scu_ipc_raw_command (int cmd,int sub,u8 *in,int inlen, -u32 *out,int outlen,u32 dptr,u32 sptr) -{ -struct intel_scu_ipc_dev *scu = &ipcdev; -int inbuflen =DIV_ROUND_UP (inlen,4 ); -u32 inbuf[4 ]; -int i, err; - -/* Up to 16 bytes */ -if (inbuflen >4 ) -return -EINVAL ; - -mutex_lock (&ipclock); -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } - -writel (dptr, scu->ipc_base +IPC_DPTR ); -writel (sptr, scu->ipc_base +IPC_SPTR ); - -/* -* SRAM controller doesn't support 8-bit writes, it only -* supports 32-bit writes, so we have to copy input data into -* the temporary buffer, and SCU FW will use the inlen to -* determine the actual input data length in the temporary -* buffer. -*/ -memcpy (inbuf, in, inlen); - -for (i =0 ; i < inbuflen; i++) -ipc_data_writel (scu, inbuf[i],4 * i); - -ipc_command (scu, (inlen <<16 ) | (sub <<12 ) | cmd); - err =intel_scu_ipc_check_status (scu); -if (!err) { -for (i =0 ; i < outlen; i++) - *out++ =ipc_data_readl (scu,4 * i); - } - -mutex_unlock (&ipclock); -return err; -} -EXPORT_SYMBOL_GPL (intel_scu_ipc_raw_command); -/* I2C commands */ #define IPC_I2C_WRITE 1/* I2C Write command */ #define IPC_I2C_READ 2/* I2C Read command */ @@ -575,48 +378,143 @@ int intel_scu_ipc_i2c_cntrl(u32 addr, u32 *data)struct intel_scu_ipc_dev *scu = &ipcdev;u32 cmd =0 ; -mutex_lock (&ipclock); -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } cmd = (addr >>24 ) &0xFF ;if (cmd ==IPC_I2C_READ ) { -writel (addr, scu->i2c_base +IPC_I2C_CNTRL_ADDR ); +regmap_write (scu->i2c_regs,IPC_I2C_CNTRL_ADDR , addr);/* Write not getting updated without delay */ mdelay (1 ); - *data =readl (scu->i2c_base +I2C_DATA_ADDR ); +regmap_read (scu->i2c_regs,I2C_DATA_ADDR , data); }else if (cmd ==IPC_I2C_WRITE ) { -writel (*data, scu->i2c_base +I2C_DATA_ADDR ); +regmap_write (scu->i2c_regs,I2C_DATA_ADDR , *data);mdelay (1 ); -writel (addr, scu->i2c_base +IPC_I2C_CNTRL_ADDR ); +regmap_write (scu->i2c_regs,IPC_I2C_CNTRL_ADDR , addr); }else {dev_err (scu->dev,"intel_scu_ipc: I2C INVALID_CMD = 0x%x\n" , cmd); -mutex_unlock (&ipclock);return -EIO ; } -mutex_unlock (&ipclock);return 0 ; }EXPORT_SYMBOL (intel_scu_ipc_i2c_cntrl); -/* -* Interrupt handler gets called when ioc bit of IPC_COMMAND_REG set to 1 -* When ioc bit is set to 1, caller api must wait for interrupt handler called -* which in turn unlocks the caller api. Currently this is not used -* -* This is edge triggered so we need take no action to clear anything -*/ -static irqreturn_t ioc (int irq,void *dev_id) +static int pre_simple_cmd_fn (u32 *cmd_list,u32 cmdlen) { -struct intel_scu_ipc_dev *scu = dev_id; +if (!cmd_list || cmdlen !=SCU_PARAM_LEN ) +return -EINVAL ; -if (scu->irq_mode) -complete (&scu->cmd_complete); + cmd_list[0 ] |= (cmd_list[1 ] <<IPC_CMD_SUBCMD ); -return IRQ_HANDLED ; +return 0 ; +} + +static int pre_cmd_fn (u32 *cmd_list,u32 cmdlen,u32 *in,u32 inlen, +u32 *out,u32 outlen) +{ +int ret; + +if (inlen >IPC_WWBUF_SIZE_DWORD || outlen >IPC_RWBUF_SIZE_DWORD ) +return -EINVAL ; + + ret =pre_simple_cmd_fn (cmd_list, cmdlen); +if (ret <0 ) +return ret; + + cmd_list[0 ] |= (inlen <<IPC_CMD_SIZE ); + +return 0 ; +} + +static int pre_raw_cmd_fn (u32 *cmd_list,u32 cmdlen,u8 *in,u32 inlen, +u32 *out,u32 outlen,u32 dptr,u32 sptr) +{ +int ret; + +if (inlen >IPC_WWBUF_SIZE || outlen >IPC_RWBUF_SIZE_DWORD ) +return -EINVAL ; + + ret =pre_simple_cmd_fn (cmd_list, cmdlen); +if (ret <0 ) +return ret; + + cmd_list[0 ] |= (inlen <<IPC_CMD_SIZE ); + +return 0 ; +} + +static int scu_ipc_err_code (int status) +{ +if (status &IPC_DEV_SCU_CMD_STATUS_ERR ) +return (status &IPC_DEV_SCU_CMD_STATUS_ERR_MASK ); +else +return 0 ; +} + +static int scu_ipc_busy_check (int status) +{ +return status |IPC_DEV_SCU_CMD_STATUS_BUSY ; +} + +static u32 scu_ipc_enable_msi (u32 cmd) +{ +return cmd |IPC_DEV_SCU_CMD_MSI ; +} + +static struct intel_ipc_dev *intel_scu_ipc_dev_create ( +struct device *dev, +void __iomem *base, +int irq) +{ +struct intel_ipc_dev_ops *ops; +struct intel_ipc_dev_cfg *cfg; +struct regmap *ipc_regs; +struct intel_scu_ipc_dev *scu =dev_get_drvdata (dev); + + cfg =devm_kzalloc (dev,sizeof (*cfg),GFP_KERNEL ); +if (!cfg) +return ERR_PTR (-ENOMEM ); + + ops =devm_kzalloc (dev,sizeof (*ops),GFP_KERNEL ); +if (!ops) +return ERR_PTR (-ENOMEM ); + + ipc_regs =devm_regmap_init_mmio_clk (dev,NULL , base, + &ipc_regmap_config); +if (IS_ERR (ipc_regs)) { +dev_err (dev,"ipc_regs regmap init failed\n" ); +return ERR_CAST (ipc_regs);; + } + + scu->ipc_regs = ipc_regs; + +/* set IPC dev ops */ + ops->to_err_code = scu_ipc_err_code; + ops->busy_check = scu_ipc_busy_check; + ops->enable_msi = scu_ipc_enable_msi; + ops->pre_cmd_fn = pre_cmd_fn; + ops->pre_raw_cmd_fn = pre_raw_cmd_fn; + ops->pre_simple_cmd_fn = pre_simple_cmd_fn; + +/* set cfg options */ +if (scu->irq_mode) + cfg->mode =IPC_DEV_MODE_IRQ ; +else + cfg->mode =IPC_DEV_MODE_POLLING ; + + cfg->chan_type =IPC_CHANNEL_IA_SCU ; + cfg->irq = irq; + cfg->use_msi = true; + cfg->support_sptr = true; + cfg->support_dptr = true; + cfg->cmd_regs = ipc_regs; + cfg->data_regs = ipc_regs; + cfg->wrbuf_reg =IPC_DEV_SCU_WRBUF_OFFSET ; + cfg->rbuf_reg =IPC_DEV_SCU_RBUF_OFFSET ; + cfg->sptr_reg =IPC_DEV_SCU_SPTR_OFFSET ; + cfg->dptr_reg =IPC_DEV_SCU_DPTR_OFFSET ; + cfg->status_reg =IPC_DEV_SCU_STATUS_OFFSET ; + +return devm_intel_ipc_dev_create (dev,INTEL_SCU_IPC_DEV , cfg, ops); }/** @@ -650,25 +548,34 @@ static int ipc_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (err)return err; -init_completion (&scu->cmd_complete); - scu->ipc_base =pcim_iomap_table (pdev)[0 ]; - scu->i2c_base =ioremap_nocache (pdata->i2c_base, pdata->i2c_len); + scu->i2c_base =devm_ioremap_nocache (&pdev->dev, pdata->i2c_base, + pdata->i2c_len);if (!scu->i2c_base)return -ENOMEM ; - err =devm_request_irq (&pdev->dev, pdev->irq, ioc,0 ,"intel_scu_ipc" , - scu); -if (err) -return err; +pci_set_drvdata (pdev, scu); + + scu->i2c_regs =devm_regmap_init_mmio_clk (&pdev->dev,NULL , + scu->i2c_base, &i2c_regmap_config); +if (IS_ERR (scu->i2c_regs)) { +dev_err (&pdev->dev,"i2c_regs regmap init failed\n" ); +return PTR_ERR (scu->i2c_regs);; + } + + scu->ipc_dev =intel_scu_ipc_dev_create (&pdev->dev, scu->ipc_base, + pdev->irq); +if (IS_ERR (scu->ipc_dev)) { +dev_err (&pdev->dev,"Failed to create SCU IPC device\n" ); +return PTR_ERR (scu->ipc_dev); + }/* Assign device at last */ scu->dev = &pdev->dev;intel_scu_devices_create (); -pci_set_drvdata (pdev, scu);return 0 ; }drivers/rtc/rtc-mrst.c +11
-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) {drivers/watchdog/intel-mid_wdt.c +11
-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,10 @@ 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}; + +return ipc_dev_cmd (scu_ipc_dev, cmds,SCU_PARAM_LEN , in, + inlen,NULL ,0 ); }static int wdt_start (struct watchdog_device *wd)@@ -129,6 +135,10 @@ static int mid_wdt_probe(struct platform_device *pdev)if (!wdt_dev)return -ENOMEM ; + 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); + 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 +10
-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,18 +131,14 @@ 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 }; 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_ret =ipc_dev_cmd (scu_ipc_dev, cmds,SCU_PARAM_LEN , ipc_wbuf, +2 ,NULL ,0 );if (ipc_ret !=0 )pr_err ("Error setting SCU watchdog timer: %x\n" , ipc_ret);@@ -460,6 +459,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 ) {Signature · 1 line
2.7.4
Re: [RFC v3 1/7] platform/x86: intel_pmc_ipc: Use devm_* calls in driver probe function
In reply to [email protected]Quoted 9 lines · On Tue, Sep 5, 2017 at 8:37 AM, <[email protected]>…
From: Kuppuswamy Sathyanarayanan <[email protected]>
This patch cleans up unnecessary free/alloc calls in
ipc_plat_probe(),ipc_pci_probe()andipc_plat_get_res()functions by using devm_* calls.This patch also adds proper error handling for failure cases in
ipc_pci_probe()function.
Pushed (this patch only) to my review queue with slight style changes, thanks.
Quoted 203 lines
Signed-off-by Kuppuswamy Sathyanarayanan <[email protected]>--- drivers/platform/x86/intel_pmc_ipc.c | 104 ++++++++++++----------------------- 1 file changed, 34 insertions(+), 70 deletions(-)Changes since v2:
* Used pcim_* device managed functions.Changes since v1:
* Merged devm_* related changes into a single function.
* Instead of removingfree_irq, usedevm_free_irqfunction.drivers/platform/x86/intel_pmc_ipc.c +34
-71@@ -480,52 +480,39 @@ static irqreturn_t ioc(int irq, void *dev_id)static int ipc_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) { -resource_size_t pci_resource;int ret; -int len; +struct intel_pmc_ipc_dev *pmc = &ipcdev; - ipcdev.dev = &pci_dev_get (pdev)->dev; - ipcdev.irq_mode =IPC_TRIGGER_MODE_IRQ ; +/* Only one PMC is supported */ +if (pmc->dev) +return -EBUSY ; - ret =pci_enable_device (pdev); + pmc->irq_mode =IPC_TRIGGER_MODE_IRQ ; + + ret =pcim_enable_device (pdev);if (ret)return ret; - ret =pci_request_regions (pdev,"intel_pmc_ipc" ); + ret =pcim_iomap_regions (pdev,1 <<0 ,pci_name (pdev));if (ret)return ret; - pci_resource =pci_resource_start (pdev,0 ); - len =pci_resource_len (pdev,0 ); -if (!pci_resource || !len) { -dev_err (&pdev->dev,"Failed to get resource\n" ); -return -ENOMEM ; - } +init_completion (&pmc->cmd_complete); -init_completion (&ipcdev.cmd_complete); + pmc->ipc_base =pcim_iomap_table (pdev)[0 ]; -if (request_irq (pdev->irq, ioc,0 ,"intel_pmc_ipc" , &ipcdev)) { + 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" ); -return -EBUSY ; +return ret; } - ipcdev.ipc_base =ioremap_nocache (pci_resource, len); -if (!ipcdev.ipc_base) { -dev_err (&pdev->dev,"Failed to ioremap ipc base\n" ); -free_irq (pdev->irq, &ipcdev); - ret = -ENOMEM ; - } + pmc->dev = &pdev->dev; -return ret; -} +pci_set_drvdata (pdev, pmc); -static void ipc_pci_remove (struct pci_dev *pdev) -{ -free_irq (pdev->irq, &ipcdev); -pci_release_regions (pdev); -pci_dev_put (pdev); -iounmap (ipcdev.ipc_base); - ipcdev.dev =NULL ; +return 0 ; }static const struct pci_device_id ipc_pci_ids[] = {@@ -540,7 +527,6 @@ static struct pci_driver ipc_pci_driver = { .name = "intel_pmc_ipc", .id_table = ipc_pci_ids, .probe = ipc_pci_probe, - .remove = ipc_pci_remove, }; static ssize_t intel_pmc_ipc_simple_cmd_store(struct device *dev,@@ -849,18 +835,16 @@ static int ipc_plat_get_res(struct platform_device *pdev)dev_err (&pdev->dev,"Failed to get ipc resource\n" );return -ENXIO ; } - size =PLAT_RESOURCE_IPC_SIZE +PLAT_RESOURCE_GCR_SIZE ; + res->end = (res->start +PLAT_RESOURCE_IPC_SIZE + +PLAT_RESOURCE_GCR_SIZE -1 ); -if (!request_mem_region (res->start, size, pdev->name)) { -dev_err (&pdev->dev,"Failed to request ipc resource\n" ); -return -EBUSY ; - } - addr =ioremap_nocache (res->start, size); -if (!addr) { -dev_err (&pdev->dev,"I/O memory remapping failed\n" ); -release_mem_region (res->start, size); -return -ENOMEM ; + addr =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (addr)) { +dev_err (&pdev->dev, +"PMC I/O memory remapping failed\n" ); +return PTR_ERR (addr); } + ipcdev.ipc_base = addr; ipcdev.gcr_mem_base = addr +PLAT_RESOURCE_GCR_OFFSET ;@@ -917,7 +901,6 @@ MODULE_DEVICE_TABLE(acpi, ipc_acpi_ids);static int ipc_plat_probe (struct platform_device *pdev) { -struct resource *res;int ret; ipcdev.dev = &pdev->dev;@@ -939,61 +922,42 @@ static int ipc_plat_probe(struct platform_device *pdev) ret =ipc_create_pmc_devices ();if (ret) {dev_err (&pdev->dev,"Failed to create pmc devices\n" ); - goto err_device; +return ret; } -if (request_irq (ipcdev.irq, ioc,IRQF_NO_SUSPEND , -"intel_pmc_ipc" , &ipcdev)) { +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; + goto unregister_devices; } 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; + goto unregister_devices; } ipcdev.has_gcr_regs = true;return 0 ; -err_sys: -free_irq (ipcdev.irq, &ipcdev); -err_irq: + +unregister_devices:platform_device_unregister (ipcdev.tco_dev);platform_device_unregister (ipcdev.punit_dev);platform_device_unregister (ipcdev.telemetry_dev); -err_device: -iounmap (ipcdev.ipc_base); - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_IPC_INDEX ); -if (res) { -release_mem_region (res->start, -PLAT_RESOURCE_IPC_SIZE + -PLAT_RESOURCE_GCR_SIZE ); - } +return ret; }static int ipc_plat_remove (struct platform_device *pdev) { -struct resource *res; -sysfs_remove_group (&pdev->dev.kobj, &intel_ipc_group); -free_irq (ipcdev.irq, &ipcdev); +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); -iounmap (ipcdev.ipc_base); - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_IPC_INDEX ); -if (res) { -release_mem_region (res->start, -PLAT_RESOURCE_IPC_SIZE + -PLAT_RESOURCE_GCR_SIZE ); - } ipcdev.dev =NULL ;return 0 ; } --2.7.4
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFC v3 2/7] platform/x86: intel_pmc_ipc: Use MFD framework to create dependent devices
In reply to [email protected]drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 635
Quoted 12 lines · On Tue, Sep 5, 2017 at 8:37 AM, <[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 +3
-0+ punit_cell.id =-1 ; +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_AUTO , + &punit_cell,1 ,NULL ,0 ,NULL );
IIRC you don't need to file cell ID in case of DEVID_AUTO.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 1 line · On Tue, Sep 5, 2017 at 8:37 AM, <[email protected]>…
From: Kuppuswamy Sathyanarayanan <[email protected].=
com>
Quoted 4 lines
Hi All,
Currently
intel_pmc_ipc.c,intel_punit_ipc.c,intel_scu_ipc.cdrivers imp=
lements the same IPC features.
Quoted 1 line
This code duplication could be avoided if we implement the IPC driver as =
a generic library and let custom
Quoted 1 line
device drivers use API provided by generic driver. This patchset mainly a=
ddresses this issue.
Quoted 2 lines
Along with above code duplication issue, This patchset also addresses fol=
lowing issues in intel_pmc_ipc and
Quoted 3 lines
intel_punit_ipcdrivers.1.
Intel_pmc_ipc.cdriver does not use any resource managed (devm_*) call=
s.
Quoted 1 line
2. In
Intel_pmc_ipc.cdriver, dependent devices like PUNIT, Telemetry and=
iTCO are created manually and uses lot of redundant buffer code.
Quoted 1 line
3. Global variable is used to store the IPC device structure and it is us=
ed across all functions in intel_pmc_ipc.c and intel_punit_ipc.c.
Quoted 5 lines
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 I= PC device channel, send raw IPC command and simple IPC commands. It also cr= eates device attribute to send IPC command from user space.
Quoted 4 lines
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 *op=
s)
Quoted 2 lines
The IPC channel drivers (PUNIT/PMC/SCU) when creating a new device can co=
nfigure their device params like register mapping, irq, irq-mode, channel t= ype,etc using intel_ipc_dev_cfg and intel_ipc_dev_ops arguments. After a n= ew IPC channel device is created, IPC users can use the generic APIs to mak= e IPC calls.
Quoted 2 lines
For example, after using this new model, IPC call to PMC device will look=
like,
Quoted 3 lines
pmc_ipc_dev=3Dintel_ipc_dev_get(INTEL_PMC_IPC_DEV); ipc_dev_raw_cmd(pmc_ipc_dev, cmd,PMC_PARAM_LEN, (u32 *)ipc_in, 1, NULL, =
0, 0, 0);
Quoted 2 lines
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 th=
ese patches in their product.
I have applied first patch from the series with some small changes. Please rebase the rest on top of my review branch (review-andy). Before sending new version, address comments that others and me did.
--=20
With Best Regards,
Andy Shevchenko
Re: [RFC v3 3/7] platform/x86: intel_pmc_ipc: Use regmap calls for GCR updates
In reply to [email protected]Quoted 8 lines · On Tue, Sep 5, 2017 at 8:37 AM, <[email protected]>…
From: Kuppuswamy Sathyanarayanan <[email protected]>
Currently,
update_no_reboot_bit()function implemented in this driver usesmutex_lockto protect its register updates. But this function is called with in atomic context iniTCO_wdt_start()andiTCO_wdt_stop()functions iniTCO_wdt.cdriver, which in turn causes "sleeping into atomic context" issue. This patch fixes this issue by refactoring the current GCR read/write/update functions with regmap APIs.
Since it sounds as candidate for stable, can we have split it to just as less as possible intrusive fix + moving to regmap as a separate change?
It should include Fixes: tag as well I suppose.
Quoted 223 lines
Signed-off-by Kuppuswamy Sathyanarayanan <[email protected]>--- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_pmc_ipc.c | 115 ++++++++++++----------------------- 2 files changed, 40 insertions(+), 76 deletions(-)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 communicationdrivers/platform/x86/intel_pmc_ipc.c +39
-77@@ -31,9 +31,11 @@#include <linux/atomic.h> #include <linux/notifier.h> #include <linux/suspend.h> +#include <linux/spinlock.h> #include <linux/acpi.h> #include <linux/io-64-nonatomic-lo-hi.h> #include <linux/mfd/core.h> +#include <linux/regmap.h> #include <asm/intel_pmc_ipc.h> @@ -125,7 +127,7 @@ static struct intel_pmc_ipc_dev {/* gcr */ void __iomem *gcr_mem_base; -bool has_gcr_regs; +struct regmap *gcr_regs;/* Telemetry */ u8 telem_res_inval;@@ -150,6 +152,14 @@ static char *ipc_err_sources[] = { "Unsigned kernel", }; +static struct regmap_config gcr_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .fast_io = true, + .max_register =PLAT_RESOURCE_GCR_SIZE , +}; +/* Prevent concurrent calls to the PMC */ static DEFINE_MUTEX (ipclock);@@ -183,21 +193,6 @@ static inline u32 ipc_data_readl(u32 offset)return readl (ipcdev.ipc_base +IPC_READ_BUFFER + offset); } -static inline u64 gcr_data_readq (u32 offset) -{ -return readq (ipcdev.gcr_mem_base + offset); -} - -static inline int is_gcr_valid (u32 offset) -{ -if (!ipcdev.has_gcr_regs) -return -EACCES ; - -if (offset >PLAT_RESOURCE_GCR_SIZE ) -return -EINVAL ; - -return 0 ; -}/** * intel_pmc_gcr_read() - Read PMC GCR register @@ -210,21 +205,10 @@ static inline int is_gcr_valid(u32 offset)*/ int intel_pmc_gcr_read (u32 offset,u32 *data) { -int ret; - -mutex_lock (&ipclock); - - ret =is_gcr_valid (offset); -if (ret <0 ) { -mutex_unlock (&ipclock); -return ret; - } - - *data =readl (ipcdev.gcr_mem_base + offset); - -mutex_unlock (&ipclock); +if (!ipcdev.gcr_regs) +return -EACCES ; -return 0 ; +return regmap_read (ipcdev.gcr_regs, offset, data); }EXPORT_SYMBOL_GPL (intel_pmc_gcr_read);@@ -240,21 +224,10 @@ EXPORT_SYMBOL_GPL(intel_pmc_gcr_read);*/ int intel_pmc_gcr_write (u32 offset,u32 data) { -int ret; - -mutex_lock (&ipclock); - - ret =is_gcr_valid (offset); -if (ret <0 ) { -mutex_unlock (&ipclock); -return ret; - } - -writel (data, ipcdev.gcr_mem_base + offset); - -mutex_unlock (&ipclock); +if (!ipcdev.gcr_regs) +return -EACCES ; -return 0 ; +return regmap_write (ipcdev.gcr_regs, offset, data); }EXPORT_SYMBOL_GPL (intel_pmc_gcr_write);@@ -271,33 +244,10 @@ EXPORT_SYMBOL_GPL(intel_pmc_gcr_write);*/ int intel_pmc_gcr_update (u32 offset,u32 mask,u32 val) { -u32 new_val; -int ret =0 ; - -mutex_lock (&ipclock); - - ret =is_gcr_valid (offset); -if (ret <0 ) - goto gcr_ipc_unlock; - - new_val =readl (ipcdev.gcr_mem_base + offset); - - new_val &= ~mask; - new_val |= val & mask; - -writel (new_val, ipcdev.gcr_mem_base + offset); - - new_val =readl (ipcdev.gcr_mem_base + offset); - -/* check whether the bit update is successful */ -if ((new_val & mask) != (val & mask)) { - ret = -EIO ; - goto gcr_ipc_unlock; - } +if (!ipcdev.gcr_regs) +return -EACCES ; -gcr_ipc_unlock: -mutex_unlock (&ipclock); -return ret; +return regmap_update_bits (ipcdev.gcr_regs, offset, mask, val); }EXPORT_SYMBOL_GPL (intel_pmc_gcr_update);@@ -776,16 +726,24 @@ static int ipc_plat_get_res(struct platform_device *pdev)int intel_pmc_s0ix_counter_read (u64 *data) {u64 deep, shlw; +int ret; -if (!ipcdev.has_gcr_regs) +if (!ipcdev.gcr_regs)return -EACCES ; - deep =gcr_data_readq (PMC_GCR_TELEM_DEEP_S0IX_REG ); - shlw =gcr_data_readq (PMC_GCR_TELEM_SHLW_S0IX_REG ); + ret =regmap_bulk_read (ipcdev.gcr_regs,PMC_GCR_TELEM_DEEP_S0IX_REG , + &deep,2 ); +if (ret) +return ret; + + ret =regmap_bulk_read (ipcdev.gcr_regs,PMC_GCR_TELEM_SHLW_S0IX_REG , + &shlw,2 ); +if (ret) +return ret; *data =S0IX_RESIDENCY_IN_USECS (deep, shlw); -return 0 ; +return ret; }EXPORT_SYMBOL_GPL (intel_pmc_s0ix_counter_read);@@ -817,6 +775,13 @@ static int ipc_plat_probe(struct platform_device *pdev)return ret; } + ipcdev.gcr_regs =devm_regmap_init_mmio_clk (ipcdev.dev,NULL , + ipcdev.gcr_mem_base, &gcr_regmap_config); +if (IS_ERR (ipcdev.gcr_regs)) { +dev_err (ipcdev.dev,"gcr_regs regmap init failed\n" ); +return PTR_ERR (ipcdev.gcr_regs);; + } + ret =ipc_create_pmc_devices (pdev);if (ret) {dev_err (&pdev->dev,"Failed to create pmc devices\n" );@@ -836,8 +801,6 @@ static int ipc_plat_probe(struct platform_device *pdev)return ret; } - ipcdev.has_gcr_regs = true; -return 0 ; } --2.7.4
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFC v3 4/7] platform: x86: Add generic Intel IPC driver
In reply to [email protected]Quoted 21 lines · On Tue, Sep 5, 2017 at 8:37 AM, <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9…
From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9/[email protected]>
Currently
intel_scu_ipc.c,intel_pmc_ipc.candintel_punit_ipc.credundantly 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.drivers/platform/x86/intel_ipc_dev.c new file +14
-0+static const char *ipc_dev_err_string (struct intel_ipc_dev *ipc_dev, +int error) +{ +switch (error) { +case IPC_DEV_ERR_NONE : +return "No error" ; +case IPC_DEV_ERR_CMD_NOT_SUPPORTED : +return "Command not-supported/Invalid" ; +case IPC_DEV_ERR_CMD_NOT_SERVICED : +return "Command not-serviced/Invalid param" ; +case IPC_DEV_ERR_UNABLE_TO_SERVICE : +return "Unable-to-service/Cmd-timeout" ; +case IPC_DEV_ERR_CMD_INVALID : +return "Command-invalid/Cmd-locked" ;
drivers/platform/x86/intel_ipc_dev.c line 104
Quoted 10 lines
drivers/platform/x86/intel_ipc_dev.c new file +10
-0+case IPC_DEV_ERR_CMD_FAILED : +return "Command-failed/Invalid-VR-id" ; +case IPC_DEV_ERR_EMSECURITY : +return "Invalid Battery/VR-Error" ; +case IPC_DEV_ERR_UNSIGNEDKERNEL : +return "Unsigned kernel" ; +default : +return "Unknown Command" ; + }; +}
Since it's continuous list you can define an array of messages like
const char * const *errors = {
[..._ERR_...] = "",
...
};
Also you can use enum in the header and define _ERR_MAX there. Thus, code would be transformed to
if (error < _ERR_MAX)
return errors[error];
return "Unknown Command";
Signature · 6 lines
With Best Regards, Andy Shevchenko -- 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
Re: [RFC v3 7/7] platform/x86: intel_scu_ipc: Use generic Intel IPC device calls
In reply to Alexandre BelloniHi Alexandre,
Quoted 6 lines · Alexandre Belloni
Quoted 5 lines · On 04/09/2017 at 22:37:27 -0700, [email protected]…
From: Kuppuswamy Sathyanarayanan <[email protected]>
Removed redundant IPC helper functions and refactored the driver to use generic IPC device driver APIs.
Quoted 6 lines
Quoted 4 lines
This patch also cleans-up SCU IPC user drivers to use APIs provided by generic IPC driver.
Signed-off-by Kuppuswamy Sathyanarayanan <[email protected]>For the RTC part:
Thanks for the review.
Quoted 890 lines
Quoted 890 lines
--- arch/x86/include/asm/intel_scu_ipc.h | 23 +- arch/x86/platform/intel-mid/intel-mid.c | 12 +- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_scu_ipc.c | 483 +++++++++++++------------------- drivers/rtc/rtc-mrst.c | 15 +- drivers/watchdog/intel-mid_wdt.c | 12 +- drivers/watchdog/intel_scu_watchdog.c | 17 +- 7 files changed, 251 insertions(+), 312 deletions(-)arch/x86/include/asm/intel_scu_ipc.h +13
-10@@ -14,9 +14,19 @@#define IPCMSG_COLD_BOOT 0xF3#define IPCMSG_VRTC 0xFA/* Set vRTC device */ -/* Command id associated with message IPCMSG_VRTC */ -#define IPC_CMD_VRTC_SETTIME 1/* Set time */ -#define IPC_CMD_VRTC_SETALARM 2/* Set alarm */ + +/* Command id associated with message IPCMSG_VRTC */ +#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 + +static inline void scu_cmd_init (u32 *cmd,u32 param1,u32 param2) +{ + cmd[0 ] = param1; + cmd[1 ] = param2; +}/* Read single register */ int intel_scu_ipc_ioread8 (u16 addr,u8 *data);@@ -45,13 +55,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 +10
-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> @@ -68,18 +69,23 @@ static void *(*get_intel_mid_ops[])(void) = INTEL_MID_OPS_INIT;enum intel_mid_cpu_type __intel_mid_cpu_chip;EXPORT_SYMBOL_GPL (__intel_mid_cpu_chip); +static struct intel_ipc_dev *ipc_dev; +static void intel_mid_power_off (void ) { +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_COLD_OFF ,1 };/* Shut down South Complex via PWRMU */ intel_mid_pwr_power_off ();/* 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 ); };static void intel_mid_reboot (void ) { -intel_scu_ipc_simple_command (IPCMSG_COLD_BOOT ,0 ); +u32 cmds[SCU_PARAM_LEN ] = {IPCMSG_COLD_BOOT ,0 }; + +ipc_dev_simple_cmd (ipc_dev, cmds,SCU_PARAM_LEN ); }static unsigned long __init intel_mid_calibrate_tsc (void )@@ -206,6 +212,8 @@ void __init x86_intel_mid_early_setup(void) x86_init.mpparse.find_smp_config = x86_init_noop; x86_init.mpparse.get_smp_config = x86_init_uint_noop;set_bit (MP_BUS_ISA , mp_bus_not_pci); + + ipc_dev =intel_ipc_dev_get (INTEL_SCU_IPC_DEV ); }/* 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 ondrivers/platform/x86/intel_scu_ipc.c +195
-288@@ -24,6 +24,8 @@#include <linux/pci.h> #include <linux/interrupt.h> #include <linux/sfi.h> +#include <linux/regmap.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> #include <asm/intel-mid.h> #include <asm/intel_scu_ipc.h> @@ -39,6 +41,25 @@#define IPC_CMD_PCNTRL_R 1/* Register read */ #define IPC_CMD_PCNTRL_M 2/* Register read-modify-write */ +/* IPC dev register offsets */ +/* +* IPC Read Buffer (Read Only): +* 16 byte buffer for receiving data from SCU, if IPC command +* processing results in response data +*/ +#define IPC_DEV_SCU_RBUF_OFFSET 0x90 +#define IPC_DEV_SCU_WRBUF_OFFSET 0x80 +#define IPC_DEV_SCU_SPTR_OFFSET 0x08 +#define IPC_DEV_SCU_DPTR_OFFSET 0x0C +#define IPC_DEV_SCU_STATUS_OFFSET 0x04 + +/* IPC dev commands */ +/* IPC command register IOC bit */ +#define IPC_DEV_SCU_CMD_MSI BIT(8) +#define IPC_DEV_SCU_CMD_STATUS_ERR BIT(1) +#define IPC_DEV_SCU_CMD_STATUS_ERR_MASK GENMASK(7, 0) +#define IPC_DEV_SCU_CMD_STATUS_BUSY BIT(0) +/* * IPC register summary * @@ -59,6 +80,11 @@#define IPC_WWBUF_SIZE 20/* IPC Write buffer Size */ #define IPC_RWBUF_SIZE 20/* IPC Read buffer Size */ #define IPC_IOC 0x100/* IPC command register IOC bit */ +#define IPC_CMD_SIZE 16 +#define IPC_CMD_SUBCMD 12 +#define IPC_RWBUF_SIZE_DWORD 5 +#define IPC_WWBUF_SIZE_DWORD 5 +#define PCI_DEVICE_ID_LINCROFT 0x082a#define PCI_DEVICE_ID_PENWELL 0x080e@@ -93,140 +119,49 @@ static struct intel_scu_ipc_pdata_t intel_scu_ipc_tangier_pdata = {struct intel_scu_ipc_dev {struct device *dev; +struct intel_ipc_dev *ipc_dev;void __iomem *ipc_base;void __iomem *i2c_base; -struct completion cmd_complete; +struct regmap *ipc_regs; +struct regmap *i2c_regs;u8 irq_mode; }; -static struct intel_scu_ipc_dev ipcdev;/* Only one for now */ +static struct regmap_config ipc_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , +}; -/* -* IPC Read Buffer (Read Only): -* 16 byte buffer for receiving data from SCU, if IPC command -* processing results in response data -*/ -#define IPC_READ_BUFFER 0x90 +static struct regmap_config i2c_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .fast_io = true, +}; + +static struct intel_scu_ipc_dev ipcdev;/* Only one for now */ #define IPC_I2C_CNTRL_ADDR 0#define I2C_DATA_ADDR 0x04 -static DEFINE_MUTEX (ipclock);/* lock used to prevent multiple call to SCU */ - -/* -* Send ipc command -* Command Register (Write Only): -* A write to this register results in an interrupt to the SCU core processor -* Format: -* |rfu2(8) | size(8) | command id(4) | rfu1(3) | ioc(1) | command(8)| -*/ -static inline void ipc_command (struct intel_scu_ipc_dev *scu,u32 cmd) -{ -if (scu->irq_mode) { -reinit_completion (&scu->cmd_complete); -writel (cmd |IPC_IOC , scu->ipc_base); - } -writel (cmd, scu->ipc_base); -} - -/* -* Write ipc data -* IPC Write Buffer (Write Only): -* 16-byte buffer for sending data associated with IPC command to -* SCU. Size of the data is specified in the IPC_COMMAND_REG register -*/ -static inline void ipc_data_writel (struct intel_scu_ipc_dev *scu,u32 data,u32 offset) -{ -writel (data, scu->ipc_base +0x80 + offset); -} - -/* -* Status Register (Read Only): -* Driver will read this register to get the ready/busy status of the IPC -* block and error status of the IPC command that was just processed by SCU -* Format: -* |rfu3(8)|error code(8)|initiator id(8)|cmd id(4)|rfu1(2)|error(1)|busy(1)| -*/ -static inline u8 ipc_read_status (struct intel_scu_ipc_dev *scu) -{ -return __raw_readl (scu->ipc_base +0x04 ); -} - -/* Read ipc byte data */ -static inline u8 ipc_data_readb (struct intel_scu_ipc_dev *scu,u32 offset) -{ -return readb (scu->ipc_base +IPC_READ_BUFFER + offset); -} - -/* Read ipc u32 data */ -static inline u32 ipc_data_readl (struct intel_scu_ipc_dev *scu,u32 offset) -{ -return readl (scu->ipc_base +IPC_READ_BUFFER + offset); -} - -/* Wait till scu status is busy */ -static inline int busy_loop (struct intel_scu_ipc_dev *scu) -{ -u32 status =ipc_read_status (scu); -u32 loop_count =100000 ; - -/* break if scu doesn't reset busy bit after huge retry */ -while ((status &BIT (0 )) && --loop_count) { -udelay (1 );/* scu processing time is in few u secods */ - status =ipc_read_status (scu); - } - -if (status &BIT (0 )) { -dev_err (scu->dev,"IPC timed out" ); -return -ETIMEDOUT ; - } - -if (status &BIT (1 )) -return -EIO ; - -return 0 ; -} - -/* Wait till ipc ioc interrupt is received or timeout in 3 HZ */ -static inline int ipc_wait_for_interrupt (struct intel_scu_ipc_dev *scu) -{ -int status; - -if (!wait_for_completion_timeout (&scu->cmd_complete,3 *HZ )) { -dev_err (scu->dev,"IPC timed out\n" ); -return -ETIMEDOUT ; - } - - status =ipc_read_status (scu); -if (status &BIT (1 )) -return -EIO ; - -return 0 ; -} - -static int intel_scu_ipc_check_status (struct intel_scu_ipc_dev *scu) -{ -return scu->irq_mode ?ipc_wait_for_interrupt (scu) :busy_loop (scu); -} -/* Read/Write power control(PMIC in Langwell, MSIC in PenWell) registers */ static int pwr_reg_rdwr (u16 *addr,u8 *data,u32 count,u32 op,u32 id) {struct intel_scu_ipc_dev *scu = &ipcdev;int nc;u32 offset =0 ; -int err; +int err = -EIO ;u8 cbuf[IPC_WWBUF_SIZE ];u32 *wbuf = (u32 *)&cbuf; +u32 cmd[SCU_PARAM_LEN ] = {0 }; +/* max rbuf size is 20 bytes */ +u8 rbuf[IPC_RWBUF_SIZE ] = {0 }; +u32 rbuflen =DIV_ROUND_UP (count,4 );memset (cbuf,0 ,sizeof (cbuf)); -mutex_lock (&ipclock); - -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } +scu_cmd_init (cmd, op, id);for (nc =0 ; nc < count; nc++, offset +=2 ) { cbuf[offset] = addr[nc];@@ -234,30 +169,30 @@ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) }if (id ==IPC_CMD_PCNTRL_R ) { -for (nc =0 , offset =0 ; nc < count; nc++, offset +=4 ) -ipc_data_writel (scu, wbuf[nc], offset); -ipc_command (scu, (count *2 ) <<16 | id <<12 |0 <<8 | op); + err =ipc_dev_raw_cmd (scu->ipc_dev, cmd,SCU_PARAM_LEN , + (u8 *)wbuf, count *2 , (u32 *)rbuf, +IPC_RWBUF_SIZE_DWORD ,0 ,0 ); }else if (id ==IPC_CMD_PCNTRL_W ) {for (nc =0 ; nc < count; nc++, offset +=1 ) cbuf[offset] = data[nc]; -for (nc =0 , offset =0 ; nc < count; nc++, offset +=4 ) -ipc_data_writel (scu, wbuf[nc], offset); -ipc_command (scu, (count *3 ) <<16 | id <<12 |0 <<8 | op); + err =ipc_dev_raw_cmd (scu->ipc_dev, cmd,SCU_PARAM_LEN , + (u8 *)wbuf, count *3 ,NULL ,0 ,0 ,0 ); + }else if (id ==IPC_CMD_PCNTRL_M ) { cbuf[offset] = data[0 ]; cbuf[offset +1 ] = data[1 ]; -ipc_data_writel (scu, wbuf[0 ],0 );/* Write wbuff */ -ipc_command (scu,4 <<16 | id <<12 |0 <<8 | op); + err =ipc_dev_raw_cmd (scu->ipc_dev, cmd,SCU_PARAM_LEN , + (u8 *)wbuf,4 ,NULL ,0 ,0 ,0 ); } - err =intel_scu_ipc_check_status (scu);if (!err && id ==IPC_CMD_PCNTRL_R ) {/* Read rbuf */ /* Workaround: values are read as 0 without memcpy_fromio */ memcpy_fromio (cbuf, scu->ipc_base +0x90 ,16 ); -for (nc =0 ; nc < count; nc++) - data[nc] =ipc_data_readb (scu, nc); +regmap_bulk_read (scu->ipc_regs,IPC_DEV_SCU_RBUF_OFFSET , + rbuf, rbuflen); +memcpy (data, rbuf, count); } -mutex_unlock (&ipclock); +return err; }@@ -422,138 +357,6 @@ int intel_scu_ipc_update_register(u16 addr, u8 bits, u8 mask) }EXPORT_SYMBOL (intel_scu_ipc_update_register); -/** -* intel_scu_ipc_simple_command - send a simple command -* @cmd: command -* @sub: sub type -* -* Issue a simple command to the SCU. Do not use this interface if -* you must then access data as any data values may be overwritten -* by another SCU access by the time this function returns. -* -* This function may sleep. Locking for SCU accesses is handled for -* the caller. -*/ -int intel_scu_ipc_simple_command (int cmd,int sub) -{ -struct intel_scu_ipc_dev *scu = &ipcdev; -int err; - -mutex_lock (&ipclock); -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } -ipc_command (scu, sub <<12 | cmd); - err =intel_scu_ipc_check_status (scu); -mutex_unlock (&ipclock); -return err; -} -EXPORT_SYMBOL (intel_scu_ipc_simple_command); - -/** -* intel_scu_ipc_command - command with data -* @cmd: command -* @sub: sub type -* @in: input data -* @inlen: input length in dwords -* @out: output data -* @outlein: output length in dwords -* -* Issue a command to the SCU which involves data transfers. Do the -* data copies under the lock but leave it for the caller to interpret -*/ -int intel_scu_ipc_command (int cmd,int sub,u32 *in,int inlen, -u32 *out,int outlen) -{ -struct intel_scu_ipc_dev *scu = &ipcdev; -int i, err; - -mutex_lock (&ipclock); -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } - -for (i =0 ; i < inlen; i++) -ipc_data_writel (scu, *in++,4 * i); - -ipc_command (scu, (inlen <<16 ) | (sub <<12 ) | cmd); - err =intel_scu_ipc_check_status (scu); - -if (!err) { -for (i =0 ; i < outlen; i++) - *out++ =ipc_data_readl (scu,4 * i); - } - -mutex_unlock (&ipclock); -return err; -} -EXPORT_SYMBOL (intel_scu_ipc_command); - -#define IPC_SPTR 0x08 -#define IPC_DPTR 0x0C - -/** -* intel_scu_ipc_raw_command() - IPC command with data and pointers -* @cmd: IPC command code. -* @sub: IPC command sub type. -* @in: input data of this IPC command. -* @inlen: input data length in dwords. -* @out: output data of this IPC command. -* @outlen: output data length in dwords. -* @sptr: data writing to SPTR register. -* @dptr: data writing to DPTR register. -* -* Send an IPC command to SCU with input/output data and source/dest pointers. -* -* Return: an IPC error code or 0 on success. -*/ -int intel_scu_ipc_raw_command (int cmd,int sub,u8 *in,int inlen, -u32 *out,int outlen,u32 dptr,u32 sptr) -{ -struct intel_scu_ipc_dev *scu = &ipcdev; -int inbuflen =DIV_ROUND_UP (inlen,4 ); -u32 inbuf[4 ]; -int i, err; - -/* Up to 16 bytes */ -if (inbuflen >4 ) -return -EINVAL ; - -mutex_lock (&ipclock); -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } - -writel (dptr, scu->ipc_base +IPC_DPTR ); -writel (sptr, scu->ipc_base +IPC_SPTR ); - -/* -* SRAM controller doesn't support 8-bit writes, it only -* supports 32-bit writes, so we have to copy input data into -* the temporary buffer, and SCU FW will use the inlen to -* determine the actual input data length in the temporary -* buffer. -*/ -memcpy (inbuf, in, inlen); - -for (i =0 ; i < inbuflen; i++) -ipc_data_writel (scu, inbuf[i],4 * i); - -ipc_command (scu, (inlen <<16 ) | (sub <<12 ) | cmd); - err =intel_scu_ipc_check_status (scu); -if (!err) { -for (i =0 ; i < outlen; i++) - *out++ =ipc_data_readl (scu,4 * i); - } - -mutex_unlock (&ipclock); -return err; -} -EXPORT_SYMBOL_GPL (intel_scu_ipc_raw_command); -/* I2C commands */ #define IPC_I2C_WRITE 1/* I2C Write command */ #define IPC_I2C_READ 2/* I2C Read command */ @@ -575,48 +378,143 @@ int intel_scu_ipc_i2c_cntrl(u32 addr, u32 *data)struct intel_scu_ipc_dev *scu = &ipcdev;u32 cmd =0 ; -mutex_lock (&ipclock); -if (scu->dev ==NULL ) { -mutex_unlock (&ipclock); -return -ENODEV ; - } cmd = (addr >>24 ) &0xFF ;if (cmd ==IPC_I2C_READ ) { -writel (addr, scu->i2c_base +IPC_I2C_CNTRL_ADDR ); +regmap_write (scu->i2c_regs,IPC_I2C_CNTRL_ADDR , addr);/* Write not getting updated without delay */ mdelay (1 ); - *data =readl (scu->i2c_base +I2C_DATA_ADDR ); +regmap_read (scu->i2c_regs,I2C_DATA_ADDR , data); }else if (cmd ==IPC_I2C_WRITE ) { -writel (*data, scu->i2c_base +I2C_DATA_ADDR ); +regmap_write (scu->i2c_regs,I2C_DATA_ADDR , *data);mdelay (1 ); -writel (addr, scu->i2c_base +IPC_I2C_CNTRL_ADDR ); +regmap_write (scu->i2c_regs,IPC_I2C_CNTRL_ADDR , addr); }else {dev_err (scu->dev,"intel_scu_ipc: I2C INVALID_CMD = 0x%x\n" , cmd); -mutex_unlock (&ipclock);return -EIO ; } -mutex_unlock (&ipclock);return 0 ; }EXPORT_SYMBOL (intel_scu_ipc_i2c_cntrl); -/* -* Interrupt handler gets called when ioc bit of IPC_COMMAND_REG set to 1 -* When ioc bit is set to 1, caller api must wait for interrupt handler called -* which in turn unlocks the caller api. Currently this is not used -* -* This is edge triggered so we need take no action to clear anything -*/ -static irqreturn_t ioc (int irq,void *dev_id) +static int pre_simple_cmd_fn (u32 *cmd_list,u32 cmdlen) { -struct intel_scu_ipc_dev *scu = dev_id; +if (!cmd_list || cmdlen !=SCU_PARAM_LEN ) +return -EINVAL ; -if (scu->irq_mode) -complete (&scu->cmd_complete); + cmd_list[0 ] |= (cmd_list[1 ] <<IPC_CMD_SUBCMD ); -return IRQ_HANDLED ; +return 0 ; +} + +static int pre_cmd_fn (u32 *cmd_list,u32 cmdlen,u32 *in,u32 inlen, +u32 *out,u32 outlen) +{ +int ret; + +if (inlen >IPC_WWBUF_SIZE_DWORD || outlen >IPC_RWBUF_SIZE_DWORD ) +return -EINVAL ; + + ret =pre_simple_cmd_fn (cmd_list, cmdlen); +if (ret <0 ) +return ret; + + cmd_list[0 ] |= (inlen <<IPC_CMD_SIZE ); + +return 0 ; +} + +static int pre_raw_cmd_fn (u32 *cmd_list,u32 cmdlen,u8 *in,u32 inlen, +u32 *out,u32 outlen,u32 dptr,u32 sptr) +{ +int ret; + +if (inlen >IPC_WWBUF_SIZE || outlen >IPC_RWBUF_SIZE_DWORD ) +return -EINVAL ; + + ret =pre_simple_cmd_fn (cmd_list, cmdlen); +if (ret <0 ) +return ret; + + cmd_list[0 ] |= (inlen <<IPC_CMD_SIZE ); + +return 0 ; +} + +static int scu_ipc_err_code (int status) +{ +if (status &IPC_DEV_SCU_CMD_STATUS_ERR ) +return (status &IPC_DEV_SCU_CMD_STATUS_ERR_MASK ); +else +return 0 ; +} + +static int scu_ipc_busy_check (int status) +{ +return status |IPC_DEV_SCU_CMD_STATUS_BUSY ; +} + +static u32 scu_ipc_enable_msi (u32 cmd) +{ +return cmd |IPC_DEV_SCU_CMD_MSI ; +} + +static struct intel_ipc_dev *intel_scu_ipc_dev_create ( +struct device *dev, +void __iomem *base, +int irq) +{ +struct intel_ipc_dev_ops *ops; +struct intel_ipc_dev_cfg *cfg; +struct regmap *ipc_regs; +struct intel_scu_ipc_dev *scu =dev_get_drvdata (dev); + + cfg =devm_kzalloc (dev,sizeof (*cfg),GFP_KERNEL ); +if (!cfg) +return ERR_PTR (-ENOMEM ); + + ops =devm_kzalloc (dev,sizeof (*ops),GFP_KERNEL ); +if (!ops) +return ERR_PTR (-ENOMEM ); + + ipc_regs =devm_regmap_init_mmio_clk (dev,NULL , base, + &ipc_regmap_config); +if (IS_ERR (ipc_regs)) { +dev_err (dev,"ipc_regs regmap init failed\n" ); +return ERR_CAST (ipc_regs);; + } + + scu->ipc_regs = ipc_regs; + +/* set IPC dev ops */ + ops->to_err_code = scu_ipc_err_code; + ops->busy_check = scu_ipc_busy_check; + ops->enable_msi = scu_ipc_enable_msi; + ops->pre_cmd_fn = pre_cmd_fn; + ops->pre_raw_cmd_fn = pre_raw_cmd_fn; + ops->pre_simple_cmd_fn = pre_simple_cmd_fn; + +/* set cfg options */ +if (scu->irq_mode) + cfg->mode =IPC_DEV_MODE_IRQ ; +else + cfg->mode =IPC_DEV_MODE_POLLING ; + + cfg->chan_type =IPC_CHANNEL_IA_SCU ; + cfg->irq = irq; + cfg->use_msi = true; + cfg->support_sptr = true; + cfg->support_dptr = true; + cfg->cmd_regs = ipc_regs; + cfg->data_regs = ipc_regs; + cfg->wrbuf_reg =IPC_DEV_SCU_WRBUF_OFFSET ; + cfg->rbuf_reg =IPC_DEV_SCU_RBUF_OFFSET ; + cfg->sptr_reg =IPC_DEV_SCU_SPTR_OFFSET ; + cfg->dptr_reg =IPC_DEV_SCU_DPTR_OFFSET ; + cfg->status_reg =IPC_DEV_SCU_STATUS_OFFSET ; + +return devm_intel_ipc_dev_create (dev,INTEL_SCU_IPC_DEV , cfg, ops); }/** @@ -650,25 +548,34 @@ static int ipc_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (err)return err; -init_completion (&scu->cmd_complete); - scu->ipc_base =pcim_iomap_table (pdev)[0 ]; - scu->i2c_base =ioremap_nocache (pdata->i2c_base, pdata->i2c_len); + scu->i2c_base =devm_ioremap_nocache (&pdev->dev, pdata->i2c_base, + pdata->i2c_len);if (!scu->i2c_base)return -ENOMEM ; - err =devm_request_irq (&pdev->dev, pdev->irq, ioc,0 ,"intel_scu_ipc" , - scu); -if (err) -return err; +pci_set_drvdata (pdev, scu); + + scu->i2c_regs =devm_regmap_init_mmio_clk (&pdev->dev,NULL , + scu->i2c_base, &i2c_regmap_config); +if (IS_ERR (scu->i2c_regs)) { +dev_err (&pdev->dev,"i2c_regs regmap init failed\n" ); +return PTR_ERR (scu->i2c_regs);; + } + + scu->ipc_dev =intel_scu_ipc_dev_create (&pdev->dev, scu->ipc_base, + pdev->irq); +if (IS_ERR (scu->ipc_dev)) { +dev_err (&pdev->dev,"Failed to create SCU IPC device\n" ); +return PTR_ERR (scu->ipc_dev); + }/* Assign device at last */ scu->dev = &pdev->dev;intel_scu_devices_create (); -pci_set_drvdata (pdev, scu);return 0 ; }drivers/rtc/rtc-mrst.c +11
-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) {drivers/watchdog/intel-mid_wdt.c +11
-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,10 @@ 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}; + +return ipc_dev_cmd (scu_ipc_dev, cmds,SCU_PARAM_LEN , in, + inlen,NULL ,0 ); }static int wdt_start (struct watchdog_device *wd)@@ -129,6 +135,10 @@ static int mid_wdt_probe(struct platform_device *pdev)if (!wdt_dev)return -ENOMEM ; + 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); + 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 +10
-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,18 +131,14 @@ 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 }; 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_ret =ipc_dev_cmd (scu_ipc_dev, cmds,SCU_PARAM_LEN , ipc_wbuf, +2 ,NULL ,0 );if (ipc_ret !=0 )pr_err ("Error setting SCU watchdog timer: %x\n" , ipc_ret);@@ -460,6 +459,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 ) {Signature · 1 line
2.7.4
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux kernel developer
Re: [RFC v3 7/7] platform/x86: intel_scu_ipc: Use generic Intel IPC device calls
In reply to Guenter RoeckHi Guenter,
Quoted 26 lines · Guenter Roeck
Quoted 6 lines · Alexandre Belloni
Quoted 5 lines · On 04/09/2017 at 22:37:27 -0700, [email protected]…
From: Kuppuswamy Sathyanarayanan <[email protected]>
Removed redundant IPC helper functions and refactored the driver to use generic IPC device driver APIs.
Quoted 18 lines
Quoted 4 lines
This patch also cleans-up SCU IPC user drivers to use APIs provided by generic IPC driver.
Signed-off-by Kuppuswamy Sathyanarayanan <[email protected]>For the RTC part:
>
Quoted 10 lines
---
arch/x86/include/asm/intel_scu_ipc.h | 23 +-arch/x86/platform/intel-mid/intel-mid.c| 12 +- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_scu_ipc.c | 483
+++++++++++++-------------------
drivers/rtc/rtc-mrst.c | 15 +- drivers/watchdog/intel-mid_wdt.c | 12 +- drivers/watchdog/intel_scu_watchdog.c | 17 +-7 files changed, 251 insertions(+), 312 deletions(-)
Quoted 1 line
I think it would help in general to mention at least in the description which drivers are touched.
I will add this info in my next patch version.
Quoted 4 lines
I see calls to
intel_ipc_dev_get()but not associated put calls. Missing the context, it may well be that those are not necessary, but then how does the ipc code know that the device reference is no longer needed ?
I also noticed this issue. Initially I thought we don't need to deal with ref count because in most cases IPC client drivers are compiled as built-in drivers ( because these APIs are required during early boot process to send IPC commands to ARC processor) and hence will have life-time until the device is powered-off.
But after looking into Kconfig params, I noticed that at least intel_pmc_ipc and intel_punit_ipc drivers can be compiled as modules. And hence we will have dangling pointer reference issue if we don't maintain proper refcount for device references.
So, I have already fixed this problem by adding intel_ipc_dev_put() and devm_intel_ipc_dev_get() APIs.
This fix will be available in next version.
Quoted 847 lines
Guenter
Quoted 843 lines
Quoted 842 lines
arch/x86/include/asm/intel_scu_ipc.h +13
-3@@ -14,9 +14,19 @@ #define IPCMSG_COLD_BOOT 0xF3 #define IPCMSG_VRTC 0xFA /* Set vRTC device */ - /* Command id associated with message IPCMSG_VRTC */ - #define IPC_CMD_VRTC_SETTIME 1 /* Set time */ - #define IPC_CMD_VRTC_SETALARM 2 /* Set alarm */ + +/* Command id associated with message IPCMSG_VRTC */ +#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 + +static inline void scu_cmd_init (u32 *cmd,u32 param1,u32 param2) +{ + cmd[0] = param1; + cmd[1] = param2; +} /* Read single register */ int intel_scu_ipc_ioread8(u16 addr, u8 *data);@@ -45,13 +55,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 */
arch/x86/include/asm/intel_scu_ipc.h +0
-6-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 */
intintel_scu_ipc_i2c_cntrl(u32 addr, u32 *data);
diff --gita/arch/x86/platform/intel-mid/intel-mid.cb/arch/x86/platform/intel-mid/intel-mid.cindex 12a2725..27541e9 100644arch/x86/platform/intel-mid/intel-mid.c +9
-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>@@ -68,18 +69,23 @@ static void *(*get_intel_mid_ops[])(void) =INTEL_MID_OPS_INIT ; enum intel_mid_cpu_type __intel_mid_cpu_chip; EXPORT_SYMBOL_GPL(__intel_mid_cpu_chip); +static struct intel_ipc_dev *ipc_dev; + static void intel_mid_power_off(void) { + u32 cmds[SCU_PARAM_LEN] = {IPCMSG_COLD_OFF, 1}; /* Shut down South Complex via PWRMU */ intel_mid_pwr_power_off(); /* 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); }; static void intel_mid_reboot(void) { - intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0); + u32 cmds[SCU_PARAM_LEN] = {IPCMSG_COLD_BOOT, 0}; + + ipc_dev_simple_cmd(ipc_dev, cmds, SCU_PARAM_LEN); } static unsigned long __init intel_mid_calibrate_tsc(void)@@ -206,6 +212,8 @@ void __init x86_intel_mid_early_setup(void) x86_init.mpparse.find_smp_config = x86_init_noop; x86_init.mpparse.get_smp_config = x86_init_uint_noop; set_bit(MP_BUS_ISA, mp_bus_not_pci); + + ipc_dev = intel_ipc_dev_get(INTEL_SCU_IPC_DEV); } /*drivers/platform/x86/Kconfig +0
-0@@ -850,6 +850,7 @@ config INTEL_VBTNconfig
INTEL_SCU_IPC
bool "Intel SCU IPC Support"
depends onX86_INTEL_MID
+ selectREGMAP_MMIO
default y
---help---
IPC is used to bridge the communications between kernel and SCU ondrivers/platform/x86/intel_scu_ipc.c +2
-0@@ -24,6 +24,8 @@ #include <linux/pci.h> #include <linux/interrupt.h> #include <linux/sfi.h> +#include <linux/regmap.h> +#include <linux/platform_data/x86/intel_ipc_dev.h> #include <asm/intel-mid.h> #include <asm/intel_scu_ipc.h>@@ -39,6 +41,25 @@
#define IPC_CMD_PCNTRL_R 1 /* Register read */ #define IPC_CMD_PCNTRL_M 2 /* Register read-modify-write */ +/* IPC dev register offsets */drivers/platform/x86/intel_scu_ipc.c +18
-0+/* +* IPC Read Buffer (Read Only): +* 16 byte buffer for receiving data from SCU, if IPC command +* processing results in response data +*/ +#define IPC_DEV_SCU_RBUF_OFFSET 0x90 +#define IPC_DEV_SCU_WRBUF_OFFSET 0x80 +#define IPC_DEV_SCU_SPTR_OFFSET 0x08 +#define IPC_DEV_SCU_DPTR_OFFSET 0x0C +#define IPC_DEV_SCU_STATUS_OFFSET 0x04 + +/* IPC dev commands */ +/* IPC command register IOC bit */ +#define IPC_DEV_SCU_CMD_MSI BIT(8) +#define IPC_DEV_SCU_CMD_STATUS_ERR BIT(1) +#define IPC_DEV_SCU_CMD_STATUS_ERR_MASK GENMASK(7, 0) +#define IPC_DEV_SCU_CMD_STATUS_BUSY BIT(0) +/*
* IPC register summary
*drivers/platform/x86/intel_scu_ipc.c +8
-1@@ -59,6 +80,11 @@ #define IPC_WWBUF_SIZE 20 /* IPC Write buffer Size */ #define IPC_RWBUF_SIZE 20 /* IPC Read buffer Size */ #define IPC_IOC 0x100 /* IPC command register IOC bit */ +#define IPC_CMD_SIZE 16 +#define IPC_CMD_SUBCMD 12 +#define IPC_RWBUF_SIZE_DWORD 5 +#define IPC_WWBUF_SIZE_DWORD 5 + #define PCI_DEVICE_ID_LINCROFT 0x082a #define PCI_DEVICE_ID_PENWELL 0x080e@@ -93,140 +119,49 @@ static struct intel_scu_ipc_pdata_t intel_scu_ipc_tangier_pdata = { struct intel_scu_ipc_dev { struct device *dev; + struct intel_ipc_dev *ipc_dev; void __iomem *ipc_base; void __iomem *i2c_base; - struct completion cmd_complete; + struct regmap *ipc_regs; + struct regmap *i2c_regs; u8 irq_mode; };-static struct intel_scu_ipc_dev ipcdev; /* Only one for now */
drivers/platform/x86/intel_scu_ipc.c +5
-0+static struct regmap_config ipc_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, +};-/*
- * IPC Read Buffer (Read Only):
- * 16 byte buffer for receiving data from SCU, if IPC command
- * processing results in response data
- */drivers/platform/x86/intel_scu_ipc.c +8
-1-#define IPC_READ_BUFFER 0x90 +static struct regmap_config i2c_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .fast_io = true, +}; + +static struct intel_scu_ipc_dev ipcdev; /* Only one for now */#define IPC_I2C_CNTRL_ADDR 0
#define I2C_DATA_ADDR0x04
-staticDEFINE_MUTEX(ipclock); /* lock used to prevent multiple call to SCU */drivers/platform/x86/intel_scu_ipc.c +0
-5- -/* -* Send ipc command -* Command Register (Write Only): -* A write to this register results in an interrupt to the SCU core processor
- * Format:
- * |rfu2(8) | size(8) | command id(4) | rfu1(3) | ioc(1) | command(8)|
- */drivers/platform/x86/intel_scu_ipc.c +0
-16-static inline void ipc_command (struct intel_scu_ipc_dev *scu,u32 cmd) -{ - if (scu->irq_mode) { - reinit_completion(&scu->cmd_complete); - writel(cmd | IPC_IOC, scu->ipc_base); - } - writel(cmd, scu->ipc_base); -} - -/* -* Write ipc data -* IPC Write Buffer (Write Only): -* 16-byte buffer for sending data associated with IPC command to -* SCU. Size of the data is specified in the IPC_COMMAND_REG register -*/ -static inline void ipc_data_writel(struct intel_scu_ipc_dev *scu,u32 data, u32 offset)
drivers/platform/x86/intel_scu_ipc.c +0
-7-{ - writel(data, scu->ipc_base + 0x80 + offset); -} - -/* -* Status Register (Read Only): -* Driver will read this register to get the ready/busy status of the IPC
- * block and error status of the IPC command that was just processed by SCU
- * Format:
- * |rfu3(8)|error code(8)|initiator id(8)|cmd id(4)|rfu1(2)|error(1)|busy(1)|
- */drivers/platform/x86/intel_scu_ipc.c +0
-7-static inline u8 ipc_read_status (struct intel_scu_ipc_dev *scu) -{ - return __raw_readl(scu->ipc_base + 0x04); -} - -/* Read ipc byte data */ -static inline u8 ipc_data_readb(struct intel_scu_ipc_dev *scu, u32offset)
drivers/platform/x86/intel_scu_ipc.c +0
-6-{ - return readb(scu->ipc_base + IPC_READ_BUFFER + offset); -} - -/* Read ipc u32 data */ -static inline u32 ipc_data_readl(struct intel_scu_ipc_dev *scu, u32offset)
drivers/platform/x86/intel_scu_ipc.c +0
-29-{ - return readl(scu->ipc_base + IPC_READ_BUFFER + offset); -} - -/* Wait till scu status is busy */ -static inline int busy_loop (struct intel_scu_ipc_dev *scu) -{ - u32 status = ipc_read_status(scu); - u32 loop_count = 100000; - - /* break if scu doesn't reset busy bit after huge retry */ - while ((status & BIT(0)) && --loop_count) { - udelay(1); /* scu processing time is in few u secods */ - status = ipc_read_status(scu); - } - - if (status & BIT(0)) { - dev_err(scu->dev, "IPC timed out"); - return -ETIMEDOUT; - } - - if (status & BIT(1)) - return -EIO; - - return 0; -} - -/* Wait till ipc ioc interrupt is received or timeout in 3 HZ */ -static inline int ipc_wait_for_interrupt(struct intel_scu_ipc_dev*scu)
drivers/platform/x86/intel_scu_ipc.c +0
-18-{ - int status; - - if (!wait_for_completion_timeout(&scu->cmd_complete, 3 * HZ)) { - dev_err(scu->dev, "IPC timed out\n"); - return -ETIMEDOUT; - } - - status = ipc_read_status(scu); - if (status & BIT(1)) - return -EIO; - - return 0; -} - -static int intel_scu_ipc_check_status (struct intel_scu_ipc_dev *scu) -{ - return scu->irq_mode ? ipc_wait_for_interrupt(scu) :
busy_loop(scu);drivers/platform/x86/intel_scu_ipc.c +0
-2-} -/* Read/Write power
control(PMIC in Langwell, MSIC in PenWell)registers */ static intpwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id){
structintel_scu_ipc_dev*scu = &ipcdev;
int nc;
u32 offset = 0;
- int err;
+ int err =-EIO;
u8 cbuf[IPC_WWBUF_SIZE];
u32 *wbuf = (u32 *)&cbuf;
+ u32 cmd[SCU_PARAM_LEN] = {0};
+ /* max rbuf size is 20 bytes */
+ u8 rbuf[IPC_RWBUF_SIZE] = {0};
+ u32 rbuflen =DIV_ROUND_UP(count, 4);
memset(cbuf, 0, sizeof(cbuf));
-mutex_lock(&ipclock);
-
- if (scu->dev== NULL) {
-mutex_unlock(&ipclock);
- return-ENODEV;
- }
+scu_cmd_init(cmd, op, id);
for (nc = 0; nc < count; nc++, offset += 2) { cbuf[offset] = addr[nc];drivers/platform/x86/intel_scu_ipc.c +8
-8@@ -234,30 +169,30 @@ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) } if (id == IPC_CMD_PCNTRL_R) { - for (nc = 0, offset = 0; nc < count; nc++, offset += 4) - ipc_data_writel(scu, wbuf[nc], offset); - ipc_command(scu, (count * 2) << 16 | id << 12 | 0 << 8 | op); + err = ipc_dev_raw_cmd(scu->ipc_dev, cmd, SCU_PARAM_LEN, + (u8 *)wbuf, count * 2, (u32 *)rbuf, + IPC_RWBUF_SIZE_DWORD, 0, 0); } else if (id == IPC_CMD_PCNTRL_W) { for (nc = 0; nc < count; nc++, offset += 1) cbuf[offset] = data[nc]; - for (nc = 0, offset = 0; nc < count; nc++, offset += 4) - ipc_data_writel(scu, wbuf[nc], offset); - ipc_command(scu, (count * 3) << 16 | id << 12 | 0 << 8 | op); + err = ipc_dev_raw_cmd(scu->ipc_dev, cmd, SCU_PARAM_LEN, + (u8 *)wbuf, count * 3, NULL, 0, 0, 0); + } else if (id == IPC_CMD_PCNTRL_M) { cbuf[offset] = data[0]; cbuf[offset + 1] = data[1]; - ipc_data_writel(scu, wbuf[0], 0); /* Write wbuff */ - ipc_command(scu, 4 << 16 | id << 12 | 0 << 8 | op); + err = ipc_dev_raw_cmd(scu->ipc_dev, cmd, SCU_PARAM_LEN, + (u8 *)wbuf, 4, NULL, 0, 0, 0); } - err = intel_scu_ipc_check_status(scu);if (!err && id ==
IPC_CMD_PCNTRL_R) { /* Read rbuf */
/* Workaround: values are read as 0 withoutmemcpy_fromio*/memcpy_fromio(cbuf, scu->ipc_base + 0x90, 16);
- for (nc = 0; nc < count; nc++)
- data[nc] =ipc_data_readb(scu, nc);
+ regmap_bulk_read(scu->ipc_regs,IPC_DEV_SCU_RBUF_OFFSET,
+ rbuf, rbuflen);
+memcpy(data, rbuf, count);
}
-mutex_unlock(&ipclock);
+
return err;
}
@@ -422,138 +357,6 @@ intintel_scu_ipc_update_register(u16 addr, u8 bits, u8 mask)}
EXPORT_SYMBOL(intel_scu_ipc_update_register);
-/**
- * intel_scu_ipc_simple_command - send a simple command
- * @cmd: command
- * @sub: sub type
- *
- * Issue a simple command to the SCU. Do not use this interface if
- * you must then access data as any data values may be overwritten
- * by another SCU access by the time this function returns.
- *
- * This function may sleep. Locking for SCU accesses is handled for
- * the caller.
- */drivers/platform/x86/intel_scu_ipc.c +0
-28-int intel_scu_ipc_simple_command (int cmd,int sub) -{ - struct intel_scu_ipc_dev *scu = &ipcdev; - int err; - - mutex_lock(&ipclock); - if (scu->dev == NULL) { - mutex_unlock(&ipclock); - return -ENODEV; - } - ipc_command(scu, sub << 12 | cmd); - err = intel_scu_ipc_check_status(scu); - mutex_unlock(&ipclock); - return err; -} -EXPORT_SYMBOL (intel_scu_ipc_simple_command); - -/** -* intel_scu_ipc_command - command with data -* @cmd: command -* @sub: sub type -* @in: input data -* @inlen: input length in dwords -* @out: output data -* @outlein: output length in dwords -* -* Issue a command to the SCU which involves data transfers. Do the -* data copies under the lock but leave it for the caller to interpret
- */drivers/platform/x86/intel_scu_ipc.c +0
-43-int intel_scu_ipc_command (int cmd,int sub,u32 *in,int inlen, - u32 *out, int outlen) -{ - struct intel_scu_ipc_dev *scu = &ipcdev; - int i, err; - - mutex_lock(&ipclock); - if (scu->dev == NULL) { - mutex_unlock(&ipclock); - return -ENODEV; - } - - for (i = 0; i < inlen; i++) - ipc_data_writel(scu, *in++, 4 * i); - - ipc_command(scu, (inlen << 16) | (sub << 12) | cmd); - err = intel_scu_ipc_check_status(scu); - - if (!err) { - for (i = 0; i < outlen; i++) - *out++ = ipc_data_readl(scu, 4 * i); - } - - mutex_unlock(&ipclock); - return err; -} -EXPORT_SYMBOL (intel_scu_ipc_command); - -#define IPC_SPTR 0x08 -#define IPC_DPTR 0x0C - -/** -* intel_scu_ipc_raw_command() - IPC command with data and pointers -* @cmd: IPC command code. -* @sub: IPC command sub type. -* @in: input data of this IPC command. -* @inlen: input data length in dwords. -* @out: output data of this IPC command. -* @outlen: output data length in dwords. -* @sptr: data writing to SPTR register. -* @dptr: data writing to DPTR register. -* -* Send an IPC command to SCU with input/output data and source/dest pointers.
- *
- * Return: an IPC error code or 0 on success.
- */drivers/platform/x86/intel_scu_ipc.c +0
-45-int intel_scu_ipc_raw_command (int cmd,int sub,u8 *in,int inlen, - u32 *out, int outlen, u32 dptr, u32 sptr) -{ - struct intel_scu_ipc_dev *scu = &ipcdev; - int inbuflen = DIV_ROUND_UP(inlen, 4); - u32 inbuf[4]; - int i, err; - - /* Up to 16 bytes */ - if (inbuflen > 4) - return -EINVAL; - - mutex_lock(&ipclock); - if (scu->dev == NULL) { - mutex_unlock(&ipclock); - return -ENODEV; - } - - writel(dptr, scu->ipc_base + IPC_DPTR); - writel(sptr, scu->ipc_base + IPC_SPTR); - - /* - * SRAM controller doesn't support 8-bit writes, it only - * supports 32-bit writes, so we have to copy input data into - * the temporary buffer, and SCU FW will use the inlen to - * determine the actual input data length in the temporary - * buffer. - */ - memcpy(inbuf, in, inlen); - - for (i = 0; i < inbuflen; i++) - ipc_data_writel(scu, inbuf[i], 4 * i); - - ipc_command(scu, (inlen << 16) | (sub << 12) | cmd); - err = intel_scu_ipc_check_status(scu); - if (!err) { - for (i = 0; i < outlen; i++) - *out++ = ipc_data_readl(scu, 4 * i); - } - - mutex_unlock(&ipclock); - return err; -} -EXPORT_SYMBOL_GPL (intel_scu_ipc_raw_command); -/* I2C commands */
#defineIPC_I2C_WRITE1 /* I2C Write command */
#define IPC_I2C_READ 2 /* I2C Read command */drivers/platform/x86/intel_scu_ipc.c +4
-9@@ -575,48 +378,143 @@ int intel_scu_ipc_i2c_cntrl(u32 addr, u32 *data) struct intel_scu_ipc_dev *scu = &ipcdev; u32 cmd = 0; - mutex_lock(&ipclock); - if (scu->dev == NULL) { - mutex_unlock(&ipclock); - return -ENODEV; - } cmd = (addr >> 24) & 0xFF; if (cmd == IPC_I2C_READ) { - writel(addr, scu->i2c_base + IPC_I2C_CNTRL_ADDR); + regmap_write(scu->i2c_regs, IPC_I2C_CNTRL_ADDR, addr); /* Write not getting updated without delay */ mdelay(1); - *data = readl(scu->i2c_base + I2C_DATA_ADDR); + regmap_read(scu->i2c_regs, I2C_DATA_ADDR, data); } else if (cmd == IPC_I2C_WRITE) { - writel(*data, scu->i2c_base + I2C_DATA_ADDR); + regmap_write(scu->i2c_regs, I2C_DATA_ADDR, *data); mdelay(1); - writel(addr, scu->i2c_base + IPC_I2C_CNTRL_ADDR); + regmap_write(scu->i2c_regs, IPC_I2C_CNTRL_ADDR, addr); } else { dev_err(scu->dev, "intel_scu_ipc: I2C INVALID_CMD = 0x%x\n", cmd); - mutex_unlock(&ipclock); return -EIO; } - mutex_unlock(&ipclock); return 0; } EXPORT_SYMBOL(intel_scu_ipc_i2c_cntrl);-/*
- * Interrupt handler gets called when ioc bit ofIPC_COMMAND_REGset to 1
- * When ioc bit is set to 1, caller api must wait for interrupt handler called
- * which in turn unlocks the caller api. Currently this is not used
- *
- * This is edge triggered so we need take no action to clear anything
- */drivers/platform/x86/intel_scu_ipc.c +1
-1-static irqreturn_t ioc (int irq,void *dev_id) +static int pre_simple_cmd_fn (u32 *cmd_list,u32 cmdlen){
- structintel_scu_ipc_dev*scu =dev_id; + if (!cmd_list || cmdlen !=SCU_PARAM_LEN) + return-EINVAL;
- if (scu->irq_mode)
-complete(&scu->cmd_complete);
+ cmd_list[0] |= (cmd_list[1] <<IPC_CMD_SUBCMD); - returnIRQ_HANDLED;
+ return 0;drivers/platform/x86/intel_scu_ipc.c +20
-0+} + +static int pre_cmd_fn (u32 *cmd_list,u32 cmdlen,u32 *in,u32 inlen, + u32 *out, u32 outlen) +{ + int ret; + + if (inlen > IPC_WWBUF_SIZE_DWORD || outlen > IPC_RWBUF_SIZE_DWORD) + return -EINVAL; + + ret = pre_simple_cmd_fn(cmd_list, cmdlen); + if (ret < 0) + return ret; + + cmd_list[0] |= (inlen << IPC_CMD_SIZE); + + return 0; +} + +static int pre_raw_cmd_fn(u32 *cmd_list, u32 cmdlen, u8 *in, u32inlen,
+ u32 *out, u32 outlen, u32 dptr, u32 sptr)drivers/platform/x86/intel_scu_ipc.c +88
-0+{ + int ret; + + if (inlen > IPC_WWBUF_SIZE || outlen > IPC_RWBUF_SIZE_DWORD) + return -EINVAL; + + ret = pre_simple_cmd_fn(cmd_list, cmdlen); + if (ret < 0) + return ret; + + cmd_list[0] |= (inlen << IPC_CMD_SIZE); + + return 0; +} + +static int scu_ipc_err_code (int status) +{ + if (status & IPC_DEV_SCU_CMD_STATUS_ERR) + return (status & IPC_DEV_SCU_CMD_STATUS_ERR_MASK); + else + return 0; +} + +static int scu_ipc_busy_check (int status) +{ + return status | IPC_DEV_SCU_CMD_STATUS_BUSY; +} + +static u32 scu_ipc_enable_msi (u32 cmd) +{ + return cmd | IPC_DEV_SCU_CMD_MSI; +} + +static struct intel_ipc_dev *intel_scu_ipc_dev_create ( + struct device *dev, + void __iomem *base, + int irq) +{ + struct intel_ipc_dev_ops *ops; + struct intel_ipc_dev_cfg *cfg; + struct regmap *ipc_regs; + struct intel_scu_ipc_dev *scu = dev_get_drvdata(dev); + + cfg = devm_kzalloc(dev, sizeof(*cfg), GFP_KERNEL); + if (!cfg) + return ERR_PTR(-ENOMEM); + + ops = devm_kzalloc(dev, sizeof(*ops), GFP_KERNEL); + if (!ops) + return ERR_PTR(-ENOMEM); + + ipc_regs = devm_regmap_init_mmio_clk(dev, NULL, base, + &ipc_regmap_config); + if (IS_ERR(ipc_regs)) { + dev_err(dev, "ipc_regs regmap init failed\n"); + return ERR_CAST(ipc_regs);; + } + + scu->ipc_regs = ipc_regs; + + /* set IPC dev ops */ + ops->to_err_code = scu_ipc_err_code; + ops->busy_check = scu_ipc_busy_check; + ops->enable_msi = scu_ipc_enable_msi; + ops->pre_cmd_fn = pre_cmd_fn; + ops->pre_raw_cmd_fn = pre_raw_cmd_fn; + ops->pre_simple_cmd_fn = pre_simple_cmd_fn; + + /* set cfg options */ + if (scu->irq_mode) + cfg->mode = IPC_DEV_MODE_IRQ; + else + cfg->mode = IPC_DEV_MODE_POLLING; + + cfg->chan_type = IPC_CHANNEL_IA_SCU; + cfg->irq = irq; + cfg->use_msi = true; + cfg->support_sptr = true; + cfg->support_dptr = true; + cfg->cmd_regs = ipc_regs; + cfg->data_regs = ipc_regs; + cfg->wrbuf_reg = IPC_DEV_SCU_WRBUF_OFFSET; + cfg->rbuf_reg = IPC_DEV_SCU_RBUF_OFFSET; + cfg->sptr_reg = IPC_DEV_SCU_SPTR_OFFSET; + cfg->dptr_reg = IPC_DEV_SCU_DPTR_OFFSET; + cfg->status_reg = IPC_DEV_SCU_STATUS_OFFSET; + + return devm_intel_ipc_dev_create(dev, INTEL_SCU_IPC_DEV, cfg,ops);
}
/**drivers/platform/x86/intel_scu_ipc.c +17
-4@@ -650,25 +548,34 @@ static int ipc_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (err) return err; - init_completion(&scu->cmd_complete); - scu->ipc_base = pcim_iomap_table(pdev)[0]; - scu->i2c_base = ioremap_nocache(pdata->i2c_base, pdata->i2c_len); + scu->i2c_base = devm_ioremap_nocache(&pdev->dev, pdata->i2c_base, + pdata->i2c_len); if (!scu->i2c_base) return -ENOMEM; - err = devm_request_irq(&pdev->dev, pdev->irq, ioc, 0, "intel_scu_ipc", - scu); - if (err) - return err; + pci_set_drvdata(pdev, scu); + + scu->i2c_regs = devm_regmap_init_mmio_clk(&pdev->dev, NULL, + scu->i2c_base, &i2c_regmap_config); + if (IS_ERR(scu->i2c_regs)) { + dev_err(&pdev->dev, "i2c_regs regmap init failed\n"); + return PTR_ERR(scu->i2c_regs);; + } + + scu->ipc_dev = intel_scu_ipc_dev_create(&pdev->dev, scu->ipc_base, + pdev->irq); + if (IS_ERR(scu->ipc_dev)) { + dev_err(&pdev->dev, "Failed to create SCU IPC device\n"); + return PTR_ERR(scu->ipc_dev); + } /* Assign device at last */ scu->dev = &pdev->dev; intel_scu_devices_create(); - pci_set_drvdata(pdev, scu); return 0; }diff --git
a/drivers/rtc/rtc-mrst.cb/drivers/rtc/rtc-mrst.cindex 7334c44..a2d87e8 100644drivers/rtc/rtc-mrst.c +4
-1@@ -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_monstarts at zero */drivers/rtc/rtc-mrst.c +3
-1@@ -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))
+ returnPTR_ERR(mrst_rtc.ipc_dev);
+
iomem =request_mem_region(iomem->start, resource_size(iomem), driver_name);
if (!iomem) {drivers/watchdog/intel-mid_wdt.c +9
-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,10 @@ 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}; + + return ipc_dev_cmd(scu_ipc_dev, cmds, SCU_PARAM_LEN, in, + inlen, NULL, 0); } static int wdt_start(struct watchdog_device *wd)@@ -129,6 +135,10 @@ static int mid_wdt_probe(struct platform_device *pdev) if (!wdt_dev) return -ENOMEM; + 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); + 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 +1
-0@@ -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, ifforce_rebootis set */
static voidwatchdog_fire(void)
{drivers/watchdog/intel_scu_watchdog.c +1
-0@@ -128,18 +131,14 @@ 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}; 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_ret=ipc_dev_cmd(scu_ipc_dev, cmds, SCU_PARAM_LEN, ipc_wbuf, + 2, NULL, 0);
if (ipc_ret!= 0)
pr_err("Error setting SCU watchdog timer: %x\n", ipc_ret);drivers/watchdog/intel_scu_watchdog.c +3
-0@@ -460,6 +459,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) {Signature · 1 line
2.7.4
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux kernel developer
Re: [RFC v3 1/7] platform/x86: intel_pmc_ipc: Use devm_* calls in driver probe function
In reply to Andy ShevchenkoHi,
Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · On Tue, Sep 5, 2017 at 8:37 AM, <[email protected]>…
From: Kuppuswamy Sathyanarayanan <[email protected]>
Quoted 8 lines
Quoted 7 lines
This patch cleans up unnecessary free/alloc calls in
ipc_plat_probe(),ipc_pci_probe()andipc_plat_get_res()functions by using devm_* calls.This patch also adds proper error handling for failure cases in
ipc_pci_probe()function.Pushed (this patch only) to my review queue with slight style changes, thanks.
Thanks Andy. Will rebase my rest of the patches on top of this patch.
Quoted 206 lines
Quoted 204 lines
Signed-off-by Kuppuswamy Sathyanarayanan <[email protected]>--- drivers/platform/x86/intel_pmc_ipc.c | 104 ++++++++++++----------------------- 1 file changed, 34 insertions(+), 70 deletions(-)Changes since v2:
* Used pcim_* device managed functions.Changes since v1:
* Merged devm_* related changes into a single function.
* Instead of removingfree_irq, usedevm_free_irqfunction.drivers/platform/x86/intel_pmc_ipc.c +34
-71@@ -480,52 +480,39 @@ static irqreturn_t ioc(int irq, void *dev_id)static int ipc_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) { -resource_size_t pci_resource;int ret; -int len; +struct intel_pmc_ipc_dev *pmc = &ipcdev; - ipcdev.dev = &pci_dev_get (pdev)->dev; - ipcdev.irq_mode =IPC_TRIGGER_MODE_IRQ ; +/* Only one PMC is supported */ +if (pmc->dev) +return -EBUSY ; - ret =pci_enable_device (pdev); + pmc->irq_mode =IPC_TRIGGER_MODE_IRQ ; + + ret =pcim_enable_device (pdev);if (ret)return ret; - ret =pci_request_regions (pdev,"intel_pmc_ipc" ); + ret =pcim_iomap_regions (pdev,1 <<0 ,pci_name (pdev));if (ret)return ret; - pci_resource =pci_resource_start (pdev,0 ); - len =pci_resource_len (pdev,0 ); -if (!pci_resource || !len) { -dev_err (&pdev->dev,"Failed to get resource\n" ); -return -ENOMEM ; - } +init_completion (&pmc->cmd_complete); -init_completion (&ipcdev.cmd_complete); + pmc->ipc_base =pcim_iomap_table (pdev)[0 ]; -if (request_irq (pdev->irq, ioc,0 ,"intel_pmc_ipc" , &ipcdev)) { + 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" ); -return -EBUSY ; +return ret; } - ipcdev.ipc_base =ioremap_nocache (pci_resource, len); -if (!ipcdev.ipc_base) { -dev_err (&pdev->dev,"Failed to ioremap ipc base\n" ); -free_irq (pdev->irq, &ipcdev); - ret = -ENOMEM ; - } + pmc->dev = &pdev->dev; -return ret; -} +pci_set_drvdata (pdev, pmc); -static void ipc_pci_remove (struct pci_dev *pdev) -{ -free_irq (pdev->irq, &ipcdev); -pci_release_regions (pdev); -pci_dev_put (pdev); -iounmap (ipcdev.ipc_base); - ipcdev.dev =NULL ; +return 0 ; }static const struct pci_device_id ipc_pci_ids[] = {@@ -540,7 +527,6 @@ static struct pci_driver ipc_pci_driver = { .name = "intel_pmc_ipc", .id_table = ipc_pci_ids, .probe = ipc_pci_probe, - .remove = ipc_pci_remove, }; static ssize_t intel_pmc_ipc_simple_cmd_store(struct device *dev,@@ -849,18 +835,16 @@ static int ipc_plat_get_res(struct platform_device *pdev)dev_err (&pdev->dev,"Failed to get ipc resource\n" );return -ENXIO ; } - size =PLAT_RESOURCE_IPC_SIZE +PLAT_RESOURCE_GCR_SIZE ; + res->end = (res->start +PLAT_RESOURCE_IPC_SIZE + +PLAT_RESOURCE_GCR_SIZE -1 ); -if (!request_mem_region (res->start, size, pdev->name)) { -dev_err (&pdev->dev,"Failed to request ipc resource\n" ); -return -EBUSY ; - } - addr =ioremap_nocache (res->start, size); -if (!addr) { -dev_err (&pdev->dev,"I/O memory remapping failed\n" ); -release_mem_region (res->start, size); -return -ENOMEM ; + addr =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (addr)) { +dev_err (&pdev->dev, +"PMC I/O memory remapping failed\n" ); +return PTR_ERR (addr); } + ipcdev.ipc_base = addr; ipcdev.gcr_mem_base = addr +PLAT_RESOURCE_GCR_OFFSET ;@@ -917,7 +901,6 @@ MODULE_DEVICE_TABLE(acpi, ipc_acpi_ids);static int ipc_plat_probe (struct platform_device *pdev) { -struct resource *res;int ret; ipcdev.dev = &pdev->dev;@@ -939,61 +922,42 @@ static int ipc_plat_probe(struct platform_device *pdev) ret =ipc_create_pmc_devices ();if (ret) {dev_err (&pdev->dev,"Failed to create pmc devices\n" ); - goto err_device; +return ret; } -if (request_irq (ipcdev.irq, ioc,IRQF_NO_SUSPEND , -"intel_pmc_ipc" , &ipcdev)) { +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; + goto unregister_devices; } 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; + goto unregister_devices; } ipcdev.has_gcr_regs = true;return 0 ; -err_sys: -free_irq (ipcdev.irq, &ipcdev); -err_irq: + +unregister_devices:platform_device_unregister (ipcdev.tco_dev);platform_device_unregister (ipcdev.punit_dev);platform_device_unregister (ipcdev.telemetry_dev); -err_device: -iounmap (ipcdev.ipc_base); - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_IPC_INDEX ); -if (res) { -release_mem_region (res->start, -PLAT_RESOURCE_IPC_SIZE + -PLAT_RESOURCE_GCR_SIZE ); - } +return ret; }static int ipc_plat_remove (struct platform_device *pdev) { -struct resource *res; -sysfs_remove_group (&pdev->dev.kobj, &intel_ipc_group); -free_irq (ipcdev.irq, &ipcdev); +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); -iounmap (ipcdev.ipc_base); - res =platform_get_resource (pdev,IORESOURCE_MEM , -PLAT_RESOURCE_IPC_INDEX ); -if (res) { -release_mem_region (res->start, -PLAT_RESOURCE_IPC_SIZE + -PLAT_RESOURCE_GCR_SIZE ); - } ipcdev.dev =NULL ;return 0 ; } --2.7.4
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux kernel developer
Re: [RFC v3 2/7] platform/x86: intel_pmc_ipc: Use MFD framework to create dependent devices
In reply to Andy ShevchenkoHi Andy,
Quoted 10 lines · Andy Shevchenko
Quoted 8 lines · On Tue, Sep 5, 2017 at 8:37 AM, <[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.
+ punit_cell.id = -1;
I will remove this line in next version.
Quoted 3 lines
drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 635
Quoted 2 lines
drivers/platform/x86/intel_pmc_ipc.c +2
-0+return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_AUTO , + &punit_cell,1 ,NULL ,0 ,NULL );IIRC you don't need to file cell ID in case of
DEVID_AUTO.
I am planning to use DEVID_NONE here to match the current behavior. Unless you have some concerns?
Quoted 1 line
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux kernel developer
Hi Andy,
Thanks for the review. I really appreciate you taking the time to review such big chunk of code changes.
Quoted 28 lines · Andy Shevchenko
Quoted 26 lines · On Tue, Sep 5, 2017 at 8:37 AM, <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9…
From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9/[email protected]>
Hi All,
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.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.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, structintel_ipc_dev_cfg*cfg, structintel_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_cfgandintel_ipc_dev_opsarguments. After a new IPC channel device is created, IPC users can use the generic APIs to make IPC calls.
Quoted 8 lines
Quoted 6 lines
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, cmd, PMC_PARAM_LEN, (u32 *)ipc_in, 1, NULL, 0, 0, 0);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.
I have applied first patch from the series with some small changes. Please rebase the rest on top of my review branch (review-andy).
Will do. I will soon send v4 version.
Quoted 1 line
Before sending new version, address comments that others and me did.
Yes.
Quoted 1 line
Signature · 7 lines
Sathyanarayanan Kuppuswamy Linux kernel developer -- 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
Re: [RFC v3 4/7] platform: x86: Add generic Intel IPC driver
In reply to Andy ShevchenkoHi,
Quoted 40 lines · Andy Shevchenko
Quoted 20 lines · On Tue, Sep 5, 2017 at 8:37 AM, <[email protected]>…
From: Kuppuswamy Sathyanarayanan <[email protected]>
Currently
intel_scu_ipc.c,intel_pmc_ipc.candintel_punit_ipc.credundantly 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.drivers/platform/x86/intel_ipc_dev.c new file +14
-0+static const char *ipc_dev_err_string (struct intel_ipc_dev *ipc_dev, +int error) +{ +switch (error) { +case IPC_DEV_ERR_NONE : +return "No error" ; +case IPC_DEV_ERR_CMD_NOT_SUPPORTED : +return "Command not-supported/Invalid" ; +case IPC_DEV_ERR_CMD_NOT_SERVICED : +return "Command not-serviced/Invalid param" ; +case IPC_DEV_ERR_UNABLE_TO_SERVICE : +return "Unable-to-service/Cmd-timeout" ; +case IPC_DEV_ERR_CMD_INVALID : +return "Command-invalid/Cmd-locked" ;drivers/platform/x86/intel_ipc_dev.c line 104
Quoted 10 lines
drivers/platform/x86/intel_ipc_dev.c new file +10
-0+case IPC_DEV_ERR_CMD_FAILED : +return "Command-failed/Invalid-VR-id" ; +case IPC_DEV_ERR_EMSECURITY : +return "Invalid Battery/VR-Error" ; +case IPC_DEV_ERR_UNSIGNEDKERNEL : +return "Unsigned kernel" ; +default : +return "Unknown Command" ; + }; +}Since it's continuous list you can define an array of messages like
const char * const *errors = {
[..._ERR_...] = "",
...};
Quoted 7 lines
Also you can use enum in the header and define
_ERR_MAXthere. Thus, code would be transformed toif (error <
_ERR_MAX)
return errors[error];return "Unknown Command";
Thanks will fix it in next version.
Quoted 1 line
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux kernel developer
Re: [RFC v3 3/7] platform/x86: intel_pmc_ipc: Use regmap calls for GCR updates
In reply to Andy ShevchenkoHi Andy,
Quoted 11 lines · Andy Shevchenko
Quoted 8 lines · On Tue, Sep 5, 2017 at 8:37 AM, <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9…
From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy-VuQAYsv1563Yd54FQh9/[email protected]>
Currently,
update_no_reboot_bit()function implemented in this driver usesmutex_lockto protect its register updates. But this function is called with in atomic context iniTCO_wdt_start()andiTCO_wdt_stop()functions iniTCO_wdt.cdriver, which in turn causes "sleeping into atomic context" issue. This patch fixes this issue by refactoring the current GCR read/write/update functions with regmap APIs.Since it sounds as candidate for stable,
Yes.
Quoted 3 lines
can we have split it to just
as less as possible intrusive fix + moving to regmap as a separate change?
If we have to split it into two patches then,
Patch #1 will fix the "sleep in atomic context issue" by replacing mutex_lock() with spin_lock() in GCR read/write APIs to protect the GCR memory updates.
Patch #2 will remove GCR read/write/update APIs and replace it with regmap APIs. But along with this change we will also remove the spin_lock() added in previous patch because regmap calls are already protected by its own locking mechanism.
Since Patch #2 will clean up what we do in Patch #1, Do we need to split it into two patches?
Quoted 1 line
It should include Fixes: tag as well I suppose.
Agree. I will add Fixes tag in next version.
Quoted 225 lines
Quoted 223 lines
--- drivers/platform/x86/Kconfig | 1 + drivers/platform/x86/intel_pmc_ipc.c | 115 ++++++++++++----------------------- 2 files changed, 40 insertions(+), 76 deletions(-)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 communicationdrivers/platform/x86/intel_pmc_ipc.c +39
-77@@ -31,9 +31,11 @@#include <linux/atomic.h> #include <linux/notifier.h> #include <linux/suspend.h> +#include <linux/spinlock.h> #include <linux/acpi.h> #include <linux/io-64-nonatomic-lo-hi.h> #include <linux/mfd/core.h> +#include <linux/regmap.h> #include <asm/intel_pmc_ipc.h> @@ -125,7 +127,7 @@ static struct intel_pmc_ipc_dev {/* gcr */ void __iomem *gcr_mem_base; -bool has_gcr_regs; +struct regmap *gcr_regs;/* Telemetry */ u8 telem_res_inval;@@ -150,6 +152,14 @@ static char *ipc_err_sources[] = { "Unsigned kernel", }; +static struct regmap_config gcr_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .fast_io = true, + .max_register =PLAT_RESOURCE_GCR_SIZE , +}; +/* Prevent concurrent calls to the PMC */ static DEFINE_MUTEX (ipclock);@@ -183,21 +193,6 @@ static inline u32 ipc_data_readl(u32 offset)return readl (ipcdev.ipc_base +IPC_READ_BUFFER + offset); } -static inline u64 gcr_data_readq (u32 offset) -{ -return readq (ipcdev.gcr_mem_base + offset); -} - -static inline int is_gcr_valid (u32 offset) -{ -if (!ipcdev.has_gcr_regs) -return -EACCES ; - -if (offset >PLAT_RESOURCE_GCR_SIZE ) -return -EINVAL ; - -return 0 ; -}/** * intel_pmc_gcr_read() - Read PMC GCR register @@ -210,21 +205,10 @@ static inline int is_gcr_valid(u32 offset)*/ int intel_pmc_gcr_read (u32 offset,u32 *data) { -int ret; - -mutex_lock (&ipclock); - - ret =is_gcr_valid (offset); -if (ret <0 ) { -mutex_unlock (&ipclock); -return ret; - } - - *data =readl (ipcdev.gcr_mem_base + offset); - -mutex_unlock (&ipclock); +if (!ipcdev.gcr_regs) +return -EACCES ; -return 0 ; +return regmap_read (ipcdev.gcr_regs, offset, data); }EXPORT_SYMBOL_GPL (intel_pmc_gcr_read);@@ -240,21 +224,10 @@ EXPORT_SYMBOL_GPL(intel_pmc_gcr_read);*/ int intel_pmc_gcr_write (u32 offset,u32 data) { -int ret; - -mutex_lock (&ipclock); - - ret =is_gcr_valid (offset); -if (ret <0 ) { -mutex_unlock (&ipclock); -return ret; - } - -writel (data, ipcdev.gcr_mem_base + offset); - -mutex_unlock (&ipclock); +if (!ipcdev.gcr_regs) +return -EACCES ; -return 0 ; +return regmap_write (ipcdev.gcr_regs, offset, data); }EXPORT_SYMBOL_GPL (intel_pmc_gcr_write);@@ -271,33 +244,10 @@ EXPORT_SYMBOL_GPL(intel_pmc_gcr_write);*/ int intel_pmc_gcr_update (u32 offset,u32 mask,u32 val) { -u32 new_val; -int ret =0 ; - -mutex_lock (&ipclock); - - ret =is_gcr_valid (offset); -if (ret <0 ) - goto gcr_ipc_unlock; - - new_val =readl (ipcdev.gcr_mem_base + offset); - - new_val &= ~mask; - new_val |= val & mask; - -writel (new_val, ipcdev.gcr_mem_base + offset); - - new_val =readl (ipcdev.gcr_mem_base + offset); - -/* check whether the bit update is successful */ -if ((new_val & mask) != (val & mask)) { - ret = -EIO ; - goto gcr_ipc_unlock; - } +if (!ipcdev.gcr_regs) +return -EACCES ; -gcr_ipc_unlock: -mutex_unlock (&ipclock); -return ret; +return regmap_update_bits (ipcdev.gcr_regs, offset, mask, val); }EXPORT_SYMBOL_GPL (intel_pmc_gcr_update);@@ -776,16 +726,24 @@ static int ipc_plat_get_res(struct platform_device *pdev)int intel_pmc_s0ix_counter_read (u64 *data) {u64 deep, shlw; +int ret; -if (!ipcdev.has_gcr_regs) +if (!ipcdev.gcr_regs)return -EACCES ; - deep =gcr_data_readq (PMC_GCR_TELEM_DEEP_S0IX_REG ); - shlw =gcr_data_readq (PMC_GCR_TELEM_SHLW_S0IX_REG ); + ret =regmap_bulk_read (ipcdev.gcr_regs,PMC_GCR_TELEM_DEEP_S0IX_REG , + &deep,2 ); +if (ret) +return ret; + + ret =regmap_bulk_read (ipcdev.gcr_regs,PMC_GCR_TELEM_SHLW_S0IX_REG , + &shlw,2 ); +if (ret) +return ret; *data =S0IX_RESIDENCY_IN_USECS (deep, shlw); -return 0 ; +return ret; }EXPORT_SYMBOL_GPL (intel_pmc_s0ix_counter_read);@@ -817,6 +775,13 @@ static int ipc_plat_probe(struct platform_device *pdev)return ret; } + ipcdev.gcr_regs =devm_regmap_init_mmio_clk (ipcdev.dev,NULL , + ipcdev.gcr_mem_base, &gcr_regmap_config); +if (IS_ERR (ipcdev.gcr_regs)) { +dev_err (ipcdev.dev,"gcr_regs regmap init failed\n" ); +return PTR_ERR (ipcdev.gcr_regs);; + } + ret =ipc_create_pmc_devices (pdev);if (ret) {dev_err (&pdev->dev,"Failed to create pmc devices\n" );@@ -836,8 +801,6 @@ static int ipc_plat_probe(struct platform_device *pdev)return ret; } - ipcdev.has_gcr_regs = true; -return 0 ; } --2.7.4
Signature · 7 lines
Sathyanarayanan Kuppuswamy Linux kernel developer -- 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
Re: [RFC v3 2/7] platform/x86: intel_pmc_ipc: Use MFD framework to create dependent devices
In reply to sathyanarayanan kuppuswamyQuoted 7 lines · sathyanarayanan kuppuswamy
Quoted 3 lines · Andy Shevchenko
On Tue, Sep 5, 2017 at 8:37 AM,
Quoted 1 line
+ punit_cell.id = -1;
I will remove this line in next version.
Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
drivers/platform/x86/intel_pmc_ipc.c static struct itco_wdt_platform_data tco_info = { · line 635
Quoted 2 lines
drivers/platform/x86/intel_pmc_ipc.c +2
-0+return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_AUTO , + &punit_cell,1 ,NULL ,0 ,NULL );IIRC you don't need to file cell ID in case of
DEVID_AUTO.I am planning to use
DEVID_NONEhere to match the current behavior. Unless you have some concerns?
Preventing behaviour is a good thing to do.
In either way cell.id can be leaved 0.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFC v3 3/7] platform/x86: intel_pmc_ipc: Use regmap calls for GCR updates
In reply to sathyanarayanan kuppuswamyQuoted 23 lines · sathyanarayanan kuppuswamy
Quoted 4 lines · Andy Shevchenko
On Tue, Sep 5, 2017 at 8:37 AM, <[email protected]> wrote:
Since it sounds as candidate for stable,
Yes.
Quoted 4 lines
can we have split it to just
as less as possible intrusive fix + moving to regmap as a separate change?If we have to split it into two patches then,
Patch #1 will fix the "sleep in atomic context issue" by replacing
mutex_lock()withspin_lock()
in GCR read/write APIs to protect the GCR memory updates. Patch #2 will remove GCR read/write/update APIs and replace it with regmap APIs. But along with this
change we will also remove thespin_lock()added in previous patch because regmap calls are already
protected by its own locking mechanism.
Quoted 2 lines
Since Patch #2 will clean up what we do in Patch #1, Do we need to split it into two patches?
Yes, please do...
Quoted 3 lines
Quoted 1 line
It should include Fixes: tag as well I suppose.
Agree. I will add Fixes tag in next version.
...because this one will go alone to stable releases.
Be also sure patch #1 will be applied on current vanilla (w/o PDx86 queue involvement).
Signature · 2 lines
With Best Regards, Andy Shevchenko