blob: fee4349364f77ed971fac838bf95391e0097f585 [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
Linus Walleij9a01be12012-03-06 21:15:51 +010015#include "pinctrl-state.h"
Stephen Warren46919ae2012-03-01 18:48:32 -070016
Stephen Warren1e2082b2012-03-02 13:05:48 -070017enum pinctrl_map_type {
18 PIN_MAP_TYPE_INVALID,
19 PIN_MAP_TYPE_DUMMY_STATE,
20 PIN_MAP_TYPE_MUX_GROUP,
21 PIN_MAP_TYPE_CONFIGS_PIN,
22 PIN_MAP_TYPE_CONFIGS_GROUP,
23};
24
25/**
26 * struct pinctrl_map_mux - mapping table content for MAP_TYPE_MUX_GROUP
27 * @group: the name of the group whose mux function is to be configured. This
28 * field may be left NULL, and the first applicable group for the function
29 * will be used.
30 * @function: the mux function to select for the group
31 */
32struct pinctrl_map_mux {
33 const char *group;
34 const char *function;
35};
36
37/**
38 * struct pinctrl_map_configs - mapping table content for MAP_TYPE_CONFIGS_*
39 * @group_or_pin: the name of the pin or group whose configuration parameters
40 * are to be configured.
41 * @configs: a pointer to an array of config parameters/values to program into
42 * hardware. Each individual pin controller defines the format and meaning
43 * of config parameters.
44 * @num_configs: the number of entries in array @configs
45 */
46struct pinctrl_map_configs {
47 const char *group_or_pin;
48 unsigned long *configs;
49 unsigned num_configs;
50};
51
Linus Walleij2744e8a2011-05-02 20:50:54 +020052/**
Linus Walleije93bcee2012-02-09 07:23:28 +010053 * struct pinctrl_map - boards/machines shall provide this map for devices
Stephen Warren806d3142012-02-23 17:04:39 -070054 * @dev_name: the name of the device using this specific mapping, the name
55 * must be the same as in your struct device*. If this name is set to the
56 * same name as the pin controllers own dev_name(), the map entry will be
57 * hogged by the driver itself upon registration
Linus Walleij2744e8a2011-05-02 20:50:54 +020058 * @name: the name of this specific map entry for the particular machine.
Stephen Warren6e5e9592012-03-02 13:05:47 -070059 * This is the parameter passed to pinmux_lookup_state()
Stephen Warren1e2082b2012-03-02 13:05:48 -070060 * @type: the type of mapping table entry
Linus Walleij2744e8a2011-05-02 20:50:54 +020061 * @ctrl_dev_name: the name of the device controlling this specific mapping,
Stephen Warren1e2082b2012-03-02 13:05:48 -070062 * the name must be the same as in your struct device*. This field is not
63 * used for PIN_MAP_TYPE_DUMMY_STATE
64 * @data: Data specific to the mapping type
Linus Walleij2744e8a2011-05-02 20:50:54 +020065 */
Linus Walleije93bcee2012-02-09 07:23:28 +010066struct pinctrl_map {
Stephen Warren806d3142012-02-23 17:04:39 -070067 const char *dev_name;
Linus Walleij2744e8a2011-05-02 20:50:54 +020068 const char *name;
Stephen Warren1e2082b2012-03-02 13:05:48 -070069 enum pinctrl_map_type type;
Linus Walleij2744e8a2011-05-02 20:50:54 +020070 const char *ctrl_dev_name;
Stephen Warren1e2082b2012-03-02 13:05:48 -070071 union {
72 struct pinctrl_map_mux mux;
73 struct pinctrl_map_configs configs;
74 } data;
Linus Walleij2744e8a2011-05-02 20:50:54 +020075};
76
Stephen Warren1e2082b2012-03-02 13:05:48 -070077/* Convenience macros to create mapping table entries */
Linus Walleij2744e8a2011-05-02 20:50:54 +020078
Stephen Warren1e2082b2012-03-02 13:05:48 -070079#define PIN_MAP_DUMMY_STATE(dev, state) \
80 { \
81 .dev_name = dev, \
82 .name = state, \
83 .type = PIN_MAP_TYPE_DUMMY_STATE, \
84 }
Stephen Warren1ddb6ff2011-12-09 16:59:03 -070085
Stephen Warren1e2082b2012-03-02 13:05:48 -070086#define PIN_MAP_MUX_GROUP(dev, state, pinctrl, grp, func) \
87 { \
88 .dev_name = dev, \
89 .name = state, \
90 .type = PIN_MAP_TYPE_MUX_GROUP, \
91 .ctrl_dev_name = pinctrl, \
92 .data.mux = { \
93 .group = grp, \
94 .function = func, \
95 }, \
96 }
97
98#define PIN_MAP_MUX_GROUP_DEFAULT(dev, pinctrl, grp, func) \
99 PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, func)
100
101#define PIN_MAP_MUX_GROUP_HOG(dev, state, grp, func) \
102 PIN_MAP_MUX_GROUP(dev, state, dev, grp, func)
103
104#define PIN_MAP_MUX_GROUP_HOG_DEFAULT(dev, grp, func) \
105 PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, func)
106
107#define PIN_MAP_CONFIGS_PIN(dev, state, pinctrl, pin, cfgs) \
108 { \
109 .dev_name = dev, \
110 .name = state, \
111 .type = PIN_MAP_TYPE_CONFIGS_PIN, \
112 .ctrl_dev_name = pinctrl, \
113 .data.configs = { \
114 .group_or_pin = pin, \
115 .configs = cfgs, \
116 .num_configs = ARRAY_SIZE(cfgs), \
117 }, \
118 }
119
120#define PIN_MAP_CONFIGS_PIN_DEFAULT(dev, pinctrl, pin, cfgs) \
121 PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, pinctrl, pin, cfgs)
122
123#define PIN_MAP_CONFIGS_PIN_HOG(dev, state, pin, cfgs) \
124 PIN_MAP_CONFIGS_PIN(dev, state, dev, pin, cfgs)
125
126#define PIN_MAP_CONFIGS_PIN_HOG_DEFAULT(dev, pin, cfgs) \
127 PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, dev, pin, cfgs)
128
129#define PIN_MAP_CONFIGS_GROUP(dev, state, pinctrl, grp, cfgs) \
130 { \
131 .dev_name = dev, \
132 .name = state, \
133 .type = PIN_MAP_TYPE_CONFIGS_GROUP, \
134 .ctrl_dev_name = pinctrl, \
135 .data.configs = { \
136 .group_or_pin = grp, \
137 .configs = cfgs, \
138 .num_configs = ARRAY_SIZE(cfgs), \
139 }, \
140 }
141
142#define PIN_MAP_CONFIGS_GROUP_DEFAULT(dev, pinctrl, grp, cfgs) \
143 PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, cfgs)
144
145#define PIN_MAP_CONFIGS_GROUP_HOG(dev, state, grp, cfgs) \
146 PIN_MAP_CONFIGS_GROUP(dev, state, dev, grp, cfgs)
147
148#define PIN_MAP_CONFIGS_GROUP_HOG_DEFAULT(dev, grp, cfgs) \
149 PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, cfgs)
Linus Walleij23750192011-12-14 09:30:08 +0100150
Linus Walleij2744e8a2011-05-02 20:50:54 +0200151#ifdef CONFIG_PINMUX
152
Linus Walleije93bcee2012-02-09 07:23:28 +0100153extern int pinctrl_register_mappings(struct pinctrl_map const *map,
Linus Walleij2744e8a2011-05-02 20:50:54 +0200154 unsigned num_maps);
155
156#else
157
Linus Walleije93bcee2012-02-09 07:23:28 +0100158static inline int pinctrl_register_mappings(struct pinctrl_map const *map,
Linus Walleij2744e8a2011-05-02 20:50:54 +0200159 unsigned num_maps)
160{
161 return 0;
162}
163
164#endif /* !CONFIG_PINMUX */
165#endif