Message ID | 1450270635-27080-4-git-send-email-marcin.krzeminski@nokia.com |
---|---|
State | New |
Headers | show |
On Wed, Dec 16, 2015 at 4:57 AM, <marcin.krzeminski@nokia.com> wrote: > From: Marcin Krzeminski <marcin.krzeminski@nokia.com> > > Signed-off-by: Marcin Krzeminski <marcin.krzeminski@nokia.com> > --- > hw/block/m25p80.c | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c > index bcb66a5..5e07b57 100644 > --- a/hw/block/m25p80.c > +++ b/hw/block/m25p80.c > @@ -231,6 +231,10 @@ typedef enum { > ERASE_4K = 0x20, > ERASE_32K = 0x52, > ERASE_SECTOR = 0xd8, > + > + RESET_ENABLE = 0x66, > + RESET_MEMORY = 0x99, > + Extra blank not needed. > } FlashCMD; > > typedef enum { > @@ -258,6 +262,7 @@ typedef struct Flash { > uint8_t cmd_in_progress; > uint64_t cur_addr; > bool write_enable; > + bool reset_enable; > bool initialized; > uint8_t reset_pin; > > @@ -441,6 +446,7 @@ static void reset_memory(Flash *s) > s->pos = 0; > s->state = STATE_IDLE; > s->write_enable = false; > + s->reset_enable = false; > > DB_PRINT_L(0, "Reset done.\n"); > } > @@ -554,6 +560,14 @@ static void decode_new_cmd(Flash *s, uint32_t value) > break; > case NOP: > break; > + case RESET_ENABLE: > + s->reset_enable = true; > + break; > + case RESET_MEMORY: > + if (s->reset_enable) { > + reset_memory(s); > + } > + break; Reading an n25q256 datasheet, the RESET_ENABLE state is cancelled by commands other that RESET_ENABLE or by bouncing the CS. A way to implement this would be something like if (value != RESET_MEMORY) { s->reset_enable = false; } before the switch of value as well as clearing reset_enable in m25p80_cs. Regards, Peter > default: > qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Unknown cmd %x\n", value); > break; > @@ -696,6 +710,7 @@ static const VMStateDescription vmstate_m25p80 = { > VMSTATE_UINT8(cmd_in_progress, Flash), > VMSTATE_UINT64(cur_addr, Flash), > VMSTATE_BOOL(write_enable, Flash), > + VMSTATE_BOOL(reset_enable, Flash), > VMSTATE_BOOL(initialized, Flash), > VMSTATE_UINT8(reset_pin, Flash), > VMSTATE_END_OF_LIST() > -- > 2.5.0 > >
W dniu 21.12.2015 o 12:18, Peter Crosthwaite pisze: > On Wed, Dec 16, 2015 at 4:57 AM, <marcin.krzeminski@nokia.com> wrote: >> From: Marcin Krzeminski <marcin.krzeminski@nokia.com> >> >> Signed-off-by: Marcin Krzeminski <marcin.krzeminski@nokia.com> >> --- >> hw/block/m25p80.c | 15 +++++++++++++++ >> 1 file changed, 15 insertions(+) >> >> diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c >> index bcb66a5..5e07b57 100644 >> --- a/hw/block/m25p80.c >> +++ b/hw/block/m25p80.c >> @@ -231,6 +231,10 @@ typedef enum { >> ERASE_4K = 0x20, >> ERASE_32K = 0x52, >> ERASE_SECTOR = 0xd8, >> + >> + RESET_ENABLE = 0x66, >> + RESET_MEMORY = 0x99, >> + > > Extra blank not needed. Ok. > > >> } FlashCMD; >> >> typedef enum { >> @@ -258,6 +262,7 @@ typedef struct Flash { >> uint8_t cmd_in_progress; >> uint64_t cur_addr; >> bool write_enable; >> + bool reset_enable; >> bool initialized; >> uint8_t reset_pin; >> >> @@ -441,6 +446,7 @@ static void reset_memory(Flash *s) >> s->pos = 0; >> s->state = STATE_IDLE; >> s->write_enable = false; >> + s->reset_enable = false; >> >> DB_PRINT_L(0, "Reset done.\n"); >> } >> @@ -554,6 +560,14 @@ static void decode_new_cmd(Flash *s, uint32_t value) >> break; >> case NOP: >> break; >> + case RESET_ENABLE: >> + s->reset_enable = true; >> + break; >> + case RESET_MEMORY: >> + if (s->reset_enable) { >> + reset_memory(s); >> + } >> + break; > > Reading an n25q256 datasheet, the RESET_ENABLE state is cancelled by > commands other that RESET_ENABLE or by bouncing the CS. A way to > implement this would be something like > > if (value != RESET_MEMORY) { > s->reset_enable = false; > } > > before the switch of value as well as clearing reset_enable in m25p80_cs. > > Regards, > Peter Agree. Thanks, Marcin > >> default: >> qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Unknown cmd %x\n", value); >> break; >> @@ -696,6 +710,7 @@ static const VMStateDescription vmstate_m25p80 = { >> VMSTATE_UINT8(cmd_in_progress, Flash), >> VMSTATE_UINT64(cur_addr, Flash), >> VMSTATE_BOOL(write_enable, Flash), >> + VMSTATE_BOOL(reset_enable, Flash), >> VMSTATE_BOOL(initialized, Flash), >> VMSTATE_UINT8(reset_pin, Flash), >> VMSTATE_END_OF_LIST() >> -- >> 2.5.0 >> >> > >
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index bcb66a5..5e07b57 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -231,6 +231,10 @@ typedef enum { ERASE_4K = 0x20, ERASE_32K = 0x52, ERASE_SECTOR = 0xd8, + + RESET_ENABLE = 0x66, + RESET_MEMORY = 0x99, + } FlashCMD; typedef enum { @@ -258,6 +262,7 @@ typedef struct Flash { uint8_t cmd_in_progress; uint64_t cur_addr; bool write_enable; + bool reset_enable; bool initialized; uint8_t reset_pin; @@ -441,6 +446,7 @@ static void reset_memory(Flash *s) s->pos = 0; s->state = STATE_IDLE; s->write_enable = false; + s->reset_enable = false; DB_PRINT_L(0, "Reset done.\n"); } @@ -554,6 +560,14 @@ static void decode_new_cmd(Flash *s, uint32_t value) break; case NOP: break; + case RESET_ENABLE: + s->reset_enable = true; + break; + case RESET_MEMORY: + if (s->reset_enable) { + reset_memory(s); + } + break; default: qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Unknown cmd %x\n", value); break; @@ -696,6 +710,7 @@ static const VMStateDescription vmstate_m25p80 = { VMSTATE_UINT8(cmd_in_progress, Flash), VMSTATE_UINT64(cur_addr, Flash), VMSTATE_BOOL(write_enable, Flash), + VMSTATE_BOOL(reset_enable, Flash), VMSTATE_BOOL(initialized, Flash), VMSTATE_UINT8(reset_pin, Flash), VMSTATE_END_OF_LIST()