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 | |
Axel Lin | 86383b5 | 2011-08-25 15:59:15 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/leds.h> |
| 18 | #include <asm/hd64461.h> |
Paul Mundt | 7639a45 | 2008-10-20 13:02:48 +0900 | [diff] [blame] | 19 | #include <mach/hp6xx.h> |
Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 20 | |
Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 21 | static void hp6xxled_green_set(struct led_classdev *led_cdev, |
| 22 | enum led_brightness value) |
Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 23 | { |
| 24 | u8 v8; |
| 25 | |
| 26 | v8 = inb(PKDR); |
| 27 | if (value) |
| 28 | outb(v8 & (~PKDR_LED_GREEN), PKDR); |
| 29 | else |
| 30 | outb(v8 | PKDR_LED_GREEN, PKDR); |
| 31 | } |
| 32 | |
Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 33 | static void hp6xxled_red_set(struct led_classdev *led_cdev, |
| 34 | enum led_brightness value) |
Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 35 | { |
| 36 | u16 v16; |
| 37 | |
| 38 | v16 = inw(HD64461_GPBDR); |
| 39 | if (value) |
| 40 | outw(v16 & (~HD64461_GPBDR_LED_RED), HD64461_GPBDR); |
| 41 | else |
| 42 | outw(v16 | HD64461_GPBDR_LED_RED, HD64461_GPBDR); |
| 43 | } |
| 44 | |
| 45 | static struct led_classdev hp6xx_red_led = { |
| 46 | .name = "hp6xx:red", |
| 47 | .default_trigger = "hp6xx-charge", |
| 48 | .brightness_set = hp6xxled_red_set, |
Richard Purdie | 859cb7f | 2009-01-08 17:55:03 +0000 | [diff] [blame] | 49 | .flags = LED_CORE_SUSPENDRESUME, |
Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | static struct led_classdev hp6xx_green_led = { |
| 53 | .name = "hp6xx:green", |
| 54 | .default_trigger = "ide-disk", |
| 55 | .brightness_set = hp6xxled_green_set, |
Richard Purdie | 859cb7f | 2009-01-08 17:55:03 +0000 | [diff] [blame] | 56 | .flags = LED_CORE_SUSPENDRESUME, |
Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 59 | static int hp6xxled_probe(struct platform_device *pdev) |
| 60 | { |
| 61 | int ret; |
| 62 | |
| 63 | ret = led_classdev_register(&pdev->dev, &hp6xx_red_led); |
| 64 | if (ret < 0) |
| 65 | return ret; |
| 66 | |
| 67 | ret = led_classdev_register(&pdev->dev, &hp6xx_green_led); |
| 68 | if (ret < 0) |
| 69 | led_classdev_unregister(&hp6xx_red_led); |
| 70 | |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | static int hp6xxled_remove(struct platform_device *pdev) |
| 75 | { |
| 76 | led_classdev_unregister(&hp6xx_red_led); |
| 77 | led_classdev_unregister(&hp6xx_green_led); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
Kay Sievers | 3c4ded9 | 2008-04-15 14:34:30 -0700 | [diff] [blame] | 82 | /* work with hotplug and coldplug */ |
| 83 | MODULE_ALIAS("platform:hp6xx-led"); |
| 84 | |
Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 85 | static struct platform_driver hp6xxled_driver = { |
| 86 | .probe = hp6xxled_probe, |
| 87 | .remove = hp6xxled_remove, |
Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 88 | .driver = { |
| 89 | .name = "hp6xx-led", |
Kay Sievers | 3c4ded9 | 2008-04-15 14:34:30 -0700 | [diff] [blame] | 90 | .owner = THIS_MODULE, |
Kristoffer Ericson | d39a7a6 | 2008-02-07 10:10:28 +0000 | [diff] [blame] | 91 | }, |
| 92 | }; |
| 93 | |
| 94 | static int __init hp6xxled_init(void) |
| 95 | { |
| 96 | return platform_driver_register(&hp6xxled_driver); |
| 97 | } |
| 98 | |
| 99 | static void __exit hp6xxled_exit(void) |
| 100 | { |
| 101 | platform_driver_unregister(&hp6xxled_driver); |
| 102 | } |
| 103 | |
| 104 | module_init(hp6xxled_init); |
| 105 | module_exit(hp6xxled_exit); |
| 106 | |
| 107 | MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>"); |
| 108 | MODULE_DESCRIPTION("HP Jornada 6xx LED driver"); |
| 109 | MODULE_LICENSE("GPL"); |