Commit 48fe2cdd authored by Rafael J. Wysocki's avatar Rafael J. Wysocki Committed by Jarkko Sakkinen
Browse files

tpm_crb: Convert ACPI driver to a platform one

In all cases in which a struct acpi_driver is used for binding a driver
to an ACPI device object, a corresponding platform device is created by
the ACPI core and that device is regarded as a proper representation of
underlying hardware.  Accordingly, a struct platform_driver should be
used by driver code to bind to that device.  There are multiple reasons
why drivers should not bind directly to ACPI device objects [1].

Overall, it is better to bind drivers to platform devices than to their
ACPI companions, so convert the tpm_crb ACPI driver to a platform one.

While this is not expected to alter functionality, it changes sysfs
layout and so it will be visible to user space.

Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/

 [1]
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
parent e6ffe094
Loading
Loading
Loading
Loading
+16 −19
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include <linux/highmem.h>
#include <linux/rculist.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#ifdef CONFIG_ARM64
#include <linux/arm-smccc.h>
@@ -602,13 +603,13 @@ static u64 crb_fixup_cmd_size(struct device *dev, struct resource *io_res,
	return io_res->end - start + 1;
}

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
static int crb_map_io(struct device *dev, struct crb_priv *priv,
		      struct acpi_table_tpm2 *buf)
{
	struct acpi_device *device = ACPI_COMPANION(dev);
	struct list_head acpi_resource_list;
	struct resource iores_array[TPM_CRB_MAX_RESOURCES + 1] = { {0} };
	void __iomem *iobase_array[TPM_CRB_MAX_RESOURCES] = {NULL};
	struct device *dev = &device->dev;
	struct resource *iores;
	void __iomem **iobase_ptr;
	int i;
@@ -782,12 +783,13 @@ static int crb_map_pluton(struct device *dev, struct crb_priv *priv,
	return 0;
}

static int crb_acpi_add(struct acpi_device *device)
static int crb_acpi_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	struct acpi_device *device = ACPI_COMPANION(dev);
	struct acpi_table_tpm2 *buf;
	struct crb_priv *priv;
	struct tpm_chip *chip;
	struct device *dev = &device->dev;
	struct tpm2_crb_smc *crb_smc;
	struct tpm2_crb_ffa *crb_ffa;
	struct tpm2_crb_pluton *crb_pluton;
@@ -867,7 +869,7 @@ static int crb_acpi_add(struct acpi_device *device)
	priv->sm = sm;
	priv->hid = acpi_device_hid(device);

	rc = crb_map_io(device, priv, buf);
	rc = crb_map_io(dev, priv, buf);
	if (rc)
		goto out;

@@ -901,12 +903,9 @@ static int crb_acpi_add(struct acpi_device *device)
	return rc;
}

static void crb_acpi_remove(struct acpi_device *device)
static void crb_acpi_remove(struct platform_device *pdev)
{
	struct device *dev = &device->dev;
	struct tpm_chip *chip = dev_get_drvdata(dev);

	tpm_chip_unregister(chip);
	tpm_chip_unregister(platform_get_drvdata(pdev));
}

static const struct dev_pm_ops crb_pm = {
@@ -919,19 +918,17 @@ static const struct acpi_device_id crb_device_ids[] = {
};
MODULE_DEVICE_TABLE(acpi, crb_device_ids);

static struct acpi_driver crb_acpi_driver = {
	.name = "tpm_crb",
	.ids = crb_device_ids,
	.ops = {
		.add = crb_acpi_add,
static struct platform_driver crb_acpi_driver = {
	.probe = crb_acpi_probe,
	.remove = crb_acpi_remove,
	},
	.drv = {
	.driver = {
		.name = "tpm_crb_acpi",
		.acpi_match_table = crb_device_ids,
		.pm = &crb_pm,
	},
};

module_acpi_driver(crb_acpi_driver);
module_platform_driver(crb_acpi_driver);
MODULE_AUTHOR("Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>");
MODULE_DESCRIPTION("TPM2 Driver");
MODULE_VERSION("0.1");