diff options
Diffstat (limited to 'drivers/video/av8100/av8100.c')
-rw-r--r-- | drivers/video/av8100/av8100.c | 1105 |
1 files changed, 733 insertions, 372 deletions
diff --git a/drivers/video/av8100/av8100.c b/drivers/video/av8100/av8100.c index dd0fcaade23..e4df11441a1 100644 --- a/drivers/video/av8100/av8100.c +++ b/drivers/video/av8100/av8100.c @@ -29,17 +29,18 @@ #include <video/av8100.h> #include <video/hdmi.h> #include "av8100_fw.h" +#include "av8100v2_fw.h" #define AV8100_INT_EVENT 0x1 #define AV8100_TIMER_INT_EVENT 0x2 #define AV8100_TIMER_INTERRUPT_POLLING_TIME 250 -#define AV8100_DRIVER_MINOR_NUMBER 240 #define GPIO_AV8100_RSTN 196 #define AV8100_MASTER_CLOCK_TIMING 0x3 #define AV8100_ON_TIME 1 -#define AV8100_OFF_TIME 0 +#define AV8100_DENC_OFF_TIME 3 +#define AV8100_HDMI_OFF_TIME 0 #define AV8100_COMMAND_OFFSET 0x10 #define AV8100_COMMAND_MAX_LENGTH 0x81 @@ -57,17 +58,28 @@ #define HDMI_CEC_MESSAGE_WRITE_BUFFER_SIZE 16 #define HDMI_HDCP_SEND_KEY_SIZE 7 #define HDMI_INFOFRAME_DATA_SIZE 28 -#define HDMI_CEC_MESSAGE_READBACK_MAXSIZE 16 #define HDMI_FUSE_AES_KEY_SIZE 16 -#define REG_16_8_LSB(p) (u8)(p & 0xFF) -#define REG_16_8_MSB(p) (u8)((p & 0xFF00)>>8) -#define REG_32_8_MSB(p) (u8)((p & 0xFF000000)>>24) -#define REG_32_8_MMSB(p) (u8)((p & 0x00FF0000)>>16) -#define REG_32_8_MLSB(p) (u8)((p & 0x0000FF00)>>8) -#define REG_32_8_LSB(p) (u8)(p & 0x000000FF) -#define REG_10_8_MSB(p) (u8)((p & 0x300)>>8) +#define HPDS_INVALID 0xF +#define CPDS_INVALID 0xF +#define CECRX_INVALID 0xF +#define REG_16_8_LSB(p) ((u8)(p & 0xFF)) +#define REG_16_8_MSB(p) ((u8)((p & 0xFF00)>>8)) +#define REG_32_8_MSB(p) ((u8)((p & 0xFF000000)>>24)) +#define REG_32_8_MMSB(p) ((u8)((p & 0x00FF0000)>>16)) +#define REG_32_8_MLSB(p) ((u8)((p & 0x0000FF00)>>8)) +#define REG_32_8_LSB(p) ((u8)(p & 0x000000FF)) +#define REG_10_8_MSB(p) ((u8)((p & 0x300)>>8)) +#define REG_12_8_MSB(p) ((u8)((p & 0xf00)>>8)) + +DEFINE_MUTEX(av8100_hw_mutex); +#define LOCK_AV8100_HW mutex_lock(&av8100_hw_mutex) +#define UNLOCK_AV8100_HW mutex_unlock(&av8100_hw_mutex) + +#define AV8100_DEBUG_EXTRA +#define AV8100_PLUGIN_DETECT_VIA_TIMER_INTERRUPTS +#define CEC_ADDR_OFFSET 3 struct av8100_config_t { struct i2c_client *client; @@ -94,6 +106,21 @@ struct av8100_config_t { struct av8100_fuse_aes_key_format_cmd hdmi_fuse_aes_key_cmd; }; +struct av8100_globals_t { + int denc_off_time;/* 5 volt time */ + int hdmi_off_time;/* 5 volt time */ + int on_time;/* 5 volt time */ + u8 hpdm;/*stby_int_mask*/ + u8 cpdm;/*stby_int_mask*/ +#ifdef AV8100_PLUGIN_DETECT_VIA_TIMER_INTERRUPTS + u8 hpds_old; + u8 cpds_old; + u8 cecrx_old; + u8 hdcps_old; +#endif + void (*hdmi_ev_cb)(enum av8100_hdmi_event); +}; + /** * struct av8100_cea - CEA(consumer electronic access) standard structure * @cea_id: @@ -142,13 +169,10 @@ enum av8100_command_size { AV8100_COMMAND_FUSE_AES_KEY_SIZE = 0x12, }; -DEFINE_MUTEX(av8100_hw_mutex); -#define LOCK_AV8100_HW mutex_lock(&av8100_hw_mutex) -#define UNLOCK_AV8100_HW mutex_unlock(&av8100_hw_mutex) - -#define AV8100_DEBUG_EXTRA -#define AV8100_PLUGIN_DETECT_VIA_TIMER_INTERRUPTS - +static void clr_plug_status(enum av8100_plugin_status status); +static void set_plug_status(enum av8100_plugin_status status); +static void cec_rx(void); +static void hdcp_changed(void); static int av8100_open(struct inode *inode, struct file *filp); static int av8100_release(struct inode *inode, struct file *filp); static int av8100_ioctl(struct inode *inode, struct file *file, @@ -164,6 +188,10 @@ static struct timer_list av8100_timer; #endif static wait_queue_head_t av8100_event; static int av8100_flag = 0x0; +static struct av8100_globals_t *av8100_globals; +static u8 chip_version; +static char av8100_receivetab[AV8100_FW_SIZE_V2]; +struct device *av8100dev; static const struct file_operations av8100_fops = { .owner = THIS_MODULE, @@ -173,7 +201,7 @@ static const struct file_operations av8100_fops = { }; static struct miscdevice av8100_miscdev = { - AV8100_DRIVER_MINOR_NUMBER, + MISC_DYNAMIC_MINOR, "av8100", &av8100_fops }; @@ -301,6 +329,101 @@ struct av8100_cea av8100_all_cea[29] = { "-", 0, 0, 0, 0, 0} /*Settings to be define*/ }; +const struct av8100_color_space_conversion_format_cmd col_cvt_identity = { + .c0 = 0x0100, + .c1 = 0x0000, + .c2 = 0x0000, + .c3 = 0x0000, + .c4 = 0x0100, + .c5 = 0x0000, + .c6 = 0x0000, + .c7 = 0x0000, + .c8 = 0x0100, + .aoffset = 0x0000, + .boffset = 0x0000, + .coffset = 0x0000, + .lmax = 0xff, + .lmin = 0x00, + .cmax = 0xff, + .cmin = 0x00, +}; + +const struct av8100_color_space_conversion_format_cmd + col_cvt_identity_clamp_yuv = { + .c0 = 0x0100, + .c1 = 0x0000, + .c2 = 0x0000, + .c3 = 0x0000, + .c4 = 0x0100, + .c5 = 0x0000, + .c6 = 0x0000, + .c7 = 0x0000, + .c8 = 0x0100, + .aoffset = 0x0000, + .boffset = 0x0000, + .coffset = 0x0000, + .lmax = 0xeb, + .lmin = 0x10, + .cmax = 0xf0, + .cmin = 0x10, +}; + +const struct av8100_color_space_conversion_format_cmd col_cvt_yuv422_to_rgb = { + .c0 = 0x00ba, + .c1 = 0x007d, + .c2 = 0x0000, + .c3 = 0xffa1, + .c4 = 0x007d, + .c5 = 0xffd3, + .c6 = 0x0000, + .c7 = 0x007d, + .c8 = 0x00eb, + .aoffset = 0xff9b, + .boffset = 0x003e, + .coffset = 0xff82, + .lmax = 0xff, + .lmin = 0x00, + .cmax = 0xff, + .cmin = 0x00, +}; + +const struct av8100_color_space_conversion_format_cmd col_cvt_yuv422_to_denc = { + .c0 = 0x0000, + .c1 = 0x0000, + .c2 = 0x0100, + .c3 = 0x0000, + .c4 = 0x0100, + .c5 = 0x0000, + .c6 = 0x0100, + .c7 = 0x0000, + .c8 = 0x0000, + .aoffset = 0x0000, + .boffset = 0x0000, + .coffset = 0x0000, + .lmax = 0xeb, + .lmin = 0x10, + .cmax = 0xf0, + .cmin = 0x10, +}; + +const struct av8100_color_space_conversion_format_cmd col_cvt_rgb_to_denc = { + .c0 = 0xffda, + .c1 = 0xffb6, + .c2 = 0x0070, + .c3 = 0x0042, + .c4 = 0x0081, + .c5 = 0x0019, + .c6 = 0x0070, + .c7 = 0xffa2, + .c8 = 0xffee, + .aoffset = 0x007f, + .boffset = 0x0010, + .coffset = 0x007f, + .lmax = 0xff, + .lmin = 0x00, + .cmax = 0xff, + .cmin = 0x00, +}; static const struct i2c_device_id av8100_id[] = { { "av8100", 0 }, @@ -332,15 +455,16 @@ static void av8100_timer_int(unsigned long value) static int av8100_thread(void *p) { - u8 cpd = 0; - u8 stby = 0; u8 hpds = 0; u8 cpds = 0; - u8 mclkrng = 0; + u8 hdcps = 0; int ret = 0; #ifdef AV8100_PLUGIN_DETECT_VIA_TIMER_INTERRUPTS - u8 hpds_old = 0xf; - u8 cpds_old = 0xf; + u8 cecrx; + u8 *hpds_old; + u8 *cpds_old; + u8 *cecrx_old; + u8 *hdcps_old; #else u8 sid = 0; u8 oni = 0; @@ -351,57 +475,65 @@ static int av8100_thread(void *p) while (1) { wait_event_interruptible(av8100_event, (av8100_flag != 0)); #ifdef AV8100_PLUGIN_DETECT_VIA_TIMER_INTERRUPTS - if (av8100_flag & AV8100_TIMER_INT_EVENT) { - if (g_av8100_status.av8100_state >= - AV8100_OPMODE_STANDBY) { - /* STANDBY */ - ret = av8100_register_standby_read( - &cpd, - &stby, - &hpds, - &cpds, - &mclkrng); - if (ret != 0) - printk(KERN_DEBUG "av8100_register_" - "standby_read fail\n"); - - /* TVout plugin change */ - if ((cpds == 1) && (cpds != cpds_old)) { - cpds_old = 1; - - g_av8100_status.av8100_plugin_status |= - AV8100_CVBS_PLUGIN; + if ((av8100_flag & AV8100_TIMER_INT_EVENT) && + (g_av8100_status.av8100_state >= + AV8100_OPMODE_STANDBY)) { + hpds_old = &(av8100_globals->hpds_old); + cpds_old = &(av8100_globals->cpds_old); + cecrx_old = &(av8100_globals->cecrx_old); + hdcps_old = &(av8100_globals->hdcps_old); + + /* STANDBY reg */ + if (av8100_reg_stby_r( + NULL, + NULL, + &hpds, + &cpds, + NULL) != 0) + dev_dbg(av8100dev, "av8100_reg_" + "stby_r fail\n"); - /* TODO: notify */ - printk(KERN_DEBUG "TVout plugin detected\n"); - } else if ((cpds == 0) && (cpds != cpds_old)) { - cpds_old = 0; - - g_av8100_status.av8100_plugin_status &= - ~AV8100_CVBS_PLUGIN; + /* TVout plugin change */ + if ((cpds == 1) && (cpds != *cpds_old)) { + *cpds_old = 1; - /* TODO: notify */ - printk(KERN_DEBUG "TVout plugout detected\n"); - } + set_plug_status(AV8100_CVBS_PLUGIN); + } else if ((cpds == 0) && (cpds != *cpds_old)) { + *cpds_old = 0; - /* HDMI plugin change */ - if ((hpds == 1) && (hpds != hpds_old)) { - hpds_old = 1; + clr_plug_status(AV8100_CVBS_PLUGIN); + } - g_av8100_status.av8100_plugin_status |= - AV8100_HDMI_PLUGIN; + /* HDMI plugin change */ + if ((hpds == 1) && (hpds != *hpds_old)) { + *hpds_old = 1; - /* TODO: notify */ - printk(KERN_DEBUG "HDMI plugin detected\n"); - } else if ((hpds == 0) && (hpds != hpds_old)) { - hpds_old = 0; + set_plug_status(AV8100_HDMI_PLUGIN); + } else if ((hpds == 0) && (hpds != *hpds_old)) { + *hpds_old = 0; - g_av8100_status.av8100_plugin_status &= - ~AV8100_HDMI_PLUGIN; + clr_plug_status(AV8100_HDMI_PLUGIN); + } - /* TODO: notify */ - printk(KERN_DEBUG "HDMI plugout detected\n"); - } + /* GENERAL_STATUS reg */ + if (av8100_reg_gen_status_r( + &cecrx, + NULL, + NULL, + NULL, + &hdcps) != 0) + dev_dbg(av8100dev, "av8100_reg_" + "gen_status_r fail\n"); + else { + if ((cecrx == 1) && (cecrx != *cecrx_old)) + /* Report CEC event */ + cec_rx(); + *cecrx_old = cecrx; + + if (hdcps != *hdcps_old) + /* Report HDCP status change event */ + hdcp_changed(); + *hdcps_old = hdcps; } } #else @@ -413,7 +545,7 @@ static int av8100_thread(void *p) &sid); if (ret) - printk(KERN_DEBUG "av8100_register_standby_" + dev_dbg(av8100dev, "av8100_register_standby_" "pending_interrupt_read failed\n"); if (hpdi | cpdi | oni) { @@ -425,36 +557,22 @@ static int av8100_thread(void *p) &cpds, &mclkrng); if (ret) - printk(KERN_DEBUG "av8100_register_standby_" + dev_dbg(av8100dev, "av8100_register_standby_" "read fail\n"); } if (cpdi) { /* TVout plugin change */ if (cpds) - g_av8100_status.av8100_plugin_status |= - AV8100_CVBS_PLUGIN; + set_plug_status(AV8100_CVBS_PLUGIN); else - g_av8100_status.av8100_plugin_status &= - ~AV8100_CVBS_PLUGIN; - - /* TODO: notify */ - printk(KERN_DEBUG "TVout plugin: %d\n", ( - g_av8100_status.av8100_plugin_status & - AV8100_CVBS_PLUGIN) == AV8100_CVBS_PLUGIN); + clr_plug_status(AV8100_CVBS_PLUGIN); } else if (hpdi) { /* HDMI plugin change */ if (hpds) - g_av8100_status.av8100_plugin_status |= - AV8100_HDMI_PLUGIN; + set_plug_status(AV8100_HDMI_PLUGIN); else - g_av8100_status.av8100_plugin_status &= - ~AV8100_HDMI_PLUGIN; - - /* TODO: notify */ - printk(KERN_DEBUG "HDMI plugin: %d\n", ( - g_av8100_status.av8100_plugin_status & - AV8100_HDMI_PLUGIN) == AV8100_HDMI_PLUGIN); + clr_plug_status(AV8100_HDMI_PLUGIN); } if (hpdi | cpdi | oni) { @@ -464,7 +582,7 @@ static int av8100_thread(void *p) cpdi, oni); if (ret) - printk(KERN_DEBUG "av8100_register_standby_" + dev_dbg(av8100dev, "av8100_register_standby_" "read fail\n"); } #endif @@ -603,15 +721,14 @@ static int av8100_config_video_output_dep(enum av8100_output_CEA_VESA config.video_input_format.ui_x4 = av8100_get_ui_x4(output_format); config.video_input_format.TE_line_nb = av8100_get_te_line_nb( output_format); -/* TODO: Dynamic test to detect AV8100 V1 or V2 */ -#ifdef AV8100_HW_TE_I2SDAT3 +#ifdef CONFIG_AV8100_HWTRIG_I2SDAT3 config.video_input_format.TE_config = AV8100_TE_GPIO_IT; #else config.video_input_format.TE_config = AV8100_TE_IT_LINE; #endif config.video_input_format.master_clock_freq = 0; - retval = av8100_configuration_prepare( + retval = av8100_conf_prep( AV8100_COMMAND_VIDEO_INPUT_FORMAT, &config); /* DENC */ @@ -639,11 +756,11 @@ static int av8100_config_init(void) int retval = 0; union av8100_configuration config; - printk(KERN_DEBUG "%s\n", __func__); + dev_dbg(av8100dev, "%s\n", __func__); av8100_config = kzalloc(sizeof(struct av8100_config_t), GFP_KERNEL); if (!av8100_config) { - pr_err("%s: Failed to allocate config\n", __func__); + dev_err(av8100dev, "%s: Failed to allocate config\n", __func__); return AV8100_FAIL; } @@ -651,24 +768,8 @@ static int av8100_config_init(void) memset(av8100_config, 0, sizeof(union av8100_configuration)); /* Color conversion */ - /* TODO: Magic numbers. Move to platform data? */ - config.color_space_conversion_format.c0 = 0x0100; - config.color_space_conversion_format.c1 = 0x0000; - config.color_space_conversion_format.c2 = 0x0000; - config.color_space_conversion_format.c3 = 0x0000; - config.color_space_conversion_format.c4 = 0x0100; - config.color_space_conversion_format.c5 = 0x0000; - config.color_space_conversion_format.c6 = 0x0000; - config.color_space_conversion_format.c7 = 0x0000; - config.color_space_conversion_format.c8 = 0x0100; - config.color_space_conversion_format.aoffset = 0x0000; - config.color_space_conversion_format.boffset = 0x0000; - config.color_space_conversion_format.coffset = 0x0000; - config.color_space_conversion_format.lmax = 0xff; - config.color_space_conversion_format.lmin = 0x00; - config.color_space_conversion_format.cmax = 0xff; - config.color_space_conversion_format.cmin = 0x00; - retval = av8100_configuration_prepare( + config.color_space_conversion_format = col_cvt_identity; + retval = av8100_conf_prep( AV8100_COMMAND_COLORSPACECONVERSION, &config); if (retval) return AV8100_FAIL; @@ -684,7 +785,7 @@ static int av8100_config_init(void) config.video_output_format.video_output_cea_vesa = AV8100_CEA4_1280X720P_60HZ; - retval = av8100_configuration_prepare( + retval = av8100_conf_prep( AV8100_COMMAND_VIDEO_OUTPUT_FORMAT, &config); if (retval) return AV8100_FAIL; @@ -700,7 +801,7 @@ static int av8100_config_init(void) AV8100_PATTERN_GENERATOR; config.pattern_generator_format.pattern_video_format = AV8100_PATTERN_720P; - retval = av8100_configuration_prepare(AV8100_COMMAND_PATTERNGENERATOR, + retval = av8100_conf_prep(AV8100_COMMAND_PATTERNGENERATOR, &config); if (retval) return AV8100_FAIL; @@ -714,7 +815,7 @@ static int av8100_config_init(void) config.audio_input_format.audio_format = AV8100_AUDIO_LPCM_MODE; config.audio_input_format.audio_if_mode = AV8100_AUDIO_MASTER; config.audio_input_format.audio_mute = AV8100_AUDIO_MUTE_DISABLE; - retval = av8100_configuration_prepare( + retval = av8100_conf_prep( AV8100_COMMAND_AUDIO_INPUT_FORMAT, &config); if (retval) return AV8100_FAIL; @@ -723,14 +824,14 @@ static int av8100_config_init(void) config.hdmi_format.hdmi_mode = AV8100_HDMI_ON; config.hdmi_format.hdmi_format = AV8100_HDMI; config.hdmi_format.dvi_format = AV8100_DVI_CTRL_CTL0; - retval = av8100_configuration_prepare(AV8100_COMMAND_HDMI, &config); + retval = av8100_conf_prep(AV8100_COMMAND_HDMI, &config); if (retval) return AV8100_FAIL; /* EDID section readback */ config.edid_section_readback_format.address = 0xA0; config.edid_section_readback_format.block_number = 0; - retval = av8100_configuration_prepare( + retval = av8100_conf_prep( AV8100_COMMAND_EDID_SECTION_READBACK, &config); if (retval) return AV8100_FAIL; @@ -740,15 +841,105 @@ static int av8100_config_init(void) static void av8100_config_exit(void) { - printk(KERN_DEBUG "%s\n", __func__); + dev_dbg(av8100dev, "%s\n", __func__); kfree(av8100_config); av8100_config = NULL; } +static int av8100_globals_init(void) +{ + dev_dbg(av8100dev, "%s\n", __func__); + + av8100_globals = kzalloc(sizeof(struct av8100_globals_t), GFP_KERNEL); + if (!av8100_globals) { + dev_err(av8100dev, "%s: Alloc failure \n", __func__); + return AV8100_FAIL; + } + + av8100_globals->denc_off_time = AV8100_DENC_OFF_TIME; + av8100_globals->hdmi_off_time = AV8100_HDMI_OFF_TIME; + av8100_globals->on_time = AV8100_ON_TIME; + av8100_globals->hpdm = AV8100_STANDBY_INTERRUPT_MASK_HPDM_LOW; + av8100_globals->cpdm = AV8100_STANDBY_INTERRUPT_MASK_CPDM_LOW; +#ifdef AV8100_PLUGIN_DETECT_VIA_TIMER_INTERRUPTS + av8100_globals->hpds_old = 0xf; + av8100_globals->cpds_old = 0xf; + av8100_globals->cecrx_old = 0xf; + av8100_globals->hdcps_old = 0xf; +#endif + + return 0; +} + +static void av8100_globals_exit(void) +{ + dev_dbg(av8100dev, "%s\n", __func__); + + kfree(av8100_globals); + av8100_globals = NULL; +} + +static void clr_plug_status(enum av8100_plugin_status status) +{ + g_av8100_status.av8100_plugin_status &= ~status; + + switch (status) { + case AV8100_HDMI_PLUGIN: + if (av8100_globals->hdmi_ev_cb) + av8100_globals->hdmi_ev_cb( + AV8100_HDMI_EVENT_HDMI_PLUGOUT); + break; + + case AV8100_CVBS_PLUGIN: + /* TODO */ + break; + + default: + break; + } +} + +static void set_plug_status(enum av8100_plugin_status status) +{ + g_av8100_status.av8100_plugin_status |= status; + + switch (status) { + case AV8100_HDMI_PLUGIN: + if (av8100_globals->hdmi_ev_cb) + av8100_globals->hdmi_ev_cb( + AV8100_HDMI_EVENT_HDMI_PLUGIN); + break; + + case AV8100_CVBS_PLUGIN: + /* TODO */ + break; + + default: + break; + } +} + +static void cec_rx(void) +{ + if (av8100_globals->hdmi_ev_cb) + av8100_globals->hdmi_ev_cb(AV8100_HDMI_EVENT_CEC); +} + +static void hdcp_changed(void) +{ + if (av8100_globals->hdmi_ev_cb) + av8100_globals->hdmi_ev_cb(AV8100_HDMI_EVENT_HDCP); +} + static void av8100_set_state(enum av8100_operating_mode state) { g_av8100_status.av8100_state = state; + if (state <= AV8100_OPMODE_STANDBY) { + clr_plug_status(AV8100_HDMI_PLUGIN); + clr_plug_status(AV8100_CVBS_PLUGIN); + g_av8100_status.hdmi_on = false; + } } /** @@ -767,7 +958,7 @@ static int write_single_byte(struct i2c_client *client, u8 reg, ret = i2c_smbus_write_byte_data(client, reg, data); if (ret < 0) - printk(KERN_DEBUG "i2c smbus write byte failed\n"); + dev_dbg(av8100dev, "i2c smbus write byte failed\n"); return ret; } @@ -788,7 +979,7 @@ static int read_single_byte(struct i2c_client *client, u8 reg, u8 *val) value = i2c_smbus_read_byte_data(client, reg); if (value < 0) { - printk(KERN_DEBUG "i2c smbus read byte failed,read data = %x " + dev_dbg(av8100dev, "i2c smbus read byte failed,read data = %x " "from offset:%x\n" , value, reg); return AV8100_FAIL; } @@ -814,7 +1005,7 @@ static int write_multi_byte(struct i2c_client *client, u8 reg, ret = i2c_smbus_write_i2c_block_data(client, reg, nbytes, buf); if (ret < 0) - printk(KERN_DEBUG "i2c smbus write multi byte error\n"); + dev_dbg(av8100dev, "i2c smbus write multi byte error\n"); return ret; } @@ -1014,51 +1205,51 @@ static int configuration_colorspace_conversion_get(char *buffer, if (!av8100_config) return AV8100_FAIL; - buffer[0] = REG_10_8_MSB(av8100_config-> + buffer[0] = REG_12_8_MSB(av8100_config-> hdmi_color_space_conversion_cmd.c0); buffer[1] = REG_16_8_LSB(av8100_config-> hdmi_color_space_conversion_cmd.c0); - buffer[2] = REG_10_8_MSB(av8100_config-> + buffer[2] = REG_12_8_MSB(av8100_config-> hdmi_color_space_conversion_cmd.c1); buffer[3] = REG_16_8_LSB(av8100_config-> hdmi_color_space_conversion_cmd.c1); - buffer[4] = REG_10_8_MSB(av8100_config-> + buffer[4] = REG_12_8_MSB(av8100_config-> hdmi_color_space_conversion_cmd.c2); buffer[5] = REG_16_8_LSB(av8100_config-> hdmi_color_space_conversion_cmd.c2); - buffer[6] = REG_10_8_MSB(av8100_config-> + buffer[6] = REG_12_8_MSB(av8100_config-> hdmi_color_space_conversion_cmd.c3); buffer[7] = REG_16_8_LSB(av8100_config-> hdmi_color_space_conversion_cmd.c3); - buffer[8] = REG_10_8_MSB(av8100_config-> + buffer[8] = REG_12_8_MSB(av8100_config-> hdmi_color_space_conversion_cmd.c4); buffer[9] = REG_16_8_LSB(av8100_config-> hdmi_color_space_conversion_cmd.c4); - buffer[10] = REG_10_8_MSB(av8100_config-> + buffer[10] = REG_12_8_MSB(av8100_config-> hdmi_color_space_conversion_cmd.c5); buffer[11] = REG_16_8_LSB(av8100_config-> hdmi_color_space_conversion_cmd.c5); - buffer[12] = REG_10_8_MSB(av8100_config-> + buffer[12] = REG_12_8_MSB(av8100_config-> hdmi_color_space_conversion_cmd.c6); buffer[13] = REG_16_8_LSB(av8100_config-> hdmi_color_space_conversion_cmd.c6); - buffer[14] = REG_10_8_MSB(av8100_config-> + buffer[14] = REG_12_8_MSB(av8100_config-> hdmi_color_space_conversion_cmd.c7); buffer[15] = REG_16_8_LSB(av8100_config-> hdmi_color_space_conversion_cmd.c7); - buffer[16] = REG_10_8_MSB(av8100_config-> + buffer[16] = REG_12_8_MSB(av8100_config-> hdmi_color_space_conversion_cmd.c8); buffer[17] = REG_16_8_LSB(av8100_config-> hdmi_color_space_conversion_cmd.c8); - buffer[18] = REG_16_8_MSB(av8100_config-> + buffer[18] = REG_10_8_MSB(av8100_config-> hdmi_color_space_conversion_cmd.aoffset); buffer[19] = REG_16_8_LSB(av8100_config-> hdmi_color_space_conversion_cmd.aoffset); - buffer[20] = REG_16_8_MSB(av8100_config-> + buffer[20] = REG_10_8_MSB(av8100_config-> hdmi_color_space_conversion_cmd.boffset); buffer[21] = REG_16_8_LSB(av8100_config-> hdmi_color_space_conversion_cmd.boffset); - buffer[22] = REG_16_8_MSB(av8100_config-> + buffer[22] = REG_10_8_MSB(av8100_config-> hdmi_color_space_conversion_cmd.coffset); buffer[23] = REG_16_8_LSB(av8100_config-> hdmi_color_space_conversion_cmd.coffset); @@ -1132,11 +1323,10 @@ static int configuration_hdcp_sendkey_get(char *buffer, return AV8100_FAIL; buffer[0] = av8100_config->hdmi_hdcp_send_key_cmd.key_number; - buffer[1] = 0; - memcpy(&buffer[2], av8100_config->hdmi_hdcp_send_key_cmd.key, - HDMI_HDCP_SEND_KEY_SIZE); + memcpy(&buffer[1], av8100_config->hdmi_hdcp_send_key_cmd.data, + av8100_config->hdmi_hdcp_send_key_cmd.data_len); - *length = AV8100_COMMAND_HDCP_SENDKEY_SIZE - 1; + *length = av8100_config->hdmi_hdcp_send_key_cmd.data_len + 1; return 0; } @@ -1146,12 +1336,9 @@ static int configuration_hdcp_management_get(char *buffer, if (!av8100_config) return AV8100_FAIL; - buffer[0] = av8100_config->hdmi_hdcp_management_format_cmd. - request_hdcp_revocation_list; - buffer[1] = av8100_config->hdmi_hdcp_management_format_cmd. - request_encrypted_transmission; - buffer[2] = av8100_config->hdmi_hdcp_management_format_cmd. - oess_eess_encryption_use; + buffer[0] = av8100_config->hdmi_hdcp_management_format_cmd.req_type; + buffer[1] = av8100_config->hdmi_hdcp_management_format_cmd.req_encr; + buffer[2] = av8100_config->hdmi_hdcp_management_format_cmd.encr_use; *length = AV8100_COMMAND_HDCP_MANAGEMENT_SIZE - 1; return 0; @@ -1227,11 +1414,11 @@ static int get_command_return_data(struct i2c_client *i2c, /* Get the first return byte */ retval = read_single_byte(i2c, AV8100_COMMAND_OFFSET, &val); if (retval) - goto get_command_return_data_fail; + goto get_command_return_data_fail1r; if (val != (0x80 | command_type)) { retval = AV8100_FAIL; - goto get_command_return_data_fail; + goto get_command_return_data_fail1v; } switch (command_type) { @@ -1250,11 +1437,11 @@ static int get_command_return_data(struct i2c_client *i2c, retval = read_single_byte(i2c, AV8100_COMMAND_OFFSET + 1, &val); if (retval) - goto get_command_return_data_fail; + goto get_command_return_data_fail2r; if (val) { retval = AV8100_FAIL; - goto get_command_return_data_fail; + goto get_command_return_data_fail2v; } break; @@ -1266,27 +1453,31 @@ static int get_command_return_data(struct i2c_client *i2c, /* Get the return buffer length */ retval = read_single_byte(i2c, - AV8100_COMMAND_OFFSET + 3, &val); + AV8100_COMMAND_OFFSET + CEC_ADDR_OFFSET, &val); if (retval) goto get_command_return_data_fail; + /* TODO: buffer_length is always zero */ + /* *buffer_length = val;*/ + dev_dbg(av8100dev, "cec buflen:%d\n", val); *buffer_length = val; if (*buffer_length > - HDMI_CEC_MESSAGE_READBACK_MAXSIZE) { - printk(KERN_DEBUG "CEC size too large %d\n", + HDMI_CEC_READ_MAXSIZE) { + dev_dbg(av8100dev, "CEC size too large %d\n", *buffer_length); - *buffer_length = HDMI_CEC_MESSAGE_READBACK_MAXSIZE; + *buffer_length = HDMI_CEC_READ_MAXSIZE; } #ifdef AV8100_DEBUG_EXTRA - printk(KERN_DEBUG "return data: "); + dev_dbg(av8100dev, "return data: "); #endif /* Get the return buffer */ for (index = 0; index < *buffer_length; ++index) { retval = read_single_byte(i2c, - AV8100_COMMAND_OFFSET + 4 + index, + AV8100_COMMAND_OFFSET + CEC_ADDR_OFFSET + 1 + + index, &val); if (retval) { *buffer_length = 0; @@ -1294,33 +1485,31 @@ static int get_command_return_data(struct i2c_client *i2c, } else { *(buffer + index) = val; #ifdef AV8100_DEBUG_EXTRA - printk(KERN_DEBUG "%02x ", *(buffer + index)); + dev_dbg(av8100dev, "%02x ", *(buffer + index)); #endif } } #ifdef AV8100_DEBUG_EXTRA - printk(KERN_DEBUG "\n"); + dev_dbg(av8100dev, "\n"); #endif break; case AV8100_COMMAND_HDCP_MANAGEMENT: - if ((buffer == NULL) || (buffer_length == NULL) || - (command_buffer == NULL)) { - retval = AV8100_FAIL; - goto get_command_return_data_fail; - } - /* Get the second return byte */ retval = read_single_byte(i2c, AV8100_COMMAND_OFFSET + 1, &val); if (retval) { - goto get_command_return_data_fail; + goto get_command_return_data_fail2r; } else { /* Check the second return byte */ if (val) - goto get_command_return_data_fail; + goto get_command_return_data_fail2v; } + if ((buffer == NULL) || (buffer_length == NULL)) + /* Ignore return data */ + break; + /* Get the return buffer length */ if (command_buffer[0] == HDMI_REQUEST_FOR_REVOCATION_LIST_INPUT) { @@ -1330,7 +1519,7 @@ static int get_command_return_data(struct i2c_client *i2c, } #ifdef AV8100_DEBUG_EXTRA - printk(KERN_DEBUG "return data: "); + dev_dbg(av8100dev, "return data: "); #endif /* Get the return buffer */ for (index = 0; index < *buffer_length; ++index) { @@ -1343,12 +1532,12 @@ static int get_command_return_data(struct i2c_client *i2c, } else { *(buffer + index) = val; #ifdef AV8100_DEBUG_EXTRA - printk(KERN_DEBUG "%02x ", *(buffer + index)); + dev_dbg(av8100dev, "%02x ", *(buffer + index)); #endif } } #ifdef AV8100_DEBUG_EXTRA - printk(KERN_DEBUG "\n"); + dev_dbg(av8100dev, "\n"); #endif break; @@ -1362,7 +1551,7 @@ static int get_command_return_data(struct i2c_client *i2c, *buffer_length = 0x80; #ifdef AV8100_DEBUG_EXTRA - printk(KERN_DEBUG "return data: "); + dev_dbg(av8100dev, "return data: "); #endif /* Get the return buffer */ for (index = 0; index < *buffer_length; ++index) { @@ -1375,12 +1564,12 @@ static int get_command_return_data(struct i2c_client *i2c, } else { *(buffer + index) = val; #ifdef AV8100_DEBUG_EXTRA - printk(KERN_DEBUG "%02x ", *(buffer + index)); + dev_dbg(av8100dev, "%02x ", *(buffer + index)); #endif } } #ifdef AV8100_DEBUG_EXTRA - printk(KERN_DEBUG "\n"); + dev_dbg(av8100dev, "\n"); #endif break; @@ -1394,12 +1583,12 @@ static int get_command_return_data(struct i2c_client *i2c, retval = read_single_byte(i2c, AV8100_COMMAND_OFFSET + 1, &val); if (retval) - goto get_command_return_data_fail; + goto get_command_return_data_fail2r; /* Check the second return byte */ if (val) { retval = AV8100_FAIL; - goto get_command_return_data_fail; + goto get_command_return_data_fail2v; } /* Return buffer length is fixed */ @@ -1413,7 +1602,7 @@ static int get_command_return_data(struct i2c_client *i2c, *(buffer + 0) = val; #ifdef AV8100_DEBUG_EXTRA - printk(KERN_DEBUG "CRC:%02x ", val); + dev_dbg(av8100dev, "CRC:%02x ", val); #endif /* Get programmed status */ @@ -1424,7 +1613,7 @@ static int get_command_return_data(struct i2c_client *i2c, *(buffer + 1) = val; #ifdef AV8100_DEBUG_EXTRA - printk(KERN_DEBUG "programmed:%02x ", val); + dev_dbg(av8100dev, "programmed:%02x ", val); #endif break; @@ -1434,96 +1623,94 @@ static int get_command_return_data(struct i2c_client *i2c, } return retval; +get_command_return_data_fail1r: + dev_dbg(av8100dev, "%s Reading first return byte failed\n", __func__); + return retval; +get_command_return_data_fail1v: + dev_dbg(av8100dev, "%s First return byte is wrong:%x\n", __func__, val); + return retval; +get_command_return_data_fail2r: + dev_dbg(av8100dev, "%s Reading 2nd return byte failed\n", __func__); + return retval; +get_command_return_data_fail2v: + dev_dbg(av8100dev, "%s 2nd return byte is wrong:%x\n", __func__, val); + return retval; get_command_return_data_fail: - printk(KERN_DEBUG "get_command_return_data FAIL\n"); + dev_dbg(av8100dev, "%s FAIL\n", __func__); return retval; } -int av8100_powerup(void) +static int av8100_powerup1(void) { int retval = 0; - struct i2c_client *i2c; - u8 cpd; - u8 stby; - u8 hpds; - u8 cpds; - u8 mclkrng; - u8 off_time; - u8 on_time; - u8 fdl; - u8 hld; - u8 wa; - u8 ra; - - if (!av8100_config) - return AV8100_FAIL; - - i2c = av8100_config->client; /* Reset av8100 */ gpio_set_value(GPIO_AV8100_RSTN, 1); av8100_set_state(AV8100_OPMODE_STANDBY); - /* Master clock timing, running, search for plug */ - retval = av8100_register_standby_write(AV8100_STANDBY_CPD_HIGH, - AV8100_STANDBY_STBY_HIGH, AV8100_MASTER_CLOCK_TIMING); + /* Get chip version */ + retval = av8100_reg_stby_pend_int_r(NULL, NULL, NULL, &chip_version); if (retval) { - pr_err("Failed to write the value to av8100 register\n"); + dev_err(av8100dev, "Failed to read chip version\n"); return -EFAULT; } - retval = av8100_register_standby_read(&cpd, &stby, &hpds, &cpds, - &mclkrng); - if (retval) { - pr_err("Failed to read the value from av8100 register\n"); - return -EFAULT; - } else { - printk(KERN_DEBUG "STANDBY_REG register cpd:%d stby:%d " - "hpds:%d cpds:%d mclkrng:%0x\n", cpd, stby, hpds, - cpds, mclkrng); - } + dev_dbg(av8100dev, "av8100 chip version:%d\n", chip_version); - /* ON time & OFF time on 5v HDMI plug detect */ - retval = av8100_register_hdmi_5_volt_time_write(AV8100_OFF_TIME, - AV8100_ON_TIME); - if (retval) { - pr_err("Failed to write the value to av8100 register\n"); - return -EFAULT; - } + switch (chip_version) { + case AV8100_CHIPVER_1: + case AV8100_CHIPVER_2: + break; - retval = av8100_register_hdmi_5_volt_time_read(&off_time, &on_time); - if (retval) { - pr_err("Failed to read the value from av8100 register\n"); + default: + dev_err(av8100dev, "Unsupported av8100 chip version:%d\n", + chip_version); return -EFAULT; - } else { - printk(KERN_DEBUG "AV8100_5_VOLT_TIME_REG register " - "off_time:%0x on_time:%0x\n", off_time, on_time); + break; } - /* Device in hold mode, enable firmware download*/ - retval = av8100_register_general_control_write( - AV8100_GENERAL_CONTROL_FDL_HIGH, - AV8100_GENERAL_CONTROL_HLD_HIGH, - AV8100_GENERAL_CONTROL_WA_LOW, - AV8100_GENERAL_CONTROL_RA_LOW); + return retval; +} + +static int av8100_powerup2(void) +{ + int retval = 0; + + /* Master clock timing, running, search for plug */ + retval = av8100_reg_stby_w(AV8100_STANDBY_CPD_HIGH, + AV8100_STANDBY_STBY_HIGH, AV8100_MASTER_CLOCK_TIMING); if (retval) { - pr_err("Failed to write the value to av8100 register\n"); + dev_err(av8100dev, + "Failed to write the value to av8100 register\n"); return -EFAULT; } - retval = av8100_register_general_control_read(&fdl, &hld, &wa, &ra); + /* ON time & OFF time on 5v HDMI plug detect */ + retval = av8100_reg_hdmi_5_volt_time_w( + av8100_globals->denc_off_time, + av8100_globals->hdmi_off_time, + av8100_globals->on_time); if (retval) { - pr_err("Failed to read the value from av8100 register\n"); + dev_err(av8100dev, + "Failed to write the value to av8100 register\n"); return -EFAULT; - } else { - printk(KERN_DEBUG "GENERAL_CONTROL_REG register fdl:%d " - "hld:%d wa:%d ra:%d\n", fdl, hld, wa, ra); } av8100_set_state(AV8100_OPMODE_SCAN); + return retval; } +int av8100_powerup(void) +{ + if (av8100_powerup1()) { + dev_err(av8100dev, "av8100_powerup1 fail\n"); + return -EFAULT; + } + + return av8100_powerup2(); +} + int av8100_powerdown(void) { gpio_set_value(GPIO_AV8100_RSTN, 0); @@ -1550,6 +1737,10 @@ int av8100_download_firmware(char *fw_buff, int nbytes, u8 uc; u8 onuvb; u8 hdcps; + u8 fdl; + u8 hld; + u8 wa; + u8 ra; if (!av8100_config) { retval = AV8100_FAIL; @@ -1557,13 +1748,44 @@ int av8100_download_firmware(char *fw_buff, int nbytes, } if (fw_buff == NULL) { - /* use default fw buffer */ - fw_buff = av8100_fw_buff; - nbytes = AV8100_FW_SIZE; + switch (chip_version) { + case AV8100_CHIPVER_1: + fw_buff = av8100_fw_buff_v1; + nbytes = AV8100_FW_SIZE_V1; + break; + + case AV8100_CHIPVER_2: + default: + fw_buff = av8100_fw_buff_v2; + nbytes = AV8100_FW_SIZE_V2; + break; + } } i2c = av8100_config->client; + /* Enable firmware download */ + retval = av8100_reg_gen_ctrl_w( + AV8100_GENERAL_CONTROL_FDL_HIGH, + AV8100_GENERAL_CONTROL_HLD_HIGH, + AV8100_GENERAL_CONTROL_WA_LOW, + AV8100_GENERAL_CONTROL_RA_LOW); + if (retval) { + dev_err(av8100dev, + "Failed to write the value to av8100 register\n"); + return -EFAULT; + } + + retval = av8100_reg_gen_ctrl_r(&fdl, &hld, &wa, &ra); + if (retval) { + dev_err(av8100dev, + "Failed to read the value from av8100 register\n"); + return -EFAULT; + } else { + dev_dbg(av8100dev, "GENERAL_CONTROL_REG register fdl:%d " + "hld:%d wa:%d ra:%d\n", fdl, hld, wa, ra); + } + LOCK_AV8100_HW; temp = nbytes % increment; @@ -1574,14 +1796,15 @@ int av8100_download_firmware(char *fw_buff, int nbytes, AV8100_FIRMWARE_DOWNLOAD_ENTRY, fw_buff + size, increment); if (retval) { - printk(KERN_DEBUG "Failed to download the " + dev_dbg(av8100dev, "Failed to download the " "av8100 firmware\n"); retval = -EFAULT; UNLOCK_AV8100_HW; goto av8100_download_firmware_out; } } else if (if_type == DSI_INTERFACE) { - printk(KERN_DEBUG "DSI_INTERFACE is currently not supported\n"); + dev_dbg(av8100dev, + "DSI_INTERFACE is currently not supported\n"); UNLOCK_AV8100_HW; goto av8100_download_firmware_out; } else { @@ -1599,7 +1822,8 @@ int av8100_download_firmware(char *fw_buff, int nbytes, retval = write_multi_byte(i2c, AV8100_FIRMWARE_DOWNLOAD_ENTRY, fw_buff + size, temp); if (retval) { - printk(KERN_DEBUG "Failed to download the av8100 firmware\n"); + dev_dbg(av8100dev, + "Failed to download the av8100 firmware\n"); retval = -EFAULT; UNLOCK_AV8100_HW; goto av8100_download_firmware_out; @@ -1622,59 +1846,63 @@ int av8100_download_firmware(char *fw_buff, int nbytes, for (size = 0; size < nbytes; size++) { CheckSum = CheckSum ^ fw_buff[size]; if (av8100_receivetab[size] != fw_buff[size]) { - printk(KERN_DEBUG ">Fw download fail....i=%d\n", size); - printk(KERN_DEBUG "Transm = %x, Receiv = %x\n", + dev_dbg(av8100dev, ">Fw download fail....i=%d\n", size); + dev_dbg(av8100dev, "Transm = %x, Receiv = %x\n", fw_buff[size], av8100_receivetab[size]); } } UNLOCK_AV8100_HW; - retval = av8100_register_firmware_download_entry_read(&val); + retval = av8100_reg_fw_dl_entry_r(&val); if (retval) { - printk(KERN_DEBUG "Failed to read the value from the av8100 register\n"); + dev_dbg(av8100dev, + "Failed to read the value from the av8100 register\n"); retval = -EFAULT; goto av8100_download_firmware_out; } - printk(KERN_DEBUG "CheckSum:%x,val:%x\n", CheckSum, val); + dev_dbg(av8100dev, "CheckSum:%x,val:%x\n", CheckSum, val); if (CheckSum != val) { - printk(KERN_DEBUG ">Fw downloading.... FAIL CheckSum issue\n"); - printk(KERN_DEBUG "Checksum = %d\n", CheckSum); - printk(KERN_DEBUG "Checksum read: %d\n", val); + dev_dbg(av8100dev, + ">Fw downloading.... FAIL CheckSum issue\n"); + dev_dbg(av8100dev, "Checksum = %d\n", CheckSum); + dev_dbg(av8100dev, "Checksum read: %d\n", val); retval = AV8100_FWDOWNLOAD_FAIL; goto av8100_download_firmware_out; } else { - printk(KERN_DEBUG ">Fw downloading.... success\n"); + dev_dbg(av8100dev, ">Fw downloading.... success\n"); } /* Set to idle mode */ - av8100_register_general_control_write(AV8100_GENERAL_CONTROL_FDL_LOW, + av8100_reg_gen_ctrl_w(AV8100_GENERAL_CONTROL_FDL_LOW, AV8100_GENERAL_CONTROL_HLD_LOW, AV8100_GENERAL_CONTROL_WA_LOW, AV8100_GENERAL_CONTROL_RA_LOW); if (retval) { - printk(KERN_DEBUG "Failed to write the value to the av8100 registers\n"); + dev_dbg(av8100dev, + "Failed to write the value to the av8100 register\n"); retval = -EFAULT; goto av8100_download_firmware_out; } /* Wait Internal Micro controler ready */ cnt = 3; - retval = av8100_register_general_status_read(&cecrec, &cectrx, &uc, + retval = av8100_reg_gen_status_r(&cecrec, &cectrx, &uc, &onuvb, &hdcps); while ((retval == 0) && (uc != 0x1) && (cnt-- > 0)) { - printk(KERN_DEBUG "av8100 wait2\n"); + dev_dbg(av8100dev, "av8100 wait2\n"); /* TODO */ for (temp = 0; temp < 0xFFFFF; temp++) ; - retval = av8100_register_general_status_read(&cecrec, &cectrx, + retval = av8100_reg_gen_status_r(&cecrec, &cectrx, &uc, &onuvb, &hdcps); } if (retval) { - printk(KERN_DEBUG "Failed to read the value from the av8100 register\n"); + dev_dbg(av8100dev, + "Failed to read the value from the av8100 register\n"); retval = -EFAULT; goto av8100_download_firmware_out; } @@ -1697,17 +1925,18 @@ int av8100_disable_interrupt(void) i2c = av8100_config->client; - retval = av8100_register_standby_pending_interrupt_write( + retval = av8100_reg_stby_pend_int_w( AV8100_STANDBY_PENDING_INTERRUPT_HPDI_LOW, AV8100_STANDBY_PENDING_INTERRUPT_CPDI_LOW, AV8100_STANDBY_PENDING_INTERRUPT_ONI_LOW); if (retval) { - printk(KERN_DEBUG "Failed to write the value to av8100 register\n"); + dev_dbg(av8100dev, + "Failed to write the value to av8100 register\n"); retval = -EFAULT; goto av8100_disable_interrupt_out; } - retval = av8100_register_general_interrupt_mask_write( + retval = av8100_reg_gen_int_mask_w( AV8100_GENERAL_INTERRUPT_MASK_EOCM_LOW, AV8100_GENERAL_INTERRUPT_MASK_VSIM_LOW, AV8100_GENERAL_INTERRUPT_MASK_VSOM_LOW, @@ -1716,26 +1945,36 @@ int av8100_disable_interrupt(void) AV8100_GENERAL_INTERRUPT_MASK_UOVBM_LOW, AV8100_GENERAL_INTERRUPT_MASK_TEM_LOW); if (retval) { - printk(KERN_DEBUG "Failed to write the value to av8100 register\n"); + dev_dbg(av8100dev, + "Failed to write the value to av8100 register\n"); retval = -EFAULT; goto av8100_disable_interrupt_out; } - retval = av8100_register_standby_interrupt_mask_write( + retval = av8100_reg_stby_int_mask_w( AV8100_STANDBY_INTERRUPT_MASK_HPDM_LOW, AV8100_STANDBY_INTERRUPT_MASK_CPDM_LOW, AV8100_STANDBY_INTERRUPT_MASK_STBYGPIOCFG_INPUT, AV8100_STANDBY_INTERRUPT_MASK_IPOL_LOW); if (retval) { - printk(KERN_DEBUG "Failed to write the value to av8100 register\n"); + dev_dbg(av8100dev, + "Failed to write the value to av8100 register\n"); retval = -EFAULT; goto av8100_disable_interrupt_out; } #ifdef AV8100_PLUGIN_DETECT_VIA_TIMER_INTERRUPTS del_timer(&av8100_timer); + + if (av8100_globals) { + /* Reset to be able to detect changes */ + av8100_globals->hpds_old = HPDS_INVALID; + av8100_globals->cpds_old = CPDS_INVALID; + av8100_globals->cecrx_old = CECRX_INVALID; + } #endif + av8100_disable_interrupt_out: return retval; } @@ -1752,17 +1991,18 @@ int av8100_enable_interrupt(void) i2c = av8100_config->client; - retval = av8100_register_standby_pending_interrupt_write( + retval = av8100_reg_stby_pend_int_w( AV8100_STANDBY_PENDING_INTERRUPT_HPDI_LOW, AV8100_STANDBY_PENDING_INTERRUPT_CPDI_LOW, AV8100_STANDBY_PENDING_INTERRUPT_ONI_LOW); if (retval) { - printk(KERN_DEBUG "Failed to write the value to av8100 register\n"); + dev_dbg(av8100dev, + "Failed to write the value to av8100 register\n"); retval = -EFAULT; goto av8100_enable_interrupt_out; } - retval = av8100_register_general_interrupt_mask_write( + retval = av8100_reg_gen_int_mask_w( AV8100_GENERAL_INTERRUPT_MASK_EOCM_LOW, AV8100_GENERAL_INTERRUPT_MASK_VSIM_LOW, AV8100_GENERAL_INTERRUPT_MASK_VSOM_LOW, @@ -1771,18 +2011,20 @@ int av8100_enable_interrupt(void) AV8100_GENERAL_INTERRUPT_MASK_UOVBM_LOW, AV8100_GENERAL_INTERRUPT_MASK_TEM_HIGH); if (retval) { - printk(KERN_DEBUG "Failed to write the value to av8100 register\n"); + dev_dbg(av8100dev, + "Failed to write the value to av8100 register\n"); retval = -EFAULT; goto av8100_enable_interrupt_out; } - retval = av8100_register_standby_interrupt_mask_write( - AV8100_STANDBY_INTERRUPT_MASK_HPDM_LOW, - AV8100_STANDBY_INTERRUPT_MASK_CPDM_LOW, + retval = av8100_reg_stby_int_mask_w( + av8100_globals->hpdm, + av8100_globals->cpdm, AV8100_STANDBY_INTERRUPT_MASK_STBYGPIOCFG_INPUT, AV8100_STANDBY_INTERRUPT_MASK_IPOL_LOW); if (retval) { - printk(KERN_DEBUG "Failed to write the value to av8100 register\n"); + dev_dbg(av8100dev, + "Failed to write the value to av8100 register\n"); retval = -EFAULT; goto av8100_enable_interrupt_out; } @@ -1814,7 +2056,8 @@ static int register_write_internal(u8 offset, u8 value) /* Write to register */ retval = write_single_byte(i2c, offset, value); if (retval) { - printk(KERN_DEBUG "Failed to write the value to av8100 register\n"); + dev_dbg(av8100dev, + "Failed to write the value to av8100 register\n"); retval = -EFAULT; } @@ -1822,7 +2065,7 @@ av8100_register_write_out: return retval; } -int av8100_register_standby_write( +int av8100_reg_stby_w( u8 cpd, u8 stby, u8 mclkrng) { int retval; @@ -1840,24 +2083,39 @@ int av8100_register_standby_write( return retval; } -int av8100_register_hdmi_5_volt_time_write(u8 off_time, u8 on_time) +int av8100_reg_hdmi_5_volt_time_w(u8 denc_off, u8 hdmi_off, u8 on) { int retval; u8 val; LOCK_AV8100_HW; - /* Set register value */ - val = AV8100_HDMI_5_VOLT_TIME_OFF_TIME(off_time) | - AV8100_HDMI_5_VOLT_TIME_ON_TIME(on_time); + /* Set register value. + * chip_version == 1 have one common off time + * chip_version > 1 support different off time for hdmi and tvout. */ + if (chip_version == 1) + val = AV8100_HDMI_5_VOLT_TIME_OFF_TIME(hdmi_off) | + AV8100_HDMI_5_VOLT_TIME_ON_TIME(on); + else + val = AV8100_HDMI_5_VOLT_TIME_DAC_OFF_TIME(denc_off) | + AV8100_HDMI_5_VOLT_TIME_SU_OFF_TIME(hdmi_off) | + AV8100_HDMI_5_VOLT_TIME_ON_TIME(on); /* Write to register */ retval = register_write_internal(AV8100_HDMI_5_VOLT_TIME, val); + + /* Set vars */ + if (chip_version > 1) + av8100_globals->denc_off_time = denc_off; + + av8100_globals->hdmi_off_time = hdmi_off; + av8100_globals->on_time = on; + UNLOCK_AV8100_HW; return retval; } -int av8100_register_standby_interrupt_mask_write( +int av8100_reg_stby_int_mask_w( u8 hpdm, u8 cpdm, u8 stbygpiocfg, u8 ipol) { int retval; @@ -1873,11 +2131,15 @@ int av8100_register_standby_interrupt_mask_write( /* Write to register */ retval = register_write_internal(AV8100_STANDBY_INTERRUPT_MASK, val); + + av8100_globals->hpdm = hpdm; + av8100_globals->cpdm = cpdm; + UNLOCK_AV8100_HW; return retval; } -int av8100_register_standby_pending_interrupt_write( +int av8100_reg_stby_pend_int_w( u8 hpdi, u8 cpdi, u8 oni) { int retval; @@ -1892,11 +2154,12 @@ int av8100_register_standby_pending_interrupt_write( /* Write to register */ retval = register_write_internal(AV8100_STANDBY_PENDING_INTERRUPT, val); + UNLOCK_AV8100_HW; return retval; } -int av8100_register_general_interrupt_mask_write( +int av8100_reg_gen_int_mask_w( u8 eocm, u8 vsim, u8 vsom, u8 cecm, u8 hdcpm, u8 uovbm, u8 tem) { int retval; @@ -1915,11 +2178,12 @@ int av8100_register_general_interrupt_mask_write( /* Write to register */ retval = register_write_internal(AV8100_GENERAL_INTERRUPT_MASK, val); + UNLOCK_AV8100_HW; return retval; } -int av8100_register_general_interrupt_write( +int av8100_reg_gen_int_w( u8 eoci, u8 vsii, u8 vsoi, u8 ceci, u8 hdcpi, u8 uovbi) { int retval; @@ -1941,7 +2205,7 @@ int av8100_register_general_interrupt_write( return retval; } -int av8100_register_gpio_configuration_write( +int av8100_reg_gpio_conf_w( u8 dat3dir, u8 dat3val, u8 dat2dir, u8 dat2val, u8 dat1dir, u8 dat1val, u8 ucdbg) { @@ -1965,7 +2229,7 @@ int av8100_register_gpio_configuration_write( return retval; } -int av8100_register_general_control_write( +int av8100_reg_gen_ctrl_w( u8 fdl, u8 hld, u8 wa, u8 ra) { int retval; @@ -1985,7 +2249,7 @@ int av8100_register_general_control_write( return retval; } -int av8100_register_firmware_download_entry_write( +int av8100_reg_fw_dl_entry_w( u8 mbyte_code_entry) { int retval; @@ -2003,7 +2267,7 @@ int av8100_register_firmware_download_entry_write( return retval; } -int av8100_register_write( +int av8100_reg_w( u8 offset, u8 value) { int retval = 0; @@ -2013,7 +2277,7 @@ int av8100_register_write( if (!av8100_config) { retval = AV8100_FAIL; - goto av8100_register_write_out; + goto av8100_reg_w_out; } i2c = av8100_config->client; @@ -2021,11 +2285,12 @@ int av8100_register_write( /* Write to register */ retval = write_single_byte(i2c, offset, value); if (retval) { - printk(KERN_DEBUG "Failed to write the value to av8100 register\n"); + dev_dbg(av8100dev, + "Failed to write the value to av8100 register\n"); retval = -EFAULT; } -av8100_register_write_out: +av8100_reg_w_out: UNLOCK_AV8100_HW; return retval; } @@ -2045,7 +2310,8 @@ int register_read_internal(u8 offset, u8 *value) /* Read from register */ retval = read_single_byte(i2c, offset, value); if (retval) { - printk(KERN_DEBUG "Failed to read the value from av8100 register\n"); + dev_dbg(av8100dev, + "Failed to read the value from av8100 register\n"); retval = -EFAULT; goto av8100_register_read_out; } @@ -2054,7 +2320,7 @@ av8100_register_read_out: return retval; } -int av8100_register_standby_read( +int av8100_reg_stby_r( u8 *cpd, u8 *stby, u8 *hpds, u8 *cpds, u8 *mclkrng) { int retval; @@ -2066,18 +2332,23 @@ int av8100_register_standby_read( retval = register_read_internal(AV8100_STANDBY, &val); /* Set return params */ - *cpd = AV8100_STANDBY_CPD_GET(val); - *stby = AV8100_STANDBY_STBY_GET(val); - *hpds = AV8100_STANDBY_HPDS_GET(val); - *cpds = AV8100_STANDBY_CPDS_GET(val); - *mclkrng = AV8100_STANDBY_MCLKRNG_GET(val); + if (cpd) + *cpd = AV8100_STANDBY_CPD_GET(val); + if (stby) + *stby = AV8100_STANDBY_STBY_GET(val); + if (hpds) + *hpds = AV8100_STANDBY_HPDS_GET(val); + if (cpds) + *cpds = AV8100_STANDBY_CPDS_GET(val); + if (mclkrng) + *mclkrng = AV8100_STANDBY_MCLKRNG_GET(val); UNLOCK_AV8100_HW; return retval; } -int av8100_register_hdmi_5_volt_time_read( - u8 *off_time, u8 *on_time) +int av8100_reg_hdmi_5_volt_time_r( + u8 *denc_off_time, u8 *hdmi_off_time, u8 *on_time) { int retval; u8 val; @@ -2088,14 +2359,29 @@ int av8100_register_hdmi_5_volt_time_read( retval = register_read_internal(AV8100_HDMI_5_VOLT_TIME, &val); /* Set return params */ - *off_time = AV8100_HDMI_5_VOLT_TIME_OFF_TIME_GET(val); - *on_time = AV8100_HDMI_5_VOLT_TIME_ON_TIME_GET(val); + if (chip_version == 1) { + if (denc_off_time) + *denc_off_time = 0; + if (hdmi_off_time) + *hdmi_off_time = + AV8100_HDMI_5_VOLT_TIME_OFF_TIME_GET(val); + } else { + if (denc_off_time) + *denc_off_time = + AV8100_HDMI_5_VOLT_TIME_DAC_OFF_TIME_GET(val); + if (hdmi_off_time) + *hdmi_off_time = + AV8100_HDMI_5_VOLT_TIME_SU_OFF_TIME_GET(val); + } + + if (on_time) + *on_time = AV8100_HDMI_5_VOLT_TIME_ON_TIME_GET(val); UNLOCK_AV8100_HW; return retval; } -int av8100_register_standby_interrupt_mask_read( +int av8100_reg_stby_int_mask_r( u8 *hpdm, u8 *cpdm, u8 *stbygpiocfg, u8 *ipol) { int retval; @@ -2107,16 +2393,21 @@ int av8100_register_standby_interrupt_mask_read( retval = register_read_internal(AV8100_STANDBY_INTERRUPT_MASK, &val); /* Set return params */ - *hpdm = AV8100_STANDBY_INTERRUPT_MASK_HPDM_GET(val); - *cpdm = AV8100_STANDBY_INTERRUPT_MASK_CPDM_GET(val); - *stbygpiocfg = AV8100_STANDBY_INTERRUPT_MASK_STBYGPIOCFG_GET(val); - *ipol = AV8100_STANDBY_INTERRUPT_MASK_IPOL_GET(val); + if (hpdm) + *hpdm = AV8100_STANDBY_INTERRUPT_MASK_HPDM_GET(val); + if (cpdm) + *cpdm = AV8100_STANDBY_INTERRUPT_MASK_CPDM_GET(val); + if (stbygpiocfg) + *stbygpiocfg = + AV8100_STANDBY_INTERRUPT_MASK_STBYGPIOCFG_GET(val); + if (ipol) + *ipol = AV8100_STANDBY_INTERRUPT_MASK_IPOL_GET(val); UNLOCK_AV8100_HW; return retval; } -int av8100_register_standby_pending_interrupt_read( +int av8100_reg_stby_pend_int_r( u8 *hpdi, u8 *cpdi, u8 *oni, u8 *sid) { int retval; @@ -2125,19 +2416,24 @@ int av8100_register_standby_pending_interrupt_read( LOCK_AV8100_HW; /* Read from register */ - retval = register_read_internal(AV8100_STANDBY_PENDING_INTERRUPT, &val); + retval = register_read_internal(AV8100_STANDBY_PENDING_INTERRUPT, + &val); /* Set return params */ - *hpdi = AV8100_STANDBY_PENDING_INTERRUPT_HPDI_GET(val); - *cpdi = AV8100_STANDBY_PENDING_INTERRUPT_CPDI_GET(val); - *oni = AV8100_STANDBY_PENDING_INTERRUPT_ONI_GET(val); - *sid = AV8100_STANDBY_PENDING_INTERRUPT_SID_GET(val); + if (hpdi) + *hpdi = AV8100_STANDBY_PENDING_INTERRUPT_HPDI_GET(val); + if (cpdi) + *cpdi = AV8100_STANDBY_PENDING_INTERRUPT_CPDI_GET(val); + if (oni) + *oni = AV8100_STANDBY_PENDING_INTERRUPT_ONI_GET(val); + if (sid) + *sid = AV8100_STANDBY_PENDING_INTERRUPT_SID_GET(val); UNLOCK_AV8100_HW; return retval; } -int av8100_register_general_interrupt_mask_read( +int av8100_reg_gen_int_mask_r( u8 *eocm, u8 *vsim, u8 *vsom, @@ -2155,19 +2451,26 @@ int av8100_register_general_interrupt_mask_read( retval = register_read_internal(AV8100_GENERAL_INTERRUPT_MASK, &val); /* Set return params */ - *eocm = AV8100_GENERAL_INTERRUPT_MASK_EOCM_GET(val); - *vsim = AV8100_GENERAL_INTERRUPT_MASK_VSIM_GET(val); - *vsom = AV8100_GENERAL_INTERRUPT_MASK_VSOM_GET(val); - *cecm = AV8100_GENERAL_INTERRUPT_MASK_CECM_GET(val); - *hdcpm = AV8100_GENERAL_INTERRUPT_MASK_HDCPM_GET(val); - *uovbm = AV8100_GENERAL_INTERRUPT_MASK_UOVBM_GET(val); - *tem = AV8100_GENERAL_INTERRUPT_MASK_TEM_GET(val); + if (eocm) + *eocm = AV8100_GENERAL_INTERRUPT_MASK_EOCM_GET(val); + if (vsim) + *vsim = AV8100_GENERAL_INTERRUPT_MASK_VSIM_GET(val); + if (vsom) + *vsom = AV8100_GENERAL_INTERRUPT_MASK_VSOM_GET(val); + if (cecm) + *cecm = AV8100_GENERAL_INTERRUPT_MASK_CECM_GET(val); + if (hdcpm) + *hdcpm = AV8100_GENERAL_INTERRUPT_MASK_HDCPM_GET(val); + if (uovbm) + *uovbm = AV8100_GENERAL_INTERRUPT_MASK_UOVBM_GET(val); + if (tem) + *tem = AV8100_GENERAL_INTERRUPT_MASK_TEM_GET(val); UNLOCK_AV8100_HW; return retval; } -int av8100_register_general_interrupt_read( +int av8100_reg_gen_int_r( u8 *eoci, u8 *vsii, u8 *vsoi, @@ -2185,19 +2488,26 @@ int av8100_register_general_interrupt_read( retval = register_read_internal(AV8100_GENERAL_INTERRUPT, &val); /* Set return params */ - *eoci = AV8100_GENERAL_INTERRUPT_EOCI_GET(val); - *vsii = AV8100_GENERAL_INTERRUPT_VSII_GET(val); - *vsoi = AV8100_GENERAL_INTERRUPT_VSOI_GET(val); - *ceci = AV8100_GENERAL_INTERRUPT_CECI_GET(val); - *hdcpi = AV8100_GENERAL_INTERRUPT_HDCPI_GET(val); - *uovbi = AV8100_GENERAL_INTERRUPT_UOVBI_GET(val); - *tei = AV8100_GENERAL_INTERRUPT_TEI_GET(val); + if (eoci) + *eoci = AV8100_GENERAL_INTERRUPT_EOCI_GET(val); + if (vsii) + *vsii = AV8100_GENERAL_INTERRUPT_VSII_GET(val); + if (vsoi) + *vsoi = AV8100_GENERAL_INTERRUPT_VSOI_GET(val); + if (ceci) + *ceci = AV8100_GENERAL_INTERRUPT_CECI_GET(val); + if (hdcpi) + *hdcpi = AV8100_GENERAL_INTERRUPT_HDCPI_GET(val); + if (uovbi) + *uovbi = AV8100_GENERAL_INTERRUPT_UOVBI_GET(val); + if (tei) + *tei = AV8100_GENERAL_INTERRUPT_TEI_GET(val); UNLOCK_AV8100_HW; return retval; } -int av8100_register_general_status_read( +int av8100_reg_gen_status_r( u8 *cecrec, u8 *cectrx, u8 *uc, @@ -2213,17 +2523,22 @@ int av8100_register_general_status_read( retval = register_read_internal(AV8100_GENERAL_STATUS, &val); /* Set return params */ - *cecrec = AV8100_GENERAL_STATUS_CECREC_GET(val); - *cectrx = AV8100_GENERAL_STATUS_CECTRX_GET(val); - *uc = AV8100_GENERAL_STATUS_UC_GET(val); - *onuvb = AV8100_GENERAL_STATUS_ONUVB_GET(val); - *hdcps = AV8100_GENERAL_STATUS_HDCPS_GET(val); + if (cecrec) + *cecrec = AV8100_GENERAL_STATUS_CECREC_GET(val); + if (cectrx) + *cectrx = AV8100_GENERAL_STATUS_CECTRX_GET(val); + if (uc) + *uc = AV8100_GENERAL_STATUS_UC_GET(val); + if (onuvb) + *onuvb = AV8100_GENERAL_STATUS_ONUVB_GET(val); + if (hdcps) + *hdcps = AV8100_GENERAL_STATUS_HDCPS_GET(val); UNLOCK_AV8100_HW; return retval; } -int av8100_register_gpio_configuration_read( +int av8100_reg_gpio_conf_r( u8 *dat3dir, u8 *dat3val, u8 *dat2dir, @@ -2241,19 +2556,26 @@ int av8100_register_gpio_configuration_read( retval = register_read_internal(AV8100_GPIO_CONFIGURATION, &val); /* Set return params */ - *dat3dir = AV8100_GPIO_CONFIGURATION_DAT3DIR_GET(val); - *dat3val = AV8100_GPIO_CONFIGURATION_DAT3VAL_GET(val); - *dat2dir = AV8100_GPIO_CONFIGURATION_DAT2DIR_GET(val); - *dat2val = AV8100_GPIO_CONFIGURATION_DAT2VAL_GET(val); - *dat1dir = AV8100_GPIO_CONFIGURATION_DAT1DIR_GET(val); - *dat1val = AV8100_GPIO_CONFIGURATION_DAT1VAL_GET(val); - *ucdbg = AV8100_GPIO_CONFIGURATION_UCDBG_GET(val); + if (dat3dir) + *dat3dir = AV8100_GPIO_CONFIGURATION_DAT3DIR_GET(val); + if (dat3val) + *dat3val = AV8100_GPIO_CONFIGURATION_DAT3VAL_GET(val); + if (dat2dir) + *dat2dir = AV8100_GPIO_CONFIGURATION_DAT2DIR_GET(val); + if (dat2val) + *dat2val = AV8100_GPIO_CONFIGURATION_DAT2VAL_GET(val); + if (dat1dir) + *dat1dir = AV8100_GPIO_CONFIGURATION_DAT1DIR_GET(val); + if (dat1val) + *dat1val = AV8100_GPIO_CONFIGURATION_DAT1VAL_GET(val); + if (ucdbg) + *ucdbg = AV8100_GPIO_CONFIGURATION_UCDBG_GET(val); UNLOCK_AV8100_HW; return retval; } -int av8100_register_general_control_read( +int av8100_reg_gen_ctrl_r( u8 *fdl, u8 *hld, u8 *wa, @@ -2267,16 +2589,20 @@ int av8100_register_general_control_read( /* Read from register */ retval = register_read_internal(AV8100_GENERAL_CONTROL, &val); /* Set return params */ - *fdl = AV8100_GENERAL_CONTROL_FDL_GET(val); - *hld = AV8100_GENERAL_CONTROL_HLD_GET(val); - *wa = AV8100_GENERAL_CONTROL_WA_GET(val); - *ra = AV8100_GENERAL_CONTROL_RA_GET(val); + if (fdl) + *fdl = AV8100_GENERAL_CONTROL_FDL_GET(val); + if (hld) + *hld = AV8100_GENERAL_CONTROL_HLD_GET(val); + if (wa) + *wa = AV8100_GENERAL_CONTROL_WA_GET(val); + if (ra) + *ra = AV8100_GENERAL_CONTROL_RA_GET(val); UNLOCK_AV8100_HW; return retval; } -int av8100_register_firmware_download_entry_read( +int av8100_reg_fw_dl_entry_r( u8 *mbyte_code_entry) { int retval; @@ -2288,14 +2614,15 @@ int av8100_register_firmware_download_entry_read( retval = register_read_internal(AV8100_FIRMWARE_DOWNLOAD_ENTRY, &val); /* Set return params */ - *mbyte_code_entry = + if (mbyte_code_entry) + *mbyte_code_entry = AV8100_FIRMWARE_DOWNLOAD_ENTRY_MBYTE_CODE_ENTRY_GET(val); UNLOCK_AV8100_HW; return retval; } -int av8100_register_read( +int av8100_reg_r( u8 offset, u8 *value) { @@ -2314,7 +2641,8 @@ int av8100_register_read( /* Read from register */ retval = read_single_byte(i2c, offset, value); if (retval) { - printk(KERN_DEBUG "Failed to read the value from av8100 register\n"); + dev_dbg(av8100dev, + "Failed to read the value from av8100 register\n"); retval = -EFAULT; goto av8100_register_read_out; } @@ -2324,7 +2652,7 @@ av8100_register_read_out: return retval; } -int av8100_configuration_get(enum av8100_command_type command_type, +int av8100_conf_get(enum av8100_command_type command_type, union av8100_configuration *config) { if (!av8100_config || !config) @@ -2431,7 +2759,7 @@ int av8100_configuration_get(enum av8100_command_type command_type, return 0; } -int av8100_configuration_prepare(enum av8100_command_type command_type, +int av8100_conf_prep(enum av8100_command_type command_type, union av8100_configuration *config) { if (!av8100_config || !config) @@ -2542,7 +2870,7 @@ int av8100_configuration_prepare(enum av8100_command_type command_type, return 0; } -int av8100_configuration_write(enum av8100_command_type command_type, +int av8100_conf_w(enum av8100_command_type command_type, u8 *return_buffer_length, u8 *return_buffer, enum interface_type if_type) { @@ -2562,7 +2890,7 @@ int av8100_configuration_write(enum av8100_command_type command_type, memset(&cmd_buffer, 0x00, AV8100_COMMAND_MAX_LENGTH); #ifdef AV8100_DEBUG_EXTRA -#define PRNK_MODE(_m) printk(KERN_DEBUG "cmd: " #_m "\n"); +#define PRNK_MODE(_m) dev_dbg(av8100dev, "cmd: " #_m "\n"); #else #define PRNK_MODE(_m) #endif @@ -2651,7 +2979,7 @@ int av8100_configuration_write(enum av8100_command_type command_type, break; default: - printk(KERN_INFO "Invalid command type\n"); + dev_dbg(av8100dev, "Invalid command type\n"); retval = AV8100_INVALID_COMMAND; break; } @@ -2662,14 +2990,14 @@ int av8100_configuration_write(enum av8100_command_type command_type, #ifdef AV8100_DEBUG_EXTRA { int cnt = 0; - printk(KERN_DEBUG "av8100_configuration_write cmd_type:%02x length:%02x ", + dev_dbg(av8100dev, "av8100_conf_w cmd_type:%02x length:%02x ", command_type, cmd_length); - printk(KERN_DEBUG "buffer: "); + dev_dbg(av8100dev, "buffer: "); while (cnt < cmd_length) { - printk(KERN_DEBUG "%02x ", cmd_buffer[cnt]); + dev_dbg(av8100dev, "%02x ", cmd_buffer[cnt]); cnt++; } - printk(KERN_DEBUG "\n"); + dev_dbg(av8100dev, "\n"); } #endif @@ -2698,7 +3026,7 @@ int av8100_configuration_write(enum av8100_command_type command_type, /* TODO */ } else { retval = AV8100_INVALID_INTERFACE; - printk(KERN_INFO "Invalid command type\n"); + dev_dbg(av8100dev, "Invalid command type\n"); } if (command_type == AV8100_COMMAND_HDMI) { @@ -2711,7 +3039,7 @@ int av8100_configuration_write(enum av8100_command_type command_type, return retval; } -int av8100_configuration_write_raw(enum av8100_command_type command_type, +int av8100_conf_w_raw(enum av8100_command_type command_type, u8 buffer_length, u8 *buffer, u8 *return_buffer_length, @@ -2727,7 +3055,7 @@ int av8100_configuration_write_raw(enum av8100_command_type command_type, if (!av8100_config) { retval = AV8100_FAIL; - goto av8100_configuration_write_raw_out; + goto av8100_conf_w_raw_out; } i2c = av8100_config->client; @@ -2736,13 +3064,13 @@ int av8100_configuration_write_raw(enum av8100_command_type command_type, retval = write_multi_byte(i2c, AV8100_COMMAND_OFFSET + 1, buffer, buffer_length); if (retval) - goto av8100_configuration_write_raw_out; + goto av8100_conf_w_raw_out; /* Write the command */ retval = write_single_byte(i2c, AV8100_COMMAND_OFFSET, command_type); if (retval) - goto av8100_configuration_write_raw_out; + goto av8100_conf_w_raw_out; /* TODO */ mdelay(100); @@ -2750,7 +3078,7 @@ int av8100_configuration_write_raw(enum av8100_command_type command_type, retval = get_command_return_data(i2c, command_type, buffer, return_buffer_length, return_buffer); -av8100_configuration_write_raw_out: +av8100_conf_w_raw_out: UNLOCK_AV8100_HW; return retval; } @@ -2787,29 +3115,49 @@ enum av8100_output_CEA_VESA av8100_video_output_format_get(int xres, av8100_all_cea[index].htotale / av8100_all_cea[index].vtotale; - printk(KERN_DEBUG "freq1:%ld freq2:%ld\n", freq1, freq2); + dev_dbg(av8100dev, "freq1:%ld freq2:%ld\n", freq1, freq2); if ((xres == av8100_all_cea[index].hactive / hres_div) && (yres == av8100_all_cea[index].vactive * yres_div) && (htot == av8100_all_cea[index].htotale / hres_div) && (vtot == av8100_all_cea[index].vtotale) && (abs(freq1 - freq2) < 2)) { - break; + goto av8100_video_output_format_get_out; } index++; } +av8100_video_output_format_get_out: + dev_dbg(av8100dev, "av8100_video_output_format_get %d %d %d %d %d\n", + xres, yres, htot, vtot, index); return index; } +void av8100_hdmi_event_cb_set(void (*hdmi_ev_cb)(enum av8100_hdmi_event)) +{ + if (av8100_globals) + av8100_globals->hdmi_ev_cb = hdmi_ev_cb; +} + +u8 av8100_ver_get(void) +{ + u8 ret; + + LOCK_AV8100_HW; + ret = chip_version; + UNLOCK_AV8100_HW; + + return ret; +} + static int av8100_open(struct inode *inode, struct file *filp) { - printk(KERN_DEBUG "av8100_open is called\n"); + dev_dbg(av8100dev, "av8100_open is called\n"); return 0; } static int av8100_release(struct inode *inode, struct file *filp) { - printk(KERN_DEBUG "av8100_release is called\n"); + dev_dbg(av8100dev, "av8100_release is called\n"); return 0; } @@ -2825,7 +3173,9 @@ static int __devinit av8100_probe(struct i2c_client *i2cClient, int ret = 0; struct av8100_platform_data *pdata = i2cClient->dev.platform_data; - printk(KERN_DEBUG "%s\n", __func__); + av8100dev = &i2cClient->dev; + + dev_dbg(av8100dev, "%s\n", __func__); g_av8100_status.av8100_state = AV8100_OPMODE_SHUTDOWN; g_av8100_status.av8100_plugin_status = AV8100_PLUGIN_NONE; @@ -2833,7 +3183,13 @@ static int __devinit av8100_probe(struct i2c_client *i2cClient, ret = av8100_config_init(); if (ret) { - pr_info("av8100_config_init failed\n"); + dev_info(av8100dev, "av8100_config_init failed\n"); + goto err; + } + + ret = av8100_globals_init(); + if (ret) { + dev_info(av8100dev, "av8100_globals_init failed\n"); goto err; } @@ -2841,7 +3197,7 @@ static int __devinit av8100_probe(struct i2c_client *i2cClient, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_READ_WORD_DATA)) { ret = -ENODEV; - pr_info("av8100 i2c_check_functionality failed\n"); + dev_info(av8100dev, "av8100 i2c_check_functionality failed\n"); goto err; } @@ -2851,17 +3207,21 @@ static int __devinit av8100_probe(struct i2c_client *i2cClient, av8100_config->id = (struct i2c_device_id *) id; i2c_set_clientdata(i2cClient, av8100_config); - kthread_run(av8100_thread, NULL, "hdmi_thread"); + kthread_run(av8100_thread, NULL, "av8100_thread"); ret = request_irq(pdata->irq, av8100_intr_handler, IRQF_TRIGGER_RISING, "av8100", av8100_config); if (ret) { - printk(KERN_ERR "av8100_hw request_irq %d failed %d\n", + dev_err(av8100dev, "av8100_hw request_irq %d failed %d\n", pdata->irq, ret); gpio_free(pdata->irq); goto err; } + /* Obtain the chip version */ + av8100_powerup1(); + av8100_powerdown(); + return ret; err: return ret; @@ -2869,9 +3229,10 @@ err: static int __devexit av8100_remove(struct i2c_client *i2cClient) { - printk(KERN_DEBUG "%s\n", __func__); + dev_dbg(av8100dev, "%s\n", __func__); av8100_config_exit(); + av8100_globals_exit(); return 0; } @@ -2880,17 +3241,17 @@ int av8100_init(void) { int ret; - printk(KERN_DEBUG "%s\n", __func__); + pr_debug("%s\n", __func__); ret = i2c_add_driver(&av8100_driver); if (ret) { - printk(KERN_DEBUG "av8100 i2c_add_driver failed\n"); + pr_err("av8100 i2c_add_driver failed\n"); goto av8100_init_err; } ret = misc_register(&av8100_miscdev); if (ret) { - printk(KERN_DEBUG "av8100 misc_register failed\n"); + pr_err("av8100 misc_register failed\n"); goto av8100_init_err; } @@ -2905,7 +3266,7 @@ module_init(av8100_init); void av8100_exit(void) { - printk(KERN_DEBUG "%s\n", __func__); + pr_debug("%s\n", __func__); hdmi_exit(); |