| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Core driver for the pin muxing portions of the pin control subsystem |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 8 | 9 | * Author: Linus Walleij <linus.walleij@linaro.org> |
|---|
| 9 | 10 | * |
|---|
| 10 | 11 | * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved. |
|---|
| 11 | | - * |
|---|
| 12 | | - * License terms: GNU General Public License (GPL) version 2 |
|---|
| 13 | 12 | */ |
|---|
| 14 | 13 | #define pr_fmt(fmt) "pinmux core: " fmt |
|---|
| 15 | 14 | |
|---|
| .. | .. |
|---|
| 72 | 71 | } |
|---|
| 73 | 72 | |
|---|
| 74 | 73 | /** |
|---|
| 74 | + * pinmux_can_be_used_for_gpio() - check if a specific pin |
|---|
| 75 | + * is either muxed to a different function or used as gpio. |
|---|
| 76 | + * |
|---|
| 77 | + * @pctldev: the associated pin controller device |
|---|
| 78 | + * @pin: the pin number in the global pin space |
|---|
| 79 | + * |
|---|
| 80 | + * Controllers not defined as strict will always return true, |
|---|
| 81 | + * menaning that the gpio can be used. |
|---|
| 82 | + */ |
|---|
| 83 | +bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, unsigned pin) |
|---|
| 84 | +{ |
|---|
| 85 | + struct pin_desc *desc = pin_desc_get(pctldev, pin); |
|---|
| 86 | + const struct pinmux_ops *ops = pctldev->desc->pmxops; |
|---|
| 87 | + |
|---|
| 88 | + /* Can't inspect pin, assume it can be used */ |
|---|
| 89 | + if (!desc || !ops) |
|---|
| 90 | + return true; |
|---|
| 91 | + |
|---|
| 92 | + if (ops->strict && desc->mux_usecount) |
|---|
| 93 | + return false; |
|---|
| 94 | + |
|---|
| 95 | + return !(ops->strict && !!desc->gpio_owner); |
|---|
| 96 | +} |
|---|
| 97 | + |
|---|
| 98 | +/** |
|---|
| 75 | 99 | * pin_request() - request a single pin to be muxed in, typically for GPIO |
|---|
| 100 | + * @pctldev: the associated pin controller device |
|---|
| 76 | 101 | * @pin: the pin number in the global pin space |
|---|
| 77 | 102 | * @owner: a representation of the owner of this pin; typically the device |
|---|
| 78 | 103 | * name that controls its mux function, or the requested GPIO name |
|---|
| .. | .. |
|---|
| 231 | 256 | * @pctldev: pin controller device affected |
|---|
| 232 | 257 | * @pin: the pin to mux in for GPIO |
|---|
| 233 | 258 | * @range: the applicable GPIO range |
|---|
| 259 | + * @gpio: number of requested GPIO |
|---|
| 234 | 260 | */ |
|---|
| 235 | 261 | int pinmux_request_gpio(struct pinctrl_dev *pctldev, |
|---|
| 236 | 262 | struct pinctrl_gpio_range *range, |
|---|
| .. | .. |
|---|
| 644 | 670 | setting->data.mux.func); |
|---|
| 645 | 671 | } |
|---|
| 646 | 672 | |
|---|
| 647 | | -static int pinmux_functions_open(struct inode *inode, struct file *file) |
|---|
| 648 | | -{ |
|---|
| 649 | | - return single_open(file, pinmux_functions_show, inode->i_private); |
|---|
| 650 | | -} |
|---|
| 651 | | - |
|---|
| 652 | | -static int pinmux_pins_open(struct inode *inode, struct file *file) |
|---|
| 653 | | -{ |
|---|
| 654 | | - return single_open(file, pinmux_pins_show, inode->i_private); |
|---|
| 655 | | -} |
|---|
| 656 | | - |
|---|
| 657 | | -static const struct file_operations pinmux_functions_ops = { |
|---|
| 658 | | - .open = pinmux_functions_open, |
|---|
| 659 | | - .read = seq_read, |
|---|
| 660 | | - .llseek = seq_lseek, |
|---|
| 661 | | - .release = single_release, |
|---|
| 662 | | -}; |
|---|
| 663 | | - |
|---|
| 664 | | -static const struct file_operations pinmux_pins_ops = { |
|---|
| 665 | | - .open = pinmux_pins_open, |
|---|
| 666 | | - .read = seq_read, |
|---|
| 667 | | - .llseek = seq_lseek, |
|---|
| 668 | | - .release = single_release, |
|---|
| 669 | | -}; |
|---|
| 673 | +DEFINE_SHOW_ATTRIBUTE(pinmux_functions); |
|---|
| 674 | +DEFINE_SHOW_ATTRIBUTE(pinmux_pins); |
|---|
| 670 | 675 | |
|---|
| 671 | 676 | void pinmux_init_device_debugfs(struct dentry *devroot, |
|---|
| 672 | 677 | struct pinctrl_dev *pctldev) |
|---|
| 673 | 678 | { |
|---|
| 674 | 679 | debugfs_create_file("pinmux-functions", S_IFREG | S_IRUGO, |
|---|
| 675 | | - devroot, pctldev, &pinmux_functions_ops); |
|---|
| 680 | + devroot, pctldev, &pinmux_functions_fops); |
|---|
| 676 | 681 | debugfs_create_file("pinmux-pins", S_IFREG | S_IRUGO, |
|---|
| 677 | | - devroot, pctldev, &pinmux_pins_ops); |
|---|
| 682 | + devroot, pctldev, &pinmux_pins_fops); |
|---|
| 678 | 683 | } |
|---|
| 679 | 684 | |
|---|
| 680 | 685 | #endif /* CONFIG_DEBUG_FS */ |
|---|
| .. | .. |
|---|
| 742 | 747 | /** |
|---|
| 743 | 748 | * pinmux_generic_get_function() - returns a function based on the number |
|---|
| 744 | 749 | * @pctldev: pin controller device |
|---|
| 745 | | - * @group_selector: function number |
|---|
| 750 | + * @selector: function number |
|---|
| 746 | 751 | */ |
|---|
| 747 | 752 | struct function_desc *pinmux_generic_get_function(struct pinctrl_dev *pctldev, |
|---|
| 748 | 753 | unsigned int selector) |
|---|