* [PATCH 1/2] leds: lm3533: replace als attribute with als_channel and als_en
@ 2012-05-22 10:05 Johan Hovold
2012-05-22 10:05 ` [PATCH 2/2] backlight: " Johan Hovold
0 siblings, 1 reply; 2+ messages in thread
From: Johan Hovold @ 2012-05-22 10:05 UTC (permalink / raw)
To: Richard Purdie, Andrew Morton
Cc: Rob Landley, Florian Tobias Schandinat, linux-doc, linux-fbdev,
Jonathan Cameron, linux-kernel, Johan Hovold
Replace the als attribute with two separate attributes for selecting ALS
channel and enabling ALS-current-control mode.
This change is needed to reflect changes made to the ALS sub-driver
which now uses 0-indexed current output channels (rather than 1-indexed
ALS-mapper target sets).
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
.../ABI/testing/sysfs-class-led-driver-lm3533 | 19 +++-
drivers/leds/leds-lm3533.c | 98 +++++++++++++++-----
2 files changed, 87 insertions(+), 30 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-class-led-driver-lm3533 b/Documentation/ABI/testing/sysfs-class-led-driver-lm3533
index a9633fd..620ebb3 100644
--- a/Documentation/ABI/testing/sysfs-class-led-driver-lm3533
+++ b/Documentation/ABI/testing/sysfs-class-led-driver-lm3533
@@ -1,13 +1,20 @@
-What: /sys/class/leds/<led>/als
-Date: April 2012
+What: /sys/class/leds/<led>/als_channel
+Date: May 2012
KernelVersion: 3.5
Contact: Johan Hovold <jhovold@gmail.com>
Description:
- Set the ALS-control mode (0, 2, 3), where
+ Set the ALS output channel to use as input in
+ ALS-current-control mode (1, 2), where
+
+ 1 - out_current1
+ 2 - out_current2
- 0 - disabled
- 2 - ALS-mapper 2
- 3 - ALS-mapper 3
+What: /sys/class/leds/<led>/als_en
+Date: May 2012
+KernelVersion: 3.5
+Contact: Johan Hovold <jhovold@gmail.com>
+Description:
+ Enable ALS-current-control mode (0, 1).
What: /sys/class/leds/<led>/falltime
What: /sys/class/leds/<led>/risetime
diff --git a/drivers/leds/leds-lm3533.c b/drivers/leds/leds-lm3533.c
index e968470..f56b6e7 100644
--- a/drivers/leds/leds-lm3533.c
+++ b/drivers/leds/leds-lm3533.c
@@ -27,8 +27,8 @@
#define LM3533_LVCTRLBANK_MAX 5
#define LM3533_LVCTRLBANK_COUNT 4
#define LM3533_RISEFALLTIME_MAX 7
-#define LM3533_ALS_LV_MIN 2
-#define LM3533_ALS_LV_MAX 3
+#define LM3533_ALS_CHANNEL_LV_MIN 1
+#define LM3533_ALS_CHANNEL_LV_MAX 2
#define LM3533_REG_CTRLBANK_BCONF_BASE 0x1b
#define LM3533_REG_PATTERN_ENABLE 0x28
@@ -39,8 +39,9 @@
#define LM3533_REG_PATTERN_STEP 0x10
-#define LM3533_REG_CTRLBANK_BCONF_MAPPING_MASK 0x04
-#define LM3533_REG_CTRLBANK_BCONF_ALS_MASK 0x03
+#define LM3533_REG_CTRLBANK_BCONF_MAPPING_MASK 0x04
+#define LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK 0x02
+#define LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK 0x01
#define LM3533_LED_FLAG_PATTERN_ENABLE 1
@@ -416,21 +417,14 @@ static ssize_t store_falltime(struct device *dev,
LM3533_REG_PATTERN_FALLTIME_BASE);
}
-/*
- * ALS-control setting:
- *
- * 0 - ALS disabled
- * 2 - ALS-mapper 2
- * 3 - ALS-mapper 3
- */
-static ssize_t show_als(struct device *dev,
+static ssize_t show_als_channel(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct lm3533_led *led = to_lm3533_led(led_cdev);
+ unsigned channel;
u8 reg;
u8 val;
- int als;
int ret;
reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
@@ -438,32 +432,85 @@ static ssize_t show_als(struct device *dev,
if (ret)
return ret;
- als = val & LM3533_REG_CTRLBANK_BCONF_ALS_MASK;
+ channel = (val & LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK) + 1;
- return scnprintf(buf, PAGE_SIZE, "%d\n", als);
+ return scnprintf(buf, PAGE_SIZE, "%u\n", channel);
}
-static ssize_t store_als(struct device *dev,
+static ssize_t store_als_channel(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t len)
{
struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct lm3533_led *led = to_lm3533_led(led_cdev);
- u8 als;
+ unsigned channel;
u8 reg;
+ u8 val;
u8 mask;
int ret;
- if (kstrtou8(buf, 0, &als))
+ if (kstrtouint(buf, 0, &channel))
return -EINVAL;
- if (als != 0 && (als < LM3533_ALS_LV_MIN || als > LM3533_ALS_LV_MAX))
+ if (channel < LM3533_ALS_CHANNEL_LV_MIN ||
+ channel > LM3533_ALS_CHANNEL_LV_MAX)
return -EINVAL;
reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
- mask = LM3533_REG_CTRLBANK_BCONF_ALS_MASK;
+ mask = LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK;
+ val = channel - 1;
+
+ ret = lm3533_update(led->lm3533, reg, val, mask);
+ if (ret)
+ return ret;
+
+ return len;
+}
+
+static ssize_t show_als_en(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct led_classdev *led_cdev = dev_get_drvdata(dev);
+ struct lm3533_led *led = to_lm3533_led(led_cdev);
+ bool enable;
+ u8 reg;
+ u8 val;
+ int ret;
+
+ reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
+ ret = lm3533_read(led->lm3533, reg, &val);
+ if (ret)
+ return ret;
- ret = lm3533_update(led->lm3533, reg, als, mask);
+ enable = val & LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK;
+
+ return scnprintf(buf, PAGE_SIZE, "%d\n", enable);
+}
+
+static ssize_t store_als_en(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct led_classdev *led_cdev = dev_get_drvdata(dev);
+ struct lm3533_led *led = to_lm3533_led(led_cdev);
+ unsigned enable;
+ u8 reg;
+ u8 mask;
+ u8 val;
+ int ret;
+
+ if (kstrtouint(buf, 0, &enable))
+ return -EINVAL;
+
+ reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
+ mask = LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK;
+
+ if (enable)
+ val = mask;
+ else
+ val = 0;
+
+ ret = lm3533_update(led->lm3533, reg, val, mask);
if (ret)
return ret;
@@ -558,7 +605,8 @@ static ssize_t store_pwm(struct device *dev,
return len;
}
-static LM3533_ATTR_RW(als);
+static LM3533_ATTR_RW(als_channel);
+static LM3533_ATTR_RW(als_en);
static LM3533_ATTR_RW(falltime);
static LM3533_ATTR_RO(id);
static LM3533_ATTR_RW(linear);
@@ -566,7 +614,8 @@ static LM3533_ATTR_RW(pwm);
static LM3533_ATTR_RW(risetime);
static struct attribute *lm3533_led_attributes[] = {
- &dev_attr_als.attr,
+ &dev_attr_als_channel.attr,
+ &dev_attr_als_en.attr,
&dev_attr_falltime.attr,
&dev_attr_id.attr,
&dev_attr_linear.attr,
@@ -583,7 +632,8 @@ static umode_t lm3533_led_attr_is_visible(struct kobject *kobj,
struct lm3533_led *led = to_lm3533_led(led_cdev);
umode_t mode = attr->mode;
- if (attr = &dev_attr_als.attr) {
+ if (attr = &dev_attr_als_channel.attr ||
+ attr = &dev_attr_als_en.attr) {
if (!led->lm3533->have_als)
mode = 0;
}
--
1.7.8.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] backlight: lm3533: replace als attribute with als_channel and als_en
2012-05-22 10:05 [PATCH 1/2] leds: lm3533: replace als attribute with als_channel and als_en Johan Hovold
@ 2012-05-22 10:05 ` Johan Hovold
0 siblings, 0 replies; 2+ messages in thread
From: Johan Hovold @ 2012-05-22 10:05 UTC (permalink / raw)
To: Richard Purdie, Andrew Morton
Cc: Rob Landley, Florian Tobias Schandinat, linux-doc, linux-fbdev,
Jonathan Cameron, linux-kernel, Johan Hovold
Replace the als attribute with two separate attributes for selecting ALS
channel and enabling ALS-current-control mode.
This change is needed to reflect changes made to the ALS sub-driver
which now uses 0-indexed current output channels (rather than 1-indexed
ALS-mapper target sets).
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
.../testing/sysfs-class-backlight-driver-lm3533 | 19 +++++---
drivers/video/backlight/lm3533_bl.c | 48 ++++++++++----------
2 files changed, 37 insertions(+), 30 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-class-backlight-driver-lm3533 b/Documentation/ABI/testing/sysfs-class-backlight-driver-lm3533
index ea91f71..77cf7ac 100644
--- a/Documentation/ABI/testing/sysfs-class-backlight-driver-lm3533
+++ b/Documentation/ABI/testing/sysfs-class-backlight-driver-lm3533
@@ -1,13 +1,20 @@
-What: /sys/class/backlight/<backlight>/als
-Date: April 2012
+What: /sys/class/backlight/<backlight>/als_channel
+Date: May 2012
KernelVersion: 3.5
Contact: Johan Hovold <jhovold@gmail.com>
Description:
- Set the ALS-control mode (0..2), where
+ Get the ALS output channel used as input in
+ ALS-current-control mode (0, 1), where
+
+ 0 - out_current0 (backlight 0)
+ 1 - out_current1 (backlight 1)
- 0 - disabled
- 1 - ALS-mapper 1 (backlight 0)
- 2 - ALS-mapper 2 (backlight 1)
+What: /sys/class/backlight/<backlight>/als_en
+Date: May 2012
+KernelVersion: 3.5
+Contact: Johan Hovold <jhovold@gmail.com>
+Description:
+ Enable ALS-current-control mode (0, 1).
What: /sys/class/backlight/<backlight>/id
Date: April 2012
diff --git a/drivers/video/backlight/lm3533_bl.c b/drivers/video/backlight/lm3533_bl.c
index d916ffe..18dca0c 100644
--- a/drivers/video/backlight/lm3533_bl.c
+++ b/drivers/video/backlight/lm3533_bl.c
@@ -79,55 +79,52 @@ static ssize_t show_id(struct device *dev,
return scnprintf(buf, PAGE_SIZE, "%d\n", bl->id);
}
-/*
- * ALS-control setting:
- *
- * 0 - ALS disabled
- * 1 - ALS-mapper 1 (backlight 0)
- * 2 - ALS-mapper 2 (backlight 1)
- */
-static ssize_t show_als(struct device *dev,
+static ssize_t show_als_channel(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct lm3533_bl *bl = dev_get_drvdata(dev);
+ unsigned channel = lm3533_bl_get_ctrlbank_id(bl);
+
+ return scnprintf(buf, PAGE_SIZE, "%u\n", channel);
+}
+
+static ssize_t show_als_en(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct lm3533_bl *bl = dev_get_drvdata(dev);
int ctrlbank = lm3533_bl_get_ctrlbank_id(bl);
u8 val;
u8 mask;
- int als;
+ bool enable;
int ret;
ret = lm3533_read(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, &val);
if (ret)
return ret;
- mask = 2 * ctrlbank;
- als = val & mask;
- if (als)
- als = ctrlbank + 1;
+ mask = 1 << (2 * ctrlbank);
+ enable = val & mask;
- return scnprintf(buf, PAGE_SIZE, "%d\n", als);
+ return scnprintf(buf, PAGE_SIZE, "%d\n", enable);
}
-static ssize_t store_als(struct device *dev,
+static ssize_t store_als_en(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t len)
{
struct lm3533_bl *bl = dev_get_drvdata(dev);
int ctrlbank = lm3533_bl_get_ctrlbank_id(bl);
- int als;
+ int enable;
u8 val;
u8 mask;
int ret;
- if (kstrtoint(buf, 0, &als))
- return -EINVAL;
-
- if (als != 0 && (als != ctrlbank + 1))
+ if (kstrtoint(buf, 0, &enable))
return -EINVAL;
mask = 1 << (2 * ctrlbank);
- if (als)
+ if (enable)
val = mask;
else
val = 0;
@@ -224,13 +221,15 @@ static ssize_t store_pwm(struct device *dev,
return len;
}
-static LM3533_ATTR_RW(als);
+static LM3533_ATTR_RO(als_channel);
+static LM3533_ATTR_RW(als_en);
static LM3533_ATTR_RO(id);
static LM3533_ATTR_RW(linear);
static LM3533_ATTR_RW(pwm);
static struct attribute *lm3533_bl_attributes[] = {
- &dev_attr_als.attr,
+ &dev_attr_als_channel.attr,
+ &dev_attr_als_en.attr,
&dev_attr_id.attr,
&dev_attr_linear.attr,
&dev_attr_pwm.attr,
@@ -244,7 +243,8 @@ static umode_t lm3533_bl_attr_is_visible(struct kobject *kobj,
struct lm3533_bl *bl = dev_get_drvdata(dev);
umode_t mode = attr->mode;
- if (attr = &dev_attr_als.attr) {
+ if (attr = &dev_attr_als_channel.attr ||
+ attr = &dev_attr_als_en.attr) {
if (!bl->lm3533->have_als)
mode = 0;
}
--
1.7.8.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-05-22 10:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-22 10:05 [PATCH 1/2] leds: lm3533: replace als attribute with als_channel and als_en Johan Hovold
2012-05-22 10:05 ` [PATCH 2/2] backlight: " Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).