|
现在都是使用class来实现动态加载并创建设备节点啦,
- static struct class *spidev_class;
- /*-------------------------------------------------------------------------*/
- static int spidev_probe(struct spi_device *spi)
- {
- ....
-
- dev = device_create(spidev_class, &spi->dev, spidev->devt,
- spidev, "spidev%d.%d",
- spi->master->bus_num, spi->chip_select);
- ...
- }
- static int spidev_remove(struct spi_device *spi)
- {
- ......
- device_destroy(spidev_class, spidev->devt);
- .....
- return 0;
- }
- static struct spi_driver spidev_spi = {
- .driver = {
- .name = "spidev",
- .owner = THIS_MODULE,
- },
- .probe = spidev_probe,
- .remove = __devexit_p(spidev_remove),
- };
- /*-------------------------------------------------------------------------*/
- static int __init spidev_init(void)
- {
- ....
- spidev_class = class_create(THIS_MODULE, "spidev");
- if (IS_ERR(spidev_class)) {
- unregister_chrdev(SPIDEV_MAJOR, spidev_spi.driver.name);
- return PTR_ERR(spidev_class);
- }
- ....
- }
- module_init(spidev_init);
- static void __exit spidev_exit(void)
- {
- ......
- class_destroy(spidev_class);
- ......
- }
- module_exit(spidev_exit);
- MODULE_AUTHOR("Andrea Paterniani, ");
- MODULE_DESCRIPTION("User mode SPI device interface");
- MODULE_LICENSE("GPL");
复制代码
大概就是这样,你自己在driver目录下找个例子看看就知道了 |
|