From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: Shreshtha Kumar SAHU <shreshthakumar.sahu@stericsson.com>
Cc: linus.walleij@stericsson.com, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] leds: add driver for LM3530 ALS
Date: Wed, 19 Jan 2011 14:10:13 +0000 [thread overview]
Message-ID: <1295446213.14388.21898.camel@rex> (raw)
In-Reply-To: <1295420175-22332-1-git-send-email-shreshthakumar.sahu@stericsson.com>
On Wed, 2011-01-19 at 12:26 +0530, Shreshtha Kumar SAHU wrote:
> From: Shreshtha Kumar Sahu <shreshthakumar.sahu@stericsson.com>
>
> simple backlight driver for National Semiconductor LM3530.
> Presently only manual mode is supported, PWM and ALS support
> to be added.
>
[...]
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_GEN_CONFIG, gen_config);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_ALS_CONFIG, als_config);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_BRT_RAMP_RATE, brt_ramp);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_ALS_IMP_SELECT, als_imp_sel);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_BRT_CTRL_REG, brightness);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_ALS_ZB0_REG, LM3530_DEF_ZB_0);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_ALS_ZB1_REG, LM3530_DEF_ZB_1);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_ALS_ZB2_REG, LM3530_DEF_ZB_2);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_ALS_ZB3_REG, LM3530_DEF_ZB_3);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_ALS_Z0T_REG, LM3530_DEF_ZT_0);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_ALS_Z1T_REG, LM3530_DEF_ZT_1);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_ALS_Z2T_REG, LM3530_DEF_ZT_2);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_ALS_Z3T_REG, LM3530_DEF_ZT_3);
> + if (ret)
> + return ret;
> + ret = i2c_smbus_write_byte_data(client,
> + LM3530_ALS_Z4T_REG, LM3530_DEF_ZT_4);
> + if (ret)
> + return ret;
> +
> + return ret;
I can't help wonder if a table of values iterated over would look a
little neater here. The last if is harmless but pointless too.
> +static ssize_t lm3530_mode_set(struct device *dev, struct device_attribute
> + *attr, const char *buf, size_t size)
> +{
> + int err;
> + struct i2c_client *client = container_of(
> + dev->parent, struct i2c_client, dev);
> + struct lm3530_data *drvdata = i2c_get_clientdata(client);
> + unsigned long mode;
> +
> + err = strict_strtoul(buf, 10, &mode);
> + if (err < 0)
> + return -EINVAL;
> +
> + if (mode == LM3530_BL_MODE_MANUAL)
> + drvdata->mode = LM3530_BL_MODE_MANUAL;
> + else if (mode == LM3530_BL_MODE_ALS)
> + drvdata->mode = LM3530_BL_MODE_ALS;
> + else if (mode == LM3530_BL_MODE_PWM) {
> + dev_err(dev, "PWM mode not supported\n");
> + return -EINVAL;
> + }
> +
> + err = lm3530_init_registers(drvdata);
> + if (err) {
> + dev_err(dev, "Setting %s Mode failed :%d\n", buf, err);
> + return err;
> + }
> +
> + return sizeof(drvdata->mode);
> +}
> +
> +static DEVICE_ATTR(mode, 0644, NULL, lm3530_mode_set);
So you poke random values of 0, 1, 2 into sysfs? I suspect that breaks
sysfs guidelines and these should be meaningful values like "pwm", "als"
and "led". The enum is ok within the kernel but not for exposure outside
of it.
Also, calling out PWM specifically as not supported seems like the wrong
approach and I'm curious what happens if I poke 4 in there.
The rest looked ok at a quick glance.
Cheers,
Richard
next prev parent reply other threads:[~2011-01-19 14:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-19 6:56 [PATCH 1/2] leds: add driver for LM3530 ALS Shreshtha Kumar SAHU
2011-01-19 6:56 ` [PATCH 2/2] u5500: Add lm3530 ALS platform data Shreshtha Kumar SAHU
2011-01-19 14:10 ` Richard Purdie [this message]
2011-01-20 10:03 ` [PATCH 1/2] leds: add driver for LM3530 ALS Shreshtha Kumar SAHU
[not found] <1295413341-30276-1-git-send-email-shreshthakumar.sahu@stericsson.com>
2011-01-19 12:46 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1295446213.14388.21898.camel@rex \
--to=richard.purdie@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=linus.walleij@stericsson.com \
--cc=linux-kernel@vger.kernel.org \
--cc=shreshthakumar.sahu@stericsson.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox