1 // SPDX-License-Identifier: GPL-2.0+
3 * PTP hardware clock driver for the IDT ClockMatrix(TM) family of timing and
4 * synchronization devices.
6 * Copyright (C) 2019 Integrated Device Technology, Inc., a Renesas Company.
8 #include <linux/firmware.h>
10 #include <linux/module.h>
11 #include <linux/ptp_clock_kernel.h>
12 #include <linux/delay.h>
13 #include <linux/jiffies.h>
14 #include <linux/kernel.h>
15 #include <linux/timekeeping.h>
16 #include <linux/string.h>
18 #include "ptp_private.h"
19 #include "ptp_clockmatrix.h"
21 MODULE_DESCRIPTION("Driver for IDT ClockMatrix(TM) family");
24 MODULE_VERSION("1.0");
25 MODULE_LICENSE("GPL");
28 * The name of the firmware file to be loaded
29 * over-rides any automatic selection
31 static char *firmware;
32 module_param(firmware, charp, 0);
34 #define SETTIME_CORRECTION (0)
36 static long set_write_phase_ready(struct ptp_clock_info *ptp)
38 struct idtcm_channel *channel =
39 container_of(ptp, struct idtcm_channel, caps);
41 channel->write_phase_ready = 1;
46 static int char_array_to_timespec(u8 *buf,
48 struct timespec64 *ts)
54 if (count < TOD_BYTE_COUNT)
57 /* Sub-nanoseconds are in buf[0]. */
59 for (i = 0; i < 3; i++) {
65 for (i = 0; i < 5; i++) {
76 static int timespec_to_char_array(struct timespec64 const *ts,
84 if (count < TOD_BYTE_COUNT)
90 /* Sub-nanoseconds are in buf[0]. */
92 for (i = 1; i < 5; i++) {
97 for (i = 5; i < TOD_BYTE_COUNT; i++) {
106 static int idtcm_strverscmp(const char *ver1, const char *ver2)
112 /* loop through each level of the version string */
113 while (result == 0) {
114 /* extract leading version numbers */
115 if (kstrtou8(ver1, 10, &num1) < 0)
118 if (kstrtou8(ver2, 10, &num2) < 0)
121 /* if numbers differ, then set the result */
124 else if (num1 > num2)
127 /* if numbers are the same, go to next level */
128 ver1 = strchr(ver1, '.');
129 ver2 = strchr(ver2, '.');
145 static int idtcm_xfer_read(struct idtcm *idtcm,
150 struct i2c_client *client = idtcm->client;
151 struct i2c_msg msg[2];
153 char *fmt = "i2c_transfer failed at %d in %s, at addr: %04X!\n";
155 msg[0].addr = client->addr;
158 msg[0].buf = ®addr;
160 msg[1].addr = client->addr;
161 msg[1].flags = I2C_M_RD;
165 cnt = i2c_transfer(client->adapter, msg, 2);
168 dev_err(&client->dev,
174 } else if (cnt != 2) {
175 dev_err(&client->dev,
176 "i2c_transfer sent only %d of %d messages\n", cnt, 2);
183 static int idtcm_xfer_write(struct idtcm *idtcm,
188 struct i2c_client *client = idtcm->client;
189 /* we add 1 byte for device register */
190 u8 msg[IDTCM_MAX_WRITE_COUNT + 1];
192 char *fmt = "i2c_master_send failed at %d in %s, at addr: %04X!\n";
194 if (count > IDTCM_MAX_WRITE_COUNT)
198 memcpy(&msg[1], buf, count);
200 cnt = i2c_master_send(client, msg, count + 1);
203 dev_err(&client->dev,
214 static int idtcm_page_offset(struct idtcm *idtcm, u8 val)
219 if (idtcm->page_offset == val)
227 err = idtcm_xfer_write(idtcm, PAGE_ADDR, buf, sizeof(buf));
230 idtcm->page_offset = 0xff;
231 dev_err(&idtcm->client->dev, "failed to set page offset\n");
233 idtcm->page_offset = val;
239 static int _idtcm_rdwr(struct idtcm *idtcm,
249 hi = (regaddr >> 8) & 0xff;
252 err = idtcm_page_offset(idtcm, hi);
258 return idtcm_xfer_write(idtcm, lo, buf, count);
260 return idtcm_xfer_read(idtcm, lo, buf, count);
263 static int idtcm_read(struct idtcm *idtcm,
269 return _idtcm_rdwr(idtcm, module + regaddr, buf, count, false);
272 static int idtcm_write(struct idtcm *idtcm,
278 return _idtcm_rdwr(idtcm, module + regaddr, buf, count, true);
281 static int _idtcm_gettime(struct idtcm_channel *channel,
282 struct timespec64 *ts)
284 struct idtcm *idtcm = channel->idtcm;
285 u8 buf[TOD_BYTE_COUNT];
290 err = idtcm_read(idtcm, channel->tod_read_primary,
291 TOD_READ_PRIMARY_CMD, &trigger, sizeof(trigger));
295 trigger &= ~(TOD_READ_TRIGGER_MASK << TOD_READ_TRIGGER_SHIFT);
296 trigger |= (1 << TOD_READ_TRIGGER_SHIFT);
297 trigger &= ~TOD_READ_TRIGGER_MODE; /* single shot */
299 err = idtcm_write(idtcm, channel->tod_read_primary,
300 TOD_READ_PRIMARY_CMD, &trigger, sizeof(trigger));
304 /* wait trigger to be 0 */
305 while (trigger & TOD_READ_TRIGGER_MASK) {
307 if (idtcm->calculate_overhead_flag)
308 idtcm->start_time = ktime_get_raw();
310 err = idtcm_read(idtcm, channel->tod_read_primary,
311 TOD_READ_PRIMARY_CMD, &trigger,
321 err = idtcm_read(idtcm, channel->tod_read_primary,
322 TOD_READ_PRIMARY, buf, sizeof(buf));
327 err = char_array_to_timespec(buf, sizeof(buf), ts);
332 static int _sync_pll_output(struct idtcm *idtcm,
344 if ((qn == 0) && (qn_plus_1 == 0))
349 sync_ctrl0 = HW_Q0_Q1_CH_SYNC_CTRL_0;
350 sync_ctrl1 = HW_Q0_Q1_CH_SYNC_CTRL_1;
353 sync_ctrl0 = HW_Q2_Q3_CH_SYNC_CTRL_0;
354 sync_ctrl1 = HW_Q2_Q3_CH_SYNC_CTRL_1;
357 sync_ctrl0 = HW_Q4_Q5_CH_SYNC_CTRL_0;
358 sync_ctrl1 = HW_Q4_Q5_CH_SYNC_CTRL_1;
361 sync_ctrl0 = HW_Q6_Q7_CH_SYNC_CTRL_0;
362 sync_ctrl1 = HW_Q6_Q7_CH_SYNC_CTRL_1;
365 sync_ctrl0 = HW_Q8_CH_SYNC_CTRL_0;
366 sync_ctrl1 = HW_Q8_CH_SYNC_CTRL_1;
369 sync_ctrl0 = HW_Q9_CH_SYNC_CTRL_0;
370 sync_ctrl1 = HW_Q9_CH_SYNC_CTRL_1;
373 sync_ctrl0 = HW_Q10_CH_SYNC_CTRL_0;
374 sync_ctrl1 = HW_Q10_CH_SYNC_CTRL_1;
377 sync_ctrl0 = HW_Q11_CH_SYNC_CTRL_0;
378 sync_ctrl1 = HW_Q11_CH_SYNC_CTRL_1;
384 val = SYNCTRL1_MASTER_SYNC_RST;
386 /* Place master sync in reset */
387 err = idtcm_write(idtcm, 0, sync_ctrl1, &val, sizeof(val));
391 err = idtcm_write(idtcm, 0, sync_ctrl0, &sync_src, sizeof(sync_src));
395 /* Set sync trigger mask */
396 val |= SYNCTRL1_FBDIV_FRAME_SYNC_TRIG | SYNCTRL1_FBDIV_SYNC_TRIG;
399 val |= SYNCTRL1_Q0_DIV_SYNC_TRIG;
402 val |= SYNCTRL1_Q1_DIV_SYNC_TRIG;
404 err = idtcm_write(idtcm, 0, sync_ctrl1, &val, sizeof(val));
408 /* PLL5 can have OUT8 as second additional output. */
409 if ((pll == 5) && (qn_plus_1 != 0)) {
410 err = idtcm_read(idtcm, 0, HW_Q8_CTRL_SPARE,
411 &temp, sizeof(temp));
415 temp &= ~(Q9_TO_Q8_SYNC_TRIG);
417 err = idtcm_write(idtcm, 0, HW_Q8_CTRL_SPARE,
418 &temp, sizeof(temp));
422 temp |= Q9_TO_Q8_SYNC_TRIG;
424 err = idtcm_write(idtcm, 0, HW_Q8_CTRL_SPARE,
425 &temp, sizeof(temp));
430 /* PLL6 can have OUT11 as second additional output. */
431 if ((pll == 6) && (qn_plus_1 != 0)) {
432 err = idtcm_read(idtcm, 0, HW_Q11_CTRL_SPARE,
433 &temp, sizeof(temp));
437 temp &= ~(Q10_TO_Q11_SYNC_TRIG);
439 err = idtcm_write(idtcm, 0, HW_Q11_CTRL_SPARE,
440 &temp, sizeof(temp));
444 temp |= Q10_TO_Q11_SYNC_TRIG;
446 err = idtcm_write(idtcm, 0, HW_Q11_CTRL_SPARE,
447 &temp, sizeof(temp));
452 /* Place master sync out of reset */
453 val &= ~(SYNCTRL1_MASTER_SYNC_RST);
454 err = idtcm_write(idtcm, 0, sync_ctrl1, &val, sizeof(val));
459 static int sync_source_dpll_tod_pps(u16 tod_addr, u8 *sync_src)
465 *sync_src = SYNC_SOURCE_DPLL0_TOD_PPS;
468 *sync_src = SYNC_SOURCE_DPLL1_TOD_PPS;
471 *sync_src = SYNC_SOURCE_DPLL2_TOD_PPS;
474 *sync_src = SYNC_SOURCE_DPLL3_TOD_PPS;
483 static int idtcm_sync_pps_output(struct idtcm_channel *channel)
485 struct idtcm *idtcm = channel->idtcm;
496 u16 output_mask = channel->output_mask;
498 err = sync_source_dpll_tod_pps(channel->tod_n, &sync_src);
502 err = idtcm_read(idtcm, 0, HW_Q8_CTRL_SPARE,
503 &temp, sizeof(temp));
507 if ((temp & Q9_TO_Q8_FANOUT_AND_CLOCK_SYNC_ENABLE_MASK) ==
508 Q9_TO_Q8_FANOUT_AND_CLOCK_SYNC_ENABLE_MASK)
511 err = idtcm_read(idtcm, 0, HW_Q11_CTRL_SPARE,
512 &temp, sizeof(temp));
516 if ((temp & Q10_TO_Q11_FANOUT_AND_CLOCK_SYNC_ENABLE_MASK) ==
517 Q10_TO_Q11_FANOUT_AND_CLOCK_SYNC_ENABLE_MASK)
520 for (pll = 0; pll < 8; pll++) {
525 /* First 4 pll has 2 outputs */
526 qn = output_mask & 0x1;
527 output_mask = output_mask >> 1;
528 qn_plus_1 = output_mask & 0x1;
529 output_mask = output_mask >> 1;
530 } else if (pll == 4) {
532 qn = output_mask & 0x1;
533 output_mask = output_mask >> 1;
535 } else if (pll == 5) {
537 qn_plus_1 = output_mask & 0x1;
538 output_mask = output_mask >> 1;
540 qn = output_mask & 0x1;
541 output_mask = output_mask >> 1;
542 } else if (pll == 6) {
543 qn = output_mask & 0x1;
544 output_mask = output_mask >> 1;
546 qn_plus_1 = output_mask & 0x1;
547 output_mask = output_mask >> 1;
549 } else if (pll == 7) {
550 if (out11_mux == 0) {
551 qn = output_mask & 0x1;
552 output_mask = output_mask >> 1;
556 if ((qn != 0) || (qn_plus_1 != 0))
557 err = _sync_pll_output(idtcm, pll, sync_src, qn,
567 static int _idtcm_set_dpll_hw_tod(struct idtcm_channel *channel,
568 struct timespec64 const *ts,
569 enum hw_tod_write_trig_sel wr_trig)
571 struct idtcm *idtcm = channel->idtcm;
573 u8 buf[TOD_BYTE_COUNT];
576 struct timespec64 local_ts = *ts;
577 s64 total_overhead_ns;
579 /* Configure HW TOD write trigger. */
580 err = idtcm_read(idtcm, channel->hw_dpll_n, HW_DPLL_TOD_CTRL_1,
587 cmd |= wr_trig | 0x08;
589 err = idtcm_write(idtcm, channel->hw_dpll_n, HW_DPLL_TOD_CTRL_1,
595 if (wr_trig != HW_TOD_WR_TRIG_SEL_MSB) {
597 err = timespec_to_char_array(&local_ts, buf, sizeof(buf));
602 err = idtcm_write(idtcm, channel->hw_dpll_n,
603 HW_DPLL_TOD_OVR__0, buf, sizeof(buf));
609 /* ARM HW TOD write trigger. */
612 err = idtcm_write(idtcm, channel->hw_dpll_n, HW_DPLL_TOD_CTRL_1,
615 if (wr_trig == HW_TOD_WR_TRIG_SEL_MSB) {
617 if (idtcm->calculate_overhead_flag) {
618 /* Assumption: I2C @ 400KHz */
619 total_overhead_ns = ktime_to_ns(ktime_get_raw()
621 + idtcm->tod_write_overhead_ns
622 + SETTIME_CORRECTION;
624 timespec64_add_ns(&local_ts, total_overhead_ns);
626 idtcm->calculate_overhead_flag = 0;
629 err = timespec_to_char_array(&local_ts, buf, sizeof(buf));
634 err = idtcm_write(idtcm, channel->hw_dpll_n,
635 HW_DPLL_TOD_OVR__0, buf, sizeof(buf));
641 static int _idtcm_set_dpll_scsr_tod(struct idtcm_channel *channel,
642 struct timespec64 const *ts,
643 enum scsr_tod_write_trig_sel wr_trig,
644 enum scsr_tod_write_type_sel wr_type)
646 struct idtcm *idtcm = channel->idtcm;
647 unsigned char buf[TOD_BYTE_COUNT], cmd;
648 struct timespec64 local_ts = *ts;
651 timespec64_add_ns(&local_ts, SETTIME_CORRECTION);
653 err = timespec_to_char_array(&local_ts, buf, sizeof(buf));
658 err = idtcm_write(idtcm, channel->tod_write, TOD_WRITE,
663 /* Trigger the write operation. */
664 err = idtcm_read(idtcm, channel->tod_write, TOD_WRITE_CMD,
669 cmd &= ~(TOD_WRITE_SELECTION_MASK << TOD_WRITE_SELECTION_SHIFT);
670 cmd &= ~(TOD_WRITE_TYPE_MASK << TOD_WRITE_TYPE_SHIFT);
671 cmd |= (wr_trig << TOD_WRITE_SELECTION_SHIFT);
672 cmd |= (wr_type << TOD_WRITE_TYPE_SHIFT);
674 err = idtcm_write(idtcm, channel->tod_write, TOD_WRITE_CMD,
679 /* Wait for the operation to complete. */
681 /* pps trigger takes up to 1 sec to complete */
682 if (wr_trig == SCSR_TOD_WR_TRIG_SEL_TODPPS)
685 err = idtcm_read(idtcm, channel->tod_write, TOD_WRITE_CMD,
694 dev_err(&idtcm->client->dev,
695 "Timed out waiting for the write counter\n");
703 static int _idtcm_settime(struct idtcm_channel *channel,
704 struct timespec64 const *ts,
705 enum hw_tod_write_trig_sel wr_trig)
707 struct idtcm *idtcm = channel->idtcm;
712 err = _idtcm_set_dpll_hw_tod(channel, ts, wr_trig);
717 /* Wait for the operation to complete. */
718 for (i = 0; i < 10000; i++) {
719 err = idtcm_read(idtcm, channel->hw_dpll_n,
720 HW_DPLL_TOD_CTRL_1, &trig_sel,
726 if (trig_sel == 0x4a)
733 dev_err(&idtcm->client->dev,
734 "Failed at line %d in func %s!\n",
740 return idtcm_sync_pps_output(channel);
743 static int _idtcm_settime_v487(struct idtcm_channel *channel,
744 struct timespec64 const *ts,
745 enum scsr_tod_write_type_sel wr_type)
747 return _idtcm_set_dpll_scsr_tod(channel, ts,
748 SCSR_TOD_WR_TRIG_SEL_IMMEDIATE,
752 static int idtcm_set_phase_pull_in_offset(struct idtcm_channel *channel,
757 struct idtcm *idtcm = channel->idtcm;
761 for (i = 0; i < 4; i++) {
762 buf[i] = 0xff & (offset_ns);
766 err = idtcm_write(idtcm, channel->dpll_phase_pull_in, PULL_IN_OFFSET,
772 static int idtcm_set_phase_pull_in_slope_limit(struct idtcm_channel *channel,
777 struct idtcm *idtcm = channel->idtcm;
781 if (max_ffo_ppb & 0xff000000)
784 for (i = 0; i < 3; i++) {
785 buf[i] = 0xff & (max_ffo_ppb);
789 err = idtcm_write(idtcm, channel->dpll_phase_pull_in,
790 PULL_IN_SLOPE_LIMIT, buf, sizeof(buf));
795 static int idtcm_start_phase_pull_in(struct idtcm_channel *channel)
798 struct idtcm *idtcm = channel->idtcm;
802 err = idtcm_read(idtcm, channel->dpll_phase_pull_in, PULL_IN_CTRL,
810 err = idtcm_write(idtcm, channel->dpll_phase_pull_in,
811 PULL_IN_CTRL, &buf, sizeof(buf));
819 static int idtcm_do_phase_pull_in(struct idtcm_channel *channel,
825 err = idtcm_set_phase_pull_in_offset(channel, -offset_ns);
830 err = idtcm_set_phase_pull_in_slope_limit(channel, max_ffo_ppb);
835 err = idtcm_start_phase_pull_in(channel);
840 static int set_tod_write_overhead(struct idtcm_channel *channel)
842 struct idtcm *idtcm = channel->idtcm;
851 char buf[TOD_BYTE_COUNT] = {0};
853 /* Set page offset */
854 idtcm_write(idtcm, channel->hw_dpll_n, HW_DPLL_TOD_OVR__0,
857 for (i = 0; i < TOD_WRITE_OVERHEAD_COUNT_MAX; i++) {
859 start = ktime_get_raw();
861 err = idtcm_write(idtcm, channel->hw_dpll_n,
862 HW_DPLL_TOD_OVR__0, buf, sizeof(buf));
867 stop = ktime_get_raw();
869 current_ns = ktime_to_ns(stop - start);
872 lowest_ns = current_ns;
874 if (current_ns < lowest_ns)
875 lowest_ns = current_ns;
879 idtcm->tod_write_overhead_ns = lowest_ns;
884 static int _idtcm_adjtime(struct idtcm_channel *channel, s64 delta)
887 struct idtcm *idtcm = channel->idtcm;
888 struct timespec64 ts;
891 if (abs(delta) < PHASE_PULL_IN_THRESHOLD_NS) {
892 err = idtcm_do_phase_pull_in(channel, delta, 0);
894 idtcm->calculate_overhead_flag = 1;
896 err = set_tod_write_overhead(channel);
901 err = _idtcm_gettime(channel, &ts);
906 now = timespec64_to_ns(&ts);
909 ts = ns_to_timespec64(now);
911 err = _idtcm_settime(channel, &ts, HW_TOD_WR_TRIG_SEL_MSB);
917 static int idtcm_state_machine_reset(struct idtcm *idtcm)
920 u8 byte = SM_RESET_CMD;
922 err = idtcm_write(idtcm, RESET_CTRL, SM_RESET, &byte, sizeof(byte));
925 msleep_interruptible(POST_SM_RESET_DELAY_MS);
930 static int idtcm_read_hw_rev_id(struct idtcm *idtcm, u8 *hw_rev_id)
932 return idtcm_read(idtcm, HW_REVISION, REV_ID, hw_rev_id, sizeof(u8));
935 static int idtcm_read_product_id(struct idtcm *idtcm, u16 *product_id)
940 err = idtcm_read(idtcm, GENERAL_STATUS, PRODUCT_ID, buf, sizeof(buf));
942 *product_id = (buf[1] << 8) | buf[0];
947 static int idtcm_read_major_release(struct idtcm *idtcm, u8 *major)
952 err = idtcm_read(idtcm, GENERAL_STATUS, MAJ_REL, &buf, sizeof(buf));
959 static int idtcm_read_minor_release(struct idtcm *idtcm, u8 *minor)
961 return idtcm_read(idtcm, GENERAL_STATUS, MIN_REL, minor, sizeof(u8));
964 static int idtcm_read_hotfix_release(struct idtcm *idtcm, u8 *hotfix)
966 return idtcm_read(idtcm,
973 static int idtcm_read_otp_scsr_config_select(struct idtcm *idtcm,
976 return idtcm_read(idtcm, GENERAL_STATUS, OTP_SCSR_CONFIG_SELECT,
977 config_select, sizeof(u8));
980 static int set_pll_output_mask(struct idtcm *idtcm, u16 addr, u8 val)
985 case TOD0_OUT_ALIGN_MASK_ADDR:
986 SET_U16_LSB(idtcm->channel[0].output_mask, val);
988 case TOD0_OUT_ALIGN_MASK_ADDR + 1:
989 SET_U16_MSB(idtcm->channel[0].output_mask, val);
991 case TOD1_OUT_ALIGN_MASK_ADDR:
992 SET_U16_LSB(idtcm->channel[1].output_mask, val);
994 case TOD1_OUT_ALIGN_MASK_ADDR + 1:
995 SET_U16_MSB(idtcm->channel[1].output_mask, val);
997 case TOD2_OUT_ALIGN_MASK_ADDR:
998 SET_U16_LSB(idtcm->channel[2].output_mask, val);
1000 case TOD2_OUT_ALIGN_MASK_ADDR + 1:
1001 SET_U16_MSB(idtcm->channel[2].output_mask, val);
1003 case TOD3_OUT_ALIGN_MASK_ADDR:
1004 SET_U16_LSB(idtcm->channel[3].output_mask, val);
1006 case TOD3_OUT_ALIGN_MASK_ADDR + 1:
1007 SET_U16_MSB(idtcm->channel[3].output_mask, val);
1010 err = -EFAULT; /* Bad address */;
1017 static int set_tod_ptp_pll(struct idtcm *idtcm, u8 index, u8 pll)
1019 if (index >= MAX_TOD) {
1020 dev_err(&idtcm->client->dev, "ToD%d not supported\n", index);
1024 if (pll >= MAX_PLL) {
1025 dev_err(&idtcm->client->dev, "Pll%d not supported\n", pll);
1029 idtcm->channel[index].pll = pll;
1034 static int check_and_set_masks(struct idtcm *idtcm,
1042 if ((val & 0xf0) || !(val & 0x0f)) {
1043 dev_err(&idtcm->client->dev,
1044 "Invalid TOD mask 0x%hhx\n", val);
1047 idtcm->tod_mask = val;
1050 case TOD0_PTP_PLL_ADDR:
1051 err = set_tod_ptp_pll(idtcm, 0, val);
1053 case TOD1_PTP_PLL_ADDR:
1054 err = set_tod_ptp_pll(idtcm, 1, val);
1056 case TOD2_PTP_PLL_ADDR:
1057 err = set_tod_ptp_pll(idtcm, 2, val);
1059 case TOD3_PTP_PLL_ADDR:
1060 err = set_tod_ptp_pll(idtcm, 3, val);
1063 err = set_pll_output_mask(idtcm, regaddr, val);
1070 static void display_pll_and_masks(struct idtcm *idtcm)
1075 dev_dbg(&idtcm->client->dev, "tod_mask = 0x%02x\n", idtcm->tod_mask);
1077 for (i = 0; i < MAX_TOD; i++) {
1080 if (mask & idtcm->tod_mask)
1081 dev_dbg(&idtcm->client->dev,
1082 "TOD%d pll = %d output_mask = 0x%04x\n",
1083 i, idtcm->channel[i].pll,
1084 idtcm->channel[i].output_mask);
1088 static int idtcm_load_firmware(struct idtcm *idtcm,
1091 char fname[128] = FW_FILENAME;
1092 const struct firmware *fw;
1093 struct idtcm_fwrc *rec;
1100 if (firmware) /* module parameter */
1101 snprintf(fname, sizeof(fname), "%s", firmware);
1103 dev_dbg(&idtcm->client->dev, "requesting firmware '%s'\n", fname);
1105 err = request_firmware(&fw, fname, dev);
1108 dev_err(&idtcm->client->dev,
1109 "Failed at line %d in func %s!\n",
1115 dev_dbg(&idtcm->client->dev, "firmware size %zu bytes\n", fw->size);
1117 rec = (struct idtcm_fwrc *) fw->data;
1120 idtcm_state_machine_reset(idtcm);
1122 for (len = fw->size; len > 0; len -= sizeof(*rec)) {
1124 if (rec->reserved) {
1125 dev_err(&idtcm->client->dev,
1126 "bad firmware, reserved field non-zero\n");
1129 regaddr = rec->hiaddr << 8;
1130 regaddr |= rec->loaddr;
1133 loaddr = rec->loaddr;
1137 err = check_and_set_masks(idtcm, regaddr, val);
1140 if (err != -EINVAL) {
1143 /* Top (status registers) and bottom are read-only */
1144 if ((regaddr < GPIO_USER_CONTROL)
1145 || (regaddr >= SCRATCH))
1148 /* Page size 128, last 4 bytes of page skipped */
1149 if (((loaddr > 0x7b) && (loaddr <= 0x7f))
1153 err = idtcm_write(idtcm, regaddr, 0, &val, sizeof(val));
1160 display_pll_and_masks(idtcm);
1163 release_firmware(fw);
1167 static int idtcm_output_enable(struct idtcm_channel *channel,
1168 bool enable, unsigned int outn)
1170 struct idtcm *idtcm = channel->idtcm;
1174 err = idtcm_read(idtcm, OUTPUT_MODULE_FROM_INDEX(outn),
1175 OUT_CTRL_1, &val, sizeof(val));
1181 val |= SQUELCH_DISABLE;
1183 val &= ~SQUELCH_DISABLE;
1185 return idtcm_write(idtcm, OUTPUT_MODULE_FROM_INDEX(outn),
1186 OUT_CTRL_1, &val, sizeof(val));
1189 static int idtcm_output_mask_enable(struct idtcm_channel *channel,
1196 mask = channel->output_mask;
1203 err = idtcm_output_enable(channel, enable, outn);
1216 static int idtcm_perout_enable(struct idtcm_channel *channel,
1218 struct ptp_perout_request *perout)
1220 unsigned int flags = perout->flags;
1222 if (flags == PEROUT_ENABLE_OUTPUT_MASK)
1223 return idtcm_output_mask_enable(channel, enable);
1225 /* Enable/disable individual output instead */
1226 return idtcm_output_enable(channel, enable, perout->index);
1229 static int idtcm_set_pll_mode(struct idtcm_channel *channel,
1230 enum pll_mode pll_mode)
1232 struct idtcm *idtcm = channel->idtcm;
1236 err = idtcm_read(idtcm, channel->dpll_n, DPLL_MODE,
1237 &dpll_mode, sizeof(dpll_mode));
1241 dpll_mode &= ~(PLL_MODE_MASK << PLL_MODE_SHIFT);
1243 dpll_mode |= (pll_mode << PLL_MODE_SHIFT);
1245 channel->pll_mode = pll_mode;
1247 err = idtcm_write(idtcm, channel->dpll_n, DPLL_MODE,
1248 &dpll_mode, sizeof(dpll_mode));
1255 /* PTP Hardware Clock interface */
1258 * @brief Maximum absolute value for write phase offset in picoseconds
1260 * Destination signed register is 32-bit register in resolution of 50ps
1262 * 0x7fffffff * 50 = 2147483647 * 50 = 107374182350
1264 static int _idtcm_adjphase(struct idtcm_channel *channel, s32 delta_ns)
1266 struct idtcm *idtcm = channel->idtcm;
1274 if (channel->pll_mode != PLL_MODE_WRITE_PHASE) {
1276 err = idtcm_set_pll_mode(channel, PLL_MODE_WRITE_PHASE);
1281 channel->write_phase_ready = 0;
1283 ptp_schedule_worker(channel->ptp_clock,
1284 msecs_to_jiffies(WR_PHASE_SETUP_MS));
1287 if (!channel->write_phase_ready)
1290 offset_ps = (s64)delta_ns * 1000;
1293 * Check for 32-bit signed max * 50:
1295 * 0x7fffffff * 50 = 2147483647 * 50 = 107374182350
1297 if (offset_ps > MAX_ABS_WRITE_PHASE_PICOSECONDS)
1298 offset_ps = MAX_ABS_WRITE_PHASE_PICOSECONDS;
1299 else if (offset_ps < -MAX_ABS_WRITE_PHASE_PICOSECONDS)
1300 offset_ps = -MAX_ABS_WRITE_PHASE_PICOSECONDS;
1302 phase_50ps = DIV_ROUND_CLOSEST(div64_s64(offset_ps, 50), 1);
1304 for (i = 0; i < 4; i++) {
1305 buf[i] = phase_50ps & 0xff;
1309 err = idtcm_write(idtcm, channel->dpll_phase, DPLL_WR_PHASE,
1315 static int _idtcm_adjfine(struct idtcm_channel *channel, long scaled_ppm)
1317 struct idtcm *idtcm = channel->idtcm;
1324 if (channel->pll_mode != PLL_MODE_WRITE_FREQUENCY) {
1325 err = idtcm_set_pll_mode(channel, PLL_MODE_WRITE_FREQUENCY);
1331 * Frequency Control Word unit is: 1.11 * 10^-10 ppm
1340 * FCW = -------------
1343 if (scaled_ppm < 0) {
1345 scaled_ppm = -scaled_ppm;
1348 /* 2 ^ -53 = 1.1102230246251565404236316680908e-16 */
1349 fcw = scaled_ppm * 244140625ULL;
1351 fcw = div_u64(fcw, 1776);
1356 for (i = 0; i < 6; i++) {
1357 buf[i] = fcw & 0xff;
1361 err = idtcm_write(idtcm, channel->dpll_freq, DPLL_WR_FREQ,
1367 static int idtcm_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
1369 struct idtcm_channel *channel =
1370 container_of(ptp, struct idtcm_channel, caps);
1371 struct idtcm *idtcm = channel->idtcm;
1374 mutex_lock(&idtcm->reg_lock);
1376 err = _idtcm_gettime(channel, ts);
1379 dev_err(&idtcm->client->dev,
1380 "Failed at line %d in func %s!\n",
1384 mutex_unlock(&idtcm->reg_lock);
1389 static int idtcm_settime(struct ptp_clock_info *ptp,
1390 const struct timespec64 *ts)
1392 struct idtcm_channel *channel =
1393 container_of(ptp, struct idtcm_channel, caps);
1394 struct idtcm *idtcm = channel->idtcm;
1397 mutex_lock(&idtcm->reg_lock);
1399 err = _idtcm_settime(channel, ts, HW_TOD_WR_TRIG_SEL_MSB);
1402 dev_err(&idtcm->client->dev,
1403 "Failed at line %d in func %s!\n",
1407 mutex_unlock(&idtcm->reg_lock);
1412 static int idtcm_settime_v487(struct ptp_clock_info *ptp,
1413 const struct timespec64 *ts)
1415 struct idtcm_channel *channel =
1416 container_of(ptp, struct idtcm_channel, caps);
1417 struct idtcm *idtcm = channel->idtcm;
1420 mutex_lock(&idtcm->reg_lock);
1422 err = _idtcm_settime_v487(channel, ts, SCSR_TOD_WR_TYPE_SEL_ABSOLUTE);
1425 dev_err(&idtcm->client->dev,
1426 "Failed at line %d in func %s!\n",
1430 mutex_unlock(&idtcm->reg_lock);
1435 static int idtcm_adjtime(struct ptp_clock_info *ptp, s64 delta)
1437 struct idtcm_channel *channel =
1438 container_of(ptp, struct idtcm_channel, caps);
1439 struct idtcm *idtcm = channel->idtcm;
1442 mutex_lock(&idtcm->reg_lock);
1444 err = _idtcm_adjtime(channel, delta);
1447 dev_err(&idtcm->client->dev,
1448 "Failed at line %d in func %s!\n",
1452 mutex_unlock(&idtcm->reg_lock);
1457 static int idtcm_adjtime_v487(struct ptp_clock_info *ptp, s64 delta)
1459 struct idtcm_channel *channel =
1460 container_of(ptp, struct idtcm_channel, caps);
1461 struct idtcm *idtcm = channel->idtcm;
1462 struct timespec64 ts;
1463 enum scsr_tod_write_type_sel type;
1466 if (abs(delta) < PHASE_PULL_IN_THRESHOLD_NS_V487) {
1467 err = idtcm_do_phase_pull_in(channel, delta, 0);
1469 dev_err(&idtcm->client->dev,
1470 "Failed at line %d in func %s!\n",
1477 ts = ns_to_timespec64(delta);
1478 type = SCSR_TOD_WR_TYPE_SEL_DELTA_PLUS;
1480 ts = ns_to_timespec64(-delta);
1481 type = SCSR_TOD_WR_TYPE_SEL_DELTA_MINUS;
1484 mutex_lock(&idtcm->reg_lock);
1486 err = _idtcm_settime_v487(channel, &ts, type);
1489 dev_err(&idtcm->client->dev,
1490 "Failed at line %d in func %s!\n",
1494 mutex_unlock(&idtcm->reg_lock);
1499 static int idtcm_adjphase(struct ptp_clock_info *ptp, s32 delta)
1501 struct idtcm_channel *channel =
1502 container_of(ptp, struct idtcm_channel, caps);
1504 struct idtcm *idtcm = channel->idtcm;
1508 mutex_lock(&idtcm->reg_lock);
1510 err = _idtcm_adjphase(channel, delta);
1513 dev_err(&idtcm->client->dev,
1514 "Failed at line %d in func %s!\n",
1518 mutex_unlock(&idtcm->reg_lock);
1523 static int idtcm_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
1525 struct idtcm_channel *channel =
1526 container_of(ptp, struct idtcm_channel, caps);
1528 struct idtcm *idtcm = channel->idtcm;
1532 mutex_lock(&idtcm->reg_lock);
1534 err = _idtcm_adjfine(channel, scaled_ppm);
1537 dev_err(&idtcm->client->dev,
1538 "Failed at line %d in func %s!\n",
1542 mutex_unlock(&idtcm->reg_lock);
1547 static int idtcm_enable(struct ptp_clock_info *ptp,
1548 struct ptp_clock_request *rq, int on)
1552 struct idtcm_channel *channel =
1553 container_of(ptp, struct idtcm_channel, caps);
1556 case PTP_CLK_REQ_PEROUT:
1558 err = idtcm_perout_enable(channel, false, &rq->perout);
1560 dev_err(&channel->idtcm->client->dev,
1561 "Failed at line %d in func %s!\n",
1567 /* Only accept a 1-PPS aligned to the second. */
1568 if (rq->perout.start.nsec || rq->perout.period.sec != 1 ||
1569 rq->perout.period.nsec)
1572 err = idtcm_perout_enable(channel, true, &rq->perout);
1574 dev_err(&channel->idtcm->client->dev,
1575 "Failed at line %d in func %s!\n",
1586 static int _enable_pll_tod_sync(struct idtcm *idtcm,
1595 u16 out0 = 0, out1 = 0;
1597 if ((qn == 0) && (qn_plus_1 == 0))
1658 * Enable OUTPUT OUT_SYNC.
1661 err = idtcm_read(idtcm, out0, OUT_CTRL_1, &val, sizeof(val));
1666 val &= ~OUT_SYNC_DISABLE;
1668 err = idtcm_write(idtcm, out0, OUT_CTRL_1, &val, sizeof(val));
1675 err = idtcm_read(idtcm, out1, OUT_CTRL_1, &val, sizeof(val));
1680 val &= ~OUT_SYNC_DISABLE;
1682 err = idtcm_write(idtcm, out1, OUT_CTRL_1, &val, sizeof(val));
1688 /* enable dpll sync tod pps, must be set before dpll_mode */
1689 err = idtcm_read(idtcm, dpll, DPLL_TOD_SYNC_CFG, &val, sizeof(val));
1693 val &= ~(TOD_SYNC_SOURCE_MASK << TOD_SYNC_SOURCE_SHIFT);
1694 val |= (sync_src << TOD_SYNC_SOURCE_SHIFT);
1697 return idtcm_write(idtcm, dpll, DPLL_TOD_SYNC_CFG, &val, sizeof(val));
1700 static int idtcm_enable_tod_sync(struct idtcm_channel *channel)
1702 struct idtcm *idtcm = channel->idtcm;
1710 u16 output_mask = channel->output_mask;
1716 * set tod_out_sync_enable to 0.
1718 err = idtcm_read(idtcm, channel->tod_n, TOD_CFG, &cfg, sizeof(cfg));
1722 cfg &= ~TOD_OUT_SYNC_ENABLE;
1724 err = idtcm_write(idtcm, channel->tod_n, TOD_CFG, &cfg, sizeof(cfg));
1728 switch (channel->tod_n) {
1745 err = idtcm_read(idtcm, 0, HW_Q8_CTRL_SPARE,
1746 &temp, sizeof(temp));
1750 if ((temp & Q9_TO_Q8_FANOUT_AND_CLOCK_SYNC_ENABLE_MASK) ==
1751 Q9_TO_Q8_FANOUT_AND_CLOCK_SYNC_ENABLE_MASK)
1754 err = idtcm_read(idtcm, 0, HW_Q11_CTRL_SPARE,
1755 &temp, sizeof(temp));
1759 if ((temp & Q10_TO_Q11_FANOUT_AND_CLOCK_SYNC_ENABLE_MASK) ==
1760 Q10_TO_Q11_FANOUT_AND_CLOCK_SYNC_ENABLE_MASK)
1763 for (pll = 0; pll < 8; pll++) {
1768 /* First 4 pll has 2 outputs */
1769 qn = output_mask & 0x1;
1770 output_mask = output_mask >> 1;
1771 qn_plus_1 = output_mask & 0x1;
1772 output_mask = output_mask >> 1;
1773 } else if (pll == 4) {
1774 if (out8_mux == 0) {
1775 qn = output_mask & 0x1;
1776 output_mask = output_mask >> 1;
1778 } else if (pll == 5) {
1780 qn_plus_1 = output_mask & 0x1;
1781 output_mask = output_mask >> 1;
1783 qn = output_mask & 0x1;
1784 output_mask = output_mask >> 1;
1785 } else if (pll == 6) {
1786 qn = output_mask & 0x1;
1787 output_mask = output_mask >> 1;
1789 qn_plus_1 = output_mask & 0x1;
1790 output_mask = output_mask >> 1;
1792 } else if (pll == 7) {
1793 if (out11_mux == 0) {
1794 qn = output_mask & 0x1;
1795 output_mask = output_mask >> 1;
1799 if ((qn != 0) || (qn_plus_1 != 0))
1800 err = _enable_pll_tod_sync(idtcm, pll, sync_src, qn,
1810 static int idtcm_enable_tod(struct idtcm_channel *channel)
1812 struct idtcm *idtcm = channel->idtcm;
1813 struct timespec64 ts = {0, 0};
1818 * Start the TOD clock ticking.
1820 err = idtcm_read(idtcm, channel->tod_n, TOD_CFG, &cfg, sizeof(cfg));
1826 err = idtcm_write(idtcm, channel->tod_n, TOD_CFG, &cfg, sizeof(cfg));
1830 return _idtcm_settime(channel, &ts, HW_TOD_WR_TRIG_SEL_MSB);
1833 static void idtcm_display_version_info(struct idtcm *idtcm)
1841 char *fmt = "%d.%d.%d, Id: 0x%04x HW Rev: %d OTP Config Select: %d\n";
1843 idtcm_read_major_release(idtcm, &major);
1844 idtcm_read_minor_release(idtcm, &minor);
1845 idtcm_read_hotfix_release(idtcm, &hotfix);
1847 idtcm_read_product_id(idtcm, &product_id);
1848 idtcm_read_hw_rev_id(idtcm, &hw_rev_id);
1850 idtcm_read_otp_scsr_config_select(idtcm, &config_select);
1852 snprintf(idtcm->version, sizeof(idtcm->version), "%u.%u.%u",
1853 major, minor, hotfix);
1855 dev_info(&idtcm->client->dev, fmt, major, minor, hotfix,
1856 product_id, hw_rev_id, config_select);
1859 static const struct ptp_clock_info idtcm_caps_v487 = {
1860 .owner = THIS_MODULE,
1863 .adjphase = &idtcm_adjphase,
1864 .adjfine = &idtcm_adjfine,
1865 .adjtime = &idtcm_adjtime_v487,
1866 .gettime64 = &idtcm_gettime,
1867 .settime64 = &idtcm_settime_v487,
1868 .enable = &idtcm_enable,
1869 .do_aux_work = &set_write_phase_ready,
1872 static const struct ptp_clock_info idtcm_caps = {
1873 .owner = THIS_MODULE,
1876 .adjphase = &idtcm_adjphase,
1877 .adjfine = &idtcm_adjfine,
1878 .adjtime = &idtcm_adjtime,
1879 .gettime64 = &idtcm_gettime,
1880 .settime64 = &idtcm_settime,
1881 .enable = &idtcm_enable,
1882 .do_aux_work = &set_write_phase_ready,
1885 static int configure_channel_pll(struct idtcm_channel *channel)
1889 switch (channel->pll) {
1891 channel->dpll_freq = DPLL_FREQ_0;
1892 channel->dpll_n = DPLL_0;
1893 channel->hw_dpll_n = HW_DPLL_0;
1894 channel->dpll_phase = DPLL_PHASE_0;
1895 channel->dpll_ctrl_n = DPLL_CTRL_0;
1896 channel->dpll_phase_pull_in = DPLL_PHASE_PULL_IN_0;
1899 channel->dpll_freq = DPLL_FREQ_1;
1900 channel->dpll_n = DPLL_1;
1901 channel->hw_dpll_n = HW_DPLL_1;
1902 channel->dpll_phase = DPLL_PHASE_1;
1903 channel->dpll_ctrl_n = DPLL_CTRL_1;
1904 channel->dpll_phase_pull_in = DPLL_PHASE_PULL_IN_1;
1907 channel->dpll_freq = DPLL_FREQ_2;
1908 channel->dpll_n = DPLL_2;
1909 channel->hw_dpll_n = HW_DPLL_2;
1910 channel->dpll_phase = DPLL_PHASE_2;
1911 channel->dpll_ctrl_n = DPLL_CTRL_2;
1912 channel->dpll_phase_pull_in = DPLL_PHASE_PULL_IN_2;
1915 channel->dpll_freq = DPLL_FREQ_3;
1916 channel->dpll_n = DPLL_3;
1917 channel->hw_dpll_n = HW_DPLL_3;
1918 channel->dpll_phase = DPLL_PHASE_3;
1919 channel->dpll_ctrl_n = DPLL_CTRL_3;
1920 channel->dpll_phase_pull_in = DPLL_PHASE_PULL_IN_3;
1923 channel->dpll_freq = DPLL_FREQ_4;
1924 channel->dpll_n = DPLL_4;
1925 channel->hw_dpll_n = HW_DPLL_4;
1926 channel->dpll_phase = DPLL_PHASE_4;
1927 channel->dpll_ctrl_n = DPLL_CTRL_4;
1928 channel->dpll_phase_pull_in = DPLL_PHASE_PULL_IN_4;
1931 channel->dpll_freq = DPLL_FREQ_5;
1932 channel->dpll_n = DPLL_5;
1933 channel->hw_dpll_n = HW_DPLL_5;
1934 channel->dpll_phase = DPLL_PHASE_5;
1935 channel->dpll_ctrl_n = DPLL_CTRL_5;
1936 channel->dpll_phase_pull_in = DPLL_PHASE_PULL_IN_5;
1939 channel->dpll_freq = DPLL_FREQ_6;
1940 channel->dpll_n = DPLL_6;
1941 channel->hw_dpll_n = HW_DPLL_6;
1942 channel->dpll_phase = DPLL_PHASE_6;
1943 channel->dpll_ctrl_n = DPLL_CTRL_6;
1944 channel->dpll_phase_pull_in = DPLL_PHASE_PULL_IN_6;
1947 channel->dpll_freq = DPLL_FREQ_7;
1948 channel->dpll_n = DPLL_7;
1949 channel->hw_dpll_n = HW_DPLL_7;
1950 channel->dpll_phase = DPLL_PHASE_7;
1951 channel->dpll_ctrl_n = DPLL_CTRL_7;
1952 channel->dpll_phase_pull_in = DPLL_PHASE_PULL_IN_7;
1961 static int idtcm_enable_channel(struct idtcm *idtcm, u32 index)
1963 struct idtcm_channel *channel;
1966 if (!(index < MAX_TOD))
1969 channel = &idtcm->channel[index];
1971 /* Set pll addresses */
1972 err = configure_channel_pll(channel);
1976 /* Set tod addresses */
1979 channel->tod_read_primary = TOD_READ_PRIMARY_0;
1980 channel->tod_write = TOD_WRITE_0;
1981 channel->tod_n = TOD_0;
1984 channel->tod_read_primary = TOD_READ_PRIMARY_1;
1985 channel->tod_write = TOD_WRITE_1;
1986 channel->tod_n = TOD_1;
1989 channel->tod_read_primary = TOD_READ_PRIMARY_2;
1990 channel->tod_write = TOD_WRITE_2;
1991 channel->tod_n = TOD_2;
1994 channel->tod_read_primary = TOD_READ_PRIMARY_3;
1995 channel->tod_write = TOD_WRITE_3;
1996 channel->tod_n = TOD_3;
2002 channel->idtcm = idtcm;
2004 if (idtcm_strverscmp(idtcm->version, "4.8.7") >= 0)
2005 channel->caps = idtcm_caps_v487;
2007 channel->caps = idtcm_caps;
2009 snprintf(channel->caps.name, sizeof(channel->caps.name),
2010 "IDT CM TOD%u", index);
2012 if (idtcm_strverscmp(idtcm->version, "4.8.7") >= 0) {
2013 err = idtcm_enable_tod_sync(channel);
2015 dev_err(&idtcm->client->dev,
2016 "Failed at line %d in func %s!\n",
2023 err = idtcm_set_pll_mode(channel, PLL_MODE_WRITE_FREQUENCY);
2025 dev_err(&idtcm->client->dev,
2026 "Failed at line %d in func %s!\n",
2032 err = idtcm_enable_tod(channel);
2034 dev_err(&idtcm->client->dev,
2035 "Failed at line %d in func %s!\n",
2041 channel->ptp_clock = ptp_clock_register(&channel->caps, NULL);
2043 if (IS_ERR(channel->ptp_clock)) {
2044 err = PTR_ERR(channel->ptp_clock);
2045 channel->ptp_clock = NULL;
2049 if (!channel->ptp_clock)
2052 channel->write_phase_ready = 0;
2054 dev_info(&idtcm->client->dev, "PLL%d registered as ptp%d\n",
2055 index, channel->ptp_clock->index);
2060 static void ptp_clock_unregister_all(struct idtcm *idtcm)
2063 struct idtcm_channel *channel;
2065 for (i = 0; i < MAX_TOD; i++) {
2067 channel = &idtcm->channel[i];
2069 if (channel->ptp_clock)
2070 ptp_clock_unregister(channel->ptp_clock);
2074 static void set_default_masks(struct idtcm *idtcm)
2076 idtcm->tod_mask = DEFAULT_TOD_MASK;
2078 idtcm->channel[0].pll = DEFAULT_TOD0_PTP_PLL;
2079 idtcm->channel[1].pll = DEFAULT_TOD1_PTP_PLL;
2080 idtcm->channel[2].pll = DEFAULT_TOD2_PTP_PLL;
2081 idtcm->channel[3].pll = DEFAULT_TOD3_PTP_PLL;
2083 idtcm->channel[0].output_mask = DEFAULT_OUTPUT_MASK_PLL0;
2084 idtcm->channel[1].output_mask = DEFAULT_OUTPUT_MASK_PLL1;
2085 idtcm->channel[2].output_mask = DEFAULT_OUTPUT_MASK_PLL2;
2086 idtcm->channel[3].output_mask = DEFAULT_OUTPUT_MASK_PLL3;
2089 static int idtcm_probe(struct i2c_client *client,
2090 const struct i2c_device_id *id)
2092 struct idtcm *idtcm;
2095 char *fmt = "Failed at %d in line %s with channel output %d!\n";
2097 /* Unused for now */
2100 idtcm = devm_kzalloc(&client->dev, sizeof(struct idtcm), GFP_KERNEL);
2105 idtcm->client = client;
2106 idtcm->page_offset = 0xff;
2107 idtcm->calculate_overhead_flag = 0;
2109 set_default_masks(idtcm);
2111 mutex_init(&idtcm->reg_lock);
2112 mutex_lock(&idtcm->reg_lock);
2114 idtcm_display_version_info(idtcm);
2116 err = idtcm_load_firmware(idtcm, &client->dev);
2119 dev_warn(&idtcm->client->dev,
2120 "loading firmware failed with %d\n", err);
2122 if (idtcm->tod_mask) {
2123 for (i = 0; i < MAX_TOD; i++) {
2124 if (idtcm->tod_mask & (1 << i)) {
2125 err = idtcm_enable_channel(idtcm, i);
2127 dev_err(&idtcm->client->dev,
2137 dev_err(&idtcm->client->dev,
2138 "no PLLs flagged as PHCs, nothing to do\n");
2142 mutex_unlock(&idtcm->reg_lock);
2145 ptp_clock_unregister_all(idtcm);
2149 i2c_set_clientdata(client, idtcm);
2154 static int idtcm_remove(struct i2c_client *client)
2156 struct idtcm *idtcm = i2c_get_clientdata(client);
2158 ptp_clock_unregister_all(idtcm);
2160 mutex_destroy(&idtcm->reg_lock);
2166 static const struct of_device_id idtcm_dt_id[] = {
2167 { .compatible = "idt,8a34000" },
2168 { .compatible = "idt,8a34001" },
2169 { .compatible = "idt,8a34002" },
2170 { .compatible = "idt,8a34003" },
2171 { .compatible = "idt,8a34004" },
2172 { .compatible = "idt,8a34005" },
2173 { .compatible = "idt,8a34006" },
2174 { .compatible = "idt,8a34007" },
2175 { .compatible = "idt,8a34008" },
2176 { .compatible = "idt,8a34009" },
2177 { .compatible = "idt,8a34010" },
2178 { .compatible = "idt,8a34011" },
2179 { .compatible = "idt,8a34012" },
2180 { .compatible = "idt,8a34013" },
2181 { .compatible = "idt,8a34014" },
2182 { .compatible = "idt,8a34015" },
2183 { .compatible = "idt,8a34016" },
2184 { .compatible = "idt,8a34017" },
2185 { .compatible = "idt,8a34018" },
2186 { .compatible = "idt,8a34019" },
2187 { .compatible = "idt,8a34040" },
2188 { .compatible = "idt,8a34041" },
2189 { .compatible = "idt,8a34042" },
2190 { .compatible = "idt,8a34043" },
2191 { .compatible = "idt,8a34044" },
2192 { .compatible = "idt,8a34045" },
2193 { .compatible = "idt,8a34046" },
2194 { .compatible = "idt,8a34047" },
2195 { .compatible = "idt,8a34048" },
2196 { .compatible = "idt,8a34049" },
2199 MODULE_DEVICE_TABLE(of, idtcm_dt_id);
2202 static const struct i2c_device_id idtcm_i2c_id[] = {
2235 MODULE_DEVICE_TABLE(i2c, idtcm_i2c_id);
2237 static struct i2c_driver idtcm_driver = {
2239 .of_match_table = of_match_ptr(idtcm_dt_id),
2242 .probe = idtcm_probe,
2243 .remove = idtcm_remove,
2244 .id_table = idtcm_i2c_id,
2247 module_i2c_driver(idtcm_driver);