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
17 #include <linux/regmap.h>
26 * the gpio is active low without a vendor specific dt-binding.
34 #define DA9062_PIN_GPO_OD 0x02 /* gpio out open-drain */
35 #define DA9062_PIN_GPO_PP 0x03 /* gpio out push-pull */
44 static int da9062_pctl_get_pin_mode(struct da9062_pctl *pctl, in da9062_pctl_get_pin_mode() argument
47 struct regmap *regmap = pctl->da9062->regmap; in da9062_pctl_get_pin_mode() local
50 ret = regmap_read(regmap, DA9062AA_GPIO_0_1 + (offset >> 1), &val); in da9062_pctl_get_pin_mode()
60 static int da9062_pctl_set_pin_mode(struct da9062_pctl *pctl, in da9062_pctl_set_pin_mode() argument
63 struct regmap *regmap = pctl->da9062->regmap; in da9062_pctl_set_pin_mode() local
72 ret = regmap_update_bits(regmap, DA9062AA_GPIO_0_1 + (offset >> 1), in da9062_pctl_set_pin_mode()
75 pctl->pin_config[offset] = mode_req; in da9062_pctl_set_pin_mode()
82 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_get() local
83 struct regmap *regmap = pctl->da9062->regmap; in da9062_gpio_get() local
87 gpio_mode = da9062_pctl_get_pin_mode(pctl, offset); in da9062_gpio_get()
93 return -ENOTSUPP; in da9062_gpio_get()
95 ret = regmap_read(regmap, DA9062AA_STATUS_B, &val); in da9062_gpio_get()
101 ret = regmap_read(regmap, DA9062AA_GPIO_MODE0_4, &val); in da9062_gpio_get()
112 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_set() local
113 struct regmap *regmap = pctl->da9062->regmap; in da9062_gpio_set() local
115 regmap_update_bits(regmap, DA9062AA_GPIO_MODE0_4, BIT(offset), in da9062_gpio_set()
121 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_get_direction() local
124 gpio_mode = da9062_pctl_get_pin_mode(pctl, offset); in da9062_gpio_get_direction()
130 return -ENOTSUPP; in da9062_gpio_get_direction()
138 return -EINVAL; in da9062_gpio_get_direction()
144 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_direction_input() local
145 struct regmap *regmap = pctl->da9062->regmap; in da9062_gpio_direction_input() local
150 ret = da9062_pctl_set_pin_mode(pctl, offset, DA9062_PIN_GPI); in da9062_gpio_direction_input()
156 * about gpio_get() because we read and return the gpio-level. So the in da9062_gpio_direction_input()
159 * 0 - active low, 1 - active high in da9062_gpio_direction_input()
163 return regmap_update_bits(regmap, DA9062AA_GPIO_0_1 + (offset >> 1), in da9062_gpio_direction_input()
171 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_direction_output() local
172 unsigned int pin_config = pctl->pin_config[offset]; in da9062_gpio_direction_output()
175 ret = da9062_pctl_set_pin_mode(pctl, offset, pin_config); in da9062_gpio_direction_output()
187 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_set_config() local
188 struct regmap *regmap = pctl->da9062->regmap; in da9062_gpio_set_config() local
193 * - PIN_CONFIG_BIAS_PULL_DOWN -> only allowed if the pin is used as in da9062_gpio_set_config()
195 * - PIN_CONFIG_BIAS_PULL_UP -> only allowed if the pin is used as in da9062_gpio_set_config()
196 * gpio output open-drain. in da9062_gpio_set_config()
201 return regmap_update_bits(regmap, DA9062AA_CONFIG_K, in da9062_gpio_set_config()
204 gpio_mode = da9062_pctl_get_pin_mode(pctl, offset); in da9062_gpio_set_config()
206 return -EINVAL; in da9062_gpio_set_config()
208 return -ENOTSUPP; in da9062_gpio_set_config()
209 return regmap_update_bits(regmap, DA9062AA_CONFIG_K, in da9062_gpio_set_config()
212 gpio_mode = da9062_pctl_get_pin_mode(pctl, offset); in da9062_gpio_set_config()
214 return -EINVAL; in da9062_gpio_set_config()
216 return -ENOTSUPP; in da9062_gpio_set_config()
217 return regmap_update_bits(regmap, DA9062AA_CONFIG_K, in da9062_gpio_set_config()
220 return da9062_pctl_set_pin_mode(pctl, offset, in da9062_gpio_set_config()
223 return da9062_pctl_set_pin_mode(pctl, offset, in da9062_gpio_set_config()
226 return -ENOTSUPP; in da9062_gpio_set_config()
232 struct da9062_pctl *pctl = gpiochip_get_data(gc); in da9062_gpio_to_irq() local
233 struct da9062 *da9062 = pctl->da9062; in da9062_gpio_to_irq()
235 return regmap_irq_get_virq(da9062->regmap_irq, in da9062_gpio_to_irq()
250 .base = -1,
255 struct device *parent = pdev->dev.parent; in da9062_pctl_probe()
256 struct da9062_pctl *pctl; in da9062_pctl_probe() local
259 pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); in da9062_pctl_probe()
260 if (!pctl) in da9062_pctl_probe()
261 return -ENOMEM; in da9062_pctl_probe()
263 pctl->da9062 = dev_get_drvdata(parent); in da9062_pctl_probe()
264 if (!pctl->da9062) in da9062_pctl_probe()
265 return -EINVAL; in da9062_pctl_probe()
267 if (!device_property_present(parent, "gpio-controller")) in da9062_pctl_probe()
270 for (i = 0; i < ARRAY_SIZE(pctl->pin_config); i++) in da9062_pctl_probe()
271 pctl->pin_config[i] = DA9062_PIN_GPO_PP; in da9062_pctl_probe()
277 pctl->gc = reference_gc; in da9062_pctl_probe()
278 pctl->gc.label = dev_name(&pdev->dev); in da9062_pctl_probe()
279 pctl->gc.parent = &pdev->dev; in da9062_pctl_probe()
281 pctl->gc.of_node = parent->of_node; 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");