11
11
#include <linux/kernel.h>
12
12
#include <linux/module.h>
13
13
#include <linux/mutex.h>
14
+ #include <linux/pm_runtime.h>
14
15
#include <linux/regulator/consumer.h>
15
16
#include <linux/slab.h>
16
17
#include <linux/types.h>
@@ -1005,33 +1006,6 @@ static void anx7625_power_on_init(struct anx7625_data *ctx)
1005
1006
}
1006
1007
}
1007
1008
1008
- static void anx7625_chip_control (struct anx7625_data * ctx , int state )
1009
- {
1010
- struct device * dev = & ctx -> client -> dev ;
1011
-
1012
- DRM_DEV_DEBUG_DRIVER (dev , "before set, power_state(%d).\n" ,
1013
- atomic_read (& ctx -> power_status ));
1014
-
1015
- if (!ctx -> pdata .low_power_mode )
1016
- return ;
1017
-
1018
- if (state ) {
1019
- atomic_inc (& ctx -> power_status );
1020
- if (atomic_read (& ctx -> power_status ) == 1 )
1021
- anx7625_power_on_init (ctx );
1022
- } else {
1023
- if (atomic_read (& ctx -> power_status )) {
1024
- atomic_dec (& ctx -> power_status );
1025
-
1026
- if (atomic_read (& ctx -> power_status ) == 0 )
1027
- anx7625_power_standby (ctx );
1028
- }
1029
- }
1030
-
1031
- DRM_DEV_DEBUG_DRIVER (dev , "after set, power_state(%d).\n" ,
1032
- atomic_read (& ctx -> power_status ));
1033
- }
1034
-
1035
1009
static void anx7625_init_gpio (struct anx7625_data * platform )
1036
1010
{
1037
1011
struct device * dev = & platform -> client -> dev ;
@@ -1061,9 +1035,6 @@ static void anx7625_stop_dp_work(struct anx7625_data *ctx)
1061
1035
ctx -> hpd_status = 0 ;
1062
1036
ctx -> hpd_high_cnt = 0 ;
1063
1037
ctx -> display_timing_valid = 0 ;
1064
-
1065
- if (ctx -> pdata .low_power_mode == 0 )
1066
- anx7625_disable_pd_protocol (ctx );
1067
1038
}
1068
1039
1069
1040
static void anx7625_start_dp_work (struct anx7625_data * ctx )
@@ -1105,49 +1076,26 @@ static void anx7625_hpd_polling(struct anx7625_data *ctx)
1105
1076
int ret , val ;
1106
1077
struct device * dev = & ctx -> client -> dev ;
1107
1078
1108
- if (atomic_read (& ctx -> power_status ) != 1 ) {
1109
- DRM_DEV_DEBUG_DRIVER (dev , "No need to poling HPD status.\n" );
1110
- return ;
1111
- }
1112
-
1113
1079
ret = readx_poll_timeout (anx7625_read_hpd_status_p0 ,
1114
1080
ctx , val ,
1115
1081
((val & HPD_STATUS ) || (val < 0 )),
1116
1082
5000 ,
1117
1083
5000 * 100 );
1118
1084
if (ret ) {
1119
- DRM_DEV_ERROR (dev , "HPD polling timeout!\n" );
1120
- } else {
1121
- DRM_DEV_DEBUG_DRIVER (dev , "HPD raise up.\n" );
1122
- anx7625_reg_write (ctx , ctx -> i2c .tcpc_client ,
1123
- INTR_ALERT_1 , 0xFF );
1124
- anx7625_reg_write (ctx , ctx -> i2c .rx_p0_client ,
1125
- INTERFACE_CHANGE_INT , 0 );
1085
+ DRM_DEV_ERROR (dev , "no hpd.\n" );
1086
+ return ;
1126
1087
}
1127
1088
1128
- anx7625_start_dp_work (ctx );
1129
- }
1130
-
1131
- static void anx7625_disconnect_check (struct anx7625_data * ctx )
1132
- {
1133
- if (atomic_read (& ctx -> power_status ) == 0 )
1134
- anx7625_stop_dp_work (ctx );
1135
- }
1136
-
1137
- static void anx7625_low_power_mode_check (struct anx7625_data * ctx ,
1138
- int state )
1139
- {
1140
- struct device * dev = & ctx -> client -> dev ;
1089
+ DRM_DEV_DEBUG_DRIVER (dev , "system status: 0x%x. HPD raise up.\n" , val );
1090
+ anx7625_reg_write (ctx , ctx -> i2c .tcpc_client ,
1091
+ INTR_ALERT_1 , 0xFF );
1092
+ anx7625_reg_write (ctx , ctx -> i2c .rx_p0_client ,
1093
+ INTERFACE_CHANGE_INT , 0 );
1141
1094
1142
- DRM_DEV_DEBUG_DRIVER ( dev , "low power mode check, state(%d).\n" , state );
1095
+ anx7625_start_dp_work ( ctx );
1143
1096
1144
- if (ctx -> pdata .low_power_mode ) {
1145
- anx7625_chip_control (ctx , state );
1146
- if (state )
1147
- anx7625_hpd_polling (ctx );
1148
- else
1149
- anx7625_disconnect_check (ctx );
1150
- }
1097
+ if (!ctx -> pdata .panel_bridge && ctx -> bridge_attached )
1098
+ drm_helper_hpd_irq_event (ctx -> bridge .dev );
1151
1099
}
1152
1100
1153
1101
static void anx7625_remove_edid (struct anx7625_data * ctx )
@@ -1180,9 +1128,6 @@ static int anx7625_hpd_change_detect(struct anx7625_data *ctx)
1180
1128
int intr_vector , status ;
1181
1129
struct device * dev = & ctx -> client -> dev ;
1182
1130
1183
- DRM_DEV_DEBUG_DRIVER (dev , "power_status=%d\n" ,
1184
- (u32 )atomic_read (& ctx -> power_status ));
1185
-
1186
1131
status = anx7625_reg_write (ctx , ctx -> i2c .tcpc_client ,
1187
1132
INTR_ALERT_1 , 0xFF );
1188
1133
if (status < 0 ) {
@@ -1228,22 +1173,25 @@ static void anx7625_work_func(struct work_struct *work)
1228
1173
struct anx7625_data , work );
1229
1174
1230
1175
mutex_lock (& ctx -> lock );
1176
+
1177
+ if (pm_runtime_suspended (& ctx -> client -> dev ))
1178
+ goto unlock ;
1179
+
1231
1180
event = anx7625_hpd_change_detect (ctx );
1232
- mutex_unlock (& ctx -> lock );
1233
1181
if (event < 0 )
1234
- return ;
1182
+ goto unlock ;
1235
1183
1236
1184
if (ctx -> bridge_attached )
1237
1185
drm_helper_hpd_irq_event (ctx -> bridge .dev );
1186
+
1187
+ unlock :
1188
+ mutex_unlock (& ctx -> lock );
1238
1189
}
1239
1190
1240
1191
static irqreturn_t anx7625_intr_hpd_isr (int irq , void * data )
1241
1192
{
1242
1193
struct anx7625_data * ctx = (struct anx7625_data * )data ;
1243
1194
1244
- if (atomic_read (& ctx -> power_status ) != 1 )
1245
- return IRQ_NONE ;
1246
-
1247
1195
queue_work (ctx -> workqueue , & ctx -> work );
1248
1196
1249
1197
return IRQ_HANDLED ;
@@ -1305,9 +1253,9 @@ static struct edid *anx7625_get_edid(struct anx7625_data *ctx)
1305
1253
return (struct edid * )edid ;
1306
1254
}
1307
1255
1308
- anx7625_low_power_mode_check ( ctx , 1 );
1256
+ pm_runtime_get_sync ( dev );
1309
1257
edid_num = sp_tx_edid_read (ctx , p_edid -> edid_raw_data );
1310
- anx7625_low_power_mode_check ( ctx , 0 );
1258
+ pm_runtime_put ( dev );
1311
1259
1312
1260
if (edid_num < 1 ) {
1313
1261
DRM_DEV_ERROR (dev , "Fail to read EDID: %d\n" , edid_num );
@@ -1611,10 +1559,7 @@ static void anx7625_bridge_enable(struct drm_bridge *bridge)
1611
1559
1612
1560
DRM_DEV_DEBUG_DRIVER (dev , "drm enable\n" );
1613
1561
1614
- anx7625_low_power_mode_check (ctx , 1 );
1615
-
1616
- if (WARN_ON (!atomic_read (& ctx -> power_status )))
1617
- return ;
1562
+ pm_runtime_get_sync (dev );
1618
1563
1619
1564
anx7625_dp_start (ctx );
1620
1565
}
@@ -1624,14 +1569,11 @@ static void anx7625_bridge_disable(struct drm_bridge *bridge)
1624
1569
struct anx7625_data * ctx = bridge_to_anx7625 (bridge );
1625
1570
struct device * dev = & ctx -> client -> dev ;
1626
1571
1627
- if (WARN_ON (!atomic_read (& ctx -> power_status )))
1628
- return ;
1629
-
1630
1572
DRM_DEV_DEBUG_DRIVER (dev , "drm disable\n" );
1631
1573
1632
1574
anx7625_dp_stop (ctx );
1633
1575
1634
- anx7625_low_power_mode_check ( ctx , 0 );
1576
+ pm_runtime_put ( dev );
1635
1577
}
1636
1578
1637
1579
static enum drm_connector_status
@@ -1735,6 +1677,39 @@ static void anx7625_unregister_i2c_dummy_clients(struct anx7625_data *ctx)
1735
1677
i2c_unregister_device (ctx -> i2c .tcpc_client );
1736
1678
}
1737
1679
1680
+ static int __maybe_unused anx7625_runtime_pm_suspend (struct device * dev )
1681
+ {
1682
+ struct anx7625_data * ctx = dev_get_drvdata (dev );
1683
+
1684
+ mutex_lock (& ctx -> lock );
1685
+
1686
+ anx7625_stop_dp_work (ctx );
1687
+ anx7625_power_standby (ctx );
1688
+
1689
+ mutex_unlock (& ctx -> lock );
1690
+
1691
+ return 0 ;
1692
+ }
1693
+
1694
+ static int __maybe_unused anx7625_runtime_pm_resume (struct device * dev )
1695
+ {
1696
+ struct anx7625_data * ctx = dev_get_drvdata (dev );
1697
+
1698
+ mutex_lock (& ctx -> lock );
1699
+
1700
+ anx7625_power_on_init (ctx );
1701
+ anx7625_hpd_polling (ctx );
1702
+
1703
+ mutex_unlock (& ctx -> lock );
1704
+
1705
+ return 0 ;
1706
+ }
1707
+
1708
+ static const struct dev_pm_ops anx7625_pm_ops = {
1709
+ SET_RUNTIME_PM_OPS (anx7625_runtime_pm_suspend ,
1710
+ anx7625_runtime_pm_resume , NULL )
1711
+ };
1712
+
1738
1713
static int anx7625_i2c_probe (struct i2c_client * client ,
1739
1714
const struct i2c_device_id * id )
1740
1715
{
@@ -1778,8 +1753,6 @@ static int anx7625_i2c_probe(struct i2c_client *client,
1778
1753
}
1779
1754
anx7625_init_gpio (platform );
1780
1755
1781
- atomic_set (& platform -> power_status , 0 );
1782
-
1783
1756
mutex_init (& platform -> lock );
1784
1757
1785
1758
platform -> pdata .intp_irq = client -> irq ;
@@ -1809,9 +1782,11 @@ static int anx7625_i2c_probe(struct i2c_client *client,
1809
1782
goto free_wq ;
1810
1783
}
1811
1784
1812
- if (platform -> pdata .low_power_mode == 0 ) {
1785
+ pm_runtime_enable (dev );
1786
+
1787
+ if (!platform -> pdata .low_power_mode ) {
1813
1788
anx7625_disable_pd_protocol (platform );
1814
- atomic_set ( & platform -> power_status , 1 );
1789
+ pm_runtime_get_sync ( dev );
1815
1790
}
1816
1791
1817
1792
/* Add work function */
@@ -1847,6 +1822,9 @@ static int anx7625_i2c_remove(struct i2c_client *client)
1847
1822
if (platform -> pdata .intp_irq )
1848
1823
destroy_workqueue (platform -> workqueue );
1849
1824
1825
+ if (!platform -> pdata .low_power_mode )
1826
+ pm_runtime_put_sync_suspend (& client -> dev );
1827
+
1850
1828
anx7625_unregister_i2c_dummy_clients (platform );
1851
1829
1852
1830
kfree (platform );
@@ -1869,6 +1847,7 @@ static struct i2c_driver anx7625_driver = {
1869
1847
.driver = {
1870
1848
.name = "anx7625" ,
1871
1849
.of_match_table = anx_match_table ,
1850
+ .pm = & anx7625_pm_ops ,
1872
1851
},
1873
1852
.probe = anx7625_i2c_probe ,
1874
1853
.remove = anx7625_i2c_remove ,
0 commit comments