diff mbox series

[v4,9/9] hw/sd: ssi-sd: Handle the rest commands with R1b response type

Message ID 20210128063035.15674-10-bmeng.cn@gmail.com
State New
Headers show
Series hw/sd: Support block read/write in SPI mode | expand

Commit Message

Bin Meng Jan. 28, 2021, 6:30 a.m. UTC
From: Bin Meng <bin.meng@windriver.com>

Besides CMD12, the following command's reponse type is R1b:

- SET_WRITE_PROT (CMD28)
- CLR_WRITE_PROT (CMD29)
- ERASE (CMD38)

Reuse the same s->stopping to indicate a R1b reponse is needed.

Signed-off-by: Bin Meng <bin.meng@windriver.com>

---

Changes in v4:
- new patch: handle the rest commands with R1b response type

 hw/sd/ssi-sd.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Philippe Mathieu-Daudé Feb. 8, 2021, 2:08 p.m. UTC | #1
On 1/28/21 7:30 AM, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Besides CMD12, the following command's reponse type is R1b:
> 
> - SET_WRITE_PROT (CMD28)
> - CLR_WRITE_PROT (CMD29)
> - ERASE (CMD38)
> 
> Reuse the same s->stopping to indicate a R1b reponse is needed.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> 
> ---
> 
> Changes in v4:
> - new patch: handle the rest commands with R1b response type
> 
>  hw/sd/ssi-sd.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
> index 907d681d19..97ee58e20c 100644
> --- a/hw/sd/ssi-sd.c
> +++ b/hw/sd/ssi-sd.c
> @@ -194,6 +194,12 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val)
>                  /* CMD13 returns a 2-byte statuse work. Other commands
>                     only return the first byte.  */
>                  s->arglen = (s->cmd == 13) ? 2 : 1;
> +
> +                /* handle R1b */
> +                if (s->cmd == 28 || s->cmd == 29 || s->cmd == 38) {

Why not also check CMD13 for completeness?

Otherwise:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> +                    s->stopping = 1;
> +                }
> +
>                  cardstatus = ldl_be_p(longresp);
>                  status = 0;
>                  if (((cardstatus >> 9) & 0xf) < 4)
>
Bin Meng Feb. 8, 2021, 2:20 p.m. UTC | #2
Hi Philippe,

On Mon, Feb 8, 2021 at 10:08 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> On 1/28/21 7:30 AM, Bin Meng wrote:
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > Besides CMD12, the following command's reponse type is R1b:
> >
> > - SET_WRITE_PROT (CMD28)
> > - CLR_WRITE_PROT (CMD29)
> > - ERASE (CMD38)
> >
> > Reuse the same s->stopping to indicate a R1b reponse is needed.
> >
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> >
> > ---
> >
> > Changes in v4:
> > - new patch: handle the rest commands with R1b response type
> >
> >  hw/sd/ssi-sd.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
> > index 907d681d19..97ee58e20c 100644
> > --- a/hw/sd/ssi-sd.c
> > +++ b/hw/sd/ssi-sd.c
> > @@ -194,6 +194,12 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val)
> >                  /* CMD13 returns a 2-byte statuse work. Other commands
> >                     only return the first byte.  */
> >                  s->arglen = (s->cmd == 13) ? 2 : 1;
> > +
> > +                /* handle R1b */
> > +                if (s->cmd == 28 || s->cmd == 29 || s->cmd == 38) {
>
> Why not also check CMD13 for completeness?
>

I am not sure I got your point. CMD13 does not respond with R1b but R2.

> Otherwise:
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>
> > +                    s->stopping = 1;
> > +                }
> > +
> >                  cardstatus = ldl_be_p(longresp);
> >                  status = 0;
> >                  if (((cardstatus >> 9) & 0xf) < 4)
> >

Regards,
Bin
Philippe Mathieu-Daudé Feb. 8, 2021, 2:27 p.m. UTC | #3
On Mon, Feb 8, 2021 at 3:20 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Philippe,
>
> On Mon, Feb 8, 2021 at 10:08 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> >
> > On 1/28/21 7:30 AM, Bin Meng wrote:
> > > From: Bin Meng <bin.meng@windriver.com>
> > >
> > > Besides CMD12, the following command's reponse type is R1b:
> > >
> > > - SET_WRITE_PROT (CMD28)
> > > - CLR_WRITE_PROT (CMD29)
> > > - ERASE (CMD38)
> > >
> > > Reuse the same s->stopping to indicate a R1b reponse is needed.
> > >
> > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > >
> > > ---
> > >
> > > Changes in v4:
> > > - new patch: handle the rest commands with R1b response type
> > >
> > >  hw/sd/ssi-sd.c | 6 ++++++
> > >  1 file changed, 6 insertions(+)
> > >
> > > diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
> > > index 907d681d19..97ee58e20c 100644
> > > --- a/hw/sd/ssi-sd.c
> > > +++ b/hw/sd/ssi-sd.c
> > > @@ -194,6 +194,12 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val)
> > >                  /* CMD13 returns a 2-byte statuse work. Other commands
> > >                     only return the first byte.  */
> > >                  s->arglen = (s->cmd == 13) ? 2 : 1;
> > > +
> > > +                /* handle R1b */
> > > +                if (s->cmd == 28 || s->cmd == 29 || s->cmd == 38) {
> >
> > Why not also check CMD13 for completeness?
> >
>
> I am not sure I got your point. CMD13 does not respond with R1b but R2.

Forget what I wrote, you are correct =)

BTW since you have a deep understanding of SD cards, would you like to
be listed as designated reviewer in the SD/MMC section?

> > Otherwise:
> > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> >
> > > +                    s->stopping = 1;
> > > +                }
> > > +
> > >                  cardstatus = ldl_be_p(longresp);
> > >                  status = 0;
> > >                  if (((cardstatus >> 9) & 0xf) < 4)
> > >
>
> Regards,
> Bin
Bin Meng Feb. 8, 2021, 2:44 p.m. UTC | #4
HI Philippe,

On Mon, Feb 8, 2021 at 10:27 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> On Mon, Feb 8, 2021 at 3:20 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > Hi Philippe,
> >
> > On Mon, Feb 8, 2021 at 10:08 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> > >
> > > On 1/28/21 7:30 AM, Bin Meng wrote:
> > > > From: Bin Meng <bin.meng@windriver.com>
> > > >
> > > > Besides CMD12, the following command's reponse type is R1b:
> > > >
> > > > - SET_WRITE_PROT (CMD28)
> > > > - CLR_WRITE_PROT (CMD29)
> > > > - ERASE (CMD38)
> > > >
> > > > Reuse the same s->stopping to indicate a R1b reponse is needed.
> > > >
> > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > >
> > > > ---
> > > >
> > > > Changes in v4:
> > > > - new patch: handle the rest commands with R1b response type
> > > >
> > > >  hw/sd/ssi-sd.c | 6 ++++++
> > > >  1 file changed, 6 insertions(+)
> > > >
> > > > diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
> > > > index 907d681d19..97ee58e20c 100644
> > > > --- a/hw/sd/ssi-sd.c
> > > > +++ b/hw/sd/ssi-sd.c
> > > > @@ -194,6 +194,12 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val)
> > > >                  /* CMD13 returns a 2-byte statuse work. Other commands
> > > >                     only return the first byte.  */
> > > >                  s->arglen = (s->cmd == 13) ? 2 : 1;
> > > > +
> > > > +                /* handle R1b */
> > > > +                if (s->cmd == 28 || s->cmd == 29 || s->cmd == 38) {
> > >
> > > Why not also check CMD13 for completeness?
> > >
> >
> > I am not sure I got your point. CMD13 does not respond with R1b but R2.
>
> Forget what I wrote, you are correct =)
>
> BTW since you have a deep understanding of SD cards, would you like to
> be listed as designated reviewer in the SD/MMC section?

I would be honored to have a try. Thanks!

Regards,
Bin
diff mbox series

Patch

diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
index 907d681d19..97ee58e20c 100644
--- a/hw/sd/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
@@ -194,6 +194,12 @@  static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val)
                 /* CMD13 returns a 2-byte statuse work. Other commands
                    only return the first byte.  */
                 s->arglen = (s->cmd == 13) ? 2 : 1;
+
+                /* handle R1b */
+                if (s->cmd == 28 || s->cmd == 29 || s->cmd == 38) {
+                    s->stopping = 1;
+                }
+
                 cardstatus = ldl_be_p(longresp);
                 status = 0;
                 if (((cardstatus >> 9) & 0xf) < 4)