2 * Generic device tree based pinctrl driver for one register per pin
3 * type pinmux controllers
5 * Copyright (C) 2012 Texas Instruments, Inc.
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
12 #include <linux/init.h>
13 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/slab.h>
17 #include <linux/err.h>
18 #include <linux/list.h>
19 #include <linux/interrupt.h>
20 #include <linux/irqchip/chained_irq.h>
22 #include <linux/of_irq.h>
23 #include <linux/seq_file.h>
25 #include <linux/pinctrl/pinconf-generic.h>
26 #include <linux/pinctrl/pinconf.h>
27 #include <linux/pinctrl/pinctrl.h>
28 #include <linux/pinctrl/pinmux.h>
30 #include <linux/platform_data/pinctrl-single.h>
33 #include "devicetree.h"
37 #define DRIVER_NAME "pinctrl-single"
38 #define PCS_OFF_DISABLED ~0U
41 * struct pcs_func_vals - mux function register offset and value pair
42 * @reg: register virtual address
43 * @val: register value
46 struct pcs_func_vals {
53 * struct pcs_conf_vals - pinconf parameter, pinconf register offset
54 * and value, enable, disable, mask
55 * @param: config parameter
56 * @val: user input bits in the pinconf register
57 * @enable: enable bits in the pinconf register
58 * @disable: disable bits in the pinconf register
59 * @mask: mask bits in the register value
61 struct pcs_conf_vals {
62 enum pin_config_param param;
70 * struct pcs_conf_type - pinconf property name, pinconf param pair
71 * @name: property name in DTS file
72 * @param: config parameter
74 struct pcs_conf_type {
76 enum pin_config_param param;
80 * struct pcs_function - pinctrl function
81 * @name: pinctrl function name
82 * @vals: register and vals array
83 * @nvals: number of entries in vals array
84 * @pgnames: array of pingroup names the function uses
85 * @npgnames: number of pingroup names the function uses
86 * @conf: array of pin configurations
87 * @nconfs: number of pin configurations available
92 struct pcs_func_vals *vals;
96 struct pcs_conf_vals *conf;
98 struct list_head node;
102 * struct pcs_gpiofunc_range - pin ranges with same mux value of gpio function
103 * @offset: offset base of pins
104 * @npins: number pins with the same mux value of gpio function
105 * @gpiofunc: mux value of gpio function
108 struct pcs_gpiofunc_range {
112 struct list_head node;
116 * struct pcs_data - wrapper for data needed by pinctrl framework
118 * @cur: index to current element
120 * REVISIT: We should be able to drop this eventually by adding
121 * support for registering pins individually in the pinctrl
122 * framework for those drivers that don't need a static array.
125 struct pinctrl_pin_desc *pa;
130 * struct pcs_soc_data - SoC specific settings
131 * @flags: initial SoC specific PCS_FEAT_xxx values
132 * @irq: optional interrupt for the controller
133 * @irq_enable_mask: optional SoC specific interrupt enable mask
134 * @irq_status_mask: optional SoC specific interrupt status mask
135 * @rearm: optional SoC specific wake-up rearm function
137 struct pcs_soc_data {
140 unsigned irq_enable_mask;
141 unsigned irq_status_mask;
146 * struct pcs_device - pinctrl device instance
148 * @base: virtual address of the controller
149 * @saved_vals: saved values for the controller
150 * @size: size of the ioremapped area
152 * @np: device tree node
153 * @pctl: pin controller device
154 * @flags: mask of PCS_FEAT_xxx values
155 * @missing_nr_pinctrl_cells: for legacy binding, may go away
156 * @socdata: soc specific data
157 * @lock: spinlock for register access
158 * @mutex: mutex protecting the lists
159 * @width: bits per mux register
160 * @fmask: function register mask
161 * @fshift: function register shift
162 * @foff: value to turn mux off
163 * @fmax: max number of functions in fmask
164 * @bits_per_mux: number of bits per mux
165 * @bits_per_pin: number of bits per pin
166 * @pins: physical pins on the SoC
167 * @gpiofuncs: list of gpio functions
168 * @irqs: list of interrupt registers
169 * @chip: chip container for this instance
170 * @domain: IRQ domain for this instance
171 * @desc: pin controller descriptor
172 * @read: register read function to use
173 * @write: register write function to use
176 struct resource *res;
181 struct device_node *np;
182 struct pinctrl_dev *pctl;
184 #define PCS_CONTEXT_LOSS_OFF (1 << 3)
185 #define PCS_QUIRK_SHARED_IRQ (1 << 2)
186 #define PCS_FEAT_IRQ (1 << 1)
187 #define PCS_FEAT_PINCONF (1 << 0)
188 struct property *missing_nr_pinctrl_cells;
189 struct pcs_soc_data socdata;
198 unsigned bits_per_pin;
199 struct pcs_data pins;
200 struct list_head gpiofuncs;
201 struct list_head irqs;
202 struct irq_chip chip;
203 struct irq_domain *domain;
204 struct pinctrl_desc desc;
205 unsigned (*read)(void __iomem *reg);
206 void (*write)(unsigned val, void __iomem *reg);
209 #define PCS_QUIRK_HAS_SHARED_IRQ (pcs->flags & PCS_QUIRK_SHARED_IRQ)
210 #define PCS_HAS_IRQ (pcs->flags & PCS_FEAT_IRQ)
211 #define PCS_HAS_PINCONF (pcs->flags & PCS_FEAT_PINCONF)
213 static int pcs_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin,
214 unsigned long *config);
215 static int pcs_pinconf_set(struct pinctrl_dev *pctldev, unsigned pin,
216 unsigned long *configs, unsigned num_configs);
218 static enum pin_config_param pcs_bias[] = {
219 PIN_CONFIG_BIAS_PULL_DOWN,
220 PIN_CONFIG_BIAS_PULL_UP,
224 * This lock class tells lockdep that irqchip core that this single
225 * pinctrl can be in a different category than its parents, so it won't
226 * report false recursion.
228 static struct lock_class_key pcs_lock_class;
230 /* Class for the IRQ request mutex */
231 static struct lock_class_key pcs_request_class;
234 * REVISIT: Reads and writes could eventually use regmap or something
235 * generic. But at least on omaps, some mux registers are performance
236 * critical as they may need to be remuxed every time before and after
237 * idle. Adding tests for register access width for every read and
238 * write like regmap is doing is not desired, and caching the registers
239 * does not help in this case.
242 static unsigned __maybe_unused pcs_readb(void __iomem *reg)
247 static unsigned __maybe_unused pcs_readw(void __iomem *reg)
252 static unsigned __maybe_unused pcs_readl(void __iomem *reg)
257 static void __maybe_unused pcs_writeb(unsigned val, void __iomem *reg)
262 static void __maybe_unused pcs_writew(unsigned val, void __iomem *reg)
267 static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg)
272 static unsigned int pcs_pin_reg_offset_get(struct pcs_device *pcs,
275 unsigned int mux_bytes = pcs->width / BITS_PER_BYTE;
277 if (pcs->bits_per_mux) {
278 unsigned int pin_offset_bytes;
280 pin_offset_bytes = (pcs->bits_per_pin * pin) / BITS_PER_BYTE;
281 return (pin_offset_bytes / mux_bytes) * mux_bytes;
284 return pin * mux_bytes;
287 static unsigned int pcs_pin_shift_reg_get(struct pcs_device *pcs,
290 return (pin % (pcs->width / pcs->bits_per_pin)) * pcs->bits_per_pin;
293 static void pcs_pin_dbg_show(struct pinctrl_dev *pctldev,
297 struct pcs_device *pcs;
299 unsigned long offset;
302 pcs = pinctrl_dev_get_drvdata(pctldev);
304 offset = pcs_pin_reg_offset_get(pcs, pin);
305 val = pcs->read(pcs->base + offset);
307 if (pcs->bits_per_mux)
308 val &= pcs->fmask << pcs_pin_shift_reg_get(pcs, pin);
310 pa = pcs->res->start + offset;
312 seq_printf(s, "%zx %08x %s ", pa, val, DRIVER_NAME);
315 static void pcs_dt_free_map(struct pinctrl_dev *pctldev,
316 struct pinctrl_map *map, unsigned num_maps)
318 struct pcs_device *pcs;
320 pcs = pinctrl_dev_get_drvdata(pctldev);
321 devm_kfree(pcs->dev, map);
324 static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev,
325 struct device_node *np_config,
326 struct pinctrl_map **map, unsigned *num_maps);
328 static const struct pinctrl_ops pcs_pinctrl_ops = {
329 .get_groups_count = pinctrl_generic_get_group_count,
330 .get_group_name = pinctrl_generic_get_group_name,
331 .get_group_pins = pinctrl_generic_get_group_pins,
332 .pin_dbg_show = pcs_pin_dbg_show,
333 .dt_node_to_map = pcs_dt_node_to_map,
334 .dt_free_map = pcs_dt_free_map,
337 static int pcs_get_function(struct pinctrl_dev *pctldev, unsigned pin,
338 struct pcs_function **func)
340 struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev);
341 struct pin_desc *pdesc = pin_desc_get(pctldev, pin);
342 const struct pinctrl_setting_mux *setting;
343 struct function_desc *function;
346 /* If pin is not described in DTS & enabled, mux_setting is NULL. */
347 setting = pdesc->mux_setting;
350 fselector = setting->func;
351 function = pinmux_generic_get_function(pctldev, fselector);
352 *func = function->data;
354 dev_err(pcs->dev, "%s could not find function%i\n",
355 __func__, fselector);
361 static int pcs_set_mux(struct pinctrl_dev *pctldev, unsigned fselector,
364 struct pcs_device *pcs;
365 struct function_desc *function;
366 struct pcs_function *func;
369 pcs = pinctrl_dev_get_drvdata(pctldev);
370 /* If function mask is null, needn't enable it. */
373 function = pinmux_generic_get_function(pctldev, fselector);
376 func = function->data;
380 dev_dbg(pcs->dev, "enabling %s function%i\n",
381 func->name, fselector);
383 for (i = 0; i < func->nvals; i++) {
384 struct pcs_func_vals *vals;
388 vals = &func->vals[i];
389 raw_spin_lock_irqsave(&pcs->lock, flags);
390 val = pcs->read(vals->reg);
392 if (pcs->bits_per_mux)
398 val |= (vals->val & mask);
399 pcs->write(val, vals->reg);
400 raw_spin_unlock_irqrestore(&pcs->lock, flags);
406 static int pcs_request_gpio(struct pinctrl_dev *pctldev,
407 struct pinctrl_gpio_range *range, unsigned pin)
409 struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev);
410 struct pcs_gpiofunc_range *frange = NULL;
411 struct list_head *pos, *tmp;
414 /* If function mask is null, return directly. */
418 list_for_each_safe(pos, tmp, &pcs->gpiofuncs) {
421 frange = list_entry(pos, struct pcs_gpiofunc_range, node);
422 if (pin >= frange->offset + frange->npins
423 || pin < frange->offset)
426 offset = pcs_pin_reg_offset_get(pcs, pin);
428 if (pcs->bits_per_mux) {
429 int pin_shift = pcs_pin_shift_reg_get(pcs, pin);
431 data = pcs->read(pcs->base + offset);
432 data &= ~(pcs->fmask << pin_shift);
433 data |= frange->gpiofunc << pin_shift;
434 pcs->write(data, pcs->base + offset);
436 data = pcs->read(pcs->base + offset);
438 data |= frange->gpiofunc;
439 pcs->write(data, pcs->base + offset);
446 static const struct pinmux_ops pcs_pinmux_ops = {
447 .get_functions_count = pinmux_generic_get_function_count,
448 .get_function_name = pinmux_generic_get_function_name,
449 .get_function_groups = pinmux_generic_get_function_groups,
450 .set_mux = pcs_set_mux,
451 .gpio_request_enable = pcs_request_gpio,
454 /* Clear BIAS value */
455 static void pcs_pinconf_clear_bias(struct pinctrl_dev *pctldev, unsigned pin)
457 unsigned long config;
459 for (i = 0; i < ARRAY_SIZE(pcs_bias); i++) {
460 config = pinconf_to_config_packed(pcs_bias[i], 0);
461 pcs_pinconf_set(pctldev, pin, &config, 1);
466 * Check whether PIN_CONFIG_BIAS_DISABLE is valid.
467 * It's depend on that PULL_DOWN & PULL_UP configs are all invalid.
469 static bool pcs_pinconf_bias_disable(struct pinctrl_dev *pctldev, unsigned pin)
471 unsigned long config;
474 for (i = 0; i < ARRAY_SIZE(pcs_bias); i++) {
475 config = pinconf_to_config_packed(pcs_bias[i], 0);
476 if (!pcs_pinconf_get(pctldev, pin, &config))
484 static int pcs_pinconf_get(struct pinctrl_dev *pctldev,
485 unsigned pin, unsigned long *config)
487 struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev);
488 struct pcs_function *func;
489 enum pin_config_param param;
490 unsigned offset = 0, data = 0, i, j, ret;
492 ret = pcs_get_function(pctldev, pin, &func);
496 for (i = 0; i < func->nconfs; i++) {
497 param = pinconf_to_config_param(*config);
498 if (param == PIN_CONFIG_BIAS_DISABLE) {
499 if (pcs_pinconf_bias_disable(pctldev, pin)) {
505 } else if (param != func->conf[i].param) {
509 offset = pin * (pcs->width / BITS_PER_BYTE);
510 data = pcs->read(pcs->base + offset) & func->conf[i].mask;
511 switch (func->conf[i].param) {
513 case PIN_CONFIG_BIAS_PULL_DOWN:
514 case PIN_CONFIG_BIAS_PULL_UP:
515 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
516 if ((data != func->conf[i].enable) ||
517 (data == func->conf[i].disable))
522 case PIN_CONFIG_INPUT_SCHMITT:
523 for (j = 0; j < func->nconfs; j++) {
524 switch (func->conf[j].param) {
525 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
526 if (data != func->conf[j].enable)
535 case PIN_CONFIG_DRIVE_STRENGTH:
536 case PIN_CONFIG_SLEW_RATE:
537 case PIN_CONFIG_MODE_LOW_POWER:
538 case PIN_CONFIG_INPUT_ENABLE:
548 static int pcs_pinconf_set(struct pinctrl_dev *pctldev,
549 unsigned pin, unsigned long *configs,
550 unsigned num_configs)
552 struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev);
553 struct pcs_function *func;
554 unsigned offset = 0, shift = 0, i, data, ret;
558 ret = pcs_get_function(pctldev, pin, &func);
562 for (j = 0; j < num_configs; j++) {
563 for (i = 0; i < func->nconfs; i++) {
564 if (pinconf_to_config_param(configs[j])
565 != func->conf[i].param)
568 offset = pin * (pcs->width / BITS_PER_BYTE);
569 data = pcs->read(pcs->base + offset);
570 arg = pinconf_to_config_argument(configs[j]);
571 switch (func->conf[i].param) {
573 case PIN_CONFIG_INPUT_SCHMITT:
574 case PIN_CONFIG_DRIVE_STRENGTH:
575 case PIN_CONFIG_SLEW_RATE:
576 case PIN_CONFIG_MODE_LOW_POWER:
577 case PIN_CONFIG_INPUT_ENABLE:
578 shift = ffs(func->conf[i].mask) - 1;
579 data &= ~func->conf[i].mask;
580 data |= (arg << shift) & func->conf[i].mask;
583 case PIN_CONFIG_BIAS_DISABLE:
584 pcs_pinconf_clear_bias(pctldev, pin);
586 case PIN_CONFIG_BIAS_PULL_DOWN:
587 case PIN_CONFIG_BIAS_PULL_UP:
589 pcs_pinconf_clear_bias(pctldev, pin);
591 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
592 data &= ~func->conf[i].mask;
594 data |= func->conf[i].enable;
596 data |= func->conf[i].disable;
601 pcs->write(data, pcs->base + offset);
605 if (i >= func->nconfs)
607 } /* for each config */
612 static int pcs_pinconf_group_get(struct pinctrl_dev *pctldev,
613 unsigned group, unsigned long *config)
615 const unsigned *pins;
616 unsigned npins, old = 0;
619 ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins);
622 for (i = 0; i < npins; i++) {
623 if (pcs_pinconf_get(pctldev, pins[i], config))
625 /* configs do not match between two pins */
626 if (i && (old != *config))
633 static int pcs_pinconf_group_set(struct pinctrl_dev *pctldev,
634 unsigned group, unsigned long *configs,
635 unsigned num_configs)
637 const unsigned *pins;
641 ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins);
644 for (i = 0; i < npins; i++) {
645 if (pcs_pinconf_set(pctldev, pins[i], configs, num_configs))
651 static void pcs_pinconf_dbg_show(struct pinctrl_dev *pctldev,
652 struct seq_file *s, unsigned pin)
656 static void pcs_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
657 struct seq_file *s, unsigned selector)
661 static void pcs_pinconf_config_dbg_show(struct pinctrl_dev *pctldev,
663 unsigned long config)
665 pinconf_generic_dump_config(pctldev, s, config);
668 static const struct pinconf_ops pcs_pinconf_ops = {
669 .pin_config_get = pcs_pinconf_get,
670 .pin_config_set = pcs_pinconf_set,
671 .pin_config_group_get = pcs_pinconf_group_get,
672 .pin_config_group_set = pcs_pinconf_group_set,
673 .pin_config_dbg_show = pcs_pinconf_dbg_show,
674 .pin_config_group_dbg_show = pcs_pinconf_group_dbg_show,
675 .pin_config_config_dbg_show = pcs_pinconf_config_dbg_show,
680 * pcs_add_pin() - add a pin to the static per controller pin array
681 * @pcs: pcs driver instance
682 * @offset: register offset from base
684 static int pcs_add_pin(struct pcs_device *pcs, unsigned int offset)
686 struct pcs_soc_data *pcs_soc = &pcs->socdata;
687 struct pinctrl_pin_desc *pin;
691 if (i >= pcs->desc.npins) {
692 dev_err(pcs->dev, "too many pins, max %i\n",
697 if (pcs_soc->irq_enable_mask) {
700 val = pcs->read(pcs->base + offset);
701 if (val & pcs_soc->irq_enable_mask) {
702 dev_dbg(pcs->dev, "irq enabled at boot for pin at %lx (%x), clearing\n",
703 (unsigned long)pcs->res->start + offset, val);
704 val &= ~pcs_soc->irq_enable_mask;
705 pcs->write(val, pcs->base + offset);
709 pin = &pcs->pins.pa[i];
717 * pcs_allocate_pin_table() - adds all the pins for the pinctrl driver
718 * @pcs: pcs driver instance
720 * In case of errors, resources are freed in pcs_free_resources.
722 * If your hardware needs holes in the address space, then just set
723 * up multiple driver instances.
725 static int pcs_allocate_pin_table(struct pcs_device *pcs)
727 int mux_bytes, nr_pins, i;
729 mux_bytes = pcs->width / BITS_PER_BYTE;
731 if (pcs->bits_per_mux && pcs->fmask) {
732 pcs->bits_per_pin = fls(pcs->fmask);
733 nr_pins = (pcs->size * BITS_PER_BYTE) / pcs->bits_per_pin;
735 nr_pins = pcs->size / mux_bytes;
738 dev_dbg(pcs->dev, "allocating %i pins\n", nr_pins);
739 pcs->pins.pa = devm_kcalloc(pcs->dev,
740 nr_pins, sizeof(*pcs->pins.pa),
745 pcs->desc.pins = pcs->pins.pa;
746 pcs->desc.npins = nr_pins;
748 for (i = 0; i < pcs->desc.npins; i++) {
752 offset = pcs_pin_reg_offset_get(pcs, i);
753 res = pcs_add_pin(pcs, offset);
755 dev_err(pcs->dev, "error adding pins: %i\n", res);
764 * pcs_add_function() - adds a new function to the function list
765 * @pcs: pcs driver instance
766 * @fcn: new function allocated
767 * @name: name of the function
768 * @vals: array of mux register value pairs used by the function
769 * @nvals: number of mux register value pairs
770 * @pgnames: array of pingroup names for the function
771 * @npgnames: number of pingroup names
773 * Caller must take care of locking.
775 static int pcs_add_function(struct pcs_device *pcs,
776 struct pcs_function **fcn,
778 struct pcs_func_vals *vals,
780 const char **pgnames,
781 unsigned int npgnames)
783 struct pcs_function *function;
786 function = devm_kzalloc(pcs->dev, sizeof(*function), GFP_KERNEL);
790 function->vals = vals;
791 function->nvals = nvals;
792 function->name = name;
794 selector = pinmux_generic_add_function(pcs->pctl, name,
798 devm_kfree(pcs->dev, function);
808 * pcs_get_pin_by_offset() - get a pin index based on the register offset
809 * @pcs: pcs driver instance
810 * @offset: register offset from the base
812 * Note that this is OK as long as the pins are in a static array.
814 static int pcs_get_pin_by_offset(struct pcs_device *pcs, unsigned offset)
818 if (offset >= pcs->size) {
819 dev_err(pcs->dev, "mux offset out of range: 0x%x (0x%x)\n",
824 if (pcs->bits_per_mux)
825 index = (offset * BITS_PER_BYTE) / pcs->bits_per_pin;
827 index = offset / (pcs->width / BITS_PER_BYTE);
833 * check whether data matches enable bits or disable bits
834 * Return value: 1 for matching enable bits, 0 for matching disable bits,
835 * and negative value for matching failure.
837 static int pcs_config_match(unsigned data, unsigned enable, unsigned disable)
843 else if (data == disable)
848 static void add_config(struct pcs_conf_vals **conf, enum pin_config_param param,
849 unsigned value, unsigned enable, unsigned disable,
852 (*conf)->param = param;
853 (*conf)->val = value;
854 (*conf)->enable = enable;
855 (*conf)->disable = disable;
856 (*conf)->mask = mask;
860 static void add_setting(unsigned long **setting, enum pin_config_param param,
863 **setting = pinconf_to_config_packed(param, arg);
867 /* add pinconf setting with 2 parameters */
868 static void pcs_add_conf2(struct pcs_device *pcs, struct device_node *np,
869 const char *name, enum pin_config_param param,
870 struct pcs_conf_vals **conf, unsigned long **settings)
872 unsigned value[2], shift;
875 ret = of_property_read_u32_array(np, name, value, 2);
878 /* set value & mask */
879 value[0] &= value[1];
880 shift = ffs(value[1]) - 1;
881 /* skip enable & disable */
882 add_config(conf, param, value[0], 0, 0, value[1]);
883 add_setting(settings, param, value[0] >> shift);
886 /* add pinconf setting with 4 parameters */
887 static void pcs_add_conf4(struct pcs_device *pcs, struct device_node *np,
888 const char *name, enum pin_config_param param,
889 struct pcs_conf_vals **conf, unsigned long **settings)
894 /* value to set, enable, disable, mask */
895 ret = of_property_read_u32_array(np, name, value, 4);
899 dev_err(pcs->dev, "mask field of the property can't be 0\n");
902 value[0] &= value[3];
903 value[1] &= value[3];
904 value[2] &= value[3];
905 ret = pcs_config_match(value[0], value[1], value[2]);
907 dev_dbg(pcs->dev, "failed to match enable or disable bits\n");
908 add_config(conf, param, value[0], value[1], value[2], value[3]);
909 add_setting(settings, param, ret);
912 static int pcs_parse_pinconf(struct pcs_device *pcs, struct device_node *np,
913 struct pcs_function *func,
914 struct pinctrl_map **map)
917 struct pinctrl_map *m = *map;
918 int i = 0, nconfs = 0;
919 unsigned long *settings = NULL, *s = NULL;
920 struct pcs_conf_vals *conf = NULL;
921 static const struct pcs_conf_type prop2[] = {
922 { "pinctrl-single,drive-strength", PIN_CONFIG_DRIVE_STRENGTH, },
923 { "pinctrl-single,slew-rate", PIN_CONFIG_SLEW_RATE, },
924 { "pinctrl-single,input-enable", PIN_CONFIG_INPUT_ENABLE, },
925 { "pinctrl-single,input-schmitt", PIN_CONFIG_INPUT_SCHMITT, },
926 { "pinctrl-single,low-power-mode", PIN_CONFIG_MODE_LOW_POWER, },
928 static const struct pcs_conf_type prop4[] = {
929 { "pinctrl-single,bias-pullup", PIN_CONFIG_BIAS_PULL_UP, },
930 { "pinctrl-single,bias-pulldown", PIN_CONFIG_BIAS_PULL_DOWN, },
931 { "pinctrl-single,input-schmitt-enable",
932 PIN_CONFIG_INPUT_SCHMITT_ENABLE, },
935 /* If pinconf isn't supported, don't parse properties in below. */
936 if (!PCS_HAS_PINCONF)
939 /* cacluate how much properties are supported in current node */
940 for (i = 0; i < ARRAY_SIZE(prop2); i++) {
941 if (of_property_present(np, prop2[i].name))
944 for (i = 0; i < ARRAY_SIZE(prop4); i++) {
945 if (of_property_present(np, prop4[i].name))
951 func->conf = devm_kcalloc(pcs->dev,
952 nconfs, sizeof(struct pcs_conf_vals),
956 func->nconfs = nconfs;
957 conf = &(func->conf[0]);
959 settings = devm_kcalloc(pcs->dev, nconfs, sizeof(unsigned long),
965 for (i = 0; i < ARRAY_SIZE(prop2); i++)
966 pcs_add_conf2(pcs, np, prop2[i].name, prop2[i].param,
968 for (i = 0; i < ARRAY_SIZE(prop4); i++)
969 pcs_add_conf4(pcs, np, prop4[i].name, prop4[i].param,
971 m->type = PIN_MAP_TYPE_CONFIGS_GROUP;
972 m->data.configs.group_or_pin = np->name;
973 m->data.configs.configs = settings;
974 m->data.configs.num_configs = nconfs;
979 * pcs_parse_one_pinctrl_entry() - parses a device tree mux entry
980 * @pcs: pinctrl driver instance
981 * @np: device node of the mux entry
983 * @num_maps: number of map
984 * @pgnames: pingroup names
986 * Note that this binding currently supports only sets of one register + value.
988 * Also note that this driver tries to avoid understanding pin and function
989 * names because of the extra bloat they would cause especially in the case of
990 * a large number of pins. This driver just sets what is specified for the board
991 * in the .dts file. Further user space debugging tools can be developed to
992 * decipher the pin and function names using debugfs.
994 * If you are concerned about the boot time, set up the static pins in
995 * the bootloader, and only set up selected pins as device tree entries.
997 static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
998 struct device_node *np,
999 struct pinctrl_map **map,
1001 const char **pgnames)
1003 const char *name = "pinctrl-single,pins";
1004 struct pcs_func_vals *vals;
1005 int rows, *pins, found = 0, res = -ENOMEM, i, fsel, gsel;
1006 struct pcs_function *function = NULL;
1008 rows = pinctrl_count_index_with_args(np, name);
1010 dev_err(pcs->dev, "Invalid number of rows: %d\n", rows);
1014 vals = devm_kcalloc(pcs->dev, rows, sizeof(*vals), GFP_KERNEL);
1018 pins = devm_kcalloc(pcs->dev, rows, sizeof(*pins), GFP_KERNEL);
1022 for (i = 0; i < rows; i++) {
1023 struct of_phandle_args pinctrl_spec;
1024 unsigned int offset;
1027 res = pinctrl_parse_index_with_args(np, name, i, &pinctrl_spec);
1031 if (pinctrl_spec.args_count < 2 || pinctrl_spec.args_count > 3) {
1032 dev_err(pcs->dev, "invalid args_count for spec: %i\n",
1033 pinctrl_spec.args_count);
1037 offset = pinctrl_spec.args[0];
1038 vals[found].reg = pcs->base + offset;
1040 switch (pinctrl_spec.args_count) {
1042 vals[found].val = pinctrl_spec.args[1];
1045 vals[found].val = (pinctrl_spec.args[1] | pinctrl_spec.args[2]);
1049 dev_dbg(pcs->dev, "%pOFn index: 0x%x value: 0x%x\n",
1050 pinctrl_spec.np, offset, vals[found].val);
1052 pin = pcs_get_pin_by_offset(pcs, offset);
1055 "could not add functions for %pOFn %ux\n",
1059 pins[found++] = pin;
1062 pgnames[0] = np->name;
1063 mutex_lock(&pcs->mutex);
1064 fsel = pcs_add_function(pcs, &function, np->name, vals, found,
1071 gsel = pinctrl_generic_add_group(pcs->pctl, np->name, pins, found, pcs);
1077 (*map)->type = PIN_MAP_TYPE_MUX_GROUP;
1078 (*map)->data.mux.group = np->name;
1079 (*map)->data.mux.function = np->name;
1081 if (PCS_HAS_PINCONF && function) {
1082 res = pcs_parse_pinconf(pcs, np, function, map);
1085 else if (res == -ENOTSUPP)
1088 goto free_pingroups;
1092 mutex_unlock(&pcs->mutex);
1097 pinctrl_generic_remove_group(pcs->pctl, gsel);
1100 pinmux_generic_remove_function(pcs->pctl, fsel);
1102 mutex_unlock(&pcs->mutex);
1103 devm_kfree(pcs->dev, pins);
1106 devm_kfree(pcs->dev, vals);
1111 static int pcs_parse_bits_in_pinctrl_entry(struct pcs_device *pcs,
1112 struct device_node *np,
1113 struct pinctrl_map **map,
1115 const char **pgnames)
1117 const char *name = "pinctrl-single,bits";
1118 struct pcs_func_vals *vals;
1119 int rows, *pins, found = 0, res = -ENOMEM, i, fsel;
1121 struct pcs_function *function = NULL;
1123 rows = pinctrl_count_index_with_args(np, name);
1125 dev_err(pcs->dev, "Invalid number of rows: %d\n", rows);
1129 if (PCS_HAS_PINCONF) {
1130 dev_err(pcs->dev, "pinconf not supported\n");
1134 npins_in_row = pcs->width / pcs->bits_per_pin;
1136 vals = devm_kzalloc(pcs->dev,
1137 array3_size(rows, npins_in_row, sizeof(*vals)),
1142 pins = devm_kzalloc(pcs->dev,
1143 array3_size(rows, npins_in_row, sizeof(*pins)),
1148 for (i = 0; i < rows; i++) {
1149 struct of_phandle_args pinctrl_spec;
1150 unsigned offset, val;
1151 unsigned mask, bit_pos, val_pos, mask_pos, submask;
1152 unsigned pin_num_from_lsb;
1155 res = pinctrl_parse_index_with_args(np, name, i, &pinctrl_spec);
1159 if (pinctrl_spec.args_count < 3) {
1160 dev_err(pcs->dev, "invalid args_count for spec: %i\n",
1161 pinctrl_spec.args_count);
1165 /* Index plus two value cells */
1166 offset = pinctrl_spec.args[0];
1167 val = pinctrl_spec.args[1];
1168 mask = pinctrl_spec.args[2];
1170 dev_dbg(pcs->dev, "%pOFn index: 0x%x value: 0x%x mask: 0x%x\n",
1171 pinctrl_spec.np, offset, val, mask);
1173 /* Parse pins in each row from LSB */
1175 bit_pos = __ffs(mask);
1176 pin_num_from_lsb = bit_pos / pcs->bits_per_pin;
1177 mask_pos = ((pcs->fmask) << bit_pos);
1178 val_pos = val & mask_pos;
1179 submask = mask & mask_pos;
1181 if ((mask & mask_pos) == 0) {
1183 "Invalid mask for %pOFn at 0x%x\n",
1190 if (submask != mask_pos) {
1192 "Invalid submask 0x%x for %pOFn at 0x%x\n",
1193 submask, np, offset);
1197 vals[found].mask = submask;
1198 vals[found].reg = pcs->base + offset;
1199 vals[found].val = val_pos;
1201 pin = pcs_get_pin_by_offset(pcs, offset);
1204 "could not add functions for %pOFn %ux\n",
1208 pins[found++] = pin + pin_num_from_lsb;
1212 pgnames[0] = np->name;
1213 mutex_lock(&pcs->mutex);
1214 fsel = pcs_add_function(pcs, &function, np->name, vals, found,
1221 res = pinctrl_generic_add_group(pcs->pctl, np->name, pins, found, pcs);
1225 (*map)->type = PIN_MAP_TYPE_MUX_GROUP;
1226 (*map)->data.mux.group = np->name;
1227 (*map)->data.mux.function = np->name;
1230 mutex_unlock(&pcs->mutex);
1235 pinmux_generic_remove_function(pcs->pctl, fsel);
1237 mutex_unlock(&pcs->mutex);
1238 devm_kfree(pcs->dev, pins);
1241 devm_kfree(pcs->dev, vals);
1246 * pcs_dt_node_to_map() - allocates and parses pinctrl maps
1247 * @pctldev: pinctrl instance
1248 * @np_config: device tree pinmux entry
1249 * @map: array of map entries
1250 * @num_maps: number of maps
1252 static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev,
1253 struct device_node *np_config,
1254 struct pinctrl_map **map, unsigned *num_maps)
1256 struct pcs_device *pcs;
1257 const char **pgnames;
1260 pcs = pinctrl_dev_get_drvdata(pctldev);
1262 /* create 2 maps. One is for pinmux, and the other is for pinconf. */
1263 *map = devm_kcalloc(pcs->dev, 2, sizeof(**map), GFP_KERNEL);
1269 pgnames = devm_kzalloc(pcs->dev, sizeof(*pgnames), GFP_KERNEL);
1275 if (pcs->bits_per_mux) {
1276 ret = pcs_parse_bits_in_pinctrl_entry(pcs, np_config, map,
1279 dev_err(pcs->dev, "no pins entries for %pOFn\n",
1284 ret = pcs_parse_one_pinctrl_entry(pcs, np_config, map,
1287 dev_err(pcs->dev, "no pins entries for %pOFn\n",
1296 devm_kfree(pcs->dev, pgnames);
1298 devm_kfree(pcs->dev, *map);
1304 * pcs_irq_free() - free interrupt
1305 * @pcs: pcs driver instance
1307 static void pcs_irq_free(struct pcs_device *pcs)
1309 struct pcs_soc_data *pcs_soc = &pcs->socdata;
1311 if (pcs_soc->irq < 0)
1315 irq_domain_remove(pcs->domain);
1317 if (PCS_QUIRK_HAS_SHARED_IRQ)
1318 free_irq(pcs_soc->irq, pcs_soc);
1320 irq_set_chained_handler(pcs_soc->irq, NULL);
1324 * pcs_free_resources() - free memory used by this driver
1325 * @pcs: pcs driver instance
1327 static void pcs_free_resources(struct pcs_device *pcs)
1330 pinctrl_unregister(pcs->pctl);
1332 #if IS_BUILTIN(CONFIG_PINCTRL_SINGLE)
1333 if (pcs->missing_nr_pinctrl_cells)
1334 of_remove_property(pcs->np, pcs->missing_nr_pinctrl_cells);
1338 static int pcs_add_gpio_func(struct device_node *node, struct pcs_device *pcs)
1340 const char *propname = "pinctrl-single,gpio-range";
1341 const char *cellname = "#pinctrl-single,gpio-range-cells";
1342 struct of_phandle_args gpiospec;
1343 struct pcs_gpiofunc_range *range;
1346 for (i = 0; ; i++) {
1347 ret = of_parse_phandle_with_args(node, propname, cellname,
1349 /* Do not treat it as error. Only treat it as end condition. */
1354 range = devm_kzalloc(pcs->dev, sizeof(*range), GFP_KERNEL);
1359 range->offset = gpiospec.args[0];
1360 range->npins = gpiospec.args[1];
1361 range->gpiofunc = gpiospec.args[2];
1362 mutex_lock(&pcs->mutex);
1363 list_add_tail(&range->node, &pcs->gpiofuncs);
1364 mutex_unlock(&pcs->mutex);
1370 * struct pcs_interrupt
1371 * @reg: virtual address of interrupt register
1372 * @hwirq: hardware irq number
1373 * @irq: virtual irq number
1376 struct pcs_interrupt {
1378 irq_hw_number_t hwirq;
1380 struct list_head node;
1384 * pcs_irq_set() - enables or disables an interrupt
1385 * @pcs_soc: SoC specific settings
1387 * @enable: enable or disable the interrupt
1389 * Note that this currently assumes one interrupt per pinctrl
1390 * register that is typically used for wake-up events.
1392 static inline void pcs_irq_set(struct pcs_soc_data *pcs_soc,
1393 int irq, const bool enable)
1395 struct pcs_device *pcs;
1396 struct list_head *pos;
1399 pcs = container_of(pcs_soc, struct pcs_device, socdata);
1400 list_for_each(pos, &pcs->irqs) {
1401 struct pcs_interrupt *pcswi;
1404 pcswi = list_entry(pos, struct pcs_interrupt, node);
1405 if (irq != pcswi->irq)
1408 soc_mask = pcs_soc->irq_enable_mask;
1409 raw_spin_lock(&pcs->lock);
1410 mask = pcs->read(pcswi->reg);
1415 pcs->write(mask, pcswi->reg);
1417 /* flush posted write */
1418 mask = pcs->read(pcswi->reg);
1419 raw_spin_unlock(&pcs->lock);
1427 * pcs_irq_mask() - mask pinctrl interrupt
1428 * @d: interrupt data
1430 static void pcs_irq_mask(struct irq_data *d)
1432 struct pcs_soc_data *pcs_soc = irq_data_get_irq_chip_data(d);
1434 pcs_irq_set(pcs_soc, d->irq, false);
1438 * pcs_irq_unmask() - unmask pinctrl interrupt
1439 * @d: interrupt data
1441 static void pcs_irq_unmask(struct irq_data *d)
1443 struct pcs_soc_data *pcs_soc = irq_data_get_irq_chip_data(d);
1445 pcs_irq_set(pcs_soc, d->irq, true);
1449 * pcs_irq_set_wake() - toggle the suspend and resume wake up
1450 * @d: interrupt data
1451 * @state: wake-up state
1453 * Note that this should be called only for suspend and resume.
1454 * For runtime PM, the wake-up events should be enabled by default.
1456 static int pcs_irq_set_wake(struct irq_data *d, unsigned int state)
1467 * pcs_irq_handle() - common interrupt handler
1468 * @pcs_soc: SoC specific settings
1470 * Note that this currently assumes we have one interrupt bit per
1471 * mux register. This interrupt is typically used for wake-up events.
1472 * For more complex interrupts different handlers can be specified.
1474 static int pcs_irq_handle(struct pcs_soc_data *pcs_soc)
1476 struct pcs_device *pcs;
1477 struct list_head *pos;
1480 pcs = container_of(pcs_soc, struct pcs_device, socdata);
1481 list_for_each(pos, &pcs->irqs) {
1482 struct pcs_interrupt *pcswi;
1485 pcswi = list_entry(pos, struct pcs_interrupt, node);
1486 raw_spin_lock(&pcs->lock);
1487 mask = pcs->read(pcswi->reg);
1488 raw_spin_unlock(&pcs->lock);
1489 if (mask & pcs_soc->irq_status_mask) {
1490 generic_handle_domain_irq(pcs->domain,
1500 * pcs_irq_handler() - handler for the shared interrupt case
1504 * Use this for cases where multiple instances of
1505 * pinctrl-single share a single interrupt like on omaps.
1507 static irqreturn_t pcs_irq_handler(int irq, void *d)
1509 struct pcs_soc_data *pcs_soc = d;
1511 return pcs_irq_handle(pcs_soc) ? IRQ_HANDLED : IRQ_NONE;
1515 * pcs_irq_chain_handler() - handler for the dedicated chained interrupt case
1516 * @desc: interrupt descriptor
1518 * Use this if you have a separate interrupt for each
1519 * pinctrl-single instance.
1521 static void pcs_irq_chain_handler(struct irq_desc *desc)
1523 struct pcs_soc_data *pcs_soc = irq_desc_get_handler_data(desc);
1524 struct irq_chip *chip;
1526 chip = irq_desc_get_chip(desc);
1527 chained_irq_enter(chip, desc);
1528 pcs_irq_handle(pcs_soc);
1529 /* REVISIT: export and add handle_bad_irq(irq, desc)? */
1530 chained_irq_exit(chip, desc);
1533 static int pcs_irqdomain_map(struct irq_domain *d, unsigned int irq,
1534 irq_hw_number_t hwirq)
1536 struct pcs_soc_data *pcs_soc = d->host_data;
1537 struct pcs_device *pcs;
1538 struct pcs_interrupt *pcswi;
1540 pcs = container_of(pcs_soc, struct pcs_device, socdata);
1541 pcswi = devm_kzalloc(pcs->dev, sizeof(*pcswi), GFP_KERNEL);
1545 pcswi->reg = pcs->base + hwirq;
1546 pcswi->hwirq = hwirq;
1549 mutex_lock(&pcs->mutex);
1550 list_add_tail(&pcswi->node, &pcs->irqs);
1551 mutex_unlock(&pcs->mutex);
1553 irq_set_chip_data(irq, pcs_soc);
1554 irq_set_chip_and_handler(irq, &pcs->chip,
1556 irq_set_lockdep_class(irq, &pcs_lock_class, &pcs_request_class);
1557 irq_set_noprobe(irq);
1562 static const struct irq_domain_ops pcs_irqdomain_ops = {
1563 .map = pcs_irqdomain_map,
1564 .xlate = irq_domain_xlate_onecell,
1568 * pcs_irq_init_chained_handler() - set up a chained interrupt handler
1569 * @pcs: pcs driver instance
1570 * @np: device node pointer
1572 static int pcs_irq_init_chained_handler(struct pcs_device *pcs,
1573 struct device_node *np)
1575 struct pcs_soc_data *pcs_soc = &pcs->socdata;
1576 const char *name = "pinctrl";
1579 if (!pcs_soc->irq_enable_mask ||
1580 !pcs_soc->irq_status_mask) {
1585 INIT_LIST_HEAD(&pcs->irqs);
1586 pcs->chip.name = name;
1587 pcs->chip.irq_ack = pcs_irq_mask;
1588 pcs->chip.irq_mask = pcs_irq_mask;
1589 pcs->chip.irq_unmask = pcs_irq_unmask;
1590 pcs->chip.irq_set_wake = pcs_irq_set_wake;
1592 if (PCS_QUIRK_HAS_SHARED_IRQ) {
1595 res = request_irq(pcs_soc->irq, pcs_irq_handler,
1596 IRQF_SHARED | IRQF_NO_SUSPEND |
1604 irq_set_chained_handler_and_data(pcs_soc->irq,
1605 pcs_irq_chain_handler,
1610 * We can use the register offset as the hardirq
1611 * number as irq_domain_add_simple maps them lazily.
1612 * This way we can easily support more than one
1613 * interrupt per function if needed.
1615 num_irqs = pcs->size;
1617 pcs->domain = irq_domain_add_simple(np, num_irqs, 0,
1621 irq_set_chained_handler(pcs_soc->irq, NULL);
1629 static int pcs_save_context(struct pcs_device *pcs)
1636 mux_bytes = pcs->width / BITS_PER_BYTE;
1638 if (!pcs->saved_vals) {
1639 pcs->saved_vals = devm_kzalloc(pcs->dev, pcs->size, GFP_ATOMIC);
1640 if (!pcs->saved_vals)
1644 switch (pcs->width) {
1646 regsl = pcs->saved_vals;
1647 for (i = 0; i < pcs->size; i += mux_bytes)
1648 *regsl++ = pcs->read(pcs->base + i);
1651 regsw = pcs->saved_vals;
1652 for (i = 0; i < pcs->size; i += mux_bytes)
1653 *regsw++ = pcs->read(pcs->base + i);
1656 regshw = pcs->saved_vals;
1657 for (i = 0; i < pcs->size; i += mux_bytes)
1658 *regshw++ = pcs->read(pcs->base + i);
1665 static void pcs_restore_context(struct pcs_device *pcs)
1672 mux_bytes = pcs->width / BITS_PER_BYTE;
1674 switch (pcs->width) {
1676 regsl = pcs->saved_vals;
1677 for (i = 0; i < pcs->size; i += mux_bytes)
1678 pcs->write(*regsl++, pcs->base + i);
1681 regsw = pcs->saved_vals;
1682 for (i = 0; i < pcs->size; i += mux_bytes)
1683 pcs->write(*regsw++, pcs->base + i);
1686 regshw = pcs->saved_vals;
1687 for (i = 0; i < pcs->size; i += mux_bytes)
1688 pcs->write(*regshw++, pcs->base + i);
1693 static int pinctrl_single_suspend(struct platform_device *pdev,
1696 struct pcs_device *pcs;
1698 pcs = platform_get_drvdata(pdev);
1702 if (pcs->flags & PCS_CONTEXT_LOSS_OFF) {
1705 ret = pcs_save_context(pcs);
1710 return pinctrl_force_sleep(pcs->pctl);
1713 static int pinctrl_single_resume(struct platform_device *pdev)
1715 struct pcs_device *pcs;
1717 pcs = platform_get_drvdata(pdev);
1721 if (pcs->flags & PCS_CONTEXT_LOSS_OFF)
1722 pcs_restore_context(pcs);
1724 return pinctrl_force_default(pcs->pctl);
1729 * pcs_quirk_missing_pinctrl_cells - handle legacy binding
1730 * @pcs: pinctrl driver instance
1731 * @np: device tree node
1732 * @cells: number of cells
1734 * Handle legacy binding with no #pinctrl-cells. This should be
1735 * always two pinctrl-single,bit-per-mux and one for others.
1736 * At some point we may want to consider removing this.
1738 static int pcs_quirk_missing_pinctrl_cells(struct pcs_device *pcs,
1739 struct device_node *np,
1743 const char *name = "#pinctrl-cells";
1747 error = of_property_read_u32(np, name, &val);
1751 dev_warn(pcs->dev, "please update dts to use %s = <%i>\n",
1754 p = devm_kzalloc(pcs->dev, sizeof(*p), GFP_KERNEL);
1758 p->length = sizeof(__be32);
1759 p->value = devm_kzalloc(pcs->dev, sizeof(__be32), GFP_KERNEL);
1762 *(__be32 *)p->value = cpu_to_be32(cells);
1764 p->name = devm_kstrdup(pcs->dev, name, GFP_KERNEL);
1768 pcs->missing_nr_pinctrl_cells = p;
1770 #if IS_BUILTIN(CONFIG_PINCTRL_SINGLE)
1771 error = of_add_property(np, pcs->missing_nr_pinctrl_cells);
1777 static int pcs_probe(struct platform_device *pdev)
1779 struct device_node *np = pdev->dev.of_node;
1780 struct pcs_pdata *pdata;
1781 struct resource *res;
1782 struct pcs_device *pcs;
1783 const struct pcs_soc_data *soc;
1786 soc = of_device_get_match_data(&pdev->dev);
1790 pcs = devm_kzalloc(&pdev->dev, sizeof(*pcs), GFP_KERNEL);
1794 pcs->dev = &pdev->dev;
1796 raw_spin_lock_init(&pcs->lock);
1797 mutex_init(&pcs->mutex);
1798 INIT_LIST_HEAD(&pcs->gpiofuncs);
1799 pcs->flags = soc->flags;
1800 memcpy(&pcs->socdata, soc, sizeof(*soc));
1802 ret = of_property_read_u32(np, "pinctrl-single,register-width",
1805 dev_err(pcs->dev, "register width not specified\n");
1810 ret = of_property_read_u32(np, "pinctrl-single,function-mask",
1813 pcs->fshift = __ffs(pcs->fmask);
1814 pcs->fmax = pcs->fmask >> pcs->fshift;
1816 /* If mask property doesn't exist, function mux is invalid. */
1822 ret = of_property_read_u32(np, "pinctrl-single,function-off",
1825 pcs->foff = PCS_OFF_DISABLED;
1827 pcs->bits_per_mux = of_property_read_bool(np,
1828 "pinctrl-single,bit-per-mux");
1829 ret = pcs_quirk_missing_pinctrl_cells(pcs, np,
1830 pcs->bits_per_mux ? 2 : 1);
1832 dev_err(&pdev->dev, "unable to patch #pinctrl-cells\n");
1837 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1839 dev_err(pcs->dev, "could not get resource\n");
1843 pcs->res = devm_request_mem_region(pcs->dev, res->start,
1844 resource_size(res), DRIVER_NAME);
1846 dev_err(pcs->dev, "could not get mem_region\n");
1850 pcs->size = resource_size(pcs->res);
1851 pcs->base = devm_ioremap(pcs->dev, pcs->res->start, pcs->size);
1853 dev_err(pcs->dev, "could not ioremap\n");
1857 platform_set_drvdata(pdev, pcs);
1859 switch (pcs->width) {
1861 pcs->read = pcs_readb;
1862 pcs->write = pcs_writeb;
1865 pcs->read = pcs_readw;
1866 pcs->write = pcs_writew;
1869 pcs->read = pcs_readl;
1870 pcs->write = pcs_writel;
1876 pcs->desc.name = DRIVER_NAME;
1877 pcs->desc.pctlops = &pcs_pinctrl_ops;
1878 pcs->desc.pmxops = &pcs_pinmux_ops;
1879 if (PCS_HAS_PINCONF)
1880 pcs->desc.confops = &pcs_pinconf_ops;
1881 pcs->desc.owner = THIS_MODULE;
1883 ret = pcs_allocate_pin_table(pcs);
1887 ret = pinctrl_register_and_init(&pcs->desc, pcs->dev, pcs, &pcs->pctl);
1889 dev_err(pcs->dev, "could not register single pinctrl driver\n");
1893 ret = pcs_add_gpio_func(np, pcs);
1897 pcs->socdata.irq = irq_of_parse_and_map(np, 0);
1898 if (pcs->socdata.irq)
1899 pcs->flags |= PCS_FEAT_IRQ;
1901 /* We still need auxdata for some omaps for PRM interrupts */
1902 pdata = dev_get_platdata(&pdev->dev);
1905 pcs->socdata.rearm = pdata->rearm;
1907 pcs->socdata.irq = pdata->irq;
1908 pcs->flags |= PCS_FEAT_IRQ;
1913 ret = pcs_irq_init_chained_handler(pcs, np);
1915 dev_warn(pcs->dev, "initialized with no interrupts\n");
1918 dev_info(pcs->dev, "%i pins, size %u\n", pcs->desc.npins, pcs->size);
1920 return pinctrl_enable(pcs->pctl);
1923 pcs_free_resources(pcs);
1928 static int pcs_remove(struct platform_device *pdev)
1930 struct pcs_device *pcs = platform_get_drvdata(pdev);
1935 pcs_free_resources(pcs);
1940 static const struct pcs_soc_data pinctrl_single_omap_wkup = {
1941 .flags = PCS_QUIRK_SHARED_IRQ,
1942 .irq_enable_mask = (1 << 14), /* OMAP_WAKEUP_EN */
1943 .irq_status_mask = (1 << 15), /* OMAP_WAKEUP_EVENT */
1946 static const struct pcs_soc_data pinctrl_single_dra7 = {
1947 .irq_enable_mask = (1 << 24), /* WAKEUPENABLE */
1948 .irq_status_mask = (1 << 25), /* WAKEUPEVENT */
1951 static const struct pcs_soc_data pinctrl_single_am437x = {
1952 .flags = PCS_QUIRK_SHARED_IRQ | PCS_CONTEXT_LOSS_OFF,
1953 .irq_enable_mask = (1 << 29), /* OMAP_WAKEUP_EN */
1954 .irq_status_mask = (1 << 30), /* OMAP_WAKEUP_EVENT */
1957 static const struct pcs_soc_data pinctrl_single_am654 = {
1958 .flags = PCS_QUIRK_SHARED_IRQ | PCS_CONTEXT_LOSS_OFF,
1959 .irq_enable_mask = (1 << 29), /* WKUP_EN */
1960 .irq_status_mask = (1 << 30), /* WKUP_EVT */
1963 static const struct pcs_soc_data pinctrl_single = {
1966 static const struct pcs_soc_data pinconf_single = {
1967 .flags = PCS_FEAT_PINCONF,
1970 static const struct of_device_id pcs_of_match[] = {
1971 { .compatible = "ti,am437-padconf", .data = &pinctrl_single_am437x },
1972 { .compatible = "ti,am654-padconf", .data = &pinctrl_single_am654 },
1973 { .compatible = "ti,dra7-padconf", .data = &pinctrl_single_dra7 },
1974 { .compatible = "ti,omap3-padconf", .data = &pinctrl_single_omap_wkup },
1975 { .compatible = "ti,omap4-padconf", .data = &pinctrl_single_omap_wkup },
1976 { .compatible = "ti,omap5-padconf", .data = &pinctrl_single_omap_wkup },
1977 { .compatible = "pinctrl-single", .data = &pinctrl_single },
1978 { .compatible = "pinconf-single", .data = &pinconf_single },
1981 MODULE_DEVICE_TABLE(of, pcs_of_match);
1983 static struct platform_driver pcs_driver = {
1985 .remove = pcs_remove,
1987 .name = DRIVER_NAME,
1988 .of_match_table = pcs_of_match,
1991 .suspend = pinctrl_single_suspend,
1992 .resume = pinctrl_single_resume,
1996 module_platform_driver(pcs_driver);
1998 MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>");
1999 MODULE_DESCRIPTION("One-register-per-pin type device tree based pinctrl driver");
2000 MODULE_LICENSE("GPL v2");