Lines Matching +full:pctl +full:- +full:regmap
1 // SPDX-License-Identifier: GPL-2.0-or-later
8 * Author: Joseph Chen <chenjh@rock-chips.com>
9 * Author: Xu Shengfei <xsf@rock-chips.com>
11 * Based on the pinctrl-as3722 driver
26 #include <linux/pinctrl/pinconf-generic.h>
32 #include "pinctrl-utils.h"
71 struct pinctrl_dev *pctl; member
264 ret = regmap_read(pci->rk808->regmap, pci->pin_cfg[offset].reg, &val); in rk805_gpio_get()
266 dev_err(pci->dev, "get gpio%d value failed\n", offset); in rk805_gpio_get()
270 return !!(val & pci->pin_cfg[offset].val_msk); in rk805_gpio_get()
280 ret = regmap_update_bits(pci->rk808->regmap, in rk805_gpio_set()
281 pci->pin_cfg[offset].reg, in rk805_gpio_set()
282 pci->pin_cfg[offset].val_msk, in rk805_gpio_set()
283 value ? pci->pin_cfg[offset].val_msk : 0); in rk805_gpio_set()
285 dev_err(pci->dev, "set gpio%d value %d failed\n", in rk805_gpio_set()
292 return pinctrl_gpio_direction_input(chip->base + offset); in rk805_gpio_direction_input()
299 return pinctrl_gpio_direction_output(chip->base + offset); in rk805_gpio_direction_output()
309 if (!pci->pin_cfg[offset].dir_msk) in rk805_gpio_get_direction()
312 ret = regmap_read(pci->rk808->regmap, in rk805_gpio_get_direction()
313 pci->pin_cfg[offset].reg, in rk805_gpio_get_direction()
316 dev_err(pci->dev, "get gpio%d direction failed\n", offset); in rk805_gpio_get_direction()
320 if (val & pci->pin_cfg[offset].dir_msk) in rk805_gpio_get_direction()
327 .label = "rk805-gpio",
336 .base = -1,
345 return pci->num_pin_groups; in rk805_pinctrl_get_groups_count()
353 return pci->groups[group].name; in rk805_pinctrl_get_group_name()
363 *pins = pci->groups[group].pins; in rk805_pinctrl_get_group_pins()
364 *num_pins = pci->groups[group].npins; in rk805_pinctrl_get_group_pins()
381 return pci->num_functions; in rk805_pinctrl_get_funcs_count()
389 return pci->functions[function].name; in rk805_pinctrl_get_func_name()
399 *groups = pci->functions[function].groups; in rk805_pinctrl_get_func_groups()
400 *num_groups = pci->functions[function].ngroups; in rk805_pinctrl_get_func_groups()
412 if (!pci->pin_cfg[offset].fun_msk) in _rk805_pinctrl_set_mux()
415 mux <<= ffs(pci->pin_cfg[offset].fun_msk) - 1; in _rk805_pinctrl_set_mux()
416 ret = regmap_update_bits(pci->rk808->regmap, in _rk805_pinctrl_set_mux()
417 pci->pin_cfg[offset].fun_reg, in _rk805_pinctrl_set_mux()
418 pci->pin_cfg[offset].fun_msk, mux); in _rk805_pinctrl_set_mux()
421 dev_err(pci->dev, "set gpio%d func%d failed\n", offset, mux); in _rk805_pinctrl_set_mux()
431 int mux = pci->functions[function].mux_option; in rk805_pinctrl_set_mux()
443 switch (pci->rk808->variant) { in rk805_pinctrl_gpio_request_enable()
450 return -ENOTSUPP; in rk805_pinctrl_gpio_request_enable()
461 if (!pci->pin_cfg[offset].dir_msk) in rk805_pmx_gpio_set_direction()
464 ret = regmap_update_bits(pci->rk808->regmap, in rk805_pmx_gpio_set_direction()
465 pci->pin_cfg[offset].reg, in rk805_pmx_gpio_set_direction()
466 pci->pin_cfg[offset].dir_msk, in rk805_pmx_gpio_set_direction()
467 input ? 0 : pci->pin_cfg[offset].dir_msk); in rk805_pmx_gpio_set_direction()
469 dev_err(pci->dev, "set gpio%d direction failed\n", offset); in rk805_pmx_gpio_set_direction()
495 arg = rk805_gpio_get(&pci->gpio_chip, pin); in rk805_pinconf_get()
498 dev_err(pci->dev, "Properties not supported\n"); in rk805_pinconf_get()
499 return -ENOTSUPP; in rk805_pinconf_get()
521 rk805_gpio_set(&pci->gpio_chip, pin, arg); in rk805_pinconf_set()
525 if (pci->rk808->variant != RK805_ID && arg) { in rk805_pinconf_set()
531 dev_err(pci->dev, "Properties not supported\n"); in rk805_pinconf_set()
532 return -ENOTSUPP; in rk805_pinconf_set()
545 .name = "rk805-pinctrl",
557 device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent)); in rk805_pinctrl_probe()
559 pci = devm_kzalloc(&pdev->dev, sizeof(*pci), GFP_KERNEL); in rk805_pinctrl_probe()
561 return -ENOMEM; in rk805_pinctrl_probe()
563 pci->dev = &pdev->dev; in rk805_pinctrl_probe()
564 pci->rk808 = dev_get_drvdata(pdev->dev.parent); in rk805_pinctrl_probe()
566 pci->pinctrl_desc = rk805_pinctrl_desc; in rk805_pinctrl_probe()
567 pci->gpio_chip = rk805_gpio_chip; in rk805_pinctrl_probe()
568 pci->gpio_chip.parent = &pdev->dev; in rk805_pinctrl_probe()
572 switch (pci->rk808->variant) { in rk805_pinctrl_probe()
574 pci->pins = rk805_pins_desc; in rk805_pinctrl_probe()
575 pci->num_pins = ARRAY_SIZE(rk805_pins_desc); in rk805_pinctrl_probe()
576 pci->functions = rk805_pin_functions; in rk805_pinctrl_probe()
577 pci->num_functions = ARRAY_SIZE(rk805_pin_functions); in rk805_pinctrl_probe()
578 pci->groups = rk805_pin_groups; in rk805_pinctrl_probe()
579 pci->num_pin_groups = ARRAY_SIZE(rk805_pin_groups); in rk805_pinctrl_probe()
580 pci->pinctrl_desc.pins = rk805_pins_desc; in rk805_pinctrl_probe()
581 pci->pinctrl_desc.npins = ARRAY_SIZE(rk805_pins_desc); in rk805_pinctrl_probe()
582 pci->pin_cfg = rk805_gpio_cfgs; in rk805_pinctrl_probe()
583 pci->gpio_chip.ngpio = ARRAY_SIZE(rk805_gpio_cfgs); in rk805_pinctrl_probe()
586 pci->pins = rk806_pins_desc; in rk805_pinctrl_probe()
587 pci->num_pins = ARRAY_SIZE(rk806_pins_desc); in rk805_pinctrl_probe()
588 pci->functions = rk806_pin_functions; in rk805_pinctrl_probe()
589 pci->num_functions = ARRAY_SIZE(rk806_pin_functions); in rk805_pinctrl_probe()
590 pci->groups = rk806_pin_groups; in rk805_pinctrl_probe()
591 pci->num_pin_groups = ARRAY_SIZE(rk806_pin_groups); in rk805_pinctrl_probe()
592 pci->pinctrl_desc.pins = rk806_pins_desc; in rk805_pinctrl_probe()
593 pci->pinctrl_desc.npins = ARRAY_SIZE(rk806_pins_desc); in rk805_pinctrl_probe()
594 pci->pin_cfg = rk806_gpio_cfgs; in rk805_pinctrl_probe()
595 pci->gpio_chip.ngpio = ARRAY_SIZE(rk806_gpio_cfgs); in rk805_pinctrl_probe()
598 dev_err(&pdev->dev, "unsupported RK805 ID %lu\n", in rk805_pinctrl_probe()
599 pci->rk808->variant); in rk805_pinctrl_probe()
600 return -EINVAL; in rk805_pinctrl_probe()
604 ret = devm_gpiochip_add_data(&pdev->dev, &pci->gpio_chip, pci); in rk805_pinctrl_probe()
606 dev_err(&pdev->dev, "Couldn't add gpiochip\n"); in rk805_pinctrl_probe()
611 pci->pctl = devm_pinctrl_register(&pdev->dev, &pci->pinctrl_desc, pci); in rk805_pinctrl_probe()
612 if (IS_ERR(pci->pctl)) { in rk805_pinctrl_probe()
613 dev_err(&pdev->dev, "Couldn't add pinctrl\n"); in rk805_pinctrl_probe()
614 return PTR_ERR(pci->pctl); in rk805_pinctrl_probe()
618 ret = gpiochip_add_pin_range(&pci->gpio_chip, dev_name(&pdev->dev), in rk805_pinctrl_probe()
619 0, 0, pci->gpio_chip.ngpio); in rk805_pinctrl_probe()
621 dev_err(&pdev->dev, "Couldn't add gpiochip pin range\n"); in rk805_pinctrl_probe()
631 .name = "rk805-pinctrl",
637 MODULE_AUTHOR("Xu Shengfei <xsf@rock-chips.com>");
638 MODULE_AUTHOR("Joseph Chen <chenjh@rock-chips.com>");