* [PATCH] 2.6 I2C re-add i2c_get_client()
@ 2004-04-29 14:06 stefan.eletzhofer
2004-05-02 6:01 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: stefan.eletzhofer @ 2004-04-29 14:06 UTC (permalink / raw)
To: Linux Kernel Mailing List; +Cc: Greg KH, Andrew Morton
[-- Attachment #1: Type: text/plain, Size: 749 bytes --]
Hi,
here's a patch which re-adds i2c_get_client() back to i2c_core.c.
That call was removed in 2003 because there were no users of that
function at that time.
I think this call is needed for I2C chip drivers which provide functionality to
be used by other driver modules, for example RTC chips or EEPROMs. These chip
drivers tend to encapsulate raw i2c chip access and provide function calls
for other modulesi, for example via the i2c_driver->command() method.
I tried to get the locking right, so please comment. The patch is
against 2.6.6-rc3 and works quite fine with my i2c rtc chip.
Thanks,
Stefan E.
--
Eletztrick Computing - Customized Linux Development
Stefan Eletzhofer, Marktstrasse 43, DE-88214 Ravensburg
http://www.eletztrick.de
[-- Attachment #2: i2c-get-client.patch --]
[-- Type: text/plain, Size: 1851 bytes --]
Add back missing i2c_get_client() call.
#
# Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher
#
--- linux-ra_alpha-update/drivers/i2c/i2c-core.c~i2c-get-client
+++ linux-ra_alpha-update/drivers/i2c/i2c-core.c
@@ -412,6 +412,57 @@
return res;
}
+struct i2c_client *i2c_get_client(int driver_id, int adapter_id,
+ struct i2c_client *prev)
+{
+ struct list_head *adap_list;
+ struct list_head *item, *_n;
+ struct i2c_adapter *adap;
+ struct i2c_client *client;
+ int found;
+
+ down(&core_lists);
+
+ adap_list = &adapters;
+ if ( prev ) {
+ /* we start searching at the previous clients adapter */
+ adap_list = &prev->adapter->list;
+ }
+
+ found = 0;
+ client = NULL;
+ list_for_each_entry(adap, adap_list, list) {
+ dev_dbg(&adap->dev, "examining adapter id=%08x\n", adap->id);
+
+ if ( adapter_id && adap->id != adapter_id )
+ continue; /* not the adapter id we want */
+
+ list_for_each_safe(item, _n, &adap->clients) {
+ client = list_entry(item, struct i2c_client, list);
+ dev_dbg(&client->dev, "examining client\n");
+ dev_dbg(&client->dev, "driver id=%08x\n", client->driver->id);
+
+ if ( prev && prev == client ) {
+ prev = NULL;
+ continue;
+ }
+
+ if (client->driver->id != driver_id)
+ continue; /* not the driver id we want */
+
+ if ( client->flags & I2C_CLIENT_ALLOW_USE ) {
+ dev_dbg(&client->dev, "found client\n");
+ found = 1;
+ goto out_unlock;
+ }
+ }
+ }
+
+out_unlock:
+ up(&core_lists);
+ return found?client:NULL;
+}
+
static int i2c_inc_use_client(struct i2c_client *client)
{
@@ -1261,6 +1312,7 @@
EXPORT_SYMBOL(i2c_del_driver);
EXPORT_SYMBOL(i2c_attach_client);
EXPORT_SYMBOL(i2c_detach_client);
+EXPORT_SYMBOL(i2c_get_client);
EXPORT_SYMBOL(i2c_use_client);
EXPORT_SYMBOL(i2c_release_client);
EXPORT_SYMBOL(i2c_clients_command);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] 2.6 I2C re-add i2c_get_client()
2004-04-29 14:06 [PATCH] 2.6 I2C re-add i2c_get_client() stefan.eletzhofer
@ 2004-05-02 6:01 ` Greg KH
2004-05-02 15:08 ` stefan.eletzhofer
0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2004-05-02 6:01 UTC (permalink / raw)
To: stefan.eletzhofer, Linux Kernel Mailing List, Andrew Morton
On Thu, Apr 29, 2004 at 04:06:57PM +0200, stefan.eletzhofer@eletztrick.de wrote:
> Hi,
> here's a patch which re-adds i2c_get_client() back to i2c_core.c.
> That call was removed in 2003 because there were no users of that
> function at that time.
>
> I think this call is needed for I2C chip drivers which provide functionality to
> be used by other driver modules, for example RTC chips or EEPROMs. These chip
> drivers tend to encapsulate raw i2c chip access and provide function calls
> for other modulesi, for example via the i2c_driver->command() method.
>
> I tried to get the locking right, so please comment. The patch is
> against 2.6.6-rc3 and works quite fine with my i2c rtc chip.
Locking looks correct, but you also need to increment either the
device's reference count, and/or the module reference count for the
client.
Care to fix that up?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] 2.6 I2C re-add i2c_get_client()
2004-05-02 6:01 ` Greg KH
@ 2004-05-02 15:08 ` stefan.eletzhofer
2004-05-07 22:30 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: stefan.eletzhofer @ 2004-05-02 15:08 UTC (permalink / raw)
To: Linux Kernel Mailing List; +Cc: Greg KH, Andrew Morton
On Sat, May 01, 2004 at 11:01:09PM -0700, Greg KH wrote:
> On Thu, Apr 29, 2004 at 04:06:57PM +0200, stefan.eletzhofer@eletztrick.de wrote:
> > Hi,
> > here's a patch which re-adds i2c_get_client() back to i2c_core.c.
> > That call was removed in 2003 because there were no users of that
> > function at that time.
> >
> > I think this call is needed for I2C chip drivers which provide functionality to
> > be used by other driver modules, for example RTC chips or EEPROMs. These chip
> > drivers tend to encapsulate raw i2c chip access and provide function calls
> > for other modulesi, for example via the i2c_driver->command() method.
> >
> > I tried to get the locking right, so please comment. The patch is
> > against 2.6.6-rc3 and works quite fine with my i2c rtc chip.
>
> Locking looks correct, but you also need to increment either the
> device's reference count, and/or the module reference count for the
> client.
I thought that would be the purpose of i2c_use_client(), like the comment
in linux/i2c.h suggests? That call also takes care of the ALLOW_USE flag.
i2c_use_client() increments both the drivers and the adapters module ref
count, if I see it correctly. Then it also increments the clients usage count,
after checking the ALLOW_MULTIPLE_USE flag.
Its counterpart is i2c_release_client().
>
> Care to fix that up?
>
> thanks,
>
> greg k-h
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
Eletztrick Computing - Customized Linux Development
Stefan Eletzhofer, Marktstrasse 43, DE-88214 Ravensburg
http://www.eletztrick.de
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] 2.6 I2C re-add i2c_get_client()
2004-05-02 15:08 ` stefan.eletzhofer
@ 2004-05-07 22:30 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2004-05-07 22:30 UTC (permalink / raw)
To: stefan.eletzhofer, Linux Kernel Mailing List, Andrew Morton
On Sun, May 02, 2004 at 05:08:15PM +0200, stefan.eletzhofer@eletztrick.de wrote:
> On Sat, May 01, 2004 at 11:01:09PM -0700, Greg KH wrote:
> > On Thu, Apr 29, 2004 at 04:06:57PM +0200, stefan.eletzhofer@eletztrick.de wrote:
> > > Hi,
> > > here's a patch which re-adds i2c_get_client() back to i2c_core.c.
> > > That call was removed in 2003 because there were no users of that
> > > function at that time.
> > >
> > > I think this call is needed for I2C chip drivers which provide functionality to
> > > be used by other driver modules, for example RTC chips or EEPROMs. These chip
> > > drivers tend to encapsulate raw i2c chip access and provide function calls
> > > for other modulesi, for example via the i2c_driver->command() method.
> > >
> > > I tried to get the locking right, so please comment. The patch is
> > > against 2.6.6-rc3 and works quite fine with my i2c rtc chip.
> >
> > Locking looks correct, but you also need to increment either the
> > device's reference count, and/or the module reference count for the
> > client.
>
> I thought that would be the purpose of i2c_use_client(), like the comment
> in linux/i2c.h suggests? That call also takes care of the ALLOW_USE flag.
Yes, but your new function doesn't call it, right? What happens if the
driver goes away between the get_client call and the use_client call?
oops...
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-05-08 0:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-29 14:06 [PATCH] 2.6 I2C re-add i2c_get_client() stefan.eletzhofer
2004-05-02 6:01 ` Greg KH
2004-05-02 15:08 ` stefan.eletzhofer
2004-05-07 22:30 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox