Message ID | 20191028073713.25664-3-warthog618@gmail.com |
---|---|
State | New |
Headers | show |
Series | gpio: expose line bias flags to userspace | expand |
pon., 28 paź 2019 o 08:38 Kent Gibson <warthog618@gmail.com> napisał(a): > > Add support for pull up/down to lineevent_create. > Use cases include receiving asynchronous presses from a > push button without an external pull up/down. > > Also restrict the application of bias to lines > explicitly requested as inputs to prevent bias being applied > to as-is line requests. > > Signed-off-by: Kent Gibson <warthog618@gmail.com> > --- > drivers/gpio/gpiolib.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index e80e689be2cc..7dfbb3676ee0 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -554,6 +554,12 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) > (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE))) > return -EINVAL; > > + /* PULL_UP and PULL_DOWN flags only make sense for input mode. */ > + if (!(lflags & GPIOHANDLE_REQUEST_INPUT) && > + ((lflags & GPIOHANDLE_REQUEST_BIAS_PULL_UP) || > + (lflags & GPIOHANDLE_REQUEST_BIAS_PULL_DOWN))) > + return -EINVAL; > + This is not part of this patch - this must go into 1/5. Bart > lh = kzalloc(sizeof(*lh), GFP_KERNEL); > if (!lh) > return -ENOMEM; > @@ -944,6 +950,10 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) > > if (lflags & GPIOHANDLE_REQUEST_ACTIVE_LOW) > set_bit(FLAG_ACTIVE_LOW, &desc->flags); > + if (lflags & GPIOHANDLE_REQUEST_BIAS_PULL_DOWN) > + set_bit(FLAG_PULL_DOWN, &desc->flags); > + if (lflags & GPIOHANDLE_REQUEST_BIAS_PULL_UP) > + set_bit(FLAG_PULL_UP, &desc->flags); > Bart. > ret = gpiod_direction_input(desc); > if (ret) > -- > 2.23.0 >
On Thu, Oct 31, 2019 at 08:11:12AM +0100, Bartosz Golaszewski wrote: > pon., 28 paź 2019 o 08:38 Kent Gibson <warthog618@gmail.com> napisał(a): > > > > Add support for pull up/down to lineevent_create. > > Use cases include receiving asynchronous presses from a > > push button without an external pull up/down. > > > > Also restrict the application of bias to lines > > explicitly requested as inputs to prevent bias being applied > > to as-is line requests. > > > > Signed-off-by: Kent Gibson <warthog618@gmail.com> > > --- > > drivers/gpio/gpiolib.c | 10 ++++++++++ > > 1 file changed, 10 insertions(+) > > > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > > index e80e689be2cc..7dfbb3676ee0 100644 > > --- a/drivers/gpio/gpiolib.c > > +++ b/drivers/gpio/gpiolib.c > > @@ -554,6 +554,12 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) > > (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE))) > > return -EINVAL; > > > > + /* PULL_UP and PULL_DOWN flags only make sense for input mode. */ > > + if (!(lflags & GPIOHANDLE_REQUEST_INPUT) && > > + ((lflags & GPIOHANDLE_REQUEST_BIAS_PULL_UP) || > > + (lflags & GPIOHANDLE_REQUEST_BIAS_PULL_DOWN))) > > + return -EINVAL; > > + > > This is not part of this patch - this must go into 1/5. > Yeah, that would make more sense. Will relocate it in v5. Cheers, Kent.
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e80e689be2cc..7dfbb3676ee0 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -554,6 +554,12 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE))) return -EINVAL; + /* PULL_UP and PULL_DOWN flags only make sense for input mode. */ + if (!(lflags & GPIOHANDLE_REQUEST_INPUT) && + ((lflags & GPIOHANDLE_REQUEST_BIAS_PULL_UP) || + (lflags & GPIOHANDLE_REQUEST_BIAS_PULL_DOWN))) + return -EINVAL; + lh = kzalloc(sizeof(*lh), GFP_KERNEL); if (!lh) return -ENOMEM; @@ -944,6 +950,10 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) if (lflags & GPIOHANDLE_REQUEST_ACTIVE_LOW) set_bit(FLAG_ACTIVE_LOW, &desc->flags); + if (lflags & GPIOHANDLE_REQUEST_BIAS_PULL_DOWN) + set_bit(FLAG_PULL_DOWN, &desc->flags); + if (lflags & GPIOHANDLE_REQUEST_BIAS_PULL_UP) + set_bit(FLAG_PULL_UP, &desc->flags); ret = gpiod_direction_input(desc); if (ret)
Add support for pull up/down to lineevent_create. Use cases include receiving asynchronous presses from a push button without an external pull up/down. Also restrict the application of bias to lines explicitly requested as inputs to prevent bias being applied to as-is line requests. Signed-off-by: Kent Gibson <warthog618@gmail.com> --- drivers/gpio/gpiolib.c | 10 ++++++++++ 1 file changed, 10 insertions(+)