All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 02/41] pinctrl: Add the concept of peripheral IDs
Date: Sun, 30 Aug 2015 16:55:13 -0600	[thread overview]
Message-ID: <1440975352-28528-3-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1440975352-28528-1-git-send-email-sjg@chromium.org>

My original pinctrl patch operating using a peripheral ID enum. This was
shared between pinmux and clock and provides an easy way to specify a device
that needs to be controlled, even it is does not (yet) have a driver within
driver model.

Masahiro's new simple pinctrl gets around this by providing a
set_state_simple() pinctrl method. By passing a device to that call the
peripheral ID becomes unnecessary. If the driver needs it, it can calculate
it itself and use it internally.

However this does not solve the problem for peripheral clocks. The 'pure'
solution would be to pass a driver to the clock uclass also. But this
requires that all devices should have a driver, and a struct udevide. Also
a key optimisation of the clock uclass is allowing a peripheral clock to
be set even when there is no device for that clock.

There may be a better way to achive the same goal, but for now it seems
expedient to add in peripheral ID to the pinctrl uclass. Two methods are
added - one to get the peripheral ID and one to select it. The existing
set_state_simple() is effectively the union of these.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v5:
- Rebase on top of Masahiro's v5 series

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/pinctrl/pinctrl-uclass.c | 40 +++++++++++++++++++++------
 include/dm/pinctrl.h             | 60 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 9 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c
index d96c201..58001ef 100644
--- a/drivers/pinctrl/pinctrl-uclass.c
+++ b/drivers/pinctrl/pinctrl-uclass.c
@@ -11,6 +11,7 @@
 #include <dm/device.h>
 #include <dm/lists.h>
 #include <dm/pinctrl.h>
+#include <dm/root.h>
 #include <dm/uclass.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -159,7 +160,8 @@ static int pinctrl_select_state_full(struct udevice *dev, const char *statename)
 
 static int pinconfig_post_bind(struct udevice *dev)
 {
-	return 0;
+	/* Scan the bus for devices */
+	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
 }
 #endif
 
@@ -205,6 +207,31 @@ int pinctrl_select_state(struct udevice *dev, const char *statename)
 	return 0;
 }
 
+int pinctrl_request(struct udevice *dev, int func, int flags)
+{
+	struct pinctrl_ops *ops = pinctrl_get_ops(dev);
+
+	if (!ops->request)
+		return -ENOSYS;
+
+	return ops->request(dev, func, flags);
+}
+
+int pinctrl_request_noflags(struct udevice *dev, int func)
+{
+	return pinctrl_request(dev, func, 0);
+}
+
+int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph)
+{
+	struct pinctrl_ops *ops = pinctrl_get_ops(dev);
+
+	if (!ops->get_periph_id)
+		return -ENOSYS;
+
+	return ops->get_periph_id(dev, periph);
+}
+
 /**
  * pinconfig_post-bind() - post binding for PINCTRL uclass
  * Recursively bind child nodes as pinconfig devices in case of full pinctrl.
@@ -222,15 +249,10 @@ static int pinctrl_post_bind(struct udevice *dev)
 	}
 
 	/*
-	 * If set_state callback is set, we assume this pinctrl driver is the
-	 * full implementation.  In this case, its child nodes should be bound
-	 * so that peripheral devices can easily search in parent devices
-	 * during later DT-parsing.
+	 * The pinctrl driver child nodes should be bound so that peripheral
+	 * devices can easily search in parent devices during later DT-parsing.
 	 */
-	if (ops->set_state)
-		return pinconfig_post_bind(dev);
-
-	return 0;
+	return pinconfig_post_bind(dev);
 }
 
 UCLASS_DRIVER(pinctrl) = {
diff --git a/include/dm/pinctrl.h b/include/dm/pinctrl.h
index bc6fdb4..f6025f6 100644
--- a/include/dm/pinctrl.h
+++ b/include/dm/pinctrl.h
@@ -87,7 +87,33 @@ struct pinctrl_ops {
 	int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector,
 				 unsigned param, unsigned argument);
 	int (*set_state)(struct udevice *dev, struct udevice *config);
+
+	/* for pinctrl-simple */
 	int (*set_state_simple)(struct udevice *dev, struct udevice *periph);
+	/**
+	 * request() - Request a particular pinctrl function
+	 *
+	 * This activates the selected function.
+	 *
+	 * @dev:	Device to adjust (UCLASS_PINCTRL)
+	 * @func:	Function number (driver-specific)
+	 * @return 0 if OK, -ve on error
+	 */
+	int (*request)(struct udevice *dev, int func, int flags);
+
+	/**
+	* get_periph_id() - get the peripheral ID for a device
+	*
+	* This generally looks at the peripheral's device tree node to work
+	* out the peripheral ID. The return value is normally interpreted as
+	* enum periph_id. so long as this is defined by the platform (which it
+	* should be).
+	*
+	* @dev:		Pinctrl device to use for decoding
+	* @periph:	Device to check
+	* @return peripheral ID of @periph, or -ENOENT on error
+	*/
+	int (*get_periph_id)(struct udevice *dev, struct udevice *periph);
 };
 
 #define pinctrl_get_ops(dev)	((struct pinctrl_ops *)(dev)->driver->ops)
@@ -224,4 +250,38 @@ static inline int pinctrl_select_state(struct udevice *dev,
 }
 #endif
 
+/**
+ * pinctrl_request() - Request a particular pinctrl function
+ *
+ * @dev:	Device to check (UCLASS_PINCTRL)
+ * @func:	Function number (driver-specific)
+ * @flags:	Flags (driver-specific)
+ * @return 0 if OK, -ve on error
+ */
+int pinctrl_request(struct udevice *dev, int func, int flags);
+
+/**
+ * pinctrl_request_noflags() - Request a particular pinctrl function
+ *
+ * This is similar to pinctrl_request() but uses 0 for @flags.
+ *
+ * @dev:	Device to check (UCLASS_PINCTRL)
+ * @func:	Function number (driver-specific)
+ * @return 0 if OK, -ve on error
+ */
+int pinctrl_request_noflags(struct udevice *dev, int func);
+
+/**
+ * pinctrl_get_periph_id() - get the peripheral ID for a device
+ *
+ * This generally looks at the peripheral's device tree node to work out the
+ * peripheral ID. The return value is normally interpreted as enum periph_id.
+ * so long as this is defined by the platform (which it should be).
+ *
+ * @dev:	Pinctrl device to use for decoding
+ * @periph:	Device to check
+ * @return peripheral ID of @periph, or -ENOENT on error
+ */
+int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph);
+
 #endif /* __PINCTRL_H */
-- 
2.5.0.457.gab17608

  parent reply	other threads:[~2015-08-30 22:55 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-30 22:55 [U-Boot] [PATCH v5 00/41] dm: Introduce Rockchip RK3288 support Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 01/41] pinctrl: Add help text to Kconfig Simon Glass
2015-09-03 17:57   ` Simon Glass
2015-08-30 22:55 ` Simon Glass [this message]
2015-09-03 17:57   ` [U-Boot] [PATCH v5 02/41] pinctrl: Add the concept of peripheral IDs Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 03/41] dm: led: Tidy up SPL options for the led and led-gpio Simon Glass
2015-09-03 17:57   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 04/41] mmc: Support bypass mode with the get_mmc_clk() method Simon Glass
2015-09-03 17:58   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 05/41] dm: Improve handling of a missing uclass Simon Glass
2015-09-03 17:58   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 06/41] dm: Provide better debugging when a device fails to bind Simon Glass
2015-09-03 17:58   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 07/41] arm: reset: Avoid a build error when the reset uclass is enabled Simon Glass
2015-09-03 17:58   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 08/41] rockchip: Add serial support Simon Glass
2015-09-03 17:58   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 09/41] rockchip: Bring in RK3288 device tree file includes and bindings Simon Glass
2015-09-03 17:58   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 10/41] rockchip: rk3288: dts: Make core devices available early Simon Glass
2015-09-03 17:58   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 11/41] mkimage: Allow padding to any length Simon Glass
2015-09-03 17:58   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 12/41] mkimage: Allow the original file size to be recorded Simon Glass
2015-09-03 17:58   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 13/41] rockchip: Add the rkimage format to mkimage Simon Glass
2015-09-03 17:58   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 14/41] rockchip: Add support for the SD image Simon Glass
2015-09-03 17:58   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 15/41] rockchip: Add support for the SPI image Simon Glass
2015-09-03 17:59   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 16/41] rockchip: gpio: Add rockchip GPIO driver Simon Glass
2015-09-03 17:59   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 17/41] rockchip: Add basic peripheral and clock definitions Simon Glass
2015-09-03 17:59   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 18/41] power: Add support for ACT8846 PMIC Simon Glass
2015-09-03 17:59   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 19/41] power: regulator: Add a driver for ACT8846 regulators Simon Glass
2015-09-03 17:59   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 20/41] rockchip: rk3288: Add clock driver Simon Glass
2015-09-03 17:59   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 21/41] rockchip: rk3288: Add header files for PMU and GRF Simon Glass
2015-09-03 17:59   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 22/41] rockchip: rk3288: Add SoC reset driver Simon Glass
2015-09-03 17:59   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 23/41] rockchip: rk3288: Add a simple syscon driver Simon Glass
2015-09-03 17:59   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 24/41] rockchip: rk3288: Add pinctrl driver Simon Glass
2015-09-03 17:59   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 25/41] rockchip: rk3288: Add SDRAM init Simon Glass
2015-09-03 17:59   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 26/41] rockchip: Add an MMC driver Simon Glass
2015-09-03 17:59   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 27/41] rockchip: Add core SoC start-up code Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 28/41] rockchip: Add I2C driver Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 29/41] rockchip: Add SPI driver Simon Glass
2015-09-01  5:23   ` Jagan Teki
2015-09-02  1:03     ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 30/41] rockchip: Add basic support for firefly-rk3288 Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 31/41] rockchip: Add basic support for jerry Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 32/41] rockchip: Add a simple README Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 33/41] doc: Fix reference to Rock pro when Rock 2 is meant Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 34/41] mmc: Probe DM based mmc devices in u-boot Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 35/41] rockchip: Disable sdio mmc slot on rk3288-firefly Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 36/41] rockchip: Turn off CONFIG_SPL_LED for firefly Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 37/41] rockchip: Add config_distro_bootcmd support Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 38/41] arm: Turn of d-cache before i-cache Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 39/41] rockchip: Drop first 32kb of zeros from the rkSD image type Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 40/41] rockchip: Update todo in README.rockchip Simon Glass
2015-09-03 18:00   ` Simon Glass
2015-08-30 22:55 ` [U-Boot] [PATCH v5 41/41] rockchip: Put README image creation commands on one line Simon Glass
2015-09-03 18:00   ` Simon Glass

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=1440975352-28528-3-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.