Patchwork i2c: introduce i2c helper i2c_find_client_by_name()

login
register
mail settings
Submitter Bin Gao
Date June 6, 2013, 6:33 p.m.
Message ID <20130606183346.GA13259@bingao-desk1.fm.intel.com>
Download mbox | patch
Permalink /patch/249531/
State Deferred
Headers show

Comments

Bin Gao - June 6, 2013, 6:33 p.m.
i2c: introduce i2c helper i2c_find_client_by_name()

There is a requirement to get the i2c_client pointer dynamically without
knowing the bus and slave address. But we do know the client name,
i.e. the name in the i2c_board_info. This patch is to fit this requirement.

A good example is that an ISP(Imaging Signal Processor) driver needs
register i2c camera sensor devices via v4l2, so it has to unregister
all i2c clients that were previously registered by calling
i2c_register_board_info(), and then re-register. For this case we
can use this helper to get i2c_client by passing the client name.

Signed-off-by: Bin Gao <bin.gao@linux.intel.com>
---
 drivers/i2c/i2c-core.c |   17 +++++++++++++++++
 include/linux/i2c.h    |    1 +
 2 files changed, 18 insertions(+), 0 deletions(-)
Andy Shevchenko - June 6, 2013, 8:32 p.m.
On Thu, Jun 6, 2013 at 9:33 PM, Bin Gao <bin.gao@linux.intel.com> wrote:
> There is a requirement to get the i2c_client pointer dynamically without
> knowing the bus and slave address. But we do know the client name,
> i.e. the name in the i2c_board_info. This patch is to fit this requirement.
>
> A good example is that an ISP(Imaging Signal Processor) driver needs
> register i2c camera sensor devices via v4l2, so it has to unregister
> all i2c clients that were previously registered by calling
> i2c_register_board_info(), and then re-register. For this case we
> can use this helper to get i2c_client by passing the client name.

Why ISP driver would like to register sensor drivers in the first place?
That seems the task of platform code, or DT, or ACPI5

Why do you need to re-register them at run time?

--
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bin Gao - June 6, 2013, 9:26 p.m.
With v4l2, the camera sensor i2c devices are taken over by v4l2 master
driver, i.e. ISP driver, and are not expected to be accessed from
user sapce by ioctl. So ISP driver has to register them by itself to
get all related information for further communication. Please check
v4l2_i2c_new_subdev_board() in drivers/media/video/v4l2-common.c for details.

The platform code can definitely disallow calling i2c_register_board_info()
to register them but keep the i2c devices list and then let ISP driver register
them. But, problems come when a single kernel is going to run on two platforms
- one platform has ACPI5 and the other has SFI. The dynamic unregister and then
register based on this new helper will not have dependency on firmware interface -
the same platform code will work for all platforms.

On Thu, Jun 06, 2013 at 11:32:06PM +0300, Andy Shevchenko wrote:
> On Thu, Jun 6, 2013 at 9:33 PM, Bin Gao <bin.gao@linux.intel.com> wrote:
> > There is a requirement to get the i2c_client pointer dynamically without
> > knowing the bus and slave address. But we do know the client name,
> > i.e. the name in the i2c_board_info. This patch is to fit this requirement.
> >
> > A good example is that an ISP(Imaging Signal Processor) driver needs
> > register i2c camera sensor devices via v4l2, so it has to unregister
> > all i2c clients that were previously registered by calling
> > i2c_register_board_info(), and then re-register. For this case we
> > can use this helper to get i2c_client by passing the client name.
> 
> Why ISP driver would like to register sensor drivers in the first place?
> That seems the task of platform code, or DT, or ACPI5
> 
> Why do you need to re-register them at run time?
> 
> --
> With Best Regards,
> Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Shevchenko - June 9, 2013, 7:53 p.m.
Please, try to avoid top posting in the future emails.

On Fri, Jun 7, 2013 at 12:26 AM, Bin Gao <bin.gao@linux.intel.com> wrote:
> With v4l2, the camera sensor i2c devices are taken over by v4l2 master
> driver, i.e. ISP driver, and are not expected to be accessed from
> user sapce by ioctl. So ISP driver has to register them by itself to
> get all related information for further communication. Please check
> v4l2_i2c_new_subdev_board() in drivers/media/video/v4l2-common.c for details.

Yes, this is legacy approach for non-DT/non-ACPI5 platforms.

> The platform code can definitely disallow calling i2c_register_board_info()
> to register them but keep the i2c devices list and then let ISP driver register
> them. But, problems come when a single kernel is going to run on two platforms
> - one platform has ACPI5 and the other has SFI.

You have to forget about SFI. Your ISP subdevices use plain platform
data anyway.
In ACPI 5 case v4l2 framework must be extended to cover that case.

> The dynamic unregister and then
> register based on this new helper will not have dependency on firmware interface -
> the same platform code will work for all platforms.

It's not a care of the ISP driver. I think you have to talk to Sakari
about your issues.

> On Thu, Jun 06, 2013 at 11:32:06PM +0300, Andy Shevchenko wrote:
>> On Thu, Jun 6, 2013 at 9:33 PM, Bin Gao <bin.gao@linux.intel.com> wrote:
>> > There is a requirement to get the i2c_client pointer dynamically without
>> > knowing the bus and slave address. But we do know the client name,
>> > i.e. the name in the i2c_board_info. This patch is to fit this requirement.
>> >
>> > A good example is that an ISP(Imaging Signal Processor) driver needs
>> > register i2c camera sensor devices via v4l2, so it has to unregister
>> > all i2c clients that were previously registered by calling
>> > i2c_register_board_info(), and then re-register. For this case we
>> > can use this helper to get i2c_client by passing the client name.
>>
>> Why ISP driver would like to register sensor drivers in the first place?
>> That seems the task of platform code, or DT, or ACPI5
>>
>> Why do you need to re-register them at run time?

--
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bin Gao - June 11, 2013, 5:11 p.m.
On Sun, Jun 09, 2013 at 10:53:35PM +0300, Andy Shevchenko wrote:
> Please, try to avoid top posting in the future emails.
> 
> On Fri, Jun 7, 2013 at 12:26 AM, Bin Gao <bin.gao@linux.intel.com> wrote:
> > With v4l2, the camera sensor i2c devices are taken over by v4l2 master
> > driver, i.e. ISP driver, and are not expected to be accessed from
> > user sapce by ioctl. So ISP driver has to register them by itself to
> > get all related information for further communication. Please check
> > v4l2_i2c_new_subdev_board() in drivers/media/video/v4l2-common.c for details.
> 
> Yes, this is legacy approach for non-DT/non-ACPI5 platforms.

So what's the new approach for DT/ACPI5 platforms?

> 
> > The platform code can definitely disallow calling i2c_register_board_info()
> > to register them but keep the i2c devices list and then let ISP driver register
> > them. But, problems come when a single kernel is going to run on two platforms
> > - one platform has ACPI5 and the other has SFI.
> 
> You have to forget about SFI. Your ISP subdevices use plain platform
> data anyway.

Why have to forget about SFI which is supported by upstream kernel?

> In ACPI 5 case v4l2 framework must be extended to cover that case.

To extend v4l2 framework is one of the options, but this helper is also one
option.

> > The dynamic unregister and then
> > register based on this new helper will not have dependency on firmware interface -
> > the same platform code will work for all platforms.
> 
> It's not a care of the ISP driver. I think you have to talk to Sakari
> about your issues.

We have to do it in the ISP driver if we want one binary kernel
supporting multiple platforms.

> > On Thu, Jun 06, 2013 at 11:32:06PM +0300, Andy Shevchenko wrote:
> >> On Thu, Jun 6, 2013 at 9:33 PM, Bin Gao <bin.gao@linux.intel.com> wrote:
> >> > There is a requirement to get the i2c_client pointer dynamically without
> >> > knowing the bus and slave address. But we do know the client name,
> >> > i.e. the name in the i2c_board_info. This patch is to fit this requirement.
> >> >
> >> > A good example is that an ISP(Imaging Signal Processor) driver needs
> >> > register i2c camera sensor devices via v4l2, so it has to unregister
> >> > all i2c clients that were previously registered by calling
> >> > i2c_register_board_info(), and then re-register. For this case we
> >> > can use this helper to get i2c_client by passing the client name.
> >>
> >> Why ISP driver would like to register sensor drivers in the first place?
> >> That seems the task of platform code, or DT, or ACPI5
> >>
> >> Why do you need to re-register them at run time?
> 
> --
> With Best Regards,
> Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Shevchenko - June 14, 2013, 7:29 a.m.
On Tue, Jun 11, 2013 at 8:11 PM, Bin Gao <bin.gao@linux.intel.com> wrote:
> On Sun, Jun 09, 2013 at 10:53:35PM +0300, Andy Shevchenko wrote:
>> Please, try to avoid top posting in the future emails.
>>
>> On Fri, Jun 7, 2013 at 12:26 AM, Bin Gao <bin.gao@linux.intel.com> wrote:
>> > With v4l2, the camera sensor i2c devices are taken over by v4l2 master
>> > driver, i.e. ISP driver, and are not expected to be accessed from
>> > user sapce by ioctl. So ISP driver has to register them by itself to
>> > get all related information for further communication. Please check
>> > v4l2_i2c_new_subdev_board() in drivers/media/video/v4l2-common.c for details.
>>
>> Yes, this is legacy approach for non-DT/non-ACPI5 platforms.
>
> So what's the new approach for DT/ACPI5 platforms?

When DT or ACPI5 is enabled and used the devices are enumerated
through corresponding frameworks in the kernel automatically. So, you
get them initialized just after i2c host.

>> > The platform code can definitely disallow calling i2c_register_board_info()
>> > to register them but keep the i2c devices list and then let ISP driver register
>> > them. But, problems come when a single kernel is going to run on two platforms
>> > - one platform has ACPI5 and the other has SFI.
>>
>> You have to forget about SFI. Your ISP subdevices use plain platform
>> data anyway.
>
> Why have to forget about SFI which is supported by upstream kernel?

It doesn't matter. Second sentence above is explained why. SFI,
unfortunately, has few design flaws, that's why the information
located there is not much useful in ISP case.

>> In ACPI 5 case v4l2 framework must be extended to cover that case.
> To extend v4l2 framework is one of the options,

That is proper option.

> but this helper is also one
> option.

I think this helper doesn't align to the current workflow.

>> > The dynamic unregister and then
>> > register based on this new helper will not have dependency on firmware interface -
>> > the same platform code will work for all platforms.
>>
>> It's not a care of the ISP driver. I think you have to talk to Sakari
>> about your issues.
>
> We have to do it in the ISP driver if we want one binary kernel
> supporting multiple platforms.

What I'm talking about is not contradicting with that.

>> >> > A good example is that an ISP(Imaging Signal Processor) driver needs
>> >> > register i2c camera sensor devices via v4l2, so it has to unregister
>> >> > all i2c clients that were previously registered by calling
>> >> > i2c_register_board_info(), and then re-register.

>> >> Why do you need to re-register them at run time?

Still this question is not answered.


--
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bin Gao - June 14, 2013, 7 p.m.
On Fri, Jun 14, 2013 at 10:29:09AM +0300, Andy Shevchenko wrote:
> On Tue, Jun 11, 2013 at 8:11 PM, Bin Gao <bin.gao@linux.intel.com> wrote:
> > On Sun, Jun 09, 2013 at 10:53:35PM +0300, Andy Shevchenko wrote:
> >> Please, try to avoid top posting in the future emails.
> >>
> >> On Fri, Jun 7, 2013 at 12:26 AM, Bin Gao <bin.gao@linux.intel.com> wrote:
> >> > With v4l2, the camera sensor i2c devices are taken over by v4l2 master
> >> > driver, i.e. ISP driver, and are not expected to be accessed from
> >> > user sapce by ioctl. So ISP driver has to register them by itself to
> >> > get all related information for further communication. Please check
> >> > v4l2_i2c_new_subdev_board() in drivers/media/video/v4l2-common.c for details.
> >>
> >> Yes, this is legacy approach for non-DT/non-ACPI5 platforms.
> >
> > So what's the new approach for DT/ACPI5 platforms?
> 
> When DT or ACPI5 is enabled and used the devices are enumerated
> through corresponding frameworks in the kernel automatically. So, you
> get them initialized just after i2c host.

This is also true for SFI.
 
> >> > The platform code can definitely disallow calling i2c_register_board_info()
> >> > to register them but keep the i2c devices list and then let ISP driver register
> >> > them. But, problems come when a single kernel is going to run on two platforms
> >> > - one platform has ACPI5 and the other has SFI.
> >>
> >> You have to forget about SFI. Your ISP subdevices use plain platform
> >> data anyway.
> >
> > Why have to forget about SFI which is supported by upstream kernel?
> 
> It doesn't matter. Second sentence above is explained why. SFI,
> unfortunately, has few design flaws, that's why the information
> located there is not much useful in ISP case.

No, from device enumeration point of view, SFI is doing the same thing
as DT and ACPI5. I didn't see any flaws here.


> >> In ACPI 5 case v4l2 framework must be extended to cover that case.
> > To extend v4l2 framework is one of the options,
> 
> That is proper option.
> 
> > but this helper is also one
> > option.
> 
> I think this helper doesn't align to the current workflow.

Even you prefer to extend v4l2, you still need this helper.
The idea is just to move the unregister/register from a specific ISP driver
to v4l2.

I think you misunderstood my pionts somehow. Let me clarfiy a little bit:

Current solution:
1. Platform codes(on top of DT/ACPI5/SFI) don't call i2c_register_board_info(),
instead, prepare a table(kind of platform data) that has all camera i2c device information.
2. ISP driver registers devices listed in the table to i2c core - this makes sure
v4l2 takes over these devices.
The problem with this solution is that when a camera device runs on both ACPI5 and
SFI, the platform codes will get a bit complicated and it's difficult to ensure one
binary kernel runs on both platforms(ACPI5 and SFI).
(To extend v4l2 with this solution doen't resolve my problem)

Solution I'm suggesting:
1. Let the platform codes call i2c_register_board_info() anyway.
2. Since ISP driver knows which camera devices it supports, so it simply unregisters
those devices (get the client by the introduced helper), then register it within v4l2.
This solution ensure one binary kernel can run on both platforms.
(To extend v4l2 with this solution could not be feasible, the device table is
ISP driver specific, not v4l2 specific)

> >> > The dynamic unregister and then
> >> > register based on this new helper will not have dependency on firmware interface -
> >> > the same platform code will work for all platforms.
> >>
> >> It's not a care of the ISP driver. I think you have to talk to Sakari
> >> about your issues.
> >
> > We have to do it in the ISP driver if we want one binary kernel
> > supporting multiple platforms.
> 
> What I'm talking about is not contradicting with that.
> 
> >> >> > A good example is that an ISP(Imaging Signal Processor) driver needs
> >> >> > register i2c camera sensor devices via v4l2, so it has to unregister
> >> >> > all i2c clients that were previously registered by calling
> >> >> > i2c_register_board_info(), and then re-register.
> 
> >> >> Why do you need to re-register them at run time?
> 
> Still this question is not answered.
> 
> 
> --
> With Best Regards,
> Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang - June 19, 2013, 10:13 a.m.
> Even you prefer to extend v4l2, you still need this helper.
> The idea is just to move the unregister/register from a specific ISP driver
> to v4l2.
> 
> I think you misunderstood my pionts somehow. Let me clarfiy a little bit:
> 
> Current solution:
> 1. Platform codes(on top of DT/ACPI5/SFI) don't call i2c_register_board_info(),
> instead, prepare a table(kind of platform data) that has all camera i2c device information.
> 2. ISP driver registers devices listed in the table to i2c core - this makes sure
> v4l2 takes over these devices.
> The problem with this solution is that when a camera device runs on both ACPI5 and
> SFI, the platform codes will get a bit complicated and it's difficult to ensure one
> binary kernel runs on both platforms(ACPI5 and SFI).
> (To extend v4l2 with this solution doen't resolve my problem)
> 
> Solution I'm suggesting:
> 1. Let the platform codes call i2c_register_board_info() anyway.
> 2. Since ISP driver knows which camera devices it supports, so it simply unregisters
> those devices (get the client by the introduced helper), then register it within v4l2.
> This solution ensure one binary kernel can run on both platforms.
> (To extend v4l2 with this solution could not be feasible, the device table is
> ISP driver specific, not v4l2 specific)

I also wonder about the need to unregister. I have to admit I don't know
much about I2C handling in v4l2. But if it requires unregistering from
i2c core and registering to v4l2 core, then it sounds to me like we
could check if there is a more fundamential cleanup needed? Deferring
for now, looks like an issue worth looking at, yet there are other
things in the queue first.
Bin Gao - June 22, 2013, 12:27 a.m.
On 6/19/2013 3:13 AM, Wolfram Sang wrote:
>
>> Even you prefer to extend v4l2, you still need this helper.
>> The idea is just to move the unregister/register from a specific ISP driver
>> to v4l2.
>>
>> I think you misunderstood my pionts somehow. Let me clarfiy a little bit:
>>
>> Current solution:
>> 1. Platform codes(on top of DT/ACPI5/SFI) don't call i2c_register_board_info(),
>> instead, prepare a table(kind of platform data) that has all camera i2c device information.
>> 2. ISP driver registers devices listed in the table to i2c core - this makes sure
>> v4l2 takes over these devices.
>> The problem with this solution is that when a camera device runs on both ACPI5 and
>> SFI, the platform codes will get a bit complicated and it's difficult to ensure one
>> binary kernel runs on both platforms(ACPI5 and SFI).
>> (To extend v4l2 with this solution doen't resolve my problem)
>>
>> Solution I'm suggesting:
>> 1. Let the platform codes call i2c_register_board_info() anyway.
>> 2. Since ISP driver knows which camera devices it supports, so it simply unregisters
>> those devices (get the client by the introduced helper), then register it within v4l2.
>> This solution ensure one binary kernel can run on both platforms.
>> (To extend v4l2 with this solution could not be feasible, the device table is
>> ISP driver specific, not v4l2 specific)
>
> I also wonder about the need to unregister. I have to admit I don't know
> much about I2C handling in v4l2. But if it requires unregistering from
> i2c core and registering to v4l2 core, then it sounds to me like we
> could check if there is a more fundamential cleanup needed? Deferring
> for now, looks like an issue worth looking at, yet there are other
> things in the queue first.
>

Platform codes are supposed to call i2c_register_board_info() or 
i2c_new_device() to register devices, we don't want to change this.
Not sure v4l2 can still take over the devices without 
unregistering/registering. Need look deeply into the v4l2 code...

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang - June 23, 2013, 12:43 p.m.
> >I also wonder about the need to unregister. I have to admit I don't know
> >much about I2C handling in v4l2. But if it requires unregistering from
> >i2c core and registering to v4l2 core, then it sounds to me like we
> >could check if there is a more fundamential cleanup needed? Deferring
> >for now, looks like an issue worth looking at, yet there are other
> >things in the queue first.
> >
> 
> Platform codes are supposed to call i2c_register_board_info() or
> i2c_new_device() to register devices, we don't want to change this.

Exactly.

> Not sure v4l2 can still take over the devices without
> unregistering/registering. Need look deeply into the v4l2 code...

That would help, I currently don't have time for that.

Thanks,

   Wolfram
Mark Brown - July 5, 2013, 7:55 p.m.
On Thu, Jun 06, 2013 at 11:33:46AM -0700, Bin Gao wrote:

> A good example is that an ISP(Imaging Signal Processor) driver needs
> register i2c camera sensor devices via v4l2, so it has to unregister
> all i2c clients that were previously registered by calling
> i2c_register_board_info(), and then re-register. For this case we
> can use this helper to get i2c_client by passing the client name.

Please look at the work that IIRC Laurent Pichart (CCed) was doing on
developing generic DT bindings for v4l in embedded systems, it sounds
like you're working on similar hardware here.  The general ideas should
apply to any enumeration mechanism, not just DT.
Andy Shevchenko - July 12, 2013, 10:54 a.m.
On Fri, Jul 5, 2013 at 10:55 PM, Mark Brown <broonie@kernel.org> wrote:
> On Thu, Jun 06, 2013 at 11:33:46AM -0700, Bin Gao wrote:
>
>> A good example is that an ISP(Imaging Signal Processor) driver needs
>> register i2c camera sensor devices via v4l2, so it has to unregister
>> all i2c clients that were previously registered by calling
>> i2c_register_board_info(), and then re-register. For this case we
>> can use this helper to get i2c_client by passing the client name.
>
> Please look at the work that IIRC Laurent Pichart (CCed) was doing on
> developing generic DT bindings for v4l in embedded systems,

I couldn't find anything related to OF except v4l2-of.c in the v4l2-core.
Is that what you mentioned?

> it sounds
> like you're working on similar hardware here.  The general ideas should
> apply to any enumeration mechanism, not just DT.

Briefly looking into ACPI tables we have and mechanisms that we can
use in ACPI case, I doubt we may apply all the ideas, probably some of
them, though I didn't get yet where to read about in details. What I
could say now is that the patch provided by Bin Gao is definitely no
go.

--
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang - July 12, 2013, 11 a.m.
> Briefly looking into ACPI tables we have and mechanisms that we can
> use in ACPI case, I doubt we may apply all the ideas, probably some of
> them, though I didn't get yet where to read about in details. What I
> could say now is that the patch provided by Bin Gao is definitely no
> go.

Laurent explained to me what V4L did and now does. It used to be the way
tha V4L drivers did register I2C slaves according to platform_data. Now,
with DT the slaves get instanciated earlier, so they now use notifiers
to know when the slaves are in place. Something like this should
probably be done here, too, instead of unregistering and re-registering.
Laurent Pinchart - July 12, 2013, 11:02 a.m.
On Friday 12 July 2013 12:00:47 Wolfram Sang wrote:
> > Briefly looking into ACPI tables we have and mechanisms that we can
> > use in ACPI case, I doubt we may apply all the ideas, probably some of
> > them, though I didn't get yet where to read about in details. What I
> > could say now is that the patch provided by Bin Gao is definitely no
> > go.
> 
> Laurent explained to me what V4L did and now does. It used to be the way
> tha V4L drivers did register I2C slaves according to platform_data. Now,
> with DT the slaves get instanciated earlier, so they now use notifiers
> to know when the slaves are in place. Something like this should
> probably be done here, too, instead of unregistering and re-registering.

This will be available in v3.11 in drivers/media/v4l2-core/v4l2-async.c.
Andy Shevchenko - July 12, 2013, 11:29 a.m.
On Fri, Jul 12, 2013 at 2:00 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
>
>> Briefly looking into ACPI tables we have and mechanisms that we can
>> use in ACPI case, I doubt we may apply all the ideas, probably some of
>> them, though I didn't get yet where to read about in details. What I
>> could say now is that the patch provided by Bin Gao is definitely no
>> go.
>
> Laurent explained to me what V4L did and now does. It used to be the way
> tha V4L drivers did register I2C slaves according to platform_data. Now,
> with DT the slaves get instanciated earlier, so they now use notifiers
> to know when the slaves are in place. Something like this should
> probably be done here, too, instead of unregistering and re-registering.

Yes, seems right way to go.
I think ACPI case can use V4L2 async API somehow, though it has its
own event model.
I'll talk to Sakari Ailus to sync.

--
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Laurent Pinchart - July 12, 2013, 11:35 a.m.
Hi Andy,

On Friday 12 July 2013 14:29:16 Andy Shevchenko wrote:
> On Fri, Jul 12, 2013 at 2:00 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
> >> Briefly looking into ACPI tables we have and mechanisms that we can
> >> use in ACPI case, I doubt we may apply all the ideas, probably some of
> >> them, though I didn't get yet where to read about in details. What I
> >> could say now is that the patch provided by Bin Gao is definitely no
> >> go.
> > 
> > Laurent explained to me what V4L did and now does. It used to be the way
> > tha V4L drivers did register I2C slaves according to platform_data. Now,
> > with DT the slaves get instanciated earlier, so they now use notifiers
> > to know when the slaves are in place. Something like this should
> > probably be done here, too, instead of unregistering and re-registering.
> 
> Yes, seems right way to go.
> I think ACPI case can use V4L2 async API somehow, though it has its
> own event model.
> I'll talk to Sakari Ailus to sync.

Do you have any pointer to the relevant parts of the ACPI specification ?
Andy Shevchenko - July 12, 2013, 11:56 a.m.
On Fri, Jul 12, 2013 at 2:35 PM, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
> On Friday 12 July 2013 14:29:16 Andy Shevchenko wrote:
>> On Fri, Jul 12, 2013 at 2:00 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
>> >> Briefly looking into ACPI tables we have and mechanisms that we can
>> >> use in ACPI case, I doubt we may apply all the ideas, probably some of
>> >> them, though I didn't get yet where to read about in details. What I
>> >> could say now is that the patch provided by Bin Gao is definitely no
>> >> go.
>> >
>> > Laurent explained to me what V4L did and now does. It used to be the way
>> > tha V4L drivers did register I2C slaves according to platform_data. Now,
>> > with DT the slaves get instanciated earlier, so they now use notifiers
>> > to know when the slaves are in place. Something like this should
>> > probably be done here, too, instead of unregistering and re-registering.
>>
>> Yes, seems right way to go.
>> I think ACPI case can use V4L2 async API somehow, though it has its
>> own event model.
>> I'll talk to Sakari Ailus to sync.
>
> Do you have any pointer to the relevant parts of the ACPI specification ?

Section 5.6.6 of ACPI5 spec describes device object notifications.
It's useful to detect hotplug events.

Otherwise, the i2c slave devices are enumerated from the i2c host
controller (for example, you can look at i2c-designware-platdrv.c:176.
It's done in a very similar way like for DT case.

However, it's possible to have i2c slaves described as children of
camera device in the DSDT (analogue of the DT). In that case camera
driver (v4l2 framework?) shall enumerate them on its own.

--
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 48e31ed..17683de6 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -2326,6 +2326,23 @@  s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
 }
 EXPORT_SYMBOL(i2c_smbus_xfer);
 
+static int match_name(struct device *dev, void *data)
+{
+	const char *name = data;
+	struct i2c_client *client = to_i2c_client(dev);
+
+	return !strncmp(client->name, name, strlen(client->name));
+}
+
+struct i2c_client *i2c_find_client_by_name(char *name)
+{
+	struct device *dev;
+
+	dev = bus_find_device(&i2c_bus_type, NULL, name, match_name);
+	return dev ? to_i2c_client(dev) : NULL;
+}
+EXPORT_SYMBOL_GPL(i2c_find_client_by_name);
+
 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
 MODULE_DESCRIPTION("I2C-Bus main module");
 MODULE_LICENSE("GPL");
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index e988fa9..7d8bf02 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -509,6 +509,7 @@  extern void i2c_clients_command(struct i2c_adapter *adap,
 extern struct i2c_adapter *i2c_get_adapter(int nr);
 extern void i2c_put_adapter(struct i2c_adapter *adap);
 
+extern struct i2c_client *i2c_find_client_by_name(char *name);
 
 /* Return the functionality mask */
 static inline u32 i2c_get_functionality(struct i2c_adapter *adap)