[PATCH v3 07/16] rockchip: adc: rockchip-saradc: use union for preparing for v2

Kever Yang kever.yang at rock-chips.com
Mon Mar 11 11:12:33 CET 2024


On 2024/3/4 19:30, Quentin Schulz wrote:
> From: Quentin Schulz <quentin.schulz at theobroma-systems.com>
>
> The registers are entirely different between SARADC v1 and SARADC v2, so
> let's prepare to add another struct for accessing v2 registers by adding
> a union.
>
> Cc: Quentin Schulz <quentin.schulz at theobroma-systems.com>
> Signed-off-by: Quentin Schulz <quentin.schulz at theobroma-systems.com>
Reviewed-by: Kever Yang <kever.yang at rock-chips.com>

Thanks,
- Kever
> ---
>   drivers/adc/rockchip-saradc.c | 23 +++++++++++++----------
>   1 file changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/adc/rockchip-saradc.c b/drivers/adc/rockchip-saradc.c
> index 03caca78b5f..4a842556a60 100644
> --- a/drivers/adc/rockchip-saradc.c
> +++ b/drivers/adc/rockchip-saradc.c
> @@ -23,13 +23,16 @@
>   
>   #define SARADC_TIMEOUT			(100 * 1000)
>   
> -struct rockchip_saradc_regs {
> +struct rockchip_saradc_regs_v1 {
>   	unsigned int data;
>   	unsigned int stas;
>   	unsigned int ctrl;
>   	unsigned int dly_pu_soc;
>   };
>   
> +union rockchip_saradc_regs {
> +	struct rockchip_saradc_regs_v1	*v1;
> +};
>   struct rockchip_saradc_data {
>   	int				num_bits;
>   	int				num_channels;
> @@ -37,7 +40,7 @@ struct rockchip_saradc_data {
>   };
>   
>   struct rockchip_saradc_priv {
> -	struct rockchip_saradc_regs		*regs;
> +	union rockchip_saradc_regs		regs;
>   	int					active_channel;
>   	const struct rockchip_saradc_data	*data;
>   };
> @@ -53,16 +56,16 @@ int rockchip_saradc_channel_data(struct udevice *dev, int channel,
>   		return -EINVAL;
>   	}
>   
> -	if ((readl(&priv->regs->ctrl) & SARADC_CTRL_IRQ_STATUS) !=
> +	if ((readl(&priv->regs.v1->ctrl) & SARADC_CTRL_IRQ_STATUS) !=
>   	    SARADC_CTRL_IRQ_STATUS)
>   		return -EBUSY;
>   
>   	/* Read value */
> -	*data = readl(&priv->regs->data);
> +	*data = readl(&priv->regs.v1->data);
>   	*data &= uc_pdata->data_mask;
>   
>   	/* Power down adc */
> -	writel(0, &priv->regs->ctrl);
> +	writel(0, &priv->regs.v1->ctrl);
>   
>   	return 0;
>   }
> @@ -77,11 +80,11 @@ int rockchip_saradc_start_channel(struct udevice *dev, int channel)
>   	}
>   
>   	/* 8 clock periods as delay between power up and start cmd */
> -	writel(8, &priv->regs->dly_pu_soc);
> +	writel(8, &priv->regs.v1->dly_pu_soc);
>   
>   	/* Select the channel to be used and trigger conversion */
>   	writel(SARADC_CTRL_POWER_CTRL | (channel & SARADC_CTRL_CHN_MASK) |
> -	       SARADC_CTRL_IRQ_ENABLE, &priv->regs->ctrl);
> +	       SARADC_CTRL_IRQ_ENABLE, &priv->regs.v1->ctrl);
>   
>   	priv->active_channel = channel;
>   
> @@ -93,7 +96,7 @@ int rockchip_saradc_stop(struct udevice *dev)
>   	struct rockchip_saradc_priv *priv = dev_get_priv(dev);
>   
>   	/* Power down adc */
> -	writel(0, &priv->regs->ctrl);
> +	writel(0, &priv->regs.v1->ctrl);
>   
>   	priv->active_channel = -1;
>   
> @@ -146,8 +149,8 @@ int rockchip_saradc_of_to_plat(struct udevice *dev)
>   	struct rockchip_saradc_data *data;
>   
>   	data = (struct rockchip_saradc_data *)dev_get_driver_data(dev);
> -	priv->regs = dev_read_addr_ptr(dev);
> -	if (!priv->regs) {
> +	priv->regs.v1 = dev_read_addr_ptr(dev);
> +	if (!priv->regs.v1) {
>   		pr_err("Dev: %s - can't get address!", dev->name);
>   		return -EINVAL;
>   	}
>


More information about the U-Boot mailing list