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: adc: ltc2309: add support for ltc2305

Add support for the LTC2305 ADC to the LTC2309 driver. The LTC2305 is
a 2-channel, 12-bit SAR ADC that is register-compatible with the
LTC2309 but has a different channel selection mapping and count.

To support multiple chips in this family, introduce ltc2309_chip_info
struct to store chip-specific channel specifications and names.
The probe function now uses i2c_get_match_data() to retrieve the
correct configuration for the detected device.

Specific channel addresses for LTC2305 (CH0, CH1, and differential
pairs) are added based on the datasheet.

Signed-off-by: Kyle Hsieh <kylehsieh1995@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Kyle Hsieh and committed by
Jonathan Cameron
8625d418 999ca380

+44 -5
+44 -5
drivers/iio/adc/ltc2309.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 + * The LTC2305 is a 2-Channel, 12-Bit SAR ADC with an I2C Interface. 3 4 * The LTC2309 is an 8-Channel, 12-Bit SAR ADC with an I2C Interface. 4 5 * 5 6 * Datasheet: 7 + * https://www.analog.com/media/en/technical-documentation/data-sheets/23015fb.pdf 6 8 * https://www.analog.com/media/en/technical-documentation/data-sheets/2309fd.pdf 7 9 * 8 10 * Copyright (c) 2023, Liam Beguin <liambeguin@gmail.com> ··· 43 41 }; 44 42 45 43 /* Order matches expected channel address, See datasheet Table 1. */ 44 + enum ltc2305_channels { 45 + LTC2305_CH0_CH1 = 0x0, 46 + LTC2305_CH1_CH0 = 0x4, 47 + LTC2305_CH0 = 0x8, 48 + LTC2305_CH1 = 0xc, 49 + }; 50 + 46 51 enum ltc2309_channels { 47 52 LTC2309_CH0_CH1 = 0x0, 48 53 LTC2309_CH2_CH3 = 0x1, ··· 89 80 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ 90 81 } 91 82 83 + static const struct iio_chan_spec ltc2305_channels[] = { 84 + LTC2309_CHAN(0, LTC2305_CH0), 85 + LTC2309_CHAN(1, LTC2305_CH1), 86 + LTC2309_DIFF_CHAN(0, 1, LTC2305_CH0_CH1), 87 + LTC2309_DIFF_CHAN(1, 0, LTC2305_CH1_CH0), 88 + }; 89 + 92 90 static const struct iio_chan_spec ltc2309_channels[] = { 93 91 LTC2309_CHAN(0, LTC2309_CH0), 94 92 LTC2309_CHAN(1, LTC2309_CH1), ··· 113 97 LTC2309_DIFF_CHAN(3, 2, LTC2309_CH3_CH2), 114 98 LTC2309_DIFF_CHAN(5, 4, LTC2309_CH5_CH4), 115 99 LTC2309_DIFF_CHAN(7, 6, LTC2309_CH7_CH6), 100 + }; 101 + 102 + struct ltc2309_chip_info { 103 + const char *name; 104 + const struct iio_chan_spec *channels; 105 + int num_channels; 106 + }; 107 + 108 + static const struct ltc2309_chip_info ltc2305_chip_info = { 109 + .name = "ltc2305", 110 + .channels = ltc2305_channels, 111 + .num_channels = ARRAY_SIZE(ltc2305_channels), 112 + }; 113 + 114 + static const struct ltc2309_chip_info ltc2309_chip_info = { 115 + .name = "ltc2309", 116 + .channels = ltc2309_channels, 117 + .num_channels = ARRAY_SIZE(ltc2309_channels), 116 118 }; 117 119 118 120 static int ltc2309_read_raw_channel(struct ltc2309 *ltc2309, ··· 192 158 193 159 static int ltc2309_probe(struct i2c_client *client) 194 160 { 161 + const struct ltc2309_chip_info *chip_info; 195 162 struct iio_dev *indio_dev; 196 163 struct ltc2309 *ltc2309; 197 164 int ret; ··· 202 167 return -ENOMEM; 203 168 204 169 ltc2309 = iio_priv(indio_dev); 170 + chip_info = i2c_get_match_data(client); 171 + 205 172 ltc2309->dev = &indio_dev->dev; 206 173 ltc2309->client = client; 207 174 208 - indio_dev->name = "ltc2309"; 175 + indio_dev->name = chip_info->name; 209 176 indio_dev->modes = INDIO_DIRECT_MODE; 210 - indio_dev->channels = ltc2309_channels; 211 - indio_dev->num_channels = ARRAY_SIZE(ltc2309_channels); 177 + indio_dev->channels = chip_info->channels; 178 + indio_dev->num_channels = chip_info->num_channels; 212 179 indio_dev->info = &ltc2309_info; 213 180 214 181 ret = devm_regulator_get_enable_read_voltage(&client->dev, "vref"); ··· 226 189 } 227 190 228 191 static const struct of_device_id ltc2309_of_match[] = { 229 - { .compatible = "lltc,ltc2309" }, 192 + { .compatible = "lltc,ltc2305", .data = &ltc2305_chip_info }, 193 + { .compatible = "lltc,ltc2309", .data = &ltc2309_chip_info }, 230 194 { } 231 195 }; 232 196 MODULE_DEVICE_TABLE(of, ltc2309_of_match); 233 197 234 198 static const struct i2c_device_id ltc2309_id[] = { 235 - { "ltc2309" }, 199 + { "ltc2305", (kernel_ulong_t)&ltc2305_chip_info }, 200 + { "ltc2309", (kernel_ulong_t)&ltc2309_chip_info }, 236 201 { } 237 202 }; 238 203 MODULE_DEVICE_TABLE(i2c, ltc2309_id);