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