lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20121127133614.c8ff3be2.akpm@linux-foundation.org>
Date:	Tue, 27 Nov 2012 13:36:14 -0800
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Thierry Reding <thierry.reding@...onic-design.de>
Cc:	Alessandro Zummo <a.zummo@...ertech.it>,
	rtc-linux@...glegroups.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH RESEND] rtc: Add NXP PCF8523 support

On Fri, 23 Nov 2012 16:17:37 +0100
Thierry Reding <thierry.reding@...onic-design.de> wrote:

> This commit adds an RTC driver for PCF8523 chips by NXP Semiconductors.
> No support is currently provided for the alarm and interrupt functions.
> Only the time and date functionality is implemented.
> 
> ...
>
> +static int pcf8523_rtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	u8 start = REG_SECONDS, regs[7];
> +	struct i2c_msg msgs[2];
> +	int err;
> +
> +	msgs[0].addr = client->addr;
> +	msgs[0].flags = 0;
> +	msgs[0].len = 1;
> +	msgs[0].buf = &start;
> +
> +	msgs[1].addr = client->addr;
> +	msgs[1].flags = I2C_M_RD;
> +	msgs[1].len = sizeof(regs);
> +	msgs[1].buf = regs;
> +
> +	err = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
> +	if (err < 0)
> +		return err;
> +
> +	if (regs[0] & REG_SECONDS_OS) {
> +		dev_dbg(dev, "clock integrity is not guaranteed\n");
> +
> +		/* try to clear the flag */

The comment explains the "what", which was pretty obvious from the code.

But readers want to know "why".

> +		regs[0] &= ~REG_SECONDS_OS;
> +
> +		err = pcf8523_write(client, REG_SECONDS, regs[0]);
> +		if (err < 0)
> +			return err;
> +	}
> +
> +	tm->tm_sec = bcd2bin(regs[0] & 0x7f);
> +	tm->tm_min = bcd2bin(regs[1] & 0x7f);
> +	tm->tm_hour = bcd2bin(regs[2] & 0x3f);
> +	tm->tm_mday = bcd2bin(regs[3] & 0x3f);
> +	tm->tm_wday = regs[4] & 0x7;
> +	tm->tm_mon = bcd2bin(regs[5] & 0x1f);
> +	tm->tm_year = bcd2bin(regs[6]) + 100;
> +
> +	return rtc_valid_tm(tm);
> +}
> +
> +static int pcf8523_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct i2c_msg msg;
> +	u8 regs[8];
> +	int err;
> +
> +	err = pcf8523_stop_rtc(client);
> +	if (err < 0)
> +		return err;
> +
> +	regs[0] = REG_SECONDS;
> +	regs[1] = bin2bcd(tm->tm_sec);
> +	regs[2] = bin2bcd(tm->tm_min);
> +	regs[3] = bin2bcd(tm->tm_hour);
> +	regs[4] = bin2bcd(tm->tm_mday);
> +	regs[5] = tm->tm_wday;
> +	regs[6] = bin2bcd(tm->tm_mon);
> +	regs[7] = bin2bcd(tm->tm_year - 100);
> +
> +	msg.addr = client->addr;
> +	msg.flags = 0;
> +	msg.len = sizeof(regs);
> +	msg.buf = regs;
> +
> +	err = i2c_transfer(client->adapter, &msg, 1);
> +	if (err < 0)
> +		return err;

Should we restart the rtc if the transfer failed?

> +	return pcf8523_start_rtc(client);
> +}
> 
> ...
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ