Linux Audio

Check our new training course

Loading...
v3.5.6
 
 
  1
  2#include <linux/module.h>
  3
  4#include <linux/platform_device.h>
  5#include <linux/err.h>
  6#include <linux/leds.h>
  7
  8#include <linux/io.h>
  9#include <linux/dmi.h>
 10
 11#include <linux/i8042.h>
 12
 13#define CLEVO_MAIL_LED_OFF		0x0084
 14#define CLEVO_MAIL_LED_BLINK_1HZ	0x008A
 15#define CLEVO_MAIL_LED_BLINK_0_5HZ	0x0083
 16
 17MODULE_AUTHOR("Márton Németh <nm127@freemail.hu>");
 18MODULE_DESCRIPTION("Clevo mail LED driver");
 19MODULE_LICENSE("GPL");
 20
 21static bool __initdata nodetect;
 22module_param_named(nodetect, nodetect, bool, 0);
 23MODULE_PARM_DESC(nodetect, "Skip DMI hardware detection");
 24
 25static struct platform_device *pdev;
 26
 27static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
 28{
 29	printk(KERN_INFO KBUILD_MODNAME ": '%s' found\n", id->ident);
 30	return 1;
 31}
 32
 33/*
 34 * struct mail_led_whitelist - List of known good models
 35 *
 36 * Contains the known good models this driver is compatible with.
 37 * When adding a new model try to be as strict as possible. This
 38 * makes it possible to keep the false positives (the model is
 39 * detected as working, but in reality it is not) as low as
 40 * possible.
 41 */
 42static struct dmi_system_id __initdata mail_led_whitelist[] = {
 43	{
 44		.callback = clevo_mail_led_dmi_callback,
 45		.ident = "Clevo D410J",
 46		.matches = {
 47			DMI_MATCH(DMI_SYS_VENDOR, "VIA"),
 48			DMI_MATCH(DMI_PRODUCT_NAME, "K8N800"),
 49			DMI_MATCH(DMI_PRODUCT_VERSION, "VT8204B")
 50		}
 51	},
 52	{
 53		.callback = clevo_mail_led_dmi_callback,
 54		.ident = "Clevo M5x0N",
 55		.matches = {
 56			DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."),
 57			DMI_MATCH(DMI_PRODUCT_NAME, "M5x0N")
 58		}
 59	},
 60	{
 61		.callback = clevo_mail_led_dmi_callback,
 62		.ident = "Positivo Mobile",
 63		.matches = {
 64			DMI_MATCH(DMI_BOARD_VENDOR, "CLEVO Co. "),
 65			DMI_MATCH(DMI_BOARD_NAME, "M5X0V "),
 66			DMI_MATCH(DMI_PRODUCT_NAME, "Positivo Mobile"),
 67			DMI_MATCH(DMI_PRODUCT_VERSION, "VT6198")
 68		}
 69	},
 70	{
 71		.callback = clevo_mail_led_dmi_callback,
 72		.ident = "Clevo D400P",
 73		.matches = {
 74			DMI_MATCH(DMI_BOARD_VENDOR, "Clevo"),
 75			DMI_MATCH(DMI_BOARD_NAME, "D400P"),
 76			DMI_MATCH(DMI_BOARD_VERSION, "Rev.A"),
 77			DMI_MATCH(DMI_PRODUCT_VERSION, "0106")
 78		}
 79	},
 80	{
 81		.callback = clevo_mail_led_dmi_callback,
 82		.ident = "Clevo D410V",
 83		.matches = {
 84			DMI_MATCH(DMI_BOARD_VENDOR, "Clevo, Co."),
 85			DMI_MATCH(DMI_BOARD_NAME, "D400V/D470V"),
 86			DMI_MATCH(DMI_BOARD_VERSION, "SS78B"),
 87			DMI_MATCH(DMI_PRODUCT_VERSION, "Rev. A1")
 88		}
 89	},
 90	{ }
 91};
 
 92
 93static void clevo_mail_led_set(struct led_classdev *led_cdev,
 94				enum led_brightness value)
 95{
 96	i8042_lock_chip();
 97
 98	if (value == LED_OFF)
 99		i8042_command(NULL, CLEVO_MAIL_LED_OFF);
100	else if (value <= LED_HALF)
101		i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ);
102	else
103		i8042_command(NULL, CLEVO_MAIL_LED_BLINK_1HZ);
104
105	i8042_unlock_chip();
106
107}
108
109static int clevo_mail_led_blink(struct led_classdev *led_cdev,
110				unsigned long *delay_on,
111				unsigned long *delay_off)
112{
113	int status = -EINVAL;
114
115	i8042_lock_chip();
116
117	if (*delay_on == 0 /* ms */ && *delay_off == 0 /* ms */) {
118		/* Special case: the leds subsystem requested us to
119		 * chose one user friendly blinking of the LED, and
120		 * start it. Let's blink the led slowly (0.5Hz).
121		 */
122		*delay_on = 1000; /* ms */
123		*delay_off = 1000; /* ms */
124		i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ);
125		status = 0;
126
127	} else if (*delay_on == 500 /* ms */ && *delay_off == 500 /* ms */) {
128		/* blink the led with 1Hz */
129		i8042_command(NULL, CLEVO_MAIL_LED_BLINK_1HZ);
130		status = 0;
131
132	} else if (*delay_on == 1000 /* ms */ && *delay_off == 1000 /* ms */) {
133		/* blink the led with 0.5Hz */
134		i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ);
135		status = 0;
136
137	} else {
138		printk(KERN_DEBUG KBUILD_MODNAME
139		       ": clevo_mail_led_blink(..., %lu, %lu),"
140		       " returning -EINVAL (unsupported)\n",
141		       *delay_on, *delay_off);
142	}
143
144	i8042_unlock_chip();
145
146	return status;
147}
148
149static struct led_classdev clevo_mail_led = {
150	.name			= "clevo::mail",
151	.brightness_set		= clevo_mail_led_set,
152	.blink_set		= clevo_mail_led_blink,
153	.flags			= LED_CORE_SUSPENDRESUME,
154};
155
156static int __devinit clevo_mail_led_probe(struct platform_device *pdev)
157{
158	return led_classdev_register(&pdev->dev, &clevo_mail_led);
159}
160
161static int clevo_mail_led_remove(struct platform_device *pdev)
162{
163	led_classdev_unregister(&clevo_mail_led);
164	return 0;
165}
166
167static struct platform_driver clevo_mail_led_driver = {
168	.probe		= clevo_mail_led_probe,
169	.remove		= clevo_mail_led_remove,
170	.driver		= {
171		.name		= KBUILD_MODNAME,
172		.owner		= THIS_MODULE,
173	},
174};
175
176static int __init clevo_mail_led_init(void)
177{
178	int error = 0;
179	int count = 0;
180
181	/* Check with the help of DMI if we are running on supported hardware */
182	if (!nodetect) {
183		count = dmi_check_system(mail_led_whitelist);
184	} else {
185		count = 1;
186		printk(KERN_ERR KBUILD_MODNAME ": Skipping DMI detection. "
187		       "If the driver works on your hardware please "
188		       "report model and the output of dmidecode in tracker "
189		       "at http://sourceforge.net/projects/clevo-mailled/\n");
190	}
191
192	if (!count)
193		return -ENODEV;
194
195	pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0);
196	if (!IS_ERR(pdev)) {
197		error = platform_driver_probe(&clevo_mail_led_driver,
198					      clevo_mail_led_probe);
199		if (error) {
200			printk(KERN_ERR KBUILD_MODNAME
201			       ": Can't probe platform driver\n");
202			platform_device_unregister(pdev);
203		}
204	} else
205		error = PTR_ERR(pdev);
206
207	return error;
208}
209
210static void __exit clevo_mail_led_exit(void)
211{
212	platform_device_unregister(pdev);
213	platform_driver_unregister(&clevo_mail_led_driver);
214
215	clevo_mail_led_set(NULL, LED_OFF);
216}
217
218module_init(clevo_mail_led_init);
219module_exit(clevo_mail_led_exit);
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0-only
  2#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  3
  4#include <linux/module.h>
  5
  6#include <linux/platform_device.h>
  7#include <linux/err.h>
  8#include <linux/leds.h>
  9
 10#include <linux/io.h>
 11#include <linux/dmi.h>
 12
 13#include <linux/i8042.h>
 14
 15#define CLEVO_MAIL_LED_OFF		0x0084
 16#define CLEVO_MAIL_LED_BLINK_1HZ	0x008A
 17#define CLEVO_MAIL_LED_BLINK_0_5HZ	0x0083
 18
 19MODULE_AUTHOR("Márton Németh <nm127@freemail.hu>");
 20MODULE_DESCRIPTION("Clevo mail LED driver");
 21MODULE_LICENSE("GPL");
 22
 23static bool nodetect;
 24module_param_named(nodetect, nodetect, bool, 0);
 25MODULE_PARM_DESC(nodetect, "Skip DMI hardware detection");
 26
 27static struct platform_device *pdev;
 28
 29static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
 30{
 31	pr_info("'%s' found\n", id->ident);
 32	return 1;
 33}
 34
 35/*
 36 * struct clevo_mail_led_dmi_table - List of known good models
 37 *
 38 * Contains the known good models this driver is compatible with.
 39 * When adding a new model try to be as strict as possible. This
 40 * makes it possible to keep the false positives (the model is
 41 * detected as working, but in reality it is not) as low as
 42 * possible.
 43 */
 44static const struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
 45	{
 46		.callback = clevo_mail_led_dmi_callback,
 47		.ident = "Clevo D410J",
 48		.matches = {
 49			DMI_MATCH(DMI_SYS_VENDOR, "VIA"),
 50			DMI_MATCH(DMI_PRODUCT_NAME, "K8N800"),
 51			DMI_MATCH(DMI_PRODUCT_VERSION, "VT8204B")
 52		}
 53	},
 54	{
 55		.callback = clevo_mail_led_dmi_callback,
 56		.ident = "Clevo M5x0N",
 57		.matches = {
 58			DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."),
 59			DMI_MATCH(DMI_PRODUCT_NAME, "M5x0N")
 60		}
 61	},
 62	{
 63		.callback = clevo_mail_led_dmi_callback,
 64		.ident = "Clevo M5x0V",
 65		.matches = {
 66			DMI_MATCH(DMI_BOARD_VENDOR, "CLEVO Co. "),
 67			DMI_MATCH(DMI_BOARD_NAME, "M5X0V "),
 
 68			DMI_MATCH(DMI_PRODUCT_VERSION, "VT6198")
 69		}
 70	},
 71	{
 72		.callback = clevo_mail_led_dmi_callback,
 73		.ident = "Clevo D400P",
 74		.matches = {
 75			DMI_MATCH(DMI_BOARD_VENDOR, "Clevo"),
 76			DMI_MATCH(DMI_BOARD_NAME, "D400P"),
 77			DMI_MATCH(DMI_BOARD_VERSION, "Rev.A"),
 78			DMI_MATCH(DMI_PRODUCT_VERSION, "0106")
 79		}
 80	},
 81	{
 82		.callback = clevo_mail_led_dmi_callback,
 83		.ident = "Clevo D410V",
 84		.matches = {
 85			DMI_MATCH(DMI_BOARD_VENDOR, "Clevo, Co."),
 86			DMI_MATCH(DMI_BOARD_NAME, "D400V/D470V"),
 87			DMI_MATCH(DMI_BOARD_VERSION, "SS78B"),
 88			DMI_MATCH(DMI_PRODUCT_VERSION, "Rev. A1")
 89		}
 90	},
 91	{ }
 92};
 93MODULE_DEVICE_TABLE(dmi, clevo_mail_led_dmi_table);
 94
 95static void clevo_mail_led_set(struct led_classdev *led_cdev,
 96				enum led_brightness value)
 97{
 98	i8042_lock_chip();
 99
100	if (value == LED_OFF)
101		i8042_command(NULL, CLEVO_MAIL_LED_OFF);
102	else if (value <= LED_HALF)
103		i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ);
104	else
105		i8042_command(NULL, CLEVO_MAIL_LED_BLINK_1HZ);
106
107	i8042_unlock_chip();
108
109}
110
111static int clevo_mail_led_blink(struct led_classdev *led_cdev,
112				unsigned long *delay_on,
113				unsigned long *delay_off)
114{
115	int status = -EINVAL;
116
117	i8042_lock_chip();
118
119	if (*delay_on == 0 /* ms */ && *delay_off == 0 /* ms */) {
120		/* Special case: the leds subsystem requested us to
121		 * chose one user friendly blinking of the LED, and
122		 * start it. Let's blink the led slowly (0.5Hz).
123		 */
124		*delay_on = 1000; /* ms */
125		*delay_off = 1000; /* ms */
126		i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ);
127		status = 0;
128
129	} else if (*delay_on == 500 /* ms */ && *delay_off == 500 /* ms */) {
130		/* blink the led with 1Hz */
131		i8042_command(NULL, CLEVO_MAIL_LED_BLINK_1HZ);
132		status = 0;
133
134	} else if (*delay_on == 1000 /* ms */ && *delay_off == 1000 /* ms */) {
135		/* blink the led with 0.5Hz */
136		i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ);
137		status = 0;
138
139	} else {
140		pr_debug("clevo_mail_led_blink(..., %lu, %lu),"
 
141		       " returning -EINVAL (unsupported)\n",
142		       *delay_on, *delay_off);
143	}
144
145	i8042_unlock_chip();
146
147	return status;
148}
149
150static struct led_classdev clevo_mail_led = {
151	.name			= "clevo::mail",
152	.brightness_set		= clevo_mail_led_set,
153	.blink_set		= clevo_mail_led_blink,
154	.flags			= LED_CORE_SUSPENDRESUME,
155};
156
157static int __init clevo_mail_led_probe(struct platform_device *pdev)
158{
159	return led_classdev_register(&pdev->dev, &clevo_mail_led);
160}
161
162static int clevo_mail_led_remove(struct platform_device *pdev)
163{
164	led_classdev_unregister(&clevo_mail_led);
165	return 0;
166}
167
168static struct platform_driver clevo_mail_led_driver = {
 
169	.remove		= clevo_mail_led_remove,
170	.driver		= {
171		.name		= KBUILD_MODNAME,
 
172	},
173};
174
175static int __init clevo_mail_led_init(void)
176{
177	int error = 0;
178	int count = 0;
179
180	/* Check with the help of DMI if we are running on supported hardware */
181	if (!nodetect) {
182		count = dmi_check_system(clevo_mail_led_dmi_table);
183	} else {
184		count = 1;
185		pr_err("Skipping DMI detection. "
186		       "If the driver works on your hardware please "
187		       "report model and the output of dmidecode in tracker "
188		       "at http://sourceforge.net/projects/clevo-mailled/\n");
189	}
190
191	if (!count)
192		return -ENODEV;
193
194	pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0);
195	if (!IS_ERR(pdev)) {
196		error = platform_driver_probe(&clevo_mail_led_driver,
197					      clevo_mail_led_probe);
198		if (error) {
199			pr_err("Can't probe platform driver\n");
 
200			platform_device_unregister(pdev);
201		}
202	} else
203		error = PTR_ERR(pdev);
204
205	return error;
206}
207
208static void __exit clevo_mail_led_exit(void)
209{
210	platform_device_unregister(pdev);
211	platform_driver_unregister(&clevo_mail_led_driver);
212
213	clevo_mail_led_set(NULL, LED_OFF);
214}
215
216module_init(clevo_mail_led_init);
217module_exit(clevo_mail_led_exit);