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

ptp: ptp_clockmatrix: Add wait_for_sys_apll_dpll_lock.

Part of the device initialization aligns the rising edge of the output
clock to the internal 1 PPS clock. If the system APLL and DPLL is not
locked, then the alignment will fail and there will be a fixed offset
between the internal 1 PPS clock and the output clock.

After loading the device firmware, poll the system APLL and DPLL for
locked state prior to initialization, timing out after 2 seconds.

Signed-off-by: Vincent Cheng <vincent.cheng.xh@renesas.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Vincent Cheng and committed by
David S. Miller
797d3186 85749080

+87 -2
+10
drivers/ptp/idt8a340_reg.h
··· 122 122 #define OTP_SCSR_CONFIG_SELECT 0x0022 123 123 124 124 #define STATUS 0xc03c 125 + #define DPLL_SYS_STATUS 0x0020 126 + #define DPLL_SYS_APLL_STATUS 0x0021 125 127 #define USER_GPIO0_TO_7_STATUS 0x008a 126 128 #define USER_GPIO8_TO_15_STATUS 0x008b 127 129 ··· 708 706 709 707 /* Bit definitions for the DPLL_CTRL_COMBO_MASTER_CFG register */ 710 708 #define COMBO_MASTER_HOLD BIT(0) 709 + 710 + /* Bit definitions for DPLL_SYS_STATUS register */ 711 + #define DPLL_SYS_STATE_MASK (0xf) 712 + 713 + /* Bit definitions for SYS_APLL_STATUS register */ 714 + #define SYS_APLL_LOSS_LOCK_LIVE_MASK BIT(0) 715 + #define SYS_APLL_LOSS_LOCK_LIVE_LOCKED 0 716 + #define SYS_APLL_LOSS_LOCK_LIVE_UNLOCKED 1 711 717 712 718 #endif
+62 -2
drivers/ptp/ptp_clockmatrix.c
··· 335 335 return -EBUSY; 336 336 } 337 337 338 + static int read_sys_apll_status(struct idtcm *idtcm, u8 *status) 339 + { 340 + return idtcm_read(idtcm, STATUS, DPLL_SYS_APLL_STATUS, status, 341 + sizeof(u8)); 342 + } 343 + 344 + static int read_sys_dpll_status(struct idtcm *idtcm, u8 *status) 345 + { 346 + return idtcm_read(idtcm, STATUS, DPLL_SYS_STATUS, status, sizeof(u8)); 347 + } 348 + 349 + static int wait_for_sys_apll_dpll_lock(struct idtcm *idtcm) 350 + { 351 + unsigned long timeout = jiffies + msecs_to_jiffies(LOCK_TIMEOUT_MS); 352 + u8 apll = 0; 353 + u8 dpll = 0; 354 + int err; 355 + 356 + do { 357 + err = read_sys_apll_status(idtcm, &apll); 358 + if (err) 359 + return err; 360 + 361 + err = read_sys_dpll_status(idtcm, &dpll); 362 + if (err) 363 + return err; 364 + 365 + apll &= SYS_APLL_LOSS_LOCK_LIVE_MASK; 366 + dpll &= DPLL_SYS_STATE_MASK; 367 + 368 + if (apll == SYS_APLL_LOSS_LOCK_LIVE_LOCKED && 369 + dpll == DPLL_STATE_LOCKED) { 370 + return 0; 371 + } else if (dpll == DPLL_STATE_FREERUN || 372 + dpll == DPLL_STATE_HOLDOVER || 373 + dpll == DPLL_STATE_OPEN_LOOP) { 374 + dev_warn(&idtcm->client->dev, 375 + "No wait state: DPLL_SYS_STATE %d", dpll); 376 + return -EPERM; 377 + } 378 + 379 + msleep(LOCK_POLL_INTERVAL_MS); 380 + } while (time_is_after_jiffies(timeout)); 381 + 382 + dev_warn(&idtcm->client->dev, 383 + "%d ms lock timeout: SYS APLL Loss Lock %d SYS DPLL state %d", 384 + LOCK_TIMEOUT_MS, apll, dpll); 385 + 386 + return -ETIME; 387 + } 388 + 389 + static void wait_for_chip_ready(struct idtcm *idtcm) 390 + { 391 + if (wait_for_boot_status_ready(idtcm)) 392 + dev_warn(&idtcm->client->dev, "BOOT_STATUS != 0xA0"); 393 + 394 + if (wait_for_sys_apll_dpll_lock(idtcm)) 395 + dev_warn(&idtcm->client->dev, 396 + "Continuing while SYS APLL/DPLL is not locked"); 397 + } 398 + 338 399 static int _idtcm_gettime(struct idtcm_channel *channel, 339 400 struct timespec64 *ts) 340 401 { ··· 2296 2235 dev_warn(&idtcm->client->dev, 2297 2236 "loading firmware failed with %d\n", err); 2298 2237 2299 - if (wait_for_boot_status_ready(idtcm)) 2300 - dev_warn(&idtcm->client->dev, "BOOT_STATUS != 0xA0\n"); 2238 + wait_for_chip_ready(idtcm); 2301 2239 2302 2240 if (idtcm->tod_mask) { 2303 2241 for (i = 0; i < MAX_TOD; i++) {
+15
drivers/ptp/ptp_clockmatrix.h
··· 51 51 #define TOD_WRITE_OVERHEAD_COUNT_MAX (2) 52 52 #define TOD_BYTE_COUNT (11) 53 53 54 + #define LOCK_TIMEOUT_MS (2000) 55 + #define LOCK_POLL_INTERVAL_MS (10) 56 + 54 57 #define PEROUT_ENABLE_OUTPUT_MASK (0xdeadbeef) 55 58 56 59 #define IDTCM_MAX_WRITE_COUNT (512) ··· 106 103 SCSR_TOD_WR_TYPE_SEL_DELTA_PLUS = 1, 107 104 SCSR_TOD_WR_TYPE_SEL_DELTA_MINUS = 2, 108 105 SCSR_TOD_WR_TYPE_SEL_MAX = SCSR_TOD_WR_TYPE_SEL_DELTA_MINUS, 106 + }; 107 + 108 + /* Values STATUS.DPLL_SYS_STATUS.DPLL_SYS_STATE */ 109 + enum dpll_state { 110 + DPLL_STATE_MIN = 0, 111 + DPLL_STATE_FREERUN = DPLL_STATE_MIN, 112 + DPLL_STATE_LOCKACQ = 1, 113 + DPLL_STATE_LOCKREC = 2, 114 + DPLL_STATE_LOCKED = 3, 115 + DPLL_STATE_HOLDOVER = 4, 116 + DPLL_STATE_OPEN_LOOP = 5, 117 + DPLL_STATE_MAX = DPLL_STATE_OPEN_LOOP, 109 118 }; 110 119 111 120 struct idtcm;