Lines Matching +full:off +full:- +full:chip
1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (c) 2009-2011 Samsung Electronics Co., Ltd.
11 // Samsung - GPIOlib support
31 #include "regs-gpio.h"
32 #include "gpio-samsung.h"
35 #include "gpio-core.h"
36 #include "gpio-cfg.h"
37 #include "gpio-cfg-helpers.h"
40 static int samsung_gpio_setpull_updown(struct samsung_gpio_chip *chip, in samsung_gpio_setpull_updown() argument
41 unsigned int off, samsung_gpio_pull_t pull) in samsung_gpio_setpull_updown() argument
43 void __iomem *reg = chip->base + 0x08; in samsung_gpio_setpull_updown()
44 int shift = off * 2; in samsung_gpio_setpull_updown()
55 static samsung_gpio_pull_t samsung_gpio_getpull_updown(struct samsung_gpio_chip *chip, in samsung_gpio_getpull_updown() argument
56 unsigned int off) in samsung_gpio_getpull_updown() argument
58 void __iomem *reg = chip->base + 0x08; in samsung_gpio_getpull_updown()
59 int shift = off * 2; in samsung_gpio_getpull_updown()
68 static int samsung_gpio_setcfg_2bit(struct samsung_gpio_chip *chip, in samsung_gpio_setcfg_2bit() argument
69 unsigned int off, unsigned int cfg) in samsung_gpio_setcfg_2bit() argument
71 void __iomem *reg = chip->base; in samsung_gpio_setcfg_2bit()
72 unsigned int shift = off * 2; in samsung_gpio_setcfg_2bit()
78 return -EINVAL; in samsung_gpio_setcfg_2bit()
92 * samsung_gpio_getcfg_2bit - Samsung 2bit style GPIO configuration read.
93 * @chip: The gpio chip that is being configured.
94 * @off: The offset for the GPIO being configured.
101 static unsigned int samsung_gpio_getcfg_2bit(struct samsung_gpio_chip *chip, in samsung_gpio_getcfg_2bit() argument
102 unsigned int off) in samsung_gpio_getcfg_2bit() argument
106 con = __raw_readl(chip->base); in samsung_gpio_getcfg_2bit()
107 con >>= off * 2; in samsung_gpio_getcfg_2bit()
115 * samsung_gpio_setcfg_4bit - Samsung 4bit single register GPIO config.
116 * @chip: The gpio chip that is being configured.
117 * @off: The offset for the GPIO being configured.
131 static int samsung_gpio_setcfg_4bit(struct samsung_gpio_chip *chip, in samsung_gpio_setcfg_4bit() argument
132 unsigned int off, unsigned int cfg) in samsung_gpio_setcfg_4bit() argument
134 void __iomem *reg = chip->base; in samsung_gpio_setcfg_4bit()
135 unsigned int shift = (off & 7) * 4; in samsung_gpio_setcfg_4bit()
138 if (off < 8 && chip->chip.ngpio > 8) in samsung_gpio_setcfg_4bit()
139 reg -= 4; in samsung_gpio_setcfg_4bit()
155 * samsung_gpio_getcfg_4bit - Samsung 4bit single register GPIO config read.
156 * @chip: The gpio chip that is being configured.
157 * @off: The offset for the GPIO being configured.
166 static unsigned samsung_gpio_getcfg_4bit(struct samsung_gpio_chip *chip, in samsung_gpio_getcfg_4bit() argument
167 unsigned int off) in samsung_gpio_getcfg_4bit() argument
169 void __iomem *reg = chip->base; in samsung_gpio_getcfg_4bit()
170 unsigned int shift = (off & 7) * 4; in samsung_gpio_getcfg_4bit()
173 if (off < 8 && chip->chip.ngpio > 8) in samsung_gpio_getcfg_4bit()
174 reg -= 4; in samsung_gpio_getcfg_4bit()
187 for (; nr_chips > 0; nr_chips--, chipcfg++) { in samsung_gpiolib_set_cfg()
188 if (!chipcfg->set_config) in samsung_gpiolib_set_cfg()
189 chipcfg->set_config = samsung_gpio_setcfg_4bit; in samsung_gpiolib_set_cfg()
190 if (!chipcfg->get_config) in samsung_gpiolib_set_cfg()
191 chipcfg->get_config = samsung_gpio_getcfg_4bit; in samsung_gpiolib_set_cfg()
192 if (!chipcfg->set_pull) in samsung_gpiolib_set_cfg()
193 chipcfg->set_pull = samsung_gpio_setpull_updown; in samsung_gpiolib_set_cfg()
194 if (!chipcfg->get_pull) in samsung_gpiolib_set_cfg()
195 chipcfg->get_pull = samsung_gpio_getpull_updown; in samsung_gpiolib_set_cfg()
236 * chip is as following:
240 * 00 = input, 01 = output, others mean special-function
245 static int samsung_gpiolib_2bit_input(struct gpio_chip *chip, unsigned offset) in samsung_gpiolib_2bit_input() argument
247 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); in samsung_gpiolib_2bit_input()
248 void __iomem *base = ourchip->base; in samsung_gpiolib_2bit_input()
263 static int samsung_gpiolib_2bit_output(struct gpio_chip *chip, in samsung_gpiolib_2bit_output() argument
266 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); in samsung_gpiolib_2bit_output()
267 void __iomem *base = ourchip->base; in samsung_gpiolib_2bit_output()
298 * 0000 = input, 0001 = output, others mean special-function
307 static int samsung_gpiolib_4bit_input(struct gpio_chip *chip, in samsung_gpiolib_4bit_input() argument
310 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); in samsung_gpiolib_4bit_input()
311 void __iomem *base = ourchip->base; in samsung_gpiolib_4bit_input()
315 if (ourchip->bitmap_gpio_int & BIT(offset)) in samsung_gpiolib_4bit_input()
326 static int samsung_gpiolib_4bit_output(struct gpio_chip *chip, in samsung_gpiolib_4bit_output() argument
329 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); in samsung_gpiolib_4bit_output()
330 void __iomem *base = ourchip->base; in samsung_gpiolib_4bit_output()
364 * 0000 = input, 0001 = output, others mean special-function
367 * 0000 = input, 0001 = output, others mean special-function
373 * the data register at ourchip->base + 0x04.
376 static int samsung_gpiolib_4bit2_input(struct gpio_chip *chip, in samsung_gpiolib_4bit2_input() argument
379 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); in samsung_gpiolib_4bit2_input()
380 void __iomem *base = ourchip->base; in samsung_gpiolib_4bit2_input()
385 offset -= 8; in samsung_gpiolib_4bit2_input()
387 regcon -= 4; in samsung_gpiolib_4bit2_input()
398 static int samsung_gpiolib_4bit2_output(struct gpio_chip *chip, in samsung_gpiolib_4bit2_output() argument
401 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); in samsung_gpiolib_4bit2_output()
402 void __iomem *base = ourchip->base; in samsung_gpiolib_4bit2_output()
409 con_offset -= 8; in samsung_gpiolib_4bit2_output()
411 regcon -= 4; in samsung_gpiolib_4bit2_output()
433 static void samsung_gpiolib_set(struct gpio_chip *chip, in samsung_gpiolib_set() argument
436 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); in samsung_gpiolib_set()
437 void __iomem *base = ourchip->base; in samsung_gpiolib_set()
452 static int samsung_gpiolib_get(struct gpio_chip *chip, unsigned offset) in samsung_gpiolib_get() argument
454 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); in samsung_gpiolib_get()
457 val = __raw_readl(ourchip->base + 0x04); in samsung_gpiolib_get()
479 static __init void s3c_gpiolib_track(struct samsung_gpio_chip *chip) in s3c_gpiolib_track() argument
484 gpn = chip->chip.base; in s3c_gpiolib_track()
485 for (i = 0; i < chip->chip.ngpio; i++, gpn++) { in s3c_gpiolib_track()
487 s3c_gpios[gpn] = chip; in s3c_gpiolib_track()
493 * samsung_gpiolib_add() - add the Samsung gpio_chip.
494 * @chip: The chip to register
496 * This is a wrapper to gpiochip_add() that takes our specific gpio chip
502 static void __init samsung_gpiolib_add(struct samsung_gpio_chip *chip) in samsung_gpiolib_add() argument
504 struct gpio_chip *gc = &chip->chip; in samsung_gpiolib_add()
507 BUG_ON(!chip->base); in samsung_gpiolib_add()
508 BUG_ON(!gc->label); in samsung_gpiolib_add()
509 BUG_ON(!gc->ngpio); in samsung_gpiolib_add()
511 spin_lock_init(&chip->lock); in samsung_gpiolib_add()
513 if (!gc->direction_input) in samsung_gpiolib_add()
514 gc->direction_input = samsung_gpiolib_2bit_input; in samsung_gpiolib_add()
515 if (!gc->direction_output) in samsung_gpiolib_add()
516 gc->direction_output = samsung_gpiolib_2bit_output; in samsung_gpiolib_add()
517 if (!gc->set) in samsung_gpiolib_add()
518 gc->set = samsung_gpiolib_set; in samsung_gpiolib_add()
519 if (!gc->get) in samsung_gpiolib_add()
520 gc->get = samsung_gpiolib_get; in samsung_gpiolib_add()
523 if (chip->pm != NULL) { in samsung_gpiolib_add()
524 if (!chip->pm->save || !chip->pm->resume) in samsung_gpiolib_add()
526 gc->label); in samsung_gpiolib_add()
528 pr_err("gpio: %s has no PM function\n", gc->label); in samsung_gpiolib_add()
532 ret = gpiochip_add_data(gc, chip); in samsung_gpiolib_add()
534 s3c_gpiolib_track(chip); in samsung_gpiolib_add()
537 static void __init samsung_gpiolib_add_2bit_chips(struct samsung_gpio_chip *chip, in samsung_gpiolib_add_2bit_chips() argument
543 for (i = 0 ; i < nr_chips; i++, chip++) { in samsung_gpiolib_add_2bit_chips()
544 chip->chip.direction_input = samsung_gpiolib_2bit_input; in samsung_gpiolib_add_2bit_chips()
545 chip->chip.direction_output = samsung_gpiolib_2bit_output; in samsung_gpiolib_add_2bit_chips()
547 if (!chip->config) in samsung_gpiolib_add_2bit_chips()
548 chip->config = &samsung_gpio_cfgs[7]; in samsung_gpiolib_add_2bit_chips()
549 if (!chip->pm) in samsung_gpiolib_add_2bit_chips()
550 chip->pm = __gpio_pm(&samsung_gpio_pm_2bit); in samsung_gpiolib_add_2bit_chips()
551 if ((base != NULL) && (chip->base == NULL)) in samsung_gpiolib_add_2bit_chips()
552 chip->base = base + ((i) * offset); in samsung_gpiolib_add_2bit_chips()
554 samsung_gpiolib_add(chip); in samsung_gpiolib_add_2bit_chips()
559 * samsung_gpiolib_add_4bit_chips - 4bit single register GPIO config.
560 * @chip: The gpio chip that is being configured.
574 static void __init samsung_gpiolib_add_4bit_chips(struct samsung_gpio_chip *chip, in samsung_gpiolib_add_4bit_chips() argument
579 for (i = 0 ; i < nr_chips; i++, chip++) { in samsung_gpiolib_add_4bit_chips()
580 chip->chip.direction_input = samsung_gpiolib_4bit_input; in samsung_gpiolib_add_4bit_chips()
581 chip->chip.direction_output = samsung_gpiolib_4bit_output; in samsung_gpiolib_add_4bit_chips()
583 if (!chip->config) in samsung_gpiolib_add_4bit_chips()
584 chip->config = &samsung_gpio_cfgs[2]; in samsung_gpiolib_add_4bit_chips()
585 if (!chip->pm) in samsung_gpiolib_add_4bit_chips()
586 chip->pm = __gpio_pm(&samsung_gpio_pm_4bit); in samsung_gpiolib_add_4bit_chips()
587 if ((base != NULL) && (chip->base == NULL)) in samsung_gpiolib_add_4bit_chips()
588 chip->base = base + ((i) * 0x20); in samsung_gpiolib_add_4bit_chips()
590 chip->bitmap_gpio_int = 0; in samsung_gpiolib_add_4bit_chips()
592 samsung_gpiolib_add(chip); in samsung_gpiolib_add_4bit_chips()
596 static void __init samsung_gpiolib_add_4bit2_chips(struct samsung_gpio_chip *chip, in samsung_gpiolib_add_4bit2_chips() argument
599 for (; nr_chips > 0; nr_chips--, chip++) { in samsung_gpiolib_add_4bit2_chips()
600 chip->chip.direction_input = samsung_gpiolib_4bit2_input; in samsung_gpiolib_add_4bit2_chips()
601 chip->chip.direction_output = samsung_gpiolib_4bit2_output; in samsung_gpiolib_add_4bit2_chips()
603 if (!chip->config) in samsung_gpiolib_add_4bit2_chips()
604 chip->config = &samsung_gpio_cfgs[2]; in samsung_gpiolib_add_4bit2_chips()
605 if (!chip->pm) in samsung_gpiolib_add_4bit2_chips()
606 chip->pm = __gpio_pm(&samsung_gpio_pm_4bit); in samsung_gpiolib_add_4bit2_chips()
608 samsung_gpiolib_add(chip); in samsung_gpiolib_add_4bit2_chips()
612 int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset) in samsung_gpiolib_to_irq() argument
614 struct samsung_gpio_chip *samsung_chip = gpiochip_get_data(chip); in samsung_gpiolib_to_irq()
616 return samsung_chip->irq_base + offset; in samsung_gpiolib_to_irq()
619 static int s3c64xx_gpiolib_mbank_to_irq(struct gpio_chip *chip, unsigned pin) in s3c64xx_gpiolib_mbank_to_irq() argument
621 return pin < 5 ? IRQ_EINT(23) + pin : -ENXIO; in s3c64xx_gpiolib_mbank_to_irq()
624 static int s3c64xx_gpiolib_lbank_to_irq(struct gpio_chip *chip, unsigned pin) in s3c64xx_gpiolib_lbank_to_irq() argument
626 return pin >= 8 ? IRQ_EINT(16) + pin - 8 : -ENXIO; in s3c64xx_gpiolib_lbank_to_irq()
657 .chip = {
663 .chip = {
669 .chip = {
675 .chip = {
682 .chip = {
689 .chip = {
697 .chip = {
709 .chip = {
717 .chip = {
725 .chip = {
738 .chip = {
745 .chip = {
752 .chip = {
759 .chip = {
766 .chip = {
773 .chip = {
782 .chip = {
797 * pinctrl-samsung driver is used, providing both GPIO and pin control in samsung_gpiolib_init()
798 * interfaces. For legacy (non-DT) platforms this driver is used. in samsung_gpiolib_init()
822 struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin); in s3c_gpio_cfgpin() local
827 if (!chip) in s3c_gpio_cfgpin()
828 return -EINVAL; in s3c_gpio_cfgpin()
830 offset = pin - chip->chip.base; in s3c_gpio_cfgpin()
832 samsung_gpio_lock(chip, flags); in s3c_gpio_cfgpin()
833 ret = samsung_gpio_do_setcfg(chip, offset, config); in s3c_gpio_cfgpin()
834 samsung_gpio_unlock(chip, flags); in s3c_gpio_cfgpin()
845 for (; nr > 0; nr--, start++) { in s3c_gpio_cfgpin_range()
860 for (; nr > 0; nr--, start++) { in s3c_gpio_cfgall_range()
873 struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin); in s3c_gpio_setpull() local
877 if (!chip) in s3c_gpio_setpull()
878 return -EINVAL; in s3c_gpio_setpull()
880 offset = pin - chip->chip.base; in s3c_gpio_setpull()
882 samsung_gpio_lock(chip, flags); in s3c_gpio_setpull()
883 ret = samsung_gpio_do_setpull(chip, offset, pull); in s3c_gpio_setpull()
884 samsung_gpio_unlock(chip, flags); in s3c_gpio_setpull()