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;
39 struct gpio_descs *gpios; member
44 static int hmc425a_write(struct iio_dev *indio_dev, u32 value) in hmc425a_write()
51 gpiod_set_array_value_cansleep(st->gpios->ndescs, st->gpios->desc, in hmc425a_write()
56 static int hmc425a_read_raw(struct iio_dev *indio_dev, in hmc425a_read_raw()
57 struct iio_chan_spec const *chan, int *val, in hmc425a_read_raw()
58 int *val2, long m) in hmc425a_read_raw()
61 int code, gain = 0; in hmc425a_read_raw()
62 int ret; in hmc425a_read_raw()
64 mutex_lock(&st->lock); in hmc425a_read_raw()
67 code = st->gain; in hmc425a_read_raw()
69 switch (st->type) { in hmc425a_read_raw()
71 gain = ~code * -500; in hmc425a_read_raw()
81 ret = -EINVAL; in hmc425a_read_raw()
83 mutex_unlock(&st->lock); in hmc425a_read_raw()
88 static int hmc425a_write_raw(struct iio_dev *indio_dev, in hmc425a_write_raw()
89 struct iio_chan_spec const *chan, int val, in hmc425a_write_raw()
90 int val2, long mask) in hmc425a_write_raw()
93 struct hmc425a_chip_info *inf = st->chip_info; in hmc425a_write_raw()
94 int code = 0, gain; in hmc425a_write_raw()
95 int ret; in hmc425a_write_raw()
98 gain = (val * 1000) - (val2 / 1000); in hmc425a_write_raw()
102 if (gain > inf->gain_max || gain < inf->gain_min) in hmc425a_write_raw()
103 return -EINVAL; in hmc425a_write_raw()
105 switch (st->type) { in hmc425a_write_raw()
111 mutex_lock(&st->lock); in hmc425a_write_raw()
114 st->gain = code; in hmc425a_write_raw()
116 ret = hmc425a_write(indio_dev, st->gain); in hmc425a_write_raw()
119 ret = -EINVAL; in hmc425a_write_raw()
121 mutex_unlock(&st->lock); in hmc425a_write_raw()
126 static int hmc425a_write_raw_get_fmt(struct iio_dev *indio_dev, in hmc425a_write_raw_get_fmt()
134 return -EINVAL; in hmc425a_write_raw_get_fmt()
170 .gain_min = -31500,
172 .default_gain = -0x40, /* set default gain -31.5db*/
176 static int hmc425a_probe(struct platform_device *pdev) in hmc425a_probe()
180 int ret; in hmc425a_probe()
182 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); in hmc425a_probe()
184 return -ENOMEM; in hmc425a_probe()
187 st->type = (uintptr_t)device_get_match_data(&pdev->dev); in hmc425a_probe()
189 st->chip_info = &hmc425a_chip_info_tbl[st->type]; in hmc425a_probe()
190 indio_dev->num_channels = st->chip_info->num_channels; in hmc425a_probe()
191 indio_dev->channels = st->chip_info->channels; in hmc425a_probe()
192 indio_dev->name = st->chip_info->name; in hmc425a_probe()
193 st->gain = st->chip_info->default_gain; in hmc425a_probe()
195 st->gpios = devm_gpiod_get_array(&pdev->dev, "ctrl", GPIOD_OUT_LOW); in hmc425a_probe()
196 if (IS_ERR(st->gpios)) in hmc425a_probe()
197 return dev_err_probe(&pdev->dev, PTR_ERR(st->gpios), in hmc425a_probe()
198 "failed to get gpios\n"); in hmc425a_probe()
200 if (st->gpios->ndescs != st->chip_info->num_gpios) { in hmc425a_probe()
201 dev_err(&pdev->dev, "%d GPIOs needed to operate\n", in hmc425a_probe()
202 st->chip_info->num_gpios); in hmc425a_probe()
203 return -ENODEV; in hmc425a_probe()
206 ret = devm_regulator_get_enable(&pdev->dev, "vcc-supply"); in hmc425a_probe()
210 mutex_init(&st->lock); in hmc425a_probe()
212 indio_dev->info = &hmc425a_info; in hmc425a_probe()
213 indio_dev->modes = INDIO_DIRECT_MODE; in hmc425a_probe()
215 return devm_iio_device_register(&pdev->dev, indio_dev); in hmc425a_probe()