From: Pavel Machek <pavel@ucw.cz>
To: Jenny TC <jenny.tc@intel.com>
Cc: linux-kernel@vger.kernel.org,
"Dmitry Eremin-Solenikov" <dbaryshkov@gmail.com>,
"Anton Vorontsov" <cbouatmailru@gmail.com>,
"Anton Vorontsov" <anton.vorontsov@linaro.org>,
"Kim Milo" <Milo.Kim@ti.com>, "Lee Jones" <lee.jones@linaro.org>,
"Jingoo Han" <jg1.han@samsung.com>,
"Chanwoo Choi" <cw00.choi@samsung.com>,
"Sachin Kamat" <sachin.kamat@linaro.org>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Pali Rohár" <pali.rohar@gmail.com>,
"Rhyland Klein" <rklein@nvidia.com>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
"David Woodhouse" <dwmw2@infradead.org>,
"Tony Lindgren" <tony@atomide.com>,
"Russell King" <linux@arm.linux.org.uk>,
"Sebastian Reichel" <sre@ring0.de>,
aaro.koskinen@iki.fi,
"Pallala Ramakrishna" <ramakrishna.pallala@intel.com>,
freemangordon@abv.bg, linux-omap@vger.kernel.org
Subject: Re: [PATCH 4/4] power_supply: bq24261 charger driver
Date: Tue, 4 Feb 2014 12:36:21 +0100 [thread overview]
Message-ID: <20140204113621.GB2450@amd.pavel.ucw.cz> (raw)
In-Reply-To: <1391490780-6141-5-git-send-email-jenny.tc@intel.com>
Hi!
> +#define DEV_MANUFACTURER "TI"
> +#define DEV_MANUFACTURER_NAME_SIZE 4
This is unneccessarily complicated for no reason. You copy "TI" to
struct, just so that ou can return pointer to the field on
get_property.
What about simply returning "TI" from get_property, without defines
and copying?
> +#define BQ24261_MIN_CV 3500
> +#define BQ24261_MAX_CV 4440
Other defines use uV as an unit :-(.
> +static void lookup_regval(u16 tbl[][2], size_t size, u16 in_val, u8 *out_val)
> +{
> + int i;
> +
> + for (i = 1; i < size; ++i)
> + if (in_val < tbl[i][0])
> + break;
> +
> + *out_val = (u8) tbl[i - 1][1];
> +}
Umm. Could we simply return the value?
> +static void bq24261_cc_to_reg(int cc, u8 *reg_val)
> +{
> +
> + cc = cc < BQ24261_MAX_CC ? cc : BQ24261_MAX_CC;
> + cc = cc - BQ24261_MIN_CC;
clamp_t?
> + *reg_val = cc > 0 ? ((cc/100) << 3) & 0xFF : 0;
> +}
Just return the value?
> +static void bq24261_cv_to_reg(int cv, u8 *reg_val)
> +{
> + int val;
> +
> + val = clamp_t(int, cv, BQ24261_MIN_CV, BQ24261_MAX_CV);
> + *reg_val =
> + (((val - BQ24261_MIN_CV) / BQ24261_CV_DIV)
> + << BQ24261_CV_BIT_POS);
> +}
Not sure if the defines really make it more readable. It should be
consistent with the above/below functions...
> +static inline void bq24261_iterm_to_reg(int iterm, u8 *regval)
> +{
> + iterm = iterm < BQ24261_MAX_ITERM ? iterm : BQ24261_MAX_ITERM;
> + iterm = iterm - BQ24261_MIN_ITERM;
clamp_t?
> + *regval = iterm > 0 ? (iterm/50) & 0xFF : 0;
> +}
Just return the value.
> +static inline void bq24261_sfty_tmr_to_reg(int tmr, u8 *regval)
> +{
> + return lookup_regval(bq24261_sfty_tmr, ARRAY_SIZE(bq24261_sfty_tmr),
> + tmr, regval);
> +}
Just return the value... returning void values with explicit return is
"interesting".
> + /* If status is fault, wait for READY before enabling the charging */
> +
> + if (!is_ready) {
> + ret = wait_event_timeout(chip->wait_ready,
> + (chip->chrgr_stat != BQ24261_CHRGR_STAT_READY),
> + HZ);
> + dev_info(&chip->client->dev,
> + "chrgr_stat=%x\n", chip->chrgr_stat);
> + if (ret == 0) {
> + dev_err(&chip->client->dev,
> + "Waiting for Charger Ready Failed.Enabling charging anyway\n");
> + }
> + }
So charger has a problem, and we force it on, anyway? Also put space
after ".".
> +static inline int bq24261_set_cv(struct bq24261_charger *chip, int cv)
> +{
> + int bat_volt;
> + int ret;
> + u8 reg_val;
> + u8 vindpm_val = 0x0;
> +
> + /*
> + * Setting VINDPM value as per the battery voltage
> + * VBatt Vindpm Register Setting
> + * < 3.7v 4.2v 0x0 (default)
> + * 3.71v - 3.96v 4.36v 0x2
> + * > 3.96v 4.6v 0x5
> + */
> + ret = get_battery_voltage(&bat_volt);
> + if (ret) {
> + dev_err(&chip->client->dev,
> + "Error getting battery voltage!!\n");
> + } else {
You forget the error value and continue anyway.
> +static inline void resume_charging(struct bq24261_charger *chip)
> +{
> +
> + if (chip->is_charger_enabled)
> + bq24261_enable_charger(chip, true);
> + if (chip->inlmt)
> + bq24261_set_inlmt(chip, chip->inlmt);
> + if (chip->cc)
> + bq24261_set_cc(chip, chip->cc);
> + if (chip->cv)
> + bq24261_set_cv(chip, chip->cv);
> + if (chip->is_charging_enabled)
> + bq24261_enable_charging(chip, true);
What about some error checking?
Is it wise to enable charging when setting voltage failed?
> +static inline bool is_bq24261_enabled(struct bq24261_charger *chip)
> +{
> + if (chip->cable_type == PSY_CHARGER_CABLE_TYPE_NONE)
> + return false;
> + else if (!chip->is_charger_enabled)
> + return false;
Kill the else.
> +static inline int get_battery_voltage(int *volt)
> +{
> + struct power_supply *psy;
> + union power_supply_propval val;
> + int ret;
> +
> + psy = get_psy_battery();
> + if (!psy)
> + return -EINVAL;
Hmm. Does this assume just one battery in the system?
Is it good idea? Older machines contain main and memory backup
batteries. Newer machines contain keyboard and display battery....
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
next prev parent reply other threads:[~2014-02-04 11:36 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-04 5:12 [PATCH v5 0/4] power_supply: Introduce power supply charging driver Jenny TC
2014-02-04 5:12 ` [PATCH 1/4] power_supply: Add inlmt,iterm, min/max temp props Jenny TC
2014-02-04 5:12 ` [PATCH 2/4] power_supply: Introduce generic psy charging driver Jenny TC
2014-02-04 11:36 ` Pavel Machek
2014-02-05 8:14 ` Jenny Tc
2014-02-12 11:00 ` Pavel Machek
2014-02-13 0:51 ` Jingoo Han
2014-02-04 5:12 ` [PATCH 3/4] power_supply: Introduce PSE compliant algorithm Jenny TC
2014-02-04 11:36 ` Pavel Machek
2014-02-20 5:16 ` Jenny Tc
2014-02-21 14:45 ` Pavel Machek
2014-02-26 2:54 ` Jenny Tc
2014-02-27 19:47 ` Linus Walleij
2014-02-28 2:52 ` Jenny Tc
2014-02-27 20:46 ` Pavel Machek
2014-02-27 20:18 ` Linus Walleij
2014-02-28 3:07 ` Jenny Tc
2014-02-28 10:08 ` Pavel Machek
2014-03-03 3:11 ` Jenny Tc
2014-03-03 10:42 ` Pavel Machek
2014-03-07 3:34 ` Linus Walleij
2014-03-07 3:43 ` Jenny Tc
2014-02-04 5:13 ` [PATCH 4/4] power_supply: bq24261 charger driver Jenny TC
2014-02-04 11:36 ` Pavel Machek [this message]
2014-02-20 5:03 ` Jenny Tc
2014-02-21 14:44 ` Pavel Machek
2014-02-25 11:51 ` Jenny Tc
-- strict thread matches above, loose matches on Subject: below --
2014-07-08 6:04 [PATCHv11 0/4] power_supply: Introduce power supply charging driver Jenny TC
2014-07-08 6:04 ` [PATCH 4/4] power_supply: bq24261 charger driver Jenny TC
2014-06-30 9:55 [PATCHv10 0/4] power_supply: Introduce power supply charging driver Jenny TC
2014-06-30 9:55 ` [PATCH 4/4] power_supply: bq24261 charger driver Jenny TC
2014-07-03 15:25 ` Sebastian Reichel
2014-06-19 14:02 [PATCHv9 0/4] power_supply: Introduce power supply charging driver Jenny TC
2014-06-19 14:02 ` [PATCH 4/4] power_supply: bq24261 charger driver Jenny TC
2014-02-20 5:53 [PATCH v6 0/4] power_supply: Introduce power supply charging driver Jenny TC
2014-02-20 5:54 ` [PATCH 4/4] power_supply: bq24261 charger driver Jenny TC
2014-01-30 17:30 [PATCH v4 0/4] power_supply: Introduce power supply charging driver Jenny TC
2014-01-30 17:30 ` [PATCH 4/4] power_supply: bq24261 charger driver Jenny TC
2014-01-30 17:01 ` Pavel Machek
2014-01-31 4:05 ` Jenny Tc
2014-01-22 17:19 [PATCH v3 0/4] power_supply: Introduce power supply charging driver Jenny TC
2014-01-22 17:19 ` [PATCH 4/4] power_supply: bq24261 charger driver Jenny TC
2014-01-23 8:58 ` Jingoo Han
2014-01-25 22:30 ` Pavel Machek
2014-01-28 14:14 ` Pavel Machek
2014-01-29 13:23 ` Jenny Tc
2014-01-29 7:26 ` Jingoo Han
2014-01-29 9:36 ` Pavel Machek
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=20140204113621.GB2450@amd.pavel.ucw.cz \
--to=pavel@ucw.cz \
--cc=Milo.Kim@ti.com \
--cc=aaro.koskinen@iki.fi \
--cc=anton.vorontsov@linaro.org \
--cc=cbouatmailru@gmail.com \
--cc=cw00.choi@samsung.com \
--cc=dbaryshkov@gmail.com \
--cc=dwmw2@infradead.org \
--cc=freemangordon@abv.bg \
--cc=jenny.tc@intel.com \
--cc=jg1.han@samsung.com \
--cc=lars@metafoo.de \
--cc=lee.jones@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=pali.rohar@gmail.com \
--cc=ramakrishna.pallala@intel.com \
--cc=rjw@rjwysocki.net \
--cc=rklein@nvidia.com \
--cc=sachin.kamat@linaro.org \
--cc=sre@ring0.de \
--cc=tony@atomide.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;
as well as URLs for NNTP newsgroup(s).