Path: blob/master/drivers/gpu/drm/bridge/adv7511/adv7511.h
29285 views
/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Analog Devices ADV7511 HDMI transmitter driver3*4* Copyright 2012 Analog Devices Inc.5*/67#ifndef __DRM_I2C_ADV7511_H__8#define __DRM_I2C_ADV7511_H__910#include <linux/hdmi.h>11#include <linux/i2c.h>12#include <linux/regmap.h>13#include <linux/regulator/consumer.h>1415#include <drm/drm_bridge.h>16#include <drm/drm_connector.h>17#include <drm/drm_mipi_dsi.h>18#include <drm/drm_modes.h>1920#define ADV7511_REG_CHIP_REVISION 0x0021#define ADV7511_REG_N0 0x0122#define ADV7511_REG_N1 0x0223#define ADV7511_REG_N2 0x0324#define ADV7511_REG_SPDIF_FREQ 0x0425#define ADV7511_REG_CTS_AUTOMATIC1 0x0526#define ADV7511_REG_CTS_AUTOMATIC2 0x0627#define ADV7511_REG_CTS_MANUAL0 0x0728#define ADV7511_REG_CTS_MANUAL1 0x0829#define ADV7511_REG_CTS_MANUAL2 0x0930#define ADV7511_REG_AUDIO_SOURCE 0x0a31#define ADV7511_REG_AUDIO_CONFIG 0x0b32#define ADV7511_REG_I2S_CONFIG 0x0c33#define ADV7511_REG_I2S_WIDTH 0x0d34#define ADV7511_REG_AUDIO_SUB_SRC0 0x0e35#define ADV7511_REG_AUDIO_SUB_SRC1 0x0f36#define ADV7511_REG_AUDIO_SUB_SRC2 0x1037#define ADV7511_REG_AUDIO_SUB_SRC3 0x1138#define ADV7511_REG_AUDIO_CFG1 0x1239#define ADV7511_REG_AUDIO_CFG2 0x1340#define ADV7511_REG_AUDIO_CFG3 0x1441#define ADV7511_REG_I2C_FREQ_ID_CFG 0x1542#define ADV7511_REG_VIDEO_INPUT_CFG1 0x1643#define ADV7511_REG_CSC_UPPER(x) (0x18 + (x) * 2)44#define ADV7511_REG_CSC_LOWER(x) (0x19 + (x) * 2)45#define ADV7511_REG_SYNC_DECODER(x) (0x30 + (x))46#define ADV7511_REG_DE_GENERATOR (0x35 + (x))47#define ADV7511_REG_PIXEL_REPETITION 0x3b48#define ADV7511_REG_VIC_MANUAL 0x3c49#define ADV7511_REG_VIC_SEND 0x3d50#define ADV7511_REG_VIC_DETECTED 0x3e51#define ADV7511_REG_AUX_VIC_DETECTED 0x3f52#define ADV7511_REG_PACKET_ENABLE0 0x4053#define ADV7511_REG_POWER 0x4154#define ADV7511_REG_STATUS 0x4255#define ADV7511_REG_EDID_I2C_ADDR 0x4356#define ADV7511_REG_PACKET_ENABLE1 0x4457#define ADV7511_REG_PACKET_I2C_ADDR 0x4558#define ADV7511_REG_DSD_ENABLE 0x4659#define ADV7511_REG_VIDEO_INPUT_CFG2 0x4860#define ADV7511_REG_INFOFRAME_UPDATE 0x4a61#define ADV7511_REG_GC(x) (0x4b + (x)) /* 0x4b - 0x51 */62#define ADV7511_REG_AVI_INFOFRAME_VERSION 0x5263#define ADV7511_REG_AVI_INFOFRAME_LENGTH 0x5364#define ADV7511_REG_AVI_INFOFRAME_CHECKSUM 0x5465#define ADV7511_REG_AVI_INFOFRAME(x) (0x55 + (x)) /* 0x55 - 0x6f */66#define ADV7511_REG_AUDIO_INFOFRAME_VERSION 0x7067#define ADV7511_REG_AUDIO_INFOFRAME_LENGTH 0x7168#define ADV7511_REG_AUDIO_INFOFRAME_CHECKSUM 0x7269#define ADV7511_REG_AUDIO_INFOFRAME(x) (0x73 + (x)) /* 0x73 - 0x7c */70#define ADV7511_REG_INT_ENABLE(x) (0x94 + (x))71#define ADV7511_REG_INT(x) (0x96 + (x))72#define ADV7511_REG_INPUT_CLK_DIV 0x9d73#define ADV7511_REG_PLL_STATUS 0x9e74#define ADV7511_REG_HDMI_POWER 0xa175#define ADV7511_REG_HDCP_HDMI_CFG 0xaf76#define ADV7511_REG_AN(x) (0xb0 + (x)) /* 0xb0 - 0xb7 */77#define ADV7511_REG_HDCP_STATUS 0xb878#define ADV7511_REG_BCAPS 0xbe79#define ADV7511_REG_BKSV(x) (0xc0 + (x)) /* 0xc0 - 0xc3 */80#define ADV7511_REG_EDID_SEGMENT 0xc481#define ADV7511_REG_DDC_STATUS 0xc882#define ADV7511_REG_EDID_READ_CTRL 0xc983#define ADV7511_REG_BSTATUS(x) (0xca + (x)) /* 0xca - 0xcb */84#define ADV7511_REG_TIMING_GEN_SEQ 0xd085#define ADV7511_REG_POWER2 0xd686#define ADV7511_REG_HSYNC_PLACEMENT_MSB 0xfa8788#define ADV7511_REG_SYNC_ADJUSTMENT(x) (0xd7 + (x)) /* 0xd7 - 0xdc */89#define ADV7511_REG_TMDS_CLOCK_INV 0xde90#define ADV7511_REG_ARC_CTRL 0xdf91#define ADV7511_REG_CEC_I2C_ADDR 0xe192#define ADV7511_REG_CEC_CTRL 0xe293#define ADV7511_REG_CHIP_ID_HIGH 0xf594#define ADV7511_REG_CHIP_ID_LOW 0xf69596/* Hardware defined default addresses for I2C register maps */97#define ADV7511_CEC_I2C_ADDR_DEFAULT 0x3c98#define ADV7511_EDID_I2C_ADDR_DEFAULT 0x3f99#define ADV7511_PACKET_I2C_ADDR_DEFAULT 0x38100101#define ADV7511_CSC_ENABLE BIT(7)102#define ADV7511_CSC_UPDATE_MODE BIT(5)103104#define ADV7511_INT0_HPD BIT(7)105#define ADV7511_INT0_VSYNC BIT(5)106#define ADV7511_INT0_AUDIO_FIFO_FULL BIT(4)107#define ADV7511_INT0_EDID_READY BIT(2)108#define ADV7511_INT0_HDCP_AUTHENTICATED BIT(1)109110#define ADV7511_INT1_DDC_ERROR BIT(7)111#define ADV7511_INT1_BKSV BIT(6)112#define ADV7511_INT1_CEC_TX_READY BIT(5)113#define ADV7511_INT1_CEC_TX_ARBIT_LOST BIT(4)114#define ADV7511_INT1_CEC_TX_RETRY_TIMEOUT BIT(3)115#define ADV7511_INT1_CEC_RX_READY3 BIT(2)116#define ADV7511_INT1_CEC_RX_READY2 BIT(1)117#define ADV7511_INT1_CEC_RX_READY1 BIT(0)118119#define ADV7511_ARC_CTRL_POWER_DOWN BIT(0)120121#define ADV7511_CEC_CTRL_POWER_DOWN BIT(0)122123#define ADV7511_POWER_POWER_DOWN BIT(6)124125#define ADV7511_HDMI_CFG_MODE_MASK 0x2126#define ADV7511_HDMI_CFG_MODE_DVI 0x0127#define ADV7511_HDMI_CFG_MODE_HDMI 0x2128129#define ADV7511_AUDIO_SELECT_I2C 0x0130#define ADV7511_AUDIO_SELECT_SPDIF 0x1131#define ADV7511_AUDIO_SELECT_DSD 0x2132#define ADV7511_AUDIO_SELECT_HBR 0x3133#define ADV7511_AUDIO_SELECT_DST 0x4134135#define ADV7511_I2S_SAMPLE_LEN_16 0x2136#define ADV7511_I2S_SAMPLE_LEN_20 0x3137#define ADV7511_I2S_SAMPLE_LEN_18 0x4138#define ADV7511_I2S_SAMPLE_LEN_22 0x5139#define ADV7511_I2S_SAMPLE_LEN_19 0x8140#define ADV7511_I2S_SAMPLE_LEN_23 0x9141#define ADV7511_I2S_SAMPLE_LEN_24 0xb142#define ADV7511_I2S_SAMPLE_LEN_17 0xc143#define ADV7511_I2S_SAMPLE_LEN_21 0xd144145#define ADV7511_SAMPLE_FREQ_44100 0x0146#define ADV7511_SAMPLE_FREQ_48000 0x2147#define ADV7511_SAMPLE_FREQ_32000 0x3148#define ADV7511_SAMPLE_FREQ_88200 0x8149#define ADV7511_SAMPLE_FREQ_96000 0xa150#define ADV7511_SAMPLE_FREQ_176400 0xc151#define ADV7511_SAMPLE_FREQ_192000 0xe152153#define ADV7511_STATUS_POWER_DOWN_POLARITY BIT(7)154#define ADV7511_STATUS_HPD BIT(6)155#define ADV7511_STATUS_MONITOR_SENSE BIT(5)156#define ADV7511_STATUS_I2S_32BIT_MODE BIT(3)157158#define ADV7511_PACKET_ENABLE_N_CTS BIT(8+6)159#define ADV7511_PACKET_ENABLE_AUDIO_SAMPLE BIT(8+5)160#define ADV7511_PACKET_ENABLE_AVI_INFOFRAME BIT(8+4)161#define ADV7511_PACKET_ENABLE_AUDIO_INFOFRAME BIT(8+3)162#define ADV7511_PACKET_ENABLE_GC BIT(7)163#define ADV7511_PACKET_ENABLE_SPD BIT(6)164#define ADV7511_PACKET_ENABLE_MPEG BIT(5)165#define ADV7511_PACKET_ENABLE_ACP BIT(4)166#define ADV7511_PACKET_ENABLE_ISRC BIT(3)167#define ADV7511_PACKET_ENABLE_GM BIT(2)168#define ADV7511_PACKET_ENABLE_SPARE2 BIT(1)169#define ADV7511_PACKET_ENABLE_SPARE1 BIT(0)170171#define ADV7535_REG_POWER2_HPD_OVERRIDE BIT(6)172#define ADV7511_REG_POWER2_HPD_SRC_MASK 0xc0173#define ADV7511_REG_POWER2_HPD_SRC_BOTH 0x00174#define ADV7511_REG_POWER2_HPD_SRC_HPD 0x40175#define ADV7511_REG_POWER2_HPD_SRC_CEC 0x80176#define ADV7511_REG_POWER2_HPD_SRC_NONE 0xc0177#define ADV7511_REG_POWER2_TDMS_ENABLE BIT(4)178#define ADV7511_REG_POWER2_GATE_INPUT_CLK BIT(0)179180#define ADV7511_LOW_REFRESH_RATE_NONE 0x0181#define ADV7511_LOW_REFRESH_RATE_24HZ 0x1182#define ADV7511_LOW_REFRESH_RATE_25HZ 0x2183#define ADV7511_LOW_REFRESH_RATE_30HZ 0x3184185#define ADV7511_AUDIO_CFG3_LEN_MASK 0x0f186#define ADV7511_I2C_FREQ_ID_CFG_RATE_MASK 0xf0187188#define ADV7511_AUDIO_SOURCE_I2S 0189#define ADV7511_AUDIO_SOURCE_SPDIF 1190191#define ADV7511_I2S_FORMAT_I2S 0192#define ADV7511_I2S_FORMAT_RIGHT_J 1193#define ADV7511_I2S_FORMAT_LEFT_J 2194#define ADV7511_I2S_IEC958_DIRECT 3195196#define ADV7511_PACKET(p, x) ((p) * 0x20 + (x))197#define ADV7511_PACKET_SPD(x) ADV7511_PACKET(0, x)198#define ADV7511_PACKET_MPEG(x) ADV7511_PACKET(1, x)199#define ADV7511_PACKET_ACP(x) ADV7511_PACKET(2, x)200#define ADV7511_PACKET_ISRC1(x) ADV7511_PACKET(3, x)201#define ADV7511_PACKET_ISRC2(x) ADV7511_PACKET(4, x)202#define ADV7511_PACKET_GM(x) ADV7511_PACKET(5, x)203#define ADV7511_PACKET_SPARE1(x) ADV7511_PACKET(6, x)204#define ADV7511_PACKET_SPARE2(x) ADV7511_PACKET(7, x)205206#define ADV7511_REG_CEC_TX_FRAME_HDR 0x00207#define ADV7511_REG_CEC_TX_FRAME_DATA0 0x01208#define ADV7511_REG_CEC_TX_FRAME_LEN 0x10209#define ADV7511_REG_CEC_TX_ENABLE 0x11210#define ADV7511_REG_CEC_TX_RETRY 0x12211#define ADV7511_REG_CEC_TX_LOW_DRV_CNT 0x14212#define ADV7511_REG_CEC_RX1_FRAME_HDR 0x15213#define ADV7511_REG_CEC_RX1_FRAME_DATA0 0x16214#define ADV7511_REG_CEC_RX1_FRAME_LEN 0x25215#define ADV7511_REG_CEC_RX_STATUS 0x26216#define ADV7511_REG_CEC_RX2_FRAME_HDR 0x27217#define ADV7511_REG_CEC_RX2_FRAME_DATA0 0x28218#define ADV7511_REG_CEC_RX2_FRAME_LEN 0x37219#define ADV7511_REG_CEC_RX3_FRAME_HDR 0x38220#define ADV7511_REG_CEC_RX3_FRAME_DATA0 0x39221#define ADV7511_REG_CEC_RX3_FRAME_LEN 0x48222#define ADV7511_REG_CEC_RX_BUFFERS 0x4a223#define ADV7511_REG_CEC_LOG_ADDR_MASK 0x4b224#define ADV7511_REG_CEC_LOG_ADDR_0_1 0x4c225#define ADV7511_REG_CEC_LOG_ADDR_2 0x4d226#define ADV7511_REG_CEC_CLK_DIV 0x4e227#define ADV7511_REG_CEC_SOFT_RESET 0x50228229#define ADV7533_REG_CEC_OFFSET 0x70230231enum adv7511_input_clock {232ADV7511_INPUT_CLOCK_1X,233ADV7511_INPUT_CLOCK_2X,234ADV7511_INPUT_CLOCK_DDR,235};236237enum adv7511_input_justification {238ADV7511_INPUT_JUSTIFICATION_EVENLY = 0,239ADV7511_INPUT_JUSTIFICATION_RIGHT = 1,240ADV7511_INPUT_JUSTIFICATION_LEFT = 2,241};242243enum adv7511_input_sync_pulse {244ADV7511_INPUT_SYNC_PULSE_DE = 0,245ADV7511_INPUT_SYNC_PULSE_HSYNC = 1,246ADV7511_INPUT_SYNC_PULSE_VSYNC = 2,247ADV7511_INPUT_SYNC_PULSE_NONE = 3,248};249250/**251* enum adv7511_sync_polarity - Polarity for the input sync signals252* @ADV7511_SYNC_POLARITY_PASSTHROUGH: Sync polarity matches that of253* the currently configured mode.254* @ADV7511_SYNC_POLARITY_LOW: Sync polarity is low255* @ADV7511_SYNC_POLARITY_HIGH: Sync polarity is high256*257* If the polarity is set to either LOW or HIGH the driver will configure the258* ADV7511 to internally invert the sync signal if required to match the sync259* polarity setting for the currently selected output mode.260*261* If the polarity is set to PASSTHROUGH, the ADV7511 will route the signal262* unchanged. This is used when the upstream graphics core already generates263* the sync signals with the correct polarity.264*/265enum adv7511_sync_polarity {266ADV7511_SYNC_POLARITY_PASSTHROUGH,267ADV7511_SYNC_POLARITY_LOW,268ADV7511_SYNC_POLARITY_HIGH,269};270271/**272* struct adv7511_link_config - Describes adv7511 hardware configuration273* @input_color_depth: Number of bits per color component (8, 10 or 12)274* @input_colorspace: The input colorspace (RGB, YUV444, YUV422)275* @input_clock: The input video clock style (1x, 2x, DDR)276* @input_style: The input component arrangement variant277* @input_justification: Video input format bit justification278* @clock_delay: Clock delay for the input clock (in ps)279* @embedded_sync: Video input uses BT.656-style embedded sync280* @sync_pulse: Select the sync pulse281* @vsync_polarity: vsync input signal configuration282* @hsync_polarity: hsync input signal configuration283*/284struct adv7511_link_config {285unsigned int input_color_depth;286enum hdmi_colorspace input_colorspace;287enum adv7511_input_clock input_clock;288unsigned int input_style;289enum adv7511_input_justification input_justification;290291int clock_delay;292293bool embedded_sync;294enum adv7511_input_sync_pulse sync_pulse;295enum adv7511_sync_polarity vsync_polarity;296enum adv7511_sync_polarity hsync_polarity;297};298299/**300* enum adv7511_csc_scaling - Scaling factor for the ADV7511 CSC301* @ADV7511_CSC_SCALING_1: CSC results are not scaled302* @ADV7511_CSC_SCALING_2: CSC results are scaled by a factor of two303* @ADV7511_CSC_SCALING_4: CSC results are scalled by a factor of four304*/305enum adv7511_csc_scaling {306ADV7511_CSC_SCALING_1 = 0,307ADV7511_CSC_SCALING_2 = 1,308ADV7511_CSC_SCALING_4 = 2,309};310311/**312* struct adv7511_video_config - Describes adv7511 hardware configuration313* @csc_enable: Whether to enable color space conversion314* @csc_scaling_factor: Color space conversion scaling factor315* @csc_coefficents: Color space conversion coefficents316*/317struct adv7511_video_config {318bool csc_enable;319enum adv7511_csc_scaling csc_scaling_factor;320const uint16_t *csc_coefficents;321};322323enum adv7511_type {324ADV7511,325ADV7533,326ADV7535,327};328329#define ADV7511_MAX_ADDRS 3330331struct adv7511_chip_info {332enum adv7511_type type;333unsigned int max_mode_clock_khz;334unsigned int max_lane_freq_khz;335const char *name;336const char * const *supply_names;337unsigned int num_supplies;338unsigned int reg_cec_offset;339bool has_dsi;340bool link_config;341bool hpd_override_enable;342};343344struct adv7511 {345struct i2c_client *i2c_main;346struct i2c_client *i2c_edid;347struct i2c_client *i2c_packet;348struct i2c_client *i2c_cec;349350struct regmap *regmap;351struct regmap *regmap_packet;352struct regmap *regmap_cec;353enum drm_connector_status status;354bool powered;355356struct drm_bridge *next_bridge;357struct drm_display_mode curr_mode;358359unsigned int f_tmds;360unsigned int f_audio;361unsigned int audio_source;362363unsigned int current_edid_segment;364uint8_t edid_buf[256];365bool edid_read;366367wait_queue_head_t wq;368struct work_struct hpd_work;369370struct drm_bridge bridge;371struct drm_connector *cec_connector;372373bool embedded_sync;374enum adv7511_sync_polarity vsync_polarity;375enum adv7511_sync_polarity hsync_polarity;376bool rgb;377378struct gpio_desc *gpio_pd;379380struct regulator_bulk_data *supplies;381382/* ADV7533 DSI RX related params */383struct device_node *host_node;384struct mipi_dsi_device *dsi;385u8 num_dsi_lanes;386bool use_timing_gen;387388const struct adv7511_chip_info *info;389390u8 cec_addr[ADV7511_MAX_ADDRS];391u8 cec_valid_addrs;392bool cec_enabled_adap;393struct clk *cec_clk;394u32 cec_clk_freq;395};396397static inline struct adv7511 *bridge_to_adv7511(struct drm_bridge *bridge)398{399return container_of(bridge, struct adv7511, bridge);400}401402#ifdef CONFIG_DRM_I2C_ADV7511_CEC403int adv7511_cec_init(struct drm_bridge *bridge,404struct drm_connector *connector);405int adv7511_cec_enable(struct drm_bridge *bridge, bool enable);406int adv7511_cec_log_addr(struct drm_bridge *bridge, u8 addr);407int adv7511_cec_transmit(struct drm_bridge *bridge, u8 attempts,408u32 signal_free_time, struct cec_msg *msg);409int adv7511_cec_irq_process(struct adv7511 *adv7511, unsigned int irq1);410#else411#define adv7511_cec_init NULL412#define adv7511_cec_enable NULL413#define adv7511_cec_log_addr NULL414#define adv7511_cec_transmit NULL415#endif416417void adv7533_dsi_power_on(struct adv7511 *adv);418void adv7533_dsi_power_off(struct adv7511 *adv);419void adv7533_dsi_config_timing_gen(struct adv7511 *adv);420enum drm_mode_status adv7533_mode_valid(struct adv7511 *adv,421const struct drm_display_mode *mode);422int adv7533_patch_registers(struct adv7511 *adv);423int adv7533_patch_cec_registers(struct adv7511 *adv);424int adv7533_attach_dsi(struct adv7511 *adv);425int adv7533_parse_dt(struct device_node *np, struct adv7511 *adv);426427#ifdef CONFIG_DRM_I2C_ADV7511_AUDIO428int adv7511_hdmi_audio_startup(struct drm_bridge *bridge,429struct drm_connector *connector);430void adv7511_hdmi_audio_shutdown(struct drm_bridge *bridge,431struct drm_connector *connector);432int adv7511_hdmi_audio_prepare(struct drm_bridge *bridge,433struct drm_connector *connector,434struct hdmi_codec_daifmt *fmt,435struct hdmi_codec_params *hparms);436#else /*CONFIG_DRM_I2C_ADV7511_AUDIO */437#define adv7511_hdmi_audio_startup NULL438#define adv7511_hdmi_audio_shutdown NULL439#define adv7511_hdmi_audio_prepare NULL440#endif /* CONFIG_DRM_I2C_ADV7511_AUDIO */441442#endif /* __DRM_I2C_ADV7511_H__ */443444445