1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020 Linaro Ltd.
5 * This device driver implements MMIO TPM on SynQuacer Platform.
7 #include <linux/acpi.h>
8 #include <linux/init.h>
9 #include <linux/module.h>
10 #include <linux/slab.h>
12 #include <linux/kernel.h>
14 #include "tpm_tis_core.h"
17 * irq > 0 means: use irq $irq;
18 * irq = 0 means: autoprobe for an irq;
19 * irq = -1 means: no irq support
21 struct tpm_tis_synquacer_info {
26 struct tpm_tis_synquacer_phy {
27 struct tpm_tis_data priv;
31 static inline struct tpm_tis_synquacer_phy *to_tpm_tis_tcg_phy(struct tpm_tis_data *data)
33 return container_of(data, struct tpm_tis_synquacer_phy, priv);
36 static int tpm_tis_synquacer_read_bytes(struct tpm_tis_data *data, u32 addr,
38 enum tpm_tis_io_mode io_mode)
40 struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
44 *result++ = ioread8(phy->iobase + addr);
47 result[1] = ioread8(phy->iobase + addr + 1);
48 result[0] = ioread8(phy->iobase + addr);
51 result[3] = ioread8(phy->iobase + addr + 3);
52 result[2] = ioread8(phy->iobase + addr + 2);
53 result[1] = ioread8(phy->iobase + addr + 1);
54 result[0] = ioread8(phy->iobase + addr);
61 static int tpm_tis_synquacer_write_bytes(struct tpm_tis_data *data, u32 addr,
62 u16 len, const u8 *value,
63 enum tpm_tis_io_mode io_mode)
65 struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
69 iowrite8(*value++, phy->iobase + addr);
75 * Due to the limitation of SPI controller on SynQuacer,
76 * 16/32 bits access must be done in byte-wise and descending order.
78 iowrite8(value[3], phy->iobase + addr + 3);
79 iowrite8(value[2], phy->iobase + addr + 2);
80 iowrite8(value[1], phy->iobase + addr + 1);
81 iowrite8(value[0], phy->iobase + addr);
88 static const struct tpm_tis_phy_ops tpm_tcg_bw = {
89 .read_bytes = tpm_tis_synquacer_read_bytes,
90 .write_bytes = tpm_tis_synquacer_write_bytes,
93 static int tpm_tis_synquacer_init(struct device *dev,
94 struct tpm_tis_synquacer_info *tpm_info)
96 struct tpm_tis_synquacer_phy *phy;
98 phy = devm_kzalloc(dev, sizeof(struct tpm_tis_synquacer_phy), GFP_KERNEL);
102 phy->iobase = devm_ioremap_resource(dev, &tpm_info->res);
103 if (IS_ERR(phy->iobase))
104 return PTR_ERR(phy->iobase);
106 return tpm_tis_core_init(dev, &phy->priv, tpm_info->irq, &tpm_tcg_bw,
110 static SIMPLE_DEV_PM_OPS(tpm_tis_synquacer_pm, tpm_pm_suspend, tpm_tis_resume);
112 static int tpm_tis_synquacer_probe(struct platform_device *pdev)
114 struct tpm_tis_synquacer_info tpm_info = {};
115 struct resource *res;
117 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
119 dev_err(&pdev->dev, "no memory resource defined\n");
126 return tpm_tis_synquacer_init(&pdev->dev, &tpm_info);
129 static void tpm_tis_synquacer_remove(struct platform_device *pdev)
131 struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
133 tpm_chip_unregister(chip);
134 tpm_tis_remove(chip);
138 static const struct of_device_id tis_synquacer_of_platform_match[] = {
139 {.compatible = "socionext,synquacer-tpm-mmio"},
142 MODULE_DEVICE_TABLE(of, tis_synquacer_of_platform_match);
146 static const struct acpi_device_id tpm_synquacer_acpi_tbl[] = {
150 MODULE_DEVICE_TABLE(acpi, tpm_synquacer_acpi_tbl);
153 static struct platform_driver tis_synquacer_drv = {
154 .probe = tpm_tis_synquacer_probe,
155 .remove_new = tpm_tis_synquacer_remove,
157 .name = "tpm_tis_synquacer",
158 .pm = &tpm_tis_synquacer_pm,
159 .of_match_table = of_match_ptr(tis_synquacer_of_platform_match),
160 .acpi_match_table = ACPI_PTR(tpm_synquacer_acpi_tbl),
164 static int __init tpm_tis_synquacer_module_init(void)
168 rc = platform_driver_register(&tis_synquacer_drv);
175 static void __exit tpm_tis_synquacer_module_exit(void)
177 platform_driver_unregister(&tis_synquacer_drv);
180 module_init(tpm_tis_synquacer_module_init);
181 module_exit(tpm_tis_synquacer_module_exit);
182 MODULE_DESCRIPTION("TPM MMIO Driver for Socionext SynQuacer platform");
183 MODULE_LICENSE("GPL");