14
14
#include <linux/module.h>
15
15
#include <linux/netdevice.h>
16
16
#include <linux/phy.h>
17
- #include <linux/ptp_clock_kernel.h>
18
17
#include <linux/skbuff.h>
19
18
#include <linux/iopoll.h>
20
19
#include <net/arp.h>
@@ -1350,6 +1349,12 @@ int ocelot_get_ts_info(struct ocelot *ocelot, int port,
1350
1349
{
1351
1350
info -> phc_index = ocelot -> ptp_clock ?
1352
1351
ptp_clock_index (ocelot -> ptp_clock ) : -1 ;
1352
+ if (info -> phc_index == -1 ) {
1353
+ info -> so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE |
1354
+ SOF_TIMESTAMPING_RX_SOFTWARE |
1355
+ SOF_TIMESTAMPING_SOFTWARE ;
1356
+ return 0 ;
1357
+ }
1353
1358
info -> so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE |
1354
1359
SOF_TIMESTAMPING_RX_SOFTWARE |
1355
1360
SOF_TIMESTAMPING_SOFTWARE |
@@ -1991,200 +1996,6 @@ struct notifier_block ocelot_switchdev_blocking_nb __read_mostly = {
1991
1996
};
1992
1997
EXPORT_SYMBOL (ocelot_switchdev_blocking_nb );
1993
1998
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
-
2188
1999
/* Configure the maximum SDU (L2 payload) on RX to the value specified in @sdu.
2189
2000
* The length of VLAN tags is accounted for automatically via DEV_MAC_TAGS_CFG.
2190
2001
* In the special case that it's the NPI port that we're configuring, the
@@ -2530,15 +2341,6 @@ int ocelot_init(struct ocelot *ocelot)
2530
2341
queue_delayed_work (ocelot -> stats_queue , & ocelot -> stats_work ,
2531
2342
OCELOT_STATS_CHECK_DELAY );
2532
2343
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
-
2542
2344
return 0 ;
2543
2345
}
2544
2346
EXPORT_SYMBOL (ocelot_init );
@@ -2551,8 +2353,6 @@ void ocelot_deinit(struct ocelot *ocelot)
2551
2353
cancel_delayed_work (& ocelot -> stats_work );
2552
2354
destroy_workqueue (ocelot -> stats_queue );
2553
2355
mutex_destroy (& ocelot -> stats_lock );
2554
- if (ocelot -> ptp_clock )
2555
- ptp_clock_unregister (ocelot -> ptp_clock );
2556
2356
2557
2357
for (i = 0 ; i < ocelot -> num_phys_ports ; i ++ ) {
2558
2358
port = ocelot -> ports [i ];
0 commit comments