15 #include <linux/module.h>
23 #include <linux/slab.h>
36 static int mxs_get_groups_count(
struct pinctrl_dev *pctldev)
40 return d->
soc->ngroups;
43 static const char *mxs_get_group_name(
struct pinctrl_dev *pctldev,
52 const unsigned **
pins,
unsigned *num_pins)
57 *num_pins = d->
soc->groups[
group].npins;
68 static int mxs_dt_node_to_map(
struct pinctrl_dev *pctldev,
76 unsigned long *pconfig;
83 if (of_property_read_u32(np,
"reg", ®))
86 ret = of_property_read_u32(np,
"fsl,drive-strength", &val);
89 ret = of_property_read_u32(np,
"fsl,voltage", &val);
92 ret = of_property_read_u32(np,
"fsl,pull-up", &val);
97 if (!purecfg && config)
100 new_map = kzalloc(
sizeof(*new_map) * new_num,
GFP_KERNEL);
146 static void mxs_dt_free_map(
struct pinctrl_dev *pctldev,
151 for (i = 0; i < num_maps; i++) {
161 static struct pinctrl_ops mxs_pinctrl_ops = {
162 .get_groups_count = mxs_get_groups_count,
163 .get_group_name = mxs_get_group_name,
164 .get_group_pins = mxs_get_group_pins,
165 .pin_dbg_show = mxs_pin_dbg_show,
166 .dt_node_to_map = mxs_dt_node_to_map,
167 .dt_free_map = mxs_dt_free_map,
170 static int mxs_pinctrl_get_funcs_count(
struct pinctrl_dev *pctldev)
174 return d->
soc->nfunctions;
177 static const char *mxs_pinctrl_get_func_name(
struct pinctrl_dev *pctldev,
182 return d->
soc->functions[
function].name;
185 static int mxs_pinctrl_get_func_groups(
struct pinctrl_dev *pctldev,
187 const char *
const **groups,
188 unsigned *
const num_groups)
192 *groups = d->
soc->functions[
group].groups;
193 *num_groups = d->
soc->functions[
group].ngroups;
208 for (i = 0; i < g->
npins; i++) {
211 reg = d->
base + d->
soc->regs->muxsel;
212 reg += bank * 0x20 + pin / 16 * 0x10;
213 shift = pin % 16 * 2;
222 static struct pinmux_ops mxs_pinmux_ops = {
223 .get_functions_count = mxs_pinctrl_get_funcs_count,
224 .get_function_name = mxs_pinctrl_get_func_name,
225 .get_function_groups = mxs_pinctrl_get_func_groups,
226 .enable = mxs_pinctrl_enable,
229 static int mxs_pinconf_get(
struct pinctrl_dev *pctldev,
230 unsigned pin,
unsigned long *config)
235 static int mxs_pinconf_set(
struct pinctrl_dev *pctldev,
236 unsigned pin,
unsigned long config)
241 static int mxs_pinconf_group_get(
struct pinctrl_dev *pctldev,
242 unsigned group,
unsigned long *config)
246 *config = d->
soc->groups[
group].config;
251 static int mxs_pinconf_group_set(
struct pinctrl_dev *pctldev,
252 unsigned group,
unsigned long config)
265 for (i = 0; i < g->
npins; i++) {
270 reg = d->
base + d->
soc->regs->drive;
271 reg += bank * 0x40 + pin / 8 * 0x10;
282 shift = pin % 8 * 4 + 2;
291 reg = d->
base + d->
soc->regs->pull;
307 static void mxs_pinconf_dbg_show(
struct pinctrl_dev *pctldev,
313 static void mxs_pinconf_group_dbg_show(
struct pinctrl_dev *pctldev,
318 if (!mxs_pinconf_group_get(pctldev, group, &config))
323 .pin_config_get = mxs_pinconf_get,
324 .pin_config_set = mxs_pinconf_set,
325 .pin_config_group_get = mxs_pinconf_group_get,
326 .pin_config_group_set = mxs_pinconf_group_set,
327 .pin_config_dbg_show = mxs_pinconf_dbg_show,
328 .pin_config_group_dbg_show = mxs_pinconf_group_dbg_show,
331 static struct pinctrl_desc mxs_pinctrl_desc = {
332 .pctlops = &mxs_pinctrl_ops,
333 .pmxops = &mxs_pinmux_ops,
340 const char **out_name)
345 const char *propname =
"fsl,pinmux-ids";
354 if (of_property_read_u32(np,
"reg", &val))
376 for (i = 0; i < g->
npins; i++) {
394 const char *gpio_compat =
"fsl,mxs-gpio";
395 const char *
fn, *fnull =
"";
396 int i = 0, idxf = 0, idxg = 0;
413 if (of_property_read_u32(child,
"reg", &val))
437 if (of_property_read_u32(child,
"reg", &val))
452 if (of_property_read_u32(child,
"reg", &val)) {
453 ret = mxs_pinctrl_parse_group(pdev, child,
470 ret = mxs_pinctrl_parse_group(pdev, child, idxg++,
497 mxs_pinctrl_desc.pins = d->
soc->pins;
498 mxs_pinctrl_desc.npins = d->
soc->npins;
499 mxs_pinctrl_desc.name = dev_name(&pdev->
dev);
501 platform_set_drvdata(pdev, d);
503 ret = mxs_pinctrl_probe_dt(pdev, d);
505 dev_err(&pdev->
dev,
"dt probe failed: %d\n", ret);
511 dev_err(&pdev->
dev,
"Couldn't register MXS pinctrl driver\n");
519 platform_set_drvdata(pdev,
NULL);
529 platform_set_drvdata(pdev,
NULL);