aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/linux/pinctrl/machine.h107
-rw-r--r--include/linux/pinctrl/pinctrl.h133
-rw-r--r--include/linux/pinctrl/pinmux.h117
3 files changed, 357 insertions, 0 deletions
diff --git a/include/linux/pinctrl/machine.h b/include/linux/pinctrl/machine.h
new file mode 100644
index 000000000000..88863531d862
--- /dev/null
+++ b/include/linux/pinctrl/machine.h
@@ -0,0 +1,107 @@
1/*
2 * Machine interface for the pinctrl subsystem.
3 *
4 * Copyright (C) 2011 ST-Ericsson SA
5 * Written on behalf of Linaro for ST-Ericsson
6 * Based on bits of regulator core, gpio core and clk core
7 *
8 * Author: Linus Walleij <linus.walleij@linaro.org>
9 *
10 * License terms: GNU General Public License (GPL) version 2
11 */
12#ifndef __LINUX_PINMUX_MACHINE_H
13#define __LINUX_PINMUX_MACHINE_H
14
15/**
16 * struct pinmux_map - boards/machines shall provide this map for devices
17 * @name: the name of this specific map entry for the particular machine.
18 * This is the second parameter passed to pinmux_get() when you want
19 * to have several mappings to the same device
20 * @ctrl_dev: the pin control device to be used by this mapping, may be NULL
21 * if you provide .ctrl_dev_name instead (this is more common)
22 * @ctrl_dev_name: the name of the device controlling this specific mapping,
23 * the name must be the same as in your struct device*, may be NULL if
24 * you provide .ctrl_dev instead
25 * @function: a function in the driver to use for this mapping, the driver
26 * will lookup the function referenced by this ID on the specified
27 * pin control device
28 * @group: sometimes a function can map to different pin groups, so this
29 * selects a certain specific pin group to activate for the function, if
30 * left as NULL, the first applicable group will be used
31 * @dev: the device using this specific mapping, may be NULL if you provide
32 * .dev_name instead (this is more common)
33 * @dev_name: the name of the device using this specific mapping, the name
34 * must be the same as in your struct device*, may be NULL if you
35 * provide .dev instead
36 * @hog_on_boot: if this is set to true, the pin control subsystem will itself
37 * hog the mappings as the pinmux device drivers are attached, so this is
38 * typically used with system maps (mux mappings without an assigned
39 * device) that you want to get hogged and enabled by default as soon as
40 * a pinmux device supporting it is registered. These maps will not be
41 * disabled and put until the system shuts down.
42 */
43struct pinmux_map {
44 const char *name;
45 struct device *ctrl_dev;
46 const char *ctrl_dev_name;
47 const char *function;
48 const char *group;
49 struct device *dev;
50 const char *dev_name;
51 const bool hog_on_boot;
52};
53
54/*
55 * Convenience macro to set a simple map from a certain pin controller and a
56 * certain function to a named device
57 */
58#define PINMUX_MAP(a, b, c, d) \
59 { .name = a, .ctrl_dev_name = b, .function = c, .dev_name = d }
60
61/*
62 * Convenience macro to map a system function onto a certain pinctrl device.
63 * System functions are not assigned to a particular device.
64 */
65#define PINMUX_MAP_SYS(a, b, c) \
66 { .name = a, .ctrl_dev_name = b, .function = c }
67
68/*
69 * Convenience macro to map a function onto the primary device pinctrl device
70 * this is especially helpful on systems that have only one pin controller
71 * or need to set up a lot of mappings on the primary controller.
72 */
73#define PINMUX_MAP_PRIMARY(a, b, c) \
74 { .name = a, .ctrl_dev_name = "pinctrl.0", .function = b, \
75 .dev_name = c }
76
77/*
78 * Convenience macro to map a system function onto the primary pinctrl device.
79 * System functions are not assigned to a particular device.
80 */
81#define PINMUX_MAP_PRIMARY_SYS(a, b) \
82 { .name = a, .ctrl_dev_name = "pinctrl.0", .function = b }
83
84/*
85 * Convenience macro to map a system function onto the primary pinctrl device,
86 * to be hogged by the pinmux core until the system shuts down.
87 */
88#define PINMUX_MAP_PRIMARY_SYS_HOG(a, b) \
89 { .name = a, .ctrl_dev_name = "pinctrl.0", .function = b, \
90 .hog_on_boot = true }
91
92
93#ifdef CONFIG_PINMUX
94
95extern int pinmux_register_mappings(struct pinmux_map const *map,
96 unsigned num_maps);
97
98#else
99
100static inline int pinmux_register_mappings(struct pinmux_map const *map,
101 unsigned num_maps)
102{
103 return 0;
104}
105
106#endif /* !CONFIG_PINMUX */
107#endif
diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h
new file mode 100644
index 000000000000..4f8d2089acce
--- /dev/null
+++ b/include/linux/pinctrl/pinctrl.h
@@ -0,0 +1,133 @@
1/*
2 * Interface the pinctrl subsystem
3 *
4 * Copyright (C) 2011 ST-Ericsson SA
5 * Written on behalf of Linaro for ST-Ericsson
6 * This interface is used in the core to keep track of pins.
7 *
8 * Author: Linus Walleij <linus.walleij@linaro.org>
9 *
10 * License terms: GNU General Public License (GPL) version 2
11 */
12#ifndef __LINUX_PINCTRL_PINCTRL_H
13#define __LINUX_PINCTRL_PINCTRL_H
14
15#ifdef CONFIG_PINCTRL
16
17#include <linux/radix-tree.h>
18#include <linux/spinlock.h>
19#include <linux/list.h>
20#include <linux/seq_file.h>
21
22struct pinctrl_dev;
23struct pinmux_ops;
24struct gpio_chip;
25
26/**
27 * struct pinctrl_pin_desc - boards/machines provide information on their
28 * pins, pads or other muxable units in this struct
29 * @number: unique pin number from the global pin number space
30 * @name: a name for this pin
31 */
32struct pinctrl_pin_desc {
33 unsigned number;
34 const char *name;
35};
36
37/* Convenience macro to define a single named or anonymous pin descriptor */
38#define PINCTRL_PIN(a, b) { .number = a, .name = b }
39#define PINCTRL_PIN_ANON(a) { .number = a }
40
41/**
42 * struct pinctrl_gpio_range - each pin controller can provide subranges of
43 * the GPIO number space to be handled by the controller
44 * @node: list node for internal use
45 * @name: a name for the chip in this range
46 * @id: an ID number for the chip in this range
47 * @base: base offset of the GPIO range
48 * @npins: number of pins in the GPIO range, including the base number
49 * @gc: an optional pointer to a gpio_chip
50 */
51struct pinctrl_gpio_range {
52 struct list_head node;
53 const char *name;
54 unsigned int id;
55 unsigned int base;
56 unsigned int npins;
57 struct gpio_chip *gc;
58};
59
60/**
61 * struct pinctrl_ops - global pin control operations, to be implemented by
62 * pin controller drivers.
63 * @list_groups: list the number of selectable named groups available
64 * in this pinmux driver, the core will begin on 0 and call this
65 * repeatedly as long as it returns >= 0 to enumerate the groups
66 * @get_group_name: return the group name of the pin group
67 * @get_group_pins: return an array of pins corresponding to a certain
68 * group selector @pins, and the size of the array in @num_pins
69 * @pin_dbg_show: optional debugfs display hook that will provide per-device
70 * info for a certain pin in debugfs
71 */
72struct pinctrl_ops {
73 int (*list_groups) (struct pinctrl_dev *pctldev, unsigned selector);
74 const char *(*get_group_name) (struct pinctrl_dev *pctldev,
75 unsigned selector);
76 int (*get_group_pins) (struct pinctrl_dev *pctldev,
77 unsigned selector,
78 unsigned ** const pins,
79 unsigned * const num_pins);
80 void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s,
81 unsigned offset);
82};
83
84/**
85 * struct pinctrl_desc - pin controller descriptor, register this to pin
86 * control subsystem
87 * @name: name for the pin controller
88 * @pins: an array of pin descriptors describing all the pins handled by
89 * this pin controller
90 * @npins: number of descriptors in the array, usually just ARRAY_SIZE()
91 * of the pins field above
92 * @maxpin: since pin spaces may be sparse, there can he "holes" in the
93 * pin range, this attribute gives the maximum pin number in the
94 * total range. This should not be lower than npins for example,
95 * but may be equal to npins if you have no holes in the pin range.
96 * @pctlops: pin control operation vtable, to support global concepts like
97 * grouping of pins, this is optional.
98 * @pmxops: pinmux operation vtable, if you support pinmuxing in your driver
99 * @owner: module providing the pin controller, used for refcounting
100 */
101struct pinctrl_desc {
102 const char *name;
103 struct pinctrl_pin_desc const *pins;
104 unsigned int npins;
105 unsigned int maxpin;
106 struct pinctrl_ops *pctlops;
107 struct pinmux_ops *pmxops;
108 struct module *owner;
109};
110
111/* External interface to pin controller */
112extern struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
113 struct device *dev, void *driver_data);
114extern void pinctrl_unregister(struct pinctrl_dev *pctldev);
115extern bool pin_is_valid(struct pinctrl_dev *pctldev, int pin);
116extern void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
117 struct pinctrl_gpio_range *range);
118extern void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
119 struct pinctrl_gpio_range *range);
120extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev);
121extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev);
122#else
123
124
125/* Sufficiently stupid default function when pinctrl is not in use */
126static inline bool pin_is_valid(struct pinctrl_dev *pctldev, int pin)
127{
128 return pin >= 0;
129}
130
131#endif /* !CONFIG_PINCTRL */
132
133#endif /* __LINUX_PINCTRL_PINCTRL_H */
diff --git a/include/linux/pinctrl/pinmux.h b/include/linux/pinctrl/pinmux.h
new file mode 100644
index 000000000000..3c430e797efc
--- /dev/null
+++ b/include/linux/pinctrl/pinmux.h
@@ -0,0 +1,117 @@
1/*
2 * Interface the pinmux subsystem
3 *
4 * Copyright (C) 2011 ST-Ericsson SA
5 * Written on behalf of Linaro for ST-Ericsson
6 * Based on bits of regulator core, gpio core and clk core
7 *
8 * Author: Linus Walleij <linus.walleij@linaro.org>
9 *
10 * License terms: GNU General Public License (GPL) version 2
11 */
12#ifndef __LINUX_PINCTRL_PINMUX_H
13#define __LINUX_PINCTRL_PINMUX_H
14
15#include <linux/list.h>
16#include <linux/seq_file.h>
17#include "pinctrl.h"
18
19/* This struct is private to the core and should be regarded as a cookie */
20struct pinmux;
21
22#ifdef CONFIG_PINMUX
23
24struct pinctrl_dev;
25
26/**
27 * struct pinmux_ops - pinmux operations, to be implemented by pin controller
28 * drivers that support pinmuxing
29 * @request: called by the core to see if a certain pin can be made available
30 * available for muxing. This is called by the core to acquire the pins
31 * before selecting any actual mux setting across a function. The driver
32 * is allowed to answer "no" by returning a negative error code
33 * @free: the reverse function of the request() callback, frees a pin after
34 * being requested
35 * @list_functions: list the number of selectable named functions available
36 * in this pinmux driver, the core will begin on 0 and call this
37 * repeatedly as long as it returns >= 0 to enumerate mux settings
38 * @get_function_name: return the function name of the muxing selector,
39 * called by the core to figure out which mux setting it shall map a
40 * certain device to
41 * @get_function_groups: return an array of groups names (in turn
42 * referencing pins) connected to a certain function selector. The group
43 * name can be used with the generic @pinctrl_ops to retrieve the
44 * actual pins affected. The applicable groups will be returned in
45 * @groups and the number of groups in @num_groups
46 * @enable: enable a certain muxing function with a certain pin group. The
47 * driver does not need to figure out whether enabling this function
48 * conflicts some other use of the pins in that group, such collisions
49 * are handled by the pinmux subsystem. The @func_selector selects a
50 * certain function whereas @group_selector selects a certain set of pins
51 * to be used. On simple controllers the latter argument may be ignored
52 * @disable: disable a certain muxing selector with a certain pin group
53 * @gpio_request_enable: requests and enables GPIO on a certain pin.
54 * Implement this only if you can mux every pin individually as GPIO. The
55 * affected GPIO range is passed along with an offset into that
56 * specific GPIO range - function selectors and pin groups are orthogonal
57 * to this, the core will however make sure the pins do not collide
58 */
59struct pinmux_ops {
60 int (*request) (struct pinctrl_dev *pctldev, unsigned offset);
61 int (*free) (struct pinctrl_dev *pctldev, unsigned offset);
62 int (*list_functions) (struct pinctrl_dev *pctldev, unsigned selector);
63 const char *(*get_function_name) (struct pinctrl_dev *pctldev,
64 unsigned selector);
65 int (*get_function_groups) (struct pinctrl_dev *pctldev,
66 unsigned selector,
67 const char * const **groups,
68 unsigned * const num_groups);
69 int (*enable) (struct pinctrl_dev *pctldev, unsigned func_selector,
70 unsigned group_selector);
71 void (*disable) (struct pinctrl_dev *pctldev, unsigned func_selector,
72 unsigned group_selector);
73 int (*gpio_request_enable) (struct pinctrl_dev *pctldev,
74 struct pinctrl_gpio_range *range,
75 unsigned offset);
76};
77
78/* External interface to pinmux */
79extern int pinmux_request_gpio(unsigned gpio);
80extern void pinmux_free_gpio(unsigned gpio);
81extern struct pinmux * __must_check pinmux_get(struct device *dev, const char *name);
82extern void pinmux_put(struct pinmux *pmx);
83extern int pinmux_enable(struct pinmux *pmx);
84extern void pinmux_disable(struct pinmux *pmx);
85
86#else /* !CONFIG_PINMUX */
87
88static inline int pinmux_request_gpio(unsigned gpio)
89{
90 return 0;
91}
92
93static inline void pinmux_free_gpio(unsigned gpio)
94{
95}
96
97static inline struct pinmux * __must_check pinmux_get(struct device *dev, const char *name)
98{
99 return NULL;
100}
101
102static inline void pinmux_put(struct pinmux *pmx)
103{
104}
105
106static inline int pinmux_enable(struct pinmux *pmx)
107{
108 return 0;
109}
110
111static inline void pinmux_disable(struct pinmux *pmx)
112{
113}
114
115#endif /* CONFIG_PINMUX */
116
117#endif /* __LINUX_PINCTRL_PINMUX_H */