Lines Matching +full:reg +full:- +full:offset

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2007-2009 Andres Salomon <dilinger@collabora.co.uk>
17 #define DRV_NAME "cs5535-gpio"
21 * 31-29,23 : reserved (always mask out)
24 * 22-16 : LPC
44 * design pattern, see Documentation/driver-api/driver-model/design-patterns.rst
61 unsigned int reg) in errata_outl() argument
63 unsigned long addr = chip->base + 0x80 + reg; in errata_outl()
68 * non-selected bits; the recommended workaround is a in errata_outl()
69 * read-modify-write operation. in errata_outl()
74 if (reg != GPIO_POSITIVE_EDGE_STS && reg != GPIO_NEGATIVE_EDGE_STS) { in errata_outl()
83 static void __cs5535_gpio_set(struct cs5535_gpio_chip *chip, unsigned offset, in __cs5535_gpio_set() argument
84 unsigned int reg) in __cs5535_gpio_set() argument
86 if (offset < 16) in __cs5535_gpio_set()
88 outl(1 << offset, chip->base + reg); in __cs5535_gpio_set()
91 errata_outl(chip, 1 << (offset - 16), reg); in __cs5535_gpio_set()
94 void cs5535_gpio_set(unsigned offset, unsigned int reg) in cs5535_gpio_set() argument
99 spin_lock_irqsave(&chip->lock, flags); in cs5535_gpio_set()
100 __cs5535_gpio_set(chip, offset, reg); in cs5535_gpio_set()
101 spin_unlock_irqrestore(&chip->lock, flags); in cs5535_gpio_set()
105 static void __cs5535_gpio_clear(struct cs5535_gpio_chip *chip, unsigned offset, in __cs5535_gpio_clear() argument
106 unsigned int reg) in __cs5535_gpio_clear() argument
108 if (offset < 16) in __cs5535_gpio_clear()
110 outl(1 << (offset + 16), chip->base + reg); in __cs5535_gpio_clear()
113 errata_outl(chip, 1 << offset, reg); in __cs5535_gpio_clear()
116 void cs5535_gpio_clear(unsigned offset, unsigned int reg) in cs5535_gpio_clear() argument
121 spin_lock_irqsave(&chip->lock, flags); in cs5535_gpio_clear()
122 __cs5535_gpio_clear(chip, offset, reg); in cs5535_gpio_clear()
123 spin_unlock_irqrestore(&chip->lock, flags); in cs5535_gpio_clear()
127 int cs5535_gpio_isset(unsigned offset, unsigned int reg) in cs5535_gpio_isset() argument
133 spin_lock_irqsave(&chip->lock, flags); in cs5535_gpio_isset()
134 if (offset < 16) in cs5535_gpio_isset()
136 val = inl(chip->base + reg); in cs5535_gpio_isset()
139 val = inl(chip->base + 0x80 + reg); in cs5535_gpio_isset()
140 offset -= 16; in cs5535_gpio_isset()
142 spin_unlock_irqrestore(&chip->lock, flags); in cs5535_gpio_isset()
144 return (val & (1 << offset)) ? 1 : 0; in cs5535_gpio_isset()
153 return -EINVAL; in cs5535_gpio_set_irq()
165 void cs5535_gpio_setup_event(unsigned offset, int pair, int pme) in cs5535_gpio_setup_event() argument
168 uint32_t shift = (offset % 8) * 4; in cs5535_gpio_setup_event()
172 if (offset >= 24) in cs5535_gpio_setup_event()
173 offset = GPIO_MAP_W; in cs5535_gpio_setup_event()
174 else if (offset >= 16) in cs5535_gpio_setup_event()
175 offset = GPIO_MAP_Z; in cs5535_gpio_setup_event()
176 else if (offset >= 8) in cs5535_gpio_setup_event()
177 offset = GPIO_MAP_Y; in cs5535_gpio_setup_event()
179 offset = GPIO_MAP_X; in cs5535_gpio_setup_event()
181 spin_lock_irqsave(&chip->lock, flags); in cs5535_gpio_setup_event()
182 val = inl(chip->base + offset); in cs5535_gpio_setup_event()
194 outl(val, chip->base + offset); in cs5535_gpio_setup_event()
195 spin_unlock_irqrestore(&chip->lock, flags); in cs5535_gpio_setup_event()
203 static int chip_gpio_request(struct gpio_chip *c, unsigned offset) in chip_gpio_request() argument
208 spin_lock_irqsave(&chip->lock, flags); in chip_gpio_request()
211 if ((mask & (1 << offset)) == 0) { in chip_gpio_request()
212 dev_info(&chip->pdev->dev, in chip_gpio_request()
213 "pin %u is not available (check mask)\n", offset); in chip_gpio_request()
214 spin_unlock_irqrestore(&chip->lock, flags); in chip_gpio_request()
215 return -EINVAL; in chip_gpio_request()
219 __cs5535_gpio_clear(chip, offset, GPIO_OUTPUT_AUX1); in chip_gpio_request()
220 __cs5535_gpio_clear(chip, offset, GPIO_OUTPUT_AUX2); in chip_gpio_request()
223 __cs5535_gpio_clear(chip, offset, GPIO_INPUT_AUX1); in chip_gpio_request()
225 spin_unlock_irqrestore(&chip->lock, flags); in chip_gpio_request()
230 static int chip_gpio_get(struct gpio_chip *chip, unsigned offset) in chip_gpio_get() argument
232 return cs5535_gpio_isset(offset, GPIO_READ_BACK); in chip_gpio_get()
235 static void chip_gpio_set(struct gpio_chip *chip, unsigned offset, int val) in chip_gpio_set() argument
238 cs5535_gpio_set(offset, GPIO_OUTPUT_VAL); in chip_gpio_set()
240 cs5535_gpio_clear(offset, GPIO_OUTPUT_VAL); in chip_gpio_set()
243 static int chip_direction_input(struct gpio_chip *c, unsigned offset) in chip_direction_input() argument
248 spin_lock_irqsave(&chip->lock, flags); in chip_direction_input()
249 __cs5535_gpio_set(chip, offset, GPIO_INPUT_ENABLE); in chip_direction_input()
250 __cs5535_gpio_clear(chip, offset, GPIO_OUTPUT_ENABLE); in chip_direction_input()
251 spin_unlock_irqrestore(&chip->lock, flags); in chip_direction_input()
256 static int chip_direction_output(struct gpio_chip *c, unsigned offset, int val) in chip_direction_output() argument
261 spin_lock_irqsave(&chip->lock, flags); in chip_direction_output()
263 __cs5535_gpio_set(chip, offset, GPIO_INPUT_ENABLE); in chip_direction_output()
264 __cs5535_gpio_set(chip, offset, GPIO_OUTPUT_ENABLE); in chip_direction_output()
266 __cs5535_gpio_set(chip, offset, GPIO_OUTPUT_VAL); in chip_direction_output()
268 __cs5535_gpio_clear(chip, offset, GPIO_OUTPUT_VAL); in chip_direction_output()
270 spin_unlock_irqrestore(&chip->lock, flags); in chip_direction_output()
307 int err = -EIO; in cs5535_gpio_probe()
319 dev_err(&pdev->dev, "can't fetch device resource info\n"); in cs5535_gpio_probe()
323 if (!devm_request_region(&pdev->dev, res->start, resource_size(res), in cs5535_gpio_probe()
324 pdev->name)) { in cs5535_gpio_probe()
325 dev_err(&pdev->dev, "can't request region\n"); in cs5535_gpio_probe()
329 /* set up the driver-specific struct */ in cs5535_gpio_probe()
330 cs5535_gpio_chip.base = res->start; in cs5535_gpio_probe()
334 dev_info(&pdev->dev, "reserved resource region %pR\n", res); in cs5535_gpio_probe()
344 dev_info(&pdev->dev, "mask changed from 0x%08lX to 0x%08lX\n", in cs5535_gpio_probe()
348 return devm_gpiochip_add_data(&pdev->dev, &cs5535_gpio_chip.chip, in cs5535_gpio_probe()