Linux-Aspeed Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: dts: Aspeed: Witherspoon: Update BMC partitioning
From: Eddie James @ 2019-03-27 15:10 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <CACPK8Xer53amWbQ-6dvEaXfHu=grk3ZWsH9NKCa_Xi_JKUnCMg@mail.gmail.com>


On 3/27/19 1:20 AM, Joel Stanley wrote:
> On Tue, 12 Mar 2019 at 16:50, Adriana Kobylak <anoo@linux.ibm.com> wrote:
>> From: "Edward A. James" <eajames@us.ibm.com>
>>
>> Add simplified partitions for BMC and alternate flash. Include these by
>> default in Witherspoon.
>>
>> Signed-off-by: Edward A. James <eajames@us.ibm.com>
>> Signed-off-by: Joel Stanley <joel@jms.id.au>
>> ---
>>   .../boot/dts/aspeed-bmc-alt-opp-flash-layout-ubi.dtsi  | 18 ++++++++++++++++++
>>   arch/arm/boot/dts/aspeed-bmc-opp-flash-layout-ubi.dtsi | 18 ++++++++++++++++++
>>   arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts       |  3 ++-
>>   3 files changed, 38 insertions(+), 1 deletion(-)
>>   create mode 100644 arch/arm/boot/dts/aspeed-bmc-alt-opp-flash-layout-ubi.dtsi
>>   create mode 100644 arch/arm/boot/dts/aspeed-bmc-opp-flash-layout-ubi.dtsi
>>
>> diff --git a/arch/arm/boot/dts/aspeed-bmc-alt-opp-flash-layout-ubi.dtsi b/arch/arm/boot/dts/aspeed-bmc-alt-opp-flash-layout-ubi.dtsi
>> new file mode 100644
>> index 0000000..9277599
>> --- /dev/null
>> +++ b/arch/arm/boot/dts/aspeed-bmc-alt-opp-flash-layout-ubi.dtsi
> As there are no other machines that use this layout, I think you
> should have the layout in the dts file.

I think the idea was we might have more machines that use this layout in 
the future...

>
>> @@ -0,0 +1,18 @@
>> +               label = "alt-bmc";
>> +               partitions {
>> +                               #address-cells = < 1 >;
>> +                               #size-cells = < 1 >;
>> +                               compatible = "fixed-partitions";
>> +                               u-boot at 0 {
>> +                                       reg = < 0 0x60000 >;
>> +                                       label = "alt-u-boot";
>> +                               };
>> +                               u-boot-env at 60000 {
>> +                                       reg = < 0x60000 0x20000 >;
>> +                                       label = "alt-u-boot-env";
>> +                               };
>> +                               obmc-ubi at 80000 {
>> +                                       reg = < 0x80000 0x1F80000 >;
>> +                                       label = "alt-obmc-ubi";
>> +                               };
>> +               };
>> diff --git a/arch/arm/boot/dts/aspeed-bmc-opp-flash-layout-ubi.dtsi b/arch/arm/boot/dts/aspeed-bmc-opp-flash-layout-ubi.dtsi
>> new file mode 100644
>> index 0000000..0059ad1
>> --- /dev/null
>> +++ b/arch/arm/boot/dts/aspeed-bmc-opp-flash-layout-ubi.dtsi
>> @@ -0,0 +1,18 @@
>> +               label = "bmc";
>> +               partitions {
>> +                               #address-cells = < 1 >;
>> +                               #size-cells = < 1 >;
>> +                               compatible = "fixed-partitions";
>> +                               u-boot at 0 {
>> +                                       reg = < 0 0x60000 >;
>> +                                       label = "u-boot";
>> +                               };
>> +                               u-boot-env at 60000 {
>> +                                       reg = < 0x60000 0x20000 >;
>> +                                       label = "u-boot-env";
>> +                               };
>> +                               obmc-ubi at 80000 {
>> +                                       reg = < 0x80000 0x1F80000 >;
>> +                                       label = "obmc-ubi";
>> +                               };
>> +               };
>> diff --git a/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts b/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
>> index c51e3e8..058b9b7 100644
>> --- a/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
>> +++ b/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
>> @@ -191,7 +191,7 @@
>>                  label = "bmc";
>>                  m25p,fast-read;
>>                  spi-max-frequency = <50000000>;
>> -#include "openbmc-flash-layout.dtsi"
>> +#include "aspeed-bmc-opp-flash-layout-ubi.dtsi"
>>          };
>>
>>          flash at 1 {
>> @@ -199,6 +199,7 @@
>>                  label = "alt";
>>                  m25p,fast-read;
>>                  spi-max-frequency = <50000000>;
>> +#include "aspeed-bmc-alt-opp-flash-layout-ubi.dtsi"
>>          };
>>   };
>>
>> --
>> 1.8.3.1
>>


^ permalink raw reply

* [PATCH v3 2/2] rtc: Add ASPEED RTC driver
From: Alexandre Belloni @ 2019-03-27 10:37 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <20190327010215.10231-3-joel@jms.id.au>

On 27/03/2019 11:32:15+1030, Joel Stanley wrote:
> Read and writes the time to the non-battery backed RTC in the ASPEED BMC
> system on chip families.
> 
> Signed-off-by: Joel Stanley <joel@jms.id.au>
> ---
> v3:
>  - Use %ptR
>  - Remove spinlock, as callback happen under the rtc_device.ops_lock
> v2: Address review from Alexandre
>  - Use devm_rtc_allocate_device
>  - Fill in range_min
>  - Direcly fill in tm struct
>  - Return EINVAL when RTC is not enabled
> 
> v1: https://lore.kernel.org/linux-arm-kernel/20181003133155.27494-2-joel at jms.id.au/
> 
> Update kconfig text
> 
> Signed-off-by: Joel Stanley <joel@jms.id.au>
> ---
>  drivers/rtc/Kconfig      |  11 ++++
>  drivers/rtc/Makefile     |   1 +
>  drivers/rtc/rtc-aspeed.c | 138 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 150 insertions(+)
>  create mode 100644 drivers/rtc/rtc-aspeed.c
> 
Applied, thanks.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply

* [PATCH v3 1/2] dt-bindings: rtc: Add on-chip ASPEED RTC documentation
From: Alexandre Belloni @ 2019-03-27 10:37 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <20190327010215.10231-2-joel@jms.id.au>

On 27/03/2019 11:32:14+1030, Joel Stanley wrote:
> Describe the RTC as used in the ASPEED BMC SoCs.
> 
> Signed-off-by: Joel Stanley <joel@jms.id.au>
> ---
> v3: Add interrupts property
> ---
>  .../devicetree/bindings/rtc/rtc-aspeed.txt    | 22 +++++++++++++++++++
>  1 file changed, 22 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/rtc/rtc-aspeed.txt
> 
Applied, thanks.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply

* Re: [PATCH] Revert "gpio: use new gpio_set_config() helper in more places"
From: Andrew Jeffery @ 2019-03-27  8:48 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <CAMRc=Mep9GNhOsO8jyxS4vHuPi3jgRbg_88Zqi1vRnw5hEXUCQ@mail.gmail.com>



On Wed, 27 Mar 2019, at 19:11, Bartosz Golaszewski wrote:
> wt., 26 mar 2019 o 19:06 Bartosz Golaszewski
> <bgolaszewski@baylibre.com> napisa?(a):
> >
> > wt., 26 mar 2019 o 05:50 Andrew Jeffery <andrew@aj.id.au> napisa?(a):
> > >
> > > gpio-aspeed implements support for PIN_CONFIG_INPUT_DEBOUNCE. As of
> > > v5.1-rc1 we're seeing the following when booting a Romulus BMC kernel:
> > >
> > > > [   21.373137] ------------[ cut here ]------------
> > > > [   21.374545] WARNING: CPU: 0 PID: 1 at drivers/gpio/gpio-aspeed.c:834 unregister_allocated_timer+0x38/0x94
> > > > [   21.376181] No timer allocated to offset 74
> > > > [   21.377672] CPU: 0 PID: 1 Comm: swapper Not tainted 5.1.0-rc1-dirty #6
> > > > [   21.378800] Hardware name: Generic DT based system
> > > > [   21.379965] Backtrace:
> > > > [   21.381024] [<80107d44>] (dump_backtrace) from [<80107f78>] (show_stack+0x20/0x24)
> > > > [   21.382713]  r7:8038b720 r6:00000009 r5:00000000 r4:87897c64
> > > > [   21.383815] [<80107f58>] (show_stack) from [<80656398>] (dump_stack+0x20/0x28)
> > > > [   21.385042] [<80656378>] (dump_stack) from [<80115f1c>] (__warn.part.3+0xb4/0xdc)
> > > > [   21.386253] [<80115e68>] (__warn.part.3) from [<80115fb0>] (warn_slowpath_fmt+0x6c/0x90)
> > > > [   21.387471]  r6:00000342 r5:807f8758 r4:80a07008
> > > > [   21.388278] [<80115f48>] (warn_slowpath_fmt) from [<8038b720>] (unregister_allocated_timer+0x38/0x94)
> > > > [   21.389809]  r3:0000004a r2:807f8774
> > > > [   21.390526]  r7:00000000 r6:0000000a r5:60000153 r4:0000004a
> > > > [   21.391601] [<8038b6e8>] (unregister_allocated_timer) from [<8038baac>] (aspeed_gpio_set_config+0x330/0x48c)
> > > > [   21.393248] [<8038b77c>] (aspeed_gpio_set_config) from [<803840b0>] (gpiod_set_debounce+0xe8/0x114)
> > > > [   21.394745]  r10:82ee2248 r9:00000000 r8:87b63a00 r7:00001388 r6:87947320 r5:80729310
> > > > [   21.396030]  r4:879f64a0
> > > > [   21.396499] [<80383fc8>] (gpiod_set_debounce) from [<804b4350>] (gpio_keys_probe+0x69c/0x8e0)
> > > > [   21.397715]  r7:845d94b8 r6:00000001 r5:00000000 r4:87b63a1c
> > > > [   21.398618] [<804b3cb4>] (gpio_keys_probe) from [<8040eeec>] (platform_dev_probe+0x44/0x80)
> > > > [   21.399834]  r10:00000003 r9:80a3a8b0 r8:00000000 r7:00000000 r6:80a7f9dc r5:80a3a8b0
> > > > [   21.401163]  r4:8796bc10
> > > > [   21.401634] [<8040eea8>] (platform_drv_probe) from [<8040d0d4>] (really_probe+0x208/0x3dc)
> > > > [   21.402786]  r5:80a7f8d0 r4:8796bc10
> > > > [   21.403547] [<8040cecc>] (really_probe) from [<8040d7a4>] (driver_probe_device+0x130/0x170)
> > > > [   21.404744]  r10:0000007b r9:8093683c r8:00000000 r7:80a07008 r6:80a3a8b0 r5:8796bc10
> > > > [   21.405854]  r4:80a3a8b0
> > > > [   21.406324] [<8040d674>] (driver_probe_device) from [<8040da8c>] (device_driver_attach+0x68/0x70)
> > > > [   21.407568]  r9:8093683c r8:00000000 r7:80a07008 r6:80a3a8b0 r5:00000000 r4:8796bc10
> > > > [   21.408877] [<8040da24>] (device_driver_attach) from [<8040db14>] (__driver_attach+0x80/0x150)
> > > > [   21.410327]  r7:80a07008 r6:8796bc10 r5:00000001 r4:80a3a8b0
> > > > [   21.411294] [<8040da94>] (__driver_attach) from [<8040b20c>] (bus_for_each_dev+0x80/0xc4)
> > > > [   21.412641]  r7:80a07008 r6:8040da94 r5:80a3a8b0 r4:87966f30
> > > > [   21.413580] [<8040b18c>] (bus_for_each_dev) from [<8040dc0c>] (driver_attach+0x28/0x30)
> > > > [   21.414943]  r7:00000000 r6:87b411e0 r5:80a33fc8 r4:80a3a8b0
> > > > [   21.415927] [<8040dbe4>] (driver_attach) from [<8040bbf0>] (bus_add_driver+0x14c/0x200)
> > > > [   21.417289] [<8040baa4>] (bus_add_driver) from [<8040e2b4>] (driver_register+0x84/0x118)
> > > > [   21.418652]  r7:80a60ae0 r6:809226b8 r5:80a07008 r4:80a3a8b0
> > > > [   21.419652] [<8040e230>] (driver_register) from [<8040fc28>] (__platform_driver_register+0x3c/0x50)
> > > > [   21.421193]  r5:80a07008 r4:809525f8
> > > > [   21.421990] [<8040fbec>] (__platform_driver_register) from [<809226d8>] (gpio_keys_init+0x20/0x28)
> > > > [   21.423447] [<809226b8>] (gpio_keys_init) from [<8090128c>] (do_one_initcall+0x80/0x180)
> > > > [   21.424886] [<8090120c>] (do_one_initcall) from [<80901538>] (kernel_init_freeable+0x1ac/0x26c)
> > > > [   21.426354]  r8:80a60ae0 r7:80a60ae0 r6:8093685c r5:00000008 r4:809525f8
> > > > [   21.427579] [<8090138c>] (kernel_init_freeable) from [<8066d9a0>] (kernel_init+0x18/0x11c)
> > > > [   21.428819]  r10:00000000 r9:00000000 r8:00000000 r7:00000000 r6:00000000 r5:8066d988
> > > > [   21.429947]  r4:00000000
> > > > [   21.430415] [<8066d988>] (kernel_init) from [<801010e8>] (ret_from_fork+0x14/0x2c)
> > > > [   21.431666] Exception stack(0x87897fb0 to 0x87897ff8)
> > > > [   21.432877] 7fa0:                                     00000000 00000000 00000000 00000000
> > > > [   21.434446] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> > > > [   21.436052] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000
> > > > [   21.437308]  r5:8066d988 r4:00000000
> > > > [   21.438102] ---[ end trace d7d7ac3a80567d0e ]---
> > >
> > > We only hit unregister_allocated_timer() if the argument to
> > > aspeed_gpio_set_config() is 0, but we can't be calling through
> > > gpiod_set_debounce() from gpio_keys_probe() unless the gpio-keys button has a
> > > non-zero debounce interval.
> > >
> > > Commit 6581eaf0e890 ("gpio: use new gpio_set_config() helper in more places")
> > > spreads the use of gpio_set_config() to the debounce and transitory
> > > state configuration paths. The implementation of gpio_set_config() is:
> > >
> > > > static int gpio_set_config(struct gpio_chip *gc, unsigned offset,
> > > >                          enum pin_config_param mode)
> > > > {
> > > >       unsigned long config = { PIN_CONF_PACKED(mode, 0) };
> > > >
> > > >       return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP;
> > > > }
> > >
> > > Here it packs its own config value with a fixed argument of 0; this is
> > > incorrect behaviour for implementing the debounce and transitory functions, and
> > > the debounce and transitory gpio_set_config() call-sites now have an undetected
> > > type mismatch as they both already pack their own config parameter (i.e. what
> > > gets passed is not an `enum pin_config_param`). Indeed this can be seen in the
> > > small diff for 6581eaf0e890:
> > >
> > > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > > > index de595fa31a1a..1f239aac43df 100644
> > > > --- a/drivers/gpio/gpiolib.c
> > > > +++ b/drivers/gpio/gpiolib.c
> > > > @@ -2725,7 +2725,7 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
> > > >         }
> > > >
> > > >         config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
> > > > -       return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
> > > > +       return gpio_set_config(chip, gpio_chip_hwgpio(desc), config);
> > > >  }
> > > >  EXPORT_SYMBOL_GPL(gpiod_set_debounce);
> > > >
> > > > @@ -2762,7 +2762,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
> > > >         packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,
> > > >                                           !transitory);
> > > >         gpio = gpio_chip_hwgpio(desc);
> > > > -       rc = chip->set_config(chip, gpio, packed);
> > > > +       rc = gpio_set_config(chip, gpio, packed);
> > > >         if (rc == -ENOTSUPP) {
> > > >                 dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",
> > > >                                 gpio);
> > >
> > > Revert commit 6581eaf0e890 ("gpio: use new gpio_set_config() helper in
> > > more places") to restore correct behaviour for gpiod_set_debounce() and
> > > gpiod_set_transitory().
> > >
> > > Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> > > Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
> > > ---
> > >  drivers/gpio/gpiolib.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > > index 144af0733581..0495bf1d480a 100644
> > > --- a/drivers/gpio/gpiolib.c
> > > +++ b/drivers/gpio/gpiolib.c
> > > @@ -2776,7 +2776,7 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
> > >         }
> > >
> > >         config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
> > > -       return gpio_set_config(chip, gpio_chip_hwgpio(desc), config);
> > > +       return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
> > >  }
> > >  EXPORT_SYMBOL_GPL(gpiod_set_debounce);
> > >
> > > @@ -2813,7 +2813,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
> > >         packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,
> > >                                           !transitory);
> > >         gpio = gpio_chip_hwgpio(desc);
> > > -       rc = gpio_set_config(chip, gpio, packed);
> > > +       rc = chip->set_config(chip, gpio, packed);
> > >         if (rc == -ENOTSUPP) {
> > >                 dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",
> > >                                 gpio);
> > > --
> > > 2.19.1
> > >
> >
> > Thanks for the detailed explanation of the problem. Can we check for
> > special cases in gpiod_set_config() and possibly pass the config
> > unchanged to the underlying driver in case of debounce and transitory
> > options?
> >
> > Bart
> 
> After giving it a second thought and seeing that Thomas is ok with
> reverting it, I applied the patch for fixes.

Ok, thanks. Didn't get around to addressing your reply today, so that's one less thing on the todo list :)

Andrew

> 
> Bart
>

^ permalink raw reply

* [PATCH] Revert "gpio: use new gpio_set_config() helper in more places"
From: Bartosz Golaszewski @ 2019-03-27  8:40 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <CAMpxmJWvL2q9+yExAwv7jZ+g9psv5-_p8B89gk_pzvHbHMdO+w@mail.gmail.com>

wt., 26 mar 2019 o 19:06 Bartosz Golaszewski
<bgolaszewski@baylibre.com> napisa?(a):
>
> wt., 26 mar 2019 o 05:50 Andrew Jeffery <andrew@aj.id.au> napisa?(a):
> >
> > gpio-aspeed implements support for PIN_CONFIG_INPUT_DEBOUNCE. As of
> > v5.1-rc1 we're seeing the following when booting a Romulus BMC kernel:
> >
> > > [   21.373137] ------------[ cut here ]------------
> > > [   21.374545] WARNING: CPU: 0 PID: 1 at drivers/gpio/gpio-aspeed.c:834 unregister_allocated_timer+0x38/0x94
> > > [   21.376181] No timer allocated to offset 74
> > > [   21.377672] CPU: 0 PID: 1 Comm: swapper Not tainted 5.1.0-rc1-dirty #6
> > > [   21.378800] Hardware name: Generic DT based system
> > > [   21.379965] Backtrace:
> > > [   21.381024] [<80107d44>] (dump_backtrace) from [<80107f78>] (show_stack+0x20/0x24)
> > > [   21.382713]  r7:8038b720 r6:00000009 r5:00000000 r4:87897c64
> > > [   21.383815] [<80107f58>] (show_stack) from [<80656398>] (dump_stack+0x20/0x28)
> > > [   21.385042] [<80656378>] (dump_stack) from [<80115f1c>] (__warn.part.3+0xb4/0xdc)
> > > [   21.386253] [<80115e68>] (__warn.part.3) from [<80115fb0>] (warn_slowpath_fmt+0x6c/0x90)
> > > [   21.387471]  r6:00000342 r5:807f8758 r4:80a07008
> > > [   21.388278] [<80115f48>] (warn_slowpath_fmt) from [<8038b720>] (unregister_allocated_timer+0x38/0x94)
> > > [   21.389809]  r3:0000004a r2:807f8774
> > > [   21.390526]  r7:00000000 r6:0000000a r5:60000153 r4:0000004a
> > > [   21.391601] [<8038b6e8>] (unregister_allocated_timer) from [<8038baac>] (aspeed_gpio_set_config+0x330/0x48c)
> > > [   21.393248] [<8038b77c>] (aspeed_gpio_set_config) from [<803840b0>] (gpiod_set_debounce+0xe8/0x114)
> > > [   21.394745]  r10:82ee2248 r9:00000000 r8:87b63a00 r7:00001388 r6:87947320 r5:80729310
> > > [   21.396030]  r4:879f64a0
> > > [   21.396499] [<80383fc8>] (gpiod_set_debounce) from [<804b4350>] (gpio_keys_probe+0x69c/0x8e0)
> > > [   21.397715]  r7:845d94b8 r6:00000001 r5:00000000 r4:87b63a1c
> > > [   21.398618] [<804b3cb4>] (gpio_keys_probe) from [<8040eeec>] (platform_dev_probe+0x44/0x80)
> > > [   21.399834]  r10:00000003 r9:80a3a8b0 r8:00000000 r7:00000000 r6:80a7f9dc r5:80a3a8b0
> > > [   21.401163]  r4:8796bc10
> > > [   21.401634] [<8040eea8>] (platform_drv_probe) from [<8040d0d4>] (really_probe+0x208/0x3dc)
> > > [   21.402786]  r5:80a7f8d0 r4:8796bc10
> > > [   21.403547] [<8040cecc>] (really_probe) from [<8040d7a4>] (driver_probe_device+0x130/0x170)
> > > [   21.404744]  r10:0000007b r9:8093683c r8:00000000 r7:80a07008 r6:80a3a8b0 r5:8796bc10
> > > [   21.405854]  r4:80a3a8b0
> > > [   21.406324] [<8040d674>] (driver_probe_device) from [<8040da8c>] (device_driver_attach+0x68/0x70)
> > > [   21.407568]  r9:8093683c r8:00000000 r7:80a07008 r6:80a3a8b0 r5:00000000 r4:8796bc10
> > > [   21.408877] [<8040da24>] (device_driver_attach) from [<8040db14>] (__driver_attach+0x80/0x150)
> > > [   21.410327]  r7:80a07008 r6:8796bc10 r5:00000001 r4:80a3a8b0
> > > [   21.411294] [<8040da94>] (__driver_attach) from [<8040b20c>] (bus_for_each_dev+0x80/0xc4)
> > > [   21.412641]  r7:80a07008 r6:8040da94 r5:80a3a8b0 r4:87966f30
> > > [   21.413580] [<8040b18c>] (bus_for_each_dev) from [<8040dc0c>] (driver_attach+0x28/0x30)
> > > [   21.414943]  r7:00000000 r6:87b411e0 r5:80a33fc8 r4:80a3a8b0
> > > [   21.415927] [<8040dbe4>] (driver_attach) from [<8040bbf0>] (bus_add_driver+0x14c/0x200)
> > > [   21.417289] [<8040baa4>] (bus_add_driver) from [<8040e2b4>] (driver_register+0x84/0x118)
> > > [   21.418652]  r7:80a60ae0 r6:809226b8 r5:80a07008 r4:80a3a8b0
> > > [   21.419652] [<8040e230>] (driver_register) from [<8040fc28>] (__platform_driver_register+0x3c/0x50)
> > > [   21.421193]  r5:80a07008 r4:809525f8
> > > [   21.421990] [<8040fbec>] (__platform_driver_register) from [<809226d8>] (gpio_keys_init+0x20/0x28)
> > > [   21.423447] [<809226b8>] (gpio_keys_init) from [<8090128c>] (do_one_initcall+0x80/0x180)
> > > [   21.424886] [<8090120c>] (do_one_initcall) from [<80901538>] (kernel_init_freeable+0x1ac/0x26c)
> > > [   21.426354]  r8:80a60ae0 r7:80a60ae0 r6:8093685c r5:00000008 r4:809525f8
> > > [   21.427579] [<8090138c>] (kernel_init_freeable) from [<8066d9a0>] (kernel_init+0x18/0x11c)
> > > [   21.428819]  r10:00000000 r9:00000000 r8:00000000 r7:00000000 r6:00000000 r5:8066d988
> > > [   21.429947]  r4:00000000
> > > [   21.430415] [<8066d988>] (kernel_init) from [<801010e8>] (ret_from_fork+0x14/0x2c)
> > > [   21.431666] Exception stack(0x87897fb0 to 0x87897ff8)
> > > [   21.432877] 7fa0:                                     00000000 00000000 00000000 00000000
> > > [   21.434446] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> > > [   21.436052] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000
> > > [   21.437308]  r5:8066d988 r4:00000000
> > > [   21.438102] ---[ end trace d7d7ac3a80567d0e ]---
> >
> > We only hit unregister_allocated_timer() if the argument to
> > aspeed_gpio_set_config() is 0, but we can't be calling through
> > gpiod_set_debounce() from gpio_keys_probe() unless the gpio-keys button has a
> > non-zero debounce interval.
> >
> > Commit 6581eaf0e890 ("gpio: use new gpio_set_config() helper in more places")
> > spreads the use of gpio_set_config() to the debounce and transitory
> > state configuration paths. The implementation of gpio_set_config() is:
> >
> > > static int gpio_set_config(struct gpio_chip *gc, unsigned offset,
> > >                          enum pin_config_param mode)
> > > {
> > >       unsigned long config = { PIN_CONF_PACKED(mode, 0) };
> > >
> > >       return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP;
> > > }
> >
> > Here it packs its own config value with a fixed argument of 0; this is
> > incorrect behaviour for implementing the debounce and transitory functions, and
> > the debounce and transitory gpio_set_config() call-sites now have an undetected
> > type mismatch as they both already pack their own config parameter (i.e. what
> > gets passed is not an `enum pin_config_param`). Indeed this can be seen in the
> > small diff for 6581eaf0e890:
> >
> > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > > index de595fa31a1a..1f239aac43df 100644
> > > --- a/drivers/gpio/gpiolib.c
> > > +++ b/drivers/gpio/gpiolib.c
> > > @@ -2725,7 +2725,7 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
> > >         }
> > >
> > >         config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
> > > -       return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
> > > +       return gpio_set_config(chip, gpio_chip_hwgpio(desc), config);
> > >  }
> > >  EXPORT_SYMBOL_GPL(gpiod_set_debounce);
> > >
> > > @@ -2762,7 +2762,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
> > >         packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,
> > >                                           !transitory);
> > >         gpio = gpio_chip_hwgpio(desc);
> > > -       rc = chip->set_config(chip, gpio, packed);
> > > +       rc = gpio_set_config(chip, gpio, packed);
> > >         if (rc == -ENOTSUPP) {
> > >                 dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",
> > >                                 gpio);
> >
> > Revert commit 6581eaf0e890 ("gpio: use new gpio_set_config() helper in
> > more places") to restore correct behaviour for gpiod_set_debounce() and
> > gpiod_set_transitory().
> >
> > Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> > Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
> > ---
> >  drivers/gpio/gpiolib.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > index 144af0733581..0495bf1d480a 100644
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -2776,7 +2776,7 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
> >         }
> >
> >         config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
> > -       return gpio_set_config(chip, gpio_chip_hwgpio(desc), config);
> > +       return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
> >  }
> >  EXPORT_SYMBOL_GPL(gpiod_set_debounce);
> >
> > @@ -2813,7 +2813,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
> >         packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,
> >                                           !transitory);
> >         gpio = gpio_chip_hwgpio(desc);
> > -       rc = gpio_set_config(chip, gpio, packed);
> > +       rc = chip->set_config(chip, gpio, packed);
> >         if (rc == -ENOTSUPP) {
> >                 dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",
> >                                 gpio);
> > --
> > 2.19.1
> >
>
> Thanks for the detailed explanation of the problem. Can we check for
> special cases in gpiod_set_config() and possibly pass the config
> unchanged to the underlying driver in case of debounce and transitory
> options?
>
> Bart

After giving it a second thought and seeing that Thomas is ok with
reverting it, I applied the patch for fixes.

Bart

^ permalink raw reply

* [PATCH] ARM: dts: Aspeed: Witherspoon: Update BMC partitioning
From: Joel Stanley @ 2019-03-27  6:20 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <1552409402-15881-1-git-send-email-anoo@linux.ibm.com>

On Tue, 12 Mar 2019 at 16:50, Adriana Kobylak <anoo@linux.ibm.com> wrote:
>
> From: "Edward A. James" <eajames@us.ibm.com>
>
> Add simplified partitions for BMC and alternate flash. Include these by
> default in Witherspoon.
>
> Signed-off-by: Edward A. James <eajames@us.ibm.com>
> Signed-off-by: Joel Stanley <joel@jms.id.au>
> ---
>  .../boot/dts/aspeed-bmc-alt-opp-flash-layout-ubi.dtsi  | 18 ++++++++++++++++++
>  arch/arm/boot/dts/aspeed-bmc-opp-flash-layout-ubi.dtsi | 18 ++++++++++++++++++
>  arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts       |  3 ++-
>  3 files changed, 38 insertions(+), 1 deletion(-)
>  create mode 100644 arch/arm/boot/dts/aspeed-bmc-alt-opp-flash-layout-ubi.dtsi
>  create mode 100644 arch/arm/boot/dts/aspeed-bmc-opp-flash-layout-ubi.dtsi
>
> diff --git a/arch/arm/boot/dts/aspeed-bmc-alt-opp-flash-layout-ubi.dtsi b/arch/arm/boot/dts/aspeed-bmc-alt-opp-flash-layout-ubi.dtsi
> new file mode 100644
> index 0000000..9277599
> --- /dev/null
> +++ b/arch/arm/boot/dts/aspeed-bmc-alt-opp-flash-layout-ubi.dtsi

As there are no other machines that use this layout, I think you
should have the layout in the dts file.

> @@ -0,0 +1,18 @@
> +               label = "alt-bmc";
> +               partitions {
> +                               #address-cells = < 1 >;
> +                               #size-cells = < 1 >;
> +                               compatible = "fixed-partitions";
> +                               u-boot at 0 {
> +                                       reg = < 0 0x60000 >;
> +                                       label = "alt-u-boot";
> +                               };
> +                               u-boot-env at 60000 {
> +                                       reg = < 0x60000 0x20000 >;
> +                                       label = "alt-u-boot-env";
> +                               };
> +                               obmc-ubi at 80000 {
> +                                       reg = < 0x80000 0x1F80000 >;
> +                                       label = "alt-obmc-ubi";
> +                               };
> +               };
> diff --git a/arch/arm/boot/dts/aspeed-bmc-opp-flash-layout-ubi.dtsi b/arch/arm/boot/dts/aspeed-bmc-opp-flash-layout-ubi.dtsi
> new file mode 100644
> index 0000000..0059ad1
> --- /dev/null
> +++ b/arch/arm/boot/dts/aspeed-bmc-opp-flash-layout-ubi.dtsi
> @@ -0,0 +1,18 @@
> +               label = "bmc";
> +               partitions {
> +                               #address-cells = < 1 >;
> +                               #size-cells = < 1 >;
> +                               compatible = "fixed-partitions";
> +                               u-boot at 0 {
> +                                       reg = < 0 0x60000 >;
> +                                       label = "u-boot";
> +                               };
> +                               u-boot-env at 60000 {
> +                                       reg = < 0x60000 0x20000 >;
> +                                       label = "u-boot-env";
> +                               };
> +                               obmc-ubi at 80000 {
> +                                       reg = < 0x80000 0x1F80000 >;
> +                                       label = "obmc-ubi";
> +                               };
> +               };
> diff --git a/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts b/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
> index c51e3e8..058b9b7 100644
> --- a/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
> +++ b/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
> @@ -191,7 +191,7 @@
>                 label = "bmc";
>                 m25p,fast-read;
>                 spi-max-frequency = <50000000>;
> -#include "openbmc-flash-layout.dtsi"
> +#include "aspeed-bmc-opp-flash-layout-ubi.dtsi"
>         };
>
>         flash at 1 {
> @@ -199,6 +199,7 @@
>                 label = "alt";
>                 m25p,fast-read;
>                 spi-max-frequency = <50000000>;
> +#include "aspeed-bmc-alt-opp-flash-layout-ubi.dtsi"
>         };
>  };
>
> --
> 1.8.3.1
>

^ permalink raw reply

* [PATCH] witherspoon.dts: Enable the USB vhub (device)
From: Joel Stanley @ 2019-03-27  6:16 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <1553610803-65797-1-git-send-email-anoo@linux.ibm.com>

Hi Adriana,

On Tue, 26 Mar 2019 at 14:34, Adriana Kobylak <anoo@linux.ibm.com> wrote:
>
> The Aspeed vhub device driver is already enabled in
> the defconfig, make use of it in the witherspoon platform.
>
> Signed-off-by: Adriana Kobylak <anoo@linux.ibm.com>

The patch looks good. However it would be good if the commit message
would follow the style used by other patches. Next time, do a git log
of the file and see how others format their messages.'

$ git log --oneline arch/arm/boot/dts/aspeed-*
2b66ba56dca9 ARM: dts: aspeed: Add Power9 and Power9 CFAM description
82545da4069b ARM: dts: aspeed: Rename flash-controller nodes
58e953107de1 ARM: dts: palmetto: Fix flash_memory region
3b1433fac7ec ARM: dts: aspeed: tiogapass: Add sensors
36b64bb6dfa2 ARM: dts: aspeed: tiogapass: Enable KCS
7dd7e19bed04 ARM: dts: aspeed: Add KCS support for LPC BMC

I've applied the version of this patch that Eddie sent, so it should
be all good.

Cheers,

Joel

^ permalink raw reply

* [PATCH v3 2/2] rtc: Add ASPEED RTC driver
From: Joel Stanley @ 2019-03-27  1:02 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <20190327010215.10231-1-joel@jms.id.au>

Read and writes the time to the non-battery backed RTC in the ASPEED BMC
system on chip families.

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
v3:
 - Use %ptR
 - Remove spinlock, as callback happen under the rtc_device.ops_lock
v2: Address review from Alexandre
 - Use devm_rtc_allocate_device
 - Fill in range_min
 - Direcly fill in tm struct
 - Return EINVAL when RTC is not enabled

v1: https://lore.kernel.org/linux-arm-kernel/20181003133155.27494-2-joel at jms.id.au/

Update kconfig text

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 drivers/rtc/Kconfig      |  11 ++++
 drivers/rtc/Makefile     |   1 +
 drivers/rtc/rtc-aspeed.c | 138 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 drivers/rtc/rtc-aspeed.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index dc0d66e80038..fd1321875cb1 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1841,6 +1841,17 @@ config RTC_DRV_RTD119X
 	  If you say yes here, you get support for the RTD1295 SoC
 	  Real Time Clock.
 
+config RTC_DRV_ASPEED
+	tristate "ASPEED RTC"
+	depends on OF
+	depends on ARCH_ASPEED || COMPILE_TEST
+	help
+	  If you say yes here you get support for the ASPEED BMC SoC real time
+	  clocks.
+
+	  This driver can also be built as a module, if so, the module
+	  will be called "rtc-aspeed".
+
 comment "HID Sensor RTC drivers"
 
 config RTC_DRV_HID_SENSOR_TIME
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index fe3962496685..9d997faa2c26 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_RTC_DRV_AC100)	+= rtc-ac100.o
 obj-$(CONFIG_RTC_DRV_ARMADA38X)	+= rtc-armada38x.o
 obj-$(CONFIG_RTC_DRV_AS3722)	+= rtc-as3722.o
 obj-$(CONFIG_RTC_DRV_ASM9260)	+= rtc-asm9260.o
+obj-$(CONFIG_RTC_DRV_ASPEED)	+= rtc-aspeed.o
 obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
 obj-$(CONFIG_RTC_DRV_AT91SAM9)	+= rtc-at91sam9.o
 obj-$(CONFIG_RTC_DRV_AU1XXX)	+= rtc-au1xxx.o
diff --git a/drivers/rtc/rtc-aspeed.c b/drivers/rtc/rtc-aspeed.c
new file mode 100644
index 000000000000..bd709feea695
--- /dev/null
+++ b/drivers/rtc/rtc-aspeed.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0+
+// Copyright 2015 IBM Corp.
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+#include <linux/io.h>
+
+struct aspeed_rtc {
+	struct rtc_device *rtc_dev;
+	void __iomem *base;
+};
+
+#define RTC_TIME	0x00
+#define RTC_YEAR	0x04
+#define RTC_CTRL	0x10
+
+#define RTC_UNLOCK	BIT(1)
+#define RTC_ENABLE	BIT(0)
+
+static int aspeed_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct aspeed_rtc *rtc = dev_get_drvdata(dev);
+	unsigned int cent, year;
+	unsigned long flags;
+	u32 reg1, reg2;
+
+	if (!(readl(rtc->base + RTC_CTRL) & RTC_ENABLE)) {
+		dev_dbg(dev, "%s failing as rtc disabled\n", __func__);
+		return -EINVAL;
+	}
+
+	do {
+		reg2 = readl(rtc->base + RTC_YEAR);
+		reg1 = readl(rtc->base + RTC_TIME);
+	} while (reg2 != readl(rtc->base + RTC_YEAR));
+
+	tm->tm_mday = (reg1 >> 24) & 0x1f;
+	tm->tm_hour = (reg1 >> 16) & 0x1f;
+	tm->tm_min = (reg1 >> 8) & 0x3f;
+	tm->tm_sec = (reg1 >> 0) & 0x3f;
+
+	cent = (reg2 >> 16) & 0x1f;
+	year = (reg2 >> 8) & 0x7f;
+	tm->tm_mon = ((reg2 >>  0) & 0x0f) - 1;
+	tm->tm_year = year + (cent * 100) - 1900;
+
+	dev_dbg(dev, "%s %ptR", __func__, tm);
+
+	return 0;
+}
+
+static int aspeed_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct aspeed_rtc *rtc = dev_get_drvdata(dev);
+	unsigned long flags;
+	u32 reg1, reg2, ctrl;
+	int year, cent;
+
+	cent = (tm->tm_year + 1900) / 100;
+	year = tm->tm_year % 100;
+
+	reg1 = (tm->tm_mday << 24) | (tm->tm_hour << 16) | (tm->tm_min << 8) |
+		tm->tm_sec;
+
+	reg2 = ((cent & 0x1f) << 16) | ((year & 0x7f) << 8) |
+		((tm->tm_mon + 1) & 0xf);
+
+	ctrl = readl(rtc->base + RTC_CTRL);
+	writel(ctrl | RTC_UNLOCK, rtc->base + RTC_CTRL);
+
+	writel(reg1, rtc->base + RTC_TIME);
+	writel(reg2, rtc->base + RTC_YEAR);
+
+	/* Re-lock and ensure enable is set now that a time is programmed */
+	writel(ctrl | RTC_ENABLE, rtc->base + RTC_CTRL);
+
+	return 0;
+}
+
+static const struct rtc_class_ops aspeed_rtc_ops = {
+	.read_time = aspeed_rtc_read_time,
+	.set_time = aspeed_rtc_set_time,
+};
+
+static int aspeed_rtc_probe(struct platform_device *pdev)
+{
+	struct aspeed_rtc *rtc;
+	struct resource *res;
+	int ret;
+
+	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	rtc->base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(rtc->base))
+		return PTR_ERR(rtc->base);
+
+	rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
+	if (IS_ERR(rtc->rtc_dev))
+		return PTR_ERR(rtc->rtc_dev);
+
+	platform_set_drvdata(pdev, rtc);
+
+	rtc->rtc_dev->ops = &aspeed_rtc_ops;
+	rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
+	rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */
+
+	ret = rtc_register_device(rtc->rtc_dev);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static const struct of_device_id aspeed_rtc_match[] = {
+	{ .compatible = "aspeed,ast2400-rtc", },
+	{ .compatible = "aspeed,ast2500-rtc", },
+	{ .compatible = "aspeed,ast2600-rtc", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, aspeed_rtc_match);
+
+static struct platform_driver aspeed_rtc_driver = {
+	.driver = {
+		.name = "aspeed-rtc",
+		.of_match_table = of_match_ptr(aspeed_rtc_match),
+	},
+};
+
+module_platform_driver_probe(aspeed_rtc_driver, aspeed_rtc_probe);
+
+MODULE_DESCRIPTION("ASPEED RTC driver");
+MODULE_AUTHOR("Joel Stanley <joel@jms.id.au>");
+MODULE_LICENSE("GPL");
-- 
2.20.1


^ permalink raw reply related

* [PATCH v3 1/2] dt-bindings: rtc: Add on-chip ASPEED RTC documentation
From: Joel Stanley @ 2019-03-27  1:02 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <20190327010215.10231-1-joel@jms.id.au>

Describe the RTC as used in the ASPEED BMC SoCs.

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
v3: Add interrupts property
---
 .../devicetree/bindings/rtc/rtc-aspeed.txt    | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-aspeed.txt

diff --git a/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt b/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt
new file mode 100644
index 000000000000..2e956b3dc276
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt
@@ -0,0 +1,22 @@
+ASPEED BMC RTC
+==============
+
+Required properties:
+ - compatible: should be one of the following
+   * aspeed,ast2400-rtc for the ast2400
+   * aspeed,ast2500-rtc for the ast2500
+   * aspeed,ast2600-rtc for the ast2600
+
+ - reg: physical base address of the controller and length of memory mapped
+   region
+
+ - interrupts: The interrupt number
+
+Example:
+
+   rtc at 1e781000 {
+           compatible = "aspeed,ast2400-rtc";
+           reg = <0x1e781000 0x18>;
+           interrupts = <22>;
+           status = "disabled";
+   };
-- 
2.20.1


^ permalink raw reply related

* [PATCH v3 0/2] rtc: Add ASPEED RTC driver
From: Joel Stanley @ 2019-03-27  1:02 UTC (permalink / raw)
  To: linux-aspeed

v3: Remove unnecessary locking, use ptR
v2: Address review from Alexandre

Joel Stanley (2):
  dt-bindings: rtc: Add on-chip ASPEED RTC documentation
  rtc: Add ASPEED RTC driver

 .../devicetree/bindings/rtc/rtc-aspeed.txt    |  22 +++
 drivers/rtc/Kconfig                           |  11 ++
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-aspeed.c                      | 138 ++++++++++++++++++
 4 files changed, 172 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-aspeed.txt
 create mode 100644 drivers/rtc/rtc-aspeed.c

-- 
2.20.1


^ permalink raw reply

* [PATCH v2 2/2] rtc: Add ASPEED RTC driver
From: Joel Stanley @ 2019-03-27  1:00 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <20190325161010.GP30105@piout.net>

On Mon, 25 Mar 2019 at 16:10, Alexandre Belloni
<alexandre.belloni@bootlin.com> wrote:> >
> While doing that change, I relaized that the whole locking is probably
> unnecessary as all the rtc_ops are called with the rtc lock taken. If
> you are not planning to add alarm support, the lock can be removed.

I had a stab at alarm support, but the select() tests in rtctest.c
were failing. I will submit a v3 without the locking so we can get
that out of the way, and defer adding alarm support for now.

Cheers,

Joel

^ permalink raw reply

* [PATCH] Revert "gpio: use new gpio_set_config() helper in more places"
From: Bartosz Golaszewski @ 2019-03-26 18:06 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <20190326044954.18671-1-andrew@aj.id.au>

wt., 26 mar 2019 o 05:50 Andrew Jeffery <andrew@aj.id.au> napisa?(a):
>
> gpio-aspeed implements support for PIN_CONFIG_INPUT_DEBOUNCE. As of
> v5.1-rc1 we're seeing the following when booting a Romulus BMC kernel:
>
> > [   21.373137] ------------[ cut here ]------------
> > [   21.374545] WARNING: CPU: 0 PID: 1 at drivers/gpio/gpio-aspeed.c:834 unregister_allocated_timer+0x38/0x94
> > [   21.376181] No timer allocated to offset 74
> > [   21.377672] CPU: 0 PID: 1 Comm: swapper Not tainted 5.1.0-rc1-dirty #6
> > [   21.378800] Hardware name: Generic DT based system
> > [   21.379965] Backtrace:
> > [   21.381024] [<80107d44>] (dump_backtrace) from [<80107f78>] (show_stack+0x20/0x24)
> > [   21.382713]  r7:8038b720 r6:00000009 r5:00000000 r4:87897c64
> > [   21.383815] [<80107f58>] (show_stack) from [<80656398>] (dump_stack+0x20/0x28)
> > [   21.385042] [<80656378>] (dump_stack) from [<80115f1c>] (__warn.part.3+0xb4/0xdc)
> > [   21.386253] [<80115e68>] (__warn.part.3) from [<80115fb0>] (warn_slowpath_fmt+0x6c/0x90)
> > [   21.387471]  r6:00000342 r5:807f8758 r4:80a07008
> > [   21.388278] [<80115f48>] (warn_slowpath_fmt) from [<8038b720>] (unregister_allocated_timer+0x38/0x94)
> > [   21.389809]  r3:0000004a r2:807f8774
> > [   21.390526]  r7:00000000 r6:0000000a r5:60000153 r4:0000004a
> > [   21.391601] [<8038b6e8>] (unregister_allocated_timer) from [<8038baac>] (aspeed_gpio_set_config+0x330/0x48c)
> > [   21.393248] [<8038b77c>] (aspeed_gpio_set_config) from [<803840b0>] (gpiod_set_debounce+0xe8/0x114)
> > [   21.394745]  r10:82ee2248 r9:00000000 r8:87b63a00 r7:00001388 r6:87947320 r5:80729310
> > [   21.396030]  r4:879f64a0
> > [   21.396499] [<80383fc8>] (gpiod_set_debounce) from [<804b4350>] (gpio_keys_probe+0x69c/0x8e0)
> > [   21.397715]  r7:845d94b8 r6:00000001 r5:00000000 r4:87b63a1c
> > [   21.398618] [<804b3cb4>] (gpio_keys_probe) from [<8040eeec>] (platform_dev_probe+0x44/0x80)
> > [   21.399834]  r10:00000003 r9:80a3a8b0 r8:00000000 r7:00000000 r6:80a7f9dc r5:80a3a8b0
> > [   21.401163]  r4:8796bc10
> > [   21.401634] [<8040eea8>] (platform_drv_probe) from [<8040d0d4>] (really_probe+0x208/0x3dc)
> > [   21.402786]  r5:80a7f8d0 r4:8796bc10
> > [   21.403547] [<8040cecc>] (really_probe) from [<8040d7a4>] (driver_probe_device+0x130/0x170)
> > [   21.404744]  r10:0000007b r9:8093683c r8:00000000 r7:80a07008 r6:80a3a8b0 r5:8796bc10
> > [   21.405854]  r4:80a3a8b0
> > [   21.406324] [<8040d674>] (driver_probe_device) from [<8040da8c>] (device_driver_attach+0x68/0x70)
> > [   21.407568]  r9:8093683c r8:00000000 r7:80a07008 r6:80a3a8b0 r5:00000000 r4:8796bc10
> > [   21.408877] [<8040da24>] (device_driver_attach) from [<8040db14>] (__driver_attach+0x80/0x150)
> > [   21.410327]  r7:80a07008 r6:8796bc10 r5:00000001 r4:80a3a8b0
> > [   21.411294] [<8040da94>] (__driver_attach) from [<8040b20c>] (bus_for_each_dev+0x80/0xc4)
> > [   21.412641]  r7:80a07008 r6:8040da94 r5:80a3a8b0 r4:87966f30
> > [   21.413580] [<8040b18c>] (bus_for_each_dev) from [<8040dc0c>] (driver_attach+0x28/0x30)
> > [   21.414943]  r7:00000000 r6:87b411e0 r5:80a33fc8 r4:80a3a8b0
> > [   21.415927] [<8040dbe4>] (driver_attach) from [<8040bbf0>] (bus_add_driver+0x14c/0x200)
> > [   21.417289] [<8040baa4>] (bus_add_driver) from [<8040e2b4>] (driver_register+0x84/0x118)
> > [   21.418652]  r7:80a60ae0 r6:809226b8 r5:80a07008 r4:80a3a8b0
> > [   21.419652] [<8040e230>] (driver_register) from [<8040fc28>] (__platform_driver_register+0x3c/0x50)
> > [   21.421193]  r5:80a07008 r4:809525f8
> > [   21.421990] [<8040fbec>] (__platform_driver_register) from [<809226d8>] (gpio_keys_init+0x20/0x28)
> > [   21.423447] [<809226b8>] (gpio_keys_init) from [<8090128c>] (do_one_initcall+0x80/0x180)
> > [   21.424886] [<8090120c>] (do_one_initcall) from [<80901538>] (kernel_init_freeable+0x1ac/0x26c)
> > [   21.426354]  r8:80a60ae0 r7:80a60ae0 r6:8093685c r5:00000008 r4:809525f8
> > [   21.427579] [<8090138c>] (kernel_init_freeable) from [<8066d9a0>] (kernel_init+0x18/0x11c)
> > [   21.428819]  r10:00000000 r9:00000000 r8:00000000 r7:00000000 r6:00000000 r5:8066d988
> > [   21.429947]  r4:00000000
> > [   21.430415] [<8066d988>] (kernel_init) from [<801010e8>] (ret_from_fork+0x14/0x2c)
> > [   21.431666] Exception stack(0x87897fb0 to 0x87897ff8)
> > [   21.432877] 7fa0:                                     00000000 00000000 00000000 00000000
> > [   21.434446] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> > [   21.436052] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000
> > [   21.437308]  r5:8066d988 r4:00000000
> > [   21.438102] ---[ end trace d7d7ac3a80567d0e ]---
>
> We only hit unregister_allocated_timer() if the argument to
> aspeed_gpio_set_config() is 0, but we can't be calling through
> gpiod_set_debounce() from gpio_keys_probe() unless the gpio-keys button has a
> non-zero debounce interval.
>
> Commit 6581eaf0e890 ("gpio: use new gpio_set_config() helper in more places")
> spreads the use of gpio_set_config() to the debounce and transitory
> state configuration paths. The implementation of gpio_set_config() is:
>
> > static int gpio_set_config(struct gpio_chip *gc, unsigned offset,
> >                          enum pin_config_param mode)
> > {
> >       unsigned long config = { PIN_CONF_PACKED(mode, 0) };
> >
> >       return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP;
> > }
>
> Here it packs its own config value with a fixed argument of 0; this is
> incorrect behaviour for implementing the debounce and transitory functions, and
> the debounce and transitory gpio_set_config() call-sites now have an undetected
> type mismatch as they both already pack their own config parameter (i.e. what
> gets passed is not an `enum pin_config_param`). Indeed this can be seen in the
> small diff for 6581eaf0e890:
>
> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > index de595fa31a1a..1f239aac43df 100644
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -2725,7 +2725,7 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
> >         }
> >
> >         config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
> > -       return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
> > +       return gpio_set_config(chip, gpio_chip_hwgpio(desc), config);
> >  }
> >  EXPORT_SYMBOL_GPL(gpiod_set_debounce);
> >
> > @@ -2762,7 +2762,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
> >         packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,
> >                                           !transitory);
> >         gpio = gpio_chip_hwgpio(desc);
> > -       rc = chip->set_config(chip, gpio, packed);
> > +       rc = gpio_set_config(chip, gpio, packed);
> >         if (rc == -ENOTSUPP) {
> >                 dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",
> >                                 gpio);
>
> Revert commit 6581eaf0e890 ("gpio: use new gpio_set_config() helper in
> more places") to restore correct behaviour for gpiod_set_debounce() and
> gpiod_set_transitory().
>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
> ---
>  drivers/gpio/gpiolib.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 144af0733581..0495bf1d480a 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -2776,7 +2776,7 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
>         }
>
>         config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
> -       return gpio_set_config(chip, gpio_chip_hwgpio(desc), config);
> +       return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
>  }
>  EXPORT_SYMBOL_GPL(gpiod_set_debounce);
>
> @@ -2813,7 +2813,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
>         packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,
>                                           !transitory);
>         gpio = gpio_chip_hwgpio(desc);
> -       rc = gpio_set_config(chip, gpio, packed);
> +       rc = chip->set_config(chip, gpio, packed);
>         if (rc == -ENOTSUPP) {
>                 dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",
>                                 gpio);
> --
> 2.19.1
>

Thanks for the detailed explanation of the problem. Can we check for
special cases in gpiod_set_config() and possibly pass the config
unchanged to the underlying driver in case of debounce and transitory
options?

Bart

^ permalink raw reply

* [PATCH] witherspoon.dts: Enable the USB vhub (device)
From: Adriana Kobylak @ 2019-03-26 14:33 UTC (permalink / raw)
  To: linux-aspeed

The Aspeed vhub device driver is already enabled in
the defconfig, make use of it in the witherspoon platform.

Signed-off-by: Adriana Kobylak <anoo@linux.ibm.com>
---
 arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts b/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
index b933ced..8ebe35e 100644
--- a/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
@@ -634,6 +634,10 @@
 	memory-region = <&gfx_memory>;
 };
 
+&vhub {
+	status = "okay";
+};
+
 &pinctrl {
 	aspeed,external-nodes = <&gfx &lhc>;
 };
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH] Revert "gpio: use new gpio_set_config() helper in more places"
From: Andrew Jeffery @ 2019-03-26  4:49 UTC (permalink / raw)
  To: linux-aspeed

gpio-aspeed implements support for PIN_CONFIG_INPUT_DEBOUNCE. As of
v5.1-rc1 we're seeing the following when booting a Romulus BMC kernel:

> [   21.373137] ------------[ cut here ]------------
> [   21.374545] WARNING: CPU: 0 PID: 1 at drivers/gpio/gpio-aspeed.c:834 unregister_allocated_timer+0x38/0x94
> [   21.376181] No timer allocated to offset 74
> [   21.377672] CPU: 0 PID: 1 Comm: swapper Not tainted 5.1.0-rc1-dirty #6
> [   21.378800] Hardware name: Generic DT based system
> [   21.379965] Backtrace:
> [   21.381024] [<80107d44>] (dump_backtrace) from [<80107f78>] (show_stack+0x20/0x24)
> [   21.382713]  r7:8038b720 r6:00000009 r5:00000000 r4:87897c64
> [   21.383815] [<80107f58>] (show_stack) from [<80656398>] (dump_stack+0x20/0x28)
> [   21.385042] [<80656378>] (dump_stack) from [<80115f1c>] (__warn.part.3+0xb4/0xdc)
> [   21.386253] [<80115e68>] (__warn.part.3) from [<80115fb0>] (warn_slowpath_fmt+0x6c/0x90)
> [   21.387471]  r6:00000342 r5:807f8758 r4:80a07008
> [   21.388278] [<80115f48>] (warn_slowpath_fmt) from [<8038b720>] (unregister_allocated_timer+0x38/0x94)
> [   21.389809]  r3:0000004a r2:807f8774
> [   21.390526]  r7:00000000 r6:0000000a r5:60000153 r4:0000004a
> [   21.391601] [<8038b6e8>] (unregister_allocated_timer) from [<8038baac>] (aspeed_gpio_set_config+0x330/0x48c)
> [   21.393248] [<8038b77c>] (aspeed_gpio_set_config) from [<803840b0>] (gpiod_set_debounce+0xe8/0x114)
> [   21.394745]  r10:82ee2248 r9:00000000 r8:87b63a00 r7:00001388 r6:87947320 r5:80729310
> [   21.396030]  r4:879f64a0
> [   21.396499] [<80383fc8>] (gpiod_set_debounce) from [<804b4350>] (gpio_keys_probe+0x69c/0x8e0)
> [   21.397715]  r7:845d94b8 r6:00000001 r5:00000000 r4:87b63a1c
> [   21.398618] [<804b3cb4>] (gpio_keys_probe) from [<8040eeec>] (platform_dev_probe+0x44/0x80)
> [   21.399834]  r10:00000003 r9:80a3a8b0 r8:00000000 r7:00000000 r6:80a7f9dc r5:80a3a8b0
> [   21.401163]  r4:8796bc10
> [   21.401634] [<8040eea8>] (platform_drv_probe) from [<8040d0d4>] (really_probe+0x208/0x3dc)
> [   21.402786]  r5:80a7f8d0 r4:8796bc10
> [   21.403547] [<8040cecc>] (really_probe) from [<8040d7a4>] (driver_probe_device+0x130/0x170)
> [   21.404744]  r10:0000007b r9:8093683c r8:00000000 r7:80a07008 r6:80a3a8b0 r5:8796bc10
> [   21.405854]  r4:80a3a8b0
> [   21.406324] [<8040d674>] (driver_probe_device) from [<8040da8c>] (device_driver_attach+0x68/0x70)
> [   21.407568]  r9:8093683c r8:00000000 r7:80a07008 r6:80a3a8b0 r5:00000000 r4:8796bc10
> [   21.408877] [<8040da24>] (device_driver_attach) from [<8040db14>] (__driver_attach+0x80/0x150)
> [   21.410327]  r7:80a07008 r6:8796bc10 r5:00000001 r4:80a3a8b0
> [   21.411294] [<8040da94>] (__driver_attach) from [<8040b20c>] (bus_for_each_dev+0x80/0xc4)
> [   21.412641]  r7:80a07008 r6:8040da94 r5:80a3a8b0 r4:87966f30
> [   21.413580] [<8040b18c>] (bus_for_each_dev) from [<8040dc0c>] (driver_attach+0x28/0x30)
> [   21.414943]  r7:00000000 r6:87b411e0 r5:80a33fc8 r4:80a3a8b0
> [   21.415927] [<8040dbe4>] (driver_attach) from [<8040bbf0>] (bus_add_driver+0x14c/0x200)
> [   21.417289] [<8040baa4>] (bus_add_driver) from [<8040e2b4>] (driver_register+0x84/0x118)
> [   21.418652]  r7:80a60ae0 r6:809226b8 r5:80a07008 r4:80a3a8b0
> [   21.419652] [<8040e230>] (driver_register) from [<8040fc28>] (__platform_driver_register+0x3c/0x50)
> [   21.421193]  r5:80a07008 r4:809525f8
> [   21.421990] [<8040fbec>] (__platform_driver_register) from [<809226d8>] (gpio_keys_init+0x20/0x28)
> [   21.423447] [<809226b8>] (gpio_keys_init) from [<8090128c>] (do_one_initcall+0x80/0x180)
> [   21.424886] [<8090120c>] (do_one_initcall) from [<80901538>] (kernel_init_freeable+0x1ac/0x26c)
> [   21.426354]  r8:80a60ae0 r7:80a60ae0 r6:8093685c r5:00000008 r4:809525f8
> [   21.427579] [<8090138c>] (kernel_init_freeable) from [<8066d9a0>] (kernel_init+0x18/0x11c)
> [   21.428819]  r10:00000000 r9:00000000 r8:00000000 r7:00000000 r6:00000000 r5:8066d988
> [   21.429947]  r4:00000000
> [   21.430415] [<8066d988>] (kernel_init) from [<801010e8>] (ret_from_fork+0x14/0x2c)
> [   21.431666] Exception stack(0x87897fb0 to 0x87897ff8)
> [   21.432877] 7fa0:                                     00000000 00000000 00000000 00000000
> [   21.434446] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> [   21.436052] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000
> [   21.437308]  r5:8066d988 r4:00000000
> [   21.438102] ---[ end trace d7d7ac3a80567d0e ]---

We only hit unregister_allocated_timer() if the argument to
aspeed_gpio_set_config() is 0, but we can't be calling through
gpiod_set_debounce() from gpio_keys_probe() unless the gpio-keys button has a
non-zero debounce interval.

Commit 6581eaf0e890 ("gpio: use new gpio_set_config() helper in more places")
spreads the use of gpio_set_config() to the debounce and transitory
state configuration paths. The implementation of gpio_set_config() is:

> static int gpio_set_config(struct gpio_chip *gc, unsigned offset,
> 			   enum pin_config_param mode)
> {
> 	unsigned long config = { PIN_CONF_PACKED(mode, 0) };
>
> 	return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP;
> }

Here it packs its own config value with a fixed argument of 0; this is
incorrect behaviour for implementing the debounce and transitory functions, and
the debounce and transitory gpio_set_config() call-sites now have an undetected
type mismatch as they both already pack their own config parameter (i.e. what
gets passed is not an `enum pin_config_param`). Indeed this can be seen in the
small diff for 6581eaf0e890:

> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index de595fa31a1a..1f239aac43df 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -2725,7 +2725,7 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
>         }
>
>         config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
> -       return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
> +       return gpio_set_config(chip, gpio_chip_hwgpio(desc), config);
>  }
>  EXPORT_SYMBOL_GPL(gpiod_set_debounce);
>
> @@ -2762,7 +2762,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
>         packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,
>                                           !transitory);
>         gpio = gpio_chip_hwgpio(desc);
> -       rc = chip->set_config(chip, gpio, packed);
> +       rc = gpio_set_config(chip, gpio, packed);
>         if (rc == -ENOTSUPP) {
>                 dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",
>                                 gpio);

Revert commit 6581eaf0e890 ("gpio: use new gpio_set_config() helper in
more places") to restore correct behaviour for gpiod_set_debounce() and
gpiod_set_transitory().

Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 drivers/gpio/gpiolib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 144af0733581..0495bf1d480a 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2776,7 +2776,7 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
 	}
 
 	config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
-	return gpio_set_config(chip, gpio_chip_hwgpio(desc), config);
+	return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
 }
 EXPORT_SYMBOL_GPL(gpiod_set_debounce);
 
@@ -2813,7 +2813,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
 	packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,
 					  !transitory);
 	gpio = gpio_chip_hwgpio(desc);
-	rc = gpio_set_config(chip, gpio, packed);
+	rc = chip->set_config(chip, gpio, packed);
 	if (rc == -ENOTSUPP) {
 		dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",
 				gpio);
-- 
2.19.1


^ permalink raw reply related

* [PATCH v2 2/2] rtc: Add ASPEED RTC driver
From: Alexandre Belloni @ 2019-03-25 16:10 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <CACPK8XfFTF2hDzwO33gE=fotEEC-CZztThoaYj98Le9JAsAQ-w@mail.gmail.com>

On 25/03/2019 15:28:26+0000, Joel Stanley wrote:
> On Mon, 25 Mar 2019 at 14:59, Alexandre Belloni
> <alexandre.belloni@bootlin.com> wrote:
> >
> > Hi,
> >
> > This seems mostly good to me.
> >
> > On 26/03/2019 00:01:59+1030, Joel Stanley wrote:
> > > +     dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
> > > +                     1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
> > > +                     tm->tm_hour, tm->tm_min, tm->tm_sec);
> > > +
> >
> > We now have %ptR, could you use that?
> 
> I tried this:
> 
>   dev_dbg(dev, "%s: %ptR", __func__, tm);
> 
> Yes, that appears to do the job. Can you make the change when applying?
> 

While doing that change, I relaized that the whole locking is probably
unnecessary as all the rtc_ops are called with the rtc lock taken. If
you are not planning to add alarm support, the lock can be removed.


-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply

* [PATCH v2 2/2] rtc: Add ASPEED RTC driver
From: Alexandre Belloni @ 2019-03-25 15:43 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <CACPK8XfFTF2hDzwO33gE=fotEEC-CZztThoaYj98Le9JAsAQ-w@mail.gmail.com>

On 25/03/2019 15:28:26+0000, Joel Stanley wrote:
> On Mon, 25 Mar 2019 at 14:59, Alexandre Belloni
> <alexandre.belloni@bootlin.com> wrote:
> > On 26/03/2019 00:01:59+1030, Joel Stanley wrote:
> > > +     dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
> > > +                     1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
> > > +                     tm->tm_hour, tm->tm_min, tm->tm_sec);
> > > +
> >
> > We now have %ptR, could you use that?
> 
> I tried this:
> 
>   dev_dbg(dev, "%s: %ptR", __func__, tm);
> 
> Yes, that appears to do the job. Can you make the change when applying?
> 

Ok, I'll do that.

> >
> > > +     rtc->rtc_dev->ops = &aspeed_rtc_ops;
> > > +     rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
> > > +     rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */
> > > +
> >
> > I'm curious how many RTC have been properly designed, could you run
> > rtc-range?
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc-range.c
> 
> It appears to pass the test:
> 
> Testing 2000-02-28 23:59:59.
> OK
> 
> Testing 2038-01-19 03:14:07.
> OK
> 
> Testing 2069-12-31 23:59:59.
> OK
> 
> Testing 2099-12-31 23:59:59.
> OK
> 
> Testing 2100-02-28 23:59:59.
> OK
> 
> Testing 2106-02-07 06:28:15.
> OK
> 
> Testing 2262-04-11 23:47:16.
> OK
> 
> The qemu model I have for the device failed though. A good test! Are
> you going to put it in the kernel tree?
> 

I was planning to add more dates to test and detect when the range is
properly reported by the rtc (right now, it reports a failure) before
doing so.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply

* [PATCH v2 2/2] rtc: Add ASPEED RTC driver
From: Joel Stanley @ 2019-03-25 15:28 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <20190325145954.GM30105@piout.net>

On Mon, 25 Mar 2019 at 14:59, Alexandre Belloni
<alexandre.belloni@bootlin.com> wrote:
>
> Hi,
>
> This seems mostly good to me.
>
> On 26/03/2019 00:01:59+1030, Joel Stanley wrote:
> > +     dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
> > +                     1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
> > +                     tm->tm_hour, tm->tm_min, tm->tm_sec);
> > +
>
> We now have %ptR, could you use that?

I tried this:

  dev_dbg(dev, "%s: %ptR", __func__, tm);

Yes, that appears to do the job. Can you make the change when applying?

>
> > +     rtc->rtc_dev->ops = &aspeed_rtc_ops;
> > +     rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
> > +     rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */
> > +
>
> I'm curious how many RTC have been properly designed, could you run
> rtc-range?
>
> https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc-range.c

It appears to pass the test:

Testing 2000-02-28 23:59:59.
OK

Testing 2038-01-19 03:14:07.
OK

Testing 2069-12-31 23:59:59.
OK

Testing 2099-12-31 23:59:59.
OK

Testing 2100-02-28 23:59:59.
OK

Testing 2106-02-07 06:28:15.
OK

Testing 2262-04-11 23:47:16.
OK

The qemu model I have for the device failed though. A good test! Are
you going to put it in the kernel tree?

Cheers,

Joel

^ permalink raw reply

* [PATCH v2 2/2] rtc: Add ASPEED RTC driver
From: Alexandre Belloni @ 2019-03-25 14:59 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <20190325133159.10653-3-joel@jms.id.au>

Hi,

This seems mostly good to me.

On 26/03/2019 00:01:59+1030, Joel Stanley wrote:
> +	dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
> +			1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
> +			tm->tm_hour, tm->tm_min, tm->tm_sec);
> +

We now have %ptR, could you use that?

> +	rtc->rtc_dev->ops = &aspeed_rtc_ops;
> +	rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
> +	rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */
> +

I'm curious how many RTC have been properly designed, could you run
rtc-range?

https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc-range.c

Thanks!

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply

* [PATCH v2 2/2] rtc: Add ASPEED RTC driver
From: Joel Stanley @ 2019-03-25 13:31 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <20190325133159.10653-1-joel@jms.id.au>

Read and writes the time to the non-battery backed RTC in the ASPEED BMC
system on chip families.

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
v2: Address review from Alexandre
 - Use devm_rtc_allocate_device
 - Fill in range_min
 - Direcly fill in tm struct
 - Return EINVAL when RTC is not enabled

v1: https://lore.kernel.org/linux-arm-kernel/20181003133155.27494-2-joel at jms.id.au/
Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 drivers/rtc/Kconfig      |  10 +++
 drivers/rtc/Makefile     |   1 +
 drivers/rtc/rtc-aspeed.c | 152 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 163 insertions(+)
 create mode 100644 drivers/rtc/rtc-aspeed.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index dc0d66e80038..2d0482bc468b 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1841,6 +1841,16 @@ config RTC_DRV_RTD119X
 	  If you say yes here, you get support for the RTD1295 SoC
 	  Real Time Clock.
 
+config RTC_DRV_ASPEED
+	tristate "Aspeed RTC"
+	depends on ARCH_ASPEED || COMPILE_TEST
+	help
+	  If you say yes here you get support for the ASPEED AST2400 and
+	  AST2500 SoC real time clocks.
+
+	  This driver can also be built as a module, if so, the module
+	  will be called "rtc-aspeed".
+
 comment "HID Sensor RTC drivers"
 
 config RTC_DRV_HID_SENSOR_TIME
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index fe3962496685..9d997faa2c26 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_RTC_DRV_AC100)	+= rtc-ac100.o
 obj-$(CONFIG_RTC_DRV_ARMADA38X)	+= rtc-armada38x.o
 obj-$(CONFIG_RTC_DRV_AS3722)	+= rtc-as3722.o
 obj-$(CONFIG_RTC_DRV_ASM9260)	+= rtc-asm9260.o
+obj-$(CONFIG_RTC_DRV_ASPEED)	+= rtc-aspeed.o
 obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
 obj-$(CONFIG_RTC_DRV_AT91SAM9)	+= rtc-at91sam9.o
 obj-$(CONFIG_RTC_DRV_AU1XXX)	+= rtc-au1xxx.o
diff --git a/drivers/rtc/rtc-aspeed.c b/drivers/rtc/rtc-aspeed.c
new file mode 100644
index 000000000000..9ddb3121b30d
--- /dev/null
+++ b/drivers/rtc/rtc-aspeed.c
@@ -0,0 +1,152 @@
+// SPDX-License-Identifier: GPL-2.0+
+// Copyright 2015 IBM Corp.
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+#include <linux/io.h>
+
+struct aspeed_rtc {
+	struct rtc_device	*rtc_dev;
+	void __iomem		*base;
+	spinlock_t		lock;
+};
+
+#define RTC_TIME	0x00
+#define RTC_YEAR	0x04
+#define RTC_CTRL	0x10
+
+#define RTC_UNLOCK	BIT(1)
+#define RTC_ENABLE	BIT(0)
+
+static int aspeed_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct aspeed_rtc *rtc = dev_get_drvdata(dev);
+	unsigned int cent, year;
+	unsigned long flags;
+	u32 reg1, reg2;
+
+	spin_lock_irqsave(&rtc->lock, flags);
+
+	if (!(readl(rtc->base + RTC_CTRL) & RTC_ENABLE)) {
+		spin_unlock_irqrestore(&rtc->lock, flags);
+		dev_dbg(dev, "%s failing as rtc disabled\n", __func__);
+		return -EINVAL;
+	}
+
+	do {
+		reg2 = readl(rtc->base + RTC_YEAR);
+		reg1 = readl(rtc->base + RTC_TIME);
+	} while (reg2 != readl(rtc->base + RTC_YEAR));
+
+	tm->tm_mday = (reg1 >> 24) & 0x1f;
+	tm->tm_hour = (reg1 >> 16) & 0x1f;
+	tm->tm_min = (reg1 >> 8) & 0x3f;
+	tm->tm_sec = (reg1 >> 0) & 0x3f;
+
+	cent = (reg2 >> 16) & 0x1f;
+	year = (reg2 >> 8) & 0x7f;
+	tm->tm_mon = ((reg2 >>  0) & 0x0f) - 1;
+	tm->tm_year = year + (cent * 100) - 1900;
+
+	dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
+			1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
+			tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+	spin_unlock_irqrestore(&rtc->lock, flags);
+
+	return 0;
+}
+
+static int aspeed_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct aspeed_rtc *rtc = dev_get_drvdata(dev);
+	unsigned long flags;
+	u32 reg1, reg2, ctrl;
+	int year, cent;
+
+	cent = (tm->tm_year + 1900) / 100;
+	year = tm->tm_year % 100;
+
+	reg1 = (tm->tm_mday << 24) | (tm->tm_hour << 16) | (tm->tm_min << 8) |
+		tm->tm_sec;
+
+	reg2 = ((cent & 0x1f) << 16) | ((year & 0x7f) << 8) |
+		((tm->tm_mon + 1) & 0xf);
+
+	spin_lock_irqsave(&rtc->lock, flags);
+
+	ctrl = readl(rtc->base + RTC_CTRL);
+	writel(ctrl | RTC_UNLOCK, rtc->base + RTC_CTRL);
+
+	writel(reg1, rtc->base + RTC_TIME);
+	writel(reg2, rtc->base + RTC_YEAR);
+
+	/* Re-lock and ensure enable is set now that a time is programmed */
+	writel(ctrl | RTC_ENABLE, rtc->base + RTC_CTRL);
+
+	spin_unlock_irqrestore(&rtc->lock, flags);
+
+	return 0;
+}
+
+static const struct rtc_class_ops aspeed_rtc_ops = {
+	.read_time = aspeed_rtc_read_time,
+	.set_time = aspeed_rtc_set_time,
+};
+
+static int aspeed_rtc_probe(struct platform_device *pdev)
+{
+	struct aspeed_rtc *rtc;
+	struct resource *res;
+	int ret;
+
+	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	rtc->base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(rtc->base))
+		return PTR_ERR(rtc->base);
+
+	rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
+	if (IS_ERR(rtc->rtc_dev))
+		return PTR_ERR(rtc->rtc_dev);
+
+	platform_set_drvdata(pdev, rtc);
+
+	rtc->rtc_dev->ops = &aspeed_rtc_ops;
+	rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
+	rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */
+
+	ret = rtc_register_device(rtc->rtc_dev);
+	if (ret)
+		return ret;
+
+	spin_lock_init(&rtc->lock);
+
+	return 0;
+}
+
+static const struct of_device_id aspeed_rtc_match[] = {
+	{ .compatible = "aspeed,ast2400-rtc", },
+	{ .compatible = "aspeed,ast2500-rtc", },
+	{ .compatible = "aspeed,ast2600-rtc", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, aspeed_rtc_match);
+
+static struct platform_driver aspeed_rtc_driver = {
+	.driver = {
+		.name = "aspeed-rtc",
+		.of_match_table = of_match_ptr(aspeed_rtc_match),
+	},
+};
+
+module_platform_driver_probe(aspeed_rtc_driver, aspeed_rtc_probe);
+
+MODULE_DESCRIPTION("ASPEED RTC driver");
+MODULE_AUTHOR("Joel Stanley <joel@jms.id.au>");
+MODULE_LICENSE("GPL");
-- 
2.20.1


^ permalink raw reply related

* [PATCH v2 1/2] dt-bindings: rtc: Add on-chip ASPEED RTC documentation
From: Joel Stanley @ 2019-03-25 13:31 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <20190325133159.10653-1-joel@jms.id.au>

Describe the RTC as used in the ASPEED BMC SoCs.

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 .../devicetree/bindings/rtc/rtc-aspeed.txt    | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-aspeed.txt

diff --git a/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt b/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt
new file mode 100644
index 000000000000..f9f7defd557e
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt
@@ -0,0 +1,19 @@
+ASPEED BMC RTC
+==============
+
+Required properties:
+ - compatible: should be one of the following
+   * aspeed,ast2400-rtc for the ast2400
+   * aspeed,ast2500-rtc for the ast2500
+   * aspeed,ast2600-rtc for the ast2600
+
+ - reg: physical base address of the controller and length of memory mapped
+   region
+
+Example:
+
+   rtc at 1e781000 {
+           compatible = "aspeed,ast2400-rtc";
+           reg = <0x1e781000 0x18>;
+           status = "disabled";
+   };
-- 
2.20.1


^ permalink raw reply related

* [PATCH v2 0/2] rtc: Add ASPEED RTC driver
From: Joel Stanley @ 2019-03-25 13:31 UTC (permalink / raw)
  To: linux-aspeed

I finally found some time to send a v2 for this one. Thanks Alexandre
for the review back in October.

v2: Address review from Alexandre

Joel Stanley (2):
  dt-bindings: rtc: Add on-chip ASPEED RTC documentation
  rtc: Add ASPEED RTC driver

 .../devicetree/bindings/rtc/rtc-aspeed.txt    |  19 +++
 drivers/rtc/Kconfig                           |  10 ++
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-aspeed.c                      | 152 ++++++++++++++++++
 4 files changed, 182 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-aspeed.txt
 create mode 100644 drivers/rtc/rtc-aspeed.c

-- 
2.20.1


^ permalink raw reply

* [PATCH] gpio: fix a potential NULL pointer dereference
From: Bartosz Golaszewski @ 2019-03-25  8:28 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <f4d27985-376a-42bb-b781-bdc96c0cef21@www.fastmail.com>

pon., 25 mar 2019 o 00:12 Andrew Jeffery <andrew@aj.id.au> napisa?(a):
>
>
>
> On Mon, 25 Mar 2019, at 09:40, Kangjie Lu wrote:
> > In case devm_kzalloc, the patch returns ENOMEM to avoid potential
> > NULL pointer dereference.
> >
> > Signed-off-by: Kangjie Lu <kjlu@umn.edu>
>
> Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
>
> > ---
> >  drivers/gpio/gpio-aspeed.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
> > index 854bce4fb9e7..217507002dbc 100644
> > --- a/drivers/gpio/gpio-aspeed.c
> > +++ b/drivers/gpio/gpio-aspeed.c
> > @@ -1224,6 +1224,8 @@ static int __init aspeed_gpio_probe(struct
> > platform_device *pdev)
> >
> >       gpio->offset_timer =
> >               devm_kzalloc(&pdev->dev, gpio->chip.ngpio, GFP_KERNEL);
> > +     if (!gpio->offset_timer)
> > +             return -ENOMEM;
> >
> >       return aspeed_gpio_setup_irqs(gpio, pdev);
> >  }
> > --
> > 2.17.1
> >
> >

Applied to fixes.

Bart

^ permalink raw reply

* [PATCH] gpio: fix a potential NULL pointer dereference
From: Andrew Jeffery @ 2019-03-24 23:12 UTC (permalink / raw)
  To: linux-aspeed
In-Reply-To: <20190324231002.2106-1-kjlu@umn.edu>



On Mon, 25 Mar 2019, at 09:40, Kangjie Lu wrote:
> In case devm_kzalloc, the patch returns ENOMEM to avoid potential
> NULL pointer dereference.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>

Reviewed-by: Andrew Jeffery <andrew@aj.id.au>

> ---
>  drivers/gpio/gpio-aspeed.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
> index 854bce4fb9e7..217507002dbc 100644
> --- a/drivers/gpio/gpio-aspeed.c
> +++ b/drivers/gpio/gpio-aspeed.c
> @@ -1224,6 +1224,8 @@ static int __init aspeed_gpio_probe(struct 
> platform_device *pdev)
>  
>  	gpio->offset_timer =
>  		devm_kzalloc(&pdev->dev, gpio->chip.ngpio, GFP_KERNEL);
> +	if (!gpio->offset_timer)
> +		return -ENOMEM;
>  
>  	return aspeed_gpio_setup_irqs(gpio, pdev);
>  }
> -- 
> 2.17.1
> 
>

^ permalink raw reply

* [PATCH] gpio: fix a potential NULL pointer dereference
From: Kangjie Lu @ 2019-03-24 23:10 UTC (permalink / raw)
  To: linux-aspeed

In case devm_kzalloc, the patch returns ENOMEM to avoid potential
NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/gpio/gpio-aspeed.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
index 854bce4fb9e7..217507002dbc 100644
--- a/drivers/gpio/gpio-aspeed.c
+++ b/drivers/gpio/gpio-aspeed.c
@@ -1224,6 +1224,8 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev)
 
 	gpio->offset_timer =
 		devm_kzalloc(&pdev->dev, gpio->chip.ngpio, GFP_KERNEL);
+	if (!gpio->offset_timer)
+		return -ENOMEM;
 
 	return aspeed_gpio_setup_irqs(gpio, pdev);
 }
-- 
2.17.1


^ permalink raw reply related

* [v3 PATCH] usb: introduce usb_ep_type_string() function
From: Chunfeng Yun @ 2019-03-21  2:27 UTC (permalink / raw)
  To: linux-aspeed

In some places, the code prints a human-readable USB endpoint
transfer type (e.g. "bulk"). This involves a switch statement
sometimes wrapped around in ({ ... }) block leading to code
repetition.
To make this scenario easier, here introduces usb_ep_type_string()
function, which returns a human-readable name of provided
endpoint type.
It also changes a few places switch was used to use this
new function.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
v2 changes:
    1. keep type string consistent with type_show() used in endpoint.c
v3 changes:
    1. abandon changes that will break user/kernel apis
---
 drivers/usb/common/common.c              | 16 ++++++++++++++++
 drivers/usb/core/hcd.c                   | 17 ++---------------
 drivers/usb/gadget/udc/aspeed-vhub/epn.c |  6 +-----
 drivers/usb/gadget/udc/dummy_hcd.c       | 16 +---------------
 include/linux/usb/ch9.h                  |  8 ++++++++
 5 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index 48277bbc15e4..2174dd9ec176 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -16,6 +16,22 @@
 #include <linux/usb/otg.h>
 #include <linux/of_platform.h>
 
+static const char *const ep_type_names[] = {
+	[USB_ENDPOINT_XFER_CONTROL] = "ctrl",
+	[USB_ENDPOINT_XFER_ISOC] = "isoc",
+	[USB_ENDPOINT_XFER_BULK] = "bulk",
+	[USB_ENDPOINT_XFER_INT] = "intr",
+};
+
+const char *usb_ep_type_string(int ep_type)
+{
+	if (ep_type < 0 || ep_type >= ARRAY_SIZE(ep_type_names))
+		return "unknown";
+
+	return ep_type_names[ep_type];
+}
+EXPORT_SYMBOL_GPL(usb_ep_type_string);
+
 const char *usb_otg_state_string(enum usb_otg_state state)
 {
 	static const char *const names[] = {
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 3189181bb628..0ccf2efeb40b 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1878,23 +1878,10 @@ void usb_hcd_flush_endpoint(struct usb_device *udev,
 		/* kick hcd */
 		unlink1(hcd, urb, -ESHUTDOWN);
 		dev_dbg (hcd->self.controller,
-			"shutdown urb %pK ep%d%s%s\n",
+			"shutdown urb %pK ep%d%s-%s\n",
 			urb, usb_endpoint_num(&ep->desc),
 			is_in ? "in" : "out",
-			({	char *s;
-
-				 switch (usb_endpoint_type(&ep->desc)) {
-				 case USB_ENDPOINT_XFER_CONTROL:
-					s = ""; break;
-				 case USB_ENDPOINT_XFER_BULK:
-					s = "-bulk"; break;
-				 case USB_ENDPOINT_XFER_INT:
-					s = "-intr"; break;
-				 default:
-					s = "-iso"; break;
-				};
-				s;
-			}));
+			usb_ep_type_string(usb_endpoint_type(&ep->desc)));
 		usb_put_urb (urb);
 
 		/* list contents may have changed */
diff --git a/drivers/usb/gadget/udc/aspeed-vhub/epn.c b/drivers/usb/gadget/udc/aspeed-vhub/epn.c
index 83340f4fdc6e..35941dc125f9 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/epn.c
+++ b/drivers/usb/gadget/udc/aspeed-vhub/epn.c
@@ -593,10 +593,6 @@ static int ast_vhub_epn_disable(struct usb_ep* u_ep)
 static int ast_vhub_epn_enable(struct usb_ep* u_ep,
 			       const struct usb_endpoint_descriptor *desc)
 {
-	static const char *ep_type_string[] __maybe_unused = { "ctrl",
-							       "isoc",
-							       "bulk",
-							       "intr" };
 	struct ast_vhub_ep *ep = to_ast_ep(u_ep);
 	struct ast_vhub_dev *dev;
 	struct ast_vhub *vhub;
@@ -646,7 +642,7 @@ static int ast_vhub_epn_enable(struct usb_ep* u_ep,
 	ep->epn.wedged = false;
 
 	EPDBG(ep, "Enabling [%s] %s num %d maxpacket=%d\n",
-	      ep->epn.is_in ? "in" : "out", ep_type_string[type],
+	      ep->epn.is_in ? "in" : "out", usb_ep_type_string(type),
 	      usb_endpoint_num(desc), maxpacket);
 
 	/* Can we use DMA descriptor mode ? */
diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
index baf72f95f0f1..40c6a484e232 100644
--- a/drivers/usb/gadget/udc/dummy_hcd.c
+++ b/drivers/usb/gadget/udc/dummy_hcd.c
@@ -617,21 +617,7 @@ static int dummy_enable(struct usb_ep *_ep,
 		_ep->name,
 		desc->bEndpointAddress & 0x0f,
 		(desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
-		({ char *val;
-		 switch (usb_endpoint_type(desc)) {
-		 case USB_ENDPOINT_XFER_BULK:
-			 val = "bulk";
-			 break;
-		 case USB_ENDPOINT_XFER_ISOC:
-			 val = "iso";
-			 break;
-		 case USB_ENDPOINT_XFER_INT:
-			 val = "intr";
-			 break;
-		 default:
-			 val = "ctrl";
-			 break;
-		 } val; }),
+		usb_ep_type_string(usb_endpoint_type(desc)),
 		max, ep->stream_en ? "enabled" : "disabled");
 
 	/* at this point real hardware should be NAKing transfers
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 523aa088f6ab..da82606be605 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -36,6 +36,14 @@
 #include <linux/device.h>
 #include <uapi/linux/usb/ch9.h>
 
+/**
+ * usb_ep_type_string() - Returns human readable-name of the endpoint type.
+ * @ep_type: The endpoint type to return human-readable name for.  If it's not
+ *   any of the types: USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT},
+ *   usually got by usb_endpoint_type(), the string 'unknown' will be returned.
+ */
+extern const char *usb_ep_type_string(int ep_type);
+
 /**
  * usb_speed_string() - Returns human readable-name of the speed.
  * @speed: The speed to return human-readable name for.  If it's not
-- 
2.20.1


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox