blob: 2fc873137ce82328a44840c2c8e371f3a80bcbe5 [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
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/sh_pfc.h>
17#include <linux/err.h>
18#include <linux/slab.h>
Paul Mundtd93a8912012-07-11 17:17:10 +090019#include <linux/spinlock.h>
Paul Mundtca5481c62012-07-10 12:08:14 +090020#include <linux/pinctrl/consumer.h>
21#include <linux/pinctrl/pinctrl.h>
22#include <linux/pinctrl/pinconf.h>
23#include <linux/pinctrl/pinmux.h>
24#include <linux/pinctrl/pinconf-generic.h>
25
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;
30 struct sh_pfc *pfc;
31
Paul Mundtd93a8912012-07-11 17:17:10 +090032 struct pinmux_gpio **functions;
33 unsigned int nr_functions;
34
Paul Mundtca5481c62012-07-10 12:08:14 +090035 struct pinctrl_pin_desc *pads;
36 unsigned int nr_pads;
Paul Mundtd93a8912012-07-11 17:17:10 +090037
38 spinlock_t lock;
Paul Mundtca5481c62012-07-10 12:08:14 +090039};
40
Paul Mundte3f805e2012-07-17 15:48:18 +090041static int sh_pfc_get_groups_count(struct pinctrl_dev *pctldev)
Paul Mundtca5481c62012-07-10 12:08:14 +090042{
Paul Mundte3f805e2012-07-17 15:48:18 +090043 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
44
45 return pmx->nr_pads;
Paul Mundtca5481c62012-07-10 12:08:14 +090046}
47
Paul Mundte3f805e2012-07-17 15:48:18 +090048static const char *sh_pfc_get_group_name(struct pinctrl_dev *pctldev,
Paul Mundtca5481c62012-07-10 12:08:14 +090049 unsigned selector)
50{
Paul Mundte3f805e2012-07-17 15:48:18 +090051 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
52
53 return pmx->pads[selector].name;
Paul Mundtca5481c62012-07-10 12:08:14 +090054}
55
56static int sh_pfc_get_group_pins(struct pinctrl_dev *pctldev, unsigned group,
57 const unsigned **pins, unsigned *num_pins)
58{
Paul Mundte3f805e2012-07-17 15:48:18 +090059 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
60
61 *pins = &pmx->pads[group].number;
62 *num_pins = 1;
63
64 return 0;
Paul Mundtca5481c62012-07-10 12:08:14 +090065}
66
Paul Mundtfdd85ec2012-07-20 16:39:09 +090067static void sh_pfc_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
68 unsigned offset)
69{
70 seq_printf(s, "%s", DRV_NAME);
71}
72
Paul Mundtca5481c62012-07-10 12:08:14 +090073static struct pinctrl_ops sh_pfc_pinctrl_ops = {
Paul Mundte3f805e2012-07-17 15:48:18 +090074 .get_groups_count = sh_pfc_get_groups_count,
75 .get_group_name = sh_pfc_get_group_name,
Paul Mundtca5481c62012-07-10 12:08:14 +090076 .get_group_pins = sh_pfc_get_group_pins,
Paul Mundtfdd85ec2012-07-20 16:39:09 +090077 .pin_dbg_show = sh_pfc_pin_dbg_show,
Paul Mundtca5481c62012-07-10 12:08:14 +090078};
79
Paul Mundtd93a8912012-07-11 17:17:10 +090080static int sh_pfc_get_functions_count(struct pinctrl_dev *pctldev)
81{
82 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
Paul Mundtca5481c62012-07-10 12:08:14 +090083
Paul Mundtd93a8912012-07-11 17:17:10 +090084 return pmx->nr_functions;
85}
86
87static const char *sh_pfc_get_function_name(struct pinctrl_dev *pctldev,
88 unsigned selector)
89{
90 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
91
92 return pmx->functions[selector]->name;
93}
94
Paul Mundtca5481c62012-07-10 12:08:14 +090095static int sh_pfc_get_function_groups(struct pinctrl_dev *pctldev, unsigned func,
96 const char * const **groups,
97 unsigned * const num_groups)
98{
Paul Mundtd93a8912012-07-11 17:17:10 +090099 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
100
101 *groups = &pmx->functions[func]->name;
102 *num_groups = 1;
103
Paul Mundtca5481c62012-07-10 12:08:14 +0900104 return 0;
105}
106
107static int sh_pfc_noop_enable(struct pinctrl_dev *pctldev, unsigned func,
108 unsigned group)
109{
110 return 0;
111}
112
113static void sh_pfc_noop_disable(struct pinctrl_dev *pctldev, unsigned func,
114 unsigned group)
115{
116}
117
Paul Mundtd93a8912012-07-11 17:17:10 +0900118static inline int sh_pfc_config_function(struct sh_pfc *pfc, unsigned offset)
119{
120 if (sh_pfc_config_gpio(pfc, offset,
121 PINMUX_TYPE_FUNCTION,
122 GPIO_CFG_DRYRUN) != 0)
123 return -EINVAL;
124
125 if (sh_pfc_config_gpio(pfc, offset,
126 PINMUX_TYPE_FUNCTION,
127 GPIO_CFG_REQ) != 0)
128 return -EINVAL;
129
130 return 0;
131}
132
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900133static int sh_pfc_reconfig_pin(struct sh_pfc *pfc, unsigned offset,
134 int new_type)
135{
136 unsigned long flags;
137 int pinmux_type;
138 int ret = -EINVAL;
139
140 spin_lock_irqsave(&pfc->lock, flags);
141
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100142 pinmux_type = pfc->pdata->gpios[offset].flags & PINMUX_FLAG_TYPE;
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900143
144 /*
145 * See if the present config needs to first be de-configured.
146 */
147 switch (pinmux_type) {
148 case PINMUX_TYPE_GPIO:
149 break;
150 case PINMUX_TYPE_OUTPUT:
151 case PINMUX_TYPE_INPUT:
152 case PINMUX_TYPE_INPUT_PULLUP:
153 case PINMUX_TYPE_INPUT_PULLDOWN:
154 sh_pfc_config_gpio(pfc, offset, pinmux_type, GPIO_CFG_FREE);
155 break;
156 default:
157 goto err;
158 }
159
160 /*
161 * Dry run
162 */
163 if (sh_pfc_config_gpio(pfc, offset, new_type,
164 GPIO_CFG_DRYRUN) != 0)
165 goto err;
166
167 /*
168 * Request
169 */
170 if (sh_pfc_config_gpio(pfc, offset, new_type,
171 GPIO_CFG_REQ) != 0)
172 goto err;
173
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100174 pfc->pdata->gpios[offset].flags &= ~PINMUX_FLAG_TYPE;
175 pfc->pdata->gpios[offset].flags |= new_type;
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900176
177 ret = 0;
178
179err:
180 spin_unlock_irqrestore(&pfc->lock, flags);
181
182 return ret;
183}
184
185
Paul Mundtca5481c62012-07-10 12:08:14 +0900186static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
187 struct pinctrl_gpio_range *range,
188 unsigned offset)
189{
190 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
191 struct sh_pfc *pfc = pmx->pfc;
Paul Mundtca5481c62012-07-10 12:08:14 +0900192 unsigned long flags;
Paul Mundtd93a8912012-07-11 17:17:10 +0900193 int ret, pinmux_type;
Paul Mundtca5481c62012-07-10 12:08:14 +0900194
195 spin_lock_irqsave(&pfc->lock, flags);
196
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100197 pinmux_type = pfc->pdata->gpios[offset].flags & PINMUX_FLAG_TYPE;
Paul Mundtca5481c62012-07-10 12:08:14 +0900198
Paul Mundtd93a8912012-07-11 17:17:10 +0900199 switch (pinmux_type) {
200 case PINMUX_TYPE_FUNCTION:
201 pr_notice_once("Use of GPIO API for function requests is "
202 "deprecated, convert to pinctrl\n");
203 /* handle for now */
204 ret = sh_pfc_config_function(pfc, offset);
205 if (unlikely(ret < 0))
Paul Mundtca5481c62012-07-10 12:08:14 +0900206 goto err;
207
Paul Mundtd93a8912012-07-11 17:17:10 +0900208 break;
209 case PINMUX_TYPE_GPIO:
Paul Mundt16d74eb2012-09-25 11:51:05 +0900210 case PINMUX_TYPE_INPUT:
211 case PINMUX_TYPE_OUTPUT:
Paul Mundtd93a8912012-07-11 17:17:10 +0900212 break;
213 default:
214 pr_err("Unsupported mux type (%d), bailing...\n", pinmux_type);
Laurent Pinchart077664a2012-09-14 20:25:48 +0200215 ret = -ENOTSUPP;
216 goto err;
Paul Mundtd93a8912012-07-11 17:17:10 +0900217 }
Paul Mundtca5481c62012-07-10 12:08:14 +0900218
219 ret = 0;
220
221err:
222 spin_unlock_irqrestore(&pfc->lock, flags);
223
224 return ret;
225}
226
227static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev,
228 struct pinctrl_gpio_range *range,
229 unsigned offset)
230{
231 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
232 struct sh_pfc *pfc = pmx->pfc;
233 unsigned long flags;
234 int pinmux_type;
235
236 spin_lock_irqsave(&pfc->lock, flags);
237
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100238 pinmux_type = pfc->pdata->gpios[offset].flags & PINMUX_FLAG_TYPE;
Paul Mundtca5481c62012-07-10 12:08:14 +0900239
240 sh_pfc_config_gpio(pfc, offset, pinmux_type, GPIO_CFG_FREE);
241
Paul Mundtca5481c62012-07-10 12:08:14 +0900242 spin_unlock_irqrestore(&pfc->lock, flags);
243}
244
245static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev,
246 struct pinctrl_gpio_range *range,
247 unsigned offset, bool input)
248{
249 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900250 int type = input ? PINMUX_TYPE_INPUT : PINMUX_TYPE_OUTPUT;
Paul Mundtca5481c62012-07-10 12:08:14 +0900251
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900252 return sh_pfc_reconfig_pin(pmx->pfc, offset, type);
Paul Mundtca5481c62012-07-10 12:08:14 +0900253}
254
255static struct pinmux_ops sh_pfc_pinmux_ops = {
Paul Mundtd93a8912012-07-11 17:17:10 +0900256 .get_functions_count = sh_pfc_get_functions_count,
257 .get_function_name = sh_pfc_get_function_name,
Paul Mundtca5481c62012-07-10 12:08:14 +0900258 .get_function_groups = sh_pfc_get_function_groups,
259 .enable = sh_pfc_noop_enable,
260 .disable = sh_pfc_noop_disable,
261 .gpio_request_enable = sh_pfc_gpio_request_enable,
262 .gpio_disable_free = sh_pfc_gpio_disable_free,
263 .gpio_set_direction = sh_pfc_gpio_set_direction,
264};
265
266static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin,
267 unsigned long *config)
268{
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900269 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
270 struct sh_pfc *pfc = pmx->pfc;
Paul Mundtd93a8912012-07-11 17:17:10 +0900271
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100272 *config = pfc->pdata->gpios[pin].flags & PINMUX_FLAG_TYPE;
Paul Mundtd93a8912012-07-11 17:17:10 +0900273
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900274 return 0;
Paul Mundtca5481c62012-07-10 12:08:14 +0900275}
276
277static int sh_pfc_pinconf_set(struct pinctrl_dev *pctldev, unsigned pin,
278 unsigned long config)
279{
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900280 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900281
282 /* Validate the new type */
283 if (config >= PINMUX_FLAG_TYPE)
284 return -EINVAL;
285
286 return sh_pfc_reconfig_pin(pmx->pfc, pin, config);
287}
288
289static void sh_pfc_pinconf_dbg_show(struct pinctrl_dev *pctldev,
290 struct seq_file *s, unsigned pin)
291{
292 const char *pinmux_type_str[] = {
293 [PINMUX_TYPE_NONE] = "none",
294 [PINMUX_TYPE_FUNCTION] = "function",
295 [PINMUX_TYPE_GPIO] = "gpio",
296 [PINMUX_TYPE_OUTPUT] = "output",
297 [PINMUX_TYPE_INPUT] = "input",
298 [PINMUX_TYPE_INPUT_PULLUP] = "input bias pull up",
299 [PINMUX_TYPE_INPUT_PULLDOWN] = "input bias pull down",
300 };
301 unsigned long config;
302 int rc;
303
304 rc = sh_pfc_pinconf_get(pctldev, pin, &config);
305 if (unlikely(rc != 0))
306 return;
307
308 seq_printf(s, " %s", pinmux_type_str[config]);
Paul Mundtca5481c62012-07-10 12:08:14 +0900309}
310
311static struct pinconf_ops sh_pfc_pinconf_ops = {
Paul Mundtca5481c62012-07-10 12:08:14 +0900312 .pin_config_get = sh_pfc_pinconf_get,
313 .pin_config_set = sh_pfc_pinconf_set,
Paul Mundtfdd85ec2012-07-20 16:39:09 +0900314 .pin_config_dbg_show = sh_pfc_pinconf_dbg_show,
Paul Mundtca5481c62012-07-10 12:08:14 +0900315};
316
317static struct pinctrl_gpio_range sh_pfc_gpio_range = {
Paul Mundt54407112012-07-20 16:18:21 +0900318 .name = DRV_NAME,
Paul Mundtca5481c62012-07-10 12:08:14 +0900319 .id = 0,
320};
321
322static struct pinctrl_desc sh_pfc_pinctrl_desc = {
Paul Mundt54407112012-07-20 16:18:21 +0900323 .name = DRV_NAME,
Paul Mundtca5481c62012-07-10 12:08:14 +0900324 .owner = THIS_MODULE,
325 .pctlops = &sh_pfc_pinctrl_ops,
326 .pmxops = &sh_pfc_pinmux_ops,
327 .confops = &sh_pfc_pinconf_ops,
328};
329
Greg Kroah-Hartman0fe763c2012-12-21 15:14:44 -0800330static inline void sh_pfc_map_one_gpio(struct sh_pfc *pfc,
331 struct sh_pfc_pinctrl *pmx,
332 struct pinmux_gpio *gpio,
333 unsigned offset)
Paul Mundtd93a8912012-07-11 17:17:10 +0900334{
335 struct pinmux_data_reg *dummy;
336 unsigned long flags;
337 int bit;
338
339 gpio->flags &= ~PINMUX_FLAG_TYPE;
340
341 if (sh_pfc_get_data_reg(pfc, offset, &dummy, &bit) == 0)
342 gpio->flags |= PINMUX_TYPE_GPIO;
343 else {
344 gpio->flags |= PINMUX_TYPE_FUNCTION;
345
346 spin_lock_irqsave(&pmx->lock, flags);
347 pmx->nr_functions++;
348 spin_unlock_irqrestore(&pmx->lock, flags);
349 }
350}
351
Paul Mundtca5481c62012-07-10 12:08:14 +0900352/* pinmux ranges -> pinctrl pin descs */
Greg Kroah-Hartman0fe763c2012-12-21 15:14:44 -0800353static int sh_pfc_map_gpios(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
Paul Mundtca5481c62012-07-10 12:08:14 +0900354{
Paul Mundtd93a8912012-07-11 17:17:10 +0900355 unsigned long flags;
Paul Mundtca5481c62012-07-10 12:08:14 +0900356 int i;
357
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100358 pmx->nr_pads = pfc->pdata->last_gpio - pfc->pdata->first_gpio + 1;
Paul Mundtca5481c62012-07-10 12:08:14 +0900359
360 pmx->pads = kmalloc(sizeof(struct pinctrl_pin_desc) * pmx->nr_pads,
361 GFP_KERNEL);
362 if (unlikely(!pmx->pads)) {
363 pmx->nr_pads = 0;
364 return -ENOMEM;
365 }
366
Paul Mundtd93a8912012-07-11 17:17:10 +0900367 spin_lock_irqsave(&pfc->lock, flags);
368
Paul Mundtca5481c62012-07-10 12:08:14 +0900369 /*
370 * We don't necessarily have a 1:1 mapping between pin and linux
371 * GPIO number, as the latter maps to the associated enum_id.
372 * Care needs to be taken to translate back to pin space when
373 * dealing with any pin configurations.
374 */
375 for (i = 0; i < pmx->nr_pads; i++) {
376 struct pinctrl_pin_desc *pin = pmx->pads + i;
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100377 struct pinmux_gpio *gpio = pfc->pdata->gpios + i;
Paul Mundtca5481c62012-07-10 12:08:14 +0900378
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100379 pin->number = pfc->pdata->first_gpio + i;
Paul Mundtca5481c62012-07-10 12:08:14 +0900380 pin->name = gpio->name;
Paul Mundtd93a8912012-07-11 17:17:10 +0900381
Paul Mundte3e79452012-07-17 15:23:11 +0900382 /* XXX */
383 if (unlikely(!gpio->enum_id))
384 continue;
385
Paul Mundtd93a8912012-07-11 17:17:10 +0900386 sh_pfc_map_one_gpio(pfc, pmx, gpio, i);
Paul Mundtca5481c62012-07-10 12:08:14 +0900387 }
388
Paul Mundtd93a8912012-07-11 17:17:10 +0900389 spin_unlock_irqrestore(&pfc->lock, flags);
390
Paul Mundtca5481c62012-07-10 12:08:14 +0900391 sh_pfc_pinctrl_desc.pins = pmx->pads;
392 sh_pfc_pinctrl_desc.npins = pmx->nr_pads;
393
394 return 0;
395}
396
Greg Kroah-Hartman0fe763c2012-12-21 15:14:44 -0800397static int sh_pfc_map_functions(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
Paul Mundtd93a8912012-07-11 17:17:10 +0900398{
399 unsigned long flags;
400 int i, fn;
401
402 pmx->functions = kzalloc(pmx->nr_functions * sizeof(void *),
403 GFP_KERNEL);
404 if (unlikely(!pmx->functions))
405 return -ENOMEM;
406
407 spin_lock_irqsave(&pmx->lock, flags);
408
409 for (i = fn = 0; i < pmx->nr_pads; i++) {
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100410 struct pinmux_gpio *gpio = pfc->pdata->gpios + i;
Paul Mundtd93a8912012-07-11 17:17:10 +0900411
412 if ((gpio->flags & PINMUX_FLAG_TYPE) == PINMUX_TYPE_FUNCTION)
413 pmx->functions[fn++] = gpio;
414 }
415
416 spin_unlock_irqrestore(&pmx->lock, flags);
417
418 return 0;
419}
420
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100421int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
Paul Mundtca5481c62012-07-10 12:08:14 +0900422{
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100423 struct sh_pfc_pinctrl *pmx;
Paul Mundtca5481c62012-07-10 12:08:14 +0900424 int ret;
425
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100426 pmx = kzalloc(sizeof(struct sh_pfc_pinctrl), GFP_KERNEL);
427 if (unlikely(!pmx))
428 return -ENOMEM;
Paul Mundtca5481c62012-07-10 12:08:14 +0900429
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100430 spin_lock_init(&pmx->lock);
Paul Mundtca5481c62012-07-10 12:08:14 +0900431
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100432 pmx->pfc = pfc;
433 pfc->pinctrl = pmx;
434
435 ret = sh_pfc_map_gpios(pfc, pmx);
Paul Mundtca5481c62012-07-10 12:08:14 +0900436 if (unlikely(ret != 0))
437 return ret;
438
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100439 ret = sh_pfc_map_functions(pfc, pmx);
Paul Mundtd93a8912012-07-11 17:17:10 +0900440 if (unlikely(ret != 0))
441 goto free_pads;
442
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100443 pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, pfc->dev, pmx);
444 if (IS_ERR(pmx->pctl)) {
445 ret = PTR_ERR(pmx->pctl);
Paul Mundtd93a8912012-07-11 17:17:10 +0900446 goto free_functions;
Paul Mundtca5481c62012-07-10 12:08:14 +0900447 }
448
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100449 sh_pfc_gpio_range.npins = pfc->pdata->last_gpio
450 - pfc->pdata->first_gpio + 1;
451 sh_pfc_gpio_range.base = pfc->pdata->first_gpio;
452 sh_pfc_gpio_range.pin_base = pfc->pdata->first_gpio;
Paul Mundtca5481c62012-07-10 12:08:14 +0900453
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100454 pinctrl_add_gpio_range(pmx->pctl, &sh_pfc_gpio_range);
Paul Mundtca5481c62012-07-10 12:08:14 +0900455
456 return 0;
457
Paul Mundtd93a8912012-07-11 17:17:10 +0900458free_functions:
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100459 kfree(pmx->functions);
Paul Mundtd93a8912012-07-11 17:17:10 +0900460free_pads:
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100461 kfree(pmx->pads);
462 kfree(pmx);
Paul Mundtd93a8912012-07-11 17:17:10 +0900463
Paul Mundtca5481c62012-07-10 12:08:14 +0900464 return ret;
465}
466
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100467int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc)
Paul Mundtca5481c62012-07-10 12:08:14 +0900468{
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100469 struct sh_pfc_pinctrl *pmx = pfc->pinctrl;
Paul Mundtca5481c62012-07-10 12:08:14 +0900470
Paul Mundtca5481c62012-07-10 12:08:14 +0900471 pinctrl_unregister(pmx->pctl);
472
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100473 kfree(pmx->functions);
474 kfree(pmx->pads);
475 kfree(pmx);
Paul Mundtca5481c62012-07-10 12:08:14 +0900476
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100477 pfc->pinctrl = NULL;
Paul Mundtca5481c62012-07-10 12:08:14 +0900478 return 0;
479}