Merge tag 'gpio-v3.13-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw...
[linux-2.6.git] / drivers / platform / x86 / samsung-q10.c
blobcae7098e9b0d70adf271eb9c31a1e833919a54b1
1 /*
2 * Driver for Samsung Q10 and related laptops: controls the backlight
4 * Copyright (c) 2011 Frederick van der Wyck <fvanderwyck@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/backlight.h>
17 #include <linux/dmi.h>
18 #include <acpi/acpi_drivers.h>
20 #define SAMSUNGQ10_BL_MAX_INTENSITY 7
22 static acpi_handle ec_handle;
24 static bool force;
25 module_param(force, bool, 0);
26 MODULE_PARM_DESC(force,
27 "Disable the DMI check and force the driver to be loaded");
29 static int samsungq10_bl_set_intensity(struct backlight_device *bd)
32 acpi_status status;
33 int i;
35 for (i = 0; i < SAMSUNGQ10_BL_MAX_INTENSITY; i++) {
36 status = acpi_evaluate_object(ec_handle, "_Q63", NULL, NULL);
37 if (ACPI_FAILURE(status))
38 return -EIO;
40 for (i = 0; i < bd->props.brightness; i++) {
41 status = acpi_evaluate_object(ec_handle, "_Q64", NULL, NULL);
42 if (ACPI_FAILURE(status))
43 return -EIO;
46 return 0;
49 static int samsungq10_bl_get_intensity(struct backlight_device *bd)
51 return bd->props.brightness;
54 static const struct backlight_ops samsungq10_bl_ops = {
55 .get_brightness = samsungq10_bl_get_intensity,
56 .update_status = samsungq10_bl_set_intensity,
59 static int samsungq10_probe(struct platform_device *pdev)
62 struct backlight_properties props;
63 struct backlight_device *bd;
65 memset(&props, 0, sizeof(struct backlight_properties));
66 props.type = BACKLIGHT_PLATFORM;
67 props.max_brightness = SAMSUNGQ10_BL_MAX_INTENSITY;
68 bd = backlight_device_register("samsung", &pdev->dev, NULL,
69 &samsungq10_bl_ops, &props);
70 if (IS_ERR(bd))
71 return PTR_ERR(bd);
73 platform_set_drvdata(pdev, bd);
75 return 0;
78 static int samsungq10_remove(struct platform_device *pdev)
81 struct backlight_device *bd = platform_get_drvdata(pdev);
83 backlight_device_unregister(bd);
85 return 0;
88 static struct platform_driver samsungq10_driver = {
89 .driver = {
90 .name = KBUILD_MODNAME,
91 .owner = THIS_MODULE,
93 .probe = samsungq10_probe,
94 .remove = samsungq10_remove,
97 static struct platform_device *samsungq10_device;
99 static int __init dmi_check_callback(const struct dmi_system_id *id)
101 printk(KERN_INFO KBUILD_MODNAME ": found model '%s'\n", id->ident);
102 return 1;
105 static struct dmi_system_id __initdata samsungq10_dmi_table[] = {
107 .ident = "Samsung Q10",
108 .matches = {
109 DMI_MATCH(DMI_SYS_VENDOR, "Samsung"),
110 DMI_MATCH(DMI_PRODUCT_NAME, "SQ10"),
112 .callback = dmi_check_callback,
115 .ident = "Samsung Q20",
116 .matches = {
117 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
118 DMI_MATCH(DMI_PRODUCT_NAME, "SENS Q20"),
120 .callback = dmi_check_callback,
123 .ident = "Samsung Q25",
124 .matches = {
125 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
126 DMI_MATCH(DMI_PRODUCT_NAME, "NQ25"),
128 .callback = dmi_check_callback,
131 .ident = "Dell Latitude X200",
132 .matches = {
133 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
134 DMI_MATCH(DMI_PRODUCT_NAME, "X200"),
136 .callback = dmi_check_callback,
138 { },
140 MODULE_DEVICE_TABLE(dmi, samsungq10_dmi_table);
142 static int __init samsungq10_init(void)
144 if (!force && !dmi_check_system(samsungq10_dmi_table))
145 return -ENODEV;
147 ec_handle = ec_get_handle();
149 if (!ec_handle)
150 return -ENODEV;
152 samsungq10_device = platform_create_bundle(&samsungq10_driver,
153 samsungq10_probe,
154 NULL, 0, NULL, 0);
156 return PTR_ERR_OR_ZERO(samsungq10_device);
159 static void __exit samsungq10_exit(void)
161 platform_device_unregister(samsungq10_device);
162 platform_driver_unregister(&samsungq10_driver);
165 module_init(samsungq10_init);
166 module_exit(samsungq10_exit);
168 MODULE_AUTHOR("Frederick van der Wyck <fvanderwyck@gmail.com>");
169 MODULE_DESCRIPTION("Samsung Q10 Driver");
170 MODULE_LICENSE("GPL");