Lines Matching +full:reg +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0-only
26 static int palmas_gpio_get(struct gpio_chip *gc, unsigned offset) in palmas_gpio_get() argument
29 struct palmas *palmas = pg->palmas; in palmas_gpio_get()
32 unsigned int reg; in palmas_gpio_get() local
33 int gpio16 = (offset/8); in palmas_gpio_get()
35 offset %= 8; in palmas_gpio_get()
36 reg = (gpio16) ? PALMAS_GPIO_DATA_DIR2 : PALMAS_GPIO_DATA_DIR; in palmas_gpio_get()
38 ret = palmas_read(palmas, PALMAS_GPIO_BASE, reg, &val); in palmas_gpio_get()
40 dev_err(gc->parent, "Reg 0x%02x read failed, %d\n", reg, ret); in palmas_gpio_get()
44 if (val & BIT(offset)) in palmas_gpio_get()
45 reg = (gpio16) ? PALMAS_GPIO_DATA_OUT2 : PALMAS_GPIO_DATA_OUT; in palmas_gpio_get()
47 reg = (gpio16) ? PALMAS_GPIO_DATA_IN2 : PALMAS_GPIO_DATA_IN; in palmas_gpio_get()
49 ret = palmas_read(palmas, PALMAS_GPIO_BASE, reg, &val); in palmas_gpio_get()
51 dev_err(gc->parent, "Reg 0x%02x read failed, %d\n", reg, ret); in palmas_gpio_get()
54 return !!(val & BIT(offset)); in palmas_gpio_get()
57 static void palmas_gpio_set(struct gpio_chip *gc, unsigned offset, in palmas_gpio_set() argument
61 struct palmas *palmas = pg->palmas; in palmas_gpio_set()
63 unsigned int reg; in palmas_gpio_set() local
64 int gpio16 = (offset/8); in palmas_gpio_set()
66 offset %= 8; in palmas_gpio_set()
68 reg = (value) ? in palmas_gpio_set()
71 reg = (value) ? in palmas_gpio_set()
74 ret = palmas_write(palmas, PALMAS_GPIO_BASE, reg, BIT(offset)); in palmas_gpio_set()
76 dev_err(gc->parent, "Reg 0x%02x write failed, %d\n", reg, ret); in palmas_gpio_set()
79 static int palmas_gpio_output(struct gpio_chip *gc, unsigned offset, in palmas_gpio_output() argument
83 struct palmas *palmas = pg->palmas; in palmas_gpio_output()
85 unsigned int reg; in palmas_gpio_output() local
86 int gpio16 = (offset/8); in palmas_gpio_output()
88 offset %= 8; in palmas_gpio_output()
89 reg = (gpio16) ? PALMAS_GPIO_DATA_DIR2 : PALMAS_GPIO_DATA_DIR; in palmas_gpio_output()
92 palmas_gpio_set(gc, offset, value); in palmas_gpio_output()
94 ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE, reg, in palmas_gpio_output()
95 BIT(offset), BIT(offset)); in palmas_gpio_output()
97 dev_err(gc->parent, "Reg 0x%02x update failed, %d\n", reg, in palmas_gpio_output()
102 static int palmas_gpio_input(struct gpio_chip *gc, unsigned offset) in palmas_gpio_input() argument
105 struct palmas *palmas = pg->palmas; in palmas_gpio_input()
107 unsigned int reg; in palmas_gpio_input() local
108 int gpio16 = (offset/8); in palmas_gpio_input()
110 offset %= 8; in palmas_gpio_input()
111 reg = (gpio16) ? PALMAS_GPIO_DATA_DIR2 : PALMAS_GPIO_DATA_DIR; in palmas_gpio_input()
113 ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE, reg, BIT(offset), 0); in palmas_gpio_input()
115 dev_err(gc->parent, "Reg 0x%02x update failed, %d\n", reg, in palmas_gpio_input()
120 static int palmas_gpio_to_irq(struct gpio_chip *gc, unsigned offset) in palmas_gpio_to_irq() argument
123 struct palmas *palmas = pg->palmas; in palmas_gpio_to_irq()
125 return palmas_irq_get_virq(palmas, PALMAS_GPIO_0_IRQ + offset); in palmas_gpio_to_irq()
137 { .compatible = "ti,palmas-gpio", .data = &palmas_dev_data,},
138 { .compatible = "ti,tps65913-gpio", .data = &palmas_dev_data,},
139 { .compatible = "ti,tps65914-gpio", .data = &palmas_dev_data,},
140 { .compatible = "ti,tps80036-gpio", .data = &tps80036_dev_data,},
146 struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); in palmas_gpio_probe()
152 dev_data = of_device_get_match_data(&pdev->dev); in palmas_gpio_probe()
156 palmas_gpio = devm_kzalloc(&pdev->dev, in palmas_gpio_probe()
159 return -ENOMEM; in palmas_gpio_probe()
161 palmas_gpio->palmas = palmas; in palmas_gpio_probe()
162 palmas_gpio->gpio_chip.owner = THIS_MODULE; in palmas_gpio_probe()
163 palmas_gpio->gpio_chip.label = dev_name(&pdev->dev); in palmas_gpio_probe()
164 palmas_gpio->gpio_chip.ngpio = dev_data->ngpio; in palmas_gpio_probe()
165 palmas_gpio->gpio_chip.can_sleep = true; in palmas_gpio_probe()
166 palmas_gpio->gpio_chip.direction_input = palmas_gpio_input; in palmas_gpio_probe()
167 palmas_gpio->gpio_chip.direction_output = palmas_gpio_output; in palmas_gpio_probe()
168 palmas_gpio->gpio_chip.to_irq = palmas_gpio_to_irq; in palmas_gpio_probe()
169 palmas_gpio->gpio_chip.set = palmas_gpio_set; in palmas_gpio_probe()
170 palmas_gpio->gpio_chip.get = palmas_gpio_get; in palmas_gpio_probe()
171 palmas_gpio->gpio_chip.parent = &pdev->dev; in palmas_gpio_probe()
173 palmas_pdata = dev_get_platdata(palmas->dev); in palmas_gpio_probe()
174 if (palmas_pdata && palmas_pdata->gpio_base) in palmas_gpio_probe()
175 palmas_gpio->gpio_chip.base = palmas_pdata->gpio_base; in palmas_gpio_probe()
177 palmas_gpio->gpio_chip.base = -1; in palmas_gpio_probe()
179 ret = devm_gpiochip_add_data(&pdev->dev, &palmas_gpio->gpio_chip, in palmas_gpio_probe()
182 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); in palmas_gpio_probe()
190 .driver.name = "palmas-gpio",