Commit ed73c4f1 authored by Ana-Maria Cusco's avatar Ana-Maria Cusco Committed by Jonathan Cameron

iio: amplifiers: hmc425a: add support for ADRF5740 Attenuator

This adds support for the Analog Devices ADRF5740 2 dB LSB, 4-Bit,
Silicon Digital Attenuator, 10 MHz to 60 GHz.
The default (maximum) gain is also set at probe time, with GPIO lines
driven high to achieve maximum gain, in contrast to other devices
where GPIOs need to be driven low.
Signed-off-by: default avatarAna-Maria Cusco <ana-maria.cusco@analog.com>
Link: https://lore.kernel.org/r/20231113102535.51074-2-anamaria.cuscoo@gmail.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 79f2ff64
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Copyright 2020 Analog Devices Inc. * Copyright 2020 Analog Devices Inc.
*/ */
#include <linux/bitops.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
enum hmc425a_type { enum hmc425a_type {
ID_HMC425A, ID_HMC425A,
ID_HMC540S, ID_HMC540S,
ID_ADRF5740
}; };
struct hmc425a_chip_info { struct hmc425a_chip_info {
...@@ -74,6 +76,10 @@ static int hmc425a_read_raw(struct iio_dev *indio_dev, ...@@ -74,6 +76,10 @@ static int hmc425a_read_raw(struct iio_dev *indio_dev,
case ID_HMC540S: case ID_HMC540S:
gain = ~code * -1000; gain = ~code * -1000;
break; break;
case ID_ADRF5740:
code = code & BIT(3) ? code & ~BIT(2) : code;
gain = code * -2000;
break;
} }
*val = gain / 1000; *val = gain / 1000;
...@@ -113,6 +119,10 @@ static int hmc425a_write_raw(struct iio_dev *indio_dev, ...@@ -113,6 +119,10 @@ static int hmc425a_write_raw(struct iio_dev *indio_dev,
case ID_HMC540S: case ID_HMC540S:
code = ~((abs(gain) / 1000) & 0xF); code = ~((abs(gain) / 1000) & 0xF);
break; break;
case ID_ADRF5740:
code = (abs(gain) / 2000) & 0xF;
code = code & BIT(3) ? code | BIT(2) : code;
break;
} }
mutex_lock(&st->lock); mutex_lock(&st->lock);
...@@ -165,6 +175,7 @@ static const struct iio_chan_spec hmc425a_channels[] = { ...@@ -165,6 +175,7 @@ static const struct iio_chan_spec hmc425a_channels[] = {
static const struct of_device_id hmc425a_of_match[] = { static const struct of_device_id hmc425a_of_match[] = {
{ .compatible = "adi,hmc425a", .data = (void *)ID_HMC425A }, { .compatible = "adi,hmc425a", .data = (void *)ID_HMC425A },
{ .compatible = "adi,hmc540s", .data = (void *)ID_HMC540S }, { .compatible = "adi,hmc540s", .data = (void *)ID_HMC540S },
{ .compatible = "adi,adrf5740", .data = (void *)ID_ADRF5740 },
{}, {},
}; };
MODULE_DEVICE_TABLE(of, hmc425a_of_match); MODULE_DEVICE_TABLE(of, hmc425a_of_match);
...@@ -188,6 +199,15 @@ static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = { ...@@ -188,6 +199,15 @@ static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = {
.gain_max = 0, .gain_max = 0,
.default_gain = -0x10, /* set default gain -15.0db*/ .default_gain = -0x10, /* set default gain -15.0db*/
}, },
[ID_ADRF5740] = {
.name = "adrf5740",
.channels = hmc425a_channels,
.num_channels = ARRAY_SIZE(hmc425a_channels),
.num_gpios = 4,
.gain_min = -22000,
.gain_max = 0,
.default_gain = 0xF, /* set default gain -22.0db*/
},
}; };
static int hmc425a_probe(struct platform_device *pdev) static int hmc425a_probe(struct platform_device *pdev)
...@@ -229,6 +249,9 @@ static int hmc425a_probe(struct platform_device *pdev) ...@@ -229,6 +249,9 @@ static int hmc425a_probe(struct platform_device *pdev)
indio_dev->info = &hmc425a_info; indio_dev->info = &hmc425a_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
/* Set default gain */
hmc425a_write(indio_dev, st->gain);
return devm_iio_device_register(&pdev->dev, indio_dev); return devm_iio_device_register(&pdev->dev, indio_dev);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment