linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Matt Ranostay <mranostay@ti.com>
Cc: michael@walle.cc, vigneshr@ti.com, robh@kernel.org,
	krzysztof.kozlowski@linaro.org, a.zummo@towertech.it,
	linus.walleij@linaro.org, lee@kernel.org, brgl@bgdev.pl,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	linux-gpio@vger.kernel.org, linux-rtc@vger.kernel.org,
	Keerthy <j-keerthy@ti.com>
Subject: Re: [PATCH v5 3/4] rtc: rtc-tps6594: Add support for TPS6594 PMIC RTC
Date: Sun, 11 Dec 2022 21:05:46 +0100	[thread overview]
Message-ID: <Y5Y4GlHc0aI6GG2g@mail.local> (raw)
In-Reply-To: <20221123053512.1195309-4-mranostay@ti.com>

Hello,

On 22/11/2022 21:35:11-0800, Matt Ranostay wrote:
> +static int tps6594_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> +	unsigned char rtc_data[TPS6594_NUM_TIME_REGS];
> +	struct tps6594 *tps6594 = dev_get_drvdata(dev->parent);
> +	unsigned int val;
> +	int ret;
> +
> +	rtc_data[0] = bin2bcd(tm->tm_sec);
> +	rtc_data[1] = bin2bcd(tm->tm_min);
> +	rtc_data[2] = bin2bcd(tm->tm_hour);
> +	rtc_data[3] = bin2bcd(tm->tm_mday);
> +	rtc_data[4] = bin2bcd(tm->tm_mon + 1);
> +	rtc_data[5] = bin2bcd(tm->tm_year - 100);
> +
> +	/* Stop RTC while updating the RTC time registers */
> +	ret = regmap_update_bits(tps6594->regmap, TPS6594_RTC_CTRL_1,
> +				 TPS6594_RTC_CTRL_REG_STOP_RTC, 0);
> +	if (ret < 0) {
> +		dev_err(dev, "RTC stop failed, err = %d\n", ret);

This function is way too verbose. There is no other action for the user
than retrying to set the time. You should probably remove all the
dev_err calls.

> +		return ret;
> +	}
> +
> +	/* Waiting till RTC isn't running */
> +	ret = regmap_read_poll_timeout(tps6594->regmap, TPS6594_RTC_STATUS,
> +				       val, !(val & TPS6594_RTC_STATUS_RUN),
> +				       TPS6594_RTC_POLL, TPS6594_RTC_TIMEOUT);
> +	if (ret) {
> +		dev_err(dev, "RTC_STATUS is still RUNNING\n");
> +		return ret;
> +	}
> +
> +	ret = regmap_bulk_write(tps6594->regmap, TPS6594_RTC_SECONDS,
> +		rtc_data, TPS6594_NUM_TIME_REGS);
> +	if (ret < 0) {
> +		dev_err(dev, "RTC_SECONDS reg write failed, err = %d\n", ret);
> +		return ret;
> +	}
> +
> +	/* Start back RTC */
> +	ret = regmap_update_bits(tps6594->regmap, TPS6594_RTC_CTRL_1,
> +				 TPS6594_RTC_CTRL_REG_STOP_RTC,
> +				 TPS6594_RTC_CTRL_REG_STOP_RTC);
> +	if (ret < 0)
> +		dev_err(dev, "RTC start failed, err = %d\n", ret);
> +
> +	return ret;
> +}
> +
> +static const struct rtc_class_ops tps6594_rtc_ops = {
> +	.read_time	= tps6594_rtc_read_time,
> +	.set_time	= tps6594_rtc_set_time,
> +};
> +
> +static int tps6594_rtc_probe(struct platform_device *pdev)
> +{
> +	struct tps6594_rtc *tps6594_rtc;
> +
> +	tps6594_rtc = devm_kzalloc(&pdev->dev, sizeof(*tps6594_rtc), GFP_KERNEL);
> +	if (!tps6594_rtc)
> +		return -ENOMEM;
> +
> +	tps6594_rtc->dev = &pdev->dev;
> +	platform_set_drvdata(pdev, tps6594_rtc);
> +
> +	tps6594_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
> +	if (IS_ERR(tps6594_rtc->rtc))
> +		return PTR_ERR(tps6594_rtc->rtc);
> +
> +	tps6594_rtc->rtc->ops = &tps6594_rtc_ops;
> +
> +	return devm_rtc_register_device(tps6594_rtc->rtc);
> +}
> +
> +static const struct of_device_id of_tps6594_rtc_match[] = {
> +	{ .compatible = "ti,tps6594-rtc", },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, of_tps6594_rtc_match);
> +
> +static struct platform_driver tps6594_rtc_driver = {
> +	.probe		= tps6594_rtc_probe,
> +	.driver		= {
> +		.name	= "tps6594-rtc",
> +		.of_match_table = of_tps6594_rtc_match,
> +	},
> +};
> +
> +module_platform_driver(tps6594_rtc_driver);
> +
> +MODULE_ALIAS("platform:tps6594-rtc");
> +MODULE_DESCRIPTION("TI TPS6594 series RTC driver");
> +MODULE_AUTHOR("Keerthy J <j-keerthy@ti.com>");
> +MODULE_LICENSE("GPL");
> -- 
> 2.38.GIT
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-12-11 20:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23  5:35 [PATCH v5 0/4] mfd: add tps6594 support for Jacinto platforms Matt Ranostay
2022-11-23  5:35 ` [PATCH v5 1/4] dt-bindings: mfd: ti,tps6594: add TPS6594 PMIC support Matt Ranostay
2022-11-23  7:08   ` Tony Lindgren
2022-11-24 14:05   ` Krzysztof Kozlowski
2022-11-30 20:42   ` Rob Herring
2022-11-23  5:35 ` [PATCH v5 2/4] mfd: tps6594: Add support for TPS6594 PMIC devices Matt Ranostay
2022-11-23  7:09   ` Tony Lindgren
2023-01-04 17:06   ` Lee Jones
2022-11-23  5:35 ` [PATCH v5 3/4] rtc: rtc-tps6594: Add support for TPS6594 PMIC RTC Matt Ranostay
2022-11-23  7:10   ` Tony Lindgren
2022-12-11 20:05   ` Alexandre Belloni [this message]
2022-11-23  5:35 ` [PATCH v5 4/4] gpio: gpio-tps6594: add GPIO support for TPS6594 PMIC Matt Ranostay
2022-11-23  7:11   ` Tony Lindgren
2022-11-23  8:40   ` Michael Walle
2022-12-01  9:10   ` Bartosz Golaszewski
2022-11-28 19:25 ` [PATCH v5 0/4] mfd: add tps6594 support for Jacinto platforms J, KEERTHY

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=Y5Y4GlHc0aI6GG2g@mail.local \
    --to=alexandre.belloni@bootlin.com \
    --cc=a.zummo@towertech.it \
    --cc=brgl@bgdev.pl \
    --cc=devicetree@vger.kernel.org \
    --cc=j-keerthy@ti.com \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=lee@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=michael@walle.cc \
    --cc=mranostay@ti.com \
    --cc=robh@kernel.org \
    --cc=vigneshr@ti.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).