Lines Matching +full:gpio +full:- +full:latch
1 // SPDX-License-Identifier: GPL-2.0-only
3 * gpio-reg: single register individually fixed-direction GPIOs
18 #include <linux/gpio/driver.h>
19 #include <linux/gpio/gpio-reg.h>
37 return r->direction & BIT(offset) ? GPIO_LINE_DIRECTION_IN : in gpio_reg_get_direction()
46 if (r->direction & BIT(offset)) in gpio_reg_direction_output()
47 return -ENOTSUPP; in gpio_reg_direction_output()
49 gc->set(gc, offset, value); in gpio_reg_direction_output()
57 return r->direction & BIT(offset) ? 0 : -ENOTSUPP; in gpio_reg_direction_input()
66 spin_lock_irqsave(&r->lock, flags); in gpio_reg_set()
67 val = r->out; in gpio_reg_set()
72 r->out = val; in gpio_reg_set()
73 writel_relaxed(val, r->reg); in gpio_reg_set()
74 spin_unlock_irqrestore(&r->lock, flags); in gpio_reg_set()
82 if (r->direction & mask) { in gpio_reg_get()
84 * double-read the value, some registers latch after the in gpio_reg_get()
87 readl_relaxed(r->reg); in gpio_reg_get()
88 val = readl_relaxed(r->reg); in gpio_reg_get()
90 val = r->out; in gpio_reg_get()
101 spin_lock_irqsave(&r->lock, flags); in gpio_reg_set_multiple()
102 r->out = (r->out & ~*mask) | (*bits & *mask); in gpio_reg_set_multiple()
103 writel_relaxed(r->out, r->reg); in gpio_reg_set_multiple()
104 spin_unlock_irqrestore(&r->lock, flags); in gpio_reg_set_multiple()
110 int irq = r->irqs[offset]; in gpio_reg_to_irq()
112 if (irq >= 0 && r->irqdomain) in gpio_reg_to_irq()
113 irq = irq_find_mapping(r->irqdomain, irq); in gpio_reg_to_irq()
119 * gpio_reg_init - add a fixed in/out register as gpio
121 * @base: start gpio number, or -1 to allocate
123 * @label: GPIO chip label
124 * @direction: bitmask of fixed direction, one per GPIO signal, 1 = in
125 * @def_out: initial GPIO output value
126 * @names: array of %num strings describing each GPIO signal or %NULL
129 * GPIO signal, or %NULL. If @irqdom is %NULL, then this
133 * Add a single-register GPIO device containing up to 32 GPIO signals,
134 * where each GPIO has a fixed input or output configuration. Only
136 * then after a double-read. Output values are assumed not to be
152 return ERR_PTR(-ENOMEM); in gpio_reg_init()
154 spin_lock_init(&r->lock); in gpio_reg_init()
156 r->gc.label = label; in gpio_reg_init()
157 r->gc.get_direction = gpio_reg_get_direction; in gpio_reg_init()
158 r->gc.direction_input = gpio_reg_direction_input; in gpio_reg_init()
159 r->gc.direction_output = gpio_reg_direction_output; in gpio_reg_init()
160 r->gc.set = gpio_reg_set; in gpio_reg_init()
161 r->gc.get = gpio_reg_get; in gpio_reg_init()
162 r->gc.set_multiple = gpio_reg_set_multiple; in gpio_reg_init()
164 r->gc.to_irq = gpio_reg_to_irq; in gpio_reg_init()
165 r->gc.base = base; in gpio_reg_init()
166 r->gc.ngpio = num; in gpio_reg_init()
167 r->gc.names = names; in gpio_reg_init()
168 r->direction = direction; in gpio_reg_init()
169 r->out = def_out; in gpio_reg_init()
170 r->reg = reg; in gpio_reg_init()
171 r->irqs = irqs; in gpio_reg_init()
174 ret = devm_gpiochip_add_data(dev, &r->gc, r); in gpio_reg_init()
176 ret = gpiochip_add_data(&r->gc, r); in gpio_reg_init()
178 return ret ? ERR_PTR(ret) : &r->gc; in gpio_reg_init()
186 spin_lock_irqsave(&r->lock, flags); in gpio_reg_resume()
187 writel_relaxed(r->out, r->reg); in gpio_reg_resume()
188 spin_unlock_irqrestore(&r->lock, flags); in gpio_reg_resume()