Lines Matching +full:axp221 +full:- +full:adc

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>
23 #include <linux/pinctrl/pinconf-generic.h>
54 /* Stores the pins supporting ADC function. Bit offset is pin number. */
124 return -EINVAL; in axp20x_gpio_get_reg()
135 ret = regmap_read(pctl->regmap, AXP20X_GPIO3_CTRL, &val); in axp20x_gpio_get()
141 ret = regmap_read(pctl->regmap, AXP20X_GPIO20_SS, &val); in axp20x_gpio_get()
145 return !!(val & BIT(offset + pctl->desc->gpio_status_offset)); in axp20x_gpio_get()
157 ret = regmap_read(pctl->regmap, AXP20X_GPIO3_CTRL, &val); in axp20x_gpio_get_direction()
170 ret = regmap_read(pctl->regmap, reg, &val); in axp20x_gpio_get_direction()
195 chip->set(chip, offset, value); in axp20x_gpio_output()
208 regmap_update_bits(pctl->regmap, AXP20X_GPIO3_CTRL, in axp20x_gpio_set()
219 regmap_update_bits(pctl->regmap, reg, in axp20x_gpio_set()
233 return regmap_update_bits(pctl->regmap, AXP20X_GPIO3_CTRL, in axp20x_pmx_set()
243 return regmap_update_bits(pctl->regmap, reg, AXP20X_GPIO_FUNCTIONS, in axp20x_pmx_set()
251 return ARRAY_SIZE(pctl->funcs); in axp20x_pmx_func_cnt()
259 return pctl->funcs[selector].name; in axp20x_pmx_func_name()
269 *groups = pctl->funcs[selector].groups; in axp20x_pmx_func_groups()
270 *num_groups = pctl->funcs[selector].ngroups; in axp20x_pmx_func_groups()
284 pctl->funcs[function].muxval); in axp20x_pmx_set_mux()
287 mask = pctl->desc->ldo_mask; in axp20x_pmx_set_mux()
289 mask = pctl->desc->adc_mask; in axp20x_pmx_set_mux()
292 return -EINVAL; in axp20x_pmx_set_mux()
303 return axp20x_pmx_set(pctldev, group, pctl->funcs[function].muxval); in axp20x_pmx_set_mux()
314 pctl->funcs[AXP20X_FUNC_GPIO_IN].muxval); in axp20x_pmx_gpio_set_direction()
317 pctl->funcs[AXP20X_FUNC_GPIO_OUT].muxval); in axp20x_pmx_gpio_set_direction()
333 return pctl->desc->npins; in axp20x_groups_cnt()
341 *pins = (unsigned int *)&pctl->desc->pins[selector]; in axp20x_group_pins()
352 return pctl->desc->pins[selector].name; in axp20x_group_name()
373 func->ngroups = ngroups; in axp20x_funcs_groups_from_mask()
374 if (func->ngroups > 0) { in axp20x_funcs_groups_from_mask()
375 func->groups = devm_kcalloc(dev, in axp20x_funcs_groups_from_mask()
378 if (!func->groups) in axp20x_funcs_groups_from_mask()
379 return -ENOMEM; in axp20x_funcs_groups_from_mask()
380 group = func->groups; in axp20x_funcs_groups_from_mask()
393 int i, ret, pin, npins = pctl->desc->npins; in axp20x_build_funcs_groups()
395 pctl->funcs[AXP20X_FUNC_GPIO_OUT].name = "gpio_out"; in axp20x_build_funcs_groups()
396 pctl->funcs[AXP20X_FUNC_GPIO_OUT].muxval = AXP20X_MUX_GPIO_OUT; in axp20x_build_funcs_groups()
397 pctl->funcs[AXP20X_FUNC_GPIO_IN].name = "gpio_in"; in axp20x_build_funcs_groups()
398 pctl->funcs[AXP20X_FUNC_GPIO_IN].muxval = AXP20X_MUX_GPIO_IN; in axp20x_build_funcs_groups()
399 pctl->funcs[AXP20X_FUNC_LDO].name = "ldo"; in axp20x_build_funcs_groups()
404 pctl->funcs[AXP20X_FUNC_ADC].name = "adc"; in axp20x_build_funcs_groups()
405 pctl->funcs[AXP20X_FUNC_ADC].muxval = pctl->desc->adc_mux; in axp20x_build_funcs_groups()
409 pctl->funcs[i].ngroups = npins; in axp20x_build_funcs_groups()
410 pctl->funcs[i].groups = devm_kcalloc(&pdev->dev, in axp20x_build_funcs_groups()
413 if (!pctl->funcs[i].groups) in axp20x_build_funcs_groups()
414 return -ENOMEM; in axp20x_build_funcs_groups()
416 pctl->funcs[i].groups[pin] = pctl->desc->pins[pin].name; in axp20x_build_funcs_groups()
419 ret = axp20x_funcs_groups_from_mask(&pdev->dev, pctl->desc->ldo_mask, in axp20x_build_funcs_groups()
420 npins, &pctl->funcs[AXP20X_FUNC_LDO], in axp20x_build_funcs_groups()
421 pctl->desc->pins); in axp20x_build_funcs_groups()
425 ret = axp20x_funcs_groups_from_mask(&pdev->dev, pctl->desc->adc_mask, in axp20x_build_funcs_groups()
426 npins, &pctl->funcs[AXP20X_FUNC_ADC], in axp20x_build_funcs_groups()
427 pctl->desc->pins); in axp20x_build_funcs_groups()
435 { .compatible = "x-powers,axp209-gpio", .data = &axp20x_data, },
436 { .compatible = "x-powers,axp221-gpio", .data = &axp22x_data, },
437 { .compatible = "x-powers,axp813-gpio", .data = &axp813_data, },
444 struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); in axp20x_pctl_probe()
446 struct device *dev = &pdev->dev; in axp20x_pctl_probe()
450 if (!of_device_is_available(pdev->dev.of_node)) in axp20x_pctl_probe()
451 return -ENODEV; in axp20x_pctl_probe()
454 dev_err(&pdev->dev, "Parent drvdata not set\n"); in axp20x_pctl_probe()
455 return -EINVAL; in axp20x_pctl_probe()
458 pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); in axp20x_pctl_probe()
460 return -ENOMEM; in axp20x_pctl_probe()
462 pctl->chip.base = -1; in axp20x_pctl_probe()
463 pctl->chip.can_sleep = true; in axp20x_pctl_probe()
464 pctl->chip.request = gpiochip_generic_request; in axp20x_pctl_probe()
465 pctl->chip.free = gpiochip_generic_free; in axp20x_pctl_probe()
466 pctl->chip.parent = &pdev->dev; in axp20x_pctl_probe()
467 pctl->chip.label = dev_name(&pdev->dev); in axp20x_pctl_probe()
468 pctl->chip.owner = THIS_MODULE; in axp20x_pctl_probe()
469 pctl->chip.get = axp20x_gpio_get; in axp20x_pctl_probe()
470 pctl->chip.get_direction = axp20x_gpio_get_direction; in axp20x_pctl_probe()
471 pctl->chip.set = axp20x_gpio_set; in axp20x_pctl_probe()
472 pctl->chip.direction_input = pinctrl_gpio_direction_input; in axp20x_pctl_probe()
473 pctl->chip.direction_output = axp20x_gpio_output; in axp20x_pctl_probe()
475 pctl->desc = of_device_get_match_data(dev); in axp20x_pctl_probe()
477 pctl->chip.ngpio = pctl->desc->npins; in axp20x_pctl_probe()
479 pctl->regmap = axp20x->regmap; in axp20x_pctl_probe()
480 pctl->dev = &pdev->dev; in axp20x_pctl_probe()
486 dev_err(&pdev->dev, "failed to build groups\n"); in axp20x_pctl_probe()
490 pctrl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctrl_desc), GFP_KERNEL); in axp20x_pctl_probe()
492 return -ENOMEM; in axp20x_pctl_probe()
494 pctrl_desc->name = dev_name(&pdev->dev); in axp20x_pctl_probe()
495 pctrl_desc->owner = THIS_MODULE; in axp20x_pctl_probe()
496 pctrl_desc->pins = pctl->desc->pins; in axp20x_pctl_probe()
497 pctrl_desc->npins = pctl->desc->npins; in axp20x_pctl_probe()
498 pctrl_desc->pctlops = &axp20x_pctrl_ops; in axp20x_pctl_probe()
499 pctrl_desc->pmxops = &axp20x_pmx_ops; in axp20x_pctl_probe()
501 pctl->pctl_dev = devm_pinctrl_register(&pdev->dev, pctrl_desc, pctl); in axp20x_pctl_probe()
502 if (IS_ERR(pctl->pctl_dev)) { in axp20x_pctl_probe()
503 dev_err(&pdev->dev, "couldn't register pinctrl driver\n"); in axp20x_pctl_probe()
504 return PTR_ERR(pctl->pctl_dev); in axp20x_pctl_probe()
507 ret = devm_gpiochip_add_data(&pdev->dev, &pctl->chip, pctl); in axp20x_pctl_probe()
509 dev_err(&pdev->dev, "Failed to register GPIO chip\n"); in axp20x_pctl_probe()
513 ret = gpiochip_add_pin_range(&pctl->chip, dev_name(&pdev->dev), in axp20x_pctl_probe()
514 pctl->desc->pins->number, in axp20x_pctl_probe()
515 pctl->desc->pins->number, in axp20x_pctl_probe()
516 pctl->desc->npins); in axp20x_pctl_probe()
518 dev_err(&pdev->dev, "failed to add pin range\n"); in axp20x_pctl_probe()
522 dev_info(&pdev->dev, "AXP209 pinctrl and GPIO driver loaded\n"); in axp20x_pctl_probe()
530 .name = "axp20x-gpio",
537 MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
538 MODULE_AUTHOR("Quentin Schulz <quentin.schulz@free-electrons.com>");