* Licensed under the GPL-2 or later.
*/
+#define LOG_CATEGORY UCLASS_SPI_FLASH
+
#include <common.h>
#include <dm.h>
#include <malloc.h>
SF_WRITE_STATUS, /* write the flash's status register */
};
+#if CONFIG_IS_ENABLED(LOG)
static const char *sandbox_sf_state_name(enum sandbox_sf_state state)
{
static const char * const states[] = {
};
return states[state];
}
+#endif /* LOG */
/* Bits for the status register */
#define STAT_WIP (1 << 0)
{
struct sandbox_spi_flash *sbsf = dev_get_priv(dev);
- debug("sandbox_sf: CS activated; state is fresh!\n");
+ log_content("sandbox_sf: CS activated; state is fresh!\n");
/* CS is asserted, so reset state */
sbsf->off = 0;
static void sandbox_sf_cs_deactivate(struct udevice *dev)
{
- debug("sandbox_sf: CS deactivated; cmd done processing!\n");
+ log_content("sandbox_sf: CS deactivated; cmd done processing!\n");
}
/*
}
if (oldstate != sbsf->state)
- debug(" cmd: transition to %s state\n",
- sandbox_sf_state_name(sbsf->state));
+ log_content(" cmd: transition to %s state\n",
+ sandbox_sf_state_name(sbsf->state));
return 0;
}
int bytes = bitlen / 8;
int ret;
- debug("sandbox_sf: state:%x(%s) bytes:%u\n", sbsf->state,
- sandbox_sf_state_name(sbsf->state), bytes);
+ log_content("sandbox_sf: state:%x(%s) bytes:%u\n", sbsf->state,
+ sandbox_sf_state_name(sbsf->state), bytes);
if ((flags & SPI_XFER_BEGIN))
sandbox_sf_cs_activate(dev);
case SF_ID: {
u8 id;
- debug(" id: off:%u tx:", sbsf->off);
+ log_content(" id: off:%u tx:", sbsf->off);
if (sbsf->off < IDCODE_LEN) {
/* Extract correct byte from ID 0x00aabbcc */
id = ((JEDEC_MFR(sbsf->data) << 16) |
} else {
id = 0;
}
- debug("%d %02x\n", sbsf->off, id);
+ log_content("%d %02x\n", sbsf->off, id);
tx[pos++] = id;
++sbsf->off;
break;
}
case SF_ADDR:
- debug(" addr: bytes:%u rx:%02x ", sbsf->addr_bytes,
- rx[pos]);
+ log_content(" addr: bytes:%u rx:%02x ",
+ sbsf->addr_bytes, rx[pos]);
if (sbsf->addr_bytes++ < SF_ADDR_LEN)
sbsf->off = (sbsf->off << 8) | rx[pos];
- debug("addr:%06x\n", sbsf->off);
+ log_content("addr:%06x\n", sbsf->off);
if (tx)
sandbox_spi_tristate(&tx[pos], 1);
sbsf->state = SF_ERASE;
goto case_sf_erase;
}
- debug(" cmd: transition to %s state\n",
- sandbox_sf_state_name(sbsf->state));
+ log_content(" cmd: transition to %s state\n",
+ sandbox_sf_state_name(sbsf->state));
break;
case SF_READ:
/*
*/
cnt = bytes - pos;
- debug(" tx: read(%u)\n", cnt);
+ log_content(" tx: read(%u)\n", cnt);
assert(tx);
ret = os_read(sbsf->fd, tx + pos, cnt);
if (ret < 0) {
pos += ret;
break;
case SF_READ_STATUS:
- debug(" read status: %#x\n", sbsf->status);
+ log_content(" read status: %#x\n", sbsf->status);
cnt = bytes - pos;
memset(tx + pos, sbsf->status, cnt);
pos += cnt;
break;
case SF_READ_STATUS1:
- debug(" read status: %#x\n", sbsf->status);
+ log_content(" read status: %#x\n", sbsf->status);
cnt = bytes - pos;
memset(tx + pos, sbsf->status >> 8, cnt);
pos += cnt;
break;
case SF_WRITE_STATUS:
- debug(" write status: %#x (ignored)\n", rx[pos]);
+ log_content(" write status: %#x (ignored)\n", rx[pos]);
pos = bytes;
break;
case SF_WRITE:
}
cnt = bytes - pos;
- debug(" rx: write(%u)\n", cnt);
+ log_content(" rx: write(%u)\n", cnt);
if (tx)
sandbox_spi_tristate(&tx[pos], cnt);
ret = os_write(sbsf->fd, rx + pos, cnt);
/* verify address is aligned */
if (sbsf->off & (sbsf->erase_size - 1)) {
- debug(" sector erase: cmd:%#x needs align:%#x, but we got %#x\n",
- sbsf->cmd, sbsf->erase_size,
- sbsf->off);
+ log_content(" sector erase: cmd:%#x needs align:%#x, but we got %#x\n",
+ sbsf->cmd, sbsf->erase_size,
+ sbsf->off);
sbsf->status &= ~STAT_WEL;
goto done;
}
- debug(" sector erase addr: %u, size: %u\n", sbsf->off,
- sbsf->erase_size);
+ log_content(" sector erase addr: %u, size: %u\n",
+ sbsf->off, sbsf->erase_size);
cnt = bytes - pos;
if (tx)
ret = sandbox_erase_part(sbsf, sbsf->erase_size);
sbsf->status &= ~STAT_WEL;
if (ret) {
- debug("sandbox_sf: Erase failed\n");
+ log_content("sandbox_sf: Erase failed\n");
goto done;
}
goto done;
}
default:
- debug(" ??? no idea what to do ???\n");
+ log_content(" ??? no idea what to do ???\n");
goto done;
}
}
* Licensed under the GPL-2 or later.
*/
+#define LOG_CATEGORY UCLASS_SPI
+
#include <common.h>
#include <dm.h>
#include <malloc.h>
struct udevice *emul;
uint bytes = bitlen / 8, i;
int ret;
- u8 *tx = (void *)dout, *rx = din;
uint busnum, cs;
if (bitlen == 0)
if (ret)
return ret;
- /* make sure rx/tx buffers are full so clients can assume */
- if (!tx) {
- debug("sandbox_spi: xfer: auto-allocating tx scratch buffer\n");
- tx = malloc(bytes);
- if (!tx) {
- debug("sandbox_spi: Out of memory\n");
- return -ENOMEM;
- }
- }
- if (!rx) {
- debug("sandbox_spi: xfer: auto-allocating rx scratch buffer\n");
- rx = malloc(bytes);
- if (!rx) {
- debug("sandbox_spi: Out of memory\n");
- return -ENOMEM;
- }
- }
-
ops = spi_emul_get_ops(emul);
ret = ops->xfer(emul, bitlen, dout, din, flags);
- debug("sandbox_spi: xfer: got back %i (that's %s)\n rx:",
- ret, ret ? "bad" : "good");
- for (i = 0; i < bytes; ++i)
- debug(" %u:%02x", i, rx[i]);
- debug("\n");
-
- if (tx != dout)
- free(tx);
- if (rx != din)
- free(rx);
+ log_content("sandbox_spi: xfer: got back %i (that's %s)\n rx:",
+ ret, ret ? "bad" : "good");
+ if (din) {
+ for (i = 0; i < bytes; ++i)
+ log_content(" %u:%02x", i, ((u8 *)din)[i]);
+ }
+ log_content("\n");
return ret;
}