2018-09-07 10:13:29 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2012-07-10 11:08:14 +08:00
|
|
|
/*
|
|
|
|
* SuperH Pin Function Controller pinmux support.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Paul Mundt
|
|
|
|
*/
|
2012-07-20 15:18:21 +08:00
|
|
|
|
2012-12-16 06:50:47 +08:00
|
|
|
#define DRV_NAME "sh-pfc"
|
2012-07-10 11:08:14 +08:00
|
|
|
|
2012-12-16 06:50:48 +08:00
|
|
|
#include <linux/device.h>
|
2012-12-16 06:50:52 +08:00
|
|
|
#include <linux/err.h>
|
2021-03-03 21:26:16 +08:00
|
|
|
#include <linux/io.h>
|
2012-07-10 11:08:14 +08:00
|
|
|
#include <linux/module.h>
|
2013-06-18 02:50:02 +08:00
|
|
|
#include <linux/of.h>
|
2022-10-07 21:44:44 +08:00
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
|
2012-07-10 11:08:14 +08:00
|
|
|
#include <linux/pinctrl/consumer.h>
|
2013-06-18 02:50:02 +08:00
|
|
|
#include <linux/pinctrl/machine.h>
|
2012-07-10 11:08:14 +08:00
|
|
|
#include <linux/pinctrl/pinconf-generic.h>
|
2022-10-07 21:44:44 +08:00
|
|
|
#include <linux/pinctrl/pinconf.h>
|
2012-12-16 06:50:52 +08:00
|
|
|
#include <linux/pinctrl/pinctrl.h>
|
|
|
|
#include <linux/pinctrl/pinmux.h>
|
2012-07-10 11:08:14 +08:00
|
|
|
|
2012-12-16 06:50:44 +08:00
|
|
|
#include "core.h"
|
2013-03-10 23:44:02 +08:00
|
|
|
#include "../core.h"
|
|
|
|
#include "../pinconf.h"
|
2012-12-16 06:50:44 +08:00
|
|
|
|
2013-03-09 00:43:54 +08:00
|
|
|
struct sh_pfc_pin_config {
|
2020-10-28 23:16:33 +08:00
|
|
|
u16 gpio_enabled:1;
|
|
|
|
u16 mux_mark:15;
|
2013-03-09 00:43:54 +08:00
|
|
|
};
|
|
|
|
|
2012-07-10 11:08:14 +08:00
|
|
|
struct sh_pfc_pinctrl {
|
|
|
|
struct pinctrl_dev *pctl;
|
2013-02-16 23:38:30 +08:00
|
|
|
struct pinctrl_desc pctl_desc;
|
|
|
|
|
2012-07-10 11:08:14 +08:00
|
|
|
struct sh_pfc *pfc;
|
|
|
|
|
2013-01-03 21:33:13 +08:00
|
|
|
struct pinctrl_pin_desc *pins;
|
2013-03-09 00:43:54 +08:00
|
|
|
struct sh_pfc_pin_config *configs;
|
2012-07-10 11:08:14 +08:00
|
|
|
};
|
|
|
|
|
2012-07-17 14:48:18 +08:00
|
|
|
static int sh_pfc_get_groups_count(struct pinctrl_dev *pctldev)
|
2012-07-10 11:08:14 +08:00
|
|
|
{
|
2012-07-17 14:48:18 +08:00
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
2013-01-03 21:33:13 +08:00
|
|
|
return pmx->pfc->info->nr_groups;
|
2012-07-10 11:08:14 +08:00
|
|
|
}
|
|
|
|
|
2012-07-17 14:48:18 +08:00
|
|
|
static const char *sh_pfc_get_group_name(struct pinctrl_dev *pctldev,
|
2012-07-10 11:08:14 +08:00
|
|
|
unsigned selector)
|
|
|
|
{
|
2012-07-17 14:48:18 +08:00
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
2013-01-03 21:33:13 +08:00
|
|
|
return pmx->pfc->info->groups[selector].name;
|
2012-07-10 11:08:14 +08:00
|
|
|
}
|
|
|
|
|
2013-01-03 21:33:13 +08:00
|
|
|
static int sh_pfc_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
|
2012-07-10 11:08:14 +08:00
|
|
|
const unsigned **pins, unsigned *num_pins)
|
|
|
|
{
|
2012-07-17 14:48:18 +08:00
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
2013-01-03 21:33:13 +08:00
|
|
|
*pins = pmx->pfc->info->groups[selector].pins;
|
|
|
|
*num_pins = pmx->pfc->info->groups[selector].nr_pins;
|
2012-07-17 14:48:18 +08:00
|
|
|
|
|
|
|
return 0;
|
2012-07-10 11:08:14 +08:00
|
|
|
}
|
|
|
|
|
2012-07-20 15:39:09 +08:00
|
|
|
static void sh_pfc_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
|
|
|
|
unsigned offset)
|
|
|
|
{
|
2018-01-07 04:50:20 +08:00
|
|
|
seq_puts(s, DRV_NAME);
|
2012-07-20 15:39:09 +08:00
|
|
|
}
|
|
|
|
|
2013-06-19 19:26:02 +08:00
|
|
|
#ifdef CONFIG_OF
|
2013-06-18 02:50:03 +08:00
|
|
|
static int sh_pfc_map_add_config(struct pinctrl_map *map,
|
|
|
|
const char *group_or_pin,
|
|
|
|
enum pinctrl_map_type type,
|
|
|
|
unsigned long *configs,
|
|
|
|
unsigned int num_configs)
|
|
|
|
{
|
|
|
|
unsigned long *cfgs;
|
|
|
|
|
|
|
|
cfgs = kmemdup(configs, num_configs * sizeof(*cfgs),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (cfgs == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
map->type = type;
|
|
|
|
map->data.configs.group_or_pin = group_or_pin;
|
|
|
|
map->data.configs.configs = cfgs;
|
|
|
|
map->data.configs.num_configs = num_configs;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-30 16:29:57 +08:00
|
|
|
static int sh_pfc_dt_subnode_to_map(struct pinctrl_dev *pctldev,
|
|
|
|
struct device_node *np,
|
2013-06-18 02:50:02 +08:00
|
|
|
struct pinctrl_map **map,
|
|
|
|
unsigned int *num_maps, unsigned int *index)
|
|
|
|
{
|
2015-06-30 16:29:57 +08:00
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
struct device *dev = pmx->pfc->dev;
|
2013-06-18 02:50:02 +08:00
|
|
|
struct pinctrl_map *maps = *map;
|
|
|
|
unsigned int nmaps = *num_maps;
|
|
|
|
unsigned int idx = *index;
|
2013-06-18 02:50:03 +08:00
|
|
|
unsigned int num_configs;
|
2013-06-18 02:50:02 +08:00
|
|
|
const char *function = NULL;
|
2013-06-18 02:50:03 +08:00
|
|
|
unsigned long *configs;
|
2013-06-18 02:50:02 +08:00
|
|
|
struct property *prop;
|
2013-06-18 02:50:03 +08:00
|
|
|
unsigned int num_groups;
|
|
|
|
unsigned int num_pins;
|
2013-06-18 02:50:02 +08:00
|
|
|
const char *group;
|
2013-06-18 02:50:03 +08:00
|
|
|
const char *pin;
|
2013-06-18 02:50:02 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Parse the function and configuration properties. At least a function
|
|
|
|
* or one configuration must be specified.
|
|
|
|
*/
|
2023-03-13 18:49:04 +08:00
|
|
|
ret = of_property_read_string(np, "function", &function);
|
2013-06-18 02:50:02 +08:00
|
|
|
if (ret < 0 && ret != -EINVAL) {
|
|
|
|
dev_err(dev, "Invalid function in DT\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-01-09 23:43:46 +08:00
|
|
|
ret = pinconf_generic_parse_dt_config(np, NULL, &configs, &num_configs);
|
2013-06-18 02:50:03 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!function && num_configs == 0) {
|
|
|
|
dev_err(dev,
|
|
|
|
"DT node must contain at least a function or config\n");
|
2015-06-30 16:29:57 +08:00
|
|
|
ret = -ENODEV;
|
2013-06-18 02:50:02 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2013-06-18 02:50:03 +08:00
|
|
|
/* Count the number of pins and groups and reallocate mappings. */
|
2023-03-13 18:49:04 +08:00
|
|
|
ret = of_property_count_strings(np, "pins");
|
2013-06-18 02:50:03 +08:00
|
|
|
if (ret == -EINVAL) {
|
|
|
|
num_pins = 0;
|
|
|
|
} else if (ret < 0) {
|
|
|
|
dev_err(dev, "Invalid pins list in DT\n");
|
|
|
|
goto done;
|
|
|
|
} else {
|
|
|
|
num_pins = ret;
|
|
|
|
}
|
|
|
|
|
2023-03-13 18:49:04 +08:00
|
|
|
ret = of_property_count_strings(np, "groups");
|
2013-06-18 02:50:03 +08:00
|
|
|
if (ret == -EINVAL) {
|
|
|
|
num_groups = 0;
|
|
|
|
} else if (ret < 0) {
|
2013-06-18 02:50:02 +08:00
|
|
|
dev_err(dev, "Invalid pin groups list in DT\n");
|
|
|
|
goto done;
|
2013-06-18 02:50:03 +08:00
|
|
|
} else {
|
|
|
|
num_groups = ret;
|
2013-06-18 02:50:02 +08:00
|
|
|
}
|
|
|
|
|
2013-06-18 02:50:03 +08:00
|
|
|
if (!num_pins && !num_groups) {
|
|
|
|
dev_err(dev, "No pin or group provided in DT node\n");
|
2013-06-18 02:50:02 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2013-06-18 02:50:03 +08:00
|
|
|
if (function)
|
|
|
|
nmaps += num_groups;
|
|
|
|
if (configs)
|
|
|
|
nmaps += num_pins + num_groups;
|
2013-06-18 02:50:02 +08:00
|
|
|
|
|
|
|
maps = krealloc(maps, sizeof(*maps) * nmaps, GFP_KERNEL);
|
|
|
|
if (maps == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
*map = maps;
|
|
|
|
*num_maps = nmaps;
|
|
|
|
|
|
|
|
/* Iterate over pins and groups and create the mappings. */
|
2023-03-13 18:49:04 +08:00
|
|
|
of_property_for_each_string(np, "groups", prop, group) {
|
2013-06-18 02:50:03 +08:00
|
|
|
if (function) {
|
|
|
|
maps[idx].type = PIN_MAP_TYPE_MUX_GROUP;
|
|
|
|
maps[idx].data.mux.group = group;
|
|
|
|
maps[idx].data.mux.function = function;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (configs) {
|
|
|
|
ret = sh_pfc_map_add_config(&maps[idx], group,
|
|
|
|
PIN_MAP_TYPE_CONFIGS_GROUP,
|
|
|
|
configs, num_configs);
|
|
|
|
if (ret < 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
2013-06-18 02:50:02 +08:00
|
|
|
}
|
|
|
|
|
2013-06-18 02:50:03 +08:00
|
|
|
if (!configs) {
|
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2023-03-13 18:49:04 +08:00
|
|
|
of_property_for_each_string(np, "pins", prop, pin) {
|
2013-06-18 02:50:03 +08:00
|
|
|
ret = sh_pfc_map_add_config(&maps[idx], pin,
|
|
|
|
PIN_MAP_TYPE_CONFIGS_PIN,
|
|
|
|
configs, num_configs);
|
|
|
|
if (ret < 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
2013-06-18 02:50:02 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
*index = idx;
|
2013-06-18 02:50:03 +08:00
|
|
|
kfree(configs);
|
2013-06-18 02:50:02 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_pfc_dt_free_map(struct pinctrl_dev *pctldev,
|
|
|
|
struct pinctrl_map *map, unsigned num_maps)
|
|
|
|
{
|
2013-06-18 02:50:03 +08:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (map == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < num_maps; ++i) {
|
|
|
|
if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP ||
|
|
|
|
map[i].type == PIN_MAP_TYPE_CONFIGS_PIN)
|
|
|
|
kfree(map[i].data.configs.configs);
|
|
|
|
}
|
|
|
|
|
2013-06-18 02:50:02 +08:00
|
|
|
kfree(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_pfc_dt_node_to_map(struct pinctrl_dev *pctldev,
|
|
|
|
struct device_node *np,
|
|
|
|
struct pinctrl_map **map, unsigned *num_maps)
|
|
|
|
{
|
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
struct device *dev = pmx->pfc->dev;
|
|
|
|
struct device_node *child;
|
|
|
|
unsigned int index;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
*map = NULL;
|
|
|
|
*num_maps = 0;
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
for_each_child_of_node(np, child) {
|
2015-06-30 16:29:57 +08:00
|
|
|
ret = sh_pfc_dt_subnode_to_map(pctldev, child, map, num_maps,
|
2013-06-18 02:50:02 +08:00
|
|
|
&index);
|
2015-12-22 00:39:46 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
of_node_put(child);
|
2013-06-18 02:50:02 +08:00
|
|
|
goto done;
|
2015-12-22 00:39:46 +08:00
|
|
|
}
|
2013-06-18 02:50:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If no mapping has been found in child nodes try the config node. */
|
|
|
|
if (*num_maps == 0) {
|
2015-06-30 16:29:57 +08:00
|
|
|
ret = sh_pfc_dt_subnode_to_map(pctldev, np, map, num_maps,
|
|
|
|
&index);
|
2013-06-18 02:50:02 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*num_maps)
|
|
|
|
return 0;
|
|
|
|
|
2017-07-19 05:43:23 +08:00
|
|
|
dev_err(dev, "no mapping found in node %pOF\n", np);
|
2013-06-18 02:50:02 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (ret < 0)
|
|
|
|
sh_pfc_dt_free_map(pctldev, *map, *num_maps);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2013-06-19 19:26:02 +08:00
|
|
|
#endif /* CONFIG_OF */
|
2013-06-18 02:50:02 +08:00
|
|
|
|
2013-02-15 23:04:47 +08:00
|
|
|
static const struct pinctrl_ops sh_pfc_pinctrl_ops = {
|
2012-07-17 14:48:18 +08:00
|
|
|
.get_groups_count = sh_pfc_get_groups_count,
|
|
|
|
.get_group_name = sh_pfc_get_group_name,
|
2012-07-10 11:08:14 +08:00
|
|
|
.get_group_pins = sh_pfc_get_group_pins,
|
2012-07-20 15:39:09 +08:00
|
|
|
.pin_dbg_show = sh_pfc_pin_dbg_show,
|
2013-06-19 19:26:02 +08:00
|
|
|
#ifdef CONFIG_OF
|
2013-06-18 02:50:02 +08:00
|
|
|
.dt_node_to_map = sh_pfc_dt_node_to_map,
|
|
|
|
.dt_free_map = sh_pfc_dt_free_map,
|
2013-06-19 19:26:02 +08:00
|
|
|
#endif
|
2012-07-10 11:08:14 +08:00
|
|
|
};
|
|
|
|
|
2012-07-11 16:17:10 +08:00
|
|
|
static int sh_pfc_get_functions_count(struct pinctrl_dev *pctldev)
|
|
|
|
{
|
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
2013-01-03 21:33:13 +08:00
|
|
|
return pmx->pfc->info->nr_functions;
|
2012-07-11 16:17:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *sh_pfc_get_function_name(struct pinctrl_dev *pctldev,
|
|
|
|
unsigned selector)
|
|
|
|
{
|
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
2013-01-03 21:33:13 +08:00
|
|
|
return pmx->pfc->info->functions[selector].name;
|
2012-07-11 16:17:10 +08:00
|
|
|
}
|
2012-07-10 11:08:14 +08:00
|
|
|
|
2013-01-03 21:33:13 +08:00
|
|
|
static int sh_pfc_get_function_groups(struct pinctrl_dev *pctldev,
|
|
|
|
unsigned selector,
|
2012-07-10 11:08:14 +08:00
|
|
|
const char * const **groups,
|
|
|
|
unsigned * const num_groups)
|
|
|
|
{
|
2012-07-11 16:17:10 +08:00
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
|
2013-01-03 21:33:13 +08:00
|
|
|
*groups = pmx->pfc->info->functions[selector].groups;
|
|
|
|
*num_groups = pmx->pfc->info->functions[selector].nr_groups;
|
2012-07-11 16:17:10 +08:00
|
|
|
|
2012-07-10 11:08:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-03 19:02:56 +08:00
|
|
|
static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector,
|
|
|
|
unsigned group)
|
2012-07-10 11:08:14 +08:00
|
|
|
{
|
2013-01-03 21:33:13 +08:00
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
struct sh_pfc *pfc = pmx->pfc;
|
|
|
|
const struct sh_pfc_pin_group *grp = &pfc->info->groups[group];
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int i;
|
2013-03-10 23:38:23 +08:00
|
|
|
int ret = 0;
|
2013-01-03 21:33:13 +08:00
|
|
|
|
2018-12-26 16:23:27 +08:00
|
|
|
dev_dbg(pctldev->dev, "Configuring pin group %s\n", grp->name);
|
|
|
|
|
2013-01-03 21:33:13 +08:00
|
|
|
spin_lock_irqsave(&pfc->lock, flags);
|
|
|
|
|
|
|
|
for (i = 0; i < grp->nr_pins; ++i) {
|
2019-08-08 14:19:03 +08:00
|
|
|
int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
|
|
|
|
struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This driver cannot manage both gpio and mux when the gpio
|
|
|
|
* pin is already enabled. So, this function fails.
|
|
|
|
*/
|
2019-08-27 17:39:27 +08:00
|
|
|
if (cfg->gpio_enabled) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto done;
|
|
|
|
}
|
2019-08-08 14:19:03 +08:00
|
|
|
|
2013-03-10 23:38:23 +08:00
|
|
|
ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION);
|
|
|
|
if (ret < 0)
|
2019-08-08 14:19:01 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2020-10-28 23:16:33 +08:00
|
|
|
/* All group pins are configured, mark the pins as muxed */
|
2019-08-08 14:19:01 +08:00
|
|
|
for (i = 0; i < grp->nr_pins; ++i) {
|
|
|
|
int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
|
|
|
|
struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
|
|
|
|
|
2019-08-08 14:19:03 +08:00
|
|
|
cfg->mux_mark = grp->mux[i];
|
2013-01-03 21:33:13 +08:00
|
|
|
}
|
|
|
|
|
2013-03-11 00:25:29 +08:00
|
|
|
done:
|
2013-01-03 21:33:13 +08:00
|
|
|
spin_unlock_irqrestore(&pfc->lock, flags);
|
|
|
|
return ret;
|
2012-07-10 11:08:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
|
|
|
|
struct pinctrl_gpio_range *range,
|
|
|
|
unsigned offset)
|
|
|
|
{
|
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
struct sh_pfc *pfc = pmx->pfc;
|
2013-03-09 00:43:54 +08:00
|
|
|
int idx = sh_pfc_get_pin_index(pfc, offset);
|
|
|
|
struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
|
2012-07-10 11:08:14 +08:00
|
|
|
unsigned long flags;
|
2013-03-09 00:43:54 +08:00
|
|
|
int ret;
|
2012-07-10 11:08:14 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&pfc->lock, flags);
|
|
|
|
|
2021-12-10 19:32:26 +08:00
|
|
|
if (!pfc->gpio && !cfg->mux_mark) {
|
2020-10-28 23:16:31 +08:00
|
|
|
/* If GPIOs are handled externally the pin mux type needs to be
|
2013-03-11 00:30:25 +08:00
|
|
|
* set to GPIO here.
|
|
|
|
*/
|
|
|
|
const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
|
|
|
|
|
|
|
|
ret = sh_pfc_config_mux(pfc, pin->enum_id, PINMUX_TYPE_GPIO);
|
|
|
|
if (ret < 0)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2019-08-08 14:19:01 +08:00
|
|
|
cfg->gpio_enabled = true;
|
2013-03-11 00:25:29 +08:00
|
|
|
|
2012-07-10 11:08:14 +08:00
|
|
|
ret = 0;
|
|
|
|
|
2013-03-11 00:25:29 +08:00
|
|
|
done:
|
2012-07-10 11:08:14 +08:00
|
|
|
spin_unlock_irqrestore(&pfc->lock, flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev,
|
|
|
|
struct pinctrl_gpio_range *range,
|
|
|
|
unsigned offset)
|
|
|
|
{
|
2013-03-11 00:25:29 +08:00
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
struct sh_pfc *pfc = pmx->pfc;
|
|
|
|
int idx = sh_pfc_get_pin_index(pfc, offset);
|
|
|
|
struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pfc->lock, flags);
|
2019-08-08 14:19:01 +08:00
|
|
|
cfg->gpio_enabled = false;
|
2019-08-08 14:19:03 +08:00
|
|
|
/* If mux is already set, this configures it here */
|
2020-10-28 23:16:33 +08:00
|
|
|
if (cfg->mux_mark)
|
2019-08-08 14:19:03 +08:00
|
|
|
sh_pfc_config_mux(pfc, cfg->mux_mark, PINMUX_TYPE_FUNCTION);
|
2013-03-11 00:25:29 +08:00
|
|
|
spin_unlock_irqrestore(&pfc->lock, flags);
|
2012-07-10 11:08:14 +08:00
|
|
|
}
|
|
|
|
|
pinctrl: renesas: Protect GPIO leftovers by CONFIG_PINCTRL_SH_FUNC_GPIO
On SuperH and ARM SH/R-Mobile SoCs, the pin control driver handles
GPIOs, too. To reduce code size when compiling a kernel supporting only
modern SoCs, most, but not all, of the GPIO functionality is protected
by checks for CONFIG_PINCTRL_SH_FUNC_GPIO.
Factor out the remaining parts when not needed:
1. sh_pfc_soc_info.{in,out}put describe GPIO pins that have input
resp. output capabilities (SuperH and SH/R-Mobile).
2. sh_pfc_soc_info.gpio_irq{,_size} describe the mapping from GPIO
pins to interrupt numbers (SH/R-Mobile).
3. sh_pfc_gpio_set_direction() configures GPIO direction, called from
the GPIO driver through pinctrl_gpio_direction_{in,out}put()
(SH/R-Mobile). Unfortunately this function cannot just be moved to
drivers/pinctrl/renesas/gpio.c, as it relies on knowledge of
sh_pfc_pinctrl, which is internal to
drivers/pinctrl/renesas/pinctrl.c.
While code size reduction is minimal, this does help in documenting
depencies.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20201028151637.1734130-9-geert+renesas@glider.be
2020-10-28 23:16:37 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_SH_PFC_GPIO
|
2012-07-10 11:08:14 +08:00
|
|
|
static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev,
|
|
|
|
struct pinctrl_gpio_range *range,
|
|
|
|
unsigned offset, bool input)
|
|
|
|
{
|
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
2013-03-10 23:55:19 +08:00
|
|
|
struct sh_pfc *pfc = pmx->pfc;
|
|
|
|
int new_type = input ? PINMUX_TYPE_INPUT : PINMUX_TYPE_OUTPUT;
|
|
|
|
int idx = sh_pfc_get_pin_index(pfc, offset);
|
|
|
|
const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
|
|
|
|
unsigned long flags;
|
2013-03-14 01:18:30 +08:00
|
|
|
unsigned int dir;
|
2013-03-10 23:55:19 +08:00
|
|
|
int ret;
|
2012-07-10 11:08:14 +08:00
|
|
|
|
2020-10-28 23:16:31 +08:00
|
|
|
/* Check if the requested direction is supported by the pin. Not all
|
|
|
|
* SoCs provide pin config data, so perform the check conditionally.
|
2013-03-14 01:18:30 +08:00
|
|
|
*/
|
|
|
|
if (pin->configs) {
|
|
|
|
dir = input ? SH_PFC_PIN_CFG_INPUT : SH_PFC_PIN_CFG_OUTPUT;
|
|
|
|
if (!(pin->configs & dir))
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-03-10 23:55:19 +08:00
|
|
|
spin_lock_irqsave(&pfc->lock, flags);
|
2013-03-11 00:25:29 +08:00
|
|
|
ret = sh_pfc_config_mux(pfc, pin->enum_id, new_type);
|
2013-03-10 23:55:19 +08:00
|
|
|
spin_unlock_irqrestore(&pfc->lock, flags);
|
|
|
|
return ret;
|
2012-07-10 11:08:14 +08:00
|
|
|
}
|
pinctrl: renesas: Protect GPIO leftovers by CONFIG_PINCTRL_SH_FUNC_GPIO
On SuperH and ARM SH/R-Mobile SoCs, the pin control driver handles
GPIOs, too. To reduce code size when compiling a kernel supporting only
modern SoCs, most, but not all, of the GPIO functionality is protected
by checks for CONFIG_PINCTRL_SH_FUNC_GPIO.
Factor out the remaining parts when not needed:
1. sh_pfc_soc_info.{in,out}put describe GPIO pins that have input
resp. output capabilities (SuperH and SH/R-Mobile).
2. sh_pfc_soc_info.gpio_irq{,_size} describe the mapping from GPIO
pins to interrupt numbers (SH/R-Mobile).
3. sh_pfc_gpio_set_direction() configures GPIO direction, called from
the GPIO driver through pinctrl_gpio_direction_{in,out}put()
(SH/R-Mobile). Unfortunately this function cannot just be moved to
drivers/pinctrl/renesas/gpio.c, as it relies on knowledge of
sh_pfc_pinctrl, which is internal to
drivers/pinctrl/renesas/pinctrl.c.
While code size reduction is minimal, this does help in documenting
depencies.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20201028151637.1734130-9-geert+renesas@glider.be
2020-10-28 23:16:37 +08:00
|
|
|
#else
|
|
|
|
#define sh_pfc_gpio_set_direction NULL
|
|
|
|
#endif
|
2012-07-10 11:08:14 +08:00
|
|
|
|
2013-02-15 23:04:47 +08:00
|
|
|
static const struct pinmux_ops sh_pfc_pinmux_ops = {
|
2012-07-11 16:17:10 +08:00
|
|
|
.get_functions_count = sh_pfc_get_functions_count,
|
|
|
|
.get_function_name = sh_pfc_get_function_name,
|
2012-07-10 11:08:14 +08:00
|
|
|
.get_function_groups = sh_pfc_get_function_groups,
|
2014-09-03 19:02:56 +08:00
|
|
|
.set_mux = sh_pfc_func_set_mux,
|
2012-07-10 11:08:14 +08:00
|
|
|
.gpio_request_enable = sh_pfc_gpio_request_enable,
|
|
|
|
.gpio_disable_free = sh_pfc_gpio_disable_free,
|
|
|
|
.gpio_set_direction = sh_pfc_gpio_set_direction,
|
|
|
|
};
|
|
|
|
|
2016-03-23 22:06:00 +08:00
|
|
|
static u32 sh_pfc_pinconf_find_drive_strength_reg(struct sh_pfc *pfc,
|
|
|
|
unsigned int pin, unsigned int *offset, unsigned int *size)
|
|
|
|
{
|
|
|
|
const struct pinmux_drive_reg_field *field;
|
|
|
|
const struct pinmux_drive_reg *reg;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (reg = pfc->info->drive_regs; reg->reg; ++reg) {
|
|
|
|
for (i = 0; i < ARRAY_SIZE(reg->fields); ++i) {
|
|
|
|
field = ®->fields[i];
|
|
|
|
|
|
|
|
if (field->size && field->pin == pin) {
|
|
|
|
*offset = field->offset;
|
|
|
|
*size = field->size;
|
|
|
|
|
|
|
|
return reg->reg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_pfc_pinconf_get_drive_strength(struct sh_pfc *pfc,
|
|
|
|
unsigned int pin)
|
|
|
|
{
|
|
|
|
unsigned int offset;
|
|
|
|
unsigned int size;
|
|
|
|
u32 reg;
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
reg = sh_pfc_pinconf_find_drive_strength_reg(pfc, pin, &offset, &size);
|
|
|
|
if (!reg)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2021-11-17 17:59:32 +08:00
|
|
|
val = (sh_pfc_read(pfc, reg) >> offset) & GENMASK(size - 1, 0);
|
2016-03-23 22:06:00 +08:00
|
|
|
|
|
|
|
/* Convert the value to mA based on a full drive strength value of 24mA.
|
|
|
|
* We can make the full value configurable later if needed.
|
|
|
|
*/
|
|
|
|
return (val + 1) * (size == 2 ? 6 : 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_pfc_pinconf_set_drive_strength(struct sh_pfc *pfc,
|
|
|
|
unsigned int pin, u16 strength)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int offset;
|
|
|
|
unsigned int size;
|
|
|
|
unsigned int step;
|
|
|
|
u32 reg;
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
reg = sh_pfc_pinconf_find_drive_strength_reg(pfc, pin, &offset, &size);
|
|
|
|
if (!reg)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
step = size == 2 ? 6 : 3;
|
|
|
|
|
|
|
|
if (strength < step || strength > 24)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Convert the value from mA based on a full drive strength value of
|
|
|
|
* 24mA. We can make the full value configurable later if needed.
|
|
|
|
*/
|
|
|
|
strength = strength / step - 1;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pfc->lock, flags);
|
|
|
|
|
2017-09-29 17:03:11 +08:00
|
|
|
val = sh_pfc_read(pfc, reg);
|
2016-03-23 22:06:00 +08:00
|
|
|
val &= ~GENMASK(offset + size - 1, offset);
|
|
|
|
val |= strength << offset;
|
|
|
|
|
2017-09-29 17:03:11 +08:00
|
|
|
sh_pfc_write(pfc, reg, val);
|
2016-03-23 22:06:00 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&pfc->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-10 23:44:02 +08:00
|
|
|
/* Check whether the requested parameter is supported for a pin. */
|
|
|
|
static bool sh_pfc_pinconf_validate(struct sh_pfc *pfc, unsigned int _pin,
|
|
|
|
enum pin_config_param param)
|
|
|
|
{
|
|
|
|
int idx = sh_pfc_get_pin_index(pfc, _pin);
|
|
|
|
const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
|
|
|
|
|
|
|
|
switch (param) {
|
|
|
|
case PIN_CONFIG_BIAS_DISABLE:
|
2019-03-21 23:17:47 +08:00
|
|
|
return pin->configs & SH_PFC_PIN_CFG_PULL_UP_DOWN;
|
2013-03-10 23:44:02 +08:00
|
|
|
|
|
|
|
case PIN_CONFIG_BIAS_PULL_UP:
|
|
|
|
return pin->configs & SH_PFC_PIN_CFG_PULL_UP;
|
|
|
|
|
|
|
|
case PIN_CONFIG_BIAS_PULL_DOWN:
|
|
|
|
return pin->configs & SH_PFC_PIN_CFG_PULL_DOWN;
|
|
|
|
|
2016-03-23 22:06:00 +08:00
|
|
|
case PIN_CONFIG_DRIVE_STRENGTH:
|
|
|
|
return pin->configs & SH_PFC_PIN_CFG_DRIVE_STRENGTH;
|
|
|
|
|
2015-07-01 00:53:59 +08:00
|
|
|
case PIN_CONFIG_POWER_SOURCE:
|
2023-03-08 18:42:39 +08:00
|
|
|
return pin->configs & SH_PFC_PIN_CFG_IO_VOLTAGE_MASK;
|
2015-07-01 00:53:59 +08:00
|
|
|
|
2013-03-10 23:44:02 +08:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 05:35:09 +08:00
|
|
|
static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned _pin,
|
2012-07-10 11:08:14 +08:00
|
|
|
unsigned long *config)
|
|
|
|
{
|
2012-07-20 15:39:09 +08:00
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
struct sh_pfc *pfc = pmx->pfc;
|
2013-03-10 23:44:02 +08:00
|
|
|
enum pin_config_param param = pinconf_to_config_param(*config);
|
|
|
|
unsigned long flags;
|
2016-09-06 23:14:14 +08:00
|
|
|
unsigned int arg;
|
2013-03-10 23:44:02 +08:00
|
|
|
|
|
|
|
if (!sh_pfc_pinconf_validate(pfc, _pin, param))
|
|
|
|
return -ENOTSUPP;
|
|
|
|
|
|
|
|
switch (param) {
|
|
|
|
case PIN_CONFIG_BIAS_DISABLE:
|
|
|
|
case PIN_CONFIG_BIAS_PULL_UP:
|
2015-07-01 00:53:59 +08:00
|
|
|
case PIN_CONFIG_BIAS_PULL_DOWN: {
|
|
|
|
unsigned int bias;
|
|
|
|
|
2013-03-10 23:44:02 +08:00
|
|
|
if (!pfc->info->ops || !pfc->info->ops->get_bias)
|
|
|
|
return -ENOTSUPP;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pfc->lock, flags);
|
|
|
|
bias = pfc->info->ops->get_bias(pfc, _pin);
|
|
|
|
spin_unlock_irqrestore(&pfc->lock, flags);
|
|
|
|
|
|
|
|
if (bias != param)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-09-06 23:14:14 +08:00
|
|
|
arg = 0;
|
2013-03-10 23:44:02 +08:00
|
|
|
break;
|
2015-07-01 00:53:59 +08:00
|
|
|
}
|
|
|
|
|
2016-03-23 22:06:00 +08:00
|
|
|
case PIN_CONFIG_DRIVE_STRENGTH: {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = sh_pfc_pinconf_get_drive_strength(pfc, _pin);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2016-09-06 23:14:14 +08:00
|
|
|
arg = ret;
|
2016-03-23 22:06:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-07-01 00:53:59 +08:00
|
|
|
case PIN_CONFIG_POWER_SOURCE: {
|
2021-01-13 00:59:08 +08:00
|
|
|
int idx = sh_pfc_get_pin_index(pfc, _pin);
|
|
|
|
const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
|
2023-03-08 18:42:39 +08:00
|
|
|
unsigned int mode, lo, hi;
|
2016-06-07 00:08:25 +08:00
|
|
|
u32 pocctrl, val;
|
|
|
|
int bit;
|
2015-07-01 00:53:59 +08:00
|
|
|
|
2016-06-07 00:08:25 +08:00
|
|
|
if (!pfc->info->ops || !pfc->info->ops->pin_to_pocctrl)
|
2015-07-01 00:53:59 +08:00
|
|
|
return -ENOTSUPP;
|
|
|
|
|
2021-12-23 22:56:17 +08:00
|
|
|
bit = pfc->info->ops->pin_to_pocctrl(_pin, &pocctrl);
|
2016-06-07 00:08:25 +08:00
|
|
|
if (WARN(bit < 0, "invalid pin %#x", _pin))
|
|
|
|
return bit;
|
|
|
|
|
2017-09-29 17:03:11 +08:00
|
|
|
val = sh_pfc_read(pfc, pocctrl);
|
2015-07-01 00:53:59 +08:00
|
|
|
|
2023-03-08 18:42:39 +08:00
|
|
|
mode = pin->configs & SH_PFC_PIN_CFG_IO_VOLTAGE_MASK;
|
|
|
|
lo = mode <= SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 ? 1800 : 2500;
|
|
|
|
hi = mode >= SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 ? 3300 : 2500;
|
2021-01-13 00:59:08 +08:00
|
|
|
|
2023-03-08 18:42:39 +08:00
|
|
|
arg = (val & BIT(bit)) ? hi : lo;
|
2015-07-01 00:53:59 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-07-11 16:17:10 +08:00
|
|
|
|
2013-03-10 23:44:02 +08:00
|
|
|
default:
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
2012-07-11 16:17:10 +08:00
|
|
|
|
2016-09-06 23:14:14 +08:00
|
|
|
*config = pinconf_to_config_packed(param, arg);
|
2012-07-20 15:39:09 +08:00
|
|
|
return 0;
|
2012-07-10 11:08:14 +08:00
|
|
|
}
|
|
|
|
|
2013-03-10 23:44:02 +08:00
|
|
|
static int sh_pfc_pinconf_set(struct pinctrl_dev *pctldev, unsigned _pin,
|
2013-08-28 02:32:12 +08:00
|
|
|
unsigned long *configs, unsigned num_configs)
|
2012-07-10 11:08:14 +08:00
|
|
|
{
|
2012-07-20 15:39:09 +08:00
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
2013-03-10 23:44:02 +08:00
|
|
|
struct sh_pfc *pfc = pmx->pfc;
|
2013-08-28 02:32:12 +08:00
|
|
|
enum pin_config_param param;
|
2013-03-10 23:44:02 +08:00
|
|
|
unsigned long flags;
|
2013-08-28 02:32:12 +08:00
|
|
|
unsigned int i;
|
2012-07-20 15:39:09 +08:00
|
|
|
|
2013-08-28 02:32:12 +08:00
|
|
|
for (i = 0; i < num_configs; i++) {
|
|
|
|
param = pinconf_to_config_param(configs[i]);
|
2012-07-20 15:39:09 +08:00
|
|
|
|
2013-08-28 02:32:12 +08:00
|
|
|
if (!sh_pfc_pinconf_validate(pfc, _pin, param))
|
2013-03-10 23:44:02 +08:00
|
|
|
return -ENOTSUPP;
|
|
|
|
|
2013-08-28 02:32:12 +08:00
|
|
|
switch (param) {
|
|
|
|
case PIN_CONFIG_BIAS_PULL_UP:
|
|
|
|
case PIN_CONFIG_BIAS_PULL_DOWN:
|
|
|
|
case PIN_CONFIG_BIAS_DISABLE:
|
|
|
|
if (!pfc->info->ops || !pfc->info->ops->set_bias)
|
|
|
|
return -ENOTSUPP;
|
2013-03-10 23:44:02 +08:00
|
|
|
|
2013-08-28 02:32:12 +08:00
|
|
|
spin_lock_irqsave(&pfc->lock, flags);
|
|
|
|
pfc->info->ops->set_bias(pfc, _pin, param);
|
|
|
|
spin_unlock_irqrestore(&pfc->lock, flags);
|
2013-03-10 23:44:02 +08:00
|
|
|
|
2013-08-28 02:32:12 +08:00
|
|
|
break;
|
|
|
|
|
2016-03-23 22:06:00 +08:00
|
|
|
case PIN_CONFIG_DRIVE_STRENGTH: {
|
|
|
|
unsigned int arg =
|
|
|
|
pinconf_to_config_argument(configs[i]);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = sh_pfc_pinconf_set_drive_strength(pfc, _pin, arg);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-07-01 00:53:59 +08:00
|
|
|
case PIN_CONFIG_POWER_SOURCE: {
|
2016-06-07 00:08:25 +08:00
|
|
|
unsigned int mV = pinconf_to_config_argument(configs[i]);
|
2021-01-13 00:59:08 +08:00
|
|
|
int idx = sh_pfc_get_pin_index(pfc, _pin);
|
|
|
|
const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
|
2023-03-08 18:42:39 +08:00
|
|
|
unsigned int mode, lo, hi;
|
2016-06-07 00:08:25 +08:00
|
|
|
u32 pocctrl, val;
|
|
|
|
int bit;
|
2015-07-01 00:53:59 +08:00
|
|
|
|
2016-06-07 00:08:25 +08:00
|
|
|
if (!pfc->info->ops || !pfc->info->ops->pin_to_pocctrl)
|
2015-07-01 00:53:59 +08:00
|
|
|
return -ENOTSUPP;
|
|
|
|
|
2021-12-23 22:56:17 +08:00
|
|
|
bit = pfc->info->ops->pin_to_pocctrl(_pin, &pocctrl);
|
2016-06-07 00:08:25 +08:00
|
|
|
if (WARN(bit < 0, "invalid pin %#x", _pin))
|
|
|
|
return bit;
|
|
|
|
|
2023-03-08 18:42:39 +08:00
|
|
|
mode = pin->configs & SH_PFC_PIN_CFG_IO_VOLTAGE_MASK;
|
|
|
|
lo = mode <= SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 ? 1800 : 2500;
|
|
|
|
hi = mode >= SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 ? 3300 : 2500;
|
2021-01-13 00:59:08 +08:00
|
|
|
|
2023-03-08 18:42:39 +08:00
|
|
|
if (mV != lo && mV != hi)
|
2016-06-07 00:08:25 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2015-07-01 00:53:59 +08:00
|
|
|
spin_lock_irqsave(&pfc->lock, flags);
|
2017-09-29 17:03:11 +08:00
|
|
|
val = sh_pfc_read(pfc, pocctrl);
|
2023-03-08 18:42:39 +08:00
|
|
|
if (mV == hi)
|
2016-06-07 00:08:25 +08:00
|
|
|
val |= BIT(bit);
|
|
|
|
else
|
|
|
|
val &= ~BIT(bit);
|
2017-09-29 17:03:11 +08:00
|
|
|
sh_pfc_write(pfc, pocctrl, val);
|
2015-07-01 00:53:59 +08:00
|
|
|
spin_unlock_irqrestore(&pfc->lock, flags);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-28 02:32:12 +08:00
|
|
|
default:
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
} /* for each config */
|
2013-03-10 23:44:02 +08:00
|
|
|
|
|
|
|
return 0;
|
2012-07-20 15:39:09 +08:00
|
|
|
}
|
|
|
|
|
2013-03-10 23:44:02 +08:00
|
|
|
static int sh_pfc_pinconf_group_set(struct pinctrl_dev *pctldev, unsigned group,
|
2013-08-28 02:32:12 +08:00
|
|
|
unsigned long *configs,
|
|
|
|
unsigned num_configs)
|
2012-07-20 15:39:09 +08:00
|
|
|
{
|
2013-03-10 23:44:02 +08:00
|
|
|
struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
|
|
|
|
const unsigned int *pins;
|
|
|
|
unsigned int num_pins;
|
2016-06-20 14:40:22 +08:00
|
|
|
unsigned int i, ret;
|
2013-03-10 23:44:02 +08:00
|
|
|
|
|
|
|
pins = pmx->pfc->info->groups[group].pins;
|
|
|
|
num_pins = pmx->pfc->info->groups[group].nr_pins;
|
|
|
|
|
2016-06-20 14:40:22 +08:00
|
|
|
for (i = 0; i < num_pins; ++i) {
|
|
|
|
ret = sh_pfc_pinconf_set(pctldev, pins[i], configs, num_configs);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2013-03-10 23:44:02 +08:00
|
|
|
|
|
|
|
return 0;
|
2012-07-10 11:08:14 +08:00
|
|
|
}
|
|
|
|
|
2013-02-15 23:04:47 +08:00
|
|
|
static const struct pinconf_ops sh_pfc_pinconf_ops = {
|
2013-03-10 23:44:02 +08:00
|
|
|
.is_generic = true,
|
|
|
|
.pin_config_get = sh_pfc_pinconf_get,
|
|
|
|
.pin_config_set = sh_pfc_pinconf_set,
|
|
|
|
.pin_config_group_set = sh_pfc_pinconf_group_set,
|
|
|
|
.pin_config_config_dbg_show = pinconf_generic_dump_config,
|
2012-07-10 11:08:14 +08:00
|
|
|
};
|
|
|
|
|
2013-02-15 08:33:38 +08:00
|
|
|
/* PFC ranges -> pinctrl pin descs */
|
|
|
|
static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
|
2012-07-10 11:08:14 +08:00
|
|
|
{
|
2013-02-15 08:33:38 +08:00
|
|
|
unsigned int i;
|
|
|
|
|
2013-07-16 00:38:30 +08:00
|
|
|
/* Allocate and initialize the pins and configs arrays. */
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:07:58 +08:00
|
|
|
pmx->pins = devm_kcalloc(pfc->dev,
|
|
|
|
pfc->info->nr_pins, sizeof(*pmx->pins),
|
2012-12-16 06:50:48 +08:00
|
|
|
GFP_KERNEL);
|
2013-01-03 21:33:13 +08:00
|
|
|
if (unlikely(!pmx->pins))
|
2012-07-10 11:08:14 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:07:58 +08:00
|
|
|
pmx->configs = devm_kcalloc(pfc->dev,
|
|
|
|
pfc->info->nr_pins, sizeof(*pmx->configs),
|
2013-03-09 00:43:54 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (unlikely(!pmx->configs))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-07-16 00:38:30 +08:00
|
|
|
for (i = 0; i < pfc->info->nr_pins; ++i) {
|
|
|
|
const struct sh_pfc_pin *info = &pfc->info->pins[i];
|
|
|
|
struct pinctrl_pin_desc *pin = &pmx->pins[i];
|
2013-02-15 08:33:38 +08:00
|
|
|
|
2013-07-16 00:38:30 +08:00
|
|
|
/* 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;
|
2012-07-10 11:08:14 +08:00
|
|
|
}
|
|
|
|
|
2013-07-16 00:38:30 +08:00
|
|
|
return 0;
|
2012-07-10 11:08:14 +08:00
|
|
|
}
|
|
|
|
|
2012-12-16 06:50:47 +08:00
|
|
|
int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
|
2012-07-10 11:08:14 +08:00
|
|
|
{
|
2012-12-16 06:50:47 +08:00
|
|
|
struct sh_pfc_pinctrl *pmx;
|
2013-07-16 00:38:30 +08:00
|
|
|
int ret;
|
2012-07-10 11:08:14 +08:00
|
|
|
|
2012-12-16 06:50:48 +08:00
|
|
|
pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL);
|
2012-12-16 06:50:47 +08:00
|
|
|
if (unlikely(!pmx))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pmx->pfc = pfc;
|
2012-07-10 11:08:14 +08:00
|
|
|
|
2013-07-16 00:38:30 +08:00
|
|
|
ret = sh_pfc_map_pins(pfc, pmx);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2012-07-10 11:08:14 +08:00
|
|
|
|
2013-02-16 23:38:30 +08:00
|
|
|
pmx->pctl_desc.name = DRV_NAME;
|
|
|
|
pmx->pctl_desc.owner = THIS_MODULE;
|
|
|
|
pmx->pctl_desc.pctlops = &sh_pfc_pinctrl_ops;
|
|
|
|
pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops;
|
|
|
|
pmx->pctl_desc.confops = &sh_pfc_pinconf_ops;
|
2013-01-03 21:33:13 +08:00
|
|
|
pmx->pctl_desc.pins = pmx->pins;
|
2013-02-15 08:33:38 +08:00
|
|
|
pmx->pctl_desc.npins = pfc->info->nr_pins;
|
2013-02-16 23:38:30 +08:00
|
|
|
|
2017-03-31 00:16:39 +08:00
|
|
|
ret = devm_pinctrl_register_and_init(pfc->dev, &pmx->pctl_desc, pmx,
|
|
|
|
&pmx->pctl);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(pfc->dev, "could not register: %i\n", ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pinctrl_enable(pmx->pctl);
|
2012-07-10 11:08:14 +08:00
|
|
|
}
|
2020-10-28 23:16:34 +08:00
|
|
|
|
2021-06-30 22:50:43 +08:00
|
|
|
const struct pinmux_bias_reg *
|
2021-12-23 22:56:19 +08:00
|
|
|
rcar_pin_to_bias_reg(const struct sh_pfc_soc_info *info, unsigned int pin,
|
2021-03-03 21:26:14 +08:00
|
|
|
unsigned int *bit)
|
|
|
|
{
|
|
|
|
unsigned int i, j;
|
|
|
|
|
2021-12-23 22:56:19 +08:00
|
|
|
for (i = 0; info->bias_regs[i].puen || info->bias_regs[i].pud; i++) {
|
|
|
|
for (j = 0; j < ARRAY_SIZE(info->bias_regs[i].pins); j++) {
|
|
|
|
if (info->bias_regs[i].pins[j] == pin) {
|
2021-03-03 21:26:14 +08:00
|
|
|
*bit = j;
|
2021-12-23 22:56:19 +08:00
|
|
|
return &info->bias_regs[i];
|
2021-03-03 21:26:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN_ONCE(1, "Pin %u is not in bias info list\n", pin);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-10-28 23:16:34 +08:00
|
|
|
unsigned int rcar_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin)
|
|
|
|
{
|
|
|
|
const struct pinmux_bias_reg *reg;
|
|
|
|
unsigned int bit;
|
|
|
|
|
2021-12-23 22:56:19 +08:00
|
|
|
reg = rcar_pin_to_bias_reg(pfc->info, pin, &bit);
|
2020-10-28 23:16:34 +08:00
|
|
|
if (!reg)
|
|
|
|
return PIN_CONFIG_BIAS_DISABLE;
|
|
|
|
|
pinctrl: renesas: Add support for R-Car SoCs with pull-down only pins
Currently, the common R-Car bias handling supports pin controllers with
either:
1. Separate pin Pull-Enable (PUEN) and pin Pull-Up/Down control (PUD)
registers, for controlling both pin pull-up and pin pull-down,
2. A single pin Pull-Up control register (PUPR), for controlling pin
pull-up.
Add support for a variant of #2, where some bits in the single pin
Pull-Up control register (PUPR) control pin pull-down instead of pin
pull-up. This is the case for the "ASEBRK#/ACK" pin on R-Car M2-W,
M2-N, and E2, and the "ACK" pin on RZ/G1M, RZ/G1N, RZ/G1E, and RZ/G1C.
To describe such a register, SoC-specific drivers need to provide two
instances of pinmux_bias_reg: a first one with the puen field filled in,
listing pins with pull-up functionality, and a second one with the pud
field filled in, listing pins with pull-down functionality.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Link: https://lore.kernel.org/r/20210303132619.3938128-6-geert+renesas@glider.be
2021-03-03 21:26:18 +08:00
|
|
|
if (reg->puen) {
|
|
|
|
if (!(sh_pfc_read(pfc, reg->puen) & BIT(bit)))
|
|
|
|
return PIN_CONFIG_BIAS_DISABLE;
|
|
|
|
else if (!reg->pud || (sh_pfc_read(pfc, reg->pud) & BIT(bit)))
|
|
|
|
return PIN_CONFIG_BIAS_PULL_UP;
|
|
|
|
else
|
|
|
|
return PIN_CONFIG_BIAS_PULL_DOWN;
|
|
|
|
} else {
|
|
|
|
if (sh_pfc_read(pfc, reg->pud) & BIT(bit))
|
|
|
|
return PIN_CONFIG_BIAS_PULL_DOWN;
|
|
|
|
else
|
|
|
|
return PIN_CONFIG_BIAS_DISABLE;
|
|
|
|
}
|
2020-10-28 23:16:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rcar_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
|
|
|
|
unsigned int bias)
|
|
|
|
{
|
|
|
|
const struct pinmux_bias_reg *reg;
|
|
|
|
u32 enable, updown;
|
|
|
|
unsigned int bit;
|
|
|
|
|
2021-12-23 22:56:19 +08:00
|
|
|
reg = rcar_pin_to_bias_reg(pfc->info, pin, &bit);
|
2020-10-28 23:16:34 +08:00
|
|
|
if (!reg)
|
|
|
|
return;
|
|
|
|
|
pinctrl: renesas: Add support for R-Car SoCs with pull-down only pins
Currently, the common R-Car bias handling supports pin controllers with
either:
1. Separate pin Pull-Enable (PUEN) and pin Pull-Up/Down control (PUD)
registers, for controlling both pin pull-up and pin pull-down,
2. A single pin Pull-Up control register (PUPR), for controlling pin
pull-up.
Add support for a variant of #2, where some bits in the single pin
Pull-Up control register (PUPR) control pin pull-down instead of pin
pull-up. This is the case for the "ASEBRK#/ACK" pin on R-Car M2-W,
M2-N, and E2, and the "ACK" pin on RZ/G1M, RZ/G1N, RZ/G1E, and RZ/G1C.
To describe such a register, SoC-specific drivers need to provide two
instances of pinmux_bias_reg: a first one with the puen field filled in,
listing pins with pull-up functionality, and a second one with the pud
field filled in, listing pins with pull-down functionality.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Link: https://lore.kernel.org/r/20210303132619.3938128-6-geert+renesas@glider.be
2021-03-03 21:26:18 +08:00
|
|
|
if (reg->puen) {
|
|
|
|
enable = sh_pfc_read(pfc, reg->puen) & ~BIT(bit);
|
2021-06-30 22:50:42 +08:00
|
|
|
if (bias != PIN_CONFIG_BIAS_DISABLE) {
|
pinctrl: renesas: Add support for R-Car SoCs with pull-down only pins
Currently, the common R-Car bias handling supports pin controllers with
either:
1. Separate pin Pull-Enable (PUEN) and pin Pull-Up/Down control (PUD)
registers, for controlling both pin pull-up and pin pull-down,
2. A single pin Pull-Up control register (PUPR), for controlling pin
pull-up.
Add support for a variant of #2, where some bits in the single pin
Pull-Up control register (PUPR) control pin pull-down instead of pin
pull-up. This is the case for the "ASEBRK#/ACK" pin on R-Car M2-W,
M2-N, and E2, and the "ACK" pin on RZ/G1M, RZ/G1N, RZ/G1E, and RZ/G1C.
To describe such a register, SoC-specific drivers need to provide two
instances of pinmux_bias_reg: a first one with the puen field filled in,
listing pins with pull-up functionality, and a second one with the pud
field filled in, listing pins with pull-down functionality.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Link: https://lore.kernel.org/r/20210303132619.3938128-6-geert+renesas@glider.be
2021-03-03 21:26:18 +08:00
|
|
|
enable |= BIT(bit);
|
2020-10-28 23:16:34 +08:00
|
|
|
|
2021-06-30 22:50:42 +08:00
|
|
|
if (reg->pud) {
|
|
|
|
updown = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
|
|
|
|
if (bias == PIN_CONFIG_BIAS_PULL_UP)
|
|
|
|
updown |= BIT(bit);
|
2020-10-28 23:16:36 +08:00
|
|
|
|
2021-06-30 22:50:42 +08:00
|
|
|
sh_pfc_write(pfc, reg->pud, updown);
|
|
|
|
}
|
pinctrl: renesas: Add support for R-Car SoCs with pull-down only pins
Currently, the common R-Car bias handling supports pin controllers with
either:
1. Separate pin Pull-Enable (PUEN) and pin Pull-Up/Down control (PUD)
registers, for controlling both pin pull-up and pin pull-down,
2. A single pin Pull-Up control register (PUPR), for controlling pin
pull-up.
Add support for a variant of #2, where some bits in the single pin
Pull-Up control register (PUPR) control pin pull-down instead of pin
pull-up. This is the case for the "ASEBRK#/ACK" pin on R-Car M2-W,
M2-N, and E2, and the "ACK" pin on RZ/G1M, RZ/G1N, RZ/G1E, and RZ/G1C.
To describe such a register, SoC-specific drivers need to provide two
instances of pinmux_bias_reg: a first one with the puen field filled in,
listing pins with pull-up functionality, and a second one with the pud
field filled in, listing pins with pull-down functionality.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Link: https://lore.kernel.org/r/20210303132619.3938128-6-geert+renesas@glider.be
2021-03-03 21:26:18 +08:00
|
|
|
}
|
|
|
|
sh_pfc_write(pfc, reg->puen, enable);
|
|
|
|
} else {
|
|
|
|
enable = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
|
|
|
|
if (bias == PIN_CONFIG_BIAS_PULL_DOWN)
|
|
|
|
enable |= BIT(bit);
|
|
|
|
|
|
|
|
sh_pfc_write(pfc, reg->pud, enable);
|
|
|
|
}
|
2020-10-28 23:16:34 +08:00
|
|
|
}
|
2021-03-03 21:26:16 +08:00
|
|
|
|
|
|
|
#define PORTnCR_PULMD_OFF (0 << 6)
|
|
|
|
#define PORTnCR_PULMD_DOWN (2 << 6)
|
|
|
|
#define PORTnCR_PULMD_UP (3 << 6)
|
|
|
|
#define PORTnCR_PULMD_MASK (3 << 6)
|
|
|
|
|
|
|
|
unsigned int rmobile_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin)
|
|
|
|
{
|
2021-12-23 22:56:18 +08:00
|
|
|
void __iomem *reg = pfc->windows->virt +
|
|
|
|
pfc->info->ops->pin_to_portcr(pin);
|
2021-03-03 21:26:16 +08:00
|
|
|
u32 value = ioread8(reg) & PORTnCR_PULMD_MASK;
|
|
|
|
|
|
|
|
switch (value) {
|
|
|
|
case PORTnCR_PULMD_UP:
|
|
|
|
return PIN_CONFIG_BIAS_PULL_UP;
|
|
|
|
case PORTnCR_PULMD_DOWN:
|
|
|
|
return PIN_CONFIG_BIAS_PULL_DOWN;
|
|
|
|
case PORTnCR_PULMD_OFF:
|
|
|
|
default:
|
|
|
|
return PIN_CONFIG_BIAS_DISABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rmobile_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
|
|
|
|
unsigned int bias)
|
|
|
|
{
|
2021-12-23 22:56:18 +08:00
|
|
|
void __iomem *reg = pfc->windows->virt +
|
|
|
|
pfc->info->ops->pin_to_portcr(pin);
|
2021-03-03 21:26:16 +08:00
|
|
|
u32 value = ioread8(reg) & ~PORTnCR_PULMD_MASK;
|
|
|
|
|
|
|
|
switch (bias) {
|
|
|
|
case PIN_CONFIG_BIAS_PULL_UP:
|
|
|
|
value |= PORTnCR_PULMD_UP;
|
|
|
|
break;
|
|
|
|
case PIN_CONFIG_BIAS_PULL_DOWN:
|
|
|
|
value |= PORTnCR_PULMD_DOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
iowrite8(value, reg);
|
|
|
|
}
|