Lines Matching +full:adc +full:- +full:diff +full:- +full:channels

1 // SPDX-License-Identifier: GPL-2.0-only
28 #define STX104_IN_CHAN(chan, diff) { \ argument
36 .differential = diff \
49 * struct stx104_reg - device register structure
50 * @ssr_ad: Software Strobe Register and ADC Data
51 * @achan: ADC Channel
53 * @dac: DAC Channels
54 * @cir_asr: Clear Interrupts and ADC Status
55 * @acr: ADC Control
57 * @acfg: ADC Configuration
71 * struct stx104_iio - IIO device private data structure
72 * @chan_out_states: channels' output states
81 * struct stx104_gpio - GPIO device private data structure
98 struct stx104_reg __iomem *const reg = priv->reg; in stx104_read_raw()
106 adc_config = ioread8(&reg->acfg); in stx104_read_raw()
112 if (chan->output) { in stx104_read_raw()
113 *val = priv->chan_out_states[chan->channel]; in stx104_read_raw()
117 /* select ADC channel */ in stx104_read_raw()
118 iowrite8(chan->channel | (chan->channel << 4), &reg->achan); in stx104_read_raw()
120 /* trigger ADC sample capture by writing to the 8-bit in stx104_read_raw()
123 iowrite8(0, &reg->ssr_ad); in stx104_read_raw()
124 while (ioread8(&reg->cir_asr) & BIT(7)); in stx104_read_raw()
126 *val = ioread16(&reg->ssr_ad); in stx104_read_raw()
129 /* get ADC bipolar/unipolar configuration */ in stx104_read_raw()
130 adc_config = ioread8(&reg->acfg); in stx104_read_raw()
133 *val = -32768 * adbu; in stx104_read_raw()
136 /* get ADC bipolar/unipolar and gain configuration */ in stx104_read_raw()
137 adc_config = ioread8(&reg->acfg); in stx104_read_raw()
142 *val2 = 15 - adbu + gain; in stx104_read_raw()
146 return -EINVAL; in stx104_read_raw()
159 iowrite8(0, &priv->reg->acfg); in stx104_write_raw()
162 iowrite8(1, &priv->reg->acfg); in stx104_write_raw()
165 iowrite8(2, &priv->reg->acfg); in stx104_write_raw()
168 iowrite8(3, &priv->reg->acfg); in stx104_write_raw()
171 return -EINVAL; in stx104_write_raw()
176 if (chan->output) { in stx104_write_raw()
177 /* DAC can only accept up to a 16-bit value */ in stx104_write_raw()
179 return -EINVAL; in stx104_write_raw()
181 priv->chan_out_states[chan->channel] = val; in stx104_write_raw()
182 iowrite16(val, &priv->reg->dac[chan->channel]); in stx104_write_raw()
186 return -EINVAL; in stx104_write_raw()
189 return -EINVAL; in stx104_write_raw()
197 /* single-ended input channels configuration */
207 /* differential input channels configuration */
218 /* GPIO 0-3 are input only, while the rest are output only */ in stx104_gpio_get_direction()
229 return -EINVAL; in stx104_gpio_direction_input()
238 return -EINVAL; in stx104_gpio_direction_output()
240 chip->set(chip, offset, value); in stx104_gpio_direction_output()
249 return -EINVAL; in stx104_gpio_get()
251 return !!(ioread8(stx104gpio->base) & BIT(offset)); in stx104_gpio_get()
259 *bits = ioread8(stx104gpio->base); in stx104_gpio_get_multiple()
274 spin_lock_irqsave(&stx104gpio->lock, flags); in stx104_gpio_set()
277 stx104gpio->out_state |= mask; in stx104_gpio_set()
279 stx104gpio->out_state &= ~mask; in stx104_gpio_set()
281 iowrite8(stx104gpio->out_state, stx104gpio->base); in stx104_gpio_set()
283 spin_unlock_irqrestore(&stx104gpio->lock, flags); in stx104_gpio_set()
304 spin_lock_irqsave(&stx104gpio->lock, flags); in stx104_gpio_set_multiple()
306 stx104gpio->out_state &= ~*mask; in stx104_gpio_set_multiple()
307 stx104gpio->out_state |= *mask & *bits; in stx104_gpio_set_multiple()
308 iowrite8(stx104gpio->out_state, stx104gpio->base); in stx104_gpio_set_multiple()
310 spin_unlock_irqrestore(&stx104gpio->lock, flags); in stx104_gpio_set_multiple()
322 return -ENOMEM; in stx104_probe()
326 return -ENOMEM; in stx104_probe()
330 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", in stx104_probe()
332 return -EBUSY; in stx104_probe()
336 priv->reg = devm_ioport_map(dev, base[id], STX104_EXTENT); in stx104_probe()
337 if (!priv->reg) in stx104_probe()
338 return -ENOMEM; in stx104_probe()
340 indio_dev->info = &stx104_info; in stx104_probe()
341 indio_dev->modes = INDIO_DIRECT_MODE; in stx104_probe()
344 if (ioread8(&priv->reg->cir_asr) & BIT(5)) { in stx104_probe()
345 indio_dev->num_channels = ARRAY_SIZE(stx104_channels_diff); in stx104_probe()
346 indio_dev->channels = stx104_channels_diff; in stx104_probe()
348 indio_dev->num_channels = ARRAY_SIZE(stx104_channels_sing); in stx104_probe()
349 indio_dev->channels = stx104_channels_sing; in stx104_probe()
352 indio_dev->name = dev_name(dev); in stx104_probe()
355 iowrite8(0, &priv->reg->acr); in stx104_probe()
358 iowrite8(0, &priv->reg->acfg); in stx104_probe()
361 iowrite16(0, &priv->reg->dac[0]); in stx104_probe()
362 iowrite16(0, &priv->reg->dac[1]); in stx104_probe()
364 stx104gpio->chip.label = dev_name(dev); in stx104_probe()
365 stx104gpio->chip.parent = dev; in stx104_probe()
366 stx104gpio->chip.owner = THIS_MODULE; in stx104_probe()
367 stx104gpio->chip.base = -1; in stx104_probe()
368 stx104gpio->chip.ngpio = STX104_NGPIO; in stx104_probe()
369 stx104gpio->chip.names = stx104_names; in stx104_probe()
370 stx104gpio->chip.get_direction = stx104_gpio_get_direction; in stx104_probe()
371 stx104gpio->chip.direction_input = stx104_gpio_direction_input; in stx104_probe()
372 stx104gpio->chip.direction_output = stx104_gpio_direction_output; in stx104_probe()
373 stx104gpio->chip.get = stx104_gpio_get; in stx104_probe()
374 stx104gpio->chip.get_multiple = stx104_gpio_get_multiple; in stx104_probe()
375 stx104gpio->chip.set = stx104_gpio_set; in stx104_probe()
376 stx104gpio->chip.set_multiple = stx104_gpio_set_multiple; in stx104_probe()
377 stx104gpio->base = &priv->reg->dio; in stx104_probe()
378 stx104gpio->out_state = 0x0; in stx104_probe()
380 spin_lock_init(&stx104gpio->lock); in stx104_probe()
382 err = devm_gpiochip_add_data(dev, &stx104gpio->chip, stx104gpio); in stx104_probe()