Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/bridge: adv7511: switch to the HDMI connector helpers

Rewrite the ADV7511 driver to use implementation provided by the DRM
HDMI connector framework, including the Audio and CEC bits. Drop the
in-bridge connector support and use drm_bridge_connector if the host
requires the connector to be provided by the bridge.

Note: currently only AVI InfoFrames are supported. Existing driver
doesn't support programming any other InfoFrames directly and Audio
InfoFrame seems to be programmed using individual bits and pieces rather
than programming it directly.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
Link: https://lore.kernel.org/r/20250517-drm-hdmi-connector-cec-v6-10-35651db6f19b@oss.qualcomm.com
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>

+212 -328
+4 -1
drivers/gpu/drm/bridge/adv7511/Kconfig
··· 5 5 select DRM_KMS_HELPER 6 6 select REGMAP_I2C 7 7 select DRM_MIPI_DSI 8 + select DRM_DISPLAY_HELPER 9 + select DRM_BRIDGE_CONNECTOR 10 + select DRM_DISPLAY_HDMI_STATE_HELPER 8 11 help 9 12 Support for the Analog Devices ADV7511(W)/13/33/35 HDMI encoders. 10 13 ··· 22 19 config DRM_I2C_ADV7511_CEC 23 20 bool "ADV7511/33/35 HDMI CEC driver" 24 21 depends on DRM_I2C_ADV7511 25 - select CEC_CORE 22 + select DRM_DISPLAY_HDMI_CEC_HELPER 26 23 default y 27 24 help 28 25 When selected the HDMI transmitter will support the CEC feature.
+28 -24
drivers/gpu/drm/bridge/adv7511/adv7511.h
··· 313 313 * @csc_enable: Whether to enable color space conversion 314 314 * @csc_scaling_factor: Color space conversion scaling factor 315 315 * @csc_coefficents: Color space conversion coefficents 316 - * @hdmi_mode: Whether to use HDMI or DVI output mode 317 - * @avi_infoframe: HDMI infoframe 318 316 */ 319 317 struct adv7511_video_config { 320 318 bool csc_enable; 321 319 enum adv7511_csc_scaling csc_scaling_factor; 322 320 const uint16_t *csc_coefficents; 323 - 324 - bool hdmi_mode; 325 - struct hdmi_avi_infoframe avi_infoframe; 326 321 }; 327 322 328 323 enum adv7511_type { ··· 332 337 enum adv7511_type type; 333 338 unsigned int max_mode_clock_khz; 334 339 unsigned int max_lane_freq_khz; 340 + const char *name; 335 341 const char * const *supply_names; 336 342 unsigned int num_supplies; 337 343 unsigned int reg_cec_offset; ··· 367 371 struct work_struct hpd_work; 368 372 369 373 struct drm_bridge bridge; 370 - struct drm_connector connector; 374 + struct drm_connector *cec_connector; 371 375 372 376 bool embedded_sync; 373 377 enum adv7511_sync_polarity vsync_polarity; ··· 385 389 bool use_timing_gen; 386 390 387 391 const struct adv7511_chip_info *info; 388 - struct platform_device *audio_pdev; 389 392 390 - struct cec_adapter *cec_adap; 391 393 u8 cec_addr[ADV7511_MAX_ADDRS]; 392 394 u8 cec_valid_addrs; 393 395 bool cec_enabled_adap; ··· 393 399 u32 cec_clk_freq; 394 400 }; 395 401 402 + static inline struct adv7511 *bridge_to_adv7511(struct drm_bridge *bridge) 403 + { 404 + return container_of(bridge, struct adv7511, bridge); 405 + } 406 + 396 407 #ifdef CONFIG_DRM_I2C_ADV7511_CEC 397 - int adv7511_cec_init(struct device *dev, struct adv7511 *adv7511); 408 + int adv7511_cec_init(struct drm_connector *connector, 409 + struct drm_bridge *bridge); 410 + int adv7511_cec_enable(struct drm_bridge *bridge, bool enable); 411 + int adv7511_cec_log_addr(struct drm_bridge *bridge, u8 addr); 412 + int adv7511_cec_transmit(struct drm_bridge *bridge, u8 attempts, 413 + u32 signal_free_time, struct cec_msg *msg); 398 414 int adv7511_cec_irq_process(struct adv7511 *adv7511, unsigned int irq1); 399 415 #else 400 - static inline int adv7511_cec_init(struct device *dev, struct adv7511 *adv7511) 401 - { 402 - regmap_write(adv7511->regmap, ADV7511_REG_CEC_CTRL, 403 - ADV7511_CEC_CTRL_POWER_DOWN); 404 - return 0; 405 - } 416 + #define adv7511_cec_init NULL 417 + #define adv7511_cec_enable NULL 418 + #define adv7511_cec_log_addr NULL 419 + #define adv7511_cec_transmit NULL 406 420 #endif 407 421 408 422 void adv7533_dsi_power_on(struct adv7511 *adv); ··· 423 421 int adv7533_parse_dt(struct device_node *np, struct adv7511 *adv); 424 422 425 423 #ifdef CONFIG_DRM_I2C_ADV7511_AUDIO 426 - int adv7511_audio_init(struct device *dev, struct adv7511 *adv7511); 427 - void adv7511_audio_exit(struct adv7511 *adv7511); 424 + int adv7511_hdmi_audio_startup(struct drm_connector *connector, 425 + struct drm_bridge *bridge); 426 + void adv7511_hdmi_audio_shutdown(struct drm_connector *connector, 427 + struct drm_bridge *bridge); 428 + int adv7511_hdmi_audio_prepare(struct drm_connector *connector, 429 + struct drm_bridge *bridge, 430 + struct hdmi_codec_daifmt *fmt, 431 + struct hdmi_codec_params *hparms); 428 432 #else /*CONFIG_DRM_I2C_ADV7511_AUDIO */ 429 - static inline int adv7511_audio_init(struct device *dev, struct adv7511 *adv7511) 430 - { 431 - return 0; 432 - } 433 - static inline void adv7511_audio_exit(struct adv7511 *adv7511) 434 - { 435 - } 433 + #define adv7511_hdmi_audio_startup NULL 434 + #define adv7511_hdmi_audio_shutdown NULL 435 + #define adv7511_hdmi_audio_prepare NULL 436 436 #endif /* CONFIG_DRM_I2C_ADV7511_AUDIO */ 437 437 438 438 #endif /* __DRM_I2C_ADV7511_H__ */
+11 -66
drivers/gpu/drm/bridge/adv7511/adv7511_audio.c
··· 55 55 return 0; 56 56 } 57 57 58 - static int adv7511_hdmi_hw_params(struct device *dev, void *data, 59 - struct hdmi_codec_daifmt *fmt, 60 - struct hdmi_codec_params *hparms) 58 + int adv7511_hdmi_audio_prepare(struct drm_connector *connector, 59 + struct drm_bridge *bridge, 60 + struct hdmi_codec_daifmt *fmt, 61 + struct hdmi_codec_params *hparms) 61 62 { 62 - struct adv7511 *adv7511 = dev_get_drvdata(dev); 63 + struct adv7511 *adv7511 = bridge_to_adv7511(bridge); 63 64 unsigned int audio_source, i2s_format = 0; 64 65 unsigned int invert_clock; 65 66 unsigned int rate; ··· 168 167 return 0; 169 168 } 170 169 171 - static int audio_startup(struct device *dev, void *data) 170 + int adv7511_hdmi_audio_startup(struct drm_connector *connector, 171 + struct drm_bridge *bridge) 172 172 { 173 - struct adv7511 *adv7511 = dev_get_drvdata(dev); 173 + struct adv7511 *adv7511 = bridge_to_adv7511(bridge); 174 174 175 175 regmap_update_bits(adv7511->regmap, ADV7511_REG_AUDIO_CONFIG, 176 176 BIT(7), 0); ··· 206 204 return 0; 207 205 } 208 206 209 - static void audio_shutdown(struct device *dev, void *data) 207 + void adv7511_hdmi_audio_shutdown(struct drm_connector *connector, 208 + struct drm_bridge *bridge) 210 209 { 211 - struct adv7511 *adv7511 = dev_get_drvdata(dev); 210 + struct adv7511 *adv7511 = bridge_to_adv7511(bridge); 212 211 213 212 if (adv7511->audio_source == ADV7511_AUDIO_SOURCE_SPDIF) 214 213 regmap_update_bits(adv7511->regmap, ADV7511_REG_AUDIO_CONFIG, 215 214 BIT(7), 0); 216 - } 217 - 218 - static int adv7511_hdmi_i2s_get_dai_id(struct snd_soc_component *component, 219 - struct device_node *endpoint, 220 - void *data) 221 - { 222 - struct of_endpoint of_ep; 223 - int ret; 224 - 225 - ret = of_graph_parse_endpoint(endpoint, &of_ep); 226 - if (ret < 0) 227 - return ret; 228 - 229 - /* 230 - * HDMI sound should be located as reg = <2> 231 - * Then, it is sound port 0 232 - */ 233 - if (of_ep.port == 2) 234 - return 0; 235 - 236 - return -EINVAL; 237 - } 238 - 239 - static const struct hdmi_codec_ops adv7511_codec_ops = { 240 - .hw_params = adv7511_hdmi_hw_params, 241 - .audio_shutdown = audio_shutdown, 242 - .audio_startup = audio_startup, 243 - .get_dai_id = adv7511_hdmi_i2s_get_dai_id, 244 - }; 245 - 246 - static const struct hdmi_codec_pdata codec_data = { 247 - .ops = &adv7511_codec_ops, 248 - .i2s_formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | 249 - SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_LE | 250 - SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE), 251 - .max_i2s_channels = 2, 252 - .i2s = 1, 253 - .no_i2s_capture = 1, 254 - .spdif = 1, 255 - .no_spdif_capture = 1, 256 - }; 257 - 258 - int adv7511_audio_init(struct device *dev, struct adv7511 *adv7511) 259 - { 260 - adv7511->audio_pdev = platform_device_register_data(dev, 261 - HDMI_CODEC_DRV_NAME, 262 - PLATFORM_DEVID_AUTO, 263 - &codec_data, 264 - sizeof(codec_data)); 265 - return PTR_ERR_OR_ZERO(adv7511->audio_pdev); 266 - } 267 - 268 - void adv7511_audio_exit(struct adv7511 *adv7511) 269 - { 270 - if (adv7511->audio_pdev) { 271 - platform_device_unregister(adv7511->audio_pdev); 272 - adv7511->audio_pdev = NULL; 273 - } 274 215 }
+22 -35
drivers/gpu/drm/bridge/adv7511/adv7511_cec.c
··· 12 12 13 13 #include <media/cec.h> 14 14 15 + #include <drm/display/drm_hdmi_cec_helper.h> 16 + 15 17 #include "adv7511.h" 16 18 17 19 static const u8 ADV7511_REG_CEC_RX_FRAME_HDR[] = { ··· 46 44 return; 47 45 48 46 if (tx_raw_status & ADV7511_INT1_CEC_TX_ARBIT_LOST) { 49 - cec_transmit_attempt_done(adv7511->cec_adap, 50 - CEC_TX_STATUS_ARB_LOST); 47 + drm_connector_hdmi_cec_transmit_attempt_done(adv7511->cec_connector, 48 + CEC_TX_STATUS_ARB_LOST); 51 49 return; 52 50 } 53 51 if (tx_raw_status & ADV7511_INT1_CEC_TX_RETRY_TIMEOUT) { ··· 74 72 if (low_drive_cnt) 75 73 status |= CEC_TX_STATUS_LOW_DRIVE; 76 74 } 77 - cec_transmit_done(adv7511->cec_adap, status, 78 - 0, nack_cnt, low_drive_cnt, err_cnt); 75 + drm_connector_hdmi_cec_transmit_done(adv7511->cec_connector, status, 76 + 0, nack_cnt, low_drive_cnt, 77 + err_cnt); 79 78 return; 80 79 } 81 80 if (tx_raw_status & ADV7511_INT1_CEC_TX_READY) { 82 - cec_transmit_attempt_done(adv7511->cec_adap, CEC_TX_STATUS_OK); 81 + drm_connector_hdmi_cec_transmit_attempt_done(adv7511->cec_connector, 82 + CEC_TX_STATUS_OK); 83 83 return; 84 84 } 85 85 } ··· 120 116 regmap_update_bits(adv7511->regmap_cec, 121 117 ADV7511_REG_CEC_RX_BUFFERS + offset, BIT(rx_buf), 0); 122 118 123 - cec_received_msg(adv7511->cec_adap, &msg); 119 + drm_connector_hdmi_cec_received_msg(adv7511->cec_connector, &msg); 124 120 } 125 121 126 122 int adv7511_cec_irq_process(struct adv7511 *adv7511, unsigned int irq1) ··· 183 179 return IRQ_HANDLED; 184 180 } 185 181 186 - static int adv7511_cec_adap_enable(struct cec_adapter *adap, bool enable) 182 + int adv7511_cec_enable(struct drm_bridge *bridge, bool enable) 187 183 { 188 - struct adv7511 *adv7511 = cec_get_drvdata(adap); 184 + struct adv7511 *adv7511 = bridge_to_adv7511(bridge); 189 185 unsigned int offset = adv7511->info->reg_cec_offset; 190 186 191 187 if (adv7511->i2c_cec == NULL) ··· 229 225 return 0; 230 226 } 231 227 232 - static int adv7511_cec_adap_log_addr(struct cec_adapter *adap, u8 addr) 228 + int adv7511_cec_log_addr(struct drm_bridge *bridge, u8 addr) 233 229 { 234 - struct adv7511 *adv7511 = cec_get_drvdata(adap); 230 + struct adv7511 *adv7511 = bridge_to_adv7511(bridge); 235 231 unsigned int offset = adv7511->info->reg_cec_offset; 236 232 unsigned int i, free_idx = ADV7511_MAX_ADDRS; 237 233 ··· 297 293 return 0; 298 294 } 299 295 300 - static int adv7511_cec_adap_transmit(struct cec_adapter *adap, u8 attempts, 301 - u32 signal_free_time, struct cec_msg *msg) 296 + int adv7511_cec_transmit(struct drm_bridge *bridge, u8 attempts, 297 + u32 signal_free_time, struct cec_msg *msg) 302 298 { 303 - struct adv7511 *adv7511 = cec_get_drvdata(adap); 299 + struct adv7511 *adv7511 = bridge_to_adv7511(bridge); 304 300 unsigned int offset = adv7511->info->reg_cec_offset; 305 301 u8 len = msg->len; 306 302 unsigned int i; ··· 332 328 return 0; 333 329 } 334 330 335 - static const struct cec_adap_ops adv7511_cec_adap_ops = { 336 - .adap_enable = adv7511_cec_adap_enable, 337 - .adap_log_addr = adv7511_cec_adap_log_addr, 338 - .adap_transmit = adv7511_cec_adap_transmit, 339 - }; 340 - 341 331 static int adv7511_cec_parse_dt(struct device *dev, struct adv7511 *adv7511) 342 332 { 343 333 adv7511->cec_clk = devm_clk_get(dev, "cec"); ··· 346 348 return 0; 347 349 } 348 350 349 - int adv7511_cec_init(struct device *dev, struct adv7511 *adv7511) 351 + int adv7511_cec_init(struct drm_connector *connector, 352 + struct drm_bridge *bridge) 350 353 { 354 + struct adv7511 *adv7511 = bridge_to_adv7511(bridge); 355 + struct device *dev = &adv7511->i2c_main->dev; 351 356 unsigned int offset = adv7511->info->reg_cec_offset; 352 357 int ret = adv7511_cec_parse_dt(dev, adv7511); 353 358 354 359 if (ret) 355 360 goto err_cec_parse_dt; 356 361 357 - adv7511->cec_adap = cec_allocate_adapter(&adv7511_cec_adap_ops, 358 - adv7511, dev_name(dev), CEC_CAP_DEFAULTS, ADV7511_MAX_ADDRS); 359 - if (IS_ERR(adv7511->cec_adap)) { 360 - ret = PTR_ERR(adv7511->cec_adap); 361 - goto err_cec_alloc; 362 - } 362 + adv7511->cec_connector = connector; 363 363 364 364 regmap_write(adv7511->regmap, ADV7511_REG_CEC_CTRL, 0); 365 365 /* cec soft reset */ ··· 374 378 ADV7511_REG_CEC_CLK_DIV + offset, 375 379 ((adv7511->cec_clk_freq / 750000) - 1) << 2); 376 380 377 - ret = cec_register_adapter(adv7511->cec_adap, dev); 378 - if (ret) 379 - goto err_cec_register; 380 381 return 0; 381 382 382 - err_cec_register: 383 - cec_delete_adapter(adv7511->cec_adap); 384 - adv7511->cec_adap = NULL; 385 - err_cec_alloc: 386 - dev_info(dev, "Initializing CEC failed with error %d, disabling CEC\n", 387 - ret); 388 383 err_cec_parse_dt: 389 384 regmap_write(adv7511->regmap, ADV7511_REG_CEC_CTRL, 390 385 ADV7511_CEC_CTRL_POWER_DOWN);
+147 -198
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
··· 12 12 #include <linux/of.h> 13 13 #include <linux/slab.h> 14 14 15 - #include <media/cec.h> 15 + #include <sound/pcm.h> 16 16 17 17 #include <drm/drm_atomic.h> 18 18 #include <drm/drm_atomic_helper.h> 19 + #include <drm/drm_bridge_connector.h> 19 20 #include <drm/drm_edid.h> 20 21 #include <drm/drm_of.h> 21 22 #include <drm/drm_print.h> 22 23 #include <drm/drm_probe_helper.h> 24 + #include <drm/display/drm_hdmi_helper.h> 25 + #include <drm/display/drm_hdmi_state_helper.h> 23 26 24 27 #include "adv7511.h" 25 28 ··· 206 203 207 204 static void adv7511_set_config_csc(struct adv7511 *adv7511, 208 205 struct drm_connector *connector, 209 - bool rgb, bool hdmi_mode) 206 + bool rgb) 210 207 { 211 208 struct adv7511_video_config config; 212 209 bool output_format_422, output_format_ycbcr; 213 210 unsigned int mode; 214 - uint8_t infoframe[17]; 215 - 216 - config.hdmi_mode = hdmi_mode; 217 - 218 - hdmi_avi_infoframe_init(&config.avi_infoframe); 219 - 220 - config.avi_infoframe.scan_mode = HDMI_SCAN_MODE_UNDERSCAN; 221 211 222 212 if (rgb) { 223 213 config.csc_enable = false; 224 - config.avi_infoframe.colorspace = HDMI_COLORSPACE_RGB; 214 + output_format_422 = false; 215 + output_format_ycbcr = false; 225 216 } else { 226 217 config.csc_scaling_factor = ADV7511_CSC_SCALING_4; 227 218 config.csc_coefficents = adv7511_csc_ycbcr_to_rgb; 228 219 229 220 if ((connector->display_info.color_formats & 230 221 DRM_COLOR_FORMAT_YCBCR422) && 231 - config.hdmi_mode) { 222 + connector->display_info.is_hdmi) { 232 223 config.csc_enable = false; 233 - config.avi_infoframe.colorspace = 234 - HDMI_COLORSPACE_YUV422; 235 - } else { 236 - config.csc_enable = true; 237 - config.avi_infoframe.colorspace = HDMI_COLORSPACE_RGB; 238 - } 239 - } 240 - 241 - if (config.hdmi_mode) { 242 - mode = ADV7511_HDMI_CFG_MODE_HDMI; 243 - 244 - switch (config.avi_infoframe.colorspace) { 245 - case HDMI_COLORSPACE_YUV444: 246 - output_format_422 = false; 247 - output_format_ycbcr = true; 248 - break; 249 - case HDMI_COLORSPACE_YUV422: 250 224 output_format_422 = true; 251 225 output_format_ycbcr = true; 252 - break; 253 - default: 226 + } else { 227 + config.csc_enable = true; 254 228 output_format_422 = false; 255 229 output_format_ycbcr = false; 256 - break; 257 230 } 258 - } else { 259 - mode = ADV7511_HDMI_CFG_MODE_DVI; 260 - output_format_422 = false; 261 - output_format_ycbcr = false; 262 231 } 263 232 264 - adv7511_packet_disable(adv7511, ADV7511_PACKET_ENABLE_AVI_INFOFRAME); 233 + if (connector->display_info.is_hdmi) 234 + mode = ADV7511_HDMI_CFG_MODE_HDMI; 235 + else 236 + mode = ADV7511_HDMI_CFG_MODE_DVI; 265 237 266 238 adv7511_set_colormap(adv7511, config.csc_enable, 267 239 config.csc_coefficents, ··· 247 269 248 270 regmap_update_bits(adv7511->regmap, ADV7511_REG_HDCP_HDMI_CFG, 249 271 ADV7511_HDMI_CFG_MODE_MASK, mode); 250 - 251 - hdmi_avi_infoframe_pack(&config.avi_infoframe, infoframe, 252 - sizeof(infoframe)); 253 - 254 - /* The AVI infoframe id is not configurable */ 255 - regmap_bulk_write(adv7511->regmap, ADV7511_REG_AVI_INFOFRAME_VERSION, 256 - infoframe + 1, sizeof(infoframe) - 1); 257 - 258 - adv7511_packet_enable(adv7511, ADV7511_PACKET_ENABLE_AVI_INFOFRAME); 259 272 } 260 273 261 274 static void adv7511_set_link_config(struct adv7511 *adv7511, ··· 415 446 * restore its state. 416 447 */ 417 448 if (status == connector_status_connected && 418 - adv7511->connector.status == connector_status_disconnected && 449 + adv7511->status == connector_status_disconnected && 419 450 adv7511->powered) { 420 451 regcache_mark_dirty(adv7511->regmap); 421 452 adv7511_power_on(adv7511); 422 453 } 423 454 424 - if (adv7511->connector.status != status) { 425 - adv7511->connector.status = status; 455 + if (adv7511->status != status) { 456 + adv7511->status = status; 426 457 427 - if (adv7511->connector.dev) { 428 - if (status == connector_status_disconnected) 429 - cec_phys_addr_invalidate(adv7511->cec_adap); 430 - drm_kms_helper_hotplug_event(adv7511->connector.dev); 431 - } else { 432 - drm_bridge_hpd_notify(&adv7511->bridge, status); 433 - } 458 + drm_bridge_hpd_notify(&adv7511->bridge, status); 434 459 } 435 460 } 436 461 ··· 599 636 if (!adv7511->powered) 600 637 __adv7511_power_off(adv7511); 601 638 602 - if (drm_edid) { 603 - /* 604 - * FIXME: The CEC physical address should be set using 605 - * cec_s_phys_addr(adap, 606 - * connector->display_info.source_physical_address, false) from 607 - * a path that has read the EDID and called 608 - * drm_edid_connector_update(). 609 - */ 610 - const struct edid *edid = drm_edid_raw(drm_edid); 611 - 612 - adv7511_set_config_csc(adv7511, connector, adv7511->rgb, 613 - drm_detect_hdmi_monitor(edid)); 614 - 615 - cec_s_phys_addr_from_edid(adv7511->cec_adap, edid); 616 - } else { 617 - cec_s_phys_addr_from_edid(adv7511->cec_adap, NULL); 618 - } 619 - 620 639 return drm_edid; 621 640 } 622 641 623 - static int adv7511_get_modes(struct adv7511 *adv7511, 624 - struct drm_connector *connector) 625 - { 626 - const struct drm_edid *drm_edid; 627 - unsigned int count; 628 - 629 - drm_edid = adv7511_edid_read(adv7511, connector); 630 - 631 - drm_edid_connector_update(connector, drm_edid); 632 - count = drm_edid_connector_add_modes(connector); 633 - 634 - drm_edid_free(drm_edid); 635 - 636 - return count; 637 - } 638 - 639 642 static enum drm_connector_status 640 - adv7511_detect(struct adv7511 *adv7511, struct drm_connector *connector) 643 + adv7511_detect(struct adv7511 *adv7511) 641 644 { 642 645 enum drm_connector_status status; 643 646 unsigned int val; ··· 628 699 if (status == connector_status_connected && hpd && adv7511->powered) { 629 700 regcache_mark_dirty(adv7511->regmap); 630 701 adv7511_power_on(adv7511); 631 - if (connector) 632 - adv7511_get_modes(adv7511, connector); 633 702 if (adv7511->status == connector_status_connected) 634 703 status = connector_status_disconnected; 635 704 } else { ··· 646 719 return status; 647 720 } 648 721 649 - static enum drm_mode_status adv7511_mode_valid(struct adv7511 *adv7511, 650 - const struct drm_display_mode *mode) 651 - { 652 - if (mode->clock > 165000) 653 - return MODE_CLOCK_HIGH; 654 - 655 - return MODE_OK; 656 - } 657 - 658 722 static void adv7511_mode_set(struct adv7511 *adv7511, 659 - const struct drm_display_mode *mode, 660 723 const struct drm_display_mode *adj_mode) 661 724 { 662 725 unsigned int low_refresh_rate; ··· 717 800 vsync_polarity = 1; 718 801 } 719 802 720 - if (drm_mode_vrefresh(mode) <= 24) 803 + if (drm_mode_vrefresh(adj_mode) <= 24) 721 804 low_refresh_rate = ADV7511_LOW_REFRESH_RATE_24HZ; 722 - else if (drm_mode_vrefresh(mode) <= 25) 805 + else if (drm_mode_vrefresh(adj_mode) <= 25) 723 806 low_refresh_rate = ADV7511_LOW_REFRESH_RATE_25HZ; 724 - else if (drm_mode_vrefresh(mode) <= 30) 807 + else if (drm_mode_vrefresh(adj_mode) <= 30) 725 808 low_refresh_rate = ADV7511_LOW_REFRESH_RATE_30HZ; 726 809 else 727 810 low_refresh_rate = ADV7511_LOW_REFRESH_RATE_NONE; ··· 743 826 * supposed to give better results. 744 827 */ 745 828 746 - adv7511->f_tmds = mode->clock; 829 + adv7511->f_tmds = adj_mode->clock; 747 830 } 748 - 749 - /* ----------------------------------------------------------------------------- 750 - * DRM Connector Operations 751 - */ 752 - 753 - static struct adv7511 *connector_to_adv7511(struct drm_connector *connector) 754 - { 755 - return container_of(connector, struct adv7511, connector); 756 - } 757 - 758 - static int adv7511_connector_get_modes(struct drm_connector *connector) 759 - { 760 - struct adv7511 *adv = connector_to_adv7511(connector); 761 - 762 - return adv7511_get_modes(adv, connector); 763 - } 764 - 765 - static enum drm_mode_status 766 - adv7511_connector_mode_valid(struct drm_connector *connector, 767 - const struct drm_display_mode *mode) 768 - { 769 - struct adv7511 *adv = connector_to_adv7511(connector); 770 - 771 - return adv7511_mode_valid(adv, mode); 772 - } 773 - 774 - static struct drm_connector_helper_funcs adv7511_connector_helper_funcs = { 775 - .get_modes = adv7511_connector_get_modes, 776 - .mode_valid = adv7511_connector_mode_valid, 777 - }; 778 - 779 - static enum drm_connector_status 780 - adv7511_connector_detect(struct drm_connector *connector, bool force) 781 - { 782 - struct adv7511 *adv = connector_to_adv7511(connector); 783 - 784 - return adv7511_detect(adv, connector); 785 - } 786 - 787 - static const struct drm_connector_funcs adv7511_connector_funcs = { 788 - .fill_modes = drm_helper_probe_single_connector_modes, 789 - .detect = adv7511_connector_detect, 790 - .destroy = drm_connector_cleanup, 791 - .reset = drm_atomic_helper_connector_reset, 792 - .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 793 - .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 794 - }; 795 831 796 832 static int adv7511_connector_init(struct adv7511 *adv) 797 833 { 798 834 struct drm_bridge *bridge = &adv->bridge; 799 - int ret; 835 + struct drm_connector *connector; 800 836 801 - if (adv->i2c_main->irq) 802 - adv->connector.polled = DRM_CONNECTOR_POLL_HPD; 803 - else 804 - adv->connector.polled = DRM_CONNECTOR_POLL_CONNECT | 805 - DRM_CONNECTOR_POLL_DISCONNECT; 806 - 807 - ret = drm_connector_init(bridge->dev, &adv->connector, 808 - &adv7511_connector_funcs, 809 - DRM_MODE_CONNECTOR_HDMIA); 810 - if (ret < 0) { 837 + connector = drm_bridge_connector_init(bridge->dev, bridge->encoder); 838 + if (IS_ERR(connector)) { 811 839 DRM_ERROR("Failed to initialize connector with drm\n"); 812 - return ret; 840 + return PTR_ERR(connector); 813 841 } 814 - drm_connector_helper_add(&adv->connector, 815 - &adv7511_connector_helper_funcs); 816 - drm_connector_attach_encoder(&adv->connector, bridge->encoder); 842 + 843 + drm_connector_attach_encoder(connector, bridge->encoder); 817 844 818 845 return 0; 819 846 } ··· 766 905 * DRM Bridge Operations 767 906 */ 768 907 769 - static struct adv7511 *bridge_to_adv7511(struct drm_bridge *bridge) 908 + static const struct adv7511 *bridge_to_adv7511_const(const struct drm_bridge *bridge) 770 909 { 771 910 return container_of(bridge, struct adv7511, bridge); 772 911 } ··· 775 914 struct drm_atomic_state *state) 776 915 { 777 916 struct adv7511 *adv = bridge_to_adv7511(bridge); 917 + struct drm_connector *connector; 918 + struct drm_connector_state *conn_state; 919 + struct drm_crtc_state *crtc_state; 778 920 779 921 adv7511_power_on(adv); 922 + 923 + connector = drm_atomic_get_new_connector_for_encoder(state, bridge->encoder); 924 + if (WARN_ON(!connector)) 925 + return; 926 + 927 + conn_state = drm_atomic_get_new_connector_state(state, connector); 928 + if (WARN_ON(!conn_state)) 929 + return; 930 + 931 + crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc); 932 + if (WARN_ON(!crtc_state)) 933 + return; 934 + 935 + adv7511_set_config_csc(adv, connector, adv->rgb); 936 + 937 + adv7511_mode_set(adv, &crtc_state->adjusted_mode); 938 + 939 + drm_atomic_helper_connector_hdmi_update_infoframes(connector, state); 780 940 } 781 941 782 942 static void adv7511_bridge_atomic_disable(struct drm_bridge *bridge, ··· 808 926 adv7511_power_off(adv); 809 927 } 810 928 811 - static void adv7511_bridge_mode_set(struct drm_bridge *bridge, 812 - const struct drm_display_mode *mode, 813 - const struct drm_display_mode *adj_mode) 929 + static enum drm_mode_status 930 + adv7511_bridge_hdmi_tmds_char_rate_valid(const struct drm_bridge *bridge, 931 + const struct drm_display_mode *mode, 932 + unsigned long long tmds_rate) 814 933 { 815 - struct adv7511 *adv = bridge_to_adv7511(bridge); 934 + const struct adv7511 *adv = bridge_to_adv7511_const(bridge); 816 935 817 - adv7511_mode_set(adv, mode, adj_mode); 936 + if (tmds_rate > 1000ULL * adv->info->max_mode_clock_khz) 937 + return MODE_CLOCK_HIGH; 938 + 939 + return MODE_OK; 818 940 } 819 941 820 942 static enum drm_mode_status adv7511_bridge_mode_valid(struct drm_bridge *bridge, ··· 827 941 { 828 942 struct adv7511 *adv = bridge_to_adv7511(bridge); 829 943 830 - if (adv->info->has_dsi) 831 - return adv7533_mode_valid(adv, mode); 832 - else 833 - return adv7511_mode_valid(adv, mode); 944 + if (!adv->info->has_dsi) 945 + return MODE_OK; 946 + 947 + return adv7533_mode_valid(adv, mode); 834 948 } 835 949 836 950 static int adv7511_bridge_attach(struct drm_bridge *bridge, ··· 864 978 { 865 979 struct adv7511 *adv = bridge_to_adv7511(bridge); 866 980 867 - return adv7511_detect(adv, NULL); 981 + return adv7511_detect(adv); 868 982 } 869 983 870 984 static const struct drm_edid *adv7511_bridge_edid_read(struct drm_bridge *bridge, ··· 875 989 return adv7511_edid_read(adv, connector); 876 990 } 877 991 878 - static void adv7511_bridge_hpd_notify(struct drm_bridge *bridge, 879 - enum drm_connector_status status) 992 + static int adv7511_bridge_hdmi_clear_infoframe(struct drm_bridge *bridge, 993 + enum hdmi_infoframe_type type) 880 994 { 881 - struct adv7511 *adv = bridge_to_adv7511(bridge); 995 + struct adv7511 *adv7511 = bridge_to_adv7511(bridge); 882 996 883 - if (status == connector_status_disconnected) 884 - cec_phys_addr_invalidate(adv->cec_adap); 997 + switch (type) { 998 + case HDMI_INFOFRAME_TYPE_AVI: 999 + adv7511_packet_disable(adv7511, ADV7511_PACKET_ENABLE_AVI_INFOFRAME); 1000 + break; 1001 + default: 1002 + drm_dbg_driver(adv7511->bridge.dev, "Unsupported HDMI InfoFrame %x\n", type); 1003 + break; 1004 + } 1005 + 1006 + return 0; 1007 + } 1008 + 1009 + static int adv7511_bridge_hdmi_write_infoframe(struct drm_bridge *bridge, 1010 + enum hdmi_infoframe_type type, 1011 + const u8 *buffer, size_t len) 1012 + { 1013 + struct adv7511 *adv7511 = bridge_to_adv7511(bridge); 1014 + 1015 + adv7511_bridge_hdmi_clear_infoframe(bridge, type); 1016 + 1017 + switch (type) { 1018 + case HDMI_INFOFRAME_TYPE_AVI: 1019 + /* The AVI infoframe id is not configurable */ 1020 + regmap_bulk_write(adv7511->regmap, ADV7511_REG_AVI_INFOFRAME_VERSION, 1021 + buffer + 1, len - 1); 1022 + 1023 + adv7511_packet_enable(adv7511, ADV7511_PACKET_ENABLE_AVI_INFOFRAME); 1024 + break; 1025 + default: 1026 + drm_dbg_driver(adv7511->bridge.dev, "Unsupported HDMI InfoFrame %x\n", type); 1027 + break; 1028 + } 1029 + 1030 + return 0; 885 1031 } 886 1032 887 1033 static const struct drm_bridge_funcs adv7511_bridge_funcs = { 888 - .mode_set = adv7511_bridge_mode_set, 889 1034 .mode_valid = adv7511_bridge_mode_valid, 890 1035 .attach = adv7511_bridge_attach, 891 1036 .detect = adv7511_bridge_detect, 892 1037 .edid_read = adv7511_bridge_edid_read, 893 - .hpd_notify = adv7511_bridge_hpd_notify, 894 1038 895 1039 .atomic_enable = adv7511_bridge_atomic_enable, 896 1040 .atomic_disable = adv7511_bridge_atomic_disable, 897 1041 .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, 898 1042 .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, 899 1043 .atomic_reset = drm_atomic_helper_bridge_reset, 1044 + 1045 + .hdmi_tmds_char_rate_valid = adv7511_bridge_hdmi_tmds_char_rate_valid, 1046 + .hdmi_clear_infoframe = adv7511_bridge_hdmi_clear_infoframe, 1047 + .hdmi_write_infoframe = adv7511_bridge_hdmi_write_infoframe, 1048 + 1049 + .hdmi_audio_startup = adv7511_hdmi_audio_startup, 1050 + .hdmi_audio_prepare = adv7511_hdmi_audio_prepare, 1051 + .hdmi_audio_shutdown = adv7511_hdmi_audio_shutdown, 1052 + 1053 + .hdmi_cec_init = adv7511_cec_init, 1054 + .hdmi_cec_enable = adv7511_cec_enable, 1055 + .hdmi_cec_log_addr = adv7511_cec_log_addr, 1056 + .hdmi_cec_transmit = adv7511_cec_transmit, 900 1057 }; 901 1058 902 1059 /* ----------------------------------------------------------------------------- ··· 1252 1323 if (adv7511->info->link_config) 1253 1324 adv7511_set_link_config(adv7511, &link_config); 1254 1325 1255 - ret = adv7511_cec_init(dev, adv7511); 1256 - if (ret) 1257 - goto err_unregister_cec; 1326 + regmap_write(adv7511->regmap, ADV7511_REG_CEC_CTRL, 1327 + ADV7511_CEC_CTRL_POWER_DOWN); 1258 1328 1259 1329 adv7511->bridge.funcs = &adv7511_bridge_funcs; 1260 - adv7511->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID; 1330 + adv7511->bridge.ops = DRM_BRIDGE_OP_DETECT | 1331 + DRM_BRIDGE_OP_EDID | 1332 + DRM_BRIDGE_OP_HDMI | 1333 + DRM_BRIDGE_OP_HDMI_AUDIO | 1334 + DRM_BRIDGE_OP_HDMI_CEC_ADAPTER; 1261 1335 if (adv7511->i2c_main->irq) 1262 1336 adv7511->bridge.ops |= DRM_BRIDGE_OP_HPD; 1337 + 1338 + adv7511->bridge.vendor = "Analog"; 1339 + adv7511->bridge.product = adv7511->info->name; 1340 + 1341 + #ifdef CONFIG_DRM_I2C_ADV7511_AUDIO 1342 + adv7511->bridge.hdmi_audio_dev = dev; 1343 + adv7511->bridge.hdmi_audio_max_i2s_playback_channels = 2; 1344 + adv7511->bridge.hdmi_audio_i2s_formats = (SNDRV_PCM_FMTBIT_S16_LE | 1345 + SNDRV_PCM_FMTBIT_S20_3LE | 1346 + SNDRV_PCM_FMTBIT_S24_3LE | 1347 + SNDRV_PCM_FMTBIT_S24_LE | 1348 + SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE), 1349 + adv7511->bridge.hdmi_audio_spdif_playback = 1; 1350 + adv7511->bridge.hdmi_audio_dai_port = 2; 1351 + #endif 1352 + 1353 + #ifdef CONFIG_DRM_I2C_ADV7511_CEC 1354 + adv7511->bridge.hdmi_cec_dev = dev; 1355 + adv7511->bridge.hdmi_cec_adapter_name = dev_name(dev); 1356 + adv7511->bridge.hdmi_cec_available_las = ADV7511_MAX_ADDRS; 1357 + #endif 1263 1358 1264 1359 adv7511->bridge.of_node = dev->of_node; 1265 1360 adv7511->bridge.type = DRM_MODE_CONNECTOR_HDMIA; 1266 1361 1267 1362 drm_bridge_add(&adv7511->bridge); 1268 - 1269 - adv7511_audio_init(dev, adv7511); 1270 1363 1271 1364 if (i2c->irq) { 1272 1365 init_waitqueue_head(&adv7511->wq); ··· 1311 1360 return 0; 1312 1361 1313 1362 err_unregister_audio: 1314 - adv7511_audio_exit(adv7511); 1315 1363 drm_bridge_remove(&adv7511->bridge); 1316 - err_unregister_cec: 1317 - cec_unregister_adapter(adv7511->cec_adap); 1318 1364 i2c_unregister_device(adv7511->i2c_cec); 1319 1365 clk_disable_unprepare(adv7511->cec_clk); 1320 1366 err_i2c_unregister_packet: ··· 1336 1388 1337 1389 drm_bridge_remove(&adv7511->bridge); 1338 1390 1339 - adv7511_audio_exit(adv7511); 1340 - 1341 - cec_unregister_adapter(adv7511->cec_adap); 1342 1391 i2c_unregister_device(adv7511->i2c_cec); 1343 1392 clk_disable_unprepare(adv7511->cec_clk); 1344 1393 ··· 1345 1400 1346 1401 static const struct adv7511_chip_info adv7511_chip_info = { 1347 1402 .type = ADV7511, 1403 + .name = "ADV7511", 1404 + .max_mode_clock_khz = 165000, 1348 1405 .supply_names = adv7511_supply_names, 1349 1406 .num_supplies = ARRAY_SIZE(adv7511_supply_names), 1350 1407 .link_config = true, ··· 1354 1407 1355 1408 static const struct adv7511_chip_info adv7533_chip_info = { 1356 1409 .type = ADV7533, 1410 + .name = "ADV7533", 1357 1411 .max_mode_clock_khz = 80000, 1358 1412 .max_lane_freq_khz = 800000, 1359 1413 .supply_names = adv7533_supply_names, ··· 1365 1417 1366 1418 static const struct adv7511_chip_info adv7535_chip_info = { 1367 1419 .type = ADV7535, 1420 + .name = "ADV7535", 1368 1421 .max_mode_clock_khz = 148500, 1369 1422 .max_lane_freq_khz = 891000, 1370 1423 .supply_names = adv7533_supply_names,
-4
drivers/gpu/drm/bridge/adv7511/adv7533.c
··· 106 106 struct mipi_dsi_device *dsi = adv->dsi; 107 107 u8 bpp = mipi_dsi_pixel_format_to_bpp(dsi->format); 108 108 109 - /* Check max clock for either 7533 or 7535 */ 110 - if (mode->clock > adv->info->max_mode_clock_khz) 111 - return MODE_CLOCK_HIGH; 112 - 113 109 /* Check max clock for each lane */ 114 110 if (mode->clock * bpp > adv->info->max_lane_freq_khz * adv->num_dsi_lanes) 115 111 return MODE_CLOCK_HIGH;