1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 8 static dev_t linuxmag_number; 9 static struct cdev *driver_object; 0 static struct class *linmag_class; 1 static struct platform_device_id pdi; 2 3 static struct file_operations fops; 4 static DECLARE_COMPLETION( dev_obj_is_free ); 5 6 static int linuxmag_probe_device( struct platform_device *pdev ) 7 { 8 struct device *dev = &pdev->dev; 9 struct device_node *nodeptr = dev->of_node; 0 const void *prop_value; 1 int size, i; 2 u16 value; 3 const __be16 *beptr; 4 5 pr_info("linuxmag_probe_device( %p, %p )\n", pdev, nodeptr); 6 pr_info("pd->id: %d\n", pdev->id ); 7 pr_info("pd->name: %s\n", pdev->name ); 8 nodeptr = of_find_node_by_path("gpio"); 9 0 prop_value = of_get_property( nodeptr, "string-property", &size ); 1 printk("linuxmag_probe_device(): prop_value=%p, size: %d\n", 2 prop_value, size); 3 if (prop_value) 4 printk("prop_value: %s\n", (char *)prop_value); 5 6 prop_value = of_get_property( nodeptr, "bytes", &size ); 7 printk("linuxmag_probe_device(): prop_value=%p, size: %d\n", 8 prop_value, size); 9 printk("byte array: [ "); 0 for ( i=0; iowner = THIS_MODULE; 3 driver_object->ops = &fops; 4 if (cdev_add(driver_object,linuxmag_number,1)) 5 goto free_cdev; 6 linmag_class = class_create( THIS_MODULE, "linuxmag" ); 7 if (IS_ERR(linmag_class)) { 8 printk("linuxmag: no udev support.\n"); 9 goto free_cdev; 0 } 1 linuxmag.dev.devt = linuxmag_number; 2 platform_device_register( &linuxmag ); 3 return 0; 4 5 free_cdev: 6 kobject_put( &driver_object->kobj ); 7 free_device_number: 8 unregister_chrdev_region( linuxmag_number, 3 ); 9 return -EIO; 0 } 1 2 static void __exit mod_exit(void) 3 { 4 pr_info("mod_exit()\n"); 5 device_release_driver( &linuxmag.dev ); 6 platform_device_unregister( &linuxmag ); 7 class_destroy( linmag_class ); 8 cdev_del( driver_object ); 9 unregister_chrdev_region( linuxmag_number, 1 ); 0 platform_driver_unregister(&mydriver); 1 wait_for_completion( &dev_obj_is_free ); 2 } 3 4 module_init( mod_init ); 5 module_exit( mod_exit ); 6 MODULE_LICENSE("GPL");