2 * pin-controller/pin-mux/pin-config/gpio-driver for Samsung's SoC's.
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
6 * Copyright (c) 2012 Linaro Ltd
7 * http://www.linaro.org
9 * Author: Thomas Abraham <thomas.ab@samsung.com>
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.
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.
23 #include <linux/module.h>
24 #include <linux/platform_device.h>
26 #include <linux/slab.h>
27 #include <linux/err.h>
28 #include <linux/gpio.h>
31 #include "pinctrl-samsung.h"
33 #define GROUP_SUFFIX "-grp"
34 #define GSUFFIX_LEN sizeof(GROUP_SUFFIX)
35 #define FUNCTION_SUFFIX "-mux"
36 #define FSUFFIX_LEN sizeof(FUNCTION_SUFFIX)
38 /* list of all possible config options supported */
41 unsigned int cfg_type;
43 { "samsung,pin-pud", PINCFG_TYPE_PUD },
44 { "samsung,pin-drv", PINCFG_TYPE_DRV },
45 { "samsung,pin-con-pdn", PINCFG_TYPE_CON_PDN },
46 { "samsung,pin-pud-pdn", PINCFG_TYPE_PUD_PDN },
49 static unsigned int pin_base = 0;
51 /* check if the selector is a valid pin group selector */
52 static int samsung_get_group_count(struct pinctrl_dev *pctldev)
54 struct samsung_pinctrl_drv_data *drvdata;
56 drvdata = pinctrl_dev_get_drvdata(pctldev);
57 return drvdata->nr_groups;
60 /* return the name of the group selected by the group selector */
61 static const char *samsung_get_group_name(struct pinctrl_dev *pctldev,
64 struct samsung_pinctrl_drv_data *drvdata;
66 drvdata = pinctrl_dev_get_drvdata(pctldev);
67 return drvdata->pin_groups[selector].name;
70 /* return the pin numbers associated with the specified group */
71 static int samsung_get_group_pins(struct pinctrl_dev *pctldev,
72 unsigned selector, const unsigned **pins, unsigned *num_pins)
74 struct samsung_pinctrl_drv_data *drvdata;
76 drvdata = pinctrl_dev_get_drvdata(pctldev);
77 *pins = drvdata->pin_groups[selector].pins;
78 *num_pins = drvdata->pin_groups[selector].num_pins;
82 /* create pinctrl_map entries by parsing device tree nodes */
83 static int samsung_dt_node_to_map(struct pinctrl_dev *pctldev,
84 struct device_node *np, struct pinctrl_map **maps,
87 struct device *dev = pctldev->dev;
88 struct pinctrl_map *map;
89 unsigned long *cfg = NULL;
91 int cfg_cnt = 0, map_cnt = 0, idx = 0;
93 /* count the number of config options specfied in the node */
94 for (idx = 0; idx < ARRAY_SIZE(pcfgs); idx++) {
95 if (of_find_property(np, pcfgs[idx].prop_cfg, NULL))
100 * Find out the number of map entries to create. All the config options
101 * can be accomadated into a single config map entry.
105 if (of_find_property(np, "samsung,pin-function", NULL))
108 dev_err(dev, "node %s does not have either config or function "
109 "configurations\n", np->name);
113 /* Allocate memory for pin-map entries */
114 map = kzalloc(sizeof(*map) * map_cnt, GFP_KERNEL);
116 dev_err(dev, "could not alloc memory for pin-maps\n");
122 * Allocate memory for pin group name. The pin group name is derived
123 * from the node name from which these map entries are be created.
125 gname = kzalloc(strlen(np->name) + GSUFFIX_LEN, GFP_KERNEL);
127 dev_err(dev, "failed to alloc memory for group name\n");
130 sprintf(gname, "%s%s", np->name, GROUP_SUFFIX);
133 * don't have config options? then skip over to creating function
139 /* Allocate memory for config entries */
140 cfg = kzalloc(sizeof(*cfg) * cfg_cnt, GFP_KERNEL);
142 dev_err(dev, "failed to alloc memory for configs\n");
146 /* Prepare a list of config settings */
147 for (idx = 0, cfg_cnt = 0; idx < ARRAY_SIZE(pcfgs); idx++) {
149 if (!of_property_read_u32(np, pcfgs[idx].prop_cfg, &value))
151 PINCFG_PACK(pcfgs[idx].cfg_type, value);
154 /* create the config map entry */
155 map[*nmaps].data.configs.group_or_pin = gname;
156 map[*nmaps].data.configs.configs = cfg;
157 map[*nmaps].data.configs.num_configs = cfg_cnt;
158 map[*nmaps].type = PIN_MAP_TYPE_CONFIGS_GROUP;
162 /* create the function map entry */
163 if (of_find_property(np, "samsung,pin-function", NULL)) {
164 fname = kzalloc(strlen(np->name) + FSUFFIX_LEN, GFP_KERNEL);
166 dev_err(dev, "failed to alloc memory for func name\n");
169 sprintf(fname, "%s%s", np->name, FUNCTION_SUFFIX);
171 map[*nmaps].data.mux.group = gname;
172 map[*nmaps].data.mux.function = fname;
173 map[*nmaps].type = PIN_MAP_TYPE_MUX_GROUP;
189 /* free the memory allocated to hold the pin-map table */
190 static void samsung_dt_free_map(struct pinctrl_dev *pctldev,
191 struct pinctrl_map *map, unsigned num_maps)
195 for (idx = 0; idx < num_maps; idx++) {
196 if (map[idx].type == PIN_MAP_TYPE_MUX_GROUP) {
197 kfree(map[idx].data.mux.function);
199 kfree(map[idx].data.mux.group);
200 } else if (map->type == PIN_MAP_TYPE_CONFIGS_GROUP) {
201 kfree(map[idx].data.configs.configs);
203 kfree(map[idx].data.configs.group_or_pin);
210 /* list of pinctrl callbacks for the pinctrl core */
211 static struct pinctrl_ops samsung_pctrl_ops = {
212 .get_groups_count = samsung_get_group_count,
213 .get_group_name = samsung_get_group_name,
214 .get_group_pins = samsung_get_group_pins,
215 .dt_node_to_map = samsung_dt_node_to_map,
216 .dt_free_map = samsung_dt_free_map,
219 /* check if the selector is a valid pin function selector */
220 static int samsung_get_functions_count(struct pinctrl_dev *pctldev)
222 struct samsung_pinctrl_drv_data *drvdata;
224 drvdata = pinctrl_dev_get_drvdata(pctldev);
225 return drvdata->nr_functions;
228 /* return the name of the pin function specified */
229 static const char *samsung_pinmux_get_fname(struct pinctrl_dev *pctldev,
232 struct samsung_pinctrl_drv_data *drvdata;
234 drvdata = pinctrl_dev_get_drvdata(pctldev);
235 return drvdata->pmx_functions[selector].name;
238 /* return the groups associated for the specified function selector */
239 static int samsung_pinmux_get_groups(struct pinctrl_dev *pctldev,
240 unsigned selector, const char * const **groups,
241 unsigned * const num_groups)
243 struct samsung_pinctrl_drv_data *drvdata;
245 drvdata = pinctrl_dev_get_drvdata(pctldev);
246 *groups = drvdata->pmx_functions[selector].groups;
247 *num_groups = drvdata->pmx_functions[selector].num_groups;
252 * given a pin number that is local to a pin controller, find out the pin bank
253 * and the register base of the pin bank.
255 static void pin_to_reg_bank(struct samsung_pinctrl_drv_data *drvdata,
256 unsigned pin, void __iomem **reg, u32 *offset,
257 struct samsung_pin_bank **bank)
259 struct samsung_pin_bank *b;
261 b = drvdata->ctrl->pin_banks;
263 while ((pin >= b->pin_base) &&
264 ((b->pin_base + b->nr_pins - 1) < pin))
267 *reg = drvdata->virt_base + b->pctl_offset;
268 *offset = pin - b->pin_base;
272 /* some banks have two config registers in a single bank */
273 if (*offset * b->func_width > BITS_PER_LONG)
277 /* enable or disable a pinmux function */
278 static void samsung_pinmux_setup(struct pinctrl_dev *pctldev, unsigned selector,
279 unsigned group, bool enable)
281 struct samsung_pinctrl_drv_data *drvdata;
282 const unsigned int *pins;
283 struct samsung_pin_bank *bank;
285 u32 mask, shift, data, pin_offset, cnt;
287 drvdata = pinctrl_dev_get_drvdata(pctldev);
288 pins = drvdata->pin_groups[group].pins;
291 * for each pin in the pin group selected, program the correspoding pin
292 * pin function number in the config register.
294 for (cnt = 0; cnt < drvdata->pin_groups[group].num_pins; cnt++) {
295 pin_to_reg_bank(drvdata, pins[cnt] - drvdata->ctrl->base,
296 ®, &pin_offset, &bank);
297 mask = (1 << bank->func_width) - 1;
298 shift = pin_offset * bank->func_width;
301 data &= ~(mask << shift);
303 data |= drvdata->pin_groups[group].func << shift;
308 /* enable a specified pinmux by writing to registers */
309 static int samsung_pinmux_enable(struct pinctrl_dev *pctldev, unsigned selector,
312 samsung_pinmux_setup(pctldev, selector, group, true);
316 /* disable a specified pinmux by writing to registers */
317 static void samsung_pinmux_disable(struct pinctrl_dev *pctldev,
318 unsigned selector, unsigned group)
320 samsung_pinmux_setup(pctldev, selector, group, false);
324 * The calls to gpio_direction_output() and gpio_direction_input()
325 * leads to this function call (via the pinctrl_gpio_direction_{input|output}()
326 * function called from the gpiolib interface).
328 static int samsung_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
329 struct pinctrl_gpio_range *range, unsigned offset, bool input)
331 struct samsung_pin_bank *bank;
332 struct samsung_pinctrl_drv_data *drvdata;
334 u32 data, pin_offset, mask, shift;
336 drvdata = pinctrl_dev_get_drvdata(pctldev);
338 pin_to_reg_bank(drvdata, offset, ®, &pin_offset, &bank);
339 mask = (1 << bank->func_width) - 1;
340 shift = pin_offset * bank->func_width;
343 data &= ~(mask << shift);
345 data |= FUNC_OUTPUT << shift;
350 /* list of pinmux callbacks for the pinmux vertical in pinctrl core */
351 static struct pinmux_ops samsung_pinmux_ops = {
352 .get_functions_count = samsung_get_functions_count,
353 .get_function_name = samsung_pinmux_get_fname,
354 .get_function_groups = samsung_pinmux_get_groups,
355 .enable = samsung_pinmux_enable,
356 .disable = samsung_pinmux_disable,
357 .gpio_set_direction = samsung_pinmux_gpio_set_direction,
360 /* set or get the pin config settings for a specified pin */
361 static int samsung_pinconf_rw(struct pinctrl_dev *pctldev, unsigned int pin,
362 unsigned long *config, bool set)
364 struct samsung_pinctrl_drv_data *drvdata;
365 struct samsung_pin_bank *bank;
366 void __iomem *reg_base;
367 enum pincfg_type cfg_type = PINCFG_UNPACK_TYPE(*config);
368 u32 data, width, pin_offset, mask, shift;
369 u32 cfg_value, cfg_reg;
371 drvdata = pinctrl_dev_get_drvdata(pctldev);
372 pin_to_reg_bank(drvdata, pin - drvdata->ctrl->base, ®_base,
376 case PINCFG_TYPE_PUD:
377 width = bank->pud_width;
380 case PINCFG_TYPE_DRV:
381 width = bank->drv_width;
384 case PINCFG_TYPE_CON_PDN:
385 width = bank->conpdn_width;
386 cfg_reg = CONPDN_REG;
388 case PINCFG_TYPE_PUD_PDN:
389 width = bank->pudpdn_width;
390 cfg_reg = PUDPDN_REG;
400 mask = (1 << width) - 1;
401 shift = pin_offset * width;
402 data = readl(reg_base + cfg_reg);
405 cfg_value = PINCFG_UNPACK_VALUE(*config);
406 data &= ~(mask << shift);
407 data |= (cfg_value << shift);
408 writel(data, reg_base + cfg_reg);
412 *config = PINCFG_PACK(cfg_type, data);
417 /* set the pin config settings for a specified pin */
418 static int samsung_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
419 unsigned long config)
421 return samsung_pinconf_rw(pctldev, pin, &config, true);
424 /* get the pin config settings for a specified pin */
425 static int samsung_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
426 unsigned long *config)
428 return samsung_pinconf_rw(pctldev, pin, config, false);
431 /* set the pin config settings for a specified pin group */
432 static int samsung_pinconf_group_set(struct pinctrl_dev *pctldev,
433 unsigned group, unsigned long config)
435 struct samsung_pinctrl_drv_data *drvdata;
436 const unsigned int *pins;
439 drvdata = pinctrl_dev_get_drvdata(pctldev);
440 pins = drvdata->pin_groups[group].pins;
442 for (cnt = 0; cnt < drvdata->pin_groups[group].num_pins; cnt++)
443 samsung_pinconf_set(pctldev, pins[cnt], config);
448 /* get the pin config settings for a specified pin group */
449 static int samsung_pinconf_group_get(struct pinctrl_dev *pctldev,
450 unsigned int group, unsigned long *config)
452 struct samsung_pinctrl_drv_data *drvdata;
453 const unsigned int *pins;
455 drvdata = pinctrl_dev_get_drvdata(pctldev);
456 pins = drvdata->pin_groups[group].pins;
457 samsung_pinconf_get(pctldev, pins[0], config);
461 /* list of pinconfig callbacks for pinconfig vertical in the pinctrl code */
462 static struct pinconf_ops samsung_pinconf_ops = {
463 .pin_config_get = samsung_pinconf_get,
464 .pin_config_set = samsung_pinconf_set,
465 .pin_config_group_get = samsung_pinconf_group_get,
466 .pin_config_group_set = samsung_pinconf_group_set,
469 /* gpiolib gpio_set callback function */
470 static void samsung_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
473 u32 pin_offset, data;
474 struct samsung_pinctrl_drv_data *drvdata;
476 drvdata = dev_get_drvdata(gc->dev);
478 pin_to_reg_bank(drvdata, offset, ®, &pin_offset, NULL);
479 data = readl(reg + DAT_REG);
480 data &= ~(1 << pin_offset);
482 data |= 1 << pin_offset;
483 writel(data, reg + DAT_REG);
486 /* gpiolib gpio_get callback function */
487 static int samsung_gpio_get(struct gpio_chip *gc, unsigned offset)
490 u32 pin_offset, data;
491 struct samsung_pinctrl_drv_data *drvdata;
493 drvdata = dev_get_drvdata(gc->dev);
495 pin_to_reg_bank(drvdata, offset, ®, &pin_offset, NULL);
496 data = readl(reg + DAT_REG);
503 * gpiolib gpio_direction_input callback function. The setting of the pin
504 * mux function as 'gpio input' will be handled by the pinctrl susbsystem
507 static int samsung_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
509 return pinctrl_gpio_direction_input(gc->base + offset);
513 * gpiolib gpio_direction_output callback function. The setting of the pin
514 * mux function as 'gpio output' will be handled by the pinctrl susbsystem
517 static int samsung_gpio_direction_output(struct gpio_chip *gc, unsigned offset,
520 samsung_gpio_set(gc, offset, value);
521 return pinctrl_gpio_direction_output(gc->base + offset);
525 * Parse the pin names listed in the 'samsung,pins' property and convert it
526 * into a list of gpio numbers are create a pin group from it.
528 static int __init samsung_pinctrl_parse_dt_pins(struct platform_device *pdev,
529 struct device_node *cfg_np, struct pinctrl_desc *pctl,
530 unsigned int **pin_list, unsigned int *npins)
532 struct device *dev = &pdev->dev;
533 struct property *prop;
534 struct pinctrl_pin_desc const *pdesc = pctl->pins;
535 unsigned int idx = 0, cnt;
536 const char *pin_name;
538 *npins = of_property_count_strings(cfg_np, "samsung,pins");
540 dev_err(dev, "invalid pin list in %s node", cfg_np->name);
544 *pin_list = devm_kzalloc(dev, *npins * sizeof(**pin_list), GFP_KERNEL);
546 dev_err(dev, "failed to allocate memory for pin list\n");
550 of_property_for_each_string(cfg_np, "samsung,pins", prop, pin_name) {
551 for (cnt = 0; cnt < pctl->npins; cnt++) {
552 if (pdesc[cnt].name) {
553 if (!strcmp(pin_name, pdesc[cnt].name)) {
554 (*pin_list)[idx++] = pdesc[cnt].number;
559 if (cnt == pctl->npins) {
560 dev_err(dev, "pin %s not valid in %s node\n",
561 pin_name, cfg_np->name);
562 devm_kfree(dev, *pin_list);
571 * Parse the information about all the available pin groups and pin functions
572 * from device node of the pin-controller. A pin group is formed with all
573 * the pins listed in the "samsung,pins" property.
575 static int __init samsung_pinctrl_parse_dt(struct platform_device *pdev,
576 struct samsung_pinctrl_drv_data *drvdata)
578 struct device *dev = &pdev->dev;
579 struct device_node *dev_np = dev->of_node;
580 struct device_node *cfg_np;
581 struct samsung_pin_group *groups, *grp;
582 struct samsung_pmx_func *functions, *func;
584 unsigned int npins, grp_cnt, func_idx = 0;
588 grp_cnt = of_get_child_count(dev_np);
592 groups = devm_kzalloc(dev, grp_cnt * sizeof(*groups), GFP_KERNEL);
594 dev_err(dev, "failed allocate memory for ping group list\n");
599 functions = devm_kzalloc(dev, grp_cnt * sizeof(*functions), GFP_KERNEL);
601 dev_err(dev, "failed to allocate memory for function list\n");
607 * Iterate over all the child nodes of the pin controller node
608 * and create pin groups and pin function lists.
610 for_each_child_of_node(dev_np, cfg_np) {
612 if (!of_find_property(cfg_np, "samsung,pins", NULL))
615 ret = samsung_pinctrl_parse_dt_pins(pdev, cfg_np,
616 &drvdata->pctl, &pin_list, &npins);
620 /* derive pin group name from the node name */
621 gname = devm_kzalloc(dev, strlen(cfg_np->name) + GSUFFIX_LEN,
624 dev_err(dev, "failed to alloc memory for group name\n");
627 sprintf(gname, "%s%s", cfg_np->name, GROUP_SUFFIX);
630 grp->pins = pin_list;
631 grp->num_pins = npins;
632 of_property_read_u32(cfg_np, "samsung,pin-function", &function);
633 grp->func = function;
636 if (!of_find_property(cfg_np, "samsung,pin-function", NULL))
639 /* derive function name from the node name */
640 fname = devm_kzalloc(dev, strlen(cfg_np->name) + FSUFFIX_LEN,
643 dev_err(dev, "failed to alloc memory for func name\n");
646 sprintf(fname, "%s%s", cfg_np->name, FUNCTION_SUFFIX);
649 func->groups = devm_kzalloc(dev, sizeof(char *), GFP_KERNEL);
651 dev_err(dev, "failed to alloc memory for group list "
655 func->groups[0] = gname;
656 func->num_groups = 1;
661 drvdata->pin_groups = groups;
662 drvdata->nr_groups = grp_cnt;
663 drvdata->pmx_functions = functions;
664 drvdata->nr_functions = func_idx;
669 /* register the pinctrl interface with the pinctrl subsystem */
670 static int __init samsung_pinctrl_register(struct platform_device *pdev,
671 struct samsung_pinctrl_drv_data *drvdata)
673 struct pinctrl_desc *ctrldesc = &drvdata->pctl;
674 struct pinctrl_pin_desc *pindesc, *pdesc;
675 struct samsung_pin_bank *pin_bank;
679 ctrldesc->name = "samsung-pinctrl";
680 ctrldesc->owner = THIS_MODULE;
681 ctrldesc->pctlops = &samsung_pctrl_ops;
682 ctrldesc->pmxops = &samsung_pinmux_ops;
683 ctrldesc->confops = &samsung_pinconf_ops;
685 pindesc = devm_kzalloc(&pdev->dev, sizeof(*pindesc) *
686 drvdata->ctrl->nr_pins, GFP_KERNEL);
688 dev_err(&pdev->dev, "mem alloc for pin descriptors failed\n");
691 ctrldesc->pins = pindesc;
692 ctrldesc->npins = drvdata->ctrl->nr_pins;
693 ctrldesc->npins = drvdata->ctrl->nr_pins;
695 /* dynamically populate the pin number and pin name for pindesc */
696 for (pin = 0, pdesc = pindesc; pin < ctrldesc->npins; pin++, pdesc++)
697 pdesc->number = pin + drvdata->ctrl->base;
700 * allocate space for storing the dynamically generated names for all
701 * the pins which belong to this pin-controller.
703 pin_names = devm_kzalloc(&pdev->dev, sizeof(char) * PIN_NAME_LENGTH *
704 drvdata->ctrl->nr_pins, GFP_KERNEL);
706 dev_err(&pdev->dev, "mem alloc for pin names failed\n");
710 /* for each pin, the name of the pin is pin-bank name + pin number */
711 for (bank = 0; bank < drvdata->ctrl->nr_banks; bank++) {
712 pin_bank = &drvdata->ctrl->pin_banks[bank];
713 for (pin = 0; pin < pin_bank->nr_pins; pin++) {
714 sprintf(pin_names, "%s-%d", pin_bank->name, pin);
715 pdesc = pindesc + pin_bank->pin_base + pin;
716 pdesc->name = pin_names;
717 pin_names += PIN_NAME_LENGTH;
721 drvdata->pctl_dev = pinctrl_register(ctrldesc, &pdev->dev, drvdata);
722 if (!drvdata->pctl_dev) {
723 dev_err(&pdev->dev, "could not register pinctrl driver\n");
727 drvdata->grange.name = "samsung-pctrl-gpio-range";
728 drvdata->grange.id = 0;
729 drvdata->grange.base = drvdata->ctrl->base;
730 drvdata->grange.npins = drvdata->ctrl->nr_pins;
731 drvdata->grange.gc = drvdata->gc;
732 pinctrl_add_gpio_range(drvdata->pctl_dev, &drvdata->grange);
734 ret = samsung_pinctrl_parse_dt(pdev, drvdata);
736 pinctrl_unregister(drvdata->pctl_dev);
743 /* register the gpiolib interface with the gpiolib subsystem */
744 static int __init samsung_gpiolib_register(struct platform_device *pdev,
745 struct samsung_pinctrl_drv_data *drvdata)
747 struct gpio_chip *gc;
750 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
752 dev_err(&pdev->dev, "mem alloc for gpio_chip failed\n");
757 gc->base = drvdata->ctrl->base;
758 gc->ngpio = drvdata->ctrl->nr_pins;
759 gc->dev = &pdev->dev;
760 gc->set = samsung_gpio_set;
761 gc->get = samsung_gpio_get;
762 gc->direction_input = samsung_gpio_direction_input;
763 gc->direction_output = samsung_gpio_direction_output;
764 gc->label = drvdata->ctrl->label;
765 gc->owner = THIS_MODULE;
766 ret = gpiochip_add(gc);
768 dev_err(&pdev->dev, "failed to register gpio_chip %s, error "
769 "code: %d\n", gc->label, ret);
776 /* unregister the gpiolib interface with the gpiolib subsystem */
777 static int __init samsung_gpiolib_unregister(struct platform_device *pdev,
778 struct samsung_pinctrl_drv_data *drvdata)
780 int ret = gpiochip_remove(drvdata->gc);
782 dev_err(&pdev->dev, "gpio chip remove failed\n");
788 static const struct of_device_id samsung_pinctrl_dt_match[];
790 /* retrieve the soc specific data */
791 static struct samsung_pin_ctrl *samsung_pinctrl_get_soc_data(
792 struct platform_device *pdev)
795 const struct of_device_id *match;
796 const struct device_node *node = pdev->dev.of_node;
797 struct samsung_pin_ctrl *ctrl;
798 struct samsung_pin_bank *bank;
801 id = of_alias_get_id(pdev->dev.of_node, "pinctrl");
803 dev_err(&pdev->dev, "failed to get alias id\n");
806 match = of_match_node(samsung_pinctrl_dt_match, node);
807 ctrl = (struct samsung_pin_ctrl *)match->data + id;
809 bank = ctrl->pin_banks;
810 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
811 bank->pin_base = ctrl->nr_pins;
812 ctrl->nr_pins += bank->nr_pins;
813 if (bank->eint_type == EINT_TYPE_GPIO) {
814 bank->irq_base = ctrl->nr_gint;
815 ctrl->nr_gint += bank->nr_pins;
819 ctrl->base = pin_base;
820 pin_base += ctrl->nr_pins;
825 static int __devinit samsung_pinctrl_probe(struct platform_device *pdev)
827 struct samsung_pinctrl_drv_data *drvdata;
828 struct device *dev = &pdev->dev;
829 struct samsung_pin_ctrl *ctrl;
830 struct resource *res;
834 dev_err(dev, "device tree node not found\n");
838 ctrl = samsung_pinctrl_get_soc_data(pdev);
840 dev_err(&pdev->dev, "driver data not available\n");
844 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
846 dev_err(dev, "failed to allocate memory for driver's "
850 drvdata->ctrl = ctrl;
853 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
855 dev_err(dev, "cannot find IO resource\n");
859 drvdata->virt_base = devm_request_and_ioremap(&pdev->dev, res);
860 if (!drvdata->virt_base) {
861 dev_err(dev, "ioremap failed\n");
865 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
867 drvdata->irq = res->start;
869 ret = samsung_gpiolib_register(pdev, drvdata);
873 ret = samsung_pinctrl_register(pdev, drvdata);
875 samsung_gpiolib_unregister(pdev, drvdata);
879 if (ctrl->eint_gpio_init)
880 ctrl->eint_gpio_init(drvdata);
881 if (ctrl->eint_wkup_init)
882 ctrl->eint_wkup_init(drvdata);
884 platform_set_drvdata(pdev, drvdata);
888 static const struct of_device_id samsung_pinctrl_dt_match[] = {
889 { .compatible = "samsung,pinctrl-exynos4210",
890 .data = (void *)exynos4210_pin_ctrl },
893 MODULE_DEVICE_TABLE(of, samsung_pinctrl_dt_match);
895 static struct platform_driver samsung_pinctrl_driver = {
896 .probe = samsung_pinctrl_probe,
898 .name = "samsung-pinctrl",
899 .owner = THIS_MODULE,
900 .of_match_table = of_match_ptr(samsung_pinctrl_dt_match),
904 static int __init samsung_pinctrl_drv_register(void)
906 return platform_driver_register(&samsung_pinctrl_driver);
908 postcore_initcall(samsung_pinctrl_drv_register);
910 static void __exit samsung_pinctrl_drv_unregister(void)
912 platform_driver_unregister(&samsung_pinctrl_driver);
914 module_exit(samsung_pinctrl_drv_unregister);
916 MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com>");
917 MODULE_DESCRIPTION("Samsung pinctrl driver");
918 MODULE_LICENSE("GPL v2");