Lines Matching +full:m +full:- +full:phy

1 // SPDX-License-Identifier: GPL-2.0
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.
52 static inline struct cr50_spi_phy *to_cr50_spi_phy(struct tpm_tis_spi_phy *phy) in to_cr50_spi_phy() argument
54 return container_of(phy, struct cr50_spi_phy, spi_phy); in to_cr50_spi_phy()
66 cr50_phy->irq_confirmed = true; in cr50_spi_irq_handler()
67 complete(&cr50_phy->spi_phy.ready); in cr50_spi_irq_handler()
76 static void cr50_ensure_access_delay(struct cr50_spi_phy *phy) in cr50_ensure_access_delay() argument
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()
117 static bool cr50_needs_waking(struct cr50_spi_phy *phy) in cr50_needs_waking() argument
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() local
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()
159 static int cr50_spi_flow_control(struct tpm_tis_spi_phy *phy, in cr50_spi_flow_control() argument
162 struct device *dev = &phy->spi_device->dev; in cr50_spi_flow_control()
164 struct spi_message m; in cr50_spi_flow_control() local
167 spi_xfer->len = 1; in cr50_spi_flow_control()
170 spi_message_init(&m); in cr50_spi_flow_control()
171 spi_message_add_tail(spi_xfer, &m); 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()
188 struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data); in tpm_tis_spi_cr50_transfer() local
189 struct cr50_spi_phy *cr50_phy = to_cr50_spi_phy(phy); in tpm_tis_spi_cr50_transfer()
192 mutex_lock(&cr50_phy->time_track_mutex); 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()
230 struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data); in cr50_print_fw_version() local
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()
255 struct tpm_tis_spi_phy *phy; in cr50_spi_probe() local
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()
318 struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data); in tpm_tis_spi_resume() local
323 phy->wake_after = jiffies; in tpm_tis_spi_resume()