Lines Matching +full:m +full:- +full:phy
1 // SPDX-License-Identifier: GPL-2.0-only
8 * Christophe Ricard <christophe-h.ricard@st.com>
10 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
47 * [1] https://trustedcomputinggroup.org/resource/pc-client-platform-tpm-profile-ptp-specification/
49 static int tpm_tis_spi_flow_control(struct tpm_tis_spi_phy *phy, in tpm_tis_spi_flow_control() argument
52 struct spi_message m; in tpm_tis_spi_flow_control() local
55 if ((phy->iobuf[3] & 0x01) == 0) { in tpm_tis_spi_flow_control()
58 spi_xfer->len = 1; in tpm_tis_spi_flow_control()
59 spi_message_init(&m); in tpm_tis_spi_flow_control()
60 spi_message_add_tail(spi_xfer, &m); in tpm_tis_spi_flow_control()
61 ret = spi_sync_locked(phy->spi_device, &m); in tpm_tis_spi_flow_control()
64 if (phy->iobuf[0] & 0x01) in tpm_tis_spi_flow_control()
69 return -ETIMEDOUT; in tpm_tis_spi_flow_control()
84 struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data); in tpm_tis_spi_transfer_half() local
86 struct spi_message m; in tpm_tis_spi_transfer_half() local
93 spi_message_init(&m); in tpm_tis_spi_transfer_half()
94 phy->iobuf[0] = (in ? 0x80 : 0) | (transfer_len - 1); in tpm_tis_spi_transfer_half()
95 phy->iobuf[1] = 0xd4; in tpm_tis_spi_transfer_half()
96 phy->iobuf[2] = addr >> 8; in tpm_tis_spi_transfer_half()
97 phy->iobuf[3] = addr; in tpm_tis_spi_transfer_half()
101 spi_xfer[0].tx_buf = phy->iobuf; in tpm_tis_spi_transfer_half()
103 spi_message_add_tail(&spi_xfer[0], &m); in tpm_tis_spi_transfer_half()
105 spi_xfer[1].tx_buf = phy->iobuf + 1; in tpm_tis_spi_transfer_half()
107 spi_message_add_tail(&spi_xfer[1], &m); in tpm_tis_spi_transfer_half()
110 spi_xfer[2].tx_buf = &phy->iobuf[4]; in tpm_tis_spi_transfer_half()
112 memcpy(&phy->iobuf[4], out, transfer_len); in tpm_tis_spi_transfer_half()
118 spi_xfer[2].rx_buf = &phy->iobuf[4]; in tpm_tis_spi_transfer_half()
122 spi_message_add_tail(&spi_xfer[2], &m); in tpm_tis_spi_transfer_half()
124 reinit_completion(&phy->ready); in tpm_tis_spi_transfer_half()
126 ret = spi_sync(phy->spi_device, &m); in tpm_tis_spi_transfer_half()
131 memcpy(in, &phy->iobuf[4], transfer_len); in tpm_tis_spi_transfer_half()
135 len -= transfer_len; in tpm_tis_spi_transfer_half()
144 struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data); in tpm_tis_spi_transfer_full() local
146 struct spi_message m; in tpm_tis_spi_transfer_full() local
150 spi_bus_lock(phy->spi_device->controller); in tpm_tis_spi_transfer_full()
155 phy->iobuf[0] = (in ? 0x80 : 0) | (transfer_len - 1); in tpm_tis_spi_transfer_full()
156 phy->iobuf[1] = 0xd4; in tpm_tis_spi_transfer_full()
157 phy->iobuf[2] = addr >> 8; in tpm_tis_spi_transfer_full()
158 phy->iobuf[3] = addr; in tpm_tis_spi_transfer_full()
161 spi_xfer.tx_buf = phy->iobuf; in tpm_tis_spi_transfer_full()
162 spi_xfer.rx_buf = phy->iobuf; in tpm_tis_spi_transfer_full()
166 spi_message_init(&m); in tpm_tis_spi_transfer_full()
167 spi_message_add_tail(&spi_xfer, &m); in tpm_tis_spi_transfer_full()
168 ret = spi_sync_locked(phy->spi_device, &m); in tpm_tis_spi_transfer_full()
174 ret = phy->flow_control(phy, &spi_xfer); in tpm_tis_spi_transfer_full()
184 spi_xfer.tx_buf = phy->iobuf; in tpm_tis_spi_transfer_full()
186 memcpy(phy->iobuf, out, transfer_len); in tpm_tis_spi_transfer_full()
190 spi_message_init(&m); in tpm_tis_spi_transfer_full()
191 spi_message_add_tail(&spi_xfer, &m); in tpm_tis_spi_transfer_full()
192 reinit_completion(&phy->ready); in tpm_tis_spi_transfer_full()
193 ret = spi_sync_locked(phy->spi_device, &m); in tpm_tis_spi_transfer_full()
198 memcpy(in, phy->iobuf, transfer_len); in tpm_tis_spi_transfer_full()
202 len -= transfer_len; in tpm_tis_spi_transfer_full()
209 spi_message_init(&m); in tpm_tis_spi_transfer_full()
210 spi_message_add_tail(&spi_xfer, &m); in tpm_tis_spi_transfer_full()
211 spi_sync_locked(phy->spi_device, &m); in tpm_tis_spi_transfer_full()
214 spi_bus_unlock(phy->spi_device->controller); in tpm_tis_spi_transfer_full()
221 struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data); in tpm_tis_spi_transfer() local
222 struct spi_controller *ctlr = phy->spi_device->controller; in tpm_tis_spi_transfer()
230 if (ctlr->flags & SPI_CONTROLLER_HALF_DUPLEX) in tpm_tis_spi_transfer()
248 int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy, in tpm_tis_spi_init() argument
251 phy->iobuf = devm_kmalloc(&spi->dev, SPI_HDRSIZE + MAX_SPI_FRAMESIZE, GFP_KERNEL); in tpm_tis_spi_init()
252 if (!phy->iobuf) in tpm_tis_spi_init()
253 return -ENOMEM; in tpm_tis_spi_init()
255 phy->spi_device = spi; in tpm_tis_spi_init()
257 return tpm_tis_core_init(&spi->dev, &phy->priv, irq, phy_ops, NULL); in tpm_tis_spi_init()
267 struct tpm_tis_spi_phy *phy; in tpm_tis_spi_probe() local
270 phy = devm_kzalloc(&dev->dev, sizeof(struct tpm_tis_spi_phy), in tpm_tis_spi_probe()
272 if (!phy) in tpm_tis_spi_probe()
273 return -ENOMEM; in tpm_tis_spi_probe()
275 phy->flow_control = tpm_tis_spi_flow_control; in tpm_tis_spi_probe()
277 if (dev->controller->flags & SPI_CONTROLLER_HALF_DUPLEX) in tpm_tis_spi_probe()
278 dev->mode |= SPI_TPM_HW_FLOW; in tpm_tis_spi_probe()
281 if (dev->irq > 0) in tpm_tis_spi_probe()
282 irq = dev->irq; in tpm_tis_spi_probe()
284 irq = -1; in tpm_tis_spi_probe()
286 init_completion(&phy->ready); in tpm_tis_spi_probe()
287 return tpm_tis_spi_init(dev, phy, irq, &tpm_spi_phy_ops); in tpm_tis_spi_probe()
297 probe_func = of_device_get_match_data(&spi->dev); in tpm_tis_spi_driver_probe()
300 probe_func = (tpm_tis_spi_probe_func)spi_dev_id->driver_data; in tpm_tis_spi_driver_probe()
302 return -ENODEV; in tpm_tis_spi_driver_probe()
322 { "st33htpm-spi", (unsigned long)tpm_tis_spi_probe },
325 { "tpm_tis-spi", (unsigned long)tpm_tis_spi_probe },
333 { .compatible = "st,st33htpm-spi", .data = tpm_tis_spi_probe },
335 { .compatible = "tcg,tpm_tis-spi", .data = tpm_tis_spi_probe },