linux-stable/drivers/char/tpm/tpm_tis_synquacer.c
Linus Torvalds ef2a0b7cdb Devicetree include cleanups for v6.6:
These are the remaining few clean-ups of DT related includes which
 didn't get applied to subsystem trees.
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEktVUI4SxYhzZyEuo+vtdtY28YcMFAmTucUoACgkQ+vtdtY28
 YcOYoQ//RwIPeWc74PHQbOb6eQR95eTHDcDE1MR9Fw8amqxFaomGlSMpbyVyP4ag
 8p82c6qfJIZautyEikbKFO+iYjFMua0KuOTMVuDxHErQOl6ym4P4Uk3+1h5stVSj
 IdfK4CACtMKxKBOPAcyxJU6HKoWcUtMKsKV6OLdDh7M2Fy/G4RCjv4w1Xf3VAn59
 VOa0KF7FhHU3dhIB/tGsj0t13+3e3kF5+l4+pdoMoZWhR4gac5FJRxiR5dMZG6jr
 VY8i9FZb7DW2VtY78FVVOaYDDVf4vNrc+0kqnCbWUaKACHPgNXC375LvS7jFGXvc
 HYVN3teqhFxNOyoSehn2bdBVwJxjQFgy2gTt2vRWTa/CaUDES90cue2R9GT2Sz0b
 eBc3DQtNeT5m8mrLkuEfZrJjKjaEy2Pr6FjNDhNcmkJak7dkMMgkG/Y/SpNmpZOe
 2C3T6i4i6FUxni/2/rWHSVLnYBGfhPNdwWAZcQOi8rqtzp3tF46wVa345+Ev3VDG
 ECDndH8Qk3gtOmGyeTIvPc51yDP6Hpuh7+0jydtehkXHB+cUJtR+g0efIGf7BDgo
 sQpa1vRxkOolrCxyzKwcogEY7jjeccv/FM7BwaZQKXEibiKGkxeDuahdwbfvDuVq
 br16Uj9VzG8Jl6KK0gexV7kzZAAdw1y3JqPGUZf7hn4zmk099ow=
 =eLMf
 -----END PGP SIGNATURE-----

Merge tag 'devicetree-header-cleanups-for-6.6' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux

Pull devicetree include cleanups from Rob Herring:
 "These are the remaining few clean-ups of DT related includes which
  didn't get applied to subsystem trees"

* tag 'devicetree-header-cleanups-for-6.6' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux:
  ipmi: Explicitly include correct DT includes
  tpm: Explicitly include correct DT includes
  lib/genalloc: Explicitly include correct DT includes
  parport: Explicitly include correct DT includes
  sbus: Explicitly include correct DT includes
  mux: Explicitly include correct DT includes
  macintosh: Explicitly include correct DT includes
  hte: Explicitly include correct DT includes
  EDAC: Explicitly include correct DT includes
  clocksource: Explicitly include correct DT includes
  sparc: Explicitly include correct DT includes
  riscv: Explicitly include correct DT includes
2023-08-30 17:04:28 -07:00

167 lines
4.2 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 Linaro Ltd.
*
* This device driver implements MMIO TPM on SynQuacer Platform.
*/
#include <linux/acpi.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/kernel.h>
#include "tpm.h"
#include "tpm_tis_core.h"
/*
* irq > 0 means: use irq $irq;
* irq = 0 means: autoprobe for an irq;
* irq = -1 means: no irq support
*/
struct tpm_tis_synquacer_info {
struct resource res;
int irq;
};
struct tpm_tis_synquacer_phy {
struct tpm_tis_data priv;
void __iomem *iobase;
};
static inline struct tpm_tis_synquacer_phy *to_tpm_tis_tcg_phy(struct tpm_tis_data *data)
{
return container_of(data, struct tpm_tis_synquacer_phy, priv);
}
static int tpm_tis_synquacer_read_bytes(struct tpm_tis_data *data, u32 addr,
u16 len, u8 *result,
enum tpm_tis_io_mode io_mode)
{
struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
switch (io_mode) {
case TPM_TIS_PHYS_8:
while (len--)
*result++ = ioread8(phy->iobase + addr);
break;
case TPM_TIS_PHYS_16:
result[1] = ioread8(phy->iobase + addr + 1);
result[0] = ioread8(phy->iobase + addr);
break;
case TPM_TIS_PHYS_32:
result[3] = ioread8(phy->iobase + addr + 3);
result[2] = ioread8(phy->iobase + addr + 2);
result[1] = ioread8(phy->iobase + addr + 1);
result[0] = ioread8(phy->iobase + addr);
break;
}
return 0;
}
static int tpm_tis_synquacer_write_bytes(struct tpm_tis_data *data, u32 addr,
u16 len, const u8 *value,
enum tpm_tis_io_mode io_mode)
{
struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
switch (io_mode) {
case TPM_TIS_PHYS_8:
while (len--)
iowrite8(*value++, phy->iobase + addr);
break;
case TPM_TIS_PHYS_16:
return -EINVAL;
case TPM_TIS_PHYS_32:
/*
* Due to the limitation of SPI controller on SynQuacer,
* 16/32 bits access must be done in byte-wise and descending order.
*/
iowrite8(value[3], phy->iobase + addr + 3);
iowrite8(value[2], phy->iobase + addr + 2);
iowrite8(value[1], phy->iobase + addr + 1);
iowrite8(value[0], phy->iobase + addr);
break;
}
return 0;
}
static const struct tpm_tis_phy_ops tpm_tcg_bw = {
.read_bytes = tpm_tis_synquacer_read_bytes,
.write_bytes = tpm_tis_synquacer_write_bytes,
};
static int tpm_tis_synquacer_init(struct device *dev,
struct tpm_tis_synquacer_info *tpm_info)
{
struct tpm_tis_synquacer_phy *phy;
phy = devm_kzalloc(dev, sizeof(struct tpm_tis_synquacer_phy), GFP_KERNEL);
if (phy == NULL)
return -ENOMEM;
phy->iobase = devm_ioremap_resource(dev, &tpm_info->res);
if (IS_ERR(phy->iobase))
return PTR_ERR(phy->iobase);
return tpm_tis_core_init(dev, &phy->priv, tpm_info->irq, &tpm_tcg_bw,
ACPI_HANDLE(dev));
}
static SIMPLE_DEV_PM_OPS(tpm_tis_synquacer_pm, tpm_pm_suspend, tpm_tis_resume);
static int tpm_tis_synquacer_probe(struct platform_device *pdev)
{
struct tpm_tis_synquacer_info tpm_info = {};
struct resource *res;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
dev_err(&pdev->dev, "no memory resource defined\n");
return -ENODEV;
}
tpm_info.res = *res;
tpm_info.irq = -1;
return tpm_tis_synquacer_init(&pdev->dev, &tpm_info);
}
static void tpm_tis_synquacer_remove(struct platform_device *pdev)
{
struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
tpm_chip_unregister(chip);
tpm_tis_remove(chip);
}
#ifdef CONFIG_OF
static const struct of_device_id tis_synquacer_of_platform_match[] = {
{.compatible = "socionext,synquacer-tpm-mmio"},
{},
};
MODULE_DEVICE_TABLE(of, tis_synquacer_of_platform_match);
#endif
#ifdef CONFIG_ACPI
static const struct acpi_device_id tpm_synquacer_acpi_tbl[] = {
{ "SCX0009" },
{},
};
MODULE_DEVICE_TABLE(acpi, tpm_synquacer_acpi_tbl);
#endif
static struct platform_driver tis_synquacer_drv = {
.probe = tpm_tis_synquacer_probe,
.remove_new = tpm_tis_synquacer_remove,
.driver = {
.name = "tpm_tis_synquacer",
.pm = &tpm_tis_synquacer_pm,
.of_match_table = of_match_ptr(tis_synquacer_of_platform_match),
.acpi_match_table = ACPI_PTR(tpm_synquacer_acpi_tbl),
},
};
module_platform_driver(tis_synquacer_drv);
MODULE_DESCRIPTION("TPM MMIO Driver for Socionext SynQuacer platform");
MODULE_LICENSE("GPL");