xref: /openbmc/linux/drivers/leds/leds-hp6xx.c (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2d39a7a63SKristoffer Ericson /*
3d39a7a63SKristoffer Ericson  * LED Triggers Core
4d39a7a63SKristoffer Ericson  * For the HP Jornada 620/660/680/690 handhelds
5d39a7a63SKristoffer Ericson  *
6d39a7a63SKristoffer Ericson  * Copyright 2008 Kristoffer Ericson <kristoffer.ericson@gmail.com>
7d39a7a63SKristoffer Ericson  *     this driver is based on leds-spitz.c by Richard Purdie.
8d39a7a63SKristoffer Ericson  */
9d39a7a63SKristoffer Ericson 
1086383b55SAxel Lin #include <linux/module.h>
11d39a7a63SKristoffer Ericson #include <linux/kernel.h>
12d39a7a63SKristoffer Ericson #include <linux/platform_device.h>
13d39a7a63SKristoffer Ericson #include <linux/leds.h>
14d39a7a63SKristoffer Ericson #include <asm/hd64461.h>
157639a454SPaul Mundt #include <mach/hp6xx.h>
16d39a7a63SKristoffer Ericson 
hp6xxled_green_set(struct led_classdev * led_cdev,enum led_brightness value)174d404fd5SNémeth Márton static void hp6xxled_green_set(struct led_classdev *led_cdev,
184d404fd5SNémeth Márton 			       enum led_brightness value)
19d39a7a63SKristoffer Ericson {
20d39a7a63SKristoffer Ericson 	u8 v8;
21d39a7a63SKristoffer Ericson 
22d39a7a63SKristoffer Ericson 	v8 = inb(PKDR);
23d39a7a63SKristoffer Ericson 	if (value)
24d39a7a63SKristoffer Ericson 		outb(v8 & (~PKDR_LED_GREEN), PKDR);
25d39a7a63SKristoffer Ericson 	else
26d39a7a63SKristoffer Ericson 		outb(v8 | PKDR_LED_GREEN, PKDR);
27d39a7a63SKristoffer Ericson }
28d39a7a63SKristoffer Ericson 
hp6xxled_red_set(struct led_classdev * led_cdev,enum led_brightness value)294d404fd5SNémeth Márton static void hp6xxled_red_set(struct led_classdev *led_cdev,
304d404fd5SNémeth Márton 			     enum led_brightness value)
31d39a7a63SKristoffer Ericson {
32d39a7a63SKristoffer Ericson 	u16 v16;
33d39a7a63SKristoffer Ericson 
34d39a7a63SKristoffer Ericson 	v16 = inw(HD64461_GPBDR);
35d39a7a63SKristoffer Ericson 	if (value)
36d39a7a63SKristoffer Ericson 		outw(v16 & (~HD64461_GPBDR_LED_RED), HD64461_GPBDR);
37d39a7a63SKristoffer Ericson 	else
38d39a7a63SKristoffer Ericson 		outw(v16 | HD64461_GPBDR_LED_RED, HD64461_GPBDR);
39d39a7a63SKristoffer Ericson }
40d39a7a63SKristoffer Ericson 
41d39a7a63SKristoffer Ericson static struct led_classdev hp6xx_red_led = {
42d39a7a63SKristoffer Ericson 	.name			= "hp6xx:red",
43d39a7a63SKristoffer Ericson 	.default_trigger	= "hp6xx-charge",
44d39a7a63SKristoffer Ericson 	.brightness_set		= hp6xxled_red_set,
45859cb7f2SRichard Purdie 	.flags			= LED_CORE_SUSPENDRESUME,
46d39a7a63SKristoffer Ericson };
47d39a7a63SKristoffer Ericson 
48d39a7a63SKristoffer Ericson static struct led_classdev hp6xx_green_led = {
49d39a7a63SKristoffer Ericson 	.name			= "hp6xx:green",
50eb25cb99SStephan Linz 	.default_trigger	= "disk-activity",
51d39a7a63SKristoffer Ericson 	.brightness_set		= hp6xxled_green_set,
52859cb7f2SRichard Purdie 	.flags			= LED_CORE_SUSPENDRESUME,
53d39a7a63SKristoffer Ericson };
54d39a7a63SKristoffer Ericson 
hp6xxled_probe(struct platform_device * pdev)55d39a7a63SKristoffer Ericson static int hp6xxled_probe(struct platform_device *pdev)
56d39a7a63SKristoffer Ericson {
57d39a7a63SKristoffer Ericson 	int ret;
58d39a7a63SKristoffer Ericson 
59c0fc68baSMuhammad Falak R Wani 	ret = devm_led_classdev_register(&pdev->dev, &hp6xx_red_led);
60d39a7a63SKristoffer Ericson 	if (ret < 0)
61d39a7a63SKristoffer Ericson 		return ret;
62d39a7a63SKristoffer Ericson 
63c0fc68baSMuhammad Falak R Wani 	return devm_led_classdev_register(&pdev->dev, &hp6xx_green_led);
64d39a7a63SKristoffer Ericson }
65d39a7a63SKristoffer Ericson 
66d39a7a63SKristoffer Ericson static struct platform_driver hp6xxled_driver = {
67d39a7a63SKristoffer Ericson 	.probe		= hp6xxled_probe,
68d39a7a63SKristoffer Ericson 	.driver		= {
69d39a7a63SKristoffer Ericson 		.name		= "hp6xx-led",
70d39a7a63SKristoffer Ericson 	},
71d39a7a63SKristoffer Ericson };
72d39a7a63SKristoffer Ericson 
73892a8843SAxel Lin module_platform_driver(hp6xxled_driver);
74d39a7a63SKristoffer Ericson 
75d39a7a63SKristoffer Ericson MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
76d39a7a63SKristoffer Ericson MODULE_DESCRIPTION("HP Jornada 6xx LED driver");
77d39a7a63SKristoffer Ericson MODULE_LICENSE("GPL");
78892a8843SAxel Lin MODULE_ALIAS("platform:hp6xx-led");
79