• Home
  • Raw
  • Download

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

1 // SPDX-License-Identifier: GPL-2.0-only
29 #define STX104_IN_CHAN(chan, diff) { \ argument
37 .differential = diff \
50 * struct stx104_reg - device register structure
51 * @ssr_ad: Software Strobe Register and ADC Data
52 * @achan: ADC Channel
54 * @dac: DAC Channels
55 * @cir_asr: Clear Interrupts and ADC Status
56 * @acr: ADC Control
58 * @acfg: ADC Configuration
72 * struct stx104_iio - IIO device private data structure
74 * @chan_out_states: channels' output states
84 * struct stx104_gpio - GPIO device private data structure
101 struct stx104_reg __iomem *const reg = priv->reg; in stx104_read_raw()
109 adc_config = ioread8(&reg->acfg); in stx104_read_raw()
115 if (chan->output) { in stx104_read_raw()
116 *val = priv->chan_out_states[chan->channel]; in stx104_read_raw()
120 mutex_lock(&priv->lock); in stx104_read_raw()
122 /* select ADC channel */ in stx104_read_raw()
123 iowrite8(chan->channel | (chan->channel << 4), &reg->achan); in stx104_read_raw()
125 /* trigger ADC sample capture by writing to the 8-bit in stx104_read_raw()
128 iowrite8(0, &reg->ssr_ad); in stx104_read_raw()
129 while (ioread8(&reg->cir_asr) & BIT(7)); in stx104_read_raw()
131 *val = ioread16(&reg->ssr_ad); in stx104_read_raw()
133 mutex_unlock(&priv->lock); in stx104_read_raw()
136 /* get ADC bipolar/unipolar configuration */ in stx104_read_raw()
137 adc_config = ioread8(&reg->acfg); in stx104_read_raw()
140 *val = -32768 * adbu; in stx104_read_raw()
143 /* get ADC bipolar/unipolar and gain configuration */ in stx104_read_raw()
144 adc_config = ioread8(&reg->acfg); in stx104_read_raw()
149 *val2 = 15 - adbu + gain; in stx104_read_raw()
153 return -EINVAL; in stx104_read_raw()
166 iowrite8(0, &priv->reg->acfg); in stx104_write_raw()
169 iowrite8(1, &priv->reg->acfg); in stx104_write_raw()
172 iowrite8(2, &priv->reg->acfg); in stx104_write_raw()
175 iowrite8(3, &priv->reg->acfg); in stx104_write_raw()
178 return -EINVAL; in stx104_write_raw()
183 if (chan->output) { in stx104_write_raw()
184 /* DAC can only accept up to a 16-bit value */ in stx104_write_raw()
186 return -EINVAL; in stx104_write_raw()
188 mutex_lock(&priv->lock); in stx104_write_raw()
190 priv->chan_out_states[chan->channel] = val; in stx104_write_raw()
191 iowrite16(val, &priv->reg->dac[chan->channel]); in stx104_write_raw()
193 mutex_unlock(&priv->lock); in stx104_write_raw()
196 return -EINVAL; in stx104_write_raw()
199 return -EINVAL; in stx104_write_raw()
207 /* single-ended input channels configuration */
217 /* differential input channels configuration */
228 /* GPIO 0-3 are input only, while the rest are output only */ in stx104_gpio_get_direction()
239 return -EINVAL; in stx104_gpio_direction_input()
248 return -EINVAL; in stx104_gpio_direction_output()
250 chip->set(chip, offset, value); in stx104_gpio_direction_output()
259 return -EINVAL; in stx104_gpio_get()
261 return !!(ioread8(stx104gpio->base) & BIT(offset)); in stx104_gpio_get()
269 *bits = ioread8(stx104gpio->base); in stx104_gpio_get_multiple()
284 spin_lock_irqsave(&stx104gpio->lock, flags); in stx104_gpio_set()
287 stx104gpio->out_state |= mask; in stx104_gpio_set()
289 stx104gpio->out_state &= ~mask; in stx104_gpio_set()
291 iowrite8(stx104gpio->out_state, stx104gpio->base); in stx104_gpio_set()
293 spin_unlock_irqrestore(&stx104gpio->lock, flags); in stx104_gpio_set()
314 spin_lock_irqsave(&stx104gpio->lock, flags); in stx104_gpio_set_multiple()
316 stx104gpio->out_state &= ~*mask; in stx104_gpio_set_multiple()
317 stx104gpio->out_state |= *mask & *bits; in stx104_gpio_set_multiple()
318 iowrite8(stx104gpio->out_state, stx104gpio->base); in stx104_gpio_set_multiple()
320 spin_unlock_irqrestore(&stx104gpio->lock, flags); in stx104_gpio_set_multiple()
332 return -ENOMEM; in stx104_probe()
336 return -ENOMEM; in stx104_probe()
340 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", in stx104_probe()
342 return -EBUSY; in stx104_probe()
346 priv->reg = devm_ioport_map(dev, base[id], STX104_EXTENT); in stx104_probe()
347 if (!priv->reg) in stx104_probe()
348 return -ENOMEM; in stx104_probe()
350 indio_dev->info = &stx104_info; in stx104_probe()
351 indio_dev->modes = INDIO_DIRECT_MODE; in stx104_probe()
354 if (ioread8(&priv->reg->cir_asr) & BIT(5)) { in stx104_probe()
355 indio_dev->num_channels = ARRAY_SIZE(stx104_channels_diff); in stx104_probe()
356 indio_dev->channels = stx104_channels_diff; in stx104_probe()
358 indio_dev->num_channels = ARRAY_SIZE(stx104_channels_sing); in stx104_probe()
359 indio_dev->channels = stx104_channels_sing; in stx104_probe()
362 indio_dev->name = dev_name(dev); in stx104_probe()
364 mutex_init(&priv->lock); in stx104_probe()
367 iowrite8(0, &priv->reg->acr); in stx104_probe()
370 iowrite8(0, &priv->reg->acfg); in stx104_probe()
373 iowrite16(0, &priv->reg->dac[0]); in stx104_probe()
374 iowrite16(0, &priv->reg->dac[1]); in stx104_probe()
376 stx104gpio->chip.label = dev_name(dev); in stx104_probe()
377 stx104gpio->chip.parent = dev; in stx104_probe()
378 stx104gpio->chip.owner = THIS_MODULE; in stx104_probe()
379 stx104gpio->chip.base = -1; in stx104_probe()
380 stx104gpio->chip.ngpio = STX104_NGPIO; in stx104_probe()
381 stx104gpio->chip.names = stx104_names; in stx104_probe()
382 stx104gpio->chip.get_direction = stx104_gpio_get_direction; in stx104_probe()
383 stx104gpio->chip.direction_input = stx104_gpio_direction_input; in stx104_probe()
384 stx104gpio->chip.direction_output = stx104_gpio_direction_output; in stx104_probe()
385 stx104gpio->chip.get = stx104_gpio_get; in stx104_probe()
386 stx104gpio->chip.get_multiple = stx104_gpio_get_multiple; in stx104_probe()
387 stx104gpio->chip.set = stx104_gpio_set; in stx104_probe()
388 stx104gpio->chip.set_multiple = stx104_gpio_set_multiple; in stx104_probe()
389 stx104gpio->base = &priv->reg->dio; in stx104_probe()
390 stx104gpio->out_state = 0x0; in stx104_probe()
392 spin_lock_init(&stx104gpio->lock); in stx104_probe()
394 err = devm_gpiochip_add_data(dev, &stx104gpio->chip, stx104gpio); in stx104_probe()