From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> To: linus.walleij@linaro.org, linux-sh@vger.kernel.org, laurent.pinchart@ideasonboard.com, linux-gpio@vger.kernel.org Subject: [PATCH v2 2/4] sh-pfc: handle pin array holes Date: Thu, 04 Jun 2015 23:27:17 +0000 [thread overview] Message-ID: <2126373.2XeHMZH1yc@wasted.cogentembedded.com> (raw) In-Reply-To: <4326653.qPvIJDU6F2@wasted.cogentembedded.com> The pin array handled by sh_pfc_init_ranges() and sh_pfc_map_pins() may contain "holes" representing non-existing pins. We have to first count the pin ranges and valid pins in order to calculate the size of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays (we still assume that a pin at index 0 always exists). We also have to return the number of valid pins from sh_pfc_map_pins() instead of 0 on success. As we have to touch devm_kzalloc() calls in sh_pfc_map_pins() anyway, use more fitting devm_kcalloc() instead which additionally checks the array size. And since PINMUX_TYPE_NONE is #define'd as 0, stop re-initializing already zeroed out 'pmx->configs' array. While at it, add spaces around the minus signs in sh_pfc_init_ranges(). Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> --- Changes in version 2: - added the handling of "holes" to sh_pfc_init_ranges(); - renamed the 'n' local variable in sh_pfc_map_pins() to 'num_pins' and declared it on a separate line; - moved the 'info' local variable inside 2nd loop in sh_pfc_map_pins(); - added comment before the 2nd devm_kcalloc() call in sh_pfc_map_pins(); - added comment to the 2nd loop in sh_pfc_map_pins(); - renamed and refreshed the patch. drivers/pinctrl/sh-pfc/core.c | 29 +++++++++++++++++++---------- drivers/pinctrl/sh-pfc/pinctrl.c | 29 +++++++++++++++++++---------- 2 files changed, 38 insertions(+), 20 deletions(-) Index: linux-pinctrl/drivers/pinctrl/sh-pfc/core.c =================================--- linux-pinctrl.orig/drivers/pinctrl/sh-pfc/core.c +++ linux-pinctrl/drivers/pinctrl/sh-pfc/core.c @@ -405,7 +405,10 @@ static int sh_pfc_init_ranges(struct sh_ * last. */ for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) { - if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1) + /* Check for the "holes" first */ + if (!pfc->info->pins[i].enum_id && !pfc->info->pins[i].configs) + continue; + if (pfc->info->pins[i - 1].pin != pfc->info->pins[i].pin - 1) nr_ranges++; } @@ -419,19 +422,25 @@ static int sh_pfc_init_ranges(struct sh_ range->start = pfc->info->pins[0].pin; for (i = 1; i < pfc->info->nr_pins; ++i) { - if (pfc->info->pins[i-1].pin = pfc->info->pins[i].pin - 1) + if (pfc->info->pins[i - 1].pin = pfc->info->pins[i].pin - 1) continue; - range->end = pfc->info->pins[i-1].pin; - if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO)) - pfc->nr_gpio_pins = range->end + 1; - - range++; - range->start = pfc->info->pins[i].pin; + if (pfc->info->pins[i - 1].enum_id || + pfc->info->pins[i - 1].configs) { + range->end = pfc->info->pins[i - 1].pin; + if (!(pfc->info->pins[i - 1].configs & + SH_PFC_PIN_CFG_NO_GPIO)) + pfc->nr_gpio_pins = range->end + 1; + } + + if (pfc->info->pins[i].enum_id || pfc->info->pins[i].configs) { + range++; + range->start = pfc->info->pins[i].pin; + } } - range->end = pfc->info->pins[i-1].pin; - if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO)) + range->end = pfc->info->pins[i - 1].pin; + if (!(pfc->info->pins[i - 1].configs & SH_PFC_PIN_CFG_NO_GPIO)) pfc->nr_gpio_pins = range->end + 1; return 0; Index: linux-pinctrl/drivers/pinctrl/sh-pfc/pinctrl.c =================================--- linux-pinctrl.orig/drivers/pinctrl/sh-pfc/pinctrl.c +++ linux-pinctrl/drivers/pinctrl/sh-pfc/pinctrl.c @@ -570,33 +570,42 @@ static const struct pinconf_ops sh_pfc_p /* PFC ranges -> pinctrl pin descs */ static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) { + struct pinctrl_pin_desc *pin; + unsigned int num_pins; unsigned int i; + /* Count the valid pins. */ + for (i = 0, num_pins = 0; i < pfc->info->nr_pins; i++) { + if (pfc->info->pins[i].enum_id || pfc->info->pins[i].configs) + num_pins++; + } + /* Allocate and initialize the pins and configs arrays. */ - pmx->pins = devm_kzalloc(pfc->dev, - sizeof(*pmx->pins) * pfc->info->nr_pins, + pmx->pins = devm_kcalloc(pfc->dev, num_pins, sizeof(*pmx->pins), GFP_KERNEL); if (unlikely(!pmx->pins)) return -ENOMEM; - pmx->configs = devm_kzalloc(pfc->dev, - sizeof(*pmx->configs) * pfc->info->nr_pins, + /* Equivalent to setting the type field to PINMUX_TYPE_NONE */ + pmx->configs = devm_kcalloc(pfc->dev, num_pins, sizeof(*pmx->configs), GFP_KERNEL); if (unlikely(!pmx->configs)) return -ENOMEM; - for (i = 0; i < pfc->info->nr_pins; ++i) { + for (i = 0, pin = pmx->pins; i < pfc->info->nr_pins; i++) { const struct sh_pfc_pin *info = &pfc->info->pins[i]; - struct sh_pfc_pin_config *cfg = &pmx->configs[i]; - struct pinctrl_pin_desc *pin = &pmx->pins[i]; + + /* Skip the "hole" */ + if (!info->enum_id && !info->configs) + continue; /* If the pin number is equal to -1 all pins are considered */ pin->number = info->pin != (u16)-1 ? info->pin : i; pin->name = info->name; - cfg->type = PINMUX_TYPE_NONE; + pin++; } - return 0; + return num_pins; } int sh_pfc_register_pinctrl(struct sh_pfc *pfc) @@ -621,7 +630,7 @@ int sh_pfc_register_pinctrl(struct sh_pf pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops; pmx->pctl_desc.confops = &sh_pfc_pinconf_ops; pmx->pctl_desc.pins = pmx->pins; - pmx->pctl_desc.npins = pfc->info->nr_pins; + pmx->pctl_desc.npins = ret; pmx->pctl = pinctrl_register(&pmx->pctl_desc, pfc->dev, pmx); if (pmx->pctl = NULL)
WARNING: multiple messages have this Message-ID (diff)
From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> To: linus.walleij@linaro.org, linux-sh@vger.kernel.org, laurent.pinchart@ideasonboard.com, linux-gpio@vger.kernel.org Subject: [PATCH v2 2/4] sh-pfc: handle pin array holes Date: Fri, 05 Jun 2015 02:27:17 +0300 [thread overview] Message-ID: <2126373.2XeHMZH1yc@wasted.cogentembedded.com> (raw) In-Reply-To: <4326653.qPvIJDU6F2@wasted.cogentembedded.com> The pin array handled by sh_pfc_init_ranges() and sh_pfc_map_pins() may contain "holes" representing non-existing pins. We have to first count the pin ranges and valid pins in order to calculate the size of the memory to be allocated, then to skip over the non-existing pins when initializing the allocated arrays (we still assume that a pin at index 0 always exists). We also have to return the number of valid pins from sh_pfc_map_pins() instead of 0 on success. As we have to touch devm_kzalloc() calls in sh_pfc_map_pins() anyway, use more fitting devm_kcalloc() instead which additionally checks the array size. And since PINMUX_TYPE_NONE is #define'd as 0, stop re-initializing already zeroed out 'pmx->configs' array. While at it, add spaces around the minus signs in sh_pfc_init_ranges(). Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> --- Changes in version 2: - added the handling of "holes" to sh_pfc_init_ranges(); - renamed the 'n' local variable in sh_pfc_map_pins() to 'num_pins' and declared it on a separate line; - moved the 'info' local variable inside 2nd loop in sh_pfc_map_pins(); - added comment before the 2nd devm_kcalloc() call in sh_pfc_map_pins(); - added comment to the 2nd loop in sh_pfc_map_pins(); - renamed and refreshed the patch. drivers/pinctrl/sh-pfc/core.c | 29 +++++++++++++++++++---------- drivers/pinctrl/sh-pfc/pinctrl.c | 29 +++++++++++++++++++---------- 2 files changed, 38 insertions(+), 20 deletions(-) Index: linux-pinctrl/drivers/pinctrl/sh-pfc/core.c =================================================================== --- linux-pinctrl.orig/drivers/pinctrl/sh-pfc/core.c +++ linux-pinctrl/drivers/pinctrl/sh-pfc/core.c @@ -405,7 +405,10 @@ static int sh_pfc_init_ranges(struct sh_ * last. */ for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) { - if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1) + /* Check for the "holes" first */ + if (!pfc->info->pins[i].enum_id && !pfc->info->pins[i].configs) + continue; + if (pfc->info->pins[i - 1].pin != pfc->info->pins[i].pin - 1) nr_ranges++; } @@ -419,19 +422,25 @@ static int sh_pfc_init_ranges(struct sh_ range->start = pfc->info->pins[0].pin; for (i = 1; i < pfc->info->nr_pins; ++i) { - if (pfc->info->pins[i-1].pin == pfc->info->pins[i].pin - 1) + if (pfc->info->pins[i - 1].pin == pfc->info->pins[i].pin - 1) continue; - range->end = pfc->info->pins[i-1].pin; - if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO)) - pfc->nr_gpio_pins = range->end + 1; - - range++; - range->start = pfc->info->pins[i].pin; + if (pfc->info->pins[i - 1].enum_id || + pfc->info->pins[i - 1].configs) { + range->end = pfc->info->pins[i - 1].pin; + if (!(pfc->info->pins[i - 1].configs & + SH_PFC_PIN_CFG_NO_GPIO)) + pfc->nr_gpio_pins = range->end + 1; + } + + if (pfc->info->pins[i].enum_id || pfc->info->pins[i].configs) { + range++; + range->start = pfc->info->pins[i].pin; + } } - range->end = pfc->info->pins[i-1].pin; - if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO)) + range->end = pfc->info->pins[i - 1].pin; + if (!(pfc->info->pins[i - 1].configs & SH_PFC_PIN_CFG_NO_GPIO)) pfc->nr_gpio_pins = range->end + 1; return 0; Index: linux-pinctrl/drivers/pinctrl/sh-pfc/pinctrl.c =================================================================== --- linux-pinctrl.orig/drivers/pinctrl/sh-pfc/pinctrl.c +++ linux-pinctrl/drivers/pinctrl/sh-pfc/pinctrl.c @@ -570,33 +570,42 @@ static const struct pinconf_ops sh_pfc_p /* PFC ranges -> pinctrl pin descs */ static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) { + struct pinctrl_pin_desc *pin; + unsigned int num_pins; unsigned int i; + /* Count the valid pins. */ + for (i = 0, num_pins = 0; i < pfc->info->nr_pins; i++) { + if (pfc->info->pins[i].enum_id || pfc->info->pins[i].configs) + num_pins++; + } + /* Allocate and initialize the pins and configs arrays. */ - pmx->pins = devm_kzalloc(pfc->dev, - sizeof(*pmx->pins) * pfc->info->nr_pins, + pmx->pins = devm_kcalloc(pfc->dev, num_pins, sizeof(*pmx->pins), GFP_KERNEL); if (unlikely(!pmx->pins)) return -ENOMEM; - pmx->configs = devm_kzalloc(pfc->dev, - sizeof(*pmx->configs) * pfc->info->nr_pins, + /* Equivalent to setting the type field to PINMUX_TYPE_NONE */ + pmx->configs = devm_kcalloc(pfc->dev, num_pins, sizeof(*pmx->configs), GFP_KERNEL); if (unlikely(!pmx->configs)) return -ENOMEM; - for (i = 0; i < pfc->info->nr_pins; ++i) { + for (i = 0, pin = pmx->pins; i < pfc->info->nr_pins; i++) { const struct sh_pfc_pin *info = &pfc->info->pins[i]; - struct sh_pfc_pin_config *cfg = &pmx->configs[i]; - struct pinctrl_pin_desc *pin = &pmx->pins[i]; + + /* Skip the "hole" */ + if (!info->enum_id && !info->configs) + continue; /* If the pin number is equal to -1 all pins are considered */ pin->number = info->pin != (u16)-1 ? info->pin : i; pin->name = info->name; - cfg->type = PINMUX_TYPE_NONE; + pin++; } - return 0; + return num_pins; } int sh_pfc_register_pinctrl(struct sh_pfc *pfc) @@ -621,7 +630,7 @@ int sh_pfc_register_pinctrl(struct sh_pf pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops; pmx->pctl_desc.confops = &sh_pfc_pinconf_ops; pmx->pctl_desc.pins = pmx->pins; - pmx->pctl_desc.npins = pfc->info->nr_pins; + pmx->pctl_desc.npins = ret; pmx->pctl = pinctrl_register(&pmx->pctl_desc, pfc->dev, pmx); if (pmx->pctl == NULL)
next prev parent reply other threads:[~2015-06-04 23:27 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-06-04 23:23 [PATCH v2 0/4] sh-pfc: handle pin array holes in sh_pfc_map_pins() Sergei Shtylyov 2015-06-04 23:23 ` Sergei Shtylyov 2015-06-04 23:25 ` [PATCH v2 1/4] sh-pfc: do not call sh_pfc_get_pin_index() when unnecessary Sergei Shtylyov 2015-06-04 23:25 ` Sergei Shtylyov 2015-06-18 19:05 ` Laurent Pinchart 2015-06-18 19:05 ` Laurent Pinchart 2015-06-22 22:42 ` Sergei Shtylyov 2015-06-22 22:42 ` Sergei Shtylyov 2015-06-23 20:00 ` Sergei Shtylyov 2015-06-23 20:00 ` Sergei Shtylyov 2015-06-04 23:27 ` Sergei Shtylyov [this message] 2015-06-04 23:27 ` [PATCH v2 2/4] sh-pfc: handle pin array holes Sergei Shtylyov 2015-06-04 23:30 ` [PATCH v2 3/4] sh-pfc: r8a7790: remove non-existing GPIO pins Sergei Shtylyov 2015-06-04 23:30 ` Sergei Shtylyov 2015-06-04 23:31 ` [PATCH v2 4/4] sh-pfc: r8a7791 " Sergei Shtylyov 2015-06-04 23:31 ` Sergei Shtylyov 2015-06-04 23:42 ` [PATCH v2 0/4] sh-pfc: handle pin array holes in sh_pfc_map_pins() Sergei Shtylyov 2015-06-04 23:42 ` Sergei Shtylyov 2015-06-10 7:49 ` Linus Walleij 2015-06-10 7:49 ` Linus Walleij 2015-06-10 12:11 ` Sergei Shtylyov 2015-06-10 12:11 ` Sergei Shtylyov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=2126373.2XeHMZH1yc@wasted.cogentembedded.com \ --to=sergei.shtylyov@cogentembedded.com \ --cc=laurent.pinchart@ideasonboard.com \ --cc=linus.walleij@linaro.org \ --cc=linux-gpio@vger.kernel.org \ --cc=linux-sh@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.