Custom sensor device driver i2c issue in Jetson TX2

Hello ,

I’m developing custom camera driver in Jetson TX2.

New custom camera support i2c communication with 16bit address and 16bit data.

I’m modifying based on reference device driver code (ov5693.c).

first of all, i2c data struct changed.

static struct regmap_config s5k2x5sp_regmap_config = {
	.reg_bits = 16,
	.val_bits = 16,
};

The val data type was changed in the read/write function of the custom camera sensor register.

static inline int s5k2x5sp_read_reg(struct camera_common_data *s_data,
u16 addr, u16 *val)
static inline int s5k2x_write_reg(struct camera_common_data *s_data, u16 addr, u16 val)

but, in the middle of test compile error message occured as shown below.

/kernel/nvidia/drivers/media/i2c/s5k2x.c:789:15: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .write_reg = s5k2x_write_reg,
               ^~~~~~~~~~~~~~~~~~
/kernel/nvidia/drivers/media/i2c/s5k2x.c:789:15: note: (near initialization for ‘s5k2x_common_ops.write_reg’)
/kernel/nvidia/drivers/media/i2c/s5k2x.c:790:14: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .read_reg = s5k2x_read_reg,

so i found “camera_common_sensor_ops” struct in /kernel/nvidia/include/media/camrea_common.h
this struct of write_reg and read_reg declation was not match.
In my opinion the camera_common.h file should not be modified.

How do I modify the i2c data type if it is 16bit ?

struct camera_common_sensor_ops {
	u32 numfrmfmts;
	const struct camera_common_frmfmt *frmfmt_table;
	int (*power_on)(struct camera_common_data *s_data);
	int (*power_off)(struct camera_common_data *s_data);
	int (*write_reg)(struct camera_common_data *s_data,
	  u16 addr, u8 val);
	int (*read_reg)(struct camera_common_data *s_data,
	  u16 addr, u8 *val);
	struct camera_common_pdata *(*parse_dt)(struct tegracam_device *tc_dev);
	int (*power_get)(struct tegracam_device *tc_dev);
	int (*power_put)(struct tegracam_device *tc_dev);
	int (*get_framesync)(struct camera_common_data *s_data,
		struct camera_common_framesync *vshs);
	int (*set_mode)(struct tegracam_device *tc_dev);
	int (*start_streaming)(struct tegracam_device *tc_dev);
	int (*stop_streaming)(struct tegracam_device *tc_dev);
};

I think you can you can remove the write_reg/read_reg from the ops of the sensor driver.

	.numfrmfmts = ARRAY_SIZE(ov5693_frmfmt),
	.frmfmt_table = ov5693_frmfmt,
	.power_on = ov5693_power_on,
	.power_off = ov5693_power_off,
	.write_reg = ov5693_write_reg,
	.read_reg = ov5693_read_reg,
	.parse_dt = ov5693_parse_dt,
	.power_get = ov5693_power_get,
	.power_put = ov5693_power_put,
	.set_mode = ov5693_set_mode,
	.start_streaming = ov5693_start_streaming,
	.stop_streaming = ov5693_stop_streaming,
};

Hello ShaneCCC,

I modified struct code as shown below.

static struct camera_common_sensor_ops s5k2x5_common_ops = {
.numfrmfmts = ARRAY_SIZE(s5k2x5_frmfmt),
.frmfmt_table = s5k2x5_frmfmt,
.power_on = s5k2x5_power_on,
.power_off = s5k2x5_power_off,
//.write_reg = s5k2x5_write_reg,
//.read_reg = s5k2x5_read_reg,
.parse_dt = s5k2x5_parse_dt,
.power_get = s5k2x5_power_get,
.power_put = s5k2x5_power_put,
.set_mode = s5k2x5_set_mode,
.start_streaming = s5k2x5_start_streaming,
.stop_streaming = s5k2x5_stop_streaming
};

compile error was removed.
but it occured error message during V4l2-ctrl test as shown below.

I was modified “s5k2x5_write_table” function to write register 16bit data from 8bit data.

static int s5k2x5_write_table(struct s5k2x5 *priv,
const s5k2x5_reg table)
{
struct camera_common_data *s_data = priv->s_data;

return regmap_util_write_table_8(s_data->regmap,
table,
NULL, 0,
S5K2X5_TABLE_WAIT_MS,
S5K2X5_TABLE_END);
}

static int s5k2x5_write_table(struct s5k2x5 *priv,
const s5k2x5_reg table)
{
struct camera_common_data *s_data = priv->s_data;

return regmap_util_write_table_16_as_8(s_data->regmap,
table,
NULL, 0,
S5K2X5_TABLE_WAIT_MS,
S5K2X5_TABLE_END);
}

[ 138.582530] tegra-i2c 3180000.i2c: no acknowledge from address 0x10
[ 138.588851] regmap_util_write_table_16_as_8:regmap_util_write_table:-121[ 138.595391] s5k2x5 2-0010: Error writing mode

I have another question.
I added “pr_err” for check error cause in regmap_util_write_table_16_as_8 function.

I have been compile kernel Image file.
and then, kernel image was flash using " sudo ./flash.sh -k kernel jetson-tx2 mmcblk0p1".
but it didn’t display any changed message on serial log.
what am I wrong ?

Just copy the Image to /boot/Image in TX2.

Hello ShaneCCC,

okay I’ll try to do that.

Let me know how to register of image sensor write setup table using 16bit register data write table function.
it support only 8bit data accessing method in regmap_util.c code.

The regmap_util_write_table_16_as_8() should be right for 16 bits address.
You can reference to below driver.