linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Jeppe Ledet-Pedersen <jlp@gomspace.com>
Cc: lee.jones@linaro.org, arnd@arndb.de, gregkh@linuxfoundation.org,
	a.zummo@towertech.it, robh+dt@kernel.org, pawel.moll@arm.com,
	mark.rutland@arm.com, ijc+devicetree@hellion.org.uk,
	galak@codeaurora.org, rtc-linux@googlegroups.com,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] rtc: add Cypress FM33256B RTC driver
Date: Fri, 22 Apr 2016 01:44:00 +0200	[thread overview]
Message-ID: <20160421234400.GG29844@piout.net> (raw)
In-Reply-To: <1461150471-23163-4-git-send-email-jlp@gomspace.com>

Hi,

Looks mostly good, a few comments below

On 20/04/2016 at 13:07:51 +0200, Jeppe Ledet-Pedersen wrote :

Please always include a commit message.

> Signed-off-by: Jeppe Ledet-Pedersen <jlp@gomspace.com>
> ---

[...]

> +static int fm33256b_rtc_readtime(struct device *dev, struct rtc_time *tm)
> +{
> +	int ret;
> +	struct fm33256b_rtc *rtc = dev_get_drvdata(dev);
> +	uint8_t time[7];

Use u8 here

> +
> +	/* Lock time update */
> +	ret = regmap_update_bits(rtc->fm33256b->regmap_pc,
> +				 FM33256B_RTC_ALARM_CONTROL_REG,
> +				 FM33256B_R, FM33256B_R);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = regmap_bulk_read(rtc->fm33256b->regmap_pc,
> +			       FM33256B_SECONDS_REG, time, sizeof(time));
> +	if (ret < 0)
> +		return ret;
> +
> +	/* Unlock time update */
> +	ret = regmap_update_bits(rtc->fm33256b->regmap_pc,
> +				 FM33256B_RTC_ALARM_CONTROL_REG,
> +				 FM33256B_R, 0);
> +	if (ret < 0)
> +		return ret;
> +
> +	tm->tm_sec	= bcd2bin(time[0]);
> +	tm->tm_min	= bcd2bin(time[1]);
> +	tm->tm_hour	= bcd2bin(time[2]);
> +	tm->tm_wday	= bcd2bin(time[3]) - 1;
> +	tm->tm_mday	= bcd2bin(time[4]);
> +	tm->tm_mon	= bcd2bin(time[5]) - 1;
> +	tm->tm_year	= bcd2bin(time[6]);
> +
> +	if (tm->tm_year < 70)
> +		tm->tm_year += 100;
> +

I would advise against using that construct. It doesn't work well with
leap years and you probably don't care about dates before 2000.

> +	return rtc_valid_tm(tm);
> +}
> +
> +static int fm33256b_rtc_settime(struct device *dev, struct rtc_time *tm)
> +{
> +	int ret;
> +	struct fm33256b_rtc *rtc = dev_get_drvdata(dev);
> +	uint8_t time[7];
> +

u8

> +	time[0] = bin2bcd(tm->tm_sec);
> +	time[1] = bin2bcd(tm->tm_min);
> +	time[2] = bin2bcd(tm->tm_hour);
> +	time[3] = bin2bcd(tm->tm_wday + 1);
> +	time[4] = bin2bcd(tm->tm_mday);
> +	time[5] = bin2bcd(tm->tm_mon + 1);
> +	time[6] = bin2bcd(tm->tm_year % 100);
> +

I would also prefer that you explicitly enforce the range of supported
years and return -EINVAL for out of range values.

> +	/* Unlock time update */
> +	ret = regmap_update_bits(rtc->fm33256b->regmap_pc,
> +				 FM33256B_RTC_ALARM_CONTROL_REG,
> +				 FM33256B_W, FM33256B_W);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = regmap_bulk_write(rtc->fm33256b->regmap_pc,
> +				FM33256B_SECONDS_REG, time, sizeof(time));
> +	if (ret < 0)
> +		return ret;
> +
> +	/* Lock time update */
> +	ret = regmap_update_bits(rtc->fm33256b->regmap_pc,
> +				 FM33256B_RTC_ALARM_CONTROL_REG,
> +				 FM33256B_W, 0);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +static const struct rtc_class_ops fm33256b_rtc_ops = {
> +	.read_time	= fm33256b_rtc_readtime,
> +	.set_time	= fm33256b_rtc_settime,
> +};
> +
> +static int fm33256b_rtc_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct fm33256b *fm33256b;
> +	struct fm33256b_rtc *rtc;
> +
> +	fm33256b = dev_get_drvdata(dev->parent);
> +
> +	rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL);
> +	if (!rtc)
> +		return -ENOMEM;
> +
> +	platform_set_drvdata(pdev, rtc);
> +
> +	rtc->fm33256b = fm33256b;
> +	rtc->rtcdev = devm_rtc_device_register(&pdev->dev, KBUILD_MODNAME,
> +					       &fm33256b_rtc_ops, THIS_MODULE);
> +	if (IS_ERR(rtc->rtcdev))
> +		return PTR_ERR(rtc->rtcdev);
> +
> +	return 0;

You can use PTR_ERR_OR_ZERO


> +}
> +
> +static int fm33256b_rtc_remove(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct fm33256b *fm33256b;
> +	struct fm33256b_rtc *rtc = platform_get_drvdata(pdev);
> +
> +	fm33256b = dev_get_drvdata(dev->parent);
> +
> +	devm_rtc_device_unregister(&pdev->dev, rtc->rtcdev);
> +
> +	return 0;
> +}
> +

The whole fm33256b_rtc_remove() is unnecessary.


> +static const struct of_device_id fm33256b_rtc_dt_ids[] = {
> +	{ .compatible = "cypress,fm33256b-rtc" },
> +	{ /* sentinel */ },
> +};
> +MODULE_DEVICE_TABLE(of, fm33256b_rtc_dt_ids);
> +
> +static struct platform_driver fm33256b_rtc_driver = {
> +	.driver = {
> +		.name = "fm33256b-rtc",
> +		.of_match_table = fm33256b_rtc_dt_ids,
> +	},
> +	.probe = fm33256b_rtc_probe,
> +	.remove = fm33256b_rtc_remove,
> +};
> +module_platform_driver(fm33256b_rtc_driver);
> +
> +MODULE_ALIAS("platform:fm33256b-rtc");
> +MODULE_AUTHOR("Jeppe Ledet-Pedersen <jlp@gomspace.com>");
> +MODULE_DESCRIPTION("Cypress FM33256B Processor Companion RTC Driver");
> +MODULE_LICENSE("GPL v2");
> -- 
> 2.1.4
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

  reply	other threads:[~2016-04-21 23:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-20 11:07 [PATCH 0/3] Cypress FM33256B processor companion support Jeppe Ledet-Pedersen
2016-04-20 11:07 ` [PATCH 1/3] mfd: add Cypress FM33256B Processor Companion driver Jeppe Ledet-Pedersen
2016-04-22  0:47   ` kbuild test robot
2016-04-22 19:32   ` Rob Herring
2016-04-22 20:11     ` Alexandre Belloni
2016-04-26 14:31       ` Jeppe Ledet-Pedersen
2016-05-03  8:14         ` Alexandre Belloni
2016-04-26 14:42     ` Jeppe Ledet-Pedersen
2016-04-20 11:07 ` [PATCH 2/3] misc: eeprom: add Cypress FM33256B FRAM driver Jeppe Ledet-Pedersen
2016-04-21 23:54   ` Alexandre Belloni
2016-04-26 12:08     ` Jeppe Ledet-Pedersen
2016-04-20 11:07 ` [PATCH 3/3] rtc: add Cypress FM33256B RTC driver Jeppe Ledet-Pedersen
2016-04-21 23:44   ` Alexandre Belloni [this message]
2016-04-26 12:17     ` Jeppe Ledet-Pedersen

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=20160421234400.GG29844@piout.net \
    --to=alexandre.belloni@free-electrons.com \
    --cc=a.zummo@towertech.it \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=jlp@gomspace.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=rtc-linux@googlegroups.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).