[PATCH v1 11/17] rockchip: adc: fix adc timer

Johan Jonker jbx6244 at gmail.com
Sun May 8 17:08:19 CEST 2022


Replace adc timer counter by SoC timer to prevent
EBUSY notifications.

Signed-off-by: Johan Jonker <jbx6244 at gmail.com>
---
 drivers/adc/adc-uclass.c      | 10 ++++++----
 drivers/adc/rockchip-saradc.c |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/adc/adc-uclass.c b/drivers/adc/adc-uclass.c
index 3dbdfa6f..a539f999 100644
--- a/drivers/adc/adc-uclass.c
+++ b/drivers/adc/adc-uclass.c
@@ -146,6 +146,7 @@ int adc_channel_data(struct udevice *dev, int channel, unsigned int *data)
 	struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev);
 	const struct adc_ops *ops = dev_get_driver_ops(dev);
 	unsigned int timeout_us = uc_pdata->data_timeout_us;
+	unsigned long start_time;
 	int ret;
 
 	if (!ops->channel_data)
@@ -155,14 +156,14 @@ int adc_channel_data(struct udevice *dev, int channel, unsigned int *data)
 	if (ret)
 		return ret;
 
+	start_time = get_timer(0);
 	do {
 		ret = ops->channel_data(dev, channel, data);
 		if (!ret || ret != -EBUSY)
 			break;
 
-		/* TODO: use timer uclass (for early calls). */
 		sdelay(5);
-	} while (timeout_us--);
+	} while (get_timer(start_time) < timeout_us);
 
 	return ret;
 }
@@ -173,6 +174,7 @@ int adc_channels_data(struct udevice *dev, unsigned int channel_mask,
 	struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev);
 	unsigned int timeout_us = uc_pdata->multidata_timeout_us;
 	const struct adc_ops *ops = dev_get_driver_ops(dev);
+	unsigned long start_time;
 	int ret;
 
 	if (!ops->channels_data)
@@ -182,14 +184,14 @@ int adc_channels_data(struct udevice *dev, unsigned int channel_mask,
 	if (ret)
 		return ret;
 
+	start_time = get_timer(0);
 	do {
 		ret = ops->channels_data(dev, channel_mask, channels);
 		if (!ret || ret != -EBUSY)
 			break;
 
-		/* TODO: use timer uclass (for early calls). */
 		sdelay(5);
-	} while (timeout_us--);
+	} while (get_timer(start_time) < timeout_us);
 
 	return ret;
 }
diff --git a/drivers/adc/rockchip-saradc.c b/drivers/adc/rockchip-saradc.c
index f61cfe4b..e6a0341d 100644
--- a/drivers/adc/rockchip-saradc.c
+++ b/drivers/adc/rockchip-saradc.c
@@ -183,7 +183,7 @@ int rockchip_saradc_of_to_plat(struct udevice *dev)
 
 	uc_pdata->data_mask = (1 << priv->data->num_bits) - 1;
 	uc_pdata->data_format = ADC_DATA_FORMAT_BIN;
-	uc_pdata->data_timeout_us = SARADC_TIMEOUT / 5;
+	uc_pdata->data_timeout_us = SARADC_TIMEOUT;
 	uc_pdata->channel_mask = (1 << priv->data->num_channels) - 1;
 
 	return 0;
-- 
2.20.1



More information about the U-Boot mailing list