mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-25 19:05:18 +07:00
8148c17b17
Core changes: - The gpiolib MMIO driver has been enhanced to handle two direction registers, i.e. one register to set lines as input and one register to set lines as output. It turns out some silicon engineer thinks the ability to configure a line as input and output at the same time makes sense, this can be debated but includes a lot of analog electronics reasoning, and the registers are there and need to be handled consistently. Unsurprisingly, we enforce the lines to be either inputs or outputs in such schemes. - Send in the proper argument value to .set_config() dispatched to the pin control subsystem. Nobody used it before, now someone does, so fix it to work as expected. - The ACPI gpiolib portions can now handle pin bias setting (pull up or pull down). This has been in the ACPI spec for years and we finally have it properly integrated with Linux GPIOs. It was based on an observation from Andy Schevchenko that Thomas Petazzoni's changes to the core for biasing the PCA950x GPIO expander actually happen to fit hand-in-glove with what the ACPI core needed. Such nice synergies happen sometimes. New drivers: - A new driver for the Mellanox BlueField GPIO controller. This is using 64bit MMIO registers and can configure lines as inputs and outputs at the same time and after improving the MMIO library we handle it just fine. Interesting. - A new IXP4xx proper gpiochip driver with hierarchical interrupts should be coming in from the ARM SoC tree as well. Driver enhancements: - The PCA053x driver handles the CAT9554 GPIO expander. - The PCA053x driver handles the NXP PCAL6416 GPIO expander. - Wake-up support on PCA053x GPIO lines. - OMAP now does a nice asynchronous IRQ handling on wake-ups by letting everything wake up on edges, and this makes runtime PM work as expected too. Misc: - Several cleanups such as devres fixes. - Get rid of some languager comstructs that cause problems when compiling with LLVMs clang. - Documentation review and update. -----BEGIN PGP SIGNATURE----- iQIcBAABAgAGBQJc1olZAAoJEEEQszewGV1zEU4P/RmTf3hG8xmNPS3MDTmR6gAy /YJOXjXBf3CD/dmEAyyaNLnUQismrtRNvHSoEGbno7gkU+htzp9UfUJkj6+HIXs2 RpF+Hi78HzZNDxGWuBLu6OZolpmBtx+sRKOhHk/XfNS45qd1FgXWDuulzsYa9Xsr hYMXdtdv9wY/vcc68q1rtKAbzlu5ZNCa3Zj1iNOr/XQt3Nl2BW66hGLgjK4mOvgx fJy4rFXuDIMfDvo69U1Opz2b39sfE7XMhfZS/MOgg4yEV9zGRgDoI1tyMcTqGb8Q 8LQbp5dXkP+3dJQB8tgbu3Vk4WC1Rd/pmIli5sMgsk0HYQ6XegfT6HJKozSmwN9r 0s8jKlrocWZvdPo1aJwQgtRS56t2rFWcrcRye8bLqxkkW5cYIq9CwkE8USwB31Kv PFpoOwRuCtj0gkCxf7WIEcC5NAkYPow3K1KPdk3E0Si6I3pj0NqqlaAD0JAlkC2V aPq3xbTuFCAdmcADEt2Z+dUJ7WIs5Y9oQgosMAx+A2AD4K3QDBMu3pZsT6SCu4XZ mK0eWJi9/CvOj/s7bA0BEJVxQA+p8KYsNRBOULg/8aAOqGcLnSydQjqrxDTE8YrL xmmRG7i7ht0B9CchZuIB5hqdvjbCgvcVa5OnCUDfLxE0GdCx8iJ9y9OrsMXbabYq 8FcPDo1N38cTYLnLqvKI =rhto -----END PGP SIGNATURE----- Merge tag 'gpio-v5.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio Pull gpio updates from Linus Walleij: "This is the bulk of the GPIO changes for the v5.2 kernel cycle. A bit later than usual because I was ironing out my own mistakes. I'm holding some stuff back for the next kernel as a result, and this should be a healthy and well tested batch. Core changes: - The gpiolib MMIO driver has been enhanced to handle two direction registers, i.e. one register to set lines as input and one register to set lines as output. It turns out some silicon engineer thinks the ability to configure a line as input and output at the same time makes sense, this can be debated but includes a lot of analog electronics reasoning, and the registers are there and need to be handled consistently. Unsurprisingly, we enforce the lines to be either inputs or outputs in such schemes. - Send in the proper argument value to .set_config() dispatched to the pin control subsystem. Nobody used it before, now someone does, so fix it to work as expected. - The ACPI gpiolib portions can now handle pin bias setting (pull up or pull down). This has been in the ACPI spec for years and we finally have it properly integrated with Linux GPIOs. It was based on an observation from Andy Schevchenko that Thomas Petazzoni's changes to the core for biasing the PCA950x GPIO expander actually happen to fit hand-in-glove with what the ACPI core needed. Such nice synergies happen sometimes. New drivers: - A new driver for the Mellanox BlueField GPIO controller. This is using 64bit MMIO registers and can configure lines as inputs and outputs at the same time and after improving the MMIO library we handle it just fine. Interesting. - A new IXP4xx proper gpiochip driver with hierarchical interrupts should be coming in from the ARM SoC tree as well. Driver enhancements: - The PCA053x driver handles the CAT9554 GPIO expander. - The PCA053x driver handles the NXP PCAL6416 GPIO expander. - Wake-up support on PCA053x GPIO lines. - OMAP now does a nice asynchronous IRQ handling on wake-ups by letting everything wake up on edges, and this makes runtime PM work as expected too. Misc: - Several cleanups such as devres fixes. - Get rid of some languager comstructs that cause problems when compiling with LLVMs clang. - Documentation review and update" * tag 'gpio-v5.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (85 commits) gpio: Update documentation docs: gpio: convert docs to ReST and rename to *.rst gpio: sch: Remove write-only core_base gpio: pxa: Make two symbols static gpiolib: acpi: Respect pin bias setting gpiolib: acpi: Add acpi_gpio_update_gpiod_lookup_flags() helper gpiolib: acpi: Set pin value, based on bias, more accurately gpiolib: acpi: Change type of dflags gpiolib: Introduce GPIO_LOOKUP_FLAGS_DEFAULT gpiolib: Make use of enum gpio_lookup_flags consistent gpiolib: Indent entry values of enum gpio_lookup_flags gpio: pca953x: add support for pca6416 dt-bindings: gpio: pca953x: document the nxp,pca6416 gpio: pca953x: add pcal6416 to the of_device_id table gpio: gpio-omap: Remove conditional pm_runtime handling for GPIO interrupts gpio: gpio-omap: configure edge detection for level IRQs for idle wakeup tracing: stop making gpio tracing configurable gpio: pca953x: Configure wake-up path when wake-up is enabled gpio: of: Optimize quirk checks gpio: mmio: Drop bgpio_dir_inverted ...
310 lines
9.8 KiB
C
310 lines
9.8 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* Internal GPIO functions.
|
|
*
|
|
* Copyright (C) 2013, Intel Corporation
|
|
* Author: Mika Westerberg <mika.westerberg@linux.intel.com>
|
|
*/
|
|
|
|
#ifndef GPIOLIB_H
|
|
#define GPIOLIB_H
|
|
|
|
#include <linux/gpio/driver.h>
|
|
#include <linux/gpio/consumer.h> /* for enum gpiod_flags */
|
|
#include <linux/err.h>
|
|
#include <linux/device.h>
|
|
#include <linux/module.h>
|
|
#include <linux/cdev.h>
|
|
|
|
enum of_gpio_flags;
|
|
struct acpi_device;
|
|
|
|
/**
|
|
* struct gpio_device - internal state container for GPIO devices
|
|
* @id: numerical ID number for the GPIO chip
|
|
* @dev: the GPIO device struct
|
|
* @chrdev: character device for the GPIO device
|
|
* @mockdev: class device used by the deprecated sysfs interface (may be
|
|
* NULL)
|
|
* @owner: helps prevent removal of modules exporting active GPIOs
|
|
* @chip: pointer to the corresponding gpiochip, holding static
|
|
* data for this device
|
|
* @descs: array of ngpio descriptors.
|
|
* @ngpio: the number of GPIO lines on this GPIO device, equal to the size
|
|
* of the @descs array.
|
|
* @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned
|
|
* at device creation time.
|
|
* @label: a descriptive name for the GPIO device, such as the part number
|
|
* or name of the IP component in a System on Chip.
|
|
* @data: per-instance data assigned by the driver
|
|
* @list: links gpio_device:s together for traversal
|
|
*
|
|
* This state container holds most of the runtime variable data
|
|
* for a GPIO device and can hold references and live on after the
|
|
* GPIO chip has been removed, if it is still being used from
|
|
* userspace.
|
|
*/
|
|
struct gpio_device {
|
|
int id;
|
|
struct device dev;
|
|
struct cdev chrdev;
|
|
struct device *mockdev;
|
|
struct module *owner;
|
|
struct gpio_chip *chip;
|
|
struct gpio_desc *descs;
|
|
int base;
|
|
u16 ngpio;
|
|
const char *label;
|
|
void *data;
|
|
struct list_head list;
|
|
|
|
#ifdef CONFIG_PINCTRL
|
|
/*
|
|
* If CONFIG_PINCTRL is enabled, then gpio controllers can optionally
|
|
* describe the actual pin range which they serve in an SoC. This
|
|
* information would be used by pinctrl subsystem to configure
|
|
* corresponding pins for gpio usage.
|
|
*/
|
|
struct list_head pin_ranges;
|
|
#endif
|
|
};
|
|
|
|
/**
|
|
* struct acpi_gpio_info - ACPI GPIO specific information
|
|
* @adev: reference to ACPI device which consumes GPIO resource
|
|
* @flags: GPIO initialization flags
|
|
* @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
|
|
* @pin_config: pin bias as provided by ACPI
|
|
* @polarity: interrupt polarity as provided by ACPI
|
|
* @triggering: triggering type as provided by ACPI
|
|
* @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping
|
|
*/
|
|
struct acpi_gpio_info {
|
|
struct acpi_device *adev;
|
|
enum gpiod_flags flags;
|
|
bool gpioint;
|
|
int pin_config;
|
|
int polarity;
|
|
int triggering;
|
|
unsigned int quirks;
|
|
};
|
|
|
|
/* gpio suffixes used for ACPI and device tree lookup */
|
|
static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" };
|
|
|
|
#ifdef CONFIG_OF_GPIO
|
|
struct gpio_desc *of_find_gpio(struct device *dev,
|
|
const char *con_id,
|
|
unsigned int idx,
|
|
unsigned long *lookupflags);
|
|
struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
|
|
const char *list_name, int index, enum of_gpio_flags *flags);
|
|
int of_gpiochip_add(struct gpio_chip *gc);
|
|
void of_gpiochip_remove(struct gpio_chip *gc);
|
|
#else
|
|
static inline struct gpio_desc *of_find_gpio(struct device *dev,
|
|
const char *con_id,
|
|
unsigned int idx,
|
|
unsigned long *lookupflags)
|
|
{
|
|
return ERR_PTR(-ENOENT);
|
|
}
|
|
static inline struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
|
|
const char *list_name, int index, enum of_gpio_flags *flags)
|
|
{
|
|
return ERR_PTR(-ENOENT);
|
|
}
|
|
static inline int of_gpiochip_add(struct gpio_chip *gc) { return 0; }
|
|
static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
|
|
#endif /* CONFIG_OF_GPIO */
|
|
|
|
#ifdef CONFIG_ACPI
|
|
void acpi_gpiochip_add(struct gpio_chip *chip);
|
|
void acpi_gpiochip_remove(struct gpio_chip *chip);
|
|
|
|
void acpi_gpiochip_request_interrupts(struct gpio_chip *chip);
|
|
void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
|
|
|
|
int acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags,
|
|
struct acpi_gpio_info *info);
|
|
int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
|
|
struct acpi_gpio_info *info);
|
|
|
|
struct gpio_desc *acpi_find_gpio(struct device *dev,
|
|
const char *con_id,
|
|
unsigned int idx,
|
|
enum gpiod_flags *dflags,
|
|
unsigned long *lookupflags);
|
|
struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
|
|
const char *propname, int index,
|
|
struct acpi_gpio_info *info);
|
|
|
|
int acpi_gpio_count(struct device *dev, const char *con_id);
|
|
|
|
bool acpi_can_fallback_to_crs(struct acpi_device *adev, const char *con_id);
|
|
#else
|
|
static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
|
|
static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
|
|
|
|
static inline void
|
|
acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { }
|
|
|
|
static inline void
|
|
acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { }
|
|
|
|
static inline int
|
|
acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, struct acpi_gpio_info *info)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline int
|
|
acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
|
|
struct acpi_gpio_info *info)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline struct gpio_desc *
|
|
acpi_find_gpio(struct device *dev, const char *con_id,
|
|
unsigned int idx, enum gpiod_flags *dflags,
|
|
unsigned long *lookupflags)
|
|
{
|
|
return ERR_PTR(-ENOENT);
|
|
}
|
|
static inline struct gpio_desc *
|
|
acpi_node_get_gpiod(struct fwnode_handle *fwnode, const char *propname,
|
|
int index, struct acpi_gpio_info *info)
|
|
{
|
|
return ERR_PTR(-ENXIO);
|
|
}
|
|
static inline int acpi_gpio_count(struct device *dev, const char *con_id)
|
|
{
|
|
return -ENODEV;
|
|
}
|
|
|
|
static inline bool acpi_can_fallback_to_crs(struct acpi_device *adev,
|
|
const char *con_id)
|
|
{
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
struct gpio_array {
|
|
struct gpio_desc **desc;
|
|
unsigned int size;
|
|
struct gpio_chip *chip;
|
|
unsigned long *get_mask;
|
|
unsigned long *set_mask;
|
|
unsigned long invert_mask[];
|
|
};
|
|
|
|
struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, u16 hwnum);
|
|
int gpiod_get_array_value_complex(bool raw, bool can_sleep,
|
|
unsigned int array_size,
|
|
struct gpio_desc **desc_array,
|
|
struct gpio_array *array_info,
|
|
unsigned long *value_bitmap);
|
|
int gpiod_set_array_value_complex(bool raw, bool can_sleep,
|
|
unsigned int array_size,
|
|
struct gpio_desc **desc_array,
|
|
struct gpio_array *array_info,
|
|
unsigned long *value_bitmap);
|
|
|
|
extern struct spinlock gpio_lock;
|
|
extern struct list_head gpio_devices;
|
|
|
|
struct gpio_desc {
|
|
struct gpio_device *gdev;
|
|
unsigned long flags;
|
|
/* flag symbols are bit numbers */
|
|
#define FLAG_REQUESTED 0
|
|
#define FLAG_IS_OUT 1
|
|
#define FLAG_EXPORT 2 /* protected by sysfs_lock */
|
|
#define FLAG_SYSFS 3 /* exported via /sys/class/gpio/control */
|
|
#define FLAG_ACTIVE_LOW 6 /* value has active low */
|
|
#define FLAG_OPEN_DRAIN 7 /* Gpio is open drain type */
|
|
#define FLAG_OPEN_SOURCE 8 /* Gpio is open source type */
|
|
#define FLAG_USED_AS_IRQ 9 /* GPIO is connected to an IRQ */
|
|
#define FLAG_IRQ_IS_ENABLED 10 /* GPIO is connected to an enabled IRQ */
|
|
#define FLAG_IS_HOGGED 11 /* GPIO is hogged */
|
|
#define FLAG_TRANSITORY 12 /* GPIO may lose value in sleep or reset */
|
|
#define FLAG_PULL_UP 13 /* GPIO has pull up enabled */
|
|
#define FLAG_PULL_DOWN 14 /* GPIO has pull down enabled */
|
|
|
|
/* Connection label */
|
|
const char *label;
|
|
/* Name of the GPIO */
|
|
const char *name;
|
|
};
|
|
|
|
int gpiod_request(struct gpio_desc *desc, const char *label);
|
|
void gpiod_free(struct gpio_desc *desc);
|
|
int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
|
|
unsigned long lflags, enum gpiod_flags dflags);
|
|
int gpiod_hog(struct gpio_desc *desc, const char *name,
|
|
unsigned long lflags, enum gpiod_flags dflags);
|
|
|
|
/*
|
|
* Return the GPIO number of the passed descriptor relative to its chip
|
|
*/
|
|
static inline int gpio_chip_hwgpio(const struct gpio_desc *desc)
|
|
{
|
|
return desc - &desc->gdev->descs[0];
|
|
}
|
|
|
|
/* With descriptor prefix */
|
|
|
|
#define gpiod_emerg(desc, fmt, ...) \
|
|
pr_emerg("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\
|
|
##__VA_ARGS__)
|
|
#define gpiod_crit(desc, fmt, ...) \
|
|
pr_crit("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
|
|
##__VA_ARGS__)
|
|
#define gpiod_err(desc, fmt, ...) \
|
|
pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
|
|
##__VA_ARGS__)
|
|
#define gpiod_warn(desc, fmt, ...) \
|
|
pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
|
|
##__VA_ARGS__)
|
|
#define gpiod_info(desc, fmt, ...) \
|
|
pr_info("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
|
|
##__VA_ARGS__)
|
|
#define gpiod_dbg(desc, fmt, ...) \
|
|
pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\
|
|
##__VA_ARGS__)
|
|
|
|
/* With chip prefix */
|
|
|
|
#define chip_emerg(chip, fmt, ...) \
|
|
dev_emerg(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__)
|
|
#define chip_crit(chip, fmt, ...) \
|
|
dev_crit(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__)
|
|
#define chip_err(chip, fmt, ...) \
|
|
dev_err(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__)
|
|
#define chip_warn(chip, fmt, ...) \
|
|
dev_warn(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__)
|
|
#define chip_info(chip, fmt, ...) \
|
|
dev_info(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__)
|
|
#define chip_dbg(chip, fmt, ...) \
|
|
dev_dbg(&chip->gpiodev->dev, "(%s): " fmt, chip->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 */
|