Lines Matching +full:int +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0
29 unsigned int num_channels;
30 unsigned int num_gpios;
31 int gain_min;
32 int gain_max;
33 int default_gain;
40 struct gpio_descs *gpios; member
45 static int hmc425a_write(struct iio_dev *indio_dev, u32 value) in hmc425a_write()
52 gpiod_set_array_value_cansleep(st->gpios->ndescs, st->gpios->desc, in hmc425a_write()
57 static int hmc425a_read_raw(struct iio_dev *indio_dev, in hmc425a_read_raw()
58 struct iio_chan_spec const *chan, int *val, in hmc425a_read_raw()
59 int *val2, long m) in hmc425a_read_raw()
62 int code, gain = 0; in hmc425a_read_raw()
63 int ret; in hmc425a_read_raw()
65 mutex_lock(&st->lock); in hmc425a_read_raw()
68 code = st->gain; in hmc425a_read_raw()
70 switch (st->type) { in hmc425a_read_raw()
72 gain = ~code * -500; in hmc425a_read_raw()
82 ret = -EINVAL; in hmc425a_read_raw()
84 mutex_unlock(&st->lock); in hmc425a_read_raw()
89 static int hmc425a_write_raw(struct iio_dev *indio_dev, in hmc425a_write_raw()
90 struct iio_chan_spec const *chan, int val, in hmc425a_write_raw()
91 int val2, long mask) in hmc425a_write_raw()
94 struct hmc425a_chip_info *inf = st->chip_info; in hmc425a_write_raw()
95 int code = 0, gain; in hmc425a_write_raw()
96 int ret; in hmc425a_write_raw()
99 gain = (val * 1000) - (val2 / 1000); in hmc425a_write_raw()
103 if (gain > inf->gain_max || gain < inf->gain_min) in hmc425a_write_raw()
104 return -EINVAL; in hmc425a_write_raw()
106 switch (st->type) { in hmc425a_write_raw()
112 mutex_lock(&st->lock); in hmc425a_write_raw()
115 st->gain = code; in hmc425a_write_raw()
117 ret = hmc425a_write(indio_dev, st->gain); in hmc425a_write_raw()
120 ret = -EINVAL; in hmc425a_write_raw()
122 mutex_unlock(&st->lock); in hmc425a_write_raw()
127 static int hmc425a_write_raw_get_fmt(struct iio_dev *indio_dev, in hmc425a_write_raw_get_fmt()
135 return -EINVAL; in hmc425a_write_raw_get_fmt()
169 regulator_disable(st->reg); in hmc425a_reg_disable()
178 .gain_min = -31500,
180 .default_gain = -0x40, /* set default gain -31.5db*/
184 static int hmc425a_probe(struct platform_device *pdev) in hmc425a_probe()
188 int ret; in hmc425a_probe()
190 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); in hmc425a_probe()
192 return -ENOMEM; in hmc425a_probe()
195 st->type = (uintptr_t)device_get_match_data(&pdev->dev); in hmc425a_probe()
197 st->chip_info = &hmc425a_chip_info_tbl[st->type]; in hmc425a_probe()
198 indio_dev->num_channels = st->chip_info->num_channels; in hmc425a_probe()
199 indio_dev->channels = st->chip_info->channels; in hmc425a_probe()
200 indio_dev->name = st->chip_info->name; in hmc425a_probe()
201 st->gain = st->chip_info->default_gain; in hmc425a_probe()
203 st->gpios = devm_gpiod_get_array(&pdev->dev, "ctrl", GPIOD_OUT_LOW); in hmc425a_probe()
204 if (IS_ERR(st->gpios)) in hmc425a_probe()
205 return dev_err_probe(&pdev->dev, PTR_ERR(st->gpios), in hmc425a_probe()
206 "failed to get gpios\n"); in hmc425a_probe()
208 if (st->gpios->ndescs != st->chip_info->num_gpios) { in hmc425a_probe()
209 dev_err(&pdev->dev, "%d GPIOs needed to operate\n", in hmc425a_probe()
210 st->chip_info->num_gpios); in hmc425a_probe()
211 return -ENODEV; in hmc425a_probe()
214 st->reg = devm_regulator_get(&pdev->dev, "vcc-supply"); in hmc425a_probe()
215 if (IS_ERR(st->reg)) in hmc425a_probe()
216 return PTR_ERR(st->reg); in hmc425a_probe()
218 ret = regulator_enable(st->reg); in hmc425a_probe()
221 ret = devm_add_action_or_reset(&pdev->dev, hmc425a_reg_disable, st); in hmc425a_probe()
225 mutex_init(&st->lock); in hmc425a_probe()
227 indio_dev->info = &hmc425a_info; in hmc425a_probe()
228 indio_dev->modes = INDIO_DIRECT_MODE; in hmc425a_probe()
230 return devm_iio_device_register(&pdev->dev, indio_dev); in hmc425a_probe()