blob: cc8e1aff0e28cadf524d73c2ffad2301b037b53d [file] [log] [blame]
Linus Walleij2744e8a2011-05-02 20:50:54 +02001/*
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>
Linus Walleij2744e8a2011-05-02 20:50:54 +020018#include <linux/list.h>
19#include <linux/seq_file.h>
David Howellsa1ce3922012-10-02 18:01:25 +010020#include <linux/pinctrl/pinctrl-state.h>
Stephen Warren46919ae2012-03-01 18:48:32 -070021
Stephen Warren0acfb072012-03-06 12:12:12 -070022struct device;
Linus Walleij2744e8a2011-05-02 20:50:54 +020023struct pinctrl_dev;
Stephen Warren57291ce2012-03-23 10:29:46 -060024struct pinctrl_map;
Linus Walleij2744e8a2011-05-02 20:50:54 +020025struct pinmux_ops;
Linus Walleijae6b4d82011-10-19 18:14:33 +020026struct pinconf_ops;
Linus Walleij2744e8a2011-05-02 20:50:54 +020027struct gpio_chip;
Stephen Warren57291ce2012-03-23 10:29:46 -060028struct device_node;
Linus Walleij2744e8a2011-05-02 20:50:54 +020029
30/**
31 * struct pinctrl_pin_desc - boards/machines provide information on their
32 * pins, pads or other muxable units in this struct
33 * @number: unique pin number from the global pin number space
34 * @name: a name for this pin
Sherman Yina30d54212013-12-20 18:13:33 -080035 * @drv_data: driver-defined per-pin data. pinctrl core does not touch this
Linus Walleij2744e8a2011-05-02 20:50:54 +020036 */
37struct pinctrl_pin_desc {
38 unsigned number;
39 const char *name;
Sherman Yina30d54212013-12-20 18:13:33 -080040 void *drv_data;
Linus Walleij2744e8a2011-05-02 20:50:54 +020041};
42
43/* Convenience macro to define a single named or anonymous pin descriptor */
44#define PINCTRL_PIN(a, b) { .number = a, .name = b }
45#define PINCTRL_PIN_ANON(a) { .number = a }
46
47/**
48 * struct pinctrl_gpio_range - each pin controller can provide subranges of
49 * the GPIO number space to be handled by the controller
50 * @node: list node for internal use
51 * @name: a name for the chip in this range
52 * @id: an ID number for the chip in this range
53 * @base: base offset of the GPIO range
Christian Ruppert56a59912013-06-14 10:24:48 +020054 * @pin_base: base pin number of the GPIO range if pins == NULL
Christian Ruppertc8587ee2013-06-13 14:55:31 +020055 * @pins: enumeration of pins in GPIO range or NULL
Linus Walleij2744e8a2011-05-02 20:50:54 +020056 * @npins: number of pins in the GPIO range, including the base number
57 * @gc: an optional pointer to a gpio_chip
58 */
59struct pinctrl_gpio_range {
60 struct list_head node;
61 const char *name;
62 unsigned int id;
63 unsigned int base;
Chanho Park3c739ad2011-11-11 18:47:58 +090064 unsigned int pin_base;
Christian Ruppertc8587ee2013-06-13 14:55:31 +020065 unsigned const *pins;
Linus Walleij2744e8a2011-05-02 20:50:54 +020066 unsigned int npins;
67 struct gpio_chip *gc;
68};
69
70/**
71 * struct pinctrl_ops - global pin control operations, to be implemented by
72 * pin controller drivers.
Viresh Kumard1e90e92012-03-30 11:25:40 +053073 * @get_groups_count: Returns the count of total number of groups registered.
Linus Walleij2744e8a2011-05-02 20:50:54 +020074 * @get_group_name: return the group name of the pin group
75 * @get_group_pins: return an array of pins corresponding to a certain
76 * group selector @pins, and the size of the array in @num_pins
77 * @pin_dbg_show: optional debugfs display hook that will provide per-device
78 * info for a certain pin in debugfs
Stephen Warren02ae6da2012-04-26 10:18:52 -060079 * @dt_node_to_map: parse a device tree "pin configuration node", and create
80 * mapping table entries for it. These are returned through the @map and
81 * @num_maps output parameters. This function is optional, and may be
82 * omitted for pinctrl drivers that do not support device tree.
83 * @dt_free_map: free mapping table entries created via @dt_node_to_map. The
84 * top-level @map pointer must be freed, along with any dynamically
85 * allocated members of the mapping table entries themselves. This
86 * function is optional, and may be omitted for pinctrl drivers that do
87 * not support device tree.
Linus Walleij2744e8a2011-05-02 20:50:54 +020088 */
89struct pinctrl_ops {
Viresh Kumard1e90e92012-03-30 11:25:40 +053090 int (*get_groups_count) (struct pinctrl_dev *pctldev);
Linus Walleij2744e8a2011-05-02 20:50:54 +020091 const char *(*get_group_name) (struct pinctrl_dev *pctldev,
92 unsigned selector);
93 int (*get_group_pins) (struct pinctrl_dev *pctldev,
94 unsigned selector,
Stephen Warrena5818a82011-10-19 16:19:25 -060095 const unsigned **pins,
96 unsigned *num_pins);
Linus Walleij2744e8a2011-05-02 20:50:54 +020097 void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s,
98 unsigned offset);
Stephen Warren57291ce2012-03-23 10:29:46 -060099 int (*dt_node_to_map) (struct pinctrl_dev *pctldev,
100 struct device_node *np_config,
101 struct pinctrl_map **map, unsigned *num_maps);
102 void (*dt_free_map) (struct pinctrl_dev *pctldev,
103 struct pinctrl_map *map, unsigned num_maps);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200104};
105
106/**
107 * struct pinctrl_desc - pin controller descriptor, register this to pin
108 * control subsystem
109 * @name: name for the pin controller
110 * @pins: an array of pin descriptors describing all the pins handled by
111 * this pin controller
112 * @npins: number of descriptors in the array, usually just ARRAY_SIZE()
113 * of the pins field above
Linus Walleij2744e8a2011-05-02 20:50:54 +0200114 * @pctlops: pin control operation vtable, to support global concepts like
115 * grouping of pins, this is optional.
Linus Walleijae6b4d82011-10-19 18:14:33 +0200116 * @pmxops: pinmux operations vtable, if you support pinmuxing in your driver
117 * @confops: pin config operations vtable, if you support pin configuration in
118 * your driver
Linus Walleij2744e8a2011-05-02 20:50:54 +0200119 * @owner: module providing the pin controller, used for refcounting
120 */
121struct pinctrl_desc {
122 const char *name;
123 struct pinctrl_pin_desc const *pins;
124 unsigned int npins;
Laurent Pinchart022ab142013-02-16 10:25:07 +0100125 const struct pinctrl_ops *pctlops;
126 const struct pinmux_ops *pmxops;
127 const struct pinconf_ops *confops;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200128 struct module *owner;
129};
130
131/* External interface to pin controller */
132extern struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
133 struct device *dev, void *driver_data);
134extern void pinctrl_unregister(struct pinctrl_dev *pctldev);
135extern bool pin_is_valid(struct pinctrl_dev *pctldev, int pin);
136extern void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
137 struct pinctrl_gpio_range *range);
Dong Aisheng3e5e00b2012-05-23 21:22:41 +0800138extern void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev,
139 struct pinctrl_gpio_range *ranges,
140 unsigned nranges);
Viresh Kumar7e10ee62012-10-27 15:21:35 +0530141extern void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
142 struct pinctrl_gpio_range *range);
Shiraz Hashimf23f1512012-10-27 15:21:36 +0530143
Linus Walleij192c3692012-11-20 14:03:37 +0100144extern struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname,
Shiraz Hashimf23f1512012-10-27 15:21:36 +0530145 struct pinctrl_gpio_range *range);
Linus Walleij9afbefb2012-11-20 14:25:07 +0100146extern struct pinctrl_gpio_range *
147pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev,
148 unsigned int pin);
Christian Ruppert586a87e2013-10-15 15:37:54 +0200149extern int pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
150 const char *pin_group, const unsigned **pins,
151 unsigned *num_pins);
Shiraz Hashimf23f1512012-10-27 15:21:36 +0530152
153#ifdef CONFIG_OF
Linus Walleij1e63d7b2012-11-06 16:03:35 +0100154extern struct pinctrl_dev *of_pinctrl_get(struct device_node *np);
Shiraz Hashimf23f1512012-10-27 15:21:36 +0530155#else
156static inline
Linus Walleij1e63d7b2012-11-06 16:03:35 +0100157struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
Shiraz Hashimf23f1512012-10-27 15:21:36 +0530158{
159 return NULL;
160}
Shiraz Hashimf23f1512012-10-27 15:21:36 +0530161#endif /* CONFIG_OF */
162
Linus Walleij2744e8a2011-05-02 20:50:54 +0200163extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev);
Haojian Zhuangd6e99ab2013-01-18 15:31:06 +0800164extern const char *pinctrl_dev_get_devname(struct pinctrl_dev *pctldev);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200165extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev);
166#else
167
Barry Songe0e20752011-10-27 20:38:24 -0700168struct pinctrl_dev;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200169
Linus Walleijae6b4d82011-10-19 18:14:33 +0200170/* Sufficiently stupid default functions when pinctrl is not in use */
Linus Walleij2744e8a2011-05-02 20:50:54 +0200171static inline bool pin_is_valid(struct pinctrl_dev *pctldev, int pin)
172{
173 return pin >= 0;
174}
175
176#endif /* !CONFIG_PINCTRL */
177
178#endif /* __LINUX_PINCTRL_PINCTRL_H */