diff options
Diffstat (limited to '')
-rw-r--r-- | drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c | 174 |
1 files changed, 63 insertions, 111 deletions
diff --git a/drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c b/drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c index 0c3e498ae99c..b8566ed898f1 100644 --- a/drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c +++ b/drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c @@ -1,10 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0 /* - * linux/drivers/pinctrl/pinctrl-rt2880.c - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * publishhed by the Free Software Foundation. - * * Copyright (C) 2013 John Crispin <blogic@openwrt.org> */ @@ -25,6 +20,7 @@ #include <asm/mach-ralink/mt7620.h> #include "core.h" +#include "pinctrl-utils.h" #define SYSC_REG_GPIO_MODE 0x60 #define SYSC_REG_GPIO_MODE2 0x64 @@ -42,7 +38,7 @@ struct rt2880_priv { const char **group_names; int group_count; - uint8_t *gpio; + u8 *gpio; int max_pins; }; @@ -54,20 +50,17 @@ static int rt2880_get_group_count(struct pinctrl_dev *pctrldev) } static const char *rt2880_get_group_name(struct pinctrl_dev *pctrldev, - unsigned group) + unsigned int group) { struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev); - if (group >= p->group_count) - return NULL; - - return p->group_names[group]; + return (group >= p->group_count) ? NULL : p->group_names[group]; } static int rt2880_get_group_pins(struct pinctrl_dev *pctrldev, - unsigned group, - const unsigned **pins, - unsigned *num_pins) + unsigned int group, + const unsigned int **pins, + unsigned int *num_pins) { struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev); @@ -80,78 +73,38 @@ static int rt2880_get_group_pins(struct pinctrl_dev *pctrldev, return 0; } -static void rt2880_pinctrl_dt_free_map(struct pinctrl_dev *pctrldev, - struct pinctrl_map *map, unsigned num_maps) -{ - int i; - - for (i = 0; i < num_maps; i++) - if (map[i].type == PIN_MAP_TYPE_CONFIGS_PIN || - map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP) - kfree(map[i].data.configs.configs); - kfree(map); -} - -static void rt2880_pinctrl_pin_dbg_show(struct pinctrl_dev *pctrldev, - struct seq_file *s, - unsigned offset) -{ - seq_printf(s, "ralink pio"); -} - -static void rt2880_pinctrl_dt_subnode_to_map(struct pinctrl_dev *pctrldev, - struct device_node *np, - struct pinctrl_map **map) -{ - const char *function; - int func = of_property_read_string(np, "ralink,function", &function); - int grps = of_property_count_strings(np, "ralink,group"); - int i; - - if (func || !grps) - return; - - for (i = 0; i < grps; i++) { - const char *group; - - of_property_read_string_index(np, "ralink,group", i, &group); - - (*map)->type = PIN_MAP_TYPE_MUX_GROUP; - (*map)->name = function; - (*map)->data.mux.group = group; - (*map)->data.mux.function = function; - (*map)++; - } -} - static int rt2880_pinctrl_dt_node_to_map(struct pinctrl_dev *pctrldev, - struct device_node *np_config, - struct pinctrl_map **map, - unsigned *num_maps) + struct device_node *np_config, + struct pinctrl_map **map, + unsigned int *num_maps) { - int max_maps = 0; - struct pinctrl_map *tmp; - struct device_node *np; - - for_each_child_of_node(np_config, np) { - int ret = of_property_count_strings(np, "ralink,group"); - - if (ret >= 0) - max_maps += ret; + struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev); + struct property *prop; + const char *function_name, *group_name; + int ret; + int ngroups; + unsigned int reserved_maps = 0; + + for_each_node_with_property(np_config, "group") + ngroups++; + + *map = NULL; + ret = pinctrl_utils_reserve_map(pctrldev, map, &reserved_maps, + num_maps, ngroups); + if (ret) { + dev_err(p->dev, "can't reserve map: %d\n", ret); + return ret; } - if (!max_maps) - return max_maps; - - *map = kcalloc(max_maps, sizeof(struct pinctrl_map), GFP_KERNEL); - if (!*map) - return -ENOMEM; - - tmp = *map; - - for_each_child_of_node(np_config, np) - rt2880_pinctrl_dt_subnode_to_map(pctrldev, np, &tmp); - *num_maps = max_maps; + of_property_for_each_string(np_config, "group", prop, group_name) { + ret = pinctrl_utils_add_map_mux(pctrldev, map, &reserved_maps, + num_maps, group_name, + function_name); + if (ret) { + dev_err(p->dev, "can't add map: %d\n", ret); + return ret; + } + } return 0; } @@ -160,9 +113,8 @@ static const struct pinctrl_ops rt2880_pctrl_ops = { .get_groups_count = rt2880_get_group_count, .get_group_name = rt2880_get_group_name, .get_group_pins = rt2880_get_group_pins, - .pin_dbg_show = rt2880_pinctrl_pin_dbg_show, .dt_node_to_map = rt2880_pinctrl_dt_node_to_map, - .dt_free_map = rt2880_pinctrl_dt_free_map, + .dt_free_map = pinctrl_utils_free_map, }; static int rt2880_pmx_func_count(struct pinctrl_dev *pctrldev) @@ -173,7 +125,7 @@ static int rt2880_pmx_func_count(struct pinctrl_dev *pctrldev) } static const char *rt2880_pmx_func_name(struct pinctrl_dev *pctrldev, - unsigned func) + unsigned int func) { struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev); @@ -181,9 +133,9 @@ static const char *rt2880_pmx_func_name(struct pinctrl_dev *pctrldev, } static int rt2880_pmx_group_get_groups(struct pinctrl_dev *pctrldev, - unsigned func, - const char * const **groups, - unsigned * const num_groups) + unsigned int func, + const char * const **groups, + unsigned int * const num_groups) { struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev); @@ -198,18 +150,18 @@ static int rt2880_pmx_group_get_groups(struct pinctrl_dev *pctrldev, } static int rt2880_pmx_group_enable(struct pinctrl_dev *pctrldev, - unsigned func, - unsigned group) + unsigned int func, unsigned int group) { struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev); - u32 mode = 0; + u32 mode = 0; u32 reg = SYSC_REG_GPIO_MODE; int i; int shift; /* dont allow double use */ if (p->groups[group].enabled) { - dev_err(p->dev, "%s is already enabled\n", p->groups[group].name); + dev_err(p->dev, "%s is already enabled\n", + p->groups[group].name); return -EBUSY; } @@ -242,8 +194,8 @@ static int rt2880_pmx_group_enable(struct pinctrl_dev *pctrldev, } static int rt2880_pmx_group_gpio_request_enable(struct pinctrl_dev *pctrldev, - struct pinctrl_gpio_range *range, - unsigned pin) + struct pinctrl_gpio_range *range, + unsigned int pin) { struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev); @@ -287,8 +239,8 @@ static int rt2880_pinmux_index(struct rt2880_priv *p) } /* allocate the group names array needed by the gpio function */ - p->group_names = devm_kcalloc(p->dev, p->group_count, sizeof(char *), - GFP_KERNEL); + p->group_names = devm_kcalloc(p->dev, p->group_count, + sizeof(char *), GFP_KERNEL); if (!p->group_names) return -1; @@ -322,7 +274,8 @@ static int rt2880_pinmux_index(struct rt2880_priv *p) for (i = 0; i < p->group_count; i++) { for (j = 0; j < p->groups[i].func_count; j++) { f[c] = &p->groups[i].func[j]; - f[c]->groups = devm_kzalloc(p->dev, sizeof(int), GFP_KERNEL); + f[c]->groups = devm_kzalloc(p->dev, sizeof(int), + GFP_KERNEL); f[c]->groups[0] = i; f[c]->group_count = 1; c++; @@ -335,7 +288,10 @@ static int rt2880_pinmux_pins(struct rt2880_priv *p) { int i, j; - /* loop over the functions and initialize the pins array. also work out the highest pin used */ + /* + * loop over the functions and initialize the pins array. + * also work out the highest pin used. + */ for (i = 0; i < p->func_count; i++) { int pin; @@ -355,18 +311,16 @@ static int rt2880_pinmux_pins(struct rt2880_priv *p) } /* the buffer that tells us which pins are gpio */ - p->gpio = devm_kcalloc(p->dev,p->max_pins, sizeof(uint8_t), - GFP_KERNEL); + p->gpio = devm_kcalloc(p->dev, p->max_pins, sizeof(u8), GFP_KERNEL); /* the pads needed to tell pinctrl about our pins */ - p->pads = devm_kcalloc(p->dev, - p->max_pins, sizeof(struct pinctrl_pin_desc), - GFP_KERNEL); - if (!p->pads || !p->gpio ) { + p->pads = devm_kcalloc(p->dev, p->max_pins, + sizeof(struct pinctrl_pin_desc), GFP_KERNEL); + if (!p->pads || !p->gpio) { dev_err(p->dev, "Failed to allocate gpio data\n"); return -ENOMEM; } - memset(p->gpio, 1, sizeof(uint8_t) * p->max_pins); + memset(p->gpio, 1, sizeof(u8) * p->max_pins); for (i = 0; i < p->func_count; i++) { if (!p->func[i]->pin_count) continue; @@ -383,10 +337,8 @@ static int rt2880_pinmux_pins(struct rt2880_priv *p) /* strlen("ioXY") + 1 = 5 */ char *name = devm_kzalloc(p->dev, 5, GFP_KERNEL); - if (!name) { - dev_err(p->dev, "Failed to allocate pad name\n"); + if (!name) return -ENOMEM; - } snprintf(name, 5, "io%d", i); p->pads[i].number = i; p->pads[i].name = name; @@ -404,7 +356,7 @@ static int rt2880_pinmux_probe(struct platform_device *pdev) struct device_node *np; if (!rt2880_pinmux_data) - return -ENOSYS; + return -ENOTSUPP; /* setup the private data */ p = devm_kzalloc(&pdev->dev, sizeof(struct rt2880_priv), GFP_KERNEL); @@ -445,7 +397,7 @@ static int rt2880_pinmux_probe(struct platform_device *pdev) return -EINVAL; } - range = devm_kzalloc(p->dev, sizeof(struct pinctrl_gpio_range) + 4, GFP_KERNEL); + range = devm_kzalloc(p->dev, sizeof(*range) + 4, GFP_KERNEL); range->name = name = (char *) &range[1]; sprintf(name, "pio"); range->npins = __be32_to_cpu(*ngpio); |