Lines Matching +full:max +full:- +full:retries
1 // SPDX-License-Identifier: GPL-2.0-or-later
34 * i.e. max size required for I2C write is 34 = addr, command, 32 bytes data
58 dev_dbg(&client->dev, in i2c_nuvoton_read_buf()
59 "%s(offset=%u size=%u data=%*ph) -> sts=%d\n", __func__, in i2c_nuvoton_read_buf()
70 dev_dbg(&client->dev, in i2c_nuvoton_write_buf()
71 "%s(offset=%u size=%u data=%*ph) -> sts=%d\n", __func__, in i2c_nuvoton_write_buf()
90 struct i2c_client *client = to_i2c_client(chip->dev.parent); in i2c_nuvoton_read_status()
96 dev_err(&chip->dev, "%s() error return %d\n", __func__, in i2c_nuvoton_read_status()
111 for (i = 0, status = -1; i < TPM_I2C_RETRY_COUNT && status < 0; i++) { in i2c_nuvoton_write_status()
123 struct i2c_client *client = to_i2c_client(chip->dev.parent); in i2c_nuvoton_ready()
129 dev_err(&chip->dev, in i2c_nuvoton_ready()
134 * return -1 on fail to read */
138 unsigned long stop = jiffies + chip->timeout_d; in i2c_nuvoton_get_burstcount()
140 int burst_count = -1; in i2c_nuvoton_get_burstcount()
143 /* wait for burstcount to be non-zero */ in i2c_nuvoton_get_burstcount()
173 if ((chip->flags & TPM_CHIP_FLAG_IRQ) && queue) { in i2c_nuvoton_wait_for_stat()
175 struct priv_data *priv = dev_get_drvdata(&chip->dev); in i2c_nuvoton_wait_for_stat()
176 unsigned int cur_intrs = priv->intrs; in i2c_nuvoton_wait_for_stat()
178 enable_irq(priv->irq); in i2c_nuvoton_wait_for_stat()
180 cur_intrs != priv->intrs, in i2c_nuvoton_wait_for_stat()
213 dev_err(&chip->dev, "%s(%02x, %02x) -> timeout\n", __func__, mask, in i2c_nuvoton_wait_for_stat()
215 return -ETIMEDOUT; in i2c_nuvoton_wait_for_stat()
232 struct priv_data *priv = dev_get_drvdata(&chip->dev); in i2c_nuvoton_recv_data()
238 chip->timeout_c, in i2c_nuvoton_recv_data()
239 &priv->read_queue) == 0) { in i2c_nuvoton_recv_data()
242 dev_err(&chip->dev, in i2c_nuvoton_recv_data()
245 return -EIO; in i2c_nuvoton_recv_data()
247 bytes2read = min_t(size_t, burst_count, count - size); in i2c_nuvoton_recv_data()
251 dev_err(&chip->dev, in i2c_nuvoton_recv_data()
254 return -EIO; in i2c_nuvoton_recv_data()
256 dev_dbg(&chip->dev, "%s(%d):", __func__, bytes2read); in i2c_nuvoton_recv_data()
266 struct priv_data *priv = dev_get_drvdata(&chip->dev); in i2c_nuvoton_recv()
267 struct device *dev = chip->dev.parent; in i2c_nuvoton_recv()
272 int retries; in i2c_nuvoton_recv() local
279 return -EIO; in i2c_nuvoton_recv()
281 for (retries = 0; retries < TPM_I2C_RETRIES; retries++) { in i2c_nuvoton_recv()
282 if (retries > 0) { in i2c_nuvoton_recv()
292 chip, chip->timeout_c, &priv->read_queue); in i2c_nuvoton_recv()
295 size = -ETIMEDOUT; in i2c_nuvoton_recv()
301 size = -EIO; in i2c_nuvoton_recv()
308 size = -EIO; in i2c_nuvoton_recv()
318 size = -EIO; in i2c_nuvoton_recv()
322 expected - size); in i2c_nuvoton_recv()
327 size = -EIO; in i2c_nuvoton_recv()
332 TPM_STS_VALID, chip->timeout_c, in i2c_nuvoton_recv()
335 size = -ETIMEDOUT; in i2c_nuvoton_recv()
341 dev_dbg(&chip->dev, "%s() -> %d\n", __func__, size); in i2c_nuvoton_recv()
354 struct priv_data *priv = dev_get_drvdata(&chip->dev); in i2c_nuvoton_send()
355 struct device *dev = chip->dev.parent; in i2c_nuvoton_send()
360 int burst_count, bytes2write, retries, rc = -EIO; in i2c_nuvoton_send() local
362 for (retries = 0; retries < TPM_RETRY; retries++) { in i2c_nuvoton_send()
366 chip->timeout_b, NULL)) { in i2c_nuvoton_send()
369 rc = -EIO; in i2c_nuvoton_send()
373 while (count < len - 1) { in i2c_nuvoton_send()
379 rc = -EIO; in i2c_nuvoton_send()
383 len - 1 - count); in i2c_nuvoton_send()
398 chip->timeout_c, in i2c_nuvoton_send()
403 rc = -ETIMEDOUT; in i2c_nuvoton_send()
416 rc = -EIO; in i2c_nuvoton_send()
423 chip->timeout_c, NULL); in i2c_nuvoton_send()
427 rc = -ETIMEDOUT; in i2c_nuvoton_send()
433 /* retries == TPM_RETRY */ in i2c_nuvoton_send()
447 rc = i2c_nuvoton_wait_for_data_avail(chip, duration, &priv->read_queue); in i2c_nuvoton_send()
455 dev_dbg(dev, "%s() -> %zd\n", __func__, len); in i2c_nuvoton_send()
478 * the source (plus that would be slow over I2C). Run the IRQ as a one-shot,
483 struct priv_data *priv = dev_get_drvdata(&chip->dev); in i2c_nuvoton_int_handler()
485 priv->intrs++; in i2c_nuvoton_int_handler()
486 wake_up(&priv->read_queue); in i2c_nuvoton_int_handler()
487 disable_irq_nosync(priv->irq); in i2c_nuvoton_int_handler()
497 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in get_vid()
498 return -ENODEV; in get_vid()
503 /* check WPCT301 values - ignore RID */ in get_vid()
515 /* check WPCT301 values - ignore RID */ in get_vid()
518 return -ENODEV; in get_vid()
530 struct device *dev = &client->dev; in i2c_nuvoton_probe()
547 return -ENOMEM; in i2c_nuvoton_probe()
549 if (dev->of_node) { in i2c_nuvoton_probe()
552 of_id = of_match_device(dev->driver->of_match_table, dev); in i2c_nuvoton_probe()
553 if (of_id && of_id->data == OF_IS_TPM2) in i2c_nuvoton_probe()
554 chip->flags |= TPM_CHIP_FLAG_TPM2; in i2c_nuvoton_probe()
556 if (id->driver_data == I2C_IS_TPM2) in i2c_nuvoton_probe()
557 chip->flags |= TPM_CHIP_FLAG_TPM2; in i2c_nuvoton_probe()
559 init_waitqueue_head(&priv->read_queue); in i2c_nuvoton_probe()
562 chip->timeout_a = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT); in i2c_nuvoton_probe()
563 chip->timeout_b = msecs_to_jiffies(TPM_I2C_LONG_TIMEOUT); in i2c_nuvoton_probe()
564 chip->timeout_c = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT); in i2c_nuvoton_probe()
565 chip->timeout_d = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT); in i2c_nuvoton_probe()
567 dev_set_drvdata(&chip->dev, priv); in i2c_nuvoton_probe()
574 priv->irq = client->irq; in i2c_nuvoton_probe()
575 if (client->irq) { in i2c_nuvoton_probe()
576 dev_dbg(dev, "%s() priv->irq\n", __func__); in i2c_nuvoton_probe()
577 rc = devm_request_irq(dev, client->irq, in i2c_nuvoton_probe()
580 dev_name(&chip->dev), in i2c_nuvoton_probe()
584 __func__, priv->irq); in i2c_nuvoton_probe()
585 priv->irq = 0; in i2c_nuvoton_probe()
587 chip->flags |= TPM_CHIP_FLAG_IRQ; in i2c_nuvoton_probe()
590 /* - wait for TPM_STS==0xA0 (stsValid, commandReady) */ in i2c_nuvoton_probe()
594 chip->timeout_b, in i2c_nuvoton_probe()
600 * TPM_DATA_FIFO_W <- rc (0) in i2c_nuvoton_probe()
607 /* TPM_STS <- 0x40 (commandReady) */ in i2c_nuvoton_probe()
611 * timeout_b reached - command was in i2c_nuvoton_probe()
612 * aborted. TIS should now be in idle state - in i2c_nuvoton_probe()
617 return -EIO; in i2c_nuvoton_probe()