| Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 1 | /* | 
 | 2 |  * LED Triggers Core | 
 | 3 |  * For the HP Jornada 620/660/680/690 handhelds | 
 | 4 |  * | 
 | 5 |  * Copyright 2008 Kristoffer Ericson <kristoffer.ericson@gmail.com> | 
 | 6 |  *     this driver is based on leds-spitz.c by Richard Purdie. | 
 | 7 |  * | 
 | 8 |  * This program is free software; you can redistribute it and/or modify | 
 | 9 |  * it under the terms of the GNU General Public License version 2 as | 
 | 10 |  * published by the Free Software Foundation. | 
 | 11 |  */ | 
 | 12 |  | 
 | 13 | #include <linux/kernel.h> | 
 | 14 | #include <linux/init.h> | 
 | 15 | #include <linux/platform_device.h> | 
 | 16 | #include <linux/leds.h> | 
 | 17 | #include <asm/hd64461.h> | 
| Paul Mundt | 7639a45 | 2008-10-20 13:02:48 +0900 | [diff] [blame] | 18 | #include <mach/hp6xx.h> | 
| Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 19 |  | 
| Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 20 | static void hp6xxled_green_set(struct led_classdev *led_cdev, | 
 | 21 | 			       enum led_brightness value) | 
| Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 22 | { | 
 | 23 | 	u8 v8; | 
 | 24 |  | 
 | 25 | 	v8 = inb(PKDR); | 
 | 26 | 	if (value) | 
 | 27 | 		outb(v8 & (~PKDR_LED_GREEN), PKDR); | 
 | 28 | 	else | 
 | 29 | 		outb(v8 | PKDR_LED_GREEN, PKDR); | 
 | 30 | } | 
 | 31 |  | 
| Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 32 | static void hp6xxled_red_set(struct led_classdev *led_cdev, | 
 | 33 | 			     enum led_brightness value) | 
| Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 34 | { | 
 | 35 | 	u16 v16; | 
 | 36 |  | 
 | 37 | 	v16 = inw(HD64461_GPBDR); | 
 | 38 | 	if (value) | 
 | 39 | 		outw(v16 & (~HD64461_GPBDR_LED_RED), HD64461_GPBDR); | 
 | 40 | 	else | 
 | 41 | 		outw(v16 | HD64461_GPBDR_LED_RED, HD64461_GPBDR); | 
 | 42 | } | 
 | 43 |  | 
 | 44 | static struct led_classdev hp6xx_red_led = { | 
 | 45 | 	.name			= "hp6xx:red", | 
 | 46 | 	.default_trigger	= "hp6xx-charge", | 
 | 47 | 	.brightness_set		= hp6xxled_red_set, | 
 | 48 | }; | 
 | 49 |  | 
 | 50 | static struct led_classdev hp6xx_green_led = { | 
 | 51 | 	.name			= "hp6xx:green", | 
 | 52 | 	.default_trigger	= "ide-disk", | 
 | 53 | 	.brightness_set		= hp6xxled_green_set, | 
 | 54 | }; | 
 | 55 |  | 
 | 56 | #ifdef CONFIG_PM | 
 | 57 | static int hp6xxled_suspend(struct platform_device *dev, pm_message_t state) | 
 | 58 | { | 
 | 59 | 	led_classdev_suspend(&hp6xx_red_led); | 
 | 60 | 	led_classdev_suspend(&hp6xx_green_led); | 
 | 61 | 	return 0; | 
 | 62 | } | 
 | 63 |  | 
 | 64 | static int hp6xxled_resume(struct platform_device *dev) | 
 | 65 | { | 
 | 66 | 	led_classdev_resume(&hp6xx_red_led); | 
 | 67 | 	led_classdev_resume(&hp6xx_green_led); | 
 | 68 | 	return 0; | 
 | 69 | } | 
 | 70 | #endif | 
 | 71 |  | 
 | 72 | static int hp6xxled_probe(struct platform_device *pdev) | 
 | 73 | { | 
 | 74 | 	int ret; | 
 | 75 |  | 
 | 76 | 	ret = led_classdev_register(&pdev->dev, &hp6xx_red_led); | 
 | 77 | 	if (ret < 0) | 
 | 78 | 		return ret; | 
 | 79 |  | 
 | 80 | 	ret = led_classdev_register(&pdev->dev, &hp6xx_green_led); | 
 | 81 | 	if (ret < 0) | 
 | 82 | 		led_classdev_unregister(&hp6xx_red_led); | 
 | 83 |  | 
 | 84 | 	return ret; | 
 | 85 | } | 
 | 86 |  | 
 | 87 | static int hp6xxled_remove(struct platform_device *pdev) | 
 | 88 | { | 
 | 89 | 	led_classdev_unregister(&hp6xx_red_led); | 
 | 90 | 	led_classdev_unregister(&hp6xx_green_led); | 
 | 91 |  | 
 | 92 | 	return 0; | 
 | 93 | } | 
 | 94 |  | 
| Kay Sievers | 3c4ded9 | 2008-04-15 14:34:30 -0700 | [diff] [blame] | 95 | /* work with hotplug and coldplug */ | 
 | 96 | MODULE_ALIAS("platform:hp6xx-led"); | 
 | 97 |  | 
| Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 98 | static struct platform_driver hp6xxled_driver = { | 
 | 99 | 	.probe		= hp6xxled_probe, | 
 | 100 | 	.remove		= hp6xxled_remove, | 
 | 101 | #ifdef CONFIG_PM | 
 | 102 | 	.suspend	= hp6xxled_suspend, | 
 | 103 | 	.resume		= hp6xxled_resume, | 
 | 104 | #endif | 
 | 105 | 	.driver		= { | 
 | 106 | 		.name		= "hp6xx-led", | 
| Kay Sievers | 3c4ded9 | 2008-04-15 14:34:30 -0700 | [diff] [blame] | 107 | 		.owner		= THIS_MODULE, | 
| Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 108 | 	}, | 
 | 109 | }; | 
 | 110 |  | 
 | 111 | static int __init hp6xxled_init(void) | 
 | 112 | { | 
 | 113 | 	return platform_driver_register(&hp6xxled_driver); | 
 | 114 | } | 
 | 115 |  | 
 | 116 | static void __exit hp6xxled_exit(void) | 
 | 117 | { | 
 | 118 | 	platform_driver_unregister(&hp6xxled_driver); | 
 | 119 | } | 
 | 120 |  | 
 | 121 | module_init(hp6xxled_init); | 
 | 122 | module_exit(hp6xxled_exit); | 
 | 123 |  | 
 | 124 | MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>"); | 
 | 125 | MODULE_DESCRIPTION("HP Jornada 6xx LED driver"); | 
 | 126 | MODULE_LICENSE("GPL"); |