• Home
  • Raw
  • Download

Lines Matching full:st

26 	struct ad5592r_state *st = gpiochip_get_data(chip);  in ad5592r_gpio_get()  local
30 mutex_lock(&st->gpio_lock); in ad5592r_gpio_get()
32 if (st->gpio_out & BIT(offset)) in ad5592r_gpio_get()
33 val = st->gpio_val; in ad5592r_gpio_get()
35 ret = st->ops->gpio_read(st, &val); in ad5592r_gpio_get()
37 mutex_unlock(&st->gpio_lock); in ad5592r_gpio_get()
47 struct ad5592r_state *st = gpiochip_get_data(chip); in ad5592r_gpio_set() local
49 mutex_lock(&st->gpio_lock); in ad5592r_gpio_set()
52 st->gpio_val |= BIT(offset); in ad5592r_gpio_set()
54 st->gpio_val &= ~BIT(offset); in ad5592r_gpio_set()
56 st->ops->reg_write(st, AD5592R_REG_GPIO_SET, st->gpio_val); in ad5592r_gpio_set()
58 mutex_unlock(&st->gpio_lock); in ad5592r_gpio_set()
63 struct ad5592r_state *st = gpiochip_get_data(chip); in ad5592r_gpio_direction_input() local
66 mutex_lock(&st->gpio_lock); in ad5592r_gpio_direction_input()
68 st->gpio_out &= ~BIT(offset); in ad5592r_gpio_direction_input()
69 st->gpio_in |= BIT(offset); in ad5592r_gpio_direction_input()
71 ret = st->ops->reg_write(st, AD5592R_REG_GPIO_OUT_EN, st->gpio_out); in ad5592r_gpio_direction_input()
75 ret = st->ops->reg_write(st, AD5592R_REG_GPIO_IN_EN, st->gpio_in); in ad5592r_gpio_direction_input()
78 mutex_unlock(&st->gpio_lock); in ad5592r_gpio_direction_input()
86 struct ad5592r_state *st = gpiochip_get_data(chip); in ad5592r_gpio_direction_output() local
89 mutex_lock(&st->gpio_lock); in ad5592r_gpio_direction_output()
92 st->gpio_val |= BIT(offset); in ad5592r_gpio_direction_output()
94 st->gpio_val &= ~BIT(offset); in ad5592r_gpio_direction_output()
96 st->gpio_in &= ~BIT(offset); in ad5592r_gpio_direction_output()
97 st->gpio_out |= BIT(offset); in ad5592r_gpio_direction_output()
99 ret = st->ops->reg_write(st, AD5592R_REG_GPIO_SET, st->gpio_val); in ad5592r_gpio_direction_output()
103 ret = st->ops->reg_write(st, AD5592R_REG_GPIO_OUT_EN, st->gpio_out); in ad5592r_gpio_direction_output()
107 ret = st->ops->reg_write(st, AD5592R_REG_GPIO_IN_EN, st->gpio_in); in ad5592r_gpio_direction_output()
110 mutex_unlock(&st->gpio_lock); in ad5592r_gpio_direction_output()
117 struct ad5592r_state *st = gpiochip_get_data(chip); in ad5592r_gpio_request() local
119 if (!(st->gpio_map & BIT(offset))) { in ad5592r_gpio_request()
120 dev_err(st->dev, "GPIO %d is reserved by alternate function\n", in ad5592r_gpio_request()
128 static int ad5592r_gpio_init(struct ad5592r_state *st) in ad5592r_gpio_init() argument
130 if (!st->gpio_map) in ad5592r_gpio_init()
133 st->gpiochip.label = dev_name(st->dev); in ad5592r_gpio_init()
134 st->gpiochip.base = -1; in ad5592r_gpio_init()
135 st->gpiochip.ngpio = 8; in ad5592r_gpio_init()
136 st->gpiochip.parent = st->dev; in ad5592r_gpio_init()
137 st->gpiochip.can_sleep = true; in ad5592r_gpio_init()
138 st->gpiochip.direction_input = ad5592r_gpio_direction_input; in ad5592r_gpio_init()
139 st->gpiochip.direction_output = ad5592r_gpio_direction_output; in ad5592r_gpio_init()
140 st->gpiochip.get = ad5592r_gpio_get; in ad5592r_gpio_init()
141 st->gpiochip.set = ad5592r_gpio_set; in ad5592r_gpio_init()
142 st->gpiochip.request = ad5592r_gpio_request; in ad5592r_gpio_init()
143 st->gpiochip.owner = THIS_MODULE; in ad5592r_gpio_init()
145 mutex_init(&st->gpio_lock); in ad5592r_gpio_init()
147 return gpiochip_add_data(&st->gpiochip, st); in ad5592r_gpio_init()
150 static void ad5592r_gpio_cleanup(struct ad5592r_state *st) in ad5592r_gpio_cleanup() argument
152 if (st->gpio_map) in ad5592r_gpio_cleanup()
153 gpiochip_remove(&st->gpiochip); in ad5592r_gpio_cleanup()
156 static int ad5592r_reset(struct ad5592r_state *st) in ad5592r_reset() argument
160 gpio = devm_gpiod_get_optional(st->dev, "reset", GPIOD_OUT_LOW); in ad5592r_reset()
168 mutex_lock(&st->lock); in ad5592r_reset()
170 st->ops->reg_write(st, AD5592R_REG_RESET, 0xdac); in ad5592r_reset()
171 mutex_unlock(&st->lock); in ad5592r_reset()
179 static int ad5592r_get_vref(struct ad5592r_state *st) in ad5592r_get_vref() argument
183 if (st->reg) { in ad5592r_get_vref()
184 ret = regulator_get_voltage(st->reg); in ad5592r_get_vref()
194 static int ad5592r_set_channel_modes(struct ad5592r_state *st) in ad5592r_set_channel_modes() argument
196 const struct ad5592r_rw_ops *ops = st->ops; in ad5592r_set_channel_modes()
202 for (i = 0; i < st->num_channels; i++) { in ad5592r_set_channel_modes()
203 switch (st->channel_modes[i]) { in ad5592r_set_channel_modes()
218 st->gpio_map |= BIT(i); in ad5592r_set_channel_modes()
219 st->gpio_in |= BIT(i); /* Default to input */ in ad5592r_set_channel_modes()
224 switch (st->channel_offstate[i]) { in ad5592r_set_channel_modes()
230 st->gpio_out |= BIT(i); in ad5592r_set_channel_modes()
234 st->gpio_out |= BIT(i); in ad5592r_set_channel_modes()
235 st->gpio_val |= BIT(i); in ad5592r_set_channel_modes()
246 mutex_lock(&st->lock); in ad5592r_set_channel_modes()
249 ret = ops->reg_write(st, AD5592R_REG_PULLDOWN, pulldown); in ad5592r_set_channel_modes()
253 ret = ops->reg_write(st, AD5592R_REG_TRISTATE, tristate); in ad5592r_set_channel_modes()
258 ret = ops->reg_write(st, AD5592R_REG_DAC_EN, dac); in ad5592r_set_channel_modes()
262 ret = ops->reg_write(st, AD5592R_REG_ADC_EN, adc); in ad5592r_set_channel_modes()
266 ret = ops->reg_write(st, AD5592R_REG_GPIO_SET, st->gpio_val); in ad5592r_set_channel_modes()
270 ret = ops->reg_write(st, AD5592R_REG_GPIO_OUT_EN, st->gpio_out); in ad5592r_set_channel_modes()
274 ret = ops->reg_write(st, AD5592R_REG_GPIO_IN_EN, st->gpio_in); in ad5592r_set_channel_modes()
279 ret = ops->reg_read(st, AD5592R_REG_ADC_EN, &read_back); in ad5592r_set_channel_modes()
284 mutex_unlock(&st->lock); in ad5592r_set_channel_modes()
288 static int ad5592r_reset_channel_modes(struct ad5592r_state *st) in ad5592r_reset_channel_modes() argument
292 for (i = 0; i < ARRAY_SIZE(st->channel_modes); i++) in ad5592r_reset_channel_modes()
293 st->channel_modes[i] = CH_MODE_UNUSED; in ad5592r_reset_channel_modes()
295 return ad5592r_set_channel_modes(st); in ad5592r_reset_channel_modes()
301 struct ad5592r_state *st = iio_priv(iio_dev); in ad5592r_write_raw() local
313 mutex_lock(&st->lock); in ad5592r_write_raw()
314 ret = st->ops->write_dac(st, chan->channel, val); in ad5592r_write_raw()
316 st->cached_dac[chan->channel] = val; in ad5592r_write_raw()
317 mutex_unlock(&st->lock); in ad5592r_write_raw()
323 if (val == st->scale_avail[0][0] && in ad5592r_write_raw()
324 val2 == st->scale_avail[0][1]) in ad5592r_write_raw()
326 else if (val == st->scale_avail[1][0] && in ad5592r_write_raw()
327 val2 == st->scale_avail[1][1]) in ad5592r_write_raw()
332 mutex_lock(&st->lock); in ad5592r_write_raw()
334 ret = st->ops->reg_read(st, AD5592R_REG_CTRL, in ad5592r_write_raw()
335 &st->cached_gp_ctrl); in ad5592r_write_raw()
337 mutex_unlock(&st->lock); in ad5592r_write_raw()
343 st->cached_gp_ctrl |= in ad5592r_write_raw()
346 st->cached_gp_ctrl &= in ad5592r_write_raw()
350 st->cached_gp_ctrl |= in ad5592r_write_raw()
353 st->cached_gp_ctrl &= in ad5592r_write_raw()
357 ret = st->ops->reg_write(st, AD5592R_REG_CTRL, in ad5592r_write_raw()
358 st->cached_gp_ctrl); in ad5592r_write_raw()
359 mutex_unlock(&st->lock); in ad5592r_write_raw()
375 struct ad5592r_state *st = iio_priv(iio_dev); in ad5592r_read_raw() local
382 mutex_lock(&st->lock); in ad5592r_read_raw()
383 ret = st->ops->read_adc(st, chan->channel, &read_val); in ad5592r_read_raw()
384 mutex_unlock(&st->lock); in ad5592r_read_raw()
389 dev_err(st->dev, "Error while reading channel %u\n", in ad5592r_read_raw()
397 mutex_lock(&st->lock); in ad5592r_read_raw()
398 read_val = st->cached_dac[chan->channel]; in ad5592r_read_raw()
399 mutex_unlock(&st->lock); in ad5592r_read_raw()
402 dev_dbg(st->dev, "Channel %u read: 0x%04hX\n", in ad5592r_read_raw()
408 *val = ad5592r_get_vref(st); in ad5592r_read_raw()
417 mutex_lock(&st->lock); in ad5592r_read_raw()
420 mult = !!(st->cached_gp_ctrl & in ad5592r_read_raw()
423 mult = !!(st->cached_gp_ctrl & in ad5592r_read_raw()
426 mutex_unlock(&st->lock); in ad5592r_read_raw()
434 ret = ad5592r_get_vref(st); in ad5592r_read_raw()
436 mutex_lock(&st->lock); in ad5592r_read_raw()
438 if (st->cached_gp_ctrl & AD5592R_REG_CTRL_ADC_RANGE) in ad5592r_read_raw()
443 mutex_unlock(&st->lock); in ad5592r_read_raw()
476 struct ad5592r_state *st = iio_priv(iio_dev); in ad5592r_show_scale_available() local
479 st->scale_avail[0][0], st->scale_avail[0][1], in ad5592r_show_scale_available()
480 st->scale_avail[1][0], st->scale_avail[1][1]); in ad5592r_show_scale_available()
509 struct ad5592r_state *st = iio_priv(iio_dev); in ad5592r_alloc_channels() local
511 num_channels = st->num_channels; in ad5592r_alloc_channels()
517 device_for_each_child_node(st->dev, child) { in ad5592r_alloc_channels()
519 if (ret || reg >= ARRAY_SIZE(st->channel_modes)) in ad5592r_alloc_channels()
524 st->channel_modes[reg] = tmp; in ad5592r_alloc_channels()
528 st->channel_offstate[reg] = tmp; in ad5592r_alloc_channels()
531 channels = devm_kcalloc(st->dev, in ad5592r_alloc_channels()
538 switch (st->channel_modes[i]) { in ad5592r_alloc_channels()
578 static void ad5592r_init_scales(struct ad5592r_state *st, int vref_mV) in ad5592r_init_scales() argument
582 st->scale_avail[0][0] = in ad5592r_init_scales()
583 div_s64_rem(tmp, 1000000000LL, &st->scale_avail[0][1]); in ad5592r_init_scales()
584 st->scale_avail[1][0] = in ad5592r_init_scales()
585 div_s64_rem(tmp * 2, 1000000000LL, &st->scale_avail[1][1]); in ad5592r_init_scales()
592 struct ad5592r_state *st; in ad5592r_probe() local
595 iio_dev = devm_iio_device_alloc(dev, sizeof(*st)); in ad5592r_probe()
599 st = iio_priv(iio_dev); in ad5592r_probe()
600 st->dev = dev; in ad5592r_probe()
601 st->ops = ops; in ad5592r_probe()
602 st->num_channels = 8; in ad5592r_probe()
605 st->reg = devm_regulator_get_optional(dev, "vref"); in ad5592r_probe()
606 if (IS_ERR(st->reg)) { in ad5592r_probe()
607 if ((PTR_ERR(st->reg) != -ENODEV) && dev->of_node) in ad5592r_probe()
608 return PTR_ERR(st->reg); in ad5592r_probe()
610 st->reg = NULL; in ad5592r_probe()
612 ret = regulator_enable(st->reg); in ad5592r_probe()
621 mutex_init(&st->lock); in ad5592r_probe()
623 ad5592r_init_scales(st, ad5592r_get_vref(st)); in ad5592r_probe()
625 ret = ad5592r_reset(st); in ad5592r_probe()
629 ret = ops->reg_write(st, AD5592R_REG_PD, in ad5592r_probe()
630 (st->reg == NULL) ? AD5592R_REG_PD_EN_REF : 0); in ad5592r_probe()
638 ret = ad5592r_set_channel_modes(st); in ad5592r_probe()
646 ret = ad5592r_gpio_init(st); in ad5592r_probe()
656 ad5592r_reset_channel_modes(st); in ad5592r_probe()
659 if (st->reg) in ad5592r_probe()
660 regulator_disable(st->reg); in ad5592r_probe()
669 struct ad5592r_state *st = iio_priv(iio_dev); in ad5592r_remove() local
672 ad5592r_reset_channel_modes(st); in ad5592r_remove()
673 ad5592r_gpio_cleanup(st); in ad5592r_remove()
675 if (st->reg) in ad5592r_remove()
676 regulator_disable(st->reg); in ad5592r_remove()