1 /*
2  * pin-controller/pin-mux/pin-config/gpio-driver for Samsung's SoC's.
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5  *		http://www.samsung.com
6  * Copyright (c) 2012 Linaro Ltd
7  *		http://www.linaro.org
8  *
9  * Author: Thomas Abraham <thomas.ab@samsung.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This driver implements the Samsung pinctrl driver. It supports setting up of
17  * pinmux and pinconf configurations. The gpiolib interface is also included.
18  * External interrupt (gpio and wakeup) support are not included in this driver
19  * but provides extensions to which platform specific implementation of the gpio
20  * and wakeup interrupts can be hooked to.
21  */
22 
23 #include <linux/module.h>
24 #include <linux/platform_device.h>
25 #include <linux/io.h>
26 #include <linux/slab.h>
27 #include <linux/err.h>
28 #include <linux/gpio.h>
29 #include <linux/irqdomain.h>
30 #include <linux/spinlock.h>
31 #include <linux/syscore_ops.h>
32 
33 #include "../core.h"
34 #include "pinctrl-samsung.h"
35 
36 /* list of all possible config options supported */
37 static struct pin_config {
38 	const char *property;
39 	enum pincfg_type param;
40 } cfg_params[] = {
41 	{ "samsung,pin-pud", PINCFG_TYPE_PUD },
42 	{ "samsung,pin-drv", PINCFG_TYPE_DRV },
43 	{ "samsung,pin-con-pdn", PINCFG_TYPE_CON_PDN },
44 	{ "samsung,pin-pud-pdn", PINCFG_TYPE_PUD_PDN },
45 	{ "samsung,pin-val", PINCFG_TYPE_DAT },
46 };
47 
48 /* Global list of devices (struct samsung_pinctrl_drv_data) */
49 static LIST_HEAD(drvdata_list);
50 
51 static unsigned int pin_base;
52 
53 static int samsung_get_group_count(struct pinctrl_dev *pctldev)
54 {
55 	struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev);
56 
57 	return pmx->nr_groups;
58 }
59 
60 static const char *samsung_get_group_name(struct pinctrl_dev *pctldev,
61 						unsigned group)
62 {
63 	struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev);
64 
65 	return pmx->pin_groups[group].name;
66 }
67 
68 static int samsung_get_group_pins(struct pinctrl_dev *pctldev,
69 					unsigned group,
70 					const unsigned **pins,
71 					unsigned *num_pins)
72 {
73 	struct samsung_pinctrl_drv_data *pmx = pinctrl_dev_get_drvdata(pctldev);
74 
75 	*pins = pmx->pin_groups[group].pins;
76 	*num_pins = pmx->pin_groups[group].num_pins;
77 
78 	return 0;
79 }
80 
81 static int reserve_map(struct device *dev, struct pinctrl_map **map,
82 		       unsigned *reserved_maps, unsigned *num_maps,
83 		       unsigned reserve)
84 {
85 	unsigned old_num = *reserved_maps;
86 	unsigned new_num = *num_maps + reserve;
87 	struct pinctrl_map *new_map;
88 
89 	if (old_num >= new_num)
90 		return 0;
91 
92 	new_map = krealloc(*map, sizeof(*new_map) * new_num, GFP_KERNEL);
93 	if (!new_map) {
94 		dev_err(dev, "krealloc(map) failed\n");
95 		return -ENOMEM;
96 	}
97 
98 	memset(new_map + old_num, 0, (new_num - old_num) * sizeof(*new_map));
99 
100 	*map = new_map;
101 	*reserved_maps = new_num;
102 
103 	return 0;
104 }
105 
106 static int add_map_mux(struct pinctrl_map **map, unsigned *reserved_maps,
107 		       unsigned *num_maps, const char *group,
108 		       const char *function)
109 {
110 	if (WARN_ON(*num_maps == *reserved_maps))
111 		return -ENOSPC;
112 
113 	(*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP;
114 	(*map)[*num_maps].data.mux.group = group;
115 	(*map)[*num_maps].data.mux.function = function;
116 	(*num_maps)++;
117 
118 	return 0;
119 }
120 
121 static int add_map_configs(struct device *dev, struct pinctrl_map **map,
122 			   unsigned *reserved_maps, unsigned *num_maps,
123 			   const char *group, unsigned long *configs,
124 			   unsigned num_configs)
125 {
126 	unsigned long *dup_configs;
127 
128 	if (WARN_ON(*num_maps == *reserved_maps))
129 		return -ENOSPC;
130 
131 	dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
132 			      GFP_KERNEL);
133 	if (!dup_configs) {
134 		dev_err(dev, "kmemdup(configs) failed\n");
135 		return -ENOMEM;
136 	}
137 
138 	(*map)[*num_maps].type = PIN_MAP_TYPE_CONFIGS_GROUP;
139 	(*map)[*num_maps].data.configs.group_or_pin = group;
140 	(*map)[*num_maps].data.configs.configs = dup_configs;
141 	(*map)[*num_maps].data.configs.num_configs = num_configs;
142 	(*num_maps)++;
143 
144 	return 0;
145 }
146 
147 static int add_config(struct device *dev, unsigned long **configs,
148 		      unsigned *num_configs, unsigned long config)
149 {
150 	unsigned old_num = *num_configs;
151 	unsigned new_num = old_num + 1;
152 	unsigned long *new_configs;
153 
154 	new_configs = krealloc(*configs, sizeof(*new_configs) * new_num,
155 			       GFP_KERNEL);
156 	if (!new_configs) {
157 		dev_err(dev, "krealloc(configs) failed\n");
158 		return -ENOMEM;
159 	}
160 
161 	new_configs[old_num] = config;
162 
163 	*configs = new_configs;
164 	*num_configs = new_num;
165 
166 	return 0;
167 }
168 
169 static void samsung_dt_free_map(struct pinctrl_dev *pctldev,
170 				      struct pinctrl_map *map,
171 				      unsigned num_maps)
172 {
173 	int i;
174 
175 	for (i = 0; i < num_maps; i++)
176 		if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP)
177 			kfree(map[i].data.configs.configs);
178 
179 	kfree(map);
180 }
181 
182 static int samsung_dt_subnode_to_map(struct samsung_pinctrl_drv_data *drvdata,
183 				     struct device *dev,
184 				     struct device_node *np,
185 				     struct pinctrl_map **map,
186 				     unsigned *reserved_maps,
187 				     unsigned *num_maps)
188 {
189 	int ret, i;
190 	u32 val;
191 	unsigned long config;
192 	unsigned long *configs = NULL;
193 	unsigned num_configs = 0;
194 	unsigned reserve;
195 	struct property *prop;
196 	const char *group;
197 	bool has_func = false;
198 
199 	ret = of_property_read_u32(np, "samsung,pin-function", &val);
200 	if (!ret)
201 		has_func = true;
202 
203 	for (i = 0; i < ARRAY_SIZE(cfg_params); i++) {
204 		ret = of_property_read_u32(np, cfg_params[i].property, &val);
205 		if (!ret) {
206 			config = PINCFG_PACK(cfg_params[i].param, val);
207 			ret = add_config(dev, &configs, &num_configs, config);
208 			if (ret < 0)
209 				goto exit;
210 		/* EINVAL=missing, which is fine since it's optional */
211 		} else if (ret != -EINVAL) {
212 			dev_err(dev, "could not parse property %s\n",
213 				cfg_params[i].property);
214 		}
215 	}
216 
217 	reserve = 0;
218 	if (has_func)
219 		reserve++;
220 	if (num_configs)
221 		reserve++;
222 	ret = of_property_count_strings(np, "samsung,pins");
223 	if (ret < 0) {
224 		dev_err(dev, "could not parse property samsung,pins\n");
225 		goto exit;
226 	}
227 	reserve *= ret;
228 
229 	ret = reserve_map(dev, map, reserved_maps, num_maps, reserve);
230 	if (ret < 0)
231 		goto exit;
232 
233 	of_property_for_each_string(np, "samsung,pins", prop, group) {
234 		if (has_func) {
235 			ret = add_map_mux(map, reserved_maps,
236 						num_maps, group, np->full_name);
237 			if (ret < 0)
238 				goto exit;
239 		}
240 
241 		if (num_configs) {
242 			ret = add_map_configs(dev, map, reserved_maps,
243 					      num_maps, group, configs,
244 					      num_configs);
245 			if (ret < 0)
246 				goto exit;
247 		}
248 	}
249 
250 	ret = 0;
251 
252 exit:
253 	kfree(configs);
254 	return ret;
255 }
256 
257 static int samsung_dt_node_to_map(struct pinctrl_dev *pctldev,
258 					struct device_node *np_config,
259 					struct pinctrl_map **map,
260 					unsigned *num_maps)
261 {
262 	struct samsung_pinctrl_drv_data *drvdata;
263 	unsigned reserved_maps;
264 	struct device_node *np;
265 	int ret;
266 
267 	drvdata = pinctrl_dev_get_drvdata(pctldev);
268 
269 	reserved_maps = 0;
270 	*map = NULL;
271 	*num_maps = 0;
272 
273 	if (!of_get_child_count(np_config))
274 		return samsung_dt_subnode_to_map(drvdata, pctldev->dev,
275 							np_config, map,
276 							&reserved_maps,
277 							num_maps);
278 
279 	for_each_child_of_node(np_config, np) {
280 		ret = samsung_dt_subnode_to_map(drvdata, pctldev->dev, np, map,
281 						&reserved_maps, num_maps);
282 		if (ret < 0) {
283 			samsung_dt_free_map(pctldev, *map, *num_maps);
284 			return ret;
285 		}
286 	}
287 
288 	return 0;
289 }
290 
291 /* list of pinctrl callbacks for the pinctrl core */
292 static const struct pinctrl_ops samsung_pctrl_ops = {
293 	.get_groups_count	= samsung_get_group_count,
294 	.get_group_name		= samsung_get_group_name,
295 	.get_group_pins		= samsung_get_group_pins,
296 	.dt_node_to_map		= samsung_dt_node_to_map,
297 	.dt_free_map		= samsung_dt_free_map,
298 };
299 
300 /* check if the selector is a valid pin function selector */
301 static int samsung_get_functions_count(struct pinctrl_dev *pctldev)
302 {
303 	struct samsung_pinctrl_drv_data *drvdata;
304 
305 	drvdata = pinctrl_dev_get_drvdata(pctldev);
306 	return drvdata->nr_functions;
307 }
308 
309 /* return the name of the pin function specified */
310 static const char *samsung_pinmux_get_fname(struct pinctrl_dev *pctldev,
311 						unsigned selector)
312 {
313 	struct samsung_pinctrl_drv_data *drvdata;
314 
315 	drvdata = pinctrl_dev_get_drvdata(pctldev);
316 	return drvdata->pmx_functions[selector].name;
317 }
318 
319 /* return the groups associated for the specified function selector */
320 static int samsung_pinmux_get_groups(struct pinctrl_dev *pctldev,
321 		unsigned selector, const char * const **groups,
322 		unsigned * const num_groups)
323 {
324 	struct samsung_pinctrl_drv_data *drvdata;
325 
326 	drvdata = pinctrl_dev_get_drvdata(pctldev);
327 	*groups = drvdata->pmx_functions[selector].groups;
328 	*num_groups = drvdata->pmx_functions[selector].num_groups;
329 	return 0;
330 }
331 
332 /*
333  * given a pin number that is local to a pin controller, find out the pin bank
334  * and the register base of the pin bank.
335  */
336 static void pin_to_reg_bank(struct samsung_pinctrl_drv_data *drvdata,
337 			unsigned pin, void __iomem **reg, u32 *offset,
338 			struct samsung_pin_bank **bank)
339 {
340 	struct samsung_pin_bank *b;
341 
342 	b = drvdata->pin_banks;
343 
344 	while ((pin >= b->pin_base) &&
345 			((b->pin_base + b->nr_pins - 1) < pin))
346 		b++;
347 
348 	*reg = drvdata->virt_base + b->pctl_offset;
349 	*offset = pin - b->pin_base;
350 	if (bank)
351 		*bank = b;
352 }
353 
354 /* enable or disable a pinmux function */
355 static void samsung_pinmux_setup(struct pinctrl_dev *pctldev, unsigned selector,
356 					unsigned group, bool enable)
357 {
358 	struct samsung_pinctrl_drv_data *drvdata;
359 	const struct samsung_pin_bank_type *type;
360 	struct samsung_pin_bank *bank;
361 	void __iomem *reg;
362 	u32 mask, shift, data, pin_offset;
363 	unsigned long flags;
364 	const struct samsung_pmx_func *func;
365 	const struct samsung_pin_group *grp;
366 
367 	drvdata = pinctrl_dev_get_drvdata(pctldev);
368 	func = &drvdata->pmx_functions[selector];
369 	grp = &drvdata->pin_groups[group];
370 
371 	pin_to_reg_bank(drvdata, grp->pins[0] - drvdata->pin_base,
372 			&reg, &pin_offset, &bank);
373 	type = bank->type;
374 	mask = (1 << type->fld_width[PINCFG_TYPE_FUNC]) - 1;
375 	shift = pin_offset * type->fld_width[PINCFG_TYPE_FUNC];
376 	if (shift >= 32) {
377 		/* Some banks have two config registers */
378 		shift -= 32;
379 		reg += 4;
380 	}
381 
382 	spin_lock_irqsave(&bank->slock, flags);
383 
384 	data = readl(reg + type->reg_offset[PINCFG_TYPE_FUNC]);
385 	data &= ~(mask << shift);
386 	if (enable)
387 		data |= func->val << shift;
388 	writel(data, reg + type->reg_offset[PINCFG_TYPE_FUNC]);
389 
390 	spin_unlock_irqrestore(&bank->slock, flags);
391 }
392 
393 /* enable a specified pinmux by writing to registers */
394 static int samsung_pinmux_set_mux(struct pinctrl_dev *pctldev,
395 				  unsigned selector,
396 				  unsigned group)
397 {
398 	samsung_pinmux_setup(pctldev, selector, group, true);
399 	return 0;
400 }
401 
402 /* list of pinmux callbacks for the pinmux vertical in pinctrl core */
403 static const struct pinmux_ops samsung_pinmux_ops = {
404 	.get_functions_count	= samsung_get_functions_count,
405 	.get_function_name	= samsung_pinmux_get_fname,
406 	.get_function_groups	= samsung_pinmux_get_groups,
407 	.set_mux		= samsung_pinmux_set_mux,
408 };
409 
410 /* set or get the pin config settings for a specified pin */
411 static int samsung_pinconf_rw(struct pinctrl_dev *pctldev, unsigned int pin,
412 				unsigned long *config, bool set)
413 {
414 	struct samsung_pinctrl_drv_data *drvdata;
415 	const struct samsung_pin_bank_type *type;
416 	struct samsung_pin_bank *bank;
417 	void __iomem *reg_base;
418 	enum pincfg_type cfg_type = PINCFG_UNPACK_TYPE(*config);
419 	u32 data, width, pin_offset, mask, shift;
420 	u32 cfg_value, cfg_reg;
421 	unsigned long flags;
422 
423 	drvdata = pinctrl_dev_get_drvdata(pctldev);
424 	pin_to_reg_bank(drvdata, pin - drvdata->pin_base, &reg_base,
425 					&pin_offset, &bank);
426 	type = bank->type;
427 
428 	if (cfg_type >= PINCFG_TYPE_NUM || !type->fld_width[cfg_type])
429 		return -EINVAL;
430 
431 	width = type->fld_width[cfg_type];
432 	cfg_reg = type->reg_offset[cfg_type];
433 
434 	spin_lock_irqsave(&bank->slock, flags);
435 
436 	mask = (1 << width) - 1;
437 	shift = pin_offset * width;
438 	data = readl(reg_base + cfg_reg);
439 
440 	if (set) {
441 		cfg_value = PINCFG_UNPACK_VALUE(*config);
442 		data &= ~(mask << shift);
443 		data |= (cfg_value << shift);
444 		writel(data, reg_base + cfg_reg);
445 	} else {
446 		data >>= shift;
447 		data &= mask;
448 		*config = PINCFG_PACK(cfg_type, data);
449 	}
450 
451 	spin_unlock_irqrestore(&bank->slock, flags);
452 
453 	return 0;
454 }
455 
456 /* set the pin config settings for a specified pin */
457 static int samsung_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
458 				unsigned long *configs, unsigned num_configs)
459 {
460 	int i, ret;
461 
462 	for (i = 0; i < num_configs; i++) {
463 		ret = samsung_pinconf_rw(pctldev, pin, &configs[i], true);
464 		if (ret < 0)
465 			return ret;
466 	} /* for each config */
467 
468 	return 0;
469 }
470 
471 /* get the pin config settings for a specified pin */
472 static int samsung_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
473 					unsigned long *config)
474 {
475 	return samsung_pinconf_rw(pctldev, pin, config, false);
476 }
477 
478 /* set the pin config settings for a specified pin group */
479 static int samsung_pinconf_group_set(struct pinctrl_dev *pctldev,
480 			unsigned group, unsigned long *configs,
481 			unsigned num_configs)
482 {
483 	struct samsung_pinctrl_drv_data *drvdata;
484 	const unsigned int *pins;
485 	unsigned int cnt;
486 
487 	drvdata = pinctrl_dev_get_drvdata(pctldev);
488 	pins = drvdata->pin_groups[group].pins;
489 
490 	for (cnt = 0; cnt < drvdata->pin_groups[group].num_pins; cnt++)
491 		samsung_pinconf_set(pctldev, pins[cnt], configs, num_configs);
492 
493 	return 0;
494 }
495 
496 /* get the pin config settings for a specified pin group */
497 static int samsung_pinconf_group_get(struct pinctrl_dev *pctldev,
498 				unsigned int group, unsigned long *config)
499 {
500 	struct samsung_pinctrl_drv_data *drvdata;
501 	const unsigned int *pins;
502 
503 	drvdata = pinctrl_dev_get_drvdata(pctldev);
504 	pins = drvdata->pin_groups[group].pins;
505 	samsung_pinconf_get(pctldev, pins[0], config);
506 	return 0;
507 }
508 
509 /* list of pinconfig callbacks for pinconfig vertical in the pinctrl code */
510 static const struct pinconf_ops samsung_pinconf_ops = {
511 	.pin_config_get		= samsung_pinconf_get,
512 	.pin_config_set		= samsung_pinconf_set,
513 	.pin_config_group_get	= samsung_pinconf_group_get,
514 	.pin_config_group_set	= samsung_pinconf_group_set,
515 };
516 
517 /*
518  * The samsung_gpio_set_vlaue() should be called with "bank->slock" held
519  * to avoid race condition.
520  */
521 static void samsung_gpio_set_value(struct gpio_chip *gc,
522 					  unsigned offset, int value)
523 {
524 	struct samsung_pin_bank *bank = gpiochip_get_data(gc);
525 	const struct samsung_pin_bank_type *type = bank->type;
526 	void __iomem *reg;
527 	u32 data;
528 
529 	reg = bank->drvdata->virt_base + bank->pctl_offset;
530 
531 	data = readl(reg + type->reg_offset[PINCFG_TYPE_DAT]);
532 	data &= ~(1 << offset);
533 	if (value)
534 		data |= 1 << offset;
535 	writel(data, reg + type->reg_offset[PINCFG_TYPE_DAT]);
536 }
537 
538 /* gpiolib gpio_set callback function */
539 static void samsung_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
540 {
541 	struct samsung_pin_bank *bank = gpiochip_get_data(gc);
542 	unsigned long flags;
543 
544 	spin_lock_irqsave(&bank->slock, flags);
545 	samsung_gpio_set_value(gc, offset, value);
546 	spin_unlock_irqrestore(&bank->slock, flags);
547 }
548 
549 /* gpiolib gpio_get callback function */
550 static int samsung_gpio_get(struct gpio_chip *gc, unsigned offset)
551 {
552 	void __iomem *reg;
553 	u32 data;
554 	struct samsung_pin_bank *bank = gpiochip_get_data(gc);
555 	const struct samsung_pin_bank_type *type = bank->type;
556 
557 	reg = bank->drvdata->virt_base + bank->pctl_offset;
558 
559 	data = readl(reg + type->reg_offset[PINCFG_TYPE_DAT]);
560 	data >>= offset;
561 	data &= 1;
562 	return data;
563 }
564 
565 /*
566  * The samsung_gpio_set_direction() should be called with "bank->slock" held
567  * to avoid race condition.
568  * The calls to gpio_direction_output() and gpio_direction_input()
569  * leads to this function call.
570  */
571 static int samsung_gpio_set_direction(struct gpio_chip *gc,
572 					     unsigned offset, bool input)
573 {
574 	const struct samsung_pin_bank_type *type;
575 	struct samsung_pin_bank *bank;
576 	struct samsung_pinctrl_drv_data *drvdata;
577 	void __iomem *reg;
578 	u32 data, mask, shift;
579 
580 	bank = gpiochip_get_data(gc);
581 	type = bank->type;
582 	drvdata = bank->drvdata;
583 
584 	reg = drvdata->virt_base + bank->pctl_offset +
585 					type->reg_offset[PINCFG_TYPE_FUNC];
586 
587 	mask = (1 << type->fld_width[PINCFG_TYPE_FUNC]) - 1;
588 	shift = offset * type->fld_width[PINCFG_TYPE_FUNC];
589 	if (shift >= 32) {
590 		/* Some banks have two config registers */
591 		shift -= 32;
592 		reg += 4;
593 	}
594 
595 	data = readl(reg);
596 	data &= ~(mask << shift);
597 	if (!input)
598 		data |= FUNC_OUTPUT << shift;
599 	writel(data, reg);
600 
601 	return 0;
602 }
603 
604 /* gpiolib gpio_direction_input callback function. */
605 static int samsung_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
606 {
607 	struct samsung_pin_bank *bank = gpiochip_get_data(gc);
608 	unsigned long flags;
609 	int ret;
610 
611 	spin_lock_irqsave(&bank->slock, flags);
612 	ret = samsung_gpio_set_direction(gc, offset, true);
613 	spin_unlock_irqrestore(&bank->slock, flags);
614 	return ret;
615 }
616 
617 /* gpiolib gpio_direction_output callback function. */
618 static int samsung_gpio_direction_output(struct gpio_chip *gc, unsigned offset,
619 							int value)
620 {
621 	struct samsung_pin_bank *bank = gpiochip_get_data(gc);
622 	unsigned long flags;
623 	int ret;
624 
625 	spin_lock_irqsave(&bank->slock, flags);
626 	samsung_gpio_set_value(gc, offset, value);
627 	ret = samsung_gpio_set_direction(gc, offset, false);
628 	spin_unlock_irqrestore(&bank->slock, flags);
629 
630 	return ret;
631 }
632 
633 /*
634  * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin
635  * and a virtual IRQ, if not already present.
636  */
637 static int samsung_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
638 {
639 	struct samsung_pin_bank *bank = gpiochip_get_data(gc);
640 	unsigned int virq;
641 
642 	if (!bank->irq_domain)
643 		return -ENXIO;
644 
645 	virq = irq_create_mapping(bank->irq_domain, offset);
646 
647 	return (virq) ? : -ENXIO;
648 }
649 
650 static struct samsung_pin_group *samsung_pinctrl_create_groups(
651 				struct device *dev,
652 				struct samsung_pinctrl_drv_data *drvdata,
653 				unsigned int *cnt)
654 {
655 	struct pinctrl_desc *ctrldesc = &drvdata->pctl;
656 	struct samsung_pin_group *groups, *grp;
657 	const struct pinctrl_pin_desc *pdesc;
658 	int i;
659 
660 	groups = devm_kzalloc(dev, ctrldesc->npins * sizeof(*groups),
661 				GFP_KERNEL);
662 	if (!groups)
663 		return ERR_PTR(-EINVAL);
664 	grp = groups;
665 
666 	pdesc = ctrldesc->pins;
667 	for (i = 0; i < ctrldesc->npins; ++i, ++pdesc, ++grp) {
668 		grp->name = pdesc->name;
669 		grp->pins = &pdesc->number;
670 		grp->num_pins = 1;
671 	}
672 
673 	*cnt = ctrldesc->npins;
674 	return groups;
675 }
676 
677 static int samsung_pinctrl_create_function(struct device *dev,
678 				struct samsung_pinctrl_drv_data *drvdata,
679 				struct device_node *func_np,
680 				struct samsung_pmx_func *func)
681 {
682 	int npins;
683 	int ret;
684 	int i;
685 
686 	if (of_property_read_u32(func_np, "samsung,pin-function", &func->val))
687 		return 0;
688 
689 	npins = of_property_count_strings(func_np, "samsung,pins");
690 	if (npins < 1) {
691 		dev_err(dev, "invalid pin list in %s node", func_np->name);
692 		return -EINVAL;
693 	}
694 
695 	func->name = func_np->full_name;
696 
697 	func->groups = devm_kzalloc(dev, npins * sizeof(char *), GFP_KERNEL);
698 	if (!func->groups)
699 		return -ENOMEM;
700 
701 	for (i = 0; i < npins; ++i) {
702 		const char *gname;
703 
704 		ret = of_property_read_string_index(func_np, "samsung,pins",
705 							i, &gname);
706 		if (ret) {
707 			dev_err(dev,
708 				"failed to read pin name %d from %s node\n",
709 				i, func_np->name);
710 			return ret;
711 		}
712 
713 		func->groups[i] = gname;
714 	}
715 
716 	func->num_groups = npins;
717 	return 1;
718 }
719 
720 static struct samsung_pmx_func *samsung_pinctrl_create_functions(
721 				struct device *dev,
722 				struct samsung_pinctrl_drv_data *drvdata,
723 				unsigned int *cnt)
724 {
725 	struct samsung_pmx_func *functions, *func;
726 	struct device_node *dev_np = dev->of_node;
727 	struct device_node *cfg_np;
728 	unsigned int func_cnt = 0;
729 	int ret;
730 
731 	/*
732 	 * Iterate over all the child nodes of the pin controller node
733 	 * and create pin groups and pin function lists.
734 	 */
735 	for_each_child_of_node(dev_np, cfg_np) {
736 		struct device_node *func_np;
737 
738 		if (!of_get_child_count(cfg_np)) {
739 			if (!of_find_property(cfg_np,
740 			    "samsung,pin-function", NULL))
741 				continue;
742 			++func_cnt;
743 			continue;
744 		}
745 
746 		for_each_child_of_node(cfg_np, func_np) {
747 			if (!of_find_property(func_np,
748 			    "samsung,pin-function", NULL))
749 				continue;
750 			++func_cnt;
751 		}
752 	}
753 
754 	functions = devm_kzalloc(dev, func_cnt * sizeof(*functions),
755 					GFP_KERNEL);
756 	if (!functions) {
757 		dev_err(dev, "failed to allocate memory for function list\n");
758 		return ERR_PTR(-EINVAL);
759 	}
760 	func = functions;
761 
762 	/*
763 	 * Iterate over all the child nodes of the pin controller node
764 	 * and create pin groups and pin function lists.
765 	 */
766 	func_cnt = 0;
767 	for_each_child_of_node(dev_np, cfg_np) {
768 		struct device_node *func_np;
769 
770 		if (!of_get_child_count(cfg_np)) {
771 			ret = samsung_pinctrl_create_function(dev, drvdata,
772 							cfg_np, func);
773 			if (ret < 0)
774 				return ERR_PTR(ret);
775 			if (ret > 0) {
776 				++func;
777 				++func_cnt;
778 			}
779 			continue;
780 		}
781 
782 		for_each_child_of_node(cfg_np, func_np) {
783 			ret = samsung_pinctrl_create_function(dev, drvdata,
784 						func_np, func);
785 			if (ret < 0)
786 				return ERR_PTR(ret);
787 			if (ret > 0) {
788 				++func;
789 				++func_cnt;
790 			}
791 		}
792 	}
793 
794 	*cnt = func_cnt;
795 	return functions;
796 }
797 
798 /*
799  * Parse the information about all the available pin groups and pin functions
800  * from device node of the pin-controller. A pin group is formed with all
801  * the pins listed in the "samsung,pins" property.
802  */
803 
804 static int samsung_pinctrl_parse_dt(struct platform_device *pdev,
805 				    struct samsung_pinctrl_drv_data *drvdata)
806 {
807 	struct device *dev = &pdev->dev;
808 	struct samsung_pin_group *groups;
809 	struct samsung_pmx_func *functions;
810 	unsigned int grp_cnt = 0, func_cnt = 0;
811 
812 	groups = samsung_pinctrl_create_groups(dev, drvdata, &grp_cnt);
813 	if (IS_ERR(groups)) {
814 		dev_err(dev, "failed to parse pin groups\n");
815 		return PTR_ERR(groups);
816 	}
817 
818 	functions = samsung_pinctrl_create_functions(dev, drvdata, &func_cnt);
819 	if (IS_ERR(functions)) {
820 		dev_err(dev, "failed to parse pin functions\n");
821 		return PTR_ERR(functions);
822 	}
823 
824 	drvdata->pin_groups = groups;
825 	drvdata->nr_groups = grp_cnt;
826 	drvdata->pmx_functions = functions;
827 	drvdata->nr_functions = func_cnt;
828 
829 	return 0;
830 }
831 
832 /* register the pinctrl interface with the pinctrl subsystem */
833 static int samsung_pinctrl_register(struct platform_device *pdev,
834 				    struct samsung_pinctrl_drv_data *drvdata)
835 {
836 	struct pinctrl_desc *ctrldesc = &drvdata->pctl;
837 	struct pinctrl_pin_desc *pindesc, *pdesc;
838 	struct samsung_pin_bank *pin_bank;
839 	char *pin_names;
840 	int pin, bank, ret;
841 
842 	ctrldesc->name = "samsung-pinctrl";
843 	ctrldesc->owner = THIS_MODULE;
844 	ctrldesc->pctlops = &samsung_pctrl_ops;
845 	ctrldesc->pmxops = &samsung_pinmux_ops;
846 	ctrldesc->confops = &samsung_pinconf_ops;
847 
848 	pindesc = devm_kzalloc(&pdev->dev, sizeof(*pindesc) *
849 			drvdata->nr_pins, GFP_KERNEL);
850 	if (!pindesc) {
851 		dev_err(&pdev->dev, "mem alloc for pin descriptors failed\n");
852 		return -ENOMEM;
853 	}
854 	ctrldesc->pins = pindesc;
855 	ctrldesc->npins = drvdata->nr_pins;
856 
857 	/* dynamically populate the pin number and pin name for pindesc */
858 	for (pin = 0, pdesc = pindesc; pin < ctrldesc->npins; pin++, pdesc++)
859 		pdesc->number = pin + drvdata->pin_base;
860 
861 	/*
862 	 * allocate space for storing the dynamically generated names for all
863 	 * the pins which belong to this pin-controller.
864 	 */
865 	pin_names = devm_kzalloc(&pdev->dev, sizeof(char) * PIN_NAME_LENGTH *
866 					drvdata->nr_pins, GFP_KERNEL);
867 	if (!pin_names) {
868 		dev_err(&pdev->dev, "mem alloc for pin names failed\n");
869 		return -ENOMEM;
870 	}
871 
872 	/* for each pin, the name of the pin is pin-bank name + pin number */
873 	for (bank = 0; bank < drvdata->nr_banks; bank++) {
874 		pin_bank = &drvdata->pin_banks[bank];
875 		for (pin = 0; pin < pin_bank->nr_pins; pin++) {
876 			sprintf(pin_names, "%s-%d", pin_bank->name, pin);
877 			pdesc = pindesc + pin_bank->pin_base + pin;
878 			pdesc->name = pin_names;
879 			pin_names += PIN_NAME_LENGTH;
880 		}
881 	}
882 
883 	ret = samsung_pinctrl_parse_dt(pdev, drvdata);
884 	if (ret)
885 		return ret;
886 
887 	drvdata->pctl_dev = pinctrl_register(ctrldesc, &pdev->dev, drvdata);
888 	if (IS_ERR(drvdata->pctl_dev)) {
889 		dev_err(&pdev->dev, "could not register pinctrl driver\n");
890 		return PTR_ERR(drvdata->pctl_dev);
891 	}
892 
893 	for (bank = 0; bank < drvdata->nr_banks; ++bank) {
894 		pin_bank = &drvdata->pin_banks[bank];
895 		pin_bank->grange.name = pin_bank->name;
896 		pin_bank->grange.id = bank;
897 		pin_bank->grange.pin_base = drvdata->pin_base
898 						+ pin_bank->pin_base;
899 		pin_bank->grange.base = pin_bank->gpio_chip.base;
900 		pin_bank->grange.npins = pin_bank->gpio_chip.ngpio;
901 		pin_bank->grange.gc = &pin_bank->gpio_chip;
902 		pinctrl_add_gpio_range(drvdata->pctl_dev, &pin_bank->grange);
903 	}
904 
905 	return 0;
906 }
907 
908 static const struct gpio_chip samsung_gpiolib_chip = {
909 	.request = gpiochip_generic_request,
910 	.free = gpiochip_generic_free,
911 	.set = samsung_gpio_set,
912 	.get = samsung_gpio_get,
913 	.direction_input = samsung_gpio_direction_input,
914 	.direction_output = samsung_gpio_direction_output,
915 	.to_irq = samsung_gpio_to_irq,
916 	.owner = THIS_MODULE,
917 };
918 
919 /* register the gpiolib interface with the gpiolib subsystem */
920 static int samsung_gpiolib_register(struct platform_device *pdev,
921 				    struct samsung_pinctrl_drv_data *drvdata)
922 {
923 	struct samsung_pin_bank *bank = drvdata->pin_banks;
924 	struct gpio_chip *gc;
925 	int ret;
926 	int i;
927 
928 	for (i = 0; i < drvdata->nr_banks; ++i, ++bank) {
929 		bank->gpio_chip = samsung_gpiolib_chip;
930 
931 		gc = &bank->gpio_chip;
932 		gc->base = drvdata->pin_base + bank->pin_base;
933 		gc->ngpio = bank->nr_pins;
934 		gc->parent = &pdev->dev;
935 		gc->of_node = bank->of_node;
936 		gc->label = bank->name;
937 
938 		ret = gpiochip_add_data(gc, bank);
939 		if (ret) {
940 			dev_err(&pdev->dev, "failed to register gpio_chip %s, error code: %d\n",
941 							gc->label, ret);
942 			goto fail;
943 		}
944 	}
945 
946 	return 0;
947 
948 fail:
949 	for (--i, --bank; i >= 0; --i, --bank)
950 		gpiochip_remove(&bank->gpio_chip);
951 	return ret;
952 }
953 
954 /* unregister the gpiolib interface with the gpiolib subsystem */
955 static int samsung_gpiolib_unregister(struct platform_device *pdev,
956 				      struct samsung_pinctrl_drv_data *drvdata)
957 {
958 	struct samsung_pin_bank *bank = drvdata->pin_banks;
959 	int i;
960 
961 	for (i = 0; i < drvdata->nr_banks; ++i, ++bank)
962 		gpiochip_remove(&bank->gpio_chip);
963 
964 	return 0;
965 }
966 
967 static const struct of_device_id samsung_pinctrl_dt_match[];
968 
969 /* retrieve the soc specific data */
970 static const struct samsung_pin_ctrl *
971 samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
972 			     struct platform_device *pdev)
973 {
974 	int id;
975 	const struct of_device_id *match;
976 	struct device_node *node = pdev->dev.of_node;
977 	struct device_node *np;
978 	const struct samsung_pin_bank_data *bdata;
979 	const struct samsung_pin_ctrl *ctrl;
980 	struct samsung_pin_bank *bank;
981 	int i;
982 
983 	id = of_alias_get_id(node, "pinctrl");
984 	if (id < 0) {
985 		dev_err(&pdev->dev, "failed to get alias id\n");
986 		return ERR_PTR(-ENOENT);
987 	}
988 	match = of_match_node(samsung_pinctrl_dt_match, node);
989 	ctrl = (struct samsung_pin_ctrl *)match->data + id;
990 
991 	d->suspend = ctrl->suspend;
992 	d->resume = ctrl->resume;
993 	d->nr_banks = ctrl->nr_banks;
994 	d->pin_banks = devm_kcalloc(&pdev->dev, d->nr_banks,
995 					sizeof(*d->pin_banks), GFP_KERNEL);
996 	if (!d->pin_banks)
997 		return ERR_PTR(-ENOMEM);
998 
999 	bank = d->pin_banks;
1000 	bdata = ctrl->pin_banks;
1001 	for (i = 0; i < ctrl->nr_banks; ++i, ++bdata, ++bank) {
1002 		bank->type = bdata->type;
1003 		bank->pctl_offset = bdata->pctl_offset;
1004 		bank->nr_pins = bdata->nr_pins;
1005 		bank->eint_func = bdata->eint_func;
1006 		bank->eint_type = bdata->eint_type;
1007 		bank->eint_mask = bdata->eint_mask;
1008 		bank->eint_offset = bdata->eint_offset;
1009 		bank->name = bdata->name;
1010 
1011 		spin_lock_init(&bank->slock);
1012 		bank->drvdata = d;
1013 		bank->pin_base = d->nr_pins;
1014 		d->nr_pins += bank->nr_pins;
1015 	}
1016 
1017 	for_each_child_of_node(node, np) {
1018 		if (!of_find_property(np, "gpio-controller", NULL))
1019 			continue;
1020 		bank = d->pin_banks;
1021 		for (i = 0; i < d->nr_banks; ++i, ++bank) {
1022 			if (!strcmp(bank->name, np->name)) {
1023 				bank->of_node = np;
1024 				break;
1025 			}
1026 		}
1027 	}
1028 
1029 	d->pin_base = pin_base;
1030 	pin_base += d->nr_pins;
1031 
1032 	return ctrl;
1033 }
1034 
1035 static int samsung_pinctrl_probe(struct platform_device *pdev)
1036 {
1037 	struct samsung_pinctrl_drv_data *drvdata;
1038 	const struct samsung_pin_ctrl *ctrl;
1039 	struct device *dev = &pdev->dev;
1040 	struct resource *res;
1041 	int ret;
1042 
1043 	if (!dev->of_node) {
1044 		dev_err(dev, "device tree node not found\n");
1045 		return -ENODEV;
1046 	}
1047 
1048 	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
1049 	if (!drvdata) {
1050 		dev_err(dev, "failed to allocate memory for driver's "
1051 				"private data\n");
1052 		return -ENOMEM;
1053 	}
1054 
1055 	ctrl = samsung_pinctrl_get_soc_data(drvdata, pdev);
1056 	if (IS_ERR(ctrl)) {
1057 		dev_err(&pdev->dev, "driver data not available\n");
1058 		return PTR_ERR(ctrl);
1059 	}
1060 	drvdata->dev = dev;
1061 
1062 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1063 	drvdata->virt_base = devm_ioremap_resource(&pdev->dev, res);
1064 	if (IS_ERR(drvdata->virt_base))
1065 		return PTR_ERR(drvdata->virt_base);
1066 
1067 	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1068 	if (res)
1069 		drvdata->irq = res->start;
1070 
1071 	ret = samsung_gpiolib_register(pdev, drvdata);
1072 	if (ret)
1073 		return ret;
1074 
1075 	ret = samsung_pinctrl_register(pdev, drvdata);
1076 	if (ret) {
1077 		samsung_gpiolib_unregister(pdev, drvdata);
1078 		return ret;
1079 	}
1080 
1081 	if (ctrl->eint_gpio_init)
1082 		ctrl->eint_gpio_init(drvdata);
1083 	if (ctrl->eint_wkup_init)
1084 		ctrl->eint_wkup_init(drvdata);
1085 
1086 	platform_set_drvdata(pdev, drvdata);
1087 
1088 	/* Add to the global list */
1089 	list_add_tail(&drvdata->node, &drvdata_list);
1090 
1091 	return 0;
1092 }
1093 
1094 #ifdef CONFIG_PM
1095 
1096 /**
1097  * samsung_pinctrl_suspend_dev - save pinctrl state for suspend for a device
1098  *
1099  * Save data for all banks handled by this device.
1100  */
1101 static void samsung_pinctrl_suspend_dev(
1102 	struct samsung_pinctrl_drv_data *drvdata)
1103 {
1104 	void __iomem *virt_base = drvdata->virt_base;
1105 	int i;
1106 
1107 	for (i = 0; i < drvdata->nr_banks; i++) {
1108 		struct samsung_pin_bank *bank = &drvdata->pin_banks[i];
1109 		void __iomem *reg = virt_base + bank->pctl_offset;
1110 		const u8 *offs = bank->type->reg_offset;
1111 		const u8 *widths = bank->type->fld_width;
1112 		enum pincfg_type type;
1113 
1114 		/* Registers without a powerdown config aren't lost */
1115 		if (!widths[PINCFG_TYPE_CON_PDN])
1116 			continue;
1117 
1118 		for (type = 0; type < PINCFG_TYPE_NUM; type++)
1119 			if (widths[type])
1120 				bank->pm_save[type] = readl(reg + offs[type]);
1121 
1122 		if (widths[PINCFG_TYPE_FUNC] * bank->nr_pins > 32) {
1123 			/* Some banks have two config registers */
1124 			bank->pm_save[PINCFG_TYPE_NUM] =
1125 				readl(reg + offs[PINCFG_TYPE_FUNC] + 4);
1126 			pr_debug("Save %s @ %p (con %#010x %08x)\n",
1127 				 bank->name, reg,
1128 				 bank->pm_save[PINCFG_TYPE_FUNC],
1129 				 bank->pm_save[PINCFG_TYPE_NUM]);
1130 		} else {
1131 			pr_debug("Save %s @ %p (con %#010x)\n", bank->name,
1132 				 reg, bank->pm_save[PINCFG_TYPE_FUNC]);
1133 		}
1134 	}
1135 
1136 	if (drvdata->suspend)
1137 		drvdata->suspend(drvdata);
1138 }
1139 
1140 /**
1141  * samsung_pinctrl_resume_dev - restore pinctrl state from suspend for a device
1142  *
1143  * Restore one of the banks that was saved during suspend.
1144  *
1145  * We don't bother doing anything complicated to avoid glitching lines since
1146  * we're called before pad retention is turned off.
1147  */
1148 static void samsung_pinctrl_resume_dev(struct samsung_pinctrl_drv_data *drvdata)
1149 {
1150 	void __iomem *virt_base = drvdata->virt_base;
1151 	int i;
1152 
1153 	if (drvdata->resume)
1154 		drvdata->resume(drvdata);
1155 
1156 	for (i = 0; i < drvdata->nr_banks; i++) {
1157 		struct samsung_pin_bank *bank = &drvdata->pin_banks[i];
1158 		void __iomem *reg = virt_base + bank->pctl_offset;
1159 		const u8 *offs = bank->type->reg_offset;
1160 		const u8 *widths = bank->type->fld_width;
1161 		enum pincfg_type type;
1162 
1163 		/* Registers without a powerdown config aren't lost */
1164 		if (!widths[PINCFG_TYPE_CON_PDN])
1165 			continue;
1166 
1167 		if (widths[PINCFG_TYPE_FUNC] * bank->nr_pins > 32) {
1168 			/* Some banks have two config registers */
1169 			pr_debug("%s @ %p (con %#010x %08x => %#010x %08x)\n",
1170 				 bank->name, reg,
1171 				 readl(reg + offs[PINCFG_TYPE_FUNC]),
1172 				 readl(reg + offs[PINCFG_TYPE_FUNC] + 4),
1173 				 bank->pm_save[PINCFG_TYPE_FUNC],
1174 				 bank->pm_save[PINCFG_TYPE_NUM]);
1175 			writel(bank->pm_save[PINCFG_TYPE_NUM],
1176 			       reg + offs[PINCFG_TYPE_FUNC] + 4);
1177 		} else {
1178 			pr_debug("%s @ %p (con %#010x => %#010x)\n", bank->name,
1179 				 reg, readl(reg + offs[PINCFG_TYPE_FUNC]),
1180 				 bank->pm_save[PINCFG_TYPE_FUNC]);
1181 		}
1182 		for (type = 0; type < PINCFG_TYPE_NUM; type++)
1183 			if (widths[type])
1184 				writel(bank->pm_save[type], reg + offs[type]);
1185 	}
1186 }
1187 
1188 /**
1189  * samsung_pinctrl_suspend - save pinctrl state for suspend
1190  *
1191  * Save data for all banks across all devices.
1192  */
1193 static int samsung_pinctrl_suspend(void)
1194 {
1195 	struct samsung_pinctrl_drv_data *drvdata;
1196 
1197 	list_for_each_entry(drvdata, &drvdata_list, node) {
1198 		samsung_pinctrl_suspend_dev(drvdata);
1199 	}
1200 
1201 	return 0;
1202 }
1203 
1204 /**
1205  * samsung_pinctrl_resume - restore pinctrl state for suspend
1206  *
1207  * Restore data for all banks across all devices.
1208  */
1209 static void samsung_pinctrl_resume(void)
1210 {
1211 	struct samsung_pinctrl_drv_data *drvdata;
1212 
1213 	list_for_each_entry_reverse(drvdata, &drvdata_list, node) {
1214 		samsung_pinctrl_resume_dev(drvdata);
1215 	}
1216 }
1217 
1218 #else
1219 #define samsung_pinctrl_suspend		NULL
1220 #define samsung_pinctrl_resume		NULL
1221 #endif
1222 
1223 static struct syscore_ops samsung_pinctrl_syscore_ops = {
1224 	.suspend	= samsung_pinctrl_suspend,
1225 	.resume		= samsung_pinctrl_resume,
1226 };
1227 
1228 static const struct of_device_id samsung_pinctrl_dt_match[] = {
1229 #ifdef CONFIG_PINCTRL_EXYNOS
1230 	{ .compatible = "samsung,exynos3250-pinctrl",
1231 		.data = (void *)exynos3250_pin_ctrl },
1232 	{ .compatible = "samsung,exynos4210-pinctrl",
1233 		.data = (void *)exynos4210_pin_ctrl },
1234 	{ .compatible = "samsung,exynos4x12-pinctrl",
1235 		.data = (void *)exynos4x12_pin_ctrl },
1236 	{ .compatible = "samsung,exynos4415-pinctrl",
1237 		.data = (void *)exynos4415_pin_ctrl },
1238 	{ .compatible = "samsung,exynos5250-pinctrl",
1239 		.data = (void *)exynos5250_pin_ctrl },
1240 	{ .compatible = "samsung,exynos5260-pinctrl",
1241 		.data = (void *)exynos5260_pin_ctrl },
1242 	{ .compatible = "samsung,exynos5410-pinctrl",
1243 		.data = (void *)exynos5410_pin_ctrl },
1244 	{ .compatible = "samsung,exynos5420-pinctrl",
1245 		.data = (void *)exynos5420_pin_ctrl },
1246 	{ .compatible = "samsung,exynos5433-pinctrl",
1247 		.data = (void *)exynos5433_pin_ctrl },
1248 	{ .compatible = "samsung,s5pv210-pinctrl",
1249 		.data = (void *)s5pv210_pin_ctrl },
1250 	{ .compatible = "samsung,exynos7-pinctrl",
1251 		.data = (void *)exynos7_pin_ctrl },
1252 #endif
1253 #ifdef CONFIG_PINCTRL_S3C64XX
1254 	{ .compatible = "samsung,s3c64xx-pinctrl",
1255 		.data = s3c64xx_pin_ctrl },
1256 #endif
1257 #ifdef CONFIG_PINCTRL_S3C24XX
1258 	{ .compatible = "samsung,s3c2412-pinctrl",
1259 		.data = s3c2412_pin_ctrl },
1260 	{ .compatible = "samsung,s3c2416-pinctrl",
1261 		.data = s3c2416_pin_ctrl },
1262 	{ .compatible = "samsung,s3c2440-pinctrl",
1263 		.data = s3c2440_pin_ctrl },
1264 	{ .compatible = "samsung,s3c2450-pinctrl",
1265 		.data = s3c2450_pin_ctrl },
1266 #endif
1267 	{},
1268 };
1269 MODULE_DEVICE_TABLE(of, samsung_pinctrl_dt_match);
1270 
1271 static struct platform_driver samsung_pinctrl_driver = {
1272 	.probe		= samsung_pinctrl_probe,
1273 	.driver = {
1274 		.name	= "samsung-pinctrl",
1275 		.of_match_table = samsung_pinctrl_dt_match,
1276 	},
1277 };
1278 
1279 static int __init samsung_pinctrl_drv_register(void)
1280 {
1281 	/*
1282 	 * Register syscore ops for save/restore of registers across suspend.
1283 	 * It's important to ensure that this driver is running at an earlier
1284 	 * initcall level than any arch-specific init calls that install syscore
1285 	 * ops that turn off pad retention (like exynos_pm_resume).
1286 	 */
1287 	register_syscore_ops(&samsung_pinctrl_syscore_ops);
1288 
1289 	return platform_driver_register(&samsung_pinctrl_driver);
1290 }
1291 postcore_initcall(samsung_pinctrl_drv_register);
1292 
1293 static void __exit samsung_pinctrl_drv_unregister(void)
1294 {
1295 	platform_driver_unregister(&samsung_pinctrl_driver);
1296 }
1297 module_exit(samsung_pinctrl_drv_unregister);
1298 
1299 MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com>");
1300 MODULE_DESCRIPTION("Samsung pinctrl driver");
1301 MODULE_LICENSE("GPL v2");
1302