History log of /linux-master/drivers/gpio/gpio-mockup.c
Revision Date Author Comments
# d652049e 15-Nov-2023 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

gpio: mockup: initialize a managed pointer in place

The preferred pattern for autopointers is to initialize them when they're
declared unless it doesn't make sense. Move the declaration of the
managed device pointer to where it's initialized.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


# ed9e8d13 07-Sep-2023 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

gpio: mockup: don't access internal GPIOLIB structures

Don't include gpiolib.h. Track the request status of lines locally
instead. In order to retrieve the device name use the fact that
gpio-mockup supports only a single GPIO device per platform device and
call device_find_any_child().

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>


# 33f909fd 07-Sep-2023 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

gpio: mockup: simplify code by using cleanup helpers

Use lock from linux/cleanup.h and simplify locking paths.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>


# ce9bcbc2 07-Sep-2023 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

gpio: mockup: remove unused field

The desc assigned to debugfs private structure is unused so remove it.

Fixes: 9202ba2397d1 ("gpio: mockup: implement event injecting over debugfs")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>


# 8d5e2db2 07-Sep-2023 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

gpio: mockup: fix kerneldoc

The pull field of the line state struct is undocumented. Fix it.

Fixes: 2a9e27408e12 ("gpio: mockup: rework debugfs interface")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>


# 0a1bb16e 16-May-2023 Zev Weiss <zev@bewilderbeest.net>

gpio: mockup: Fix mode of debugfs files

This driver's debugfs files have had a read operation since commit
2a9e27408e12 ("gpio: mockup: rework debugfs interface"), but were
still being created with write-only mode bits. Update them to
indicate that the files can also be read.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Fixes: 2a9e27408e12 ("gpio: mockup: rework debugfs interface")
Cc: stable@kernel.org # v5.1+
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


# 5cedd3c2 07-Oct-2022 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

gpio: mockup: Add missing header(s)

Do not imply that some of the generic headers may be always included.
Instead, include explicitly what we are direct user of.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 02743c40 20-Sep-2022 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

gpio: mockup: Fix potential resource leakage when register a chip

If creation of software node fails, the locally allocated string
array is left unfreed. Free it on error path.

Fixes: 6fda593f3082 ("gpio: mockup: Convert to use software nodes")
Cc: stable@vger.kernel.org
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>


# b7df41a6 20-Sep-2022 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: fix NULL pointer dereference when removing debugfs

We now remove the device's debugfs entries when unbinding the driver.
This now causes a NULL-pointer dereference on module exit because the
platform devices are unregistered *after* the global debugfs directory
has been recursively removed. Fix it by unregistering the devices first.

Fixes: 303e6da99429 ("gpio: mockup: remove gpio debugfs when remove device")
Cc: Wei Yongjun <weiyongjun1@huawei.com>
Cc: stable@vger.kernel.org
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>


# 303e6da9 21-Aug-2022 Wei Yongjun <weiyongjun1@huawei.com>

gpio: mockup: remove gpio debugfs when remove device

GPIO mockup debugfs is created in gpio_mockup_probe() but
forgot to remove when remove device. This patch add a devm
managed callback for removing them.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>


# f7c151d8 05-Nov-2021 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

gpio: mockup: Switch to use kasprintf_strarray()

Since we have a generic helper, switch the module to use it.
No functional change intended.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Bartosz Golaszewski <brgl@bgdev.pl>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>


# 6fda593f 05-Oct-2021 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

gpio: mockup: Convert to use software nodes

The gpio-mockup driver creates the properties that are shared between
platform and GPIO devices. Because of that, the properties may not
be removed at the proper point of time without provoking a use-after-free
as shown in the following backtrace:

refcount_t: underflow; use-after-free.
WARNING: CPU: 0 PID: 103 at lib/refcount.c:28 refcount_warn_saturate+0xd1/0x120
...
Call Trace:
kobject_put+0xdc/0xf0
software_node_notify_remove+0xa8/0xc0
device_del+0x15a/0x3e0

That's why the driver has to manage the lifetime of the software nodes
by itself.

The problem originates from the old device_add_properties() API, but
has been only revealed after the commit bd1e336aa853 ("driver core: platform:
Remove platform_device_add_properties()"). Hence, it's used as a landmark
for backporting.

Fixes: bd1e336aa853 ("driver core: platform: Remove platform_device_add_properties()")
Reported-by: Kent Gibson <warthog618@gmail.com>
Tested-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
[Bartosz: tweaked local variable placement]
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>


# e7d8fde4 10-May-2021 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

gpio: mockup: Switch to use gpiochip_get_desc()

Switch to use gpiochip_get_desc() helper.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# e5391a02 15-Mar-2021 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

gpio: mockup: Drop duplicate NULL check in gpio_mockup_unregister_pdevs()

Since platform_device_unregister() is NULL-aware, we don't need to duplicate
this check. Remove it and fold the rest of the code.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# 43ddebdd 29-Oct-2020 Vincent Whitchurch <vincent.whitchurch@axis.com>

gpio: mockup: Allow probing from device tree

Allow the mockup driver to be probed via the device tree without any
module parameters, allowing it to be used to configure and test higher
level drivers like the leds-gpio driver and corresponding userspace
before actual hardware is available.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# 42e9acc6 28-Sep-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: refactor the module init function

Let's move the code preparing the device properties into a separate
routine. This has the advantage of simplifying the error handling and
makes the indentation less deep.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 582be05e 28-Sep-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: use the generic 'gpio-line-names' property

GPIO line names are currently created by the driver from the chip label.
We'll want to support custom formats for line names (for instance: to
name all lines the same) for user-space tests so create them in the
module init function and pass them to the driver using the standard
'gpio-line-names' property.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 148c2560 28-Sep-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: pass the chip label as device property

While we do check the "chip-name" property in probe(), we never actually
use it. Let's pass the chip label to the driver using device properties
as we'll want to allow users to define their own once dynamically
created chips are supported.

The property is renamed to "chip-label" to not cause any confusion with
the actual chip name which is of the form: "gpiochipX".

If the "chip-label" property is missing, let's do what most devices in
drivers/gpio/ do and use dev_name().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 383bb2de 28-Sep-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: increase the number of supported device properties

The driver actually supports 4 properties but we only ever set up up to
three. This will change however in upcoming patches so increase the
number of really (as in: the number the property array can hold)
supported properties to 4.

Reported-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 66f222ef 28-Sep-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: remove unneeded return statement

There's a return; at the end of a void function. This is not needed so
remove it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 56f6cb35 28-Sep-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: use pr_fmt()

We don't need a custom logging helper. Let's use the standard pr_fmt()
macro which allows us to use all pr_*() routines with custom format.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 25f00066 28-Sep-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: use KBUILD_MODNAME

Drop the definition for the driver name. Let's use KBUILD_MODNAME for
the log format and use the "gpio-mockup" value directly in the only
place where it's relevant: in the name of the device.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 94502ba9 28-Sep-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: drop unneeded includes

This module doesn't need gpio/consumer.h - it's a provider. It also
doesn't use any symbols from init.h so let's remove both includes.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# e0ab949f 08-Sep-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: fix resource leak in error path

If the module init function fails after creating the debugs directory,
it's never removed. Add proper cleanup calls to avoid this resource
leak.

Fixes: 9202ba2397d1 ("gpio: mockup: implement event injecting over debugfs")
Cc: <stable@vger.kernel.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 1b02d9e7 08-Sep-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: fix resource leak in error path

If the module init function fails after creating the debugs directory,
it's never removed. Add proper cleanup calls to avoid this resource
leak.

Fixes: 9202ba2397d1 ("gpio: mockup: implement event injecting over debugfs")
Cc: <stable@vger.kernel.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


# 337cbeb2 14-May-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

genirq/irq_sim: Simplify the API

The interrupt simulator API exposes a lot of custom data structures and
functions and doesn't reuse the interfaces already exposed by the irq
subsystem. This patch tries to address it.

We hide all the simulator-related data structures from users and instead
rely on the well-known irq domain. When creating the interrupt simulator
the user receives a pointer to a newly created irq_domain and can use it
to create mappings for simulated interrupts.

It is also possible to pass a handle to fwnode when creating the simulator
domain and retrieve it using irq_find_matching_fwnode().

The irq_sim_fire() function is dropped as well. Instead we implement the
irq_get/set_irqchip_state interface.

We modify the two modules that use the simulator at the same time as
adding these changes in order to reduce the intermediate bloat that would
result when trying to migrate the drivers in separate patches.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> #for IIO
Link: https://lore.kernel.org/r/20200514083901.23445-3-brgl@bgdev.pl


# f6e51bb3 10-Feb-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: coding-style fix

The indentation is wrong in gpio_mockup_apply_pull(). This patch makes
the code more readable.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Link: https://lore.kernel.org/r/20200210155059.29609-1-brgl@bgdev.pl
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 726a4453 14-Jan-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: sort headers alphabetically

For consistency and easier maintenance: sort the headers alphabetically.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Link: https://lore.kernel.org/r/20200114150253.28716-3-brgl@bgdev.pl
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# f2f67983 14-Jan-2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: update the license tag

The current GPL v2.0 or later SPDX tag is 'GPL-2.0-or-later' as defined
at https://spdx.org/licenses/.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Link: https://lore.kernel.org/r/20200114150253.28716-2-brgl@bgdev.pl
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# ee8598ae 16-Dec-2019 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: fix coding style

I have missed two indentation issues in commit 64e7112ee307 ("gpio:
mockup: add set_config to support pull up/down"). This commit fixes them.

Fixes: 64e7112ee307 ("gpio: mockup: add set_config to support pull up/down")
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# bc7bc688 10-Dec-2019 Kent Gibson <warthog618@gmail.com>

gpio: mockup: Fix usage of new GPIO_LINE_DIRECTION

Restore the external behavior of gpio-mockup to what it was prior to the
change to using GPIO_LINE_DIRECTION.

Fixes: e42615ec233b ("gpio: Use new GPIO_LINE_DIRECTION")
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# 64e7112e 04-Nov-2019 Kent Gibson <warthog618@gmail.com>

gpio: mockup: add set_config to support pull up/down

Add support for the pull up/down state set via gpiolib line requests to
be reflected in the state of the mockup.
Use case is for testing of the GPIO uAPI, specifically the pull up/down
flags.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# e42615ec 06-Nov-2019 Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>

gpio: Use new GPIO_LINE_DIRECTION

It's hard for occasional GPIO code reader/writer to know if values 0/1
equal to IN or OUT. Use defined GPIO_LINE_DIRECTION_IN and
GPIO_LINE_DIRECTION_OUT to help them out.

NOTE - for gpio-amd-fch and gpio-bd9571mwv:
This commit also changes the return value for direction get to equal 1
for direction INPUT. Prior this commit these drivers might have
returned some other positive value but 1 for INPUT.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Acked-by: Scott Branden <scott.branden@broadcom.com>
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 59929d3a 04-Sep-2019 Wei Yongjun <weiyongjun1@huawei.com>

gpio: mockup: add missing single_release()

When using single_open() for opening, single_release() should be
used instead of seq_release(), otherwise there is a memory leak.

Fixes: 2a9e27408e12 ("gpio: mockup: rework debugfs interface")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# f360dcd4 26-Jun-2019 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

gpio: mockup: no need to check return value of debugfs_create functions

When calling debugfs functions, there is no need to ever check the
return value. The function can work or not, but the code logic should
never do something different based on this.

Cc: Bamvor Jian Zhang <bamv2005@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: linux-gpio@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[Bartosz: removed one more check for debugfs return value]
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>


# ce9fb53c 28-Mar-2019 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: use simple_read_from_buffer() in debugfs read callback

Calling read() for a single byte read will return 2 currently. Use
simple_read_from_buffer() which correctly handles all sizes.

Fixes: 2a9e27408e12 ("gpio: mockup: rework debugfs interface")
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# 2583303d 22-Mar-2019 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: fix debugfs read

The debugfs read callback must advance ppos or users using read() on
the file descriptor will never get the EOL. This wasn't spotted before
as I was using busybox cat for testing which uses sendfile() internally
and only noticed it now when switched to cat from coreutils.

Fixes: 2a9e27408e12 ("gpio: mockup: rework debugfs interface")
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# 2a9e2740 17-Jan-2019 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: rework debugfs interface

Modify the way the debugfs interface works in gpio-mockup. Introduce
the concept of dummy pull config which will keep the mockup lines in
known state. The pull values can be modified by writing to the debugfs
files corresponding to lines. Lines in input mode always report the
current pull value, lines in output mode change the line value but
it will revert back to the one specified by current pull when released.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# e09313ce 23-Jan-2019 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: change the signature of unlocked get/set helpers

The unlocked variants only get called from places where we already have
the pointer to the underlying gpio_mockup_chip structure, so take it
as parameter instead of struct gpio_chip.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# 83336668 18-Jan-2019 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: change the type of 'offset' to unsigned int

This field can never be negative.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# d51ee07a 17-Jan-2019 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: don't create the debugfs link named after the label

User-space tests no longer use it and we're breaking the interface
anyway.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# cbf1e092 31-Oct-2018 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: implement get_multiple()

We already support set_multiple(). Implement get_multiple() as well.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# 9212492f 31-Oct-2018 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: add locking

While no user reported any race condition problems with gpio-mockup,
let's be on the safe side and use a mutex when performing any changes
on the dummy chip structures.

Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>


# bff466ba 08-Nov-2018 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: fix indicated direction

Commit 3edfb7bd76bd ("gpiolib: Show correct direction from the
beginning") fixed an existing issue but broke libgpiod tests by
changing the default direction of dummy lines to output.

We don't break user-space so make gpio-mockup behave as before.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 3ea47b44 25-Sep-2018 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: use device properties instead of platform_data

Some users want to introduce device tree support to the mockup driver.
Let's make it easier by switching to using generic device properties.
The driver stays compatible with previous use cases and after this
conversion there'll be no need to change the way probing of mockup
GPIO chips works.

Tested with libgpiod test suite.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 058de348 26-Apr-2018 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: use the SPDX identifier and remove license boilerplate

Use the SPDX license identifier for GPLv2.0 or later and remove the
license boilerplate.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 6cb9215b 04-Mar-2018 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: fix a potential crash when creating debugfs entries

If we failed to create the top debugfs directory, we must not try to
create the child nodes. We currently only check if gpio_mockup_dbg_dir
is not NULL, but it can also contain an errno if debugfs is disabled
in build options. Use IS_ERR_OR_NULL() instead.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 4f9a4cd6 06-Mar-2018 Linus Walleij <linus.walleij@linaro.org>

gpio: mockup: Update Bamvors mail address

Bamvor changed his mail so let's updat his mail address
everywhere.

Cc: Bamvor Jian Zhang <bamv2005@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# c4b54e13 06-Dec-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: fix a return value check

The return value of platform_device_register_resndata() on error is
an error code converted to pointer with ERR_PTR(), not NULL.

Check the return value correctly.

Fixes: 8a39f597bcfd ("gpio: mockup: rework device probing")
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# cd9835f1 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: add helpers for accessing the gpio ranges

In order to avoid repeating the calculations on every access - add
helpers for gpio base and ngpio components of the ranges array.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# e63a006f 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: rename gpio_mockup_params_nr to gpio_mockup_num_ranges

This variable holds the number of mockup GPIO ranges so rename it
accordingly.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 1e0dca67 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: modify the return value check for devm_irq_sim_init()

As discussed with Marc Zyngier: irq_sim_init() and its devres variant
should return the base of the allocated interrupt range on success
rather than 0. This will be modified later - first, change the way
users handle the return value of these routines.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# c47bee95 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: implement gpio_mockup_set_multiple()

Implement the set_multiple() callback and register it with the gpiolib
framework. This is only meant to also test the internal kernel API.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 2a9d742c 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: tweak line breaks

Minor readability tweak: prefer breaking the lines in a way where the
second part is longer than the first.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# fa86963a 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: verify that ngpio > 0

Improve the module params sanitization: bail out from init if the user
tries to pass a non-positive number of GPIO lines for any mockup chip.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 46526c15 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: fix debugfs handling

The debugfs routines returning pointers can return NULL or error codes
embedded with ERR_PTR(). Check the return values with IS_ERR_OR_NULL().

While we're at it: make the error message more specific so it's not
confused with the one emitted when the top-level gpio-mockup debugfs
directory creation fails.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 1cea4734 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: group code by logic

Keep GPIO chip callbacks, event trigger callbacks and mockup chip
setup code visibly separated. We're mostly good - just need to move
the line naming routine below.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 5b7908c0 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: change the type of value field in line state struct

GPIO values are universally represented as integers. Change the type
of the variable storing the current line value to int for consistency.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# ca8792af 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: extend the debugfs layout

Currently each chip has a dedicated directory in debugfs for event
triggers. We use the chip's label for the directory name, but the user
can't really associate these directories with chip names without
parsing the relevant sysfs entries.

Use chip names for directory names. For backward compatibility: create
links pointing to the actual directories named using the chip labels.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# c3196a78 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: pass the named_lines parameter over platform_data

Move the last bits of code dealing with module parameters to the init
function. Add a new variable to platform data, which indicates to the
probe function if it should name the GPIO lines. If we ever want to
make the line naming more fine-grained (e.g. per chip switch) it will
be easier this way.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 6d974d32 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: merge gpio_mockup_add() into gpio_mockup_probe()

Now that the probe() function only does what is should, there's no
need to split the chip adding logic into a separate routine. Merge
gpio_mockup_add() into gpio_mockup_probe().

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# b9576d03 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: remove a stray tab

Minor coding style fix.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# f1bec99a 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: implement gpio_mockup_err()

Visually shrink the pr_err() calls by encapsulating adding the module
name prefix to the message in a macro.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 8a39f597 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: rework device probing

We currently create a single platform device in init and then parse
the configuration passed to us via module parameters in probe() before
creating GPIO chips and registering them with the gpiolib framework.

The relation between platform devices and mockup chips should be 1:1.

Create a separate platform device for each mockup chip using convenient
helpers (platform_device_register_resndata()). Pass a platform data
structure to probe() in which the configuration (GPIO base, number of
lines, chip index) extracted from the module params is stored. Make
probe() create a single mockup chip for every platform device.

This approach has several advantages:
- we only parse the module parameters in init() and can bail out before
attaching any device if the input is invalid (currently we would
have to examine kernel logs),
- we'll get notified by the device framework about errors in probe()
for specific chips,
- probe() gets simplified and only does what it's supposed to.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# b447a751 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: verify the number of GPIO chips requested

The number of supported mockup chips is limited. Check this limit when
parsing the module parameters.

Also: make sure that each chip is described with a <base - ngpio> pair.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 20c35ac4 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: parse the module params in init, not probe

If the module parameters are invalid, we should bail out from the init
function instead of detecting it during the device probe. That way we
don't even allow the user to load the module if we don't accept the
arguments.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# f3b47170 27-Nov-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: add missing prefixes

Add the gpio_mockup_ prefix to the remaining symbols that still don't
have it, so that the entire driver code is consistent.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 02b6bddb 23-Aug-2017 Colin Ian King <colin.king@canonical.com>

gpio: mockup: remove unused variable gc

The variable gc is assigned but never read and is redundant. Remove it.
Cleans up clang warning:

drivers/gpio/gpio-mockup.c:169:2: warning: Value stored to 'gc' is never read

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# b4c495f0 14-Aug-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: use irq_sim

Shrink the driver by removing the code dealing with dummy interrupts
and replacing it with calls to the irq_sim API.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# f6ac438e 09-Jun-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: use devm_kcalloc() where applicable

When allocating a zeroed array of objects use devm_kcalloc() instead
of manually calculating the required size and using devm_kzalloc().

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# c60c7f4c 09-Jun-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: add myself as author

Just taking credit for the recent changes and new features. :)

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# ec604f15 09-Jun-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: improve the error message

Indicate the error number and make the message a bit more elaborate.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 4dc9d76c 09-Jun-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: don't return magic numbers from probe()

When the requested number of GPIO lines is 0, return -EINVAL, not
-1 which is -EPERM.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# b652336d 09-Jun-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: improve readability

We currently shift bits here and there without actually explaining
what we're doing. Add some helper variables with names indicating
their purpose to improve the code readability.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# b6c2e77d 09-Jun-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: refuse to accept an odd number of GPIO ranges

Currently we ignore the last odd range value, since each chip is
described by two values. Be more strict and require the user to
pass an even number of ranges.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 650b57b0 09-Jun-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: tweak gpio_mockup_event_write()

Invert the logic of the irq_enabled check and only access the private
data after the input is sanitized.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 6f9b3e77 09-Jun-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: improve the debugfs input sanitization

We're currently only checking the first character of the input to the
debugfs event files, so a string like '0sdfdsf' is valid and indicates
a falling edge event.

Be more strict and only allow '0', '1', '0\n' & '1\n'.

While we're at it: move the sanitization code before the irq_enabled
check so that we indicate an error on invalid input even if nobody is
waiting for events.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# c7f5326f 25-May-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: support irqmask and irqunmask

Even though this is a testing module, be nice and actually implement
these functions.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 01a3f23c 25-May-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: be quiet unless something goes wrong

When inserting and removing the module repeatedly (e.g. when running
the libgpiod test-suite) the kernel log gets clobbered with messages
reporting successful creation of dummy gpiochips.

Remove this message and only emit logs when something bad happens.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# c650c00c 25-May-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: add prefixes to the direction enum

All internal symbols except for the direction enum follow the same
convention and use the gpio_mockup prefix. Add the prefix to the
DIR_IN and DIR_OUT definitions as well for consistency across the
file.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# c9546cf1 25-May-2017 Bartosz Golaszewski <brgl@bgdev.pl>

gpio: mockup: fix direction values

The comment in linux/gpio/driver.h says:

@get_direction: returns direction for signal "offset", 0=out, 1=in

We got those switched at some point. Fix the values.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 62a7ca07 04-Mar-2017 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: use devm_irq_alloc_descs()

Use the resource managed variant of irq_alloc_descs(). This allows us
to remove gpio_mockup_remove().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# fa6256db 14-Feb-2017 Dan Carpenter <dan.carpenter@oracle.com>

gpio: mockup: return -EFAULT if copy_from_user() fails

copy_from_user() returns the number of bytes remaining to be copied but
we want to return negative error codes on failue.

Fixes: 9202ba2397d1 ("gpio: mockup: implement event injecting over debugfs")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 9202ba23 06-Feb-2017 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: implement event injecting over debugfs

Create a debugfs directory for every mockup chip and a single file
for every line. Writing (0 or 1) to these files allows the user to
inject line events (falling or rising edge respectively).

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# e2ff7408 06-Feb-2017 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: add a dummy irqchip

Setup a dummy irqchip that will allow us to inject line events for
testing purposes.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 8a68ea00 06-Feb-2017 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: implement naming the lines

In order to allow testing line lookup by name from user space, add
a new boolean parameter that indicates whether we want the lines to
be named. The name is created by concatenating the chip name and the
line offset value.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# e4ba07bf 06-Feb-2017 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: code shrink

Moving a couple of lines around allows us to shrink the code a bit
while keeping the same functionality.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# ca409160 06-Feb-2017 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: readability tweaks

The following patch tries to improve the readability of the mockup
driver.

The driver is called gpio-mockup, so add the same prefix to all
functions and structures.

Add some newlines and use a temporary pointer in gpio_mockup_add().

Drop the name of the direction enum and rename the enum values to
better reflect their purpose.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 364ac456 19-Dec-2016 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: coding style fixes

Fix whitespace errors and arrange local variables for better
readability.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# ad6d8004 19-Dec-2016 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: dynamically allocate memory for chip name

Currently the chip name buffer is allocated on the stack and the
address of the buffer is passed to the gpio framework. It's invalid
after probe() returns, so the sysfs label attribute displays garbage.

Use devm_kasprintf() for each string instead.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# e53c6028 19-Dec-2016 Bartosz Golaszewski <bgolaszewski@baylibre.com>

gpio: mockup: make pins_name_start static

This variable is not used outside this module. Make it static.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


# 0f98dd1b 31-Aug-2016 Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>

gpio/mockup: add virtual gpio device

This patch add basic structure of a virtual gpio device(gpio-mockup)
for testing gpio subsystem. The tester could manipulate such device
through userspace(sysfs or char device) and check the result from
debugfs.

Currently, it support one or more gpiochip(determined by module
parameters with base,ngpio pair). One could test the overlap of
different gpiochip and test the direction and/or output values of
these chips.

Signed-off-by: Kamlakant Patel <kamlakant.patel@broadcom.com>
Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>