Lines Matching +full:gain +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0
3 * HMC425A and similar Gain Amplifiers
26 * The LTC6373 amplifier supports configuring gain using GPIO's with the following
30 * From here, it is observed that all values are multiples of the '2' gain setting,
56 int (*gain_dB_to_code)(int gain, int *code);
63 struct gpio_descs *gpios; member
64 u32 gain; member
70 const struct hmc425a_chip_info *inf = st->chip_info; in gain_dB_to_code()
71 int gain; in gain_dB_to_code() local
74 gain = (val * 1000) - (val2 / 1000); in gain_dB_to_code()
76 gain = (val * 1000) + (val2 / 1000); in gain_dB_to_code()
78 if (gain > inf->gain_max || gain < inf->gain_min) in gain_dB_to_code()
79 return -EINVAL; in gain_dB_to_code()
80 if (st->powerdown) in gain_dB_to_code()
81 return -EPERM; in gain_dB_to_code()
83 return st->chip_info->gain_dB_to_code(gain, code); in gain_dB_to_code()
86 static int hmc425a_gain_dB_to_code(int gain, int *code) in hmc425a_gain_dB_to_code() argument
88 *code = ~((abs(gain) / 500) & 0x3F); in hmc425a_gain_dB_to_code()
92 static int hmc540s_gain_dB_to_code(int gain, int *code) in hmc540s_gain_dB_to_code() argument
94 *code = ~((abs(gain) / 1000) & 0xF); in hmc540s_gain_dB_to_code()
98 static int adrf5740_gain_dB_to_code(int gain, int *code) in adrf5740_gain_dB_to_code() argument
100 int temp = (abs(gain) / 2000) & 0xF; in adrf5740_gain_dB_to_code()
102 /* Bit [0-3]: 2dB 4dB 8dB 8dB */ in adrf5740_gain_dB_to_code()
107 static int ltc6373_gain_dB_to_code(int gain, int *code) in ltc6373_gain_dB_to_code() argument
109 *code = ~(DIV_ROUND_CLOSEST(gain, LTC6373_CONVERSION_CONSTANT) + 3) in ltc6373_gain_dB_to_code()
116 if (st->powerdown) in code_to_gain_dB()
117 return -EPERM; in code_to_gain_dB()
118 return st->chip_info->code_to_gain_dB(st->gain, val, val2); in code_to_gain_dB()
123 *val = (~code * -500) / 1000; in hmc425a_code_to_gain_dB()
124 *val2 = ((~code * -500) % 1000) * 1000; in hmc425a_code_to_gain_dB()
130 *val = (~code * -1000) / 1000; in hmc540s_code_to_gain_dB()
131 *val2 = ((~code * -1000) % 1000) * 1000; in hmc540s_code_to_gain_dB()
138 * Bit [0-3]: 2dB 4dB 8dB 8dB in adrf5740_code_to_gain_dB()
142 *val = (code * -2000) / 1000; in adrf5740_code_to_gain_dB()
143 *val2 = ((code * -2000) % 1000) * 1000; in adrf5740_code_to_gain_dB()
149 int gain = ((~code & LTC6373_CONVERSION_MASK) - 3) * in ltc6373_code_to_gain_dB() local
152 *val = gain / 1000; in ltc6373_code_to_gain_dB()
153 *val2 = (gain % 1000) * 1000; in ltc6373_code_to_gain_dB()
164 gpiod_set_array_value_cansleep(st->gpios->ndescs, st->gpios->desc, in hmc425a_write()
176 mutex_lock(&st->lock); in hmc425a_read_raw()
185 ret = -EINVAL; in hmc425a_read_raw()
187 mutex_unlock(&st->lock); in hmc425a_read_raw()
199 mutex_lock(&st->lock); in hmc425a_write_raw()
205 st->gain = code; in hmc425a_write_raw()
207 ret = hmc425a_write(indio_dev, st->gain); in hmc425a_write_raw()
210 ret = -EINVAL; in hmc425a_write_raw()
212 mutex_unlock(&st->lock); in hmc425a_write_raw()
225 return -EINVAL; in hmc425a_write_raw_get_fmt()
242 return sysfs_emit(buf, "%d\n", st->powerdown); in ltc6373_read_powerdown()
259 mutex_lock(&st->lock); in ltc6373_write_powerdown()
260 st->powerdown = powerdown; in ltc6373_write_powerdown()
261 code = (powerdown) ? LTC6373_SHUTDOWN : st->gain; in ltc6373_write_powerdown()
263 mutex_unlock(&st->lock); in ltc6373_write_powerdown()
310 .gain_min = -31500,
312 .default_gain = -0x40, /* set default gain -31.5db*/
321 .gain_min = -15000,
323 .default_gain = -0x10, /* set default gain -15.0db*/
332 .gain_min = -22000,
334 .default_gain = 0xF, /* set default gain -22.0db*/
343 .gain_min = -12041, /* gain setting x0.25*/
344 .gain_max = 24082, /* gain setting x16 */
359 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); in hmc425a_probe()
361 return -ENOMEM; in hmc425a_probe()
365 st->chip_info = device_get_match_data(&pdev->dev); in hmc425a_probe()
366 indio_dev->num_channels = st->chip_info->num_channels; in hmc425a_probe()
367 indio_dev->channels = st->chip_info->channels; in hmc425a_probe()
368 indio_dev->name = st->chip_info->name; in hmc425a_probe()
369 st->gain = st->chip_info->default_gain; in hmc425a_probe()
371 st->gpios = devm_gpiod_get_array(&pdev->dev, "ctrl", GPIOD_OUT_LOW); in hmc425a_probe()
372 if (IS_ERR(st->gpios)) in hmc425a_probe()
373 return dev_err_probe(&pdev->dev, PTR_ERR(st->gpios), in hmc425a_probe()
374 "failed to get gpios\n"); in hmc425a_probe()
376 if (st->gpios->ndescs != st->chip_info->num_gpios) { in hmc425a_probe()
377 dev_err(&pdev->dev, "%d GPIOs needed to operate\n", in hmc425a_probe()
378 st->chip_info->num_gpios); in hmc425a_probe()
379 return -ENODEV; in hmc425a_probe()
382 ret = devm_regulator_get_enable(&pdev->dev, "vcc-supply"); in hmc425a_probe()
386 mutex_init(&st->lock); in hmc425a_probe()
388 indio_dev->info = &hmc425a_info; in hmc425a_probe()
389 indio_dev->modes = INDIO_DIRECT_MODE; in hmc425a_probe()
391 if (st->chip_info->has_powerdown) { in hmc425a_probe()
392 st->powerdown = true; in hmc425a_probe()
393 hmc425a_write(indio_dev, st->chip_info->powerdown_val); in hmc425a_probe()
395 /* Set default gain */ in hmc425a_probe()
396 hmc425a_write(indio_dev, st->gain); in hmc425a_probe()
399 return devm_iio_device_register(&pdev->dev, indio_dev); in hmc425a_probe()
426 MODULE_DESCRIPTION("Analog Devices HMC425A and similar GPIO control Gain Amplifiers");