blob: e5b1716f98cc5c6ebba26ead768ed36223c004bc [file] [log] [blame]
Linus Walleij2744e8a2011-05-02 20:50:54 +02001/*
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 */
Linus Walleije93bcee2012-02-09 07:23:28 +010012#ifndef __LINUX_PINCTRL_MACHINE_H
13#define __LINUX_PINCTRL_MACHINE_H
Linus Walleij2744e8a2011-05-02 20:50:54 +020014
Stephen Warren22f099d2012-03-16 14:54:23 -060015#include <linux/bug.h>
16
David Howellsa1ce3922012-10-02 18:01:25 +010017#include <linux/pinctrl/pinctrl-state.h>
Stephen Warren46919ae2012-03-01 18:48:32 -070018
Stephen Warren1e2082b2012-03-02 13:05:48 -070019enum pinctrl_map_type {
20 PIN_MAP_TYPE_INVALID,
21 PIN_MAP_TYPE_DUMMY_STATE,
22 PIN_MAP_TYPE_MUX_GROUP,
23 PIN_MAP_TYPE_CONFIGS_PIN,
24 PIN_MAP_TYPE_CONFIGS_GROUP,
25};
26
27/**
28 * struct pinctrl_map_mux - mapping table content for MAP_TYPE_MUX_GROUP
29 * @group: the name of the group whose mux function is to be configured. This
30 * field may be left NULL, and the first applicable group for the function
31 * will be used.
32 * @function: the mux function to select for the group
33 */
34struct pinctrl_map_mux {
35 const char *group;
36 const char *function;
37};
38
39/**
40 * struct pinctrl_map_configs - mapping table content for MAP_TYPE_CONFIGS_*
41 * @group_or_pin: the name of the pin or group whose configuration parameters
42 * are to be configured.
43 * @configs: a pointer to an array of config parameters/values to program into
44 * hardware. Each individual pin controller defines the format and meaning
45 * of config parameters.
46 * @num_configs: the number of entries in array @configs
47 */
48struct pinctrl_map_configs {
49 const char *group_or_pin;
50 unsigned long *configs;
51 unsigned num_configs;
52};
53
Linus Walleij2744e8a2011-05-02 20:50:54 +020054/**
Linus Walleije93bcee2012-02-09 07:23:28 +010055 * struct pinctrl_map - boards/machines shall provide this map for devices
Stephen Warren806d3142012-02-23 17:04:39 -070056 * @dev_name: the name of the device using this specific mapping, the name
57 * must be the same as in your struct device*. If this name is set to the
58 * same name as the pin controllers own dev_name(), the map entry will be
59 * hogged by the driver itself upon registration
Linus Walleij2744e8a2011-05-02 20:50:54 +020060 * @name: the name of this specific map entry for the particular machine.
Stephen Warren6e5e9592012-03-02 13:05:47 -070061 * This is the parameter passed to pinmux_lookup_state()
Stephen Warren1e2082b2012-03-02 13:05:48 -070062 * @type: the type of mapping table entry
Linus Walleij2744e8a2011-05-02 20:50:54 +020063 * @ctrl_dev_name: the name of the device controlling this specific mapping,
Stephen Warren1e2082b2012-03-02 13:05:48 -070064 * the name must be the same as in your struct device*. This field is not
65 * used for PIN_MAP_TYPE_DUMMY_STATE
66 * @data: Data specific to the mapping type
Linus Walleij2744e8a2011-05-02 20:50:54 +020067 */
Linus Walleije93bcee2012-02-09 07:23:28 +010068struct pinctrl_map {
Stephen Warren806d3142012-02-23 17:04:39 -070069 const char *dev_name;
Linus Walleij2744e8a2011-05-02 20:50:54 +020070 const char *name;
Stephen Warren1e2082b2012-03-02 13:05:48 -070071 enum pinctrl_map_type type;
Linus Walleij2744e8a2011-05-02 20:50:54 +020072 const char *ctrl_dev_name;
Stephen Warren1e2082b2012-03-02 13:05:48 -070073 union {
74 struct pinctrl_map_mux mux;
75 struct pinctrl_map_configs configs;
76 } data;
Linus Walleij2744e8a2011-05-02 20:50:54 +020077};
78
Stephen Warren1e2082b2012-03-02 13:05:48 -070079/* Convenience macros to create mapping table entries */
Linus Walleij2744e8a2011-05-02 20:50:54 +020080
Stephen Warren1e2082b2012-03-02 13:05:48 -070081#define PIN_MAP_DUMMY_STATE(dev, state) \
82 { \
83 .dev_name = dev, \
84 .name = state, \
85 .type = PIN_MAP_TYPE_DUMMY_STATE, \
86 }
Stephen Warren1ddb6ff2011-12-09 16:59:03 -070087
Stephen Warren1e2082b2012-03-02 13:05:48 -070088#define PIN_MAP_MUX_GROUP(dev, state, pinctrl, grp, func) \
89 { \
90 .dev_name = dev, \
91 .name = state, \
92 .type = PIN_MAP_TYPE_MUX_GROUP, \
93 .ctrl_dev_name = pinctrl, \
94 .data.mux = { \
95 .group = grp, \
96 .function = func, \
97 }, \
98 }
99
100#define PIN_MAP_MUX_GROUP_DEFAULT(dev, pinctrl, grp, func) \
101 PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, func)
102
103#define PIN_MAP_MUX_GROUP_HOG(dev, state, grp, func) \
104 PIN_MAP_MUX_GROUP(dev, state, dev, grp, func)
105
106#define PIN_MAP_MUX_GROUP_HOG_DEFAULT(dev, grp, func) \
107 PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, func)
108
109#define PIN_MAP_CONFIGS_PIN(dev, state, pinctrl, pin, cfgs) \
110 { \
111 .dev_name = dev, \
112 .name = state, \
113 .type = PIN_MAP_TYPE_CONFIGS_PIN, \
114 .ctrl_dev_name = pinctrl, \
115 .data.configs = { \
116 .group_or_pin = pin, \
117 .configs = cfgs, \
118 .num_configs = ARRAY_SIZE(cfgs), \
119 }, \
120 }
121
122#define PIN_MAP_CONFIGS_PIN_DEFAULT(dev, pinctrl, pin, cfgs) \
123 PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, pinctrl, pin, cfgs)
124
125#define PIN_MAP_CONFIGS_PIN_HOG(dev, state, pin, cfgs) \
126 PIN_MAP_CONFIGS_PIN(dev, state, dev, pin, cfgs)
127
128#define PIN_MAP_CONFIGS_PIN_HOG_DEFAULT(dev, pin, cfgs) \
129 PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, dev, pin, cfgs)
130
131#define PIN_MAP_CONFIGS_GROUP(dev, state, pinctrl, grp, cfgs) \
132 { \
133 .dev_name = dev, \
134 .name = state, \
135 .type = PIN_MAP_TYPE_CONFIGS_GROUP, \
136 .ctrl_dev_name = pinctrl, \
137 .data.configs = { \
138 .group_or_pin = grp, \
139 .configs = cfgs, \
140 .num_configs = ARRAY_SIZE(cfgs), \
141 }, \
142 }
143
144#define PIN_MAP_CONFIGS_GROUP_DEFAULT(dev, pinctrl, grp, cfgs) \
145 PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, cfgs)
146
147#define PIN_MAP_CONFIGS_GROUP_HOG(dev, state, grp, cfgs) \
148 PIN_MAP_CONFIGS_GROUP(dev, state, dev, grp, cfgs)
149
150#define PIN_MAP_CONFIGS_GROUP_HOG_DEFAULT(dev, grp, cfgs) \
151 PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, cfgs)
Linus Walleij23750192011-12-14 09:30:08 +0100152
Dong Aisheng6974f1f2012-04-05 17:07:23 +0800153#ifdef CONFIG_PINCTRL
Linus Walleij2744e8a2011-05-02 20:50:54 +0200154
Linus Walleije93bcee2012-02-09 07:23:28 +0100155extern int pinctrl_register_mappings(struct pinctrl_map const *map,
Linus Walleij2744e8a2011-05-02 20:50:54 +0200156 unsigned num_maps);
Dong Aisheng5b3aa5f2012-04-26 16:15:50 +0800157extern void pinctrl_provide_dummies(void);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200158#else
159
Linus Walleije93bcee2012-02-09 07:23:28 +0100160static inline int pinctrl_register_mappings(struct pinctrl_map const *map,
Linus Walleij2744e8a2011-05-02 20:50:54 +0200161 unsigned num_maps)
162{
163 return 0;
164}
165
Dong Aisheng5b3aa5f2012-04-26 16:15:50 +0800166static inline void pinctrl_provide_dummies(void)
167{
168}
Linus Walleijdd512702012-04-24 15:20:02 +0200169#endif /* !CONFIG_PINCTRL */
Linus Walleij2744e8a2011-05-02 20:50:54 +0200170#endif