Skip to content

Commit 54c8e25

Browse files
William Breathitt Graybrgl
authored andcommitted
gpio: gpio-mm: 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 e0a574e commit 54c8e25

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

drivers/gpio/gpio-gpio-mm.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct gpiomm_gpio {
4242
unsigned char out_state[6];
4343
unsigned char control[2];
4444
spinlock_t lock;
45-
unsigned int base;
45+
void __iomem *base;
4646
};
4747

4848
static int gpiomm_gpio_get_direction(struct gpio_chip *chip,
@@ -64,7 +64,6 @@ static int gpiomm_gpio_direction_input(struct gpio_chip *chip,
6464
struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip);
6565
const unsigned int io_port = offset / 8;
6666
const unsigned int control_port = io_port / 3;
67-
const unsigned int control_addr = gpiommgpio->base + 3 + control_port*4;
6867
unsigned long flags;
6968
unsigned int control;
7069

@@ -89,7 +88,7 @@ static int gpiomm_gpio_direction_input(struct gpio_chip *chip,
8988
}
9089

9190
control = BIT(7) | gpiommgpio->control[control_port];
92-
outb(control, control_addr);
91+
iowrite8(control, gpiommgpio->base + 3 + control_port*4);
9392

9493
spin_unlock_irqrestore(&gpiommgpio->lock, flags);
9594

@@ -103,7 +102,6 @@ static int gpiomm_gpio_direction_output(struct gpio_chip *chip,
103102
const unsigned int io_port = offset / 8;
104103
const unsigned int control_port = io_port / 3;
105104
const unsigned int mask = BIT(offset % 8);
106-
const unsigned int control_addr = gpiommgpio->base + 3 + control_port*4;
107105
const unsigned int out_port = (io_port > 2) ? io_port + 1 : io_port;
108106
unsigned long flags;
109107
unsigned int control;
@@ -134,9 +132,9 @@ static int gpiomm_gpio_direction_output(struct gpio_chip *chip,
134132
gpiommgpio->out_state[io_port] &= ~mask;
135133

136134
control = BIT(7) | gpiommgpio->control[control_port];
137-
outb(control, control_addr);
135+
iowrite8(control, gpiommgpio->base + 3 + control_port*4);
138136

139-
outb(gpiommgpio->out_state[io_port], gpiommgpio->base + out_port);
137+
iowrite8(gpiommgpio->out_state[io_port], gpiommgpio->base + out_port);
140138

141139
spin_unlock_irqrestore(&gpiommgpio->lock, flags);
142140

@@ -160,7 +158,7 @@ static int gpiomm_gpio_get(struct gpio_chip *chip, unsigned int offset)
160158
return -EINVAL;
161159
}
162160

163-
port_state = inb(gpiommgpio->base + in_port);
161+
port_state = ioread8(gpiommgpio->base + in_port);
164162

165163
spin_unlock_irqrestore(&gpiommgpio->lock, flags);
166164

@@ -175,15 +173,15 @@ static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
175173
struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip);
176174
unsigned long offset;
177175
unsigned long gpio_mask;
178-
unsigned int port_addr;
176+
void __iomem *port_addr;
179177
unsigned long port_state;
180178

181179
/* clear bits array to a clean slate */
182180
bitmap_zero(bits, chip->ngpio);
183181

184182
for_each_set_clump8(offset, gpio_mask, mask, ARRAY_SIZE(ports) * 8) {
185183
port_addr = gpiommgpio->base + ports[offset / 8];
186-
port_state = inb(port_addr) & gpio_mask;
184+
port_state = ioread8(port_addr) & gpio_mask;
187185

188186
bitmap_set_value8(bits, port_state, offset);
189187
}
@@ -207,7 +205,7 @@ static void gpiomm_gpio_set(struct gpio_chip *chip, unsigned int offset,
207205
else
208206
gpiommgpio->out_state[port] &= ~mask;
209207

210-
outb(gpiommgpio->out_state[port], gpiommgpio->base + out_port);
208+
iowrite8(gpiommgpio->out_state[port], gpiommgpio->base + out_port);
211209

212210
spin_unlock_irqrestore(&gpiommgpio->lock, flags);
213211
}
@@ -219,7 +217,7 @@ static void gpiomm_gpio_set_multiple(struct gpio_chip *chip,
219217
unsigned long offset;
220218
unsigned long gpio_mask;
221219
size_t index;
222-
unsigned int port_addr;
220+
void __iomem *port_addr;
223221
unsigned long bitmask;
224222
unsigned long flags;
225223

@@ -234,7 +232,7 @@ static void gpiomm_gpio_set_multiple(struct gpio_chip *chip,
234232
/* update output state data and set device gpio register */
235233
gpiommgpio->out_state[index] &= ~gpio_mask;
236234
gpiommgpio->out_state[index] |= bitmask;
237-
outb(gpiommgpio->out_state[index], port_addr);
235+
iowrite8(gpiommgpio->out_state[index], port_addr);
238236

239237
spin_unlock_irqrestore(&gpiommgpio->lock, flags);
240238
}
@@ -268,6 +266,10 @@ static int gpiomm_probe(struct device *dev, unsigned int id)
268266
return -EBUSY;
269267
}
270268

269+
gpiommgpio->base = devm_ioport_map(dev, base[id], GPIOMM_EXTENT);
270+
if (!gpiommgpio->base)
271+
return -ENOMEM;
272+
271273
gpiommgpio->chip.label = name;
272274
gpiommgpio->chip.parent = dev;
273275
gpiommgpio->chip.owner = THIS_MODULE;
@@ -281,7 +283,6 @@ static int gpiomm_probe(struct device *dev, unsigned int id)
281283
gpiommgpio->chip.get_multiple = gpiomm_gpio_get_multiple;
282284
gpiommgpio->chip.set = gpiomm_gpio_set;
283285
gpiommgpio->chip.set_multiple = gpiomm_gpio_set_multiple;
284-
gpiommgpio->base = base[id];
285286

286287
spin_lock_init(&gpiommgpio->lock);
287288

@@ -292,14 +293,14 @@ static int gpiomm_probe(struct device *dev, unsigned int id)
292293
}
293294

294295
/* initialize all GPIO as output */
295-
outb(0x80, base[id] + 3);
296-
outb(0x00, base[id]);
297-
outb(0x00, base[id] + 1);
298-
outb(0x00, base[id] + 2);
299-
outb(0x80, base[id] + 7);
300-
outb(0x00, base[id] + 4);
301-
outb(0x00, base[id] + 5);
302-
outb(0x00, base[id] + 6);
296+
iowrite8(0x80, gpiommgpio->base + 3);
297+
iowrite8(0x00, gpiommgpio->base);
298+
iowrite8(0x00, gpiommgpio->base + 1);
299+
iowrite8(0x00, gpiommgpio->base + 2);
300+
iowrite8(0x80, gpiommgpio->base + 7);
301+
iowrite8(0x00, gpiommgpio->base + 4);
302+
iowrite8(0x00, gpiommgpio->base + 5);
303+
iowrite8(0x00, gpiommgpio->base + 6);
303304

304305
return 0;
305306
}

0 commit comments

Comments
 (0)