Skip to contentSkip to conversation

Add the I3C subsystem

PATCH Superseded Boris Brezillon 3 participants 16 messages Sep 5, 2018 – Sep 18, 2018

Subsystems (6)

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v7 cover Add the I3C subsystem

This patch series is adding a new subsystem to support I3C devices.

This is just adding basic features of the protocol, and new features will be added afterwards.

There are a few design choices that are worth mentioning because they impact the way I3C device drivers can interact with their devices:

- all functions used to send I3C/I2C frames must be called in non-atomic context. Mainly done this way to ease implementation, but this is still open to discussion. Please let me know if you think it's worth considering an asynchronous model here
- the I3C bus and I3C master controller are now tightly coupled even though they're still allocated separately. There's now a 1:1 relationship between these objects, and the I3C master is no longer represented under the I3C bus object.
Arnd, let me know if you had something different in mind, and I'll rework the implementation accordingly.

- I2C backward compatibility has been designed to be transparent to I2C drivers and the I2C subsystem. The I3C master just registers an I2C adapter which creates a new I2C bus. I'd say that, from a representation PoV it's not ideal because what should appear as a single I3C bus exposing I3C and I2C devices here appears as 2 different busses connected to each other through the parenting (the I3C master is the parent of the I2C and I3C busses).
On the other hand, I don't see a better solution if we want something that is not invasive.

Missing features (will be added in separate patch series after initial support has been accepted/merged):
- support for HDR modes (has been removed because of lack of real users)
- no support for multi-master and the associated concepts (mastership handover, support for secondary masters, ...)
- I2C devices can only be described using DT because this is the only use case I have. However, the framework can easily be extended with ACPI and board info support
- I3C slave framework. This has been completely omitted, but shouldn't have a huge impact on the I3C framework because I3C slaves don't see the whole bus, it's only about handling master requests and generating IBIs. Some of the struct, constant and enum definitions could be shared, but most of the I3C slave framework logic will be different

Note that this patchset is available on the linux-i3c repo[1].

Main changes between v6 and v7:
- I3C bus/master representations have been reworked to match what other subsystems are doing (master implicitly represented by the bus object)
- I3C dev registration has been fixed
- I3C bus mode selection has been fixed
- Calls to readsl/writesl() in the Cadence I3C master driver have been fixed

Main changes between v5 and v6:
- Introduce {i3c,i2c}_dev_desc structures to better match how I3C master controllers (reservation of one HW slot for each device attached to the bus). With this solution, the resource migration that happens when a device lose its dynamic address and is re-assigned a different address is simplified on the driver side, because most of it is now handled in the core (reserve a new dev slot, reserve IBI resources and free all resources attached to the old slot)
- Add I3C error codes (M0 to M2) so that the core and device drivers can have fine grained information on what caused an EIO error.

Only minor things happened between v3 and v5 (you can go check the changelog in each patch for more details).

Main changes between v2 and v3 are:
- Reworked the DT bindings as suggested by Rob
- Reworked the bus initialization step as suggested by Vitor
- Added a driver for an I3C GPIO expander

Main changes between the initial RFC and this v2 are:
- Add a generic infrastructure to support IBIs. It's worth mentioning that I tried exposing IBIs as a regular IRQs, but after several attempts and a discussion with Mark Zyngier, it appeared that it was not really fitting in the Linux IRQ model (the fact that you have payload attached to IBIs, the fact that most of the time an IBI will generate a transfer on the bus which has to be done in an atomic context, ...)
The counterpart of this decision is the latency induced by the workqueue approach, but since I don't have real use cases, I don't know if this can be a problem or not.
- Add helpers to support Hot Join
- Add support for IBIs and Hot Join in Cadence I3C master driver
- Address several issues in how I was using the device model

Thanks,

Boris

[1]https://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux.git/log/?h=i3c/next

Boris Brezillon (10):
i3c: Add core I3C infrastructure
docs: driver-api: Add I3C documentation
i3c: Add sysfs ABI spec
dt-bindings: i3c: Document core bindings
dt-bindings: i3c: Add macros to help fill I3C/I2C device's reg
property
MAINTAINERS: Add myself as the I3C subsystem maintainer
i3c: master: Add driver for Cadence IP
dt-bindings: i3c: Document Cadence I3C master bindings
gpio: Add a driver for Cadence I3C GPIO expander
dt-bindings: gpio: Add bindings for Cadence I3C gpio expander

 Documentation/ABI/testing/sysfs-bus-i3c            |  146 ++
 .../devicetree/bindings/gpio/gpio-cdns-i3c.txt     |   39 +
 .../devicetree/bindings/i3c/cdns,i3c-master.txt    |   44 +
 Documentation/devicetree/bindings/i3c/i3c.txt      |  140 ++
 Documentation/driver-api/i3c/device-driver-api.rst |    9 +
 Documentation/driver-api/i3c/index.rst             |   11 +
 Documentation/driver-api/i3c/master-driver-api.rst |   10 +
 Documentation/driver-api/i3c/protocol.rst          |  203 ++
 Documentation/driver-api/index.rst                 |    1 +
 MAINTAINERS                                        |   12 +
 drivers/Kconfig                                    |    2 +
 drivers/Makefile                                   |    2 +-
 drivers/gpio/Kconfig                               |   11 +
 drivers/gpio/Makefile                              |    1 +
 drivers/gpio/gpio-cdns-i3c.c                       |  411 ++++
 drivers/i3c/Kconfig                                |   24 +
 drivers/i3c/Makefile                               |    4 +
 drivers/i3c/core.c                                 |  623 ++++++
 drivers/i3c/device.c                               |  233 +++
 drivers/i3c/internals.h                            |   36 +
 drivers/i3c/master.c                               | 2074 ++++++++++++++++++++
 drivers/i3c/master/Kconfig                         |    6 +
 drivers/i3c/master/Makefile                        |    1 +
 drivers/i3c/master/i3c-master-cdns.c               | 1668 ++++++++++++++++
 include/dt-bindings/i3c/i3c.h                      |   28 +
 include/linux/i3c/ccc.h                            |  385 ++++
 include/linux/i3c/device.h                         |  331 ++++
 include/linux/i3c/master.h                         |  653 ++++++
 include/linux/mod_devicetable.h                    |   17 +
 29 files changed, 7124 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i3c
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-cdns-i3c.txt
 create mode 100644 Documentation/devicetree/bindings/i3c/cdns,i3c-master.txt
 create mode 100644 Documentation/devicetree/bindings/i3c/i3c.txt
 create mode 100644 Documentation/driver-api/i3c/device-driver-api.rst
 create mode 100644 Documentation/driver-api/i3c/index.rst
 create mode 100644 Documentation/driver-api/i3c/master-driver-api.rst
 create mode 100644 Documentation/driver-api/i3c/protocol.rst
 create mode 100644 drivers/gpio/gpio-cdns-i3c.c
 create mode 100644 drivers/i3c/Kconfig
 create mode 100644 drivers/i3c/Makefile
 create mode 100644 drivers/i3c/core.c
 create mode 100644 drivers/i3c/device.c
 create mode 100644 drivers/i3c/internals.h
 create mode 100644 drivers/i3c/master.c
 create mode 100644 drivers/i3c/master/Kconfig
 create mode 100644 drivers/i3c/master/Makefile
 create mode 100644 drivers/i3c/master/i3c-master-cdns.c
 create mode 100644 include/dt-bindings/i3c/i3c.h
 create mode 100644 include/linux/i3c/ccc.h
 create mode 100644 include/linux/i3c/device.h
 create mode 100644 include/linux/i3c/master.h
Signature · 1 line
2.14.1
#1 lore raw

PATCH v7 1/10 i3c: Add core I3C infrastructure

Add core infrastructure to support I3C in Linux and document it.

This infrastructure adds basic I3C support. Advanced features will be added afterwards.

There are a few design choices that are worth mentioning because they impact the way I3C device drivers can interact with their devices:

- all functions used to send I3C/I2C frames must be called in non-atomic context. Mainly done this way to ease implementation, but this is not set in stone, and if anyone needs async support, new functions can be added later on.
- the bus element is a separate object, but it's tightly coupled with the master object. We thus have a 1:1 relationship between i3c_bus and i3c_master_controller objects, and if 2 master controllers are connected to the same bus and both exposed to the same Linux instance they will appear as two distinct busses, and devices on this bus will be exposed twice.
- I2C backward compatibility has been designed to be transparent to I2C drivers and the I2C subsystem. The I3C master just registers an I2C adapter which creates a new I2C bus. I'd say that, from a representation PoV it's not ideal because what should appear as a single I3C bus exposing I3C and I2C devices here appears as 2 different buses connected to each other through the parenting (the I3C master is the parent of the I2C and I3C busses).
On the other hand, I don't see a better solution if we want something that is not invasive.

Missing features:
- I3C HDR modes are not supported
- no support for multi-master and the associated concepts (mastership handover, support for secondary masters, ...)
- I2C devices can only be described using DT because this is the only use case I have. However, the framework can easily be extended with ACPI and board info support
- I3C slave framework. This has been completely omitted, but shouldn't have a huge impact on the I3C framework because I3C slaves don't see the whole bus, it's only about handling master requests and generating IBIs. Some of the struct, constant and enum definitions could be shared, but most of the I3C slave framework logic will be different

---
Changes in v7:
- Stop representing the I3C master as a device under the I3C bus
- Enforce a 1:1 relationship between i3c_bus and i3c_master_controller objects
- Fix I3C bus mode selection when I2C devices are described in the DT.
- Fix I3C device registration

Changes in v6:
- Add I3C/I2C dev descriptors to simplify I3C driver controllers when migrating resources from on I3C device slot to anoter
- Add I3C error codes and return them when doing SDR/priv and CCC transfers. This allows us to properly detect when no devices acked a CCC command, which in some cases is a valid situation (no I3C devices on the bus)
- Remove __packed specifiers where unneeded
- Allocate all IBI slots in one call using kcalloc()

Changes in v5:
- Rename the address sysfs entry into dynamic_address to clarify things
- Document that we expect buffers passed to i3c_device_do_priv_xfers() to be DMA-able
- Fix DEFSLVS CCC command
- s/2017/2018/ in copyright headers
- Fix SPDX header in internals.h
- Fix coding style issues

Changes in v4:
- none

Changes in v3:
- Fix locking issues
- Explicitly include a bunch of headers (reported by Randy Dunlap)
- Rename {i2c,i3c}-scl-frequency DT prop into {i2c,i3c}-scl-hz
- Do not use BIT() macro in mod_devicetable.h
- Fix typos
- Fix/enhance some kernel doc headers
- Rework the bus initialization code to simplify master drivers
- Assign dynamic address with SETDASA if the device has a static address and the DT has a valid assigned-address property
- Rework the LVR extraction in DT parsing code
- Add code to detect when a device is re-attached to the bus after losing its dynamic address. In this case we know try to re-assign the old address, and most importantly, the I3C device driver sees the same device instance, not a new one
- Add an ->i2c_funcs() hook to let the master declare which I2C features it supports
- Unexport a few functions
- Remove support for HDR mode since we have no real user yet

Changes in v2:
- Fix a bunch of mistake I made with the device model (pointed by GKH)
- Move the documentation out of this commit (pointed by GKH)
- only source drivers/i3c/master/Kconfig when CONFIG_I3C is enabled (pointed by GKH)
- Add IBI infrastructure
- Add helpers to ease support for Hot Join (most of the logic is delegated to I3C controller drivers)
- move the doc out of this commit to improve readability
- Fix a few bugs in device probing/remove (detected after trying to load/unload modules in various orders)
- Add a module_i3c_i2c_driver() macro to ease integration of drivers for devices that support both I3C and I2C mode

---
 drivers/Kconfig                 |    2 +
 drivers/Makefile                |    2 +-
 drivers/i3c/Kconfig             |   24 +
 drivers/i3c/Makefile            |    4 +
 drivers/i3c/core.c              |  623 ++++++++++++
 drivers/i3c/device.c            |  233 +++++
 drivers/i3c/internals.h         |   36 +
 drivers/i3c/master.c            | 2074 +++++++++++++++++++++++++++++++++++++++
 drivers/i3c/master/Kconfig      |    0
 drivers/i3c/master/Makefile     |    0
 include/linux/i3c/ccc.h         |  385 ++++++++
 include/linux/i3c/device.h      |  331 +++++++
 include/linux/i3c/master.h      |  653 ++++++++++++
 include/linux/mod_devicetable.h |   17 +
 14 files changed, 4383 insertions(+), 1 deletion(-)
 create mode 100644 drivers/i3c/Kconfig
 create mode 100644 drivers/i3c/Makefile
 create mode 100644 drivers/i3c/core.c
 create mode 100644 drivers/i3c/device.c
 create mode 100644 drivers/i3c/internals.h
 create mode 100644 drivers/i3c/master.c
 create mode 100644 drivers/i3c/master/Kconfig
 create mode 100644 drivers/i3c/master/Makefile
 create mode 100644 include/linux/i3c/ccc.h
 create mode 100644 include/linux/i3c/device.h
 create mode 100644 include/linux/i3c/master.h
drivers/Kconfig +2 -0
index ab4d43923c4d..8395bc515996 100644
@@ -57,6 +57,8 @@ source "drivers/char/Kconfig"
 
 source "drivers/i2c/Kconfig"
 
+source "drivers/i3c/Kconfig"
+
 source "drivers/spi/Kconfig"
 
 source "drivers/spmi/Kconfig"
drivers/Makefile +1 -1
index 578f469f72fb..e1ce029d28fd 100644
@@ -111,7 +111,7 @@ obj-$(CONFIG_SERIO)		+= input/serio/
 obj-$(CONFIG_GAMEPORT)		+= input/gameport/
 obj-$(CONFIG_INPUT)		+= input/
 obj-$(CONFIG_RTC_LIB)		+= rtc/
-obj-y				+= i2c/ media/
+obj-y				+= i2c/ i3c/ media/
 obj-$(CONFIG_PPS)		+= pps/
 obj-y				+= ptp/
 obj-$(CONFIG_W1)		+= w1/
drivers/i3c/Kconfig new file +24 -0
new file mode 100644
index 000000000000..30a441506f61
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0
+
+menuconfig I3C
+	tristate "I3C support"
+	select I2C
+	help
+	  I3C is a serial protocol standardized by the MIPI alliance.
+
+	  It's supposed to be backward compatible with I2C while providing
+	  support for high speed transfers and native interrupt support
+	  without the need for extra pins.
+
+	  The I3C protocol also standardizes the slave device types and is
+	  mainly designed to communicate with sensors.
+
+	  If you want I3C support, you should say Y here and also to the
+	  specific driver for your bus adapter(s) below.
+
+	  This I3C support can also be built as a module.  If so, the module
+	  will be called i3c.
+
+if I3C
+source "drivers/i3c/master/Kconfig"
+endif # I3C
drivers/i3c/Makefile new file +4 -0
new file mode 100644
index 000000000000..3b6d1502d6e6
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+i3c-y				:= core.o device.o master.o
+obj-$(CONFIG_I3C)		+= i3c.o
+obj-$(CONFIG_I3C)		+= master/
drivers/i3c/core.c new file +623 -0

623 lines not on this page · raw message

drivers/i3c/device.c new file +233 -0

233 lines not on this page · raw message

drivers/i3c/internals.h new file +36 -0
new file mode 100644
index 000000000000..b0d784d8caa4
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2018 Cadence Design Systems Inc.
+ *
+ * Author: Boris Brezillon <[email protected]>
+ */
+
+#ifndef I3C_INTERNALS_H
+#define I3C_INTERNALS_H
+
+#include <linux/i3c/master.h>
+
+extern struct bus_type i3c_bus_type;
+extern const struct device_type i3c_device_type;
+
+void i3c_bus_put(struct i3c_bus *bus);
+struct i3c_bus *i3c_bus_create(struct i3c_master_controller *master);
+int i3c_bus_add(struct i3c_bus *i3cbus);
+void i3c_bus_del(struct i3c_bus *i3cbus);
+int i3c_bus_set_mode(struct i3c_bus *i3cbus, enum i3c_bus_mode mode);
+int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr);
+bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr);
+void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr,
+				  enum i3c_addr_slot_status status);
+enum i3c_addr_slot_status i3c_bus_get_addr_slot_status(struct i3c_bus *bus,
+						       u16 addr);
+
+int i3c_dev_do_priv_xfers_locked(struct i3c_dev_desc *dev,
+				 struct i3c_priv_xfer *xfers,
+				 int nxfers);
+int i3c_dev_disable_ibi_locked(struct i3c_dev_desc *dev);
+int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev);
+int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev,
+			       const struct i3c_ibi_setup *req);
+void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev);
+#endif /* I3C_INTERNAL_H */
drivers/i3c/master.c new file +2074 -0

2,064 lines not on this page · raw message

drivers/i3c/master/Kconfig new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
drivers/i3c/master/Makefile new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
include/linux/i3c/ccc.h new file +385 -0

385 lines not on this page · raw message

include/linux/i3c/device.h new file +331 -0

331 lines not on this page · raw message

include/linux/i3c/master.h new file +653 -0

653 lines not on this page · raw message

include/linux/mod_devicetable.h +17 -0
index 1298a7daa57d..9d1923cbeb54 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.14.1

Part of the diff is not shown here. View the raw message.

#2 lore raw

Re: [PATCH v7 01/10] i3c: Add core I3C infrastructure

Quoted 5 lines · Boris Brezillon

---
Changes in v7:
- Stop representing the I3C master as a device under the I3C bus
- Enforce a 1:1 relationship between i3c_bus and i3c_master_controller objects

Thanks for implementing those changes. What is your feeling so far about the difference? Has it gotten much simpler as I was hoping?

I definitely like this version much better. I have found a couple of things that I point out below that could be improved (or me being proven wrong on them), but overall I think it looks great and I don't see major issues.

Great work!

drivers/i3c/core.c line 541

Quoted 8 lines
drivers/i3c/core.c new file +8 -0
+struct i3c_bus *i3c_bus_create(struct i3c_master_controller *master)
+{
+       struct i3c_bus *i3cbus;
+       int ret;
+
+       i3cbus = kzalloc(sizeof(*i3cbus), GFP_KERNEL);
+       if (!i3cbus)
+               return ERR_PTR(-ENOMEM);

I find it a bit confusing to have separate i3c_master_controller and i3c_bus structures with this version. Why not merge the two structures into one now and move the bus management into master.c?

drivers/i3c/master.c line 760

Quoted 9 lines
drivers/i3c/master.c new file +9 -0
+static int i3c_master_attach_i3c_dev(struct i3c_master_controller *master,
+                                    struct i3c_dev_desc *dev)
+{
+       int ret;
+
+       /*
+        * We don't attach devices to the controller until they are
+        * addressable on the bus.
+

Apparently the new gmail version decided to cut off the second half of your email after this line when I hit reply, which makes it much harder for me to continue a proper review. I fear I'll have to get a real email client again :(

Quoted 4 lines

+ * The I3C bus is represented with its own object and not implicitly described
+ * by the I3C master to cope with the multi-master functionality, where one bus
+ * can be shared amongst several masters, each of them requesting bus ownership
+ * when they need to.

This comment is now stale, even without merging the structures, right?

include/linux/i3c/master.h line 479

Quoted 4 lines
include/linux/i3c/master.h new file +4 -0
+struct i3c_master_controller {
+       struct device *parent;
+       struct i3c_dev_desc *this;
+       struct i2c_adapter i2c;

I think the 'parent' pointer is better omitted, it should always be the same as master->dev->parent, right?

Since it contains an i2c_adapter, maybe a good name for the combined i3c_master_controller+i3c_bus structure would be 'i3c_adapter'?

+#define i3c_bus_for_each_i2cdev(bus, dev) \
+ list_for_each_entry(dev, &(bus)->devs.i2c, common.node)
+
+#define i3c_bus_for_each_i3cdev(bus, dev) \
+ list_for_each_entry(dev, &(bus)->devs.i3c, common.node)

I wonder if it would simplify things to drop the i2c and i3c device lists and instead implement these for_each loops based on device_for_each_child() with a check of the bus_type==&i2c_bus/&i3c_bus. That might help with locking and keeping the two lists synchronized, which may or may not be a problem here.

Arnd

#3 lore raw

Re: [PATCH v7 01/10] i3c: Add core I3C infrastructure

Quoted 11 lines · On Thu, 6 Sep 2018 15:38:49 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 5 lines · Boris Brezillon

---
Changes in v7:
- Stop representing the I3C master as a device under the I3C bus
- Enforce a 1:1 relationship between i3c_bus and i3c_master_controller objects

Thanks for implementing those changes. What is your feeling so far about the difference? Has it gotten much simpler as I was hoping?

Hm, to be honest I don't see a big difference in term of simplicity, but that's probably because I kept the bus/master concepts separated (even if the 1:1 relationship is enforced).

Quoted 7 lines

I definitely like this version much better. I have found a couple of things that I point out below that could be improved (or me being proven wrong on them), but overall I think it looks great and I don't see major issues.

Great work!

Thanks, I'm glad you think these changes go in the right direction. Will try to address your new comments.

Quoted 14 lines

drivers/i3c/core.c line 541

Quoted 9 lines
drivers/i3c/core.c new file +8 -0
+struct i3c_bus *i3c_bus_create(struct i3c_master_controller *master)
+{
+       struct i3c_bus *i3cbus;
+       int ret;
+
+       i3cbus = kzalloc(sizeof(*i3cbus), GFP_KERNEL);
+       if (!i3cbus)
+               return ERR_PTR(-ENOMEM);  

I find it a bit confusing to have separate i3c_master_controller and i3c_bus structures with this version. Why not merge the two structures into one now and move the bus management into master.c?

Yes, I considered this approach. Not sure it would make the whole code a lot simpler though, and it was definitely more work on my side, so I decided to delay that and wait for someone to explicitly request this change ;-).

I also like the bus/master separation in that it allows one to clearly identify the properties that are bus (speed, mode, ...) related and those that are master controller oriented (PID, DCR, ...).

Quoted 16 lines

drivers/i3c/master.c line 760

Quoted 10 lines
drivers/i3c/master.c new file +9 -0
+static int i3c_master_attach_i3c_dev(struct i3c_master_controller *master,
+                                    struct i3c_dev_desc *dev)
+{
+       int ret;
+
+       /*
+        * We don't attach devices to the controller until they are
+        * addressable on the bus.
+  

Apparently the new gmail version decided to cut off the second half of your email after this line when I hit reply, which makes it much harder for me to continue a proper review. I fear I'll have to get a real email client again :(

Quoted 6 lines
Quoted 4 lines

+ * The I3C bus is represented with its own object and not implicitly described
+ * by the I3C master to cope with the multi-master functionality, where one bus
+ * can be shared amongst several masters, each of them requesting bus ownership
+ * when they need to.

This comment is now stale, even without merging the structures, right?

Yep, it is. I'll drop it.

Quoted 8 lines

include/linux/i3c/master.h line 479

Quoted 5 lines
include/linux/i3c/master.h new file +4 -0
+struct i3c_master_controller {
+       struct device *parent;
+       struct i3c_dev_desc *this;
+       struct i2c_adapter i2c;  

I think the 'parent' pointer is better omitted, it should always be the same as master->dev->parent, right?

Absolutely.

Quoted 4 lines

Since it contains an i2c_adapter, maybe a good name for the combined i3c_master_controller+i3c_bus structure would be 'i3c_adapter'?

Hm, I'd really like to keep the name master and not adapter, just because that's how it's named in the spec.

Quoted 11 lines
include/linux/i3c/master.h new file +5 -0
+#define i3c_bus_for_each_i2cdev(bus, dev)                              \
+       list_for_each_entry(dev, &(bus)->devs.i2c, common.node)
+
+#define i3c_bus_for_each_i3cdev(bus, dev)                              \
+       list_for_each_entry(dev, &(bus)->devs.i3c, common.node)

I wonder if it would simplify things to drop the i2c and i3c device lists and instead implement these for_each loops based on device_for_each_child() with a check of the bus_type==&i2c_bus/&i3c_bus.

We don't store i3c/i3c_device objects in those lists, but i3c/i2c_dev_desc objects, so device_for_each_child() won't work. Remember that i3c devs can be present but not registered yet, and we need to have those representations somehow attached to the master/bus.

Regarding the possibility of merging those 2 lists together, we could do it, but I find it simpler to have them separated.

Quoted 3 lines

That might help with locking
and keeping the two lists synchronized, which may or may not be a problem here.

Regarding the locking aspects. Anything touching those lists is either init code (which should be serialized) or DAA related, which requires the bus lock to be held in write mode (exclusive access mode). Do you see any other possible race?

Thanks,

Boris

#4 lore raw

Re: [PATCH v7 01/10] i3c: Add core I3C infrastructure

Quoted 18 lines · Boris Brezillon
Quoted 16 lines · On Thu, 6 Sep 2018 15:38:49 +0200 Arnd Bergmann <[email protected]> wrote:

drivers/i3c/core.c line 541

Quoted 8 lines · Boris Brezillon
drivers/i3c/core.c new file +8 -0
+struct i3c_bus *i3c_bus_create(struct i3c_master_controller *master)
+{
+       struct i3c_bus *i3cbus;
+       int ret;
+
+       i3cbus = kzalloc(sizeof(*i3cbus), GFP_KERNEL);
+       if (!i3cbus)
+               return ERR_PTR(-ENOMEM);

I find it a bit confusing to have separate i3c_master_controller and i3c_bus structures with this version. Why not merge the two structures into one now and move the bus management into master.c?

Quoted 8 lines

Yes, I considered this approach. Not sure it would make the whole code a lot simpler though, and it was definitely more work on my side, so I decided to delay that and wait for someone to explicitly request this change ;-).

I also like the bus/master separation in that it allows one to clearly identify the properties that are bus (speed, mode, ...) related and those that are master controller oriented (PID, DCR, ...).

Maybe you could make the bus a member of the master rather than a pointer from it?

That would still let us avoid the separate dynamic allocations, and not having to worry about separate lifetime rules for the two, but also group the bus properties together a bit more as you said. It can also have code deal with the the bus object without including the structure definition of the master (if that is desirable).

Quoted 6 lines
Quoted 3 lines

Since it contains an i2c_adapter, maybe a good name for the combined i3c_master_controller+i3c_bus structure would be 'i3c_adapter'?

Hm, I'd really like to keep the name master and not adapter, just because that's how it's named in the spec.

Fair enough.

Quoted 4 lines

We don't store i3c/i3c_device objects in those lists, but i3c/i2c_dev_desc objects, so device_for_each_child() won't work. Remember that i3c devs can be present but not registered yet, and we need to have those representations somehow attached to the master/bus.

Ah right, I remember you explained that before.

Quoted 2 lines

Regarding the possibility of merging those 2 lists together, we could do it, but I find it simpler to have them separated.

Agreed. It would only make sense if we had the combined list already.

Quoted 8 lines
Quoted 3 lines

That might help with locking
and keeping the two lists synchronized, which may or may not be a problem here.

Regarding the locking aspects. Anything touching those lists is either init code (which should be serialized) or DAA related, which requires the bus lock to be held in write mode (exclusive access mode). Do you see any other possible race?

No, nothing specific, it was just a general feeling.

Arnd

#5 lore raw

Re: [PATCH v7 01/10] i3c: Add core I3C infrastructure

In reply to Boris Brezillon

Hi Boris,

drivers/i3c/master.c line 882

Quoted 8 lines · Boris Brezillon
drivers/i3c/master.c new file +8 -0
+i3c_master_register_new_i3c_devs(struct i3c_master_controller *master)
+{
+	struct i3c_dev_desc *desc;
+	int ret;
+
+	if (!master->init_done)
+		return;
+

If you have a hot-join and call i3c_master_do_daa this function will return without create the i3c_device.

Quoted 17 lines
drivers/i3c/master.c new file +16 -0
+	i3c_bus_for_each_i3cdev(master->bus, desc) {
+		if (desc->dev || !desc->info.dyn_addr || desc == master->this)
+			continue;
+
+		desc->dev = kzalloc(sizeof(*desc->dev), GFP_KERNEL);
+		if (!desc->dev)
+			continue;
+
+		desc->dev->bus = master->bus;
+		desc->dev->desc = desc;
+		desc->dev->dev.parent = &master->bus->dev;
+		desc->dev->dev.type = &i3c_device_type;
+		desc->dev->dev.bus = &i3c_bus_type;
+		desc->dev->dev.release = i3c_device_release;
+		dev_set_name(&desc->dev->dev, "%d-%llx", master->bus->id,
+			     desc->info.pid);

drivers/i3c/master.c line 908

Quoted 10 lines
drivers/i3c/master.c new file +10 -0
+
+		if (desc->boardinfo)
+			desc->dev->dev.of_node = desc->boardinfo->of_node;
+
+		ret = device_register(&desc->dev->dev);
+		if (ret)
+			dev_err(master->parent,
+				"Failed to add I3C device (err = %d)\n", ret);
+	}
+}

Best regards,
Vitor Soares

#6 lore raw

Re: [PATCH v7 01/10] i3c: Add core I3C infrastructure

Hi Vitor,

Sorry for the late reply, I was not at the office last week.

Quoted 13 lines · On Tue, 11 Sep 2018 11:04:07 +0100 vitor <[email protected]> wrote:

Hi Boris,

drivers/i3c/master.c line 882

Quoted 8 lines · Boris Brezillon
drivers/i3c/master.c new file +8 -0
+i3c_master_register_new_i3c_devs(struct i3c_master_controller *master)
+{
+	struct i3c_dev_desc *desc;
+	int ret;
+
+	if (!master->init_done)
+		return;
+  

If you have a hot-join and call i3c_master_do_daa this function will return without create the i3c_device.

Hm, you mean if hot-join happens when the I3C master is not yet registered? That shouldn't be a problem since all devices will be registered at the end of i3c_master_register(). Am I missing something? Is this a problem you actually face or just something you found out doing code inspection?

Quoted 19 lines
Quoted 19 lines
drivers/i3c/master.c new file +18 -0
+	i3c_bus_for_each_i3cdev(master->bus, desc) {
+		if (desc->dev || !desc->info.dyn_addr || desc == master->this)
+			continue;
+
+		desc->dev = kzalloc(sizeof(*desc->dev), GFP_KERNEL);
+		if (!desc->dev)
+			continue;
+
+		desc->dev->bus = master->bus;
+		desc->dev->desc = desc;
+		desc->dev->dev.parent = &master->bus->dev;
+		desc->dev->dev.type = &i3c_device_type;
+		desc->dev->dev.bus = &i3c_bus_type;
+		desc->dev->dev.release = i3c_device_release;
+		dev_set_name(&desc->dev->dev, "%d-%llx", master->bus->id,
+			     desc->info.pid);
+
+		if (desc->boardinfo)
Quoted 8 lines

drivers/i3c/master.c line 908

Quoted 8 lines
drivers/i3c/master.c new file +8 -0
+			desc->dev->dev.of_node = desc->boardinfo->of_node;
+
+		ret = device_register(&desc->dev->dev);
+		if (ret)
+			dev_err(master->parent,
+				"Failed to add I3C device (err = %d)\n", ret);
+	}
+}

Regards,

Boris

#7 lore raw

PATCH v7 2/10 docs: driver-api: Add I3C documentation

In reply to Boris Brezillon

Add the I3C documentation describing the protocol, the master driver API and the device driver API.

---
Changes in v6:
- Fix typos reported by Randy
- Add Randy's R-b

Changes in v5:
- Remove useless conf.py file
- Add SPDX headers

Changes in v2:
- Moved out of patch "i3c: Add core I3C infrastructure"
- Add link to the I3C spec
- Move rst files in Documentation/driver-api/i3c/

---
 Documentation/driver-api/i3c/device-driver-api.rst |   9 +
 Documentation/driver-api/i3c/index.rst             |  11 ++
 Documentation/driver-api/i3c/master-driver-api.rst |  10 +
 Documentation/driver-api/i3c/protocol.rst          | 203 +++++++++++++++++++++
 Documentation/driver-api/index.rst                 |   1 +
 5 files changed, 234 insertions(+)
 create mode 100644 Documentation/driver-api/i3c/device-driver-api.rst
 create mode 100644 Documentation/driver-api/i3c/index.rst
 create mode 100644 Documentation/driver-api/i3c/master-driver-api.rst
 create mode 100644 Documentation/driver-api/i3c/protocol.rst
Documentation/driver-api/i3c/device-driver-api.rst new file +9 -0
new file mode 100644
index 000000000000..85bc3381cd3e
@@ -0,0 +1,9 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=====================
+I3C device driver API
+=====================
+
+.. kernel-doc:: include/linux/i3c/device.h
+
+.. kernel-doc:: drivers/i3c/device.c
Documentation/driver-api/i3c/index.rst new file +11 -0
new file mode 100644
index 000000000000..783d6dad054b
@@ -0,0 +1,11 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=============
+I3C subsystem
+=============
+
+.. toctree::
+
+   protocol
+   device-driver-api
+   master-driver-api
Documentation/driver-api/i3c/master-driver-api.rst new file +10 -0
new file mode 100644
index 000000000000..bb19264aa239
@@ -0,0 +1,10 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+================================
+I3C master controller driver API
+================================
+
+.. kernel-doc:: drivers/i3c/master.c
+
+.. kernel-doc:: include/linux/i3c/master.h
+
Documentation/driver-api/i3c/protocol.rst new file +203 -0

203 lines not on this page · raw message

Documentation/driver-api/index.rst +1 -0
index 6d9f2f9fe20e..cc6a33f232ea 100644
@@ -32,6 +32,7 @@ available subsections can be seen below.
    pci
    spi
    i2c
+   i3c/index
    hsi
    edac
    scsi
Signature · 1 line
2.14.1
#8 lore raw

PATCH v7 3/10 i3c: Add sysfs ABI spec

In reply to Boris Brezillon

Document sysfs files/directories/symlinks exposed by the I3C subsystem.

---
Changes in v7:
- Bump KernelVersion to 4.20
- Add new entries under i3c-<bus-id> now that the master controller is no longer represented as a device under this directory but implicitly represented by the bus object

Changes in v6:
- none

Changes in v5:
- Fix the kernel version
- Rename address into dynamic_address to match changes done in the code

Changes in v4:
- none

Changes in v3:
- none

Changes in v2:
- new patch

---
 Documentation/ABI/testing/sysfs-bus-i3c | 146 ++++++++++++++++++++++++++++++++
 1 file changed, 146 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i3c
Documentation/ABI/testing/sysfs-bus-i3c new file +146 -0
new file mode 100644
index 000000000000..d7c7485b0c17
@@ -0,0 +1,146 @@
+What:		/sys/bus/i3c/devices/i3c-<bus-id>
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		An I3C bus. This directory will contain one sub-directory per
+		I3C device present on the bus.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/current_master
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		Expose the master that owns the bus (<bus-id>-<master-pid>) at
+		the time this file is read. Note that bus ownership can change
+		overtime, so there's no guarantee that when the read() call
+		returns, the value returned is still valid.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/mode
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		I3C bus mode. Can be "pure", "mixed-fast" or "mixed-slow". See
+		the I3C specification for a detailed description of what each
+		of these modes implies.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/i3c_scl_frequency
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		The frequency (expressed in Hz) of the SCL signal when
+		operating in I3C SDR mode.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/i2c_scl_frequency
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		The frequency (expressed in Hz) of the SCL signal when
+		operating in I2C mode.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/dynamic_address
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		Dynamic address assigned to the master controller. This
+		address may change if the bus is re-initialized.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/bcr
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		BCR stands for Bus Characteristics Register and express the
+		device capabilities in term of speed, maximum read/write
+		length, etc. See the I3C specification for more details.
+		This entry describes the BCR of the master controller driving
+		the bus.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/dcr
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		DCR stands for Device Characteristics Register and express the
+		device capabilities in term of exposed features. See the I3C
+		specification for more details.
+		This entry describes the DCR of the master controller driving
+		the bus.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/pid
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		PID stands for Provisional ID and is used to uniquely identify
+		a device on a bus. This PID contains information about the
+		vendor, the part and an instance ID so that several devices of
+		the same type can be connected on the same bus.
+		See the I3C specification for more details.
+		This entry describes the PID of the master controller driving
+		the bus.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/hdrcap
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		Expose the HDR (High Data Rate) capabilities of a device.
+		Returns a list of supported HDR mode, each element is separated
+		by space. Modes can be "hdr-ddr", "hdr-tsp" and "hdr-tsl".
+		See the I3C specification for more details about these HDR
+		modes.
+		This entry describes the HDRCAP of the master controller
+		driving the bus.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		An I3C device present on I3C bus identified by <bus-id>. Note
+		that all devices are represented including the master driving
+		the bus.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/dynamic_address
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		Dynamic address assigned to device <bus-id>-<device-pid>. This
+		address may change if the bus is re-initialized.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/bcr
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		BCR stands for Bus Characteristics Register and express the
+		device capabilities in term of speed, maximum read/write
+		length, etc. See the I3C specification for more details.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/dcr
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		DCR stands for Device Characteristics Register and express the
+		device capabilities in term of exposed features. See the I3C
+		specification for more details.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/pid
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		PID stands for Provisional ID and is used to uniquely identify
+		a device on a bus. This PID contains information about the
+		vendor, the part and an instance ID so that several devices of
+		the same type can be connected on the same bus.
+		See the I3C specification for more details.
+
+What:		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>/hdrcap
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		Expose the HDR (High Data Rate) capabilities of a device.
+		Returns a list of supported HDR mode, each element is separated
+		by space. Modes can be "hdr-ddr", "hdr-tsp" and "hdr-tsl".
+		See the I3C specification for more details about these HDR
+		modes.
+
+What:		/sys/bus/i3c/devices/<bus-id>-<device-pid>
+KernelVersion:  4.20
+Contact:	[email protected]
+Description:
+		These directories are just symbolic links to
+		/sys/bus/i3c/devices/i3c-<bus-id>/<bus-id>-<device-pid>.
Signature · 1 line
2.14.1
#9 lore raw

PATCH v7 4/10 dt-bindings: i3c: Document core bindings

In reply to Boris Brezillon

A new I3C subsystem has been added and a generic description has been created to represent the I3C bus and the devices connected on it.

Document this generic representation.

---
Changes in v5:
- Add Rob's R-b

Changes in v4:
- Clarify the fact that static address == I3C address and dynamic address == I3C address
- Use i2c-scl-hz in the example

Changes in v3:
- Rename {i2c,i3c}-scl-frequency DT prop into {i2c,i3c}-scl-hz
- Rework the way we expose the provisional ID and LVR information
- Rename dynamic-address into assigned-address
- Enforce the I3C master node name

Changes in v2:
- Define how to describe I3C devices in the DT and when it should be used. Note that the parsing of I3C devices is not yet implemented in the framework. Will be added when someone really needs it.

---
 Documentation/devicetree/bindings/i3c/i3c.txt | 140 ++++++++++++++++++++++++++
 1 file changed, 140 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i3c/i3c.txt
Documentation/devicetree/bindings/i3c/i3c.txt new file +140 -0
new file mode 100644
index 000000000000..13b719f1ef15
@@ -0,0 +1,140 @@
+Generic device tree bindings for I3C busses
+===========================================
+
+This document describes generic bindings that should be used to describe I3C
+busses in a device tree.
+
+Required properties
+-------------------
+
+- #address-cells  - should be <3>. Read more about addresses below.
+- #size-cells     - should be <0>.
+- compatible      - name of the I3C master controller driving the I3C bus
+
+For other required properties e.g. to describe register sets,
+clocks, etc. check the binding documentation of the specific driver.
+The node describing an I3C bus should be named i3c-master.
+
+Optional properties
+-------------------
+
+These properties may not be supported by all I3C master drivers. Each I3C
+master bindings should specify which of them are supported.
+
+- i3c-scl-hz: frequency of the SCL signal used for I3C transfers.
+	      When undefined the core sets it to 12.5MHz.
+
+- i2c-scl-hz: frequency of the SCL signal used for I2C transfers.
+	      When undefined, the core looks at LVR (Legacy Virtual Register)
+	      values of I2C devices described in the device tree to determine
+	      the maximum I2C frequency.
+
+I2C devices
+===========
+
+Each I2C device connected to the bus should be described in a subnode. All
+properties described in Documentation/devicetree/bindings/i2c/i2c.txt are
+valid here, but several new properties have been added.
+
+New constraint on existing properties:
+--------------------------------------
+- reg: contains 3 cells
+  + first cell : still encoding the I2C address
+
+  + second cell: should have bit 31 set to 1 to signify that this is an I2C
+		 device. Bits 0 to 7 encode the I3C LVR (Legacy Virtual
+		 Register):
+
+	bit[7:5]: I2C device index. Possible values
+	* 0: I2C device has a 50 ns spike filter
+	* 1: I2C device does not have a 50 ns spike filter but supports high
+	     frequency on SCL
+	* 2: I2C device does not have a 50 ns spike filter and is not tolerant
+	     to high frequencies
+	* 3-7: reserved
+
+	bit[4]: tell whether the device operates in FM (Fast Mode) or FM+ mode
+	* 0: FM+ mode
+	* 1: FM mode
+
+	bit[3:0]: device type
+	* 0-15: reserved
+
+  + third cell: should be 0
+
+I3C devices
+===========
+
+All I3C devices are supposed to support DAA (Dynamic Address Assignment), and
+are thus discoverable. So, by default, I3C devices do not have to be described
+in the device tree.
+This being said, one might want to attach extra resources to these devices,
+and those resources may have to be described in the device tree, which in turn
+means we have to describe I3C devices.
+
+Another use case for describing an I3C device in the device tree is when this
+I3C device has a static I2C address and we want to assign it a specific I3C
+dynamic address before the DAA takes place (so that other devices on the bus
+can't take this dynamic address).
+
+The I3C device should be names <device-type>@<static-i2c-address>,<i3c-pid>,
+where device-type is describing the type of device connected on the bus
+(gpio-controller, sensor, ...).
+
+Required properties
+-------------------
+- reg: contains 3 cells
+  + first cell : encodes the static I2C address. Should be 0 if the device does
+		 not have one (0 is not a valid I2C address).
+
+  + second and third cells: should encode the ProvisionalID. The second cell
+			    contains the manufacturer ID left-shifted by 1.
+			    The third cell contains ORing of the part ID
+			    left-shifted by 16, the instance ID left-shifted
+			    by 12 and the extra information. This encoding is
+			    following the PID definition provided by the I3C
+			    specification.
+
+Optional properties
+-------------------
+- assigned-address: dynamic address to be assigned to this device. This
+		    property is only valid if the I3C device has a static
+		    address (first cell of the reg property != 0).
+
+
+Example:
+
+	i3c-master@d040000 {
+		compatible = "cdns,i3c-master";
+		clocks = <&coreclock>, <&i3csysclock>;
+		clock-names = "pclk", "sysclk";
+		interrupts = <3 0>;
+		reg = <0x0d040000 0x1000>;
+		#address-cells = <3>;
+		#size-cells = <0>;
+
+		status = "okay";
+		i2c-scl-hz = <100000>;
+
+		/* I2C device. */
+		nunchuk: nunchuk@52 {
+			compatible = "nintendo,nunchuk";
+			reg = <0x52 0x80000010 0x0>;
+		};
+
+		/* I3C device with a static I2C address. */
+		thermal_sensor: sensor@68,39200144004 {
+			reg = <0x68 0x392 0x144004>;
+			assigned-address = <0xa>;
+		};
+
+		/*
+		 * I3C device without a static I2C address but requiring
+		 * resources described in the DT.
+		 */
+		sensor@0,39200154004 {
+			reg = <0x0 0x392 0x154004>;
+			clocks = <&clock_provider 0>;
+		};
+	};
+
Signature · 1 line
2.14.1
#10 lore raw

PATCH v7 5/10 dt-bindings: i3c: Add macros to help fill I3C/I2C device's reg property

In reply to Boris Brezillon

The reg property of devices connected to an I3C bus have 3 cells, and filling them manually is not trivial. Provides macros to help doing that.

---
Changes in v5:
- none

---
 include/dt-bindings/i3c/i3c.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 include/dt-bindings/i3c/i3c.h
include/dt-bindings/i3c/i3c.h new file +28 -0
new file mode 100644
index 000000000000..97448c546649
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2017 Cadence Design Systems Inc.
+ *
+ * Author: Boris Brezillon <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_I3C_I3C_H
+#define _DT_BINDINGS_I3C_I3C_H
+
+#define IS_I2C_DEV		0x80000000
+
+#define I2C_DEV(addr, lvr)					\
+	(addr) (IS_I2C_DEV | (lvr)) 0x0
+
+#define I3C_PID(manufid, partid, instid, extrainfo)		\
+	((manufid) << 1)					\
+	(((partid) << 16) | ((instid) << 12) | (extrainfo))
+
+#define I3C_DEV_WITH_STATIC_ADDR(addr, manufid, partid,		\
+				 instid, extrainfo)		\
+	(addr) I3C_PID(manufid, partid, instid, extrainfo)
+
+#define I3C_DEV(manufid, partid, instid, extrainfo)		\
+	I3C_DEV_WITH_STATIC_ADDR(0x0, manufid, partid,		\
+				 instid, extrainfo)
+
+#endif
Signature · 1 line
2.14.1
#11 lore raw

PATCH v7 6/10 MAINTAINERS: Add myself as the I3C subsystem maintainer

In reply to Boris Brezillon

Create an entry for the I3C subsystem and mark it as maintained by me. There's no official git repository, patchwork instance, mailing list or website yet, but this will be added after the subsystem has been accepted.

---
Changes in v7:
- Add a ML (not created yet) and a git repo

Changes in v5:
- Add the sysfs ABI file

---
 MAINTAINERS | 12 ++++++++++++
 1 file changed, 12 insertions(+)
MAINTAINERS +12 -0
index a5b256b25905..293c863b6f9f 100644
@@ -6918,6 +6918,18 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/i2c/i2c-stub.c
 
+I3C SUBSYSTEM
+M:	Boris Brezillon <[email protected]>
+L:	[email protected]
+T:	git git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux.git
+S:	Maintained
+F:	Documentation/ABI/testing/sysfs-bus-i3c
+F:	Documentation/devicetree/bindings/i3c/
+F:	Documentation/driver-api/i3c
+F:	drivers/i3c/
+F:	include/linux/i3c/
+F:	include/dt-bindings/i3c/
+
 IA64 (Itanium) PLATFORM
 M:	Tony Luck <[email protected]>
 M:	Fenghua Yu <[email protected]>
Signature · 1 line
2.14.1
#12 lore raw

PATCH v7 7/10 i3c: master: Add driver for Cadence IP

In reply to Boris Brezillon

Add a driver for Cadence I3C master IP.

---
Changes in v7:
- Fix readsl/writesl() usage
- Add a depends on ARM || ARM64 || XTENSA to forbid selection of this driver on platforms that are not implementing readsl/writesl

Changes in v6:
- Rework the attach/detach logic to match the new way of doing things.
- Use kcalloc() where appropriate
- Simplfy access to the RX/TX/IBI_DATA FIFOs

Changes in v5:
- Drop unused len var in cdns_i3c_master_handle_ibi()
- Get IBIR and CMDR depth from CONF_STATUS0
- s/2017/2018/ in copyright header
- Fix coding style issues

Changes in v4:
- Fix potential unsigned integer underflow
- Add missing static specific on IBI related functions

Changes in v3:
- Adjust to match I3C framework changes
- Implement support the CMD RESPONSE QUEUE and IBI QUEUE added in the latest revision of Cadence master IP
- Remove support for HDR modes

Changes in v2:
- Add basic IBI support. Note that the IP is not really reliable with regards to IBI because you can't extract IBI payloads as soon as you have more than one IBI waiting in the HW queue. This is something that will hopefully be addressed in future revisions of this IP
- Add a simple xfer queueing mechanism to optimize message queuing.
- Fix a few bugs
- Add support for Hot Join

---
 drivers/i3c/master/Kconfig           |    6 +
 drivers/i3c/master/Makefile          |    1 +
 drivers/i3c/master/i3c-master-cdns.c | 1668 ++++++++++++++++++++++++++++++++++
 3 files changed, 1675 insertions(+)
 create mode 100644 drivers/i3c/master/i3c-master-cdns.c
drivers/i3c/master/Kconfig +6 -0
index e69de29bb2d1..efab2a358359 100644
@@ -0,0 +1,6 @@
+config CDNS_I3C_MASTER
+	tristate "Cadence I3C master driver"
+	depends on I3C
+	depends on ARM || ARM64 || XTENSA
+	help
+	  Enable this driver if you want to support Cadence I3C master block.
drivers/i3c/master/Makefile +1 -0
index e69de29bb2d1..4c4304aa9534 100644
@@ -0,0 +1 @@
+obj-$(CONFIG_CDNS_I3C_MASTER)		+= i3c-master-cdns.o
drivers/i3c/master/i3c-master-cdns.c new file +1668 -0

1,668 lines not on this page · raw message

Signature · 1 line
2.14.1
#13 lore raw

PATCH v7 8/10 dt-bindings: i3c: Document Cadence I3C master bindings

In reply to Boris Brezillon

Document Cadence I3C master DT bindings.

---
Changes in v5:
- Add Rob's R-b

Changes in v4:
- Fix example to match the new representation

---
 .../devicetree/bindings/i3c/cdns,i3c-master.txt    | 44 ++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i3c/cdns,i3c-master.txt
Documentation/devicetree/bindings/i3c/cdns,i3c-master.txt new file +44 -0
new file mode 100644
index 000000000000..0e2b8b8770bf
@@ -0,0 +1,44 @@
+Bindings for cadence I3C master block
+=====================================
+
+Required properties:
+--------------------
+- compatible: shall be "cdns,i3c-master"
+- clocks: shall reference the pclk and sysclk
+- clock-names: shall contain "pclk" and "sysclk"
+- interrupts: the interrupt line connected to this I3C master
+- reg: I3C master registers
+
+Mandatory properties defined by the generic binding (see
+Documentation/devicetree/bindings/i3c/i3c.txt for more details):
+
+- #address-cells: shall be set to 1
+- #size-cells: shall be set to 0
+
+Optional properties defined by the generic binding (see
+Documentation/devicetree/bindings/i3c/i3c.txt for more details):
+
+- i2c-scl-hz
+- i3c-scl-hz
+
+I3C device connected on the bus follow the generic description (see
+Documentation/devicetree/bindings/i3c/i3c.txt for more details).
+
+Example:
+
+	i3c-master@0d040000 {
+		compatible = "cdns,i3c-master";
+		clocks = <&coreclock>, <&i3csysclock>;
+		clock-names = "pclk", "sysclk";
+		interrupts = <3 0>;
+		reg = <0x0d040000 0x1000>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		i2c-scl-hz = <100000>;
+
+		nunchuk: nunchuk@52 {
+			compatible = "nintendo,nunchuk";
+			reg = <0x52 0x80000010 0>;
+		};
+	};
+
Signature · 1 line
2.14.1
#14 lore raw

PATCH v7 9/10 gpio: Add a driver for Cadence I3C GPIO expander

In reply to Boris Brezillon

Add a driver for Cadence I3C GPIO expander.

---
Changes in v6:
- Use kmalloc_array() instead of kmalloc(N * sizeof(X))
- Add Linus' ack

Changes in v5:
- Use the !! operator to return 0 or 1 in cdns_i3c_gpio_get_direction()
- Use a scratch buffer to make sure the buffers passed to i3c_device_do_priv_xfers() are DMA-able
- Fix errors reported by checkpatch

Changes in v4:
- none

Changes in v3:
- new

---
 drivers/gpio/Kconfig         |  11 ++
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/gpio-cdns-i3c.c | 411 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 423 insertions(+)
 create mode 100644 drivers/gpio/gpio-cdns-i3c.c
drivers/gpio/Kconfig +11 -0
index 4f52c3a8ec99..a941601bf448 100644
@@ -908,6 +908,17 @@ config GPIO_TS4900
 
 endmenu
 
+menu "I3C GPIO expanders"
+	depends on I3C
+
+config GPIO_CDNS_I3C
+	tristate "Cadence I3C GPIO expander"
+	select GPIOLIB_IRQCHIP
+	help
+	  Say yes here to enabled the driver for Cadence I3C GPIO expander.
+
+endmenu
+
 menu "MFD GPIO expanders"
 
 config GPIO_ADP5520
drivers/gpio/Makefile +1 -0
index c256aff66a65..12fa0ace618e 100644
@@ -37,6 +37,7 @@ obj-$(CONFIG_GPIO_BCM_KONA)	+= gpio-bcm-kona.o
 obj-$(CONFIG_GPIO_BD9571MWV)	+= gpio-bd9571mwv.o
 obj-$(CONFIG_GPIO_BRCMSTB)	+= gpio-brcmstb.o
 obj-$(CONFIG_GPIO_BT8XX)	+= gpio-bt8xx.o
+obj-$(CONFIG_GPIO_CDNS_I3C)	+= gpio-cdns-i3c.o
 obj-$(CONFIG_GPIO_CLPS711X)	+= gpio-clps711x.o
 obj-$(CONFIG_GPIO_CS5535)	+= gpio-cs5535.o
 obj-$(CONFIG_GPIO_CRYSTAL_COVE)	+= gpio-crystalcove.o
drivers/gpio/gpio-cdns-i3c.c new file +411 -0

411 lines not on this page · raw message

Signature · 1 line
2.14.1
#15 lore raw

PATCH v7 10/10 dt-bindings: gpio: Add bindings for Cadence I3C gpio expander

In reply to Boris Brezillon

Document the Cadence I3C gpio expander bindings.

---
Changes in v5:
- Add Rob's R-b

Changes in v4:
- Use GPIO_ and IRQ_TYPE_ macros instead of raw numbers
- Fix the unit-address in the example

---
 .../devicetree/bindings/gpio/gpio-cdns-i3c.txt     | 39 ++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-cdns-i3c.txt
Documentation/devicetree/bindings/gpio/gpio-cdns-i3c.txt new file +39 -0
new file mode 100644
index 000000000000..d0155a9cea79
@@ -0,0 +1,39 @@
+* Cadence I3C GPIO expander
+
+The Cadence I3C GPIO expander provides 8 GPIOs controllable over I3C.
+This GPIOs can be configured in output or input mode and if they are in input
+mode they can generate IBIs (In Band Interrupts).
+
+Required properties for GPIO node:
+- reg : 3 cells encoding the I3C static address (none in our case) and the I3C
+	Provisional ID. See Documentation/devicetree/bindings/i3c/i3c.txt for
+	more details.
+	Should be <0x0 0x392 0x0>.
+- gpio-controller : Marks the device node as a gpio controller.
+- #gpio-cells : Should be two. The first cell is the pin number and
+  the second cell is used to specify the gpio polarity (GPIO_ACTIVE_HIGH or
+  GPIO_ACTIVE_LOW)
+- interrupt-controller: Marks the device node as an interrupt controller.
+- #interrupt-cells : Should be 2. The first cell is the GPIO number.
+  The second cell is used to specify trigger type and level flags.
+  The following trigger types are accepted (see
+  <dt-bindings/interrupt-controller/irq.h> for their definition):
+	IRQ_TYPE_EDGE_RISING
+	IRQ_TYPE_EDGE_FALLING
+	IRQ_TYPE_EDGE_BOTH
+	IRQ_TYPE_LEVEL_HIGH
+	IRQ_TYPE_LEVEL_LOW
+
+Example:
+
+	i3c-master@xxx {
+		...
+		i3c_gpio_expander: gpio@0,39200000000 {
+			reg = <0 0x392 0x0>;
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <2>;
+		};
+		...
+	};
Signature · 1 line
2.14.1