Lines Matching +full:spi +full:- +full:lsb +full:- +full:first
1 // SPDX-License-Identifier: GPL-2.0
5 * This device driver implements a TCG PTP FIFO interface over SPI for chips
15 #include <linux/spi/spi.h>
23 * - can go to sleep not earlier than after CR50_SLEEP_DELAY_MSEC.
24 * - needs up to CR50_WAKE_START_DELAY_USEC to wake after sleep.
25 * - requires waiting for "ready" IRQ, if supported; or waiting for at least
27 * - waits for up to CR50_FLOW_CONTROL for flow control 'ready' indication.
66 cr50_phy->irq_confirmed = true; in cr50_spi_irq_handler()
67 complete(&cr50_phy->spi_phy.ready); in cr50_spi_irq_handler()
78 unsigned long allowed_access = phy->last_access + phy->access_delay; in cr50_ensure_access_delay()
80 struct device *dev = &phy->spi_phy.spi_device->dev; in cr50_ensure_access_delay()
88 if (time_in_range_open(time_now, phy->last_access, allowed_access)) { in cr50_ensure_access_delay()
89 unsigned long remaining, timeout = allowed_access - time_now; in cr50_ensure_access_delay()
91 remaining = wait_for_completion_timeout(&phy->spi_phy.ready, in cr50_ensure_access_delay()
93 if (!remaining && phy->irq_confirmed) in cr50_ensure_access_delay()
97 if (phy->irq_needs_confirmation) { in cr50_ensure_access_delay()
98 unsigned int attempt = ++phy->irq_confirmation_attempt; in cr50_ensure_access_delay()
100 if (phy->irq_confirmed) { in cr50_ensure_access_delay()
101 phy->irq_needs_confirmation = false; in cr50_ensure_access_delay()
102 phy->access_delay = CR50_READY_IRQ_TIMEOUT; in cr50_ensure_access_delay()
106 phy->irq_needs_confirmation = false; in cr50_ensure_access_delay()
107 dev_warn(dev, "IRQ not confirmed - will use delays\n"); in cr50_ensure_access_delay()
113 * Cr50 might go to sleep if there is no SPI activity for some time and
114 * miss the first few bits/bytes on the bus. In such case, wake it up
125 return !time_in_range_open(jiffies, phy->last_access, in cr50_needs_waking()
126 phy->spi_phy.wake_after); in cr50_needs_waking()
131 struct tpm_tis_spi_phy *phy = &cr50_phy->spi_phy; in cr50_wake_if_needed()
142 spi_sync_transfer(phy->spi_device, &spi_cs_wake, 1); in cr50_wake_if_needed()
149 phy->wake_after = jiffies + msecs_to_jiffies(CR50_SLEEP_DELAY_MSEC); in cr50_wake_if_needed()
153 * Flow control: clock the bus and wait for cr50 to set LSB before
162 struct device *dev = &phy->spi_device->dev; in cr50_spi_flow_control()
167 spi_xfer->len = 1; in cr50_spi_flow_control()
172 ret = spi_sync_locked(phy->spi_device, &m); in cr50_spi_flow_control()
178 return -EBUSY; in cr50_spi_flow_control()
180 } while (!(phy->iobuf[0] & 0x01)); in cr50_spi_flow_control()
192 mutex_lock(&cr50_phy->time_track_mutex); in tpm_tis_spi_cr50_transfer()
195 * only device on that spi bus. in tpm_tis_spi_cr50_transfer()
202 cr50_phy->last_access = jiffies; in tpm_tis_spi_cr50_transfer()
203 mutex_unlock(&cr50_phy->time_track_mutex); in tpm_tis_spi_cr50_transfer()
239 tpm_tis_write8(data, TPM_CR50_FW_VER(data->locality), 0); in cr50_print_fw_version()
243 tpm_tis_read_bytes(data, TPM_CR50_FW_VER(data->locality), 4, in cr50_print_fw_version()
250 dev_info(&phy->spi_device->dev, "Cr50 firmware version: %s\n", fw_ver); in cr50_print_fw_version()
253 int cr50_spi_probe(struct spi_device *spi) in cr50_spi_probe() argument
260 cr50_phy = devm_kzalloc(&spi->dev, sizeof(*cr50_phy), GFP_KERNEL); in cr50_spi_probe()
262 return -ENOMEM; in cr50_spi_probe()
264 phy = &cr50_phy->spi_phy; in cr50_spi_probe()
265 phy->flow_control = cr50_spi_flow_control; in cr50_spi_probe()
266 phy->wake_after = jiffies; in cr50_spi_probe()
267 init_completion(&phy->ready); in cr50_spi_probe()
269 cr50_phy->access_delay = CR50_NOIRQ_ACCESS_DELAY; in cr50_spi_probe()
270 cr50_phy->last_access = jiffies; in cr50_spi_probe()
271 mutex_init(&cr50_phy->time_track_mutex); in cr50_spi_probe()
273 if (spi->irq > 0) { in cr50_spi_probe()
274 ret = devm_request_irq(&spi->dev, spi->irq, in cr50_spi_probe()
279 if (ret == -EPROBE_DEFER) in cr50_spi_probe()
281 dev_warn(&spi->dev, "Requesting IRQ %d failed: %d\n", in cr50_spi_probe()
282 spi->irq, ret); in cr50_spi_probe()
294 cr50_phy->irq_needs_confirmation = true; in cr50_spi_probe()
297 dev_warn(&spi->dev, in cr50_spi_probe()
298 "No IRQ - will use delays between transactions.\n"); in cr50_spi_probe()
301 ret = tpm_tis_spi_init(spi, phy, -1, &tpm_spi_cr50_phy_ops); in cr50_spi_probe()
305 cr50_print_fw_version(&phy->priv); in cr50_spi_probe()
307 chip = dev_get_drvdata(&spi->dev); in cr50_spi_probe()
308 chip->flags |= TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED; in cr50_spi_probe()
317 struct tpm_tis_data *data = dev_get_drvdata(&chip->dev); in tpm_tis_spi_resume()
323 phy->wake_after = jiffies; in tpm_tis_spi_resume()