All of lore.kernel.org
 help / color / mirror / Atom feed
* new style i2c client problem: probe () is not called
@ 2008-05-13 10:20 Darius
  2008-05-13 10:49 ` Wolfram Sang
  0 siblings, 1 reply; 9+ messages in thread
From: Darius @ 2008-05-13 10:20 UTC (permalink / raw)
  To: i2c-GZX6beZjE8VD60Wz+7aTrA

I'm writing i2c client driver. I have writen my own i2c adapter driver.
For testing, I have one small LCD driver, that is writen in "legacy" 
driver model. It works ok - does attach client, dettach adapter, detects 
my LCD on i2c bus, transmits data...
But when I use the same adapter driver with new style i2c client, it 
only  registers new client driver to i2c-core, but does not call probe() 
function.
What I'm doing wrong?
I set up i2c_board_info in board init function. Should I somewhere call 
i2c_new_device()?

Darius.


_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: new style i2c client problem: probe () is not called
  2008-05-13 10:20 new style i2c client problem: probe () is not called Darius
@ 2008-05-13 10:49 ` Wolfram Sang
       [not found]   ` <20080513104921.GA4485-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Wolfram Sang @ 2008-05-13 10:49 UTC (permalink / raw)
  To: Darius; +Cc: i2c-GZX6beZjE8VD60Wz+7aTrA


[-- Attachment #1.1: Type: text/plain, Size: 407 bytes --]

On Tue, May 13, 2008 at 01:20:24PM +0300, Darius wrote:
> I set up i2c_board_info in board init function. Should I somewhere
> call i2c_new_device()?
Have you called i2c_register_board_info? (If not, check
arch/arm/mach-iop32x/em7210.c for an example)

All the best,

   Wolfram

-- 
  Dipl.-Ing. Wolfram Sang | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 157 bytes --]

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: new style i2c client problem: probe () is not called
       [not found]   ` <20080513104921.GA4485-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
@ 2008-05-13 11:29     ` Darius
  2008-05-13 12:13       ` Jean Delvare
  0 siblings, 1 reply; 9+ messages in thread
From: Darius @ 2008-05-13 11:29 UTC (permalink / raw)
  To: i2c-GZX6beZjE8VD60Wz+7aTrA

Wolfram Sang wrote:
> On Tue, May 13, 2008 at 01:20:24PM +0300, Darius wrote:
>> I set up i2c_board_info in board init function. Should I somewhere
>> call i2c_new_device()?
> Have you called i2c_register_board_info? (If not, check
> arch/arm/mach-iop32x/em7210.c for an example)
> 
> All the best,
> 
>    Wolfram

yes, I have.
I attach simplified i2c code part from my driver above:

---------------------------------------------------------------------------------------------------------

struct ov7670 {
	struct i2c_client *client;
};

static int ov7670_probe(struct i2c_client *client, const struct 
i2c_device_id *did)
{
	struct ov7670 *ov7670;
	struct i2c_adapter *adapter =to_i2c_adapter(client->dev.parent);
	int ret;

	printk ("OV7670: error1\n");

	if (!i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA)){
		return -EIO;
	}
	
	ov7670 = kzalloc(sizeof(struct ov7670), GFP_KERNEL);
	if (!ov7670)
		return -ENOMEM;
	ov7670->client = client;
	i2c_set_clientdata(client, ov7670);
	return 0;
}

static int ov7670_remove(struct i2c_client *client)
{
	struct ov7670 *ov7670 = i2c_get_clientdata(client);
	struct i2c_adapter *adapter =to_i2c_adapter(client->dev.parent);
	kfree(ov7670);
	return 0;
}

static const struct i2c_device_id ov7670_id[] = {
	{ "ov7670", 0 },
	{ }
};
MODULE_DEVICE_TABLE(i2c, ov7670_id);

static struct i2c_driver ov7670_i2c_driver = {
	.driver = 	
			{
				.name = "ov7670",
			},
	.probe		= ov7670_probe,
	.remove		= ov7670_remove,
	.id_table	= ov7670_id,
};

static int __init ov7670_init(void)
{
	printk ("OV7670: driver init\n");
	return i2c_add_driver(&ov7670_i2c_driver);
}

static void __exit ov7670_exit(void)
{
	printk ("OV7670: driver exit\n");	
	i2c_del_driver(&ov7670_i2c_driver);
}

module_init(ov7670_init);
module_exit(ov7670_exit);


-------------------------------------------------------------------------------------------

And piece from board init:

------------------------------------------------------------------------------------------

static struct i2c_board_info __initdata mx1ads_i2c_devices[] = {
	{
		I2C_BOARD_INFO("ov7670", 0x42),
	}
};

<...>
i2c_register_board_info(0,mx1ads_i2c_devices,ARRAY_SIZE(mx1ads_i2c_devices));
<...>


_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: new style i2c client problem: probe () is not called
  2008-05-13 11:29     ` Darius
@ 2008-05-13 12:13       ` Jean Delvare
       [not found]         ` <20080513141337.20068339-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Jean Delvare @ 2008-05-13 12:13 UTC (permalink / raw)
  To: Darius; +Cc: i2c-GZX6beZjE8VD60Wz+7aTrA

Hi Darius,

On Tue, 13 May 2008 14:29:03 +0300, Darius wrote:
> I attach simplified i2c code part from my driver above:
> 
> ---------------------------------------------------------------------------------------------------------
> 
> struct ov7670 {
> 	struct i2c_client *client;
> };
> 
> static int ov7670_probe(struct i2c_client *client, const struct 
> i2c_device_id *did)
> {
> 	struct ov7670 *ov7670;
> 	struct i2c_adapter *adapter =to_i2c_adapter(client->dev.parent);
> 	int ret;
> 
> 	printk ("OV7670: error1\n");
> 
> 	if (!i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA)){
> 		return -EIO;
> 	}
> 	
> 	ov7670 = kzalloc(sizeof(struct ov7670), GFP_KERNEL);
> 	if (!ov7670)
> 		return -ENOMEM;
> 	ov7670->client = client;
> 	i2c_set_clientdata(client, ov7670);
> 	return 0;
> }
> 
> static int ov7670_remove(struct i2c_client *client)
> {
> 	struct ov7670 *ov7670 = i2c_get_clientdata(client);
> 	struct i2c_adapter *adapter =to_i2c_adapter(client->dev.parent);
> 	kfree(ov7670);
> 	return 0;
> }
> 
> static const struct i2c_device_id ov7670_id[] = {
> 	{ "ov7670", 0 },
> 	{ }
> };
> MODULE_DEVICE_TABLE(i2c, ov7670_id);
> 
> static struct i2c_driver ov7670_i2c_driver = {
> 	.driver = 	
> 			{
> 				.name = "ov7670",
> 			},
> 	.probe		= ov7670_probe,
> 	.remove		= ov7670_remove,
> 	.id_table	= ov7670_id,
> };
> 
> static int __init ov7670_init(void)
> {
> 	printk ("OV7670: driver init\n");
> 	return i2c_add_driver(&ov7670_i2c_driver);
> }
> 
> static void __exit ov7670_exit(void)
> {
> 	printk ("OV7670: driver exit\n");	
> 	i2c_del_driver(&ov7670_i2c_driver);
> }
> 
> module_init(ov7670_init);
> module_exit(ov7670_exit);
> 
> 
> -------------------------------------------------------------------------------------------
> 
> And piece from board init:
> 
> ------------------------------------------------------------------------------------------
> 
> static struct i2c_board_info __initdata mx1ads_i2c_devices[] = {
> 	{
> 		I2C_BOARD_INFO("ov7670", 0x42),
> 	}
> };
> 
> <...>
> i2c_register_board_info(0,mx1ads_i2c_devices,ARRAY_SIZE(mx1ads_i2c_devices));
> <...>

This code looks OK to me. But which driver handles i2c bus 0? Does your
platform code create i2c bus 0? i2c-code will instantiate the ov7670
i2c device when i2c bus 0 is created by i2c_add_numbered_adapter(). So
if you don't see it created, I suspect that i2c bus 0 itself is never
registered.

-- 
Jean Delvare

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: new style i2c client problem: probe () is not called
       [not found]         ` <20080513141337.20068339-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
@ 2008-05-13 12:45           ` Darius
  2008-05-13 12:56             ` Jean Delvare
  2008-05-14 21:20             ` Ben Dooks
  0 siblings, 2 replies; 9+ messages in thread
From: Darius @ 2008-05-13 12:45 UTC (permalink / raw)
  To: i2c-GZX6beZjE8VD60Wz+7aTrA

  > This code looks OK to me. But which driver handles i2c bus 0? Does your
> platform code create i2c bus 0? i2c-code will instantiate the ov7670
> i2c device when i2c bus 0 is created by i2c_add_numbered_adapter(). So
> if you don't see it created, I suspect that i2c bus 0 itself is never
> registered.
> 

Thanks, there was the problem. I have modified i2c adapter driver to use 
  i2c_add_numbered_adapter() instead i2c_add_adapter() and pass to the 
adapter->nr = pdev->id. now probe is called.

Jean, what do you think about adding my i2c driver to mainline kernel?
I've added this to Russel patch tracking system. Now it is a bit 
ugraded. Should I make new patch and send it here?


_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: new style i2c client problem: probe () is not called
       [not found]               ` <20080513145641.14522f5c-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
@ 2008-05-13 12:53                 ` Darius
  0 siblings, 0 replies; 9+ messages in thread
From: Darius @ 2008-05-13 12:53 UTC (permalink / raw)
  To: i2c-GZX6beZjE8VD60Wz+7aTrA

Jean Delvare wrote:
> On Tue, 13 May 2008 15:45:29 +0300, Darius wrote:
>>   > This code looks OK to me. But which driver handles i2c bus 0? Does your
>>> platform code create i2c bus 0? i2c-code will instantiate the ov7670
>>> i2c device when i2c bus 0 is created by i2c_add_numbered_adapter(). So
>>> if you don't see it created, I suspect that i2c bus 0 itself is never
>>> registered.
>>>
>> Thanks, there was the problem. I have modified i2c adapter driver to use 
>>   i2c_add_numbered_adapter() instead i2c_add_adapter() and pass to the 
>> adapter->nr = pdev->id. now probe is called.
>>
>> Jean, what do you think about adding my i2c driver to mainline kernel?
> 
> Sorry, which driver? 

I2C driver for IMX

> 
>> I've added this to Russel patch tracking system. Now it is a bit 
>> ugraded. Should I make new patch and send it here?
> 
> Sure, sending an updated patch can't hurt.
> 

ok, i'll prepare it.


_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: new style i2c client problem: probe () is not called
  2008-05-13 12:45           ` Darius
@ 2008-05-13 12:56             ` Jean Delvare
       [not found]               ` <20080513145641.14522f5c-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
  2008-05-14 21:20             ` Ben Dooks
  1 sibling, 1 reply; 9+ messages in thread
From: Jean Delvare @ 2008-05-13 12:56 UTC (permalink / raw)
  To: Darius; +Cc: i2c-GZX6beZjE8VD60Wz+7aTrA

On Tue, 13 May 2008 15:45:29 +0300, Darius wrote:
>   > This code looks OK to me. But which driver handles i2c bus 0? Does your
> > platform code create i2c bus 0? i2c-code will instantiate the ov7670
> > i2c device when i2c bus 0 is created by i2c_add_numbered_adapter(). So
> > if you don't see it created, I suspect that i2c bus 0 itself is never
> > registered.
> > 
> 
> Thanks, there was the problem. I have modified i2c adapter driver to use 
>   i2c_add_numbered_adapter() instead i2c_add_adapter() and pass to the 
> adapter->nr = pdev->id. now probe is called.
> 
> Jean, what do you think about adding my i2c driver to mainline kernel?

Sorry, which driver? 

> I've added this to Russel patch tracking system. Now it is a bit 
> ugraded. Should I make new patch and send it here?

Sure, sending an updated patch can't hurt.

-- 
Jean Delvare

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: new style i2c client problem: probe () is not called
  2008-05-13 12:45           ` Darius
  2008-05-13 12:56             ` Jean Delvare
@ 2008-05-14 21:20             ` Ben Dooks
       [not found]               ` <20080514212006.GA16881-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>
  1 sibling, 1 reply; 9+ messages in thread
From: Ben Dooks @ 2008-05-14 21:20 UTC (permalink / raw)
  To: Darius; +Cc: i2c-GZX6beZjE8VD60Wz+7aTrA

On Tue, May 13, 2008 at 03:45:29PM +0300, Darius wrote:
>   > This code looks OK to me. But which driver handles i2c bus 0? Does your
> > platform code create i2c bus 0? i2c-code will instantiate the ov7670
> > i2c device when i2c bus 0 is created by i2c_add_numbered_adapter(). So
> > if you don't see it created, I suspect that i2c bus 0 itself is never
> > registered.
> > 
> 
> Thanks, there was the problem. I have modified i2c adapter driver to use 
>   i2c_add_numbered_adapter() instead i2c_add_adapter() and pass to the 
> adapter->nr = pdev->id. now probe is called.

I'm not so sure this 1:1 mapping of platform to i2c bus ID is such a
good idea, what if you have two i2c controllers and want to swap the
two of them around?
 
> Jean, what do you think about adding my i2c driver to mainline kernel?
> I've added this to Russel patch tracking system. Now it is a bit 
> ugraded. Should I make new patch and send it here?

As a rule, stuff that touches drivers/i2c should be submitted via the
i2c list with a cc: to the architecture specific list as a courtesy to
the maintainer of that arch. It is not really within Russell (or any
other arch maintainer) remit to be actually submitting upstream for
drivers/i2c.

If a patch really has to touch both drivers/i2c and some other part of
the kernel, then it either is up to the architecture maintainer(s) to
ack the package for inclusion via the i2c tree, or up to both the i2c
and architecture maintainers to get someone like akpm to merge.

-- 
Ben (ben-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org, http://www.fluff.org/)

  'a smiley only costs 4 bytes'

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: new style i2c client problem: probe () is not called
       [not found]               ` <20080514212006.GA16881-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>
@ 2008-05-15  9:41                 ` Jean Delvare
  0 siblings, 0 replies; 9+ messages in thread
From: Jean Delvare @ 2008-05-15  9:41 UTC (permalink / raw)
  To: Ben Dooks; +Cc: Darius, i2c-GZX6beZjE8VD60Wz+7aTrA

Hi Ben,

On Wed, 14 May 2008 22:20:06 +0100, Ben Dooks wrote:
> On Tue, May 13, 2008 at 03:45:29PM +0300, Darius wrote:
> > Thanks, there was the problem. I have modified i2c adapter driver to use 
> >   i2c_add_numbered_adapter() instead i2c_add_adapter() and pass to the 
> > adapter->nr = pdev->id. now probe is called.
> 
> I'm not so sure this 1:1 mapping of platform to i2c bus ID is such a
> good idea, what if you have two i2c controllers and want to swap the
> two of them around?

You are right that using the platform device ID as the bus number has
limitations. It seems that it has worked fine for everyone so far
though. I guess that most embedded platforms have only one type of I2C
controllers so there are no collisions. If a platform was to use
several types of I2C controllers, presumably requiring different
drivers, then the current strategy may lead to collisions. But then it
shouldn't be too difficult to work around it, by passing the correct
I2C bus number as platform data. I guess developers have been using the
platform device ID merely as a shortcut.

I'm not too sure what you mean with "swapping the i2c controllers"
though. Why would you want to do that? Maybe a concrete example would
help.

-- 
Jean Delvare

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-05-15  9:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-13 10:20 new style i2c client problem: probe () is not called Darius
2008-05-13 10:49 ` Wolfram Sang
     [not found]   ` <20080513104921.GA4485-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2008-05-13 11:29     ` Darius
2008-05-13 12:13       ` Jean Delvare
     [not found]         ` <20080513141337.20068339-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-13 12:45           ` Darius
2008-05-13 12:56             ` Jean Delvare
     [not found]               ` <20080513145641.14522f5c-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-13 12:53                 ` Darius
2008-05-14 21:20             ` Ben Dooks
     [not found]               ` <20080514212006.GA16881-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>
2008-05-15  9:41                 ` Jean Delvare

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.