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.
55 static inline struct cr50_spi_phy *to_cr50_spi_phy(struct tpm_tis_spi_phy *phy) in to_cr50_spi_phy() argument
57 return container_of(phy, struct cr50_spi_phy, spi_phy); in to_cr50_spi_phy()
69 cr50_phy->irq_confirmed = true; in cr50_spi_irq_handler()
70 complete(&cr50_phy->spi_phy.ready); in cr50_spi_irq_handler()
79 static void cr50_ensure_access_delay(struct cr50_spi_phy *phy) in cr50_ensure_access_delay() argument
81 unsigned long allowed_access = phy->last_access + phy->access_delay; in cr50_ensure_access_delay()
83 struct device *dev = &phy->spi_phy.spi_device->dev; in cr50_ensure_access_delay()
91 if (time_in_range_open(time_now, phy->last_access, allowed_access)) { in cr50_ensure_access_delay()
92 unsigned long remaining, timeout = allowed_access - time_now; in cr50_ensure_access_delay()
94 remaining = wait_for_completion_timeout(&phy->spi_phy.ready, in cr50_ensure_access_delay()
96 if (!remaining && phy->irq_confirmed) in cr50_ensure_access_delay()
100 if (phy->irq_needs_confirmation) { in cr50_ensure_access_delay()
101 unsigned int attempt = ++phy->irq_confirmation_attempt; in cr50_ensure_access_delay()
103 if (phy->irq_confirmed) { in cr50_ensure_access_delay()
104 phy->irq_needs_confirmation = false; in cr50_ensure_access_delay()
105 phy->access_delay = CR50_READY_IRQ_TIMEOUT; in cr50_ensure_access_delay()
109 phy->irq_needs_confirmation = false; in cr50_ensure_access_delay()
110 dev_warn(dev, "IRQ not confirmed - will use delays\n"); in cr50_ensure_access_delay()
120 static bool cr50_needs_waking(struct cr50_spi_phy *phy) in cr50_needs_waking() argument
128 return !time_in_range_open(jiffies, phy->last_access, in cr50_needs_waking()
129 phy->spi_phy.wake_after); in cr50_needs_waking()
134 struct tpm_tis_spi_phy *phy = &cr50_phy->spi_phy; in cr50_wake_if_needed() local
145 spi_sync_transfer(phy->spi_device, &spi_cs_wake, 1); in cr50_wake_if_needed()
152 phy->wake_after = jiffies + msecs_to_jiffies(CR50_SLEEP_DELAY_MSEC); in cr50_wake_if_needed()
162 static int cr50_spi_flow_control(struct tpm_tis_spi_phy *phy, in cr50_spi_flow_control() argument
165 struct device *dev = &phy->spi_device->dev; in cr50_spi_flow_control()
167 struct spi_message m; in cr50_spi_flow_control() local
170 spi_xfer->len = 1; in cr50_spi_flow_control()
173 spi_message_init(&m); in cr50_spi_flow_control()
174 spi_message_add_tail(spi_xfer, &m); in cr50_spi_flow_control()
175 ret = spi_sync_locked(phy->spi_device, &m); in cr50_spi_flow_control()
181 return -EBUSY; in cr50_spi_flow_control()
183 } while (!(phy->iobuf[0] & 0x01)); in cr50_spi_flow_control()
194 ret = device_property_read_u8(dev, "firmware-power-managed", &val); in tpm_cr50_spi_is_firmware_power_managed()
204 struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data); in tpm_tis_spi_cr50_transfer() local
205 struct cr50_spi_phy *cr50_phy = to_cr50_spi_phy(phy); in tpm_tis_spi_cr50_transfer()
208 mutex_lock(&cr50_phy->time_track_mutex); in tpm_tis_spi_cr50_transfer()
218 cr50_phy->last_access = jiffies; in tpm_tis_spi_cr50_transfer()
219 mutex_unlock(&cr50_phy->time_track_mutex); in tpm_tis_spi_cr50_transfer()
243 struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data); in cr50_print_fw_version() local
252 tpm_tis_write8(data, TPM_CR50_FW_VER(data->locality), 0); in cr50_print_fw_version()
256 tpm_tis_read_bytes(data, TPM_CR50_FW_VER(data->locality), 4, in cr50_print_fw_version()
263 dev_info(&phy->spi_device->dev, "Cr50 firmware version: %s\n", fw_ver); in cr50_print_fw_version()
268 struct tpm_tis_spi_phy *phy; in cr50_spi_probe() local
273 cr50_phy = devm_kzalloc(&spi->dev, sizeof(*cr50_phy), GFP_KERNEL); in cr50_spi_probe()
275 return -ENOMEM; in cr50_spi_probe()
277 phy = &cr50_phy->spi_phy; in cr50_spi_probe()
278 phy->flow_control = cr50_spi_flow_control; in cr50_spi_probe()
279 phy->wake_after = jiffies; in cr50_spi_probe()
280 phy->priv.rng_quality = TPM_CR50_DEFAULT_RNG_QUALITY; in cr50_spi_probe()
281 init_completion(&phy->ready); in cr50_spi_probe()
283 cr50_phy->access_delay = CR50_NOIRQ_ACCESS_DELAY; in cr50_spi_probe()
284 cr50_phy->last_access = jiffies; in cr50_spi_probe()
285 mutex_init(&cr50_phy->time_track_mutex); in cr50_spi_probe()
287 if (spi->irq > 0) { in cr50_spi_probe()
288 ret = devm_request_irq(&spi->dev, spi->irq, in cr50_spi_probe()
293 if (ret == -EPROBE_DEFER) in cr50_spi_probe()
295 dev_warn(&spi->dev, "Requesting IRQ %d failed: %d\n", in cr50_spi_probe()
296 spi->irq, ret); in cr50_spi_probe()
308 cr50_phy->irq_needs_confirmation = true; in cr50_spi_probe()
311 dev_warn(&spi->dev, in cr50_spi_probe()
312 "No IRQ - will use delays between transactions.\n"); in cr50_spi_probe()
315 ret = tpm_tis_spi_init(spi, phy, -1, &tpm_spi_cr50_phy_ops); in cr50_spi_probe()
319 cr50_print_fw_version(&phy->priv); in cr50_spi_probe()
321 chip = dev_get_drvdata(&spi->dev); in cr50_spi_probe()
322 if (tpm_cr50_spi_is_firmware_power_managed(&spi->dev)) in cr50_spi_probe()
323 chip->flags |= TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED; in cr50_spi_probe()
332 struct tpm_tis_data *data = dev_get_drvdata(&chip->dev); in tpm_tis_spi_resume()
333 struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data); in tpm_tis_spi_resume() local
338 phy->wake_after = jiffies; in tpm_tis_spi_resume()