Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit caa5bac3 authored by Laurent Pinchart's avatar Laurent Pinchart
Browse files

sh-pfc: Replace SoC info data and mark ranges with a number of pins



The data and mark ranges are only used to check whether a GPIO
corresponds to a real pin or a function. As pins come first in the list
of GPIOs and in the platform-specific GPIO enumerations, we can replace
the data and mark ranges by a number of pins.

Add an nr_pins field to struct sh_pfc_soc_info to store the number of
pins implemented by the SoC, remove the data and mark range fields and
introduce sh_pfc_gpio_is_pin() and sh_pfc_gpio_is_function() functions
to replace range-based checks.

Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent d7a7ca57
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -89,6 +89,18 @@ static int sh_pfc_enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r)
	return 1;
}

static bool sh_pfc_gpio_is_pin(struct sh_pfc *pfc, unsigned int gpio)
{
	return (gpio < pfc->info->nr_pins) &&
	       (pfc->info->gpios[gpio].enum_id != 0);
}

static bool sh_pfc_gpio_is_function(struct sh_pfc *pfc, unsigned int gpio)
{
	return (gpio >= pfc->info->nr_pins) && (gpio < pfc->info->nr_gpios) &&
	       (pfc->info->gpios[gpio].enum_id != 0);
}

static unsigned long sh_pfc_read_raw_reg(void __iomem *mapped_reg,
					 unsigned long reg_width)
{
@@ -226,7 +238,7 @@ static int sh_pfc_setup_data_reg(struct sh_pfc *pfc, unsigned gpio)
	struct pinmux_data_reg *data_reg;
	int k, n;

	if (!sh_pfc_enum_in_range(gpiop->enum_id, &pfc->info->data))
	if (!sh_pfc_gpio_is_pin(pfc, gpio))
		return -1;

	k = 0;
@@ -260,7 +272,7 @@ static void sh_pfc_setup_data_regs(struct sh_pfc *pfc)
	struct pinmux_data_reg *drp;
	int k;

	for (k = 0; k < pfc->info->nr_gpios; k++)
	for (k = 0; k < pfc->info->nr_pins; k++)
		sh_pfc_setup_data_reg(pfc, k);

	k = 0;
@@ -282,7 +294,7 @@ int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio,
	struct pinmux_gpio *gpiop = &pfc->info->gpios[gpio];
	int k, n;

	if (!sh_pfc_enum_in_range(gpiop->enum_id, &pfc->info->data))
	if (!sh_pfc_gpio_is_pin(pfc, gpio))
		return -1;

	k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT;
@@ -344,12 +356,11 @@ int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos,
	pinmux_enum_t *data = pfc->info->gpio_data;
	int k;

	if (!sh_pfc_enum_in_range(enum_id, &pfc->info->data)) {
		if (!sh_pfc_enum_in_range(enum_id, &pfc->info->mark)) {
	if (!sh_pfc_gpio_is_pin(pfc, gpio) &&
	    !sh_pfc_gpio_is_function(pfc, gpio)) {
		pr_err("non data/mark enum_id for gpio %d\n", gpio);
		return -1;
	}
	}

	if (pos) {
		*enum_idp = data[pos + 1];
+1 −4
Original line number Diff line number Diff line
@@ -2582,8 +2582,6 @@ static struct pinmux_irq pinmux_irqs[] = {
struct sh_pfc_soc_info r8a7740_pinmux_info = {
	.name		= "r8a7740_pfc",
	.reserved_id	= PINMUX_RESERVED,
	.data		= { PINMUX_DATA_BEGIN,
			    PINMUX_DATA_END },
	.input		= { PINMUX_INPUT_BEGIN,
			    PINMUX_INPUT_END },
	.input_pu	= { PINMUX_INPUT_PULLUP_BEGIN,
@@ -2592,12 +2590,11 @@ struct sh_pfc_soc_info r8a7740_pinmux_info = {
			    PINMUX_INPUT_PULLDOWN_END },
	.output		= { PINMUX_OUTPUT_BEGIN,
			    PINMUX_OUTPUT_END },
	.mark		= { PINMUX_MARK_BEGIN,
			    PINMUX_MARK_END },
	.function	= { PINMUX_FUNCTION_BEGIN,
			    PINMUX_FUNCTION_END },

	.gpios		= pinmux_gpios,
	.nr_pins	= GPIO_PORT211 + 1,
	.nr_gpios	= ARRAY_SIZE(pinmux_gpios),

	.cfg_regs	= pinmux_config_regs,
+1 −2
Original line number Diff line number Diff line
@@ -2606,13 +2606,12 @@ struct sh_pfc_soc_info r8a7779_pinmux_info = {
	.unlock_reg = 0xfffc0000, /* PMMR */

	.reserved_id = PINMUX_RESERVED,
	.data = { PINMUX_DATA_BEGIN, PINMUX_DATA_END },
	.input = { PINMUX_INPUT_BEGIN, PINMUX_INPUT_END },
	.output = { PINMUX_OUTPUT_BEGIN, PINMUX_OUTPUT_END },
	.mark = { PINMUX_MARK_BEGIN, PINMUX_MARK_END },
	.function = { PINMUX_FUNCTION_BEGIN, PINMUX_FUNCTION_END },

	.gpios = pinmux_gpios,
	.nr_pins = GPIO_GP_6_8 + 1,
	.nr_gpios = ARRAY_SIZE(pinmux_gpios),

	.cfg_regs = pinmux_config_regs,
+1 −2
Original line number Diff line number Diff line
@@ -1574,13 +1574,12 @@ static struct pinmux_data_reg pinmux_data_regs[] = {
struct sh_pfc_soc_info sh7203_pinmux_info = {
	.name = "sh7203_pfc",
	.reserved_id = PINMUX_RESERVED,
	.data = { PINMUX_DATA_BEGIN, PINMUX_DATA_END },
	.input = { PINMUX_INPUT_BEGIN, PINMUX_INPUT_END, FORCE_IN },
	.output = { PINMUX_OUTPUT_BEGIN, PINMUX_OUTPUT_END, FORCE_OUT },
	.mark = { PINMUX_MARK_BEGIN, PINMUX_MARK_END },
	.function = { PINMUX_FUNCTION_BEGIN, PINMUX_FUNCTION_END },

	.gpios = pinmux_gpios,
	.nr_pins = GPIO_PF0 + 1,
	.nr_gpios = ARRAY_SIZE(pinmux_gpios),

	.cfg_regs = pinmux_config_regs,
+1 −2
Original line number Diff line number Diff line
@@ -2113,13 +2113,12 @@ static struct pinmux_data_reg pinmux_data_regs[] = {
struct sh_pfc_soc_info sh7264_pinmux_info = {
	.name = "sh7264_pfc",
	.reserved_id = PINMUX_RESERVED,
	.data = { PINMUX_DATA_BEGIN, PINMUX_DATA_END },
	.input = { PINMUX_INPUT_BEGIN, PINMUX_INPUT_END, FORCE_IN },
	.output = { PINMUX_OUTPUT_BEGIN, PINMUX_OUTPUT_END, FORCE_OUT },
	.mark = { PINMUX_MARK_BEGIN, PINMUX_MARK_END },
	.function = { PINMUX_FUNCTION_BEGIN, PINMUX_FUNCTION_END },

	.gpios = pinmux_gpios,
	.nr_pins = GPIO_PK0 + 1,
	.nr_gpios = ARRAY_SIZE(pinmux_gpios),

	.cfg_regs = pinmux_config_regs,
Loading