i2c-smbus: Add poll interface for smbus alert
RFC PATCH 1/3 i2c-smbus: Add poll interface for smbus alert
The current i2c smbus alert module depends on smbus alert mechanism supported by underlying bus drivers. By specifications, these alerts can be polled if there is no hardware support.
Currently multiple drivers who needs smbus alerts are creating a new i2c dummy device with address 0x0C (ARA register), by luck they don't co-exist. Otherwise i2c device creation will fail. Added a poll interface, so that all these driver can call a common interface to poll. Even if they polli, all drivers bound to an adapater will be notified by their alert callback if ARA register read is successful.
--- drivers/i2c/i2c-smbus.c | 23 +++++++++++++++++++++++ include/linux/i2c-smbus.h | 3 +++ 2 files changed, 26 insertions(+)
drivers/i2c/i2c-smbus.c +23 -0
@@ -72,6 +72,29 @@ static int smbus_do_alert(struct device *dev, void *addrp)return -EBUSY ; } +int i2c_smbus_ara_poll (const struct i2c_client *client) +{ +union i2c_smbus_data data; +int status; +struct alert_data alert_data; + + status =i2c_smbus_xfer (client->adapter,0x0C ,0 , +I2C_SMBUS_READ ,0 , +I2C_SMBUS_BYTE , &data); +if (status <0 ) +return status; + + alert_data.flag = data.byte &1 ; + alert_data.addr = data.byte >>1 ; + +/* Notify driver for the device which issued the alert */ +device_for_each_child (&client->adapter->dev, &alert_data, + smbus_do_alert); + +return data.byte; +} +EXPORT_SYMBOL_GPL (i2c_smbus_ara_poll); +/* * The alert IRQ handler needs to hand work off to a task which can issue * SMBus calls, because those sleeping calls can't be made in IRQ context.
include/linux/i2c-smbus.h +3 -0
@@ -48,4 +48,7 @@ struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter, struct i2c_smbus_alert_setup *setup);int i2c_handle_smbus_alert (struct i2c_client *ara); +/* Interface to poll smbus alert */ +int i2c_smbus_ara_poll (const struct i2c_client *client); +#endif /* _LINUX_I2C_SMBUS_H */
Signature · 1 line
1.8.3.2
A message that is not in the archive (sent off-list or not yet received): 1395880932-19124-1-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/[email protected]
RFC PATCH 2/3 i2c-smbus: Allow building with I2C_HELPER_AUTO support
Currentlty the config is conditional on !I2C_HELPER_AUTO. I don't know their dependency, but without this we can't build.
--- drivers/i2c/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/Kconfig +1 -1
@@ -74,7 +74,7 @@ config I2C_HELPER_AUTO In doubt, say Y. config I2C_SMBUS - tristate "SMBus-specific protocols" if !I2C_HELPER_AUTO + tristate "SMBus-specific protocols" help Say Y here if you want support for SMBus extensions to the I2C specification. At the moment, the only supported extension is
Signature · 1 line
1.8.3.2
A message that is not in the archive (sent off-list or not yet received): 1395880932-19124-2-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/[email protected]
Re: [RFC Patch v0 2/3] i2c-smbus: Allow building with I2C_HELPER_AUTO support
Quoted 2 lines · Srinivas Pandruvada
Currentlty the config is conditional on !I2C_HELPER_AUTO. I don't know their dependency, but without this we can't build.
Nack. Just because you don't understand something and did not bother looking into it, is no good reason to break a perfectly working and valid mechanism.
Just read the Kconfig help text for I2C_HELPER_AUTO and you should be able to figure it out. Also grep the kernel tree for "select I2C_SMBUS".
As a summary: any driver which depends on i2c-smbus, should select it in Kconfig.
Quoted 18 lines
--- drivers/i2c/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/Kconfig +1
-1@@ -74,7 +74,7 @@ config I2C_HELPER_AUTO In doubt, say Y. config I2C_SMBUS - tristate "SMBus-specific protocols" if !I2C_HELPER_AUTO + tristate "SMBus-specific protocols" help Say Y here if you want support for SMBus extensions to the I2C specification. At the moment, the only supported extension is
Signature · 2 lines
Jean Delvare SUSE L3 Support
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RFC Patch v0 2/3] i2c-smbus: Allow building with I2C_HELPER_AUTO support
Quoted 6 lines · Jean Delvare
Quoted 2 lines · Srinivas Pandruvada
Currentlty the config is conditional on !I2C_HELPER_AUTO. I don't know their dependency, but without this we can't build.
Nack. Just because you don't understand something and did not bother looking into it, is no good reason to break a perfectly working and valid mechanism.
That is why it RFC.
Quoted 26 lines
Just read the
Kconfighelp text forI2C_HELPER_AUTOand you should be able to figure it out. Also grep the kernel tree for "selectI2C_SMBUS".As a summary: any driver which depends on i2c-smbus, should select it in
Kconfig.Quoted 18 lines
--- drivers/i2c/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/Kconfig +1
-1@@ -74,7 +74,7 @@ config I2C_HELPER_AUTO In doubt, say Y. config I2C_SMBUS - tristate "SMBus-specific protocols" if !I2C_HELPER_AUTO + tristate "SMBus-specific protocols" help Say Y here if you want support for SMBus extensions to the I2C specification. At the moment, the only supported extension is
RFC PATCH 3/3 iio: Capella cm3218x: smbus alert processing
In reply to a message not in the archiveAdded driver alert callback and modified existing polls to the core calls.
--- drivers/iio/light/cm3218x.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
drivers/iio/light/cm3218x.c +9 -13
@@ -23,6 +23,7 @@#include <linux/iio/events.h> #include <linux/init.h> #include <linux/acpi.h> +#include <linux/i2c-smbus.h> /* Registers Address */ #define CM3218x_REG_ADDR_CMD 0x00
@@ -130,6 +131,12 @@ static int cm3218x_get_lux(struct cm3218x_chip *chip);static int cm3218x_threshold_update (struct cm3218x_chip *chip,int percent);static int cm3218x_read_als_it (struct cm3218x_chip *chip,int *val2); +/* alert callback for i2c driver */ +static void cm3218x_alert (struct i2c_client *client,unsigned int flag) +{ +dev_err (&client->dev,"SMBUS alert flag %d\n" , flag); +} +/** * cm3218x_read_ara() - Read ARA register * @cm3218x: pointer of struct cm3218x.
@@ -142,19 +149,7 @@ static int cm3218x_read_als_it(struct cm3218x_chip *chip, int *val2);*/ static int cm3218x_read_ara (struct cm3218x_chip *chip) { -struct i2c_client *client = chip->client; -int status; -unsigned short addr; - - addr = client->addr; - client->addr =0x0C ; - status =i2c_smbus_read_byte (client); - client->addr = addr; - -if (status <0 ) -return -ENODEV ; - -return status; +return i2c_smbus_ara_poll (chip->client); }/**
@@ -760,6 +755,7 @@ static struct i2c_driver cm3218x_driver = { .id_table = cm3218x_id, .probe = cm3218x_probe, .remove = cm3218x_remove, + .alert = cm3218x_alert, };module_i2c_driver (cm3218x_driver);
Signature · 1 line
1.8.3.2
Quoted 36 lines · Srinivas Pandruvada
The current i2c smbus alert module depends on smbus alert mechanism supported by underlying bus drivers. By specifications, these alerts can be polled if there is no hardware support.
Currently multiple drivers who needs smbus alerts are creating a new i2c dummy device with address0x0C(ARA register), by luck they don't co-exist. Otherwise i2c device creation will fail. Added a poll interface, so that all these driver can call a common interface to poll. Even if they polli, all drivers bound to an adapater will be notified by their alert callback if ARA register read is successful.--- drivers/i2c/i2c-smbus.c | 23 +++++++++++++++++++++++ include/linux/i2c-smbus.h | 3 +++ 2 files changed, 26 insertions(+)drivers/i2c/i2c-smbus.c +11
-0@@ -72,6 +72,29 @@ static int smbus_do_alert(struct device *dev, void *addrp)return -EBUSY ; } +int i2c_smbus_ara_poll (const struct i2c_client *client) +{ +union i2c_smbus_data data; +int status; +struct alert_data alert_data; + + status =i2c_smbus_xfer (client->adapter,0x0C ,0 , +I2C_SMBUS_READ ,0 , +I2C_SMBUS_BYTE , &data); +if (status <0 ) +return status;
drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void *addrp) · line 95
Quoted 10 lines
drivers/i2c/i2c-smbus.c +10
-0+ + alert_data.flag = data.byte &1 ; + alert_data.addr = data.byte >>1 ; + +/* Notify driver for the device which issued the alert */ +device_for_each_child (&client->adapter->dev, &alert_data, + smbus_do_alert); + +return data.byte; +}
This is essentially duplicating code from smbus_alert(), but in a hackish way, as the ARA is never properly reserved. Your bus driver should really register the ARA with i2c_setup_smbus_alert().
I see that the code may not properly deal with the polled case everywhere but it should be pretty trivial to deal with. For example, check for alert->irq > 0 before re-enabling the irq in smbus_alert(). I don't immediately see any other change needed.
If SMBus alert polling is done from the i2c device driver, we'll have to find a standard way for i2c device drivers to retrieve the ara client associated with an i2c_adapter. However I still need to be convinced that this makes any sense at all. Ultimately the alert will call the i2c device drivers's alert() callback. If the i2c device driver needs to do that, there's no need to go through ARA, it might as well just call the callback by itself.
So can you please explain what problem exactly you are trying to solve?
Quoted 17 lines
drivers/i2c/i2c-smbus.c +2
-0+EXPORT_SYMBOL_GPL (i2c_smbus_ara_poll); +/* * The alert IRQ handler needs to hand work off to a task which can issue * SMBus calls, because those sleeping calls can't be made in IRQ context. include/linux/i2c-smbus.h +3
-0@@ -48,4 +48,7 @@ struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter, struct i2c_smbus_alert_setup *setup);int i2c_handle_smbus_alert (struct i2c_client *ara); +/* Interface to poll smbus alert */ +int i2c_smbus_ara_poll (const struct i2c_client *client); +#endif /* _LINUX_I2C_SMBUS_H */
Signature · 2 lines
Jean Delvare SUSE L3 Support
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 64 lines · Jean Delvare
Quoted 36 lines · Srinivas Pandruvada
The current i2c smbus alert module depends on smbus alert mechanism supported by underlying bus drivers. By specifications, these alerts can be polled if there is no hardware support.
Currently multiple drivers who needs smbus alerts are creating a new i2c dummy device with address0x0C(ARA register), by luck they don't co-exist. Otherwise i2c device creation will fail. Added a poll interface, so that all these driver can call a common interface to poll. Even if they polli, all drivers bound to an adapater will be notified by their alert callback if ARA register read is successful.--- drivers/i2c/i2c-smbus.c | 23 +++++++++++++++++++++++ include/linux/i2c-smbus.h | 3 +++ 2 files changed, 26 insertions(+)drivers/i2c/i2c-smbus.c +11
-0@@ -72,6 +72,29 @@ static int smbus_do_alert(struct device *dev, void *addrp)return -EBUSY ; } +int i2c_smbus_ara_poll (const struct i2c_client *client) +{ +union i2c_smbus_data data; +int status; +struct alert_data alert_data; + + status =i2c_smbus_xfer (client->adapter,0x0C ,0 , +I2C_SMBUS_READ ,0 , +I2C_SMBUS_BYTE , &data); +if (status <0 ) +return status;drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void *addrp) · line 95
Quoted 10 lines
drivers/i2c/i2c-smbus.c +10
-0+ + alert_data.flag = data.byte &1 ; + alert_data.addr = data.byte >>1 ; + +/* Notify driver for the device which issued the alert */ +device_for_each_child (&client->adapter->dev, &alert_data, + smbus_do_alert); + +return data.byte; +}This is essentially duplicating code from
smbus_alert(), but in a hackish way, as the ARA is never properly reserved. Your bus driver should really register the ARA withi2c_setup_smbus_alert().I see that the code may not properly deal with the polled case everywhere but it should be pretty trivial to deal with. For example, check for
alert->irq> 0 before re-enabling the irq insmbus_alert(). I don't immediately see any other change needed.If SMBus alert polling is done from the i2c device driver, we'll have to find a standard way for i2c device drivers to retrieve the ara client associated with an
i2c_adapter. However I still need to be convinced that this makes any sense at all. Ultimately the alert will call the i2c device drivers'salert()callback. If the i2c device driver needs to do that, there's no need to go through ARA, it might as well just call the callback by itself.
Quoted 1 line
So can you please explain what problem exactly you are trying to solve?
The current i2c clients and proposed patches are creating dummy devices. You can't create two devices with same address. So they can't coexist. Also 0x0c is a valid i2c address, so we can't create a new i2c device. We have products there are devices on i2C on 0x0c. So don't you think after callingi2c_setup_smbus_alert()
the other device can really be setup by calling i2c_new_device(). This function does a busy_check for same addresses.
The idea is if some i2c client triggers ARA read, it doesn't destroy the real receiver of the the smb alert and call respective alert() callbacks,
Quoted 18 lines
Quoted 17 lines
drivers/i2c/i2c-smbus.c +2
-0+EXPORT_SYMBOL_GPL (i2c_smbus_ara_poll); +/* * The alert IRQ handler needs to hand work off to a task which can issue * SMBus calls, because those sleeping calls can't be made in IRQ context. include/linux/i2c-smbus.h +3
-0@@ -48,4 +48,7 @@ struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter, struct i2c_smbus_alert_setup *setup);int i2c_handle_smbus_alert (struct i2c_client *ara); +/* Interface to poll smbus alert */ +int i2c_smbus_ara_poll (const struct i2c_client *client); +#endif /* _LINUX_I2C_SMBUS_H */
Quoted 67 lines · Jean Delvare
Quoted 11 lines · Srinivas Pandruvada
The current i2c smbus alert module depends on smbus alert mechanism supported by underlying bus drivers. By specifications, these alerts can be polled if there is no hardware support.
Currently multiple drivers who needs smbus alerts are creating a new i2c dummy device with address0x0C(ARA register), by luck they don't co-exist. Otherwise i2c device creation will fail. Added a poll interface, so that all these driver can call a common interface to poll. Even if they polli, all drivers bound to an adapater will be notified by their alert callback if ARA register read is successful.Quoted 1 line
Signed-off-by Srinivas Pandruvada<srinivas.pandruvada-VuQAYsv1563Yd54FQh9/[email protected]>
drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void
Quoted 10 lines
--- drivers/i2c/i2c-smbus.c | 23 +++++++++++++++++++++++ include/linux/i2c-smbus.h | 3 +++ 2 files changed, 26 insertions(+)drivers/i2c/i2c-smbus.c +0
-0@@ -72,6 +72,29 @@ static int smbus_do_alert(struct device *dev, void*addrp)
Quoted 14 lines
drivers/i2c/i2c-smbus.c +11
-0return -EBUSY ; } +int i2c_smbus_ara_poll (const struct i2c_client *client) +{ +union i2c_smbus_data data; +int status; +struct alert_data alert_data; + + status =i2c_smbus_xfer (client->adapter,0x0C ,0 , +I2C_SMBUS_READ ,0 , +I2C_SMBUS_BYTE , &data); +if (status <0 ) +return status;drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void *addrp) · line 95
Quoted 10 lines
drivers/i2c/i2c-smbus.c +10
-0+ + alert_data.flag = data.byte &1 ; + alert_data.addr = data.byte >>1 ; + +/* Notify driver for the device which issued the alert */ +device_for_each_child (&client->adapter->dev, &alert_data, + smbus_do_alert); + +return data.byte; +}This is essentially duplicating code from
smbus_alert(), but in a hackish way, as the ARA is never properly reserved. Your bus driver should really register the ARA withi2c_setup_smbus_alert().I see that the code may not properly deal with the polled case everywhere but it should be pretty trivial to deal with. For example, check for
alert->irq> 0 before re-enabling the irq insmbus_alert(). I don't immediately see any other change needed.If SMBus alert polling is done from the i2c device driver, we'll have to find a standard way for i2c device drivers to retrieve the ara client associated with an
i2c_adapter. However I still need to be convinced that this makes any sense at all. Ultimately the alert will call the i2c device drivers'salert()callback. If the i2c device driver needs to do that, there's no need to go through ARA, it might as well just call the callback by itself.
Quoted 1 line
So can you please explain what problem exactly you are trying to solve?
As I understand it the issue is that some parts will not clear their internal interrupt status unless an at a read occurs and presumably the read has to get the correct address?
To my mind we should have polling inside the core and it should ensure all devices that want to have replied. Have I miss understood how Ara is supposed to work but should we not know which device to call the callback on?
Quoted 21 lines
drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void *addrp)
Quoted 5 lines
drivers/i2c/i2c-smbus.c +2
-0+EXPORT_SYMBOL_GPL (i2c_smbus_ara_poll); +/* * The alert IRQ handler needs to hand work off to a task which can issue
drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void · line 100
Quoted 1 line
drivers/i2c/i2c-smbus.c +0
-0* SMBus calls, because those sleeping calls can't be made in IRQ context.
include/linux/i2c-smbus.h struct i2c_client *i2c_setup_smbus_alert(struct
Quoted 5 lines
include/linux/i2c-smbus.h +0
-0@@ -48,4 +48,7 @@ struct i2c_client *i2c_setup_smbus_alert(struct
i2c_adapter*adapter,Quoted 7 lines
include/linux/i2c-smbus.h +3
-0struct i2c_smbus_alert_setup *setup);int i2c_handle_smbus_alert (struct i2c_client *ara); +/* Interface to poll smbus alert */ +int i2c_smbus_ara_poll (const struct i2c_client *client); +#endif /* _LINUX_I2C_SMBUS_H */
Signature · 1 line
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
Quoted 68 lines · Jonathan Cameron
Quoted 66 lines · Jean Delvare
Quoted 11 lines · Srinivas Pandruvada
The current i2c smbus alert module depends on smbus alert mechanism supported by underlying bus drivers. By specifications, these alerts can be polled if there is no hardware support.
Currently multiple drivers who needs smbus alerts are creating a new i2c dummy device with address0x0C(ARA register), by luck they don't co-exist. Otherwise i2c device creation will fail. Added a poll interface, so that all these driver can call a common interface to poll. Even if they polli, all drivers bound to an adapater will be notified by their alert callback if ARA register read is successful.Quoted 1 line
Signed-off-by Srinivas Pandruvadadrivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void
Quoted 10 lines
--- drivers/i2c/i2c-smbus.c | 23 +++++++++++++++++++++++ include/linux/i2c-smbus.h | 3 +++ 2 files changed, 26 insertions(+)drivers/i2c/i2c-smbus.c +0
-0@@ -72,6 +72,29 @@ static int smbus_do_alert(struct device *dev, void*addrp)
Quoted 14 lines
drivers/i2c/i2c-smbus.c +11
-0return -EBUSY ; } +int i2c_smbus_ara_poll (const struct i2c_client *client) +{ +union i2c_smbus_data data; +int status; +struct alert_data alert_data; + + status =i2c_smbus_xfer (client->adapter,0x0C ,0 , +I2C_SMBUS_READ ,0 , +I2C_SMBUS_BYTE , &data); +if (status <0 ) +return status;drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void *addrp) · line 95
Quoted 10 lines
drivers/i2c/i2c-smbus.c +10
-0+ + alert_data.flag = data.byte &1 ; + alert_data.addr = data.byte >>1 ; + +/* Notify driver for the device which issued the alert */ +device_for_each_child (&client->adapter->dev, &alert_data, + smbus_do_alert); + +return data.byte; +}This is essentially duplicating code from
smbus_alert(), but in a hackish way, as the ARA is never properly reserved. Your bus driver should really register the ARA withi2c_setup_smbus_alert().I see that the code may not properly deal with the polled case everywhere but it should be pretty trivial to deal with. For example, check for
alert->irq> 0 before re-enabling the irq insmbus_alert(). I don't immediately see any other change needed.If SMBus alert polling is done from the i2c device driver, we'll have to find a standard way for i2c device drivers to retrieve the ara client associated with an
i2c_adapter. However I still need to be convinced that this makes any sense at all. Ultimately the alert will call the i2c device drivers'salert()callback. If the i2c device driver needs to do that, there's no need to go through ARA, it might as well just call the callback by itself.
Quoted 4 lines
Quoted 1 line
So can you please explain what problem exactly you are trying to solve?
As I understand it the issue is that some parts will not clear their internal interrupt status unless an at a read occurs and presumably the read has to get the correct address?
To my mind we should have polling inside the core and it should ensure all devices that want to have replied. Have I miss understood how Ara is supposed to work but should we not know which device to call the callback on?
This is summary: May be Jean can suggest some better solution:
- We have some sensor devices on i2C bus, which need to read ARA register to ack smbus alert signal. Without acking this, they will not allow further reads. They currently are calling i2c_new_dummy() for reserving ARA (0x0C) register. But the problem is if there are two devices on this bus both have to read ARA, they can't call i2c_new_dummy() as one of them will fail (__i2c_check_addr_busy() will return -EBUSY).
- In above case, If they use hacked way to use i2_transfer function, but it will not address the real issue. Because one driver is reading ARA basically can acknowledge ALERT from wrong device.
So their needs to be a core level poll so that devices can be notified, if there is an alert for their device only.
From physical interface level many i2controllers (including x86s) don't have separate signal for SMBALERT#. So somewhere it needs polling. For some devices SMBALERT is wired through a GPIO for GPIO interrupt. But they still need to read ARA to ACK.
Also we can't blindly reserve 0x0c for every i2c-bus as 0x0C is a valid i2C address. There are already occupied (e.g. AK8963 slave address is 0x0C on the same platforms). So can't call i2c_setup_smbus_alert from the bus driver for all i2c buses.
For polling, a bus driver can't decide periodic polling as this is power/perf drain. So my idea was to somehow kick a read on ARA on a bus from interested clients may be when the receive GPIO interrupt. But the results are notified to interested drivers who needs smbus alert processing.
Thanks,
Srinivas
Quoted 20 lines
Quoted 20 lines
drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void *addrp)
Quoted 4 lines
drivers/i2c/i2c-smbus.c +2
-0+EXPORT_SYMBOL_GPL (i2c_smbus_ara_poll); +/* * The alert IRQ handler needs to hand work off to a task which can issue
drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void · line 100
Quoted 1 line
drivers/i2c/i2c-smbus.c +0
-0* SMBus calls, because those sleeping calls can't be made in IRQ context.
include/linux/i2c-smbus.h struct i2c_client *i2c_setup_smbus_alert(struct
Quoted 5 lines
include/linux/i2c-smbus.h +0
-0@@ -48,4 +48,7 @@ struct i2c_client *i2c_setup_smbus_alert(struct
i2c_adapter*adapter,Quoted 7 lines
include/linux/i2c-smbus.h +3
-0struct i2c_smbus_alert_setup *setup);int i2c_handle_smbus_alert (struct i2c_client *ara); +/* Interface to poll smbus alert */ +int i2c_smbus_ara_poll (const struct i2c_client *client); +#endif /* _LINUX_I2C_SMBUS_H */
A message that is not in the archive (sent off-list or not yet received): 53349D41.4090209-VuQAYsv1563Yd54FQh9/[email protected]
Quoted 70 lines · Srinivas Pandruvada
Quoted 69 lines · Jonathan Cameron
Quoted 67 lines · Jean Delvare
Quoted 11 lines · Srinivas Pandruvada
The current i2c smbus alert module depends on smbus alert mechanism supported by underlying bus drivers. By specifications, these alerts can be polled if there is no hardware support.
Currently multiple drivers who needs smbus alerts are creating a new i2c dummy device with address0x0C(ARA register), by luck they don't co-exist. Otherwise i2c device creation will fail. Added a poll interface, so that all these driver can call a common interface to poll. Even if they polli, all drivers bound to an adapater will be notified by their alert callback if ARA register read is successful.Quoted 1 line
Signed-off-by Srinivas Pandruvadadrivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void
Quoted 10 lines
--- drivers/i2c/i2c-smbus.c | 23 +++++++++++++++++++++++ include/linux/i2c-smbus.h | 3 +++ 2 files changed, 26 insertions(+)drivers/i2c/i2c-smbus.c +0
-0@@ -72,6 +72,29 @@ static int smbus_do_alert(struct device *dev, void*addrp)
Quoted 14 lines
drivers/i2c/i2c-smbus.c +11
-0return -EBUSY ; } +int i2c_smbus_ara_poll (const struct i2c_client *client) +{ +union i2c_smbus_data data; +int status; +struct alert_data alert_data; + + status =i2c_smbus_xfer (client->adapter,0x0C ,0 , +I2C_SMBUS_READ ,0 , +I2C_SMBUS_BYTE , &data); +if (status <0 ) +return status;drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void · line 95
Quoted 10 lines
drivers/i2c/i2c-smbus.c +10
-0+ + alert_data.flag = data.byte &1 ; + alert_data.addr = data.byte >>1 ; + +/* Notify driver for the device which issued the alert */ +device_for_each_child (&client->adapter->dev, &alert_data, + smbus_do_alert); + +return data.byte; +}This is essentially duplicating code from
smbus_alert(), but in a hackish way, as the ARA is never properly reserved. Your bus driver should really register the ARA withi2c_setup_smbus_alert().I see that the code may not properly deal with the polled case everywhere but it should be pretty trivial to deal with. For example, check for
alert->irq> 0 before re-enabling the irq insmbus_alert(). I don't immediately see any other change needed.If SMBus alert polling is done from the i2c device driver, we'll have to find a standard way for i2c device drivers to retrieve the ara client associated with an
i2c_adapter. However I still need to be convinced that this makes any sense at all. Ultimately the alert will call the i2c device drivers'salert()callback. If the i2c device driver needs to do that, there's no need to go through ARA, it might as well just call the callback by itself.So can you please explain what problem exactly you are trying to solve?
Quoted 8 lines
Quoted 8 lines
As I understand it the issue is that some parts will not clear their internal interrupt status unless an at a read occurs and presumably the read has to get the correct address?
To my mind we should have polling inside the core and it should ensure all devices that want to have replied. Have I miss understood how Ara is supposed to work but should we not know which device to call the callback on?
Ah, I was barking up the wrong tree with this one and had missed the check that was conducted to ensure that only the right device is notified. Sorry about that.
Quoted 12 lines
This is summary: May be Jean can suggest some better solution: - We have some sensor devices on i2C bus, which need to read ARA register to ack smbus alert signal. Without acking this, they will not allow further reads. They currently are calling
i2c_new_dummy()for reserving ARA (0x0C) register. But the problem is if there are two devices on this bus both have to read ARA, they can't calli2c_new_dummy()as one of them will fail (__i2c_check_addr_busy()will return-EBUSY). - In above case, If they use hacked way to usei2_transferfunction, but it will not address the real issue. Because one driver is reading ARA basically can acknowledge ALERT from wrong device.
Quoted 2 lines
So their needs to be a core level poll so that devices can be notified, if there is an alert for their device only.
Agreed. Right now at a quick glance, all devices are notified which seems odd...
Quoted 5 lines
From physical interface level many i2controllers (including x86s) don't have separate signal for SMBALERT#. So somewhere it needs polling. For some devices SMBALERT is wired through a GPIO for GPIO interrupt. But they still need to read ARA to ACK.
If it is wired through a gpio interrupt (and that interrupt is shared by various smbalert equipped devices - or there is only one present on the i2c bus) then it should be handled using the existing infrastructure. (perhaps modified slightly)
Quoted 5 lines
Also we can't blindly reserve
0x0cfor every i2c-bus as0x0Cis a valid i2C address. There are already occupied (e.g. AK8963 slave address is0x0Con the same platforms). So can't calli2c_setup_smbus_alertfrom the bus driver for all i2c buses.
If platforms are wiring up both devices using this i2c address and smbus alert devices then we are in an irritating corner case. This is effectively the same as having two different smbus devices on the same address and relying on the fact they don't have overlapping address spaces. Nuts but I guess we want to find some way of coping with it?
Perhaps we need away of allow multiple i2c devices to share a bus in this case? Is this something that could be done via a nefarious hack of using a mux to pretend that they are separately wired (when they aren't).
Quoted 3 lines
For polling, a bus driver can't decide periodic polling as this is power/perf drain.
Agreed, so hints from the drivers to the core would be needed.
Quoted 2 lines
So my idea was to somehow kick a read on ARA on a
bus from interested clients may be when the receive GPIO interrupt.
Then you can end up with considerable waste if you have lots of devices using this functionality on the same bus. Each driver polls at say 50Hz, because it wants 50Hz, but you have 20 devices hence you get uneven sampling at say 1kHz and might even block the i2c bus up entirely. Hence the polling needs to be handled by the core. I'd suggest a call to request enabling of polling and a frequency. Then the core just uses the highest frequency currently requested.
It's a bit more complex than the nice sensible interrupt driven version, but if board designers are going to do silly things I guess we have to figure out how to make them work.
Quoted 39 lines
But the results are notified to interested drivers who needs smbus alert processing.
Thanks,
SrinivasQuoted 20 lines
Quoted 20 lines
drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void · line 99
Quoted 4 lines
drivers/i2c/i2c-smbus.c +2
-0+EXPORT_SYMBOL_GPL (i2c_smbus_ara_poll); +/* * The alert IRQ handler needs to hand work off to a task which can issue
drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void · line 100
Quoted 1 line
drivers/i2c/i2c-smbus.c +0
-0* SMBus calls, because those sleeping calls can't be made in IRQ context.
include/linux/i2c-smbus.h struct i2c_client *i2c_setup_smbus_alert(struct
Quoted 5 lines
include/linux/i2c-smbus.h +0
-0@@ -48,4 +48,7 @@ struct i2c_client *i2c_setup_smbus_alert(struct
i2c_adapter*adapter,Quoted 7 lines
include/linux/i2c-smbus.h +3
-0struct i2c_smbus_alert_setup *setup);int i2c_handle_smbus_alert (struct i2c_client *ara); +/* Interface to poll smbus alert */ +int i2c_smbus_ara_poll (const struct i2c_client *client); +#endif /* _LINUX_I2C_SMBUS_H */
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 100 lines · Jonathan Cameron
Quoted 70 lines · Srinivas Pandruvada
Quoted 69 lines · Jonathan Cameron
Quoted 67 lines · Jean Delvare
Quoted 11 lines · Srinivas Pandruvada
The current i2c smbus alert module depends on smbus alert mechanism supported by underlying bus drivers. By specifications, these alerts can be polled if there is no hardware support.
Currently multiple drivers who needs smbus alerts are creating a new i2c dummy device with address0x0C(ARA register), by luck they don't co-exist. Otherwise i2c device creation will fail. Added a poll interface, so that all these driver can call a common interface to poll. Even if they polli, all drivers bound to an adapater will be notified by their alert callback if ARA register read is successful.Quoted 1 line
Signed-off-by Srinivas Pandruvada<srinivas.pandruvada-VuQAYsv1563Yd54FQh9/[email protected]>
drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void
Quoted 10 lines
--- drivers/i2c/i2c-smbus.c | 23 +++++++++++++++++++++++ include/linux/i2c-smbus.h | 3 +++ 2 files changed, 26 insertions(+)drivers/i2c/i2c-smbus.c +0
-0@@ -72,6 +72,29 @@ static int smbus_do_alert(struct device *dev, void*addrp)
Quoted 14 lines
drivers/i2c/i2c-smbus.c +11
-0return -EBUSY ; } +int i2c_smbus_ara_poll (const struct i2c_client *client) +{ +union i2c_smbus_data data; +int status; +struct alert_data alert_data; + + status =i2c_smbus_xfer (client->adapter,0x0C ,0 , +I2C_SMBUS_READ ,0 , +I2C_SMBUS_BYTE , &data); +if (status <0 ) +return status;drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void · line 95
Quoted 10 lines
drivers/i2c/i2c-smbus.c +10
-0+ + alert_data.flag = data.byte &1 ; + alert_data.addr = data.byte >>1 ; + +/* Notify driver for the device which issued the alert */ +device_for_each_child (&client->adapter->dev, &alert_data, + smbus_do_alert); + +return data.byte; +}This is essentially duplicating code from
smbus_alert(), but in a hackish way, as the ARA is never properly reserved. Your bus driver should really register the ARA withi2c_setup_smbus_alert().I see that the code may not properly deal with the polled case everywhere but it should be pretty trivial to deal with. For example, check for
alert->irq> 0 before re-enabling the irq insmbus_alert(). I don't immediately see any other change needed.If SMBus alert polling is done from the i2c device driver, we'll have to find a standard way for i2c device drivers to retrieve the ara client associated with an
i2c_adapter. However I still need to be convinced that this makes any sense at all. Ultimately the alert will call the i2c device drivers'salert()callback. If the i2c device driver needs to do that, there's no need to go through ARA, it might as well just call the callback by itself.So can you please explain what problem exactly you are trying to solve?
Quoted 8 lines
Quoted 8 lines
As I understand it the issue is that some parts will not clear their internal interrupt status unless an at a read occurs and presumably the read has to get the correct address?
To my mind we should have polling inside the core and it should ensure all devices that want to have replied. Have I miss understood how Ara is supposed to work but should we not know which device to call the callback on?
Ah, I was barking up the wrong tree with this one and had missed the check that was conducted to ensure that only the right device is notified. Sorry about that.
Quoted 12 lines
This is summary: May be Jean can suggest some better solution: - We have some sensor devices on i2C bus, which need to read ARA register to ack smbus alert signal. Without acking this, they will not allow further reads. They currently are calling
i2c_new_dummy()for reserving ARA (0x0C) register. But the problem is if there are two devices on this bus both have to read ARA, they can't calli2c_new_dummy()as one of them will fail (__i2c_check_addr_busy()will return-EBUSY). - In above case, If they use hacked way to usei2_transferfunction, but it will not address the real issue. Because one driver is reading ARA basically can acknowledge ALERT from wrong device.Quoted 2 lines
So their needs to be a core level poll so that devices can be notified, if there is an alert for their device only.
Agreed. Right now at a quick glance, all devices are notified which seems odd...
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
From physical interface level many i2controllers (including x86s) don't have separate signal for SMBALERT#. So somewhere it needs polling. For some devices SMBALERT is wired through a GPIO for GPIO interrupt. But they still need to read ARA to ACK.
If it is wired through a gpio interrupt (and that interrupt is shared by various smbalert equipped devices - or there is only one present on the i2c bus) then it should be handled using the existing infrastructure. (perhaps modified slightly)
If we somehow know that the interrupt is for SMBALERT, we could
do with the current mechanisms. The ACPI configuration only provides
an IRQ number for each device, but don't provide whether it is for SMBALERT.
If we know we can handle it better. I will ping ACPI committee, if they can add better support.
Quoted 22 lines
Quoted 5 lines
Also we can't blindly reserve
0x0cfor every i2c-bus as0x0Cis a valid i2C address. There are already occupied (e.g. AK8963 slave address is0x0Con the same platforms). So can't calli2c_setup_smbus_alertfrom the bus driver for all i2c buses.If platforms are wiring up both devices using this i2c address and smbus alert devices then we are in an irritating corner case. This is effectively the same as having two different smbus devices on the same address and relying on the fact they don't have overlapping address spaces. Nuts but I guess we want to find some way of coping with it?
Perhaps we need away of allow multiple i2c devices to share a bus in this case? Is this something that could be done via a nefarious hack of using a mux to pretend that they are separately wired (when they aren't).
Quoted 3 lines
For polling, a bus driver can't decide periodic polling as this is power/perf drain.
Agreed, so hints from the drivers to the core would be needed.
Quoted 2 lines
So my idea was to somehow kick a read on ARA on a
bus from interested clients may be when the receive GPIO interrupt.
Quoted 8 lines
Then you can end up with considerable waste if you have lots of devices using this functionality on the same bus. Each driver polls at say 50Hz, because it wants 50Hz, but you have 20 devices hence you get uneven sampling at say 1kHz and might even block the i2c bus up entirely. Hence the polling needs to be handled by the core. I'd suggest a call to request enabling of polling and a frequency. Then the core just uses the highest frequency currently requested.
Agreed.
Quoted 4 lines
It's a bit more complex than the nice sensible interrupt driven version, but if board designers are going to do silly things I guess we have to figure out how to make them work.
That is the reality.
Thanks,
Srinivas
Quoted 41 lines
Quoted 39 lines
But the results are notified to interested drivers who needs smbus alert processing.
Thanks,
SrinivasQuoted 20 lines
Quoted 20 lines
drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void · line 99
Quoted 4 lines
drivers/i2c/i2c-smbus.c +2
-0+EXPORT_SYMBOL_GPL (i2c_smbus_ara_poll); +/* * The alert IRQ handler needs to hand work off to a task which can issue
drivers/i2c/i2c-smbus.c static int smbus_do_alert(struct device *dev, void · line 100
Quoted 1 line
drivers/i2c/i2c-smbus.c +0
-0* SMBus calls, because those sleeping calls can't be made in IRQ context.
include/linux/i2c-smbus.h struct i2c_client *i2c_setup_smbus_alert(struct
Quoted 5 lines
include/linux/i2c-smbus.h +0
-0@@ -48,4 +48,7 @@ struct i2c_client *i2c_setup_smbus_alert(struct
i2c_adapter*adapter,Quoted 7 lines
include/linux/i2c-smbus.h +3
-0struct i2c_smbus_alert_setup *setup);int i2c_handle_smbus_alert (struct i2c_client *ara); +/* Interface to poll smbus alert */ +int i2c_smbus_ara_poll (const struct i2c_client *client); +#endif /* _LINUX_I2C_SMBUS_H */