268
268
#define REG_SSC_CTRL1 0x189
269
269
#define REG_SSC_CTRL2 0x18A
270
270
271
+ #define REG_AUX_USER_CTRL 0x190
272
+ #define EN_USER_AUX BIT(0)
273
+ #define USER_AUX_DONE BIT(1)
274
+ #define AUX_EVENT BIT(4)
275
+
276
+ #define REG_AUX_USER_DATA_REC 0x191
277
+ #define M_AUX_IN_REC 0xF0
278
+ #define M_AUX_OUT_REC 0x0F
279
+
280
+ #define REG_AUX_USER_REPLY 0x19A
281
+ #define REG_AUX_USER_RXB (n ) (n + 0x19B)
282
+
271
283
#define RBR DP_LINK_BW_1_62
272
284
#define HBR DP_LINK_BW_2_7
273
285
#define HBR2 DP_LINK_BW_5_4
303
315
#define MAX_EQ_LEVEL 0x03
304
316
#define AUX_WAIT_TIMEOUT_MS 15
305
317
#define AUX_FIFO_MAX_SIZE 16
318
+ #define AUX_I2C_MAX_SIZE 4
319
+ #define AUX_I2C_DEFER_RETRY 4
306
320
#define PIXEL_CLK_DELAY 1
307
321
#define PIXEL_CLK_INVERSE 0
308
322
#define ADJUST_PHASE_THRESHOLD 80000
325
339
enum aux_cmd_type {
326
340
CMD_AUX_NATIVE_READ = 0x0 ,
327
341
CMD_AUX_NATIVE_WRITE = 0x5 ,
342
+ CMD_AUX_GI2C_ADR = 0x08 ,
343
+ CMD_AUX_GI2C_READ = 0x09 ,
344
+ CMD_AUX_GI2C_WRITE = 0x0A ,
328
345
CMD_AUX_I2C_EDID_READ = 0xB ,
346
+ CMD_AUX_I2C_READ = 0x0D ,
347
+ CMD_AUX_I2C_WRITE = 0x0C ,
329
348
330
349
/* KSV read with AUX FIFO extend from CMD_AUX_NATIVE_READ*/
331
350
CMD_AUX_GET_KSV_LIST = 0x10 ,
@@ -1107,6 +1126,161 @@ static ssize_t it6505_aux_do_transfer(struct it6505 *it6505,
1107
1126
return ret ;
1108
1127
}
1109
1128
1129
+ static bool it6505_aux_i2c_reply_defer (u8 reply )
1130
+ {
1131
+ if (reply == DP_AUX_NATIVE_REPLY_DEFER || reply == DP_AUX_I2C_REPLY_DEFER )
1132
+ return true;
1133
+ return false;
1134
+ }
1135
+
1136
+ static bool it6505_aux_i2c_reply_nack (u8 reply )
1137
+ {
1138
+ if (reply == DP_AUX_NATIVE_REPLY_NACK || reply == DP_AUX_I2C_REPLY_NACK )
1139
+ return true;
1140
+ return false;
1141
+ }
1142
+
1143
+ static int it6505_aux_i2c_wait (struct it6505 * it6505 , u8 * reply )
1144
+ {
1145
+ int err = 0 ;
1146
+ unsigned long timeout ;
1147
+ struct device * dev = it6505 -> dev ;
1148
+
1149
+ timeout = jiffies + msecs_to_jiffies (AUX_WAIT_TIMEOUT_MS ) + 1 ;
1150
+
1151
+ do {
1152
+ if (it6505_read (it6505 , REG_AUX_USER_CTRL ) & AUX_EVENT )
1153
+ break ;
1154
+ if (time_after (jiffies , timeout )) {
1155
+ dev_err (dev , "Timed out waiting AUX I2C, BUSY = %X\n" ,
1156
+ it6505_aux_op_finished (it6505 ));
1157
+ err = - ETIMEDOUT ;
1158
+ goto end_aux_i2c_wait ;
1159
+ }
1160
+ usleep_range (300 , 800 );
1161
+ } while (!it6505_aux_op_finished (it6505 ));
1162
+
1163
+ * reply = it6505_read (it6505 , REG_AUX_USER_REPLY ) >> 4 ;
1164
+
1165
+ if (* reply == 0 )
1166
+ goto end_aux_i2c_wait ;
1167
+
1168
+ if (it6505_aux_i2c_reply_defer (* reply ))
1169
+ err = - EBUSY ;
1170
+ else if (it6505_aux_i2c_reply_nack (* reply ))
1171
+ err = - ENXIO ;
1172
+
1173
+ end_aux_i2c_wait :
1174
+ it6505_set_bits (it6505 , REG_AUX_USER_CTRL , USER_AUX_DONE , USER_AUX_DONE );
1175
+ return err ;
1176
+ }
1177
+
1178
+ static int it6505_aux_i2c_readb (struct it6505 * it6505 , u8 * buf , size_t size , u8 * reply )
1179
+ {
1180
+ int ret , i ;
1181
+ int retry ;
1182
+
1183
+ for (retry = 0 ; retry < AUX_I2C_DEFER_RETRY ; retry ++ ) {
1184
+ it6505_write (it6505 , REG_AUX_CMD_REQ , CMD_AUX_GI2C_READ );
1185
+
1186
+ ret = it6505_aux_i2c_wait (it6505 , reply );
1187
+ if (it6505_aux_i2c_reply_defer (* reply ))
1188
+ continue ;
1189
+ if (ret >= 0 )
1190
+ break ;
1191
+ }
1192
+
1193
+ for (i = 0 ; i < size ; i ++ )
1194
+ buf [i ] = it6505_read (it6505 , REG_AUX_USER_RXB (0 + i ));
1195
+
1196
+ return size ;
1197
+ }
1198
+
1199
+ static int it6505_aux_i2c_writeb (struct it6505 * it6505 , u8 * buf , size_t size , u8 * reply )
1200
+ {
1201
+ int i , ret ;
1202
+ int retry ;
1203
+
1204
+ for (i = 0 ; i < size ; i ++ )
1205
+ it6505_write (it6505 , REG_AUX_OUT_DATA0 + i , buf [i ]);
1206
+
1207
+ for (retry = 0 ; retry < AUX_I2C_DEFER_RETRY ; retry ++ ) {
1208
+ it6505_write (it6505 , REG_AUX_CMD_REQ , CMD_AUX_GI2C_WRITE );
1209
+
1210
+ ret = it6505_aux_i2c_wait (it6505 , reply );
1211
+ if (it6505_aux_i2c_reply_defer (* reply ))
1212
+ continue ;
1213
+ if (ret >= 0 )
1214
+ break ;
1215
+ }
1216
+ return size ;
1217
+ }
1218
+
1219
+ static ssize_t it6505_aux_i2c_operation (struct it6505 * it6505 ,
1220
+ struct drm_dp_aux_msg * msg )
1221
+ {
1222
+ int ret ;
1223
+ ssize_t request_size , data_cnt = 0 ;
1224
+ u8 * buffer = msg -> buffer ;
1225
+
1226
+ /* set AUX user mode */
1227
+ it6505_set_bits (it6505 , REG_AUX_CTRL ,
1228
+ AUX_USER_MODE | AUX_NO_SEGMENT_WR , AUX_USER_MODE );
1229
+ it6505_set_bits (it6505 , REG_AUX_USER_CTRL , EN_USER_AUX , EN_USER_AUX );
1230
+ /* clear AUX FIFO */
1231
+ it6505_set_bits (it6505 , REG_AUX_CTRL ,
1232
+ AUX_EN_FIFO_READ | CLR_EDID_FIFO ,
1233
+ AUX_EN_FIFO_READ | CLR_EDID_FIFO );
1234
+
1235
+ it6505_set_bits (it6505 , REG_AUX_CTRL ,
1236
+ AUX_EN_FIFO_READ | CLR_EDID_FIFO , 0x00 );
1237
+
1238
+ it6505_write (it6505 , REG_AUX_ADR_0_7 , 0x00 );
1239
+ it6505_write (it6505 , REG_AUX_ADR_8_15 , msg -> address << 1 );
1240
+
1241
+ if (msg -> size == 0 ) {
1242
+ /* IIC Start/STOP dummy write */
1243
+ it6505_write (it6505 , REG_AUX_ADR_16_19 , msg -> request );
1244
+ it6505_write (it6505 , REG_AUX_CMD_REQ , CMD_AUX_GI2C_ADR );
1245
+ ret = it6505_aux_i2c_wait (it6505 , & msg -> reply );
1246
+ goto end_aux_i2c_transfer ;
1247
+ }
1248
+
1249
+ /* IIC data transfer */
1250
+ data_cnt = 0 ;
1251
+ do {
1252
+ request_size = min_t (ssize_t , msg -> size - data_cnt , AUX_I2C_MAX_SIZE );
1253
+ it6505_write (it6505 , REG_AUX_ADR_16_19 ,
1254
+ msg -> request | ((request_size - 1 ) << 4 ));
1255
+ if ((msg -> request & DP_AUX_I2C_READ ) == DP_AUX_I2C_READ )
1256
+ ret = it6505_aux_i2c_readb (it6505 , & buffer [data_cnt ],
1257
+ request_size , & msg -> reply );
1258
+ else
1259
+ ret = it6505_aux_i2c_writeb (it6505 , & buffer [data_cnt ],
1260
+ request_size , & msg -> reply );
1261
+
1262
+ if (ret < 0 )
1263
+ goto end_aux_i2c_transfer ;
1264
+
1265
+ data_cnt += request_size ;
1266
+ } while (data_cnt < msg -> size );
1267
+ ret = data_cnt ;
1268
+ end_aux_i2c_transfer :
1269
+
1270
+ it6505_set_bits (it6505 , REG_AUX_USER_CTRL , EN_USER_AUX , 0 );
1271
+ it6505_set_bits (it6505 , REG_AUX_CTRL , AUX_USER_MODE , 0 );
1272
+ return ret ;
1273
+ }
1274
+
1275
+ static ssize_t it6505_aux_i2c_transfer (struct drm_dp_aux * aux ,
1276
+ struct drm_dp_aux_msg * msg )
1277
+ {
1278
+ struct it6505 * it6505 = container_of (aux , struct it6505 , aux );
1279
+
1280
+ guard (mutex )(& it6505 -> aux_lock );
1281
+ return it6505_aux_i2c_operation (it6505 , msg );
1282
+ }
1283
+
1110
1284
static ssize_t it6505_aux_transfer (struct drm_dp_aux * aux ,
1111
1285
struct drm_dp_aux_msg * msg )
1112
1286
{
@@ -1116,9 +1290,8 @@ static ssize_t it6505_aux_transfer(struct drm_dp_aux *aux,
1116
1290
int ret ;
1117
1291
enum aux_cmd_reply reply ;
1118
1292
1119
- /* IT6505 doesn't support arbitrary I2C read / write. */
1120
1293
if (is_i2c )
1121
- return - EINVAL ;
1294
+ return it6505_aux_i2c_transfer ( aux , msg ) ;
1122
1295
1123
1296
switch (msg -> request ) {
1124
1297
case DP_AUX_NATIVE_READ :
0 commit comments