Lines Matching +full:nr +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0-or-later
17 (c) 1999-2002 Gerd Knorr
23 (c) 2005-2006 Nickolay V. Shmyrev
60 #define bgwrite(dat, adr) writel((dat), bg->mmio+(adr))
61 #define bgread(adr) readl(bg->mmio+(adr))
64 static int modparam_gpiobase = -1/* dynamic */;
66 MODULE_PARM_DESC(gpiobase, "The GPIO number base. -1 means dynamic, which is the default.");
69 static int bt8xxgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) in bt8xxgpio_gpio_direction_input() argument
75 spin_lock_irqsave(&bg->lock, flags); in bt8xxgpio_gpio_direction_input()
78 data &= ~(1 << nr); in bt8xxgpio_gpio_direction_input()
82 outen &= ~(1 << nr); in bt8xxgpio_gpio_direction_input()
85 spin_unlock_irqrestore(&bg->lock, flags); in bt8xxgpio_gpio_direction_input()
90 static int bt8xxgpio_gpio_get(struct gpio_chip *gpio, unsigned nr) in bt8xxgpio_gpio_get() argument
96 spin_lock_irqsave(&bg->lock, flags); in bt8xxgpio_gpio_get()
98 spin_unlock_irqrestore(&bg->lock, flags); in bt8xxgpio_gpio_get()
100 return !!(val & (1 << nr)); in bt8xxgpio_gpio_get()
104 unsigned nr, int val) in bt8xxgpio_gpio_direction_output() argument
110 spin_lock_irqsave(&bg->lock, flags); in bt8xxgpio_gpio_direction_output()
113 outen |= (1 << nr); in bt8xxgpio_gpio_direction_output()
118 data |= (1 << nr); in bt8xxgpio_gpio_direction_output()
120 data &= ~(1 << nr); in bt8xxgpio_gpio_direction_output()
123 spin_unlock_irqrestore(&bg->lock, flags); in bt8xxgpio_gpio_direction_output()
129 unsigned nr, int val) in bt8xxgpio_gpio_set() argument
135 spin_lock_irqsave(&bg->lock, flags); in bt8xxgpio_gpio_set()
139 data |= (1 << nr); in bt8xxgpio_gpio_set()
141 data &= ~(1 << nr); in bt8xxgpio_gpio_set()
144 spin_unlock_irqrestore(&bg->lock, flags); in bt8xxgpio_gpio_set()
149 struct gpio_chip *c = &bg->gpio; in bt8xxgpio_gpio_setup()
151 c->label = dev_name(&bg->pdev->dev); in bt8xxgpio_gpio_setup()
152 c->owner = THIS_MODULE; in bt8xxgpio_gpio_setup()
153 c->direction_input = bt8xxgpio_gpio_direction_input; in bt8xxgpio_gpio_setup()
154 c->get = bt8xxgpio_gpio_get; in bt8xxgpio_gpio_setup()
155 c->direction_output = bt8xxgpio_gpio_direction_output; in bt8xxgpio_gpio_setup()
156 c->set = bt8xxgpio_gpio_set; in bt8xxgpio_gpio_setup()
157 c->dbg_show = NULL; in bt8xxgpio_gpio_setup()
158 c->base = modparam_gpiobase; in bt8xxgpio_gpio_setup()
159 c->ngpio = BT8XXGPIO_NR_GPIOS; in bt8xxgpio_gpio_setup()
160 c->can_sleep = false; in bt8xxgpio_gpio_setup()
169 bg = devm_kzalloc(&dev->dev, sizeof(struct bt8xxgpio), GFP_KERNEL); in bt8xxgpio_probe()
171 return -ENOMEM; in bt8xxgpio_probe()
173 bg->pdev = dev; in bt8xxgpio_probe()
174 spin_lock_init(&bg->lock); in bt8xxgpio_probe()
178 dev_err(&dev->dev, "can't enable device.\n"); in bt8xxgpio_probe()
181 if (!devm_request_mem_region(&dev->dev, pci_resource_start(dev, 0), in bt8xxgpio_probe()
184 dev_warn(&dev->dev, "can't request iomem (0x%llx).\n", in bt8xxgpio_probe()
186 err = -EBUSY; in bt8xxgpio_probe()
192 bg->mmio = devm_ioremap(&dev->dev, pci_resource_start(dev, 0), 0x1000); in bt8xxgpio_probe()
193 if (!bg->mmio) { in bt8xxgpio_probe()
194 dev_err(&dev->dev, "ioremap() failed\n"); in bt8xxgpio_probe()
195 err = -EIO; in bt8xxgpio_probe()
208 err = gpiochip_add_data(&bg->gpio, bg); in bt8xxgpio_probe()
210 dev_err(&dev->dev, "failed to register GPIOs\n"); in bt8xxgpio_probe()
226 gpiochip_remove(&bg->gpio); in bt8xxgpio_remove()
241 spin_lock_irqsave(&bg->lock, flags); in bt8xxgpio_suspend()
243 bg->saved_outen = bgread(BT848_GPIO_OUT_EN); in bt8xxgpio_suspend()
244 bg->saved_data = bgread(BT848_GPIO_DATA); in bt8xxgpio_suspend()
250 spin_unlock_irqrestore(&bg->lock, flags); in bt8xxgpio_suspend()
271 spin_lock_irqsave(&bg->lock, flags); in bt8xxgpio_resume()
276 bgwrite(bg->saved_outen, BT848_GPIO_OUT_EN); in bt8xxgpio_resume()
277 bgwrite(bg->saved_data & bg->saved_outen, in bt8xxgpio_resume()
280 spin_unlock_irqrestore(&bg->lock, flags); in bt8xxgpio_resume()