U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Dario Binacchi <dariobin@libero.it>
To: u-boot@lists.denx.de
Subject: [PATCH v2 09/12] pinctrl: single: add get_pins_count operation
Date: Thu, 28 Jan 2021 23:24:58 +0100	[thread overview]
Message-ID: <20210128222501.31943-10-dariobin@libero.it> (raw)
In-Reply-To: <20210128222501.31943-1-dariobin@libero.it>

It returns the number of selectable pins.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
Reviewed-by: Simon Glass <sjg@chromium.org>

---

Changes in v2:
- Added Simon Glass review tag.

 drivers/pinctrl/pinctrl-single.c | 37 ++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 5b3ccc2281..e99eb552f5 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -26,6 +26,16 @@ struct single_pdata {
 	bool bits_per_mux;
 };
 
+/**
+ * struct single_priv - private data
+ * @bits_per_pin: number of bits per pin
+ * @npins: number of selectable pins
+ */
+struct single_priv {
+	unsigned int bits_per_pin;
+	unsigned int npins;
+};
+
 /**
  * struct single_fdt_pin_cfg - pin configuration
  *
@@ -194,6 +204,30 @@ static int single_set_state(struct udevice *dev,
 	return len;
 }
 
+static int single_get_pins_count(struct udevice *dev)
+{
+	struct single_priv *priv = dev_get_priv(dev);
+
+	return priv->npins;
+}
+
+static int single_probe(struct udevice *dev)
+{
+	struct single_pdata *pdata = dev_get_plat(dev);
+	struct single_priv *priv = dev_get_priv(dev);
+	u32 size;
+
+	size = pdata->offset + pdata->width / BITS_PER_BYTE;
+	priv->npins = size / (pdata->width / BITS_PER_BYTE);
+	if (pdata->bits_per_mux) {
+		priv->bits_per_pin = fls(pdata->mask);
+		priv->npins *= (pdata->width / priv->bits_per_pin);
+	}
+
+	dev_dbg(dev, "%d pins\n", priv->npins);
+	return 0;
+}
+
 static int single_of_to_plat(struct udevice *dev)
 {
 	fdt_addr_t addr;
@@ -244,6 +278,7 @@ static int single_of_to_plat(struct udevice *dev)
 }
 
 const struct pinctrl_ops single_pinctrl_ops = {
+	.get_pins_count	= single_get_pins_count,
 	.set_state = single_set_state,
 };
 
@@ -258,5 +293,7 @@ U_BOOT_DRIVER(single_pinctrl) = {
 	.of_match = single_pinctrl_match,
 	.ops = &single_pinctrl_ops,
 	.plat_auto	= sizeof(struct single_pdata),
+	.priv_auto = sizeof(struct single_priv),
 	.of_to_plat = single_of_to_plat,
+	.probe = single_probe,
 };
-- 
2.17.1

  parent reply	other threads:[~2021-01-28 22:24 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28 22:24 [PATCH v2 00/12] Add support for pinmux status command on beaglebone Dario Binacchi
2021-01-28 22:24 ` [PATCH v2 01/12] pinctrl: single: fix format of structure documentation Dario Binacchi
2021-01-28 22:24 ` [PATCH v2 02/12] pinctrl: single: fix the loop counter variable type Dario Binacchi
2021-01-28 22:24 ` [PATCH v2 03/12] pinctrl: single: fix offset management Dario Binacchi
2021-01-29 16:50   ` Pratyush Yadav
2021-01-28 22:24 ` [PATCH v2 04/12] pinctrl: single: fix debug messages formatting Dario Binacchi
2021-01-29 16:53   ` Pratyush Yadav
2021-01-28 22:24 ` [PATCH v2 05/12] pinctrl: single: get register area size by device API Dario Binacchi
2021-01-29 17:47   ` Pratyush Yadav
2021-01-28 22:24 ` [PATCH v2 06/12] pinctrl: single: check "register-width" DT property Dario Binacchi
2021-01-28 22:24 ` [PATCH v2 07/12] pinctrl: single: change function mask default value Dario Binacchi
2021-02-01 20:44   ` Simon Glass
2021-01-28 22:24 ` [PATCH v2 08/12] pinctrl: single: add register access functions Dario Binacchi
2021-02-01 20:44   ` Simon Glass
2021-01-28 22:24 ` Dario Binacchi [this message]
2021-01-28 22:24 ` [PATCH v2 10/12] pinctrl: single: add get_pin_name operation Dario Binacchi
2021-01-28 22:25 ` [PATCH v2 11/12] pinctrl: single: add get_pin_muxing operation Dario Binacchi
2021-02-01 20:44   ` Simon Glass
2021-01-28 22:25 ` [PATCH v2 12/12] test: pinmux: add test for 'pinctrl-single' driver Dario Binacchi
2021-02-04 18:02 ` [PATCH v2 00/12] Add support for pinmux status command on beaglebone Lokesh Vutla
2021-02-05 10:54   ` Dario Binacchi
2021-02-05 14:17     ` Lokesh Vutla
2021-02-05 18:37       ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210128222501.31943-10-dariobin@libero.it \
    --to=dariobin@libero.it \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox