Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

misc: ioc4: simplify wave period measurement in clock_calibrate

The loop for measuring the square wave periods over some cycles is
refactored to be more easily readable. This includes avoiding a
"by-hand-implemented" for loop with a "real" one and adding some
comments.

Furthermore the following compiler warning is avoided by this patch:
drivers/misc/ioc4.c: In function ‘ioc4_probe’:
drivers/misc/ioc4.c:194:16: warning: ‘start’ may be used uninitialized
in this function [-Wmaybe-uninitialized]
period = (end - start) /
^
drivers/misc/ioc4.c:148:11: note: ‘start’ was declared here
uint64_t start, end, period;
^

Signed-off-by: Richard Leitner <dev@g0hl1n.net>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Richard Leitner and committed by
Greg Kroah-Hartman
769105aa 0ec0cf19

+16 -15
+16 -15
drivers/misc/ioc4.c
··· 144 144 { 145 145 union ioc4_int_out int_out; 146 146 union ioc4_gpcr gpcr; 147 - unsigned int state, last_state = 1; 147 + unsigned int state, last_state; 148 148 uint64_t start, end, period; 149 - unsigned int count = 0; 149 + unsigned int count; 150 150 151 151 /* Enable output */ 152 152 gpcr.raw = 0; ··· 167 167 mmiowb(); 168 168 169 169 /* Check square wave period averaged over some number of cycles */ 170 - do { 171 - int_out.raw = readl(&idd->idd_misc_regs->int_out.raw); 172 - state = int_out.fields.int_out; 173 - if (!last_state && state) { 174 - count++; 175 - if (count == IOC4_CALIBRATE_END) { 176 - end = ktime_get_ns(); 177 - break; 178 - } else if (count == IOC4_CALIBRATE_DISCARD) 179 - start = ktime_get_ns(); 180 - } 181 - last_state = state; 182 - } while (1); 170 + start = ktime_get_ns(); 171 + state = 1; /* make sure the first read isn't a rising edge */ 172 + for (count = 0; count <= IOC4_CALIBRATE_END; count++) { 173 + do { /* wait for a rising edge */ 174 + last_state = state; 175 + int_out.raw = readl(&idd->idd_misc_regs->int_out.raw); 176 + state = int_out.fields.int_out; 177 + } while (last_state || !state); 178 + 179 + /* discard the first few cycles */ 180 + if (count == IOC4_CALIBRATE_DISCARD) 181 + start = ktime_get_ns(); 182 + } 183 + end = ktime_get_ns(); 183 184 184 185 /* Calculation rearranged to preserve intermediate precision. 185 186 * Logically: