Received: by 2002:ab2:715a:0:b0:1fd:c064:50c with SMTP id l26csp133691lqm; Mon, 10 Jun 2024 15:37:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWBHIPt0lkToOqhl8lKeW6xA3zo8lOiuwv+5fF5p+IouudL0oGQYVqIFyFfOegpxkCloKcvgZ+Bc5jeqrvg7TXF5Sm15q1Q3mJJRvIg+w== X-Google-Smtp-Source: AGHT+IG+0gzziqily2TRzVv9UyLEOxIuJyHcRBQucDi2TTYO7im47JKDiyvLjm/JIRW8PsLpYEtt X-Received: by 2002:a05:6358:520d:b0:19c:334c:4ff9 with SMTP id e5c5f4694b2df-19f1fe13bf4mr1475261255d.14.1718059053180; Mon, 10 Jun 2024 15:37:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718059053; cv=pass; d=google.com; s=arc-20160816; b=cwCz6rGmLqmDOBtlKZjRDzuW7PE+nyCtRXDlNn1aBiRzIp1tgyKjxH14plHahW0pMV PINbFZHtNETRg/S0bwgedmsV8WEuzaGTJzfxNkimd93ECfyurmxwJV527OVsp2oUhtTz EedQcIKpYoX9JqpxtidKREJ5UVl3gHT+9DOYiQjZ7Ck6c6WGqbMYdl+Qdvq8HEAIGVOQ PO/uGopLVOZ4GS/eyil6ltXU5k4VAYNhGpSuAQv3eZq77gRqpi1yBKFCrG5JGAGnxUoa OVR8kf7fQIm3b+Zq/Ox3pXTIWc8GoeTtjI1xL9SbdK5vkK0r4Yffy+1zkdQbgiZ2t97a z43w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ZVakbSBa6dZitfxQZ/j7697RJOGMNZNIGWjY6iQ4YZ0=; fh=LzqOdi4fpSZxLXu47C1t9Lqa/E3Gw8ij4Vfmfc2MH8s=; b=vZKMd5RTt1BmW0O4rL4feON6T4yxktUdooG4x+WUlWOjSmiRXR/2zBGoGZWEt/BTDf KOZLxwA23yJSY06COsFfUZZ6eG1/FvJPzlL5mmNcskqbW/YH7sBM10e8X3cRsBn94JiZ 01i7uTcThHFiDRR4RiSE5iNKB1ReZUobZEjTLsV0zEZmZ4fUugGno5HZZ/aPPrXY2zmZ NsIflffwjyTwQk+pqoxgPu3bdR94dVmcaaTDbpc0qM3zilGsbQRt9Qj8F81wRgCJMrGM bs3qIFWAas5phnzgGsbd76M3jhI2JQVlzUO/B1MfynJ/svOQbU+AVk9VKgCIgjDrN3X9 w1jQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QBpCa1xA; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-209011-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209011-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6b06d8c836bsi62534846d6.272.2024.06.10.15.37.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 15:37:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209011-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QBpCa1xA; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-209011-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209011-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A9DB61C20E0D for ; Mon, 10 Jun 2024 22:37:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2FBC1514FD; Mon, 10 Jun 2024 22:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="QBpCa1xA" Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83E175466B for ; Mon, 10 Jun 2024 22:37:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718059032; cv=none; b=t8LGqEkWNzl2ewTJAR4+LJF42Cr1nCSussbSipDuaceiNIBdzQSsalMSY7FYMa6TeeNmEbvUi4LNpvJg5ZE0L5RsDmPm1wAkM6Mjx+yHjkB2sh93f7mcM941u5+imVad4RUSC7roC7Eu9tINwWfzbwmg+FEiUI0Wkm2HSBW9KbA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718059032; c=relaxed/simple; bh=66a1ffjr6Zv2xr56V1fSJTgrgR5TwTx2rgR37gxmQhQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aX4BK7REYz6Otr2/9DfiWvHFY1b+eIORqO5BLyNXRKlBYoQR6S2CsHQVR87DJOkPzYIs/mmhKyF6KYGMmCYPO0Wbjd8Qvl+nZMV1ryaoLDvCznRJ0iMe0dvCU4QxerBYYpdUhsufKJWKoChhJoe3j9qnpTFdXUE5aG29jwWL7wg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=QBpCa1xA; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: linus.walleij@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1718059028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZVakbSBa6dZitfxQZ/j7697RJOGMNZNIGWjY6iQ4YZ0=; b=QBpCa1xADX2TIdEEPQ4XIDxt0pzB31KR/qA/W0py51U3J73ttJAv5ac0BqpIi/yaVEASug dKjRJ0qJHoO3lZI1QqsUh4Wciyhm7skYZ+q/9YSziSh0Z2b2nZvtrGesoWErtIhHiFEbej avmTFm0oQn7rPt209uRLEnY72kaYlVE= X-Envelope-To: michal.simek@amd.com X-Envelope-To: linux-gpio@vger.kernel.org X-Envelope-To: andy.shevchenko@gmail.com X-Envelope-To: sai.krishna.potthuri@amd.com X-Envelope-To: linux-arm-kernel@lists.infradead.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: sean.anderson@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Sean Anderson To: Linus Walleij , Michal Simek , linux-gpio@vger.kernel.org Cc: Andy Shevchenko , Krishna Potthuri , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sean Anderson Subject: [PATCH v3 2/2] pinctrl: zynqmp: Support muxing individual pins Date: Mon, 10 Jun 2024 18:35:50 -0400 Message-Id: <20240610223550.2449230-3-sean.anderson@linux.dev> In-Reply-To: <20240610223550.2449230-1-sean.anderson@linux.dev> References: <20240610223550.2449230-1-sean.anderson@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT While muxing groups of pins at once can be convenient for large interfaces, it can also be rigid. This is because the group is set to all pins which support a particular function, even though not all pins may be used. For example, the sdhci0 function may be used with a 8-bit eMMC, 4-bit SD card, or even a 1-bit SD card. In these cases, the extra pins may be repurposed for other uses, but this is not currently allowed. There is not too much point in pin "groups" when there are not actual pin groups at the hardware level. The pins can all be muxed individually, so there's no point in adding artificial groups on top. Just mux the pins like the hardware allows. To this effect, add a new group for each pin which can be muxed. These groups are part of each function the pin can be muxed to. We treat group selectors beyond the number of groups as "pin" groups. To set this up, we initialize groups before functions, and then create a bitmap of used pins for each function. These used pins are appended to the function's list of groups. Signed-off-by: Sean Anderson --- Changes in v3: - Fix zynqmp_pinmux_set_mux and zynqmp_pinconf_group_set not handling "pin" groups (thanks Sai Krishna). Changes in v2: - Use __set_bit instead of set_bit - Use size_add when calculating the number of kcalloc members - Expand commit message with some more motivation drivers/pinctrl/pinctrl-zynqmp.c | 83 +++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/drivers/pinctrl/pinctrl-zynqmp.c b/drivers/pinctrl/pinctrl-zynqmp.c index 5c46b7d7ebcb..e4ff3c55b87d 100644 --- a/drivers/pinctrl/pinctrl-zynqmp.c +++ b/drivers/pinctrl/pinctrl-zynqmp.c @@ -10,6 +10,7 @@ #include +#include #include #include #include @@ -97,7 +98,7 @@ static int zynqmp_pctrl_get_groups_count(struct pinctrl_dev *pctldev) { struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); - return pctrl->ngroups; + return pctrl->ngroups + zynqmp_desc.npins; } static const char *zynqmp_pctrl_get_group_name(struct pinctrl_dev *pctldev, @@ -105,7 +106,10 @@ static const char *zynqmp_pctrl_get_group_name(struct pinctrl_dev *pctldev, { struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); - return pctrl->groups[selector].name; + if (selector < pctrl->ngroups) + return pctrl->groups[selector].name; + + return zynqmp_desc.pins[selector - pctrl->ngroups].name; } static int zynqmp_pctrl_get_group_pins(struct pinctrl_dev *pctldev, @@ -115,8 +119,13 @@ static int zynqmp_pctrl_get_group_pins(struct pinctrl_dev *pctldev, { struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); - *pins = pctrl->groups[selector].pins; - *npins = pctrl->groups[selector].npins; + if (selector < pctrl->ngroups) { + *pins = pctrl->groups[selector].pins; + *npins = pctrl->groups[selector].npins; + } else { + *pins = &zynqmp_desc.pins[selector - pctrl->ngroups].number; + *npins = 1; + } return 0; } @@ -197,17 +206,16 @@ static int zynqmp_pinmux_set_mux(struct pinctrl_dev *pctldev, unsigned int function, unsigned int group) { - struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); - const struct zynqmp_pctrl_group *pgrp = &pctrl->groups[group]; + const unsigned int *pins; + unsigned int npins; int ret, i; - for (i = 0; i < pgrp->npins; i++) { - unsigned int pin = pgrp->pins[i]; - - ret = zynqmp_pm_pinctrl_set_function(pin, function); + zynqmp_pctrl_get_group_pins(pctldev, group, &pins, &npins); + for (i = 0; i < npins; i++) { + ret = zynqmp_pm_pinctrl_set_function(pins[i], function); if (ret) { dev_err(pctldev->dev, "set mux failed for pin %u\n", - pin); + pins[i]); return ret; } } @@ -467,12 +475,13 @@ static int zynqmp_pinconf_group_set(struct pinctrl_dev *pctldev, unsigned long *configs, unsigned int num_configs) { + const unsigned int *pins; + unsigned int npins; int i, ret; - struct zynqmp_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); - const struct zynqmp_pctrl_group *pgrp = &pctrl->groups[selector]; - for (i = 0; i < pgrp->npins; i++) { - ret = zynqmp_pinconf_cfg_set(pctldev, pgrp->pins[i], configs, + zynqmp_pctrl_get_group_pins(pctldev, selector, &pins, &npins); + for (i = 0; i < npins; i++) { + ret = zynqmp_pinconf_cfg_set(pctldev, pins[i], configs, num_configs); if (ret) return ret; @@ -560,10 +569,12 @@ static int zynqmp_pinctrl_prepare_func_groups(struct device *dev, u32 fid, { u16 resp[NUM_GROUPS_PER_RESP] = {0}; const char **fgroups; - int ret, index, i; + int ret, index, i, pin; + unsigned int npins; + unsigned long *used_pins __free(bitmap) = + bitmap_zalloc(zynqmp_desc.npins, GFP_KERNEL); - fgroups = devm_kcalloc(dev, func->ngroups, sizeof(*fgroups), GFP_KERNEL); - if (!fgroups) + if (!used_pins) return -ENOMEM; for (index = 0; index < func->ngroups; index += NUM_GROUPS_PER_RESP) { @@ -578,23 +589,37 @@ static int zynqmp_pinctrl_prepare_func_groups(struct device *dev, u32 fid, if (resp[i] == RESERVED_GROUP) continue; - fgroups[index + i] = devm_kasprintf(dev, GFP_KERNEL, - "%s_%d_grp", - func->name, - index + i); - if (!fgroups[index + i]) - return -ENOMEM; - groups[resp[i]].name = devm_kasprintf(dev, GFP_KERNEL, "%s_%d_grp", func->name, index + i); if (!groups[resp[i]].name) return -ENOMEM; + + for (pin = 0; pin < groups[resp[i]].npins; pin++) + __set_bit(groups[resp[i]].pins[pin], used_pins); } } done: + npins = bitmap_weight(used_pins, zynqmp_desc.npins); + fgroups = devm_kcalloc(dev, size_add(func->ngroups, npins), + sizeof(*fgroups), GFP_KERNEL); + if (!fgroups) + return -ENOMEM; + + for (i = 0; i < func->ngroups; i++) { + fgroups[i] = devm_kasprintf(dev, GFP_KERNEL, "%s_%d_grp", + func->name, i); + if (!fgroups[i]) + return -ENOMEM; + } + + pin = 0; + for_each_set_bit(pin, used_pins, zynqmp_desc.npins) + fgroups[i++] = zynqmp_desc.pins[pin].name; + func->groups = fgroups; + func->ngroups += npins; return 0; } @@ -772,6 +797,10 @@ static int zynqmp_pinctrl_prepare_function_info(struct device *dev, if (!groups) return -ENOMEM; + ret = zynqmp_pinctrl_prepare_group_pins(dev, groups, pctrl->ngroups); + if (ret) + return ret; + for (i = 0; i < pctrl->nfuncs; i++) { ret = zynqmp_pinctrl_prepare_func_groups(dev, i, &funcs[i], groups); @@ -779,10 +808,6 @@ static int zynqmp_pinctrl_prepare_function_info(struct device *dev, return ret; } - ret = zynqmp_pinctrl_prepare_group_pins(dev, groups, pctrl->ngroups); - if (ret) - return ret; - pctrl->funcs = funcs; pctrl->groups = groups; -- 2.35.1.1320.gc452695387.dirty