1 From 13e754b5fff5be1930e2b8fe534a52b608c9e479 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Mon, 3 Dec 2012 19:27:28 +0100
4 Subject: [PATCH] PINCTRL: lantiq: fixes
7 drivers/pinctrl/pinctrl-lantiq.c | 54 ++++++++++++++++++-----------
8 drivers/pinctrl/pinctrl-lantiq.h | 1 +
9 drivers/pinctrl/pinctrl-xway.c | 70 ++++++++++++++++++++++++++++++++++----
10 3 files changed, 99 insertions(+), 26 deletions(-)
12 Index: linux-3.7-rc8/drivers/pinctrl/pinctrl-lantiq.c
13 ===================================================================
14 --- linux-3.7-rc8.orig/drivers/pinctrl/pinctrl-lantiq.c 2012-12-03 20:22:37.000000000 +0100
15 +++ linux-3.7-rc8/drivers/pinctrl/pinctrl-lantiq.c 2012-12-14 22:59:40.687563565 +0100
17 seq_printf(s, " %s", dev_name(pctldev->dev));
20 -static int ltq_pinctrl_dt_subnode_to_map(struct pinctrl_dev *pctldev,
21 +static void ltq_pinctrl_dt_subnode_to_map(struct pinctrl_dev *pctldev,
22 struct device_node *np,
23 struct pinctrl_map **map)
25 struct ltq_pinmux_info *info = pinctrl_dev_get_drvdata(pctldev);
26 + struct property *pins = of_find_property(np, "lantiq,pins", NULL);
27 + struct property *groups = of_find_property(np, "lantiq,groups", NULL);
28 unsigned long configs[3];
29 unsigned num_configs = 0;
30 struct property *prop;
35 + if (!pins && !groups) {
36 + dev_err(pctldev->dev, "%s defines neither pins nor groups\n",
41 + if (pins && groups) {
42 + dev_err(pctldev->dev, "%s defines both pins and groups\n",
47 ret = of_property_read_string(np, "lantiq,function", &function);
49 + if (groups && !ret) {
50 of_property_for_each_string(np, "lantiq,groups", prop, group) {
51 (*map)->type = PIN_MAP_TYPE_MUX_GROUP;
52 (*map)->name = function;
54 (*map)->data.mux.function = function;
57 - if (of_find_property(np, "lantiq,pins", NULL))
58 - dev_err(pctldev->dev,
59 - "%s mixes pins and groups settings\n",
64 for (i = 0; i < info->num_params; i++) {
72 of_property_for_each_string(np, "lantiq,pins", prop, pin) {
73 (*map)->data.configs.configs = kmemdup(configs,
75 (*map)->data.configs.num_configs = num_configs;
79 + of_property_for_each_string(np, "lantiq,groups", prop, group) {
80 + (*map)->data.configs.configs = kmemdup(configs,
81 + num_configs * sizeof(unsigned long),
83 + (*map)->type = PIN_MAP_TYPE_CONFIGS_GROUP;
84 + (*map)->name = group;
85 + (*map)->data.configs.group_or_pin = group;
86 + (*map)->data.configs.num_configs = num_configs;
91 static int ltq_pinctrl_dt_subnode_size(struct device_node *np)
94 struct pinctrl_map *tmp;
95 struct device_node *np;
100 for_each_child_of_node(np_config, np)
101 - *num_maps += ltq_pinctrl_dt_subnode_size(np);
102 - *map = kzalloc(*num_maps * sizeof(struct pinctrl_map), GFP_KERNEL);
103 + max_maps += ltq_pinctrl_dt_subnode_size(np);
104 + *map = kzalloc(max_maps * sizeof(struct pinctrl_map) * 2, GFP_KERNEL);
109 - for_each_child_of_node(np_config, np) {
110 - ret = ltq_pinctrl_dt_subnode_to_map(pctldev, np, &tmp);
112 - ltq_pinctrl_dt_free_map(pctldev, *map, *num_maps);
116 + for_each_child_of_node(np_config, np)
117 + ltq_pinctrl_dt_subnode_to_map(pctldev, np, &tmp);
118 + *num_maps = ((int)(tmp - *map));
123 Index: linux-3.7-rc8/drivers/pinctrl/pinctrl-lantiq.h
124 ===================================================================
125 --- linux-3.7-rc8.orig/drivers/pinctrl/pinctrl-lantiq.h 2012-12-03 20:22:37.000000000 +0100
126 +++ linux-3.7-rc8/drivers/pinctrl/pinctrl-lantiq.h 2012-12-14 22:55:26.591557194 +0100
128 LTQ_PINCONF_PARAM_OPEN_DRAIN,
129 LTQ_PINCONF_PARAM_DRIVE_CURRENT,
130 LTQ_PINCONF_PARAM_SLEW_RATE,
131 + LTQ_PINCONF_PARAM_OUTPUT,
134 struct ltq_cfg_param {
135 Index: linux-3.7-rc8/drivers/pinctrl/pinctrl-xway.c
136 ===================================================================
137 --- linux-3.7-rc8.orig/drivers/pinctrl/pinctrl-xway.c 2012-12-14 22:55:26.567557195 +0100
138 +++ linux-3.7-rc8/drivers/pinctrl/pinctrl-xway.c 2012-12-14 22:55:26.595557195 +0100
142 *config = LTQ_PINCONF_PACK(param,
143 - !!gpio_getbit(info->membase[0], reg, PORT_PIN(pin)));
144 + !gpio_getbit(info->membase[0], reg, PORT_PIN(pin)));
147 case LTQ_PINCONF_PARAM_PULL:
149 *config = LTQ_PINCONF_PACK(param, 1);
152 + case LTQ_PINCONF_PARAM_OUTPUT:
153 + reg = GPIO_DIR(pin);
154 + *config = LTQ_PINCONF_PACK(param,
155 + gpio_getbit(info->membase[0], reg, PORT_PIN(pin)));
158 dev_err(pctldev->dev, "Invalid config param %04x\n", param);
164 - gpio_setbit(info->membase[0], reg, PORT_PIN(pin));
166 + gpio_setbit(info->membase[0], reg, PORT_PIN(pin));
168 + gpio_clearbit(info->membase[0], reg, PORT_PIN(pin));
171 case LTQ_PINCONF_PARAM_PULL:
173 dev_err(pctldev->dev, "Invalid pull value %d\n", arg);
176 + case LTQ_PINCONF_PARAM_OUTPUT:
177 + reg = GPIO_DIR(pin);
179 + gpio_clearbit(info->membase[0], reg, PORT_PIN(pin));
181 + gpio_setbit(info->membase[0], reg, PORT_PIN(pin));
185 dev_err(pctldev->dev, "Invalid config param %04x\n", param);
191 +int xway_pinconf_group_set(struct pinctrl_dev *pctldev,
193 + unsigned long config)
195 + struct ltq_pinmux_info *info = pinctrl_dev_get_drvdata(pctldev);
198 + for (i = 0; i < info->grps[selector].npins && !ret; i++)
199 + ret = xway_pinconf_set(pctldev,
200 + info->grps[selector].pins[i], config);
206 struct pinconf_ops xway_pinconf_ops = {
207 .pin_config_get = xway_pinconf_get,
208 .pin_config_set = xway_pinconf_set,
209 + .pin_config_group_set = xway_pinconf_group_set,
212 static struct pinctrl_desc xway_pctrl_desc = {
214 .confops = &xway_pinconf_ops,
217 -static inline int xway_mux_apply(struct pinctrl_dev *pctrldev,
218 +static int mux_apply(struct ltq_pinmux_info *info,
221 - struct ltq_pinmux_info *info = pinctrl_dev_get_drvdata(pctrldev);
222 int port = PORT(pin);
223 u32 alt1_reg = GPIO_ALT1(pin);
229 +static inline int xway_mux_apply(struct pinctrl_dev *pctrldev,
232 + struct ltq_pinmux_info *info = pinctrl_dev_get_drvdata(pctrldev);
234 + return mux_apply(info, pin, mux);
237 static const struct ltq_cfg_param xway_cfg_params[] = {
238 {"lantiq,pull", LTQ_PINCONF_PARAM_PULL},
239 {"lantiq,open-drain", LTQ_PINCONF_PARAM_OPEN_DRAIN},
240 + {"lantiq,output", LTQ_PINCONF_PARAM_OUTPUT},
243 static struct ltq_pinmux_info xway_info = {
246 struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev);
248 + if (PORT(pin) == PORT3)
249 + gpio_setbit(info->membase[0], GPIO3_OD, PORT_PIN(pin));
251 + gpio_setbit(info->membase[0], GPIO_OD(pin), PORT_PIN(pin));
252 gpio_setbit(info->membase[0], GPIO_DIR(pin), PORT_PIN(pin));
253 xway_gpio_set(chip, pin, val);
256 pinctrl_free_gpio(gpio);
259 +static int xway_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
261 + struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev);
264 + for (i = 0; i < info->num_exin; i++)
265 + if (info->exin[i] == offset)
266 + return ltq_eiu_get_irq(i);
271 static struct gpio_chip xway_chip = {
272 .label = "gpio-xway",
273 .direction_input = xway_gpio_dir_in,
275 .set = xway_gpio_set,
276 .request = xway_gpio_req,
277 .free = xway_gpio_free,
278 + .to_irq = xway_gpio_to_irq,