rename kernel-power folder to kernel-bfs.
[kernel-bfs] / kernel-bfs-2.6.28 / debian / patches / led_dbrightness.diff
1 --- orig/kernel-source/drivers/leds/led-class.c 2008-12-25 01:26:37.000000000 +0200
2 +++ kernel-source/drivers/leds/led-class.c      2010-04-16 15:43:04.000000000 +0300
3 @@ -22,6 +22,8 @@
4  #include <linux/leds.h>
5  #include "leds.h"
6  
7 +#define LED_FLAG_DBRIGHTNESS 0x100
8 +
9  static struct class *leds_class;
10  
11  static void led_update_brightness(struct led_classdev *led_cdev)
12 @@ -50,6 +52,9 @@
13         unsigned long state = simple_strtoul(buf, &after, 10);
14         size_t count = after - buf;
15  
16 +       if (led_cdev->flags & LED_FLAG_DBRIGHTNESS) 
17 +               return size;
18 +
19         if (*after && isspace(*after))
20                 count++;
21  
22 @@ -69,6 +74,51 @@
23  static DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store);
24  #endif
25  
26 +static ssize_t led_dbrightness_show(struct device *dev, 
27 +               struct device_attribute *attr, char *buf)
28 +{
29 +       struct led_classdev *led_cdev = dev_get_drvdata(dev);
30 +
31 +       if (!(led_cdev->flags & LED_FLAG_DBRIGHTNESS)) 
32 +               return sprintf(buf, "-1\n");
33 +               
34 +       /* no lock needed for this */
35 +       led_update_brightness(led_cdev);
36 +
37 +       return sprintf(buf, "%u\n", led_cdev->brightness);
38 +}
39 +
40 +static ssize_t led_dbrightness_store(struct device *dev,
41 +               struct device_attribute *attr, const char *buf, size_t size)
42 +{
43 +       struct led_classdev *led_cdev = dev_get_drvdata(dev);
44 +       ssize_t ret = -EINVAL;
45 +       char *after;
46 +       unsigned long state = simple_strtol(buf, &after, 10);
47 +       size_t count = after - buf;
48 +
49 +       if (state == -1) {
50 +               led_cdev->flags &= ~LED_FLAG_DBRIGHTNESS;
51 +               return size;
52 +       }
53 +
54 +       if (*after && isspace(*after))
55 +               count++;
56 +
57 +       if (count == size) {
58 +               ret = count;
59 +
60 +               led_cdev->flags |= LED_FLAG_DBRIGHTNESS;
61 +               if (state == LED_OFF)
62 +                       led_trigger_remove(led_cdev);
63 +               led_set_brightness(led_cdev, state);
64 +       }
65 +
66 +       return ret;
67 +}
68 +
69 +static DEVICE_ATTR(dbrightness, 0644, led_dbrightness_show, led_dbrightness_store);
70 +
71  /**
72   * led_classdev_suspend - suspend an led_classdev.
73   * @led_cdev: the led_classdev to suspend.
74 @@ -110,6 +160,10 @@
75         if (rc)
76                 goto err_out;
77  
78 +       rc = device_create_file(led_cdev->dev, &dev_attr_dbrightness);
79 +       if (rc)
80 +               goto err_out_dbrightness;
81 +
82  #ifdef CONFIG_LEDS_TRIGGERS
83         init_rwsem(&led_cdev->trigger_lock);
84  #endif
85 @@ -135,9 +189,11 @@
86  
87  #ifdef CONFIG_LEDS_TRIGGERS
88  err_out_led_list:
89 -       device_remove_file(led_cdev->dev, &dev_attr_brightness);
90 +       device_remove_file(led_cdev->dev, &dev_attr_dbrightness);
91         list_del(&led_cdev->node);
92  #endif
93 +err_out_dbrightness:
94 +       device_remove_file(led_cdev->dev, &dev_attr_brightness);
95  err_out:
96         device_unregister(led_cdev->dev);
97         return rc;