add regmap-spi-avmm & Intel Max10 BMC chip support
Subsystems (4)
Xu Yilun
maintainerv2 cover add regmap-spi-avmm & Intel Max10 BMC chip support
This patchset adds the regmap-spi-avmm to support the Intel SPI Slave to AVMM Bus Bridge (spi-avmm) IP block. It also implements the usercase - the driver of Intel Max10 BMC chip which integrates this IP block.
Patch #1 implements the main part of regmap-spi-avmm. Patch #2 is a fix of the HW issue in spi-avmm IP block. Patch #3 implements the mfd driver of Intel Max10 BMC chip.
Main changes from v1:
- Split out the regmap-spi-avmm module out of intel-m10-bmc module.
Matthew Gerlach (1):
regmap: spi-avmm: start with the last SOP on phy rx buffer parsing
Xu Yilun (2):
regmap: add Intel SPI Slave to AVMM Bus Bridge support
mfd: intel-m10-bmc: add Max10 BMC chip support for Intel FPGA PAC
.../ABI/testing/sysfs-driver-intel-m10-bmc | 15 + drivers/base/regmap/Kconfig | 6 +- drivers/base/regmap/Makefile | 1 + drivers/base/regmap/regmap-spi-avmm.c | 932 +++++++++++++++++++++ drivers/mfd/Kconfig | 13 + drivers/mfd/Makefile | 2 + drivers/mfd/intel-m10-bmc.c | 174 ++++ include/linux/mfd/intel-m10-bmc.h | 57 ++ include/linux/regmap.h | 36 + 9 files changed, 1235 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-intel-m10-bmc create mode 100644 drivers/base/regmap/regmap-spi-avmm.c create mode 100644 drivers/mfd/intel-m10-bmc.c create mode 100644 include/linux/mfd/intel-m10-bmc.h
Signature · 1 line
2.7.4
Xu Yilun
maintainerPATCH v2 1/3 regmap: add Intel SPI Slave to AVMM Bus Bridge support
This patch add support for regmap API that is intended to be used by the drivers of some SPI slave chips which integrate the "SPI slave to Avalon Master Bridge" (spi-avmm) IP.
The spi-avmm IP acts as a bridge to convert encoded streams of bytes from the host to the chip's internal mmio read/write on Avalon bus. The driver implements the read/write protocol for a generic SPI master to communicate with the spi-avmm IP.
---
v2: Split out the regmap-spi-avmm as an independent module.
--- drivers/base/regmap/Kconfig | 6 +- drivers/base/regmap/Makefile | 1 + drivers/base/regmap/regmap-spi-avmm.c | 932 ++++++++++++++++++++++++++++++++++ include/linux/regmap.h | 36 ++ 4 files changed, 974 insertions(+), 1 deletion(-) create mode 100644 drivers/base/regmap/regmap-spi-avmm.c
drivers/base/regmap/Kconfig +5 -1
@@ -4,7 +4,7 @@ # subsystems should select the appropriate symbols. config REGMAP - default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ || REGMAP_SOUNDWIRE || REGMAP_SCCB || REGMAP_I3C) + default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ || REGMAP_SOUNDWIRE || REGMAP_SCCB || REGMAP_I3C || REGMAP_SPI_AVMM) select IRQ_DOMAIN if REGMAP_IRQ bool
@@ -53,3 +53,7 @@ config REGMAP_SCCB config REGMAP_I3C tristate depends on I3C + +config REGMAP_SPI_AVMM + tristate + depends on SPI
drivers/base/regmap/Makefile +1 -0
@@ -17,3 +17,4 @@ obj-$(CONFIG_REGMAP_W1) += regmap-w1.o obj-$(CONFIG_REGMAP_SOUNDWIRE) += regmap-sdw.o obj-$(CONFIG_REGMAP_SCCB) += regmap-sccb.o obj-$(CONFIG_REGMAP_I3C) += regmap-i3c.o +obj-$(CONFIG_REGMAP_SPI_AVMM) += regmap-spi-avmm.o
drivers/base/regmap/regmap-spi-avmm.c new file +932 -0
932 lines not on this page · raw message
include/linux/regmap.h +36 -0
@@ -567,6 +567,10 @@ struct regmap *__regmap_init_sdw(struct sdw_slave *sdw,const struct regmap_config *config, struct lock_class_key *lock_key, const char *lock_name); +struct regmap *__regmap_init_spi_avmm (struct spi_device *spi, +const struct regmap_config *config, +struct lock_class_key *lock_key, +const char *lock_name); struct regmap *__devm_regmap_init(struct device *dev, const struct regmap_bus *bus,
@@ -620,6 +624,10 @@ struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c,const struct regmap_config *config, struct lock_class_key *lock_key, const char *lock_name); +struct regmap *__devm_regmap_init_spi_avmm (struct spi_device *spi, +const struct regmap_config *config, +struct lock_class_key *lock_key, +const char *lock_name);/* * Wrapper for regmap_init macros to include a unique lockdep key and name * for each call. No-op if CONFIG_LOCKDEP is not set.
@@ -806,6 +814,19 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg); __regmap_lockdep_wrapper(__regmap_init_sdw, #config, \ sdw, config) +/** +* regmap_init_spi_avmm() - Initialize register map for Intel SPI Slave +* to AVMM Bus Bridge +* +* @spi: Device that will be interacted with +* @config: Configuration for register map +* +* The return value will be an ERR_PTR() on error or a valid pointer +* to a struct regmap. + */ +#define regmap_init_spi_avmm (spi, config) \ + __regmap_lockdep_wrapper(__regmap_init_spi_avmm, #config, \ + spi, config)/** * devm_regmap_init() - Initialise managed register map
@@ -993,6 +1014,21 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg); __regmap_lockdep_wrapper(__devm_regmap_init_i3c, #config, \ i3c, config) +/** +* devm_regmap_init_spi_avmm() - Initialize register map for Intel SPI Slave +* to AVMM Bus Bridge +* +* @spi: Device that will be interacted with +* @config: Configuration for register map +* +* The return value will be an ERR_PTR() on error or a valid pointer +* to a struct regmap. The map will be automatically freed by the +* device management code. + */ +#define devm_regmap_init_spi_avmm (spi, config) \ + __regmap_lockdep_wrapper(__devm_regmap_init_spi_avmm, #config, \ + spi, config) +int regmap_mmio_attach_clk (struct regmap *map,struct clk *clk);void regmap_mmio_detach_clk (struct regmap *map);void regmap_exit (struct regmap *map);
Signature · 1 line
2.7.4
Mark Brown
maintainerRe: [PATCH v2 1/3] regmap: add Intel SPI Slave to AVMM Bus Bridge support
Quoted 3 lines · Xu Yilun
This patch add support for regmap API that is intended to be used by the drivers of some SPI slave chips which integrate the "SPI slave to Avalon Master Bridge" (spi-avmm) IP.
At a very high level this looks far too complicated. Some of that is due to the protocol it's implementing which looks awfully like you've got a microcontroller in there trying to proxy a bus of some kind but there looks to be a lot of abstraction layers simply within the software here which make things hard to follow. At the very least there doesn't seem to be any interaction with this other than proxying stuff. As things stand this would be the largest regmap bus implementation by an order of magnitude.
It is not clear to me that this is really a generic thing that will have multiple users and that it shouldn't be implemented as reg_read() and reg_write() operations in the driver that uses it.
drivers/base/regmap/Kconfig config REGMAP_SCCB · line 59
Quoted 3 lines
drivers/base/regmap/Kconfig +3
-0+config REGMAP_SPI_AVMM + tristate + depends on SPI
Note that for selected symbols dependencies don't take effect.
drivers/base/regmap/regmap-spi-avmm.c line 3
Quoted 4 lines
drivers/base/regmap/regmap-spi-avmm.c new file +3
-0@@ -0,0 +1,932 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for Intel SPI Slave to AVMM Bus Bridge
Please make the entire comment a C++ one so things look omre intentional.
drivers/base/regmap/regmap-spi-avmm.c line 26
Quoted 3 lines
drivers/base/regmap/regmap-spi-avmm.c new file +3
-0+* Reference Documents could be found at: +* https://www.intel.com/content/www/us/en/programmable/documentation/ +* sfo1400787952932.html
Please don't corrupt links like this, that makes them harder to use.
Quoted 8 lines
drivers/base/regmap/regmap-spi-avmm.c new file +7
-0+* The main function of the physical layer is the use of PHY_IDLE (4a). Host +* issues SCLK to query data from slave, but if slave is not ready to submit +* data yet, it will repeat PHY_IDLE until data is prepared. +* Because of this special char, it also needs an ESCAPE char (4d), to help +* represent data "4a". The escape rule is "4d first, following 4a ^ 20". +* So "4d, 6a" for data "4a", and "4d, 6d" for data "4d". +* The packet layer defines the boundary of a whole packet. It defines the
drivers/base/regmap/regmap-spi-avmm.c line 57
Quoted 10 lines
drivers/base/regmap/regmap-spi-avmm.c new file +10
-0+* Start Of Packet (SOP, 7a) char and End Of Packet (EOP, 7b) char. Please +* note that the non-special byte after EOP is the last byte of the packet. +* The packet layer also defines a Channel char (7c) + Channel number for +* multiple channel transfer. This not currently supported by this driver. So +* host will always send "7c, 00" when needed, and will drop the packet if +* "7c, non-zero" is received. +* Finally, a packet layer ESCAPE char (7d) is also needed to represent a +* data value that is the same as the special chars. The escape rule is the +* same. The escape rule should be used if the last byte requires it. So if a +* packet ends up with data 7a, the last bytes should be "7b, 7d, 5a".
This comment is not particularly intelligable. I assume all these number/letter combinations are references to something - it'd be good to say what.
drivers/base/regmap/regmap-spi-avmm.c line 178
Quoted 4 lines
drivers/base/regmap/regmap-spi-avmm.c new file +4
-0+/* slave's register addr is 32 bits */ +#define REG_SIZE 4UL +/* slave's register value is 32 bits */ +#define VAL_SIZE 4UL
These and many of the other constants are liable to conflict with something, namespacing would be good.
drivers/base/regmap/regmap-spi-avmm.c line 198
Quoted 12 lines
drivers/base/regmap/regmap-spi-avmm.c new file +12
-0+struct trans_header { +u8 trans_code; +u8 rsvd; +__be16 size; +__be32 addr; +}; + +struct trans_response { +u8 r_trans_code; +u8 rsvd; +__be16 size; +};
Do these need to be packed?
drivers/base/regmap/regmap-spi-avmm.c line 216
Quoted 3 lines
drivers/base/regmap/regmap-spi-avmm.c new file +3
-0+/* No additional chars are in transaction layer RX, just read out data */ +#define TRANS_RX_MAX (VAL_SIZE * MAX_RX_CNT) +/*
Blank line before the comment.
drivers/base/regmap/regmap-spi-avmm.c line 230
Quoted 2 lines
drivers/base/regmap/regmap-spi-avmm.c new file +2
-0+#define TRANS_BUF_SIZE ((TRANS_TX_MAX > TRANS_RX_MAX) ? \ + TRANS_TX_MAX : TRANS_RX_MAX)
This could be more simply written using max() couldn't it (which IIRC can also be evaluated at compile time)?
drivers/base/regmap/regmap-spi-avmm.c line 285
Quoted 12 lines
drivers/base/regmap/regmap-spi-avmm.c new file +12
-0+/* Format a transaction layer byte stream for tx_buf */ +static void trans_tx_prepare (bool is_read,u32 reg,u16 count,u32 *wr_val, +char *tx_buf,unsigned int *tx_len) +{ +struct trans_header *header; +u8 trans_code; +__le32 *data; +int i; + + trans_code = is_read ? + (count ==1 ?TRANS_CODE_READ :TRANS_CODE_SEQ_READ ) : + (count ==1 ?TRANS_CODE_WRITE :TRANS_CODE_SEQ_WRITE );
Please write this using normal conditional statements for legibility.
drivers/base/regmap/regmap-spi-avmm.c line 287
Quoted 1 line
drivers/base/regmap/regmap-spi-avmm.c new file +1
-0+ header = (struct trans_header *)tx_buf;
No need to cast away from char *.
Quoted 8 lines
drivers/base/regmap/regmap-spi-avmm.c new file +8
-0+/* +* The input is a transaction layer byte stream in rx_buf, the output is read +* out data. +*/ +static int trans_rx_parse (bool is_read,char *rx_buf,unsigned int rx_len, +u16 expected_count,u32 *rd_val) +{ +unsigned int expected_len = expected_count *VAL_SIZE ;
drivers/base/regmap/regmap-spi-avmm.c line 373
Quoted 10 lines
drivers/base/regmap/regmap-spi-avmm.c new file +10
-0+ +if (is_read) { +if (expected_len != rx_len) +return -EINVAL ; + +return rd_trans_rx_parse (rx_buf, rx_len, rd_val); + } + +return wr_trans_rx_parse (rx_buf, rx_len, expected_len); +}
Please write the is_read check as an if/else, it'd be clearer.
drivers/base/regmap/regmap-spi-avmm.c line 384
Quoted 10 lines
drivers/base/regmap/regmap-spi-avmm.c new file +10
-0+/* Packet Layer & Physical Layer */ +/* The input is a trans stream in trans_buf, format a phy stream in phy_buf. */ +static void pkt_phy_tx_prepare (char *trans_buf,unsigned int trans_len, +char *phy_buf,unsigned int *phy_len) +{ +unsigned int i; +char *b, *p; + + b = trans_buf; + p = phy_buf;
I'm not seeing any bounds checking on the size of an operation in this function and I think I'd expect some, similarly for a lot of the other I/O operations.
drivers/base/regmap/regmap-spi-avmm.c line 586
Quoted 2 lines
drivers/base/regmap/regmap-spi-avmm.c new file +2
-0+ poll_timeout = jiffies +SPI_AVMM_XFER_TIMEOUT ; +for (;;) {
Please rewrite this loop so it's clear that it terminates, usually that'd mean a do { } while (!timeout) type construction. The extra effort involved in doing one more check after timeout could just as well be a slightly longer timeout and it'd be clearer.
drivers/base/regmap/regmap-spi-avmm.c line 611
Quoted 11 lines
drivers/base/regmap/regmap-spi-avmm.c new file +11
-0+/* +* We timeout when rx is invalid for some time. But +* it is possible we are scheduled out for long time +* after a spi_read. So when we are scheduled in, a SW +* timeout happens. But actually HW may have worked fine and +* has been ready long time ago. So we need to do an extra +* read, if we get a valid word we return a valid rx word, +* otherwise real a HW issue happens. +*/ +if (time_after (jiffies, poll_timeout)) + last_try = true;
If the system is that heavily loaded I fear there's bigger problems, you could also express the timeout in terms of number of times you poll with a delay (at the minute this will busy wait which doesn't seem ideal either).
drivers/base/regmap/regmap-spi-avmm.c line 629
Quoted 13 lines
drivers/base/regmap/regmap-spi-avmm.c new file +13
-0+static void br_tx_prepare (struct spi_avmm_bridge *br,bool is_read,u32 reg, +u16 count,u32 *wr_val) +{ +unsigned int tx_len; + +trans_tx_prepare (is_read, reg, count, wr_val, + br->trans_buf, &tx_len); +pkt_phy_tx_prepare (br->trans_buf, tx_len, + br->phy_buf, &tx_len); +phy_tx_pad (br->word_len, br->phy_buf, tx_len, &tx_len); + + br->phy_len = tx_len; +}
This is the sort of thing I'm looking at when I say this code has too many abstraction layers, this function and all of the functions it calls have exactly one caller spread out all over the code and I can't help but think that some of them could be usefully inlined. As things stand it's really hard to tell what any individual bit of code is supposed to be doing or if it's doing it correctly.
drivers/base/regmap/regmap-spi-avmm.c line 763
Quoted 6 lines
drivers/base/regmap/regmap-spi-avmm.c new file +6
-0+ ret = ret ? : (eop ?0 : -EINVAL ); +if (ret) { +dev_err (&br->spi->dev,"%s br txrx err %d\n" , __func__, ret); +print_hex_dump (KERN_DEBUG ,"phy rx:" ,DUMP_PREFIX_OFFSET , +16 ,1 , br->phy_buf, rx_len, true); + }
Please write normal conditional statements for legibility.
drivers/base/regmap/regmap-spi-avmm.c line 785
Quoted 5 lines
drivers/base/regmap/regmap-spi-avmm.c new file +5
-0+ +#define do_reg_read (_ctx, _reg, _value, _count) \ + do_reg_access(_ctx, true, _reg, _value, _count) +#define do_reg_write (_ctx, _reg, _value, _count) \ + do_reg_access(_ctx, false, _reg, _value, _count)
Please write these as proper functions so that the compiler can check things more thoroughly.
drivers/base/regmap/regmap-spi-avmm.c line 808
Quoted 10 lines
drivers/base/regmap/regmap-spi-avmm.c new file +10
-0+static int regmap_spi_avmm_gather_write (void *context, +const void *reg_buf,size_t reg_len, +const void *val_buf,size_t val_len) +{ +if (reg_len !=REG_SIZE ) +return -EINVAL ; + +return do_reg_write (context, *(u32 *)reg_buf, (u32 *)val_buf, + (u16)(val_len /VAL_SIZE )); +}
The cast on the length looks worrying...
drivers/base/regmap/regmap-spi-avmm.c line 840
Quoted 3 lines
drivers/base/regmap/regmap-spi-avmm.c new file +3
-0+/* Only support BPW == 8 or 32 now */ +if (spi->bits_per_word !=8 && spi->bits_per_word !=32 ) +return ERR_PTR (-EINVAL );
Most controllers support configurable bits per word (and modes) - you shouldn't be rejecting things based on whatever the default happens to be.
Quoted 4 lines
drivers/base/regmap/regmap-spi-avmm.c new file +4
-0+static const struct regmap_bus regmap_spi_avmm_bus = { + .write = regmap_spi_avmm_write, + .gather_write = regmap_spi_avmm_gather_write, + .read = regmap_spi_avmm_read,
drivers/base/regmap/regmap-spi-avmm.c line 884
Quoted 10 lines
drivers/base/regmap/regmap-spi-avmm.c new file +10
-0+ .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, + .val_format_endian_default = REGMAP_ENDIAN_NATIVE, + .max_raw_read = VAL_SIZE * MAX_RX_CNT, + .max_raw_write = VAL_SIZE * MAX_TX_CNT, + + .reg_write = regmap_spi_avmm_reg_write, + .reg_read = regmap_spi_avmm_reg_read, + + .free_context = spi_avmm_bridge_ctx_free, +};
This seems confused, you shouldn't have both unformatted I/O operations and register I/O operations. Either the hardware implements a byte stream and the core will handle formatting register operations into that byte stream or the hardware understands registers and values in which case there shouldn't be unformatted operations. A combination of the two is not going to work well.
Xu Yilun
maintainerRe: [PATCH v2 1/3] regmap: add Intel SPI Slave to AVMM Bus Bridge support
Quoted 9 lines · Mark Brown
Quoted 3 lines · Xu Yilun
This patch add support for regmap API that is intended to be used by the drivers of some SPI slave chips which integrate the "SPI slave to Avalon Master Bridge" (spi-avmm) IP.
At a very high level this looks far too complicated. Some of that is due to the protocol it's implementing which looks awfully like you've got a microcontroller in there trying to proxy a bus of some kind but
Maybe I should introduce about the role of the spi-avmm in the system. Usually it is used in a SPI slave chip which integrates an Avalon Memory Mapped bus (Avmm bus) and several sub devices. Like the following diagram:
+-------------------------------------+ | Max10 BMC | | | | +---------+ | | +--------+ | | |subdev A | | | |subdev B| | | |register |----|Avmm|----|register| | | |space | |bus | |space | | | |(Avmm | | | |(Avmm | | +---------+ | | Slave) | | | | Slave) | | | | | +---------+ | | +--------+ | | Host | | | | | | system | | +---------+ | | +--------| | | | |Embedded |----| |------|spi-avmm| | | | |processor| | | |bridge | |------+ | | | (Avmm | | | |(Avmm |----|spi | | | | Master)| | Master)| |master| | | +---------+ +--------| |------+ | | | | | +-------------------------------------+ +---------+
In order for the host to access the sub device's register space, the spi-avmm IP is needed to receive the formatted byte stream from host, convert them to internal Avmm RW, and send back results to host.
Quoted 2 lines
there looks to be a lot of abstraction layers simply within the software here which make things hard to follow. At the very least there doesn't
We need to follow the 3 layers protocol for register accessing. On SPI slave side, spi-avmm HW finishes the whole protocol encoding/decoding work. But on host side, no dedicated IP block is designed. So host need to handle all the protocol work by SW. This introduces the complexity of the driver.
We don't introduce any extra software layers, just follows the definition of 3 layers in HW spec. But I know reviewing the detail of the protocol is tedious. Maybe I should put more comments about what part of SPEC should be referenced for some piece of code. Hope this makes the review work easier.
Quoted 7 lines
seem to be any interaction with this other than proxying stuff. As things stand this would be the largest regmap bus implementation by an order of magnitude.
It is not clear to me that this is really a generic thing that will have multiple users and that it shouldn't be implemented as
reg_read()andreg_write()operations in the driver that uses it.
This spi-avmm IP is not dedicated to the intel Max10 bmc. It is a soft IP provided in Altera (now Intel) IP library. It could be implemented on FPGA/CPLDs according to designers need. Actually Max10 is the CPLD chip which is programed to have this IP on it.
I think it may be good to implement the regmap to support any SPI chips with this IP.
Another thing is, the Max10 could integrate some sub devices (soft IPs) which are already supported by platform drivers. Using the regmap could make the sub devices supported by these drivers in a generic way, just like the way we do in recent spi-altera patchset.
Quoted 6 lines
drivers/base/regmap/Kconfig config REGMAP_SCCB · line 59
Quoted 4 lines
drivers/base/regmap/Kconfig +3
-0+config REGMAP_SPI_AVMM + tristate + depends on SPINote that for selected symbols dependencies don't take effect.
I see. So should I change something here? I see the same case for other regmap options.
Quoted 8 lines
drivers/base/regmap/regmap-spi-avmm.c line 3
Quoted 5 lines
drivers/base/regmap/regmap-spi-avmm.c new file +3
-0@@ -0,0 +1,932 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for Intel SPI Slave to AVMM Bus Bridge Please make the entire comment a C++ one so things look omre intentional.
Yes I'll change it.
Quoted 6 lines
drivers/base/regmap/regmap-spi-avmm.c line 26
Quoted 4 lines
drivers/base/regmap/regmap-spi-avmm.c new file +3
-0+* Reference Documents could be found at: +* https://www.intel.com/content/www/us/en/programmable/documentation/ +* sfo1400787952932.html Please don't corrupt links like this, that makes them harder to use.
I see. No wrapper for the URL.
Quoted 20 lines
Quoted 9 lines
drivers/base/regmap/regmap-spi-avmm.c new file +7
-0+* The main function of the physical layer is the use of PHY_IDLE (4a). Host +* issues SCLK to query data from slave, but if slave is not ready to submit +* data yet, it will repeat PHY_IDLE until data is prepared. +* Because of this special char, it also needs an ESCAPE char (4d), to help +* represent data "4a". The escape rule is "4d first, following 4a ^ 20". +* So "4d, 6a" for data "4a", and "4d, 6d" for data "4d". +* The packet layer defines the boundary of a whole packet. It defines the drivers/base/regmap/regmap-spi-avmm.c line 57
Quoted 10 lines
drivers/base/regmap/regmap-spi-avmm.c new file +10
-0+* Start Of Packet (SOP, 7a) char and End Of Packet (EOP, 7b) char. Please +* note that the non-special byte after EOP is the last byte of the packet. +* The packet layer also defines a Channel char (7c) + Channel number for +* multiple channel transfer. This not currently supported by this driver. So +* host will always send "7c, 00" when needed, and will drop the packet if +* "7c, non-zero" is received. +* Finally, a packet layer ESCAPE char (7d) is also needed to represent a +* data value that is the same as the special chars. The escape rule is the +* same. The escape rule should be used if the last byte requires it. So if a +* packet ends up with data 7a, the last bytes should be "7b, 7d, 5a".
Quoted 3 lines
This comment is not particularly intelligable. I assume all these number/letter combinations are references to something - it'd be good to say what.
Yes I'll add the table of definitions of these chars referenced in HW spec.
Quoted 8 lines
drivers/base/regmap/regmap-spi-avmm.c line 178
Quoted 5 lines
drivers/base/regmap/regmap-spi-avmm.c new file +4
-0+/* slave's register addr is 32 bits */ +#define REG_SIZE 4UL +/* slave's register value is 32 bits */ +#define VAL_SIZE 4ULThese and many of the other constants are liable to conflict with something, namespacing would be good.
Yes I'll add the prefix for naming.
Quoted 15 lines
drivers/base/regmap/regmap-spi-avmm.c line 198
Quoted 13 lines
drivers/base/regmap/regmap-spi-avmm.c new file +12
-0+struct trans_header { +u8 trans_code; +u8 rsvd; +__be16 size; +__be32 addr; +}; + +struct trans_response { +u8 r_trans_code; +u8 rsvd; +__be16 size; +};Do these need to be packed?
Yes.
Quoted 6 lines
drivers/base/regmap/regmap-spi-avmm.c line 216
Quoted 4 lines
drivers/base/regmap/regmap-spi-avmm.c new file +3
-0+/* No additional chars are in transaction layer RX, just read out data */ +#define TRANS_RX_MAX (VAL_SIZE * MAX_RX_CNT) +/* Blank line before the comment.
Yes.
Quoted 6 lines
drivers/base/regmap/regmap-spi-avmm.c line 230
Quoted 3 lines
drivers/base/regmap/regmap-spi-avmm.c new file +2
-0+#define TRANS_BUF_SIZE ((TRANS_TX_MAX > TRANS_RX_MAX) ? \ + TRANS_TX_MAX : TRANS_RX_MAX)This could be more simply written using
max()couldn't it (which IIRC can also be evaluated at compile time)?
I tried to use max(), but seems it can only be used within a function. We intend to use the macro in struct definition:
struct spi_avmm_bridge {
...
char trans_buf[TRANS_BUF_SIZE];
char phy_buf[PHY_BUF_SIZE];
};It will cause the compile error with max().
Quoted 15 lines
drivers/base/regmap/regmap-spi-avmm.c line 285
Quoted 13 lines
drivers/base/regmap/regmap-spi-avmm.c new file +12
-0+/* Format a transaction layer byte stream for tx_buf */ +static void trans_tx_prepare (bool is_read,u32 reg,u16 count,u32 *wr_val, +char *tx_buf,unsigned int *tx_len) +{ +struct trans_header *header; +u8 trans_code; +__le32 *data; +int i; + + trans_code = is_read ? + (count ==1 ?TRANS_CODE_READ :TRANS_CODE_SEQ_READ ) : + (count ==1 ?TRANS_CODE_WRITE :TRANS_CODE_SEQ_WRITE );Please write this using normal conditional statements for legibility.
Yes.
Quoted 4 lines
drivers/base/regmap/regmap-spi-avmm.c line 287
Quoted 2 lines
drivers/base/regmap/regmap-spi-avmm.c new file +1
-0+ header = (struct trans_header *)tx_buf;No need to cast away from char *.
Yes.
Quoted 13 lines
Quoted 13 lines
drivers/base/regmap/regmap-spi-avmm.c new file +12
-0+/* +* The input is a transaction layer byte stream in rx_buf, the output is read +* out data. +*/ +static int trans_rx_parse (bool is_read,char *rx_buf,unsigned int rx_len, +u16 expected_count,u32 *rd_val) +{ +unsigned int expected_len = expected_count *VAL_SIZE ; + +if (is_read) { +if (expected_len != rx_len) +return -EINVAL ;
Quoted 8 lines
drivers/base/regmap/regmap-spi-avmm.c line 373
Quoted 6 lines
drivers/base/regmap/regmap-spi-avmm.c new file +6
-0+ +return rd_trans_rx_parse (rx_buf, rx_len, rd_val); + } + +return wr_trans_rx_parse (rx_buf, rx_len, expected_len); +}Please write the
is_readcheck as an if/else, it'd be clearer.
Yes.
Quoted 15 lines
drivers/base/regmap/regmap-spi-avmm.c line 384
Quoted 11 lines
drivers/base/regmap/regmap-spi-avmm.c new file +10
-0+/* Packet Layer & Physical Layer */ +/* The input is a trans stream in trans_buf, format a phy stream in phy_buf. */ +static void pkt_phy_tx_prepare (char *trans_buf,unsigned int trans_len, +char *phy_buf,unsigned int *phy_len) +{ +unsigned int i; +char *b, *p; + + b = trans_buf; + p = phy_buf;I'm not seeing any bounds checking on the size of an operation in this function and I think I'd expect some, similarly for a lot of the other I/O operations.
I have caculated and allocated 2 buffers that are large enough to contain any possible data stream for regmap_bus.max_raw_read/write. See the definition of TRANS_BUF_SIZE & PHY_BUF_SIZE.
So maybe we don't have to check the length?
Quoted 9 lines
drivers/base/regmap/regmap-spi-avmm.c line 586
Quoted 3 lines
drivers/base/regmap/regmap-spi-avmm.c new file +2
-0+ poll_timeout = jiffies +SPI_AVMM_XFER_TIMEOUT ; +for (;;) {Please rewrite this loop so it's clear that it terminates, usually that'd mean a do { } while (!timeout) type construction. The extra effort involved in doing one more check after timeout could just as well be a slightly longer timeout and it'd be clearer.
Quoted 16 lines
drivers/base/regmap/regmap-spi-avmm.c line 611
Quoted 11 lines
drivers/base/regmap/regmap-spi-avmm.c new file +11
-0+/* +* We timeout when rx is invalid for some time. But +* it is possible we are scheduled out for long time +* after a spi_read. So when we are scheduled in, a SW +* timeout happens. But actually HW may have worked fine and +* has been ready long time ago. So we need to do an extra +* read, if we get a valid word we return a valid rx word, +* otherwise real a HW issue happens. +*/ +if (time_after (jiffies, poll_timeout)) + last_try = true;If the system is that heavily loaded I fear there's bigger problems, you could also express the timeout in terms of number of times you poll with a delay (at the minute this will busy wait which doesn't seem ideal either).
Actually this is to fix issue found on systems with Realtime kernel patchset. In the system you may be scheduled out for enough long time as long as the higher priority tasks keep running. In that case the slightly longer timeout didn't work. The number of times delay is not a good solution either. So I still want to keep the last_try machanism. But I'll try my best to rewrite this to make it clear when it terminates.
Quoted 13 lines
Quoted 13 lines
drivers/base/regmap/regmap-spi-avmm.c new file +12
-0+static void br_tx_prepare (struct spi_avmm_bridge *br,bool is_read,u32 reg, +u16 count,u32 *wr_val) +{ +unsigned int tx_len; + +trans_tx_prepare (is_read, reg, count, wr_val, + br->trans_buf, &tx_len); +pkt_phy_tx_prepare (br->trans_buf, tx_len, + br->phy_buf, &tx_len); +phy_tx_pad (br->word_len, br->phy_buf, tx_len, &tx_len); + + br->phy_len = tx_len;
Quoted 8 lines
Quoted 1 line
+}
This is the sort of thing I'm looking at when I say this code has too many abstraction layers, this function and all of the functions it calls have exactly one caller spread out all over the code and I can't help but think that some of them could be usefully inlined. As things stand it's really hard to tell what any individual bit of code is supposed to be doing or if it's doing it correctly.
OK. I'll try to refactor the code and remove unnecessary function calls, only keep the functions that represents the steps clearly defined in HW spec, and add some comments about what part of spec they are referenced.
Quoted 9 lines
drivers/base/regmap/regmap-spi-avmm.c line 763
Quoted 7 lines
drivers/base/regmap/regmap-spi-avmm.c new file +6
-0+ ret = ret ? : (eop ?0 : -EINVAL ); +if (ret) { +dev_err (&br->spi->dev,"%s br txrx err %d\n" , __func__, ret); +print_hex_dump (KERN_DEBUG ,"phy rx:" ,DUMP_PREFIX_OFFSET , +16 ,1 , br->phy_buf, rx_len, true); + }Please write normal conditional statements for legibility.
Yes.
Quoted 9 lines
drivers/base/regmap/regmap-spi-avmm.c line 785
Quoted 6 lines
drivers/base/regmap/regmap-spi-avmm.c new file +5
-0+ +#define do_reg_read (_ctx, _reg, _value, _count) \ + do_reg_access(_ctx, true, _reg, _value, _count) +#define do_reg_write (_ctx, _reg, _value, _count) \ + do_reg_access(_ctx, false, _reg, _value, _count)Please write these as proper functions so that the compiler can check things more thoroughly.
Yes
Quoted 13 lines
drivers/base/regmap/regmap-spi-avmm.c line 808
Quoted 11 lines
drivers/base/regmap/regmap-spi-avmm.c new file +10
-0+static int regmap_spi_avmm_gather_write (void *context, +const void *reg_buf,size_t reg_len, +const void *val_buf,size_t val_len) +{ +if (reg_len !=REG_SIZE ) +return -EINVAL ; + +return do_reg_write (context, *(u32 *)reg_buf, (u32 *)val_buf, + (u16)(val_len /VAL_SIZE )); +}The cast on the length looks worrying...
OK, I'll reconsider the do_reg_access definition. Cast to u16 here seems a little confusing.
Quoted 8 lines
drivers/base/regmap/regmap-spi-avmm.c line 840
Quoted 4 lines
drivers/base/regmap/regmap-spi-avmm.c new file +3
-0+/* Only support BPW == 8 or 32 now */ +if (spi->bits_per_word !=8 && spi->bits_per_word !=32 ) +return ERR_PTR (-EINVAL );Most controllers support configurable bits per word (and modes) - you shouldn't be rejecting things based on whatever the default happens to be.
I'm not sure if it is good that the spi_avmm_regmap_init changes the configuration of spi devices silently.
In my current implementation, the spi device driver should be aware and choose the right spi setup before trying to init the regmap. Would it be too hard for other drivers to use it?
Quoted 14 lines
Quoted 14 lines
drivers/base/regmap/regmap-spi-avmm.c new file +13
-0+static const struct regmap_bus regmap_spi_avmm_bus = { + .write = regmap_spi_avmm_write, + .gather_write = regmap_spi_avmm_gather_write, + .read = regmap_spi_avmm_read, + .reg_format_endian_default =REGMAP_ENDIAN_NATIVE , + .val_format_endian_default =REGMAP_ENDIAN_NATIVE , + .max_raw_read =VAL_SIZE *MAX_RX_CNT , + .max_raw_write =VAL_SIZE *MAX_TX_CNT , + + .reg_write = regmap_spi_avmm_reg_write, + .reg_read = regmap_spi_avmm_reg_read, + + .free_context = spi_avmm_bridge_ctx_free,
Quoted 8 lines
Quoted 1 line
+};
This seems confused, you shouldn't have both unformatted I/O operations and register I/O operations. Either the hardware implements a byte stream and the core will handle formatting register operations into that byte stream or the hardware understands registers and values in which case there shouldn't be unformatted operations. A combination of the two is not going to work well.
I see. We implemented the byte stream callbacks because we need to support incremental register read/write mode. I'll remove the reg_write/read callbacks.
Thanks,
Yilun
Mark Brown
maintainerRe: [PATCH v2 1/3] regmap: add Intel SPI Slave to AVMM Bus Bridge support
Quoted 11 lines · Xu Yilun
Quoted 2 lines · Mark Brown
there looks to be a lot of abstraction layers simply within the software here which make things hard to follow. At the very least there doesn't
We need to follow the 3 layers protocol for register accessing. On SPI slave side, spi-avmm HW finishes the whole protocol encoding/decoding work. But on host side, no dedicated IP block is designed. So host need to handle all the protocol work by SW. This introduces the complexity of the driver.
Quoted 5 lines
We don't introduce any extra software layers, just follows the definition of 3 layers in HW spec. But I know reviewing the detail of the protocol is tedious. Maybe I should put more comments about what part of SPEC should be referenced for some piece of code. Hope this makes the review work easier.
You don't need to reflect all the layers that the system has in the software, if some of the layers are always used together with no possibility of replacing them then it can make sense to collapse them in software. That did seem to be the case here.
Quoted 8 lines
Quoted 5 lines
drivers/base/regmap/Kconfig config REGMAP_SCCB · line 59
Quoted 3 lines
drivers/base/regmap/Kconfig +3
-0+config REGMAP_SPI_AVMM + tristate + depends on SPINote that for selected symbols dependencies don't take effect.
I see. So should I change something here? I see the same case for other regmap options.
It's fine, just be aware that you still need to have appropriate dependencies and selects in the user.
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/base/regmap/regmap-spi-avmm.c new file +5
-0+/* The input is a trans stream in trans_buf, format a phy stream in phy_buf. */ +static void pkt_phy_tx_prepare (char *trans_buf,unsigned int trans_len, +char *phy_buf,unsigned int *phy_len) +{ +unsigned int i;Quoted 8 lines
drivers/base/regmap/regmap-spi-avmm.c line 384
Quoted 4 lines
drivers/base/regmap/regmap-spi-avmm.c new file +4
-0+char *b, *p; + + b = trans_buf; + p = phy_buf;I'm not seeing any bounds checking on the size of an operation in this function and I think I'd expect some, similarly for a lot of the other I/O operations.
Quoted 5 lines
I have caculated and allocated 2 buffers that are large enough to contain any possible data stream for regmap_bus.max_raw_read/write. See the definition of
TRANS_BUF_SIZE&PHY_BUF_SIZE.So maybe we don't have to check the length?
This isn't at all clear looking at the code, perhaps it would be clearer with fewer layers of abstraction but at the minute it's a lot of effort to confirm if it's safe.
Quoted 9 lines
Quoted 6 lines
drivers/base/regmap/regmap-spi-avmm.c line 840
Quoted 2 lines
drivers/base/regmap/regmap-spi-avmm.c new file +2
-0+if (spi->bits_per_word !=8 && spi->bits_per_word !=32 ) +return ERR_PTR (-EINVAL );Most controllers support configurable bits per word (and modes) - you shouldn't be rejecting things based on whatever the default happens to be.
I'm not sure if it is good that the
spi_avmm_regmap_initchanges the configuration of spi devices silently.
That's the expected usage.
Quoted 3 lines
In my current implementation, the spi device driver should be aware and choose the right spi setup before trying to init the regmap. Would it be too hard for other drivers to use it?
It'd be duplicated effort in all the users, if the only way to use the bus is with this configuration then simply saying that they're using the bus should be enough.
Xu Yilun
maintainerRe: [PATCH v2 1/3] regmap: add Intel SPI Slave to AVMM Bus Bridge support
Quoted 18 lines · Mark Brown
Quoted 11 lines · Xu Yilun
Quoted 2 lines · Mark Brown
there looks to be a lot of abstraction layers simply within the software here which make things hard to follow. At the very least there doesn't
We need to follow the 3 layers protocol for register accessing. On SPI slave side, spi-avmm HW finishes the whole protocol encoding/decoding work. But on host side, no dedicated IP block is designed. So host need to handle all the protocol work by SW. This introduces the complexity of the driver.
Quoted 5 lines
We don't introduce any extra software layers, just follows the definition of 3 layers in HW spec. But I know reviewing the detail of the protocol is tedious. Maybe I should put more comments about what part of SPEC should be referenced for some piece of code. Hope this makes the review work easier.
Quoted 4 lines
You don't need to reflect all the layers that the system has in the software, if some of the layers are always used together with no possibility of replacing them then it can make sense to collapse them in software. That did seem to be the case here.
OK. I understand your point.
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
drivers/base/regmap/Kconfig config REGMAP_SCCB · line 59
Quoted 4 lines
drivers/base/regmap/Kconfig +3
-0+config REGMAP_SPI_AVMM + tristate + depends on SPINote that for selected symbols dependencies don't take effect.
Quoted 5 lines
Quoted 2 lines
I see. So should I change something here? I see the same case for other regmap options.
It's fine, just be aware that you still need to have appropriate dependencies and selects in the user.
OK. Thanks for the reminding.
Quoted 19 lines
Quoted 18 lines
Quoted 14 lines
drivers/base/regmap/regmap-spi-avmm.c line 384
Quoted 10 lines
drivers/base/regmap/regmap-spi-avmm.c new file +9
-0+/* The input is a trans stream in trans_buf, format a phy stream in phy_buf. */ +static void pkt_phy_tx_prepare (char *trans_buf,unsigned int trans_len, +char *phy_buf,unsigned int *phy_len) +{ +unsigned int i; +char *b, *p; + + b = trans_buf; + p = phy_buf;I'm not seeing any bounds checking on the size of an operation in this function and I think I'd expect some, similarly for a lot of the other I/O operations.
I have caculated and allocated 2 buffers that are large enough to contain any possible data stream for regmap_bus.max_raw_read/write. See the definition of
TRANS_BUF_SIZE&PHY_BUF_SIZE.
Quoted 5 lines
Quoted 1 line
So maybe we don't have to check the length?
This isn't at all clear looking at the code, perhaps it would be clearer with fewer layers of abstraction but at the minute it's a lot of effort to confirm if it's safe.
OK. I'll add the check.
Quoted 13 lines
Quoted 10 lines
Quoted 7 lines
drivers/base/regmap/regmap-spi-avmm.c line 840
Quoted 3 lines
drivers/base/regmap/regmap-spi-avmm.c new file +2
-0+if (spi->bits_per_word !=8 && spi->bits_per_word !=32 ) +return ERR_PTR (-EINVAL );Most controllers support configurable bits per word (and modes) - you shouldn't be rejecting things based on whatever the default happens to be.
I'm not sure if it is good that the
spi_avmm_regmap_initchanges the configuration of spi devices silently.That's the expected usage.
Quoted 7 lines
Quoted 3 lines
In my current implementation, the spi device driver should be aware and choose the right spi setup before trying to init the regmap. Would it be too hard for other drivers to use it?
It'd be duplicated effort in all the users, if the only way to use the bus is with this configuration then simply saying that they're using the bus should be enough.
OK. I could add the spi_setup on init.
Xu Yilun
maintainerPATCH v2 2/3 regmap: spi-avmm: start with the last SOP on phy rx buffer parsing
In reply to Xu YilunFrom: Matthew Gerlach <[email protected]>
This patch works around a bug in the SPI Slave to Avalon Master bridge. The SPI slave will send an unexpected extra SOP in the following case.
One in approximately one million read requests results in an apparant stall on the avalon bus where the SPI slave inserts IDLE characters. When the stall is over, the slave sends an extra SOP character instead of the 0x7c indicating channel. The other characters are correct.
To eliminate the impact of the bug, this patch changes to look for the last SOP as the start point of the valid phy rx data.
---
v2: no change.
--- drivers/base/regmap/regmap-spi-avmm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/base/regmap/regmap-spi-avmm.c +5 -5
@@ -433,14 +433,14 @@ static int pkt_phy_rx_parse(struct device *dev, {char *b, *p; - b = phy_buf; p = trans_buf; -/* Find the SOP */ -while (b < phy_buf + phy_len && *b !=PKT_SOP ) - b++; +/* Find the last SOP */ + b = (phy_buf + phy_len) -1 ; +while (b >= phy_buf && *b !=PKT_SOP ) + b--; -if (b >= phy_buf + phy_len) { +if (b < phy_buf) {dev_err (dev,"%s no SOP\n" , __func__);return -EINVAL ; }
Signature · 1 line
2.7.4
Mark Brown
maintainerRe: [PATCH v2 2/3] regmap: spi-avmm: start with the last SOP on phy rx buffer parsing
Quoted 4 lines · Xu Yilun
From: Matthew Gerlach <[email protected]>
This patch works around a bug in the SPI Slave to Avalon Master bridge. The SPI slave will send an unexpected extra SOP in the following case.
This is fixing a bug introduced in patch 1 - just send a version of patch 1 that works, don't incrementally fix it.
Xu Yilun
maintainerPATCH v2 3/3 mfd: intel-m10-bmc: add Max10 BMC chip support for Intel FPGA PAC
In reply to Xu YilunThis patch implements the basic functions of the BMC chip for some Intel FPGA PCIe Acceleration Cards (PAC). The BMC is implemented using the intel max10 CPLD.
This BMC chip is connected to FPGA by a SPI bus. To provide reliable register access from FPGA, an Avalon Memory-Mapped (Avmm) transaction protocol over the SPI bus is used between host and slave.
This driver implements the basic register access using the regmap-spi-avmm. The mfd cells array is empty now as a placeholder.
---
v2: Split out the regmap-spi-avmm part.
Rename the file intel-m10-bmc-main.c to intel-m10-bmc.c, cause
there is only one source file left for this module now.
--- .../ABI/testing/sysfs-driver-intel-m10-bmc | 15 ++ drivers/mfd/Kconfig | 13 ++ drivers/mfd/Makefile | 2 + drivers/mfd/intel-m10-bmc.c | 174 +++++++++++++++++++++ include/linux/mfd/intel-m10-bmc.h | 57 +++++++ 5 files changed, 261 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-intel-m10-bmc create mode 100644 drivers/mfd/intel-m10-bmc.c create mode 100644 include/linux/mfd/intel-m10-bmc.h
Documentation/ABI/testing/sysfs-driver-intel-m10-bmc new file +15 -0
@@ -0,0 +1,15 @@ +What: /sys/bus/spi/devices/.../bmc_version +Date: June 2020 +KernelVersion: 5.9 +Contact: Xu Yilun <[email protected]> +Description: Read only. Returns the hardware build version of Intel + MAX10 BMC chip. + Format: "0x%x". + +What: /sys/bus/spi/devices/.../bmcfw_version +Date: June 2020 +KernelVersion: 5.9 +Contact: Xu Yilun <[email protected]> +Description: Read only. Returns the firmware version of Intel MAX10 + BMC chip. + Format: "0x%x".
drivers/mfd/Kconfig +13 -0
@@ -2130,5 +2130,18 @@ config SGI_MFD_IOC3 If you have an SGI Origin, Octane, or a PCI IOC3 card, then say Y. Otherwise say N. +config MFD_INTEL_M10_BMC + tristate "Intel MAX10 board management controller" + depends on SPI_MASTER + select REGMAP_SPI_AVMM + select MFD_CORE + help + Support for the Intel MAX10 board management controller using the + SPI interface. + + This driver provides common support for accessing the device, + additional drivers must be enabled in order to use the functionality + of the device. + endmenu endif
drivers/mfd/Makefile +2 -0
@@ -265,3 +265,5 @@ obj-$(CONFIG_MFD_STMFX) += stmfx.o obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o + +obj-$(CONFIG_MFD_INTEL_M10_BMC) += intel-m10-bmc.o
drivers/mfd/intel-m10-bmc.c new file +174 -0
174 lines not on this page · raw message
include/linux/mfd/intel-m10-bmc.h new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v2 3/3] mfd: intel-m10-bmc: add Max10 BMC chip support for Intel FPGA PAC
Quoted 37 lines · Xu Yilun
This patch implements the basic functions of the BMC chip for some Intel FPGA PCIe Acceleration Cards (PAC). The BMC is implemented using the intel max10 CPLD.
This BMC chip is connected to FPGA by a SPI bus. To provide reliable register access from FPGA, an Avalon Memory-Mapped (Avmm) transaction protocol over the SPI bus is used between host and slave.
This driver implements the basic register access using the regmap-spi-avmm. The mfd cells array is empty now as a placeholder.
Signed-off-by Xu Yilun <[email protected]>Signed-off-by Wu Hao <[email protected]>Signed-off-by Matthew Gerlach <[email protected]>Signed-off-by Russ Weight <[email protected]>Signed-off-by Tom Rix <[email protected]>---
v2: Split out the regmap-spi-avmm part.
Rename the fileintel-m10-bmc-main.ctointel-m10-bmc.c, cause
there is only one source file left for this module now.--- .../ABI/testing/sysfs-driver-intel-m10-bmc | 15 ++ drivers/mfd/Kconfig | 13 ++ drivers/mfd/Makefile | 2 + drivers/mfd/intel-m10-bmc.c | 174 +++++++++++++++++++++ include/linux/mfd/intel-m10-bmc.h | 57 +++++++ 5 files changed, 261 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-intel-m10-bmc create mode 100644 drivers/mfd/intel-m10-bmc.c create mode 100644 include/linux/mfd/intel-m10-bmc.hDocumentation/ABI/testing/sysfs-driver-intel-m10-bmc new file +0
-0
Documentation/ABI/testing/sysfs-driver-intel-m10-bmc line 1
Quoted 1 line
Documentation/ABI/testing/sysfs-driver-intel-m10-bmc new file +1
-0@@ -0,0 +1,15 @@ +What: /sys/bus/spi/devices/.../bmc_version
Why is this in your MFD patch?
Again, this looks like it's documenting a SPI device?
Quoted 14 lines
Documentation/ABI/testing/sysfs-driver-intel-m10-bmc new file +14
-0+Date: June 2020 +KernelVersion: 5.9 +Contact: Xu Yilun <[email protected]> +Description: Read only. Returns the hardware build version of Intel + MAX10 BMC chip. + Format: "0x%x". + +What: /sys/bus/spi/devices/.../bmcfw_version +Date: June 2020 +KernelVersion: 5.9 +Contact: Xu Yilun <[email protected]> +Description: Read only. Returns the firmware version of Intel MAX10 + BMC chip. + Format: "0x%x".
[...]
drivers/mfd/Kconfig config SGI_MFD_IOC3 · line 2134
Quoted 10 lines
drivers/mfd/Kconfig +2
-0@@ -2130,5 +2130,18 @@ config SGI_MFD_IOC3 If you have an SGI Origin, Octane, or a PCI IOC3 card, then say Y. Otherwise say N. +config MFD_INTEL_M10_BMC + tristate "Intel MAX10 board management controller"
"Board Management Controller"
Quoted 29 lines
drivers/mfd/Kconfig +11
-0+ depends on SPI_MASTER + select REGMAP_SPI_AVMM + select MFD_CORE + help + Support for the Intel MAX10 board management controller using the + SPI interface. + + This driver provides common support for accessing the device, + additional drivers must be enabled in order to use the functionality + of the device. + endmenu endifdrivers/mfd/Makefile +2
-0@@ -265,3 +265,5 @@ obj-$(CONFIG_MFD_STMFX) += stmfx.o obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o + +obj-$(CONFIG_MFD_INTEL_M10_BMC) += intel-m10-bmc.odrivers/mfd/intel-m10-bmc.c new file +0
-0
drivers/mfd/intel-m10-bmc.c line 3
Quoted 3 lines
drivers/mfd/intel-m10-bmc.c new file +3
-0@@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Intel Max10 Board Management Controller chip Driver
Drop "Driver"
drivers/mfd/intel-m10-bmc.c line 15
Quoted 11 lines
drivers/mfd/intel-m10-bmc.c new file +11
-0+* Copyright (C) 2018-2020 Intel Corporation. All rights reserved. +* +*/ +#include <linux/bitfield.h> +#include <linux/mutex.h> +#include <linux/regmap.h> +#include <linux/module.h> +#include <linux/mfd/core.h> +#include <linux/init.h> +#include <linux/spi/spi.h> +#include <linux/mfd/intel-m10-bmc.h>
Alphabetical.
drivers/mfd/intel-m10-bmc.c line 19
Quoted 3 lines
drivers/mfd/intel-m10-bmc.c new file +3
-0+enum m10bmc_type { +M10_N3000 , +};
Will there be others?
Quoted 53 lines
drivers/mfd/intel-m10-bmc.c new file +53
-0+static struct mfd_cell m10bmc_pacn3000_subdevs[] = {}; + +static struct regmap_config intel_m10bmc_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =M10BMC_MEM_END , +}; + +static ssize_t bmc_version_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct intel_m10bmc *m10bmc =dev_get_drvdata (dev); +unsigned int val; +int ret; + + ret =m10bmc_sys_read (m10bmc,M10BMC_BUILD_VER , &val); +if (ret) +return ret; + +return sprintf (buf,"0x%x\n" , val); +} +static DEVICE_ATTR_RO (bmc_version); + +static ssize_t bmcfw_version_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct intel_m10bmc *max10 =dev_get_drvdata (dev); +unsigned int val; +int ret; + + ret =m10bmc_sys_read (max10,NIOS2_FW_VERSION , &val); +if (ret) +return ret; + +return sprintf (buf,"0x%x\n" , val); +} +static DEVICE_ATTR_RO (bmcfw_version); + +static struct attribute *m10bmc_attrs[] = { + &dev_attr_bmc_version.attr, + &dev_attr_bmcfw_version.attr, +NULL , +}; + +static struct attribute_group m10bmc_attr_group = { + .attrs = m10bmc_attrs, +}; + +static const struct attribute_group *m10bmc_dev_groups[] = { + &m10bmc_attr_group, +NULL +};
drivers/mfd/intel-m10-bmc.c line 83
Quoted 10 lines
drivers/mfd/intel-m10-bmc.c new file +10
-0+ +static int check_m10bmc_version (struct intel_m10bmc *m10bmc) +{ +unsigned int v; + +if (m10bmc_raw_read (m10bmc,M10BMC_LEGACY_SYS_BASE +M10BMC_BUILD_VER , + &v)) +return -ENODEV ; + +if (v !=0xffffffff ) {
So the only supported version number is all 1's?
Quoted 7 lines
drivers/mfd/intel-m10-bmc.c new file +7
-0+dev_err (m10bmc->dev,"bad version M10BMC detected\n" ); +return -ENODEV ; + } + +return 0 ; +} +
drivers/mfd/intel-m10-bmc.c line 100
Quoted 10 lines
drivers/mfd/intel-m10-bmc.c new file +10
-0+static int m10bmc_spi_setup (struct spi_device *spi) +{ +/* try 32 bits bpw first then fall back to 8 bits bpw */ + spi->mode =SPI_MODE_1 ; + spi->bits_per_word =32 ; +if (!spi_setup (spi)) +return 0 ; + + spi->bits_per_word =8 ; +return spi_setup (spi);
Looks odd. Comments needed.
Quoted 30 lines
drivers/mfd/intel-m10-bmc.c new file +30
-0+} + +static int intel_m10_bmc_spi_probe (struct spi_device *spi) +{ +const struct spi_device_id *id =spi_get_device_id (spi); +struct device *dev = &spi->dev; +struct mfd_cell *cells; +struct intel_m10bmc *m10bmc; +int ret, n_cell; + + ret =m10bmc_spi_setup (spi); +if (ret) +return ret; + + m10bmc =devm_kzalloc (dev,sizeof (*m10bmc),GFP_KERNEL ); +if (!m10bmc) +return -ENOMEM ; + + m10bmc->dev = dev; + + m10bmc->regmap = +devm_regmap_init_spi_avmm (spi, &intel_m10bmc_regmap_config); +if (IS_ERR (m10bmc->regmap)) { + ret =PTR_ERR (m10bmc->regmap); +dev_err (dev,"Failed to allocate regmap: %d\n" , ret); +return ret; + } + +spi_set_drvdata (spi, m10bmc); +
drivers/mfd/intel-m10-bmc.c line 140
Quoted 10 lines
drivers/mfd/intel-m10-bmc.c new file +10
-0+ ret =check_m10bmc_version (m10bmc); +if (ret) { +dev_err (dev,"Failed to identify m10bmc hardware\n" ); +return ret; + } + +switch (id->driver_data) { +case M10_N3000 : + cells = m10bmc_pacn3000_subdevs; + n_cell =ARRAY_SIZE (m10bmc_pacn3000_subdevs);
This is just an empty cell though, right?
I'm not even sure why this doesn't just crash.
drivers/mfd/intel-m10-bmc.c line 147
Quoted 7 lines
drivers/mfd/intel-m10-bmc.c new file +7
-0+break ; +default : +return -ENODEV ; + } + + ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_AUTO , cells, n_cell, +NULL ,0 ,NULL );
What sub-devices does this actually register?
Quoted 75 lines
drivers/mfd/intel-m10-bmc.c new file +27
-0+if (ret) +dev_err (dev,"Failed to register sub-devices: %d\n" , ret); + +return ret; +} + +static const struct spi_device_id m10bmc_spi_id[] = { + {"m10-n3000" ,M10_N3000 }, + { } +}; +MODULE_DEVICE_TABLE (spi, m10bmc_spi_id); + +static struct spi_driver intel_m10bmc_spi_driver = { + .driver = { + .name ="intel-m10-bmc" , + .dev_groups = m10bmc_dev_groups, + }, + .probe = intel_m10_bmc_spi_probe, + .id_table = m10bmc_spi_id, +}; + +module_spi_driver (intel_m10bmc_spi_driver); + +MODULE_DESCRIPTION ("Intel Max10 BMC Device Driver" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("spi:intel-m10-bmc" );include/linux/mfd/intel-m10-bmc.h new file +42
-0@@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Driver Header File for Intel Max10 Board Management Controller chip. +* +* Copyright (C) 2018-2020 Intel Corporation, Inc. +* +*/ +#ifndef __INTEL_M10_BMC_H +#define __INTEL_M10_BMC_H + +#include <linux/regmap.h> + +#define M10BMC_LEGACY_SYS_BASE 0x300400 +#define M10BMC_SYS_BASE 0x300800 +#define M10BMC_MEM_END 0x200000fc + +/* Register offset of system registers */ +#define NIOS2_FW_VERSION 0x0 +#define M10BMC_TEST_REG 0x3c +#define M10BMC_BUILD_VER 0x68 +#define M10BMC_VER_MAJOR_MSK GENMASK(23, 16) +#define M10BMC_VER_PCB_INFO_MSK GENMASK(31, 24) + +/** +* struct intel_m10bmc - Intel Max10 BMC MFD device private data structure +* @dev: this device +* @regmap: the regmap used to access registers by m10bmc itself +*/ +struct intel_m10bmc { +struct device *dev; +struct regmap *regmap; +}; + +/* +* register access helper functions. +* +* m10bmc_raw_read - read m10bmc register per addr +* m10bmc_sys_read - read m10bmc system register per offset +*/ +static inline int +m10bmc_raw_read (struct intel_m10bmc *m10bmc,unsigned int addr, +unsigned int *val)
include/linux/mfd/intel-m10-bmc.h line 52
Quoted 10 lines
include/linux/mfd/intel-m10-bmc.h new file +10
-0+{ +int ret; + + ret =regmap_read (m10bmc->regmap, addr, val); +if (ret) +dev_err (m10bmc->dev,"fail to read raw reg %x: %d\n" , + addr, ret); + +return ret; +}
Why are you abstracting Regmap?
Quoted 4 lines
include/linux/mfd/intel-m10-bmc.h new file +4
-0+#define m10bmc_sys_read (m10bmc, offset, val) \ + m10bmc_raw_read(m10bmc, M10BMC_SYS_BASE + (offset), val) + +#endif /* __INTEL_M10_BMC_H */
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
Xu Yilun
maintainerRe: [PATCH v2 3/3] mfd: intel-m10-bmc: add Max10 BMC chip support for Intel FPGA PAC
Quoted 43 lines · Lee Jones
Quoted 37 lines · Xu Yilun
This patch implements the basic functions of the BMC chip for some Intel FPGA PCIe Acceleration Cards (PAC). The BMC is implemented using the intel max10 CPLD.
This BMC chip is connected to FPGA by a SPI bus. To provide reliable register access from FPGA, an Avalon Memory-Mapped (Avmm) transaction protocol over the SPI bus is used between host and slave.
This driver implements the basic register access using the regmap-spi-avmm. The mfd cells array is empty now as a placeholder.
Signed-off-by Xu Yilun <[email protected]>Signed-off-by Wu Hao <[email protected]>Signed-off-by Matthew Gerlach <[email protected]>Signed-off-by Russ Weight <[email protected]>Signed-off-by Tom Rix <[email protected]>---
v2: Split out the regmap-spi-avmm part.
Rename the fileintel-m10-bmc-main.ctointel-m10-bmc.c, cause
there is only one source file left for this module now.--- .../ABI/testing/sysfs-driver-intel-m10-bmc | 15 ++ drivers/mfd/Kconfig | 13 ++ drivers/mfd/Makefile | 2 + drivers/mfd/intel-m10-bmc.c | 174 +++++++++++++++++++++ include/linux/mfd/intel-m10-bmc.h | 57 +++++++ 5 files changed, 261 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-intel-m10-bmc create mode 100644 drivers/mfd/intel-m10-bmc.c create mode 100644 include/linux/mfd/intel-m10-bmc.hDocumentation/ABI/testing/sysfs-driver-intel-m10-bmc new file +0
-0Documentation/ABI/testing/sysfs-driver-intel-m10-bmc line 1
Quoted 1 line
Documentation/ABI/testing/sysfs-driver-intel-m10-bmc new file +1
-0@@ -0,0 +1,15 @@ +What: /sys/bus/spi/devices/.../bmc_versionWhy is this in your MFD patch?
Quoted 1 line
Again, this looks like it's documenting a SPI device?
The intel-m10-bmc device is a spi device, which contains several sub devices in it, and I use the mfd APIs for subdev creating.
I see some example drivers in mfd folder which also match a spi/i2c parent device and creates the sub devices. So I think I may follow the examples and put the intel-m10-bmc driver in mfd folder.
A little difference is that the driver added 2 sysfs nodes for the parent device itself. I'm not sure how I should document the sysfs path correctly. The device is a mfd parent, but I didn't find a sysfs path that could explicitly indicate its role of mfd parent.
Do you have any suggestion on that?
Quoted 26 lines
Quoted 15 lines
Documentation/ABI/testing/sysfs-driver-intel-m10-bmc new file +14
-0+Date: June 2020 +KernelVersion: 5.9 +Contact: Xu Yilun <[email protected]> +Description: Read only. Returns the hardware build version of Intel + MAX10 BMC chip. + Format: "0x%x". + +What: /sys/bus/spi/devices/.../bmcfw_version +Date: June 2020 +KernelVersion: 5.9 +Contact: Xu Yilun <[email protected]> +Description: Read only. Returns the firmware version of Intel MAX10 + BMC chip. + Format: "0x%x".[...]
Quoted 8 lines
drivers/mfd/Kconfig +0
-0@@ -2130,5 +2130,18 @@ config SGI_MFD_IOC3 If you have an SGI Origin, Octane, or a PCI IOC3 card, then say Y. Otherwise say N.
Quoted 4 lines
drivers/mfd/Kconfig config SGI_MFD_IOC3 · line 2134
Quoted 2 lines
drivers/mfd/Kconfig +2
-0+config MFD_INTEL_M10_BMC + tristate "Intel MAX10 board management controller""Board Management Controller"
Yes, I'll change it.
Quoted 21 lines
Quoted 21 lines
drivers/mfd/Kconfig +11
-0+ depends on SPI_MASTER + select REGMAP_SPI_AVMM + select MFD_CORE + help + Support for the Intel MAX10 board management controller using the + SPI interface. + + This driver provides common support for accessing the device, + additional drivers must be enabled in order to use the functionality + of the device. + endmenu endifdrivers/mfd/Makefile +0
-0@@ -265,3 +265,5 @@ obj-$(CONFIG_MFD_STMFX) += stmfx.o obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o
Quoted 14 lines
drivers/mfd/intel-m10-bmc.c line 3
Quoted 12 lines
drivers/mfd/Makefile +2
-0obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o + +obj-$(CONFIG_MFD_INTEL_M10_BMC) += intel-m10-bmc.odrivers/mfd/intel-m10-bmc.c new file +3
-0@@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Intel Max10 Board Management Controller chip Driver Drop "Driver"
Yes
Quoted 14 lines
drivers/mfd/intel-m10-bmc.c line 15
Quoted 12 lines
drivers/mfd/intel-m10-bmc.c new file +11
-0+* Copyright (C) 2018-2020 Intel Corporation. All rights reserved. +* +*/ +#include <linux/bitfield.h> +#include <linux/mutex.h> +#include <linux/regmap.h> +#include <linux/module.h> +#include <linux/mfd/core.h> +#include <linux/init.h> +#include <linux/spi/spi.h> +#include <linux/mfd/intel-m10-bmc.h> Alphabetical.
Yes
Quoted 6 lines
drivers/mfd/intel-m10-bmc.c line 19
Quoted 4 lines
drivers/mfd/intel-m10-bmc.c new file +3
-0+enum m10bmc_type { +M10_N3000 , +};Will there be others?
Yes.
The M10_N3000 is for "intel pac n3000" FPGA card. There is another M10_D5005 for "intel pac d5005" FPGA card.
We may add d5005 support later on.
Quoted 58 lines
Quoted 58 lines
drivers/mfd/intel-m10-bmc.c new file +57
-0+static struct mfd_cell m10bmc_pacn3000_subdevs[] = {}; + +static struct regmap_config intel_m10bmc_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =M10BMC_MEM_END , +}; + +static ssize_t bmc_version_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct intel_m10bmc *m10bmc =dev_get_drvdata (dev); +unsigned int val; +int ret; + + ret =m10bmc_sys_read (m10bmc,M10BMC_BUILD_VER , &val); +if (ret) +return ret; + +return sprintf (buf,"0x%x\n" , val); +} +static DEVICE_ATTR_RO (bmc_version); + +static ssize_t bmcfw_version_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct intel_m10bmc *max10 =dev_get_drvdata (dev); +unsigned int val; +int ret; + + ret =m10bmc_sys_read (max10,NIOS2_FW_VERSION , &val); +if (ret) +return ret; + +return sprintf (buf,"0x%x\n" , val); +} +static DEVICE_ATTR_RO (bmcfw_version); + +static struct attribute *m10bmc_attrs[] = { + &dev_attr_bmc_version.attr, + &dev_attr_bmcfw_version.attr, +NULL , +}; + +static struct attribute_group m10bmc_attr_group = { + .attrs = m10bmc_attrs, +}; + +static const struct attribute_group *m10bmc_dev_groups[] = { + &m10bmc_attr_group, +NULL +}; + +static int check_m10bmc_version (struct intel_m10bmc *m10bmc) +{ +unsigned int v;
Quoted 8 lines
drivers/mfd/intel-m10-bmc.c line 83
Quoted 6 lines
drivers/mfd/intel-m10-bmc.c new file +6
-0+ +if (m10bmc_raw_read (m10bmc,M10BMC_LEGACY_SYS_BASE +M10BMC_BUILD_VER , + &v)) +return -ENODEV ; + +if (v !=0xffffffff ) {So the only supported version number is all 1's?
No, this is to exclude the legacy version of m10bmc.
The legacy version of m10bmc has different system register base. So if there is valid version value in the legacy version register, it is the legacy m10bmc and we filter it out.
Quoted 12 lines
Quoted 12 lines
drivers/mfd/intel-m10-bmc.c new file +11
-0+dev_err (m10bmc->dev,"bad version M10BMC detected\n" ); +return -ENODEV ; + } + +return 0 ; +} + +static int m10bmc_spi_setup (struct spi_device *spi) +{ +/* try 32 bits bpw first then fall back to 8 bits bpw */ + spi->mode =SPI_MODE_1 ;
Quoted 8 lines
drivers/mfd/intel-m10-bmc.c line 100
Quoted 6 lines
drivers/mfd/intel-m10-bmc.c new file +6
-0+ spi->bits_per_word =32 ; +if (!spi_setup (spi)) +return 0 ; + + spi->bits_per_word =8 ; +return spi_setup (spi);Looks odd. Comments needed.
OK, I'll add more comments here.
Quoted 44 lines
Quoted 31 lines
drivers/mfd/intel-m10-bmc.c new file +30
-0+} + +static int intel_m10_bmc_spi_probe (struct spi_device *spi) +{ +const struct spi_device_id *id =spi_get_device_id (spi); +struct device *dev = &spi->dev; +struct mfd_cell *cells; +struct intel_m10bmc *m10bmc; +int ret, n_cell; + + ret =m10bmc_spi_setup (spi); +if (ret) +return ret; + + m10bmc =devm_kzalloc (dev,sizeof (*m10bmc),GFP_KERNEL ); +if (!m10bmc) +return -ENOMEM ; + + m10bmc->dev = dev; + + m10bmc->regmap = +devm_regmap_init_spi_avmm (spi, &intel_m10bmc_regmap_config); +if (IS_ERR (m10bmc->regmap)) { + ret =PTR_ERR (m10bmc->regmap); +dev_err (dev,"Failed to allocate regmap: %d\n" , ret); +return ret; + } + +spi_set_drvdata (spi, m10bmc); +drivers/mfd/intel-m10-bmc.c line 140
Quoted 10 lines
drivers/mfd/intel-m10-bmc.c new file +10
-0+ ret =check_m10bmc_version (m10bmc); +if (ret) { +dev_err (dev,"Failed to identify m10bmc hardware\n" ); +return ret; + } + +switch (id->driver_data) { +case M10_N3000 : + cells = m10bmc_pacn3000_subdevs; + n_cell =ARRAY_SIZE (m10bmc_pacn3000_subdevs);This is just an empty cell though, right?
Quoted 1 line
I'm not even sure why this doesn't just crash.
Yes, I didn't add the sub device info now. I tested it will not crash, but I think I don't have to the subdev info one by one along with the sub device drivers, right? An empty cell is confusing.
Quoted 10 lines
drivers/mfd/intel-m10-bmc.c line 147
Quoted 8 lines
drivers/mfd/intel-m10-bmc.c new file +7
-0+break ; +default : +return -ENODEV ; + } + + ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_AUTO , cells, n_cell, +NULL ,0 ,NULL );What sub-devices does this actually register?
We have 3 sub devices now.
"n3000bmc-hwmon" is a set of sensors "n3000bmc-pkvl" is a set of ethernet phys "m10bmc-secure" is the secure reprograming engine for FPGA
I'll add the sub devices info in my next version.
Quoted 80 lines
Quoted 80 lines
drivers/mfd/intel-m10-bmc.c new file +27
-0+if (ret) +dev_err (dev,"Failed to register sub-devices: %d\n" , ret); + +return ret; +} + +static const struct spi_device_id m10bmc_spi_id[] = { + {"m10-n3000" ,M10_N3000 }, + { } +}; +MODULE_DEVICE_TABLE (spi, m10bmc_spi_id); + +static struct spi_driver intel_m10bmc_spi_driver = { + .driver = { + .name ="intel-m10-bmc" , + .dev_groups = m10bmc_dev_groups, + }, + .probe = intel_m10_bmc_spi_probe, + .id_table = m10bmc_spi_id, +}; + +module_spi_driver (intel_m10bmc_spi_driver); + +MODULE_DESCRIPTION ("Intel Max10 BMC Device Driver" ); +MODULE_AUTHOR ("Intel Corporation" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("spi:intel-m10-bmc" );include/linux/mfd/intel-m10-bmc.h new file +46
-0@@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Driver Header File for Intel Max10 Board Management Controller chip. +* +* Copyright (C) 2018-2020 Intel Corporation, Inc. +* +*/ +#ifndef __INTEL_M10_BMC_H +#define __INTEL_M10_BMC_H + +#include <linux/regmap.h> + +#define M10BMC_LEGACY_SYS_BASE 0x300400 +#define M10BMC_SYS_BASE 0x300800 +#define M10BMC_MEM_END 0x200000fc + +/* Register offset of system registers */ +#define NIOS2_FW_VERSION 0x0 +#define M10BMC_TEST_REG 0x3c +#define M10BMC_BUILD_VER 0x68 +#define M10BMC_VER_MAJOR_MSK GENMASK(23, 16) +#define M10BMC_VER_PCB_INFO_MSK GENMASK(31, 24) + +/** +* struct intel_m10bmc - Intel Max10 BMC MFD device private data structure +* @dev: this device +* @regmap: the regmap used to access registers by m10bmc itself +*/ +struct intel_m10bmc { +struct device *dev; +struct regmap *regmap; +}; + +/* +* register access helper functions. +* +* m10bmc_raw_read - read m10bmc register per addr +* m10bmc_sys_read - read m10bmc system register per offset +*/ +static inline int +m10bmc_raw_read (struct intel_m10bmc *m10bmc,unsigned int addr, +unsigned int *val) +{ +int ret; + + ret =regmap_read (m10bmc->regmap, addr, val);
Quoted 8 lines
include/linux/mfd/intel-m10-bmc.h line 52
Quoted 6 lines
include/linux/mfd/intel-m10-bmc.h new file +6
-0+if (ret) +dev_err (m10bmc->dev,"fail to read raw reg %x: %d\n" , + addr, ret); + +return ret; +}Why are you abstracting Regmap?
I may paste the comments from previous patch:
This spi-avmm IP is not dedicated to the intel Max10 bmc. It is a soft IP provided in Altera (now Intel) IP library. It could be implemented on FPGA/CPLDs according to designers need. Actually Max10 is the CPLD chip which is programed to have this IP on it.
I think it may be good to implement the regmap to support any SPI chips with this IP.
Another thing is, the Max10 could integrate some sub devices (soft IPs) which are already supported by platform drivers. Using the regmap could make the sub devices supported by these drivers in a generic way.
We wapper the regmap operations in an function just to help print some error info if regmap r/w fails.
Thanks,
Yilun
Quoted 11 lines
Quoted 5 lines
include/linux/mfd/intel-m10-bmc.h new file +4
-0+#define m10bmc_sys_read (m10bmc, offset, val) \ + m10bmc_raw_read(m10bmc, M10BMC_SYS_BASE + (offset), val) + +#endif /* __INTEL_M10_BMC_H */ Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
Mark Brown
maintainerRe: [PATCH v2 3/3] mfd: intel-m10-bmc: add Max10 BMC chip support for Intel FPGA PAC
In reply to Xu YilunQuoted 6 lines · Xu Yilun
drivers/mfd/intel-m10-bmc.c new file +5
-0+static const struct spi_device_id m10bmc_spi_id[] = { + {"m10-n3000" ,M10_N3000 }, + { } +}; +MODULE_DEVICE_TABLE (spi, m10bmc_spi_id);
drivers/mfd/intel-m10-bmc.c line 169
Quoted 10 lines
drivers/mfd/intel-m10-bmc.c new file +9
-0+static struct spi_driver intel_m10bmc_spi_driver = { + .driver = { + .name ="intel-m10-bmc" , + .dev_groups = m10bmc_dev_groups, + }, + .probe = intel_m10_bmc_spi_probe, + .id_table = m10bmc_spi_id, +}; +module_spi_driver (intel_m10bmc_spi_driver);
This device has no ACPI information - how will it be instantiated?
Xu Yilun
maintainerRe: [PATCH v2 3/3] mfd: intel-m10-bmc: add Max10 BMC chip support for Intel FPGA PAC
Quoted 17 lines · Mark Brown
Quoted 14 lines · Xu Yilun
drivers/mfd/intel-m10-bmc.c new file +13
-0+static const struct spi_device_id m10bmc_spi_id[] = { + {"m10-n3000" ,M10_N3000 }, + { } +}; +MODULE_DEVICE_TABLE (spi, m10bmc_spi_id); +static struct spi_driver intel_m10bmc_spi_driver = { + .driver = { + .name ="intel-m10-bmc" , + .dev_groups = m10bmc_dev_groups, + }, + .probe = intel_m10_bmc_spi_probe, + .id_table = m10bmc_spi_id, +};
Quoted 3 lines
Quoted 1 line
+module_spi_driver(intel_m10bmc_spi_driver);
This device has no ACPI information - how will it be instantiated?
In our case, The m10-bmc is connected to the intel FPGA (PAC N3000), which uses the Device Feature List (DFL) mechanism to enumerate features (devices) on FPGA. Each feature in DFL has a feature_id. And for this m10-n3000 feature (feature_id = 0xd), it contains a spi-altera & a m10-n3000 chip. So the DFL subsystem would help enumerate the info.
Recently I added the platform data for slave information in spi-altera, to support this use case.
Thanks,
Yilun
Xu Yilun
maintainerRe: [PATCH v2 3/3] mfd: intel-m10-bmc: add Max10 BMC chip support for Intel FPGA PAC
Quoted 20 lines · Xu Yilun
Quoted 19 lines · Mark Brown
Quoted 16 lines · Xu Yilun
drivers/mfd/intel-m10-bmc.c new file +14
-0+static const struct spi_device_id m10bmc_spi_id[] = { + {"m10-n3000" ,M10_N3000 }, + { } +}; +MODULE_DEVICE_TABLE (spi, m10bmc_spi_id); +static struct spi_driver intel_m10bmc_spi_driver = { + .driver = { + .name ="intel-m10-bmc" , + .dev_groups = m10bmc_dev_groups, + }, + .probe = intel_m10_bmc_spi_probe, + .id_table = m10bmc_spi_id, +}; +module_spi_driver (intel_m10bmc_spi_driver);
Quoted 7 lines
Quoted 1 line
This device has no ACPI information - how will it be instantiated?
In our case, The m10-bmc is connected to the intel FPGA (PAC N3000), which uses the Device Feature List (DFL) mechanism to enumerate features (devices) on FPGA. Each feature in DFL has a
feature_id. And for this m10-n3000 feature (feature_id=0xd), it contains a spi-altera & a m10-n3000 chip. So the DFL subsystem would help enumerate the info.
And some DFL related infomation:
Documentation/fpga/dfl.rst
drivers/fpga/dfl*
Thanks,
Yilun
Quoted 6 lines
Recently I added the platform data for slave information in spi-altera, to support this use case.
Thanks,
Yilun