Download raw body.
add iic_detach() to iic driver, for USB/IIC adapters
Hi,
I'm working on a driver for I2C-Tiny-USB[1], a USB device (Atmel/AVR or
RP2040/Pico) providing an i2c bus to the system, similar to the Silicon Labs
CP2112 (my next driver on the list). As this is a USB device, it must be
able to be attached and detached, and it must also detach its child iic
device.
But the iic driver doesn't implement iic_detach() and so config_detach()
in my driver panics the kernel with the message: "forced detach of iic1
failed". So I added a few lines to i2c.c. What do you think?
[1] https://github.com/harbaum/I2C-Tiny-USB
diff --git sys/dev/i2c/i2c.c sys/dev/i2c/i2c.c
index 0d63b40d136..5b0d9609530 100644
--- sys/dev/i2c/i2c.c
+++ sys/dev/i2c/i2c.c
@@ -54,12 +54,14 @@ struct iic_softc {
int iic_match(struct device *, void *, void *);
void iic_attach(struct device *, struct device *, void *);
+int iic_detach(struct device *, int);
int iic_search(struct device *, void *, void *);
const struct cfattach iic_ca = {
sizeof (struct iic_softc),
iic_match,
- iic_attach
+ iic_attach,
+ iic_detach
};
struct cfdriver iic_cd = {
@@ -144,6 +146,12 @@ iic_attach(struct device *parent, struct device *self, void *aux)
iic_scan(self, aux);
}
+int
+iic_detach(struct device *self, int flags)
+{
+ return (config_detach_children(self, flags));
+}
+
int
iic_is_compatible(const struct i2c_attach_args *ia, const char *name)
{
--
Denis
add iic_detach() to iic driver, for USB/IIC adapters