Arnaud Patard | bd4009a | 2007-02-12 23:09:32 +0000 | [diff] [blame] | 1 | /* |
Uwe Kleine-König | 5886269 | 2007-05-09 07:51:49 +0200 | [diff] [blame] | 2 | * drivers/leds/leds-h1940.c |
Arnaud Patard | bd4009a | 2007-02-12 23:09:32 +0000 | [diff] [blame] | 3 | * Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org> |
| 4 | * |
| 5 | * This file is subject to the terms and conditions of the GNU General Public |
| 6 | * License. See the file COPYING in the main directory of this archive for |
| 7 | * more details. |
| 8 | * |
| 9 | * H1940 leds driver |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <linux/ctype.h> |
| 18 | #include <linux/leds.h> |
Ben Dooks | ec976d6 | 2009-05-13 22:52:24 +0100 | [diff] [blame] | 19 | #include <linux/gpio.h> |
| 20 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 21 | #include <mach/regs-gpio.h> |
| 22 | #include <mach/hardware.h> |
| 23 | #include <mach/h1940-latch.h> |
Arnaud Patard | bd4009a | 2007-02-12 23:09:32 +0000 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | * Green led. |
| 27 | */ |
Ben Dooks | dd1160d | 2008-06-09 22:00:49 +0100 | [diff] [blame] | 28 | static void h1940_greenled_set(struct led_classdev *led_dev, |
| 29 | enum led_brightness value) |
Arnaud Patard | bd4009a | 2007-02-12 23:09:32 +0000 | [diff] [blame] | 30 | { |
| 31 | switch (value) { |
Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 32 | case LED_HALF: |
| 33 | h1940_latch_control(0, H1940_LATCH_LED_FLASH); |
| 34 | s3c2410_gpio_setpin(S3C2410_GPA7, 1); |
| 35 | break; |
| 36 | case LED_FULL: |
| 37 | h1940_latch_control(0, H1940_LATCH_LED_GREEN); |
| 38 | s3c2410_gpio_setpin(S3C2410_GPA7, 1); |
| 39 | break; |
| 40 | default: |
| 41 | case LED_OFF: |
| 42 | h1940_latch_control(H1940_LATCH_LED_FLASH, 0); |
| 43 | h1940_latch_control(H1940_LATCH_LED_GREEN, 0); |
| 44 | s3c2410_gpio_setpin(S3C2410_GPA7, 0); |
| 45 | break; |
Arnaud Patard | bd4009a | 2007-02-12 23:09:32 +0000 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
| 49 | static struct led_classdev h1940_greenled = { |
| 50 | .name = "h1940:green", |
| 51 | .brightness_set = h1940_greenled_set, |
| 52 | .default_trigger = "h1940-charger", |
| 53 | }; |
| 54 | |
| 55 | /* |
| 56 | * Red led. |
| 57 | */ |
Ben Dooks | dd1160d | 2008-06-09 22:00:49 +0100 | [diff] [blame] | 58 | static void h1940_redled_set(struct led_classdev *led_dev, |
| 59 | enum led_brightness value) |
Arnaud Patard | bd4009a | 2007-02-12 23:09:32 +0000 | [diff] [blame] | 60 | { |
| 61 | switch (value) { |
Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 62 | case LED_HALF: |
| 63 | h1940_latch_control(0, H1940_LATCH_LED_FLASH); |
| 64 | s3c2410_gpio_setpin(S3C2410_GPA1, 1); |
| 65 | break; |
| 66 | case LED_FULL: |
| 67 | h1940_latch_control(0, H1940_LATCH_LED_RED); |
| 68 | s3c2410_gpio_setpin(S3C2410_GPA1, 1); |
| 69 | break; |
| 70 | default: |
| 71 | case LED_OFF: |
| 72 | h1940_latch_control(H1940_LATCH_LED_FLASH, 0); |
| 73 | h1940_latch_control(H1940_LATCH_LED_RED, 0); |
| 74 | s3c2410_gpio_setpin(S3C2410_GPA1, 0); |
| 75 | break; |
Arnaud Patard | bd4009a | 2007-02-12 23:09:32 +0000 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
| 79 | static struct led_classdev h1940_redled = { |
| 80 | .name = "h1940:red", |
| 81 | .brightness_set = h1940_redled_set, |
| 82 | .default_trigger = "h1940-charger", |
| 83 | }; |
| 84 | |
| 85 | /* |
| 86 | * Blue led. |
| 87 | * (it can only be blue flashing led) |
| 88 | */ |
Ben Dooks | dd1160d | 2008-06-09 22:00:49 +0100 | [diff] [blame] | 89 | static void h1940_blueled_set(struct led_classdev *led_dev, |
| 90 | enum led_brightness value) |
Arnaud Patard | bd4009a | 2007-02-12 23:09:32 +0000 | [diff] [blame] | 91 | { |
| 92 | if (value) { |
| 93 | /* flashing Blue */ |
Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 94 | h1940_latch_control(0, H1940_LATCH_LED_FLASH); |
| 95 | s3c2410_gpio_setpin(S3C2410_GPA3, 1); |
Arnaud Patard | bd4009a | 2007-02-12 23:09:32 +0000 | [diff] [blame] | 96 | } else { |
Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 97 | h1940_latch_control(H1940_LATCH_LED_FLASH, 0); |
| 98 | s3c2410_gpio_setpin(S3C2410_GPA3, 0); |
Arnaud Patard | bd4009a | 2007-02-12 23:09:32 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | } |
| 102 | |
| 103 | static struct led_classdev h1940_blueled = { |
| 104 | .name = "h1940:blue", |
| 105 | .brightness_set = h1940_blueled_set, |
| 106 | .default_trigger = "h1940-bluetooth", |
| 107 | }; |
| 108 | |
Uwe Kleine-König | b0edba7 | 2009-03-28 00:26:38 +0100 | [diff] [blame] | 109 | static int __devinit h1940leds_probe(struct platform_device *pdev) |
Arnaud Patard | bd4009a | 2007-02-12 23:09:32 +0000 | [diff] [blame] | 110 | { |
| 111 | int ret; |
| 112 | |
| 113 | ret = led_classdev_register(&pdev->dev, &h1940_greenled); |
| 114 | if (ret) |
| 115 | goto err_green; |
| 116 | |
| 117 | ret = led_classdev_register(&pdev->dev, &h1940_redled); |
| 118 | if (ret) |
| 119 | goto err_red; |
| 120 | |
| 121 | ret = led_classdev_register(&pdev->dev, &h1940_blueled); |
| 122 | if (ret) |
| 123 | goto err_blue; |
| 124 | |
| 125 | return 0; |
| 126 | |
| 127 | err_blue: |
| 128 | led_classdev_unregister(&h1940_redled); |
| 129 | err_red: |
| 130 | led_classdev_unregister(&h1940_greenled); |
| 131 | err_green: |
| 132 | return ret; |
| 133 | } |
| 134 | |
| 135 | static int h1940leds_remove(struct platform_device *pdev) |
| 136 | { |
| 137 | led_classdev_unregister(&h1940_greenled); |
| 138 | led_classdev_unregister(&h1940_redled); |
| 139 | led_classdev_unregister(&h1940_blueled); |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | |
| 144 | static struct platform_driver h1940leds_driver = { |
| 145 | .driver = { |
| 146 | .name = "h1940-leds", |
Kay Sievers | 3c4ded9 | 2008-04-15 14:34:30 -0700 | [diff] [blame] | 147 | .owner = THIS_MODULE, |
Arnaud Patard | bd4009a | 2007-02-12 23:09:32 +0000 | [diff] [blame] | 148 | }, |
| 149 | .probe = h1940leds_probe, |
| 150 | .remove = h1940leds_remove, |
| 151 | }; |
| 152 | |
| 153 | |
| 154 | static int __init h1940leds_init(void) |
| 155 | { |
| 156 | return platform_driver_register(&h1940leds_driver); |
| 157 | } |
| 158 | |
| 159 | static void __exit h1940leds_exit(void) |
| 160 | { |
| 161 | platform_driver_unregister(&h1940leds_driver); |
| 162 | } |
| 163 | |
| 164 | module_init(h1940leds_init); |
| 165 | module_exit(h1940leds_exit); |
| 166 | |
| 167 | MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>"); |
| 168 | MODULE_DESCRIPTION("LED driver for the iPAQ H1940"); |
| 169 | MODULE_LICENSE("GPL"); |
Kay Sievers | 3c4ded9 | 2008-04-15 14:34:30 -0700 | [diff] [blame] | 170 | MODULE_ALIAS("platform:h1940-leds"); |