Re: [PATCH v5 4/4] rtc: ds1307: add frequency_test_enable sysfs attribute to check tick on m41txx

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Il 16/05/2018 22:22, Andy Shevchenko ha scritto:
On Wed, May 16, 2018 at 1:32 PM, Giulio Benetti
<giulio.benetti@xxxxxxxxxxxxxxxx> wrote:
On m41txx you can enable open-drain OUT pin to check if offset is ok.
Enabling OUT pin with frequency_test_enable attribute, OUT pin will tick
512 times faster than 1s tick base.

Enable or Disable FT bit on CONTROL register if freq_test is 1 or 0.

Signed-off-by: Giulio Benetti <giulio.benetti@xxxxxxxxxxxxxxxx>

+static ssize_t frequency_test_enable_store(struct device *dev,
+                                          struct device_attribute *attr,
+                                          const char *buf, size_t count)
+{
+       struct ds1307 *ds1307 = dev_get_drvdata(dev);
+       unsigned long freq_test = 0;
+       int retval;
+
+       retval = kstrtoul(buf, 10, &freq_test);
+       if ((retval < 0) || (retval > 1)) {

kstrtobool() then?

Yes, you're right.


+               dev_err(dev, "Failed to store RTC Frequency Test attribute\n");

+               return -EINVAL;

...and do not shadow actual error code.

Ok


+       }
+
+       regmap_update_bits(ds1307->regmap, M41TXX_REG_CONTROL, M41TXX_BIT_FT,
+                          freq_test ? M41TXX_BIT_FT : 0);
+

+       return retval ? retval : count;

Does the condition make any sense?

You're right, not at all.
I changed it into:
"return count;"


+}

+static ssize_t frequency_test_enable_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{

+       int freq_test_en = 0;

+       if (ctrl_reg & M41TXX_BIT_FT)
+               freq_test_en = true;
+       else
+               freq_test_en = false;
+
+       return sprintf(buf, "%d\n", freq_test_en);

So, is it boolean or integer? This code makes it confusing a lot.

It is a boolean, so now I've updated with this:

if (ctrl_reg & M41TXX_BIT_FT)
	return scnprintf(buf, PAGE_SIZE, "on\n");
else
	return scnprintf(buf, PAGE_SIZE, "off\n");


+}


Thank you very much for review

Giulio Benetti
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux