From: patrice.chotard@st.com (Patrice Chotard)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 4/9] pinctrl: Add STM32 MCUs support
Date: Wed, 16 Dec 2015 17:55:09 +0100 [thread overview]
Message-ID: <5671976D.2050706@st.com> (raw)
In-Reply-To: <1449822306-9035-5-git-send-email-mcoquelin.stm32@gmail.com>
Hi Maxime
On 12/11/2015 09:25 AM, Maxime Coquelin wrote:
> This patch adds pinctrl and GPIO support to STMicroelectronic's STM32
> family of MCUs.
>
> While it only supports STM32F429 for now, it has been designed to enable
> support of other MCUs of the family (e.g. STM32F746).
>
> Signed-off-by: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> ---
> drivers/pinctrl/Kconfig | 1 +
> drivers/pinctrl/Makefile | 1 +
> drivers/pinctrl/stm32/Kconfig | 16 +
> drivers/pinctrl/stm32/Makefile | 5 +
> drivers/pinctrl/stm32/pinctrl-stm32.c | 856 +++++++++++++++
> drivers/pinctrl/stm32/pinctrl-stm32.h | 43 +
> drivers/pinctrl/stm32/pinctrl-stm32f429.c | 1598 +++++++++++++++++++++++++++++
> 7 files changed, 2520 insertions(+)
> create mode 100644 drivers/pinctrl/stm32/Kconfig
> create mode 100644 drivers/pinctrl/stm32/Makefile
> create mode 100644 drivers/pinctrl/stm32/pinctrl-stm32.c
> create mode 100644 drivers/pinctrl/stm32/pinctrl-stm32.h
> create mode 100644 drivers/pinctrl/stm32/pinctrl-stm32f429.c
>
[...]
> +
> +static int stm32_pctrl_dt_subnode_to_map(struct pinctrl_dev *pctldev,
> + struct device_node *node,
> + struct pinctrl_map **map,
> + unsigned *reserved_maps,
> + unsigned *num_maps)
> +{
> + struct stm32_pinctrl *pctl;
> + struct stm32_pinctrl_group *grp;
> + struct property *pins;
> + u32 pinfunc, pin, func;
> + unsigned long *configs;
> + unsigned int num_configs;
> + bool has_config = 0;
> + unsigned reserve = 0;
> + int num_pins, num_funcs, maps_per_pin, i, err;
> +
> + pctl = pinctrl_dev_get_drvdata(pctldev);
> +
> + pins = of_find_property(node, "pinmux", NULL);
> + if (!pins) {
> + dev_err(pctl->dev, "missing pins property in node %s .\n",
> + node->name);
> + return -EINVAL;
> + }
> +
> + err = pinconf_generic_parse_dt_config(node, pctldev, &configs,
> + &num_configs);
> + if (num_configs)
> + has_config = 1;
> +
> + num_pins = pins->length / sizeof(u32);
> + num_funcs = num_pins;
> + maps_per_pin = 0;
> + if (num_funcs)
> + maps_per_pin++;
> + if (has_config && num_pins >= 1)
> + maps_per_pin++;
> +
> + if (!num_pins || !maps_per_pin)
> + return -EINVAL;
> +
> + reserve = num_pins * maps_per_pin;
> +
> + err = pinctrl_utils_reserve_map(pctldev, map,
> + reserved_maps, num_maps, reserve);
> + if (err < 0)
> + goto fail;
> +
> + for (i = 0; i < num_pins; i++) {
> + err = of_property_read_u32_index(node, "pinmux",
> + i, &pinfunc);
> + if (err)
> + goto fail;
as a "goto fail" doesn't do more than a return, here do directly "return
err;"
> +
> + pin = STM32_GET_PIN_NO(pinfunc);
> + func = STM32_GET_PIN_FUNC(pinfunc);
> +
> + if (pin >= pctl->match_data->npins) {
> + dev_err(pctl->dev, "invalid pin number.\n");
> + err = -EINVAL;
> + goto fail;
ditto, return -EINVAL
> + }
> +
> + if (!stm32_pctrl_is_function_valid(pctl, pin, func)) {
> + dev_err(pctl->dev, "invalid function.\n");
> + err = -EINVAL;
> + goto fail;
ditto
> + }
> +
> + grp = stm32_pctrl_find_group_by_pin(pctl, pin);
> + if (!grp) {
> + dev_err(pctl->dev, "unable to match pin %d to group\n",
> + pin);
> + return -EINVAL;
> + }
> +
> + err = stm32_pctrl_dt_node_to_map_func(pctl, pin, func, grp, map,
> + reserved_maps, num_maps);
> + if (err < 0)
> + goto fail;
ditto
> +
> + if (has_config) {
> + err = pinctrl_utils_add_map_configs(pctldev, map,
> + reserved_maps, num_maps, grp->name,
> + configs, num_configs,
> + PIN_MAP_TYPE_CONFIGS_GROUP);
> + if (err < 0)
> + goto fail;
ditto
> + }
> + }
> +
> + return 0;
> +
> +fail:
> + return err;
> +}
> +
[...]
> +
> +static int stm32_pmx_set_mux(struct pinctrl_dev *pctldev,
> + unsigned function,
> + unsigned group)
> +{
> + bool ret;
> + const struct stm32_desc_function *desc;
> + struct stm32_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
> + struct stm32_pinctrl_group *g = pctl->groups + group;
> + struct pinctrl_gpio_range *range;
> + struct stm32_gpio_bank *bank;
> + u32 mode, alt;
> + int pin;
> +
> + ret = stm32_pctrl_is_function_valid(pctl, g->pin, function);
> + if (!ret) {
> + dev_err(pctl->dev, "invalid function %d on group %d .\n",
> + function, group);
> + return -EINVAL;
> + }
> +
> + desc = stm32_pctrl_find_function_by_pin(pctl, g->pin, function);
> + if (!desc)
> + return -EINVAL;
stm32_pctrl_find_function_by_pin() is useless, desc is never used
stm32_pctrl_is_function_valid(), above, already checks that function exists for the requested pins
> +
> + range = pinctrl_find_gpio_range_from_pin(pctldev, g->pin);
> + bank = gpio_range_to_bank(range);
> + pin = stm32_gpio_pin(g->pin);
> +
> + mode = stm32_gpio_get_mode(function);
> + alt = stm32_gpio_get_alt(function);
> +
> + stm32_pmx_set_mode(bank, pin, mode, alt);
> +
> + return 0;
> +}
> +
>
next prev parent reply other threads:[~2015-12-16 16:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-11 8:24 [PATCH RESEND v3 0/9] Add STM32 pinctrl/GPIO driver Maxime Coquelin
2015-12-11 8:24 ` [PATCH v3 1/9] ARM: Kconfig: Introduce MACH_STM32F429 flag Maxime Coquelin
2015-12-11 8:24 ` [PATCH v3 2/9] Documentation: dt-bindings: Document STM32 pinctrl driver DT bindings Maxime Coquelin
2015-12-11 8:25 ` [PATCH v3 3/9] includes: dt-bindings: Add STM32F429 pinctrl " Maxime Coquelin
2015-12-11 8:25 ` [PATCH v3 4/9] pinctrl: Add STM32 MCUs support Maxime Coquelin
2015-12-16 16:55 ` Patrice Chotard [this message]
2015-12-11 8:25 ` [PATCH v3 5/9] ARM: mach-stm32: Select pinctrl Maxime Coquelin
2015-12-11 8:25 ` [PATCH v3 6/9] ARM: dts: Add pinctrl node to STM32F429 Maxime Coquelin
2015-12-11 8:25 ` [PATCH v3 7/9] ARM: dts: Add USART1 pin config to STM32F429 boards Maxime Coquelin
2015-12-11 8:25 ` [PATCH v3 8/9] ARM: dts: Add leds support " Maxime Coquelin
2015-12-11 8:25 ` [PATCH v3 9/9] ARM: config: Enable GPIO Led driver in stm32_defconfig Maxime Coquelin
2015-12-16 16:56 ` [PATCH RESEND v3 0/9] Add STM32 pinctrl/GPIO driver Patrice Chotard
2016-01-14 12:55 ` Maxime Coquelin
-- strict thread matches above, loose matches on Subject: below --
2015-12-08 12:45 [PATCH " Maxime Coquelin
2015-12-08 12:45 ` [PATCH v3 4/9] pinctrl: Add STM32 MCUs support Maxime Coquelin
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=5671976D.2050706@st.com \
--to=patrice.chotard@st.com \
--cc=linux-arm-kernel@lists.infradead.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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).