hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/pinctrl/pinmux.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Core driver for the pin muxing portions of the pin control subsystem
34 *
....@@ -8,8 +9,6 @@
89 * Author: Linus Walleij <linus.walleij@linaro.org>
910 *
1011 * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
11
- *
12
- * License terms: GNU General Public License (GPL) version 2
1312 */
1413 #define pr_fmt(fmt) "pinmux core: " fmt
1514
....@@ -72,7 +71,33 @@
7271 }
7372
7473 /**
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
+/**
7599 * pin_request() - request a single pin to be muxed in, typically for GPIO
100
+ * @pctldev: the associated pin controller device
76101 * @pin: the pin number in the global pin space
77102 * @owner: a representation of the owner of this pin; typically the device
78103 * name that controls its mux function, or the requested GPIO name
....@@ -231,6 +256,7 @@
231256 * @pctldev: pin controller device affected
232257 * @pin: the pin to mux in for GPIO
233258 * @range: the applicable GPIO range
259
+ * @gpio: number of requested GPIO
234260 */
235261 int pinmux_request_gpio(struct pinctrl_dev *pctldev,
236262 struct pinctrl_gpio_range *range,
....@@ -644,37 +670,16 @@
644670 setting->data.mux.func);
645671 }
646672
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);
670675
671676 void pinmux_init_device_debugfs(struct dentry *devroot,
672677 struct pinctrl_dev *pctldev)
673678 {
674679 debugfs_create_file("pinmux-functions", S_IFREG | S_IRUGO,
675
- devroot, pctldev, &pinmux_functions_ops);
680
+ devroot, pctldev, &pinmux_functions_fops);
676681 debugfs_create_file("pinmux-pins", S_IFREG | S_IRUGO,
677
- devroot, pctldev, &pinmux_pins_ops);
682
+ devroot, pctldev, &pinmux_pins_fops);
678683 }
679684
680685 #endif /* CONFIG_DEBUG_FS */
....@@ -742,7 +747,7 @@
742747 /**
743748 * pinmux_generic_get_function() - returns a function based on the number
744749 * @pctldev: pin controller device
745
- * @group_selector: function number
750
+ * @selector: function number
746751 */
747752 struct function_desc *pinmux_generic_get_function(struct pinctrl_dev *pctldev,
748753 unsigned int selector)