All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudiu Beznea <claudiu.beznea@microchip.com>
To: u-boot@lists.denx.de
Subject: [PATCH 08/22] clk: at91: pmc: add helpers for clock drivers
Date: Wed, 29 Jul 2020 17:51:27 +0300	[thread overview]
Message-ID: <1596034301-5428-9-git-send-email-claudiu.beznea@microchip.com> (raw)
In-Reply-To: <1596034301-5428-1-git-send-email-claudiu.beznea@microchip.com>

Add helper for clock drivers. These will be used by following
commits in the process of switching AT91 clock drivers to CCF.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/clk/at91/pmc.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/at91/pmc.h | 13 ++++++++
 2 files changed, 104 insertions(+)

diff --git a/drivers/clk/at91/pmc.c b/drivers/clk/at91/pmc.c
index 9d9d77d861d7..0984dc321578 100644
--- a/drivers/clk/at91/pmc.c
+++ b/drivers/clk/at91/pmc.c
@@ -118,3 +118,94 @@ int at91_clk_probe(struct udevice *dev)
 
 	return 0;
 }
+
+/**
+ * pmc_read() - read content at address base + off into val
+ *
+ * @base: base address
+ * @off: offset to read from
+ * @val: where the content of base + off is stored
+ *
+ * @return: void
+ */
+void pmc_read(void __iomem *base, unsigned int off, unsigned int *val)
+{
+	*val = readl(base + off);
+}
+
+/**
+ * pmc_write() - write content of val at address base + off
+ *
+ * @base: base address
+ * @off: offset to write to
+ * @val: content to be written at base + off
+ *
+ * @return: void
+ */
+void pmc_write(void __iomem *base, unsigned int off, unsigned int val)
+{
+	writel(val, base + off);
+}
+
+/**
+ * pmc_update_bits() - update a set of bits at address base + off
+ *
+ * @base: base address
+ * @off: offset to be updated
+ * @mask: mask of bits to be updated
+ * @bits: the new value to be updated
+ *
+ * @return: void
+ */
+void pmc_update_bits(void __iomem *base, unsigned int off,
+		     unsigned int mask, unsigned int bits)
+{
+	unsigned int tmp;
+
+	tmp = readl(base + off);
+	tmp &= ~mask;
+	writel(tmp | (bits & mask), base + off);
+}
+
+/**
+ * at91_clk_mux_val_to_index() - get parent index in mux table
+ *
+ * @table: clock mux table
+ * @num_parents: clock number of parents
+ * @val: clock id who's mux index should be retrieved
+ *
+ * @return: clock index in mux table or a negative error number in case of
+ *		failure
+ */
+int at91_clk_mux_val_to_index(const u32 *table, u32 num_parents, u32 val)
+{
+	int i;
+
+	if (!table || !num_parents)
+		return -EINVAL;
+
+	for (i = 0; i < num_parents; i++) {
+		if (table[i] == val)
+			return i;
+	}
+
+	return -EINVAL;
+}
+
+/**
+ * at91_clk_mux_index_to_val() - get parent ID corresponding to an entry in
+ *	clock's mux table
+ *
+ * @table: clock's mux table
+ * @num_parents: clock's number of parents
+ * @index: index in mux table which clock's ID should be retrieved
+ *
+ * @return: clock ID or a negative error number in case of failure
+ */
+int at91_clk_mux_index_to_val(const u32 *table, u32 num_parents, u32 index)
+{
+	if (!table || !num_parents || index < 0 || index > num_parents)
+		return -EINVAL;
+
+	return table[index];
+}
diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h
index 517ba1d6b452..b1ab0a95c855 100644
--- a/drivers/clk/at91/pmc.h
+++ b/drivers/clk/at91/pmc.h
@@ -8,6 +8,12 @@
 #define __AT91_PMC_H__
 
 #include <regmap.h>
+#include <linux/bitops.h>
+#include <linux/io.h>
+
+/* Keep a range of 256 available clocks for every clock type. */
+#define AT91_TO_CLK_ID(_t, _i)		(((_t) << 8) | ((_i) & 0xff))
+#define AT91_CLK_ID_TO_DID(_i)		((_i) & 0xff)
 
 struct pmc_platdata {
 	struct at91_pmc *reg_base;
@@ -20,4 +26,11 @@ int at91_clk_sub_device_bind(struct udevice *dev, const char *drv_name);
 int at91_clk_of_xlate(struct clk *clk, struct ofnode_phandle_args *args);
 int at91_clk_probe(struct udevice *dev);
 
+int at91_clk_mux_val_to_index(const u32 *table, u32 num_parents, u32 val);
+int at91_clk_mux_index_to_val(const u32 *table, u32 num_parents, u32 index);
+
+void pmc_read(void __iomem *base, unsigned int off, unsigned int *val);
+void pmc_write(void __iomem *base, unsigned int off, unsigned int val);
+void pmc_update_bits(void __iomem *base, unsigned int off, unsigned int mask,
+			unsigned int bits);
 #endif
-- 
2.7.4

  parent reply	other threads:[~2020-07-29 14:51 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-29 14:51 [PATCH 00/22] clk: at91: add sama7g5 support Claudiu Beznea
2020-07-29 14:51 ` [PATCH 01/22] clk: check hw and hw->dev before dereference it Claudiu Beznea
2020-08-04  2:00   ` Simon Glass
2020-08-04  7:19     ` Claudiu.Beznea at microchip.com
2020-08-04 15:08       ` Simon Glass
2020-08-04 15:25         ` Claudiu.Beznea at microchip.com
2020-08-04 15:29           ` Simon Glass
2020-08-04 15:55             ` Claudiu.Beznea at microchip.com
2020-07-29 14:51 ` [PATCH 02/22] clk: check pointer returned by dev_get_parent() Claudiu Beznea
2020-08-04  2:00   ` Simon Glass
2020-08-04  7:19     ` Claudiu.Beznea at microchip.com
2020-07-29 14:51 ` [PATCH 03/22] dm: core: add support for device re-parenting Claudiu Beznea
2020-08-04  2:00   ` Simon Glass
2020-08-04  7:24     ` Claudiu.Beznea at microchip.com
2020-07-29 14:51 ` [PATCH 04/22] clk: bind clk to new parent device Claudiu Beznea
2020-08-04  2:00   ` Simon Glass
2020-08-04  7:24     ` Claudiu.Beznea at microchip.com
2020-07-29 14:51 ` [PATCH 05/22] clk: do not disable clock if it is critical Claudiu Beznea
2020-08-04  2:00   ` Simon Glass
2020-07-29 14:51 ` [PATCH 06/22] clk: get clock pointer before proceeding Claudiu Beznea
2020-08-04  2:00   ` Simon Glass
2020-08-04  7:26     ` Claudiu.Beznea at microchip.com
2020-07-29 14:51 ` [PATCH 07/22] clk: at91: add pre-requisite headers for AT91 clock architecture Claudiu Beznea
2020-07-29 14:51 ` Claudiu Beznea [this message]
2020-07-29 14:51 ` [PATCH 09/22] clk: at91: move clock code to compat.c Claudiu Beznea
2020-07-29 14:51 ` [PATCH 10/22] clk: at91: sckc: add driver compatible with ccf Claudiu Beznea
2020-07-29 14:51 ` [PATCH 11/22] clk: at91: clk-main: " Claudiu Beznea
2020-07-29 14:51 ` [PATCH 12/22] clk: at91: sam9x60-pll: " Claudiu Beznea
2020-07-29 14:51 ` [PATCH 13/22] clk: at91: clk-master: " Claudiu Beznea
2020-07-29 14:51 ` [PATCH 14/22] clk: at91: clk-master: add support for sama7g5 Claudiu Beznea
2020-07-29 14:51 ` [PATCH 15/22] clk: at91: clk-utmi: add driver compatible with ccf Claudiu Beznea
2020-07-29 14:51 ` [PATCH 16/22] clk: at91: clk-utmi: add support for sama7g5 Claudiu Beznea
2020-07-29 14:51 ` [PATCH 17/22] clk: at91: clk-programmable: add driver compatible with ccf Claudiu Beznea
2020-07-29 14:51 ` [PATCH 18/22] clk: at91: clk-system: " Claudiu Beznea
2020-07-29 14:51 ` [PATCH 19/22] clk: at91: clk-peripheral: " Claudiu Beznea
2020-07-29 14:51 ` [PATCH 20/22] clk: at91: clk-generic: " Claudiu Beznea
2020-07-29 14:51 ` [PATCH 21/22] clk: at91: pmc: add generic clock ops Claudiu Beznea
2020-07-29 14:51 ` [PATCH 22/22] clk: at91: sama7g5: add clock support Claudiu Beznea

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=1596034301-5428-9-git-send-email-claudiu.beznea@microchip.com \
    --to=claudiu.beznea@microchip.com \
    --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.