1414#include <linux/module.h>
1515#include <linux/netdevice.h>
1616#include <linux/phy.h>
17- #include <linux/ptp_clock_kernel.h>
1817#include <linux/skbuff.h>
1918#include <linux/iopoll.h>
2019#include <net/arp.h>
@@ -1991,200 +1990,6 @@ struct notifier_block ocelot_switchdev_blocking_nb __read_mostly = {
19911990};
19921991EXPORT_SYMBOL (ocelot_switchdev_blocking_nb );
19931992
1994- int ocelot_ptp_gettime64 (struct ptp_clock_info * ptp , struct timespec64 * ts )
1995- {
1996- struct ocelot * ocelot = container_of (ptp , struct ocelot , ptp_info );
1997- unsigned long flags ;
1998- time64_t s ;
1999- u32 val ;
2000- s64 ns ;
2001-
2002- spin_lock_irqsave (& ocelot -> ptp_clock_lock , flags );
2003-
2004- val = ocelot_read_rix (ocelot , PTP_PIN_CFG , TOD_ACC_PIN );
2005- val &= ~(PTP_PIN_CFG_SYNC | PTP_PIN_CFG_ACTION_MASK | PTP_PIN_CFG_DOM );
2006- val |= PTP_PIN_CFG_ACTION (PTP_PIN_ACTION_SAVE );
2007- ocelot_write_rix (ocelot , val , PTP_PIN_CFG , TOD_ACC_PIN );
2008-
2009- s = ocelot_read_rix (ocelot , PTP_PIN_TOD_SEC_MSB , TOD_ACC_PIN ) & 0xffff ;
2010- s <<= 32 ;
2011- s += ocelot_read_rix (ocelot , PTP_PIN_TOD_SEC_LSB , TOD_ACC_PIN );
2012- ns = ocelot_read_rix (ocelot , PTP_PIN_TOD_NSEC , TOD_ACC_PIN );
2013-
2014- spin_unlock_irqrestore (& ocelot -> ptp_clock_lock , flags );
2015-
2016- /* Deal with negative values */
2017- if (ns >= 0x3ffffff0 && ns <= 0x3fffffff ) {
2018- s -- ;
2019- ns &= 0xf ;
2020- ns += 999999984 ;
2021- }
2022-
2023- set_normalized_timespec64 (ts , s , ns );
2024- return 0 ;
2025- }
2026- EXPORT_SYMBOL (ocelot_ptp_gettime64 );
2027-
2028- static int ocelot_ptp_settime64 (struct ptp_clock_info * ptp ,
2029- const struct timespec64 * ts )
2030- {
2031- struct ocelot * ocelot = container_of (ptp , struct ocelot , ptp_info );
2032- unsigned long flags ;
2033- u32 val ;
2034-
2035- spin_lock_irqsave (& ocelot -> ptp_clock_lock , flags );
2036-
2037- val = ocelot_read_rix (ocelot , PTP_PIN_CFG , TOD_ACC_PIN );
2038- val &= ~(PTP_PIN_CFG_SYNC | PTP_PIN_CFG_ACTION_MASK | PTP_PIN_CFG_DOM );
2039- val |= PTP_PIN_CFG_ACTION (PTP_PIN_ACTION_IDLE );
2040-
2041- ocelot_write_rix (ocelot , val , PTP_PIN_CFG , TOD_ACC_PIN );
2042-
2043- ocelot_write_rix (ocelot , lower_32_bits (ts -> tv_sec ), PTP_PIN_TOD_SEC_LSB ,
2044- TOD_ACC_PIN );
2045- ocelot_write_rix (ocelot , upper_32_bits (ts -> tv_sec ), PTP_PIN_TOD_SEC_MSB ,
2046- TOD_ACC_PIN );
2047- ocelot_write_rix (ocelot , ts -> tv_nsec , PTP_PIN_TOD_NSEC , TOD_ACC_PIN );
2048-
2049- val = ocelot_read_rix (ocelot , PTP_PIN_CFG , TOD_ACC_PIN );
2050- val &= ~(PTP_PIN_CFG_SYNC | PTP_PIN_CFG_ACTION_MASK | PTP_PIN_CFG_DOM );
2051- val |= PTP_PIN_CFG_ACTION (PTP_PIN_ACTION_LOAD );
2052-
2053- ocelot_write_rix (ocelot , val , PTP_PIN_CFG , TOD_ACC_PIN );
2054-
2055- spin_unlock_irqrestore (& ocelot -> ptp_clock_lock , flags );
2056- return 0 ;
2057- }
2058-
2059- static int ocelot_ptp_adjtime (struct ptp_clock_info * ptp , s64 delta )
2060- {
2061- if (delta > - (NSEC_PER_SEC / 2 ) && delta < (NSEC_PER_SEC / 2 )) {
2062- struct ocelot * ocelot = container_of (ptp , struct ocelot , ptp_info );
2063- unsigned long flags ;
2064- u32 val ;
2065-
2066- spin_lock_irqsave (& ocelot -> ptp_clock_lock , flags );
2067-
2068- val = ocelot_read_rix (ocelot , PTP_PIN_CFG , TOD_ACC_PIN );
2069- val &= ~(PTP_PIN_CFG_SYNC | PTP_PIN_CFG_ACTION_MASK | PTP_PIN_CFG_DOM );
2070- val |= PTP_PIN_CFG_ACTION (PTP_PIN_ACTION_IDLE );
2071-
2072- ocelot_write_rix (ocelot , val , PTP_PIN_CFG , TOD_ACC_PIN );
2073-
2074- ocelot_write_rix (ocelot , 0 , PTP_PIN_TOD_SEC_LSB , TOD_ACC_PIN );
2075- ocelot_write_rix (ocelot , 0 , PTP_PIN_TOD_SEC_MSB , TOD_ACC_PIN );
2076- ocelot_write_rix (ocelot , delta , PTP_PIN_TOD_NSEC , TOD_ACC_PIN );
2077-
2078- val = ocelot_read_rix (ocelot , PTP_PIN_CFG , TOD_ACC_PIN );
2079- val &= ~(PTP_PIN_CFG_SYNC | PTP_PIN_CFG_ACTION_MASK | PTP_PIN_CFG_DOM );
2080- val |= PTP_PIN_CFG_ACTION (PTP_PIN_ACTION_DELTA );
2081-
2082- ocelot_write_rix (ocelot , val , PTP_PIN_CFG , TOD_ACC_PIN );
2083-
2084- spin_unlock_irqrestore (& ocelot -> ptp_clock_lock , flags );
2085- } else {
2086- /* Fall back using ocelot_ptp_settime64 which is not exact. */
2087- struct timespec64 ts ;
2088- u64 now ;
2089-
2090- ocelot_ptp_gettime64 (ptp , & ts );
2091-
2092- now = ktime_to_ns (timespec64_to_ktime (ts ));
2093- ts = ns_to_timespec64 (now + delta );
2094-
2095- ocelot_ptp_settime64 (ptp , & ts );
2096- }
2097- return 0 ;
2098- }
2099-
2100- static int ocelot_ptp_adjfine (struct ptp_clock_info * ptp , long scaled_ppm )
2101- {
2102- struct ocelot * ocelot = container_of (ptp , struct ocelot , ptp_info );
2103- u32 unit = 0 , direction = 0 ;
2104- unsigned long flags ;
2105- u64 adj = 0 ;
2106-
2107- spin_lock_irqsave (& ocelot -> ptp_clock_lock , flags );
2108-
2109- if (!scaled_ppm )
2110- goto disable_adj ;
2111-
2112- if (scaled_ppm < 0 ) {
2113- direction = PTP_CFG_CLK_ADJ_CFG_DIR ;
2114- scaled_ppm = - scaled_ppm ;
2115- }
2116-
2117- adj = PSEC_PER_SEC << 16 ;
2118- do_div (adj , scaled_ppm );
2119- do_div (adj , 1000 );
2120-
2121- /* If the adjustment value is too large, use ns instead */
2122- if (adj >= (1L << 30 )) {
2123- unit = PTP_CFG_CLK_ADJ_FREQ_NS ;
2124- do_div (adj , 1000 );
2125- }
2126-
2127- /* Still too big */
2128- if (adj >= (1L << 30 ))
2129- goto disable_adj ;
2130-
2131- ocelot_write (ocelot , unit | adj , PTP_CLK_CFG_ADJ_FREQ );
2132- ocelot_write (ocelot , PTP_CFG_CLK_ADJ_CFG_ENA | direction ,
2133- PTP_CLK_CFG_ADJ_CFG );
2134-
2135- spin_unlock_irqrestore (& ocelot -> ptp_clock_lock , flags );
2136- return 0 ;
2137-
2138- disable_adj :
2139- ocelot_write (ocelot , 0 , PTP_CLK_CFG_ADJ_CFG );
2140-
2141- spin_unlock_irqrestore (& ocelot -> ptp_clock_lock , flags );
2142- return 0 ;
2143- }
2144-
2145- static struct ptp_clock_info ocelot_ptp_clock_info = {
2146- .owner = THIS_MODULE ,
2147- .name = "ocelot ptp" ,
2148- .max_adj = 0x7fffffff ,
2149- .n_alarm = 0 ,
2150- .n_ext_ts = 0 ,
2151- .n_per_out = 0 ,
2152- .n_pins = 0 ,
2153- .pps = 0 ,
2154- .gettime64 = ocelot_ptp_gettime64 ,
2155- .settime64 = ocelot_ptp_settime64 ,
2156- .adjtime = ocelot_ptp_adjtime ,
2157- .adjfine = ocelot_ptp_adjfine ,
2158- };
2159-
2160- static int ocelot_init_timestamp (struct ocelot * ocelot )
2161- {
2162- struct ptp_clock * ptp_clock ;
2163-
2164- ocelot -> ptp_info = ocelot_ptp_clock_info ;
2165- ptp_clock = ptp_clock_register (& ocelot -> ptp_info , ocelot -> dev );
2166- if (IS_ERR (ptp_clock ))
2167- return PTR_ERR (ptp_clock );
2168- /* Check if PHC support is missing at the configuration level */
2169- if (!ptp_clock )
2170- return 0 ;
2171-
2172- ocelot -> ptp_clock = ptp_clock ;
2173-
2174- ocelot_write (ocelot , SYS_PTP_CFG_PTP_STAMP_WID (30 ), SYS_PTP_CFG );
2175- ocelot_write (ocelot , 0xffffffff , ANA_TABLES_PTP_ID_LOW );
2176- ocelot_write (ocelot , 0xffffffff , ANA_TABLES_PTP_ID_HIGH );
2177-
2178- ocelot_write (ocelot , PTP_CFG_MISC_PTP_EN , PTP_CFG_MISC );
2179-
2180- /* There is no device reconfiguration, PTP Rx stamping is always
2181- * enabled.
2182- */
2183- ocelot -> hwtstamp_config .rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT ;
2184-
2185- return 0 ;
2186- }
2187-
21881993/* Configure the maximum SDU (L2 payload) on RX to the value specified in @sdu.
21891994 * The length of VLAN tags is accounted for automatically via DEV_MAC_TAGS_CFG.
21901995 * In the special case that it's the NPI port that we're configuring, the
@@ -2530,15 +2335,6 @@ int ocelot_init(struct ocelot *ocelot)
25302335 queue_delayed_work (ocelot -> stats_queue , & ocelot -> stats_work ,
25312336 OCELOT_STATS_CHECK_DELAY );
25322337
2533- if (ocelot -> ptp ) {
2534- ret = ocelot_init_timestamp (ocelot );
2535- if (ret ) {
2536- dev_err (ocelot -> dev ,
2537- "Timestamp initialization failed\n" );
2538- return ret ;
2539- }
2540- }
2541-
25422338 return 0 ;
25432339}
25442340EXPORT_SYMBOL (ocelot_init );
@@ -2551,8 +2347,6 @@ void ocelot_deinit(struct ocelot *ocelot)
25512347 cancel_delayed_work (& ocelot -> stats_work );
25522348 destroy_workqueue (ocelot -> stats_queue );
25532349 mutex_destroy (& ocelot -> stats_lock );
2554- if (ocelot -> ptp_clock )
2555- ptp_clock_unregister (ocelot -> ptp_clock );
25562350
25572351 for (i = 0 ; i < ocelot -> num_phys_ports ; i ++ ) {
25582352 port = ocelot -> ports [i ];
0 commit comments