public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ladislav Michl <ladis@linux-mips.org>
To: Jean Delvare <khali@linux-fr.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	LM Sensors <sensors@Stimpy.netroedge.com>,
	James Chapman <jchapman@katalix.com>, Greg KH <greg@kroah.com>
Subject: Re: [PATCH] ds1337 4/4
Date: Fri, 8 Apr 2005 14:35:45 +0200	[thread overview]
Message-ID: <20050408123545.GA4961@orphique> (raw)
In-Reply-To: <FxPJVIPZ.1112958526.4787880.khali@localhost>

On Fri, Apr 08, 2005 at 01:08:46PM +0200, Jean Delvare wrote:
> > Add support for DS1339. The only difference against DS1337 is Trickle
> > Charge register at address 10h, which is used to enable battery or gold
> > cap charging. Please note that value may vary for different batteries,
> > so it should be made module parameter. 0xaa is sane default and also
> > matches my board ;-)
> 
> "Sane default" is a non-sense here. A sane default is that loading a
> real-time clock driver should not affect the battery at all IMHO.
>
> Can you tell us more on that battery thing? I admit I don't exatcly get
> what it is. Which type of battery are we talking about? Are there
> similar drivers in the kernel tree already?

Sorry, I have no clue what devices are using it and what may come to
board designer's mind. This chip will be most likely used in embedded,
where every sane developer is expected to review drivers he is using.
Also in such situation driver is compiled staticaly. (And in ideal world
firmware (such as U-Boot, RedBoot, etc.) should set this register).

> Sounds weird to me that loading a driver would enable charging of a
> battery, and removing it wouldn't disable it. And since the driver
> might not be removed, it would possibly make more sense to have an entry
> in /sys to enable and disable this thing.

Disabling battery charge makes no sense. The only reason I can think
about is when suspending device, so it is likely pm job. /sys entry
might help as well, but I do not see any point making driver more
complicated and bigger just to make someone else happy.

Golden rule is: implement features as needed :)

> Also, arbitrarily picking one of the 6 possible charging modes just
> because it matches your board is a bad idea. It looks like a value which
> should be set on a per-board basis, rather than picked randomly by the
> user, so as to avoid accidental hardware breakage.

Well free to provide that way, so far I'm the only user so I did what is
usefull for me [*]. Everyone is welcome to change it to more generic
way.

> > +static int ds1339_charge = 0xaa;
> 
> I see little reason why this would be a global variable rather than a
> define (let alone the fact that this shouldn't be hardcoded at all
> IMHO, as I just explained).

[*] This way it can be easily turned into module parameter or whatever
someone who will need different value may want to do.

Lets choose define, later it can be converted to module parameter.
Gcc is smart enough to optimize charge enable code away.
#define ds1339_charge	0

> > +/*
> > + * DS1339 has Trickle Charge register at address 10h. During a multibyte
> > + * access, when the address pointer reaches the end of the register space,
> > + * it wraps around to location 00h.
> > + * We read 17 bytes from device and compare first and last one. If they
> > + * are same it is most likely DS1337 chip.
> > + */
> > +static int ds1337_is_ds1339(struct i2c_client *client)
> > +{
> > +	char buf[17], addr = 0;
> > +	struct i2c_msg msg[2];
> > +	int result;
> > +
> > +	msg[0].addr = client->addr;
> > +	msg[0].flags = 0;
> > +	msg[0].len = 1;
> > +	msg[0].buf = &addr;
> > +
> > +	msg[1].addr = client->addr;
> > +	msg[1].flags = I2C_M_RD;
> > +	msg[1].len = sizeof(buf);
> > +	msg[1].buf = buf;
> > +
> > +	result = i2c_transfer(client->adapter, msg, 2);
> > +	if (result < 0) {
> > +		dev_err(&client->dev, "error reading data! %d\n", result);
> > +		return 0;
> > +	} else
> > +		return (buf[0] == buf[16]) ? 0 : 1;
> > +}
> 
> This will fail eventually. The first register is the seconds count, which
> by definition is changing. I2C is slow, by the time you wrap over the
> register range, the value could have changed. The datasheet explicitely
> says that the register cache will refresh on address wrapping.

I was running test overnight and didn't meet any single case when this
happen. Perhaps device also needs to see start condition?

> Also, 0x00 is a possible value for both the seconds count and the battery
> register, so you could miss a DS1339 at times.
> 
> One possible check to start with would be on the value of the additional
> register itself. It has only 7 possible values. (...) 

Eh? Register is 8bit, that's 256 combinations.

> (...) But of course it would be better if we could default to a DS1337
> and find a way to identify the DS1339, rather than the (unsafe) other
> way around. I also don't know what a DS1337 will answer for this
> missing register. Maybe James can help?
>
> One possibility would be to start reading at 0x0E instead of 0x00,
> because register 0x00 is the control register and is the only one which
> will not change in our back as far as I can see. Oh, and the additional
> battery register too. But this still doesn't sound like a bulletproof
> method to me (we depend on the seconds and possibly minutes count
> again). So it would be better to additionally perform the same tests
> that were done on the non-wrapped registers for the regular DS1337
> detection, but on the wrapped area.
> 
> The problem here is that all this will significantly increase the
> detection delay.

That's probably overkill, see above.

Look, the only difference between ds1339 and ds1337 is Trickle Charge
register. We won't touch it by default and if anyone wants to use it, he
need to provide its value. In that case he also knows it is DS1339 and
also knows what battery is wired, so he knows charging current.

I hope it is also clear that without picking one "sane default" there is
no point to do any detection at all.

> Yet another method would be to write a non-significant value to the
> battery register, such as 0x80. If we can read it back then it has to be
> a DS1339. But what effect will it have on the DS1337? I'd hope none,
> but this better be verified. And in general I don't much like using
> register writes in detection methods.

You will change register 00h.

> Could you please provide the output of i2cdump in b and c modes for your
> DS1339 chip? This might help finding an detection method. A similar dump
> for the DS1337 would help too.

Sorry it seems there is no easy way to cross-compile this package. I
have admit I haven't tried too hard.

> > -	const char *name = "";
> > +	const char *name;
> (...)
> > +	default:
> > +		name = "";
> > +	}
> 
> This is noise.

No it is not. Look at generated machine code for each case and try to do
it for at least two architectures different from i386 ;-) I'm bored with
arguing about such changes, do what you think is right, but it will
remain in patch. The rest is up to you.

Also note that this very way of rejecting tiny cleanups leads to hardly
readable and unoptimized code and after some greater amount of time code
rewrite occurs anyway (once someone is sufficienly upset).

Have a nice weekend,
	ladis

  reply	other threads:[~2005-04-08 12:36 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-31 23:22 [BK PATCH] I2C patches for 2.6.12-rc1 Greg KH
2005-03-31 23:23 ` [PATCH] i2c/i2c-ite: remove interruptible_sleep_on_timeout() usage Greg KH
2005-03-31 23:23   ` [PATCH] i2c/i2c-elektor: " Greg KH
2005-03-31 23:23     ` [PATCH] I2C: New lm92 chip driver Greg KH
2005-03-31 23:23       ` [PATCH] I2C: Cleanup adm1021 unused defines Greg KH
2005-03-31 23:23         ` [PATCH] I2C: Fix adm1021 alarms mask Greg KH
2005-03-31 23:23           ` [PATCH] I2C: Kill unused struct members in w83627hf driver Greg KH
2005-03-31 23:23             ` [PATCH] I2C: Make master_xfer debug messages more useful Greg KH
2005-03-31 23:23               ` [PATCH] I2C: Skip broken detection step in it87 Greg KH
2005-03-31 23:23                 ` [PATCH] I2C: group Intel on I2C Hardware Bus support Greg KH
2005-03-31 23:23                   ` [PATCH] i2c: new driver for ds1337 RTC Greg KH
2005-03-31 23:23                     ` [PATCH] i2c: add adt7461 chip support to lm90 driver Greg KH
2005-03-31 23:23                       ` [PATCH] I2C: Clean up of i2c-elektor.c build Greg KH
2005-03-31 23:23                         ` [PATCH] I2C: Fix breakage in m41t00 i2c rtc driver Greg KH
2005-03-31 23:23                           ` [PATCH] I2C: Fix some i2c algorithm initialization Greg KH
2005-03-31 23:23                             ` [PATCH] I2C: Kill outdated defines in i2c.h Greg KH
2005-03-31 23:23                               ` [PATCH] I2C: Avoid repeated resets of i2c-viapro Greg KH
2005-03-31 23:23                                 ` [PATCH] I2C: Recognize new revision of the ADT7463 chip Greg KH
2005-03-31 23:23                                   ` [PATCH] I2C: Fix Vaio EEPROM detection Greg KH
2005-03-31 23:23                                     ` [PATCH] I2C: busses documentation update 1 of 2 Greg KH
2005-03-31 23:23                                       ` [PATCH] I2C: busses documentation update 2 " Greg KH
2005-03-31 23:23                                         ` [PATCH] I2C: lost arbitration detection for PCF8584 Greg KH
2005-03-31 23:23                                           ` [PATCH] I2C: lsb in emc6d102 and adm1027 Greg KH
2005-03-31 23:23                                             ` [PATCH] I2C: Delete useless instruction in it87 Greg KH
2005-03-31 23:23                                               ` [PATCH] I2C: Fix race condition in it87 driver Greg KH
2005-03-31 23:23                                                 ` [PATCH] I2C: i2c-s3c2410 functionality and fixes Greg KH
2005-03-31 23:23                                                   ` [PATCH] i2c: add adt7461 chip support to lm90 driver's Kconfig entry Greg KH
2005-03-31 23:23                                                     ` [PATCH] I2C: Fix broken force parameter handling Greg KH
2005-03-31 23:23                                                       ` [PATCH] I2C: Fix indentation of lm87 driver Greg KH
2005-03-31 23:23                                                         ` [PATCH] I2C: Drop useless w83781d RT feature Greg KH
2005-03-31 23:23                                                           ` [PATCH] i2c: i2c-mv64xxx - set adapter owner and class fields Greg KH
2005-04-07  9:45                     ` [PATCH] i2c: new driver for ds1337 RTC Ladislav Michl
2005-04-07  9:59                       ` Jean Delvare
2005-04-07 11:16                         ` Ladislav Michl
2005-04-07 13:07                           ` Jean Delvare
2005-04-07 14:28                             ` Ladislav Michl
2005-04-07 21:18                               ` Greg KH
2005-04-07 23:17                                 ` [PATCH] ds1337 1/4 Ladislav Michl
2005-04-07 23:36                                   ` Greg KH
2005-04-08 13:00                                     ` Ladislav Michl
2005-04-08 16:31                                       ` James Chapman
2005-05-02 20:41                                       ` Greg KH
2005-04-08  8:49                                   ` Jean Delvare
2005-04-07 23:18                                 ` [PATCH] ds1337 2/4 Ladislav Michl
2005-04-08  8:51                                   ` Jean Delvare
2005-04-08 13:02                                     ` Ladislav Michl
2005-05-02 20:41                                       ` Greg KH
2005-04-07 23:18                                 ` [PATCH] ds1337 3/4 Ladislav Michl
2005-04-08 10:08                                   ` Jean Delvare
2005-04-08 13:06                                     ` Ladislav Michl
2005-05-02 20:41                                       ` Greg KH
2005-05-04  6:13                                         ` [PATCH] ds1337 1/3 Ladislav Michl
2005-05-04  8:41                                           ` Jean Delvare
2005-05-04  6:13                                         ` [PATCH] ds1337 2/3 Ladislav Michl
2005-05-04  9:44                                           ` Jean Delvare
2005-05-04  6:14                                         ` [PATCH] ds1337 3/3 Ladislav Michl
2005-05-04 10:07                                           ` Jean Delvare
2005-05-10 12:08                                             ` [PATCH] ds1337 driver works also with ds1339 chip Ladislav Michl
2005-05-10 12:40                                               ` Jean Delvare
2005-05-10 12:48                                               ` Russell King
     [not found]                                           ` <1DTwF8-18P-00@press.kroah.org>
     [not found]                                             ` <20050508204021.627f9cd1.khali@linux-fr.org>
     [not found]                                               ` <427E6E21.60001@katalix.com>
     [not found]                                                 ` <20050508222351.08bfe2e1.khali@linux-fr.org>
2005-05-10 12:18                                                   ` [PATCH] ds1337: export ds1337_do_command Ladislav Michl
2005-05-10 12:51                                                     ` Jean Delvare
2005-05-10 17:55                                                     ` Greg KH
2005-05-10 18:36                                                       ` Ladislav Michl
2005-05-10 20:30                                                         ` Greg KH
2005-05-11  8:32                                                       ` Ladislav Michl
2005-04-07 23:19                                 ` [PATCH] ds1337 4/4 Ladislav Michl
2005-04-08 11:08                                   ` Jean Delvare
2005-04-08 12:35                                     ` Ladislav Michl [this message]
2005-04-08 16:21                                       ` Jean Delvare
2005-04-08 17:44                                       ` James Chapman
2005-04-10 19:51                                         ` Ladislav Michl
2005-04-10 21:10                                           ` Jean Delvare
2005-04-12 18:10                                             ` James Chapman
2005-04-13 11:04                                               ` Ladislav Michl
2005-04-13 19:02                                                 ` James Chapman
2005-04-13 19:48                                                   ` Ladislav Michl
2005-04-07 21:29                               ` [PATCH] i2c: new driver for ds1337 RTC Jean Delvare
2005-04-07 23:16                                 ` Ladislav Michl

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=20050408123545.GA4961@orphique \
    --to=ladis@linux-mips.org \
    --cc=greg@kroah.com \
    --cc=jchapman@katalix.com \
    --cc=khali@linux-fr.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sensors@Stimpy.netroedge.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