Lines Matching refs:pc
73 static int meson_get_bank(struct meson_pinctrl *pc, unsigned int pin, in meson_get_bank() argument
78 for (i = 0; i < pc->data->num_banks; i++) { in meson_get_bank()
79 if (pin >= pc->data->banks[i].first && in meson_get_bank()
80 pin <= pc->data->banks[i].last) { in meson_get_bank()
81 *bank = &pc->data->banks[i]; in meson_get_bank()
111 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_get_groups_count() local
113 return pc->data->num_groups; in meson_get_groups_count()
119 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_get_group_name() local
121 return pc->data->groups[selector].name; in meson_get_group_name()
127 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_get_group_pins() local
129 *pins = pc->data->groups[selector].pins; in meson_get_group_pins()
130 *num_pins = pc->data->groups[selector].num_pins; in meson_get_group_pins()
152 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_pmx_get_funcs_count() local
154 return pc->data->num_funcs; in meson_pmx_get_funcs_count()
161 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_pmx_get_func_name() local
163 return pc->data->funcs[selector].name; in meson_pmx_get_func_name()
171 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_pmx_get_groups() local
173 *groups = pc->data->funcs[selector].groups; in meson_pmx_get_groups()
174 *num_groups = pc->data->funcs[selector].num_groups; in meson_pmx_get_groups()
180 static int meson_pinconf_set_gpio_bit(struct meson_pinctrl *pc, in meson_pinconf_set_gpio_bit() argument
189 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_set_gpio_bit()
194 return regmap_update_bits(pc->reg_gpio, reg, BIT(bit), in meson_pinconf_set_gpio_bit()
198 static int meson_pinconf_get_gpio_bit(struct meson_pinctrl *pc, in meson_pinconf_get_gpio_bit() argument
206 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_get_gpio_bit()
211 ret = regmap_read(pc->reg_gpio, reg, &val); in meson_pinconf_get_gpio_bit()
218 static int meson_pinconf_set_output(struct meson_pinctrl *pc, in meson_pinconf_set_output() argument
222 return meson_pinconf_set_gpio_bit(pc, pin, MESON_REG_DIR, !out); in meson_pinconf_set_output()
225 static int meson_pinconf_get_output(struct meson_pinctrl *pc, in meson_pinconf_get_output() argument
228 int ret = meson_pinconf_get_gpio_bit(pc, pin, MESON_REG_DIR); in meson_pinconf_get_output()
236 static int meson_pinconf_set_drive(struct meson_pinctrl *pc, in meson_pinconf_set_drive() argument
240 return meson_pinconf_set_gpio_bit(pc, pin, MESON_REG_OUT, high); in meson_pinconf_set_drive()
243 static int meson_pinconf_get_drive(struct meson_pinctrl *pc, in meson_pinconf_get_drive() argument
246 return meson_pinconf_get_gpio_bit(pc, pin, MESON_REG_OUT); in meson_pinconf_get_drive()
249 static int meson_pinconf_set_output_drive(struct meson_pinctrl *pc, in meson_pinconf_set_output_drive() argument
255 ret = meson_pinconf_set_output(pc, pin, true); in meson_pinconf_set_output_drive()
259 return meson_pinconf_set_drive(pc, pin, high); in meson_pinconf_set_output_drive()
262 static int meson_pinconf_disable_bias(struct meson_pinctrl *pc, in meson_pinconf_disable_bias() argument
269 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_disable_bias()
274 ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), 0); in meson_pinconf_disable_bias()
281 static int meson_pinconf_enable_bias(struct meson_pinctrl *pc, unsigned int pin, in meson_pinconf_enable_bias() argument
288 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_enable_bias()
296 ret = regmap_update_bits(pc->reg_pull, reg, BIT(bit), val); in meson_pinconf_enable_bias()
301 ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), BIT(bit)); in meson_pinconf_enable_bias()
308 static int meson_pinconf_set_drive_strength(struct meson_pinctrl *pc, in meson_pinconf_set_drive_strength() argument
316 if (!pc->reg_ds) { in meson_pinconf_set_drive_strength()
317 dev_err(pc->dev, "drive-strength not supported\n"); in meson_pinconf_set_drive_strength()
321 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_set_drive_strength()
336 dev_warn_once(pc->dev, in meson_pinconf_set_drive_strength()
342 ret = regmap_update_bits(pc->reg_ds, reg, 0x3 << bit, ds_val << bit); in meson_pinconf_set_drive_strength()
352 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_pinconf_set() local
373 ret = meson_pinconf_disable_bias(pc, pin); in meson_pinconf_set()
376 ret = meson_pinconf_enable_bias(pc, pin, true); in meson_pinconf_set()
379 ret = meson_pinconf_enable_bias(pc, pin, false); in meson_pinconf_set()
382 ret = meson_pinconf_set_drive_strength(pc, pin, arg); in meson_pinconf_set()
385 ret = meson_pinconf_set_output(pc, pin, arg); in meson_pinconf_set()
388 ret = meson_pinconf_set_output_drive(pc, pin, arg); in meson_pinconf_set()
401 static int meson_pinconf_get_pull(struct meson_pinctrl *pc, unsigned int pin) in meson_pinconf_get_pull() argument
407 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_get_pull()
413 ret = regmap_read(pc->reg_pullen, reg, &val); in meson_pinconf_get_pull()
422 ret = regmap_read(pc->reg_pull, reg, &val); in meson_pinconf_get_pull()
435 static int meson_pinconf_get_drive_strength(struct meson_pinctrl *pc, in meson_pinconf_get_drive_strength() argument
444 if (!pc->reg_ds) in meson_pinconf_get_drive_strength()
447 ret = meson_get_bank(pc, pin, &bank); in meson_pinconf_get_drive_strength()
453 ret = regmap_read(pc->reg_ds, reg, &val); in meson_pinconf_get_drive_strength()
480 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_pinconf_get() local
489 if (meson_pinconf_get_pull(pc, pin) == param) in meson_pinconf_get()
495 ret = meson_pinconf_get_drive_strength(pc, pin, &arg); in meson_pinconf_get()
500 ret = meson_pinconf_get_output(pc, pin); in meson_pinconf_get()
506 ret = meson_pinconf_get_output(pc, pin); in meson_pinconf_get()
510 ret = meson_pinconf_get_drive(pc, pin); in meson_pinconf_get()
522 dev_dbg(pc->dev, "pinconf for pin %u is %lu\n", pin, *config); in meson_pinconf_get()
531 struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); in meson_pinconf_group_set() local
532 struct meson_pmx_group *group = &pc->data->groups[num_group]; in meson_pinconf_group_set()
535 dev_dbg(pc->dev, "set pinconf for group %s\n", group->name); in meson_pinconf_group_set()
561 struct meson_pinctrl *pc = gpiochip_get_data(chip); in meson_gpio_get_direction() local
564 ret = meson_pinconf_get_output(pc, gpio); in meson_gpio_get_direction()
590 struct meson_pinctrl *pc = gpiochip_get_data(chip); in meson_gpio_get() local
595 ret = meson_get_bank(pc, gpio, &bank); in meson_gpio_get()
600 regmap_read(pc->reg_gpio, reg, &val); in meson_gpio_get()
605 static int meson_gpiolib_register(struct meson_pinctrl *pc) in meson_gpiolib_register() argument
609 pc->chip.label = pc->data->name; in meson_gpiolib_register()
610 pc->chip.parent = pc->dev; in meson_gpiolib_register()
611 pc->chip.fwnode = pc->fwnode; in meson_gpiolib_register()
612 pc->chip.request = gpiochip_generic_request; in meson_gpiolib_register()
613 pc->chip.free = gpiochip_generic_free; in meson_gpiolib_register()
614 pc->chip.set_config = gpiochip_generic_config; in meson_gpiolib_register()
615 pc->chip.get_direction = meson_gpio_get_direction; in meson_gpiolib_register()
616 pc->chip.direction_input = meson_gpio_direction_input; in meson_gpiolib_register()
617 pc->chip.direction_output = meson_gpio_direction_output; in meson_gpiolib_register()
618 pc->chip.get = meson_gpio_get; in meson_gpiolib_register()
619 pc->chip.set = meson_gpio_set; in meson_gpiolib_register()
620 pc->chip.base = -1; in meson_gpiolib_register()
621 pc->chip.ngpio = pc->data->num_pins; in meson_gpiolib_register()
622 pc->chip.can_sleep = false; in meson_gpiolib_register()
624 ret = gpiochip_add_data(&pc->chip, pc); in meson_gpiolib_register()
626 dev_err(pc->dev, "can't add gpio chip %s\n", in meson_gpiolib_register()
627 pc->data->name); in meson_gpiolib_register()
640 static struct regmap *meson_map_resource(struct meson_pinctrl *pc, in meson_map_resource() argument
651 base = devm_ioremap_resource(pc->dev, &res); in meson_map_resource()
656 meson_regmap_config.name = devm_kasprintf(pc->dev, GFP_KERNEL, in meson_map_resource()
662 return devm_regmap_init_mmio(pc->dev, base, &meson_regmap_config); in meson_map_resource()
665 static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc) in meson_pinctrl_parse_dt() argument
670 chips = gpiochip_node_count(pc->dev); in meson_pinctrl_parse_dt()
672 dev_err(pc->dev, "no gpio node found\n"); in meson_pinctrl_parse_dt()
676 dev_err(pc->dev, "multiple gpio nodes\n"); in meson_pinctrl_parse_dt()
680 pc->fwnode = gpiochip_node_get_first(pc->dev); in meson_pinctrl_parse_dt()
681 gpio_np = to_of_node(pc->fwnode); in meson_pinctrl_parse_dt()
683 pc->reg_mux = meson_map_resource(pc, gpio_np, "mux"); in meson_pinctrl_parse_dt()
684 if (IS_ERR_OR_NULL(pc->reg_mux)) { in meson_pinctrl_parse_dt()
685 dev_err(pc->dev, "mux registers not found\n"); in meson_pinctrl_parse_dt()
686 return pc->reg_mux ? PTR_ERR(pc->reg_mux) : -ENOENT; in meson_pinctrl_parse_dt()
689 pc->reg_gpio = meson_map_resource(pc, gpio_np, "gpio"); in meson_pinctrl_parse_dt()
690 if (IS_ERR_OR_NULL(pc->reg_gpio)) { in meson_pinctrl_parse_dt()
691 dev_err(pc->dev, "gpio registers not found\n"); in meson_pinctrl_parse_dt()
692 return pc->reg_gpio ? PTR_ERR(pc->reg_gpio) : -ENOENT; in meson_pinctrl_parse_dt()
695 pc->reg_pull = meson_map_resource(pc, gpio_np, "pull"); in meson_pinctrl_parse_dt()
696 if (IS_ERR(pc->reg_pull)) in meson_pinctrl_parse_dt()
697 pc->reg_pull = NULL; in meson_pinctrl_parse_dt()
699 pc->reg_pullen = meson_map_resource(pc, gpio_np, "pull-enable"); in meson_pinctrl_parse_dt()
700 if (IS_ERR(pc->reg_pullen)) in meson_pinctrl_parse_dt()
701 pc->reg_pullen = NULL; in meson_pinctrl_parse_dt()
703 pc->reg_ds = meson_map_resource(pc, gpio_np, "ds"); in meson_pinctrl_parse_dt()
704 if (IS_ERR(pc->reg_ds)) { in meson_pinctrl_parse_dt()
705 dev_dbg(pc->dev, "ds registers not found - skipping\n"); in meson_pinctrl_parse_dt()
706 pc->reg_ds = NULL; in meson_pinctrl_parse_dt()
709 if (pc->data->parse_dt) in meson_pinctrl_parse_dt()
710 return pc->data->parse_dt(pc); in meson_pinctrl_parse_dt()
715 int meson8_aobus_parse_dt_extra(struct meson_pinctrl *pc) in meson8_aobus_parse_dt_extra() argument
717 if (!pc->reg_pull) in meson8_aobus_parse_dt_extra()
720 pc->reg_pullen = pc->reg_pull; in meson8_aobus_parse_dt_extra()
726 int meson_a1_parse_dt_extra(struct meson_pinctrl *pc) in meson_a1_parse_dt_extra() argument
728 pc->reg_pull = pc->reg_gpio; in meson_a1_parse_dt_extra()
729 pc->reg_pullen = pc->reg_gpio; in meson_a1_parse_dt_extra()
730 pc->reg_ds = pc->reg_gpio; in meson_a1_parse_dt_extra()
739 struct meson_pinctrl *pc; in meson_pinctrl_probe() local
742 pc = devm_kzalloc(dev, sizeof(struct meson_pinctrl), GFP_KERNEL); in meson_pinctrl_probe()
743 if (!pc) in meson_pinctrl_probe()
746 pc->dev = dev; in meson_pinctrl_probe()
747 pc->data = (struct meson_pinctrl_data *) of_device_get_match_data(dev); in meson_pinctrl_probe()
749 ret = meson_pinctrl_parse_dt(pc); in meson_pinctrl_probe()
753 pc->desc.name = "pinctrl-meson"; in meson_pinctrl_probe()
754 pc->desc.owner = THIS_MODULE; in meson_pinctrl_probe()
755 pc->desc.pctlops = &meson_pctrl_ops; in meson_pinctrl_probe()
756 pc->desc.pmxops = pc->data->pmx_ops; in meson_pinctrl_probe()
757 pc->desc.confops = &meson_pinconf_ops; in meson_pinctrl_probe()
758 pc->desc.pins = pc->data->pins; in meson_pinctrl_probe()
759 pc->desc.npins = pc->data->num_pins; in meson_pinctrl_probe()
761 pc->pcdev = devm_pinctrl_register(pc->dev, &pc->desc, pc); in meson_pinctrl_probe()
762 if (IS_ERR(pc->pcdev)) { in meson_pinctrl_probe()
763 dev_err(pc->dev, "can't register pinctrl device"); in meson_pinctrl_probe()
764 return PTR_ERR(pc->pcdev); in meson_pinctrl_probe()
767 return meson_gpiolib_register(pc); in meson_pinctrl_probe()