summaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-max732x.c
Commit message (Collapse)AuthorAgeFilesLines
* gpio: simplify adding threaded interruptsLinus Walleij2016-11-251-9/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This tries to simplify the use of CONFIG_GPIOLIB_IRQCHIP when using threaded interrupts: add a new call gpiochip_irqchip_add_nested() to indicate that we're dealing with a nested rather than a chained irqchip, then create a separate gpiochip_set_nested_irqchip() to mirror the gpiochip_set_chained_irqchip() call to connect the parent and child interrupts. In the nested case gpiochip_set_nested_irqchip() does nothing more than call irq_set_parent() on each valid child interrupt, which has little semantic effect in the kernel, but this is probably still formally correct. Update all drivers using nested interrupts to use gpiochip_irqchip_add_nested() so we can now see clearly which these users are. The DLN2 driver can drop its specific hack with .irq_not_threaded as we now recognize whether a chip is threaded or not from its use of gpiochip_irqchip_add_nested() signature rather than from inspecting .can_sleep. We rename the .irq_parent to .irq_chained_parent since this parent IRQ is only really kept around for the chained interrupt handlers. Cc: Lars Poeschel <poeschel@lemonage.de> Cc: Octavian Purdila <octavian.purdila@intel.com> Cc: Daniel Baluta <daniel.baluta@intel.com> Cc: Bin Gao <bin.gao@linux.intel.com> Cc: Mika Westerberg <mika.westerberg@linux.intel.com> Cc: Ajay Thomas <ajay.thomas.david.rajamanickam@intel.com> Cc: Semen Protsenko <semen.protsenko@globallogic.com> Cc: Alexander Stein <alexander.stein@systec-electronic.com> Cc: Phil Reid <preid@electromag.com.au> Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com> Cc: Patrice Chotard <patrice.chotard@st.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: use gpiochip data pointerLinus Walleij2016-01-051-15/+10
| | | | | | | | | | | This makes the driver use the data pointer added to the gpio_chip to store a pointer to the state container instead of relying on container_of(). Cc: Nicholas Krause <xerofoify@gmail.com> Cc: Marek Vasut <marex@denx.de> Cc: Semen Protsenko <semen.protsenko@globallogic.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: Be sure to clamp return valueLinus Walleij2015-12-261-2/+2
| | | | | | | | | | | | | | | As we want gpio_chip .get() calls to be able to return negative error codes and propagate to drivers, we need to go over all drivers and make sure their return values are clamped to [0,1]. We do this by using the ret = !!(val) design pattern. Also start to propagate the error code here as the end of the series fixes this to work for all drivers. Cc: Semen Protsenko <semen.protsenko@globallogic.com> Reviewed-by: Marek Vasut <marex@denx.de> Reviewed-by:Nicholas Krause <xerofoify@gmail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: Drop owner assignment from i2c_driverKrzysztof Kozlowski2015-11-301-1/+0
| | | | | | | | i2c_driver does not need to set an owner because i2c_register_driver() will set it. Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: change member .dev to .parentLinus Walleij2015-11-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The name .dev in a struct is normally reserved for a struct device that is let us say a superclass to the thing described by the struct. struct gpio_chip stands out by confusingly using a struct device *dev to point to the parent device (such as a platform_device) that represents the hardware. As we want to give gpio_chip:s real devices, this is not working. We need to rename this member to parent. This was done by two coccinelle scripts, I guess it is possible to combine them into one, but I don't know such stuff. They look like this: @@ struct gpio_chip *var; @@ -var->dev +var->parent and: @@ struct gpio_chip var; @@ -var.dev +var.parent and: @@ struct bgpio_chip *var; @@ -var->gc.dev +var->gc.parent Plus a few instances of bgpio that I couldn't figure out how to teach Coccinelle to rewrite. This patch hits all over the place, but I *strongly* prefer this solution to any piecemal approaches that just exercise patch mechanics all over the place. It mainly hits drivers/gpio and drivers/pinctrl which is my own backyard anyway. Cc: Haavard Skinnemoen <hskinnemoen@gmail.com> Cc: Rafał Miłecki <zajec5@gmail.com> Cc: Richard Purdie <rpurdie@rpsys.net> Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com> Cc: Alek Du <alek.du@intel.com> Cc: Jaroslav Kysela <perex@perex.cz> Cc: Takashi Iwai <tiwai@suse.com> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Lee Jones <lee.jones@linaro.org> Acked-by: Jiri Kosina <jkosina@suse.cz> Acked-by: Hans-Christian Egtvedt <egtvedt@samfundet.no> Acked-by: Jacek Anaszewski <j.anaszewski@samsung.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: Fix error handling in probe()Nicholas Krause2015-08-261-3/+8
| | | | | | | | | This fixes error handling in the function max732x_probe by checking if the calls to the function max732x_readb fail by returning a error code. Signed-off-by: Nicholas Krause <xerofoify@gmail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: Add missing dev reference to gpiochipMarek Vasut2015-07-161-0/+1
| | | | | | | | | | | | | | | | | | | In case the gpiochip doesn't have the .dev field set, as is the case in here, it is not possible to reference this device in DT as a GPIO controller. A good example of this problem is that gpio-leds can not be used when connected to this chip, the gpio-leds driver bails out with -EPROBE_DEFER. Fix this problem by setting the .dev field of the gpio_chip to the parent i2c device. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Alexandre Courbot <gnurou@gmail.com> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Mans Rullgard <mans@mansr.com> Cc: Olaf Mandel <o.mandel@menlosystems.com> Cc: Semen Protsenko <semen.protsenko@globallogic.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: Fix irq-events handlerSemen Protsenko2015-05-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | MAX732X clears all pending interrupts on I2C read (when interrupts register is being read). Driver doesn't need to send any ACKs when interrupt was handled. So replace handle_edge_irq() with handle_simple_irq(). Using handle_edge_irq() (w/o .irq_ack callback set) may lead to NULL pointer dereference in some cases. E.g. this was observed on hibernation process: Unable to handle kernel NULL pointer dereference at virtual address 0 Backtrace: (handle_edge_irq) from (resend_irqs) (resend_irqs) from (tasklet_action) (tasklet_action) from (__do_softirq) (__do_softirq) from (run_ksoftirqd) (run_ksoftirqd) from (smpboot_thread_fn) (smpboot_thread_fn) from (kthread) (kthread) from (ret_from_fork) Signed-off-by: Semen Protsenko <semen.protsenko@globallogic.com> Reviewed-by: Grygorii Strashko <grygorii.strashko@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: Add IRQF_SHARED to irq flagsSemen Protsenko2015-05-061-6/+4
| | | | | | | | It's possible that multiple MAX732X can be hooked up to the same interrupt line with the processor. So add IRQF_SHARED in requesting irq. Signed-off-by: Semen Protsenko <semen.protsenko@globallogic.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: Propagate wake-up setting to parent irq controllerSemen Protsenko2015-05-041-0/+9
| | | | | | | | | | Set .irq_set_wake callback to prevent possible issues on wake-up. This patch was inspired by this commit: b80eef95beb04760629822fa130aeed54cdfafca Signed-off-by: Semen Protsenko <semen.protsenko@globallogic.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: convert to GPIOLIB_IRQCHIPLinus Walleij2015-03-021-92/+42
| | | | | | | | | | | | | Take a sweep to bring the irq support for the MAX732x expanders into the gpiolib core to cut down on duplicated code. Only compile tested! I need some feedback from people using this expander with interrupts to tell me if things go right or wrong when I do this. Cc: Semen Protsenko <semen.protsenko@globallogic.com> Cc: Mans Rullgard <mans@mansr.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: use an inline function for container castLinus Walleij2015-02-031-15/+10
| | | | | | | | | | Cast the struct gpio_chip into a max732x_chip using an inline macro and move the assignment to the variable declaration to save lines and simplify things. Cc: Semen Protsenko <semen.protsenko@globallogic.com> Acked-by: Mans Rullgard <mans@mansr.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: add set_multiple functionMans Rullgard2015-01-301-3/+25
| | | | | | | | This adds a set_multiple function to the MAX732x GPIO driver, allowing for performance gains when using gpiod_set_array(). Signed-off-by: Mans Rullgard <mans@mansr.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: Fix possible deadlockSemen Protsenko2015-01-151-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch was derived from next one: "gpio: fix pca953x set_type 'scheduling while atomic' bug". After adding entry that consumes max732x GPIO as interrupt line to dts file, deadlock appears somewhere in max732x probe function. Deadlock caught by lockdep (from kernel log): <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< cut here >>>>>>>>>>>>>>>>>>>>>>>>>>> [ 0.473419] ====================================================== [ 0.473419] [ INFO: HARDIRQ-safe -> HARDIRQ-unsafe lock order detected ] [ 0.473449] 3.x.xx-xxxxx-xxxxxxxx-dirty #2 Tainted: G W [ 0.473449] ------------------------------------------------------ [ 0.473449] swapper/0/1 [HC0[0]:SC0[0]:HE0:SE1] is trying to acquire: [ 0.473449] (&lock->wait_lock){+.+...}, at: [<c072e350>] rt_mutex_trylock+0xc/0x74 [ 0.473480] [ 0.473480] and this task is already holding: [ 0.473510] (&chip->lock){......}, at: [<c0314514>] max732x_gpio_set_value+0x2c/0xa4 [ 0.473541] which would create a new lock dependency: [ 0.473541] (&chip->lock){......} -> (&lock->wait_lock){+.+...} ... [ 0.474273] *** DEADLOCK *** [ 0.474273] [ 0.474273] 5 locks held by swapper/0/1: [ 0.474273] #0: (&__lockdep_no_validate__){......}, at: [<c03b2328>] __driver_attach+0x48/0x98 [ 0.474304] #1: (&__lockdep_no_validate__){......}, at: [<c03b2338>] __driver_attach+0x58/0x98 [ 0.474334] #2: (&chip->irq_lock){+.+...}, at: [<c0313e3c>] max732x_irq_bus_lock+0x14/0x20 [ 0.474365] #3: (&irq_desc_lock_class){-.....}, at: [<c00a65a4>] __irq_get_desc_lock+0x48/0x88 [ 0.474365] #4: (&chip->lock){......}, at: [<c0314514>] max732x_gpio <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< cut here >>>>>>>>>>>>>>>>>>>>>>>>>>> Signed-off-by: Semen Protsenko <semen.protsenko@globallogic.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: Rewrite IRQ code to use irq_domain APISemen Protsenko2015-01-151-35/+65
| | | | | Signed-off-by: Semen Protsenko <semen.protsenko@globallogic.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: Add device tree supportSemen Protsenko2015-01-151-11/+51
| | | | | Signed-off-by: Semen Protsenko <semen.protsenko@globallogic.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: remove all usage of gpio_remove retval in driver/gpioabdoulaye berthe2014-07-221-6/+1
| | | | | Signed-off-by: abdoulaye berthe <berthe.ab@gmail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: Fix possible NULL pointer dereference on i2c_new_dummy errorKrzysztof Kozlowski2014-03-121-0/+7
| | | | | | | | | | | | | In max732x_probe() driver allocates dummy I2C device (if number of ports is greater than 8) with i2c_new_dummy() but it does not check the return value of this call. In case of error (i2c_new_device(): memory allocation failure or I2C address cannot be used) this function returns NULL which is later dereferenced by i2c_smbus_read_byte() (called from max732x_readb()). Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: Fix I2C dummy device resource leak on probe failureKrzysztof Kozlowski2014-03-121-0/+2
| | | | | | | | | In max732x_probe() driver allocates dummy I2C device (if number of ports is greater than 8) however it is not unregistered if probe fails later. Fix the leak by unregistering dummy I2C device if it was allocated. Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio/pinctrl: make gpio_chip members typed booleanLinus Walleij2013-12-041-1/+1
| | | | | | | | | | | This switches the two members of struct gpio_chip that were defined as unsigned foo:1 to bool, because that is indeed what they are. Switch all users in the gpio and pinctrl subsystems to assign these values with true/false instead of 0/1. The users outside these subsystems will survive since true/false is 1/0, atleast we set some kind of more strict typing example. Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: use dev_get_platdata()Jingoo Han2013-08-161-4/+4
| | | | | | | | Use the wrapper function for retrieving the platform data instead of accessing dev->platform_data directly. Signed-off-by: Jingoo Han <jg1.han@samsung.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: max732x: use devm_kzalloc()Jingoo Han2013-03-271-3/+2
| | | | | | | Use devm_kzalloc() to make cleanup paths simpler. Signed-off-by: Jingoo Han <jg1.han@samsung.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
* gpio: remove use of __devexitBill Pemberton2012-11-281-1/+1
| | | | | | | | | | | | CONFIG_HOTPLUG is going away as an option so __devexit is no longer needed. Signed-off-by: Bill Pemberton <wfp5p@virginia.edu> Cc: Grant Likely <grant.likely@secretlab.ca> Acked-by: Linus Walleij <linus.walleij@linaro.org> Cc: Peter Tyser <ptyser@xes-inc.com> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* gpio: remove use of __devinitBill Pemberton2012-11-281-2/+2
| | | | | | | | | | | | | | CONFIG_HOTPLUG is going away as an option so __devinit is no longer needed. Signed-off-by: Bill Pemberton <wfp5p@virginia.edu> Cc: Grant Likely <grant.likely@secretlab.ca> Cc: Peter Tyser <ptyser@xes-inc.com> Cc: Santosh Shilimkar <santosh.shilimkar@ti.com> Cc: Kevin Hilman <khilman@ti.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* gpio: remove use of __devexit_pBill Pemberton2012-11-281-1/+1
| | | | | | | | | | | | CONFIG_HOTPLUG is going away as an option so __devexit_p is no longer needed. Signed-off-by: Bill Pemberton <wfp5p@virginia.edu> Cc: Grant Likely <grant.likely@secretlab.ca> Cc: Peter Tyser <ptyser@xes-inc.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* gpio: reorganize driversGrant Likely2011-06-061-0/+714
Sort the gpio makefile and enforce the naming convention gpio-*.c for gpio drivers. v2: cleaned up filenames in Kconfig and comment blocks v3: fixup use of BASIC_MMIO to GENERIC_GPIO for mxc Signed-off-by: Grant Likely <grant.likely@secretlab.ca>