Commit 1752911c authored by Linus Walleij's avatar Linus Walleij

Merge tag 'gpio-updates-for-v5.9-part2' of...

Merge tag 'gpio-updates-for-v5.9-part2' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux into devel

gpio updates for v5.9 - part 2

- several improvements and minor tweaks to the GPIO character device code
parents a6175e89 df51f402
...@@ -64,6 +64,7 @@ static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset) ...@@ -64,6 +64,7 @@ static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset)
ret = pm_runtime_get_sync(chip->parent); ret = pm_runtime_get_sync(chip->parent);
if (ret < 0) { if (ret < 0) {
dev_err(chip->parent, "Failed to resume: %d\n", ret); dev_err(chip->parent, "Failed to resume: %d\n", ret);
pm_runtime_put_autosuspend(chip->parent);
return ret; return ret;
} }
...@@ -72,12 +73,15 @@ static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset) ...@@ -72,12 +73,15 @@ static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset)
if (ret < 0) { if (ret < 0) {
dev_err(chip->parent, "Failed to drop cache: %d\n", dev_err(chip->parent, "Failed to drop cache: %d\n",
ret); ret);
pm_runtime_put_autosuspend(chip->parent);
return ret; return ret;
} }
ret = regmap_read(arizona->regmap, reg, &val); ret = regmap_read(arizona->regmap, reg, &val);
if (ret < 0) if (ret < 0) {
pm_runtime_put_autosuspend(chip->parent);
return ret; return ret;
}
pm_runtime_mark_last_busy(chip->parent); pm_runtime_mark_last_busy(chip->parent);
pm_runtime_put_autosuspend(chip->parent); pm_runtime_put_autosuspend(chip->parent);
...@@ -106,6 +110,7 @@ static int arizona_gpio_direction_out(struct gpio_chip *chip, ...@@ -106,6 +110,7 @@ static int arizona_gpio_direction_out(struct gpio_chip *chip,
ret = pm_runtime_get_sync(chip->parent); ret = pm_runtime_get_sync(chip->parent);
if (ret < 0) { if (ret < 0) {
dev_err(chip->parent, "Failed to resume: %d\n", ret); dev_err(chip->parent, "Failed to resume: %d\n", ret);
pm_runtime_put(chip->parent);
return ret; return ret;
} }
} }
......
...@@ -108,6 +108,84 @@ static const struct i2c_device_id pca953x_id[] = { ...@@ -108,6 +108,84 @@ static const struct i2c_device_id pca953x_id[] = {
}; };
MODULE_DEVICE_TABLE(i2c, pca953x_id); MODULE_DEVICE_TABLE(i2c, pca953x_id);
#ifdef CONFIG_GPIO_PCA953X_IRQ
#include <linux/dmi.h>
#include <linux/gpio.h>
#include <linux/list.h>
static const struct dmi_system_id pca953x_dmi_acpi_irq_info[] = {
{
/*
* On Intel Galileo Gen 2 board the IRQ pin of one of
* the I²C GPIO expanders, which has GpioInt() resource,
* is provided as an absolute number instead of being
* relative. Since first controller (gpio-sch.c) and
* second (gpio-dwapb.c) are at the fixed bases, we may
* safely refer to the number in the global space to get
* an IRQ out of it.
*/
.matches = {
DMI_EXACT_MATCH(DMI_BOARD_NAME, "GalileoGen2"),
},
},
{}
};
#ifdef CONFIG_ACPI
static int pca953x_acpi_get_pin(struct acpi_resource *ares, void *data)
{
struct acpi_resource_gpio *agpio;
int *pin = data;
if (acpi_gpio_get_irq_resource(ares, &agpio))
*pin = agpio->pin_table[0];
return 1;
}
static int pca953x_acpi_find_pin(struct device *dev)
{
struct acpi_device *adev = ACPI_COMPANION(dev);
int pin = -ENOENT, ret;
LIST_HEAD(r);
ret = acpi_dev_get_resources(adev, &r, pca953x_acpi_get_pin, &pin);
acpi_dev_free_resource_list(&r);
if (ret < 0)
return ret;
return pin;
}
#else
static inline int pca953x_acpi_find_pin(struct device *dev) { return -ENXIO; }
#endif
static int pca953x_acpi_get_irq(struct device *dev)
{
int pin, ret;
pin = pca953x_acpi_find_pin(dev);
if (pin < 0)
return pin;
dev_info(dev, "Applying ACPI interrupt quirk (GPIO %d)\n", pin);
if (!gpio_is_valid(pin))
return -EINVAL;
ret = gpio_request(pin, "pca953x interrupt");
if (ret)
return ret;
ret = gpio_to_irq(pin);
/* When pin is used as an IRQ, no need to keep it requested */
gpio_free(pin);
return ret;
}
#endif
static const struct acpi_device_id pca953x_acpi_ids[] = { static const struct acpi_device_id pca953x_acpi_ids[] = {
{ "INT3491", 16 | PCA953X_TYPE | PCA_LATCH_INT, }, { "INT3491", 16 | PCA953X_TYPE | PCA_LATCH_INT, },
{ } { }
...@@ -323,6 +401,7 @@ static const struct regmap_config pca953x_ai_i2c_regmap = { ...@@ -323,6 +401,7 @@ static const struct regmap_config pca953x_ai_i2c_regmap = {
.writeable_reg = pca953x_writeable_register, .writeable_reg = pca953x_writeable_register,
.volatile_reg = pca953x_volatile_register, .volatile_reg = pca953x_volatile_register,
.disable_locking = true,
.cache_type = REGCACHE_RBTREE, .cache_type = REGCACHE_RBTREE,
.max_register = 0x7f, .max_register = 0x7f,
}; };
...@@ -624,8 +703,6 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d) ...@@ -624,8 +703,6 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
DECLARE_BITMAP(reg_direction, MAX_LINE); DECLARE_BITMAP(reg_direction, MAX_LINE);
int level; int level;
pca953x_read_regs(chip, chip->regs->direction, reg_direction);
if (chip->driver_data & PCA_PCAL) { if (chip->driver_data & PCA_PCAL) {
/* Enable latch on interrupt-enabled inputs */ /* Enable latch on interrupt-enabled inputs */
pca953x_write_regs(chip, PCAL953X_IN_LATCH, chip->irq_mask); pca953x_write_regs(chip, PCAL953X_IN_LATCH, chip->irq_mask);
...@@ -636,7 +713,11 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d) ...@@ -636,7 +713,11 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
pca953x_write_regs(chip, PCAL953X_INT_MASK, irq_mask); pca953x_write_regs(chip, PCAL953X_INT_MASK, irq_mask);
} }
/* Switch direction to input if needed */
pca953x_read_regs(chip, chip->regs->direction, reg_direction);
bitmap_or(irq_mask, chip->irq_trig_fall, chip->irq_trig_raise, gc->ngpio); bitmap_or(irq_mask, chip->irq_trig_fall, chip->irq_trig_raise, gc->ngpio);
bitmap_complement(reg_direction, reg_direction, gc->ngpio);
bitmap_and(irq_mask, irq_mask, reg_direction, gc->ngpio); bitmap_and(irq_mask, irq_mask, reg_direction, gc->ngpio);
/* Look for any newly setup interrupt */ /* Look for any newly setup interrupt */
...@@ -735,14 +816,16 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid) ...@@ -735,14 +816,16 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
struct gpio_chip *gc = &chip->gpio_chip; struct gpio_chip *gc = &chip->gpio_chip;
DECLARE_BITMAP(pending, MAX_LINE); DECLARE_BITMAP(pending, MAX_LINE);
int level; int level;
bool ret;
if (!pca953x_irq_pending(chip, pending)) mutex_lock(&chip->i2c_lock);
return IRQ_NONE; ret = pca953x_irq_pending(chip, pending);
mutex_unlock(&chip->i2c_lock);
for_each_set_bit(level, pending, gc->ngpio) for_each_set_bit(level, pending, gc->ngpio)
handle_nested_irq(irq_find_mapping(gc->irq.domain, level)); handle_nested_irq(irq_find_mapping(gc->irq.domain, level));
return IRQ_HANDLED; return IRQ_RETVAL(ret);
} }
static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base) static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base)
...@@ -753,6 +836,12 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base) ...@@ -753,6 +836,12 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base)
DECLARE_BITMAP(irq_stat, MAX_LINE); DECLARE_BITMAP(irq_stat, MAX_LINE);
int ret; int ret;
if (dmi_first_match(pca953x_dmi_acpi_irq_info)) {
ret = pca953x_acpi_get_irq(&client->dev);
if (ret > 0)
client->irq = ret;
}
if (!client->irq) if (!client->irq)
return 0; return 0;
......
This diff is collapsed.
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <linux/ctype.h> #include <linux/ctype.h>
#include "gpiolib.h" #include "gpiolib.h"
#include "gpiolib-sysfs.h"
#define GPIO_IRQF_TRIGGER_FALLING BIT(0) #define GPIO_IRQF_TRIGGER_FALLING BIT(0)
#define GPIO_IRQF_TRIGGER_RISING BIT(1) #define GPIO_IRQF_TRIGGER_RISING BIT(1)
......
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef GPIOLIB_SYSFS_H
#define GPIOLIB_SYSFS_H
#ifdef CONFIG_GPIO_SYSFS
int gpiochip_sysfs_register(struct gpio_device *gdev);
void gpiochip_sysfs_unregister(struct gpio_device *gdev);
#else
static inline int gpiochip_sysfs_register(struct gpio_device *gdev)
{
return 0;
}
static inline void gpiochip_sysfs_unregister(struct gpio_device *gdev)
{
}
#endif /* CONFIG_GPIO_SYSFS */
#endif /* GPIOLIB_SYSFS_H */
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "gpiolib-of.h" #include "gpiolib-of.h"
#include "gpiolib-acpi.h" #include "gpiolib-acpi.h"
#include "gpiolib-cdev.h" #include "gpiolib-cdev.h"
#include "gpiolib-sysfs.h"
#define CREATE_TRACE_POINTS #define CREATE_TRACE_POINTS
#include <trace/events/gpio.h> #include <trace/events/gpio.h>
...@@ -614,7 +615,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, ...@@ -614,7 +615,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
spin_unlock_irqrestore(&gpio_lock, flags); spin_unlock_irqrestore(&gpio_lock, flags);
ATOMIC_INIT_NOTIFIER_HEAD(&gdev->notifier); BLOCKING_INIT_NOTIFIER_HEAD(&gdev->notifier);
#ifdef CONFIG_PINCTRL #ifdef CONFIG_PINCTRL
INIT_LIST_HEAD(&gdev->pin_ranges); INIT_LIST_HEAD(&gdev->pin_ranges);
...@@ -2048,8 +2049,8 @@ static bool gpiod_free_commit(struct gpio_desc *desc) ...@@ -2048,8 +2049,8 @@ static bool gpiod_free_commit(struct gpio_desc *desc)
} }
spin_unlock_irqrestore(&gpio_lock, flags); spin_unlock_irqrestore(&gpio_lock, flags);
atomic_notifier_call_chain(&desc->gdev->notifier, blocking_notifier_call_chain(&desc->gdev->notifier,
GPIOLINE_CHANGED_RELEASED, desc); GPIOLINE_CHANGED_RELEASED, desc);
return ret; return ret;
} }
...@@ -3926,8 +3927,8 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev, ...@@ -3926,8 +3927,8 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
return ERR_PTR(ret); return ERR_PTR(ret);
} }
atomic_notifier_call_chain(&desc->gdev->notifier, blocking_notifier_call_chain(&desc->gdev->notifier,
GPIOLINE_CHANGED_REQUESTED, desc); GPIOLINE_CHANGED_REQUESTED, desc);
return desc; return desc;
} }
...@@ -3994,8 +3995,8 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, ...@@ -3994,8 +3995,8 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
return ERR_PTR(ret); return ERR_PTR(ret);
} }
atomic_notifier_call_chain(&desc->gdev->notifier, blocking_notifier_call_chain(&desc->gdev->notifier,
GPIOLINE_CHANGED_REQUESTED, desc); GPIOLINE_CHANGED_REQUESTED, desc);
return desc; return desc;
} }
......
...@@ -56,7 +56,7 @@ struct gpio_device { ...@@ -56,7 +56,7 @@ struct gpio_device {
const char *label; const char *label;
void *data; void *data;
struct list_head list; struct list_head list;
struct atomic_notifier_head notifier; struct blocking_notifier_head notifier;
#ifdef CONFIG_PINCTRL #ifdef CONFIG_PINCTRL
/* /*
...@@ -175,22 +175,4 @@ static inline int gpio_chip_hwgpio(const struct gpio_desc *desc) ...@@ -175,22 +175,4 @@ static inline int gpio_chip_hwgpio(const struct gpio_desc *desc)
#define chip_dbg(gc, fmt, ...) \ #define chip_dbg(gc, fmt, ...) \
dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__)
#ifdef CONFIG_GPIO_SYSFS
int gpiochip_sysfs_register(struct gpio_device *gdev);
void gpiochip_sysfs_unregister(struct gpio_device *gdev);
#else
static inline int gpiochip_sysfs_register(struct gpio_device *gdev)
{
return 0;
}
static inline void gpiochip_sysfs_unregister(struct gpio_device *gdev)
{
}
#endif /* CONFIG_GPIO_SYSFS */
#endif /* GPIOLIB_H */ #endif /* GPIOLIB_H */
...@@ -71,8 +71,8 @@ enum { ...@@ -71,8 +71,8 @@ enum {
* of a GPIO line * of a GPIO line
* @info: updated line information * @info: updated line information
* @timestamp: estimate of time of status change occurrence, in nanoseconds * @timestamp: estimate of time of status change occurrence, in nanoseconds
* and GPIOLINE_CHANGED_CONFIG
* @event_type: one of GPIOLINE_CHANGED_REQUESTED, GPIOLINE_CHANGED_RELEASED * @event_type: one of GPIOLINE_CHANGED_REQUESTED, GPIOLINE_CHANGED_RELEASED
* and GPIOLINE_CHANGED_CONFIG
* *
* Note: struct gpioline_info embedded here has 32-bit alignment on its own, * Note: struct gpioline_info embedded here has 32-bit alignment on its own,
* but it works fine with 64-bit alignment too. With its 72 byte size, we can * but it works fine with 64-bit alignment too. With its 72 byte size, we can
......
...@@ -45,7 +45,7 @@ int monitor_device(const char *device_name, ...@@ -45,7 +45,7 @@ int monitor_device(const char *device_name,
if (fd == -1) { if (fd == -1) {
ret = -errno; ret = -errno;
fprintf(stderr, "Failed to open %s\n", chrdev_name); fprintf(stderr, "Failed to open %s\n", chrdev_name);
goto exit_close_error; goto exit_free_name;
} }
req.lineoffset = line; req.lineoffset = line;
...@@ -117,6 +117,7 @@ int monitor_device(const char *device_name, ...@@ -117,6 +117,7 @@ int monitor_device(const char *device_name,
exit_close_error: exit_close_error:
if (close(fd) == -1) if (close(fd) == -1)
perror("Failed to close GPIO character device file"); perror("Failed to close GPIO character device file");
exit_free_name:
free(chrdev_name); free(chrdev_name);
return ret; return ret;
} }
......
...@@ -75,7 +75,7 @@ int gpiotools_request_linehandle(const char *device_name, unsigned int *lines, ...@@ -75,7 +75,7 @@ int gpiotools_request_linehandle(const char *device_name, unsigned int *lines,
ret = -errno; ret = -errno;
fprintf(stderr, "Failed to open %s, %s\n", fprintf(stderr, "Failed to open %s, %s\n",
chrdev_name, strerror(errno)); chrdev_name, strerror(errno));
goto exit_close_error; goto exit_free_name;
} }
for (i = 0; i < nlines; i++) for (i = 0; i < nlines; i++)
...@@ -94,9 +94,9 @@ int gpiotools_request_linehandle(const char *device_name, unsigned int *lines, ...@@ -94,9 +94,9 @@ int gpiotools_request_linehandle(const char *device_name, unsigned int *lines,
"GPIO_GET_LINEHANDLE_IOCTL", ret, strerror(errno)); "GPIO_GET_LINEHANDLE_IOCTL", ret, strerror(errno));
} }
exit_close_error:
if (close(fd) == -1) if (close(fd) == -1)
perror("Failed to close GPIO character device file"); perror("Failed to close GPIO character device file");
exit_free_name:
free(chrdev_name); free(chrdev_name);
return ret < 0 ? ret : req.fd; return ret < 0 ? ret : req.fd;
} }
......
...@@ -94,7 +94,7 @@ int list_device(const char *device_name) ...@@ -94,7 +94,7 @@ int list_device(const char *device_name)
if (fd == -1) { if (fd == -1) {
ret = -errno; ret = -errno;
fprintf(stderr, "Failed to open %s\n", chrdev_name); fprintf(stderr, "Failed to open %s\n", chrdev_name);
goto exit_close_error; goto exit_free_name;
} }
/* Inspect this GPIO chip */ /* Inspect this GPIO chip */
...@@ -141,6 +141,7 @@ int list_device(const char *device_name) ...@@ -141,6 +141,7 @@ int list_device(const char *device_name)
exit_close_error: exit_close_error:
if (close(fd) == -1) if (close(fd) == -1)
perror("Failed to close GPIO character device file"); perror("Failed to close GPIO character device file");
exit_free_name:
free(chrdev_name); free(chrdev_name);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment