diff mbox series

[2/5] pinctrl: meson: Add support to set direction with a secure monitor call

Message ID 1533117623-27856-3-git-send-email-narmstrong@baylibre.com (mailing list archive)
State New, archived
Headers show
Series pinctrl: meson: Add support for TEST_N gpio | expand

Commit Message

Neil Armstrong Aug. 1, 2018, 10 a.m. UTC
The Amlogic Meson GX and AXG SoCs needs to do a Secure Monitor call to
set the TEST_N pin direction.
This patch adds a "smc" boolean to the bank structure to differentiate
the TEST_N bank and call the Secure Monitor in the _input/_output functions.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
---
 drivers/pinctrl/meson/Kconfig         |  1 +
 drivers/pinctrl/meson/pinctrl-meson.c | 31 ++++++++++++++++++++++++++-----
 drivers/pinctrl/meson/pinctrl-meson.h | 10 +++++++++-
 3 files changed, 36 insertions(+), 6 deletions(-)

Comments

Martin Blumenstingl Aug. 1, 2018, 8:23 p.m. UTC | #1
Hi Neil,

On Wed, Aug 1, 2018 at 12:05 PM Neil Armstrong <narmstrong@baylibre.com> wrote:
>
> The Amlogic Meson GX and AXG SoCs needs to do a Secure Monitor call to
> set the TEST_N pin direction.
> This patch adds a "smc" boolean to the bank structure to differentiate
> the TEST_N bank and call the Secure Monitor in the _input/_output functions.
>
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> ---
>  drivers/pinctrl/meson/Kconfig         |  1 +
>  drivers/pinctrl/meson/pinctrl-meson.c | 31 ++++++++++++++++++++++++++-----
>  drivers/pinctrl/meson/pinctrl-meson.h | 10 +++++++++-
>  3 files changed, 36 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pinctrl/meson/Kconfig b/drivers/pinctrl/meson/Kconfig
> index c80951d..1b90470 100644
> --- a/drivers/pinctrl/meson/Kconfig
> +++ b/drivers/pinctrl/meson/Kconfig
> @@ -8,6 +8,7 @@ menuconfig PINCTRL_MESON
>         select GPIOLIB
>         select OF_GPIO
>         select REGMAP_MMIO
> +       select MESON_SM
I wonder why PINCTRL_MESON has to select MESON_SM - shouldn't
PINCTRL_MESON_GXBB, PINCTRL_MESON_GXL and PINCTRL_MESON_AXG select it
instead?
selecting MESON_SM is probably no-op on Meson8 and Meson8b (which
don't have the GX secure monitor), but I haven't tested it yet


Regards
Martin
Neil Armstrong Aug. 2, 2018, 7:52 a.m. UTC | #2
On 01/08/2018 22:23, Martin Blumenstingl wrote:
> Hi Neil,
> 
> On Wed, Aug 1, 2018 at 12:05 PM Neil Armstrong <narmstrong@baylibre.com> wrote:
>>
>> The Amlogic Meson GX and AXG SoCs needs to do a Secure Monitor call to
>> set the TEST_N pin direction.
>> This patch adds a "smc" boolean to the bank structure to differentiate
>> the TEST_N bank and call the Secure Monitor in the _input/_output functions.
>>
>> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
>> ---
>>  drivers/pinctrl/meson/Kconfig         |  1 +
>>  drivers/pinctrl/meson/pinctrl-meson.c | 31 ++++++++++++++++++++++++++-----
>>  drivers/pinctrl/meson/pinctrl-meson.h | 10 +++++++++-
>>  3 files changed, 36 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/pinctrl/meson/Kconfig b/drivers/pinctrl/meson/Kconfig
>> index c80951d..1b90470 100644
>> --- a/drivers/pinctrl/meson/Kconfig
>> +++ b/drivers/pinctrl/meson/Kconfig
>> @@ -8,6 +8,7 @@ menuconfig PINCTRL_MESON
>>         select GPIOLIB
>>         select OF_GPIO
>>         select REGMAP_MMIO
>> +       select MESON_SM
> I wonder why PINCTRL_MESON has to select MESON_SM - shouldn't
> PINCTRL_MESON_GXBB, PINCTRL_MESON_GXL and PINCTRL_MESON_AXG select it
> instead?
> selecting MESON_SM is probably no-op on Meson8 and Meson8b (which
> don't have the GX secure monitor), but I haven't tested it yet

Hi Martin, you are right !

I will fix it on v2..

Neil

> 
> 
> Regards
> Martin
>
Jerome Brunet Aug. 2, 2018, 11:21 a.m. UTC | #3
On Thu, 2018-08-02 at 09:52 +0200, Neil Armstrong wrote:
> On 01/08/2018 22:23, Martin Blumenstingl wrote:
> > Hi Neil,
> > 
> > On Wed, Aug 1, 2018 at 12:05 PM Neil Armstrong <narmstrong@baylibre.com> wrote:
> > > 
> > > The Amlogic Meson GX and AXG SoCs needs to do a Secure Monitor call to
> > > set the TEST_N pin direction.
> > > This patch adds a "smc" boolean to the bank structure to differentiate
> > > the TEST_N bank and call the Secure Monitor in the _input/_output functions.
> > > 
> > > Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> > > ---
> > >  drivers/pinctrl/meson/Kconfig         |  1 +
> > >  drivers/pinctrl/meson/pinctrl-meson.c | 31 ++++++++++++++++++++++++++-----
> > >  drivers/pinctrl/meson/pinctrl-meson.h | 10 +++++++++-
> > >  3 files changed, 36 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/drivers/pinctrl/meson/Kconfig b/drivers/pinctrl/meson/Kconfig
> > > index c80951d..1b90470 100644
> > > --- a/drivers/pinctrl/meson/Kconfig
> > > +++ b/drivers/pinctrl/meson/Kconfig
> > > @@ -8,6 +8,7 @@ menuconfig PINCTRL_MESON
> > >         select GPIOLIB
> > >         select OF_GPIO
> > >         select REGMAP_MMIO
> > > +       select MESON_SM
> > 
> > I wonder why PINCTRL_MESON has to select MESON_SM - shouldn't
> > PINCTRL_MESON_GXBB, PINCTRL_MESON_GXL and PINCTRL_MESON_AXG select it
> > instead?
> > selecting MESON_SM is probably no-op on Meson8 and Meson8b (which
> > don't have the GX secure monitor), but I haven't tested it yet

I'm not so sure about that. meson_sm_call() symbol is used in the common pinctrl
code, so it should be selected when compiled even if meson8b is not going to use
it in the end.

> 
> Hi Martin, you are right !
> 
> I will fix it on v2..
> 
> Neil
> 
> > 
> > 
> > Regards
> > Martin
> > 
> 
>
Martin Blumenstingl Aug. 2, 2018, 8:42 p.m. UTC | #4
On Thu, Aug 2, 2018 at 1:21 PM Jerome Brunet <jbrunet@baylibre.com> wrote:
>
> On Thu, 2018-08-02 at 09:52 +0200, Neil Armstrong wrote:
> > On 01/08/2018 22:23, Martin Blumenstingl wrote:
> > > Hi Neil,
> > >
> > > On Wed, Aug 1, 2018 at 12:05 PM Neil Armstrong <narmstrong@baylibre.com> wrote:
> > > >
> > > > The Amlogic Meson GX and AXG SoCs needs to do a Secure Monitor call to
> > > > set the TEST_N pin direction.
> > > > This patch adds a "smc" boolean to the bank structure to differentiate
> > > > the TEST_N bank and call the Secure Monitor in the _input/_output functions.
> > > >
> > > > Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> > > > ---
> > > >  drivers/pinctrl/meson/Kconfig         |  1 +
> > > >  drivers/pinctrl/meson/pinctrl-meson.c | 31 ++++++++++++++++++++++++++-----
> > > >  drivers/pinctrl/meson/pinctrl-meson.h | 10 +++++++++-
> > > >  3 files changed, 36 insertions(+), 6 deletions(-)
> > > >
> > > > diff --git a/drivers/pinctrl/meson/Kconfig b/drivers/pinctrl/meson/Kconfig
> > > > index c80951d..1b90470 100644
> > > > --- a/drivers/pinctrl/meson/Kconfig
> > > > +++ b/drivers/pinctrl/meson/Kconfig
> > > > @@ -8,6 +8,7 @@ menuconfig PINCTRL_MESON
> > > >         select GPIOLIB
> > > >         select OF_GPIO
> > > >         select REGMAP_MMIO
> > > > +       select MESON_SM
> > >
> > > I wonder why PINCTRL_MESON has to select MESON_SM - shouldn't
> > > PINCTRL_MESON_GXBB, PINCTRL_MESON_GXL and PINCTRL_MESON_AXG select it
> > > instead?
> > > selecting MESON_SM is probably no-op on Meson8 and Meson8b (which
> > > don't have the GX secure monitor), but I haven't tested it yet
>
> I'm not so sure about that. meson_sm_call() symbol is used in the common pinctrl
> code, so it should be selected when compiled even if meson8b is not going to use
> it in the end.
unfortunately MESON_SM depends on ARM64_4K_PAGES so it can't be
enabled for the 32-bit SoCs
any ideas how to solve this?


Regards
Martin
Neil Armstrong Aug. 3, 2018, 8:10 a.m. UTC | #5
On 02/08/2018 22:42, Martin Blumenstingl wrote:
> On Thu, Aug 2, 2018 at 1:21 PM Jerome Brunet <jbrunet@baylibre.com> wrote:
>>
>> On Thu, 2018-08-02 at 09:52 +0200, Neil Armstrong wrote:
>>> On 01/08/2018 22:23, Martin Blumenstingl wrote:
>>>> Hi Neil,
>>>>
>>>> On Wed, Aug 1, 2018 at 12:05 PM Neil Armstrong <narmstrong@baylibre.com> wrote:
>>>>>
>>>>> The Amlogic Meson GX and AXG SoCs needs to do a Secure Monitor call to
>>>>> set the TEST_N pin direction.
>>>>> This patch adds a "smc" boolean to the bank structure to differentiate
>>>>> the TEST_N bank and call the Secure Monitor in the _input/_output functions.
>>>>>
>>>>> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
>>>>> ---
>>>>>  drivers/pinctrl/meson/Kconfig         |  1 +
>>>>>  drivers/pinctrl/meson/pinctrl-meson.c | 31 ++++++++++++++++++++++++++-----
>>>>>  drivers/pinctrl/meson/pinctrl-meson.h | 10 +++++++++-
>>>>>  3 files changed, 36 insertions(+), 6 deletions(-)
>>>>>
>>>>> diff --git a/drivers/pinctrl/meson/Kconfig b/drivers/pinctrl/meson/Kconfig
>>>>> index c80951d..1b90470 100644
>>>>> --- a/drivers/pinctrl/meson/Kconfig
>>>>> +++ b/drivers/pinctrl/meson/Kconfig
>>>>> @@ -8,6 +8,7 @@ menuconfig PINCTRL_MESON
>>>>>         select GPIOLIB
>>>>>         select OF_GPIO
>>>>>         select REGMAP_MMIO
>>>>> +       select MESON_SM
>>>>
>>>> I wonder why PINCTRL_MESON has to select MESON_SM - shouldn't
>>>> PINCTRL_MESON_GXBB, PINCTRL_MESON_GXL and PINCTRL_MESON_AXG select it
>>>> instead?
>>>> selecting MESON_SM is probably no-op on Meson8 and Meson8b (which
>>>> don't have the GX secure monitor), but I haven't tested it yet
>>
>> I'm not so sure about that. meson_sm_call() symbol is used in the common pinctrl
>> code, so it should be selected when compiled even if meson8b is not going to use
>> it in the end.
> unfortunately MESON_SM depends on ARM64_4K_PAGES so it can't be
> enabled for the 32-bit SoCs
> any ideas how to solve this?

I think I'll need to wrap the meson_sm calls around a
#if IS_ENABLED(MESON_SM)

and
select MESON_SM if ARM64

in Kconfig

> 
> 
> Regards
> Martin
>
diff mbox series

Patch

diff --git a/drivers/pinctrl/meson/Kconfig b/drivers/pinctrl/meson/Kconfig
index c80951d..1b90470 100644
--- a/drivers/pinctrl/meson/Kconfig
+++ b/drivers/pinctrl/meson/Kconfig
@@ -8,6 +8,7 @@  menuconfig PINCTRL_MESON
 	select GPIOLIB
 	select OF_GPIO
 	select REGMAP_MMIO
+	select MESON_SM
 
 if PINCTRL_MESON
 
diff --git a/drivers/pinctrl/meson/pinctrl-meson.c b/drivers/pinctrl/meson/pinctrl-meson.c
index 29a458d..8e445aa 100644
--- a/drivers/pinctrl/meson/pinctrl-meson.c
+++ b/drivers/pinctrl/meson/pinctrl-meson.c
@@ -54,6 +54,7 @@ 
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/seq_file.h>
+#include <linux/firmware/meson/meson_sm.h>
 
 #include "../core.h"
 #include "../pinctrl-utils.h"
@@ -99,8 +100,14 @@  static void meson_calc_reg_and_bit(struct meson_bank *bank, unsigned int pin,
 {
 	struct meson_reg_desc *desc = &bank->regs[reg_type];
 
-	*reg = desc->reg * 4;
-	*bit = desc->bit + pin - bank->first;
+	/* TEST_N pin direction needs to be set using a Secure Monitor call */
+	if (reg_type == REG_DIR && bank->smc) {
+		*reg = desc->reg;
+		*bit = desc->bit;
+	} else {
+		*reg = desc->reg * 4;
+		*bit = desc->bit + pin - bank->first;
+	}
 }
 
 static int meson_get_groups_count(struct pinctrl_dev *pcdev)
@@ -342,6 +349,12 @@  static int meson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
 
 	meson_calc_reg_and_bit(bank, gpio, REG_DIR, &reg, &bit);
 
+	/* TEST_N pin direction needs to be set using a Secure Monitor call */
+	if (bank->smc) {
+		u32 smc_ret = 0;
+		return meson_sm_call(reg, &smc_ret, 0, 0, 0, 0, 0);
+	}
+
 	return regmap_update_bits(pc->reg_gpio, reg, BIT(bit), BIT(bit));
 }
 
@@ -358,9 +371,17 @@  static int meson_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
 		return ret;
 
 	meson_calc_reg_and_bit(bank, gpio, REG_DIR, &reg, &bit);
-	ret = regmap_update_bits(pc->reg_gpio, reg, BIT(bit), 0);
-	if (ret)
-		return ret;
+	/* TEST_N pin direction needs to be set using a Secure Monitor call */
+	if (bank->smc) {
+		u32 smc_ret = 0;
+		ret = meson_sm_call(reg, &smc_ret, bit, 0, 0, 0, 0);
+		if (ret)
+			return ret;
+	} else {
+		ret = regmap_update_bits(pc->reg_gpio, reg, BIT(bit), 0);
+		if (ret)
+			return ret;
+	}
 
 	meson_calc_reg_and_bit(bank, gpio, REG_OUT, &reg, &bit);
 	return regmap_update_bits(pc->reg_gpio, reg, BIT(bit),
diff --git a/drivers/pinctrl/meson/pinctrl-meson.h b/drivers/pinctrl/meson/pinctrl-meson.h
index 12a39110..d32e9a9 100644
--- a/drivers/pinctrl/meson/pinctrl-meson.h
+++ b/drivers/pinctrl/meson/pinctrl-meson.h
@@ -92,6 +92,7 @@  struct meson_bank {
 	const char *name;
 	unsigned int first;
 	unsigned int last;
+	bool smc; /* Direction needs to use a Secure Monitor call */
 	int irq_first;
 	int irq_last;
 	struct meson_reg_desc regs[NUM_REG];
@@ -131,11 +132,12 @@  struct meson_pinctrl {
 		.num_groups = ARRAY_SIZE(fn ## _groups),		\
 	}
 
-#define BANK(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib)	\
+#define __BANK(n, f, l, sm, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
 	{								\
 		.name		= n,					\
 		.first		= f,					\
 		.last		= l,					\
+		.smc		= sm,					\
 		.irq_first	= fi,					\
 		.irq_last	= li,					\
 		.regs = {						\
@@ -147,6 +149,12 @@  struct meson_pinctrl {
 		},							\
 	 }
 
+#define BANK(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
+	__BANK(n, f, l, false, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib)
+
+#define BANK_SMC(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
+	__BANK(n, f, l, true, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib)
+
 #define MESON_PIN(x) PINCTRL_PIN(x, #x)
 
 /* Common pmx functions */