Linux Audio

Check our new training course

Linux debugging, profiling, tracing and performance analysis training

Mar 24-27, 2025, special US time zones
Register
Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (C) 2020 Linaro Ltd.
  4 *
  5 * This device driver implements MMIO TPM on SynQuacer Platform.
  6 */
  7#include <linux/acpi.h>
  8#include <linux/init.h>
  9#include <linux/module.h>
 10#include <linux/slab.h>
 11#include <linux/of.h>
 
 12#include <linux/kernel.h>
 13#include "tpm.h"
 14#include "tpm_tis_core.h"
 15
 16/*
 17 * irq > 0 means: use irq $irq;
 18 * irq = 0 means: autoprobe for an irq;
 19 * irq = -1 means: no irq support
 20 */
 21struct tpm_tis_synquacer_info {
 22	struct resource res;
 23	int irq;
 24};
 25
 26struct tpm_tis_synquacer_phy {
 27	struct tpm_tis_data priv;
 28	void __iomem *iobase;
 29};
 30
 31static inline struct tpm_tis_synquacer_phy *to_tpm_tis_tcg_phy(struct tpm_tis_data *data)
 32{
 33	return container_of(data, struct tpm_tis_synquacer_phy, priv);
 34}
 35
 36static int tpm_tis_synquacer_read_bytes(struct tpm_tis_data *data, u32 addr,
 37					u16 len, u8 *result,
 38					enum tpm_tis_io_mode io_mode)
 39{
 40	struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
 41	switch (io_mode) {
 42	case TPM_TIS_PHYS_8:
 43		while (len--)
 44			*result++ = ioread8(phy->iobase + addr);
 45		break;
 46	case TPM_TIS_PHYS_16:
 47		result[1] = ioread8(phy->iobase + addr + 1);
 48		result[0] = ioread8(phy->iobase + addr);
 49		break;
 50	case TPM_TIS_PHYS_32:
 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);
 55		break;
 56	}
 57
 58	return 0;
 59}
 60
 61static 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)
 64{
 65	struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
 66	switch (io_mode) {
 67	case TPM_TIS_PHYS_8:
 68		while (len--)
 69			iowrite8(*value++, phy->iobase + addr);
 70		break;
 71	case TPM_TIS_PHYS_16:
 72		return -EINVAL;
 73	case TPM_TIS_PHYS_32:
 74		/*
 75		 * Due to the limitation of SPI controller on SynQuacer,
 76		 * 16/32 bits access must be done in byte-wise and descending order.
 77		 */
 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);
 82		break;
 83	}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 84
 85	return 0;
 86}
 87
 88static 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,
 
 
 
 91};
 92
 93static int tpm_tis_synquacer_init(struct device *dev,
 94				  struct tpm_tis_synquacer_info *tpm_info)
 95{
 96	struct tpm_tis_synquacer_phy *phy;
 97
 98	phy = devm_kzalloc(dev, sizeof(struct tpm_tis_synquacer_phy), GFP_KERNEL);
 99	if (phy == NULL)
100		return -ENOMEM;
101
102	phy->iobase = devm_ioremap_resource(dev, &tpm_info->res);
103	if (IS_ERR(phy->iobase))
104		return PTR_ERR(phy->iobase);
105
106	return tpm_tis_core_init(dev, &phy->priv, tpm_info->irq, &tpm_tcg_bw,
107				 ACPI_HANDLE(dev));
108}
109
110static SIMPLE_DEV_PM_OPS(tpm_tis_synquacer_pm, tpm_pm_suspend, tpm_tis_resume);
111
112static int tpm_tis_synquacer_probe(struct platform_device *pdev)
113{
114	struct tpm_tis_synquacer_info tpm_info = {};
115	struct resource *res;
116
117	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
118	if (res == NULL) {
119		dev_err(&pdev->dev, "no memory resource defined\n");
120		return -ENODEV;
121	}
122	tpm_info.res = *res;
123
124	tpm_info.irq = -1;
125
126	return tpm_tis_synquacer_init(&pdev->dev, &tpm_info);
127}
128
129static void tpm_tis_synquacer_remove(struct platform_device *pdev)
130{
131	struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
132
133	tpm_chip_unregister(chip);
134	tpm_tis_remove(chip);
 
 
135}
136
137#ifdef CONFIG_OF
138static const struct of_device_id tis_synquacer_of_platform_match[] = {
139	{.compatible = "socionext,synquacer-tpm-mmio"},
140	{},
141};
142MODULE_DEVICE_TABLE(of, tis_synquacer_of_platform_match);
143#endif
144
145#ifdef CONFIG_ACPI
146static const struct acpi_device_id tpm_synquacer_acpi_tbl[] = {
147	{ "SCX0009" },
148	{},
149};
150MODULE_DEVICE_TABLE(acpi, tpm_synquacer_acpi_tbl);
151#endif
152
153static struct platform_driver tis_synquacer_drv = {
154	.probe = tpm_tis_synquacer_probe,
155	.remove_new = tpm_tis_synquacer_remove,
156	.driver = {
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),
161	},
162};
163
164module_platform_driver(tis_synquacer_drv);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
 
166MODULE_DESCRIPTION("TPM MMIO Driver for Socionext SynQuacer platform");
167MODULE_LICENSE("GPL");
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (C) 2020 Linaro Ltd.
  4 *
  5 * This device driver implements MMIO TPM on SynQuacer Platform.
  6 */
  7#include <linux/acpi.h>
  8#include <linux/init.h>
  9#include <linux/module.h>
 10#include <linux/slab.h>
 11#include <linux/of.h>
 12#include <linux/of_device.h>
 13#include <linux/kernel.h>
 14#include "tpm.h"
 15#include "tpm_tis_core.h"
 16
 17/*
 18 * irq > 0 means: use irq $irq;
 19 * irq = 0 means: autoprobe for an irq;
 20 * irq = -1 means: no irq support
 21 */
 22struct tpm_tis_synquacer_info {
 23	struct resource res;
 24	int irq;
 25};
 26
 27struct tpm_tis_synquacer_phy {
 28	struct tpm_tis_data priv;
 29	void __iomem *iobase;
 30};
 31
 32static inline struct tpm_tis_synquacer_phy *to_tpm_tis_tcg_phy(struct tpm_tis_data *data)
 33{
 34	return container_of(data, struct tpm_tis_synquacer_phy, priv);
 35}
 36
 37static int tpm_tis_synquacer_read_bytes(struct tpm_tis_data *data, u32 addr,
 38					u16 len, u8 *result)
 
 39{
 40	struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
 41
 42	while (len--)
 43		*result++ = ioread8(phy->iobase + addr);
 
 
 
 
 
 
 
 
 
 
 
 
 
 44
 45	return 0;
 46}
 47
 48static int tpm_tis_synquacer_write_bytes(struct tpm_tis_data *data, u32 addr,
 49					 u16 len, const u8 *value)
 
 50{
 51	struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
 52
 53	while (len--)
 54		iowrite8(*value++, phy->iobase + addr);
 55
 56	return 0;
 57}
 58
 59static int tpm_tis_synquacer_read16_bw(struct tpm_tis_data *data,
 60				       u32 addr, u16 *result)
 61{
 62	struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
 63
 64	/*
 65	 * Due to the limitation of SPI controller on SynQuacer,
 66	 * 16/32 bits access must be done in byte-wise and descending order.
 67	 */
 68	*result = (ioread8(phy->iobase + addr + 1) << 8) |
 69		  (ioread8(phy->iobase + addr));
 70
 71	return 0;
 72}
 73
 74static int tpm_tis_synquacer_read32_bw(struct tpm_tis_data *data,
 75				       u32 addr, u32 *result)
 76{
 77	struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
 78
 79	/*
 80	 * Due to the limitation of SPI controller on SynQuacer,
 81	 * 16/32 bits access must be done in byte-wise and descending order.
 82	 */
 83	*result = (ioread8(phy->iobase + addr + 3) << 24) |
 84		  (ioread8(phy->iobase + addr + 2) << 16) |
 85		  (ioread8(phy->iobase + addr + 1) << 8) |
 86		  (ioread8(phy->iobase + addr));
 87
 88	return 0;
 89}
 90
 91static int tpm_tis_synquacer_write32_bw(struct tpm_tis_data *data,
 92					u32 addr, u32 value)
 93{
 94	struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
 95
 96	/*
 97	 * Due to the limitation of SPI controller on SynQuacer,
 98	 * 16/32 bits access must be done in byte-wise and descending order.
 99	 */
100	iowrite8(value >> 24, phy->iobase + addr + 3);
101	iowrite8(value >> 16, phy->iobase + addr + 2);
102	iowrite8(value >> 8, phy->iobase + addr + 1);
103	iowrite8(value, phy->iobase + addr);
104
105	return 0;
106}
107
108static const struct tpm_tis_phy_ops tpm_tcg_bw = {
109	.read_bytes	= tpm_tis_synquacer_read_bytes,
110	.write_bytes	= tpm_tis_synquacer_write_bytes,
111	.read16		= tpm_tis_synquacer_read16_bw,
112	.read32		= tpm_tis_synquacer_read32_bw,
113	.write32	= tpm_tis_synquacer_write32_bw,
114};
115
116static int tpm_tis_synquacer_init(struct device *dev,
117				  struct tpm_tis_synquacer_info *tpm_info)
118{
119	struct tpm_tis_synquacer_phy *phy;
120
121	phy = devm_kzalloc(dev, sizeof(struct tpm_tis_synquacer_phy), GFP_KERNEL);
122	if (phy == NULL)
123		return -ENOMEM;
124
125	phy->iobase = devm_ioremap_resource(dev, &tpm_info->res);
126	if (IS_ERR(phy->iobase))
127		return PTR_ERR(phy->iobase);
128
129	return tpm_tis_core_init(dev, &phy->priv, tpm_info->irq, &tpm_tcg_bw,
130				 ACPI_HANDLE(dev));
131}
132
133static SIMPLE_DEV_PM_OPS(tpm_tis_synquacer_pm, tpm_pm_suspend, tpm_tis_resume);
134
135static int tpm_tis_synquacer_probe(struct platform_device *pdev)
136{
137	struct tpm_tis_synquacer_info tpm_info = {};
138	struct resource *res;
139
140	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
141	if (res == NULL) {
142		dev_err(&pdev->dev, "no memory resource defined\n");
143		return -ENODEV;
144	}
145	tpm_info.res = *res;
146
147	tpm_info.irq = -1;
148
149	return tpm_tis_synquacer_init(&pdev->dev, &tpm_info);
150}
151
152static int tpm_tis_synquacer_remove(struct platform_device *pdev)
153{
154	struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
155
156	tpm_chip_unregister(chip);
157	tpm_tis_remove(chip);
158
159	return 0;
160}
161
162#ifdef CONFIG_OF
163static const struct of_device_id tis_synquacer_of_platform_match[] = {
164	{.compatible = "socionext,synquacer-tpm-mmio"},
165	{},
166};
167MODULE_DEVICE_TABLE(of, tis_synquacer_of_platform_match);
168#endif
169
170#ifdef CONFIG_ACPI
171static const struct acpi_device_id tpm_synquacer_acpi_tbl[] = {
172	{ "SCX0009" },
173	{},
174};
175MODULE_DEVICE_TABLE(acpi, tpm_synquacer_acpi_tbl);
176#endif
177
178static struct platform_driver tis_synquacer_drv = {
179	.probe = tpm_tis_synquacer_probe,
180	.remove = tpm_tis_synquacer_remove,
181	.driver = {
182		.name		= "tpm_tis_synquacer",
183		.pm		= &tpm_tis_synquacer_pm,
184		.of_match_table = of_match_ptr(tis_synquacer_of_platform_match),
185		.acpi_match_table = ACPI_PTR(tpm_synquacer_acpi_tbl),
186	},
187};
188
189static int __init tpm_tis_synquacer_module_init(void)
190{
191	int rc;
192
193	rc = platform_driver_register(&tis_synquacer_drv);
194	if (rc)
195		return rc;
196
197	return 0;
198}
199
200static void __exit tpm_tis_synquacer_module_exit(void)
201{
202	platform_driver_unregister(&tis_synquacer_drv);
203}
204
205module_init(tpm_tis_synquacer_module_init);
206module_exit(tpm_tis_synquacer_module_exit);
207MODULE_DESCRIPTION("TPM MMIO Driver for Socionext SynQuacer platform");
208MODULE_LICENSE("GPL");