dt-bindings: rtc: zynqmp: Add clock information
Subsystems (3)
PATCH v8 1/3 dt-bindings: rtc: zynqmp: Add clock information
Added clock information and deprecated calibration support.
---
Changes in V8:
-None
Changes in V7:
-None
Changes in V6:
-Removed dtc warnings.
Changes in V5:
-Removed quotes and _clk suffix from clocknames.
Changes in V4:
- Deprecated calibrtion support
Changes in V3:
- New patch
--- .../devicetree/bindings/rtc/xlnx,zynqmp-rtc.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/rtc/xlnx,zynqmp-rtc.yaml +11 -1
@@ -23,8 +23,15 @@ properties: reg: maxItems: 1 + clocks: + items: + - description: rtc_clk is the operating frequency of crystal. + + clock-names: + maxItems: 1 + interrupts: - minItems: 2 + maxItems: 2 interrupt-names: items:
@@ -39,6 +46,7 @@ properties: minimum: 0x1 maximum: 0x1FFFFF default: 0x198233 + deprecated: true required: - compatible
@@ -61,5 +69,7 @@ examples: interrupts = <0 26 4>, <0 27 4>; interrupt-names = "alarm", "sec"; calibration = <0x198233>; + clock-names = "rtc_clk"; + clocks = <&rtc_clk>; }; };
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v8 2/3 rtc: zynqmp: Updated calibration value
As per RTC spec default calibration value is 0x7FFF.
---
Changes in V8
-None, just swapped 2/3 and 3/3 patches from V7. Changes in V7:
-New patch
-TRM not updated yet, Internal design document contains 0x7FFF as
default value. TRM Will update in next release.
--- drivers/rtc/rtc-zynqmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-zynqmp.c +1 -1
@@ -36,7 +36,7 @@#define RTC_OSC_EN BIT(24)#define RTC_BATT_EN BIT(31) -#define RTC_CALIB_DEF 0x198233 +#define RTC_CALIB_DEF 0x7FFF#define RTC_CALIB_MASK 0x1FFFFF#define RTC_ALRM_MASK BIT(1)#define RTC_MSEC 1000
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH V8 2/3] rtc: zynqmp: Updated calibration value
Review
Quoted 12 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Srinivas" == Srinivas Neeli <[email protected]> writes:
As per RTC spec default calibration value is
0x7FFF.Signed-off-by Srinivas Neeli <[email protected]>---
Changes in V8
-None, just swapped 2/3 and 3/3 patches from V7.
Changes in V7:(quoted diff) +0
-2-New patch -TRM not updated yet, Internal design document contains 0x7FFF as default value. TRM Will update in next release.
Maybe add this to the commit message so it is clear where this comes from. If possible specific the TRM version number that will contain the fix.
Other than that:
Signature · 1 line
Bye, Peter Korsgaard
PATCH v8 3/3 rtc: zynqmp: Add calibration set and get support
In reply to Srinivas NeeliZynqmp RTC controller has a calibration feature to compensate time deviation due to input clock inaccuracy.
Set and get calibration API's are used for setting and getting calibration value from the controller calibration register.
---
Changes in V7:
-Removed calibration default value update from this patch. Changes in V6:
-None
Changes in V5:
-None
Changes in V4:
-Updated MIN and MAX calibration values.
Changes in V3:
-Calculated tick_mult using crystal frequency.
-Calibration register updating based on crystal frequency in probe. -Supressed MIN an MAX calibration values,Will send separate patch in future. Changes in V2:
-Removed unused macro.
-Updated code with review comments.
--- drivers/rtc/rtc-zynqmp.c | 113 ++++++++++++++++++++++++++++++++------- 1 file changed, 94 insertions(+), 19 deletions(-)
drivers/rtc/rtc-zynqmp.c +94 -19
@@ -6,6 +6,7 @@* */ +#include <linux/clk.h> #include <linux/delay.h> #include <linux/init.h> #include <linux/io.h>
@@ -40,13 +41,19 @@#define RTC_CALIB_MASK 0x1FFFFF#define RTC_ALRM_MASK BIT(1)#define RTC_MSEC 1000 +#define RTC_FR_MASK 0xF0000 +#define RTC_FR_MAX_TICKS 16 +#define RTC_PPB 1000000000LL +#define RTC_MIN_OFFSET -32768000 +#define RTC_MAX_OFFSET 32767000struct xlnx_rtc_dev {struct rtc_device *rtc;void __iomem *reg_base;int alarm_irq;int sec_irq; -unsigned int calibval; +struct clk *rtc_clk; +unsigned int freq; };static int xlnx_rtc_set_time (struct device *dev,struct rtc_time *tm)
@@ -61,13 +68,6 @@ static int xlnx_rtc_set_time(struct device *dev, struct rtc_time *tm)*/ new_time =rtc_tm_to_time64 (tm) +1 ; -/* -* Writing into calibration register will clear the Tick Counter and -* force the next second to be signaled exactly in 1 second period -*/ - xrtcdev->calibval &=RTC_CALIB_MASK ; -writel (xrtcdev->calibval, (xrtcdev->reg_base +RTC_CALIB_WR )); -writel (new_time, xrtcdev->reg_base +RTC_SET_TM_WR );/*
@@ -173,15 +173,76 @@ static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev) rtc_ctrl =readl (xrtcdev->reg_base +RTC_CTRL ); rtc_ctrl |=RTC_BATT_EN ;writel (rtc_ctrl, xrtcdev->reg_base +RTC_CTRL ); +} -/* -* Based on crystal freq of 33.330 KHz -* set the seconds counter and enable, set fractions counter -* to default value suggested as per design spec -* to correct RTC delay in frequency over period of time. +static int xlnx_rtc_read_offset (struct device *dev,long *offset) +{ +struct xlnx_rtc_dev *xrtcdev =dev_get_drvdata (dev); +unsigned long long rtc_ppb =RTC_PPB ; +unsigned int tick_mult =do_div (rtc_ppb, xrtcdev->freq); +unsigned int calibval; +long offset_val; + + calibval =readl (xrtcdev->reg_base +RTC_CALIB_RD ); +/* Offset with seconds ticks */ + offset_val = calibval &RTC_TICK_MASK ; + offset_val = offset_val -RTC_CALIB_DEF ; + offset_val = offset_val * tick_mult; + +/* Offset with fractional ticks */ +if (calibval &RTC_FR_EN ) + offset_val += ((calibval &RTC_FR_MASK ) >>RTC_FR_DATSHIFT ) + * (tick_mult /RTC_FR_MAX_TICKS ); + *offset = offset_val; + +return 0 ; +} + +static int xlnx_rtc_set_offset (struct device *dev,long offset) +{ +struct xlnx_rtc_dev *xrtcdev =dev_get_drvdata (dev); +unsigned long long rtc_ppb =RTC_PPB ; +unsigned int tick_mult =do_div (rtc_ppb, xrtcdev->freq); +unsigned char fract_tick; +unsigned int calibval; +short int max_tick; +int fract_offset; + +if (offset <RTC_MIN_OFFSET || offset >RTC_MAX_OFFSET ) +return -ERANGE ; + +/* Number ticks for given offset */ + max_tick =div_s64_rem (offset, tick_mult, &fract_offset); + +/* Number fractional ticks for given offset */ +if (fract_offset) { +if (fract_offset <0 ) { + fract_offset = fract_offset + tick_mult; + max_tick--; + } +if (fract_offset > (tick_mult /RTC_FR_MAX_TICKS )) { +for (fract_tick =1 ; fract_tick <16 ; fract_tick++) { +if (fract_offset <= + (fract_tick * + (tick_mult /RTC_FR_MAX_TICKS ))) +break ; + } + } + } + +/* Zynqmp RTC uses second and fractional tick +* counters for compensation */ - xrtcdev->calibval &=RTC_CALIB_MASK ; -writel (xrtcdev->calibval, (xrtcdev->reg_base +RTC_CALIB_WR )); + calibval = max_tick +RTC_CALIB_DEF ; + +if (fract_tick) + calibval |=RTC_FR_EN ; + + calibval |= (fract_tick <<RTC_FR_DATSHIFT ); + +writel (calibval, (xrtcdev->reg_base +RTC_CALIB_WR )); + +return 0 ; }static const struct rtc_class_ops xlnx_rtc_ops = {
@@ -190,6 +251,8 @@ static const struct rtc_class_ops xlnx_rtc_ops = { .read_alarm = xlnx_rtc_read_alarm, .set_alarm = xlnx_rtc_set_alarm, .alarm_irq_enable = xlnx_rtc_alarm_irq_enable, + .read_offset = xlnx_rtc_read_offset, + .set_offset = xlnx_rtc_set_offset, };static irqreturn_t xlnx_rtc_interrupt (int irq,void *id)
@@ -255,10 +318,22 @@ static int xlnx_rtc_probe(struct platform_device *pdev)return ret; } - ret =of_property_read_u32 (pdev->dev.of_node,"calibration" , - &xrtcdev->calibval); -if (ret) - xrtcdev->calibval =RTC_CALIB_DEF ; +/* Getting the rtc_clk info */ + xrtcdev->rtc_clk =devm_clk_get_optional (&pdev->dev,"rtc_clk" ); +if (IS_ERR (xrtcdev->rtc_clk)) { +if (PTR_ERR (xrtcdev->rtc_clk) != -EPROBE_DEFER ) +dev_warn (&pdev->dev,"Device clock not found.\n" ); + } + xrtcdev->freq =clk_get_rate (xrtcdev->rtc_clk); +if (!xrtcdev->freq) { + ret =of_property_read_u32 (pdev->dev.of_node,"calibration" , + &xrtcdev->freq); +if (ret) + xrtcdev->freq =RTC_CALIB_DEF ; + } + ret =readl (xrtcdev->reg_base +RTC_CALIB_RD ); +if (!ret) +writel (xrtcdev->freq, (xrtcdev->reg_base +RTC_CALIB_WR ));xlnx_init_rtc (xrtcdev);
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
kernel test robot
build botRe: [PATCH V8 3/3] rtc: zynqmp: Add calibration set and get support
I love your patch! Perhaps something to improve:
Hi Srinivas,
I love your patch! Perhaps something to improve:
[auto build test WARNING on abelloni/rtc-next]
[also build test WARNING on v5.19-rc2 next-20220610]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Srinivas-Neeli/dt-bindings-rtc-zynqmp-Add-clock-information/20220614-013701 base: https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next config: i386-randconfig-a006-20220613 (https://download.01.org/0day-ci/archive/20220614/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project c97436f8b6e2718286e8496faf53a2c800e281cf)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/2781fd75583878d86f256113b19bb005dc83fb70
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Srinivas-Neeli/dt-bindings-rtc-zynqmp-Add-clock-information/20220614-013701 git checkout 2781fd75583878d86f256113b19bb005dc83fb70
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/rtc/
If you fix the issue, kindly add following tag where applicable
All warnings (new ones prefixed by >>):
>> drivers/rtc/rtc-zynqmp.c:223:7: warning: variable 'fract_tick' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (fract_offset > (tick_mult / RTC_FR_MAX_TICKS)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/rtc/rtc-zynqmp.c:238:6: note: uninitialized use occurs here
if (fract_tick)
^~~~~~~~~~
drivers/rtc/rtc-zynqmp.c:223:3: note: remove the 'if' if its condition is always true
if (fract_offset > (tick_mult / RTC_FR_MAX_TICKS)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/rtc/rtc-zynqmp.c:218:6: warning: variable 'fract_tick' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (fract_offset) {
^~~~~~~~~~~~
drivers/rtc/rtc-zynqmp.c:238:6: note: uninitialized use occurs here
if (fract_tick)
^~~~~~~~~~
drivers/rtc/rtc-zynqmp.c:218:2: note: remove the 'if' if its condition is always true
if (fract_offset) {
^~~~~~~~~~~~~~~~~~
drivers/rtc/rtc-zynqmp.c:206:26: note: initialize the variable 'fract_tick' to silence this warning
unsigned char fract_tick;
^
= '\0'2 warnings generated.
vim +223 drivers/rtc/rtc-zynqmp.c
200
201 static int xlnx_rtc_set_offset(struct device *dev, long offset)
202 {
203 struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
204 unsigned long long rtc_ppb = RTC_PPB;
205 unsigned int tick_mult = do_div(rtc_ppb, xrtcdev->freq);
206 unsigned char fract_tick;
207 unsigned int calibval;
208 short int max_tick;
209 int fract_offset;
210
211 if (offset < RTC_MIN_OFFSET || offset > RTC_MAX_OFFSET)
212 return -ERANGE;
213
214 /* Number ticks for given offset */
215 max_tick = div_s64_rem(offset, tick_mult, &fract_offset);
216
217 /* Number fractional ticks for given offset */
218 if (fract_offset) {
219 if (fract_offset < 0) {
220 fract_offset = fract_offset + tick_mult;
221 max_tick--;
222 }
> 223 if (fract_offset > (tick_mult / RTC_FR_MAX_TICKS)) { 224 for (fract_tick = 1; fract_tick < 16; fract_tick++) {
225 if (fract_offset <=
226 (fract_tick *
227 (tick_mult / RTC_FR_MAX_TICKS)))
228 break;
229 }
230 }
231 }
232
233 /* Zynqmp RTC uses second and fractional tick
234 * counters for compensation
235 */
236 calibval = max_tick + RTC_CALIB_DEF;
237
238 if (fract_tick)
239 calibval |= RTC_FR_EN;
240
241 calibval |= (fract_tick << RTC_FR_DATSHIFT);
242
243 writel(calibval, (xrtcdev->reg_base + RTC_CALIB_WR));
244
245 return 0;
246 }
247
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
kernel test robot
build botRe: [PATCH V8 3/3] rtc: zynqmp: Add calibration set and get support
In reply to Srinivas NeeliI love your patch! Perhaps something to improve:
Hi Srinivas,
I love your patch! Perhaps something to improve:
[auto build test WARNING on abelloni/rtc-next]
[also build test WARNING on v5.19-rc2 next-20220610]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Srinivas-Neeli/dt-bindings-rtc-zynqmp-Add-clock-information/20220614-013701 base: https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next config: arm-randconfig-r035-20220612 (https://download.01.org/0day-ci/archive/20220614/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project c97436f8b6e2718286e8496faf53a2c800e281cf)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://github.com/intel-lab-lkp/linux/commit/2781fd75583878d86f256113b19bb005dc83fb70
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Srinivas-Neeli/dt-bindings-rtc-zynqmp-Add-clock-information/20220614-013701 git checkout 2781fd75583878d86f256113b19bb005dc83fb70
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/rtc/
If you fix the issue, kindly add following tag where applicable
All warnings (new ones prefixed by >>):
>> drivers/rtc/rtc-zynqmp.c:223:7: warning: variable 'fract_tick' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (fract_offset > (tick_mult / RTC_FR_MAX_TICKS)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/rtc/rtc-zynqmp.c:238:6: note: uninitialized use occurs here
if (fract_tick)
^~~~~~~~~~
drivers/rtc/rtc-zynqmp.c:223:3: note: remove the 'if' if its condition is always true
if (fract_offset > (tick_mult / RTC_FR_MAX_TICKS)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/rtc/rtc-zynqmp.c:218:6: warning: variable 'fract_tick' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (fract_offset) {
^~~~~~~~~~~~
drivers/rtc/rtc-zynqmp.c:238:6: note: uninitialized use occurs here
if (fract_tick)
^~~~~~~~~~
drivers/rtc/rtc-zynqmp.c:218:2: note: remove the 'if' if its condition is always true
if (fract_offset) {
^~~~~~~~~~~~~~~~~~
drivers/rtc/rtc-zynqmp.c:206:26: note: initialize the variable 'fract_tick' to silence this warning
unsigned char fract_tick;
^
= '\0'2 warnings generated.
vim +223 drivers/rtc/rtc-zynqmp.c
200
201 static int xlnx_rtc_set_offset(struct device *dev, long offset)
202 {
203 struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
204 unsigned long long rtc_ppb = RTC_PPB;
205 unsigned int tick_mult = do_div(rtc_ppb, xrtcdev->freq);
206 unsigned char fract_tick;
207 unsigned int calibval;
208 short int max_tick;
209 int fract_offset;
210
211 if (offset < RTC_MIN_OFFSET || offset > RTC_MAX_OFFSET)
212 return -ERANGE;
213
214 /* Number ticks for given offset */
215 max_tick = div_s64_rem(offset, tick_mult, &fract_offset);
216
217 /* Number fractional ticks for given offset */
218 if (fract_offset) {
219 if (fract_offset < 0) {
220 fract_offset = fract_offset + tick_mult;
221 max_tick--;
222 }
> 223 if (fract_offset > (tick_mult / RTC_FR_MAX_TICKS)) { 224 for (fract_tick = 1; fract_tick < 16; fract_tick++) {
225 if (fract_offset <=
226 (fract_tick *
227 (tick_mult / RTC_FR_MAX_TICKS)))
228 break;
229 }
230 }
231 }
232
233 /* Zynqmp RTC uses second and fractional tick
234 * counters for compensation
235 */
236 calibval = max_tick + RTC_CALIB_DEF;
237
238 if (fract_tick)
239 calibval |= RTC_FR_EN;
240
241 calibval |= (fract_tick << RTC_FR_DATSHIFT);
242
243 writel(calibval, (xrtcdev->reg_base + RTC_CALIB_WR));
244
245 return 0;
246 }
247
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
Quoted 16 lines · Srinivas Neeli
Added clock information and deprecated calibration support.
Signed-off-by Srinivas Neeli <[email protected]>---
Changes in V8:
-None
Changes in V7:
-None
Changes in V6:
-Removed dtc warnings.
Changes in V5:
-Removed quotes and_clksuffix from clocknames.
Changes in V4:
- Deprecated calibrtion support
Changes in V3:
- New patch
Quoted 4 lines
--- .../devicetree/bindings/rtc/xlnx,zynqmp-rtc.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
Quoted 25 lines · Srinivas Neeli
Added clock information and deprecated calibration support.
Signed-off-by Srinivas Neeli <[email protected]>---
Changes in V8:
-None
Changes in V7:
-None
Changes in V6:
-Removed dtc warnings.
Changes in V5:
-Removed quotes and_clksuffix from clocknames.
Changes in V4:
- Deprecated calibrtion support
Changes in V3:
- New patch--- .../devicetree/bindings/rtc/xlnx,zynqmp-rtc.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/rtc/xlnx,zynqmp-rtc.yaml +0
-0
Documentation/devicetree/bindings/rtc/xlnx,zynqmp-rtc.yaml properties: · line 31
Quoted 9 lines
Documentation/devicetree/bindings/rtc/xlnx,zynqmp-rtc.yaml +6
-0@@ -23,8 +23,15 @@ properties: reg: maxItems: 1 + clocks: + items: + - description: rtc_clk is the operating frequency of crystal. + + clock-names: + maxItems: 1
You need to specify the name instead of maxItems.
Quoted 16 lines
Documentation/devicetree/bindings/rtc/xlnx,zynqmp-rtc.yaml +3
-1+ interrupts: - minItems: 2 + maxItems: 2 interrupt-names: items:@@ -39,6 +46,7 @@ properties: minimum: 0x1 maximum: 0x1FFFFF default: 0x198233 + deprecated: true required: - compatible
Documentation/devicetree/bindings/rtc/xlnx,zynqmp-rtc.yaml examples: · line 75
Quoted 7 lines
Documentation/devicetree/bindings/rtc/xlnx,zynqmp-rtc.yaml +2
-0@@ -61,5 +69,7 @@ examples: interrupts = <0 26 4>, <0 27 4>; interrupt-names = "alarm", "sec"; calibration = <0x198233>; + clock-names = "rtc_clk"; + clocks = <&rtc_clk>; }; };
Best regards,
Krzysztof