[PATCH v3 03/23] mfd: kempld: Simplify device abstraction

From: Uwe Kleine-König (The Capable Hub)

Date: Thu Jul 09 2026 - 13:02:31 EST


The devices that are created by the driver from DMI data and also ACPI
devices all use the same platform data. Other devices don't exist. (A
provider of such a device would need to know about struct
kempld_platform_data, but none of the other consumers of
<linux/mfd/kempld.h> creates devices.)

Simplify the driver by hardcoding this instead of using the ACPI
abstraction for multi-variant support without real variants.

Then apart from .gpio_base all members of `struct kempld_platform_data`
are only used in drivers/mfd/kempld-core.c, so they can be dropped.

Signed-off-by: Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@xxxxxxxxxxxx>
---
drivers/mfd/kempld-core.c | 66 ++++++++++----------------------------
include/linux/mfd/kempld.h | 12 -------
2 files changed, 17 insertions(+), 61 deletions(-)

diff --git a/drivers/mfd/kempld-core.c b/drivers/mfd/kempld-core.c
index b64729918dfd..839328bce150 100644
--- a/drivers/mfd/kempld-core.c
+++ b/drivers/mfd/kempld-core.c
@@ -118,25 +118,19 @@ static struct resource kempld_ioresource = {
};

static const struct kempld_platform_data kempld_platform_data_generic = {
- .pld_clock = KEMPLD_CLK,
- .ioresource = &kempld_ioresource,
- .get_hardware_mutex = kempld_get_hardware_mutex,
- .release_hardware_mutex = kempld_release_hardware_mutex,
- .get_info = kempld_get_info_generic,
- .register_cells = kempld_register_cells_generic,
};

static struct platform_device *kempld_pdev;

-static int kempld_create_platform_device(const struct kempld_platform_data *pdata)
+static int kempld_create_platform_device(void)
{
const struct platform_device_info pdevinfo = {
.name = "kempld",
.id = PLATFORM_DEVID_NONE,
- .res = pdata->ioresource,
+ .res = &kempld_ioresource,
.num_res = 1,
- .data = pdata,
- .size_data = sizeof(*pdata),
+ .data = &kempld_platform_data_generic,
+ .size_data = sizeof(kempld_platform_data_generic),
};

kempld_pdev = platform_device_register_full(&pdevinfo);
@@ -235,10 +229,8 @@ EXPORT_SYMBOL_GPL(kempld_write32);
*/
void kempld_get_mutex(struct kempld_device_data *pld)
{
- const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
-
mutex_lock(&pld->lock);
- pdata->get_hardware_mutex(pld);
+ kempld_get_hardware_mutex(pld);
}
EXPORT_SYMBOL_GPL(kempld_get_mutex);

@@ -248,9 +240,7 @@ EXPORT_SYMBOL_GPL(kempld_get_mutex);
*/
void kempld_release_mutex(struct kempld_device_data *pld)
{
- const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
-
- pdata->release_hardware_mutex(pld);
+ kempld_release_hardware_mutex(pld);
mutex_unlock(&pld->lock);
}
EXPORT_SYMBOL_GPL(kempld_release_mutex);
@@ -266,10 +256,9 @@ EXPORT_SYMBOL_GPL(kempld_release_mutex);
static int kempld_get_info(struct kempld_device_data *pld)
{
int ret;
- const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
char major, minor;

- ret = pdata->get_info(pld);
+ ret = kempld_get_info_generic(pld);
if (ret)
return ret;

@@ -296,20 +285,6 @@ static int kempld_get_info(struct kempld_device_data *pld)
return 0;
}

-/*
- * kempld_register_cells - register cell drivers
- *
- * This function registers cell drivers for the detected hardware by calling
- * the configured kempld_register_cells_XXXX function which is responsible
- * to detect and register the needed cell drivers.
- */
-static int kempld_register_cells(struct kempld_device_data *pld)
-{
- const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
-
- return pdata->register_cells(pld);
-}
-
static const char *kempld_get_type_string(struct kempld_device_data *pld)
{
const char *version_type;
@@ -399,12 +374,12 @@ static int kempld_detect_device(struct kempld_device_data *pld)
pld->info.version, kempld_get_type_string(pld),
pld->info.spec_major, pld->info.spec_minor);

- return kempld_register_cells(pld);
+ return kempld_register_cells_generic(pld);
}

static int kempld_probe(struct platform_device *pdev)
{
- const struct kempld_platform_data *pdata;
+ const struct kempld_platform_data *pdata = &kempld_platform_data_generic;
struct device *dev = &pdev->dev;
struct kempld_device_data *pld;
struct resource *ioport;
@@ -415,16 +390,10 @@ static int kempld_probe(struct platform_device *pdev)
* No kempld_pdev device has been registered in kempld_init,
* so we seem to be probing an ACPI platform device.
*/
- pdata = device_get_match_data(dev);
- if (!pdata)
- return -ENODEV;
-
- ret = platform_device_add_data(pdev, pdata, sizeof(*pdata));
+ ret = platform_device_add_data(pdev, pdata, sizeof(pdata));
if (ret)
return ret;
- } else if (kempld_pdev == pdev) {
- pdata = dev_get_platdata(dev);
- } else {
+ } else if (kempld_pdev != pdev) {
/*
* The platform device we are probing is not the one we
* registered in kempld_init using the DMI table, so this one
@@ -451,7 +420,7 @@ static int kempld_probe(struct platform_device *pdev)

pld->io_index = pld->io_base;
pld->io_data = pld->io_base + 1;
- pld->pld_clock = pdata->pld_clock;
+ pld->pld_clock = KEMPLD_CLK;
pld->dev = dev;

mutex_init(&pld->lock);
@@ -463,15 +432,14 @@ static int kempld_probe(struct platform_device *pdev)
static void kempld_remove(struct platform_device *pdev)
{
struct kempld_device_data *pld = platform_get_drvdata(pdev);
- const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);

mfd_remove_devices(&pdev->dev);
- pdata->release_hardware_mutex(pld);
+ kempld_release_hardware_mutex(pld);
}

static const struct acpi_device_id kempld_acpi_table[] = {
- { "KEM0000", (kernel_ulong_t)&kempld_platform_data_generic },
- { "KEM0001", (kernel_ulong_t)&kempld_platform_data_generic },
+ { "KEM0000" },
+ { "KEM0001" },
{}
};
MODULE_DEVICE_TABLE(acpi, kempld_acpi_table);
@@ -787,13 +755,13 @@ static int __init kempld_init(void)
if (force_device_id[0]) {
for (id = kempld_dmi_table; id->matches[0].slot != DMI_NONE; id++)
if (strstr(id->ident, force_device_id))
- if (!kempld_create_platform_device(&kempld_platform_data_generic))
+ if (!kempld_create_platform_device())
break;
if (id->matches[0].slot == DMI_NONE)
return -ENODEV;
} else {
for (id = dmi_first_match(kempld_dmi_table); id; id = dmi_first_match(id+1))
- if (kempld_create_platform_device(&kempld_platform_data_generic))
+ if (kempld_create_platform_device())
break;
}
return platform_driver_register(&kempld_driver);
diff --git a/include/linux/mfd/kempld.h b/include/linux/mfd/kempld.h
index 5d75071eaaea..d7a823ba1a7a 100644
--- a/include/linux/mfd/kempld.h
+++ b/include/linux/mfd/kempld.h
@@ -97,22 +97,10 @@ struct kempld_device_data {

/**
* struct kempld_platform_data - PLD hardware configuration structure
- * @pld_clock: PLD clock frequency
* @gpio_base: GPIO base pin number
- * @ioresource: IO addresses of the PLD
- * @get_hardware_mutex: PLD specific get_mutex callback
- * @release_hardware_mutex: PLD specific release_mutex callback
- * @get_info: PLD specific get_info callback
- * @register_cells: PLD specific register_cells callback
*/
struct kempld_platform_data {
- u32 pld_clock;
int gpio_base;
- struct resource *ioresource;
- void (*get_hardware_mutex) (struct kempld_device_data *);
- void (*release_hardware_mutex) (struct kempld_device_data *);
- int (*get_info) (struct kempld_device_data *);
- int (*register_cells) (struct kempld_device_data *);
};

extern void kempld_get_mutex(struct kempld_device_data *pld);
--
2.55.0.11.g153666a7d9bb