Commit b311c5cb authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Bartosz Golaszewski

gpiolib: of: consolidate simple renames into a single quirk

This consolidates all quirks doing simple renames (either allowing
suffix-less names or trivial renames, when index changes are not
required) into a single quirk.
Reviewed-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
parent 326c3753
...@@ -365,127 +365,90 @@ struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node, ...@@ -365,127 +365,90 @@ struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
} }
EXPORT_SYMBOL_GPL(gpiod_get_from_of_node); EXPORT_SYMBOL_GPL(gpiod_get_from_of_node);
/* static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
* The SPI GPIO bindings happened before we managed to establish that GPIO
* properties should be named "foo-gpios" so we have this special kludge for
* them.
*/
static struct gpio_desc *of_find_spi_gpio(struct device_node *np,
const char *con_id, const char *con_id,
unsigned int idx, unsigned int idx,
enum of_gpio_flags *of_flags) enum of_gpio_flags *of_flags)
{ {
char prop_name[32]; /* 32 is max size of property name */ static const struct of_rename_gpio {
const char *con_id;
const char *legacy_id; /* NULL - same as con_id */
/* /*
* Hopefully the compiler stubs the rest of the function if this * Compatible string can be set to NULL in case where
* is false. * matching to a particular compatible is not practical,
* but it should only be done for gpio names that have
* vendor prefix to reduce risk of false positives.
* Addition of such entries is strongly discouraged.
*/ */
if (!IS_ENABLED(CONFIG_SPI_MASTER)) const char *compatible;
return ERR_PTR(-ENOENT); } gpios[] = {
#if IS_ENABLED(CONFIG_MFD_ARIZONA)
/* Allow this specifically for "spi-gpio" devices */ { "wlf,reset", NULL, NULL },
if (!of_device_is_compatible(np, "spi-gpio") || !con_id) #endif
return ERR_PTR(-ENOENT); #if IS_ENABLED(CONFIG_REGULATOR)
/*
/* Will be "gpio-sck", "gpio-mosi" or "gpio-miso" */ * Some regulator bindings happened before we managed to
snprintf(prop_name, sizeof(prop_name), "%s-%s", "gpio", con_id); * establish that GPIO properties should be named
* "foo-gpios" so we have this special kludge for them.
return of_get_named_gpiod_flags(np, prop_name, idx, of_flags);
}
/*
* The old Freescale bindings use simply "gpios" as name for the chip select
* lines rather than "cs-gpios" like all other SPI hardware. Account for this
* with a special quirk.
*/ */
static struct gpio_desc *of_find_spi_cs_gpio(struct device_node *np, { "wlf,ldoena", NULL, NULL }, /* Arizona */
const char *con_id, { "wlf,ldo1ena", NULL, NULL }, /* WM8994 */
unsigned int idx, { "wlf,ldo2ena", NULL, NULL }, /* WM8994 */
enum of_gpio_flags *of_flags) #endif
{ #if IS_ENABLED(CONFIG_SPI_MASTER)
if (!IS_ENABLED(CONFIG_SPI_MASTER))
return ERR_PTR(-ENOENT);
/* Allow this specifically for Freescale and PPC devices */
if (!of_device_is_compatible(np, "fsl,spi") &&
!of_device_is_compatible(np, "aeroflexgaisler,spictrl") &&
!of_device_is_compatible(np, "ibm,ppc4xx-spi"))
return ERR_PTR(-ENOENT);
/* Allow only if asking for "cs-gpios" */
if (!con_id || strcmp(con_id, "cs"))
return ERR_PTR(-ENOENT);
/* /*
* While all other SPI controllers use "cs-gpios" the Freescale * The SPI GPIO bindings happened before we managed to
* uses just "gpios" so translate to that when "cs-gpios" is * establish that GPIO properties should be named
* requested. * "foo-gpios" so we have this special kludge for them.
*/ */
return of_get_named_gpiod_flags(np, "gpios", idx, of_flags); { "miso", "gpio-miso", "spi-gpio" },
} { "mosi", "gpio-mosi", "spi-gpio" },
{ "sck", "gpio-sck", "spi-gpio" },
/* /*
* Some regulator bindings happened before we managed to establish that GPIO * The old Freescale bindings use simply "gpios" as name
* properties should be named "foo-gpios" so we have this special kludge for * for the chip select lines rather than "cs-gpios" like
* them. * all other SPI hardware. Allow this specifically for
* Freescale and PPC devices.
*/ */
static struct gpio_desc *of_find_regulator_gpio(struct device_node *np, { "cs", "gpios", "fsl,spi" },
const char *con_id, { "cs", "gpios", "aeroflexgaisler,spictrl" },
unsigned int idx, { "cs", "gpios", "ibm,ppc4xx-spi" },
enum of_gpio_flags *of_flags) #endif
{ #if IS_ENABLED(CONFIG_TYPEC_FUSB302)
/* These are the connection IDs we accept as legacy GPIO phandles */ /*
const char *whitelist[] = { * Fairchild FUSB302 host is using undocumented "fcs,int_n"
"wlf,ldoena", /* Arizona */ * property without the compulsory "-gpios" suffix.
"wlf,ldo1ena", /* WM8994 */ */
"wlf,ldo2ena", /* WM8994 */ { "fcs,int_n", NULL, "fcs,fusb302" },
#endif
}; };
int i; struct gpio_desc *desc;
const char *legacy_id;
if (!IS_ENABLED(CONFIG_REGULATOR)) unsigned int i;
return ERR_PTR(-ENOENT);
if (!con_id) if (!con_id)
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
i = match_string(whitelist, ARRAY_SIZE(whitelist), con_id); for (i = 0; i < ARRAY_SIZE(gpios); i++) {
if (i < 0) if (strcmp(con_id, gpios[i].con_id))
return ERR_PTR(-ENOENT); continue;
return of_get_named_gpiod_flags(np, con_id, idx, of_flags);
}
static struct gpio_desc *of_find_arizona_gpio(struct device_node *np,
const char *con_id,
unsigned int idx,
enum of_gpio_flags *of_flags)
{
if (!IS_ENABLED(CONFIG_MFD_ARIZONA))
return ERR_PTR(-ENOENT);
if (!con_id || strcmp(con_id, "wlf,reset"))
return ERR_PTR(-ENOENT);
return of_get_named_gpiod_flags(np, con_id, idx, of_flags); if (gpios[i].compatible &&
} !of_device_is_compatible(np, gpios[i].compatible))
continue;
static struct gpio_desc *of_find_usb_gpio(struct device_node *np, legacy_id = gpios[i].legacy_id ?: gpios[i].con_id;
const char *con_id, desc = of_get_named_gpiod_flags(np, legacy_id, idx, of_flags);
unsigned int idx, if (!gpiod_not_found(desc)) {
enum of_gpio_flags *of_flags) pr_info("%s uses legacy gpio name '%s' instead of '%s-gpios'\n",
{ of_node_full_name(np), legacy_id, con_id);
/* return desc;
* Currently this USB quirk is only for the Fairchild FUSB302 host }
* which is using an undocumented DT GPIO line named "fcs,int_n" }
* without the compulsory "-gpios" suffix.
*/
if (!IS_ENABLED(CONFIG_TYPEC_FUSB302))
return ERR_PTR(-ENOENT);
if (!con_id || strcmp(con_id, "fcs,int_n"))
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
return of_get_named_gpiod_flags(np, con_id, idx, of_flags);
} }
static struct gpio_desc *of_find_mt2701_gpio(struct device_node *np, static struct gpio_desc *of_find_mt2701_gpio(struct device_node *np,
...@@ -525,11 +488,7 @@ typedef struct gpio_desc *(*of_find_gpio_quirk)(struct device_node *np, ...@@ -525,11 +488,7 @@ typedef struct gpio_desc *(*of_find_gpio_quirk)(struct device_node *np,
unsigned int idx, unsigned int idx,
enum of_gpio_flags *of_flags); enum of_gpio_flags *of_flags);
static const of_find_gpio_quirk of_find_gpio_quirks[] = { static const of_find_gpio_quirk of_find_gpio_quirks[] = {
of_find_spi_gpio, of_find_gpio_rename,
of_find_spi_cs_gpio,
of_find_regulator_gpio,
of_find_arizona_gpio,
of_find_usb_gpio,
of_find_mt2701_gpio, of_find_mt2701_gpio,
NULL NULL
}; };
......
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