#include #include #include #include #define DRIVER_MAJOR 240 MODULE_LICENSE("GPL"); static struct file_operations fops; static DECLARE_COMPLETION( dev_obj_is_free ); static int frequenz; // Zustandsvariable des Gerätes static void mydevice_release( struct device *dev ) { complete( &dev_obj_is_free ); } struct platform_device mydevice = { .name = "MyDevice", .id = 0, .dev = { .release = mydevice_release, } }; static struct device_driver mydriver = { .name = "MyDevDrv", .bus = &platform_bus_type, }; static ssize_t read_freq( struct device *dev, char *buf ) { snprintf(buf, 256, "frequenz: %d", frequenz ); return strlen(buf)+1; } static ssize_t write_freq( struct device *dev, const char *buf, size_t count ) { frequenz = simple_strtoul( buf, NULL, 0 ); return strlen(buf)+1; } static DEVICE_ATTR( freq ,S_IRUGO|S_IWUGO, read_freq, write_freq ); static int __init drv_init(void) { if(register_chrdev(DRIVER_MAJOR, "MyDevice", &fops) == 0) { driver_register(&mydriver); // register the driver platform_device_register( &mydevice );// register the device mydevice.dev.driver = &mydriver; // now tie them together device_bind_driver( &mydevice.dev ); // links the driver to the device device_create_file( &mydevice.dev, &dev_attr_freq ); return 0; } return -EIO; } static void __exit drv_exit(void) { device_remove_file( &mydevice.dev, &dev_attr_freq ); device_release_driver( &mydevice.dev ); platform_device_unregister( &mydevice ); driver_unregister(&mydriver); unregister_chrdev(DRIVER_MAJOR,"MyDevice"); wait_for_completion( &dev_obj_is_free ); } module_init( drv_init ); module_exit( drv_exit );