devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: "Miclaus, Antoniu" <Antoniu.Miclaus@analog.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	"linux-rtc@vger.kernel.org" <linux-rtc@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>
Subject: Re: [PATCH v4 2/2] rtc: max31335: add driver support
Date: Thu, 2 Nov 2023 17:57:13 +0100	[thread overview]
Message-ID: <20231102165713296ca50b@mail.local> (raw)
In-Reply-To: <CY4PR03MB3399BAAA3A3F6FC4B9A7A9FB9BA6A@CY4PR03MB3399.namprd03.prod.outlook.com>

On 02/11/2023 13:44:16+0000, Miclaus, Antoniu wrote:
>  
> > On 01/11/2023 11:48:14+0200, Antoniu Miclaus wrote:
> > > +static int max31335_get_hour(u8 hour_reg)
> > > +{
> > > +	int hour;
> > > +
> > > +	/* 24Hr mode */
> > > +	if (!FIELD_GET(MAX31335_HOURS_F_24_12, hour_reg))
> > > +		return bcd2bin(hour_reg & 0x3f);
> > > +
> > > +	/* 12Hr mode */
> > > +	hour = bcd2bin(hour_reg & 0x1f);
> > > +	if (hour == 12)
> > > +		hour = 0;
> > > +
> > 
> > Do you really need to support 12h mode?
> 
> Is is a feature supported by the part, so I think is nice to have.
> 

Is anything on the system going to use it? This driver is not setting
12h time so if there is no other component in the system accessing the
time, there is no chance this is going to be used. Dead code is not nice
to maintain.

> > 
> > > +	if (FIELD_GET(MAX31335_HOURS_HR_20_AM_PM, hour_reg))
> > > +		hour += 12;
> > > +
> > > +	return hour;
> > > +}
> > > +
> > > +static int max31335_read_offset(struct device *dev, long *offset)
> > > +{
> > > +	struct max31335_data *max31335 = dev_get_drvdata(dev);
> > > +	u32 value;
> > > +	int ret;
> > > +
> > > +	ret = regmap_read(max31335->regmap, MAX31335_AGING_OFFSET,
> > &value);
> > > +	if (ret)
> > > +		return ret;
> > > +
> > > +	*offset = value;
> > 
> > This is super dubious, what is the unit of MAX31335_AGING_OFFSET ?
> > 
> 
> There is not additional information on the AGING_OFFSET register (no
> other offset registers).
> I treated it as a raw value that user can write/read. Should I drop the 
> offset implementation?
> 

The value exposed to userspace is in parts per billion. If you can't do
the conversion, then you have to drop it.

> > > +
> > > +		return 0;
> > > +	}
> > > +
> > > +	if (diode)
> > > +		i = i + 4;
> > > +	else
> > > +		i = i + 1;
> > 
> > Do you actually need to configure the trickle charger when there is
> > nothing to charge?
> 
> These are the options for the trickle chager:
> MAX31335_TRICKLE_REG_TRICKLE bits
> 
> 0x0: 3KΩ in series with a Schottky diode
> 0x1: 3KΩ in series with a Schottky diode
> 0x2: 6KΩ in series with a Schottky diode 
> 0x3: 11KΩ in series with a Schottky diode
> 0x4: 3KΩ in series with a diode+Schottky diode
> 0x5: 3KΩ in series with a diode+Schottky diode
> 0x6: 6KΩ in series with a diode+Schottky diode
> 0x7: 11KΩ in series with a diode+Schottky diode
> 

Then you need a property to select with diodes you are going to use. The
ABX80X supports something similar.

> > 
> > > +
> > > +	return regmap_write(max31335->regmap, MAX31335_TRICKLE_REG,
> > > +			    FIELD_PREP(MAX31335_TRICKLE_REG_TRICKLE, i) |
> > > +				       MAX31335_TRICKLE_REG_EN_TRICKLE);
> > > +}
> > > +
> > > +static int max31335_clkout_register(struct device *dev)
> > > +{
> > > +	struct max31335_data *max31335 = dev_get_drvdata(dev);
> > > +	int ret;
> > > +
> > > +	if (!device_property_present(dev, "#clock-cells"))
> > > +		return 0;
> > 
> > Is the clock output disabled by default?
> 
> No, I will disable it.

The CCF is responsible to disable the clock, else you will have a glitch
in the clock at boot time which will break use cases. But for this to
work, you will have to always register the clock.

> 
> > 
> > > +
> > > +static int max31335_probe(struct i2c_client *client)
> > > +{
> > > +	struct max31335_data *max31335;
> > > +	struct device *hwmon;
> > > +	int ret;
> > > +
> > > +	max31335 = devm_kzalloc(&client->dev, sizeof(*max31335),
> > GFP_KERNEL);
> > > +	if (!max31335)
> > > +		return -ENOMEM;
> > > +
> > > +	max31335->regmap = devm_regmap_init_i2c(client,
> > &regmap_config);
> > > +	if (IS_ERR(max31335->regmap))
> > > +		return PTR_ERR(max31335->regmap);
> > > +
> > > +	i2c_set_clientdata(client, max31335);
> > > +
> > > +	ret = regmap_write(max31335->regmap, MAX31335_RTC_RESET, 1);
> > > +	if (ret)
> > > +		return ret;
> > > +
> > > +	ret = regmap_write(max31335->regmap, MAX31335_RTC_RESET, 0);
> > > +	if (ret)
> > > +		return ret;
> > 
> > What does this register do?
> > 
> 
> RTC Software Reset Register: 
> 0x0: Device is in normal mode.
> 0x1: Resets the digital block and the I2C programmable registers except for
> Timestamp/RAM registers and the SWRST bit. Oscillator is disabled.
> 
> The bit doesn't clear itself.
> 

Then you definitively don't want to do this, this will invalidate time
and date as the oscillator is disabled and this renders the RTC useless.
The whole point of the RTC is that it survives the reboot or shutdown of
the system.


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

  reply	other threads:[~2023-11-02 16:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-01  9:48 [PATCH v4 1/2] dt-bindings: rtc: max31335: add max31335 bindings Antoniu Miclaus
2023-11-01  9:48 ` [PATCH v4 2/2] rtc: max31335: add driver support Antoniu Miclaus
2023-11-01 14:21   ` Guenter Roeck
2023-11-01 15:21     ` Miclaus, Antoniu
2023-11-01 15:30       ` Guenter Roeck
2023-11-01 22:23   ` Alexandre Belloni
2023-11-02 13:44     ` Miclaus, Antoniu
2023-11-02 16:57       ` Alexandre Belloni [this message]
2023-11-02 17:17         ` Guenter Roeck
2023-11-01 15:11 ` [PATCH v4 1/2] dt-bindings: rtc: max31335: add max31335 bindings Krzysztof Kozlowski

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=20231102165713296ca50b@mail.local \
    --to=alexandre.belloni@bootlin.com \
    --cc=Antoniu.Miclaus@analog.com \
    --cc=a.zummo@towertech.it \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=robh+dt@kernel.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;
as well as URLs for NNTP newsgroup(s).