Re: [RFC 2/5] gpio: add support for Technologic Systems TS-5500 GPIOs
From: Arnd Bergmann
Date: Wed May 04 2011 - 12:29:21 EST
On Saturday 30 April 2011, Vivien Didelot wrote:
> + ts5xxx_sbcinfo_set(&sbcinfo);
> + if (5500 != sbcinfo.board_id) {
> + printk(MODULE_NAME ": Incompatible TS Board.\n");
> + return -ENODEV;
> + }
The above should not be necessary:
> +static int __init ts5500_gpio_init(void)
> +{
> + int ret;
> +
> + ret = platform_driver_register(&ts5500_gpio_driver);
> + if (ret)
> + return ret;
> +
> + ret = platform_device_register(&gpio_device);
> + if (ret) {
> + printk(MODULE_NAME ": Failed to register platform device\n");
> + platform_driver_unregister(&ts5500_gpio_driver);
> + return ret;
> + }
> +
> + printk(MODULE_NAME ": GPIO/DIO driver loaded.\n");
> + return 0;
> +}
> +module_init(ts5500_gpio_init);
Doing it this way requires you know that you have to load the driver,
which is not good if you want to have the same kernel running on
different machines.
Better move the device registration into your platform code, in the
place where you know what device you have. The add a MODULE_DEVICE_TABLE()
entry to the module so the driver gets automatically loaded (if it's
a module), and match the platform device to the driver you register
from the module_init function.
Same for the other devices where you follow the same pattern.
Another way to do the same in a more modern fashion would be
to provide a flattened device tree that describes all your devices
and pass that into the kernel. Take a look at the CE4100 and OLPC
platforms to see how that is done.
Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/