11 #define pr_fmt(fmt) "pinconfig core: " fmt
13 #include <linux/kernel.h>
14 #include <linux/module.h>
16 #include <linux/device.h>
17 #include <linux/slab.h>
28 const struct pinconf_ops *
ops = pctldev->
desc->confops;
31 if (!ops->pin_config_get && !ops->pin_config_group_get) {
33 "pinconf must be able to read out pin status\n");
37 if (!ops->pin_config_set && !ops->pin_config_group_set) {
39 "pinconf has to be able to set a pins config\n");
48 pr_err(
"failed to register map %s (%d): no group/pin given\n",
55 pr_err(
"failed to register map %s (%d): no configs given\n",
66 const struct pinconf_ops *
ops = pctldev->
desc->confops;
68 if (!ops || !ops->pin_config_get) {
69 dev_err(pctldev->
dev,
"cannot get pin configuration, missing "
70 "pin_config_get() function in driver\n");
74 return ops->pin_config_get(pctldev, pin, config);
111 static int pin_config_set_for_pin(
struct pinctrl_dev *pctldev,
unsigned pin,
114 const struct pinconf_ops *
ops = pctldev->
desc->confops;
117 if (!ops || !ops->pin_config_set) {
118 dev_err(pctldev->
dev,
"cannot configure pin, missing "
119 "config function in driver\n");
123 ret = ops->pin_config_set(pctldev, pin, config);
126 "unable to set pin configuration on pin %d\n", pin);
142 unsigned long config)
161 ret = pin_config_set_for_pin(pctldev, pin, config);
170 unsigned long *config)
173 const struct pinconf_ops *ops;
183 ops = pctldev->
desc->confops;
185 if (!ops || !ops->pin_config_group_get) {
186 dev_err(pctldev->
dev,
"cannot get configuration for pin "
187 "group, missing group config get function in "
199 ret = ops->pin_config_group_get(pctldev, selector, config);
208 unsigned long config)
211 const struct pinconf_ops *ops;
212 const struct pinctrl_ops *pctlops;
214 const unsigned *
pins;
226 ops = pctldev->
desc->confops;
227 pctlops = pctldev->
desc->pctlops;
229 if (!ops || (!ops->pin_config_group_set && !ops->pin_config_set)) {
230 dev_err(pctldev->
dev,
"cannot configure pin group, missing "
231 "config function in driver\n");
242 ret = pctlops->get_group_pins(pctldev, selector, &pins, &num_pins);
244 dev_err(pctldev->
dev,
"cannot configure pin group, error "
253 if (ops->pin_config_group_set) {
254 ret = ops->pin_config_group_set(pctldev, selector, config);
267 if (!ops->pin_config_set) {
272 for (i = 0; i < num_pins; i++) {
273 ret = ops->pin_config_set(pctldev, pins[i], config);
293 switch (setting->
type) {
298 dev_err(pctldev->
dev,
"could not map pin config for \"%s\"",
308 dev_err(pctldev->
dev,
"could not map group config for \"%s\"",
331 const struct pinconf_ops *ops = pctldev->
desc->confops;
339 switch (setting->
type) {
341 if (!ops->pin_config_set) {
342 dev_err(pctldev->
dev,
"missing pin_config_set op\n");
345 for (i = 0; i < setting->
data.
configs.num_configs; i++) {
346 ret = ops->pin_config_set(pctldev,
351 "pin_config_set op failed for pin %d config %08lx\n",
359 if (!ops->pin_config_group_set) {
361 "missing pin_config_group_set op\n");
364 for (i = 0; i < setting->
data.
configs.num_configs; i++) {
365 ret = ops->pin_config_group_set(pctldev,
370 "pin_config_group_set op failed for group %d config %08lx\n",
384 #ifdef CONFIG_DEBUG_FS
389 const struct pinconf_ops *confops;
394 confops = pctldev->
desc->confops;
411 for (i = 0; i < map->
data.
configs.num_configs; i++) {
413 if (confops && confops->pin_config_config_dbg_show)
414 confops->pin_config_config_dbg_show(pctldev, s,
422 void pinconf_show_setting(
struct seq_file *s,
426 const struct pinctrl_ops *pctlops = pctldev->
desc->pctlops;
427 const struct pinconf_ops *confops = pctldev->
desc->confops;
431 switch (setting->
type) {
433 desc = pin_desc_get(setting->
pctldev,
436 desc->
name ? desc->
name :
"unnamed",
441 pctlops->get_group_name(pctldev,
453 for (i = 0; i < setting->
data.
configs.num_configs; i++) {
455 if (confops && confops->pin_config_config_dbg_show)
456 confops->pin_config_config_dbg_show(pctldev, s,
466 static void pinconf_dump_pin(
struct pinctrl_dev *pctldev,
469 const struct pinconf_ops *ops = pctldev->
desc->confops;
472 pinconf_generic_dump_pin(pctldev, s, pin);
473 if (ops && ops->pin_config_dbg_show)
474 ops->pin_config_dbg_show(pctldev, s, pin);
477 static int pinconf_pins_show(
struct seq_file *s,
void *
what)
480 const struct pinconf_ops *ops = pctldev->
desc->confops;
483 if (!ops || !ops->pin_config_get)
486 seq_puts(s,
"Pin config settings per pin\n");
487 seq_puts(s,
"Format: pin (name): configs\n");
492 for (i = 0; i < pctldev->
desc->npins; i++) {
495 pin = pctldev->
desc->pins[
i].number;
496 desc = pin_desc_get(pctldev, pin);
502 desc->
name ? desc->
name :
"unnamed");
504 pinconf_dump_pin(pctldev, s, pin);
514 static void pinconf_dump_group(
struct pinctrl_dev *pctldev,
518 const struct pinconf_ops *ops = pctldev->
desc->confops;
521 pinconf_generic_dump_group(pctldev, s, gname);
522 if (ops && ops->pin_config_group_dbg_show)
523 ops->pin_config_group_dbg_show(pctldev, s, selector);
526 static int pinconf_groups_show(
struct seq_file *s,
void *what)
529 const struct pinctrl_ops *pctlops = pctldev->
desc->pctlops;
530 const struct pinconf_ops *ops = pctldev->
desc->confops;
531 unsigned ngroups = pctlops->get_groups_count(pctldev);
532 unsigned selector = 0;
534 if (!ops || !ops->pin_config_group_get)
537 seq_puts(s,
"Pin config settings per pin group\n");
538 seq_puts(s,
"Format: group (name): configs\n");
540 while (selector < ngroups) {
541 const char *gname = pctlops->get_group_name(pctldev, selector);
544 pinconf_dump_group(pctldev, s, selector, gname);
564 .
open = pinconf_pins_open,
571 .
open = pinconf_groups_open,
577 void pinconf_init_device_debugfs(
struct dentry *devroot,
581 devroot, pctldev, &pinconf_pins_ops);
583 devroot, pctldev, &pinconf_groups_ops);