From: "Niklas Söderlund" <niklas.soderlund@ragnatech.se>
To: Geert Uytterhoeven <geert+renesas@glider.be>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: "Linus Walleij" <linus.walleij@linaro.org>,
linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org,
"Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Subject: [PATCHv2 2/6] pinctrl: sh-pfc: Add helper to handle bias lookup table
Date: Fri, 11 Nov 2016 21:30:17 +0100 [thread overview]
Message-ID: <20161111203021.3384-3-niklas.soderlund@ragnatech.se> (raw)
In-Reply-To: <20161111203021.3384-1-niklas.soderlund@ragnatech.se>
From: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
On some SoC there are no simple mapping of pins to bias register bits
and a lookup table is needed. This logic is already implemented in some
SoC specific drivers that could benefit from a generic implementation.
Add helpers to deal with the lookup which later can be used by the SoC
specific drivers. The logic used to lookup are different from the one it
aims to replace, this is intentional. This new method reduces the memory
consumption at the cost of increased CPU usage and fix a bug where a
WARN() would incorrectly be triggered if the register offset is 0.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
drivers/pinctrl/sh-pfc/core.c | 16 ++++++++++++++++
drivers/pinctrl/sh-pfc/core.h | 4 ++++
drivers/pinctrl/sh-pfc/sh_pfc.h | 6 ++++++
3 files changed, 26 insertions(+)
diff --git a/drivers/pinctrl/sh-pfc/core.c b/drivers/pinctrl/sh-pfc/core.c
index f3a8897..8e38df7 100644
--- a/drivers/pinctrl/sh-pfc/core.c
+++ b/drivers/pinctrl/sh-pfc/core.c
@@ -389,6 +389,22 @@ int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type)
return 0;
}
+int sh_pfc_pin_to_bias_info(const struct sh_pfc_bias_info *pullups,
+ unsigned int num, unsigned int pin,
+ struct sh_pfc_bias_info *info)
+{
+ unsigned int i;
+
+ for (i = 0; i < num; i++) {
+ if (pullups[i].pin == pin) {
+ *info = pullups[i];
+ return 0;
+ }
+ }
+
+ return WARN_ON_ONCE(-EINVAL);
+}
+
static int sh_pfc_init_ranges(struct sh_pfc *pfc)
{
struct sh_pfc_pin_range *range;
diff --git a/drivers/pinctrl/sh-pfc/core.h b/drivers/pinctrl/sh-pfc/core.h
index 0bbdea58..d902cd2 100644
--- a/drivers/pinctrl/sh-pfc/core.h
+++ b/drivers/pinctrl/sh-pfc/core.h
@@ -33,4 +33,8 @@ void sh_pfc_write_reg(struct sh_pfc *pfc, u32 reg, unsigned int width,
int sh_pfc_get_pin_index(struct sh_pfc *pfc, unsigned int pin);
int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type);
+int sh_pfc_pin_to_bias_info(const struct sh_pfc_bias_info *pullups,
+ unsigned int num, unsigned int pin,
+ struct sh_pfc_bias_info *info);
+
#endif /* __SH_PFC_CORE_H__ */
diff --git a/drivers/pinctrl/sh-pfc/sh_pfc.h b/drivers/pinctrl/sh-pfc/sh_pfc.h
index 2345421..fc82b6d 100644
--- a/drivers/pinctrl/sh-pfc/sh_pfc.h
+++ b/drivers/pinctrl/sh-pfc/sh_pfc.h
@@ -189,6 +189,12 @@ struct sh_pfc_window {
unsigned long size;
};
+struct sh_pfc_bias_info {
+ unsigned int pin;
+ u16 reg : 11;
+ u16 bit : 5;
+};
+
struct sh_pfc_pin_range;
struct sh_pfc {
--
2.10.2
next prev parent reply other threads:[~2016-11-11 20:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-11 20:30 [PATCHv2 0/6] pinctrl: sh-pfc: Fixups for bias handling and preparation for none GPIO pins Niklas Söderlund
2016-11-11 20:30 ` [PATCHv2 1/6] pinctrl: sh-pfc: Do not unconditionally support PIN_CONFIG_BIAS_DISABLE Niklas Söderlund
2016-11-11 20:30 ` Niklas Söderlund [this message]
2016-11-12 1:46 ` [PATCHv2 2/6] pinctrl: sh-pfc: Add helper to handle bias lookup table Laurent Pinchart
2016-11-12 13:41 ` Niklas Söderlund
2016-11-11 20:30 ` [PATCHv2 3/6] pinctrl: sh-pfc: r8a7795: Simplify get bias logic Niklas Söderlund
2016-11-11 22:42 ` Laurent Pinchart
2016-11-11 20:30 ` [PATCHv2 4/6] pinctrl: sh-pfc: r8a7795: Use lookup function for bias data Niklas Söderlund
2016-11-12 1:47 ` Laurent Pinchart
2016-11-12 13:44 ` Niklas Söderlund
2016-11-11 20:30 ` [PATCHv2 5/6] pinctrl: sh-pfc: r8a7778: " Niklas Söderlund
2016-11-11 20:30 ` [PATCHv2 6/6] pinctrl: sh-pfc: Support named pins with custom configuration Niklas Söderlund
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=20161111203021.3384-3-niklas.soderlund@ragnatech.se \
--to=niklas.soderlund@ragnatech.se \
--cc=geert+renesas@glider.be \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
/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;
as well as URLs for NNTP newsgroup(s).