public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: pavel@ucw.cz (Pavel Machek)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] Add support for bq27521 battery monitor
Date: Thu, 9 Nov 2017 22:45:40 +0100	[thread overview]
Message-ID: <20171109214540.GB23376@amd> (raw)
In-Reply-To: <20171109212945.2sgu56zkse7nbzo3@pali>

On Thu 2017-11-09 22:29:45, Pali Roh?r wrote:
> On Thursday 09 November 2017 22:06:15 Pavel Machek wrote:
> > diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
> > index ed44439..ee2851a 100644
> > --- a/drivers/power/supply/bq27xxx_battery.c
> > +++ b/drivers/power/supply/bq27xxx_battery.c
> > @@ -381,6 +381,30 @@ static u8 bq27xxx_regs[][BQ27XXX_REG_MAX] = {
> >  		[BQ27XXX_REG_AP] = INVALID_REG_ADDR,
> >  		BQ27XXX_DM_REG_ROWS,
> >  	},
> > +	[BQ27521] = {				/* FIXME */
> > +		[BQ27XXX_REG_CTRL] = 0x02,
> > +		[BQ27XXX_REG_TEMP] = 0x0a,
> > +		[BQ27XXX_REG_INT_TEMP] = INVALID_REG_ADDR,
> > +		[BQ27XXX_REG_VOLT] = 0x0c,
> > +		[BQ27XXX_REG_AI] = 0x0e,
> > +		[BQ27XXX_REG_FLAGS] = 0x08,
> > +		[BQ27XXX_REG_TTE] = INVALID_REG_ADDR,
> > +		[BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
> > +		[BQ27XXX_REG_TTES] = INVALID_REG_ADDR,
> > +		[BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
> > +		[BQ27XXX_REG_NAC] = INVALID_REG_ADDR,
> > +		[BQ27XXX_REG_FCC] = INVALID_REG_ADDR,
> > +		[BQ27XXX_REG_CYCT] = INVALID_REG_ADDR,
> > +		[BQ27XXX_REG_AE] = INVALID_REG_ADDR,
> > +		[BQ27XXX_REG_SOC] = INVALID_REG_ADDR,
> > +		[BQ27XXX_REG_DCAP] = INVALID_REG_ADDR,
> > +		[BQ27XXX_REG_AP] = INVALID_REG_ADDR,
> > +		[BQ27XXX_DM_CTRL] = INVALID_REG_ADDR,
> > +		[BQ27XXX_DM_CLASS] = INVALID_REG_ADDR,
> > +		[BQ27XXX_DM_BLOCK] = INVALID_REG_ADDR,
> > +		[BQ27XXX_DM_DATA] = INVALID_REG_ADDR,
> > +		[BQ27XXX_DM_CKSUM] = INVALID_REG_ADDR,
> > +	},
> >  	[BQ27530] = {
> >  		[BQ27XXX_REG_CTRL] = 0x00,
> >  		[BQ27XXX_REG_TEMP] = 0x06,
> 
> Hi! IIRC those registers are valid only for sn27521 chip in revision 14
> (or new). For older revision is used different register map. And
> detection of chip revision is somehow possible via some registers.

Yes, I know.. I even had this, but as I can't test it, and early N950
samples should be very very rare, I'd prefer the patch as is.

@@ -1905,6 +1940,23 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di)
 
 	dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION);
 
+	if (di->chip == BQ27521) {
+		int val;
+		val = di->bus.read(di, 0x32, false);
+		if (val == 0x2100) {
+			printk("rev. 13 chip detected; add support\n");
+			/* https://elinux.org/N950 has details */
+			return PTR_ERR(ENODEV);
+		}
+
+		val = di->bus.read(di, 0x34, false);
+		if ((val & 0xff00) != 0x2100) {
+			printk("rev. 14 chip not detected?!\n");
+			return PTR_ERR(EINVAL);
+		}
+		printk("verified chip rev. 14\n");
+	}
+
 	bq27xxx_battery_settings(di);
 	bq27xxx_battery_update(di);
 

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20171109/c8612126/attachment.sig>

  reply	other threads:[~2017-11-09 21:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-09 21:06 [PATCH] Add support for bq27521 battery monitor Pavel Machek
2017-11-09 21:29 ` Pali Rohár
2017-11-09 21:45   ` Pavel Machek [this message]
2017-11-09 21:52     ` Pali Rohár
2017-11-10 10:39 ` [PATCH v4.14] " Pavel Machek
2017-12-01 23:06   ` Pavel Machek
2017-12-04 15:20     ` Andrew F. Davis
2017-12-08 17:06       ` Sebastian Reichel
2017-12-13  8:39         ` Lithium battery protection was " Pavel Machek
2017-11-15 19:20 ` [PATCH] " Rob Herring

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=20171109214540.GB23376@amd \
    --to=pavel@ucw.cz \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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