1 /* 2 * Driver for Samsung Q10 and related laptops: controls the backlight 3 * 4 * Copyright (c) 2011 Frederick van der Wyck <fvanderwyck@gmail.com> 5 * 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. 9 * 10 */ 11 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 <linux/acpi.h> 19 20 #define SAMSUNGQ10_BL_MAX_INTENSITY 7 21 22 static acpi_handle ec_handle; 23 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"); 28 29 static int samsungq10_bl_set_intensity(struct backlight_device *bd) 30 { 31 32 acpi_status status; 33 int i; 34 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; 39 } 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; 44 } 45 46 return 0; 47 } 48 49 static const struct backlight_ops samsungq10_bl_ops = { 50 .update_status = samsungq10_bl_set_intensity, 51 }; 52 53 static int samsungq10_probe(struct platform_device *pdev) 54 { 55 56 struct backlight_properties props; 57 struct backlight_device *bd; 58 59 memset(&props, 0, sizeof(struct backlight_properties)); 60 props.type = BACKLIGHT_PLATFORM; 61 props.max_brightness = SAMSUNGQ10_BL_MAX_INTENSITY; 62 bd = backlight_device_register("samsung", &pdev->dev, NULL, 63 &samsungq10_bl_ops, &props); 64 if (IS_ERR(bd)) 65 return PTR_ERR(bd); 66 67 platform_set_drvdata(pdev, bd); 68 69 return 0; 70 } 71 72 static int samsungq10_remove(struct platform_device *pdev) 73 { 74 75 struct backlight_device *bd = platform_get_drvdata(pdev); 76 77 backlight_device_unregister(bd); 78 79 return 0; 80 } 81 82 static struct platform_driver samsungq10_driver = { 83 .driver = { 84 .name = KBUILD_MODNAME, 85 .owner = THIS_MODULE, 86 }, 87 .probe = samsungq10_probe, 88 .remove = samsungq10_remove, 89 }; 90 91 static struct platform_device *samsungq10_device; 92 93 static int __init dmi_check_callback(const struct dmi_system_id *id) 94 { 95 printk(KERN_INFO KBUILD_MODNAME ": found model '%s'\n", id->ident); 96 return 1; 97 } 98 99 static struct dmi_system_id __initdata samsungq10_dmi_table[] = { 100 { 101 .ident = "Samsung Q10", 102 .matches = { 103 DMI_MATCH(DMI_SYS_VENDOR, "Samsung"), 104 DMI_MATCH(DMI_PRODUCT_NAME, "SQ10"), 105 }, 106 .callback = dmi_check_callback, 107 }, 108 { 109 .ident = "Samsung Q20", 110 .matches = { 111 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"), 112 DMI_MATCH(DMI_PRODUCT_NAME, "SENS Q20"), 113 }, 114 .callback = dmi_check_callback, 115 }, 116 { 117 .ident = "Samsung Q25", 118 .matches = { 119 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"), 120 DMI_MATCH(DMI_PRODUCT_NAME, "NQ25"), 121 }, 122 .callback = dmi_check_callback, 123 }, 124 { 125 .ident = "Dell Latitude X200", 126 .matches = { 127 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), 128 DMI_MATCH(DMI_PRODUCT_NAME, "X200"), 129 }, 130 .callback = dmi_check_callback, 131 }, 132 { }, 133 }; 134 MODULE_DEVICE_TABLE(dmi, samsungq10_dmi_table); 135 136 static int __init samsungq10_init(void) 137 { 138 if (!force && !dmi_check_system(samsungq10_dmi_table)) 139 return -ENODEV; 140 141 ec_handle = ec_get_handle(); 142 143 if (!ec_handle) 144 return -ENODEV; 145 146 samsungq10_device = platform_create_bundle(&samsungq10_driver, 147 samsungq10_probe, 148 NULL, 0, NULL, 0); 149 150 return PTR_ERR_OR_ZERO(samsungq10_device); 151 } 152 153 static void __exit samsungq10_exit(void) 154 { 155 platform_device_unregister(samsungq10_device); 156 platform_driver_unregister(&samsungq10_driver); 157 } 158 159 module_init(samsungq10_init); 160 module_exit(samsungq10_exit); 161 162 MODULE_AUTHOR("Frederick van der Wyck <fvanderwyck@gmail.com>"); 163 MODULE_DESCRIPTION("Samsung Q10 Driver"); 164 MODULE_LICENSE("GPL"); 165