]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: frequency: adf4377: add adf4378 support
authorAntoniu Miclaus <antoniu.miclaus@analog.com>
Mon, 29 Jul 2024 09:50:44 +0000 (12:50 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 3 Aug 2024 09:13:45 +0000 (10:13 +0100)
Add separate handling for adf4378 within the driver.

The main difference between adf4377 and adf4378 is that adf4378 has only
one output which is handled by only one gpio.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Link: https://patch.msgid.link/20240729095047.25040-3-antoniu.miclaus@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/frequency/adf4377.c

index 9284c13f1abb3428d1d9b8d9d1a08089a7d753a1..25fbc2cef1f715695f550050d6f6be49530a21b8 100644 (file)
@@ -400,7 +400,13 @@ enum muxout_select_mode {
        ADF4377_MUXOUT_HIGH = 0x8,
 };
 
+struct adf4377_chip_info {
+       const char *name;
+       bool has_gpio_enclk2;
+};
+
 struct adf4377_state {
+       const struct adf4377_chip_info  *chip_info;
        struct spi_device       *spi;
        struct regmap           *regmap;
        struct clk              *clkin;
@@ -889,11 +895,13 @@ static int adf4377_properties_parse(struct adf4377_state *st)
                return dev_err_probe(&spi->dev, PTR_ERR(st->gpio_enclk1),
                                     "failed to get the CE GPIO\n");
 
-       st->gpio_enclk2 = devm_gpiod_get_optional(&st->spi->dev, "clk2-enable",
-                                                 GPIOD_OUT_LOW);
-       if (IS_ERR(st->gpio_enclk2))
-               return dev_err_probe(&spi->dev, PTR_ERR(st->gpio_enclk2),
-                                    "failed to get the CE GPIO\n");
+       if (st->chip_info->has_gpio_enclk2) {
+               st->gpio_enclk2 = devm_gpiod_get_optional(&st->spi->dev, "clk2-enable",
+                                                         GPIOD_OUT_LOW);
+               if (IS_ERR(st->gpio_enclk2))
+                       return dev_err_probe(&spi->dev, PTR_ERR(st->gpio_enclk2),
+                                       "failed to get the CE GPIO\n");
+       }
 
        ret = device_property_match_property_string(&spi->dev, "adi,muxout-select",
                                                    adf4377_muxout_modes,
@@ -921,6 +929,16 @@ static int adf4377_freq_change(struct notifier_block *nb, unsigned long action,
        return NOTIFY_OK;
 }
 
+static const struct adf4377_chip_info adf4377_chip_info = {
+       .name = "adf4377",
+       .has_gpio_enclk2 = true,
+};
+
+static const struct adf4377_chip_info adf4378_chip_info = {
+       .name = "adf4378",
+       .has_gpio_enclk2 = false,
+};
+
 static int adf4377_probe(struct spi_device *spi)
 {
        struct iio_dev *indio_dev;
@@ -945,6 +963,7 @@ static int adf4377_probe(struct spi_device *spi)
 
        st->regmap = regmap;
        st->spi = spi;
+       st->chip_info = spi_get_device_match_data(spi);
        mutex_init(&st->lock);
 
        ret = adf4377_properties_parse(st);
@@ -964,13 +983,15 @@ static int adf4377_probe(struct spi_device *spi)
 }
 
 static const struct spi_device_id adf4377_id[] = {
-       { "adf4377", 0 },
+       { "adf4377", (kernel_ulong_t)&adf4377_chip_info },
+       { "adf4378", (kernel_ulong_t)&adf4378_chip_info },
        {}
 };
 MODULE_DEVICE_TABLE(spi, adf4377_id);
 
 static const struct of_device_id adf4377_of_match[] = {
-       { .compatible = "adi,adf4377" },
+       { .compatible = "adi,adf4377", .data = &adf4377_chip_info },
+       { .compatible = "adi,adf4378", .data = &adf4378_chip_info },
        {}
 };
 MODULE_DEVICE_TABLE(of, adf4377_of_match);