public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* Dynamically-allocated i2c_device_id vs MODULE_DEVICE_TABLE
@ 2009-01-23 21:03 Timur Tabi
       [not found] ` <497A3097.1030808-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Timur Tabi @ 2009-01-23 21:03 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA

I currently have this in my code:

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

static struct i2c_driver cs4270_i2c_driver = {
	.driver = {
		.name = "cs4270",
		.owner = THIS_MODULE,
	},
	.id_table = cs4270_id,
	.probe = cs4270_i2c_probe,
	.remove = cs4270_i2c_remove,
};

ret = i2c_add_driver(&cs4270_i2c_driver);

I would like to use the i2c_device_id.driver_data variable to pass private data
to my cs4270_i2c_probe() function.  So it will look like this:

	socdev = kmalloc(...);
	c24270_id.driver_data = socdev;
	i2c_add_driver(&cs4270_i2c_driver);

And then in my cs4270_i2c_probe(), I would do this:

static int cs4270_i2c_probe(struct i2c_client *i2c_client,
	const struct i2c_device_id *id)
{
	struct X *socdev = (struct X *) id->driver_data.

The problem I'm having is the MODULE_DEVICE_TABLE.  What I really should be
doing is this:

	socdev = kmalloc(...);
	struct i2c_driver *cs4270_i2c_driver = kmalloc(...);
	struct i2c_device_id *cs4270_id = kmalloc(...);
	cs4270_i2c_driver->id_table = cs4270_id;
	c24270_id->driver_data = socdev;
	i2c_add_driver(cs4270_i2c_driver);

But if I do this, then I can't use MODULE_DEVICE_TABLE.  So I have two questions:

1) What happens if I don't use MODULE_DEVICE_TABLE to identify my I2C ID table?

2) Is there a way to mimic the behavior of MODULE_DEVICE_TABLE on a
dynamically-created ID table?

-- 
Timur Tabi
Linux kernel developer at Freescale

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

end of thread, other threads:[~2009-01-26 19:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-23 21:03 Dynamically-allocated i2c_device_id vs MODULE_DEVICE_TABLE Timur Tabi
     [not found] ` <497A3097.1030808-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2009-01-23 22:26   ` Jon Smirl
2009-01-24  1:28   ` Mark Brown
     [not found]     ` <20090124012817.GA31775-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2009-01-24  2:23       ` Timur Tabi
     [not found]         ` <497A7BA4.2080908-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2009-01-24 11:39           ` Mark Brown
2009-01-24 16:50   ` Ben Dooks
     [not found]     ` <20090124165040.GL8032-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>
2009-01-26 18:06       ` Timur Tabi
     [not found]         ` <ed82fe3e0901261006u2223ccb3n5d7b3be9a85df7c7-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-01-26 19:16           ` Jon Smirl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox