@@ -1164,9 +1164,9 @@ static void rswitch_rmac_setting(struct rswitch_etha *etha, const u8 *mac)
1164
1164
1165
1165
static void rswitch_etha_enable_mii (struct rswitch_etha * etha )
1166
1166
{
1167
- rswitch_modify (etha -> addr , MPIC , MPIC_PSMCS_MASK | MPIC_PSMHT_MASK ,
1168
- MPIC_PSMCS ( etha -> psmcs ) | MPIC_PSMHT ( 0x06 ));
1169
- rswitch_modify ( etha -> addr , MPSM , 0 , MPSM_MFF_C45 );
1167
+ rswitch_modify (etha -> addr , MPIC , MPIC_PSMCS | MPIC_PSMHT ,
1168
+ FIELD_PREP ( MPIC_PSMCS , etha -> psmcs ) |
1169
+ FIELD_PREP ( MPIC_PSMHT , 0x06 ) );
1170
1170
}
1171
1171
1172
1172
static int rswitch_etha_hw_init (struct rswitch_etha * etha , const u8 * mac )
@@ -1195,42 +1195,29 @@ static int rswitch_etha_hw_init(struct rswitch_etha *etha, const u8 *mac)
1195
1195
return rswitch_etha_change_mode (etha , EAMC_OPC_OPERATION );
1196
1196
}
1197
1197
1198
- static int rswitch_etha_set_access (struct rswitch_etha * etha , bool read ,
1199
- int phyad , int devad , int regad , int data )
1198
+ static int rswitch_etha_mpsm_op (struct rswitch_etha * etha , bool read ,
1199
+ unsigned int mmf , unsigned int pda ,
1200
+ unsigned int pra , unsigned int pop ,
1201
+ unsigned int prd )
1200
1202
{
1201
- int pop = read ? MDIO_READ_C45 : MDIO_WRITE_C45 ;
1202
1203
u32 val ;
1203
1204
int ret ;
1204
1205
1205
- if (devad == 0xffffffff )
1206
- return - ENODEV ;
1207
-
1208
- writel (MMIS1_CLEAR_FLAGS , etha -> addr + MMIS1 );
1206
+ val = MPSM_PSME |
1207
+ FIELD_PREP (MPSM_MFF , mmf ) |
1208
+ FIELD_PREP (MPSM_PDA , pda ) |
1209
+ FIELD_PREP (MPSM_PRA , pra ) |
1210
+ FIELD_PREP (MPSM_POP , pop ) |
1211
+ FIELD_PREP (MPSM_PRD , prd );
1212
+ iowrite32 (val , etha -> addr + MPSM );
1209
1213
1210
- val = MPSM_PSME | MPSM_MFF_C45 ;
1211
- iowrite32 ((regad << 16 ) | (devad << 8 ) | (phyad << 3 ) | val , etha -> addr + MPSM );
1212
-
1213
- ret = rswitch_reg_wait (etha -> addr , MMIS1 , MMIS1_PAACS , MMIS1_PAACS );
1214
+ ret = rswitch_reg_wait (etha -> addr , MPSM , MPSM_PSME , 0 );
1214
1215
if (ret )
1215
1216
return ret ;
1216
1217
1217
- rswitch_modify (etha -> addr , MMIS1 , MMIS1_PAACS , MMIS1_PAACS );
1218
-
1219
1218
if (read ) {
1220
- writel ((pop << 13 ) | (devad << 8 ) | (phyad << 3 ) | val , etha -> addr + MPSM );
1221
-
1222
- ret = rswitch_reg_wait (etha -> addr , MMIS1 , MMIS1_PRACS , MMIS1_PRACS );
1223
- if (ret )
1224
- return ret ;
1225
-
1226
- ret = (ioread32 (etha -> addr + MPSM ) & MPSM_PRD_MASK ) >> 16 ;
1227
-
1228
- rswitch_modify (etha -> addr , MMIS1 , MMIS1_PRACS , MMIS1_PRACS );
1229
- } else {
1230
- iowrite32 ((data << 16 ) | (pop << 13 ) | (devad << 8 ) | (phyad << 3 ) | val ,
1231
- etha -> addr + MPSM );
1232
-
1233
- ret = rswitch_reg_wait (etha -> addr , MMIS1 , MMIS1_PWACS , MMIS1_PWACS );
1219
+ val = ioread32 (etha -> addr + MPSM );
1220
+ ret = FIELD_GET (MPSM_PRD , val );
1234
1221
}
1235
1222
1236
1223
return ret ;
@@ -1240,16 +1227,47 @@ static int rswitch_etha_mii_read_c45(struct mii_bus *bus, int addr, int devad,
1240
1227
int regad )
1241
1228
{
1242
1229
struct rswitch_etha * etha = bus -> priv ;
1230
+ int ret ;
1243
1231
1244
- return rswitch_etha_set_access (etha , true, addr , devad , regad , 0 );
1232
+ ret = rswitch_etha_mpsm_op (etha , false, MPSM_MMF_C45 , addr , devad ,
1233
+ MPSM_POP_ADDRESS , regad );
1234
+ if (ret )
1235
+ return ret ;
1236
+
1237
+ return rswitch_etha_mpsm_op (etha , true, MPSM_MMF_C45 , addr , devad ,
1238
+ MPSM_POP_READ_C45 , 0 );
1245
1239
}
1246
1240
1247
1241
static int rswitch_etha_mii_write_c45 (struct mii_bus * bus , int addr , int devad ,
1248
1242
int regad , u16 val )
1249
1243
{
1250
1244
struct rswitch_etha * etha = bus -> priv ;
1245
+ int ret ;
1246
+
1247
+ ret = rswitch_etha_mpsm_op (etha , false, MPSM_MMF_C45 , addr , devad ,
1248
+ MPSM_POP_ADDRESS , regad );
1249
+ if (ret )
1250
+ return ret ;
1251
+
1252
+ return rswitch_etha_mpsm_op (etha , false, MPSM_MMF_C45 , addr , devad ,
1253
+ MPSM_POP_WRITE , val );
1254
+ }
1255
+
1256
+ static int rswitch_etha_mii_read_c22 (struct mii_bus * bus , int phyad , int regad )
1257
+ {
1258
+ struct rswitch_etha * etha = bus -> priv ;
1259
+
1260
+ return rswitch_etha_mpsm_op (etha , true, MPSM_MMF_C22 , phyad , regad ,
1261
+ MPSM_POP_READ_C22 , 0 );
1262
+ }
1263
+
1264
+ static int rswitch_etha_mii_write_c22 (struct mii_bus * bus , int phyad ,
1265
+ int regad , u16 val )
1266
+ {
1267
+ struct rswitch_etha * etha = bus -> priv ;
1251
1268
1252
- return rswitch_etha_set_access (etha , false, addr , devad , regad , val );
1269
+ return rswitch_etha_mpsm_op (etha , false, MPSM_MMF_C22 , phyad , regad ,
1270
+ MPSM_POP_WRITE , val );
1253
1271
}
1254
1272
1255
1273
/* Call of_node_put(port) after done */
@@ -1334,6 +1352,8 @@ static int rswitch_mii_register(struct rswitch_device *rdev)
1334
1352
mii_bus -> priv = rdev -> etha ;
1335
1353
mii_bus -> read_c45 = rswitch_etha_mii_read_c45 ;
1336
1354
mii_bus -> write_c45 = rswitch_etha_mii_write_c45 ;
1355
+ mii_bus -> read = rswitch_etha_mii_read_c22 ;
1356
+ mii_bus -> write = rswitch_etha_mii_write_c22 ;
1337
1357
mii_bus -> parent = & rdev -> priv -> pdev -> dev ;
1338
1358
1339
1359
mdio_np = of_get_child_by_name (rdev -> np_port , "mdio" );
0 commit comments