Lines Matching +full:pinmux +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0
11 #include <linux/pinctrl/pinconf-generic.h>
12 #include <linux/pinctrl/pinmux.h>
17 #include "pinmux.h"
18 #include "pinctrl-equilibrium.h"
20 #define PIN_NAME_FMT "io-%d"
31 raw_spin_lock_irqsave(&gctrl->lock, flags); in eqbr_gpio_disable_irq()
32 writel(BIT(offset), gctrl->membase + GPIO_IRNENCLR); in eqbr_gpio_disable_irq()
33 raw_spin_unlock_irqrestore(&gctrl->lock, flags); in eqbr_gpio_disable_irq()
43 gc->direction_input(gc, offset); in eqbr_gpio_enable_irq()
44 raw_spin_lock_irqsave(&gctrl->lock, flags); in eqbr_gpio_enable_irq()
45 writel(BIT(offset), gctrl->membase + GPIO_IRNRNSET); in eqbr_gpio_enable_irq()
46 raw_spin_unlock_irqrestore(&gctrl->lock, flags); in eqbr_gpio_enable_irq()
56 raw_spin_lock_irqsave(&gctrl->lock, flags); in eqbr_gpio_ack_irq()
57 writel(BIT(offset), gctrl->membase + GPIO_IRNCR); in eqbr_gpio_ack_irq()
58 raw_spin_unlock_irqrestore(&gctrl->lock, flags); in eqbr_gpio_ack_irq()
82 raw_spin_lock_irqsave(&gctrl->lock, flags); in eqbr_irq_type_cfg()
83 eqbr_cfg_bit(gctrl->membase + GPIO_IRNCFG, offset, type->trig_type); in eqbr_irq_type_cfg()
84 eqbr_cfg_bit(gctrl->membase + GPIO_EXINTCR1, offset, type->trig_type); in eqbr_irq_type_cfg()
85 eqbr_cfg_bit(gctrl->membase + GPIO_EXINTCR0, offset, type->logic_type); in eqbr_irq_type_cfg()
86 raw_spin_unlock_irqrestore(&gctrl->lock, flags); in eqbr_irq_type_cfg()
135 return -EINVAL; in eqbr_gpio_set_irq_type()
155 pins = readl(gctrl->membase + GPIO_IRNCR); in eqbr_irq_handler()
157 for_each_set_bit(offset, &pins, gc->ngpio) in eqbr_irq_handler()
158 generic_handle_irq(irq_find_mapping(gc->irq.domain, offset)); in eqbr_irq_handler()
168 gc = &gctrl->chip; in gpiochip_setup()
169 gc->label = gctrl->name; in gpiochip_setup()
171 gc->of_node = gctrl->node; in gpiochip_setup()
174 if (!of_property_read_bool(gctrl->node, "interrupt-controller")) { in gpiochip_setup()
176 gctrl->name); in gpiochip_setup()
180 gctrl->ic.name = "gpio_irq"; in gpiochip_setup()
181 gctrl->ic.irq_mask = eqbr_gpio_disable_irq; in gpiochip_setup()
182 gctrl->ic.irq_unmask = eqbr_gpio_enable_irq; in gpiochip_setup()
183 gctrl->ic.irq_ack = eqbr_gpio_ack_irq; in gpiochip_setup()
184 gctrl->ic.irq_mask_ack = eqbr_gpio_mask_ack_irq; in gpiochip_setup()
185 gctrl->ic.irq_set_type = eqbr_gpio_set_irq_type; in gpiochip_setup()
187 girq = &gctrl->chip.irq; in gpiochip_setup()
188 girq->chip = &gctrl->ic; in gpiochip_setup()
189 girq->parent_handler = eqbr_irq_handler; in gpiochip_setup()
190 girq->num_parents = 1; in gpiochip_setup()
191 girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), GFP_KERNEL); in gpiochip_setup()
192 if (!girq->parents) in gpiochip_setup()
193 return -ENOMEM; in gpiochip_setup()
195 girq->default_type = IRQ_TYPE_NONE; in gpiochip_setup()
196 girq->handler = handle_bad_irq; in gpiochip_setup()
197 girq->parents[0] = gctrl->virq; in gpiochip_setup()
204 struct device *dev = drvdata->dev; in gpiolib_reg()
210 for (i = 0; i < drvdata->nr_gpio_ctrls; i++) { in gpiolib_reg()
211 gctrl = drvdata->gpio_ctrls + i; in gpiolib_reg()
212 np = gctrl->node; in gpiolib_reg()
214 gctrl->name = devm_kasprintf(dev, GFP_KERNEL, "gpiochip%d", i); in gpiolib_reg()
215 if (!gctrl->name) in gpiolib_reg()
216 return -ENOMEM; in gpiolib_reg()
220 return -ENXIO; in gpiolib_reg()
223 gctrl->membase = devm_ioremap_resource(dev, &res); in gpiolib_reg()
224 if (IS_ERR(gctrl->membase)) in gpiolib_reg()
225 return PTR_ERR(gctrl->membase); in gpiolib_reg()
227 gctrl->virq = irq_of_parse_and_map(np, 0); in gpiolib_reg()
228 if (!gctrl->virq) { in gpiolib_reg()
230 gctrl->name); in gpiolib_reg()
231 return -ENXIO; in gpiolib_reg()
233 raw_spin_lock_init(&gctrl->lock); in gpiolib_reg()
235 ret = bgpio_init(&gctrl->chip, dev, gctrl->bank->nr_pins / 8, in gpiolib_reg()
236 gctrl->membase + GPIO_IN, in gpiolib_reg()
237 gctrl->membase + GPIO_OUTSET, in gpiolib_reg()
238 gctrl->membase + GPIO_OUTCLR, in gpiolib_reg()
239 gctrl->membase + GPIO_DIR, in gpiolib_reg()
250 ret = devm_gpiochip_add_data(dev, &gctrl->chip, gctrl); in gpiolib_reg()
264 for (i = 0; i < pctl->nr_banks; i++) { in find_pinbank_via_pin()
265 bank = &pctl->pin_banks[i]; in find_pinbank_via_pin()
266 if (pin >= bank->pin_base && in find_pinbank_via_pin()
267 (pin - bank->pin_base) < bank->nr_pins) in find_pinbank_via_pin()
292 dev_err(pctl->dev, "Couldn't find pin bank for pin %u\n", pin); in eqbr_set_pin_mux()
293 return -ENODEV; in eqbr_set_pin_mux()
295 mem = bank->membase; in eqbr_set_pin_mux()
296 offset = pin - bank->pin_base; in eqbr_set_pin_mux()
298 if (!(bank->aval_pinmap & BIT(offset))) { in eqbr_set_pin_mux()
299 dev_err(pctl->dev, in eqbr_set_pin_mux()
301 pin, bank->pin_base, bank->aval_pinmap); in eqbr_set_pin_mux()
302 return -ENODEV; in eqbr_set_pin_mux()
305 raw_spin_lock_irqsave(&pctl->lock, flags); in eqbr_set_pin_mux()
307 raw_spin_unlock_irqrestore(&pctl->lock, flags); in eqbr_set_pin_mux()
317 unsigned int *pinmux; in eqbr_pinmux_set_mux() local
322 return -EINVAL; in eqbr_pinmux_set_mux()
326 return -EINVAL; in eqbr_pinmux_set_mux()
328 pinmux = grp->data; in eqbr_pinmux_set_mux()
329 for (i = 0; i < grp->num_pins; i++) in eqbr_pinmux_set_mux()
330 eqbr_set_pin_mux(pctl, pinmux[i], grp->pins[i]); in eqbr_pinmux_set_mux()
355 unsigned int idx = offset / DRV_CUR_PINS; /* 0-15, 16-31 per register*/ in get_drv_cur()
367 for (i = 0; i < pctl->nr_gpio_ctrls; i++) { in get_gpio_ctrls_via_bank()
368 if (pctl->gpio_ctrls[i].bank == bank) in get_gpio_ctrls_via_bank()
369 return &pctl->gpio_ctrls[i]; in get_gpio_ctrls_via_bank()
389 dev_err(pctl->dev, "Couldn't find pin bank for pin %u\n", pin); in eqbr_pinconf_get()
390 return -ENODEV; in eqbr_pinconf_get()
392 mem = bank->membase; in eqbr_pinconf_get()
393 offset = pin - bank->pin_base; in eqbr_pinconf_get()
395 if (!(bank->aval_pinmap & BIT(offset))) { in eqbr_pinconf_get()
396 dev_err(pctl->dev, in eqbr_pinconf_get()
398 pin, bank->pin_base, bank->aval_pinmap); in eqbr_pinconf_get()
399 return -ENODEV; in eqbr_pinconf_get()
402 raw_spin_lock_irqsave(&pctl->lock, flags); in eqbr_pinconf_get()
422 dev_err(pctl->dev, "Failed to find gpio via bank pinbase: %u, pin: %u\n", in eqbr_pinconf_get()
423 bank->pin_base, pin); in eqbr_pinconf_get()
424 raw_spin_unlock_irqrestore(&pctl->lock, flags); in eqbr_pinconf_get()
425 return -ENODEV; in eqbr_pinconf_get()
427 val = !!(readl(gctrl->membase + GPIO_DIR) & BIT(offset)); in eqbr_pinconf_get()
430 raw_spin_unlock_irqrestore(&pctl->lock, flags); in eqbr_pinconf_get()
431 return -ENOTSUPP; in eqbr_pinconf_get()
433 raw_spin_unlock_irqrestore(&pctl->lock, flags); in eqbr_pinconf_get()
459 dev_err(pctl->dev, in eqbr_pinconf_set()
461 return -ENODEV; in eqbr_pinconf_set()
463 mem = bank->membase; in eqbr_pinconf_set()
464 offset = pin - bank->pin_base; in eqbr_pinconf_set()
491 dev_err(pctl->dev, "Failed to find gpio via bank pinbase: %u, pin: %u\n", in eqbr_pinconf_set()
492 bank->pin_base, pin); in eqbr_pinconf_set()
493 return -ENODEV; in eqbr_pinconf_set()
495 gc = &gctrl->chip; in eqbr_pinconf_set()
496 gc->direction_output(gc, offset, 0); in eqbr_pinconf_set()
499 return -ENOTSUPP; in eqbr_pinconf_set()
502 raw_spin_lock_irqsave(&pctl->lock, flags); in eqbr_pinconf_set()
506 raw_spin_unlock_irqrestore(&pctl->lock, flags); in eqbr_pinconf_set()
525 return -ENOTSUPP; in eqbr_pinconf_group_get()
528 return -ENOTSUPP; in eqbr_pinconf_group_get()
585 struct device_node *node = dev->of_node; in funcs_utils()
601 (char *)prop->value); in funcs_utils()
626 funcs[fid].groups[j] = prop->value; in funcs_utils()
631 return -EINVAL; in funcs_utils()
641 struct device *dev = drvdata->dev; in eqbr_build_functions()
652 return -ENOMEM; in eqbr_build_functions()
669 return -ENOMEM; in eqbr_build_functions()
677 ret = pinmux_generic_add_function(drvdata->pctl_dev, in eqbr_build_functions()
694 struct device *dev = drvdata->dev; in eqbr_build_groups()
695 struct device_node *node = dev->of_node; in eqbr_build_groups()
696 unsigned int *pinmux, pin_id, pinmux_id; in eqbr_build_groups() local
709 dev_err(dev, "No pins in the group: %s\n", prop->name); in eqbr_build_groups()
710 return -EINVAL; in eqbr_build_groups()
712 group.name = prop->value; in eqbr_build_groups()
716 return -ENOMEM; in eqbr_build_groups()
718 pinmux = devm_kcalloc(dev, group.num_pins, sizeof(*pinmux), in eqbr_build_groups()
720 if (!pinmux) in eqbr_build_groups()
721 return -ENOMEM; in eqbr_build_groups()
725 dev_err(dev, "Group %s: Read intel pins id failed\n", in eqbr_build_groups()
727 return -EINVAL; in eqbr_build_groups()
729 if (pin_id >= drvdata->pctl_desc.npins) { in eqbr_build_groups()
730 dev_err(dev, "Group %s: Invalid pin ID, idx: %d, pin %u\n", in eqbr_build_groups()
732 return -EINVAL; in eqbr_build_groups()
735 if (of_property_read_u32_index(np, "pinmux", j, &pinmux_id)) { in eqbr_build_groups()
736 dev_err(dev, "Group %s: Read intel pinmux id failed\n", in eqbr_build_groups()
738 return -EINVAL; in eqbr_build_groups()
740 pinmux[j] = pinmux_id; in eqbr_build_groups()
743 err = pinctrl_generic_add_group(drvdata->pctl_dev, group.name, in eqbr_build_groups()
745 pinmux); in eqbr_build_groups()
751 pinmux = NULL; in eqbr_build_groups()
766 dev = drvdata->dev; in pinctrl_reg()
767 pctl_desc = &drvdata->pctl_desc; in pinctrl_reg()
768 pctl_desc->name = "eqbr-pinctrl"; in pinctrl_reg()
769 pctl_desc->owner = THIS_MODULE; in pinctrl_reg()
770 pctl_desc->pctlops = &eqbr_pctl_ops; in pinctrl_reg()
771 pctl_desc->pmxops = &eqbr_pinmux_ops; in pinctrl_reg()
772 pctl_desc->confops = &eqbr_pinconf_ops; in pinctrl_reg()
773 raw_spin_lock_init(&drvdata->lock); in pinctrl_reg()
775 for (i = 0, nr_pins = 0; i < drvdata->nr_banks; i++) in pinctrl_reg()
776 nr_pins += drvdata->pin_banks[i].nr_pins; in pinctrl_reg()
780 return -ENOMEM; in pinctrl_reg()
783 return -ENOMEM; in pinctrl_reg()
791 pctl_desc->pins = pdesc; in pinctrl_reg()
792 pctl_desc->npins = nr_pins; in pinctrl_reg()
796 &drvdata->pctl_dev); in pinctrl_reg()
812 return pinctrl_enable(drvdata->pctl_dev); in pinctrl_reg()
817 struct eqbr_pin_bank *bank, unsigned int id) in pinbank_init() argument
819 struct device *dev = drvdata->dev; in pinbank_init()
823 bank->membase = drvdata->membase + id * PAD_REG_OFF; in pinbank_init()
825 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &spec); in pinbank_init()
827 dev_err(dev, "gpio-range not available!\n"); in pinbank_init()
831 bank->pin_base = spec.args[1]; in pinbank_init()
832 bank->nr_pins = spec.args[2]; in pinbank_init()
834 bank->aval_pinmap = readl(bank->membase + REG_AVAIL); in pinbank_init()
835 bank->id = id; in pinbank_init()
837 dev_dbg(dev, "pinbank id: %d, reg: %px, pinbase: %u, pin number: %u, pinmap: 0x%x\n", in pinbank_init()
838 id, bank->membase, bank->pin_base, in pinbank_init()
839 bank->nr_pins, bank->aval_pinmap); in pinbank_init()
846 struct device *dev = drvdata->dev; in pinbank_probe()
861 return -ENODEV; in pinbank_probe()
867 return -ENOMEM; in pinbank_probe()
871 return -ENOMEM; in pinbank_probe()
888 drvdata->pin_banks = banks; in pinbank_probe()
889 drvdata->nr_banks = nr_gpio; in pinbank_probe()
890 drvdata->gpio_ctrls = gctrls; in pinbank_probe()
891 drvdata->nr_gpio_ctrls = nr_gpio; in pinbank_probe()
899 struct device *dev = &pdev->dev; in eqbr_pinctrl_probe()
904 return -ENOMEM; in eqbr_pinctrl_probe()
906 drvdata->dev = dev; in eqbr_pinctrl_probe()
908 drvdata->membase = devm_platform_ioremap_resource(pdev, 0); in eqbr_pinctrl_probe()
909 if (IS_ERR(drvdata->membase)) in eqbr_pinctrl_probe()
910 return PTR_ERR(drvdata->membase); in eqbr_pinctrl_probe()
929 { .compatible = "intel,lgm-io" },
936 .name = "eqbr-pinctrl",