@@ -116,11 +116,15 @@ struct rockchip_chg_det_reg {
116
116
* @bvalid_det_en: vbus valid rise detection enable register.
117
117
* @bvalid_det_st: vbus valid rise detection status register.
118
118
* @bvalid_det_clr: vbus valid rise detection clear register.
119
+ * @id_det_en: id detection enable register.
120
+ * @id_det_st: id detection state register.
121
+ * @id_det_clr: id detection clear register.
119
122
* @ls_det_en: linestate detection enable register.
120
123
* @ls_det_st: linestate detection state register.
121
124
* @ls_det_clr: linestate detection clear register.
122
125
* @utmi_avalid: utmi vbus avalid status register.
123
126
* @utmi_bvalid: utmi vbus bvalid status register.
127
+ * @utmi_id: utmi id state register.
124
128
* @utmi_ls: utmi linestate state register.
125
129
* @utmi_hstdet: utmi host disconnect register.
126
130
*/
@@ -129,11 +133,15 @@ struct rockchip_usb2phy_port_cfg {
129
133
struct usb2phy_reg bvalid_det_en ;
130
134
struct usb2phy_reg bvalid_det_st ;
131
135
struct usb2phy_reg bvalid_det_clr ;
136
+ struct usb2phy_reg id_det_en ;
137
+ struct usb2phy_reg id_det_st ;
138
+ struct usb2phy_reg id_det_clr ;
132
139
struct usb2phy_reg ls_det_en ;
133
140
struct usb2phy_reg ls_det_st ;
134
141
struct usb2phy_reg ls_det_clr ;
135
142
struct usb2phy_reg utmi_avalid ;
136
143
struct usb2phy_reg utmi_bvalid ;
144
+ struct usb2phy_reg utmi_id ;
137
145
struct usb2phy_reg utmi_ls ;
138
146
struct usb2phy_reg utmi_hstdet ;
139
147
};
@@ -161,6 +169,7 @@ struct rockchip_usb2phy_cfg {
161
169
* @suspended: phy suspended flag.
162
170
* @vbus_attached: otg device vbus status.
163
171
* @bvalid_irq: IRQ number assigned for vbus valid rise detection.
172
+ * @id_irq: IRQ number assigned for ID pin detection.
164
173
* @ls_irq: IRQ number assigned for linestate detection.
165
174
* @otg_mux_irq: IRQ number which multiplex otg-id/otg-bvalid/linestate
166
175
* irqs to one irq in otg-port.
@@ -179,6 +188,7 @@ struct rockchip_usb2phy_port {
179
188
bool suspended ;
180
189
bool vbus_attached ;
181
190
int bvalid_irq ;
191
+ int id_irq ;
182
192
int ls_irq ;
183
193
int otg_mux_irq ;
184
194
struct mutex mutex ;
@@ -419,6 +429,19 @@ static int rockchip_usb2phy_init(struct phy *phy)
419
429
if (ret )
420
430
goto out ;
421
431
432
+ /* clear id status and enable id detect irq */
433
+ ret = property_enable (rphy -> grf ,
434
+ & rport -> port_cfg -> id_det_clr ,
435
+ true);
436
+ if (ret )
437
+ goto out ;
438
+
439
+ ret = property_enable (rphy -> grf ,
440
+ & rport -> port_cfg -> id_det_en ,
441
+ true);
442
+ if (ret )
443
+ goto out ;
444
+
422
445
schedule_delayed_work (& rport -> otg_sm_work ,
423
446
OTG_SCHEDULE_DELAY * 3 );
424
447
} else {
@@ -913,11 +936,30 @@ static irqreturn_t rockchip_usb2phy_bvalid_irq(int irq, void *data)
913
936
return IRQ_HANDLED ;
914
937
}
915
938
939
+ static irqreturn_t rockchip_usb2phy_id_irq (int irq , void * data )
940
+ {
941
+ struct rockchip_usb2phy_port * rport = data ;
942
+ struct rockchip_usb2phy * rphy = dev_get_drvdata (rport -> phy -> dev .parent );
943
+ bool id ;
944
+
945
+ if (!property_enabled (rphy -> grf , & rport -> port_cfg -> id_det_st ))
946
+ return IRQ_NONE ;
947
+
948
+ /* clear id detect irq pending status */
949
+ property_enable (rphy -> grf , & rport -> port_cfg -> id_det_clr , true);
950
+
951
+ id = property_enabled (rphy -> grf , & rport -> port_cfg -> utmi_id );
952
+ extcon_set_state_sync (rphy -> edev , EXTCON_USB_HOST , !id );
953
+
954
+ return IRQ_HANDLED ;
955
+ }
956
+
916
957
static irqreturn_t rockchip_usb2phy_otg_mux_irq (int irq , void * data )
917
958
{
918
959
irqreturn_t ret = IRQ_NONE ;
919
960
920
961
ret |= rockchip_usb2phy_bvalid_irq (irq , data );
962
+ ret |= rockchip_usb2phy_id_irq (irq , data );
921
963
922
964
return ret ;
923
965
}
@@ -1015,6 +1057,25 @@ static int rockchip_usb2phy_port_irq_init(struct rockchip_usb2phy *rphy,
1015
1057
"failed to request otg-bvalid irq handle\n" );
1016
1058
return ret ;
1017
1059
}
1060
+
1061
+ rport -> id_irq = of_irq_get_byname (child_np , "otg-id" );
1062
+ if (rport -> id_irq < 0 ) {
1063
+ dev_err (rphy -> dev , "no otg-id irq provided\n" );
1064
+ ret = rport -> id_irq ;
1065
+ return ret ;
1066
+ }
1067
+
1068
+ ret = devm_request_threaded_irq (rphy -> dev , rport -> id_irq ,
1069
+ NULL ,
1070
+ rockchip_usb2phy_id_irq ,
1071
+ IRQF_ONESHOT ,
1072
+ "rockchip_usb2phy_id" ,
1073
+ rport );
1074
+ if (ret ) {
1075
+ dev_err (rphy -> dev ,
1076
+ "failed to request otg-id irq handle\n" );
1077
+ return ret ;
1078
+ }
1018
1079
}
1019
1080
break ;
1020
1081
default :
@@ -1289,10 +1350,14 @@ static const struct rockchip_usb2phy_cfg rk3228_phy_cfgs[] = {
1289
1350
.bvalid_det_en = { 0x0680 , 3 , 3 , 0 , 1 },
1290
1351
.bvalid_det_st = { 0x0690 , 3 , 3 , 0 , 1 },
1291
1352
.bvalid_det_clr = { 0x06a0 , 3 , 3 , 0 , 1 },
1353
+ .id_det_en = { 0x0680 , 6 , 5 , 0 , 3 },
1354
+ .id_det_st = { 0x0690 , 6 , 5 , 0 , 3 },
1355
+ .id_det_clr = { 0x06a0 , 6 , 5 , 0 , 3 },
1292
1356
.ls_det_en = { 0x0680 , 2 , 2 , 0 , 1 },
1293
1357
.ls_det_st = { 0x0690 , 2 , 2 , 0 , 1 },
1294
1358
.ls_det_clr = { 0x06a0 , 2 , 2 , 0 , 1 },
1295
1359
.utmi_bvalid = { 0x0480 , 4 , 4 , 0 , 1 },
1360
+ .utmi_id = { 0x0480 , 1 , 1 , 0 , 1 },
1296
1361
.utmi_ls = { 0x0480 , 3 , 2 , 0 , 1 },
1297
1362
},
1298
1363
[USB2PHY_PORT_HOST ] = {
@@ -1348,11 +1413,15 @@ static const struct rockchip_usb2phy_cfg rk3308_phy_cfgs[] = {
1348
1413
.bvalid_det_en = { 0x3020 , 3 , 2 , 0 , 3 },
1349
1414
.bvalid_det_st = { 0x3024 , 3 , 2 , 0 , 3 },
1350
1415
.bvalid_det_clr = { 0x3028 , 3 , 2 , 0 , 3 },
1416
+ .id_det_en = { 0x3020 , 5 , 4 , 0 , 3 },
1417
+ .id_det_st = { 0x3024 , 5 , 4 , 0 , 3 },
1418
+ .id_det_clr = { 0x3028 , 5 , 4 , 0 , 3 },
1351
1419
.ls_det_en = { 0x3020 , 0 , 0 , 0 , 1 },
1352
1420
.ls_det_st = { 0x3024 , 0 , 0 , 0 , 1 },
1353
1421
.ls_det_clr = { 0x3028 , 0 , 0 , 0 , 1 },
1354
1422
.utmi_avalid = { 0x0120 , 10 , 10 , 0 , 1 },
1355
1423
.utmi_bvalid = { 0x0120 , 9 , 9 , 0 , 1 },
1424
+ .utmi_id = { 0x0120 , 6 , 6 , 0 , 1 },
1356
1425
.utmi_ls = { 0x0120 , 5 , 4 , 0 , 1 },
1357
1426
},
1358
1427
[USB2PHY_PORT_HOST ] = {
@@ -1391,11 +1460,15 @@ static const struct rockchip_usb2phy_cfg rk3328_phy_cfgs[] = {
1391
1460
.bvalid_det_en = { 0x0110 , 3 , 2 , 0 , 3 },
1392
1461
.bvalid_det_st = { 0x0114 , 3 , 2 , 0 , 3 },
1393
1462
.bvalid_det_clr = { 0x0118 , 3 , 2 , 0 , 3 },
1463
+ .id_det_en = { 0x0110 , 5 , 4 , 0 , 3 },
1464
+ .id_det_st = { 0x0114 , 5 , 4 , 0 , 3 },
1465
+ .id_det_clr = { 0x0118 , 5 , 4 , 0 , 3 },
1394
1466
.ls_det_en = { 0x0110 , 0 , 0 , 0 , 1 },
1395
1467
.ls_det_st = { 0x0114 , 0 , 0 , 0 , 1 },
1396
1468
.ls_det_clr = { 0x0118 , 0 , 0 , 0 , 1 },
1397
1469
.utmi_avalid = { 0x0120 , 10 , 10 , 0 , 1 },
1398
1470
.utmi_bvalid = { 0x0120 , 9 , 9 , 0 , 1 },
1471
+ .utmi_id = { 0x0120 , 6 , 6 , 0 , 1 },
1399
1472
.utmi_ls = { 0x0120 , 5 , 4 , 0 , 1 },
1400
1473
},
1401
1474
[USB2PHY_PORT_HOST ] = {
@@ -1453,8 +1526,12 @@ static const struct rockchip_usb2phy_cfg rk3399_phy_cfgs[] = {
1453
1526
.bvalid_det_en = { 0xe3c0 , 3 , 3 , 0 , 1 },
1454
1527
.bvalid_det_st = { 0xe3e0 , 3 , 3 , 0 , 1 },
1455
1528
.bvalid_det_clr = { 0xe3d0 , 3 , 3 , 0 , 1 },
1529
+ .id_det_en = { 0xe3c0 , 5 , 4 , 0 , 3 },
1530
+ .id_det_st = { 0xe3e0 , 5 , 4 , 0 , 3 },
1531
+ .id_det_clr = { 0xe3d0 , 5 , 4 , 0 , 3 },
1456
1532
.utmi_avalid = { 0xe2ac , 7 , 7 , 0 , 1 },
1457
1533
.utmi_bvalid = { 0xe2ac , 12 , 12 , 0 , 1 },
1534
+ .utmi_id = { 0xe2ac , 8 , 8 , 0 , 1 },
1458
1535
},
1459
1536
[USB2PHY_PORT_HOST ] = {
1460
1537
.phy_sus = { 0xe458 , 1 , 0 , 0x2 , 0x1 },
@@ -1488,8 +1565,12 @@ static const struct rockchip_usb2phy_cfg rk3399_phy_cfgs[] = {
1488
1565
.bvalid_det_en = { 0xe3c0 , 8 , 8 , 0 , 1 },
1489
1566
.bvalid_det_st = { 0xe3e0 , 8 , 8 , 0 , 1 },
1490
1567
.bvalid_det_clr = { 0xe3d0 , 8 , 8 , 0 , 1 },
1568
+ .id_det_en = { 0xe3c0 , 10 , 9 , 0 , 3 },
1569
+ .id_det_st = { 0xe3e0 , 10 , 9 , 0 , 3 },
1570
+ .id_det_clr = { 0xe3d0 , 10 , 9 , 0 , 3 },
1491
1571
.utmi_avalid = { 0xe2ac , 10 , 10 , 0 , 1 },
1492
1572
.utmi_bvalid = { 0xe2ac , 16 , 16 , 0 , 1 },
1573
+ .utmi_id = { 0xe2ac , 11 , 11 , 0 , 1 },
1493
1574
},
1494
1575
[USB2PHY_PORT_HOST ] = {
1495
1576
.phy_sus = { 0xe468 , 1 , 0 , 0x2 , 0x1 },
@@ -1515,8 +1596,12 @@ static const struct rockchip_usb2phy_cfg rk3568_phy_cfgs[] = {
1515
1596
.bvalid_det_en = { 0x0080 , 3 , 2 , 0 , 3 },
1516
1597
.bvalid_det_st = { 0x0084 , 3 , 2 , 0 , 3 },
1517
1598
.bvalid_det_clr = { 0x0088 , 3 , 2 , 0 , 3 },
1599
+ .id_det_en = { 0x0080 , 5 , 4 , 0 , 3 },
1600
+ .id_det_st = { 0x0084 , 5 , 4 , 0 , 3 },
1601
+ .id_det_clr = { 0x0088 , 5 , 4 , 0 , 3 },
1518
1602
.utmi_avalid = { 0x00c0 , 10 , 10 , 0 , 1 },
1519
1603
.utmi_bvalid = { 0x00c0 , 9 , 9 , 0 , 1 },
1604
+ .utmi_id = { 0x00c0 , 6 , 6 , 0 , 1 },
1520
1605
},
1521
1606
[USB2PHY_PORT_HOST ] = {
1522
1607
/* Select suspend control from controller */
0 commit comments