PERFORCE change 107399 for review
Warner Losh
imp at FreeBSD.org
Sat Oct 7 00:15:00 PDT 2006
http://perforce.freebsd.org/chv.cgi?CH=107399
Change 107399 by imp at imp_lighthouse on 2006/10/07 07:14:29
Simplify a bit
Affected files ...
.. //depot/projects/arm/src/sys/dev/flash/at45d.c#5 edit
Differences ...
==== //depot/projects/arm/src/sys/dev/flash/at45d.c#5 (text+ko) ====
@@ -250,32 +250,56 @@
}
#endif
+static uint8_t
+at45d_get_status(device_t dev)
+{
+ uint8_t txBuf[8], rxBuf[8];
+ struct spi_command cmd;
+ int err;
+
+ memset(&cmd, 0, sizeof(cmd));
+ memset(txBuf, 0, sizeof(txBuf));
+ memset(rxBuf, 0, sizeof(rxBuf));
+
+ txBuf[0] = STATUS_REGISTER_READ;
+ cmd.tx_cmd = txBuf;
+ cmd.rx_cmd = rxBuf;
+ cmd.rx_cmd_sz = 2;
+ cmd.tx_cmd_sz = 2;
+ err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd);
+ return (rxBuf[1]);
+}
+
+static void
+at45d_wait_for_device_ready(device_t dev)
+{
+ while (at45d_get_status(dev) & 0x80)
+ continue;
+}
+
static int
at45d_get_mfg_info(device_t dev, uint8_t *resp)
{
- uint8_t txCmdBuf[8], rxCmdBuf[8], txBuf[8], rxBuf[8];
+ uint8_t txBuf[8], rxBuf[8];
struct spi_command cmd;
int err;
- memset(txCmdBuf, 0, sizeof(txCmdBuf));
+ memset(&cmd, 0, sizeof(cmd));
memset(txBuf, 0, sizeof(txBuf));
- memset(rxCmdBuf, 0, sizeof(rxCmdBuf));
memset(rxBuf, 0, sizeof(rxBuf));
- txCmdBuf[0] = MANUFACTURER_ID;
-
- cmd.tx_cmd = &txCmdBuf;
- cmd.rx_cmd = &rxCmdBuf;
- cmd.tx_cmd_sz = 1;
- cmd.rx_cmd_sz = 1;
- cmd.tx_data = &txBuf;
- cmd.rx_data = &rxBuf;
- cmd.tx_data_sz = 4;
- cmd.rx_data_sz = 4;
+ txBuf[0] = MANUFACTURER_ID;
+ cmd.tx_cmd = &txBuf;
+ cmd.rx_cmd = &rxBuf;
+ cmd.tx_cmd_sz = 5;
+ cmd.rx_cmd_sz = 5;
err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd);
if (err)
return (err);
- memcpy(resp, rxBuf, 4);
+ memcpy(resp, rxBuf + 1, 4);
+ // XXX We really should 'decode' the reply into some kind of
+ // XXX structure. To be generic (and not just for atmel parts)
+ // XXX we'd have to loop until we got a full reply.
return (0);
}
@@ -317,6 +341,8 @@
at45d_get_mfg_info(sc->dev, buf);
printf("Reply is %#x %#x %#x %#x\n", buf[0], buf[1], buf[2], buf[3]);
+ at45d_wait_for_device_ready(sc->dev);
+ printf("Status is %#x\b", at45d_get_status(sc->dev));
config_intrhook_disestablish(&sc->config_intrhook);
}
More information about the p4-projects
mailing list