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

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2016 Maxime Ripard <maxime.ripard@free-electrons.com>
6 * Copyright (C) 2017 Quentin Schulz <quentin.schulz@free-electrons.com>
19 #include <linux/pinctrl/pinconf-generic.h>
23 #include <linux/regmap.h>
63 struct regmap *regmap; member
117 return -EINVAL; in axp20x_gpio_get_reg()
122 return pinctrl_gpio_direction_input(chip->base + offset); in axp20x_gpio_input()
127 struct axp20x_pctl *pctl = gpiochip_get_data(chip); in axp20x_gpio_get() local
131 ret = regmap_read(pctl->regmap, AXP20X_GPIO20_SS, &val); in axp20x_gpio_get()
135 return !!(val & BIT(offset + pctl->desc->gpio_status_offset)); in axp20x_gpio_get()
141 struct axp20x_pctl *pctl = gpiochip_get_data(chip); in axp20x_gpio_get_direction() local
149 ret = regmap_read(pctl->regmap, reg, &val); in axp20x_gpio_get_direction()
174 chip->set(chip, offset, value); in axp20x_gpio_output()
182 struct axp20x_pctl *pctl = gpiochip_get_data(chip); in axp20x_gpio_set() local
189 regmap_update_bits(pctl->regmap, reg, in axp20x_gpio_set()
198 struct axp20x_pctl *pctl = pinctrl_dev_get_drvdata(pctldev); in axp20x_pmx_set() local
205 return regmap_update_bits(pctl->regmap, reg, AXP20X_GPIO_FUNCTIONS, in axp20x_pmx_set()
211 struct axp20x_pctl *pctl = pinctrl_dev_get_drvdata(pctldev); in axp20x_pmx_func_cnt() local
213 return ARRAY_SIZE(pctl->funcs); in axp20x_pmx_func_cnt()
219 struct axp20x_pctl *pctl = pinctrl_dev_get_drvdata(pctldev); in axp20x_pmx_func_name() local
221 return pctl->funcs[selector].name; in axp20x_pmx_func_name()
229 struct axp20x_pctl *pctl = pinctrl_dev_get_drvdata(pctldev); in axp20x_pmx_func_groups() local
231 *groups = pctl->funcs[selector].groups; in axp20x_pmx_func_groups()
232 *num_groups = pctl->funcs[selector].ngroups; in axp20x_pmx_func_groups()
240 struct axp20x_pctl *pctl = pinctrl_dev_get_drvdata(pctldev); in axp20x_pmx_set_mux() local
246 pctl->funcs[function].muxval); in axp20x_pmx_set_mux()
249 mask = pctl->desc->ldo_mask; in axp20x_pmx_set_mux()
251 mask = pctl->desc->adc_mask; in axp20x_pmx_set_mux()
254 return -EINVAL; in axp20x_pmx_set_mux()
265 return axp20x_pmx_set(pctldev, group, pctl->funcs[function].muxval); in axp20x_pmx_set_mux()
272 struct axp20x_pctl *pctl = pinctrl_dev_get_drvdata(pctldev); in axp20x_pmx_gpio_set_direction() local
276 pctl->funcs[AXP20X_FUNC_GPIO_IN].muxval); in axp20x_pmx_gpio_set_direction()
279 pctl->funcs[AXP20X_FUNC_GPIO_OUT].muxval); in axp20x_pmx_gpio_set_direction()
293 struct axp20x_pctl *pctl = pinctrl_dev_get_drvdata(pctldev); in axp20x_groups_cnt() local
295 return pctl->desc->npins; in axp20x_groups_cnt()
301 struct axp20x_pctl *pctl = pinctrl_dev_get_drvdata(pctldev); in axp20x_group_pins() local
303 *pins = (unsigned int *)&pctl->desc->pins[selector]; in axp20x_group_pins()
312 struct axp20x_pctl *pctl = pinctrl_dev_get_drvdata(pctldev); in axp20x_group_name() local
314 return pctl->desc->pins[selector].name; in axp20x_group_name()
335 func->ngroups = ngroups; in axp20x_funcs_groups_from_mask()
336 if (func->ngroups > 0) { in axp20x_funcs_groups_from_mask()
337 func->groups = devm_kcalloc(dev, in axp20x_funcs_groups_from_mask()
340 if (!func->groups) in axp20x_funcs_groups_from_mask()
341 return -ENOMEM; in axp20x_funcs_groups_from_mask()
342 group = func->groups; in axp20x_funcs_groups_from_mask()
354 struct axp20x_pctl *pctl = platform_get_drvdata(pdev); in axp20x_build_funcs_groups() local
355 int i, ret, pin, npins = pctl->desc->npins; in axp20x_build_funcs_groups()
357 pctl->funcs[AXP20X_FUNC_GPIO_OUT].name = "gpio_out"; in axp20x_build_funcs_groups()
358 pctl->funcs[AXP20X_FUNC_GPIO_OUT].muxval = AXP20X_MUX_GPIO_OUT; in axp20x_build_funcs_groups()
359 pctl->funcs[AXP20X_FUNC_GPIO_IN].name = "gpio_in"; in axp20x_build_funcs_groups()
360 pctl->funcs[AXP20X_FUNC_GPIO_IN].muxval = AXP20X_MUX_GPIO_IN; in axp20x_build_funcs_groups()
361 pctl->funcs[AXP20X_FUNC_LDO].name = "ldo"; in axp20x_build_funcs_groups()
366 pctl->funcs[AXP20X_FUNC_ADC].name = "adc"; in axp20x_build_funcs_groups()
367 pctl->funcs[AXP20X_FUNC_ADC].muxval = pctl->desc->adc_mux; in axp20x_build_funcs_groups()
371 pctl->funcs[i].ngroups = npins; in axp20x_build_funcs_groups()
372 pctl->funcs[i].groups = devm_kcalloc(&pdev->dev, in axp20x_build_funcs_groups()
375 if (!pctl->funcs[i].groups) in axp20x_build_funcs_groups()
376 return -ENOMEM; in axp20x_build_funcs_groups()
378 pctl->funcs[i].groups[pin] = pctl->desc->pins[pin].name; in axp20x_build_funcs_groups()
381 ret = axp20x_funcs_groups_from_mask(&pdev->dev, pctl->desc->ldo_mask, in axp20x_build_funcs_groups()
382 npins, &pctl->funcs[AXP20X_FUNC_LDO], in axp20x_build_funcs_groups()
383 pctl->desc->pins); in axp20x_build_funcs_groups()
387 ret = axp20x_funcs_groups_from_mask(&pdev->dev, pctl->desc->adc_mask, in axp20x_build_funcs_groups()
388 npins, &pctl->funcs[AXP20X_FUNC_ADC], in axp20x_build_funcs_groups()
389 pctl->desc->pins); in axp20x_build_funcs_groups()
397 { .compatible = "x-powers,axp209-gpio", .data = &axp20x_data, },
398 { .compatible = "x-powers,axp221-gpio", .data = &axp22x_data, },
399 { .compatible = "x-powers,axp813-gpio", .data = &axp813_data, },
406 struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); in axp20x_pctl_probe()
407 struct axp20x_pctl *pctl; in axp20x_pctl_probe() local
408 struct device *dev = &pdev->dev; in axp20x_pctl_probe()
412 if (!of_device_is_available(pdev->dev.of_node)) in axp20x_pctl_probe()
413 return -ENODEV; in axp20x_pctl_probe()
416 dev_err(&pdev->dev, "Parent drvdata not set\n"); in axp20x_pctl_probe()
417 return -EINVAL; in axp20x_pctl_probe()
420 pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); in axp20x_pctl_probe()
421 if (!pctl) in axp20x_pctl_probe()
422 return -ENOMEM; in axp20x_pctl_probe()
424 pctl->chip.base = -1; in axp20x_pctl_probe()
425 pctl->chip.can_sleep = true; in axp20x_pctl_probe()
426 pctl->chip.request = gpiochip_generic_request; in axp20x_pctl_probe()
427 pctl->chip.free = gpiochip_generic_free; in axp20x_pctl_probe()
428 pctl->chip.parent = &pdev->dev; in axp20x_pctl_probe()
429 pctl->chip.label = dev_name(&pdev->dev); in axp20x_pctl_probe()
430 pctl->chip.owner = THIS_MODULE; in axp20x_pctl_probe()
431 pctl->chip.get = axp20x_gpio_get; in axp20x_pctl_probe()
432 pctl->chip.get_direction = axp20x_gpio_get_direction; in axp20x_pctl_probe()
433 pctl->chip.set = axp20x_gpio_set; in axp20x_pctl_probe()
434 pctl->chip.direction_input = axp20x_gpio_input; in axp20x_pctl_probe()
435 pctl->chip.direction_output = axp20x_gpio_output; in axp20x_pctl_probe()
437 pctl->desc = of_device_get_match_data(dev); in axp20x_pctl_probe()
439 pctl->chip.ngpio = pctl->desc->npins; in axp20x_pctl_probe()
441 pctl->regmap = axp20x->regmap; in axp20x_pctl_probe()
442 pctl->dev = &pdev->dev; in axp20x_pctl_probe()
444 platform_set_drvdata(pdev, pctl); in axp20x_pctl_probe()
448 dev_err(&pdev->dev, "failed to build groups\n"); in axp20x_pctl_probe()
452 pctrl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctrl_desc), GFP_KERNEL); in axp20x_pctl_probe()
454 return -ENOMEM; in axp20x_pctl_probe()
456 pctrl_desc->name = dev_name(&pdev->dev); in axp20x_pctl_probe()
457 pctrl_desc->owner = THIS_MODULE; in axp20x_pctl_probe()
458 pctrl_desc->pins = pctl->desc->pins; in axp20x_pctl_probe()
459 pctrl_desc->npins = pctl->desc->npins; in axp20x_pctl_probe()
460 pctrl_desc->pctlops = &axp20x_pctrl_ops; in axp20x_pctl_probe()
461 pctrl_desc->pmxops = &axp20x_pmx_ops; in axp20x_pctl_probe()
463 pctl->pctl_dev = devm_pinctrl_register(&pdev->dev, pctrl_desc, pctl); in axp20x_pctl_probe()
464 if (IS_ERR(pctl->pctl_dev)) { in axp20x_pctl_probe()
465 dev_err(&pdev->dev, "couldn't register pinctrl driver\n"); in axp20x_pctl_probe()
466 return PTR_ERR(pctl->pctl_dev); in axp20x_pctl_probe()
469 ret = devm_gpiochip_add_data(&pdev->dev, &pctl->chip, pctl); in axp20x_pctl_probe()
471 dev_err(&pdev->dev, "Failed to register GPIO chip\n"); in axp20x_pctl_probe()
475 ret = gpiochip_add_pin_range(&pctl->chip, dev_name(&pdev->dev), in axp20x_pctl_probe()
476 pctl->desc->pins->number, in axp20x_pctl_probe()
477 pctl->desc->pins->number, in axp20x_pctl_probe()
478 pctl->desc->npins); in axp20x_pctl_probe()
480 dev_err(&pdev->dev, "failed to add pin range\n"); in axp20x_pctl_probe()
484 dev_info(&pdev->dev, "AXP209 pinctrl and GPIO driver loaded\n"); in axp20x_pctl_probe()
492 .name = "axp20x-gpio",
499 MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
500 MODULE_AUTHOR("Quentin Schulz <quentin.schulz@free-electrons.com>");