Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / platform / x86 / samsung-q10.c
blob6eb08b5393114d6ab565ecf5ed2424654665874b
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Driver for Samsung Q10 and related laptops: controls the backlight
5 * Copyright (c) 2011 Frederick van der Wyck <fvanderwyck@gmail.com>
6 */
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/platform_device.h>
12 #include <linux/backlight.h>
13 #include <linux/dmi.h>
14 #include <linux/acpi.h>
16 #define SAMSUNGQ10_BL_MAX_INTENSITY 7
18 static acpi_handle ec_handle;
20 static bool force;
21 module_param(force, bool, 0);
22 MODULE_PARM_DESC(force,
23 "Disable the DMI check and force the driver to be loaded");
25 static int samsungq10_bl_set_intensity(struct backlight_device *bd)
28 acpi_status status;
29 int i;
31 for (i = 0; i < SAMSUNGQ10_BL_MAX_INTENSITY; i++) {
32 status = acpi_evaluate_object(ec_handle, "_Q63", NULL, NULL);
33 if (ACPI_FAILURE(status))
34 return -EIO;
36 for (i = 0; i < bd->props.brightness; i++) {
37 status = acpi_evaluate_object(ec_handle, "_Q64", NULL, NULL);
38 if (ACPI_FAILURE(status))
39 return -EIO;
42 return 0;
45 static const struct backlight_ops samsungq10_bl_ops = {
46 .update_status = samsungq10_bl_set_intensity,
49 static int samsungq10_probe(struct platform_device *pdev)
52 struct backlight_properties props;
53 struct backlight_device *bd;
55 memset(&props, 0, sizeof(struct backlight_properties));
56 props.type = BACKLIGHT_PLATFORM;
57 props.max_brightness = SAMSUNGQ10_BL_MAX_INTENSITY;
58 bd = backlight_device_register("samsung", &pdev->dev, NULL,
59 &samsungq10_bl_ops, &props);
60 if (IS_ERR(bd))
61 return PTR_ERR(bd);
63 platform_set_drvdata(pdev, bd);
65 return 0;
68 static int samsungq10_remove(struct platform_device *pdev)
71 struct backlight_device *bd = platform_get_drvdata(pdev);
73 backlight_device_unregister(bd);
75 return 0;
78 static struct platform_driver samsungq10_driver = {
79 .driver = {
80 .name = KBUILD_MODNAME,
82 .probe = samsungq10_probe,
83 .remove = samsungq10_remove,
86 static struct platform_device *samsungq10_device;
88 static int __init dmi_check_callback(const struct dmi_system_id *id)
90 printk(KERN_INFO KBUILD_MODNAME ": found model '%s'\n", id->ident);
91 return 1;
94 static const struct dmi_system_id samsungq10_dmi_table[] __initconst = {
96 .ident = "Samsung Q10",
97 .matches = {
98 DMI_MATCH(DMI_SYS_VENDOR, "Samsung"),
99 DMI_MATCH(DMI_PRODUCT_NAME, "SQ10"),
101 .callback = dmi_check_callback,
104 .ident = "Samsung Q20",
105 .matches = {
106 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
107 DMI_MATCH(DMI_PRODUCT_NAME, "SENS Q20"),
109 .callback = dmi_check_callback,
112 .ident = "Samsung Q25",
113 .matches = {
114 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
115 DMI_MATCH(DMI_PRODUCT_NAME, "NQ25"),
117 .callback = dmi_check_callback,
120 .ident = "Dell Latitude X200",
121 .matches = {
122 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
123 DMI_MATCH(DMI_PRODUCT_NAME, "X200"),
125 .callback = dmi_check_callback,
127 { },
129 MODULE_DEVICE_TABLE(dmi, samsungq10_dmi_table);
131 static int __init samsungq10_init(void)
133 if (!force && !dmi_check_system(samsungq10_dmi_table))
134 return -ENODEV;
136 ec_handle = ec_get_handle();
138 if (!ec_handle)
139 return -ENODEV;
141 samsungq10_device = platform_create_bundle(&samsungq10_driver,
142 samsungq10_probe,
143 NULL, 0, NULL, 0);
145 return PTR_ERR_OR_ZERO(samsungq10_device);
148 static void __exit samsungq10_exit(void)
150 platform_device_unregister(samsungq10_device);
151 platform_driver_unregister(&samsungq10_driver);
154 module_init(samsungq10_init);
155 module_exit(samsungq10_exit);
157 MODULE_AUTHOR("Frederick van der Wyck <fvanderwyck@gmail.com>");
158 MODULE_DESCRIPTION("Samsung Q10 Driver");
159 MODULE_LICENSE("GPL");