From d2b46a8dc7b927ab672220c67619364e3df35efd Mon Sep 17 00:00:00 2001 From: Hu Kejun Date: Mon, 3 Jun 2019 10:03:34 +0800 Subject: [PATCH] media: i2c: nvp6324: set i2c bus id by dts Change-Id: I6d80f5a78183c36312629d9b77c1d9cfe9c1f853 Signed-off-by: Hu Kejun --- drivers/media/i2c/jaguar1_drv/jaguar1_drv.c | 81 ++++++++++++++------ drivers/media/i2c/jaguar1_drv/jaguar1_drv.h | 2 + drivers/media/i2c/jaguar1_drv/jaguar1_v4l2.c | 9 +++ 3 files changed, 69 insertions(+), 23 deletions(-) diff --git a/drivers/media/i2c/jaguar1_drv/jaguar1_drv.c b/drivers/media/i2c/jaguar1_drv/jaguar1_drv.c index 35e18ae6aae3..28838572ada6 100644 --- a/drivers/media/i2c/jaguar1_drv/jaguar1_drv.c +++ b/drivers/media/i2c/jaguar1_drv/jaguar1_drv.c @@ -61,7 +61,7 @@ #endif //#include "video_eq.h" //To do -#define STREAM_ON_DEFLAULT +//#define STREAM_ON_DEFLAULT #define I2C_0 (0) #define I2C_1 (1) @@ -94,6 +94,7 @@ module_param_named(jaguar1_fmt, fmt, uint, S_IRUGO); static unsigned int ntpal = 0; module_param_named(jaguar1_ntpal, ntpal, uint, S_IRUGO); +static bool jaguar1_init_state; struct semaphore jaguar1_lock; struct i2c_client* jaguar1_client; static struct i2c_board_info hi_info = @@ -721,12 +722,15 @@ void jaguar1_stop(void) * Modify : * warning : *******************************************************************************/ -static int i2c_client_init(void) +static int i2c_client_init(int i2c_bus) { struct i2c_adapter* i2c_adap; printk("[DRV] I2C Client Init \n"); - i2c_adap = i2c_get_adapter(I2C_3); + i2c_adap = i2c_get_adapter(i2c_bus); + if (!i2c_adap) + return -EINVAL; + jaguar1_client = i2c_new_device(i2c_adap, &hi_info); i2c_put_adapter(i2c_adap); @@ -758,6 +762,46 @@ static struct miscdevice jaguar1_dev = { .fops = &jaguar1_fops, }; +int jaguar1_init(int i2c_bus) +{ + int ret = 0; +#ifdef FMT_SETTING_SAMPLE + int dev_num = 0; +#endif + + if (jaguar1_init_state) + return 0; + + ret = i2c_client_init(i2c_bus); + if (ret) { + printk(KERN_ERR "ERROR: could not find jaguar1\n"); + return ret; + } + + /* decoder count function */ + ret = check_decoder_count(); + if (ret <= 0) { + printk(KERN_ERR "ERROR: could not find jaguar1 devices:%#x\n", ret); + i2c_client_exit(); + return -ENODEV; + } + + /* initialize semaphore */ + sema_init(&jaguar1_lock, 1); + down(&jaguar1_lock); + video_decoder_init(); + up(&jaguar1_lock); + jaguar1_init_state = true; + + return 0; +} + +void jaguar1_exit(void) +{ + i2c_client_exit(); + jaguar1_init_state = false; +} + /******************************************************************************* * Description : It is called when "insmod jaguar1.ko" command run * Argurments : void @@ -768,10 +812,6 @@ static struct miscdevice jaguar1_dev = { static int __init jaguar1_module_init(void) { int ret = 0; -#ifdef FMT_SETTING_SAMPLE - int dev_num = 0; -#endif - #ifdef STREAM_ON_DEFLAULT video_init_all sVideoall; int ch; @@ -782,29 +822,21 @@ static int __init jaguar1_module_init(void) #endif ret = misc_register(&jaguar1_dev); - if (ret) { - printk("ERROR: could not register jaguar1-i2c :%#x \n",ret); + printk(KERN_ERR "ERROR: could not register jaguar1-i2c :%#x\n", ret); return -1; } - i2c_client_init(); - - /* decoder count function */ - ret = check_decoder_count(); - if (ret <= 0) +#ifdef STREAM_ON_DEFLAULT + ret = jaguar1_init(I2C_3); + if (ret) { - printk("ERROR: could not find jaguar1 devices:%#x \n",ret); - return ret; + printk(KERN_ERR "ERROR: jaguar1 init failed\n"); + return -1; } - /* initialize semaphore */ - sema_init(&jaguar1_lock, 1); down(&jaguar1_lock); - video_decoder_init(); - -#ifdef STREAM_ON_DEFLAULT if(init) { for(ch=0;chadapter)); + if (ret) { + dev_err(dev, "Failed to init jaguar1\n"); + __jaguar1_power_off(jaguar1); + mutex_destroy(&jaguar1->mutex); + + return ret; + } pm_runtime_set_active(dev); pm_runtime_enable(dev); @@ -789,6 +797,7 @@ static int jaguar1_remove(struct i2c_client *client) struct v4l2_subdev *sd = i2c_get_clientdata(client); struct jaguar1 *jaguar1 = to_jaguar1(sd); + jaguar1_exit(); mutex_destroy(&jaguar1->mutex); pm_runtime_disable(&client->dev);