blob: d113746ec8736dbdc3dda8c8d628c3637146695a [file] [log] [blame]
Paul Mundtca5481c62012-07-10 12:08:14 +09001/*
2 * SuperH Pin Function Controller pinmux support.
3 *
4 * Copyright (C) 2012 Paul Mundt
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
Paul Mundt54407112012-07-20 16:18:21 +090010
Laurent Pinchartc6193ea2012-12-15 23:50:47 +010011#define DRV_NAME "sh-pfc"
Laurent Pinchartf9492fd2012-12-15 23:50:45 +010012#define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt
Paul Mundtca5481c62012-07-10 12:08:14 +090013
Laurent Pinchart1724acf2012-12-15 23:50:48 +010014#include <linux/device.h>
Laurent Pinchart90efde22012-12-15 23:50:52 +010015#include <linux/err.h>
Paul Mundtca5481c62012-07-10 12:08:14 +090016#include <linux/init.h>
17#include <linux/module.h>
Laurent Pinchart90efde22012-12-15 23:50:52 +010018#include <linux/pinctrl/consumer.h>
19#include <linux/pinctrl/pinconf.h>
20#include <linux/pinctrl/pinconf-generic.h>
21#include <linux/pinctrl/pinctrl.h>
22#include <linux/pinctrl/pinmux.h>
Paul Mundtca5481c62012-07-10 12:08:14 +090023#include <linux/slab.h>
Paul Mundtd93a8912012-07-11 17:17:10 +090024#include <linux/spinlock.h>
Paul Mundtca5481c62012-07-10 12:08:14 +090025
Laurent Pinchartf9165132012-12-15 23:50:44 +010026#include "core.h"
27
Paul Mundtca5481c62012-07-10 12:08:14 +090028struct sh_pfc_pinctrl {
29 struct pinctrl_dev *pctl;
Laurent Pinchartdcc427e2013-02-16 16:38:30 +010030 struct pinctrl_desc pctl_desc;
31 struct pinctrl_gpio_range range;
32
Paul Mundtca5481c62012-07-10 12:08:14 +090033 struct sh_pfc *pfc;
34
Paul Mundtd93a8912012-07-11 17:17:10 +090035 struct pinmux_gpio **functions;
36 unsigned int nr_functions;
37
Paul Mundtca5481c62012-07-10 12:08:14 +090038 struct pinctrl_pin_desc *pads;
39 unsigned int nr_pads;
Paul Mundtd93a8912012-07-11 17:17:10 +090040
41 spinlock_t lock;
Paul Mundtca5481c62012-07-10 12:08:14 +090042};
43
Paul Mundte3f805e2012-07-17 15:48:18 +090044static int sh_pfc_get_groups_count(struct pinctrl_dev *pctldev)
Paul Mundtca5481c62012-07-10 12:08:14 +090045{
Paul Mundte3f805e2012-07-17 15:48:18 +090046 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
47
48 return pmx->nr_pads;
Paul Mundtca5481c62012-07-10 12:08:14 +090049}
50
Paul Mundte3f805e2012-07-17 15:48:18 +090051static const char *sh_pfc_get_group_name(struct pinctrl_dev *pctldev,
Paul Mundtca5481c62012-07-10 12:08:14 +090052 unsigned selector)
53{
Paul Mundte3f805e2012-07-17 15:48:18 +090054 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
55
56 return pmx->pads[selector].name;
Paul Mundtca5481c62012-07-10 12:08:14 +090057}
58
59static int sh_pfc_get_group_pins(struct pinctrl_dev *pctldev, unsigned group,
60 const unsigned **pins, unsigned *num_pins)
61{
Paul Mundte3f805e2012-07-17 15:48:18 +090062 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
63
64 *pins = &pmx->pads[group].number;
65 *num_pins = 1;
66
67 return 0;
Paul Mundtca5481c62012-07-10 12:08:14 +090068}
69
Paul Mundtfdd85ec2012-07-20 16:39:09 +090070static void sh_pfc_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
71 unsigned offset)
72{
73 seq_printf(s, "%s", DRV_NAME);
74}
75
Laurent Pinchartfe330ce2013-02-15 16:04:47 +010076static const struct pinctrl_ops sh_pfc_pinctrl_ops = {
Paul Mundte3f805e2012-07-17 15:48:18 +090077 .get_groups_count = sh_pfc_get_groups_count,
78 .get_group_name = sh_pfc_get_group_name,
Paul Mundtca5481c62012-07-10 12:08:14 +090079 .get_group_pins = sh_pfc_get_group_pins,
Paul Mundtfdd85ec2012-07-20 16:39:09 +090080 .pin_dbg_show = sh_pfc_pin_dbg_show,
Paul Mundtca5481c62012-07-10 12:08:14 +090081};
82
Paul Mundtd93a8912012-07-11 17:17:10 +090083static int sh_pfc_get_functions_count(struct pinctrl_dev *pctldev)
84{
85 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
Paul Mundtca5481c62012-07-10 12:08:14 +090086
Paul Mundtd93a8912012-07-11 17:17:10 +090087 return pmx->nr_functions;
88}
89
90static const char *sh_pfc_get_function_name(struct pinctrl_dev *pctldev,
91 unsigned selector)
92{
93 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
94
95 return pmx->functions[selector]->name;
96}
97
Paul Mundtca5481c62012-07-10 12:08:14 +090098static int sh_pfc_get_function_groups(struct pinctrl_dev *pctldev, unsigned func,
99 const char * const **groups,
100 unsigned * const num_groups)
101{
Paul Mundtd93a8912012-07-11 17:17:10 +0900102 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
103
104 *groups = &pmx->functions[func]->name;
105 *num_groups = 1;
106
Paul Mundtca5481c62012-07-10 12:08:14 +0900107 return 0;
108}
109
110static int sh_pfc_noop_enable(struct pinctrl_dev *pctldev, unsigned func,
111 unsigned group)
112{
113 return 0;
114}
115
116static void sh_pfc_noop_disable(struct pinctrl_dev *pctldev, unsigned func,
117 unsigned group)
118{
119}
120
Laurent Pinchart4a2e0d12012-12-15 23:50:50 +0100121static int sh_pfc_config_function(struct sh_pfc *pfc, unsigned offset)
Paul Mundtd93a8912012-07-11 17:17:10 +0900122{
123 if (sh_pfc_config_gpio(pfc, offset,
124 PINMUX_TYPE_FUNCTION,
125 GPIO_CFG_DRYRUN) != 0)
126 return -EINVAL;
127
128 if (sh_pfc_config_gpio(pfc, offset,
129 PINMUX_TYPE_FUNCTION,
130 GPIO_CFG_REQ) != 0)
131 return -EINVAL;
132
133 return 0;
134}
135
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900136static int sh_pfc_reconfig_pin(struct sh_pfc *pfc, unsigned offset,
137 int new_type)
138{
139 unsigned long flags;
140 int pinmux_type;
141 int ret = -EINVAL;
142
143 spin_lock_irqsave(&pfc->lock, flags);
144
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100145 pinmux_type = pfc->info->gpios[offset].flags & PINMUX_FLAG_TYPE;
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900146
147 /*
148 * See if the present config needs to first be de-configured.
149 */
150 switch (pinmux_type) {
151 case PINMUX_TYPE_GPIO:
152 break;
153 case PINMUX_TYPE_OUTPUT:
154 case PINMUX_TYPE_INPUT:
155 case PINMUX_TYPE_INPUT_PULLUP:
156 case PINMUX_TYPE_INPUT_PULLDOWN:
157 sh_pfc_config_gpio(pfc, offset, pinmux_type, GPIO_CFG_FREE);
158 break;
159 default:
160 goto err;
161 }
162
163 /*
164 * Dry run
165 */
166 if (sh_pfc_config_gpio(pfc, offset, new_type,
167 GPIO_CFG_DRYRUN) != 0)
168 goto err;
169
170 /*
171 * Request
172 */
173 if (sh_pfc_config_gpio(pfc, offset, new_type,
174 GPIO_CFG_REQ) != 0)
175 goto err;
176
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100177 pfc->info->gpios[offset].flags &= ~PINMUX_FLAG_TYPE;
178 pfc->info->gpios[offset].flags |= new_type;
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900179
180 ret = 0;
181
182err:
183 spin_unlock_irqrestore(&pfc->lock, flags);
184
185 return ret;
186}
187
188
Paul Mundtca5481c62012-07-10 12:08:14 +0900189static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
190 struct pinctrl_gpio_range *range,
191 unsigned offset)
192{
193 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
194 struct sh_pfc *pfc = pmx->pfc;
Paul Mundtca5481c62012-07-10 12:08:14 +0900195 unsigned long flags;
Paul Mundtd93a8912012-07-11 17:17:10 +0900196 int ret, pinmux_type;
Paul Mundtca5481c62012-07-10 12:08:14 +0900197
198 spin_lock_irqsave(&pfc->lock, flags);
199
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100200 pinmux_type = pfc->info->gpios[offset].flags & PINMUX_FLAG_TYPE;
Paul Mundtca5481c62012-07-10 12:08:14 +0900201
Paul Mundtd93a8912012-07-11 17:17:10 +0900202 switch (pinmux_type) {
203 case PINMUX_TYPE_FUNCTION:
204 pr_notice_once("Use of GPIO API for function requests is "
205 "deprecated, convert to pinctrl\n");
206 /* handle for now */
207 ret = sh_pfc_config_function(pfc, offset);
208 if (unlikely(ret < 0))
Paul Mundtca5481c62012-07-10 12:08:14 +0900209 goto err;
210
Paul Mundtd93a8912012-07-11 17:17:10 +0900211 break;
212 case PINMUX_TYPE_GPIO:
Paul Mundt16d74eb2012-09-25 11:51:05 +0900213 case PINMUX_TYPE_INPUT:
214 case PINMUX_TYPE_OUTPUT:
Paul Mundtd93a8912012-07-11 17:17:10 +0900215 break;
216 default:
217 pr_err("Unsupported mux type (%d), bailing...\n", pinmux_type);
Laurent Pinchart077664a2012-09-14 20:25:48 +0200218 ret = -ENOTSUPP;
219 goto err;
Paul Mundtd93a8912012-07-11 17:17:10 +0900220 }
Paul Mundtca5481c62012-07-10 12:08:14 +0900221
222 ret = 0;
223
224err:
225 spin_unlock_irqrestore(&pfc->lock, flags);
226
227 return ret;
228}
229
230static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev,
231 struct pinctrl_gpio_range *range,
232 unsigned offset)
233{
234 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
235 struct sh_pfc *pfc = pmx->pfc;
236 unsigned long flags;
237 int pinmux_type;
238
239 spin_lock_irqsave(&pfc->lock, flags);
240
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100241 pinmux_type = pfc->info->gpios[offset].flags & PINMUX_FLAG_TYPE;
Paul Mundtca5481c62012-07-10 12:08:14 +0900242
243 sh_pfc_config_gpio(pfc, offset, pinmux_type, GPIO_CFG_FREE);
244
Paul Mundtca5481c62012-07-10 12:08:14 +0900245 spin_unlock_irqrestore(&pfc->lock, flags);
246}
247
248static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev,
249 struct pinctrl_gpio_range *range,
250 unsigned offset, bool input)
251{
252 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900253 int type = input ? PINMUX_TYPE_INPUT : PINMUX_TYPE_OUTPUT;
Paul Mundtca5481c62012-07-10 12:08:14 +0900254
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900255 return sh_pfc_reconfig_pin(pmx->pfc, offset, type);
Paul Mundtca5481c62012-07-10 12:08:14 +0900256}
257
Laurent Pinchartfe330ce2013-02-15 16:04:47 +0100258static const struct pinmux_ops sh_pfc_pinmux_ops = {
Paul Mundtd93a8912012-07-11 17:17:10 +0900259 .get_functions_count = sh_pfc_get_functions_count,
260 .get_function_name = sh_pfc_get_function_name,
Paul Mundtca5481c62012-07-10 12:08:14 +0900261 .get_function_groups = sh_pfc_get_function_groups,
262 .enable = sh_pfc_noop_enable,
263 .disable = sh_pfc_noop_disable,
264 .gpio_request_enable = sh_pfc_gpio_request_enable,
265 .gpio_disable_free = sh_pfc_gpio_disable_free,
266 .gpio_set_direction = sh_pfc_gpio_set_direction,
267};
268
269static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin,
270 unsigned long *config)
271{
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900272 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
273 struct sh_pfc *pfc = pmx->pfc;
Paul Mundtd93a8912012-07-11 17:17:10 +0900274
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100275 *config = pfc->info->gpios[pin].flags & PINMUX_FLAG_TYPE;
Paul Mundtd93a8912012-07-11 17:17:10 +0900276
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900277 return 0;
Paul Mundtca5481c62012-07-10 12:08:14 +0900278}
279
280static int sh_pfc_pinconf_set(struct pinctrl_dev *pctldev, unsigned pin,
281 unsigned long config)
282{
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900283 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900284
285 /* Validate the new type */
286 if (config >= PINMUX_FLAG_TYPE)
287 return -EINVAL;
288
289 return sh_pfc_reconfig_pin(pmx->pfc, pin, config);
290}
291
292static void sh_pfc_pinconf_dbg_show(struct pinctrl_dev *pctldev,
293 struct seq_file *s, unsigned pin)
294{
295 const char *pinmux_type_str[] = {
296 [PINMUX_TYPE_NONE] = "none",
297 [PINMUX_TYPE_FUNCTION] = "function",
298 [PINMUX_TYPE_GPIO] = "gpio",
299 [PINMUX_TYPE_OUTPUT] = "output",
300 [PINMUX_TYPE_INPUT] = "input",
301 [PINMUX_TYPE_INPUT_PULLUP] = "input bias pull up",
302 [PINMUX_TYPE_INPUT_PULLDOWN] = "input bias pull down",
303 };
304 unsigned long config;
305 int rc;
306
307 rc = sh_pfc_pinconf_get(pctldev, pin, &config);
308 if (unlikely(rc != 0))
309 return;
310
311 seq_printf(s, " %s", pinmux_type_str[config]);
Paul Mundtca5481c62012-07-10 12:08:14 +0900312}
313
Laurent Pinchartfe330ce2013-02-15 16:04:47 +0100314static const struct pinconf_ops sh_pfc_pinconf_ops = {
Paul Mundtca5481c62012-07-10 12:08:14 +0900315 .pin_config_get = sh_pfc_pinconf_get,
316 .pin_config_set = sh_pfc_pinconf_set,
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900317 .pin_config_dbg_show = sh_pfc_pinconf_dbg_show,
Paul Mundtca5481c62012-07-10 12:08:14 +0900318};
319
Laurent Pinchart4a2e0d12012-12-15 23:50:50 +0100320static void sh_pfc_map_one_gpio(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx,
321 struct pinmux_gpio *gpio, unsigned offset)
Paul Mundtd93a8912012-07-11 17:17:10 +0900322{
323 struct pinmux_data_reg *dummy;
324 unsigned long flags;
325 int bit;
326
327 gpio->flags &= ~PINMUX_FLAG_TYPE;
328
329 if (sh_pfc_get_data_reg(pfc, offset, &dummy, &bit) == 0)
330 gpio->flags |= PINMUX_TYPE_GPIO;
331 else {
332 gpio->flags |= PINMUX_TYPE_FUNCTION;
333
334 spin_lock_irqsave(&pmx->lock, flags);
335 pmx->nr_functions++;
336 spin_unlock_irqrestore(&pmx->lock, flags);
337 }
338}
339
Paul Mundtca5481c62012-07-10 12:08:14 +0900340/* pinmux ranges -> pinctrl pin descs */
Greg Kroah-Hartman0fe763c2012-12-21 15:14:44 -0800341static int sh_pfc_map_gpios(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
Paul Mundtca5481c62012-07-10 12:08:14 +0900342{
Paul Mundtd93a8912012-07-11 17:17:10 +0900343 unsigned long flags;
Paul Mundtca5481c62012-07-10 12:08:14 +0900344 int i;
345
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100346 pmx->nr_pads = pfc->info->last_gpio - pfc->info->first_gpio + 1;
Paul Mundtca5481c62012-07-10 12:08:14 +0900347
Laurent Pinchart1724acf2012-12-15 23:50:48 +0100348 pmx->pads = devm_kzalloc(pfc->dev, sizeof(*pmx->pads) * pmx->nr_pads,
349 GFP_KERNEL);
Paul Mundtca5481c62012-07-10 12:08:14 +0900350 if (unlikely(!pmx->pads)) {
351 pmx->nr_pads = 0;
352 return -ENOMEM;
353 }
354
Paul Mundtd93a8912012-07-11 17:17:10 +0900355 spin_lock_irqsave(&pfc->lock, flags);
356
Paul Mundtca5481c62012-07-10 12:08:14 +0900357 /*
358 * We don't necessarily have a 1:1 mapping between pin and linux
359 * GPIO number, as the latter maps to the associated enum_id.
360 * Care needs to be taken to translate back to pin space when
361 * dealing with any pin configurations.
362 */
363 for (i = 0; i < pmx->nr_pads; i++) {
364 struct pinctrl_pin_desc *pin = pmx->pads + i;
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100365 struct pinmux_gpio *gpio = pfc->info->gpios + i;
Paul Mundtca5481c62012-07-10 12:08:14 +0900366
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100367 pin->number = pfc->info->first_gpio + i;
Paul Mundtca5481c62012-07-10 12:08:14 +0900368 pin->name = gpio->name;
Paul Mundtd93a8912012-07-11 17:17:10 +0900369
Paul Mundte3e79452012-07-17 15:23:11 +0900370 /* XXX */
371 if (unlikely(!gpio->enum_id))
372 continue;
373
Paul Mundtd93a8912012-07-11 17:17:10 +0900374 sh_pfc_map_one_gpio(pfc, pmx, gpio, i);
Paul Mundtca5481c62012-07-10 12:08:14 +0900375 }
376
Paul Mundtd93a8912012-07-11 17:17:10 +0900377 spin_unlock_irqrestore(&pfc->lock, flags);
378
Paul Mundtca5481c62012-07-10 12:08:14 +0900379 return 0;
380}
381
Greg Kroah-Hartman0fe763c2012-12-21 15:14:44 -0800382static int sh_pfc_map_functions(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
Paul Mundtd93a8912012-07-11 17:17:10 +0900383{
384 unsigned long flags;
385 int i, fn;
386
Laurent Pinchart1724acf2012-12-15 23:50:48 +0100387 pmx->functions = devm_kzalloc(pfc->dev, pmx->nr_functions *
388 sizeof(*pmx->functions), GFP_KERNEL);
Paul Mundtd93a8912012-07-11 17:17:10 +0900389 if (unlikely(!pmx->functions))
390 return -ENOMEM;
391
392 spin_lock_irqsave(&pmx->lock, flags);
393
394 for (i = fn = 0; i < pmx->nr_pads; i++) {
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100395 struct pinmux_gpio *gpio = pfc->info->gpios + i;
Paul Mundtd93a8912012-07-11 17:17:10 +0900396
397 if ((gpio->flags & PINMUX_FLAG_TYPE) == PINMUX_TYPE_FUNCTION)
398 pmx->functions[fn++] = gpio;
399 }
400
401 spin_unlock_irqrestore(&pmx->lock, flags);
402
403 return 0;
404}
405
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100406int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
Paul Mundtca5481c62012-07-10 12:08:14 +0900407{
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100408 struct sh_pfc_pinctrl *pmx;
Paul Mundtca5481c62012-07-10 12:08:14 +0900409 int ret;
410
Laurent Pinchart1724acf2012-12-15 23:50:48 +0100411 pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL);
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100412 if (unlikely(!pmx))
413 return -ENOMEM;
Paul Mundtca5481c62012-07-10 12:08:14 +0900414
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100415 spin_lock_init(&pmx->lock);
Paul Mundtca5481c62012-07-10 12:08:14 +0900416
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100417 pmx->pfc = pfc;
418 pfc->pinctrl = pmx;
419
420 ret = sh_pfc_map_gpios(pfc, pmx);
Paul Mundtca5481c62012-07-10 12:08:14 +0900421 if (unlikely(ret != 0))
422 return ret;
423
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100424 ret = sh_pfc_map_functions(pfc, pmx);
Paul Mundtd93a8912012-07-11 17:17:10 +0900425 if (unlikely(ret != 0))
Laurent Pinchart1724acf2012-12-15 23:50:48 +0100426 return ret;
Paul Mundtd93a8912012-07-11 17:17:10 +0900427
Laurent Pinchartdcc427e2013-02-16 16:38:30 +0100428 pmx->pctl_desc.name = DRV_NAME;
429 pmx->pctl_desc.owner = THIS_MODULE;
430 pmx->pctl_desc.pctlops = &sh_pfc_pinctrl_ops;
431 pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops;
432 pmx->pctl_desc.confops = &sh_pfc_pinconf_ops;
433 pmx->pctl_desc.pins = pmx->pads;
434 pmx->pctl_desc.npins = pmx->nr_pads;
435
436 pmx->pctl = pinctrl_register(&pmx->pctl_desc, pfc->dev, pmx);
Laurent Pinchart1724acf2012-12-15 23:50:48 +0100437 if (IS_ERR(pmx->pctl))
438 return PTR_ERR(pmx->pctl);
Paul Mundtca5481c62012-07-10 12:08:14 +0900439
Laurent Pinchartdcc427e2013-02-16 16:38:30 +0100440 pmx->range.name = DRV_NAME,
441 pmx->range.id = 0;
442 pmx->range.npins = pfc->info->last_gpio - pfc->info->first_gpio + 1;
443 pmx->range.base = pfc->info->first_gpio;
444 pmx->range.pin_base = pfc->info->first_gpio;
Paul Mundtca5481c62012-07-10 12:08:14 +0900445
Laurent Pinchartdcc427e2013-02-16 16:38:30 +0100446 pinctrl_add_gpio_range(pmx->pctl, &pmx->range);
Paul Mundtca5481c62012-07-10 12:08:14 +0900447
448 return 0;
Paul Mundtca5481c62012-07-10 12:08:14 +0900449}
450
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100451int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc)
Paul Mundtca5481c62012-07-10 12:08:14 +0900452{
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100453 struct sh_pfc_pinctrl *pmx = pfc->pinctrl;
Paul Mundtca5481c62012-07-10 12:08:14 +0900454
Paul Mundtca5481c62012-07-10 12:08:14 +0900455 pinctrl_unregister(pmx->pctl);
456
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100457 pfc->pinctrl = NULL;
Paul Mundtca5481c62012-07-10 12:08:14 +0900458 return 0;
459}