pinctrl-zynqmp.c (50287367812602598a39f93620ec7cf009443258) pinctrl-zynqmp.c (f28cbab9bbd57abc3661ff84b7df60e28ded20b7)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * ZynqMP pin controller
4 *
5 * Copyright (C) 2020, 2021 Xilinx, Inc.
6 *
7 * Sai Krishna Potthuri <lakshmi.sai.krishna.potthuri@xilinx.com>
8 * Rajan Vaja <rajan.vaja@xilinx.com>
9 */
10
11#include <dt-bindings/pinctrl/pinctrl-zynqmp.h>
12
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * ZynqMP pin controller
4 *
5 * Copyright (C) 2020, 2021 Xilinx, Inc.
6 *
7 * Sai Krishna Potthuri <lakshmi.sai.krishna.potthuri@xilinx.com>
8 * Rajan Vaja <rajan.vaja@xilinx.com>
9 */
10
11#include <dt-bindings/pinctrl/pinctrl-zynqmp.h>
12
13#include <linux/bitmap.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/of_address.h>
16#include <linux/platform_device.h>
17
18#include <linux/firmware/xlnx-zynqmp.h>
19
20#include <linux/pinctrl/pinconf-generic.h>

--- 71 unchanged lines hidden (view full) ---

92};
93
94static struct pinctrl_desc zynqmp_desc;
95
96static int zynqmp_pctrl_get_groups_count(struct pinctrl_dev *pctldev)
97{
98 struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
99
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/of_address.h>
17#include <linux/platform_device.h>
18
19#include <linux/firmware/xlnx-zynqmp.h>
20
21#include <linux/pinctrl/pinconf-generic.h>

--- 71 unchanged lines hidden (view full) ---

93};
94
95static struct pinctrl_desc zynqmp_desc;
96
97static int zynqmp_pctrl_get_groups_count(struct pinctrl_dev *pctldev)
98{
99 struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
100
100 return pctrl->ngroups;
101 return pctrl->ngroups + zynqmp_desc.npins;
101}
102
103static const char *zynqmp_pctrl_get_group_name(struct pinctrl_dev *pctldev,
104 unsigned int selector)
105{
106 struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
107
102}
103
104static const char *zynqmp_pctrl_get_group_name(struct pinctrl_dev *pctldev,
105 unsigned int selector)
106{
107 struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
108
108 return pctrl->groups[selector].name;
109 if (selector < pctrl->ngroups)
110 return pctrl->groups[selector].name;
111
112 return zynqmp_desc.pins[selector - pctrl->ngroups].name;
109}
110
111static int zynqmp_pctrl_get_group_pins(struct pinctrl_dev *pctldev,
112 unsigned int selector,
113 const unsigned int **pins,
114 unsigned int *npins)
115{
116 struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
117
113}
114
115static int zynqmp_pctrl_get_group_pins(struct pinctrl_dev *pctldev,
116 unsigned int selector,
117 const unsigned int **pins,
118 unsigned int *npins)
119{
120 struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
121
118 *pins = pctrl->groups[selector].pins;
119 *npins = pctrl->groups[selector].npins;
122 if (selector < pctrl->ngroups) {
123 *pins = pctrl->groups[selector].pins;
124 *npins = pctrl->groups[selector].npins;
125 } else {
126 *pins = &zynqmp_desc.pins[selector - pctrl->ngroups].number;
127 *npins = 1;
128 }
120
121 return 0;
122}
123
124static const struct pinctrl_ops zynqmp_pctrl_ops = {
125 .get_groups_count = zynqmp_pctrl_get_groups_count,
126 .get_group_name = zynqmp_pctrl_get_group_name,
127 .get_group_pins = zynqmp_pctrl_get_group_pins,

--- 64 unchanged lines hidden (view full) ---

192 * to set requested function for all pins in the group.
193 *
194 * Return: 0 on success else error code.
195 */
196static int zynqmp_pinmux_set_mux(struct pinctrl_dev *pctldev,
197 unsigned int function,
198 unsigned int group)
199{
129
130 return 0;
131}
132
133static const struct pinctrl_ops zynqmp_pctrl_ops = {
134 .get_groups_count = zynqmp_pctrl_get_groups_count,
135 .get_group_name = zynqmp_pctrl_get_group_name,
136 .get_group_pins = zynqmp_pctrl_get_group_pins,

--- 64 unchanged lines hidden (view full) ---

201 * to set requested function for all pins in the group.
202 *
203 * Return: 0 on success else error code.
204 */
205static int zynqmp_pinmux_set_mux(struct pinctrl_dev *pctldev,
206 unsigned int function,
207 unsigned int group)
208{
200 struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
201 const struct zynqmp_pctrl_group *pgrp = &pctrl->groups[group];
209 const unsigned int *pins;
210 unsigned int npins;
202 int ret, i;
203
211 int ret, i;
212
204 for (i = 0; i < pgrp->npins; i++) {
205 unsigned int pin = pgrp->pins[i];
206
207 ret = zynqmp_pm_pinctrl_set_function(pin, function);
213 zynqmp_pctrl_get_group_pins(pctldev, group, &pins, &npins);
214 for (i = 0; i < npins; i++) {
215 ret = zynqmp_pm_pinctrl_set_function(pins[i], function);
208 if (ret) {
209 dev_err(pctldev->dev, "set mux failed for pin %u\n",
216 if (ret) {
217 dev_err(pctldev->dev, "set mux failed for pin %u\n",
210 pin);
218 pins[i]);
211 return ret;
212 }
213 }
214
215 return 0;
216}
217
218static int zynqmp_pinmux_release_pin(struct pinctrl_dev *pctldev,

--- 243 unchanged lines hidden (view full) ---

462 *
463 * Return: 0 on success else error code.
464 */
465static int zynqmp_pinconf_group_set(struct pinctrl_dev *pctldev,
466 unsigned int selector,
467 unsigned long *configs,
468 unsigned int num_configs)
469{
219 return ret;
220 }
221 }
222
223 return 0;
224}
225
226static int zynqmp_pinmux_release_pin(struct pinctrl_dev *pctldev,

--- 243 unchanged lines hidden (view full) ---

470 *
471 * Return: 0 on success else error code.
472 */
473static int zynqmp_pinconf_group_set(struct pinctrl_dev *pctldev,
474 unsigned int selector,
475 unsigned long *configs,
476 unsigned int num_configs)
477{
478 const unsigned int *pins;
479 unsigned int npins;
470 int i, ret;
480 int i, ret;
471 struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
472 const struct zynqmp_pctrl_group *pgrp = &pctrl->groups[selector];
473
481
474 for (i = 0; i < pgrp->npins; i++) {
475 ret = zynqmp_pinconf_cfg_set(pctldev, pgrp->pins[i], configs,
482 zynqmp_pctrl_get_group_pins(pctldev, selector, &pins, &npins);
483 for (i = 0; i < npins; i++) {
484 ret = zynqmp_pinconf_cfg_set(pctldev, pins[i], configs,
476 num_configs);
477 if (ret)
478 return ret;
479 }
480
481 return 0;
482}
483

--- 71 unchanged lines hidden (view full) ---

555 * Return: 0 on success else error code.
556 */
557static int zynqmp_pinctrl_prepare_func_groups(struct device *dev, u32 fid,
558 struct zynqmp_pmux_function *func,
559 struct zynqmp_pctrl_group *groups)
560{
561 u16 resp[NUM_GROUPS_PER_RESP] = {0};
562 const char **fgroups;
485 num_configs);
486 if (ret)
487 return ret;
488 }
489
490 return 0;
491}
492

--- 71 unchanged lines hidden (view full) ---

564 * Return: 0 on success else error code.
565 */
566static int zynqmp_pinctrl_prepare_func_groups(struct device *dev, u32 fid,
567 struct zynqmp_pmux_function *func,
568 struct zynqmp_pctrl_group *groups)
569{
570 u16 resp[NUM_GROUPS_PER_RESP] = {0};
571 const char **fgroups;
563 int ret, index, i;
572 int ret, index, i, pin;
573 unsigned int npins;
574 unsigned long *used_pins __free(bitmap) =
575 bitmap_zalloc(zynqmp_desc.npins, GFP_KERNEL);
564
576
565 fgroups = devm_kcalloc(dev, func->ngroups, sizeof(*fgroups), GFP_KERNEL);
566 if (!fgroups)
577 if (!used_pins)
567 return -ENOMEM;
568
569 for (index = 0; index < func->ngroups; index += NUM_GROUPS_PER_RESP) {
570 ret = zynqmp_pinctrl_get_function_groups(fid, index, resp);
571 if (ret)
572 return ret;
573
574 for (i = 0; i < NUM_GROUPS_PER_RESP; i++) {
575 if (resp[i] == NA_GROUP)
576 goto done;
577
578 if (resp[i] == RESERVED_GROUP)
579 continue;
580
578 return -ENOMEM;
579
580 for (index = 0; index < func->ngroups; index += NUM_GROUPS_PER_RESP) {
581 ret = zynqmp_pinctrl_get_function_groups(fid, index, resp);
582 if (ret)
583 return ret;
584
585 for (i = 0; i < NUM_GROUPS_PER_RESP; i++) {
586 if (resp[i] == NA_GROUP)
587 goto done;
588
589 if (resp[i] == RESERVED_GROUP)
590 continue;
591
581 fgroups[index + i] = devm_kasprintf(dev, GFP_KERNEL,
582 "%s_%d_grp",
583 func->name,
584 index + i);
585 if (!fgroups[index + i])
586 return -ENOMEM;
587
588 groups[resp[i]].name = devm_kasprintf(dev, GFP_KERNEL,
589 "%s_%d_grp",
590 func->name,
591 index + i);
592 if (!groups[resp[i]].name)
593 return -ENOMEM;
592 groups[resp[i]].name = devm_kasprintf(dev, GFP_KERNEL,
593 "%s_%d_grp",
594 func->name,
595 index + i);
596 if (!groups[resp[i]].name)
597 return -ENOMEM;
598
599 for (pin = 0; pin < groups[resp[i]].npins; pin++)
600 __set_bit(groups[resp[i]].pins[pin], used_pins);
594 }
595 }
596done:
601 }
602 }
603done:
604 npins = bitmap_weight(used_pins, zynqmp_desc.npins);
605 fgroups = devm_kcalloc(dev, size_add(func->ngroups, npins),
606 sizeof(*fgroups), GFP_KERNEL);
607 if (!fgroups)
608 return -ENOMEM;
609
610 for (i = 0; i < func->ngroups; i++) {
611 fgroups[i] = devm_kasprintf(dev, GFP_KERNEL, "%s_%d_grp",
612 func->name, i);
613 if (!fgroups[i])
614 return -ENOMEM;
615 }
616
617 pin = 0;
618 for_each_set_bit(pin, used_pins, zynqmp_desc.npins)
619 fgroups[i++] = zynqmp_desc.pins[pin].name;
620
597 func->groups = fgroups;
621 func->groups = fgroups;
622 func->ngroups += npins;
598
599 return 0;
600}
601
602static void zynqmp_pinctrl_get_function_name(u32 fid, char *name)
603{
604 struct zynqmp_pm_query_data qdata = {0};
605 u32 payload[PAYLOAD_ARG_CNT];

--- 161 unchanged lines hidden (view full) ---

767
768 pctrl->ngroups += funcs[i].ngroups;
769 }
770
771 groups = devm_kcalloc(dev, pctrl->ngroups, sizeof(*groups), GFP_KERNEL);
772 if (!groups)
773 return -ENOMEM;
774
623
624 return 0;
625}
626
627static void zynqmp_pinctrl_get_function_name(u32 fid, char *name)
628{
629 struct zynqmp_pm_query_data qdata = {0};
630 u32 payload[PAYLOAD_ARG_CNT];

--- 161 unchanged lines hidden (view full) ---

792
793 pctrl->ngroups += funcs[i].ngroups;
794 }
795
796 groups = devm_kcalloc(dev, pctrl->ngroups, sizeof(*groups), GFP_KERNEL);
797 if (!groups)
798 return -ENOMEM;
799
800 ret = zynqmp_pinctrl_prepare_group_pins(dev, groups, pctrl->ngroups);
801 if (ret)
802 return ret;
803
775 for (i = 0; i < pctrl->nfuncs; i++) {
776 ret = zynqmp_pinctrl_prepare_func_groups(dev, i, &funcs[i],
777 groups);
778 if (ret)
779 return ret;
780 }
781
804 for (i = 0; i < pctrl->nfuncs; i++) {
805 ret = zynqmp_pinctrl_prepare_func_groups(dev, i, &funcs[i],
806 groups);
807 if (ret)
808 return ret;
809 }
810
782 ret = zynqmp_pinctrl_prepare_group_pins(dev, groups, pctrl->ngroups);
783 if (ret)
784 return ret;
785
786 pctrl->funcs = funcs;
787 pctrl->groups = groups;
788
789 return 0;
790}
791
792static int zynqmp_pinctrl_get_num_pins(unsigned int *npins)
793{

--- 107 unchanged lines hidden ---
811 pctrl->funcs = funcs;
812 pctrl->groups = groups;
813
814 return 0;
815}
816
817static int zynqmp_pinctrl_get_num_pins(unsigned int *npins)
818{

--- 107 unchanged lines hidden ---