Lines Matching refs:pc
72 static int meson_get_bank(struct meson_pinctrl *pc, unsigned int pin, in meson_get_bank() argument
77 for (i = 0; i < pc->data->num_banks; i++) { in meson_get_bank()
78 if (pin >= pc->data->banks[i].first && in meson_get_bank()
79 pin <= pc->data->banks[i].last) { in meson_get_bank()
80 *bank = &pc->data->banks[i]; in meson_get_bank()
110 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_get_groups_count() local
112 return pc->data->num_groups; in meson_get_groups_count()
118 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_get_group_name() local
120 return pc->data->groups[selector].name; in meson_get_group_name()
126 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_get_group_pins() local
128 *pins = pc->data->groups[selector].pins; in meson_get_group_pins()
129 *num_pins = pc->data->groups[selector].num_pins; in meson_get_group_pins()
151 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_pmx_get_funcs_count() local
153 return pc->data->num_funcs; in meson_pmx_get_funcs_count()
160 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_pmx_get_func_name() local
162 return pc->data->funcs[selector].name; in meson_pmx_get_func_name()
170 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_pmx_get_groups() local
172 *groups = pc->data->funcs[selector].groups; in meson_pmx_get_groups()
173 *num_groups = pc->data->funcs[selector].num_groups; in meson_pmx_get_groups()
179 static int meson_pinconf_set_gpio_bit(struct meson_pinctrl *pc, in meson_pinconf_set_gpio_bit() argument
188 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_set_gpio_bit()
193 return regmap_update_bits(pc->reg_gpio, reg, BIT(bit), in meson_pinconf_set_gpio_bit()
197 static int meson_pinconf_get_gpio_bit(struct meson_pinctrl *pc, in meson_pinconf_get_gpio_bit() argument
205 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_get_gpio_bit()
210 ret = regmap_read(pc->reg_gpio, reg, &val); in meson_pinconf_get_gpio_bit()
217 static int meson_pinconf_set_output(struct meson_pinctrl *pc, in meson_pinconf_set_output() argument
221 return meson_pinconf_set_gpio_bit(pc, pin, MESON_REG_DIR, !out); in meson_pinconf_set_output()
224 static int meson_pinconf_get_output(struct meson_pinctrl *pc, in meson_pinconf_get_output() argument
227 int ret = meson_pinconf_get_gpio_bit(pc, pin, MESON_REG_DIR); in meson_pinconf_get_output()
235 static int meson_pinconf_set_drive(struct meson_pinctrl *pc, in meson_pinconf_set_drive() argument
239 return meson_pinconf_set_gpio_bit(pc, pin, MESON_REG_OUT, high); in meson_pinconf_set_drive()
242 static int meson_pinconf_get_drive(struct meson_pinctrl *pc, in meson_pinconf_get_drive() argument
245 return meson_pinconf_get_gpio_bit(pc, pin, MESON_REG_OUT); in meson_pinconf_get_drive()
248 static int meson_pinconf_set_output_drive(struct meson_pinctrl *pc, in meson_pinconf_set_output_drive() argument
254 ret = meson_pinconf_set_output(pc, pin, true); in meson_pinconf_set_output_drive()
258 return meson_pinconf_set_drive(pc, pin, high); in meson_pinconf_set_output_drive()
261 static int meson_pinconf_disable_bias(struct meson_pinctrl *pc, in meson_pinconf_disable_bias() argument
268 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_disable_bias()
273 ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), 0); in meson_pinconf_disable_bias()
280 static int meson_pinconf_enable_bias(struct meson_pinctrl *pc, unsigned int pin, in meson_pinconf_enable_bias() argument
287 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_enable_bias()
295 ret = regmap_update_bits(pc->reg_pull, reg, BIT(bit), val); in meson_pinconf_enable_bias()
300 ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), BIT(bit)); in meson_pinconf_enable_bias()
307 static int meson_pinconf_set_drive_strength(struct meson_pinctrl *pc, in meson_pinconf_set_drive_strength() argument
315 if (!pc->reg_ds) { in meson_pinconf_set_drive_strength()
316 dev_err(pc->dev, "drive-strength not supported\n"); in meson_pinconf_set_drive_strength()
320 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_set_drive_strength()
335 dev_warn_once(pc->dev, in meson_pinconf_set_drive_strength()
341 ret = regmap_update_bits(pc->reg_ds, reg, 0x3 << bit, ds_val << bit); in meson_pinconf_set_drive_strength()
351 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_pinconf_set() local
372 ret = meson_pinconf_disable_bias(pc, pin); in meson_pinconf_set()
375 ret = meson_pinconf_enable_bias(pc, pin, true); in meson_pinconf_set()
378 ret = meson_pinconf_enable_bias(pc, pin, false); in meson_pinconf_set()
381 ret = meson_pinconf_set_drive_strength(pc, pin, arg); in meson_pinconf_set()
384 ret = meson_pinconf_set_output(pc, pin, arg); in meson_pinconf_set()
387 ret = meson_pinconf_set_output_drive(pc, pin, arg); in meson_pinconf_set()
400 static int meson_pinconf_get_pull(struct meson_pinctrl *pc, unsigned int pin) in meson_pinconf_get_pull() argument
406 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_get_pull()
412 ret = regmap_read(pc->reg_pullen, reg, &val); in meson_pinconf_get_pull()
421 ret = regmap_read(pc->reg_pull, reg, &val); in meson_pinconf_get_pull()
434 static int meson_pinconf_get_drive_strength(struct meson_pinctrl *pc, in meson_pinconf_get_drive_strength() argument
443 if (!pc->reg_ds) in meson_pinconf_get_drive_strength()
446 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_get_drive_strength()
452 ret = regmap_read(pc->reg_ds, reg, &val); in meson_pinconf_get_drive_strength()
479 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_pinconf_get() local
488 if (meson_pinconf_get_pull(pc, pin) == param) in meson_pinconf_get()
494 ret = meson_pinconf_get_drive_strength(pc, pin, &arg); in meson_pinconf_get()
499 ret = meson_pinconf_get_output(pc, pin); in meson_pinconf_get()
505 ret = meson_pinconf_get_output(pc, pin); in meson_pinconf_get()
509 ret = meson_pinconf_get_drive(pc, pin); in meson_pinconf_get()
521 dev_dbg(pc->dev, "pinconf for pin %u is %lu\n", pin, *config); in meson_pinconf_get()
530 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_pinconf_group_set() local
531 struct meson_pmx_group *group = &pc->data->groups[num_group]; in meson_pinconf_group_set()
534 dev_dbg(pc->dev, "set pinconf for group %s\n", group->name); in meson_pinconf_group_set()
560 struct meson_pinctrl *pc = gpiochip_get_data(chip); in meson_gpio_get_direction() local
563 ret = meson_pinconf_get_output(pc, gpio); in meson_gpio_get_direction()
589 struct meson_pinctrl *pc = gpiochip_get_data(chip); in meson_gpio_get() local
594 ret = meson_get_bank(pc, gpio, &bank); in meson_gpio_get()
599 regmap_read(pc->reg_gpio, reg, &val); in meson_gpio_get()
604 static int meson_gpiolib_register(struct meson_pinctrl *pc) in meson_gpiolib_register() argument
608 pc->chip.label = pc->data->name; in meson_gpiolib_register()
609 pc->chip.parent = pc->dev; in meson_gpiolib_register()
610 pc->chip.fwnode = pc->fwnode; in meson_gpiolib_register()
611 pc->chip.request = gpiochip_generic_request; in meson_gpiolib_register()
612 pc->chip.free = gpiochip_generic_free; in meson_gpiolib_register()
613 pc->chip.set_config = gpiochip_generic_config; in meson_gpiolib_register()
614 pc->chip.get_direction = meson_gpio_get_direction; in meson_gpiolib_register()
615 pc->chip.direction_input = meson_gpio_direction_input; in meson_gpiolib_register()
616 pc->chip.direction_output = meson_gpio_direction_output; in meson_gpiolib_register()
617 pc->chip.get = meson_gpio_get; in meson_gpiolib_register()
618 pc->chip.set = meson_gpio_set; in meson_gpiolib_register()
619 pc->chip.base = -1; in meson_gpiolib_register()
620 pc->chip.ngpio = pc->data->num_pins; in meson_gpiolib_register()
621 pc->chip.can_sleep = false; in meson_gpiolib_register()
623 ret = gpiochip_add_data(&pc->chip, pc); in meson_gpiolib_register()
625 dev_err(pc->dev, "can't add gpio chip %s\n", in meson_gpiolib_register()
626 pc->data->name); in meson_gpiolib_register()
639 static struct regmap *meson_map_resource(struct meson_pinctrl *pc, in meson_map_resource() argument
650 base = devm_ioremap_resource(pc->dev, &res); in meson_map_resource()
655 meson_regmap_config.name = devm_kasprintf(pc->dev, GFP_KERNEL, in meson_map_resource()
661 return devm_regmap_init_mmio(pc->dev, base, &meson_regmap_config); in meson_map_resource()
664 static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc) in meson_pinctrl_parse_dt() argument
669 chips = gpiochip_node_count(pc->dev); in meson_pinctrl_parse_dt()
671 dev_err(pc->dev, "no gpio node found\n"); in meson_pinctrl_parse_dt()
675 dev_err(pc->dev, "multiple gpio nodes\n"); in meson_pinctrl_parse_dt()
679 pc->fwnode = gpiochip_node_get_first(pc->dev); in meson_pinctrl_parse_dt()
680 gpio_np = to_of_node(pc->fwnode); in meson_pinctrl_parse_dt()
682 pc->reg_mux = meson_map_resource(pc, gpio_np, "mux"); in meson_pinctrl_parse_dt()
683 if (IS_ERR_OR_NULL(pc->reg_mux)) { in meson_pinctrl_parse_dt()
684 dev_err(pc->dev, "mux registers not found\n"); in meson_pinctrl_parse_dt()
685 return pc->reg_mux ? PTR_ERR(pc->reg_mux) : -ENOENT; in meson_pinctrl_parse_dt()
688 pc->reg_gpio = meson_map_resource(pc, gpio_np, "gpio"); in meson_pinctrl_parse_dt()
689 if (IS_ERR_OR_NULL(pc->reg_gpio)) { in meson_pinctrl_parse_dt()
690 dev_err(pc->dev, "gpio registers not found\n"); in meson_pinctrl_parse_dt()
691 return pc->reg_gpio ? PTR_ERR(pc->reg_gpio) : -ENOENT; in meson_pinctrl_parse_dt()
694 pc->reg_pull = meson_map_resource(pc, gpio_np, "pull"); in meson_pinctrl_parse_dt()
695 if (IS_ERR(pc->reg_pull)) in meson_pinctrl_parse_dt()
696 pc->reg_pull = NULL; in meson_pinctrl_parse_dt()
698 pc->reg_pullen = meson_map_resource(pc, gpio_np, "pull-enable"); in meson_pinctrl_parse_dt()
699 if (IS_ERR(pc->reg_pullen)) in meson_pinctrl_parse_dt()
700 pc->reg_pullen = NULL; in meson_pinctrl_parse_dt()
702 pc->reg_ds = meson_map_resource(pc, gpio_np, "ds"); in meson_pinctrl_parse_dt()
703 if (IS_ERR(pc->reg_ds)) { in meson_pinctrl_parse_dt()
704 dev_dbg(pc->dev, "ds registers not found - skipping\n"); in meson_pinctrl_parse_dt()
705 pc->reg_ds = NULL; in meson_pinctrl_parse_dt()
708 if (pc->data->parse_dt) in meson_pinctrl_parse_dt()
709 return pc->data->parse_dt(pc); in meson_pinctrl_parse_dt()
714 int meson8_aobus_parse_dt_extra(struct meson_pinctrl *pc) in meson8_aobus_parse_dt_extra() argument
716 if (!pc->reg_pull) in meson8_aobus_parse_dt_extra()
719 pc->reg_pullen = pc->reg_pull; in meson8_aobus_parse_dt_extra()
725 int meson_a1_parse_dt_extra(struct meson_pinctrl *pc) in meson_a1_parse_dt_extra() argument
727 pc->reg_pull = pc->reg_gpio; in meson_a1_parse_dt_extra()
728 pc->reg_pullen = pc->reg_gpio; in meson_a1_parse_dt_extra()
729 pc->reg_ds = pc->reg_gpio; in meson_a1_parse_dt_extra()
738 struct meson_pinctrl *pc; in meson_pinctrl_probe() local
741 pc = devm_kzalloc(dev, sizeof(struct meson_pinctrl), GFP_KERNEL); in meson_pinctrl_probe()
742 if (!pc) in meson_pinctrl_probe()
745 pc->dev = dev; in meson_pinctrl_probe()
746 pc->data = (struct meson_pinctrl_data *) of_device_get_match_data(dev); in meson_pinctrl_probe()
748 ret = meson_pinctrl_parse_dt(pc); in meson_pinctrl_probe()
752 pc->desc.name = "pinctrl-meson"; in meson_pinctrl_probe()
753 pc->desc.owner = THIS_MODULE; in meson_pinctrl_probe()
754 pc->desc.pctlops = &meson_pctrl_ops; in meson_pinctrl_probe()
755 pc->desc.pmxops = pc->data->pmx_ops; in meson_pinctrl_probe()
756 pc->desc.confops = &meson_pinconf_ops; in meson_pinctrl_probe()
757 pc->desc.pins = pc->data->pins; in meson_pinctrl_probe()
758 pc->desc.npins = pc->data->num_pins; in meson_pinctrl_probe()
760 pc->pcdev = devm_pinctrl_register(pc->dev, &pc->desc, pc); in meson_pinctrl_probe()
761 if (IS_ERR(pc->pcdev)) { in meson_pinctrl_probe()
762 dev_err(pc->dev, "can't register pinctrl device"); in meson_pinctrl_probe()
763 return PTR_ERR(pc->pcdev); in meson_pinctrl_probe()
766 return meson_gpiolib_register(pc); in meson_pinctrl_probe()