linux/drivers/gpu/drm/bridge/ite-it6505.c

// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/*
 * Copyright (c) 2020, The Linux Foundation. All rights reserved.
 */
#include <linux/bits.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/extcon.h>
#include <linux/fs.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pm_runtime.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/types.h>
#include <linux/wait.h>

#include <crypto/hash.h>

#include <drm/display/drm_dp_helper.h>
#include <drm/display/drm_hdcp_helper.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_bridge.h>
#include <drm/drm_crtc.h>
#include <drm/drm_edid.h>
#include <drm/drm_print.h>
#include <drm/drm_probe_helper.h>

#include <sound/hdmi-codec.h>

#define REG_IC_VER

#define REG_RESET_CTRL
#define VIDEO_RESET
#define AUDIO_RESET
#define ALL_LOGIC_RESET
#define AUX_RESET
#define HDCP_RESET

#define INT_STATUS_01
#define INT_MASK_01
#define INT_HPD_CHANGE
#define INT_RECEIVE_HPD_IRQ
#define INT_SCDT_CHANGE
#define INT_HDCP_FAIL
#define INT_HDCP_DONE
#define BIT_OFFSET(x)
#define BIT_INT_HPD
#define BIT_INT_HPD_IRQ
#define BIT_INT_SCDT
#define BIT_INT_HDCP_FAIL
#define BIT_INT_HDCP_DONE

#define INT_STATUS_02
#define INT_MASK_02
#define INT_AUX_CMD_FAIL
#define INT_HDCP_KSV_CHECK
#define INT_AUDIO_FIFO_ERROR
#define BIT_INT_AUX_CMD_FAIL
#define BIT_INT_HDCP_KSV_CHECK
#define BIT_INT_AUDIO_FIFO_ERROR

#define INT_STATUS_03
#define INT_MASK_03
#define INT_LINK_TRAIN_FAIL
#define INT_VID_FIFO_ERROR
#define INT_IO_LATCH_FIFO_OVERFLOW
#define BIT_INT_LINK_TRAIN_FAIL
#define BIT_INT_VID_FIFO_ERROR
#define BIT_INT_IO_FIFO_OVERFLOW

#define REG_SYSTEM_STS
#define INT_STS
#define HPD_STS
#define VIDEO_STB

#define REG_LINK_TRAIN_STS
#define LINK_STATE_CR
#define LINK_STATE_EQ
#define LINK_STATE_NORP

#define REG_BANK_SEL
#define REG_CLK_CTRL0
#define M_PCLK_DELAY

#define REG_AUX_OPT
#define AUX_AUTO_RST
#define AUX_FIX_FREQ

#define REG_DATA_CTRL0
#define VIDEO_LATCH_EDGE
#define ENABLE_PCLK_COUNTER

#define REG_PCLK_COUNTER_VALUE

#define REG_501_FIFO_CTRL
#define RST_501_FIFO

#define REG_TRAIN_CTRL0
#define FORCE_LBR
#define LANE_COUNT_MASK
#define LANE_SWAP
#define SPREAD_AMP_5
#define FORCE_CR_DONE
#define FORCE_EQ_DONE

#define REG_TRAIN_CTRL1
#define AUTO_TRAIN
#define MANUAL_TRAIN
#define FORCE_RETRAIN

#define REG_AUX_CTRL
#define CLR_EDID_FIFO
#define AUX_USER_MODE
#define AUX_NO_SEGMENT_WR
#define AUX_EN_FIFO_READ

#define REG_AUX_ADR_0_7
#define REG_AUX_ADR_8_15
#define REG_AUX_ADR_16_19
#define REG_AUX_OUT_DATA0

#define REG_AUX_CMD_REQ
#define AUX_BUSY

#define REG_AUX_DATA_0_7
#define REG_AUX_DATA_8_15
#define REG_AUX_DATA_16_23
#define REG_AUX_DATA_24_31

#define REG_AUX_DATA_FIFO

#define REG_AUX_ERROR_STS
#define M_AUX_REQ_FAIL

#define REG_HDCP_CTRL1
#define HDCP_CP_ENABLE

#define REG_HDCP_TRIGGER
#define HDCP_TRIGGER_START
#define HDCP_TRIGGER_CPIRQ
#define HDCP_TRIGGER_KSV_DONE
#define HDCP_TRIGGER_KSV_FAIL

#define REG_HDCP_CTRL2
#define HDCP_AN_SEL
#define HDCP_AN_GEN
#define HDCP_HW_HPDIRQ_ACT
#define HDCP_EN_M0_READ

#define REG_M0_0_7
#define REG_AN_0_7
#define REG_SP_CTRL0
#define REG_IP_CTRL1
#define REG_IP_CTRL2

#define REG_LINK_DRV
#define DRV_HS

#define REG_DRV_LN_DATA_SEL

#define REG_AUX

#define REG_VID_BUS_CTRL0
#define IN_DDR
#define DDR_CD

#define REG_VID_BUS_CTRL1
#define TX_FIFO_RESET

#define REG_INPUT_CTRL
#define INPUT_HSYNC_POL
#define INPUT_VSYNC_POL
#define INPUT_INTERLACED

#define REG_INPUT_HTOTAL
#define REG_INPUT_HACTIVE_START
#define REG_INPUT_HACTIVE_WIDTH
#define REG_INPUT_HFRONT_PORCH
#define REG_INPUT_HSYNC_WIDTH
#define REG_INPUT_VTOTAL
#define REG_INPUT_VACTIVE_START
#define REG_INPUT_VACTIVE_WIDTH
#define REG_INPUT_VFRONT_PORCH
#define REG_INPUT_VSYNC_WIDTH

#define REG_AUDIO_SRC_CTRL
#define M_AUDIO_I2S_EN
#define EN_I2S0
#define EN_I2S1
#define EN_I2S2
#define EN_I2S3
#define AUDIO_FIFO_RESET

#define REG_AUDIO_FMT
#define REG_AUDIO_FIFO_SEL

#define REG_AUDIO_CTRL0
#define AUDIO_FULL_PKT
#define AUDIO_16B_BOUND

#define REG_AUDIO_CTRL1
#define REG_AUDIO_INPUT_FREQ

#define REG_IEC958_STS0
#define REG_IEC958_STS1
#define REG_IEC958_STS2
#define REG_IEC958_STS3
#define REG_IEC958_STS4

#define REG_HPD_IRQ_TIME
#define REG_AUX_DEBUG_MODE
#define REG_AUX_OPT2
#define REG_HDCP_OPT
#define REG_USER_DRV_PRE

#define REG_DATA_MUTE_CTRL
#define ENABLE_ENHANCED_FRAME
#define ENABLE_AUTO_VIDEO_FIFO_RESET
#define EN_VID_MUTE
#define EN_AUD_MUTE

#define REG_TIME_STMP_CTRL
#define EN_ENHANCE_VID_STMP
#define EN_ENHANCE_AUD_STMP
#define M_STAMP_STEP
#define EN_SSC_GAT

#define REG_INFOFRAME_CTRL
#define EN_AVI_PKT
#define EN_AUD_PKT
#define EN_MPG_PKT
#define EN_GEN_PKT
#define EN_VID_TIME_STMP
#define EN_AUD_TIME_STMP
#define EN_VID_CTRL_PKT
#define EN_AUD_CTRL_PKT

#define REG_AUDIO_N_0_7
#define REG_AUDIO_N_8_15
#define REG_AUDIO_N_16_23

#define REG_AVI_INFO_DB1
#define REG_AVI_INFO_DB2
#define REG_AVI_INFO_DB3
#define REG_AVI_INFO_DB4
#define REG_AVI_INFO_DB5
#define REG_AVI_INFO_SUM

#define REG_AUD_INFOFRAM_DB1
#define REG_AUD_INFOFRAM_DB2
#define REG_AUD_INFOFRAM_DB3
#define REG_AUD_INFOFRAM_DB4
#define REG_AUD_INFOFRAM_SUM

/* the following six registers are in bank1 */
#define REG_DRV_0_DB_800_MV
#define REG_PRE_0_DB_800_MV
#define REG_PRE_3P5_DB_800_MV
#define REG_SSC_CTRL0
#define REG_SSC_CTRL1
#define REG_SSC_CTRL2

#define RBR
#define HBR
#define HBR2
#define HBR3

#define DPCD_V_1_1
#define MISC_VERB
#define MISC_VERC
#define I2S_INPUT_FORMAT_STANDARD
#define I2S_INPUT_FORMAT_32BIT
#define I2S_INPUT_LEFT_JUSTIFIED
#define I2S_INPUT_RIGHT_JUSTIFIED
#define I2S_DATA_1T_DELAY
#define I2S_DATA_NO_DELAY
#define I2S_WS_LEFT_CHANNEL
#define I2S_WS_RIGHT_CHANNEL
#define I2S_DATA_MSB_FIRST
#define I2S_DATA_LSB_FIRST
#define WORD_LENGTH_16BIT
#define WORD_LENGTH_18BIT
#define WORD_LENGTH_20BIT
#define WORD_LENGTH_24BIT
#define DEBUGFS_DIR_NAME
#define READ_BUFFER_SIZE

/* Vendor option */
#define HDCP_DESIRED
#define MAX_LANE_COUNT
#define MAX_LINK_RATE
#define AUTO_TRAIN_RETRY
#define MAX_HDCP_DOWN_STREAM_COUNT
#define MAX_CR_LEVEL
#define MAX_EQ_LEVEL
#define AUX_WAIT_TIMEOUT_MS
#define AUX_FIFO_MAX_SIZE
#define PIXEL_CLK_DELAY
#define PIXEL_CLK_INVERSE
#define ADJUST_PHASE_THRESHOLD
#define DPI_PIXEL_CLK_MAX
#define HDCP_SHA1_FIFO_LEN
#define DEFAULT_PWR_ON
#define DEFAULT_DRV_HOLD

#define AUDIO_SELECT
#define AUDIO_TYPE
#define AUDIO_SAMPLE_RATE
#define AUDIO_CHANNEL_COUNT
#define I2S_INPUT_FORMAT
#define I2S_JUSTIFIED
#define I2S_DATA_DELAY
#define I2S_WS_CHANNEL
#define I2S_DATA_SEQUENCE
#define AUDIO_WORD_LENGTH

enum aux_cmd_type {};

enum aux_cmd_reply {};

enum link_train_status {};

enum hdcp_state {};

struct it6505_platform_data {};

enum it6505_audio_select {};

enum it6505_audio_sample_rate {};

enum it6505_audio_type {};

struct it6505_audio_data {};

struct it6505_audio_sample_rate_map {};

struct it6505_drm_dp_link {};

struct debugfs_entries {};

struct it6505 {};

struct it6505_step_train_para {};

/*
 * Vendor option afe settings for different platforms
 * 0: without FPC cable
 * 1: with FPC cable
 */

static const u8 afe_setting_table[][3] =;

static const struct it6505_audio_sample_rate_map audio_sample_rate_map[] =;

static const struct regmap_range it6505_bridge_volatile_ranges[] =;

static const struct regmap_access_table it6505_bridge_volatile_table =;

static const struct regmap_range_cfg it6505_regmap_banks[] =;

static const struct regmap_config it6505_regmap_config =;

static int it6505_read(struct it6505 *it6505, unsigned int reg_addr)
{}

static int it6505_write(struct it6505 *it6505, unsigned int reg_addr,
			unsigned int reg_val)
{}

static int it6505_set_bits(struct it6505 *it6505, unsigned int reg,
			   unsigned int mask, unsigned int value)
{}

static void it6505_debug_print(struct it6505 *it6505, unsigned int reg,
			       const char *prefix)
{}

static int it6505_dpcd_read(struct it6505 *it6505, unsigned long offset)
{}

static int it6505_dpcd_write(struct it6505 *it6505, unsigned long offset,
			     u8 datain)
{}

static int it6505_get_dpcd(struct it6505 *it6505, int offset, u8 *dpcd, int num)
{}

static void it6505_dump(struct it6505 *it6505)
{}

static bool it6505_get_sink_hpd_status(struct it6505 *it6505)
{}

static int it6505_read_word(struct it6505 *it6505, unsigned int reg)
{}

static void it6505_calc_video_info(struct it6505 *it6505)
{}

static int it6505_drm_dp_link_set_power(struct drm_dp_aux *aux,
					struct it6505_drm_dp_link *link,
					u8 mode)
{}

static void it6505_clear_int(struct it6505 *it6505)
{}

static void it6505_int_mask_enable(struct it6505 *it6505)
{}

static void it6505_int_mask_disable(struct it6505 *it6505)
{}

static void it6505_lane_termination_on(struct it6505 *it6505)
{}

static void it6505_lane_termination_off(struct it6505 *it6505)
{}

static void it6505_lane_power_on(struct it6505 *it6505)
{}

static void it6505_lane_power_off(struct it6505 *it6505)
{}

static void it6505_lane_off(struct it6505 *it6505)
{}

static void it6505_aux_termination_on(struct it6505 *it6505)
{}

static void it6505_aux_power_on(struct it6505 *it6505)
{}

static void it6505_aux_on(struct it6505 *it6505)
{}

static void it6505_aux_reset(struct it6505 *it6505)
{}

static void it6505_reset_logic(struct it6505 *it6505)
{}

static bool it6505_aux_op_finished(struct it6505 *it6505)
{}

static int it6505_aux_wait(struct it6505 *it6505)
{}

static ssize_t it6505_aux_operation(struct it6505 *it6505,
				    enum aux_cmd_type cmd,
				    unsigned int address, u8 *buffer,
				    size_t size, enum aux_cmd_reply *reply)
{}

static ssize_t it6505_aux_do_transfer(struct it6505 *it6505,
				      enum aux_cmd_type cmd,
				      unsigned int address, u8 *buffer,
				      size_t size, enum aux_cmd_reply *reply)
{}

static ssize_t it6505_aux_transfer(struct drm_dp_aux *aux,
				   struct drm_dp_aux_msg *msg)
{}

static int it6505_get_edid_block(void *data, u8 *buf, unsigned int block,
				 size_t len)
{}

static void it6505_variable_config(struct it6505 *it6505)
{}

static int it6505_send_video_infoframe(struct it6505 *it6505,
				       struct hdmi_avi_infoframe *frame)
{}

static void it6505_get_extcon_property(struct it6505 *it6505)
{}

static void it6505_clk_phase_adjustment(struct it6505 *it6505,
					const struct drm_display_mode *mode)
{}

static void it6505_link_reset_step_train(struct it6505 *it6505)
{}

static void it6505_init(struct it6505 *it6505)
{}

static void it6505_video_disable(struct it6505 *it6505)
{}

static void it6505_video_reset(struct it6505 *it6505)
{}

static void it6505_update_video_parameter(struct it6505 *it6505,
					  const struct drm_display_mode *mode)
{}

static bool it6505_audio_input(struct it6505 *it6505)
{}

static void it6505_setup_audio_channel_status(struct it6505 *it6505)
{}

static void it6505_setup_audio_format(struct it6505 *it6505)
{}

static void it6505_enable_audio_source(struct it6505 *it6505)
{}

static void it6505_enable_audio_infoframe(struct it6505 *it6505)
{}

static void it6505_disable_audio(struct it6505 *it6505)
{}

static void it6505_enable_audio(struct it6505 *it6505)
{}

static bool it6505_use_step_train_check(struct it6505 *it6505)
{}

static void it6505_parse_link_capabilities(struct it6505 *it6505)
{}

static void it6505_setup_ssc(struct it6505 *it6505)
{}

static inline void it6505_link_rate_setup(struct it6505 *it6505)
{}

static void it6505_lane_count_setup(struct it6505 *it6505)
{}

static void it6505_link_training_setup(struct it6505 *it6505)
{}

static bool it6505_link_start_auto_train(struct it6505 *it6505)
{}

static int it6505_drm_dp_link_configure(struct it6505 *it6505)
{}

static bool it6505_check_voltage_swing_max(u8 lane_voltage_swing_pre_emphasis)
{}

static bool it6505_check_pre_emphasis_max(u8 lane_voltage_swing_pre_emphasis)
{}

static bool it6505_check_max_voltage_swing_reached(u8 *lane_voltage_swing,
						   u8 lane_count)
{}

static bool
step_train_lane_voltage_para_set(struct it6505 *it6505,
				 struct it6505_step_train_para
				 *lane_voltage_pre_emphasis,
				 u8 *lane_voltage_pre_emphasis_set)
{}

static bool
it6505_step_cr_train(struct it6505 *it6505,
		     struct it6505_step_train_para *lane_voltage_pre_emphasis)
{}

static bool
it6505_step_eq_train(struct it6505 *it6505,
		     struct it6505_step_train_para *lane_voltage_pre_emphasis)
{}

static bool it6505_link_start_step_train(struct it6505 *it6505)
{}

static bool it6505_get_video_status(struct it6505 *it6505)
{}

static void it6505_reset_hdcp(struct it6505 *it6505)
{}

static void it6505_start_hdcp(struct it6505 *it6505)
{}

static void it6505_stop_hdcp(struct it6505 *it6505)
{}

static bool it6505_hdcp_is_ksv_valid(u8 *ksv)
{}

static void it6505_hdcp_part1_auth(struct it6505 *it6505)
{}

static int it6505_sha1_digest(struct it6505 *it6505, u8 *sha1_input,
			      unsigned int size, u8 *output_av)
{}

static int it6505_setup_sha1_input(struct it6505 *it6505, u8 *sha1_input)
{}

static bool it6505_hdcp_part2_ksvlist_check(struct it6505 *it6505)
{}

static void it6505_hdcp_wait_ksv_list(struct work_struct *work)
{}

static void it6505_hdcp_work(struct work_struct *work)
{}

static void it6505_show_hdcp_info(struct it6505 *it6505)
{}

static void it6505_stop_link_train(struct it6505 *it6505)
{}

static void it6505_link_train_ok(struct it6505 *it6505)
{}

static void it6505_link_step_train_process(struct it6505 *it6505)
{}

static void it6505_link_training_work(struct work_struct *work)
{}

static void it6505_plugged_status_to_codec(struct it6505 *it6505)
{}

static void it6505_remove_edid(struct it6505 *it6505)
{}

static int it6505_process_hpd_irq(struct it6505 *it6505)
{}

static void it6505_irq_hpd(struct it6505 *it6505)
{}

static void it6505_irq_hpd_irq(struct it6505 *it6505)
{}

static void it6505_irq_scdt(struct it6505 *it6505)
{}

static void it6505_irq_hdcp_done(struct it6505 *it6505)
{}

static void it6505_irq_hdcp_fail(struct it6505 *it6505)
{}

static void it6505_irq_aux_cmd_fail(struct it6505 *it6505)
{}

static void it6505_irq_hdcp_ksv_check(struct it6505 *it6505)
{}

static void it6505_irq_audio_fifo_error(struct it6505 *it6505)
{}

static void it6505_irq_link_train_fail(struct it6505 *it6505)
{}

static bool it6505_test_bit(unsigned int bit, const unsigned int *addr)
{}

static void it6505_irq_video_handler(struct it6505 *it6505, const int *int_status)
{}

static irqreturn_t it6505_int_threaded_handler(int unused, void *data)
{}

static int it6505_poweron(struct it6505 *it6505)
{}

static int it6505_poweroff(struct it6505 *it6505)
{}

static enum drm_connector_status it6505_detect(struct it6505 *it6505)
{}

static int it6505_extcon_notifier(struct notifier_block *self,
				  unsigned long event, void *ptr)
{}

static void it6505_extcon_work(struct work_struct *work)
{}

static int it6505_use_notifier_module(struct it6505 *it6505)
{}

static void it6505_remove_notifier_module(struct it6505 *it6505)
{}

static void __maybe_unused it6505_delayed_audio(struct work_struct *work)
{}

static int __maybe_unused it6505_audio_setup_hw_params(struct it6505 *it6505,
						       struct hdmi_codec_params
						       *params)
{}

static void __maybe_unused it6505_audio_shutdown(struct device *dev, void *data)
{}

static int __maybe_unused it6505_audio_hook_plugged_cb(struct device *dev,
						       void *data,
						       hdmi_codec_plugged_cb fn,
						       struct device *codec_dev)
{}

static inline struct it6505 *bridge_to_it6505(struct drm_bridge *bridge)
{}

static int it6505_bridge_attach(struct drm_bridge *bridge,
				enum drm_bridge_attach_flags flags)
{}

static void it6505_bridge_detach(struct drm_bridge *bridge)
{}

static enum drm_mode_status
it6505_bridge_mode_valid(struct drm_bridge *bridge,
			 const struct drm_display_info *info,
			 const struct drm_display_mode *mode)
{}

static void it6505_bridge_atomic_enable(struct drm_bridge *bridge,
					struct drm_bridge_state *old_state)
{}

static void it6505_bridge_atomic_disable(struct drm_bridge *bridge,
					 struct drm_bridge_state *old_state)
{}

static void it6505_bridge_atomic_pre_enable(struct drm_bridge *bridge,
					    struct drm_bridge_state *old_state)
{}

static void it6505_bridge_atomic_post_disable(struct drm_bridge *bridge,
					      struct drm_bridge_state *old_state)
{}

static enum drm_connector_status
it6505_bridge_detect(struct drm_bridge *bridge)
{}

static const struct drm_edid *it6505_bridge_edid_read(struct drm_bridge *bridge,
						      struct drm_connector *connector)
{}

static const struct drm_bridge_funcs it6505_bridge_funcs =;

static __maybe_unused int it6505_bridge_resume(struct device *dev)
{}

static __maybe_unused int it6505_bridge_suspend(struct device *dev)
{}

static const struct dev_pm_ops it6505_bridge_pm_ops =;

static int it6505_init_pdata(struct it6505 *it6505)
{}

static int it6505_get_data_lanes_count(const struct device_node *endpoint,
				       const unsigned int min,
				       const unsigned int max)
{}

static void it6505_parse_dt(struct it6505 *it6505)
{}

static ssize_t receive_timing_debugfs_show(struct file *file, char __user *buf,
					   size_t len, loff_t *ppos)
{}

static int force_power_on_off_debugfs_write(void *data, u64 value)
{}

static int enable_drv_hold_debugfs_show(void *data, u64 *buf)
{}

static int enable_drv_hold_debugfs_write(void *data, u64 drv_hold)
{}

static const struct file_operations receive_timing_fops =;

DEFINE_DEBUGFS_ATTRIBUTE();

DEFINE_DEBUGFS_ATTRIBUTE();

static const struct debugfs_entries debugfs_entry[] =;

static void debugfs_create_files(struct it6505 *it6505)
{}

static void debugfs_init(struct it6505 *it6505)
{}

static void it6505_debugfs_remove(struct it6505 *it6505)
{}

static void it6505_shutdown(struct i2c_client *client)
{}

static int it6505_i2c_probe(struct i2c_client *client)
{}

static void it6505_i2c_remove(struct i2c_client *client)
{}

static const struct i2c_device_id it6505_id[] =;

MODULE_DEVICE_TABLE(i2c, it6505_id);

static const struct of_device_id it6505_of_match[] =;

static struct i2c_driver it6505_i2c_driver =;

module_i2c_driver();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();