@@ -517,7 +517,7 @@ static bool mv88e6xxx_6185_family(struct dsa_switch *ds)
517
517
return false;
518
518
}
519
519
520
- bool mv88e6xxx_6320_family (struct dsa_switch * ds )
520
+ static bool mv88e6xxx_6320_family (struct dsa_switch * ds )
521
521
{
522
522
struct mv88e6xxx_priv_state * ps = ds_to_priv (ds );
523
523
@@ -808,54 +808,6 @@ void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
808
808
}
809
809
}
810
810
811
- #ifdef CONFIG_NET_DSA_HWMON
812
-
813
- int mv88e6xxx_get_temp (struct dsa_switch * ds , int * temp )
814
- {
815
- struct mv88e6xxx_priv_state * ps = ds_to_priv (ds );
816
- int ret ;
817
- int val ;
818
-
819
- * temp = 0 ;
820
-
821
- mutex_lock (& ps -> smi_mutex );
822
-
823
- ret = _mv88e6xxx_phy_write (ds , 0x0 , 0x16 , 0x6 );
824
- if (ret < 0 )
825
- goto error ;
826
-
827
- /* Enable temperature sensor */
828
- ret = _mv88e6xxx_phy_read (ds , 0x0 , 0x1a );
829
- if (ret < 0 )
830
- goto error ;
831
-
832
- ret = _mv88e6xxx_phy_write (ds , 0x0 , 0x1a , ret | (1 << 5 ));
833
- if (ret < 0 )
834
- goto error ;
835
-
836
- /* Wait for temperature to stabilize */
837
- usleep_range (10000 , 12000 );
838
-
839
- val = _mv88e6xxx_phy_read (ds , 0x0 , 0x1a );
840
- if (val < 0 ) {
841
- ret = val ;
842
- goto error ;
843
- }
844
-
845
- /* Disable temperature sensor */
846
- ret = _mv88e6xxx_phy_write (ds , 0x0 , 0x1a , ret & ~(1 << 5 ));
847
- if (ret < 0 )
848
- goto error ;
849
-
850
- * temp = ((val & 0x1f ) - 5 ) * 5 ;
851
-
852
- error :
853
- _mv88e6xxx_phy_write (ds , 0x0 , 0x16 , 0x0 );
854
- mutex_unlock (& ps -> smi_mutex );
855
- return ret ;
856
- }
857
- #endif /* CONFIG_NET_DSA_HWMON */
858
-
859
811
/* Must be called with SMI lock held */
860
812
static int _mv88e6xxx_wait (struct dsa_switch * ds , int reg , int offset ,
861
813
u16 mask )
@@ -2180,6 +2132,132 @@ mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int port, int regnum,
2180
2132
return ret ;
2181
2133
}
2182
2134
2135
+ #ifdef CONFIG_NET_DSA_HWMON
2136
+
2137
+ static int mv88e61xx_get_temp (struct dsa_switch * ds , int * temp )
2138
+ {
2139
+ struct mv88e6xxx_priv_state * ps = ds_to_priv (ds );
2140
+ int ret ;
2141
+ int val ;
2142
+
2143
+ * temp = 0 ;
2144
+
2145
+ mutex_lock (& ps -> smi_mutex );
2146
+
2147
+ ret = _mv88e6xxx_phy_write (ds , 0x0 , 0x16 , 0x6 );
2148
+ if (ret < 0 )
2149
+ goto error ;
2150
+
2151
+ /* Enable temperature sensor */
2152
+ ret = _mv88e6xxx_phy_read (ds , 0x0 , 0x1a );
2153
+ if (ret < 0 )
2154
+ goto error ;
2155
+
2156
+ ret = _mv88e6xxx_phy_write (ds , 0x0 , 0x1a , ret | (1 << 5 ));
2157
+ if (ret < 0 )
2158
+ goto error ;
2159
+
2160
+ /* Wait for temperature to stabilize */
2161
+ usleep_range (10000 , 12000 );
2162
+
2163
+ val = _mv88e6xxx_phy_read (ds , 0x0 , 0x1a );
2164
+ if (val < 0 ) {
2165
+ ret = val ;
2166
+ goto error ;
2167
+ }
2168
+
2169
+ /* Disable temperature sensor */
2170
+ ret = _mv88e6xxx_phy_write (ds , 0x0 , 0x1a , ret & ~(1 << 5 ));
2171
+ if (ret < 0 )
2172
+ goto error ;
2173
+
2174
+ * temp = ((val & 0x1f ) - 5 ) * 5 ;
2175
+
2176
+ error :
2177
+ _mv88e6xxx_phy_write (ds , 0x0 , 0x16 , 0x0 );
2178
+ mutex_unlock (& ps -> smi_mutex );
2179
+ return ret ;
2180
+ }
2181
+
2182
+ static int mv88e63xx_get_temp (struct dsa_switch * ds , int * temp )
2183
+ {
2184
+ int phy = mv88e6xxx_6320_family (ds ) ? 3 : 0 ;
2185
+ int ret ;
2186
+
2187
+ * temp = 0 ;
2188
+
2189
+ ret = mv88e6xxx_phy_page_read (ds , phy , 6 , 27 );
2190
+ if (ret < 0 )
2191
+ return ret ;
2192
+
2193
+ * temp = (ret & 0xff ) - 25 ;
2194
+
2195
+ return 0 ;
2196
+ }
2197
+
2198
+ int mv88e6xxx_get_temp (struct dsa_switch * ds , int * temp )
2199
+ {
2200
+ if (mv88e6xxx_6320_family (ds ) || mv88e6xxx_6352_family (ds ))
2201
+ return mv88e63xx_get_temp (ds , temp );
2202
+
2203
+ return mv88e61xx_get_temp (ds , temp );
2204
+ }
2205
+
2206
+ int mv88e6xxx_get_temp_limit (struct dsa_switch * ds , int * temp )
2207
+ {
2208
+ int phy = mv88e6xxx_6320_family (ds ) ? 3 : 0 ;
2209
+ int ret ;
2210
+
2211
+ if (!mv88e6xxx_6320_family (ds ) && !mv88e6xxx_6352_family (ds ))
2212
+ return - EOPNOTSUPP ;
2213
+
2214
+ * temp = 0 ;
2215
+
2216
+ ret = mv88e6xxx_phy_page_read (ds , phy , 6 , 26 );
2217
+ if (ret < 0 )
2218
+ return ret ;
2219
+
2220
+ * temp = (((ret >> 8 ) & 0x1f ) * 5 ) - 25 ;
2221
+
2222
+ return 0 ;
2223
+ }
2224
+
2225
+ int mv88e6xxx_set_temp_limit (struct dsa_switch * ds , int temp )
2226
+ {
2227
+ int phy = mv88e6xxx_6320_family (ds ) ? 3 : 0 ;
2228
+ int ret ;
2229
+
2230
+ if (!mv88e6xxx_6320_family (ds ) && !mv88e6xxx_6352_family (ds ))
2231
+ return - EOPNOTSUPP ;
2232
+
2233
+ ret = mv88e6xxx_phy_page_read (ds , phy , 6 , 26 );
2234
+ if (ret < 0 )
2235
+ return ret ;
2236
+ temp = clamp_val (DIV_ROUND_CLOSEST (temp , 5 ) + 5 , 0 , 0x1f );
2237
+ return mv88e6xxx_phy_page_write (ds , phy , 6 , 26 ,
2238
+ (ret & 0xe0ff ) | (temp << 8 ));
2239
+ }
2240
+
2241
+ int mv88e6xxx_get_temp_alarm (struct dsa_switch * ds , bool * alarm )
2242
+ {
2243
+ int phy = mv88e6xxx_6320_family (ds ) ? 3 : 0 ;
2244
+ int ret ;
2245
+
2246
+ if (!mv88e6xxx_6320_family (ds ) && !mv88e6xxx_6352_family (ds ))
2247
+ return - EOPNOTSUPP ;
2248
+
2249
+ * alarm = false;
2250
+
2251
+ ret = mv88e6xxx_phy_page_read (ds , phy , 6 , 26 );
2252
+ if (ret < 0 )
2253
+ return ret ;
2254
+
2255
+ * alarm = !!(ret & 0x40 );
2256
+
2257
+ return 0 ;
2258
+ }
2259
+ #endif /* CONFIG_NET_DSA_HWMON */
2260
+
2183
2261
static int __init mv88e6xxx_init (void )
2184
2262
{
2185
2263
#if IS_ENABLED (CONFIG_NET_DSA_MV88E6131 )
0 commit comments