Lines Matching +full:pctl +full:- +full:regmap

1 // SPDX-License-Identifier: GPL-2.0
7 * - add pinmux and pinctrl support (gpio alternate mode)
10 * [1] https://www.dialog-semiconductor.com/sites/default/files/da9062_datasheet_3v6.pdf
18 #include <linux/regmap.h>
27 * the gpio is active low without a vendor specific dt-binding.
35 #define DA9062_PIN_GPO_OD 0x02 /* gpio out open-drain */
36 #define DA9062_PIN_GPO_PP 0x03 /* gpio out push-pull */
45 static int da9062_pctl_get_pin_mode(struct da9062_pctl *pctl, in da9062_pctl_get_pin_mode() argument
48 struct regmap *regmap = pctl->da9062->regmap; in da9062_pctl_get_pin_mode() local
51 ret = regmap_read(regmap, DA9062AA_GPIO_0_1 + (offset >> 1), &val); in da9062_pctl_get_pin_mode()
61 static int da9062_pctl_set_pin_mode(struct da9062_pctl *pctl, in da9062_pctl_set_pin_mode() argument
64 struct regmap *regmap = pctl->da9062->regmap; in da9062_pctl_set_pin_mode() local
73 ret = regmap_update_bits(regmap, DA9062AA_GPIO_0_1 + (offset >> 1), in da9062_pctl_set_pin_mode()
76 pctl->pin_config[offset] = mode_req; in da9062_pctl_set_pin_mode()
83 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_get() local
84 struct regmap *regmap = pctl->da9062->regmap; in da9062_gpio_get() local
88 gpio_mode = da9062_pctl_get_pin_mode(pctl, offset); in da9062_gpio_get()
94 return -ENOTSUPP; in da9062_gpio_get()
96 ret = regmap_read(regmap, DA9062AA_STATUS_B, &val); in da9062_gpio_get()
102 ret = regmap_read(regmap, DA9062AA_GPIO_MODE0_4, &val); in da9062_gpio_get()
113 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_set() local
114 struct regmap *regmap = pctl->da9062->regmap; in da9062_gpio_set() local
116 regmap_update_bits(regmap, DA9062AA_GPIO_MODE0_4, BIT(offset), in da9062_gpio_set()
122 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_get_direction() local
125 gpio_mode = da9062_pctl_get_pin_mode(pctl, offset); in da9062_gpio_get_direction()
131 return -ENOTSUPP; in da9062_gpio_get_direction()
139 return -EINVAL; in da9062_gpio_get_direction()
145 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_direction_input() local
146 struct regmap *regmap = pctl->da9062->regmap; in da9062_gpio_direction_input() local
151 ret = da9062_pctl_set_pin_mode(pctl, offset, DA9062_PIN_GPI); in da9062_gpio_direction_input()
157 * about gpio_get() because we read and return the gpio-level. So the in da9062_gpio_direction_input()
160 * 0 - active low, 1 - active high in da9062_gpio_direction_input()
164 return regmap_update_bits(regmap, DA9062AA_GPIO_0_1 + (offset >> 1), in da9062_gpio_direction_input()
172 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_direction_output() local
173 unsigned int pin_config = pctl->pin_config[offset]; in da9062_gpio_direction_output()
176 ret = da9062_pctl_set_pin_mode(pctl, offset, pin_config); in da9062_gpio_direction_output()
188 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_set_config() local
189 struct regmap *regmap = pctl->da9062->regmap; in da9062_gpio_set_config() local
194 * - PIN_CONFIG_BIAS_PULL_DOWN -> only allowed if the pin is used as in da9062_gpio_set_config()
196 * - PIN_CONFIG_BIAS_PULL_UP -> only allowed if the pin is used as in da9062_gpio_set_config()
197 * gpio output open-drain. in da9062_gpio_set_config()
202 return regmap_update_bits(regmap, DA9062AA_CONFIG_K, in da9062_gpio_set_config()
205 gpio_mode = da9062_pctl_get_pin_mode(pctl, offset); in da9062_gpio_set_config()
207 return -EINVAL; in da9062_gpio_set_config()
209 return -ENOTSUPP; in da9062_gpio_set_config()
210 return regmap_update_bits(regmap, DA9062AA_CONFIG_K, in da9062_gpio_set_config()
213 gpio_mode = da9062_pctl_get_pin_mode(pctl, offset); in da9062_gpio_set_config()
215 return -EINVAL; in da9062_gpio_set_config()
217 return -ENOTSUPP; in da9062_gpio_set_config()
218 return regmap_update_bits(regmap, DA9062AA_CONFIG_K, in da9062_gpio_set_config()
221 return da9062_pctl_set_pin_mode(pctl, offset, in da9062_gpio_set_config()
224 return da9062_pctl_set_pin_mode(pctl, offset, in da9062_gpio_set_config()
227 return -ENOTSUPP; in da9062_gpio_set_config()
233 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_to_irq() local
234 struct da9062 *da9062 = pctl->da9062; in da9062_gpio_to_irq()
236 return regmap_irq_get_virq(da9062->regmap_irq, in da9062_gpio_to_irq()
251 .base = -1,
256 struct device *parent = pdev->dev.parent; in da9062_pctl_probe()
257 struct da9062_pctl *pctl; in da9062_pctl_probe() local
260 device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent)); in da9062_pctl_probe()
262 pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); in da9062_pctl_probe()
263 if (!pctl) in da9062_pctl_probe()
264 return -ENOMEM; in da9062_pctl_probe()
266 pctl->da9062 = dev_get_drvdata(parent); in da9062_pctl_probe()
267 if (!pctl->da9062) in da9062_pctl_probe()
268 return -EINVAL; in da9062_pctl_probe()
270 if (!device_property_present(parent, "gpio-controller")) in da9062_pctl_probe()
273 for (i = 0; i < ARRAY_SIZE(pctl->pin_config); i++) in da9062_pctl_probe()
274 pctl->pin_config[i] = DA9062_PIN_GPO_PP; in da9062_pctl_probe()
280 pctl->gc = reference_gc; in da9062_pctl_probe()
281 pctl->gc.label = dev_name(&pdev->dev); in da9062_pctl_probe()
282 pctl->gc.parent = &pdev->dev; in da9062_pctl_probe()
284 platform_set_drvdata(pdev, pctl); in da9062_pctl_probe()
286 return devm_gpiochip_add_data(&pdev->dev, &pctl->gc, pctl); in da9062_pctl_probe()
292 .name = "da9062-gpio",
300 MODULE_ALIAS("platform:da9062-gpio");