From: Siarhei Siamashka <siarhei.siamashka@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/8] sunxi: axp221: Add ELDO[1-3] support
Date: Sun, 11 Jan 2015 14:05:08 +0200 [thread overview]
Message-ID: <20150111140508.62cea298@i7> (raw)
In-Reply-To: <20150109180535.41f14077@crub>
On Fri, 9 Jan 2015 18:05:35 +0100
Anatolij Gustschin <agust@denx.de> wrote:
> On Fri, 9 Jan 2015 12:01:09 +0200
> Siarhei Siamashka <siarhei.siamashka@gmail.com> wrote:
> ...
> > +int axp221_set_eldo2(unsigned int mvolt)
> > +{
> > + int ret;
> > + u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
> > +
> > + if (mvolt == 0)
> > + return axp221_clrbits(AXP221_OUTPUT_CTRL2,
> > + AXP221_OUTPUT_CTRL2_ELDO2_EN);
> > +
> > + ret = pmic_bus_write(AXP221_ELDO2_CTRL, cfg);
> > + if (ret)
> > + return ret;
> > +
> > + return axp221_setbits(AXP221_OUTPUT_CTRL2,
> > + AXP221_OUTPUT_CTRL2_ELDO2_EN);
> > +}
> > +
> > +int axp221_set_eldo3(unsigned int mvolt)
> > +{
> > + int ret;
> > + u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
> > +
> > + if (mvolt == 0)
> > + return axp221_clrbits(AXP221_OUTPUT_CTRL2,
> > + AXP221_OUTPUT_CTRL2_ELDO3_EN);
> > +
> > + ret = pmic_bus_write(AXP221_ELDO3_CTRL, cfg);
> > + if (ret)
> > + return ret;
> > +
> > + return axp221_setbits(AXP221_OUTPUT_CTRL2,
> > + AXP221_OUTPUT_CTRL2_ELDO3_EN);
> > +}
>
> Can we avoid code duplication here? I.e. only one function
> should be sufficient here:
>
> int axp221_set_eldo(int eldo_num, unsigned int mvolt)
> {
> int ret;
> u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
> u8 addr, bits;
>
> switch (eldo_num) {
> case 3:
> addr = AXP221_ELDO3_CTRL;
> bits = AXP221_OUTPUT_CTRL2_ELDO3_EN;
> break;
> case 2:
> addr = AXP221_ELDO2_CTRL;
> bits = AXP221_OUTPUT_CTRL2_ELDO2_EN;
> break;
> case 1:
> default:
> addr = AXP221_ELDO1_CTRL;
> bits = AXP221_OUTPUT_CTRL2_ELDO1_EN;
> break;
> }
>
> if (mvolt == 0)
> return axp221_clrbits(AXP221_OUTPUT_CTRL2, bits);
>
> ret = pmic_bus_write(addr, cfg);
> if (ret)
> return ret;
>
> return axp221_setbits(AXP221_OUTPUT_CTRL2, bits);
> }
Thanks for the review.
Yes, I am not very happy about this code duplication either. But I just
made it so that it follows the same pattern as the rest of the code in
the axp221 source file for the other voltage regulators. Does it mean
that we want to change it all to have a consistent style?
This is a purely sunxi code and not directly related to video. And I
would like to know what sunxi custodians think about it.
--
Best regards,
Siarhei Siamashka
next prev parent reply other threads:[~2015-01-11 12:05 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-09 10:01 [U-Boot] [PATCH 0/8] video: Add support for SSD2828 (parallel LCD to MIPI bridge) Siarhei Siamashka
2015-01-09 10:01 ` [U-Boot] [PATCH 1/8] sunxi: axp221: Add ELDO[1-3] support Siarhei Siamashka
2015-01-09 17:05 ` Anatolij Gustschin
2015-01-11 12:05 ` Siarhei Siamashka [this message]
2015-01-11 13:43 ` Hans de Goede
2015-01-09 10:01 ` [U-Boot] [PATCH 2/8] include: Add header file with MIPI DSI constants from the Linux kernel Siarhei Siamashka
2015-01-09 17:15 ` Anatolij Gustschin
2015-01-11 12:05 ` Siarhei Siamashka
2015-01-09 10:01 ` [U-Boot] [PATCH 3/8] video: Add support for SSD2828 (parallel LCD to MIPI bridge) Siarhei Siamashka
2015-01-10 0:01 ` Anatolij Gustschin
2015-01-09 10:01 ` [U-Boot] [PATCH 4/8] video: sunxi: Hook up SSD2828 with the sunxi video driver Siarhei Siamashka
2015-01-10 0:21 ` Anatolij Gustschin
2015-01-09 10:01 ` [U-Boot] [PATCH 5/8] sun6i: Add LCD display support for MSI Primo81 tablet Siarhei Siamashka
2015-01-10 0:24 ` Anatolij Gustschin
2015-01-09 10:01 ` [U-Boot] [PATCH 6/8] video: ssd2828: Allow using 'pclk' as the PLL clock source Siarhei Siamashka
2015-01-10 0:33 ` Anatolij Gustschin
2015-01-09 10:01 ` [U-Boot] [PATCH 7/8] video: sunxi: Switch from 'tx_clk' to 'pclk' for SSD2828 Siarhei Siamashka
2015-01-10 0:39 ` Anatolij Gustschin
2015-01-09 10:01 ` [U-Boot] [PATCH 8/8] video: ssd2828: Use MIPI DCS commands to retrieve the LCD panel id Siarhei Siamashka
2015-01-09 10:28 ` [U-Boot] [PATCH 0/8] video: Add support for SSD2828 (parallel LCD to MIPI bridge) Siarhei Siamashka
2015-01-09 15:35 ` Hans de Goede
2015-01-10 9:17 ` Hans de Goede
2015-01-10 10:52 ` Ian Campbell
2015-01-11 12:09 ` Siarhei Siamashka
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=20150111140508.62cea298@i7 \
--to=siarhei.siamashka@gmail.com \
--cc=u-boot@lists.denx.de \
/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