Commit 73b8390c authored by William Breathitt Gray's avatar William Breathitt Gray Committed by Jonathan Cameron

iio: adc: stx104: Utilize iomap interface

This driver doesn't need to access I/O ports directly via inb()/outb()
and friends. This patch abstracts such access by calling ioport_map()
to enable the use of more typical ioread8()/iowrite8() I/O memory
accessor calls.
Suggested-by: default avatarDavid Laight <David.Laight@ACULAB.COM>
Signed-off-by: default avatarWilliam Breathitt Gray <william.gray@linaro.org>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/64673797df382c52fc32fce24348b25a0b05e73a.1652201921.git.william.gray@linaro.orgSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 48d1ae77
...@@ -51,7 +51,7 @@ MODULE_PARM_DESC(base, "Apex Embedded Systems STX104 base addresses"); ...@@ -51,7 +51,7 @@ MODULE_PARM_DESC(base, "Apex Embedded Systems STX104 base addresses");
*/ */
struct stx104_iio { struct stx104_iio {
unsigned int chan_out_states[STX104_NUM_OUT_CHAN]; unsigned int chan_out_states[STX104_NUM_OUT_CHAN];
unsigned int base; void __iomem *base;
}; };
/** /**
...@@ -64,7 +64,7 @@ struct stx104_iio { ...@@ -64,7 +64,7 @@ struct stx104_iio {
struct stx104_gpio { struct stx104_gpio {
struct gpio_chip chip; struct gpio_chip chip;
spinlock_t lock; spinlock_t lock;
unsigned int base; void __iomem *base;
unsigned int out_state; unsigned int out_state;
}; };
...@@ -79,7 +79,7 @@ static int stx104_read_raw(struct iio_dev *indio_dev, ...@@ -79,7 +79,7 @@ static int stx104_read_raw(struct iio_dev *indio_dev,
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_HARDWAREGAIN: case IIO_CHAN_INFO_HARDWAREGAIN:
/* get gain configuration */ /* get gain configuration */
adc_config = inb(priv->base + 11); adc_config = ioread8(priv->base + 11);
gain = adc_config & 0x3; gain = adc_config & 0x3;
*val = 1 << gain; *val = 1 << gain;
...@@ -91,24 +91,24 @@ static int stx104_read_raw(struct iio_dev *indio_dev, ...@@ -91,24 +91,24 @@ static int stx104_read_raw(struct iio_dev *indio_dev,
} }
/* select ADC channel */ /* select ADC channel */
outb(chan->channel | (chan->channel << 4), priv->base + 2); iowrite8(chan->channel | (chan->channel << 4), priv->base + 2);
/* trigger ADC sample capture and wait for completion */ /* trigger ADC sample capture and wait for completion */
outb(0, priv->base); iowrite8(0, priv->base);
while (inb(priv->base + 8) & BIT(7)); while (ioread8(priv->base + 8) & BIT(7));
*val = inw(priv->base); *val = ioread16(priv->base);
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
/* get ADC bipolar/unipolar configuration */ /* get ADC bipolar/unipolar configuration */
adc_config = inb(priv->base + 11); adc_config = ioread8(priv->base + 11);
adbu = !(adc_config & BIT(2)); adbu = !(adc_config & BIT(2));
*val = -32768 * adbu; *val = -32768 * adbu;
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
/* get ADC bipolar/unipolar and gain configuration */ /* get ADC bipolar/unipolar and gain configuration */
adc_config = inb(priv->base + 11); adc_config = ioread8(priv->base + 11);
adbu = !(adc_config & BIT(2)); adbu = !(adc_config & BIT(2));
gain = adc_config & 0x3; gain = adc_config & 0x3;
...@@ -130,16 +130,16 @@ static int stx104_write_raw(struct iio_dev *indio_dev, ...@@ -130,16 +130,16 @@ static int stx104_write_raw(struct iio_dev *indio_dev,
/* Only four gain states (x1, x2, x4, x8) */ /* Only four gain states (x1, x2, x4, x8) */
switch (val) { switch (val) {
case 1: case 1:
outb(0, priv->base + 11); iowrite8(0, priv->base + 11);
break; break;
case 2: case 2:
outb(1, priv->base + 11); iowrite8(1, priv->base + 11);
break; break;
case 4: case 4:
outb(2, priv->base + 11); iowrite8(2, priv->base + 11);
break; break;
case 8: case 8:
outb(3, priv->base + 11); iowrite8(3, priv->base + 11);
break; break;
default: default:
return -EINVAL; return -EINVAL;
...@@ -153,7 +153,7 @@ static int stx104_write_raw(struct iio_dev *indio_dev, ...@@ -153,7 +153,7 @@ static int stx104_write_raw(struct iio_dev *indio_dev,
return -EINVAL; return -EINVAL;
priv->chan_out_states[chan->channel] = val; priv->chan_out_states[chan->channel] = val;
outw(val, priv->base + 4 + 2 * chan->channel); iowrite16(val, priv->base + 4 + 2 * chan->channel);
return 0; return 0;
} }
...@@ -222,7 +222,7 @@ static int stx104_gpio_get(struct gpio_chip *chip, unsigned int offset) ...@@ -222,7 +222,7 @@ static int stx104_gpio_get(struct gpio_chip *chip, unsigned int offset)
if (offset >= 4) if (offset >= 4)
return -EINVAL; return -EINVAL;
return !!(inb(stx104gpio->base) & BIT(offset)); return !!(ioread8(stx104gpio->base) & BIT(offset));
} }
static int stx104_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, static int stx104_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
...@@ -230,7 +230,7 @@ static int stx104_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, ...@@ -230,7 +230,7 @@ static int stx104_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
{ {
struct stx104_gpio *const stx104gpio = gpiochip_get_data(chip); struct stx104_gpio *const stx104gpio = gpiochip_get_data(chip);
*bits = inb(stx104gpio->base); *bits = ioread8(stx104gpio->base);
return 0; return 0;
} }
...@@ -252,7 +252,7 @@ static void stx104_gpio_set(struct gpio_chip *chip, unsigned int offset, ...@@ -252,7 +252,7 @@ static void stx104_gpio_set(struct gpio_chip *chip, unsigned int offset,
else else
stx104gpio->out_state &= ~mask; stx104gpio->out_state &= ~mask;
outb(stx104gpio->out_state, stx104gpio->base); iowrite8(stx104gpio->out_state, stx104gpio->base);
spin_unlock_irqrestore(&stx104gpio->lock, flags); spin_unlock_irqrestore(&stx104gpio->lock, flags);
} }
...@@ -279,7 +279,7 @@ static void stx104_gpio_set_multiple(struct gpio_chip *chip, ...@@ -279,7 +279,7 @@ static void stx104_gpio_set_multiple(struct gpio_chip *chip,
stx104gpio->out_state &= ~*mask; stx104gpio->out_state &= ~*mask;
stx104gpio->out_state |= *mask & *bits; stx104gpio->out_state |= *mask & *bits;
outb(stx104gpio->out_state, stx104gpio->base); iowrite8(stx104gpio->out_state, stx104gpio->base);
spin_unlock_irqrestore(&stx104gpio->lock, flags); spin_unlock_irqrestore(&stx104gpio->lock, flags);
} }
...@@ -306,11 +306,16 @@ static int stx104_probe(struct device *dev, unsigned int id) ...@@ -306,11 +306,16 @@ static int stx104_probe(struct device *dev, unsigned int id)
return -EBUSY; return -EBUSY;
} }
priv = iio_priv(indio_dev);
priv->base = devm_ioport_map(dev, base[id], STX104_EXTENT);
if (!priv->base)
return -ENOMEM;
indio_dev->info = &stx104_info; indio_dev->info = &stx104_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
/* determine if differential inputs */ /* determine if differential inputs */
if (inb(base[id] + 8) & BIT(5)) { if (ioread8(priv->base + 8) & BIT(5)) {
indio_dev->num_channels = ARRAY_SIZE(stx104_channels_diff); indio_dev->num_channels = ARRAY_SIZE(stx104_channels_diff);
indio_dev->channels = stx104_channels_diff; indio_dev->channels = stx104_channels_diff;
} else { } else {
...@@ -320,18 +325,15 @@ static int stx104_probe(struct device *dev, unsigned int id) ...@@ -320,18 +325,15 @@ static int stx104_probe(struct device *dev, unsigned int id)
indio_dev->name = dev_name(dev); indio_dev->name = dev_name(dev);
priv = iio_priv(indio_dev);
priv->base = base[id];
/* configure device for software trigger operation */ /* configure device for software trigger operation */
outb(0, base[id] + 9); iowrite8(0, priv->base + 9);
/* initialize gain setting to x1 */ /* initialize gain setting to x1 */
outb(0, base[id] + 11); iowrite8(0, priv->base + 11);
/* initialize DAC output to 0V */ /* initialize DAC output to 0V */
outw(0, base[id] + 4); iowrite16(0, priv->base + 4);
outw(0, base[id] + 6); iowrite16(0, priv->base + 6);
stx104gpio->chip.label = dev_name(dev); stx104gpio->chip.label = dev_name(dev);
stx104gpio->chip.parent = dev; stx104gpio->chip.parent = dev;
...@@ -346,7 +348,7 @@ static int stx104_probe(struct device *dev, unsigned int id) ...@@ -346,7 +348,7 @@ static int stx104_probe(struct device *dev, unsigned int id)
stx104gpio->chip.get_multiple = stx104_gpio_get_multiple; stx104gpio->chip.get_multiple = stx104_gpio_get_multiple;
stx104gpio->chip.set = stx104_gpio_set; stx104gpio->chip.set = stx104_gpio_set;
stx104gpio->chip.set_multiple = stx104_gpio_set_multiple; stx104gpio->chip.set_multiple = stx104_gpio_set_multiple;
stx104gpio->base = base[id] + 3; stx104gpio->base = priv->base + 3;
stx104gpio->out_state = 0x0; stx104gpio->out_state = 0x0;
spin_lock_init(&stx104gpio->lock); spin_lock_init(&stx104gpio->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment