Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Ana-Maria Cusco <ana-maria.cusco@analog.com>
Link: https://lore.kernel.org/r/20231113102535.51074-2-anamaria.cuscoo@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Ana-Maria Cusco and committed by
Jonathan Cameron
ed73c4f1 79f2ff64

+23
+23
drivers/iio/amplifiers/hmc425a.c
··· 5 5 * Copyright 2020 Analog Devices Inc. 6 6 */ 7 7 8 + #include <linux/bitops.h> 8 9 #include <linux/device.h> 9 10 #include <linux/err.h> 10 11 #include <linux/gpio/consumer.h> ··· 23 22 enum hmc425a_type { 24 23 ID_HMC425A, 25 24 ID_HMC540S, 25 + ID_ADRF5740 26 26 }; 27 27 28 28 struct hmc425a_chip_info { ··· 76 74 case ID_HMC540S: 77 75 gain = ~code * -1000; 78 76 break; 77 + case ID_ADRF5740: 78 + code = code & BIT(3) ? code & ~BIT(2) : code; 79 + gain = code * -2000; 80 + break; 79 81 } 80 82 81 83 *val = gain / 1000; ··· 118 112 break; 119 113 case ID_HMC540S: 120 114 code = ~((abs(gain) / 1000) & 0xF); 115 + break; 116 + case ID_ADRF5740: 117 + code = (abs(gain) / 2000) & 0xF; 118 + code = code & BIT(3) ? code | BIT(2) : code; 121 119 break; 122 120 } 123 121 ··· 175 165 static const struct of_device_id hmc425a_of_match[] = { 176 166 { .compatible = "adi,hmc425a", .data = (void *)ID_HMC425A }, 177 167 { .compatible = "adi,hmc540s", .data = (void *)ID_HMC540S }, 168 + { .compatible = "adi,adrf5740", .data = (void *)ID_ADRF5740 }, 178 169 {}, 179 170 }; 180 171 MODULE_DEVICE_TABLE(of, hmc425a_of_match); ··· 198 187 .gain_min = -15000, 199 188 .gain_max = 0, 200 189 .default_gain = -0x10, /* set default gain -15.0db*/ 190 + }, 191 + [ID_ADRF5740] = { 192 + .name = "adrf5740", 193 + .channels = hmc425a_channels, 194 + .num_channels = ARRAY_SIZE(hmc425a_channels), 195 + .num_gpios = 4, 196 + .gain_min = -22000, 197 + .gain_max = 0, 198 + .default_gain = 0xF, /* set default gain -22.0db*/ 201 199 }, 202 200 }; 203 201 ··· 248 228 249 229 indio_dev->info = &hmc425a_info; 250 230 indio_dev->modes = INDIO_DIRECT_MODE; 231 + 232 + /* Set default gain */ 233 + hmc425a_write(indio_dev, st->gain); 251 234 252 235 return devm_iio_device_register(&pdev->dev, indio_dev); 253 236 }