laforge submitted this change.

View Change

Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved
icE1usb fw: Add device request to read/write I2C device registers

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I55a72762d535827a51e5ea1775e9abbd116bc8a8
---
M firmware/ice40-riscv/icE1usb/ice1usb_proto.h
M firmware/ice40-riscv/icE1usb/usb_dev.c
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/firmware/ice40-riscv/icE1usb/ice1usb_proto.h b/firmware/ice40-riscv/icE1usb/ice1usb_proto.h
index 5b65d76..8cf8439 100644
--- a/firmware/ice40-riscv/icE1usb/ice1usb_proto.h
+++ b/firmware/ice40-riscv/icE1usb/ice1usb_proto.h
@@ -20,6 +20,10 @@
/*! returns a string describing the firmware version */
#define ICE1USB_DEV_GET_FW_BUILD 0x02

+/*! performs an I2C register access (read/write depends on direction) */
+#define ICE1USB_DEV_I2C_REG_ACCESS 0x10
+
+
enum e1usb_dev_capability {
/*! Does this board have a GPS-DO */
ICE1USB_DEV_CAP_GPSDO,
diff --git a/firmware/ice40-riscv/icE1usb/usb_dev.c b/firmware/ice40-riscv/icE1usb/usb_dev.c
index e834142..da1e7f2 100644
--- a/firmware/ice40-riscv/icE1usb/usb_dev.c
+++ b/firmware/ice40-riscv/icE1usb/usb_dev.c
@@ -12,6 +12,7 @@
#include <no2usb/usb_proto.h>

#include "console.h"
+#include "i2c.h"
#include "misc.h"

#include "ice1usb_proto.h"
@@ -24,6 +25,10 @@
_usb_dev_ctrl_req_write(struct usb_ctrl_req *req, struct usb_xfer *xfer)
{
switch (req->bRequest) {
+ case ICE1USB_DEV_I2C_REG_ACCESS:
+ if (!i2c_write_reg((req->wIndex >> 8), req->wIndex & 0xff, req->wValue & 0xff))
+ return USB_FND_ERROR;
+ break;
default:
return USB_FND_ERROR;
}
@@ -43,6 +48,11 @@
xfer->data = (void*) fw_build_str;
xfer->len = strlen(fw_build_str);
break;
+ case ICE1USB_DEV_I2C_REG_ACCESS:
+ if (!i2c_read_reg((req->wIndex >> 8), req->wIndex & 0xff, &xfer->data[0]))
+ return USB_FND_ERROR;
+ xfer->len = 1;
+ break;
default:
return USB_FND_ERROR;
}

To view, visit change 30066. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: osmo-e1-hardware
Gerrit-Branch: master
Gerrit-Change-Id: I55a72762d535827a51e5ea1775e9abbd116bc8a8
Gerrit-Change-Number: 30066
Gerrit-PatchSet: 2
Gerrit-Owner: tnt <tnt@246tNt.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-MessageType: merged