@@ -142,7 +142,8 @@ static int radeon_process_aux_ch(struct radeon_i2c_chan *chan,
142142 return recv_bytes ;
143143}
144144
145- #define HEADER_SIZE 4
145+ #define BARE_ADDRESS_SIZE 3
146+ #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
146147
147148static ssize_t
148149radeon_dp_aux_transfer (struct drm_dp_aux * aux , struct drm_dp_aux_msg * msg )
@@ -160,13 +161,19 @@ radeon_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
160161 tx_buf [0 ] = msg -> address & 0xff ;
161162 tx_buf [1 ] = msg -> address >> 8 ;
162163 tx_buf [2 ] = msg -> request << 4 ;
163- tx_buf [3 ] = msg -> size - 1 ;
164+ tx_buf [3 ] = msg -> size ? ( msg -> size - 1 ) : 0 ;
164165
165166 switch (msg -> request & ~DP_AUX_I2C_MOT ) {
166167 case DP_AUX_NATIVE_WRITE :
167168 case DP_AUX_I2C_WRITE :
169+ /* tx_size needs to be 4 even for bare address packets since the atom
170+ * table needs the info in tx_buf[3].
171+ */
168172 tx_size = HEADER_SIZE + msg -> size ;
169- tx_buf [3 ] |= tx_size << 4 ;
173+ if (msg -> size == 0 )
174+ tx_buf [3 ] |= BARE_ADDRESS_SIZE << 4 ;
175+ else
176+ tx_buf [3 ] |= tx_size << 4 ;
170177 memcpy (tx_buf + HEADER_SIZE , msg -> buffer , msg -> size );
171178 ret = radeon_process_aux_ch (chan ,
172179 tx_buf , tx_size , NULL , 0 , delay , & ack );
@@ -176,8 +183,14 @@ radeon_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
176183 break ;
177184 case DP_AUX_NATIVE_READ :
178185 case DP_AUX_I2C_READ :
186+ /* tx_size needs to be 4 even for bare address packets since the atom
187+ * table needs the info in tx_buf[3].
188+ */
179189 tx_size = HEADER_SIZE ;
180- tx_buf [3 ] |= tx_size << 4 ;
190+ if (msg -> size == 0 )
191+ tx_buf [3 ] |= BARE_ADDRESS_SIZE << 4 ;
192+ else
193+ tx_buf [3 ] |= tx_size << 4 ;
181194 ret = radeon_process_aux_ch (chan ,
182195 tx_buf , tx_size , msg -> buffer , msg -> size , delay , & ack );
183196 break ;
@@ -186,106 +199,23 @@ radeon_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
186199 break ;
187200 }
188201
189- if (ret > 0 )
202+ if (ret >= 0 )
190203 msg -> reply = ack >> 4 ;
191204
192205 return ret ;
193206}
194207
195208void radeon_dp_aux_init (struct radeon_connector * radeon_connector )
196209{
197- struct radeon_connector_atom_dig * dig_connector = radeon_connector -> con_priv ;
198-
199- dig_connector -> dp_i2c_bus -> aux .dev = radeon_connector -> base .kdev ;
200- dig_connector -> dp_i2c_bus -> aux .transfer = radeon_dp_aux_transfer ;
201- }
202-
203- int radeon_dp_i2c_aux_ch (struct i2c_adapter * adapter , int mode ,
204- u8 write_byte , u8 * read_byte )
205- {
206- struct i2c_algo_dp_aux_data * algo_data = adapter -> algo_data ;
207- struct radeon_i2c_chan * auxch = i2c_get_adapdata (adapter );
208- u16 address = algo_data -> address ;
209- u8 msg [5 ];
210- u8 reply [2 ];
211- unsigned retry ;
212- int msg_bytes ;
213- int reply_bytes = 1 ;
214210 int ret ;
215- u8 ack ;
216-
217- /* Set up the address */
218- msg [0 ] = address ;
219- msg [1 ] = address >> 8 ;
220-
221- /* Set up the command byte */
222- if (mode & MODE_I2C_READ ) {
223- msg [2 ] = DP_AUX_I2C_READ << 4 ;
224- msg_bytes = 4 ;
225- msg [3 ] = msg_bytes << 4 ;
226- } else {
227- msg [2 ] = DP_AUX_I2C_WRITE << 4 ;
228- msg_bytes = 5 ;
229- msg [3 ] = msg_bytes << 4 ;
230- msg [4 ] = write_byte ;
231- }
232-
233- /* special handling for start/stop */
234- if (mode & (MODE_I2C_START | MODE_I2C_STOP ))
235- msg [3 ] = 3 << 4 ;
236-
237- /* Set MOT bit for all but stop */
238- if ((mode & MODE_I2C_STOP ) == 0 )
239- msg [2 ] |= DP_AUX_I2C_MOT << 4 ;
240-
241- for (retry = 0 ; retry < 7 ; retry ++ ) {
242- ret = radeon_process_aux_ch (auxch ,
243- msg , msg_bytes , reply , reply_bytes , 0 , & ack );
244- if (ret == - EBUSY )
245- continue ;
246- else if (ret < 0 ) {
247- DRM_DEBUG_KMS ("aux_ch failed %d\n" , ret );
248- return ret ;
249- }
250-
251- switch ((ack >> 4 ) & DP_AUX_NATIVE_REPLY_MASK ) {
252- case DP_AUX_NATIVE_REPLY_ACK :
253- /* I2C-over-AUX Reply field is only valid
254- * when paired with AUX ACK.
255- */
256- break ;
257- case DP_AUX_NATIVE_REPLY_NACK :
258- DRM_DEBUG_KMS ("aux_ch native nack\n" );
259- return - EREMOTEIO ;
260- case DP_AUX_NATIVE_REPLY_DEFER :
261- DRM_DEBUG_KMS ("aux_ch native defer\n" );
262- usleep_range (500 , 600 );
263- continue ;
264- default :
265- DRM_ERROR ("aux_ch invalid native reply 0x%02x\n" , ack );
266- return - EREMOTEIO ;
267- }
268211
269- switch ((ack >> 4 ) & DP_AUX_I2C_REPLY_MASK ) {
270- case DP_AUX_I2C_REPLY_ACK :
271- if (mode == MODE_I2C_READ )
272- * read_byte = reply [0 ];
273- return ret ;
274- case DP_AUX_I2C_REPLY_NACK :
275- DRM_DEBUG_KMS ("aux_i2c nack\n" );
276- return - EREMOTEIO ;
277- case DP_AUX_I2C_REPLY_DEFER :
278- DRM_DEBUG_KMS ("aux_i2c defer\n" );
279- usleep_range (400 , 500 );
280- break ;
281- default :
282- DRM_ERROR ("aux_i2c invalid reply 0x%02x\n" , ack );
283- return - EREMOTEIO ;
284- }
285- }
212+ radeon_connector -> ddc_bus -> aux .dev = radeon_connector -> base .kdev ;
213+ radeon_connector -> ddc_bus -> aux .transfer = radeon_dp_aux_transfer ;
214+ ret = drm_dp_aux_register_i2c_bus (& radeon_connector -> ddc_bus -> aux );
215+ if (!ret )
216+ radeon_connector -> ddc_bus -> has_aux = true;
286217
287- DRM_DEBUG_KMS ("aux i2c too many retries, giving up\n" );
288- return - EREMOTEIO ;
218+ WARN (ret , "drm_dp_aux_register_i2c_bus() failed with error %d\n" , ret );
289219}
290220
291221/***** general DP utility functions *****/
@@ -420,12 +350,11 @@ static u8 radeon_dp_encoder_service(struct radeon_device *rdev,
420350
421351u8 radeon_dp_getsinktype (struct radeon_connector * radeon_connector )
422352{
423- struct radeon_connector_atom_dig * dig_connector = radeon_connector -> con_priv ;
424353 struct drm_device * dev = radeon_connector -> base .dev ;
425354 struct radeon_device * rdev = dev -> dev_private ;
426355
427356 return radeon_dp_encoder_service (rdev , ATOM_DP_ACTION_GET_SINK_TYPE , 0 ,
428- dig_connector -> dp_i2c_bus -> rec .i2c_id , 0 );
357+ radeon_connector -> ddc_bus -> rec .i2c_id , 0 );
429358}
430359
431360static void radeon_dp_probe_oui (struct radeon_connector * radeon_connector )
@@ -436,11 +365,11 @@ static void radeon_dp_probe_oui(struct radeon_connector *radeon_connector)
436365 if (!(dig_connector -> dpcd [DP_DOWN_STREAM_PORT_COUNT ] & DP_OUI_SUPPORT ))
437366 return ;
438367
439- if (drm_dp_dpcd_read (& dig_connector -> dp_i2c_bus -> aux , DP_SINK_OUI , buf , 3 ))
368+ if (drm_dp_dpcd_read (& radeon_connector -> ddc_bus -> aux , DP_SINK_OUI , buf , 3 ))
440369 DRM_DEBUG_KMS ("Sink OUI: %02hx%02hx%02hx\n" ,
441370 buf [0 ], buf [1 ], buf [2 ]);
442371
443- if (drm_dp_dpcd_read (& dig_connector -> dp_i2c_bus -> aux , DP_BRANCH_OUI , buf , 3 ))
372+ if (drm_dp_dpcd_read (& radeon_connector -> ddc_bus -> aux , DP_BRANCH_OUI , buf , 3 ))
444373 DRM_DEBUG_KMS ("Branch OUI: %02hx%02hx%02hx\n" ,
445374 buf [0 ], buf [1 ], buf [2 ]);
446375}
@@ -451,7 +380,7 @@ bool radeon_dp_getdpcd(struct radeon_connector *radeon_connector)
451380 u8 msg [DP_DPCD_SIZE ];
452381 int ret , i ;
453382
454- ret = drm_dp_dpcd_read (& dig_connector -> dp_i2c_bus -> aux , DP_DPCD_REV , msg ,
383+ ret = drm_dp_dpcd_read (& radeon_connector -> ddc_bus -> aux , DP_DPCD_REV , msg ,
455384 DP_DPCD_SIZE );
456385 if (ret > 0 ) {
457386 memcpy (dig_connector -> dpcd , msg , DP_DPCD_SIZE );
@@ -489,7 +418,7 @@ int radeon_dp_get_panel_mode(struct drm_encoder *encoder,
489418
490419 if (dp_bridge != ENCODER_OBJECT_ID_NONE ) {
491420 /* DP bridge chips */
492- drm_dp_dpcd_readb (& dig_connector -> dp_i2c_bus -> aux ,
421+ drm_dp_dpcd_readb (& radeon_connector -> ddc_bus -> aux ,
493422 DP_EDP_CONFIGURATION_CAP , & tmp );
494423 if (tmp & 1 )
495424 panel_mode = DP_PANEL_MODE_INTERNAL_DP2_MODE ;
@@ -500,7 +429,7 @@ int radeon_dp_get_panel_mode(struct drm_encoder *encoder,
500429 panel_mode = DP_PANEL_MODE_EXTERNAL_DP_MODE ;
501430 } else if (connector -> connector_type == DRM_MODE_CONNECTOR_eDP ) {
502431 /* eDP */
503- drm_dp_dpcd_readb (& dig_connector -> dp_i2c_bus -> aux ,
432+ drm_dp_dpcd_readb (& radeon_connector -> ddc_bus -> aux ,
504433 DP_EDP_CONFIGURATION_CAP , & tmp );
505434 if (tmp & 1 )
506435 panel_mode = DP_PANEL_MODE_INTERNAL_DP2_MODE ;
@@ -554,7 +483,8 @@ bool radeon_dp_needs_link_train(struct radeon_connector *radeon_connector)
554483 u8 link_status [DP_LINK_STATUS_SIZE ];
555484 struct radeon_connector_atom_dig * dig = radeon_connector -> con_priv ;
556485
557- if (drm_dp_dpcd_read_link_status (& dig -> dp_i2c_bus -> aux , link_status ) <= 0 )
486+ if (drm_dp_dpcd_read_link_status (& radeon_connector -> ddc_bus -> aux , link_status )
487+ <= 0 )
558488 return false;
559489 if (drm_dp_channel_eq_ok (link_status , dig -> dp_lane_count ))
560490 return false;
@@ -574,7 +504,7 @@ void radeon_dp_set_rx_power_state(struct drm_connector *connector,
574504
575505 /* power up/down the sink */
576506 if (dig_connector -> dpcd [0 ] >= 0x11 ) {
577- drm_dp_dpcd_writeb (& dig_connector -> dp_i2c_bus -> aux ,
507+ drm_dp_dpcd_writeb (& radeon_connector -> ddc_bus -> aux ,
578508 DP_SET_POWER , power_state );
579509 usleep_range (1000 , 2000 );
580510 }
@@ -878,7 +808,7 @@ void radeon_dp_link_train(struct drm_encoder *encoder,
878808 else
879809 dp_info .enc_id |= ATOM_DP_CONFIG_LINK_A ;
880810
881- drm_dp_dpcd_readb (& dig_connector -> dp_i2c_bus -> aux , DP_MAX_LANE_COUNT , & tmp );
811+ drm_dp_dpcd_readb (& radeon_connector -> ddc_bus -> aux , DP_MAX_LANE_COUNT , & tmp );
882812 if (ASIC_IS_DCE5 (rdev ) && (tmp & DP_TPS3_SUPPORTED ))
883813 dp_info .tp3_supported = true;
884814 else
@@ -890,7 +820,7 @@ void radeon_dp_link_train(struct drm_encoder *encoder,
890820 dp_info .connector = connector ;
891821 dp_info .dp_lane_count = dig_connector -> dp_lane_count ;
892822 dp_info .dp_clock = dig_connector -> dp_clock ;
893- dp_info .aux = & dig_connector -> dp_i2c_bus -> aux ;
823+ dp_info .aux = & radeon_connector -> ddc_bus -> aux ;
894824
895825 if (radeon_dp_link_train_init (& dp_info ))
896826 goto done ;
0 commit comments