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] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 2 Nov 2023 17:57:13 +0100
From:   Alexandre Belloni <alexandre.belloni@...tlin.com>
To:     "Miclaus, Antoniu" <Antoniu.Miclaus@...log.com>
Cc:     Alessandro Zummo <a.zummo@...ertech.it>,
        Rob Herring <robh+dt@...nel.org>,
        Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
        Conor Dooley <conor+dt@...nel.org>,
        Jean Delvare <jdelvare@...e.com>,
        Guenter Roeck <linux@...ck-us.net>,
        "linux-rtc@...r.kernel.org" <linux-rtc@...r.kernel.org>,
        "devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "linux-hwmon@...r.kernel.org" <linux-hwmon@...r.kernel.org>
Subject: Re: [PATCH v4 2/2] rtc: max31335: add driver support

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ