]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
rockchip: adc: rockchip-saradc: factor out start_channel callback
authorQuentin Schulz <quentin.schulz@theobroma-systems.com>
Thu, 14 Mar 2024 09:36:22 +0000 (10:36 +0100)
committerKever Yang <kever.yang@rock-chips.com>
Thu, 14 Mar 2024 10:19:44 +0000 (18:19 +0800)
SARADC v1 and v2 have a different way of starting a channel, therefore
let's abstract this function so that it can be provided from the
udevice.data pointer.

Cc: Quentin Schulz <foss+uboot@0leil.net>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
drivers/adc/rockchip-saradc.c

index 1cc57beecc2e9481065fc1887007edc9617cb4c3..607d10b5b709585ee2adcdec3490ba721a62b494 100644 (file)
@@ -38,6 +38,7 @@ struct rockchip_saradc_data {
        int                             num_channels;
        unsigned long                   clk_rate;
        int (*channel_data)(struct udevice *dev, int channel, unsigned int *data);
+       int (*start_channel)(struct udevice *dev, int channel);
 };
 
 struct rockchip_saradc_priv {
@@ -88,15 +89,10 @@ int rockchip_saradc_channel_data(struct udevice *dev, int channel,
        return 0;
 }
 
-int rockchip_saradc_start_channel(struct udevice *dev, int channel)
+int rockchip_saradc_start_channel_v1(struct udevice *dev, int channel)
 {
        struct rockchip_saradc_priv *priv = dev_get_priv(dev);
 
-       if (channel < 0 || channel >= priv->data->num_channels) {
-               pr_err("Requested channel is invalid!");
-               return -EINVAL;
-       }
-
        /* 8 clock periods as delay between power up and start cmd */
        writel(8, &priv->regs.v1->dly_pu_soc);
 
@@ -104,6 +100,25 @@ int rockchip_saradc_start_channel(struct udevice *dev, int channel)
        writel(SARADC_CTRL_POWER_CTRL | (channel & SARADC_CTRL_CHN_MASK) |
               SARADC_CTRL_IRQ_ENABLE, &priv->regs.v1->ctrl);
 
+       return 0;
+}
+
+int rockchip_saradc_start_channel(struct udevice *dev, int channel)
+{
+       struct rockchip_saradc_priv *priv = dev_get_priv(dev);
+       int ret;
+
+       if (channel < 0 || channel >= priv->data->num_channels) {
+               pr_err("Requested channel is invalid!");
+               return -EINVAL;
+       }
+
+       ret = priv->data->start_channel(dev, channel);
+       if (ret) {
+               pr_err("Error starting channel, %d!", ret);
+               return ret;
+       }
+
        priv->active_channel = channel;
 
        return 0;
@@ -193,6 +208,7 @@ static const struct rockchip_saradc_data saradc_data = {
        .num_channels = 3,
        .clk_rate = 1000000,
        .channel_data = rockchip_saradc_channel_data_v1,
+       .start_channel = rockchip_saradc_start_channel_v1,
 };
 
 static const struct rockchip_saradc_data rk3066_tsadc_data = {
@@ -200,6 +216,7 @@ static const struct rockchip_saradc_data rk3066_tsadc_data = {
        .num_channels = 2,
        .clk_rate = 50000,
        .channel_data = rockchip_saradc_channel_data_v1,
+       .start_channel = rockchip_saradc_start_channel_v1,
 };
 
 static const struct rockchip_saradc_data rk3399_saradc_data = {
@@ -207,6 +224,7 @@ static const struct rockchip_saradc_data rk3399_saradc_data = {
        .num_channels = 6,
        .clk_rate = 1000000,
        .channel_data = rockchip_saradc_channel_data_v1,
+       .start_channel = rockchip_saradc_start_channel_v1,
 };
 
 static const struct udevice_id rockchip_saradc_ids[] = {