Skip to contentSkip to conversation

spi: bcm2835: add spi-bcm2835aux driver for the auxiliar spi1 and spi2

PATCH Superseded [email protected] 6 participants 37 messages Jun 22, 2015 – Aug 1, 2015 27 messages not in the archive

Subsystems (8)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 spi: bcm2835: add spi-bcm2835aux driver for the auxiliar spi1 and spi2

From: Martin Sperl <[email protected]>

This driver does NOT make use of native chip-selects but uses the generic cs-gpios facilities provided by the framework allowing for more than 3 chip-selects.

---
 drivers/spi/Kconfig          |   10 +
 drivers/spi/Makefile         |    1 +
 drivers/spi/spi-bcm2835aux.c |  549 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 560 insertions(+)
 create mode 100644 drivers/spi/spi-bcm2835aux.c

Only tested spi1, as no Compute Module is available to me to test spi2.

Also note that the driver currently implements locking of the auxiliar device enable bits inside the driver. This is shared with the uart1, for which we have so far no driver. Ideally this should get moved out as soon as we get the uart1 driver enabled.

Uart1 is also only accessible on the Compute Module.

drivers/spi/Kconfig +10 -0
index 0cae169..270445c 100644
@@ -88,6 +88,16 @@ config SPI_BCM2835
 	  is for the regular SPI controller. Slave mode operation is not also
 	  not supported.
 
+config SPI_BCM2835AUX
+	tristate "BCM2835 SPI auxiliar controller"
+	depends on ARCH_BCM2835 || COMPILE_TEST
+	help
+	  This selects a driver for the Broadcom BCM2835 SPI aux master.
+
+	  The BCM2835 contains two types of SPI master controller; the
+	  "universal SPI master", and the regular SPI controller. This driver
+	  is for the universal/auxiliar SPI controller.
+
 config SPI_BFIN5XX
 	tristate "SPI controller driver for ADI Blackfin5xx"
 	depends on BLACKFIN && !BF60x
drivers/spi/Makefile +1 -0
index 1154dba..eed9614 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_SPI_ATMEL)			+= spi-atmel.o
 obj-$(CONFIG_SPI_ATH79)			+= spi-ath79.o
 obj-$(CONFIG_SPI_AU1550)		+= spi-au1550.o
 obj-$(CONFIG_SPI_BCM2835)		+= spi-bcm2835.o
+obj-$(CONFIG_SPI_BCM2835AUX)		+= spi-bcm2835aux.o
 obj-$(CONFIG_SPI_BCM53XX)		+= spi-bcm53xx.o
 obj-$(CONFIG_SPI_BCM63XX)		+= spi-bcm63xx.o
 obj-$(CONFIG_SPI_BCM63XX_HSSPI)		+= spi-bcm63xx-hsspi.o
drivers/spi/spi-bcm2835aux.c new file +549 -0

549 lines not on this page · raw message

Signature · 4 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in

A message that is not in the archive (sent off-list or not yet received): 1434980408-4086-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#2 lore raw

PATCH 2/2 dt: brcm,bcm2835-aux-spi: add binding documentation for new spi-bcm2835aux

From: Martin Sperl <[email protected]>

---
 .../bindings/spi/brcm,bcm2835-aux-spi.txt          |   33 ++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/brcm,bcm2835-aux-spi.txt
Documentation/devicetree/bindings/spi/brcm,bcm2835-aux-spi.txt new file +33 -0
new file mode 100644
index 0000000..23e4138
@@ -0,0 +1,33 @@
+Broadcom BCM2835 SPI1/2 controller
+
+The BCM2835 contains two forms of SPI master controller, one known simply as
+SPI0, and the other known as the "Universal SPI Master"; part of the
+auxiliary block. This binding applies to the SPI1/2 controller.
+
+Required properties:
+- compatible: Should be "brcm,bcm2835-aux-spi".
+- reg: Should contain register location and length for the spi block
+       as well as for the common aux block control
+- interrupts: Should contain shared interrupt of the aux block
+- clocks: The clock feeding the SPI controller.
+- gpio-cs: the gpio-cs (native cs is NOT supported)
+
+Example:
+
+spi1@7e215080 {
+	compatible = "brcm,bcm2835-aux-spi";
+	reg = <0x7e215080 0x40>, <0x7e215000 0x08>;
+	interrupts = <1 29>;
+	clocks = <&clk_spi>;
+	#address-cells = <1>;
+	#size-cells = <0>;
+};
+
+spi2@7e215080 {
+	compatible = "brcm,bcm2835-aux-spi";
+	reg = <0x7e2150c0 0x40>, <0x7e215000 0x08>;
+	interrupts = <1 29>;
+	clocks = <&clk_spi>;
+	#address-cells = <1>;
+	#size-cells = <0>;
+};
Signature · 4 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in

A message that is not in the archive (sent off-list or not yet received): 1434980408-4086-2-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#4 lore raw

Re: [PATCH 2/2] dt: brcm, bcm2835-aux-spi: add binding documentation for new spi-bcm2835aux

Hi Martin,

Am 22.06.2015 um 15:40 schrieb [email protected]:

Quoted 17 lines

From: Martin Sperl <[email protected]>

---
  .../bindings/spi/brcm,bcm2835-aux-spi.txt          |   33 ++++++++++++++++++++
  1 file changed, 33 insertions(+)

create mode 100644 Documentation/devicetree/bindings/spi/brcm,bcm2835-aux-spi.txt

Documentation/devicetree/bindings/spi/brcm,bcm2835-aux-spi.txt new file +3 -0
new file mode 100644
index 0000000..23e4138
@@ -0,0 +1,33 @@
+Broadcom BCM2835 SPI1/2 controller
+
+The BCM2835 contains two forms of SPI master controller, one known simply as

Documentation/devicetree/bindings/spi/brcm,bcm2835-aux-spi.txt line 13

Quoted 10 lines
Documentation/devicetree/bindings/spi/brcm,bcm2835-aux-spi.txt new file +10 -0
+SPI0, and the other known as the "Universal SPI Master"; part of the
+auxiliary block. This binding applies to the SPI1/2 controller.
+
+Required properties:
+- compatible: Should be "brcm,bcm2835-aux-spi".
+- reg: Should contain register location and length for the spi block
+       as well as for the common aux block control
+- interrupts: Should contain shared interrupt of the aux block
+- clocks: The clock feeding the SPI controller.
+- gpio-cs: the gpio-cs (native cs is NOT supported)

do you mean "gpio-cs" or "cs-gpios" from spi/spi-bus.txt?

Documentation/devicetree/bindings/spi/brcm,bcm2835-aux-spi.txt line 23

Quoted 10 lines
Documentation/devicetree/bindings/spi/brcm,bcm2835-aux-spi.txt new file +10 -0
+
+Example:
+
+spi1@7e215080 {
+	compatible = "brcm,bcm2835-aux-spi";
+	reg = <0x7e215080 0x40>, <0x7e215000 0x08>;
+	interrupts = <1 29>;
+	clocks = <&clk_spi>;
+	#address-cells = <1>;
+	#size-cells = <0>;

Why is gpio-cs is missing in the examples, if it's required?

Documentation/devicetree/bindings/spi/brcm,bcm2835-aux-spi.txt line 26

Quoted 3 lines
Documentation/devicetree/bindings/spi/brcm,bcm2835-aux-spi.txt new file +3 -0
+};
+
+spi2@7e215080 {

spi2@7e2150c0 ?

Documentation/devicetree/bindings/spi/brcm,bcm2835-aux-spi.txt line 33

Quoted 8 lines
Documentation/devicetree/bindings/spi/brcm,bcm2835-aux-spi.txt new file +7 -0
+	compatible = "brcm,bcm2835-aux-spi";
+	reg = <0x7e2150c0 0x40>, <0x7e215000 0x08>;
+	interrupts = <1 29>;
+	clocks = <&clk_spi>;
+	#address-cells = <1>;
+	#size-cells = <0>;
+};

Regards
Stefan
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [PATCH 2/2] dt: brcm, bcm2835-aux-spi: add binding documentation for new spi-bcm2835aux

Quoted 3 lines · Stefan Wahren

do you mean "gpio-cs" or "cs-gpios" from spi/spi-bus.txt?

...

Quoted 1 line

Why is gpio-cs is missing in the examples, if it's required?

...

Quoted 1 line

spi2@7e2150c0 ?

Shall fix that in the next version.

Martin

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in

#7 lore raw
In reply to a message not in the archive

Den 22.06.2015 15:40, skrev [email protected]:

Quoted 15 lines

From: Martin Sperl <[email protected]>

This driver does NOT make use of native chip-selects but uses the generic cs-gpios facilities provided by the framework allowing for more than 3 chip-selects.

---
  drivers/spi/Kconfig          |   10 +
  drivers/spi/Makefile         |    1 +
  drivers/spi/spi-bcm2835aux.c |  549 ++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 560 insertions(+)

create mode 100644 drivers/spi/spi-bcm2835aux.c

Quoted 8 lines

Only tested spi1, as no Compute Module is available to me to test spi2.

Also note that the driver currently implements locking of the auxiliar device enable bits inside the driver. This is shared with the uart1, for which we have so far no driver. Ideally this should get moved out as soon as we get the uart1 driver enabled.

Uart1 is also only accessible on the Compute Module.

Uart1 is available on the uart0 pins (alt5) and the 8250 driver can be used (ns16550 compatible).
See: https://github.com/raspberrypi/linux/pull/1008

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in

#8 lore raw
In reply to a message not in the archive
Quoted 4 lines · On Mon, 22 Jun 2015 13:40:06 +0000, [email protected].…

Also note that the driver currently implements locking of the auxiliar device enable bits inside the driver. This is shared with the uart1, for which we have so far no driver. Ideally this should get moved out as soon as we get the uart1 driver enabled.

As mentioned by Noralf UART1 is quite commonly used on Compute Modules. Proper driver - perhaps modelled as a bus - seems like a prerequisite for this work. You are also not using IRQ mux in DT binding example which is very misleading.

Do we have any indication weather this AUX hardware is available on RPi2 as well? IIRC bcm2836 differs only in CPU cores, peripherals remain identical. Perhaps this driver could be used on RPi2 and naming it 283x would be more appropriate?
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in

#9 lore raw
Quoted 6 lines · Jakub Kiciński

As mentioned by Noralf UART1 is quite commonly used on Compute Modules. Proper driver - perhaps modelled as a bus - seems like a prerequisite for this work. You are also not using IRQ mux in DT binding example which is very misleading.

Well - there is no support far for uart1 in upstream as of now. And I am not even sure if the compute module is supported as there is no device tree available in upstream for that...

So I have taken the simple route of using shared interrupts and providing a minimal framework to enable the spi1/spi2 hw blocks with proper locking. And I have mentioned that it would need to get modified when uart1 support comes along.

If you know of a better solution how to control this and that also incorporates a patch to enable uart1, then please share it!

Just modify the bcm2835aux_spi_enable/disable to use a different framework than just bcm2835_aux_modify_enable.

The patch Noralf mentions only applies downstream and only sets the enable-register during the boot sequence, so it would not impact the solution as is.

Quoted 4 lines

Do we have any indication weather this AUX hardware is available on RPi2 as well? IIRC bcm2836 differs only in CPU cores, peripherals remain identical. Perhaps this driver could be used on RPi2 and naming it 283x would be more appropriate?

I have not checked, but I would guess that it exists.

As for naming: I have asked around and bcm2835aux seemed fine. Also if we go that route we should start renaming ALL driver instances that contain 2835.--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in

A message that is not in the archive (sent off-list or not yet received): E72B3D8C-EA1B-4B4C-8EAF-C14A5631882E-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#11 lore raw

So what does it require to get this merged?

Rename of the module?

Thanks

Quoted 33 lines · Martin Sperl
Quoted 7 lines · Jakub Kiciński

As mentioned by Noralf UART1 is quite commonly used on Compute Modules. Proper driver - perhaps modelled as a bus - seems like a prerequisite for this work. You are also not using IRQ mux in DT binding example which is very misleading.

Well - there is no support far for uart1 in upstream as of now. And I am not even sure if the compute module is supported as there is no device tree available in upstream for that...

So I have taken the simple route of using shared interrupts and providing a minimal framework to enable the spi1/spi2 hw blocks with proper locking. And I have mentioned that it would need to get modified when uart1 support comes along.

If you know of a better solution how to control this and that also incorporates a patch to enable uart1, then please share it!

Just modify the bcm2835aux_spi_enable/disable to use a different framework than just bcm2835_aux_modify_enable.

The patch Noralf mentions only applies downstream and only sets the enable-register during the boot sequence, so it would not impact the solution as is.

Quoted 4 lines

Do we have any indication weather this AUX hardware is available on RPi2 as well? IIRC bcm2836 differs only in CPU cores, peripherals remain identical. Perhaps this driver could be used on RPi2 and naming it 283x would be more appropriate?

Quoted 5 lines

I have not checked, but I would guess that it exists.

As for naming: I have asked around and bcm2835aux seemed fine. Also if we go that route we should start renaming ALL driver instances that contain 2835.

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 97C7561C-6D67-4F51-94BB-3B8D401D77A0-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#13 lore raw
Quoted 1 line · Martin Sperl

So what does it require to get this merged?

Don't top post.

This looks relevant:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Jakub Kiciński

As mentioned by Noralf UART1 is quite commonly used on Compute Modules. Proper driver - perhaps modelled as a bus - seems like a prerequisite for this work. You are also not using IRQ mux in DT binding example which is very misleading.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#15 lore raw
Quoted 10 lines · Mark Brown

This looks relevant:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Jakub Kiciński

As mentioned by Noralf UART1 is quite commonly used on Compute Modules. Proper driver - perhaps modelled as a bus - seems like a prerequisite for this work. You are also not using IRQ mux in DT binding example which is very misleading.

Well, we are using shared interrupts, which is typical for other drivers on the rpi as well - i2c and usb are examples for multiple handlers on a single irq line on the rpi - excerpt from /proc/interrupts:
CPU0

33: 3547607286  ARMCTRL-level  41 Edge      20980000.usb, dwc2_hsotg:usb1
77:          0  ARMCTRL-level  85 Edge      20205000.i2c, 20804000.i2c

The compute module is not supported upstream and nobody created any patches for a device tree for a cm...

On top there is no direct support for uart1 in the upstream kernel.

Support only exists in the foundation kernel where the implementation enables the uart1 in the board-config directly, so that uart1 can also get used as the console during boot.

This means (as far as I understand) that there can be no race-condition, as spi would get configured later during boot and the access to the enable register is then properly protected against concurrent access when enabling both auxiliar spi devices (and spi2 is only usable on the compute Module - see above for upstream support of the cm)

Finally asking for a recommendation with regards to using a bus to arbitrate access to the enable register there was no feedback how this could be get implemented...

This last piece is actually one of the last reasons why I have not posted a patch for spi1 and spi2 to the default device-trees for the rpi models yet.
(That and the fact that assigning pins in multiple pinctrl groups
- i2s and spi1 - gives warnings or errors in dmesg, because i2s is also requiring Gpio 18, 19, 20 and 21 on the model-b-plus device tree - so it can only be either/or not both...)

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 6A2CCE70-5DAF-4E86-A0A4-F5E93FD1B540-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#17 lore raw

Den 01.07.2015 21:39, skrev Martin Sperl:

Quoted 9 lines
Quoted 9 lines · Mark Brown

This looks relevant:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Jakub Kiciński

As mentioned by Noralf UART1 is quite commonly used on Compute Modules. Proper driver - perhaps modelled as a bus - seems like a prerequisite for this work. You are also not using IRQ mux in DT binding example which is very misleading.

[...]

Quoted 3 lines

Finally asking for a recommendation with regards to using a bus to arbitrate access to the enable register there was no feedback how this could be get implemented...

Maybe you can use drivers/mfd/syscon.c to enable shared access to the aux enable register. Then the spi driver could get the regmap with:
aux_regmap = syscon_regmap_lookup_by_phandle(np, "syscon");

aux_syscon: aux_syscon@7e215000 {
compatible = "syscon";
reg = <0x7e215000 0x08>;
};

spi2@7e2150c0 {
compatible = "brcm,bcm2835-aux-spi";
reg = <0x7e2150c0 0x40>;
syscon = <&aux_syscon>;
};

So if someone later will add a Pi extension to the 8250 serial driver or enable the mini uart by some other means, they can use the syscon regmap.

About sharing the aux interrupt, could this be implemented in irq-bcm2835 as a Bank 3?

spi1@7e215080 {
compatible = "brcm,bcm2835-aux-spi";
reg = <0x7e215080 0x40>, <0x7e215000 0x08>;
interrupts = <3 1>;
};

spi2@7e2150c0 {
compatible = "brcm,bcm2835-aux-spi";
reg = <0x7e2150c0 0x40>, <0x7e215000 0x08>;
interrupts = <3 2>;
};

These are just a suggestions, I don't know if it is "the correct" way to do it.

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw
Quoted 17 lines · Noralf Trønnes

Den 01.07.2015 21:39, skrev Martin Sperl:

Quoted 9 lines
Quoted 9 lines · Mark Brown

This looks relevant:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Jakub Kiciński

As mentioned by Noralf UART1 is quite commonly used on Compute Modules. Proper driver - perhaps modelled as a bus - seems like a prerequisite for this work. You are also not using IRQ mux in DT binding example which is very misleading.

[...]

Quoted 7 lines
Quoted 3 lines

Finally asking for a recommendation with regards to using a bus to arbitrate access to the enable register there was no feedback how this could be get implemented...

Maybe you can use drivers/mfd/syscon.c to enable shared access to the aux enable register. Then the spi driver could get the regmap with:
aux_regmap = syscon_regmap_lookup_by_phandle(np, "syscon");

Seems as if you found an answer to my original question of if there is a framework to handle this.

Quoted 2 lines

About sharing the aux interrupt, could this be implemented in irq-bcm2835 as a Bank 3?

Obviously it could, but the question is if it is not more overhead than using a shared interrupt (requesting an interrupt with the shared flag set) in the first place (like this driver currently does or i2c and USB do).

I am working on a new version to make use of syscon.

Thanks, Martin

_______________________________________________
linux-rpi-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rpi-kernel

A message that is not in the archive (sent off-list or not yet received): 1400E1A3-43E1-4D0E-A54D-E5D668A4C516-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#21 lore raw

Den 05.07.2015 03:14, skrev Martin Sperl:

Quoted 13 lines
Quoted 13 lines · Noralf Trønnes

Den 01.07.2015 21:39, skrev Martin Sperl:

Quoted 9 lines
Quoted 9 lines · Mark Brown

This looks relevant:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Jakub Kiciński

As mentioned by Noralf UART1 is quite commonly used on Compute Modules. Proper driver - perhaps modelled as a bus - seems like a prerequisite for this work. You are also not using IRQ mux in DT binding example which is very misleading.

[...]

Quoted 5 lines
Quoted 2 lines

About sharing the aux interrupt, could this be implemented in irq-bcm2835 as a Bank 3?

Obviously it could, but the question is if it is not more overhead than using a shared interrupt (requesting an interrupt with the shared flag set) in the first place (like this driver currently does or i2c and USB do).

I have looked closer at the 8250 serial driver, and in fact it has a framework for writing 8250 like drivers. This makes it easy to extend it to include support for the mini uart. drivers/tty/serial/8250/8250_dw.c is an example of a driver that overrides the interrupt handler. So a 8250_bcm2835.c can easily be made with interrupt sharing as you suggest (and aux enabling). But this means that the irq status register has to be included in the syscon regmap as well.

Noralf.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#23 lore raw
Quoted 11 lines · Noralf Trønnes

I have looked closer at the 8250 serial driver, and in fact it has a framework for writing 8250 like drivers. This makes it easy to extend it to include support for the mini uart. drivers/tty/serial/8250/8250_dw.c is an example of a driver that overrides the interrupt handler. So a 8250_bcm2835.c can easily be made with interrupt sharing as you suggest (and aux enabling). But this means that the irq status register has to be included in the syscon regmap as well.

With the Module parameter share_irqs=1 the stock 8250 driver will request a shared irq, but you can also control it via:
CONFIG_SERIAL_8250_SHARE_IRQ

As for regmap support - the driver only uses the status register of the uart so it does not need access to the shared interrupt flag register. (If no irq condition is detected then IRQ_NoNE is returned and the Shared irq system will call the next irq handler in the list)

So all that is left to do is enabling the uart device in the aux-enable registers using regmap and then the uart can get used.

Martin--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#24 lore raw
In reply to a message not in the archive
Quoted 21 lines · Martin Sperl
Quoted 21 lines · Noralf Trønnes

Den 01.07.2015 21:39, skrev Martin Sperl:

Quoted 9 lines
Quoted 9 lines · Mark Brown

This looks relevant:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Jakub Kiciński

As mentioned by Noralf UART1 is quite commonly used on Compute Modules. Proper driver - perhaps modelled as a bus - seems like a prerequisite for this work. You are also not using IRQ mux in DT binding example which is very misleading.

[...]

Quoted 3 lines

Finally asking for a recommendation with regards to using a bus to arbitrate access to the enable register there was no feedback how this could be get implemented...

Quoted 6 lines
Quoted 3 lines

Maybe you can use drivers/mfd/syscon.c to enable shared access to the aux enable register. Then the spi driver could get the regmap with:
aux_regmap = syscon_regmap_lookup_by_phandle(np, "syscon");

Seems as if you found an answer to my original question of if there is a framework to handle this.

I'd suggest avoiding syscon. IIUC, it just exposes raw register IO for the shared register region, which is very "non-semantic", hence completely hides what the reason the registers are being touched. I'd much prefer a custom driver with use-case-specific APIs. If the registers implement an IRQ mux/demux, an explicit IRQ controller driver would be much better.

Quoted 6 lines
Quoted 2 lines

About sharing the aux interrupt, could this be implemented in irq-bcm2835 as a Bank 3?

Obviously it could, but the question is if it is not more overhead than using a shared interrupt (requesting an interrupt with the shared flag set) in the first place (like this driver currently does or i2c and USB do).

IIUC, these registers aren't part of the main IRQ controller's register set, and hence shouldn't be touched by the main IRQ controller driver. Create a separate driver for entirely separate HW blocks/functionality/...

Quoted 1 line

I am working on a new version to make use of syscon.

:-(

_______________________________________________
linux-rpi-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rpi-kernel

#25 lore raw
In reply to a message not in the archive
Quoted 9 lines · Martin Sperl
Quoted 5 lines · Jakub Kiciński

As mentioned by Noralf UART1 is quite commonly used on Compute Modules. Proper driver - perhaps modelled as a bus - seems like a prerequisite for this work. You are also not using IRQ mux in DT binding example which is very misleading.

Well - there is no support far for uart1 in upstream as of now. And I am not even sure if the compute module is supported as there is no device tree available in upstream for that...

IIRC I've run the CM with the RPi B DT. I've been meaning to upstream explicit DTs for all the various RPi models, but haven't manage to get around to that yet.

Quoted 7 lines

So I have taken the simple route of using shared interrupts and providing a minimal framework to enable the spi1/spi2 hw blocks with proper locking. And I have mentioned that it would need to get modified when uart1 support comes along.

If you know of a better solution how to control this and that also incorporates a patch to enable uart1, then please share it!

I haven't looked at the registers to be sure of the structure and hence if this is good advice, but creating an IRQ controller driver for the aux registers (as Mark intimated) sounds like a good idea.

Quoted 12 lines

Just modify the bcm2835aux_spi_enable/disable to use a different framework than just bcm2835_aux_modify_enable.

The patch Noralf mentions only applies downstream and only sets the enable-register during the boot sequence, so it would not impact the solution as is.

Quoted 4 lines

Do we have any indication weather this AUX hardware is available on RPi2 as well? IIRC bcm2836 differs only in CPU cores, peripherals remain identical. Perhaps this driver could be used on RPi2 and naming it 283x would be more appropriate?

Quoted 5 lines

I have not checked, but I would guess that it exists.

As for naming: I have asked around and bcm2835aux seemed fine. Also if we go that route we should start renaming ALL driver instances that contain 2835.

I'd suggest leaving named after the "first" chip the driver supports, in a similar fashion to how DT compatible values work. There's zero benefit from renaming existing drivers, and having new drivers continue with the existing naming convention would leave everything nice and consistent.

_______________________________________________
linux-rpi-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rpi-kernel

#26 lore raw
In reply to a message not in the archive
Quoted 7 lines · On 06/22/2015 07:40 AM, [email protected] wrote:

From: Martin Sperl <[email protected]>

This driver does NOT make use of native chip-selects but uses the generic cs-gpios facilities provided by the framework allowing for more than 3 chip-selects.

drivers/spi/spi-bcm2835aux.c line 63

Quoted 10 lines
drivers/spi/spi-bcm2835aux.c +9 -0
 
+/*
+ * spi register defines
+ *
+ * note there is garbage in the "official" documentation,
+ * so somedata taken from the file:
+ *   brcm_usrlib/dag/vmcsx/vcinclude/bcm2708_chip/aux_io.h
+ * inside of:
+ *   http://www.broadcom.com/docs/support/videocore/Brcm_Android_ICS_Graphics_Stack.tar.gz
+ */

Hopefully the license of that tar file allows for that. I didn't look.

Quoted 6 lines
drivers/spi/spi-bcm2835aux.c +6 -0
+DEFINE_SPINLOCK(__bcm2835_aux_lock);
+static void bcm2835_aux_modify_enable(struct bcm2835aux_spi *bs,
+				      u32 mask, u32 val)
+{
+	unsigned long flags;
+	u32 r;

drivers/spi/spi-bcm2835aux.c line 147

Quoted 10 lines
drivers/spi/spi-bcm2835aux.c +10 -0
+
+	spin_lock_irqsave(&__bcm2835_aux_lock, flags);
+
+	r = readl(bs->aux_regs + BCM2835_AUX_ENABLE);
+	r &= mask;
+	r |= val;
+	writel(r, bs->aux_regs + BCM2835_AUX_ENABLE);
+
+	spin_unlock_irqrestore(&__bcm2835_aux_lock, flags);
+}

As mentioned elsewhere, I'd hope all the shared aux register manipulations can be pushed into a shared driver.

drivers/spi/spi-bcm2835aux.c line 156

Quoted 8 lines
drivers/spi/spi-bcm2835aux.c +8 -0
+static void bcm2835aux_spi_enable(struct bcm2835aux_spi *bs)
+{
+	/* identify the spi device - needed to activate the right HW-block */
+	u32 mask = (size_t)bs->regs & 0x00000040 ?
+		   BCM2835_AUX_BIT_SPI2 : BCM2835_AUX_BIT_SPI1;
+
+	bcm2835_aux_modify_enable(bs, ~mask, mask);
+}

I expect that function will go away when my previous comment is resolved. If not, it'd be nice to encode the "ID" of the device into DT, so that the driver has no hard-coded idea of what register addresses exist; what happens when (a hypothetical) bcm2837 comes along with 3 instances of this HW block?

drivers/spi/spi-bcm2835aux.c line 521

Quoted 7 lines
drivers/spi/spi-bcm2835aux.c +7 -0
+static int bcm2835aux_spi_remove(struct platform_device *pdev)
+{
+	struct spi_master *master = platform_get_drvdata(pdev);
+	struct bcm2835aux_spi *bs = spi_master_get_devdata(master);
+
+	/* Clear FIFOs, and disable the HW block */
+	clk_disable_unprepare(bs->clk);

You probably want remove() to do things in the reverse order of probe(). In particular, disable the clock after anything that could touch registers in the HW.

Quoted 4 lines
drivers/spi/spi-bcm2835aux.c +4 -0
+	bcm2835aux_spi_reset_hw(bs);
+
+	/* disable HW block */
+	bcm2835aux_spi_disable(bs);

A message that is not in the archive (sent off-list or not yet received): [email protected]

#28 lore raw

I am on a business-trip right now, so I can not check the mailing list that often and my access to a rpi to develop is also limited hence the V3 patch set took some time to get out of the door and crossed the responses you had sent.

Quoted 2 lines · Stephen Warren

Hopefully the license of that tar file allows for that. I didn't look.

Well, I just took the values from the released video driver for those values where doe documentation is obviously wrong - essentially clarifying the SPI_STAT register on page 25.

Quoted 2 lines

As mentioned elsewhere, I'd hope all the shared aux register manipulations can be pushed into a shared driver.

I just found this email after having sent the latest version of the patch that makes use of syscon/regmap to serialize access to the
bcm2835_AUX_ENABLE register - that is all that it is really needed for.

Quoted 1 line

From my perspective it seems that a new driver just would produce

more code (to maintain) for something that the syscon driver already provides. If someone starts to enable aux-uart, then it could go with a new framework, but that is still more code that needs to get maintained than just using syscon as that "shared" driver.

As for hardcoded ids, that may be the case, but I just wanted to keep Device tree as minimal as necessary...
If we get to that situation then we can easily move that to some other logic...

Finally with regards to interrupts: these are shared anyway so I wonder why we would want to write an extra irq chip driver when it works as is anyway.

If someone thinks that is of a performance advantage then this extra layer of indirection could get written and we would only need to change the device-tree to use the new irq vectors instead.

But we are really only talking about 2 drivers and 3 interrupt sources.

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): ECFBB7BF-1316-4565-B1F2-FB2651131882-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#30 lore raw
Quoted 33 lines · Martin Sperl

I am on a business-trip right now, so I can not check the mailing list that often and my access to a rpi to develop is also limited hence the V3 patch set took some time to get out of the door and crossed the responses you had sent.

Quoted 2 lines · Stephen Warren

Hopefully the license of that tar file allows for that. I didn't look.

Well, I just took the values from the released video driver for those values where doe documentation is obviously wrong - essentially clarifying the SPI_STAT register on page 25.

Quoted 2 lines

As mentioned elsewhere, I'd hope all the shared aux register manipulations can be pushed into a shared driver.

I just found this email after having sent the latest version of the patch that makes use of syscon/regmap to serialize access to the
bcm2835_AUX_ENABLE register - that is all that it is really needed for.

From my perspective it seems that a new driver just would produce more code (to maintain) for something that the syscon driver already provides. If someone starts to enable aux-uart, then it could go with a new framework, but that is still more code that needs to get maintained than just using syscon as that "shared" driver.

As for hardcoded ids, that may be the case, but I just wanted to keep Device tree as minimal as necessary...
If we get to that situation then we can easily move that to some other logic...

Finally with regards to interrupts: these are shared anyway so I wonder why we would want to write an extra irq chip driver when it works as is anyway.

Quoted 5 lines

If someone thinks that is of a performance advantage then this extra layer of indirection could get written and we would only need to change the device-tree to use the new irq vectors instead.

But we are really only talking about 2 drivers and 3 interrupt sources.

I don't care so much about the internal code details; anything there can be trivially changed. But please do make sure the DT correctly represents the HW by:

* Having a separate DT node for each HW block (SPI controller, UART, and any shared interrupt mux/demux/controller/...)

* If e.g. the SPI controller driver is going to need to manipulate the "shared interrupt mux/demux/controller/...", there should be a phandle from the SPI controller node to the "shared interrupt mux/demux/controller/..." node, rather than listing the shared registers in each "client"'s reg property.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#32 lore raw
Quoted 9 lines · Stephen Warren

I don't care so much about the internal code details; anything there can be trivially changed. But please do make sure the DT correctly represents the HW by:

* Having a separate DT node for each HW block (SPI controller, UART, and any shared interrupt mux/demux/controller/...)

That is what we have with the v3 patch:
* spi1
* spi2
* syscon controlling the aux-enable register
(only used to enable/disable the hw block)

Quoted 5 lines

* If e.g. the SPI controller driver is going to need to manipulate the "shared interrupt mux/demux/controller/...", there should be a phandle from the SPI controller node to the "shared interrupt mux/demux/controller/..." node, rather than listing the shared registers in each "client"'s reg property.

That is not what is in the v3 release of the patch any longer.

Each of the above dt-nodes has their own (non-overlapping) register ranges and interrupts are enabled/disabled in the respective ranges for spi1/spi2. Also the status register of spi1/2 contain the corresponding flags for the reason of an interrupt - so no need to access any of the shared aux registers for that - hence the use of IRQF_SHARED.

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 2768BFA9-7FE9-4EDC-8692-AC3F070BD874-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#34 lore raw
Quoted 7 lines · Martin Sperl
Quoted 7 lines · Stephen Warren

I don't care so much about the internal code details; anything there can be trivially changed. But please do make sure the DT correctly represents the HW by:

Quoted 8 lines
Quoted 2 lines

* Having a separate DT node for each HW block (SPI controller, UART, and any shared interrupt mux/demux/controller/...)

That is what we have with the v3 patch:
* spi1
* spi2
* syscon controlling the aux-enable register
(only used to enable/disable the hw block)

OK, having separate nodes is great.

However, I'd like to see a "semantic" driver for the shared register region rather than a "syscon". IIUC, "syscon" simply provides a stylized way for one driver to touch some shared registers directly without any semantics. I'd strongly prefer to see a real driver inside Linux rather than something that just lets drivers fiddle with the shared registers willy nilly. Still, this aspect is an internal implementation detail inside the kernel that we can change without external impact later if we need.

More concerning: The bcm283x HW doesn't implement a "syscon" module, but some semantic IP block. The DT should contain a real compatible value that describes what the HW block really is, not just "syscon". We could bind the syscon driver to this compatible value if we have to for now.

Quoted 5 lines
Quoted 5 lines

* If e.g. the SPI controller driver is going to need to manipulate the "shared interrupt mux/demux/controller/...", there should be a phandle from the SPI controller node to the "shared interrupt mux/demux/controller/..." node, rather than listing the shared registers in each "client"'s reg property.

Quoted 8 lines

That is not what is in the v3 release of the patch any longer.

Each of the above dt-nodes has their own (non-overlapping) register ranges and interrupts are enabled/disabled in the respective ranges for spi1/spi2. Also the status register of spi1/2 contain the corresponding flags for the reason of an interrupt - so no need to access any of the shared aux registers for that - hence the use of IRQF_SHARED.

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#36 lore raw
Quoted 13 lines · Stephen Warren

However, I'd like to see a "semantic" driver for the shared register region rather than a "syscon". IIUC, "syscon" simply provides a stylized way for one driver to touch some shared registers directly without any semantics. I'd strongly prefer to see a real driver inside Linux rather than something that just lets drivers fiddle with the shared registers willy nilly. Still, this aspect is an internal implementation detail inside the kernel that we can change without external impact later if we need.

Quoted 4 lines

More concerning: The bcm283x HW doesn't implement a "syscon" module, but some semantic IP block. The DT should contain a real compatible value that describes what the HW block really is, not just "syscon". We could bind the syscon driver to this compatible value if we have to for

So, do I understand you correctly that if we would call the node bcm2835aux_enable as syscon with only the enable bit field register in it and add a enable_reg (pointing to the above) and enable_reg_mask=2 or 4 to the spi1/2 nodes then it would be acceptable?

Would look like this:
spi2@7e2150c0 {

+    compatible = "brcm,bcm2835-aux-spi";
+    reg = <0x7e2150c0 0x40>;
+    interrupts = <1 29>;
+    clocks = <&clk_spi>;
+    #address-cells = <1>;
+    #size-cells = <0>;
+    cs-gpios = <&gpio 43>, <&gpio 44>, <&gpio 45>;
+    enable_reg = <&bcm2835aux_enable>;
+    enable_reg_mask = 4;

+};
+
+/* the necessary syscon config referenced above */ +bcm2835aux_enable: bcm2835aux_enable@0x7e215004 {
+ compatible = "syscon";
+ reg = <0x7e215004 0x04>;
+};

The uart aux driver would use:
+ enable_reg = <&bcm2835aux_enable>;
+ enable_reg_mask = 1;

Or maybe you would prefer a different naming?

The only use-case would be using:
regmap_update_bits(enable_reg, 0, enable_reg_mask, enable_reg_mask); /*enable */ regmap_update_bits(enable_reg, 0, enable_reg_mask, 0); /* disable */

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 0125992E-40F4-4702-8404-2943FF9A8788-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#38 lore raw
Quoted 44 lines · Martin Sperl
Quoted 13 lines · Stephen Warren

However, I'd like to see a "semantic" driver for the shared register region rather than a "syscon". IIUC, "syscon" simply provides a stylized way for one driver to touch some shared registers directly without any semantics. I'd strongly prefer to see a real driver inside Linux rather than something that just lets drivers fiddle with the shared registers willy nilly. Still, this aspect is an internal implementation detail inside the kernel that we can change without external impact later if we need.

Quoted 4 lines

More concerning: The bcm283x HW doesn't implement a "syscon" module, but some semantic IP block. The DT should contain a real compatible value that describes what the HW block really is, not just "syscon". We could bind the syscon driver to this compatible value if we have to for

So, do I understand you correctly that if we would call the node bcm2835aux_enable as syscon with only the enable bit field register in it and add a enable_reg (pointing to the above) and enable_reg_mask=2 or 4 to the spi1/2 nodes then it would be acceptable?

Would look like this:
spi2@7e2150c0 {

(quoted diff) +16 -0
+    compatible = "brcm,bcm2835-aux-spi";
+    reg = <0x7e2150c0 0x40>;
+    interrupts = <1 29>;
+    clocks = <&clk_spi>;
+    #address-cells = <1>;
+    #size-cells = <0>;
+    cs-gpios = <&gpio 43>, <&gpio 44>, <&gpio 45>;
+    enable_reg = <&bcm2835aux_enable>;
+    enable_reg_mask = 4;
+};
+
+/* the necessary syscon config referenced above */
+bcm2835aux_enable: bcm2835aux_enable@0x7e215004 {
+    compatible = "syscon";
+    reg = <0x7e215004 0x04>;
+};

The uart aux driver would use:

Review

Quoted 2 lines
(quoted diff) +2 -0
+    enable_reg = <&bcm2835aux_enable>;
+    enable_reg_mask = 1;

I think I'd expect the shared registers to be:

bcm2835aux: misc@0x7e215000 {
    compatible = "brcm,bcm2835-aux";
    reg = <0x7e215000 0x08>;
};

There are two 4-byte registers outside the UART/SPI blocks, and the compatible value should reflect what the block is, not that Linux may use a syscon driver to implement the driver for it.

In the client, I'd expect a more semantic naming for the reference; something like:

	brcm,aux = <&bcm2835aux 4>;

brcm, since it's a custom/vendor-specific property. aux is the name of the object that's referenced. Packing the phandle and data together into a single property reduces the number of separate properties, and is a typical thing to do in a client of a service in DT.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#40 lore raw
Quoted 17 lines · Stephen Warren

I think I'd expect the shared registers to be:

bcm2835aux: misc@0x7e215000 {
   compatible = "brcm,bcm2835-aux";
   reg = <0x7e215000 0x08>;
};

There are two 4-byte registers outside the UART/SPI blocks, and the compatible value should reflect what the block is, not that Linux may use a syscon driver to implement the driver for it.

In the client, I'd expect a more semantic naming for the reference; something like:

Quoted 6 lines
	brcm,aux = <&bcm2835aux 4>;

brcm, since it's a custom/vendor-specific property. aux is the name of the object that's referenced. Packing the phandle and data together into a single property reduces the number of separate properties, and is a typical thing to do in a client of a service in DT.

So in the end you are saying we need a separate driver to get written (because of ‘compatible = "brcm,bcm2835-aux”;’)

That is unless you would allow:
compatible = compatible = "brcm,bcm2835-aux”, “syscon”;

If this is not acceptable, then where should such a driver go in the kernel tree?

It would essentially implement the following:
bcm2835aux_enable(dev, device-id);
bcm2835aux_disable(dev, device-id);

Which would just set/clean the bits in the register while holding a lock.

As an alternative: maybe we could implement it as an IRQ driver and when the irq is requested for that device, then the HW-block gets enabled automatically (and disabled when released).

That way we may not need to have a separate driver that would enable the uart1, but it would be sufficient to configure it as follows:

uart1: uart@7e215040 {
	compatible = "brcm,bcm2835-aux-uart", "ns16550";
	reg = <0x7e215040 0x40>;
	interrupts = <X 0>;
	clock-frequency = <500000000>;
	reg-shift = <2>;
	no-loopback-test;
	status = "disabled";
};

(taken from the foundation device-tree)

Please clarify

Thanks,
Martin--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 9005ABEC-C60A-4814-AD60-AD5BB09808F2-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#42 lore raw
Quoted 19 lines · Martin Sperl
Quoted 19 lines · Stephen Warren

I think I'd expect the shared registers to be:

bcm2835aux: misc@0x7e215000 {
   compatible = "brcm,bcm2835-aux";
   reg = <0x7e215000 0x08>;
};

There are two 4-byte registers outside the UART/SPI blocks, and the compatible value should reflect what the block is, not that Linux may use a syscon driver to implement the driver for it.

In the client, I'd expect a more semantic naming for the reference; something like:

	brcm,aux = <&bcm2835aux 4>;
Quoted 7 lines
Quoted 4 lines

brcm, since it's a custom/vendor-specific property. aux is the name of the object that's referenced. Packing the phandle and data together into a single property reduces the number of separate properties, and is a typical thing to do in a client of a service in DT.

So in the end you are saying we need a separate driver to get written (because of ‘compatible = "brcm,bcm2835-aux”;’)

It's fine if some existing driver matches that compatible value.

Quoted 2 lines

That is unless you would allow:
compatible = compatible = "brcm,bcm2835-aux”, “syscon”;

"syscon" definitely shouldn't be in a DT.

Quoted 8 lines

If this is not acceptable, then where should such a driver go in the kernel tree?

It would essentially implement the following:
bcm2835aux_enable(dev, device-id);
bcm2835aux_disable(dev, device-id);

Which would just set/clean the bits in the register while holding a lock.

That sounds reasonable. I'd also expect a function that the client drivers could call during probe() to look up the device (and implement deferred probe) and another to release the reference during the client's remove().

Quoted 3 lines

As an alternative: maybe we could implement it as an IRQ driver and when the irq is requested for that device, then the HW-block gets enabled automatically (and disabled when released).

That seems a bit too implicit; there's no strict requirement that a driver for e.g. the SPI block has to use an interrupt; it's merely extremely likely.

Quoted 2 lines

That way we may not need to have a separate driver that would enable the uart1, but it would be sufficient to configure it as follows:

Surely the IRQ driver would be a separate driver either way? The only difference is whether it exposes custom APIs, or does things as a side-effect of the existing IRQ API.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#44 lore raw

Hi Stephen!

Quoted 10 lines · Stephen Warren
Quoted 9 lines

If this is not acceptable, then where should such a driver go in the kernel tree?

It would essentially implement the following:
bcm2835aux_enable(dev, device-id);
bcm2835aux_disable(dev, device-id);

Quoted 6 lines
Quoted 1 line

Which would just set/clean the bits in the register while holding a lock.

That sounds reasonable. I'd also expect a function that the client drivers could call during probe() to look up the device (and implement deferred probe) and another to release the reference during the client's remove().

But the bigger question you have not answered is: “where should such an auxiliar driver go in the kernel tree?” i.e. which directory?

I really do not want to implement it and then get told: “that should not go here” - been thru too many iterations already…

Also I am not sure I understood the “defer” thingy.
I thought of actually implementing only 2 functions to use during probe and removal:
* bcm2835aux_enable(dev)
* bcm2835aux_disable(dev)

Both would pick up the “bcrm,aux” property from the device tree (as per “bcrm,aux = <&bcm2835aux 4>”) and set the enable register accordingly holding a lock.

I still could leave those 2 functions in the spi driver for now and when someone wants to implement the uart1, then they would need to pull that out into a separate driver.

As for interrupt-handler: it was a simple idea that would work fine for the bcm2835aux case to avoid configuring things for the uart, but then you do not want the uart1 to get configured as 'compatible=“ns16650”;’ inside the device-tree, so this is not acceptable anyway (unless there were some way to define “additional” compatibility for a driver without modifying the driver itself).
This means we will need to implement a minimal driver for uart1 that wraps ns16650.

But as all the drivers (spi-bcm2835aux as well as ns16650) can use FIRQ_SHARED (and do not need to read/write the shared aux_irg registers) the need for a interrupt controller is not there.

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 836DA157-3072-441A-A160-E1FDBB119E88-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#46 lore raw
Quoted 3 lines · Martin Sperl

Hi Stephen!
But the bigger question you have not answered is: “where should such an auxiliar driver go in the kernel tree?” i.e. which directory?

One thing: could the "module" be a regulator?

So drivers/regulators/bcm2835-aux-regulator.c

The devicetree would look something like this:

regulators {
    bcm2835aux_reg {
        compatible = "bcrm,bcrm-2835-aux-enable";
        reg = <0x7e215004 0x4>; /* the AUX enable register */

        bcm2835aux_uart1: {
            regulator-name = "bcm2835_aux_uart1";
            reg = <0>; /* bit 0 in enable register */
        };
        bcm2835aux_spi1: {
            regulator-name = "bcm2835_aux_spi1";
            reg = <1>; /* bit 1 in enable register */
        };
        bcm2835aux_spi2: {
            regulator-name = "bcm2835_aux_spi2";
            reg = <2>; /* bit 2 in enable register */
        };
    }
};

uart1: uart1@7e215040 {

compatible = "brcm,bcm2835-aux-uart";
    reg = <0x7e215040 0x40>;
    ...
    vcc = <&bcm2835aux_uart1>
};

spi1: spi1@7e215080 {

compatible = "brcm,bcm2835-aux-spi";
    reg = <0x7e215080 0x40>;
    ...
    vcc = <&bcm2835aux_spi1>
};

spi2: spi2@7e2150C0 {

compatible = "brcm,bcm2835-aux-spi";
    reg = <0x7e2150C0 0x40>;
    ...
    vcc = <&bcm2835aux_spi2>
};

And the necessary driver-side code for bcm2835aux_spi and bcm2835aux_uart would be along those lines:

probe:
/* get the "power-supply" */
bs->power = devm_regulator_get(dev, "vcc");
if ((PTR_ERR(priv->power) == -EPROBE_DEFER)
return -EPROBE_DEFER
/* enable the power-supply */
regulator_enable(bs->power);

remove:
regulator_disable(bs->power);

Would that look like an acceptable solution?

Thanks,
Martin

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#48 lore raw

Hi Martin,

Am 28.07.2015 um 12:48 schrieb Martin Sperl:

Quoted 6 lines · Martin Sperl
Quoted 3 lines

Hi Stephen!
But the bigger question you have not answered is: “where should such an auxiliar driver go in the kernel tree?” i.e. which directory?

One thing: could the "module" be a regulator?

IMHO that won't be acceptable.

How about a multifunction device driver (drivers/mfd)?

Other candidates could be drivers/soc or drivers/misc.

Regards Stefan
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#50 lore raw

Den 29.07.2015 18:37, skrev Stefan Wahren:

Quoted 7 lines

Hi Martin,

Am 28.07.2015 um 12:48 schrieb Martin Sperl:

Quoted 4 lines · Martin Sperl
Quoted 3 lines

Hi Stephen!
But the bigger question you have not answered is: “where should such an auxiliar driver go in the kernel tree?” i.e. which directory?

Quoted 9 lines
Quoted 2 lines

One thing: could the "module" be a regulator?

IMHO that won't be acceptable.

How about a multifunction device driver (drivers/mfd)?

Other candidates could be drivers/soc or drivers/misc.

Could it be a power domain driver? Documentation/devicetree/bindings/power/power_domain.txt

There are currently a deferred probing issue that might be a problem depending on the module linking order:
https://lkml.org/lkml/2015/3/11/483

Noralf.

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#51 lore raw
In reply to a message not in the archive
Quoted 14 lines · Stefan Wahren

Hi Martin,

Quoted 6 lines

Am 28.07.2015 um 12:48 schrieb Martin Sperl:

Quoted 4 lines · Martin Sperl

Hi Stephen!
But the bigger question you have not answered is: “where should such an auxiliar driver go in the kernel tree?” i.e. which directory?

One thing: could the "module" be a regulator?

IMHO that won't be acceptable.

Why would it not be acceptable?

It provides all sorts of methods and you do not have to implement all of them. Enable and disable would be sufficient.
On top it would be a generic interface.

Even the mcp251x can driver uses 2 of those to enable/disable the controller chip and the transceiver (and 2 dummy regulators if none are defined) There are also gpio regulators to switch a gpio to enable/disable a power-supply.

So with all those features it should be fairly standard to be used for such things.

See here for a bit of documentation:
http://lxr.free-electrons.com/source/Documentation/power/regulator/design.txt
http://lxr.free-electrons.com/source/Documentation/power/regulator/consumer.txt
(Especially point 2 about enable/disable)

Quoted 2 lines

How about a multifunction device driver (drivers/mfd)? Other candidates could be drivers/soc or drivers/misc.

Also possible...

Martin--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): C767C9AD-A9B5-428F-A207-D67269B380C6-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#53 lore raw

Hi Martin,

Am 29.07.2015 um 23:16 schrieb Martin Sperl:

Quoted 7 lines
Quoted 7 lines · Stefan Wahren

Hi Martin,

Quoted 1 line

Am 28.07.2015 um 12:48 schrieb Martin Sperl:

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines · Martin Sperl

Hi Stephen!
But the bigger question you have not answered is: “where should such an auxiliar driver go in the kernel tree?” i.e. which directory?

One thing: could the "module" be a regulator?

IMHO that won't be acceptable.

Why would it not be acceptable?

first of all, sorry i didn't follow this thread in every detail. My intention was to give you some ideas. I'm a not maintainer.

IMU a regulator is a hardware part who controls voltage or current.

Does it apply in your case?

Any question: would a user expect this function in the regulator framework?

Regards Stefan

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#55 lore raw
Quoted 23 lines · Stefan Wahren

Hi Martin,

Am 29.07.2015 um 23:16 schrieb Martin Sperl:

Quoted 7 lines
Quoted 7 lines · Stefan Wahren

Hi Martin,

Quoted 1 line

Am 28.07.2015 um 12:48 schrieb Martin Sperl:

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines · Martin Sperl

Hi Stephen!
But the bigger question you have not answered is: “where should such an auxiliar driver go in the kernel tree?” i.e. which directory?

One thing: could the "module" be a regulator?

IMHO that won't be acceptable.

Why would it not be acceptable?

Quoted 7 lines

first of all, sorry i didn't follow this thread in every detail. My intention was to give you some ideas. I'm a not maintainer.

IMU a regulator is a hardware part who controls voltage or current.

Does it apply in your case?

Any question: would a user expect this function in the regulator framework?

I am just trying to find a solution that will get accepted with the minimum number of reposts/rewrites to avoid frustration, but nobody has an answer which api we really should use.

The problem is that we have DT and we have code and as we only want HW being represented in the device tree we need something “sensible”.

What about adding “bcrm,bcm2835-aux-enable” to drivers/mfd/syscon.c compatibility?

That way we:
* have a clean dt that only represents hardware
* reuse existing code with minimal modifications
* minimal effort

That would be a minimal patch to enable this, so we can ask if that is acceptable and if it is not then we can still think of something else, which would be mostly replicating the bit-management portion of syscon.

Sometimes I wish there was a way to “extend” compatibility of a driver by just adding something to the device-tree (say compatibility) or define it in the platform config c-files without having to touch the actual drivers to add that compatibility string...

Martin

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): C2C16277-C6C1-4F86-BB88-580CF667EF24-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#57 lore raw

Hi Stefan!

Quoted 12 lines · Martin Sperl

I am just trying to find a solution that will get accepted with the minimum number of reposts/rewrites to avoid frustration, but nobody has an answer which api we really should use.

The problem is that we have DT and we have code and as we only want HW being represented in the device tree we need something “sensible”.

What about adding “bcrm,bcm2835-aux-enable” to drivers/mfd/syscon.c compatibility?

Quoted 8 lines

That way we:
* have a clean dt that only represents hardware
* reuse existing code with minimal modifications
* minimal effort

That would be a minimal patch to enable this, so we can ask if that is acceptable and if it is not then we can still think of something else, which would be mostly replicating the bit-management portion of syscon.

that minimal patch extending compatibility of syscon and also including the config portion for the kernel as well as the device tree would look something like this (note that it is not tested yet):

arch/arm/boot/dts/bcm2835.dtsi +5 -0
index 301c73f..bde42ce 100644
@@ -158,6 +158,11 @@
                arm-pmu {
                        compatible = "arm,arm1176-pmu";
                };
+
+               aux-enable: aux-enable@0x7e215004 {
+                       compatible = "bcrm,bcm2835-aux-enable";
+                       reg = <0x7e215004 0x04>;
+               };
        };
 
        clocks {
arch/arm/mach-bcm/Kconfig +1 -0
index 0ac9e4b3..e32ceea 100644
@@ -116,6 +116,7 @@ config ARCH_BCM2835
        select CLKSRC_OF
        select PINCTRL
        select PINCTRL_BCM2835
+       select MFD_SYSCON
        help
          This enables support for the Broadcom BCM2835 SoC. This SoC is
          used in the Raspberry Pi and Roku 2 devices.
drivers/mfd/syscon.c +7 -0
index 176bf0f..49cdd37 100644
@@ -211,6 +211,12 @@ static int syscon_probe(struct platform_device *pdev)
        return 0;
 }
 
+static const struct of_device_id syscon_match[] = {
+       { .compatible = "bcrm,bcm2835-aux-enable", },
+       {}
+};
+MODULE_DEVICE_TABLE(of, syscon_match);
+
 static const struct platform_device_id syscon_ids[] = {
        { "syscon", },
        { }
@@ -219,6 +225,7 @@ static const struct platform_device_id syscon_ids[] = {
 static struct platform_driver syscon_driver = {
        .driver = {
                .name = "syscon",
+               .of_match_table = syscon_match,
        },
        .probe          = syscon_probe,
        .id_table       = syscon_ids,

(please ignore the tabs converted to spaces for now introduced by copy/paste)

Then what would be missing is the config of the spi/uart devices that would require a property in the device-tree like:

	bcrm,aux-enable = <&aux-enable 1 /* bitmask for device */>;

which then would be used by the respective drivers like this:
enable:
regmap_update_bits(bs->aux_enable, 0,

		     bs->aux_enable_mask, bs->aux_enable_mask);
disable:
  regmap_update_bits(bs->aux_enable, 0,
		     bs->aux_enable_mask, 0);

Is this something that you would accept?

Thanks,
Martin--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 97861F80-CF83-4FF2-B96E-CDFB1A8F4921-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#59 lore raw
Quoted 23 lines · Martin Sperl
Quoted 11 lines

What about adding “bcrm,bcm2835-aux-enable” to drivers/mfd/syscon.c compatibility?

That way we:
* have a clean dt that only represents hardware
* reuse existing code with minimal modifications
* minimal effort

That would be a minimal patch to enable this, so we can ask if that is acceptable and if it is not then we can still think of something else, which would be mostly replicating the bit-management portion of syscon.

that minimal patch extending compatibility of syscon and also including the config portion for the kernel as well as the device tree would look something like this (note that it is not tested yet):

drivers/mfd/syscon.c +0 -0
@@ -211,6 +211,12 @@ static int syscon_probe(struct platform_device *pdev)
       return 0;
 }

drivers/mfd/syscon.c static int syscon_probe(struct platform_device *pdev) · line 222

Quoted 10 lines
drivers/mfd/syscon.c +6 -0
 
+static const struct of_device_id syscon_match[] = {
+       { .compatible = "bcrm,bcm2835-aux-enable", },
+       {}
+};
+MODULE_DEVICE_TABLE(of, syscon_match);
+
 static const struct platform_device_id syscon_ids[] = {
       { "syscon", },
       { }

Unfortunately the above does not work with syscon, as it _explicitly_ requires a compatibility of “syscon”:

        if (!of_device_is_compatible(np, "syscon"))
                return ERR_PTR(-EINVAL);

So by the rational of device-tree representing only the hardware this driver should never get used because of this limitation

Replicating syscon/regmap into a separate driver that has explicit compatibility of “bcrm, bcm2835-aux” results in more than 162 lines of extra code (plus changes to Makefile and Kconfig)

So I wonder if it would not be acceptable to allow:
compatiblity = “bcrm,bcm2835-aux”, “syscon”;

and avoid an unnecessary extra driver which provides only the following functions:

void bcm2835aux_enable(struct bcm2835aux *aux, u32 mask); void bcm2835aux_disable(struct bcm2835aux *aux, u32 mask); struct bcm2835aux *bcm2835aux_lookup_by_phandle(

	struct device_node *np,
	const char *property);

all of which are available almost identical in syscon/regmap.

We can also try to discuss if a modification to syscon so that it also checks the “explicit” compatibility in the configured list.

Martin--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): E9EEB426-95DE-4785-949C-6A402A25E115-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#61 lore raw

Hi Martin,

Am 30.07.2015 um 17:27 schrieb Martin Sperl:

Quoted 19 lines

[...]

Replicating syscon/regmap into a separate driver that has explicit compatibility of “bcrm, bcm2835-aux” results in more than 162 lines of extra code (plus changes to Makefile and Kconfig)

So I wonder if it would not be acceptable to allow:

   compatiblity = “bcrm,bcm2835-aux”, “syscon”;

and avoid an unnecessary extra driver which provides only the following functions:

void bcm2835aux_enable(struct bcm2835aux *aux, u32 mask); void bcm2835aux_disable(struct bcm2835aux *aux, u32 mask); struct bcm2835aux *bcm2835aux_lookup_by_phandle(

	struct device_node *np,
	const char *property);
Quoted 7 lines

all of which are available almost identical in syscon/regmap.

We can also try to discuss if a modification to syscon so that it also checks the “explicit” compatibility in the configured list.

Martin

syscon is hardware independent, which is used by many platforms. It won't be a good idea to change that only to safe some extra code.

Please think of the benefits of a separate driver for aux peripheral like extensibility in the near future (e.g. power management).

Stefan

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#62 lore raw
In reply to a message not in the archive
Quoted 6 lines · Martin Sperl
Quoted 3 lines · Martin Sperl

Hi Stephen!
But the bigger question you have not answered is: “where should such an auxiliar driver go in the kernel tree?” i.e. which directory?

One thing: could the "module" be a regulator?

The HW docs aren't very detailed on this point, but they certainly don't state that these bits control a regulator (or power domain as mentioned later in the thread). I guess it's possible, but it feels like an assumption to me. The HW modules seem small enough that it doesn't feel likely anyone would have bothered with power-gating them.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#63 lore raw
In reply to a message not in the archive
Quoted 14 lines · Martin Sperl

Hi Stephen!

Quoted 12 lines · Stephen Warren
Quoted 10 lines

If this is not acceptable, then where should such a driver go in the kernel tree?

It would essentially implement the following:
bcm2835aux_enable(dev, device-id);
bcm2835aux_disable(dev, device-id);

Which would just set/clean the bits in the register while holding a lock.

Quoted 7 lines
Quoted 4 lines

That sounds reasonable. I'd also expect a function that the client drivers could call during probe() to look up the device (and implement deferred probe) and another to release the reference during the client's remove().

But the bigger question you have not answered is: “where should such an auxiliar driver go in the kernel tree?” i.e. which directory?

drivers/soc seems made for this.

Quoted 9 lines

I really do not want to implement it and then get told: “that should not go here” - been thru too many iterations already…

Also I am not sure I understood the “defer” thingy.
I thought of actually implementing only 2 functions to use during probe and removal:
* bcm2835aux_enable(dev)
* bcm2835aux_disable(dev)

Quoted 3 lines

Both would pick up the “bcrm,aux” property from the device tree (as per “bcrm,aux = <&bcm2835aux 4>”) and set the enable register accordingly holding a lock.

That'd probably be fine. The important thing is to get the DT right since that's an ABI. The implementation can be refactored/rewritten at will later provided the right info is in the DT.

If you go this route, deferred probe isn't relevant.

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html