Lines Matching +full:pin +full:- +full:function

1 // SPDX-License-Identifier: GPL-2.0
3 * ZynqMP pin controller
11 #include <dt-bindings/pinctrl/pinctrl-zynqmp.h>
18 #include <linux/firmware/xlnx-zynqmp.h>
20 #include <linux/pinctrl/pinconf-generic.h>
26 #include "pinctrl-utils.h"
47 * struct zynqmp_pmux_function - a pinmux function
48 * @name: Name of the pin mux function
49 * @groups: List of pin groups for this function
51 * @node: Firmware node matching with the function
53 * This structure holds information about pin control function
54 * and function group names supporting that function.
63 * struct zynqmp_pinctrl - driver data
64 * @pctrl: Pin control device
65 * @groups: Pin groups
67 * @funcs: Pin mux functions
71 * information regarding pin control functions, groups and
83 * struct zynqmp_pctrl_group - Pin control group info
85 * @pins: Group pin numbers
100 return pctrl->ngroups; in zynqmp_pctrl_get_groups_count()
108 return pctrl->groups[selector].name; in zynqmp_pctrl_get_group_name()
118 *pins = pctrl->groups[selector].pins; in zynqmp_pctrl_get_group_pins()
119 *npins = pctrl->groups[selector].npins; in zynqmp_pctrl_get_group_pins()
133 unsigned int pin) in zynqmp_pinmux_request_pin() argument
137 ret = zynqmp_pm_pinctrl_request(pin); in zynqmp_pinmux_request_pin()
139 dev_err(pctldev->dev, "request failed for pin %u\n", pin); in zynqmp_pinmux_request_pin()
150 return pctrl->nfuncs; in zynqmp_pmux_get_functions_count()
158 return pctrl->funcs[selector].name; in zynqmp_pmux_get_function_name()
162 * zynqmp_pmux_get_function_groups() - Get groups for the function
164 * @selector: Function ID
166 * @num_groups: Number of function groups.
168 * Get function's group count and group names.
179 *groups = pctrl->funcs[selector].groups; in zynqmp_pmux_get_function_groups()
180 *num_groups = pctrl->funcs[selector].ngroups; in zynqmp_pmux_get_function_groups()
186 * zynqmp_pinmux_set_mux() - Set requested function for the group
188 * @function: Function ID.
192 * to set requested function for all pins in the group.
197 unsigned int function, in zynqmp_pinmux_set_mux() argument
201 const struct zynqmp_pctrl_group *pgrp = &pctrl->groups[group]; in zynqmp_pinmux_set_mux()
204 for (i = 0; i < pgrp->npins; i++) { in zynqmp_pinmux_set_mux()
205 unsigned int pin = pgrp->pins[i]; in zynqmp_pinmux_set_mux() local
207 ret = zynqmp_pm_pinctrl_set_function(pin, function); in zynqmp_pinmux_set_mux()
209 dev_err(pctldev->dev, "set mux failed for pin %u\n", in zynqmp_pinmux_set_mux()
210 pin); in zynqmp_pinmux_set_mux()
219 unsigned int pin) in zynqmp_pinmux_release_pin() argument
223 ret = zynqmp_pm_pinctrl_release(pin); in zynqmp_pinmux_release_pin()
225 dev_err(pctldev->dev, "free pin failed for pin %u\n", in zynqmp_pinmux_release_pin()
226 pin); in zynqmp_pinmux_release_pin()
243 * zynqmp_pinconf_cfg_get() - get config value for the pin
244 * @pctldev: Pin control device pointer.
245 * @pin: Pin number.
249 * given pin.
254 unsigned int pin, in zynqmp_pinconf_cfg_get() argument
263 ret = zynqmp_pm_pinctrl_get_config(pin, param, &arg); in zynqmp_pinconf_cfg_get()
267 ret = zynqmp_pm_pinctrl_get_config(pin, param, &arg); in zynqmp_pinconf_cfg_get()
269 return -EINVAL; in zynqmp_pinconf_cfg_get()
275 ret = zynqmp_pm_pinctrl_get_config(pin, param, &arg); in zynqmp_pinconf_cfg_get()
277 return -EINVAL; in zynqmp_pinconf_cfg_get()
283 ret = zynqmp_pm_pinctrl_get_config(pin, param, &arg); in zynqmp_pinconf_cfg_get()
285 return -EINVAL; in zynqmp_pinconf_cfg_get()
291 ret = zynqmp_pm_pinctrl_get_config(pin, param, &arg); in zynqmp_pinconf_cfg_get()
295 ret = zynqmp_pm_pinctrl_get_config(pin, param, &arg); in zynqmp_pinconf_cfg_get()
299 ret = zynqmp_pm_pinctrl_get_config(pin, param, &arg); in zynqmp_pinconf_cfg_get()
315 dev_warn(pctldev->dev, in zynqmp_pinconf_cfg_get()
316 "Invalid drive strength for pin %d\n", in zynqmp_pinconf_cfg_get()
317 pin); in zynqmp_pinconf_cfg_get()
318 return -EINVAL; in zynqmp_pinconf_cfg_get()
322 ret = -ENOTSUPP; in zynqmp_pinconf_cfg_get()
336 * zynqmp_pinconf_cfg_set() - Set requested config for the pin
338 * @pin: Pin number.
343 * to set requested configurations for the pin.
348 unsigned int pin, unsigned long *configs, in zynqmp_pinconf_cfg_set() argument
361 ret = zynqmp_pm_pinctrl_set_config(pin, param, arg); in zynqmp_pinconf_cfg_set()
366 ret = zynqmp_pm_pinctrl_set_config(pin, param, arg); in zynqmp_pinconf_cfg_set()
371 ret = zynqmp_pm_pinctrl_set_config(pin, param, arg); in zynqmp_pinconf_cfg_set()
376 ret = zynqmp_pm_pinctrl_set_config(pin, param, arg); in zynqmp_pinconf_cfg_set()
380 ret = zynqmp_pm_pinctrl_set_config(pin, param, arg); in zynqmp_pinconf_cfg_set()
398 dev_warn(pctldev->dev, in zynqmp_pinconf_cfg_set()
399 "Invalid drive strength for pin %d\n", in zynqmp_pinconf_cfg_set()
400 pin); in zynqmp_pinconf_cfg_set()
401 return -EINVAL; in zynqmp_pinconf_cfg_set()
405 ret = zynqmp_pm_pinctrl_set_config(pin, param, value); in zynqmp_pinconf_cfg_set()
409 ret = zynqmp_pm_pinctrl_get_config(pin, param, &value); in zynqmp_pinconf_cfg_set()
412 dev_warn(pctldev->dev, in zynqmp_pinconf_cfg_set()
413 "Invalid IO Standard requested for pin %d\n", in zynqmp_pinconf_cfg_set()
414 pin); in zynqmp_pinconf_cfg_set()
420 ret = zynqmp_pm_pinctrl_set_config(pin, param, arg); in zynqmp_pinconf_cfg_set()
433 ret = zynqmp_pm_pinctrl_set_config(pin, param, arg); in zynqmp_pinconf_cfg_set()
436 dev_warn(pctldev->dev, in zynqmp_pinconf_cfg_set()
439 ret = -ENOTSUPP; in zynqmp_pinconf_cfg_set()
446 dev_warn(pctldev->dev, in zynqmp_pinconf_cfg_set()
447 "failed to set: pin %u param %u value %u\n", in zynqmp_pinconf_cfg_set()
448 pin, param, arg); in zynqmp_pinconf_cfg_set()
455 * zynqmp_pinconf_group_set() - Set requested config for the group
461 * Call function to set configs for each pin in the group.
472 const struct zynqmp_pctrl_group *pgrp = &pctrl->groups[selector]; in zynqmp_pinconf_group_set()
474 for (i = 0; i < pgrp->npins; i++) { in zynqmp_pinconf_group_set()
475 ret = zynqmp_pinconf_cfg_set(pctldev, pgrp->pins[i], configs, in zynqmp_pinconf_group_set()
537 * zynqmp_pinctrl_prepare_func_groups() - prepare function and groups data
539 * @fid: Function ID.
540 * @func: Function data.
543 * Query firmware to get group IDs for each function. Firmware returns
544 * group IDs. Based on the group index for the function, group names in
545 * the function are stored. For example, the first group in "eth0" function
548 * Based on the group ID received from the firmware, function stores name of
552 * Once done for each function, each function would have its group names
565 fgroups = devm_kzalloc(dev, sizeof(*fgroups) * func->ngroups, GFP_KERNEL); in zynqmp_pinctrl_prepare_func_groups()
567 return -ENOMEM; in zynqmp_pinctrl_prepare_func_groups()
569 for (index = 0; index < func->ngroups; index += NUM_GROUPS_PER_RESP) { in zynqmp_pinctrl_prepare_func_groups()
583 func->name, in zynqmp_pinctrl_prepare_func_groups()
586 return -ENOMEM; in zynqmp_pinctrl_prepare_func_groups()
590 func->name, in zynqmp_pinctrl_prepare_func_groups()
593 return -ENOMEM; in zynqmp_pinctrl_prepare_func_groups()
597 func->groups = fgroups; in zynqmp_pinctrl_prepare_func_groups()
611 * Name of the function is maximum 16 bytes and cannot in zynqmp_pinctrl_get_function_name()
636 static int zynqmp_pinctrl_get_pin_groups(u32 pin, u32 index, u16 *groups) in zynqmp_pinctrl_get_pin_groups() argument
643 qdata.arg1 = pin; in zynqmp_pinctrl_get_pin_groups()
656 unsigned int pin) in zynqmp_pinctrl_group_add_pin() argument
658 group->pins[group->npins++] = pin; in zynqmp_pinctrl_group_add_pin()
662 * zynqmp_pinctrl_create_pin_groups() - assign pins to respective groups
665 * @pin: Pin number.
667 * Query firmware to get groups available for the given pin.
668 * Based on the firmware response(group IDs for the pin), add
669 * pin number to the respective group's pin array.
672 * of pins and pin numbers data.
678 unsigned int pin) in zynqmp_pinctrl_create_pin_groups() argument
684 ret = zynqmp_pinctrl_get_pin_groups(pin, index, resp); in zynqmp_pinctrl_create_pin_groups()
695 zynqmp_pinctrl_group_add_pin(&groups[resp[i]], pin); in zynqmp_pinctrl_create_pin_groups()
704 * zynqmp_pinctrl_prepare_group_pins() - prepare each group's pin data
709 * Prepare pin number and number of pins data for each pins.
717 unsigned int pin; in zynqmp_pinctrl_prepare_group_pins() local
720 for (pin = 0; pin < zynqmp_desc.npins; pin++) { in zynqmp_pinctrl_prepare_group_pins()
721 ret = zynqmp_pinctrl_create_pin_groups(dev, groups, pin); in zynqmp_pinctrl_prepare_group_pins()
730 * zynqmp_pinctrl_prepare_function_info() - prepare function info
732 * @pctrl: Pin control driver data.
734 * Query firmware for functions, groups and pin information and
735 * prepare pin control driver data.
737 * Query number of functions and number of function groups (number
738 * of groups in the given function) to allocate required memory buffers
741 * (number of groups and group names for each function, number of
742 * pins and pin numbers for each group).
753 ret = zynqmp_pinctrl_get_num_functions(&pctrl->nfuncs); in zynqmp_pinctrl_prepare_function_info()
757 funcs = devm_kzalloc(dev, sizeof(*funcs) * pctrl->nfuncs, GFP_KERNEL); in zynqmp_pinctrl_prepare_function_info()
759 return -ENOMEM; in zynqmp_pinctrl_prepare_function_info()
761 for (i = 0; i < pctrl->nfuncs; i++) { in zynqmp_pinctrl_prepare_function_info()
768 pctrl->ngroups += funcs[i].ngroups; in zynqmp_pinctrl_prepare_function_info()
771 groups = devm_kzalloc(dev, sizeof(*groups) * pctrl->ngroups, GFP_KERNEL); in zynqmp_pinctrl_prepare_function_info()
773 return -ENOMEM; in zynqmp_pinctrl_prepare_function_info()
775 for (i = 0; i < pctrl->nfuncs; i++) { in zynqmp_pinctrl_prepare_function_info()
782 ret = zynqmp_pinctrl_prepare_group_pins(dev, groups, pctrl->ngroups); in zynqmp_pinctrl_prepare_function_info()
786 pctrl->funcs = funcs; in zynqmp_pinctrl_prepare_function_info()
787 pctrl->groups = groups; in zynqmp_pinctrl_prepare_function_info()
810 * zynqmp_pinctrl_prepare_pin_desc() - prepare pin description info
812 * @zynqmp_pins: Pin information.
815 * Query number of pins information from firmware and prepare pin
816 * description containing pin number and pin name.
825 struct pinctrl_pin_desc *pins, *pin; in zynqmp_pinctrl_prepare_pin_desc() local
835 return -ENOMEM; in zynqmp_pinctrl_prepare_pin_desc()
838 pin = &pins[i]; in zynqmp_pinctrl_prepare_pin_desc()
839 pin->number = i; in zynqmp_pinctrl_prepare_pin_desc()
840 pin->name = devm_kasprintf(dev, GFP_KERNEL, "%s%d", in zynqmp_pinctrl_prepare_pin_desc()
842 if (!pin->name) in zynqmp_pinctrl_prepare_pin_desc()
843 return -ENOMEM; in zynqmp_pinctrl_prepare_pin_desc()
856 pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); in zynqmp_pinctrl_probe()
858 return -ENOMEM; in zynqmp_pinctrl_probe()
860 ret = zynqmp_pinctrl_prepare_pin_desc(&pdev->dev, in zynqmp_pinctrl_probe()
864 dev_err(&pdev->dev, "pin desc prepare fail with %d\n", ret); in zynqmp_pinctrl_probe()
868 ret = zynqmp_pinctrl_prepare_function_info(&pdev->dev, pctrl); in zynqmp_pinctrl_probe()
870 dev_err(&pdev->dev, "function info prepare fail with %d\n", ret); in zynqmp_pinctrl_probe()
874 pctrl->pctrl = devm_pinctrl_register(&pdev->dev, &zynqmp_desc, pctrl); in zynqmp_pinctrl_probe()
875 if (IS_ERR(pctrl->pctrl)) in zynqmp_pinctrl_probe()
876 return PTR_ERR(pctrl->pctrl); in zynqmp_pinctrl_probe()
884 { .compatible = "xlnx,zynqmp-pinctrl" },
891 .name = "zynqmp-pinctrl",
899 MODULE_DESCRIPTION("ZynqMP Pin Controller Driver");