Commit 7f6ee0a5 authored by Masahiro Yamada's avatar Masahiro Yamada Committed by Linus Walleij

pinctrl: uniphier: clean up GPIO port muxing

There are a bunch of GPIO muxing data, but most of them are actually
unneeded because GPIO-to-pin mapping can be specified by "gpio-ranges"
DT properties.

Tables that contain a set of GPIO pins are still needed for the named
mapping by "gpio-ranges-group-names".  This is a much cleaner way for
UniPhier SoC family where GPIO numbers are not straight mapped to pin
numbers.
Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent e3829d15
...@@ -651,30 +651,27 @@ static int uniphier_pmx_gpio_request_enable(struct pinctrl_dev *pctldev, ...@@ -651,30 +651,27 @@ static int uniphier_pmx_gpio_request_enable(struct pinctrl_dev *pctldev,
unsigned offset) unsigned offset)
{ {
struct uniphier_pinctrl_priv *priv = pinctrl_dev_get_drvdata(pctldev); struct uniphier_pinctrl_priv *priv = pinctrl_dev_get_drvdata(pctldev);
const struct uniphier_pinctrl_group *groups = priv->socdata->groups; unsigned int gpio_offset;
int groups_count = priv->socdata->groups_count; int muxval, i;
enum uniphier_pinmux_gpio_range_type range_type;
int i, j; if (range->pins) {
for (i = 0; i < range->npins; i++)
if (strstr(range->name, "irq")) if (range->pins[i] == offset)
range_type = UNIPHIER_PINMUX_GPIO_RANGE_IRQ; break;
else
range_type = UNIPHIER_PINMUX_GPIO_RANGE_PORT; if (WARN_ON(i == range->npins))
return -EINVAL;
for (i = 0; i < groups_count; i++) {
if (groups[i].range_type != range_type) gpio_offset = i;
continue; } else {
gpio_offset = offset - range->pin_base;
for (j = 0; j < groups[i].num_pins; j++)
if (groups[i].pins[j] == offset)
goto found;
} }
dev_err(pctldev->dev, "pin %u does not support GPIO\n", offset); gpio_offset += range->id;
return -EINVAL;
muxval = priv->socdata->get_gpio_muxval(offset, gpio_offset);
found: return uniphier_pmx_set_one_mux(pctldev, offset, muxval);
return uniphier_pmx_set_one_mux(pctldev, offset, groups[i].muxvals[j]);
} }
static const struct pinmux_ops uniphier_pmxops = { static const struct pinmux_ops uniphier_pmxops = {
......
...@@ -131,18 +131,11 @@ static inline unsigned int uniphier_pin_get_pull_dir(void *drv_data) ...@@ -131,18 +131,11 @@ static inline unsigned int uniphier_pin_get_pull_dir(void *drv_data)
UNIPHIER_PIN_PULL_DIR_MASK; UNIPHIER_PIN_PULL_DIR_MASK;
} }
enum uniphier_pinmux_gpio_range_type {
UNIPHIER_PINMUX_GPIO_RANGE_PORT,
UNIPHIER_PINMUX_GPIO_RANGE_IRQ,
UNIPHIER_PINMUX_GPIO_RANGE_NONE,
};
struct uniphier_pinctrl_group { struct uniphier_pinctrl_group {
const char *name; const char *name;
const unsigned *pins; const unsigned *pins;
unsigned num_pins; unsigned num_pins;
const int *muxvals; const int *muxvals;
enum uniphier_pinmux_gpio_range_type range_type;
}; };
struct uniphier_pinmux_function { struct uniphier_pinmux_function {
...@@ -158,6 +151,7 @@ struct uniphier_pinctrl_socdata { ...@@ -158,6 +151,7 @@ struct uniphier_pinctrl_socdata {
int groups_count; int groups_count;
const struct uniphier_pinmux_function *functions; const struct uniphier_pinmux_function *functions;
int functions_count; int functions_count;
int (*get_gpio_muxval)(unsigned int pin, unsigned int gpio_offset);
unsigned int caps; unsigned int caps;
#define UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL BIT(1) #define UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL BIT(1)
#define UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE BIT(0) #define UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE BIT(0)
...@@ -170,33 +164,22 @@ struct uniphier_pinctrl_socdata { ...@@ -170,33 +164,22 @@ struct uniphier_pinctrl_socdata {
.drv_data = (void *)UNIPHIER_PIN_ATTR_PACKED(c, d, e, f, g), \ .drv_data = (void *)UNIPHIER_PIN_ATTR_PACKED(c, d, e, f, g), \
} }
#define __UNIPHIER_PINCTRL_GROUP(grp, type) \ #define __UNIPHIER_PINCTRL_GROUP(grp, mux) \
{ \ { \
.name = #grp, \ .name = #grp, \
.pins = grp##_pins, \ .pins = grp##_pins, \
.num_pins = ARRAY_SIZE(grp##_pins), \ .num_pins = ARRAY_SIZE(grp##_pins), \
.muxvals = grp##_muxvals + \ .muxvals = mux, \
BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \
ARRAY_SIZE(grp##_muxvals)), \
.range_type = type, \
} }
#define UNIPHIER_PINCTRL_GROUP(grp) \ #define UNIPHIER_PINCTRL_GROUP(grp) \
__UNIPHIER_PINCTRL_GROUP(grp, UNIPHIER_PINMUX_GPIO_RANGE_NONE) __UNIPHIER_PINCTRL_GROUP(grp, \
grp##_muxvals + \
#define UNIPHIER_PINCTRL_GROUP_GPIO_RANGE_PORT(grp) \ BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \
__UNIPHIER_PINCTRL_GROUP(grp, UNIPHIER_PINMUX_GPIO_RANGE_PORT) ARRAY_SIZE(grp##_muxvals)))
#define UNIPHIER_PINCTRL_GROUP_GPIO_RANGE_IRQ(grp) \
__UNIPHIER_PINCTRL_GROUP(grp, UNIPHIER_PINMUX_GPIO_RANGE_IRQ)
#define UNIPHIER_PINCTRL_GROUP_SINGLE(grp, array, ofst) \ #define UNIPHIER_PINCTRL_GROUP_GPIO(grp) \
{ \ __UNIPHIER_PINCTRL_GROUP(grp, NULL)
.name = #grp, \
.pins = array##_pins + ofst, \
.num_pins = 1, \
.muxvals = array##_muxvals + ofst, \
}
#define UNIPHIER_PINMUX_FUNCTION(func) \ #define UNIPHIER_PINMUX_FUNCTION(func) \
{ \ { \
......
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