ptp: clockmatrix: support 32-bit address space
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v7 1/5 ptp: clockmatrix: support 32-bit address space
From: Min Li <[email protected]>
We used to assume 0x2010xxxx address. Now that we need to access 0x2011xxxx address, we need to support read/write the whole 32-bit address space.
---
- Drop MAX_ABS_WRITE_PHASE_PICOSECONDS advised by Rahul
- Apply SCSR_ADDR to scrach register in idtcm_load_firmware advised by Simon
- Apply u32 to base in idtcm_output_enable advised by Simon
- Correct sync_ctrl0/1 parameter position for idtcm_write advised by Simon
- Restore adjphase function suggested by Rahul
- Separate unrelated stuff to patches suggested by Paolo
- Squash commits and add missing commit msg suggested by Jakub
- Provide cover-letter suggested by Jakub
drivers/ptp/ptp_clockmatrix.c | 59 ++-- drivers/ptp/ptp_clockmatrix.h | 32 +- include/linux/mfd/idt8a340_reg.h | 542 ++++++++++++++++--------------- 3 files changed, 317 insertions(+), 316 deletions(-)
drivers/ptp/ptp_clockmatrix.c +30 -29
@@ -41,8 +41,8 @@ module_param(firmware, charp, 0);static int _idtcm_adjfine (struct idtcm_channel *channel,long scaled_ppm);static inline int idtcm_read (struct idtcm *idtcm, -u16 module, -u16 regaddr, +u32 module, +u32 regaddr,u8 *buf,u16 count) {
@@ -50,8 +50,8 @@ static inline int idtcm_read(struct idtcm *idtcm, }static inline int idtcm_write (struct idtcm *idtcm, -u16 module, -u16 regaddr, +u32 module, +u32 regaddr,u8 *buf,u16 count) {
@@ -62,7 +62,8 @@ static int contains_full_configuration(struct idtcm *idtcm, const struct firmware *fw) {struct idtcm_fwrc *rec = (struct idtcm_fwrc *)fw->data; -u16 scratch =IDTCM_FW_REG (idtcm->fw_ver,V520 ,SCRATCH ); +u16 scratch =SCSR_ADDR (IDTCM_FW_REG (idtcm->fw_ver,V520 ,SCRATCH )); +u16 gpio_control =SCSR_ADDR (GPIO_USER_CONTROL );s32 full_count;s32 count =0 ;u16 regaddr;
@@ -70,8 +71,8 @@ static int contains_full_configuration(struct idtcm *idtcm,s32 len;/* 4 bytes skipped every 0x80 */ - full_count = (scratch -GPIO_USER_CONTROL ) - - ((scratch >>7 ) - (GPIO_USER_CONTROL >>7 )) *4 ; + full_count = (scratch - gpio_control) - + ((scratch >>7 ) - (gpio_control >>7 )) *4 ;/* If the firmware contains 'full configuration' SM_RESET can be used * to ensure proper configuration.
@@ -88,7 +89,7 @@ static int contains_full_configuration(struct idtcm *idtcm, rec++;/* Top (status registers) and bottom are read-only */ -if (regaddr <GPIO_USER_CONTROL || regaddr >= scratch) +if (regaddr < gpio_control || regaddr >= scratch)continue ;/* Page size 128, last 4 bytes of page skipped */
@@ -506,8 +507,8 @@ static int _sync_pll_output(struct idtcm *idtcm, {int err;u8 val; -u16 sync_ctrl0; -u16 sync_ctrl1; +u32 sync_ctrl0; +u32 sync_ctrl1;u8 temp;if (qn ==0 && qn_plus_1 ==0 )
@@ -553,11 +554,11 @@ static int _sync_pll_output(struct idtcm *idtcm, val =SYNCTRL1_MASTER_SYNC_RST ;/* Place master sync in reset */ - err =idtcm_write (idtcm,0 , sync_ctrl1, &val,sizeof (val)); + err =idtcm_write (idtcm, sync_ctrl1,0 , &val,sizeof (val));if (err)return err; - err =idtcm_write (idtcm,0 , sync_ctrl0, &sync_src,sizeof (sync_src)); + err =idtcm_write (idtcm, sync_ctrl0,0 , &sync_src,sizeof (sync_src));if (err)return err;
@@ -570,27 +571,27 @@ static int _sync_pll_output(struct idtcm *idtcm,if (qn_plus_1) val |=SYNCTRL1_Q1_DIV_SYNC_TRIG ; - err =idtcm_write (idtcm,0 , sync_ctrl1, &val,sizeof (val)); + err =idtcm_write (idtcm, sync_ctrl1,0 , &val,sizeof (val));if (err)return err;/* PLL5 can have OUT8 as second additional output. */ if (pll ==5 && qn_plus_1 !=0 ) { - err =idtcm_read (idtcm,0 ,HW_Q8_CTRL_SPARE , + err =idtcm_read (idtcm,HW_Q8_CTRL_SPARE ,0 , &temp,sizeof (temp));if (err)return err; temp &= ~(Q9_TO_Q8_SYNC_TRIG ); - err =idtcm_write (idtcm,0 ,HW_Q8_CTRL_SPARE , + err =idtcm_write (idtcm,HW_Q8_CTRL_SPARE ,0 , &temp,sizeof (temp));if (err)return err; temp |=Q9_TO_Q8_SYNC_TRIG ; - err =idtcm_write (idtcm,0 ,HW_Q8_CTRL_SPARE , + err =idtcm_write (idtcm,HW_Q8_CTRL_SPARE ,0 , &temp,sizeof (temp));if (err)return err;
@@ -598,21 +599,21 @@ static int _sync_pll_output(struct idtcm *idtcm,/* PLL6 can have OUT11 as second additional output. */ if (pll ==6 && qn_plus_1 !=0 ) { - err =idtcm_read (idtcm,0 ,HW_Q11_CTRL_SPARE , + err =idtcm_read (idtcm,HW_Q11_CTRL_SPARE ,0 , &temp,sizeof (temp));if (err)return err; temp &= ~(Q10_TO_Q11_SYNC_TRIG ); - err =idtcm_write (idtcm,0 ,HW_Q11_CTRL_SPARE , + err =idtcm_write (idtcm,HW_Q11_CTRL_SPARE ,0 , &temp,sizeof (temp));if (err)return err; temp |=Q10_TO_Q11_SYNC_TRIG ; - err =idtcm_write (idtcm,0 ,HW_Q11_CTRL_SPARE , + err =idtcm_write (idtcm,HW_Q11_CTRL_SPARE ,0 , &temp,sizeof (temp));if (err)return err;
@@ -620,7 +621,7 @@ static int _sync_pll_output(struct idtcm *idtcm,/* Place master sync out of reset */ val &= ~(SYNCTRL1_MASTER_SYNC_RST ); - err =idtcm_write (idtcm,0 , sync_ctrl1, &val,sizeof (val)); + err =idtcm_write (idtcm, sync_ctrl1,0 , &val,sizeof (val));return err; }
@@ -637,7 +638,7 @@ static int idtcm_sync_pps_output(struct idtcm_channel *channel)u8 temp;u16 output_mask = channel->output_mask; - err =idtcm_read (idtcm,0 ,HW_Q8_CTRL_SPARE , + err =idtcm_read (idtcm,HW_Q8_CTRL_SPARE ,0 , &temp,sizeof (temp));if (err)return err;
@@ -646,7 +647,7 @@ static int idtcm_sync_pps_output(struct idtcm_channel *channel) Q9_TO_Q8_FANOUT_AND_CLOCK_SYNC_ENABLE_MASK) out8_mux =1 ; - err =idtcm_read (idtcm,0 ,HW_Q11_CTRL_SPARE , + err =idtcm_read (idtcm,HW_Q11_CTRL_SPARE ,0 , &temp,sizeof (temp));if (err)return err;
@@ -1253,7 +1254,7 @@ static void display_pll_and_masks(struct idtcm *idtcm)static int idtcm_load_firmware (struct idtcm *idtcm,struct device *dev) { -u16 scratch =IDTCM_FW_REG (idtcm->fw_ver,V520 ,SCRATCH ); +u16 scratch =SCSR_ADDR (IDTCM_FW_REG (idtcm->fw_ver,V520 ,SCRATCH ));char fname[128 ] =FW_FILENAME ;const struct firmware *fw;struct idtcm_fwrc *rec;
@@ -1303,14 +1304,14 @@ static int idtcm_load_firmware(struct idtcm *idtcm, err =0 ;/* Top (status registers) and bottom are read-only */ -if (regaddr <GPIO_USER_CONTROL || regaddr >= scratch) +if (regaddr <SCSR_ADDR (GPIO_USER_CONTROL ) || regaddr >= scratch)continue ;/* Page size 128, last 4 bytes of page skipped */ if ((loaddr >0x7b && loaddr <=0x7f ) || loaddr >0xfb )continue ; - err =idtcm_write (idtcm, regaddr,0 , &val,sizeof (val)); + err =idtcm_write (idtcm,SCSR_BASE , regaddr, &val,sizeof (val)); }if (err)
@@ -1340,7 +1341,7 @@ static int idtcm_output_enable(struct idtcm_channel *channel,return base; } - err =idtcm_read (idtcm, (u16 )base,OUT_CTRL_1 , &val,sizeof (val)); + err =idtcm_read (idtcm, (u32 )base,OUT_CTRL_1 , &val,sizeof (val));if (err)return err;
@@ -1349,7 +1350,7 @@ static int idtcm_output_enable(struct idtcm_channel *channel,else val &= ~SQUELCH_DISABLE ; -return idtcm_write (idtcm, (u16 )base,OUT_CTRL_1 , &val,sizeof (val)); +return idtcm_write (idtcm, (u32 )base,OUT_CTRL_1 , &val,sizeof (val)); } static int idtcm_perout_enable(struct idtcm_channel *channel,
@@ -1713,10 +1714,10 @@ static s32 idtcm_getmaxphase(struct ptp_clock_info *ptp __always_unused)static int _idtcm_adjphase (struct idtcm_channel *channel,s32 delta_ns) {struct idtcm *idtcm = channel->idtcm; -int err; -u8 i;u8 buf[4 ] = {0 };s32 phase_50ps; +int err; +u8 i;if (channel->mode !=PTP_PLL_MODE_WRITE_PHASE ) { err = channel->configure_write_phase (channel);
drivers/ptp/ptp_clockmatrix.h +10 -22
@@ -54,21 +54,9 @@#define LOCK_TIMEOUT_MS (2000)#define LOCK_POLL_INTERVAL_MS (10) -#define IDTCM_MAX_WRITE_COUNT (512) -#define PHASE_PULL_IN_MAX_PPB (144000)#define PHASE_PULL_IN_MIN_THRESHOLD_NS (2) -/* -* Return register address based on passed in firmware version -*/ -#define IDTCM_FW_REG (FW ,VER ,REG ) (((FW) < (VER)) ? (REG) : (REG##_##VER)) -enum fw_version { -V_DEFAULT =0 , -V487 =1 , -V520 =2 , -}; -/* PTP PLL Mode */ enum ptp_pll_mode {PTP_PLL_MODE_MIN =0 ,
@@ -84,16 +72,16 @@ struct idtcm_channel {struct ptp_clock_info caps;struct ptp_clock *ptp_clock;struct idtcm *idtcm; -u16 dpll_phase; -u16 dpll_freq; -u16 dpll_n; -u16 dpll_ctrl_n; -u16 dpll_phase_pull_in; -u16 tod_read_primary; -u16 tod_read_secondary; -u16 tod_write; -u16 tod_n; -u16 hw_dpll_n; +u32 dpll_phase; +u32 dpll_freq; +u32 dpll_n; +u32 dpll_ctrl_n; +u32 dpll_phase_pull_in; +u32 tod_read_primary; +u32 tod_read_secondary; +u32 tod_write; +u32 tod_n; +u32 hw_dpll_n;u8 sync_src;enum ptp_pll_mode mode;int (*configure_write_frequency)(struct idtcm_channel *channel);
include/linux/mfd/idt8a340_reg.h +277 -265
654 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH v7 2/5 ptp: clockmatrix: set write phase timer to 0 when not in PCW mode
In reply to a message not in the archiveFrom: Min Li <[email protected]>
In order for phase pull-in to work, write phase timer shall be 0 when not in write phase mode. Also Fix u8 -> u16, DPLL_WF_TIMER and DPLL_WP_TIMER are 2-byte registers
--- drivers/ptp/ptp_clockmatrix.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/ptp/ptp_clockmatrix.c +14 -0
@@ -1396,6 +1396,20 @@ static int idtcm_set_pll_mode(struct idtcm_channel *channel,struct idtcm *idtcm = channel->idtcm;int err;u8 dpll_mode; +u8 buf[2 ] = {0 }; + +/* Setup WF/WP timer for phase pull-in to work correctly */ + err =idtcm_write (idtcm, channel->dpll_n,DPLL_WF_TIMER , + buf,sizeof (buf)); +if (err) +return err; + +if (mode ==PLL_MODE_WRITE_PHASE ) + buf[0 ] =160 ; + err =idtcm_write (idtcm, channel->dpll_n,DPLL_WP_TIMER , + buf,sizeof (buf)); +if (err) +return err; err = idtcm_read(idtcm, channel->dpll_n, IDTCM_FW_REG(idtcm->fw_ver, V520, DPLL_MODE),
Signature · 1 line
2.39.2
PATCH v7 3/5 ptp: clockmatrix: dco input-to-output delay is 20 FOD cycles + 8ns
In reply to a message not in the archiveFrom: Min Li <[email protected]>
Set dco input-to-output delay is 20 FOD cycles + 8ns
--- drivers/ptp/ptp_clockmatrix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ptp/ptp_clockmatrix.c +2 -2
@@ -2165,7 +2165,7 @@ static int configure_channel_pll(struct idtcm_channel *channel)/* * Compensate for the PTP DCO input-to-output delay. -* This delay is 18 FOD cycles. +* This delay is 20 FOD cycles + 8ns. */ static u32 idtcm_get_dco_delay (struct idtcm_channel *channel) {
@@ -2196,7 +2196,7 @@ static u32 idtcm_get_dco_delay(struct idtcm_channel *channel) fodFreq = (u32 )div_u64 (m, n);if (fodFreq >=500000000 ) -return (u32 )div_u64 (18 * (u64 )NSEC_PER_SEC , fodFreq); +return (u32 )div_u64 (20 * (u64 )NSEC_PER_SEC , fodFreq) +8 ;return 0 ; }
Signature · 1 line
2.39.2
PATCH v7 4/5 ptp: clockmatrix: Fix caps.max_adj to reflect DPLL_MAX_FREQ_OFFSET[MAX_FFO]
In reply to a message not in the archiveFrom: Min Li <[email protected]>
Query MAX_FREQ_OFFSET register to set the proper limit.
--- drivers/ptp/ptp_clockmatrix.c | 43 +++++++++++++++++++++++++------- drivers/ptp/ptp_clockmatrix.h | 1 + include/linux/mfd/idt8a340_reg.h | 1 + 3 files changed, 36 insertions(+), 9 deletions(-)
drivers/ptp/ptp_clockmatrix.c +34 -9
@@ -1038,7 +1038,7 @@ static int _idtcm_adjtime_deprecated(struct idtcm_channel *channel, s64 delta)s64 now;if (abs (delta) <PHASE_PULL_IN_THRESHOLD_NS_DEPRECATED ) { - err = channel->do_phase_pull_in (channel, delta,0 ); + err = channel->do_phase_pull_in (channel, delta, channel->caps.max_adj); }else { idtcm->calculate_overhead_flag =1 ;
@@ -1594,7 +1594,7 @@ static int do_phase_pull_in_sw(struct idtcm_channel *channel,if (abs (delta_ns) <PHASE_PULL_IN_MIN_THRESHOLD_NS )return 0 ; -if (max_ffo_ppb ==0 ) +if (max_ffo_ppb ==0 || max_ffo_ppb >PHASE_PULL_IN_MAX_PPB ) max_ffo_ppb =PHASE_PULL_IN_MAX_PPB ;/* For most cases, keep phase pull-in duration 1 second */
@@ -1880,7 +1880,7 @@ static int idtcm_adjtime(struct ptp_clock_info *ptp, s64 delta)mutex_lock (idtcm->lock);if (abs (delta) <PHASE_PULL_IN_THRESHOLD_NS ) { - err = channel->do_phase_pull_in (channel, delta,0 ); + err = channel->do_phase_pull_in (channel, delta, channel->caps.max_adj); }else {if (delta >=0 ) { ts =ns_to_timespec64 (delta);
@@ -1927,9 +1927,6 @@ static int idtcm_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)if (channel->phase_pull_in == true)return 0 ; -if (scaled_ppm == channel->current_freq_scaled_ppm) -return 0 ; -mutex_lock (idtcm->lock); err =_idtcm_adjfine (channel, scaled_ppm);mutex_unlock (idtcm->lock);
@@ -2054,7 +2051,7 @@ static struct ptp_pin_desc pin_config[MAX_TOD][MAX_REF_CLK];static const struct ptp_clock_info idtcm_caps = { .owner =THIS_MODULE , - .max_adj =244000 , + .max_adj =MAX_FFO_PPB , .n_per_out =12 , .n_ext_ts =MAX_TOD , .n_pins =MAX_REF_CLK ,
@@ -2071,7 +2068,7 @@ static const struct ptp_clock_info idtcm_caps = {static const struct ptp_clock_info idtcm_caps_deprecated = { .owner =THIS_MODULE , - .max_adj =244000 , + .max_adj =MAX_FFO_PPB , .n_per_out =12 , .n_ext_ts =MAX_TOD , .n_pins =MAX_REF_CLK ,
@@ -2242,6 +2239,25 @@ static int configure_channel_tod(struct idtcm_channel *channel, u32 index)return 0 ; } +static int initialize_max_adj (struct idtcm_channel *channel) +{ +struct idtcm *idtcm = channel->idtcm; +u8 ffo_ppm; +int err; + + err =idtcm_read (idtcm, channel->dpll_n,DPLL_MAX_FREQ_OFFSET , + &ffo_ppm,sizeof (ffo_ppm)); +if (err) +return err; + +if (ffo_ppm && ffo_ppm <= (MAX_FFO_PPB /1000 )) + channel->caps.max_adj = ffo_ppm *1000 ; +else + channel->caps.max_adj =MAX_FFO_PPB ; + +return 0 ; +} +static int idtcm_enable_channel (struct idtcm *idtcm,u32 index) {struct idtcm_channel *channel;
@@ -2285,6 +2301,10 @@ static int idtcm_enable_channel(struct idtcm *idtcm, u32 index) ppd->chan = index; } + err =initialize_max_adj (channel); +if (err) +return err; + err =initialize_dco_operating_mode (channel);if (err)return err;
@@ -2437,8 +2457,13 @@ static int idtcm_probe(struct platform_device *pdev) err =idtcm_load_firmware (idtcm, &pdev->dev); -if (err) +if (err) { +if (err == -ENOENT ) { +mutex_unlock (idtcm->lock); +return -EPROBE_DEFER ; + }dev_warn (idtcm->dev,"loading firmware failed with %d" , err); + }wait_for_chip_ready (idtcm);
drivers/ptp/ptp_clockmatrix.h +1 -0
@@ -19,6 +19,7 @@#define MAX_REF_CLK (16)#define MAX_ABS_WRITE_PHASE_NANOSECONDS (107374182L) +#define MAX_FFO_PPB (244000)#define TOD_MASK_ADDR (0xFFA5)#define DEFAULT_TOD_MASK (0x04)
include/linux/mfd/idt8a340_reg.h +1 -0
@@ -192,6 +192,7 @@#define DPLL_CTRL_REG_0 0x0002#define DPLL_CTRL_REG_1 0x0003#define DPLL_CTRL_REG_2 0x0004 +#define DPLL_MAX_FREQ_OFFSET 0x0025#define DPLL_WF_TIMER 0x002c#define DPLL_WP_TIMER 0x002e#define DPLL_TOD_SYNC_CFG 0x0031
Signature · 1 line
2.39.2
PATCH v7 5/5 ptp: clockmatrix: move register and firmware related definition to idt8a340_reg.h
In reply to a message not in the archiveFrom: Min Li <[email protected]>
This change is needed by rsmu driver, which will be submitted separately from mfd tree.
--- drivers/ptp/ptp_clockmatrix.h | 33 --------- include/linux/mfd/idt8a340_reg.h | 121 +++++++++++++++++++++++++++++-- 2 files changed, 113 insertions(+), 41 deletions(-)
drivers/ptp/ptp_clockmatrix.h +0 -33
@@ -21,32 +21,6 @@#define MAX_ABS_WRITE_PHASE_NANOSECONDS (107374182L)#define MAX_FFO_PPB (244000) -#define TOD_MASK_ADDR (0xFFA5) -#define DEFAULT_TOD_MASK (0x04) - -#define SET_U16_LSB (orig, val8) (orig = (0xff00 & (orig)) | (val8)) -#define SET_U16_MSB (orig, val8) (orig = (0x00ff & (orig)) | (val8 << 8)) - -#define TOD0_PTP_PLL_ADDR (0xFFA8) -#define TOD1_PTP_PLL_ADDR (0xFFA9) -#define TOD2_PTP_PLL_ADDR (0xFFAA) -#define TOD3_PTP_PLL_ADDR (0xFFAB) - -#define TOD0_OUT_ALIGN_MASK_ADDR (0xFFB0) -#define TOD1_OUT_ALIGN_MASK_ADDR (0xFFB2) -#define TOD2_OUT_ALIGN_MASK_ADDR (0xFFB4) -#define TOD3_OUT_ALIGN_MASK_ADDR (0xFFB6) - -#define DEFAULT_OUTPUT_MASK_PLL0 (0x003) -#define DEFAULT_OUTPUT_MASK_PLL1 (0x00c) -#define DEFAULT_OUTPUT_MASK_PLL2 (0x030) -#define DEFAULT_OUTPUT_MASK_PLL3 (0x0c0) - -#define DEFAULT_TOD0_PTP_PLL (0) -#define DEFAULT_TOD1_PTP_PLL (1) -#define DEFAULT_TOD2_PTP_PLL (2) -#define DEFAULT_TOD3_PTP_PLL (3) -#define PHASE_PULL_IN_THRESHOLD_NS_DEPRECATED (150000)#define PHASE_PULL_IN_THRESHOLD_NS (15000)#define TOD_WRITE_OVERHEAD_COUNT_MAX (2)
@@ -121,11 +95,4 @@ struct idtcm { ktime_t start_time; }; -struct idtcm_fwrc { -u8 hiaddr; -u8 loaddr; -u8 value; -u8 reserved; -} __packed; -#endif /* PTP_IDTCLOCKMATRIX_H */
include/linux/mfd/idt8a340_reg.h +113 -8
151 lines not on this page · raw message
Signature · 1 line
2.39.2