diff -pruN clean/drivers/hwmon/hdaps.c dirty/drivers/hwmon/hdaps.c --- clean/drivers/hwmon/hdaps.c 2006-01-15 11:27:15.579714416 +0100 +++ dirty/drivers/hwmon/hdaps.c 2006-01-15 11:53:57.853131832 +0100 @@ -36,7 +36,7 @@ #include #define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */ -#define HDAPS_HI_PORT 0x162f /* last port used by hdaps */ +#define HDAPS_NR_PORTS 0x30 /* number of ports: 0x1600 - 0x162f */ #define HDAPS_PORT_STATE 0x1611 /* device state */ #define HDAPS_PORT_YPOS 0x1612 /* y-axis position */ @@ -62,12 +62,6 @@ #define HDAPS_INPUT_FUZZ 4 /* input event threshold */ #define HDAPS_INPUT_FLAT 4 -static struct resource __initdata hdaps_iores = { - .flags = IORESOURCE_IO, - .start = HDAPS_LOW_PORT, - .end = HDAPS_HI_PORT, -}; - static struct timer_list hdaps_timer; static struct platform_device *pdev; static struct input_dev *hdaps_idev; @@ -290,6 +284,34 @@ out: } +/* Device model stuff */ + +static int hdaps_probe(struct platform_device *dev) +{ + int ret; + + ret = hdaps_device_init(); + if (ret) + return ret; + + printk(KERN_INFO "hdaps: device successfully initialized.\n"); + return 0; +} + +static int hdaps_resume(struct platform_device *dev) +{ + return hdaps_device_init(); +} + +static struct platform_driver hdaps_driver = { + .probe = hdaps_probe, + .resume = hdaps_resume, + .driver = { + .name = "hdaps", + .owner = THIS_MODULE, + }, +}; + /* * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_sem. */ @@ -298,13 +320,13 @@ static void hdaps_calibrate(void) __hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &rest_x, &rest_y); } -static void hdaps_inputdev_poll(unsigned long unused) +static void hdaps_mousedev_poll(unsigned long unused) { int x, y; /* Cannot sleep. Try nonblockingly. If we fail, try again later. */ if (down_trylock(&hdaps_sem)) { - mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD); + mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD); return; } @@ -317,7 +339,7 @@ static void hdaps_inputdev_poll(unsigned mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD); - out: +out: up(&hdaps_sem); } @@ -451,80 +473,6 @@ static struct attribute_group hdaps_attr .attrs = hdaps_attributes, }; -/* Device model stuff */ - -static int __devinit hdaps_probe(struct platform_device *dev) -{ - int error; - - /* initial calibrate for the input device */ - hdaps_calibrate(); - - hdaps_idev = input_allocate_device(); - if (!hdaps_idev) - return -ENOMEM; - - /* initialize the input class */ - hdaps_idev->name = "hdaps"; - hdaps_idev->phys = "hdaps/input0"; - hdaps_idev->cdev.dev = &dev->dev; - hdaps_idev->evbit[0] = BIT(EV_ABS); - input_set_abs_params(hdaps_idev, ABS_X, - -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT); - input_set_abs_params(hdaps_idev, ABS_Y, - -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT); - - error = sysfs_create_group(&pdev->dev.kobj, &hdaps_attribute_group); - if (error) - goto err_free_input_dev; - - error = hdaps_device_init(); - if (error) - goto err_sysfs_remove_group; - - error = input_register_device(hdaps_idev); - if (error) - goto err_sysfs_remove_group; - - /* start up our timer for the input device */ - init_timer(&hdaps_timer); - hdaps_timer.function = hdaps_inputdev_poll; - hdaps_timer.expires = jiffies + HDAPS_POLL_PERIOD; - add_timer(&hdaps_timer); - - return 0; - - err_free_input_dev: - input_free_device(hdaps_idev); - err_sysfs_remove_group: - sysfs_remove_group(&dev->dev.kobj, &hdaps_attribute_group); - return error; -} - -static int __devexit hdaps_remove(struct platform_device *dev) -{ - del_timer_sync(&hdaps_timer); - input_unregister_device(hdaps_idev); - sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group); - - return 0; -} - -static int hdaps_resume(struct platform_device *dev) -{ - return hdaps_device_init(); -} - -static struct platform_driver hdaps_driver = { - .driver = { - .name = "hdaps", - .owner = THIS_MODULE, - }, - .probe = hdaps_probe, - .remove = __devexit_p(hdaps_remove), - .resume = hdaps_resume, -}; - /* Module stuff */ @@ -563,7 +511,7 @@ static int hdaps_dmi_match_invert(struct static int __init hdaps_init(void) { - int error; + int ret; /* Note that DMI_MATCH(...,"ThinkPad T42") will match "ThinkPad T42p" */ struct dmi_system_id hdaps_whitelist[] = { @@ -584,43 +532,79 @@ static int __init hdaps_init(void) if (!dmi_check_system(hdaps_whitelist)) { printk(KERN_WARNING "hdaps: supported laptop not found!\n"); - return -ENODEV; + ret = -ENXIO; + goto out; } - error = platform_driver_register(&hdaps_driver); - if (error) - return error; - - pdev = platform_device_alloc("hdaps", -1); - if (!pdev) { - error = -ENOMEM; - goto err_unregister_driver; + if (!request_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS, "hdaps")) { + ret = -ENXIO; + goto out; } - error = platform_device_add_resources(pdev, &hdaps_iores, 1); - if (error) - goto err_free_device; - - error = platform_device_add(pdev); - if (error) - goto err_free_device; + ret = platform_driver_register(&hdaps_driver); + if (ret) + goto out_region; + + pdev = platform_device_register_simple("hdaps", -1, NULL, 0); + if (IS_ERR(pdev)) { + ret = PTR_ERR(pdev); + goto out_driver; + } + + ret = sysfs_create_group(&pdev->dev.kobj, &hdaps_attribute_group); + if (ret) + goto out_device; + + hdaps_idev = input_allocate_device(); + if (!hdaps_idev) { + ret = -ENOMEM; + goto out_group; + } + + /* initial calibrate for the input device */ + hdaps_calibrate(); + + /* initialize the input class */ + hdaps_idev->name = "hdaps"; + hdaps_idev->cdev.dev = &pdev->dev; + hdaps_idev->evbit[0] = BIT(EV_ABS); + input_set_abs_params(hdaps_idev, ABS_X, + -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT); + input_set_abs_params(hdaps_idev, ABS_Y, + -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT); + + input_register_device(hdaps_idev); + + /* start up our timer for the input device */ + init_timer(&hdaps_timer); + hdaps_timer.function = hdaps_mousedev_poll; + hdaps_timer.expires = jiffies + HDAPS_POLL_PERIOD; + add_timer(&hdaps_timer); printk(KERN_INFO "hdaps: driver successfully loaded.\n"); return 0; - err_free_device: - platform_device_put(pdev); - err_unregister_driver: +out_group: + sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group); +out_device: + platform_device_unregister(pdev); +out_driver: platform_driver_unregister(&hdaps_driver); - - printk(KERN_WARNING "hdaps: driver init failed (error=%d)!\n", error); - return error; +out_region: + release_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS); +out: + printk(KERN_WARNING "hdaps: driver init failed (ret=%d)!\n", ret); + return ret; } static void __exit hdaps_exit(void) { + del_timer_sync(&hdaps_timer); + input_unregister_device(hdaps_idev); + sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group); platform_device_unregister(pdev); platform_driver_unregister(&hdaps_driver); + release_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS); printk(KERN_INFO "hdaps: driver unloaded.\n"); }