50 #include <linux/kernel.h>
51 #include <linux/module.h>
53 #include <linux/compiler.h>
54 #include <linux/types.h>
55 #include <linux/errno.h>
60 #include <linux/slab.h>
70 static unsigned long bgpio_read8(
void __iomem *
reg)
80 static unsigned long bgpio_read16(
void __iomem *
reg)
90 static unsigned long bgpio_read32(
void __iomem *
reg)
95 #if BITS_PER_LONG >= 64
101 static unsigned long bgpio_read64(
void __iomem *
reg)
107 static unsigned long bgpio_pin2mask(
struct bgpio_chip *bgc,
unsigned int pin)
112 static unsigned long bgpio_pin2mask_be(
struct bgpio_chip *bgc,
115 return 1 << (bgc->
bits - 1 -
pin);
118 static int bgpio_get(
struct gpio_chip *
gc,
unsigned int gpio)
125 static void bgpio_set(
struct gpio_chip *gc,
unsigned int gpio,
int val)
140 spin_unlock_irqrestore(&bgc->
lock, flags);
143 static void bgpio_set_with_clear(
struct gpio_chip *gc,
unsigned int gpio,
147 unsigned long mask = bgc->
pin2mask(bgc, gpio);
155 static void bgpio_set_set(
struct gpio_chip *gc,
unsigned int gpio,
int val)
158 unsigned long mask = bgc->
pin2mask(bgc, gpio);
170 spin_unlock_irqrestore(&bgc->
lock, flags);
173 static int bgpio_simple_dir_in(
struct gpio_chip *gc,
unsigned int gpio)
178 static int bgpio_simple_dir_out(
struct gpio_chip *gc,
unsigned int gpio,
181 gc->set(gc, gpio, val);
186 static int bgpio_dir_in(
struct gpio_chip *gc,
unsigned int gpio)
196 spin_unlock_irqrestore(&bgc->
lock, flags);
201 static int bgpio_dir_out(
struct gpio_chip *gc,
unsigned int gpio,
int val)
206 gc->set(gc, gpio, val);
213 spin_unlock_irqrestore(&bgc->
lock, flags);
218 static int bgpio_dir_in_inv(
struct gpio_chip *gc,
unsigned int gpio)
228 spin_unlock_irqrestore(&bgc->
lock, flags);
233 static int bgpio_dir_out_inv(
struct gpio_chip *gc,
unsigned int gpio,
int val)
238 gc->set(gc, gpio, val);
245 spin_unlock_irqrestore(&bgc->
lock, flags);
250 static int bgpio_setup_accessors(
struct device *
dev,
268 #if BITS_PER_LONG >= 64
275 dev_err(dev,
"unsupported data width %u bits\n", bgc->
bits);
279 bgc->
pin2mask = be ? bgpio_pin2mask_be : bgpio_pin2mask;
306 static int bgpio_setup_io(
struct bgpio_chip *bgc,
319 bgc->
gc.set = bgpio_set_with_clear;
320 }
else if (
set && !clr) {
322 bgc->
gc.set = bgpio_set_set;
324 bgc->
gc.set = bgpio_set;
327 bgc->
gc.get = bgpio_get;
332 static int bgpio_setup_direction(
struct bgpio_chip *bgc,
333 void __iomem *dirout,
336 if (dirout && dirin) {
340 bgc->
gc.direction_output = bgpio_dir_out;
341 bgc->
gc.direction_input = bgpio_dir_in;
344 bgc->
gc.direction_output = bgpio_dir_out_inv;
345 bgc->
gc.direction_input = bgpio_dir_in_inv;
347 bgc->
gc.direction_output = bgpio_simple_dir_out;
348 bgc->
gc.direction_input = bgpio_simple_dir_in;
365 unsigned long sz,
void __iomem *dat,
void __iomem *
set,
366 void __iomem *clr,
void __iomem *dirout,
void __iomem *dirin,
380 bgc->
gc.label = dev_name(dev);
382 bgc->
gc.ngpio = bgc->
bits;
384 ret = bgpio_setup_io(bgc, dat,
set, clr);
392 ret = bgpio_setup_direction(bgc, dirout, dirin);
397 if (bgc->
gc.set == bgpio_set_set &&
407 #ifdef CONFIG_GPIO_GENERIC_PLATFORM
426 sz = resource_size(r);
454 void __iomem *dirout;
457 unsigned long flags = 0;
466 sz = resource_size(r);
468 dat = bgpio_map(pdev,
"dat", sz, &err);
470 return err ? err : -
EINVAL;
472 set = bgpio_map(pdev,
"set", sz, &err);
476 clr = bgpio_map(pdev,
"clr", sz, &err);
480 dirout = bgpio_map(pdev,
"dirout", sz, &err);
484 dirin = bgpio_map(pdev,
"dirin", sz, &err);
495 err =
bgpio_init(bgc, dev, sz, dat,
set, clr, dirout, dirin, flags);
500 bgc->
gc.base = pdata->
base;
501 if (pdata->
ngpio > 0)
505 platform_set_drvdata(pdev, bgc);
512 struct bgpio_chip *bgc = platform_get_drvdata(pdev);
518 {
"basic-mmio-gpio", },
519 {
"basic-mmio-gpio-be", },
526 .name =
"basic-mmio-gpio",
528 .id_table = bgpio_id_table,
529 .probe = bgpio_pdev_probe,