Add support for Nuvoton npcm845 i3c controller
Subsystems (3)
v2 cover Add support for Nuvoton npcm845 i3c controller
This patchset adds support for the Nuvoton npcm845 Board Management controller (BMC) SoC family.
The Nuvoton npcm845 uses the same Silvico IP but an older version. This patchset adds fixes for the npcm845 specific hardware issues.
---
v2:
- Add a new compatible string in dt-binding doc.
- Add driver data for npcm845 to address the quirks.
- Modify svc_i3c_master_write to be reused by SVC_I3C_QUIRK_FIFO_EMPTY fix.
- Fix typo of SVC_I3C_QUIRK_FALSE_SLVSTART fix.
- Remove the code changes in svc_i3c_master_do_daa_locked, will add it in another patch series for common improvement.
---
Stanley Chu (4):
dt-bindings: i3c: silvaco: Add npcm845 compatible string
i3c: master: svc: Add support for Nuvoton npcm845 i3c
i3c: master: svc: Fix npcm845 FIFO empty issue
i3c: master: svc: Fix npcm845 invalid slvstart event
.../bindings/i3c/silvaco,i3c-master.yaml | 4 +- drivers/i3c/master/svc-i3c-master.c | 57 +++++++++++++++++-- 2 files changed, 56 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/4 dt-bindings: i3c: silvaco: Add npcm845 compatible string
Add a compatible string for Nuvoton BMC NPCM845 i3c controller.
--- Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml +3 -1
@@ -14,7 +14,9 @@ allOf: properties: compatible: - const: silvaco,i3c-master-v1 + enum: + - silvaco,i3c-master-v1 + - nuvoton,npcm845-i3c reg: maxItems: 1
Signature · 1 line
2.34.1
Re: [PATCH v2 1/4] dt-bindings: i3c: silvaco: Add npcm845 compatible string
Quoted 1 line · Stanley Chu
Add a compatible string for Nuvoton BMC NPCM845 i3c controller.
Why is a fallback not an option here? Your commit message should call out why not.
Quoted 25 lines
Signed-off-by Stanley Chu <[email protected]>--- Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml +3
-1@@ -14,7 +14,9 @@ allOf: properties: compatible: - const: silvaco,i3c-master-v1 + enum: + - silvaco,i3c-master-v1 + - nuvoton,npcm845-i3c reg: maxItems: 1Signature · 1 line
2.34.1
PATCH v2 2/4 i3c: master: svc: Add support for Nuvoton npcm845 i3c
In reply to Stanley ChuNuvoton npcm845 SoC uses the same Silvico IP but an older version. Add npcm845 specific quirks.
--- drivers/i3c/master/svc-i3c-master.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
drivers/i3c/master/svc-i3c-master.c +29 -0
@@ -133,6 +133,22 @@#define SVC_I3C_EVENT_IBI GENMASK(7, 0)#define SVC_I3C_EVENT_HOTJOIN BIT(31) +/* +* SVC_I3C_QUIRK_FIFO_EMPTY: +* I3C HW stalls the write transfer if the transmit FIFO becomes empty, +* when new data is written to FIFO, I3C HW resumes the transfer but +* the first transmitted data bit may have the wrong value. +* Workaround: +* Fill the FIFO in advance to prevent FIFO from becoming empty. +*/ +#define SVC_I3C_QUIRK_FIFO_EMPTY BIT(0) +/* +* SVC_I3C_QUIRK_FLASE_SLVSTART: +* I3C HW may generate an invalid SlvStart event when emitting a STOP. +* If it is a true SlvStart, the MSTATUS state should be SLVREQ. +*/ +#define SVC_I3C_QUIRK_FALSE_SLVSTART BIT(1) +struct svc_i3c_cmd {u8 addr;bool rnw;
@@ -216,6 +232,7 @@ struct svc_i3c_master {struct mutex lock;u32 enabled_events;u32 mctrl_config; +u32 quirks; };/**
@@ -230,6 +247,14 @@ struct svc_i3c_i2c_dev_data {struct i3c_generic_ibi_pool *ibi_pool; }; +struct svc_i3c_drvdata { +u32 quirks; +}; + +const struct svc_i3c_drvdata npcm845_drvdata = { + .quirks =SVC_I3C_QUIRK_FIFO_EMPTY |SVC_I3C_QUIRK_FALSE_SLVSTART , +}; +static inline bool is_events_enabled (struct svc_i3c_master *master,u32 mask) {return !!(master->enabled_events & mask);
@@ -1811,6 +1836,7 @@ static int svc_i3c_master_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct svc_i3c_master *master; +const struct svc_i3c_drvdata *data =of_device_get_match_data (dev);int ret; master =devm_kzalloc (dev,sizeof (*master),GFP_KERNEL );
@@ -1868,6 +1894,8 @@ static int svc_i3c_master_probe(struct platform_device *pdev) }platform_set_drvdata (pdev, master); +if (data) + master->quirks = data->quirks;pm_runtime_set_autosuspend_delay (&pdev->dev,SVC_I3C_PM_TIMEOUT_MS );pm_runtime_use_autosuspend (&pdev->dev);
@@ -1960,6 +1988,7 @@ static const struct dev_pm_ops svc_i3c_pm_ops = {static const struct of_device_id svc_i3c_master_of_match_tbl[] = { { .compatible ="silvaco,i3c-master-v1" }, + { .compatible ="nuvoton,npcm845-i3c" , .data = &npcm845_drvdata }, {/* sentinel */ }, };MODULE_DEVICE_TABLE (of, svc_i3c_master_of_match_tbl);
Signature · 1 line
2.34.1
PATCH v2 3/4 i3c: master: svc: Fix npcm845 FIFO empty issue
In reply to Stanley ChuI3C HW stalls the write transfer if the transmit FIFO becomes empty, when new data is written to FIFO, I3C HW resumes the transfer but the first transmitted data bit may have the wrong value.
Fill the FIFO in advance to prevent FIFO from becoming empty.
--- drivers/i3c/master/svc-i3c-master.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/i3c/master/svc-i3c-master.c +18 -4
@@ -1196,8 +1196,8 @@ static int svc_i3c_master_read(struct svc_i3c_master *master,return offset; } -static int svc_i3c_master_write (struct svc_i3c_master *master, -const u8 *out,unsigned int len) +static int svc_i3c_master_write (struct svc_i3c_master *master,const u8 *out, +unsigned int len,bool last) {int offset =0 , ret;u32 mdctrl;
@@ -1214,7 +1214,7 @@ static int svc_i3c_master_write(struct svc_i3c_master *master,* The last byte to be sent over the bus must either have the * "end" bit set or be written in MWDATABE. */ -if (likely (offset < (len -1 ))) +if (likely (offset < (len -1 )) || !last)writel (out[offset++], master->regs +SVC_I3C_MWDATAB );else writel (out[offset++], master->regs +SVC_I3C_MWDATABE );
@@ -1245,6 +1245,19 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,SVC_I3C_MCTRL_RDTERM (*actual_len), master->regs + SVC_I3C_MCTRL); +if ((master->quirks &SVC_I3C_QUIRK_FIFO_EMPTY ) && !rnw && xfer_len) { +unsigned int len = xfer_len; + +if (xfer_len >SVC_I3C_FIFO_SIZE ) + len =SVC_I3C_FIFO_SIZE ; + ret =svc_i3c_master_write (master, out, len, + xfer_len <=SVC_I3C_FIFO_SIZE ); +if (ret <0 ) + goto emit_stop; + xfer_len -= len; + out += len; + } + ret =readl_poll_timeout (master->regs +SVC_I3C_MSTATUS , reg,SVC_I3C_MSTATUS_MCTRLDONE (reg),0 ,1000 );if (ret)
@@ -1306,7 +1319,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,if (rnw) ret =svc_i3c_master_read (master, in, xfer_len);else - ret =svc_i3c_master_write (master, out, xfer_len); + ret =svc_i3c_master_write (master, out, xfer_len, true);if (ret <0 ) goto emit_stop;
@@ -1333,6 +1346,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master, emit_stop:svc_i3c_master_emit_stop (master);svc_i3c_master_clear_merrwarn (master); +svc_i3c_master_flush_fifo (master);return ret; }
Signature · 1 line
2.34.1
PATCH v2 4/4 i3c: master: svc: Fix npcm845 invalid slvstart event
In reply to Stanley ChuI3C HW may generate an invalid SlvStart event when emitting a STOP. If it is a true SlvStart, the MSTATUS state should be SLVREQ. Check the MSTATUS state to ignore the false event.
--- drivers/i3c/master/svc-i3c-master.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/i3c/master/svc-i3c-master.c +6 -0
@@ -58,6 +58,7 @@#define SVC_I3C_MSTATUS 0x088#define SVC_I3C_MSTATUS_STATE (x) FIELD_GET(GENMASK(2, 0), (x))#define SVC_I3C_MSTATUS_STATE_DAA (x) (SVC_I3C_MSTATUS_STATE(x) == 5) +#define SVC_I3C_MSTATUS_STATE_SLVREQ (x) (SVC_I3C_MSTATUS_STATE(x) == 1)#define SVC_I3C_MSTATUS_STATE_IDLE (x) (SVC_I3C_MSTATUS_STATE(x) == 0)#define SVC_I3C_MSTATUS_BETWEEN (x) FIELD_GET(BIT(4), (x))#define SVC_I3C_MSTATUS_NACKED (x) FIELD_GET(BIT(5), (x))
@@ -589,6 +590,11 @@ static irqreturn_t svc_i3c_master_irq_handler(int irq, void *dev_id)/* Clear the interrupt status */ writel (SVC_I3C_MINT_SLVSTART , master->regs +SVC_I3C_MSTATUS ); +/* Ignore the false event */ +if ((master->quirks &SVC_I3C_QUIRK_FALSE_SLVSTART ) && + !SVC_I3C_MSTATUS_STATE_SLVREQ (active)) +return IRQ_HANDLED ; +svc_i3c_master_disable_interrupts (master);/* Handle the interrupt in a non atomic context */
Signature · 1 line
2.34.1