gpio: Use an 'ops' variable everywhere

Update this driver to use the common method of putting the driver
operations in an 'ops' variable install of calling gpio_get_ops()
repeatedly. Make it const since operations do not change.

Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
This commit is contained in:
Simon Glass 2021-02-04 21:22:05 -07:00 committed by Tom Rini
parent ca1e1f57be
commit 3d64774716

View File

@ -220,7 +220,7 @@ int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
static int gpio_find_and_xlate(struct gpio_desc *desc, static int gpio_find_and_xlate(struct gpio_desc *desc,
struct ofnode_phandle_args *args) struct ofnode_phandle_args *args)
{ {
struct dm_gpio_ops *ops = gpio_get_ops(desc->dev); const struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
if (ops->xlate) if (ops->xlate)
return ops->xlate(desc->dev, desc, args); return ops->xlate(desc->dev, desc, args);
@ -353,6 +353,7 @@ int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc)
int dm_gpio_request(struct gpio_desc *desc, const char *label) int dm_gpio_request(struct gpio_desc *desc, const char *label)
{ {
const struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
struct udevice *dev = desc->dev; struct udevice *dev = desc->dev;
struct gpio_dev_priv *uc_priv; struct gpio_dev_priv *uc_priv;
char *str; char *str;
@ -364,8 +365,8 @@ int dm_gpio_request(struct gpio_desc *desc, const char *label)
str = strdup(label); str = strdup(label);
if (!str) if (!str)
return -ENOMEM; return -ENOMEM;
if (gpio_get_ops(dev)->request) { if (ops->request) {
ret = gpio_get_ops(dev)->request(dev, desc->offset, label); ret = ops->request(dev, desc->offset, label);
if (ret) { if (ret) {
free(str); free(str);
return ret; return ret;
@ -442,14 +443,15 @@ int gpio_requestf(unsigned gpio, const char *fmt, ...)
int _dm_gpio_free(struct udevice *dev, uint offset) int _dm_gpio_free(struct udevice *dev, uint offset)
{ {
const struct dm_gpio_ops *ops = gpio_get_ops(dev);
struct gpio_dev_priv *uc_priv; struct gpio_dev_priv *uc_priv;
int ret; int ret;
uc_priv = dev_get_uclass_priv(dev); uc_priv = dev_get_uclass_priv(dev);
if (!uc_priv->name[offset]) if (!uc_priv->name[offset])
return -ENXIO; return -ENXIO;
if (gpio_get_ops(dev)->rfree) { if (ops->rfree) {
ret = gpio_get_ops(dev)->rfree(dev, offset); ret = ops->rfree(dev, offset);
if (ret) if (ret)
return ret; return ret;
} }
@ -546,9 +548,10 @@ int gpio_direction_output(unsigned gpio, int value)
static int _gpio_get_value(const struct gpio_desc *desc) static int _gpio_get_value(const struct gpio_desc *desc)
{ {
const struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
int value; int value;
value = gpio_get_ops(desc->dev)->get_value(desc->dev, desc->offset); value = ops->get_value(desc->dev, desc->offset);
return desc->flags & GPIOD_ACTIVE_LOW ? !value : value; return desc->flags & GPIOD_ACTIVE_LOW ? !value : value;
} }
@ -644,7 +647,7 @@ static int check_dir_flags(ulong flags)
static int _dm_gpio_set_flags(struct gpio_desc *desc, ulong flags) static int _dm_gpio_set_flags(struct gpio_desc *desc, ulong flags)
{ {
struct udevice *dev = desc->dev; struct udevice *dev = desc->dev;
struct dm_gpio_ops *ops = gpio_get_ops(dev); const struct dm_gpio_ops *ops = gpio_get_ops(dev);
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
int ret = 0; int ret = 0;
@ -722,7 +725,7 @@ int dm_gpio_get_flags(struct gpio_desc *desc, ulong *flagsp)
{ {
struct udevice *dev = desc->dev; struct udevice *dev = desc->dev;
int ret, value; int ret, value;
struct dm_gpio_ops *ops = gpio_get_ops(dev); const struct dm_gpio_ops *ops = gpio_get_ops(dev);
ulong flags; ulong flags;
ret = check_reserved(desc, "get_flags"); ret = check_reserved(desc, "get_flags");
@ -820,7 +823,7 @@ static int get_function(struct udevice *dev, int offset, bool skip_unused,
const char **namep) const char **namep)
{ {
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct dm_gpio_ops *ops = gpio_get_ops(dev); const struct dm_gpio_ops *ops = gpio_get_ops(dev);
BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function)); BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function));
if (!device_active(dev)) if (!device_active(dev))
@ -857,7 +860,7 @@ int gpio_get_raw_function(struct udevice *dev, int offset, const char **namep)
int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize) int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize)
{ {
struct dm_gpio_ops *ops = gpio_get_ops(dev); const struct dm_gpio_ops *ops = gpio_get_ops(dev);
struct gpio_dev_priv *priv; struct gpio_dev_priv *priv;
char *str = buf; char *str = buf;
int func; int func;
@ -897,7 +900,7 @@ int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize)
#if CONFIG_IS_ENABLED(ACPIGEN) #if CONFIG_IS_ENABLED(ACPIGEN)
int gpio_get_acpi(const struct gpio_desc *desc, struct acpi_gpio *gpio) int gpio_get_acpi(const struct gpio_desc *desc, struct acpi_gpio *gpio)
{ {
struct dm_gpio_ops *ops; const struct dm_gpio_ops *ops;
memset(gpio, '\0', sizeof(*gpio)); memset(gpio, '\0', sizeof(*gpio));
if (!dm_gpio_is_valid(desc)) { if (!dm_gpio_is_valid(desc)) {