2021-06-21 11:03:22

by Sai Krishna Potthuri

[permalink] [raw]
Subject: [PATCH] pinctrl: zynqmp: some code cleanups

Some minor code cleanups and updates which includes
- Mention module name under help in Kconfig.
- Remove extra lines and duplicate Pin range checks.
- Replace 'return ret' with 'return 0' in success path.
- Copyright year update.
- use devm_pinctrl_register() instead pinctrl_register() in probe.

Signed-off-by: Sai Krishna Potthuri <[email protected]>
---
drivers/pinctrl/Kconfig | 2 ++
drivers/pinctrl/pinctrl-zynqmp.c | 50 +++++++++++++-------------------
2 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
index c2c7e7963ed0..f38f12801f18 100644
--- a/drivers/pinctrl/Kconfig
+++ b/drivers/pinctrl/Kconfig
@@ -336,6 +336,8 @@ config PINCTRL_ZYNQMP
Configuration can include the mux function to select on those
pin(s)/group(s), and various pin configuration parameters
such as pull-up, slew rate, etc.
+ This driver can also be built as a module. If so, the module
+ will be called pinctrl-zynqmp.

config PINCTRL_INGENIC
bool "Pinctrl driver for the Ingenic JZ47xx SoCs"
diff --git a/drivers/pinctrl/pinctrl-zynqmp.c b/drivers/pinctrl/pinctrl-zynqmp.c
index d5497003ce71..bbde676b7313 100644
--- a/drivers/pinctrl/pinctrl-zynqmp.c
+++ b/drivers/pinctrl/pinctrl-zynqmp.c
@@ -2,7 +2,7 @@
/*
* ZynqMP pin controller
*
- * Copyright (C) 2020 Xilinx, Inc.
+ * Copyright (C) 2020, 2021 Xilinx, Inc.
*
* Sai Krishna Potthuri <[email protected]>
* Rajan Vaja <[email protected]>
@@ -252,9 +252,6 @@ static int zynqmp_pinconf_cfg_get(struct pinctrl_dev *pctldev,
unsigned int arg, param = pinconf_to_config_param(*config);
int ret;

- if (pin >= zynqmp_desc.npins)
- return -EOPNOTSUPP;
-
switch (param) {
case PIN_CONFIG_SLEW_RATE:
param = PM_PINCTRL_CONFIG_SLEW_RATE;
@@ -317,7 +314,7 @@ static int zynqmp_pinconf_cfg_get(struct pinctrl_dev *pctldev,
}
break;
default:
- ret = -EOPNOTSUPP;
+ ret = -ENOTSUPP;
break;
}

@@ -348,9 +345,6 @@ static int zynqmp_pinconf_cfg_set(struct pinctrl_dev *pctldev,
{
int i, ret;

- if (pin >= zynqmp_desc.npins)
- return -EOPNOTSUPP;
-
for (i = 0; i < num_configs; i++) {
unsigned int param = pinconf_to_config_param(configs[i]);
unsigned int arg = pinconf_to_config_argument(configs[i]);
@@ -428,7 +422,7 @@ static int zynqmp_pinconf_cfg_set(struct pinctrl_dev *pctldev,
dev_warn(pctldev->dev,
"unsupported configuration parameter '%u'\n",
param);
- ret = -EOPNOTSUPP;
+ ret = -ENOTSUPP;
break;
}

@@ -504,7 +498,7 @@ static int zynqmp_pinctrl_get_function_groups(u32 fid, u32 index, u16 *groups)

memcpy(groups, &payload[1], PINCTRL_GET_FUNC_GROUPS_RESP_LEN);

- return ret;
+ return 0;
}

static int zynqmp_pinctrl_get_func_num_groups(u32 fid, unsigned int *ngroups)
@@ -522,7 +516,7 @@ static int zynqmp_pinctrl_get_func_num_groups(u32 fid, unsigned int *ngroups)

*ngroups = payload[1];

- return ret;
+ return 0;
}

/**
@@ -533,16 +527,16 @@ static int zynqmp_pinctrl_get_func_num_groups(u32 fid, unsigned int *ngroups)
* @groups: Groups data.
*
* Query firmware to get group IDs for each function. Firmware returns
- * group IDs. Based on group index for the function, group names in
+ * group IDs. Based on the group index for the function, group names in
* the function are stored. For example, the first group in "eth0" function
- * is named as "eth0_0" and second group as "eth0_1" and so on.
+ * is named as "eth0_0" and the second group as "eth0_1" and so on.
*
* Based on the group ID received from the firmware, function stores name of
* the group for that group ID. For example, if "eth0" first group ID
* is x, groups[x] name will be stored as "eth0_0".
*
* Once done for each function, each function would have its group names
- * and each groups would also have their names.
+ * and each group would also have their names.
*
* Return: 0 on success else error code.
*/
@@ -552,7 +546,7 @@ static int zynqmp_pinctrl_prepare_func_groups(struct device *dev, u32 fid,
{
u16 resp[NUM_GROUPS_PER_RESP] = {0};
const char **fgroups;
- int ret = 0, index, i;
+ int ret, index, i;

fgroups = devm_kzalloc(dev, sizeof(*fgroups) * func->ngroups, GFP_KERNEL);
if (!fgroups)
@@ -588,7 +582,7 @@ static int zynqmp_pinctrl_prepare_func_groups(struct device *dev, u32 fid,
done:
func->groups = fgroups;

- return ret;
+ return 0;
}

static void zynqmp_pinctrl_get_function_name(u32 fid, char *name)
@@ -622,7 +616,7 @@ static int zynqmp_pinctrl_get_num_functions(unsigned int *nfuncs)

*nfuncs = payload[1];

- return ret;
+ return 0;
}

static int zynqmp_pinctrl_get_pin_groups(u32 pin, u32 index, u16 *groups)
@@ -641,7 +635,7 @@ static int zynqmp_pinctrl_get_pin_groups(u32 pin, u32 index, u16 *groups)

memcpy(groups, &payload[1], PINCTRL_GET_PIN_GROUPS_RESP_LEN);

- return ret;
+ return 0;
}

static void zynqmp_pinctrl_group_add_pin(struct zynqmp_pctrl_group *group,
@@ -660,7 +654,7 @@ static void zynqmp_pinctrl_group_add_pin(struct zynqmp_pctrl_group *group,
* Based on the firmware response(group IDs for the pin), add
* pin number to the respective group's pin array.
*
- * Once all pins are queries, each groups would have its number
+ * Once all pins are queries, each group would have its number
* of pins and pin numbers data.
*
* Return: 0 on success else error code.
@@ -689,7 +683,7 @@ static int zynqmp_pinctrl_create_pin_groups(struct device *dev,
index += NUM_GROUPS_PER_RESP;
} while (index <= MAX_PIN_GROUPS);

- return ret;
+ return 0;
}

/**
@@ -727,7 +721,7 @@ static int zynqmp_pinctrl_prepare_group_pins(struct device *dev,
* prepare pin control driver data.
*
* Query number of functions and number of function groups (number
- * of groups in given function) to allocate required memory buffers
+ * of groups in the given function) to allocate required memory buffers
* for functions and groups. Once buffers are allocated to store
* functions and groups data, query and store required information
* (number of groups and group names for each function, number of
@@ -778,7 +772,7 @@ static int zynqmp_pinctrl_prepare_function_info(struct device *dev,
pctrl->funcs = funcs;
pctrl->groups = groups;

- return ret;
+ return 0;
}

static int zynqmp_pinctrl_get_num_pins(unsigned int *npins)
@@ -795,7 +789,7 @@ static int zynqmp_pinctrl_get_num_pins(unsigned int *npins)

*npins = payload[1];

- return ret;
+ return 0;
}

/**
@@ -853,19 +847,17 @@ static int zynqmp_pinctrl_probe(struct platform_device *pdev)
&zynqmp_desc.pins,
&zynqmp_desc.npins);
if (ret) {
- dev_err(&pdev->dev, "pin desc prepare fail with %d\n",
- ret);
+ dev_err(&pdev->dev, "pin desc prepare fail with %d\n", ret);
return ret;
}

ret = zynqmp_pinctrl_prepare_function_info(&pdev->dev, pctrl);
if (ret) {
- dev_err(&pdev->dev, "function info prepare fail with %d\n",
- ret);
+ dev_err(&pdev->dev, "function info prepare fail with %d\n", ret);
return ret;
}

- pctrl->pctrl = pinctrl_register(&zynqmp_desc, &pdev->dev, pctrl);
+ pctrl->pctrl = devm_pinctrl_register(&pdev->dev, &zynqmp_desc, pctrl);
if (IS_ERR(pctrl->pctrl))
return PTR_ERR(pctrl->pctrl);

@@ -887,7 +879,6 @@ static const struct of_device_id zynqmp_pinctrl_of_match[] = {
{ .compatible = "xlnx,zynqmp-pinctrl" },
{ }
};
-
MODULE_DEVICE_TABLE(of, zynqmp_pinctrl_of_match);

static struct platform_driver zynqmp_pinctrl_driver = {
@@ -898,7 +889,6 @@ static struct platform_driver zynqmp_pinctrl_driver = {
.probe = zynqmp_pinctrl_probe,
.remove = zynqmp_pinctrl_remove,
};
-
module_platform_driver(zynqmp_pinctrl_driver);

MODULE_AUTHOR("Sai Krishna Potthuri <[email protected]>");
--
2.17.1


2021-06-25 23:47:56

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: zynqmp: some code cleanups

On Mon, Jun 21, 2021 at 1:01 PM Sai Krishna Potthuri
<[email protected]> wrote:

> Some minor code cleanups and updates which includes
> - Mention module name under help in Kconfig.
> - Remove extra lines and duplicate Pin range checks.
> - Replace 'return ret' with 'return 0' in success path.
> - Copyright year update.
> - use devm_pinctrl_register() instead pinctrl_register() in probe.
>
> Signed-off-by: Sai Krishna Potthuri <[email protected]>

I like these cleanups, so: patch applied!

Yours,
Linus Walleij