Linux Audio

Check our new training course

Linux debugging, profiling, tracing and performance analysis training

Apr 14-17, 2025
Register
Loading...
v6.2
  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 int 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	return 0;
 76}
 77
 78static struct platform_driver samsungq10_driver = {
 79	.driver		= {
 80		.name	= KBUILD_MODNAME,
 81	},
 82	.probe		= samsungq10_probe,
 83	.remove		= samsungq10_remove,
 84};
 85
 86static struct platform_device *samsungq10_device;
 87
 88static int __init dmi_check_callback(const struct dmi_system_id *id)
 89{
 90	printk(KERN_INFO KBUILD_MODNAME ": found model '%s'\n", id->ident);
 91	return 1;
 92}
 93
 94static const struct dmi_system_id samsungq10_dmi_table[] __initconst = {
 95	{
 96		.ident = "Samsung Q10",
 97		.matches = {
 98			DMI_MATCH(DMI_SYS_VENDOR, "Samsung"),
 99			DMI_MATCH(DMI_PRODUCT_NAME, "SQ10"),
100		},
101		.callback = dmi_check_callback,
102	},
103	{
104		.ident = "Samsung Q20",
105		.matches = {
106			DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
107			DMI_MATCH(DMI_PRODUCT_NAME, "SENS Q20"),
108		},
109		.callback = dmi_check_callback,
110	},
111	{
112		.ident = "Samsung Q25",
113		.matches = {
114			DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
115			DMI_MATCH(DMI_PRODUCT_NAME, "NQ25"),
116		},
117		.callback = dmi_check_callback,
118	},
119	{
120		.ident = "Dell Latitude X200",
121		.matches = {
122			DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
123			DMI_MATCH(DMI_PRODUCT_NAME, "X200"),
124		},
125		.callback = dmi_check_callback,
126	},
127	{ },
128};
129MODULE_DEVICE_TABLE(dmi, samsungq10_dmi_table);
130
131static int __init samsungq10_init(void)
132{
133	if (!force && !dmi_check_system(samsungq10_dmi_table))
134		return -ENODEV;
135
136	ec_handle = ec_get_handle();
137
138	if (!ec_handle)
139		return -ENODEV;
140
141	samsungq10_device = platform_create_bundle(&samsungq10_driver,
142						   samsungq10_probe,
143						   NULL, 0, NULL, 0);
144
145	return PTR_ERR_OR_ZERO(samsungq10_device);
146}
147
148static void __exit samsungq10_exit(void)
149{
150	platform_device_unregister(samsungq10_device);
151	platform_driver_unregister(&samsungq10_driver);
152}
153
154module_init(samsungq10_init);
155module_exit(samsungq10_exit);
156
157MODULE_AUTHOR("Frederick van der Wyck <fvanderwyck@gmail.com>");
158MODULE_DESCRIPTION("Samsung Q10 Driver");
159MODULE_LICENSE("GPL");
v4.6
 
  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 const struct backlight_ops samsungq10_bl_ops = {
 50	.update_status	= samsungq10_bl_set_intensity,
 51};
 52
 53static 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
 72static 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
 82static struct platform_driver samsungq10_driver = {
 83	.driver		= {
 84		.name	= KBUILD_MODNAME,
 85	},
 86	.probe		= samsungq10_probe,
 87	.remove		= samsungq10_remove,
 88};
 89
 90static struct platform_device *samsungq10_device;
 91
 92static int __init dmi_check_callback(const struct dmi_system_id *id)
 93{
 94	printk(KERN_INFO KBUILD_MODNAME ": found model '%s'\n", id->ident);
 95	return 1;
 96}
 97
 98static struct dmi_system_id __initdata samsungq10_dmi_table[] = {
 99	{
100		.ident = "Samsung Q10",
101		.matches = {
102			DMI_MATCH(DMI_SYS_VENDOR, "Samsung"),
103			DMI_MATCH(DMI_PRODUCT_NAME, "SQ10"),
104		},
105		.callback = dmi_check_callback,
106	},
107	{
108		.ident = "Samsung Q20",
109		.matches = {
110			DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
111			DMI_MATCH(DMI_PRODUCT_NAME, "SENS Q20"),
112		},
113		.callback = dmi_check_callback,
114	},
115	{
116		.ident = "Samsung Q25",
117		.matches = {
118			DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG Electronics"),
119			DMI_MATCH(DMI_PRODUCT_NAME, "NQ25"),
120		},
121		.callback = dmi_check_callback,
122	},
123	{
124		.ident = "Dell Latitude X200",
125		.matches = {
126			DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
127			DMI_MATCH(DMI_PRODUCT_NAME, "X200"),
128		},
129		.callback = dmi_check_callback,
130	},
131	{ },
132};
133MODULE_DEVICE_TABLE(dmi, samsungq10_dmi_table);
134
135static int __init samsungq10_init(void)
136{
137	if (!force && !dmi_check_system(samsungq10_dmi_table))
138		return -ENODEV;
139
140	ec_handle = ec_get_handle();
141
142	if (!ec_handle)
143		return -ENODEV;
144
145	samsungq10_device = platform_create_bundle(&samsungq10_driver,
146						   samsungq10_probe,
147						   NULL, 0, NULL, 0);
148
149	return PTR_ERR_OR_ZERO(samsungq10_device);
150}
151
152static void __exit samsungq10_exit(void)
153{
154	platform_device_unregister(samsungq10_device);
155	platform_driver_unregister(&samsungq10_driver);
156}
157
158module_init(samsungq10_init);
159module_exit(samsungq10_exit);
160
161MODULE_AUTHOR("Frederick van der Wyck <fvanderwyck@gmail.com>");
162MODULE_DESCRIPTION("Samsung Q10 Driver");
163MODULE_LICENSE("GPL");