diff options
Diffstat (limited to 'drivers/gpio/gpio-generic.c')
-rw-r--r-- | drivers/gpio/gpio-generic.c | 292 |
1 files changed, 133 insertions, 159 deletions
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c index 053a7f0a83e6..2a4f2333a50b 100644 --- a/drivers/gpio/gpio-generic.c +++ b/drivers/gpio/gpio-generic.c | |||
@@ -56,12 +56,11 @@ o ` ~~~~\___/~~~~ ` controller in FPGA is ,.` | |||
56 | #include <linux/log2.h> | 56 | #include <linux/log2.h> |
57 | #include <linux/ioport.h> | 57 | #include <linux/ioport.h> |
58 | #include <linux/io.h> | 58 | #include <linux/io.h> |
59 | #include <linux/gpio.h> | 59 | #include <linux/gpio/driver.h> |
60 | #include <linux/slab.h> | 60 | #include <linux/slab.h> |
61 | #include <linux/bitops.h> | 61 | #include <linux/bitops.h> |
62 | #include <linux/platform_device.h> | 62 | #include <linux/platform_device.h> |
63 | #include <linux/mod_devicetable.h> | 63 | #include <linux/mod_devicetable.h> |
64 | #include <linux/basic_mmio_gpio.h> | ||
65 | 64 | ||
66 | static void bgpio_write8(void __iomem *reg, unsigned long data) | 65 | static void bgpio_write8(void __iomem *reg, unsigned long data) |
67 | { | 66 | { |
@@ -125,33 +124,30 @@ static unsigned long bgpio_read32be(void __iomem *reg) | |||
125 | return ioread32be(reg); | 124 | return ioread32be(reg); |
126 | } | 125 | } |
127 | 126 | ||
128 | static unsigned long bgpio_pin2mask(struct bgpio_chip *bgc, unsigned int pin) | 127 | static unsigned long bgpio_pin2mask(struct gpio_chip *gc, unsigned int pin) |
129 | { | 128 | { |
130 | return BIT(pin); | 129 | return BIT(pin); |
131 | } | 130 | } |
132 | 131 | ||
133 | static unsigned long bgpio_pin2mask_be(struct bgpio_chip *bgc, | 132 | static unsigned long bgpio_pin2mask_be(struct gpio_chip *gc, |
134 | unsigned int pin) | 133 | unsigned int pin) |
135 | { | 134 | { |
136 | return BIT(bgc->bits - 1 - pin); | 135 | return BIT(gc->bgpio_bits - 1 - pin); |
137 | } | 136 | } |
138 | 137 | ||
139 | static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio) | 138 | static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio) |
140 | { | 139 | { |
141 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | 140 | unsigned long pinmask = gc->pin2mask(gc, gpio); |
142 | unsigned long pinmask = bgc->pin2mask(bgc, gpio); | ||
143 | 141 | ||
144 | if (bgc->dir & pinmask) | 142 | if (gc->bgpio_dir & pinmask) |
145 | return !!(bgc->read_reg(bgc->reg_set) & pinmask); | 143 | return !!(gc->read_reg(gc->reg_set) & pinmask); |
146 | else | 144 | else |
147 | return !!(bgc->read_reg(bgc->reg_dat) & pinmask); | 145 | return !!(gc->read_reg(gc->reg_dat) & pinmask); |
148 | } | 146 | } |
149 | 147 | ||
150 | static int bgpio_get(struct gpio_chip *gc, unsigned int gpio) | 148 | static int bgpio_get(struct gpio_chip *gc, unsigned int gpio) |
151 | { | 149 | { |
152 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | 150 | return !!(gc->read_reg(gc->reg_dat) & gc->pin2mask(gc, gpio)); |
153 | |||
154 | return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio)); | ||
155 | } | 151 | } |
156 | 152 | ||
157 | static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val) | 153 | static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val) |
@@ -160,53 +156,50 @@ static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val) | |||
160 | 156 | ||
161 | static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) | 157 | static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) |
162 | { | 158 | { |
163 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | 159 | unsigned long mask = gc->pin2mask(gc, gpio); |
164 | unsigned long mask = bgc->pin2mask(bgc, gpio); | ||
165 | unsigned long flags; | 160 | unsigned long flags; |
166 | 161 | ||
167 | spin_lock_irqsave(&bgc->lock, flags); | 162 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
168 | 163 | ||
169 | if (val) | 164 | if (val) |
170 | bgc->data |= mask; | 165 | gc->bgpio_data |= mask; |
171 | else | 166 | else |
172 | bgc->data &= ~mask; | 167 | gc->bgpio_data &= ~mask; |
173 | 168 | ||
174 | bgc->write_reg(bgc->reg_dat, bgc->data); | 169 | gc->write_reg(gc->reg_dat, gc->bgpio_data); |
175 | 170 | ||
176 | spin_unlock_irqrestore(&bgc->lock, flags); | 171 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
177 | } | 172 | } |
178 | 173 | ||
179 | static void bgpio_set_with_clear(struct gpio_chip *gc, unsigned int gpio, | 174 | static void bgpio_set_with_clear(struct gpio_chip *gc, unsigned int gpio, |
180 | int val) | 175 | int val) |
181 | { | 176 | { |
182 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | 177 | unsigned long mask = gc->pin2mask(gc, gpio); |
183 | unsigned long mask = bgc->pin2mask(bgc, gpio); | ||
184 | 178 | ||
185 | if (val) | 179 | if (val) |
186 | bgc->write_reg(bgc->reg_set, mask); | 180 | gc->write_reg(gc->reg_set, mask); |
187 | else | 181 | else |
188 | bgc->write_reg(bgc->reg_clr, mask); | 182 | gc->write_reg(gc->reg_clr, mask); |
189 | } | 183 | } |
190 | 184 | ||
191 | static void bgpio_set_set(struct gpio_chip *gc, unsigned int gpio, int val) | 185 | static void bgpio_set_set(struct gpio_chip *gc, unsigned int gpio, int val) |
192 | { | 186 | { |
193 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | 187 | unsigned long mask = gc->pin2mask(gc, gpio); |
194 | unsigned long mask = bgc->pin2mask(bgc, gpio); | ||
195 | unsigned long flags; | 188 | unsigned long flags; |
196 | 189 | ||
197 | spin_lock_irqsave(&bgc->lock, flags); | 190 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
198 | 191 | ||
199 | if (val) | 192 | if (val) |
200 | bgc->data |= mask; | 193 | gc->bgpio_data |= mask; |
201 | else | 194 | else |
202 | bgc->data &= ~mask; | 195 | gc->bgpio_data &= ~mask; |
203 | 196 | ||
204 | bgc->write_reg(bgc->reg_set, bgc->data); | 197 | gc->write_reg(gc->reg_set, gc->bgpio_data); |
205 | 198 | ||
206 | spin_unlock_irqrestore(&bgc->lock, flags); | 199 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
207 | } | 200 | } |
208 | 201 | ||
209 | static void bgpio_multiple_get_masks(struct bgpio_chip *bgc, | 202 | static void bgpio_multiple_get_masks(struct gpio_chip *gc, |
210 | unsigned long *mask, unsigned long *bits, | 203 | unsigned long *mask, unsigned long *bits, |
211 | unsigned long *set_mask, | 204 | unsigned long *set_mask, |
212 | unsigned long *clear_mask) | 205 | unsigned long *clear_mask) |
@@ -216,19 +209,19 @@ static void bgpio_multiple_get_masks(struct bgpio_chip *bgc, | |||
216 | *set_mask = 0; | 209 | *set_mask = 0; |
217 | *clear_mask = 0; | 210 | *clear_mask = 0; |
218 | 211 | ||
219 | for (i = 0; i < bgc->bits; i++) { | 212 | for (i = 0; i < gc->bgpio_bits; i++) { |
220 | if (*mask == 0) | 213 | if (*mask == 0) |
221 | break; | 214 | break; |
222 | if (__test_and_clear_bit(i, mask)) { | 215 | if (__test_and_clear_bit(i, mask)) { |
223 | if (test_bit(i, bits)) | 216 | if (test_bit(i, bits)) |
224 | *set_mask |= bgc->pin2mask(bgc, i); | 217 | *set_mask |= gc->pin2mask(gc, i); |
225 | else | 218 | else |
226 | *clear_mask |= bgc->pin2mask(bgc, i); | 219 | *clear_mask |= gc->pin2mask(gc, i); |
227 | } | 220 | } |
228 | } | 221 | } |
229 | } | 222 | } |
230 | 223 | ||
231 | static void bgpio_set_multiple_single_reg(struct bgpio_chip *bgc, | 224 | static void bgpio_set_multiple_single_reg(struct gpio_chip *gc, |
232 | unsigned long *mask, | 225 | unsigned long *mask, |
233 | unsigned long *bits, | 226 | unsigned long *bits, |
234 | void __iomem *reg) | 227 | void __iomem *reg) |
@@ -236,47 +229,42 @@ static void bgpio_set_multiple_single_reg(struct bgpio_chip *bgc, | |||
236 | unsigned long flags; | 229 | unsigned long flags; |
237 | unsigned long set_mask, clear_mask; | 230 | unsigned long set_mask, clear_mask; |
238 | 231 | ||
239 | spin_lock_irqsave(&bgc->lock, flags); | 232 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
240 | 233 | ||
241 | bgpio_multiple_get_masks(bgc, mask, bits, &set_mask, &clear_mask); | 234 | bgpio_multiple_get_masks(gc, mask, bits, &set_mask, &clear_mask); |
242 | 235 | ||
243 | bgc->data |= set_mask; | 236 | gc->bgpio_data |= set_mask; |
244 | bgc->data &= ~clear_mask; | 237 | gc->bgpio_data &= ~clear_mask; |
245 | 238 | ||
246 | bgc->write_reg(reg, bgc->data); | 239 | gc->write_reg(reg, gc->bgpio_data); |
247 | 240 | ||
248 | spin_unlock_irqrestore(&bgc->lock, flags); | 241 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
249 | } | 242 | } |
250 | 243 | ||
251 | static void bgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, | 244 | static void bgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, |
252 | unsigned long *bits) | 245 | unsigned long *bits) |
253 | { | 246 | { |
254 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | 247 | bgpio_set_multiple_single_reg(gc, mask, bits, gc->reg_dat); |
255 | |||
256 | bgpio_set_multiple_single_reg(bgc, mask, bits, bgc->reg_dat); | ||
257 | } | 248 | } |
258 | 249 | ||
259 | static void bgpio_set_multiple_set(struct gpio_chip *gc, unsigned long *mask, | 250 | static void bgpio_set_multiple_set(struct gpio_chip *gc, unsigned long *mask, |
260 | unsigned long *bits) | 251 | unsigned long *bits) |
261 | { | 252 | { |
262 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | 253 | bgpio_set_multiple_single_reg(gc, mask, bits, gc->reg_set); |
263 | |||
264 | bgpio_set_multiple_single_reg(bgc, mask, bits, bgc->reg_set); | ||
265 | } | 254 | } |
266 | 255 | ||
267 | static void bgpio_set_multiple_with_clear(struct gpio_chip *gc, | 256 | static void bgpio_set_multiple_with_clear(struct gpio_chip *gc, |
268 | unsigned long *mask, | 257 | unsigned long *mask, |
269 | unsigned long *bits) | 258 | unsigned long *bits) |
270 | { | 259 | { |
271 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | ||
272 | unsigned long set_mask, clear_mask; | 260 | unsigned long set_mask, clear_mask; |
273 | 261 | ||
274 | bgpio_multiple_get_masks(bgc, mask, bits, &set_mask, &clear_mask); | 262 | bgpio_multiple_get_masks(gc, mask, bits, &set_mask, &clear_mask); |
275 | 263 | ||
276 | if (set_mask) | 264 | if (set_mask) |
277 | bgc->write_reg(bgc->reg_set, set_mask); | 265 | gc->write_reg(gc->reg_set, set_mask); |
278 | if (clear_mask) | 266 | if (clear_mask) |
279 | bgc->write_reg(bgc->reg_clr, clear_mask); | 267 | gc->write_reg(gc->reg_clr, clear_mask); |
280 | } | 268 | } |
281 | 269 | ||
282 | static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio) | 270 | static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio) |
@@ -300,111 +288,103 @@ static int bgpio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio, | |||
300 | 288 | ||
301 | static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) | 289 | static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) |
302 | { | 290 | { |
303 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | ||
304 | unsigned long flags; | 291 | unsigned long flags; |
305 | 292 | ||
306 | spin_lock_irqsave(&bgc->lock, flags); | 293 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
307 | 294 | ||
308 | bgc->dir &= ~bgc->pin2mask(bgc, gpio); | 295 | gc->bgpio_dir &= ~gc->pin2mask(gc, gpio); |
309 | bgc->write_reg(bgc->reg_dir, bgc->dir); | 296 | gc->write_reg(gc->reg_dir, gc->bgpio_dir); |
310 | 297 | ||
311 | spin_unlock_irqrestore(&bgc->lock, flags); | 298 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
312 | 299 | ||
313 | return 0; | 300 | return 0; |
314 | } | 301 | } |
315 | 302 | ||
316 | static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) | 303 | static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) |
317 | { | 304 | { |
318 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | 305 | /* Return 0 if output, 1 of input */ |
319 | 306 | return !(gc->read_reg(gc->reg_dir) & gc->pin2mask(gc, gpio)); | |
320 | return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ? | ||
321 | GPIOF_DIR_OUT : GPIOF_DIR_IN; | ||
322 | } | 307 | } |
323 | 308 | ||
324 | static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) | 309 | static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) |
325 | { | 310 | { |
326 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | ||
327 | unsigned long flags; | 311 | unsigned long flags; |
328 | 312 | ||
329 | gc->set(gc, gpio, val); | 313 | gc->set(gc, gpio, val); |
330 | 314 | ||
331 | spin_lock_irqsave(&bgc->lock, flags); | 315 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
332 | 316 | ||
333 | bgc->dir |= bgc->pin2mask(bgc, gpio); | 317 | gc->bgpio_dir |= gc->pin2mask(gc, gpio); |
334 | bgc->write_reg(bgc->reg_dir, bgc->dir); | 318 | gc->write_reg(gc->reg_dir, gc->bgpio_dir); |
335 | 319 | ||
336 | spin_unlock_irqrestore(&bgc->lock, flags); | 320 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
337 | 321 | ||
338 | return 0; | 322 | return 0; |
339 | } | 323 | } |
340 | 324 | ||
341 | static int bgpio_dir_in_inv(struct gpio_chip *gc, unsigned int gpio) | 325 | static int bgpio_dir_in_inv(struct gpio_chip *gc, unsigned int gpio) |
342 | { | 326 | { |
343 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | ||
344 | unsigned long flags; | 327 | unsigned long flags; |
345 | 328 | ||
346 | spin_lock_irqsave(&bgc->lock, flags); | 329 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
347 | 330 | ||
348 | bgc->dir |= bgc->pin2mask(bgc, gpio); | 331 | gc->bgpio_dir |= gc->pin2mask(gc, gpio); |
349 | bgc->write_reg(bgc->reg_dir, bgc->dir); | 332 | gc->write_reg(gc->reg_dir, gc->bgpio_dir); |
350 | 333 | ||
351 | spin_unlock_irqrestore(&bgc->lock, flags); | 334 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
352 | 335 | ||
353 | return 0; | 336 | return 0; |
354 | } | 337 | } |
355 | 338 | ||
356 | static int bgpio_dir_out_inv(struct gpio_chip *gc, unsigned int gpio, int val) | 339 | static int bgpio_dir_out_inv(struct gpio_chip *gc, unsigned int gpio, int val) |
357 | { | 340 | { |
358 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | ||
359 | unsigned long flags; | 341 | unsigned long flags; |
360 | 342 | ||
361 | gc->set(gc, gpio, val); | 343 | gc->set(gc, gpio, val); |
362 | 344 | ||
363 | spin_lock_irqsave(&bgc->lock, flags); | 345 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
364 | 346 | ||
365 | bgc->dir &= ~bgc->pin2mask(bgc, gpio); | 347 | gc->bgpio_dir &= ~gc->pin2mask(gc, gpio); |
366 | bgc->write_reg(bgc->reg_dir, bgc->dir); | 348 | gc->write_reg(gc->reg_dir, gc->bgpio_dir); |
367 | 349 | ||
368 | spin_unlock_irqrestore(&bgc->lock, flags); | 350 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
369 | 351 | ||
370 | return 0; | 352 | return 0; |
371 | } | 353 | } |
372 | 354 | ||
373 | static int bgpio_get_dir_inv(struct gpio_chip *gc, unsigned int gpio) | 355 | static int bgpio_get_dir_inv(struct gpio_chip *gc, unsigned int gpio) |
374 | { | 356 | { |
375 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | 357 | /* Return 0 if output, 1 if input */ |
376 | 358 | return !!(gc->read_reg(gc->reg_dir) & gc->pin2mask(gc, gpio)); | |
377 | return (bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)) ? | ||
378 | GPIOF_DIR_IN : GPIOF_DIR_OUT; | ||
379 | } | 359 | } |
380 | 360 | ||
381 | static int bgpio_setup_accessors(struct device *dev, | 361 | static int bgpio_setup_accessors(struct device *dev, |
382 | struct bgpio_chip *bgc, | 362 | struct gpio_chip *gc, |
383 | bool bit_be, | 363 | bool bit_be, |
384 | bool byte_be) | 364 | bool byte_be) |
385 | { | 365 | { |
386 | 366 | ||
387 | switch (bgc->bits) { | 367 | switch (gc->bgpio_bits) { |
388 | case 8: | 368 | case 8: |
389 | bgc->read_reg = bgpio_read8; | 369 | gc->read_reg = bgpio_read8; |
390 | bgc->write_reg = bgpio_write8; | 370 | gc->write_reg = bgpio_write8; |
391 | break; | 371 | break; |
392 | case 16: | 372 | case 16: |
393 | if (byte_be) { | 373 | if (byte_be) { |
394 | bgc->read_reg = bgpio_read16be; | 374 | gc->read_reg = bgpio_read16be; |
395 | bgc->write_reg = bgpio_write16be; | 375 | gc->write_reg = bgpio_write16be; |
396 | } else { | 376 | } else { |
397 | bgc->read_reg = bgpio_read16; | 377 | gc->read_reg = bgpio_read16; |
398 | bgc->write_reg = bgpio_write16; | 378 | gc->write_reg = bgpio_write16; |
399 | } | 379 | } |
400 | break; | 380 | break; |
401 | case 32: | 381 | case 32: |
402 | if (byte_be) { | 382 | if (byte_be) { |
403 | bgc->read_reg = bgpio_read32be; | 383 | gc->read_reg = bgpio_read32be; |
404 | bgc->write_reg = bgpio_write32be; | 384 | gc->write_reg = bgpio_write32be; |
405 | } else { | 385 | } else { |
406 | bgc->read_reg = bgpio_read32; | 386 | gc->read_reg = bgpio_read32; |
407 | bgc->write_reg = bgpio_write32; | 387 | gc->write_reg = bgpio_write32; |
408 | } | 388 | } |
409 | break; | 389 | break; |
410 | #if BITS_PER_LONG >= 64 | 390 | #if BITS_PER_LONG >= 64 |
@@ -414,17 +394,17 @@ static int bgpio_setup_accessors(struct device *dev, | |||
414 | "64 bit big endian byte order unsupported\n"); | 394 | "64 bit big endian byte order unsupported\n"); |
415 | return -EINVAL; | 395 | return -EINVAL; |
416 | } else { | 396 | } else { |
417 | bgc->read_reg = bgpio_read64; | 397 | gc->read_reg = bgpio_read64; |
418 | bgc->write_reg = bgpio_write64; | 398 | gc->write_reg = bgpio_write64; |
419 | } | 399 | } |
420 | break; | 400 | break; |
421 | #endif /* BITS_PER_LONG >= 64 */ | 401 | #endif /* BITS_PER_LONG >= 64 */ |
422 | default: | 402 | default: |
423 | dev_err(dev, "unsupported data width %u bits\n", bgc->bits); | 403 | dev_err(dev, "unsupported data width %u bits\n", gc->bgpio_bits); |
424 | return -EINVAL; | 404 | return -EINVAL; |
425 | } | 405 | } |
426 | 406 | ||
427 | bgc->pin2mask = bit_be ? bgpio_pin2mask_be : bgpio_pin2mask; | 407 | gc->pin2mask = bit_be ? bgpio_pin2mask_be : bgpio_pin2mask; |
428 | 408 | ||
429 | return 0; | 409 | return 0; |
430 | } | 410 | } |
@@ -451,44 +431,44 @@ static int bgpio_setup_accessors(struct device *dev, | |||
451 | * - an input direction register (named "dirin") where a 1 bit indicates | 431 | * - an input direction register (named "dirin") where a 1 bit indicates |
452 | * the GPIO is an input. | 432 | * the GPIO is an input. |
453 | */ | 433 | */ |
454 | static int bgpio_setup_io(struct bgpio_chip *bgc, | 434 | static int bgpio_setup_io(struct gpio_chip *gc, |
455 | void __iomem *dat, | 435 | void __iomem *dat, |
456 | void __iomem *set, | 436 | void __iomem *set, |
457 | void __iomem *clr, | 437 | void __iomem *clr, |
458 | unsigned long flags) | 438 | unsigned long flags) |
459 | { | 439 | { |
460 | 440 | ||
461 | bgc->reg_dat = dat; | 441 | gc->reg_dat = dat; |
462 | if (!bgc->reg_dat) | 442 | if (!gc->reg_dat) |
463 | return -EINVAL; | 443 | return -EINVAL; |
464 | 444 | ||
465 | if (set && clr) { | 445 | if (set && clr) { |
466 | bgc->reg_set = set; | 446 | gc->reg_set = set; |
467 | bgc->reg_clr = clr; | 447 | gc->reg_clr = clr; |
468 | bgc->gc.set = bgpio_set_with_clear; | 448 | gc->set = bgpio_set_with_clear; |
469 | bgc->gc.set_multiple = bgpio_set_multiple_with_clear; | 449 | gc->set_multiple = bgpio_set_multiple_with_clear; |
470 | } else if (set && !clr) { | 450 | } else if (set && !clr) { |
471 | bgc->reg_set = set; | 451 | gc->reg_set = set; |
472 | bgc->gc.set = bgpio_set_set; | 452 | gc->set = bgpio_set_set; |
473 | bgc->gc.set_multiple = bgpio_set_multiple_set; | 453 | gc->set_multiple = bgpio_set_multiple_set; |
474 | } else if (flags & BGPIOF_NO_OUTPUT) { | 454 | } else if (flags & BGPIOF_NO_OUTPUT) { |
475 | bgc->gc.set = bgpio_set_none; | 455 | gc->set = bgpio_set_none; |
476 | bgc->gc.set_multiple = NULL; | 456 | gc->set_multiple = NULL; |
477 | } else { | 457 | } else { |
478 | bgc->gc.set = bgpio_set; | 458 | gc->set = bgpio_set; |
479 | bgc->gc.set_multiple = bgpio_set_multiple; | 459 | gc->set_multiple = bgpio_set_multiple; |
480 | } | 460 | } |
481 | 461 | ||
482 | if (!(flags & BGPIOF_UNREADABLE_REG_SET) && | 462 | if (!(flags & BGPIOF_UNREADABLE_REG_SET) && |
483 | (flags & BGPIOF_READ_OUTPUT_REG_SET)) | 463 | (flags & BGPIOF_READ_OUTPUT_REG_SET)) |
484 | bgc->gc.get = bgpio_get_set; | 464 | gc->get = bgpio_get_set; |
485 | else | 465 | else |
486 | bgc->gc.get = bgpio_get; | 466 | gc->get = bgpio_get; |
487 | 467 | ||
488 | return 0; | 468 | return 0; |
489 | } | 469 | } |
490 | 470 | ||
491 | static int bgpio_setup_direction(struct bgpio_chip *bgc, | 471 | static int bgpio_setup_direction(struct gpio_chip *gc, |
492 | void __iomem *dirout, | 472 | void __iomem *dirout, |
493 | void __iomem *dirin, | 473 | void __iomem *dirin, |
494 | unsigned long flags) | 474 | unsigned long flags) |
@@ -496,21 +476,21 @@ static int bgpio_setup_direction(struct bgpio_chip *bgc, | |||
496 | if (dirout && dirin) { | 476 | if (dirout && dirin) { |
497 | return -EINVAL; | 477 | return -EINVAL; |
498 | } else if (dirout) { | 478 | } else if (dirout) { |
499 | bgc->reg_dir = dirout; | 479 | gc->reg_dir = dirout; |
500 | bgc->gc.direction_output = bgpio_dir_out; | 480 | gc->direction_output = bgpio_dir_out; |
501 | bgc->gc.direction_input = bgpio_dir_in; | 481 | gc->direction_input = bgpio_dir_in; |
502 | bgc->gc.get_direction = bgpio_get_dir; | 482 | gc->get_direction = bgpio_get_dir; |
503 | } else if (dirin) { | 483 | } else if (dirin) { |
504 | bgc->reg_dir = dirin; | 484 | gc->reg_dir = dirin; |
505 | bgc->gc.direction_output = bgpio_dir_out_inv; | 485 | gc->direction_output = bgpio_dir_out_inv; |
506 | bgc->gc.direction_input = bgpio_dir_in_inv; | 486 | gc->direction_input = bgpio_dir_in_inv; |
507 | bgc->gc.get_direction = bgpio_get_dir_inv; | 487 | gc->get_direction = bgpio_get_dir_inv; |
508 | } else { | 488 | } else { |
509 | if (flags & BGPIOF_NO_OUTPUT) | 489 | if (flags & BGPIOF_NO_OUTPUT) |
510 | bgc->gc.direction_output = bgpio_dir_out_err; | 490 | gc->direction_output = bgpio_dir_out_err; |
511 | else | 491 | else |
512 | bgc->gc.direction_output = bgpio_simple_dir_out; | 492 | gc->direction_output = bgpio_simple_dir_out; |
513 | bgc->gc.direction_input = bgpio_simple_dir_in; | 493 | gc->direction_input = bgpio_simple_dir_in; |
514 | } | 494 | } |
515 | 495 | ||
516 | return 0; | 496 | return 0; |
@@ -524,14 +504,7 @@ static int bgpio_request(struct gpio_chip *chip, unsigned gpio_pin) | |||
524 | return -EINVAL; | 504 | return -EINVAL; |
525 | } | 505 | } |
526 | 506 | ||
527 | int bgpio_remove(struct bgpio_chip *bgc) | 507 | int bgpio_init(struct gpio_chip *gc, struct device *dev, |
528 | { | ||
529 | gpiochip_remove(&bgc->gc); | ||
530 | return 0; | ||
531 | } | ||
532 | EXPORT_SYMBOL_GPL(bgpio_remove); | ||
533 | |||
534 | int bgpio_init(struct bgpio_chip *bgc, struct device *dev, | ||
535 | unsigned long sz, void __iomem *dat, void __iomem *set, | 508 | unsigned long sz, void __iomem *dat, void __iomem *set, |
536 | void __iomem *clr, void __iomem *dirout, void __iomem *dirin, | 509 | void __iomem *clr, void __iomem *dirout, void __iomem *dirin, |
537 | unsigned long flags) | 510 | unsigned long flags) |
@@ -541,36 +514,36 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev, | |||
541 | if (!is_power_of_2(sz)) | 514 | if (!is_power_of_2(sz)) |
542 | return -EINVAL; | 515 | return -EINVAL; |
543 | 516 | ||
544 | bgc->bits = sz * 8; | 517 | gc->bgpio_bits = sz * 8; |
545 | if (bgc->bits > BITS_PER_LONG) | 518 | if (gc->bgpio_bits > BITS_PER_LONG) |
546 | return -EINVAL; | 519 | return -EINVAL; |
547 | 520 | ||
548 | spin_lock_init(&bgc->lock); | 521 | spin_lock_init(&gc->bgpio_lock); |
549 | bgc->gc.parent = dev; | 522 | gc->parent = dev; |
550 | bgc->gc.label = dev_name(dev); | 523 | gc->label = dev_name(dev); |
551 | bgc->gc.base = -1; | 524 | gc->base = -1; |
552 | bgc->gc.ngpio = bgc->bits; | 525 | gc->ngpio = gc->bgpio_bits; |
553 | bgc->gc.request = bgpio_request; | 526 | gc->request = bgpio_request; |
554 | 527 | ||
555 | ret = bgpio_setup_io(bgc, dat, set, clr, flags); | 528 | ret = bgpio_setup_io(gc, dat, set, clr, flags); |
556 | if (ret) | 529 | if (ret) |
557 | return ret; | 530 | return ret; |
558 | 531 | ||
559 | ret = bgpio_setup_accessors(dev, bgc, flags & BGPIOF_BIG_ENDIAN, | 532 | ret = bgpio_setup_accessors(dev, gc, flags & BGPIOF_BIG_ENDIAN, |
560 | flags & BGPIOF_BIG_ENDIAN_BYTE_ORDER); | 533 | flags & BGPIOF_BIG_ENDIAN_BYTE_ORDER); |
561 | if (ret) | 534 | if (ret) |
562 | return ret; | 535 | return ret; |
563 | 536 | ||
564 | ret = bgpio_setup_direction(bgc, dirout, dirin, flags); | 537 | ret = bgpio_setup_direction(gc, dirout, dirin, flags); |
565 | if (ret) | 538 | if (ret) |
566 | return ret; | 539 | return ret; |
567 | 540 | ||
568 | bgc->data = bgc->read_reg(bgc->reg_dat); | 541 | gc->bgpio_data = gc->read_reg(gc->reg_dat); |
569 | if (bgc->gc.set == bgpio_set_set && | 542 | if (gc->set == bgpio_set_set && |
570 | !(flags & BGPIOF_UNREADABLE_REG_SET)) | 543 | !(flags & BGPIOF_UNREADABLE_REG_SET)) |
571 | bgc->data = bgc->read_reg(bgc->reg_set); | 544 | gc->bgpio_data = gc->read_reg(gc->reg_set); |
572 | if (bgc->reg_dir && !(flags & BGPIOF_UNREADABLE_REG_DIR)) | 545 | if (gc->reg_dir && !(flags & BGPIOF_UNREADABLE_REG_DIR)) |
573 | bgc->dir = bgc->read_reg(bgc->reg_dir); | 546 | gc->bgpio_dir = gc->read_reg(gc->reg_dir); |
574 | 547 | ||
575 | return ret; | 548 | return ret; |
576 | } | 549 | } |
@@ -608,7 +581,7 @@ static int bgpio_pdev_probe(struct platform_device *pdev) | |||
608 | unsigned long sz; | 581 | unsigned long sz; |
609 | unsigned long flags = pdev->id_entry->driver_data; | 582 | unsigned long flags = pdev->id_entry->driver_data; |
610 | int err; | 583 | int err; |
611 | struct bgpio_chip *bgc; | 584 | struct gpio_chip *gc; |
612 | struct bgpio_pdata *pdata = dev_get_platdata(dev); | 585 | struct bgpio_pdata *pdata = dev_get_platdata(dev); |
613 | 586 | ||
614 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); | 587 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); |
@@ -637,32 +610,33 @@ static int bgpio_pdev_probe(struct platform_device *pdev) | |||
637 | if (IS_ERR(dirin)) | 610 | if (IS_ERR(dirin)) |
638 | return PTR_ERR(dirin); | 611 | return PTR_ERR(dirin); |
639 | 612 | ||
640 | bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); | 613 | gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); |
641 | if (!bgc) | 614 | if (!gc) |
642 | return -ENOMEM; | 615 | return -ENOMEM; |
643 | 616 | ||
644 | err = bgpio_init(bgc, dev, sz, dat, set, clr, dirout, dirin, flags); | 617 | err = bgpio_init(gc, dev, sz, dat, set, clr, dirout, dirin, flags); |
645 | if (err) | 618 | if (err) |
646 | return err; | 619 | return err; |
647 | 620 | ||
648 | if (pdata) { | 621 | if (pdata) { |
649 | if (pdata->label) | 622 | if (pdata->label) |
650 | bgc->gc.label = pdata->label; | 623 | gc->label = pdata->label; |
651 | bgc->gc.base = pdata->base; | 624 | gc->base = pdata->base; |
652 | if (pdata->ngpio > 0) | 625 | if (pdata->ngpio > 0) |
653 | bgc->gc.ngpio = pdata->ngpio; | 626 | gc->ngpio = pdata->ngpio; |
654 | } | 627 | } |
655 | 628 | ||
656 | platform_set_drvdata(pdev, bgc); | 629 | platform_set_drvdata(pdev, gc); |
657 | 630 | ||
658 | return gpiochip_add(&bgc->gc); | 631 | return gpiochip_add_data(gc, NULL); |
659 | } | 632 | } |
660 | 633 | ||
661 | static int bgpio_pdev_remove(struct platform_device *pdev) | 634 | static int bgpio_pdev_remove(struct platform_device *pdev) |
662 | { | 635 | { |
663 | struct bgpio_chip *bgc = platform_get_drvdata(pdev); | 636 | struct gpio_chip *gc = platform_get_drvdata(pdev); |
664 | 637 | ||
665 | return bgpio_remove(bgc); | 638 | gpiochip_remove(gc); |
639 | return 0; | ||
666 | } | 640 | } |
667 | 641 | ||
668 | static const struct platform_device_id bgpio_id_table[] = { | 642 | static const struct platform_device_id bgpio_id_table[] = { |