Lines Matching +full:gpio +full:- +full:open +full:- +full:drain
1 // SPDX-License-Identifier: GPL-2.0+
3 * Linux GPIOlib driver for the VIA VX855 integrated southbridge GPIO
12 #include <linux/gpio/driver.h>
21 /* The VX855 south bridge has the following GPIO pins:
24 * GPIO 0...14 General Purpose I/O (Open-Drain)
35 struct gpio_chip gpio; member
74 /* Mapping between numeric GPIO ID and the actual GPIO hardware numbering:
77 * 27..41 GPIO 0..14
80 static int vx855gpio_direction_input(struct gpio_chip *gpio, in vx855gpio_direction_input() argument
83 struct vx855_gpio *vg = gpiochip_get_data(gpio); in vx855gpio_direction_input()
93 return -EINVAL; in vx855gpio_direction_input()
95 /* Open Drain GPIO have to be set to one */ in vx855gpio_direction_input()
96 spin_lock_irqsave(&vg->lock, flags); in vx855gpio_direction_input()
97 reg_out = inl(vg->io_gpo); in vx855gpio_direction_input()
98 reg_out |= gpio_o_bit(nr - NR_VX855_GPInO); in vx855gpio_direction_input()
99 outl(reg_out, vg->io_gpo); in vx855gpio_direction_input()
100 spin_unlock_irqrestore(&vg->lock, flags); in vx855gpio_direction_input()
105 static int vx855gpio_get(struct gpio_chip *gpio, unsigned int nr) in vx855gpio_get() argument
107 struct vx855_gpio *vg = gpiochip_get_data(gpio); in vx855gpio_get()
112 reg_in = inl(vg->io_gpi); in vx855gpio_get()
118 reg_in = inl(vg->io_gpo); in vx855gpio_get()
119 if (reg_in & gpo_o_bit(nr - NR_VX855_GPI)) in vx855gpio_get()
122 reg_in = inl(vg->io_gpi); in vx855gpio_get()
123 if (reg_in & gpio_i_bit(nr - NR_VX855_GPInO)) in vx855gpio_get()
130 static void vx855gpio_set(struct gpio_chip *gpio, unsigned int nr, in vx855gpio_set() argument
133 struct vx855_gpio *vg = gpiochip_get_data(gpio); in vx855gpio_set()
141 spin_lock_irqsave(&vg->lock, flags); in vx855gpio_set()
142 reg_out = inl(vg->io_gpo); in vx855gpio_set()
145 reg_out |= gpo_o_bit(nr - NR_VX855_GPI); in vx855gpio_set()
147 reg_out &= ~gpo_o_bit(nr - NR_VX855_GPI); in vx855gpio_set()
150 reg_out |= gpio_o_bit(nr - NR_VX855_GPInO); in vx855gpio_set()
152 reg_out &= ~gpio_o_bit(nr - NR_VX855_GPInO); in vx855gpio_set()
154 outl(reg_out, vg->io_gpo); in vx855gpio_set()
155 spin_unlock_irqrestore(&vg->lock, flags); in vx855gpio_set()
158 static int vx855gpio_direction_output(struct gpio_chip *gpio, in vx855gpio_direction_output() argument
163 return -EINVAL; in vx855gpio_direction_output()
166 * and GPIO are open-drain, i.e. also need no switching, in vx855gpio_direction_output()
168 vx855gpio_set(gpio, nr, val); in vx855gpio_direction_output()
173 static int vx855gpio_set_config(struct gpio_chip *gpio, unsigned int nr, in vx855gpio_set_config() argument
178 /* The GPI cannot be single-ended */ in vx855gpio_set_config()
180 return -EINVAL; in vx855gpio_set_config()
182 /* The GPO's are push-pull */ in vx855gpio_set_config()
185 return -ENOTSUPP; in vx855gpio_set_config()
189 /* The GPIO's are open drain */ in vx855gpio_set_config()
191 return -ENOTSUPP; in vx855gpio_set_config()
211 struct gpio_chip *c = &vg->gpio; in vx855gpio_gpio_setup()
213 c->label = "VX855 South Bridge"; in vx855gpio_gpio_setup()
214 c->owner = THIS_MODULE; in vx855gpio_gpio_setup()
215 c->direction_input = vx855gpio_direction_input; in vx855gpio_gpio_setup()
216 c->direction_output = vx855gpio_direction_output; in vx855gpio_gpio_setup()
217 c->get = vx855gpio_get; in vx855gpio_gpio_setup()
218 c->set = vx855gpio_set; in vx855gpio_gpio_setup()
219 c->set_config = vx855gpio_set_config; in vx855gpio_gpio_setup()
220 c->dbg_show = NULL; in vx855gpio_gpio_setup()
221 c->base = 0; in vx855gpio_gpio_setup()
222 c->ngpio = NR_VX855_GP; in vx855gpio_gpio_setup()
223 c->can_sleep = false; in vx855gpio_gpio_setup()
224 c->names = vx855gpio_names; in vx855gpio_gpio_setup()
237 return -EBUSY; in vx855gpio_probe()
239 vg = devm_kzalloc(&pdev->dev, sizeof(*vg), GFP_KERNEL); in vx855gpio_probe()
241 return -ENOMEM; in vx855gpio_probe()
243 dev_info(&pdev->dev, "found VX855 GPIO controller\n"); in vx855gpio_probe()
244 vg->io_gpi = res_gpi->start; in vx855gpio_probe()
245 vg->io_gpo = res_gpo->start; in vx855gpio_probe()
246 spin_lock_init(&vg->lock); in vx855gpio_probe()
249 * A single byte is used to control various GPIO ports on the VX855, in vx855gpio_probe()
250 * and in the case of the OLPC XO-1.5, some of those ports are used in vx855gpio_probe()
256 if (!devm_request_region(&pdev->dev, res_gpi->start, in vx855gpio_probe()
258 dev_warn(&pdev->dev, in vx855gpio_probe()
261 if (!devm_request_region(&pdev->dev, res_gpo->start, in vx855gpio_probe()
263 dev_warn(&pdev->dev, in vx855gpio_probe()
268 return devm_gpiochip_add_data(&pdev->dev, &vg->gpio, vg); in vx855gpio_probe()
282 MODULE_DESCRIPTION("GPIO driver for the VIA VX855 chipset");