Re: [alsa-devel] [RFC] ucb1400 touchscreen, irq auto probing and ac97 with its private field
From: Jaroslav Kysela <perex@perex.cz>
Date: 2008-04-25 07:10:33
Also in:
alsa-devel
On Fri, 25 Apr 2008, Takashi Iwai wrote:
Hm, indeed it's more than a single value...
For multiple anonymous data, we can use a data with a key like below:
struct device_hint {
char *key;
void *data;
struct list_head list;
};
and the controller driver assigns the data like
controller_init()
{
...
controller.hint.key = "ucb1000-irq";
controller.hint.data = whatever;
list_add(&controller.hint. &ac97->device_hint_list);
...
}
and the device driver retrieves the data like
device_init()
{
struct device_hint *hint;
hint = device_hint_get(&ac97->device_hint_list, "ucb1000-irq");
if (hint) {
whatever = hint->data;
...
}
}
where device_hint_get() is defined like
struct device_hint *device_hint_get(struct device_hint *head,
const char *key)
{
struct device_hint *hint;
list_for_each_entry(hint, head, list)
if (!strcmp(hint, key))
return hint;
return NULL;
}
Of course, we can cast via container_of() to a container type instead
of using a void pointer there.
This is obviously an overweight for a single use-case, but if we have
more and more complex ones, maybe worth to consider.Sure. I applied the simple 'void *device_private_data' patch, because current usage request is really trivial. We can implement complex code to handle data for multiple "extra" devices on AC97 bus later. Jaroslav ----- Jaroslav Kysela [off-list ref] Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.