Skip to contentSkip to conversation

chardev/char-i2c: Implement Linux I2C character device

PATCH Superseded Ernest Esene 2 participants 3 messages May 3, 2019

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 chardev/char-i2c: Implement Linux I2C character device

Add support for Linux I2C character device for I2C device passthrough For example:
-chardev linux-i2c,address=0x46,path=/dev/i2c-N,id=i2c-chardev

---
 chardev/Makefile.objs  |   1 +
 chardev/char-i2c.c     | 142 +++++++++++++++++++++++++++++++++++++++++++++++++
 chardev/char.c         |   3 ++
 include/chardev/char.h |   1 +
 qapi/char.json         |  16 ++++++
 5 files changed, 163 insertions(+)
 create mode 100644 chardev/char-i2c.c
chardev/Makefile.objs +1 -0
index d68e1347f9..6c96b9a353 100644
@@ -16,6 +16,7 @@ chardev-obj-y += char-stdio.o
 chardev-obj-y += char-udp.o
 chardev-obj-$(CONFIG_WIN32) += char-win.o
 chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
+chardev-obj-$(CONFIG_POSIX) +=char-i2c.o
 
 common-obj-y += msmouse.o wctablet.o testdev.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
chardev/char-i2c.c new file +142 -0

142 lines not on this page · raw message

chardev/char.c +3 -0
index 54724a56b1..93732a9909 100644
@@ -926,6 +926,9 @@ QemuOptsList qemu_chardev_opts = {
         },{
             .name = "logappend",
             .type = QEMU_OPT_BOOL,
+        },{
+            .name = "address",
+            .type = QEMU_OPT_STRING,
         },
         { /* end of list */ }
     },
include/chardev/char.h +1 -0
index c0b57f7685..880614391f 100644
@@ -245,6 +245,7 @@ int qemu_chr_wait_connected(Chardev *chr, Error **errp);
 #define TYPE_CHARDEV_SERIAL "chardev-serial"
 #define TYPE_CHARDEV_SOCKET "chardev-socket"
 #define TYPE_CHARDEV_UDP "chardev-udp"
+#define TYPE_CHARDEV_I2C "chardev-linux-i2c"
 
 #define CHARDEV_IS_RINGBUF(chr) \
     object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_RINGBUF)
qapi/char.json +16 -0
index a6e81ac7bc..602b4099dc 100644
@@ -240,6 +240,21 @@
   'data': { 'device': 'str' },
   'base': 'ChardevCommon' }
 
+##
+# @ChardevI2c:
+#
+# Configuration info for i2c chardev (only on linux).
+#
+# @device: The name of the special file for the device,
+#          i.e. /dev/i2c-0 on linux
+# @address: The address of the i2c device on the host.
+#
+##
+{ 'struct': 'ChardevI2c',
+  'data': { 'device': 'str',
+            'address': 'int16'},
+  'base': 'ChardevCommon'}
+
 ##
 # @ChardevSocket:
 #
@@ -398,6 +413,7 @@
   'data': { 'file': 'ChardevFile',
             'serial': 'ChardevHostdev',
             'parallel': 'ChardevHostdev',
+            'i2c': 'ChardevI2c',
             'pipe': 'ChardevHostdev',
             'socket': 'ChardevSocket',
             'udp': 'ChardevUdp',
Signature · 1 line
2.14.2
#1 lore raw
Quoted 6 lines · Ernest Esene

Add support for Linux I2C character device for I2C device passthrough For example:
-chardev linux-i2c,address=0x46,path=/dev/i2c-N,id=i2c-chardev

---

Just an interface review:

qapi/char.json line 246

Quoted 9 lines

+++ b/qapi/char.json

qapi/char.json +4 -0
@@ -240,6 +240,21 @@
   'data': { 'device': 'str' },
   'base': 'ChardevCommon' }
 
+##
+# @ChardevI2c:
+#
+# Configuration info for i2c chardev (only on linux).

Rather than a parenthetical comment, you could use:

qapi/char.json line 252

Quoted 6 lines
qapi/char.json +6 -0
+#
+# @device: The name of the special file for the device,
+#          i.e. /dev/i2c-0 on linux
+# @address: The address of the i2c device on the host.
+#
+##

Missing a 'Since: 4.1' line.

qapi/char.json line 256

Quoted 4 lines
qapi/char.json +4 -0
+{ 'struct': 'ChardevI2c',
+  'data': { 'device': 'str',
+            'address': 'int16'},
+  'base': 'ChardevCommon'}

'if': 'defined(CONFIG_LINUX)'

as part of the usage of this struct, so that introspection will only see the struct where it can be used.

Quoted 13 lines
qapi/char.json +2 -0
+
 ##
 # @ChardevSocket:
 #
@@ -398,6 +413,7 @@
   'data': { 'file': 'ChardevFile',
             'serial': 'ChardevHostdev',
             'parallel': 'ChardevHostdev',
+            'i2c': 'ChardevI2c',
             'pipe': 'ChardevHostdev',
             'socket': 'ChardevSocket',
             'udp': 'ChardevUdp',
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#2 lore raw
Quoted 8 lines · Eric Blake
Quoted 6 lines · Ernest Esene

Add support for Linux I2C character device for I2C device passthrough For example:
-chardev linux-i2c,address=0x46,path=/dev/i2c-N,id=i2c-chardev

---

Quoted 8 lines

Just an interface review:

qapi/char.json line 242

Quoted 5 lines

+++ b/qapi/char.json

qapi/char.json +0 -0
@@ -240,6 +240,21 @@
   'data': { 'device': 'str' },
   'base': 'ChardevCommon' }
 

Missing a 'Since: 4.1' line.

4.1? Oh! I couldn't guess this number, I had to deliberately omit it.

Quoted 11 lines

qapi/char.json line 256

Quoted 5 lines
qapi/char.json +4 -0
+{ 'struct': 'ChardevI2c',
+  'data': { 'device': 'str',
+            'address': 'int16'},
+  'base': 'ChardevCommon'}

'if': 'defined(CONFIG_LINUX)'

as part of the usage of this struct, so that introspection will only see the struct where it can be used.

Quoted 19 lines
Quoted 13 lines
qapi/char.json +2 -0
+
 ##
 # @ChardevSocket:
 #
@@ -398,6 +413,7 @@
   'data': { 'file': 'ChardevFile',
             'serial': 'ChardevHostdev',
             'parallel': 'ChardevHostdev',
+            'i2c': 'ChardevI2c',
             'pipe': 'ChardevHostdev',
             'socket': 'ChardevSocket',
             'udp': 'ChardevUdp',
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Thanks so much for the useful review. I have applied the changes and will soon send v2 of the patch.

I hope it is OK to update the "MAINTAINERS" file this

Character Devices (Linux I2C)
M: Ernest Esene <[email protected]>
S: Maintained
F: chardev/char-i2c.c

-Ernest Esene