spi: aspeed: SPI1 mode control driver enabling sysfs control
cover spi: aspeed: SPI1 mode control driver enabling sysfs control
Hello,
I'm looking for feedback on a simple Aspeed SPI1 mode control driver that does two things mainly:
1. Expose a sysfs interface for userland control of SPI1 interface.
2. Optionally override the SPI1 mode at probe if "start_mode" is configured in device tree.
Aspeed 24XX/25XX support three interface modes for their SPI1 interface, which can be configured via HW strap register. In the typical case of connecting a host flash chip SPI1 interface:
- SPI master mode makes BMC the master to the host SPI flash
- SPI pass-through mode make whichever external SPI interface connected to SYSSPI be the master
- There are also "disable" and "debug" modes. Aspeed 25XX specified the debug mode is reserved though.
In particular, SPI pass-through mode would enable an external SPI master to directly program host SPI chip and possibly serve as an alternative way to LPC for host CPU accessing SPI flash. I think by providing a sysfs handle, userspace applications can have a flexible way to mux host SPI flash ownership between BMC/external on the fly.
Overriding the SPI mode at probe time can be useful to make sure 2500-smc flash controller always identifies the flash chip and create /dev/mtd files correctly.
I wrote the driver as a standalone misc driver for the ease of initial implementation. There are other options such as merging the functionality into the SMC driver itself, possibly enabled by optional device tree arguments/nodes, but I just want to send the patches out first to gather comments on perceived usefulness of the feature and how you think the driver should be constructed.
Feedback greatly appreciated!
Regards,
Kun
RFC 1/2 spi: aspeed: ASPEED 24XX/25XX SPI1 disable/passthrough/master mode control
Simple driver that exposes userspace sysfs to control SPI1 mode. It also optionally override initial SPI mode if given "start_mode" parameter in the device tree.
--- drivers/misc/Kconfig | 6 ++ drivers/misc/Makefile | 1 + drivers/misc/aspeed-spi-mode.c | 191 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 198 insertions(+) create mode 100644 drivers/misc/aspeed-spi-mode.c
drivers/misc/Kconfig +6 -0
@@ -809,6 +809,12 @@ config ASPEED_BT_IPMI_HOST help Support for the Aspeed BT ipmi host. +config SPI_MODECTRL_ASPEED + tristate "Support for SPI1 host flash mode change on Aspeed 24xx/25xx" + ---help--- + Support for the Aspeed 24xx/25xx sysfs control toggle between + disabled/master/pass-through modes. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
@@ -58,3 +58,4 @@ obj-$(CONFIG_VEXPRESS_SYSCFG) += vexpress-syscfg.o obj-$(CONFIG_CXL_BASE) += cxl/ obj-$(CONFIG_PANEL) += panel.o obj-$(CONFIG_ASPEED_BT_IPMI_HOST) += bt-host.o +obj-$(CONFIG_SPI_MODECTRL_ASPEED) += aspeed-spi-mode.o
drivers/misc/aspeed-spi-mode.c new file +191 -0
191 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
RFC 2/2 spi: aspeed: documentation and device tree bindings for ASPEED SPI1 mode controller
In reply to Kun YiThere is no accurate HW representation for the driver at the moment, thus it is represented as a "virtual" platform device node. The driver is placed in misc for the same reason.
--- .../devicetree/bindings/misc/aspeed-spi-mode.txt | 29 ++++++++++++++++++++++ arch/arm/boot/dts/aspeed-ast2500-evb.dts | 10 ++++++++ 2 files changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/aspeed-spi-mode.txt
Documentation/devicetree/bindings/misc/aspeed-spi-mode.txt new file +29 -0
@@ -0,0 +1,29 @@ +Device tree entry for SPI1 mode controller on AST24XX/AST25XX. + +This binding enables the SPI1 mode controller virtual driver that exposes +the SPI1 interface toggle capability to userspace through sysfs interface. If +optional argument "start_mode" is defined, it also configures the SPI mode. + +Required Properties: +- #address-cells : should be 1 +- #size-cells : should be 1 +- compatible : should be "aspeed, aspeed_spi_mode" +- reg : addresses and sizes of HW strap register and HW strap + reset register. Should be < 0x1e6e2070 0x4 > and + < 0x1e6e207c 0x4 > respectively. + +Optional Properties: +- start_mode : spi mode to override HW strap setting during probe. + Can be 0(disabled) 1(master) or 3(pass-through). + If not defined, HW strap or pinctrl setting is kept. + +Example: + spi_mode_ctrl: spi_mode { + #address-cells = <1>; + #size-cells = <1>; + compatible = "aspeed,aspeed_spi_mode"; + start_mode = <1>; + status = "okay"; + reg = < 0x1e6e2070 0x4 + 0x1e6e207c 0x4 >; + };
arch/arm/boot/dts/aspeed-ast2500-evb.dts +10 -0
@@ -18,6 +18,16 @@ memory { reg = <0x80000000 0x20000000>; }; + + spi_mode_ctrl: spi_mode { + #address-cells = <1>; + #size-cells = <1>; + compatible = "aspeed,aspeed_spi_mode"; + start_mode = <1>; + status = "okay"; + reg = < 0x1e6e2070 0x4 + 0x1e6e207c 0x4 >; + }; }; &fmc {
Signature · 1 line
2.8.0.rc3.226.g39d4020
Joel Stanley
maintainerHell Kun,
Quoted 6 lines · Kun Yi
Hello,
I'm looking for feedback on a simple Aspeed SPI1 mode control driver that does two things mainly:
1. Expose a sysfs interface for userland control of SPI1 interface.
2. Optionally override the SPI1 mode at probe if "start_mode" is configured in device tree.
Why do you plan to override the mode at boot time? Is this for firmware updates?
We plan to move away from having the NOR flash accessible from both the host and the BMC for all platforms. There's no good way to indicate ownership, and the Linux mtd subsystem does not have a good way of relinquishing nor reestablishing control. For instance, there's no way to "unmount" the MTD device, and there's no way to force a re-scan of partitions if you modify the layout.
I think there are some issues with your approach that break pinctrl/pinmux that Andrew will highlight.
Cheers,
Joel
Quoted 34 lines
Aspeed 24XX/25XX support three interface modes for their SPI1 interface, which can be configured via HW strap register. In the typical case of connecting a host flash chip SPI1 interface:
- SPI master mode makes BMC the master to the host SPI flash
- SPI pass-through mode make whichever external SPI interface connected to SYSSPI be the master
- There are also "disable" and "debug" modes. Aspeed 25XX specified the debug mode is reserved though.In particular, SPI pass-through mode would enable an external SPI master to directly program host SPI chip and possibly serve as an alternative way to LPC for host CPU accessing SPI flash. I think by providing a sysfs handle, userspace applications can have a flexible way to mux host SPI flash ownership between BMC/external on the fly.
Overriding the SPI mode at probe time can be useful to make sure 2500-smc flash controller always identifies the flash chip and create
/dev/mtdfiles correctly.I wrote the driver as a standalone misc driver for the ease of initial implementation. There are other options such as merging the functionality into the SMC driver itself, possibly enabled by optional device tree arguments/nodes, but I just want to send the patches out first to gather comments on perceived usefulness of the feature and how you think the driver should be constructed.
Feedback greatly appreciated!
Regards,
Kun_______________________________________________
openbmc mailing list
[email protected]
https://lists.ozlabs.org/listinfo/openbmc
Hi Kun,
Quoted 22 lines · Kun Yi
Hello,
I'm looking for feedback on a simple Aspeed SPI1 mode control driver that does two things mainly:
1. Expose a sysfs interface for userland control of SPI1 interface.
2. Optionally override the SPI1 mode at probe if "start_mode" is configured in device tree.Aspeed 24XX/25XX support three interface modes for their SPI1 interface, which can be configured via HW strap register. In the typical case of connecting a host flash chip SPI1 interface:
- SPI master mode makes BMC the master to the host SPI flash
- SPI pass-through mode make whichever external SPI interface connected to SYSSPI be the master
- There are also "disable" and "debug" modes. Aspeed 25XX specified the debug mode is reserved though.In particular, SPI pass-through mode would enable an external SPI master to directly program host SPI chip and possibly serve as an alternative way to LPC for host CPU accessing SPI flash. I think by providing a sysfs handle, userspace applications can have a flexible way to mux host SPI flash ownership between BMC/external on the fly.
Quoted 8 lines
Overriding the SPI mode at probe time can be useful to make sure 2500-smc flash controller always identifies the flash chip and create
/dev/mtdfiles correctly.I wrote the driver as a standalone misc driver for the ease of initial implementation. There are other options such as merging the functionality into the SMC driver itself, possibly enabled by optional device tree arguments/nodes, but I just want to send the patches out first to gather comments on perceived usefulness of the feature and how you think the driver should be constructed.
At least one issue I have with the implementation is that the strap register is currently "owned" by the pinctrl driver, but the patch as it stands has no interaction with this subsystem. Arguably the pinctrl driver is where this should be implemented, as it encapsulates pinmux whose aim is to manage the functionality made available on the SoC's pins.
Currently the pinctrl driver treats the strapping register as read- only. That should probably change in light of what you're trying to do here, though only to the extent of allowing the SPI mode switch.
Cheers,
Andrew
Hi Joel, thanks for commenting!
Quoted 6 lines · Joel Stanley
Hell Kun,
Quoted 3 lines · Kun Yi
Hello,
I'm looking for feedback on a simple Aspeed SPI1 mode control driver
Quoted 9 lines
that does two things mainly:
Quoted 2 lines
1. Expose a sysfs interface for userland control of SPI1 interface.
2. Optionally override the SPI1 mode at probe if "start_mode" isconfigured in
Quoted 1 line
device tree.
Why do you plan to override the mode at boot time? Is this for firmware updates?
More important here is the ability to change the SPI mode at *run time*. One use case is for platforms without eSPI/LPC support. When host CPU is booting and BIOS needs to read SPI chip, the most straightforward way for BMC to allow host access to the SPI chip is to toggle to SPI pass-through mode. Thus the core purpose of the driver is for enabling SPI pass-through mode on demand.
Overriding the SPI mode at boot time is only to make sure the host SPI chip can be recognized correctly by the SMC driver. Because currently pinctrl treats HW strap as read-only, mis-configured HW strap pins will cause SMC driver to fail reading SPI flash ID and not register it in MTD subsystem, and there is no easy way to probe again later. Though enabling pinctrl to set HW strap register might be a better approach as Andrew mentioned.
Quoted 7 lines
We plan to move away from having the NOR flash accessible from both the host and the BMC for all platforms. There's no good way to indicate ownership, and the Linux mtd subsystem does not have a good way of relinquishing nor reestablishing control. For instance, there's no way to "unmount" the MTD device, and there's no way to force a re-scan of partitions if you modify the layout.
I saw some discussions related on IRC but wasn't clear about the details. Could you elaborate a little? Do you plan to only allow BMC daemons to access both host/BMC NOR flashes?
I got the impression that mtd will stick around for now. Do we have a time frame for deprecating that?
Quoted 3 lines
I think there are some issues with your approach that break pinctrl/pinmux that Andrew will highlight.
Sure I will reply to those in Andrew's email.
Quoted 52 lines
Cheers,
Joel
Quoted 3 lines
Aspeed 24XX/25XX support three interface modes for their SPI1 interface, which can be configured via HW strap register. In the typical case of
connecting
Quoted 3 lines
a host flash chip SPI1 interface:
- SPI master mode makes BMC the master to the host SPI flash
- SPI pass-through mode make whichever external SPI interface connectedto SYSSPI
Quoted 2 lines
be the master
- There are also "disable" and "debug" modes. Aspeed 25XX specified thedebug
Quoted 3 lines
mode is reserved though.
In particular, SPI pass-through mode would enable an external SPI master
to
Quoted 1 line
directly program host SPI chip and possibly serve as an alternative way
to LPC
Quoted 1 line
for host CPU accessing SPI flash. I think by providing a sysfs handle,
userspace
Quoted 1 line
applications can have a flexible way to mux host SPI flash ownership
between
Quoted 3 lines
BMC/external on the fly.
Overriding the SPI mode at probe time can be useful to make sure
2500-smc flash
Quoted 1 line
controller always identifies the flash chip and create
/dev/mtdfilescorrectly.
Quoted 2 lines
I wrote the driver as a standalone misc driver for the ease of initial
implementation.
Quoted 1 line
There are other options such as merging the functionality into the SMC
driver
Quoted 1 line
itself, possibly enabled by optional device tree arguments/nodes, but I
just want to
Quoted 12 lines
send the patches out first to gather comments on perceived usefulness of the feature and how you think the driver should be constructed.
Feedback greatly appreciated!
Regards,
Kun_______________________________________________
openbmc mailing list
[email protected]
https://lists.ozlabs.org/listinfo/openbmc
Signature · 2 lines
Regards, Kun
Hi Andrew,
One question I have though: I think pinmux/pinctrl driver is supposed to be a boot time static pin configure module and parses DT and configures accordingly. Is it possible to use pinmux to dynamically modify the pin states? This is essentially the problem I'm trying to deal with.
Thanks,
Kun
Quoted 62 lines · Andrew Jeffery
Hi Kun,
Quoted 3 lines · Kun Yi
Hello,
I'm looking for feedback on a simple Aspeed SPI1 mode control driver
that does two things mainly:
Quoted 2 lines
1. Expose a sysfs interface for userland control of SPI1 interface.
2. Optionally override the SPI1 mode at probe if "start_mode" isconfigured in
Quoted 4 lines
device tree.
Aspeed 24XX/25XX support three interface modes for their SPI1 interface, which can be configured via HW strap register. In the typical case of
connecting
Quoted 3 lines
a host flash chip SPI1 interface:
- SPI master mode makes BMC the master to the host SPI flash
- SPI pass-through mode make whichever external SPI interface connectedto SYSSPI
Quoted 2 lines
be the master
- There are also "disable" and "debug" modes. Aspeed 25XX specified thedebug
Quoted 3 lines
mode is reserved though.
In particular, SPI pass-through mode would enable an external SPI master
to
Quoted 1 line
directly program host SPI chip and possibly serve as an alternative way
to LPC
Quoted 1 line
for host CPU accessing SPI flash. I think by providing a sysfs handle,
userspace
Quoted 1 line
applications can have a flexible way to mux host SPI flash ownership
between
Quoted 3 lines
BMC/external on the fly.
Overriding the SPI mode at probe time can be useful to make sure
2500-smc flash
Quoted 1 line
controller always identifies the flash chip and create
/dev/mtdfilescorrectly.
Quoted 2 lines
I wrote the driver as a standalone misc driver for the ease of initial
implementation.
Quoted 1 line
There are other options such as merging the functionality into the SMC
driver
Quoted 1 line
itself, possibly enabled by optional device tree arguments/nodes, but I
just want to
Quoted 2 lines
send the patches out first to gather comments on perceived usefulness of the feature and how you think the driver should be constructed.
At least one issue I have with the implementation is that the strap register is currently "owned" by the pinctrl driver, but the patch as it stands has no interaction with this subsystem. Arguably the pinctrl driver is where this should be implemented, as it encapsulates pinmux whose aim is to manage the functionality made available on the SoC's pins.
Currently the pinctrl driver treats the strapping register as read- only. That should probably change in light of what you're trying to do here, though only to the extent of allowing the SPI mode switch.
Cheers,
Andrew
Signature · 2 lines
Regards, Kun
Quoted 6 lines · Kun Yi
Hi Andrew,
One question I have though: I think pinmux/pinctrl driver is supposed to be a boot time static pin configure module and parses DT and configures accordingly. Is it possible to use pinmux to dynamically modify the pin states?
Yes, see "Runtime pinmuxing" here (at the bottom of the document):
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/pinctrl.txt
So you'd need to patch the FMC driver that Milton and Cedric have been working on to (de)activate pin states, likely at probe() and remove() (this implies you'll need to somehow orchestrate a remove/switch, switch/probe dance). Alternatively, provide a way to suspend operations on the MTD and switch the pins between master and passthru in the FMC driver. Some complications are that this functionality is only available for SPI1, and you might need to do a bit of work to guarantee sensible outcomes for operations that might span the mode switch.
Cheers,
Andrew
Thanks Andrew that was helpful! I will look into pinctrl and FMC driver then.
Thanks,
Kun
Quoted 25 lines · Andrew Jeffery
Quoted 6 lines · Kun Yi
Hi Andrew,
One question I have though: I think pinmux/pinctrl driver is supposed to be a boot time static pin configure module and parses DT and configures accordingly. Is it possible to use pinmux to dynamically modify the pin states?
Yes, see "Runtime pinmuxing" here (at the bottom of the document):
https://git.kernel.org/cgit/linux/kernel/git/torvalds/
linux.git/tree/Documentation/pinctrl.txtSo you'd need to patch the FMC driver that Milton and Cedric have been working on to (de)activate pin states, likely at
probe()andremove()(this implies you'll need to somehow orchestrate a remove/switch, switch/probe dance). Alternatively, provide a way to suspend operations on the MTD and switch the pins between master and passthru in the FMC driver. Some complications are that this functionality is only available for SPI1, and you might need to do a bit of work to guarantee sensible outcomes for operations that might span the mode switch.Cheers,
Andrew
Signature · 2 lines
Regards, Kun