diff mbox

[2/6] pinctrl: st: Introduce a 'get pin function' call

Message ID 1426675899-19882-3-git-send-email-lee.jones@linaro.org
State New
Headers show

Commit Message

Lee Jones March 18, 2015, 10:51 a.m. UTC
This call fetches the numerical function value a specified pin is
currently operating in.  Function zero is more often than not the
GPIO function.  Greater than zero values represent an alternative
function.  You'd need to either look those up in the Device Tree
sources or the Programmer's Manual.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/pinctrl/pinctrl-st.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Maxime COQUELIN March 18, 2015, 4:41 p.m. UTC | #1
On 03/18/2015 11:51 AM, Lee Jones wrote:
> This call fetches the numerical function value a specified pin is
> currently operating in.  Function zero is more often than not the
> GPIO function.  Greater than zero values represent an alternative
> function.  You'd need to either look those up in the Device Tree
> sources or the Programmer's Manual.
>
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>   drivers/pinctrl/pinctrl-st.c | 14 ++++++++++++++
>   1 file changed, 14 insertions(+)
>
> diff --git a/drivers/pinctrl/pinctrl-st.c b/drivers/pinctrl/pinctrl-st.c
> index 9e5ec00..5362e45 100644
> --- a/drivers/pinctrl/pinctrl-st.c
> +++ b/drivers/pinctrl/pinctrl-st.c
> @@ -460,6 +460,20 @@ static void st_pctl_set_function(struct st_pio_control *pc,
>   	regmap_field_write(alt, val);
>   }
>   
> +static unsigned int st_pctl_get_pin_function(struct st_pio_control *pc, int pin)
> +{
> +	struct regmap_field *alt = pc->alt;
> +	unsigned int val;
> +	int offset = pin * 4;
> +
> +	if (!alt)
> +		return 0;
Shouldn't we print something if alt is NULL?
Else we can think we are on alternate 0.

> +
> +	regmap_field_read(alt, &val);
> +
> +	return (val >> offset) & 0xf;
> +}
> +
>   static unsigned long st_pinconf_delay_to_bit(unsigned int delay,
>   	const struct st_pctl_data *data, unsigned long config)
>   {

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lee Jones March 18, 2015, 4:51 p.m. UTC | #2
On Wed, 18 Mar 2015, Maxime Coquelin wrote:

> 
> 
> On 03/18/2015 11:51 AM, Lee Jones wrote:
> >This call fetches the numerical function value a specified pin is
> >currently operating in.  Function zero is more often than not the
> >GPIO function.  Greater than zero values represent an alternative
> >function.  You'd need to either look those up in the Device Tree
> >sources or the Programmer's Manual.
> >
> >Signed-off-by: Lee Jones <lee.jones@linaro.org>
> >---
> >  drivers/pinctrl/pinctrl-st.c | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> >
> >diff --git a/drivers/pinctrl/pinctrl-st.c b/drivers/pinctrl/pinctrl-st.c
> >index 9e5ec00..5362e45 100644
> >--- a/drivers/pinctrl/pinctrl-st.c
> >+++ b/drivers/pinctrl/pinctrl-st.c
> >@@ -460,6 +460,20 @@ static void st_pctl_set_function(struct st_pio_control *pc,
> >  	regmap_field_write(alt, val);
> >  }
> >+static unsigned int st_pctl_get_pin_function(struct st_pio_control *pc, int pin)
> >+{
> >+	struct regmap_field *alt = pc->alt;
> >+	unsigned int val;
> >+	int offset = pin * 4;
> >+
> >+	if (!alt)
> >+		return 0;
> Shouldn't we print something if alt is NULL?
> Else we can think we are on alternate 0.

That is the assumption that I've made.  Is there isn't an alt, then a
pin can only be on Alt-0.  Have I made the incorrect assumption here?

> >+
> >+	regmap_field_read(alt, &val);
> >+
> >+	return (val >> offset) & 0xf;
> >+}
> >+
> >  static unsigned long st_pinconf_delay_to_bit(unsigned int delay,
> >  	const struct st_pctl_data *data, unsigned long config)
> >  {
>
Maxime COQUELIN March 18, 2015, 5 p.m. UTC | #3
On 03/18/2015 05:51 PM, Lee Jones wrote:
> On Wed, 18 Mar 2015, Maxime Coquelin wrote:
>
>>
>> On 03/18/2015 11:51 AM, Lee Jones wrote:
>>> This call fetches the numerical function value a specified pin is
>>> currently operating in.  Function zero is more often than not the
>>> GPIO function.  Greater than zero values represent an alternative
>>> function.  You'd need to either look those up in the Device Tree
>>> sources or the Programmer's Manual.
>>>
>>> Signed-off-by: Lee Jones <lee.jones@linaro.org>
>>> ---
>>>   drivers/pinctrl/pinctrl-st.c | 14 ++++++++++++++
>>>   1 file changed, 14 insertions(+)
>>>
>>> diff --git a/drivers/pinctrl/pinctrl-st.c b/drivers/pinctrl/pinctrl-st.c
>>> index 9e5ec00..5362e45 100644
>>> --- a/drivers/pinctrl/pinctrl-st.c
>>> +++ b/drivers/pinctrl/pinctrl-st.c
>>> @@ -460,6 +460,20 @@ static void st_pctl_set_function(struct st_pio_control *pc,
>>>   	regmap_field_write(alt, val);
>>>   }
>>> +static unsigned int st_pctl_get_pin_function(struct st_pio_control *pc, int pin)
>>> +{
>>> +	struct regmap_field *alt = pc->alt;
>>> +	unsigned int val;
>>> +	int offset = pin * 4;
>>> +
>>> +	if (!alt)
>>> +		return 0;
>> Shouldn't we print something if alt is NULL?
>> Else we can think we are on alternate 0.
> That is the assumption that I've made.  Is there isn't an alt, then a
> pin can only be on Alt-0.  Have I made the incorrect assumption here?
Just re-checked the code, and yes you are right.
No alt here means alt field of struct st_pctl_data is -1, which in turn 
means the register is not available.

You can forget my remark, and add my:
Acked-by: Maxime Coquelin <maxime.coquelin@st.com>

Thanks,
Maxime
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/pinctrl/pinctrl-st.c b/drivers/pinctrl/pinctrl-st.c
index 9e5ec00..5362e45 100644
--- a/drivers/pinctrl/pinctrl-st.c
+++ b/drivers/pinctrl/pinctrl-st.c
@@ -460,6 +460,20 @@  static void st_pctl_set_function(struct st_pio_control *pc,
 	regmap_field_write(alt, val);
 }
 
+static unsigned int st_pctl_get_pin_function(struct st_pio_control *pc, int pin)
+{
+	struct regmap_field *alt = pc->alt;
+	unsigned int val;
+	int offset = pin * 4;
+
+	if (!alt)
+		return 0;
+
+	regmap_field_read(alt, &val);
+
+	return (val >> offset) & 0xf;
+}
+
 static unsigned long st_pinconf_delay_to_bit(unsigned int delay,
 	const struct st_pctl_data *data, unsigned long config)
 {