2020-05-05 05:54:33

by Alain Volmat

[permalink] [raw]
Subject: [PATCH 0/4] stm32-f7: Addition of SMBus Alert / Host-notify features

This serie adds SMBus Alert and SMBus Host-Notify features for the i2c-stm32f7.

For that purpore, I propose two enhancements to the i2c framework.
1. Addition of host-notify client handling as part of the
i2c-core-smbus so that any other i2c adapter can benefit from it,
even those without specific HW support for Host-Notify.
2. Addition of two i2c_algorithm reg_client and unreg_client allowing
adapter to take some actions when a client is being probed.
Indeed, in case of host-notify, the binding/flag is related to the
client and the adapter might want to enable the host-notify feature
only when there is a client requesting the host-notify.
(Since SMBus host-notify is using the address 0x08 which is a valid
I2C address, keeping host-notify always enabled would make the 0x08
I2C slave address non usable).

Alain Volmat (4):
i2c: smbus: add core function handling SMBus host-notify
i2c: addition of client reg/unreg callbacks
dt-bindings: i2c-stm32: add SMBus Alert bindings
i2c: stm32f7: Add SMBus-specific protocols support

.../devicetree/bindings/i2c/st,stm32-i2c.yaml | 4 +
drivers/i2c/busses/Kconfig | 1 +
drivers/i2c/busses/i2c-stm32f7.c | 198 +++++++++++++++++-
drivers/i2c/i2c-core-base.c | 11 +
drivers/i2c/i2c-core-smbus.c | 105 ++++++++++
include/linux/i2c-smbus.h | 2 +
include/linux/i2c.h | 6 +
7 files changed, 317 insertions(+), 10 deletions(-)

--
2.17.1


2020-05-05 05:55:23

by Alain Volmat

[permalink] [raw]
Subject: [PATCH 1/4] i2c: smbus: add core function handling SMBus host-notify

SMBus Host-Notify protocol, from the adapter point of view
consist of receiving a message from a client, including the
client address and some other data.

It can be simply handled by creating a new slave device
and registering a callback performing the parsing of the
message received from the client.

This commit introduces two new core functions
* i2c_new_smbus_host_notify_device
* i2c_free_smbus_host_notify_device
that take care of registration of the new slave device and
callback and will call i2c_handle_smbus_host_notify once a
Host-Notify event is received.

Signed-off-by: Alain Volmat <[email protected]>
---
drivers/i2c/i2c-core-smbus.c | 105 +++++++++++++++++++++++++++++++++++
include/linux/i2c-smbus.h | 2 +
2 files changed, 107 insertions(+)

diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
index b34d2ff06931..0c7e135c73e1 100644
--- a/drivers/i2c/i2c-core-smbus.c
+++ b/drivers/i2c/i2c-core-smbus.c
@@ -708,3 +708,108 @@ int of_i2c_setup_smbus_alert(struct i2c_adapter *adapter)
}
EXPORT_SYMBOL_GPL(of_i2c_setup_smbus_alert);
#endif
+
+struct i2c_smbus_host_notify_status {
+ bool notify_start;
+ u8 addr;
+};
+
+static int i2c_smbus_host_notify_cb(struct i2c_client *client,
+ enum i2c_slave_event event, u8 *val)
+{
+ struct i2c_smbus_host_notify_status *status = client->dev.platform_data;
+ int ret;
+
+ switch (event) {
+ case I2C_SLAVE_WRITE_REQUESTED:
+ status->notify_start = true;
+ break;
+ case I2C_SLAVE_WRITE_RECEIVED:
+ /* We only retrieve the first byte received (addr)
+ * since there is currently no way to retrieve the data
+ * parameter from the client.
+ */
+ if (!status->notify_start)
+ break;
+ status->addr = *val;
+ status->notify_start = false;
+ break;
+ case I2C_SLAVE_STOP:
+ ret = i2c_handle_smbus_host_notify(client->adapter,
+ status->addr);
+ if (ret < 0) {
+ dev_warn(&client->adapter->dev, "failed to handle host_notify (%d)\n",
+ ret);
+ return ret;
+ }
+ break;
+ default:
+ /* Only handle necessary events */
+ break;
+ }
+
+ return 0;
+}
+
+/**
+ * i2c_new_smbus_host_notify_device - get a client for SMBus host-notify support
+ * @adapter: the target adapter
+ * Context: can sleep
+ *
+ * Setup handling of the SMBus host-notify protocol on a given I2C bus segment.
+ *
+ * Handling is done by creating a device and its callback and handling data
+ * received via the SMBus host-notify address (0x8)
+ *
+ * This returns the client, which should be ultimately freed using
+ * i2c_free_smbus_host_notify_device(); or an ERRPTR to indicate an error.
+ */
+struct i2c_client *i2c_new_smbus_host_notify_device(struct i2c_adapter *adapter)
+{
+ struct i2c_board_info host_notify_board_info = {
+ I2C_BOARD_INFO("smbus_host_notify", 0x08),
+ .flags = I2C_CLIENT_SLAVE,
+ };
+ struct i2c_smbus_host_notify_status *status;
+ struct i2c_client *client;
+ int ret;
+
+ status = kzalloc(sizeof(struct i2c_smbus_host_notify_status),
+ GFP_KERNEL);
+ if (!status)
+ return ERR_PTR(-ENOMEM);
+
+ host_notify_board_info.platform_data = status;
+
+ client = i2c_new_client_device(adapter, &host_notify_board_info);
+ if (IS_ERR(client)) {
+ kfree(status);
+ return client;
+ }
+
+ ret = i2c_slave_register(client, i2c_smbus_host_notify_cb);
+ if (ret) {
+ i2c_unregister_device(client);
+ kfree(status);
+ return ERR_PTR(ret);
+ }
+
+ return client;
+}
+EXPORT_SYMBOL_GPL(i2c_new_smbus_host_notify_device);
+
+/**
+ * i2c_free_smbus_host_notify_device - free the client for SMBus host-notify
+ * support
+ * @client: the client to free
+ * Context: can sleep
+ *
+ * Free the i2c_client allocated via i2c_new_smbus_host_notify_device
+ */
+void i2c_free_smbus_host_notify_device(struct i2c_client *client)
+{
+ i2c_slave_unregister(client);
+ kfree(client->dev.platform_data);
+ i2c_unregister_device(client);
+}
+EXPORT_SYMBOL_GPL(i2c_free_smbus_host_notify_device);
diff --git a/include/linux/i2c-smbus.h b/include/linux/i2c-smbus.h
index 8c5459034f92..926f6d8ae30d 100644
--- a/include/linux/i2c-smbus.h
+++ b/include/linux/i2c-smbus.h
@@ -38,5 +38,7 @@ static inline int of_i2c_setup_smbus_alert(struct i2c_adapter *adap)
return 0;
}
#endif
+struct i2c_client *i2c_new_smbus_host_notify_device(struct i2c_adapter *adapter);
+void i2c_free_smbus_host_notify_device(struct i2c_client *client);

#endif /* _LINUX_I2C_SMBUS_H */
--
2.17.1

2020-05-05 05:55:34

by Alain Volmat

[permalink] [raw]
Subject: [PATCH 2/4] i2c: addition of client reg/unreg callbacks

Addition of two callbacks reg_client and unreg_client that can be
implemented by adapter drivers in order to take action whenever a
client is being registered to it.

Signed-off-by: Alain Volmat <[email protected]>
---
drivers/i2c/i2c-core-base.c | 11 +++++++++++
include/linux/i2c.h | 6 ++++++
2 files changed, 17 insertions(+)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 2e4560671183..4c84c6264314 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -319,6 +319,12 @@ static int i2c_device_probe(struct device *dev)
if (!client)
return 0;

+ if (client->adapter->algo->reg_client) {
+ status = client->adapter->algo->reg_client(client);
+ if (status)
+ return status;
+ }
+
driver = to_i2c_driver(dev->driver);

client->irq = client->init_irq;
@@ -417,6 +423,8 @@ static int i2c_device_probe(struct device *dev)
put_sync_adapter:
if (client->flags & I2C_CLIENT_HOST_NOTIFY)
pm_runtime_put_sync(&client->adapter->dev);
+ if (client->adapter->algo->reg_client)
+ client->adapter->algo->unreg_client(client);

return status;
}
@@ -445,6 +453,9 @@ static int i2c_device_remove(struct device *dev)
if (client->flags & I2C_CLIENT_HOST_NOTIFY)
pm_runtime_put(&client->adapter->dev);

+ if (client->adapter->algo->unreg_client)
+ client->adapter->algo->unreg_client(client);
+
return status;
}

diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 45d36ba4826b..61b838caf454 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -509,6 +509,8 @@ i2c_register_board_info(int busnum, struct i2c_board_info const *info,
* so e.g. PMICs can be accessed very late before shutdown. Optional.
* @functionality: Return the flags that this algorithm/adapter pair supports
* from the ``I2C_FUNC_*`` flags.
+ * @reg_client: Callback informing that a new client is being registered
+ * @unreg_client: Callback informing that a client is being removed
* @reg_slave: Register given client to I2C slave mode of this adapter
* @unreg_slave: Unregister given client from I2C slave mode of this adapter
*
@@ -545,6 +547,10 @@ struct i2c_algorithm {
/* To determine what the adapter supports */
u32 (*functionality)(struct i2c_adapter *adap);

+ /* To inform the adapter of the probe/remove of a client */
+ int (*reg_client)(struct i2c_client *client);
+ void (*unreg_client)(struct i2c_client *client);
+
#if IS_ENABLED(CONFIG_I2C_SLAVE)
int (*reg_slave)(struct i2c_client *client);
int (*unreg_slave)(struct i2c_client *client);
--
2.17.1

2020-05-11 08:28:50

by Pierre-Yves MORDRET

[permalink] [raw]
Subject: Re: [PATCH 1/4] i2c: smbus: add core function handling SMBus host-notify

Hi all,

Reviewed-by: Pierre-Yves MORDRET <[email protected]>

Thanks

On 5/5/20 7:51 AM, Alain Volmat wrote:
> SMBus Host-Notify protocol, from the adapter point of view
> consist of receiving a message from a client, including the
> client address and some other data.
>
> It can be simply handled by creating a new slave device
> and registering a callback performing the parsing of the
> message received from the client.
>
> This commit introduces two new core functions
> * i2c_new_smbus_host_notify_device
> * i2c_free_smbus_host_notify_device
> that take care of registration of the new slave device and
> callback and will call i2c_handle_smbus_host_notify once a
> Host-Notify event is received.
>
> Signed-off-by: Alain Volmat <[email protected]>
> ---
> drivers/i2c/i2c-core-smbus.c | 105 +++++++++++++++++++++++++++++++++++
> include/linux/i2c-smbus.h | 2 +
> 2 files changed, 107 insertions(+)
>
> diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
> index b34d2ff06931..0c7e135c73e1 100644
> --- a/drivers/i2c/i2c-core-smbus.c
> +++ b/drivers/i2c/i2c-core-smbus.c
> @@ -708,3 +708,108 @@ int of_i2c_setup_smbus_alert(struct i2c_adapter *adapter)
> }
> EXPORT_SYMBOL_GPL(of_i2c_setup_smbus_alert);
> #endif
> +
> +struct i2c_smbus_host_notify_status {
> + bool notify_start;
> + u8 addr;
> +};
> +
> +static int i2c_smbus_host_notify_cb(struct i2c_client *client,
> + enum i2c_slave_event event, u8 *val)
> +{
> + struct i2c_smbus_host_notify_status *status = client->dev.platform_data;
> + int ret;
> +
> + switch (event) {
> + case I2C_SLAVE_WRITE_REQUESTED:
> + status->notify_start = true;
> + break;
> + case I2C_SLAVE_WRITE_RECEIVED:
> + /* We only retrieve the first byte received (addr)
> + * since there is currently no way to retrieve the data
> + * parameter from the client.
> + */
> + if (!status->notify_start)
> + break;
> + status->addr = *val;
> + status->notify_start = false;
> + break;
> + case I2C_SLAVE_STOP:
> + ret = i2c_handle_smbus_host_notify(client->adapter,
> + status->addr);
> + if (ret < 0) {
> + dev_warn(&client->adapter->dev, "failed to handle host_notify (%d)\n",
> + ret);
> + return ret;
> + }
> + break;
> + default:
> + /* Only handle necessary events */
> + break;
> + }
> +
> + return 0;
> +}
> +
> +/**
> + * i2c_new_smbus_host_notify_device - get a client for SMBus host-notify support
> + * @adapter: the target adapter
> + * Context: can sleep
> + *
> + * Setup handling of the SMBus host-notify protocol on a given I2C bus segment.
> + *
> + * Handling is done by creating a device and its callback and handling data
> + * received via the SMBus host-notify address (0x8)
> + *
> + * This returns the client, which should be ultimately freed using
> + * i2c_free_smbus_host_notify_device(); or an ERRPTR to indicate an error.
> + */
> +struct i2c_client *i2c_new_smbus_host_notify_device(struct i2c_adapter *adapter)
> +{
> + struct i2c_board_info host_notify_board_info = {
> + I2C_BOARD_INFO("smbus_host_notify", 0x08),
> + .flags = I2C_CLIENT_SLAVE,
> + };
> + struct i2c_smbus_host_notify_status *status;
> + struct i2c_client *client;
> + int ret;
> +
> + status = kzalloc(sizeof(struct i2c_smbus_host_notify_status),
> + GFP_KERNEL);
> + if (!status)
> + return ERR_PTR(-ENOMEM);
> +
> + host_notify_board_info.platform_data = status;
> +
> + client = i2c_new_client_device(adapter, &host_notify_board_info);
> + if (IS_ERR(client)) {
> + kfree(status);
> + return client;
> + }
> +
> + ret = i2c_slave_register(client, i2c_smbus_host_notify_cb);
> + if (ret) {
> + i2c_unregister_device(client);
> + kfree(status);
> + return ERR_PTR(ret);
> + }
> +
> + return client;
> +}
> +EXPORT_SYMBOL_GPL(i2c_new_smbus_host_notify_device);
> +
> +/**
> + * i2c_free_smbus_host_notify_device - free the client for SMBus host-notify
> + * support
> + * @client: the client to free
> + * Context: can sleep
> + *
> + * Free the i2c_client allocated via i2c_new_smbus_host_notify_device
> + */
> +void i2c_free_smbus_host_notify_device(struct i2c_client *client)
> +{
> + i2c_slave_unregister(client);
> + kfree(client->dev.platform_data);
> + i2c_unregister_device(client);
> +}
> +EXPORT_SYMBOL_GPL(i2c_free_smbus_host_notify_device);
> diff --git a/include/linux/i2c-smbus.h b/include/linux/i2c-smbus.h
> index 8c5459034f92..926f6d8ae30d 100644
> --- a/include/linux/i2c-smbus.h
> +++ b/include/linux/i2c-smbus.h
> @@ -38,5 +38,7 @@ static inline int of_i2c_setup_smbus_alert(struct i2c_adapter *adap)
> return 0;
> }
> #endif
> +struct i2c_client *i2c_new_smbus_host_notify_device(struct i2c_adapter *adapter);
> +void i2c_free_smbus_host_notify_device(struct i2c_client *client);
>
> #endif /* _LINUX_I2C_SMBUS_H */
>

2020-05-11 08:32:22

by Pierre-Yves MORDRET

[permalink] [raw]
Subject: Re: [PATCH 2/4] i2c: addition of client reg/unreg callbacks

Hi all,

Reviewed-by: Pierre-Yves MORDRET <[email protected]>

Thanks

On 5/5/20 7:51 AM, Alain Volmat wrote:
> Addition of two callbacks reg_client and unreg_client that can be
> implemented by adapter drivers in order to take action whenever a
> client is being registered to it.
>
> Signed-off-by: Alain Volmat <[email protected]>
> ---
> drivers/i2c/i2c-core-base.c | 11 +++++++++++
> include/linux/i2c.h | 6 ++++++
> 2 files changed, 17 insertions(+)
>
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 2e4560671183..4c84c6264314 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -319,6 +319,12 @@ static int i2c_device_probe(struct device *dev)
> if (!client)
> return 0;
>
> + if (client->adapter->algo->reg_client) {
> + status = client->adapter->algo->reg_client(client);
> + if (status)
> + return status;
> + }
> +
> driver = to_i2c_driver(dev->driver);
>
> client->irq = client->init_irq;
> @@ -417,6 +423,8 @@ static int i2c_device_probe(struct device *dev)
> put_sync_adapter:
> if (client->flags & I2C_CLIENT_HOST_NOTIFY)
> pm_runtime_put_sync(&client->adapter->dev);
> + if (client->adapter->algo->reg_client)
> + client->adapter->algo->unreg_client(client);
>
> return status;
> }
> @@ -445,6 +453,9 @@ static int i2c_device_remove(struct device *dev)
> if (client->flags & I2C_CLIENT_HOST_NOTIFY)
> pm_runtime_put(&client->adapter->dev);
>
> + if (client->adapter->algo->unreg_client)
> + client->adapter->algo->unreg_client(client);
> +
> return status;
> }
>
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index 45d36ba4826b..61b838caf454 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -509,6 +509,8 @@ i2c_register_board_info(int busnum, struct i2c_board_info const *info,
> * so e.g. PMICs can be accessed very late before shutdown. Optional.
> * @functionality: Return the flags that this algorithm/adapter pair supports
> * from the ``I2C_FUNC_*`` flags.
> + * @reg_client: Callback informing that a new client is being registered
> + * @unreg_client: Callback informing that a client is being removed
> * @reg_slave: Register given client to I2C slave mode of this adapter
> * @unreg_slave: Unregister given client from I2C slave mode of this adapter
> *
> @@ -545,6 +547,10 @@ struct i2c_algorithm {
> /* To determine what the adapter supports */
> u32 (*functionality)(struct i2c_adapter *adap);
>
> + /* To inform the adapter of the probe/remove of a client */
> + int (*reg_client)(struct i2c_client *client);
> + void (*unreg_client)(struct i2c_client *client);
> +
> #if IS_ENABLED(CONFIG_I2C_SLAVE)
> int (*reg_slave)(struct i2c_client *client);
> int (*unreg_slave)(struct i2c_client *client);
>

2020-05-23 10:48:37

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 1/4] i2c: smbus: add core function handling SMBus host-notify


Adding Benjamin who mainly implemented this.

On Tue, May 05, 2020 at 07:51:08AM +0200, Alain Volmat wrote:
> SMBus Host-Notify protocol, from the adapter point of view
> consist of receiving a message from a client, including the
> client address and some other data.
>
> It can be simply handled by creating a new slave device
> and registering a callback performing the parsing of the
> message received from the client.
>
> This commit introduces two new core functions
> * i2c_new_smbus_host_notify_device
> * i2c_free_smbus_host_notify_device
> that take care of registration of the new slave device and
> callback and will call i2c_handle_smbus_host_notify once a
> Host-Notify event is received.

Yay, cool idea to use the slave interface. I like it a lot!

> +static int i2c_smbus_host_notify_cb(struct i2c_client *client,
> + enum i2c_slave_event event, u8 *val)
> +{
> + struct i2c_smbus_host_notify_status *status = client->dev.platform_data;
> + int ret;
> +
> + switch (event) {
> + case I2C_SLAVE_WRITE_REQUESTED:
> + status->notify_start = true;
> + break;
> + case I2C_SLAVE_WRITE_RECEIVED:
> + /* We only retrieve the first byte received (addr)
> + * since there is currently no way to retrieve the data
> + * parameter from the client.

Maybe s/no way/no support/ ? I still wonder if we couldn't add it
somehow. Once we find a device which needs this, of course.

> + */
> + if (!status->notify_start)
> + break;
> + status->addr = *val;
> + status->notify_start = false;
> + break;
> + case I2C_SLAVE_STOP:

What about setting 'notify_start' to false here as well? In the case of
an incomplete write?

> + ret = i2c_handle_smbus_host_notify(client->adapter,
> + status->addr);
> + if (ret < 0) {
> + dev_warn(&client->adapter->dev, "failed to handle host_notify (%d)\n",
> + ret);

I think we should rather add such error strings to the core if we think
they are needed. I am not convinced they are, though.

> + return ret;
> + }
> + break;
> + default:
> + /* Only handle necessary events */
> + break;
> + }
> +
> + return 0;
> +}
> +

Rest of the code looks good. Maybe we should compile all this only when
I2C_SLAVE is enabled?


Attachments:
(No filename) (2.22 kB)
signature.asc (849.00 B)
Download all attachments

2020-05-23 10:51:11

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 2/4] i2c: addition of client reg/unreg callbacks

On Tue, May 05, 2020 at 07:51:09AM +0200, Alain Volmat wrote:
> Addition of two callbacks reg_client and unreg_client that can be
> implemented by adapter drivers in order to take action whenever a
> client is being registered to it.
>
> Signed-off-by: Alain Volmat <[email protected]>

Sorry, but NACK. After years of work, we just recently got rid of attach
and detach callbacks. They were abused in quite a lot of ways. I think
we can find other solutions to what you need them for. Let's move the
discussion to patch 4.


Attachments:
(No filename) (540.00 B)
signature.asc (849.00 B)
Download all attachments

2020-05-26 13:40:22

by Alain Volmat

[permalink] [raw]
Subject: Re: [PATCH 1/4] i2c: smbus: add core function handling SMBus host-notify

On Sat, May 23, 2020 at 10:46:25AM +0000, Wolfram Sang wrote:
>
> Adding Benjamin who mainly implemented this.
>
> On Tue, May 05, 2020 at 07:51:08AM +0200, Alain Volmat wrote:
> > SMBus Host-Notify protocol, from the adapter point of view
> > consist of receiving a message from a client, including the
> > client address and some other data.
> >
> > It can be simply handled by creating a new slave device
> > and registering a callback performing the parsing of the
> > message received from the client.
> >
> > This commit introduces two new core functions
> > * i2c_new_smbus_host_notify_device
> > * i2c_free_smbus_host_notify_device
> > that take care of registration of the new slave device and
> > callback and will call i2c_handle_smbus_host_notify once a
> > Host-Notify event is received.
>
> Yay, cool idea to use the slave interface. I like it a lot!
>
> > +static int i2c_smbus_host_notify_cb(struct i2c_client *client,
> > + enum i2c_slave_event event, u8 *val)
> > +{
> > + struct i2c_smbus_host_notify_status *status = client->dev.platform_data;
> > + int ret;
> > +
> > + switch (event) {
> > + case I2C_SLAVE_WRITE_REQUESTED:
> > + status->notify_start = true;
> > + break;
> > + case I2C_SLAVE_WRITE_RECEIVED:
> > + /* We only retrieve the first byte received (addr)
> > + * since there is currently no way to retrieve the data
> > + * parameter from the client.
>
> Maybe s/no way/no support/ ? I still wonder if we couldn't add it
> somehow. Once we find a device which needs this, of course.

Indeed. Such support can be added later on once such device is found. For the
time being I will state "no support"

>
> > + */
> > + if (!status->notify_start)
> > + break;
> > + status->addr = *val;
> > + status->notify_start = false;
> > + break;
> > + case I2C_SLAVE_STOP:
>
> What about setting 'notify_start' to false here as well? In the case of
> an incomplete write?

Ok. I will check that notify_start is false before calling host_notify
(since otherwise it will call i2c_handle_smbus_host_notify with a bad addr
value) and reset notify_start to false if it is still true.

>
> > + ret = i2c_handle_smbus_host_notify(client->adapter,
> > + status->addr);
> > + if (ret < 0) {
> > + dev_warn(&client->adapter->dev, "failed to handle host_notify (%d)\n",
> > + ret);
>
> I think we should rather add such error strings to the core if we think
> they are needed. I am not convinced they are, though.

Agreed, this error can be removed.

>
> > + return ret;
> > + }
> > + break;
> > + default:
> > + /* Only handle necessary events */
> > + break;
> > + }
> > +
> > + return 0;
> > +}
> > +
>
> Rest of the code looks good. Maybe we should compile all this only when
> I2C_SLAVE is enabled?
>

Yes, I will enclose that around I2C_SLAVE support check.