Skip to content

Commit 5561a2b

Browse files
William Breathitt Graybrgl
authored andcommitted
gpio: ws16c48: 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: David Laight <[email protected]> Signed-off-by: William Breathitt Gray <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 54c8e25 commit 5561a2b

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

drivers/gpio/gpio-ws16c48.c

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct ws16c48_gpio {
4747
raw_spinlock_t lock;
4848
unsigned long irq_mask;
4949
unsigned long flow_mask;
50-
unsigned base;
50+
void __iomem *base;
5151
};
5252

5353
static int ws16c48_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
@@ -73,7 +73,7 @@ static int ws16c48_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
7373

7474
ws16c48gpio->io_state[port] |= mask;
7575
ws16c48gpio->out_state[port] &= ~mask;
76-
outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port);
76+
iowrite8(ws16c48gpio->out_state[port], ws16c48gpio->base + port);
7777

7878
raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
7979

@@ -95,7 +95,7 @@ static int ws16c48_gpio_direction_output(struct gpio_chip *chip,
9595
ws16c48gpio->out_state[port] |= mask;
9696
else
9797
ws16c48gpio->out_state[port] &= ~mask;
98-
outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port);
98+
iowrite8(ws16c48gpio->out_state[port], ws16c48gpio->base + port);
9999

100100
raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
101101

@@ -118,7 +118,7 @@ static int ws16c48_gpio_get(struct gpio_chip *chip, unsigned offset)
118118
return -EINVAL;
119119
}
120120

121-
port_state = inb(ws16c48gpio->base + port);
121+
port_state = ioread8(ws16c48gpio->base + port);
122122

123123
raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
124124

@@ -131,15 +131,15 @@ static int ws16c48_gpio_get_multiple(struct gpio_chip *chip,
131131
struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip);
132132
unsigned long offset;
133133
unsigned long gpio_mask;
134-
unsigned int port_addr;
134+
void __iomem *port_addr;
135135
unsigned long port_state;
136136

137137
/* clear bits array to a clean slate */
138138
bitmap_zero(bits, chip->ngpio);
139139

140140
for_each_set_clump8(offset, gpio_mask, mask, chip->ngpio) {
141141
port_addr = ws16c48gpio->base + offset / 8;
142-
port_state = inb(port_addr) & gpio_mask;
142+
port_state = ioread8(port_addr) & gpio_mask;
143143

144144
bitmap_set_value8(bits, port_state, offset);
145145
}
@@ -166,7 +166,7 @@ static void ws16c48_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
166166
ws16c48gpio->out_state[port] |= mask;
167167
else
168168
ws16c48gpio->out_state[port] &= ~mask;
169-
outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port);
169+
iowrite8(ws16c48gpio->out_state[port], ws16c48gpio->base + port);
170170

171171
raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
172172
}
@@ -178,7 +178,7 @@ static void ws16c48_gpio_set_multiple(struct gpio_chip *chip,
178178
unsigned long offset;
179179
unsigned long gpio_mask;
180180
size_t index;
181-
unsigned int port_addr;
181+
void __iomem *port_addr;
182182
unsigned long bitmask;
183183
unsigned long flags;
184184

@@ -195,7 +195,7 @@ static void ws16c48_gpio_set_multiple(struct gpio_chip *chip,
195195
/* update output state data and set device gpio register */
196196
ws16c48gpio->out_state[index] &= ~gpio_mask;
197197
ws16c48gpio->out_state[index] |= bitmask;
198-
outb(ws16c48gpio->out_state[index], port_addr);
198+
iowrite8(ws16c48gpio->out_state[index], port_addr);
199199

200200
raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
201201
}
@@ -219,10 +219,10 @@ static void ws16c48_irq_ack(struct irq_data *data)
219219

220220
port_state = ws16c48gpio->irq_mask >> (8*port);
221221

222-
outb(0x80, ws16c48gpio->base + 7);
223-
outb(port_state & ~mask, ws16c48gpio->base + 8 + port);
224-
outb(port_state | mask, ws16c48gpio->base + 8 + port);
225-
outb(0xC0, ws16c48gpio->base + 7);
222+
iowrite8(0x80, ws16c48gpio->base + 7);
223+
iowrite8(port_state & ~mask, ws16c48gpio->base + 8 + port);
224+
iowrite8(port_state | mask, ws16c48gpio->base + 8 + port);
225+
iowrite8(0xC0, ws16c48gpio->base + 7);
226226

227227
raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
228228
}
@@ -244,9 +244,9 @@ static void ws16c48_irq_mask(struct irq_data *data)
244244

245245
ws16c48gpio->irq_mask &= ~mask;
246246

247-
outb(0x80, ws16c48gpio->base + 7);
248-
outb(ws16c48gpio->irq_mask >> (8*port), ws16c48gpio->base + 8 + port);
249-
outb(0xC0, ws16c48gpio->base + 7);
247+
iowrite8(0x80, ws16c48gpio->base + 7);
248+
iowrite8(ws16c48gpio->irq_mask >> (8*port), ws16c48gpio->base + 8 + port);
249+
iowrite8(0xC0, ws16c48gpio->base + 7);
250250

251251
raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
252252
}
@@ -268,9 +268,9 @@ static void ws16c48_irq_unmask(struct irq_data *data)
268268

269269
ws16c48gpio->irq_mask |= mask;
270270

271-
outb(0x80, ws16c48gpio->base + 7);
272-
outb(ws16c48gpio->irq_mask >> (8*port), ws16c48gpio->base + 8 + port);
273-
outb(0xC0, ws16c48gpio->base + 7);
271+
iowrite8(0x80, ws16c48gpio->base + 7);
272+
iowrite8(ws16c48gpio->irq_mask >> (8*port), ws16c48gpio->base + 8 + port);
273+
iowrite8(0xC0, ws16c48gpio->base + 7);
274274

275275
raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
276276
}
@@ -304,9 +304,9 @@ static int ws16c48_irq_set_type(struct irq_data *data, unsigned flow_type)
304304
return -EINVAL;
305305
}
306306

307-
outb(0x40, ws16c48gpio->base + 7);
308-
outb(ws16c48gpio->flow_mask >> (8*port), ws16c48gpio->base + 8 + port);
309-
outb(0xC0, ws16c48gpio->base + 7);
307+
iowrite8(0x40, ws16c48gpio->base + 7);
308+
iowrite8(ws16c48gpio->flow_mask >> (8*port), ws16c48gpio->base + 8 + port);
309+
iowrite8(0xC0, ws16c48gpio->base + 7);
310310

311311
raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
312312

@@ -330,20 +330,20 @@ static irqreturn_t ws16c48_irq_handler(int irq, void *dev_id)
330330
unsigned long int_id;
331331
unsigned long gpio;
332332

333-
int_pending = inb(ws16c48gpio->base + 6) & 0x7;
333+
int_pending = ioread8(ws16c48gpio->base + 6) & 0x7;
334334
if (!int_pending)
335335
return IRQ_NONE;
336336

337337
/* loop until all pending interrupts are handled */
338338
do {
339339
for_each_set_bit(port, &int_pending, 3) {
340-
int_id = inb(ws16c48gpio->base + 8 + port);
340+
int_id = ioread8(ws16c48gpio->base + 8 + port);
341341
for_each_set_bit(gpio, &int_id, 8)
342342
generic_handle_domain_irq(chip->irq.domain,
343343
gpio + 8*port);
344344
}
345345

346-
int_pending = inb(ws16c48gpio->base + 6) & 0x7;
346+
int_pending = ioread8(ws16c48gpio->base + 6) & 0x7;
347347
} while (int_pending);
348348

349349
return IRQ_HANDLED;
@@ -370,11 +370,11 @@ static int ws16c48_irq_init_hw(struct gpio_chip *gc)
370370
struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(gc);
371371

372372
/* Disable IRQ by default */
373-
outb(0x80, ws16c48gpio->base + 7);
374-
outb(0, ws16c48gpio->base + 8);
375-
outb(0, ws16c48gpio->base + 9);
376-
outb(0, ws16c48gpio->base + 10);
377-
outb(0xC0, ws16c48gpio->base + 7);
373+
iowrite8(0x80, ws16c48gpio->base + 7);
374+
iowrite8(0, ws16c48gpio->base + 8);
375+
iowrite8(0, ws16c48gpio->base + 9);
376+
iowrite8(0, ws16c48gpio->base + 10);
377+
iowrite8(0xC0, ws16c48gpio->base + 7);
378378

379379
return 0;
380380
}
@@ -396,6 +396,10 @@ static int ws16c48_probe(struct device *dev, unsigned int id)
396396
return -EBUSY;
397397
}
398398

399+
ws16c48gpio->base = devm_ioport_map(dev, base[id], WS16C48_EXTENT);
400+
if (!ws16c48gpio->base)
401+
return -ENOMEM;
402+
399403
ws16c48gpio->chip.label = name;
400404
ws16c48gpio->chip.parent = dev;
401405
ws16c48gpio->chip.owner = THIS_MODULE;
@@ -409,7 +413,6 @@ static int ws16c48_probe(struct device *dev, unsigned int id)
409413
ws16c48gpio->chip.get_multiple = ws16c48_gpio_get_multiple;
410414
ws16c48gpio->chip.set = ws16c48_gpio_set;
411415
ws16c48gpio->chip.set_multiple = ws16c48_gpio_set_multiple;
412-
ws16c48gpio->base = base[id];
413416

414417
girq = &ws16c48gpio->chip.irq;
415418
girq->chip = &ws16c48_irqchip;

0 commit comments

Comments
 (0)