summaryrefslogtreecommitdiff
path: root/drivers/gpio/gpio-mockup.c
AgeCommit message (Collapse)Author
2020-01-03gpio: mockup: fix coding styleBartosz Golaszewski
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>
2019-12-11gpio: mockup: Fix usage of new GPIO_LINE_DIRECTIONKent Gibson
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>
2019-11-12gpio: mockup: add set_config to support pull up/downKent Gibson
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>
2019-11-07gpio: Use new GPIO_LINE_DIRECTIONMatti Vaittinen
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>
2019-09-09gpio: mockup: add missing single_release()Wei Yongjun
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>
2019-06-27gpio: mockup: no need to check return value of debugfs_create functionsGreg Kroah-Hartman
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>
2019-03-28gpio: mockup: use simple_read_from_buffer() in debugfs read callbackBartosz Golaszewski
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>
2019-03-27gpio: mockup: fix debugfs readBartosz Golaszewski
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>
2019-02-19gpio: mockup: rework debugfs interfaceBartosz Golaszewski
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>
2019-02-19gpio: mockup: change the signature of unlocked get/set helpersBartosz Golaszewski
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>
2019-02-19gpio: mockup: change the type of 'offset' to unsigned intBartosz Golaszewski
This field can never be negative. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-02-19gpio: mockup: don't create the debugfs link named after the labelBartosz Golaszewski
User-space tests no longer use it and we're breaking the interface anyway. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-02-19gpio: mockup: implement get_multiple()Bartosz Golaszewski
We already support set_multiple(). Implement get_multiple() as well. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-02-19gpio: mockup: add lockingBartosz Golaszewski
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>
2018-11-16gpio: mockup: fix indicated directionBartosz Golaszewski
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>
2018-10-03gpio: mockup: use device properties instead of platform_dataBartosz Golaszewski
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>
2018-05-16gpio: mockup: use the SPDX identifier and remove license boilerplateBartosz Golaszewski
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>
2018-03-27gpio: mockup: fix a potential crash when creating debugfs entriesBartosz Golaszewski
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>
2018-03-06gpio: mockup: Update Bamvors mail addressLinus Walleij
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>
2017-12-08gpio: mockup: fix a return value checkBartosz Golaszewski
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>
2017-12-02gpio: mockup: add helpers for accessing the gpio rangesBartosz Golaszewski
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>
2017-12-02gpio: mockup: rename gpio_mockup_params_nr to gpio_mockup_num_rangesBartosz Golaszewski
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>
2017-12-02gpio: mockup: modify the return value check for devm_irq_sim_init()Bartosz Golaszewski
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>
2017-12-02gpio: mockup: implement gpio_mockup_set_multiple()Bartosz Golaszewski
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>
2017-12-02gpio: mockup: tweak line breaksBartosz Golaszewski
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>
2017-12-02gpio: mockup: verify that ngpio > 0Bartosz Golaszewski
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>
2017-12-02gpio: mockup: fix debugfs handlingBartosz Golaszewski
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>
2017-12-02gpio: mockup: group code by logicBartosz Golaszewski
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>
2017-12-02gpio: mockup: change the type of value field in line state structBartosz Golaszewski
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>
2017-12-02gpio: mockup: extend the debugfs layoutBartosz Golaszewski
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>
2017-12-02gpio: mockup: pass the named_lines parameter over platform_dataBartosz Golaszewski
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>
2017-12-02gpio: mockup: merge gpio_mockup_add() into gpio_mockup_probe()Bartosz Golaszewski
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>
2017-12-02gpio: mockup: remove a stray tabBartosz Golaszewski
Minor coding style fix. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2017-12-02gpio: mockup: implement gpio_mockup_err()Bartosz Golaszewski
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>
2017-12-02gpio: mockup: rework device probingBartosz Golaszewski
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>
2017-12-02gpio: mockup: verify the number of GPIO chips requestedBartosz Golaszewski
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>
2017-12-02gpio: mockup: parse the module params in init, not probeBartosz Golaszewski
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>
2017-12-02gpio: mockup: add missing prefixesBartosz Golaszewski
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>
2017-08-31gpio: mockup: remove unused variable gcColin Ian King
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>
2017-08-21gpio: mockup: use irq_simBartosz Golaszewski
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>
2017-06-20gpio: mockup: use devm_kcalloc() where applicableBartosz Golaszewski
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>
2017-06-20gpio: mockup: add myself as authorBartosz Golaszewski
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>
2017-06-20gpio: mockup: improve the error messageBartosz Golaszewski
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>
2017-06-20gpio: mockup: don't return magic numbers from probe()Bartosz Golaszewski
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>
2017-06-20gpio: mockup: improve readabilityBartosz Golaszewski
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>
2017-06-20gpio: mockup: refuse to accept an odd number of GPIO rangesBartosz Golaszewski
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>
2017-06-20gpio: mockup: tweak gpio_mockup_event_write()Bartosz Golaszewski
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>
2017-06-20gpio: mockup: improve the debugfs input sanitizationBartosz Golaszewski
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>
2017-05-29gpio: mockup: support irqmask and irqunmaskBartosz Golaszewski
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>
2017-05-29gpio: mockup: be quiet unless something goes wrongBartosz Golaszewski
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>