12 #include <linux/module.h>
13 #include <linux/device.h>
16 #include <linux/slab.h>
21 static int ltq_get_group_count(
struct pinctrl_dev *pctrldev)
27 static const char *ltq_get_group_name(
struct pinctrl_dev *pctrldev,
33 return info->
grps[selector].name;
36 static int ltq_get_group_pins(
struct pinctrl_dev *pctrldev,
38 const unsigned **
pins,
44 *pins = info->
grps[selector].pins;
45 *num_pins = info->
grps[selector].npins;
54 for (i = 0; i < num_maps; i++)
60 static void ltq_pinctrl_pin_dbg_show(
struct pinctrl_dev *pctldev,
67 static int ltq_pinctrl_dt_subnode_to_map(
struct pinctrl_dev *pctldev,
72 unsigned long configs[3];
73 unsigned num_configs = 0;
83 (*map)->name =
function;
84 (*map)->data.mux.group =
group;
85 (*map)->data.mux.function =
function;
90 "%s mixes pins and groups settings\n",
97 int ret = of_property_read_u32(np,
98 info->
params[i].property, &val);
100 configs[num_configs++] =
109 (*map)->data.configs.configs =
kmemdup(configs,
110 num_configs *
sizeof(
unsigned long),
114 (*map)->data.configs.group_or_pin =
pin;
115 (*map)->data.configs.num_configs = num_configs;
121 static int ltq_pinctrl_dt_subnode_size(
struct device_node *np)
142 *num_maps += ltq_pinctrl_dt_subnode_size(np);
149 ret = ltq_pinctrl_dt_subnode_to_map(pctldev, np, &tmp);
158 static struct pinctrl_ops ltq_pctrl_ops = {
159 .get_groups_count = ltq_get_group_count,
160 .get_group_name = ltq_get_group_name,
161 .get_group_pins = ltq_get_group_pins,
162 .pin_dbg_show = ltq_pinctrl_pin_dbg_show,
167 static int ltq_pmx_func_count(
struct pinctrl_dev *pctrldev)
174 static const char *ltq_pmx_func_name(
struct pinctrl_dev *pctrldev,
182 return info->
funcs[selector].name;
185 static int ltq_pmx_get_groups(
struct pinctrl_dev *pctrldev,
187 const char *
const **groups,
188 unsigned *
const num_groups)
193 *num_groups = info->
funcs[
func].num_groups;
203 if (mfp->
func[i] == mux)
206 if (i >= LTQ_MAX_MUX)
215 for (i = 0; i < info->
num_mfp; i++) {
216 if (info->
mfp[i].pin == pin)
228 for (i = 0; i < grp->
npins; i++) {
229 pin = match_mfp(info, grp->
pins[i]);
231 dev_err(info->
dev,
"could not find mfp for pin %d\n",
235 ret = match_mux(&info->
mfp[pin], mux);
237 dev_err(info->
dev,
"Can't find mux %d on pin%d\n",
245 static int ltq_pmx_enable(
struct pinctrl_dev *pctrldev,
253 if (!pin_grp->
npins ||
254 (match_group_mux(pin_grp, info, pin_grp->
mux) < 0)) {
255 dev_err(info->
dev,
"Failed to set the pin group: %s\n",
256 info->
grps[group].name);
259 for (i = 0; i < pin_grp->
npins; i++) {
260 pin = match_mfp(info, pin_grp->
pins[i]);
262 dev_err(info->
dev,
"could not find mfp for pin %d\n",
266 pin_func = match_mux(&info->
mfp[pin], pin_grp->
mux);
267 ret = info->
apply_mux(pctrldev, pin, pin_func);
270 "failed to apply mux %d for pin %d\n",
278 static void ltq_pmx_disable(
struct pinctrl_dev *pctrldev,
288 static int ltq_pmx_gpio_request_enable(
struct pinctrl_dev *pctrldev,
289 struct pinctrl_gpio_range *
range,
293 int mfp = match_mfp(info, pin + (range->id * 32));
297 dev_err(info->
dev,
"could not find mfp for pin %d\n", pin);
301 pin_func = match_mux(&info->
mfp[mfp], 0);
303 dev_err(info->
dev,
"No GPIO function on pin%d\n", mfp);
307 return info->
apply_mux(pctrldev, mfp, pin_func);
310 static struct pinmux_ops ltq_pmx_ops = {
311 .get_functions_count = ltq_pmx_func_count,
312 .get_function_name = ltq_pmx_func_name,
313 .get_function_groups = ltq_pmx_get_groups,
314 .enable = ltq_pmx_enable,
315 .disable = ltq_pmx_disable,
316 .gpio_request_enable = ltq_pmx_gpio_request_enable,
326 struct pinctrl_desc *
desc;
331 desc->pctlops = <q_pctrl_ops;
332 desc->pmxops = <q_pmx_ops;
337 dev_err(&pdev->
dev,
"failed to register LTQ pinmux driver\n");
340 platform_set_drvdata(pdev, info);