Add GPIO support for MStar/SigmaStar ARMv7
Subsystems (3)
v4 cover Add GPIO support for MStar/SigmaStar ARMv7
At the moment the MStar/SigmaStar support is only really capable of shell from an initramfs and not much else.
Most of the interesting drivers are blocked on clock and pinctrl drivers and those are going to take me a little while to get cleaned up.
Clock and pinctrl aren't needed for basic GPIO to work (all pins start off as GPIOs..) and it makes it possible to actually do something so this series adds everything that is needed for the main GPIO block in these chips.
Changes since v3:
- Remove unneeded "gpio-ranges-group-names" property from binding yaml.
Changes since v2:
- Numerous style and code cleanups as suggested by Andy Shevchenko, Linus Walleij, Marc Zyngier and Rob Herring.
- Pad names moved out of the binding header because they are no longer needed there. The pin/pad numbers are still there as I couldn't think of a better way to do this. meson8b-gpio.h seems to be similar.
Changes since v1:
- Moves the binding header commit before the yaml commit
- Fixes the license on the binding header to include BSD-2-Clause
- The driver has been reworked to use the gpiolib irqchip functionality as suggested by Linus[0]. I think I got this right. The gpio controller doesn't actually do anything with interrupts itself.. It just happens to have 4 lines that are also wired to lines on one of the interrupt controllers.
- Now that the driver is an interrupt controller in it's own right for the gpio lines that have associated interrupts the binding description has been updated to add the interrupt-controller bits and remove the description of the interrupt-names that described how the interrupts used to be passed in.
Daniel Palmer (5):
dt-bindings: gpio: Add a binding header for the MSC313 GPIO driver
dt-bindings: gpio: Binding for MStar MSC313 GPIO controller
gpio: msc313: MStar MSC313 GPIO driver
ARM: mstar: Add gpio controller to MStar base dtsi
ARM: mstar: Fill in GPIO controller properties for infinity
.../bindings/gpio/mstar,msc313-gpio.yaml | 59 +++ MAINTAINERS | 3 + arch/arm/boot/dts/mstar-infinity.dtsi | 7 + arch/arm/boot/dts/mstar-v7.dtsi | 10 + drivers/gpio/Kconfig | 11 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-msc313.c | 460 ++++++++++++++++++ include/dt-bindings/gpio/msc313-gpio.h | 53 ++ 8 files changed, 604 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/mstar,msc313-gpio.yaml create mode 100644 drivers/gpio/gpio-msc313.c create mode 100644 include/dt-bindings/gpio/msc313-gpio.h
Signature · 1 line
2.29.2
PATCH v4 1/5 dt-bindings: gpio: Add a binding header for the MSC313 GPIO driver
Header adds defines for the gpio number of each pad from the driver view.
The gpio block seems to have enough registers for 128 lines but what line is mapped to a physical pin depends on the chip. The gpio block also seems to contain some registers that are not related to gpio but needed somewhere to go.
Because of the above the driver itself uses the index of a pin's offset in an array of the possible offsets for a chip as the gpio number.
--- MAINTAINERS | 1 + include/dt-bindings/gpio/msc313-gpio.h | 53 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 include/dt-bindings/gpio/msc313-gpio.h
MAINTAINERS +1 -0
@@ -2135,6 +2135,7 @@ W: http://linux-chenxing.org/ F: Documentation/devicetree/bindings/arm/mstar/* F: arch/arm/boot/dts/mstar-* F: arch/arm/mach-mstar/ +F: include/dt-bindings/gpio/msc313-gpio.h ARM/NEC MOBILEPRO 900/c MACHINE SUPPORT M: Michael Petchkovsky <[email protected]>
include/dt-bindings/gpio/msc313-gpio.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.29.2
PATCH v4 2/5 dt-bindings: gpio: Binding for MStar MSC313 GPIO controller
In reply to Daniel PalmerAdd a binding description for the MStar/SigmaStar GPIO controller found in the MSC313 and later ARMv7 SoCs.
--- .../bindings/gpio/mstar,msc313-gpio.yaml | 59 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 60 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/mstar,msc313-gpio.yaml
Documentation/devicetree/bindings/gpio/mstar,msc313-gpio.yaml new file +59 -0
@@ -0,0 +1,59 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/mstar,msc313-gpio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MStar/SigmaStar GPIO controller + +maintainers: + - Daniel Palmer <[email protected]> + +properties: + $nodename: + pattern: "^gpio@[0-9a-f]+$" + + compatible: + const: mstar,msc313-gpio + + reg: + maxItems: 1 + + gpio-controller: true + + "#gpio-cells": + const: 2 + + gpio-ranges: true + + interrupt-controller: true + + "#interrupt-cells": + const: 2 + +required: + - compatible + - reg + - gpio-controller + - "#gpio-cells" + - interrupt-controller + - "#interrupt-cells" + +additionalProperties: false + +examples: + - | + #include <dt-bindings/gpio/msc313-gpio.h> + + gpio: gpio@207800 { + compatible = "mstar,msc313e-gpio"; + #gpio-cells = <2>; + reg = <0x207800 0x200>; + gpio-controller; + gpio-ranges = <&pinctrl 0 36 22>, + <&pinctrl 22 63 4>, + <&pinctrl 26 68 6>; + #interrupt-cells = <2>; + interrupt-controller; + interrupt-parent = <&intc_fiq>; + };
MAINTAINERS +1 -0
@@ -2133,6 +2133,7 @@ L: [email protected] (moderated for non-subscribers) S: Maintained W: http://linux-chenxing.org/ F: Documentation/devicetree/bindings/arm/mstar/* +F: Documentation/devicetree/bindings/gpio/mstar,msc313-gpio.yaml F: arch/arm/boot/dts/mstar-* F: arch/arm/mach-mstar/ F: include/dt-bindings/gpio/msc313-gpio.h
Signature · 1 line
2.29.2
Re: [PATCH v4 2/5] dt-bindings: gpio: Binding for MStar MSC313 GPIO controller
Quoted 10 lines · Daniel Palmer
Add a binding description for the MStar/SigmaStar GPIO controller found in the MSC313 and later ARMv7 SoCs.
Signed-off-by Daniel Palmer <[email protected]>--- .../bindings/gpio/mstar,msc313-gpio.yaml | 59 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 60 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/mstar,msc313-gpio.yaml
PATCH v4 3/5 gpio: msc313: MStar MSC313 GPIO driver
In reply to Daniel PalmerThis adds a driver that supports the GPIO block found in MStar/SigmaStar ARMv7 SoCs.
The controller seems to have enough register for 128 lines but where they are wired up differs between chips and
no currently known chip uses anywhere near 128 lines so there needs to be some per-chip data to collect together what lines actually have physical pins attached and map the right names to them.
The core peripherals seem to use the same lines on the currently known chips but the lines used for the sensor interface, lcd controller etc pins seem to be totally different between the infinity and mercury chips
The code tries to collect all of the re-usable names, offsets etc together so that it's easy to build the extra per-chip data for other chips in the future.
So far this only supports the MSC313 and MSC313E chips.
Support for the SSC8336N (mercury5) is trivial to add once all of the lines have been mapped out.
--- MAINTAINERS | 1 + drivers/gpio/Kconfig | 11 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-msc313.c | 460 +++++++++++++++++++++++++++++++++++++ 4 files changed, 473 insertions(+) create mode 100644 drivers/gpio/gpio-msc313.c
MAINTAINERS +1 -0
@@ -2136,6 +2136,7 @@ F: Documentation/devicetree/bindings/arm/mstar/* F: Documentation/devicetree/bindings/gpio/mstar,msc313-gpio.yaml F: arch/arm/boot/dts/mstar-* F: arch/arm/mach-mstar/ +F: drivers/gpio/gpio-msc313.c F: include/dt-bindings/gpio/msc313-gpio.h ARM/NEC MOBILEPRO 900/c MACHINE SUPPORT
drivers/gpio/Kconfig +11 -0
@@ -737,6 +737,17 @@ config GPIO_AMD_FCH Note: This driver doesn't registers itself automatically, as it needs to be provided with platform specific configuration. (See eg. CONFIG_PCENGINES_APU2.) + +config GPIO_MSC313 + bool "MStar MSC313 GPIO support" + depends on ARCH_MSTARV7 + default ARCH_MSTARV7 + select GPIOLIB_IRQCHIP + select IRQ_DOMAIN_HIERARCHY + help + Say Y here to support the main GPIO block on MStar/SigmaStar + ARMv7 based SoCs. + endmenu menu "Port-mapped I/O GPIO drivers"
drivers/gpio/Makefile +1 -0
@@ -101,6 +101,7 @@ obj-$(CONFIG_GPIO_MOCKUP) += gpio-mockup.o obj-$(CONFIG_GPIO_MOXTET) += gpio-moxtet.o obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o +obj-$(CONFIG_GPIO_MSC313) += gpio-msc313.o obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o obj-$(CONFIG_GPIO_MT7621) += gpio-mt7621.o obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o
drivers/gpio/gpio-msc313.c new file +460 -0
460 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [PATCH v4 3/5] gpio: msc313: MStar MSC313 GPIO driver
Quoted 9 lines · Daniel Palmer
This adds a driver that supports the GPIO block found in MStar/SigmaStar ARMv7 SoCs.
The controller seems to have enough register for 128 lines but where they are wired up differs between chips and
no currently known chip uses anywhere near 128 lines so there needs to be some per-chip data to collect together what lines actually have physical pins attached and map the right names to them.
I took a closer look at the driver now, to figure out why this even needs a dt-bindings header in the first place. I noticed a few other things as well:
Quoted 38 lines
drivers/gpio/gpio-msc313.c new file +38
-0+#define OFF_SR_IO3 0x8c +#define OFF_SR_IO4 0x90 +#define OFF_SR_IO5 0x94 +#define OFF_SR_IO6 0x98 +#define OFF_SR_IO7 0x9c +#define OFF_SR_IO8 0xa0 +#define OFF_SR_IO9 0xa4 +#define OFF_SR_IO10 0xa8 +#define OFF_SR_IO11 0xac +#define OFF_SR_IO12 0xb0 +#define OFF_SR_IO13 0xb4 +#define OFF_SR_IO14 0xb8 +#define OFF_SR_IO15 0xbc +#define OFF_SR_IO16 0xc0 +#define OFF_SR_IO17 0xc4 + +#define SR_OFFSETS \ + OFF_SR_IO2, \ + OFF_SR_IO3, \ + OFF_SR_IO4, \ + OFF_SR_IO5, \ + OFF_SR_IO6, \ + OFF_SR_IO7, \ + OFF_SR_IO8, \ + OFF_SR_IO9, \ + OFF_SR_IO10, \ + OFF_SR_IO11, \ + OFF_SR_IO12, \ + OFF_SR_IO13, \ + OFF_SR_IO14, \ + OFF_SR_IO15, \ + OFF_SR_IO16, \ + OFF_SR_IO17 + +#define SD_NAMES \ + MSC313_PINNAME_SD_CLK, \ + MSC313_PINNAME_SD_CMD, \ + MSC313_PINNAME_SD_D0, \
drivers/gpio/gpio-msc313.c line 155
Quoted 10 lines
drivers/gpio/gpio-msc313.c new file +10
-0+MSC313_PINNAME_SD_D1 , \ +MSC313_PINNAME_SD_D2 , \ + MSC313_PINNAME_SD_D3 + +#define OFF_SD_CLK 0x140 +#define OFF_SD_CMD 0x144 +#define OFF_SD_D0 0x148 +#define OFF_SD_D1 0x14c +#define OFF_SD_D2 0x150 +#define OFF_SD_D3 0x154
These seem to just be contiguous ranges, so I probably would have suggested describing them as separate gpio controllers to avoid all the complexity with the names. As Linus already merged the driver into the gpio tree, I won't complain too much about it.
Maybe you can do that for the other chips though and have one implementation that works for all others, leaving only the msc313 as the one with the extra complexity.
drivers/gpio/gpio-msc313.c line 209
Quoted 11 lines
+#define
MSC313_GPIO_CHIPDATA(_chip)\
static const structmsc313_gpio_data_chip##_data = { \drivers/gpio/gpio-msc313.c new file +8
-0+ .names = _chip##_names, \ + .offsets = _chip##_offsets, \ + .num = ARRAY_SIZE(_chip##_offsets), \ +} +#ifdef CONFIG_MACH_INFINITY +static const char *const msc313_names[] = { +FUART_NAMES , + SR_NAMES,
I would try to avoid the #ifdefs and the macros here, don't overthink it. The macro really hurts readability with the ## concatenation making it impossible to grep for where things are defined, and the #ifdef means you get worse compile test coverage compared to an if(IS_ENABLED()) check in the place where the identifiers are actually used.
Even better would be to completely avoid the lookup tables here, and have one driver that is instantiated based on settings from the DT.
Quoted 8 lines
drivers/gpio/gpio-msc313.c new file +8
-0+struct msc313_gpio { +void __iomem *base; +const struct msc313_gpio_data *gpio_data; +u8 *saved; +}; + +static void msc313_gpio_set (struct gpio_chip *chip,unsigned int offset,int value) +{
drivers/gpio/gpio-msc313.c line 243
Quoted 10 lines
drivers/gpio/gpio-msc313.c new file +10
-0+struct msc313_gpio *gpio =gpiochip_get_data (chip); +u8 gpioreg =readb_relaxed (gpio->base + gpio->gpio_data->offsets[offset]); + +if (value) + gpioreg |=MSC313_GPIO_OUT ; +else + gpioreg &= ~MSC313_GPIO_OUT ; + +writeb_relaxed (gpioreg, gpio->base + gpio->gpio_data->offsets[offset]); +}
It would be helpful here to replace all the readb_relaxed/writeb_relaxed() with normal readb()/writeb(). Don't use _relaxed() unless there is a strong reason why you have to do it, and if you do, explain it in a comment what the reason is.
drivers/gpio/gpio-msc313.c line 273
Quoted 11 lines
drivers/gpio/gpio-msc313.c new file +11
-0+static int msc313_gpio_direction_output (struct gpio_chip *chip,unsigned int offset,int value) +{ +struct msc313_gpio *gpio =gpiochip_get_data (chip); +u8 gpioreg =readb_relaxed (gpio->base + gpio->gpio_data->offsets[offset]); + + gpioreg &= ~MSC313_GPIO_OEN ; +if (value) + gpioreg |=MSC313_GPIO_OUT ; +else + gpioreg &= ~MSC313_GPIO_OUT ; +writeb_relaxed (gpioreg, gpio->base + gpio->gpio_data->offsets[offset]);
These look like they also need a spinlock to avoid races between concurrent read-modify-write cycles on the same register.
Quoted 1 line
+builtin_platform_driver(msc313_gpio_driver);
There is a trend to make all drivers optionally loadable modules these days. Is there a reason this has to be built-in?
Arnd
Re: [PATCH v4 3/5] gpio: msc313: MStar MSC313 GPIO driver
Hi Arnd,
Quoted 8 lines · Arnd Bergmann
These seem to just be contiguous ranges, so I probably would have suggested describing them as separate gpio controllers to avoid all the complexity with the names. As Linus already merged the driver into the gpio tree, I won't complain too much about it.
Maybe you can do that for the other chips though and have one implementation that works for all others, leaving only the msc313 as the one with the extra complexity.
I'll have a think about that. The other chips I'm aiming to support (the mercury5 ssc8336 and infinity2m ssd202) currently reuse most of the msc313 bits with a few extras for the differences. i.e. the ssc8336 reuses most of the tables for the msc313 with some additions. Adding new chips hasn't been too bad so far.
Quoted 7 lines
Quoted 6 lines
+#define
MSC313_GPIO_CHIPDATA(_chip)\
static const structmsc313_gpio_data_chip##_data = { \drivers/gpio/gpio-msc313.c new file +4
-0+ .names = _chip##_names, \ + .offsets = _chip##_offsets, \ + .num = ARRAY_SIZE(_chip##_offsets), \ +}
Quoted 11 lines
drivers/gpio/gpio-msc313.c line 209
Quoted 4 lines
drivers/gpio/gpio-msc313.c new file +4
-0+#ifdef CONFIG_MACH_INFINITY +static const char *const msc313_names[] = { +FUART_NAMES , + SR_NAMES,I would try to avoid the #ifdefs and the macros here, don't overthink it. The macro really hurts readability with the ## concatenation making it impossible to grep for where things are defined, and the #ifdef means you get worse compile test coverage compared to an if(IS_ENABLED()) check in the place where the identifiers are actually used.
Ok. I was really just trying to enforce some sort of pattern there so that each chip that gets added follows the same convention.
Quoted 3 lines
Even better would be to completely avoid the lookup tables here, and have one driver that is instantiated based on settings from the DT.
I did think about this and I did this with the clk mux driver I haven't pushed yet. In that case there is a random lump of registers with some muxes mixed into it so I decided to make the lump a syscon and then have a node for each clk mux in the lump and some properties for the muxes within. The driver is certainly less complex but the device tree is pretty unmanageable as there are probably 30 or more muxes.
Quoted 9 lines
Quoted 9 lines
drivers/gpio/gpio-msc313.c new file +9
-0+static void msc313_gpio_set (struct gpio_chip *chip,unsigned int offset,int value) +{ +struct msc313_gpio *gpio =gpiochip_get_data (chip); +u8 gpioreg =readb_relaxed (gpio->base + gpio->gpio_data->offsets[offset]); + +if (value) + gpioreg |=MSC313_GPIO_OUT ; +else + gpioreg &= ~MSC313_GPIO_OUT ;
Quoted 8 lines
drivers/gpio/gpio-msc313.c line 243
Quoted 3 lines
drivers/gpio/gpio-msc313.c new file +3
-0+ +writeb_relaxed (gpioreg, gpio->base + gpio->gpio_data->offsets[offset]); +}It would be helpful here to replace all the readb_relaxed/writeb_relaxed() with normal readb()/writeb(). Don't use
_relaxed()unless there is a strong reason why you have to do it, and if you do, explain it in a comment what the reason is.
The reason is that readb()/writeb() will invoke the heavy memory barrier even though it's not needed for peripheral registers. I guess it doesn't actually make all that much difference in reality.
Quoted 6 lines
Quoted 6 lines
drivers/gpio/gpio-msc313.c new file +6
-0+static int msc313_gpio_direction_output (struct gpio_chip *chip,unsigned int offset,int value) +{ +struct msc313_gpio *gpio =gpiochip_get_data (chip); +u8 gpioreg =readb_relaxed (gpio->base + gpio->gpio_data->offsets[offset]); + + gpioreg &= ~MSC313_GPIO_OEN ;
Quoted 8 lines
drivers/gpio/gpio-msc313.c line 242
Quoted 5 lines
drivers/gpio/gpio-msc313.c new file +5
-0+if (value) + gpioreg |=MSC313_GPIO_OUT ; +else + gpioreg &= ~MSC313_GPIO_OUT ; +writeb_relaxed (gpioreg, gpio->base + gpio->gpio_data->offsets[offset]);These look like they also need a spinlock to avoid races between concurrent read-modify-write cycles on the same register.
Noted. I'll fix this and the readb and send a patch at some point.
Quoted 4 lines
Quoted 1 line
+builtin_platform_driver(msc313_gpio_driver);
There is a trend to make all drivers optionally loadable modules these days. Is there a reason this has to be built-in?
This was discussed and I think Linus said it was ok.
Thanks,
Daniel
Re: [PATCH v4 3/5] gpio: msc313: MStar MSC313 GPIO driver
Quoted 27 lines · Daniel Palmer
Quoted 7 lines · Arnd Bergmann
Quoted 6 lines
+#define
MSC313_GPIO_CHIPDATA(_chip)\
static const structmsc313_gpio_data_chip##_data = { \drivers/gpio/gpio-msc313.c new file +4
-0+ .names = _chip##_names, \ + .offsets = _chip##_offsets, \ + .num = ARRAY_SIZE(_chip##_offsets), \ +}Quoted 11 lines
drivers/gpio/gpio-msc313.c line 209
Quoted 4 lines
drivers/gpio/gpio-msc313.c new file +4
-0+#ifdef CONFIG_MACH_INFINITY +static const char *const msc313_names[] = { +FUART_NAMES , + SR_NAMES,I would try to avoid the #ifdefs and the macros here, don't overthink it. The macro really hurts readability with the ## concatenation making it impossible to grep for where things are defined, and the #ifdef means you get worse compile test coverage compared to an if(IS_ENABLED()) check in the place where the identifiers are actually used.
Ok. I was really just trying to enforce some sort of pattern there so that each chip that gets added follows the same convention.
Quoted 3 lines
Even better would be to completely avoid the lookup tables here, and have one driver that is instantiated based on settings from the DT.
Quoted 7 lines
I did think about this and I did this with the clk mux driver I haven't pushed yet. In that case there is a random lump of registers with some muxes mixed into it so I decided to make the lump a syscon and then have a node for each clk mux in the lump and some properties for the muxes within. The driver is certainly less complex but the device tree is pretty unmanageable as there are probably 30 or more muxes.
Right, for clk drivers, the trade-off is often different, it's not unusual that they are a bit of a mess and require a separate driver for each cheap.
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpio/gpio-msc313.c new file +9
-0+static void msc313_gpio_set (struct gpio_chip *chip,unsigned int offset,int value) +{ +struct msc313_gpio *gpio =gpiochip_get_data (chip); +u8 gpioreg =readb_relaxed (gpio->base + gpio->gpio_data->offsets[offset]); + +if (value) + gpioreg |=MSC313_GPIO_OUT ; +else + gpioreg &= ~MSC313_GPIO_OUT ;Quoted 8 lines
drivers/gpio/gpio-msc313.c line 243
Quoted 3 lines
drivers/gpio/gpio-msc313.c new file +3
-0+ +writeb_relaxed (gpioreg, gpio->base + gpio->gpio_data->offsets[offset]); +}It would be helpful here to replace all the readb_relaxed/writeb_relaxed() with normal readb()/writeb(). Don't use
_relaxed()unless there is a strong reason why you have to do it, and if you do, explain it in a comment what the reason is.
Quoted 3 lines
The reason is that readb()/writeb() will invoke the heavy memory barrier even though it's not needed for peripheral registers. I guess it doesn't actually make all that much difference in reality.
Ah, I forgot you had that heavy barrier. It depends a bit on what you use the GPIOs for then. For most uses I think the overhead does not matter, but if there is any bit-banged I/O it might make a difference.
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpio/gpio-msc313.c new file +6
-0+static int msc313_gpio_direction_output (struct gpio_chip *chip,unsigned int offset,int value) +{ +struct msc313_gpio *gpio =gpiochip_get_data (chip); +u8 gpioreg =readb_relaxed (gpio->base + gpio->gpio_data->offsets[offset]); + + gpioreg &= ~MSC313_GPIO_OEN ;Quoted 8 lines
drivers/gpio/gpio-msc313.c line 242
Quoted 5 lines
drivers/gpio/gpio-msc313.c new file +5
-0+if (value) + gpioreg |=MSC313_GPIO_OUT ; +else + gpioreg &= ~MSC313_GPIO_OUT ; +writeb_relaxed (gpioreg, gpio->base + gpio->gpio_data->offsets[offset]);These look like they also need a spinlock to avoid races between concurrent read-modify-write cycles on the same register.
Quoted 1 line
Noted. I'll fix this and the readb and send a patch at some point.
Ok
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+builtin_platform_driver(msc313_gpio_driver);
There is a trend to make all drivers optionally loadable modules these days. Is there a reason this has to be built-in?
This was discussed and I think Linus said it was ok.
Ok.
Arnd
Re: [PATCH v4 3/5] gpio: msc313: MStar MSC313 GPIO driver
Hi Arnd,
Quoted 11 lines · Arnd Bergmann
Quoted 7 lines
I did think about this and I did this with the clk mux driver I haven't pushed yet. In that case there is a random lump of registers with some muxes mixed into it so I decided to make the lump a syscon and then have a node for each clk mux in the lump and some properties for the muxes within. The driver is certainly less complex but the device tree is pretty unmanageable as there are probably 30 or more muxes.
Right, for clk drivers, the trade-off is often different, it's not unusual that they are a bit of a mess and require a separate driver for each cheap.
I will try to clean up the additions for the ssd202 (the smp enabled chip) this weekend and send a series for that.
If it still seems wrong after adding that I will can that series and refactor this before lumping more on top of it.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
It would be helpful here to replace all the readb_relaxed/writeb_relaxed() with normal readb()/writeb(). Don't use
_relaxed()unless there is a strong reason why you have to do it, and if you do, explain it in a comment what the reason is.
Quoted 7 lines
Quoted 3 lines
The reason is that readb()/writeb() will invoke the heavy memory barrier even though it's not needed for peripheral registers. I guess it doesn't actually make all that much difference in reality.
Ah, I forgot you had that heavy barrier. It depends a bit on what you use the GPIOs for then. For most uses I think the overhead does not matter, but if there is any bit-banged I/O it might make a difference.
Bit-banged buses are likely to happen I think as there is a lot of gpio compared to hardware peripherals.
Anyhow, I'll add a comment for the readb_relaxed()/writeb_relaxed() usage.
Cheers,
Daniel
Re: [PATCH v4 3/5] gpio: msc313: MStar MSC313 GPIO driver
Quoted 10 lines · Daniel Palmer
Quoted 9 lines · Arnd Bergmann
Quoted 8 lines
Quoted 4 lines
It would be helpful here to replace all the readb_relaxed/writeb_relaxed() with normal readb()/writeb(). Don't use
_relaxed()unless there is a strong reason why you have to do it, and if you do, explain it in a comment what the reason is.The reason is that readb()/writeb() will invoke the heavy memory barrier even though it's not needed for peripheral registers. I guess it doesn't actually make all that much difference in reality.
Quoted 7 lines
Quoted 3 lines
Ah, I forgot you had that heavy barrier. It depends a bit on what you use the GPIOs for then. For most uses I think the overhead does not matter, but if there is any bit-banged I/O it might make a difference.
Bit-banged buses are likely to happen I think as there is a lot of gpio compared to hardware peripherals.
Anyhow, I'll add a comment for the readb_relaxed()/writeb_relaxed() usage.
In that case, maybe add an abstraction for register access in an inline function that takes a pointer to your device-private data and the register offset, so you have a good place to describe it once.
Arnd
Re: [PATCH v4 3/5] gpio: msc313: MStar MSC313 GPIO driver
In reply to Daniel PalmerQuoted 23 lines · Daniel Palmer
This adds a driver that supports the GPIO block found in MStar/SigmaStar ARMv7 SoCs.
The controller seems to have enough register for 128 lines but where they are wired up differs between chips and
no currently known chip uses anywhere near 128 lines so there needs to be some per-chip data to collect together what lines actually have physical pins attached and map the right names to them.The core peripherals seem to use the same lines on the currently known chips but the lines used for the sensor interface, lcd controller etc pins seem to be totally different between the infinity and mercury chips
The code tries to collect all of the re-usable names, offsets etc together so that it's easy to build the extra per-chip data for other chips in the future.
So far this only supports the MSC313 and MSC313E chips.
Support for the SSC8336N (mercury5) is trivial to add once all of the lines have been mapped out.
...
drivers/gpio/gpio-msc313.c line 13
Quoted 7 lines
drivers/gpio/gpio-msc313.c new file +7
-0+#include <linux/io.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/of_irq.h> +#include <linux/gpio/driver.h> +#include <linux/module.h> +#include <linux/platform_device.h>
Perhaps ordered?
...
drivers/gpio/gpio-msc313.c line 328
Quoted 5 lines
drivers/gpio/gpio-msc313.c new file +5
-0+/* +* only the spi0 pins have interrupts on the parent +* on all of the known chips and so far they are all +* mapped to the same place +*/
You have a different comment style here (no capital letter, no period).
Quoted 1 line
+ if (offset >=
OFF_SPI0_CZ&& offset <=OFF_SPI0_DO) {
Why not traditional pattern, i.e.
if (...)
return -EINVAL;
...
?
Quoted 6 lines
drivers/gpio/gpio-msc313.c new file +6
-0+ *parent_type = child_type; + *parent = ((offset -OFF_SPI0_CZ ) >>2 ) +28 ; +return 0 ; + } + +return -EINVAL ;
...
drivers/gpio/gpio-msc313.c line 403
Quoted 2 lines
drivers/gpio/gpio-msc313.c new file +2
-0+ ret =devm_gpiochip_add_data (dev, gpiochip, gpio); +return ret;
Purpose?
return devm_...(...);
...
drivers/gpio/gpio-msc313.c line 409
Quoted 4 lines
drivers/gpio/gpio-msc313.c new file +4
-0+static int msc313_gpio_remove (struct platform_device *pdev) +{ +return 0 ; +}
Purpose?
...
drivers/gpio/gpio-msc313.c line 412
Quoted 3 lines
drivers/gpio/gpio-msc313.c new file +2
-0+static const struct of_device_id msc313_gpio_of_match[] = { +#ifdef CONFIG_MACH_INFINITY
What's the point? Are you expecting two drivers for the same IP?
Quoted 7 lines
drivers/gpio/gpio-msc313.c new file +7
-0+ { + .compatible = "mstar,msc313-gpio", + .data = &msc313_data, + }, +#endif + { } +};
...
drivers/gpio/gpio-msc313.c line 459
Quoted 11 lines
drivers/gpio/gpio-msc313.c new file +10
-0+static struct platform_driver msc313_gpio_driver = { + .driver = { + .name =DRIVER_NAME , + .of_match_table = msc313_gpio_of_match, + .pm = &msc313_gpio_ops, + }, + .probe = msc313_gpio_probe, + .remove = msc313_gpio_remove, +}; +
Redundant blank line.
Quoted 1 line
+builtin_platform_driver(msc313_gpio_driver);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 3/5] gpio: msc313: MStar MSC313 GPIO driver
Hi Andy,
Quoted 9 lines · Andy Shevchenko
drivers/gpio/gpio-msc313.c line 13
Quoted 7 lines
drivers/gpio/gpio-msc313.c new file +7
-0+#include <linux/io.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/of_irq.h> +#include <linux/gpio/driver.h> +#include <linux/module.h> +#include <linux/platform_device.h> Perhaps ordered?
Ok. I did try to find some rules on includes, mainly what should be included even though it's included in another include, but couldn't find anything really.
If you have a link that would be helpful. So I could track what includes I actually needed I went for order they are used in the code.
Quoted 7 lines
Quoted 1 line
+ if (offset >=
OFF_SPI0_CZ&& offset <=OFF_SPI0_DO) {Why not traditional pattern, i.e.
if (...)
return-EINVAL;
...
You mean check if the offset is not in the interrupt capable range, returning -EINVAL if so, and then having the interrupt mapping code?
Quoted 4 lines
drivers/gpio/gpio-msc313.c line 403
Quoted 2 lines
drivers/gpio/gpio-msc313.c new file +2
-0+ ret =devm_gpiochip_add_data (dev, gpiochip, gpio); +return ret;Purpose?
Sorry I think that is probably an artefact of splitting the driver apart to extract just the msc313 support.
The current version of this driver supports more chips but those aren't completely reverse engineered yet so I've been constantly switching back and forth.
Quoted 11 lines
return devm_...(...);
...
drivers/gpio/gpio-msc313.c line 409
Quoted 4 lines
drivers/gpio/gpio-msc313.c new file +4
-0+static int msc313_gpio_remove (struct platform_device *pdev) +{ +return 0 ; +}Purpose?
None that I can think of. I think I was under the impression that a remove callback was needed even if it did nothing.
Quoted 6 lines
drivers/gpio/gpio-msc313.c line 412
Quoted 4 lines
drivers/gpio/gpio-msc313.c new file +2
-0+static const struct of_device_id msc313_gpio_of_match[] = { +#ifdef CONFIG_MACH_INFINITYWhat's the point? Are you expecting two drivers for the same IP?
This will make more sense when the support for CONFIG_MACH_MERCURY is added. infinity and mercury are very very close but have slightly different pinouts, slightly different tables for clks, pin mux etc.
These chips only have 64MB of DRAM and it's embedded into the chip so you probably don't want to include all the baggage for the whole family in your kernel if you possibly can. Also the kernel only has a few megabytes to fit into on the SPI NOR it's loaded from. Something similar is going on for the ingenic pinctrl and I thought maybe wrapping of_device_ids in #ifdefs was a no no and asked [0]. Arguably this is "peeing into the ocean" for a driver like this because the difference is going to be tiny but I think I'm probably tens of kilobytes away from my kernel not fitting anymore :).
Quoted 10 lines
Quoted 7 lines
drivers/gpio/gpio-msc313.c new file +7
-0+ { + .compatible = "mstar,msc313-gpio", + .data = &msc313_data, + }, +#endif + { } +};...
Quoted 9 lines
drivers/gpio/gpio-msc313.c line 458
Quoted 9 lines
drivers/gpio/gpio-msc313.c new file +9
-0+static struct platform_driver msc313_gpio_driver = { + .driver = { + .name =DRIVER_NAME , + .of_match_table = msc313_gpio_of_match, + .pm = &msc313_gpio_ops, + }, + .probe = msc313_gpio_probe, + .remove = msc313_gpio_remove, +};
For the fixes to the above should I send another series just to fix these up or can it wait a little while?
I'm pretty close to having all of the registers mapped out for another chip that'll go into this driver so I could send these small changes as part of that series.
Thanks,
Daniel
PATCH v4 4/5 ARM: mstar: Add gpio controller to MStar base dtsi
In reply to Daniel PalmerThe GPIO controller is at the same address in all of the currently known chips so create a node for it in the base dtsi.
Some extra properties are needed to actually use it so disable it by default.
--- arch/arm/boot/dts/mstar-v7.dtsi | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm/boot/dts/mstar-v7.dtsi +10 -0
@@ -109,6 +109,16 @@ l3bridge: l3bridge@204400 { reg = <0x204400 0x200>; }; + gpio: gpio@207800 { + #gpio-cells = <2>; + reg = <0x207800 0x200>; + gpio-controller; + #interrupt-cells = <2>; + interrupt-controller; + interrupt-parent = <&intc_fiq>; + status = "disabled"; + }; + pm_uart: uart@221000 { compatible = "ns16550a"; reg = <0x221000 0x100>;
Signature · 1 line
2.29.2
PATCH v4 5/5 ARM: mstar: Fill in GPIO controller properties for infinity
In reply to Daniel PalmerFill in the properties needed to use the GPIO controller in the infinity and infinity3 chips.
--- arch/arm/boot/dts/mstar-infinity.dtsi | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm/boot/dts/mstar-infinity.dtsi +7 -0
@@ -6,6 +6,13 @@ #include "mstar-v7.dtsi" +#include <dt-bindings/gpio/msc313-gpio.h> + &imi { reg = <0xa0000000 0x16000>; }; + +&gpio { + compatible = "mstar,msc313-gpio"; + status = "okay"; +};
Signature · 1 line
2.29.2
Quoted 7 lines · Daniel Palmer
At the moment the MStar/SigmaStar support is only really capable of shell from an initramfs and not much else.
Most of the interesting drivers are blocked on clock and pinctrl drivers and those are going to take me a little while to get cleaned up.
Quoted 7 lines
Clock and pinctrl aren't needed for basic GPIO to work (all pins start off as GPIOs..) and it makes it possible to actually do something so this series adds everything that is needed for the main GPIO block in these chips.
Changes since v3:
- Remove unneeded "gpio-ranges-group-names" property from binding yaml.
OK finished!
Patches 1, 2 & 3 applied to the GPIO tree for v5.11.
Thanks for the good work!
Yours,
Linus Walleij
Hi Linus,
Quoted 2 lines · Linus Walleij
OK finished!
Patches 1, 2 & 3 applied to the GPIO tree for v5.11.
Awesome! Thank you Linus. :)
Arnd and Olof: Sorry for being a noob.. Is there anything I need to do for patches 4 and 5 (device tree bits)?
They are in the Linux SoC patchwork.
Thanks,
Daniel
Quoted 5 lines · Daniel Palmer
Hi Linus,
On Sun, 6 Dec 2020 at 06:43, Linus Walleij <[email protected]> wrote:
Quoted 8 lines
Quoted 2 lines
OK finished!
Patches 1, 2 & 3 applied to the GPIO tree for v5.11.Awesome! Thank you Linus. :)
Arnd and Olof: Sorry for being a noob.. Is there anything I need to do for patches 4 and 5 (device tree bits)?
They are in the Linux SoC patchwork.
I've picked them up from there along with the second series of DT changes.
The easiest way for me though is if you include the patches in a pull request or patch series that can go through the soc tree in one chunk.
Arnd
Quoted 10 lines · Arnd Bergmann
Quoted 8 lines · Daniel Palmer
Hi Linus,
Quoted 2 lines · Linus Walleij
OK finished!
Patches 1, 2 & 3 applied to the GPIO tree for v5.11.
Quoted 7 lines
Quoted 5 lines
Awesome! Thank you Linus. :)
Arnd and Olof: Sorry for being a noob.. Is there anything I need to do for patches 4 and 5 (device tree bits)?
They are in the Linux SoC patchwork.I've picked them up from there along with the second series of DT changes.
And I made a mess, as I had not realized that the DT patches depend on the dt-binding header. I've applied that patch on top now to make my branch build cleanly again, even though it is not fully bisectable.
Arnd
Arnd Bergmann
AppliedFrom: Arnd Bergmann <[email protected]>
Quoted 8 lines · Daniel Palmer
At the moment the MStar/SigmaStar support is only really capable of shell from an initramfs and not much else.
Most of the interesting drivers are blocked on clock and pinctrl drivers and those are going to take me a little while to get cleaned up.
[...]
Applied to arm/dt, thanks!
[4/5] ARM: mstar: Add gpio controller to MStar base dtsi
commit: 74530d645126c2934b16db135edaef16eff9e35b
[5/5] ARM: mstar: Fill in GPIO controller properties for infinity
commit: 5b8a05b9e8d10c8df29bb719e73ea8ed916a1eea
Arnd