From: Mark Brown <broonie@opensource.wolfsonmicro.com>
To: Yadwinder Singh <yadi.brar@samsung.com>
Cc: linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 2/2] regulator: Add support for MAX77686.
Date: Wed, 9 May 2012 19:47:09 +0100 [thread overview]
Message-ID: <20120509184709.GC32037@sirena.org.uk> (raw)
In-Reply-To: <1336580695-1184-3-git-send-email-yadi.brar@samsung.com>
On Wed, May 09, 2012 at 09:54:55PM +0530, Yadwinder Singh wrote:
> +/* Voltage maps in mV */
> +static const struct voltage_map_desc ldo_voltage_map_desc = {
> + .min = 800, .max = 3950, .step = 50, .n_bits = 6,
> +}; /* LDO3 ~ 5, 9 ~ 14, 16 ~ 26 */
Hrm, funnily enough I was just thinking about factoring this stuff out
into the core after a conversation with Graeme Gregory the other week.
Let's do that...
> + [MAX77686_EN32KHZ_AP] = NULL,
> + [MAX77686_EN32KHZ_CP] = NULL,
Now that the generic clock API is in mainline these should be moved over
to use it.
> +static int max77686_get_voltage_unit(int rid)
> +{
> + int unit = 0;
> +
> + switch (rid) {
> + case MAX77686_BUCK2...MAX77686_BUCK4:
> + unit = 1; /* BUCK2,3,4 is uV */
> + break;
> + default:
> + unit = 1000;
Why not just list everything in uV?
> +static int max77686_get_voltage(struct regulator_dev *rdev)
> +{
Implement get_voltage_sel().
> +static inline int max77686_get_voltage_proper_val(const struct voltage_map_desc
> + *desc, int min_vol,
> + int max_vol)
> +{
> + int i = 0;
> +
> + if (desc == NULL)
> + return -EINVAL;
> +
> + if (max_vol < desc->min || min_vol > desc->max)
> + return -EINVAL;
> +
> + while (desc->min + desc->step * i < min_vol &&
> + desc->min + desc->step * i < desc->max)
> + i++;
Why are you iterating here? Calculate! Though like I say let's factor
this out anyway.
> + if (rid == MAX77686_BUCK2 || rid == MAX77686_BUCK3 ||
> + rid == MAX77686_BUCK4) {
> + /* If the voltage is increasing */
> + if (org < i)
> + udelay(DIV_ROUND_UP(desc->step * (i - org),
> + ramp[max77686->ramp_delay]));
> + }
Don't do this, implement set_voltage_time_sel().
> + .enable = max77686_reg_enable,
> + .disable = max77686_reg_disable,
> + .set_suspend_enable = max77686_reg_enable,
> + .set_suspend_disable = max77686_reg_disable,
You've got the same ops for suspend and non-suspend cases here, this is
clearly buggy.
> +/* count the number of regulators to be supported in pmic */
> + pdata->num_regulators = 0;
Coding style.
> + if (iodev->dev->of_node) {
> + ret = max77686_pmic_dt_parse_pdata(iodev, pdata);
> + if (ret)
> + return ret;
This ought to use of_regulator_match().
> + }
> +
> + if (!pdata) {
> + dev_err(&pdev->dev, "platform data not found\n");
> + return -ENODEV;
> + }
This should be totally fine.
> + max77686 = kzalloc(sizeof(struct max77686_data), GFP_KERNEL);
> + if (!max77686)
> + return -ENOMEM;
devm_kzalloc().
> + if (pdata->ramp_delay) {
> + max77686->ramp_delay = pdata->ramp_delay;
> + max77686_update_reg(i2c, MAX77686_REG_BUCK2CTRL1,
> + RAMP_VALUE, RAMP_MASK);
This appears not to actually use the value passed in as platform_data.
> +
> + for (i = 0; i < pdata->num_regulators; i++) {
> + const struct voltage_map_desc *desc;
> + int id = pdata->regulators[i].id;
> +
> + desc = reg_voltage_map[id];
> + if (desc)
> + regulators[id].n_voltages =
> + (desc->max - desc->min) / desc->step + 1;
> +
> + rdev[i] = regulator_register(®ulators[id], max77686->dev,
> + pdata->regulators[i].initdata,
> + max77686, NULL);
No, you should unconditionally register all regulators the device
physically has. This is useful for debug and simplifies the code.
next prev parent reply other threads:[~2012-05-09 18:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-09 16:24 [PATCH 0/2] regulator: add initial suport for max77686 Yadwinder Singh
2012-05-09 16:24 ` [PATCH 1/2] mfd: Add support for MAX77686 Yadwinder Singh
2012-05-09 18:27 ` Mark Brown
2012-05-09 23:42 ` Chanwoo Choi
2012-05-10 7:30 ` Yadwinder Singh Brar
2012-05-09 16:24 ` [PATCH 2/2] regulator: " Yadwinder Singh
2012-05-09 18:47 ` Mark Brown [this message]
2012-05-10 7:24 ` Yadwinder Singh Brar
2012-05-10 9:34 ` Mark Brown
2012-05-10 10:56 ` Yadwinder Singh Brar
2012-05-15 13:47 ` Yadwinder Singh Brar
2012-05-16 13:08 ` Mark Brown
2012-05-09 19:54 ` Sylwester Nawrocki
2012-05-10 7:31 ` Yadwinder Singh Brar
2012-05-09 18:23 ` [PATCH 0/2] regulator: add initial suport for max77686 Mark Brown
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=20120509184709.GC32037@sirena.org.uk \
--to=broonie@opensource.wolfsonmicro.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=yadi.brar@samsung.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