Skip to contentSkip to conversation

SMIA(++) driver improvements, fixes

PATCH New Sakari Ailus 1 participant 11 messages May 17, 2012 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

cover SMIA(++) driver improvements, fixes

Hi,

This patchset contains a few improvements and fixes to the SMIA++ driver. Perhaps most importantly, it's no longer necessary to use board code to use the driver: alternatively a clock name can be provided instead of a function to configure the external clock. The platform data function to configure the clock will be removed later on when platforms such as the OMAP 3 allow controlling the clock through the clock framework.

Support for 8-bit raw bayer formats is added, too. There are changes in quirk handling and 8-bit only reads (based on a quirk flag) for badly behaving sensors.

Cheers,

Signature · 2 lines
Sakari Ailus
[email protected]
#1 lore raw

PATCH 1/10 smiapp: Allow using external clock from the clock framework

Instead of providing a function in platform data, allow also providing the name of the external clock and use it through the clock framework.

---
 drivers/media/video/smiapp/smiapp-core.c |   55 ++++++++++++++++++++++++++----
 drivers/media/video/smiapp/smiapp.h      |    1 +
 include/media/smiapp.h                   |    1 +
 3 files changed, 50 insertions(+), 7 deletions(-)
drivers/media/video/smiapp/smiapp-core.c +48 -7
index a8a1db9..999f3fc 100644
@@ -26,6 +26,7 @@
  *
  */
 
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/gpio.h>
@@ -1111,8 +1112,11 @@ static int smiapp_power_on(struct smiapp_sensor *sensor)
 	}
 	usleep_range(1000, 1000);
 
-	rval = sensor->platform_data->set_xclk(&sensor->src->sd,
-					sensor->platform_data->ext_clk);
+	if (sensor->platform_data->set_xclk)
+		rval = sensor->platform_data->set_xclk(
+			&sensor->src->sd, sensor->platform_data->ext_clk);
+	else
+		rval = clk_enable(sensor->ext_clk);
 	if (rval < 0) {
 		dev_dbg(&client->dev, "failed to set xclk\n");
 		goto out_xclk_fail;
@@ -1231,7 +1235,10 @@ static int smiapp_power_on(struct smiapp_sensor *sensor)
 out_cci_addr_fail:
 	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
 		gpio_set_value(sensor->platform_data->xshutdown, 0);
-	sensor->platform_data->set_xclk(&sensor->src->sd, 0);
+	if (sensor->platform_data->set_xclk)
+		sensor->platform_data->set_xclk(&sensor->src->sd, 0);
+	else
+		clk_disable(sensor->ext_clk);
 
 out_xclk_fail:
 	regulator_disable(sensor->vana);
@@ -1256,7 +1263,10 @@ static void smiapp_power_off(struct smiapp_sensor *sensor)
 
 	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
 		gpio_set_value(sensor->platform_data->xshutdown, 0);
-	sensor->platform_data->set_xclk(&sensor->src->sd, 0);
+	if (sensor->platform_data->set_xclk)
+		sensor->platform_data->set_xclk(&sensor->src->sd, 0);
+	else
+		clk_disable(sensor->ext_clk);
 	usleep_range(5000, 5000);
 	regulator_disable(sensor->vana);
 	sensor->streaming = 0;
@@ -2327,6 +2337,28 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
 		return -ENODEV;
 	}
 
+	if (!sensor->platform_data->set_xclk) {
+		sensor->ext_clk = clk_get(&client->dev,
+					  sensor->platform_data->ext_clk_name);
+		if (IS_ERR(sensor->ext_clk)) {
+			dev_err(&client->dev, "could not get clock %s\n",
+				sensor->platform_data->ext_clk_name);
+			rval = -ENODEV;
+			goto out_clk_get;
+		}
+
+		rval = clk_set_rate(sensor->ext_clk,
+				    sensor->platform_data->ext_clk);
+		if (rval < 0) {
+			dev_err(&client->dev,
+				"unable to set clock %s freq to %u\n",
+				sensor->platform_data->ext_clk_name,
+				sensor->platform_data->ext_clk);
+			rval = -ENODEV;
+			goto out_clk_set_rate;
+		}
+	}
+
 	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) {
 		if (gpio_request_one(sensor->platform_data->xshutdown, 0,
 				     "SMIA++ xshutdown") != 0) {
@@ -2334,7 +2366,7 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
 				"unable to acquire reset gpio %d\n",
 				sensor->platform_data->xshutdown);
 			rval = -ENODEV;
-			goto out_gpio_request;
+			goto out_clk_set_rate;
 		}
 	}
 
@@ -2589,7 +2621,11 @@ out_smiapp_power_on:
 	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
 		gpio_free(sensor->platform_data->xshutdown);
 
-out_gpio_request:
+out_clk_set_rate:
+	clk_put(sensor->ext_clk);
+	sensor->ext_clk = NULL;
+
+out_clk_get:
 	regulator_put(sensor->vana);
 	sensor->vana = NULL;
 	return rval;
@@ -2778,7 +2814,10 @@ static int __exit smiapp_remove(struct i2c_client *client)
 	if (sensor->power_count) {
 		if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
 			gpio_set_value(sensor->platform_data->xshutdown, 0);
-		sensor->platform_data->set_xclk(&sensor->src->sd, 0);
+		if (sensor->platform_data->set_xclk)
+			sensor->platform_data->set_xclk(&sensor->src->sd, 0);
+		else
+			clk_disable(sensor->ext_clk);
 		sensor->power_count = 0;
 	}
 
@@ -2794,6 +2833,8 @@ static int __exit smiapp_remove(struct i2c_client *client)
 	smiapp_free_controls(sensor);
 	if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
 		gpio_free(sensor->platform_data->xshutdown);
+	if (sensor->ext_clk)
+		clk_put(sensor->ext_clk);
 	if (sensor->vana)
 		regulator_put(sensor->vana);
 
drivers/media/video/smiapp/smiapp.h +1 -0
index 35b9216..587f7f1 100644
@@ -198,6 +198,7 @@ struct smiapp_sensor {
 	struct smiapp_subdev *pixel_array;
 	struct smiapp_platform_data *platform_data;
 	struct regulator *vana;
+	struct clk *ext_clk;
 	u32 limits[SMIAPP_LIMIT_LAST];
 	u8 nbinning_subtypes;
 	struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES];
include/media/smiapp.h +1 -0
index a7877cd..9ab07fd 100644
@@ -77,6 +77,7 @@ struct smiapp_platform_data {
 	struct smiapp_flash_strobe_parms *strobe_setup;
 
 	int (*set_xclk)(struct v4l2_subdev *sd, int hz);
+	char *ext_clk_name;
 	int xshutdown;			/* gpio or SMIAPP_NO_XSHUTDOWN */
 };
 
Signature · 1 line
1.7.2.5
#2 lore raw

PATCH 2/10 smiapp: Pass struct sensor to register writing commands instead of i2c_client

In reply to Sakari Ailus

Pass struct sensor to register access commands. This allows taking quirks into account in register access.

---
 drivers/media/video/smiapp/smiapp-core.c  |  154 ++++++++++++++---------------
 drivers/media/video/smiapp/smiapp-quirk.c |    4 +-
 drivers/media/video/smiapp/smiapp-regs.c  |    7 +-
 drivers/media/video/smiapp/smiapp-regs.h  |    6 +-
 4 files changed, 84 insertions(+), 87 deletions(-)
drivers/media/video/smiapp/smiapp-core.c +74 -80
index 999f3fc..de5c947 100644
@@ -75,12 +75,12 @@ static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor)
 	int embedded_start = -1, embedded_end = -1;
 	int image_start = 0;
 
-	rval = smiapp_read(client, SMIAPP_REG_U8_FRAME_FORMAT_MODEL_TYPE,
+	rval = smiapp_read(sensor, SMIAPP_REG_U8_FRAME_FORMAT_MODEL_TYPE,
 			   &fmt_model_type);
 	if (rval)
 		return rval;
 
-	rval = smiapp_read(client, SMIAPP_REG_U8_FRAME_FORMAT_MODEL_SUBTYPE,
+	rval = smiapp_read(sensor, SMIAPP_REG_U8_FRAME_FORMAT_MODEL_SUBTYPE,
 			   &fmt_model_subtype);
 	if (rval)
 		return rval;
@@ -106,7 +106,7 @@ static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor)
 
 		if (fmt_model_type == SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE) {
 			rval = smiapp_read(
-				client,
+				sensor,
 				SMIAPP_REG_U16_FRAME_FORMAT_DESCRIPTOR_2(i),
 				&desc);
 			if (rval)
@@ -120,7 +120,7 @@ static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor)
 		} else if (fmt_model_type
 			   == SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE) {
 			rval = smiapp_read(
-				client,
+				sensor,
 				SMIAPP_REG_U32_FRAME_FORMAT_DESCRIPTOR_4(i),
 				&desc);
 			if (rval)
@@ -199,44 +199,43 @@ static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor)
 
 static int smiapp_pll_configure(struct smiapp_sensor *sensor)
 {
-	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	struct smiapp_pll *pll = &sensor->pll;
 	int rval;
 
 	rval = smiapp_write(
-		client, SMIAPP_REG_U16_VT_PIX_CLK_DIV, pll->vt_pix_clk_div);
+		sensor, SMIAPP_REG_U16_VT_PIX_CLK_DIV, pll->vt_pix_clk_div);
 	if (rval < 0)
 		return rval;
 
 	rval = smiapp_write(
-		client, SMIAPP_REG_U16_VT_SYS_CLK_DIV, pll->vt_sys_clk_div);
+		sensor, SMIAPP_REG_U16_VT_SYS_CLK_DIV, pll->vt_sys_clk_div);
 	if (rval < 0)
 		return rval;
 
 	rval = smiapp_write(
-		client, SMIAPP_REG_U16_PRE_PLL_CLK_DIV, pll->pre_pll_clk_div);
+		sensor, SMIAPP_REG_U16_PRE_PLL_CLK_DIV, pll->pre_pll_clk_div);
 	if (rval < 0)
 		return rval;
 
 	rval = smiapp_write(
-		client, SMIAPP_REG_U16_PLL_MULTIPLIER, pll->pll_multiplier);
+		sensor, SMIAPP_REG_U16_PLL_MULTIPLIER, pll->pll_multiplier);
 	if (rval < 0)
 		return rval;
 
 	/* Lane op clock ratio does not apply here. */
 	rval = smiapp_write(
-		client, SMIAPP_REG_U32_REQUESTED_LINK_BIT_RATE_MBPS,
+		sensor, SMIAPP_REG_U32_REQUESTED_LINK_BIT_RATE_MBPS,
 		DIV_ROUND_UP(pll->op_sys_clk_freq_hz, 1000000 / 256 / 256));
 	if (rval < 0 || sensor->minfo.smiapp_profile == SMIAPP_PROFILE_0)
 		return rval;
 
 	rval = smiapp_write(
-		client, SMIAPP_REG_U16_OP_PIX_CLK_DIV, pll->op_pix_clk_div);
+		sensor, SMIAPP_REG_U16_OP_PIX_CLK_DIV, pll->op_pix_clk_div);
 	if (rval < 0)
 		return rval;
 
 	return smiapp_write(
-		client, SMIAPP_REG_U16_OP_SYS_CLK_DIV, pll->op_sys_clk_div);
+		sensor, SMIAPP_REG_U16_OP_SYS_CLK_DIV, pll->op_sys_clk_div);
 }
 
 static int smiapp_pll_update(struct smiapp_sensor *sensor)
@@ -425,7 +424,6 @@ static int smiapp_set_ctrl(struct v4l2_ctrl *ctrl)
 	struct smiapp_sensor *sensor =
 		container_of(ctrl->handler, struct smiapp_subdev, ctrl_handler)
 			->sensor;
-	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	u32 orient = 0;
 	int exposure;
 	int rval;
@@ -433,12 +431,12 @@ static int smiapp_set_ctrl(struct v4l2_ctrl *ctrl)
 	switch (ctrl->id) {
 	case V4L2_CID_ANALOGUE_GAIN:
 		return smiapp_write(
-			client,
+			sensor,
 			SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_GLOBAL, ctrl->val);
 
 	case V4L2_CID_EXPOSURE:
 		return smiapp_write(
-			client,
+			sensor,
 			SMIAPP_REG_U16_COARSE_INTEGRATION_TIME, ctrl->val);
 
 	case V4L2_CID_HFLIP:
@@ -453,7 +451,7 @@ static int smiapp_set_ctrl(struct v4l2_ctrl *ctrl)
 			orient |= SMIAPP_IMAGE_ORIENTATION_VFLIP;
 
 		orient ^= sensor->hvflip_inv_mask;
-		rval = smiapp_write(client,
+		rval = smiapp_write(sensor,
 				    SMIAPP_REG_U8_IMAGE_ORIENTATION,
 				    orient);
 		if (rval < 0)
@@ -478,13 +476,13 @@ static int smiapp_set_ctrl(struct v4l2_ctrl *ctrl)
 		}
 
 		return smiapp_write(
-			client, SMIAPP_REG_U16_FRAME_LENGTH_LINES,
+			sensor, SMIAPP_REG_U16_FRAME_LENGTH_LINES,
 			sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height
 			+ ctrl->val);
 
 	case V4L2_CID_HBLANK:
 		return smiapp_write(
-			client, SMIAPP_REG_U16_LINE_LENGTH_PCK,
+			sensor, SMIAPP_REG_U16_LINE_LENGTH_PCK,
 			sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].width
 			+ ctrl->val);
 
@@ -624,7 +622,7 @@ static int smiapp_get_limits(struct smiapp_sensor *sensor, int const *limit,
 
 	for (i = 0; i < n; i++) {
 		rval = smiapp_read(
-			client, smiapp_reg_limits[limit[i]].addr, &val);
+			sensor, smiapp_reg_limits[limit[i]].addr, &val);
 		if (rval)
 			return rval;
 		sensor->limits[limit[i]] = val;
@@ -696,13 +694,13 @@ static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor)
 	int rval;
 
 	rval = smiapp_read(
-		client, SMIAPP_REG_U8_DATA_FORMAT_MODEL_TYPE, &type);
+		sensor, SMIAPP_REG_U8_DATA_FORMAT_MODEL_TYPE, &type);
 	if (rval)
 		return rval;
 
 	dev_dbg(&client->dev, "data_format_model_type %d\n", type);
 
-	rval = smiapp_read(client, SMIAPP_REG_U8_PIXEL_ORDER,
+	rval = smiapp_read(sensor, SMIAPP_REG_U8_PIXEL_ORDER,
 			   &pixel_order);
 	if (rval)
 		return rval;
@@ -733,7 +731,7 @@ static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor)
 		unsigned int fmt, j;
 
 		rval = smiapp_read(
-			client,
+			sensor,
 			SMIAPP_REG_U16_DATA_FORMAT_DESCRIPTOR(i), &fmt);
 		if (rval)
 			return rval;
@@ -831,13 +829,13 @@ static int smiapp_update_mode(struct smiapp_sensor *sensor)
 			| sensor->binning_vertical;
 
 		rval = smiapp_write(
-			client, SMIAPP_REG_U8_BINNING_TYPE, binning_type);
+			sensor, SMIAPP_REG_U8_BINNING_TYPE, binning_type);
 		if (rval < 0)
 			return rval;
 
 		binning_mode = 1;
 	}
-	rval = smiapp_write(client, SMIAPP_REG_U8_BINNING_MODE, binning_mode);
+	rval = smiapp_write(sensor, SMIAPP_REG_U8_BINNING_MODE, binning_mode);
 	if (rval < 0)
 		return rval;
 
@@ -874,19 +872,18 @@ static int smiapp_update_mode(struct smiapp_sensor *sensor)
 static int smiapp_read_nvm(struct smiapp_sensor *sensor,
 			   unsigned char *nvm)
 {
-	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	u32 i, s, p, np, v;
 	int rval, rval2;
 
 	np = sensor->nvm_size / SMIAPP_NVM_PAGE_SIZE;
 	for (p = 0; p < np; p++) {
 		rval = smiapp_write(
-			client,
+			sensor,
 			SMIAPP_REG_U8_DATA_TRANSFER_IF_1_PAGE_SELECT, p);
 		if (rval)
 			goto out;
 
-		rval = smiapp_write(client,
+		rval = smiapp_write(sensor,
 				    SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL,
 				    SMIAPP_DATA_TRANSFER_IF_1_CTRL_EN |
 				    SMIAPP_DATA_TRANSFER_IF_1_CTRL_RD_EN);
@@ -895,7 +892,7 @@ static int smiapp_read_nvm(struct smiapp_sensor *sensor,
 
 		for (i = 0; i < 1000; i++) {
 			rval = smiapp_read(
-				client,
+				sensor,
 				SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS, &s);
 
 			if (rval)
@@ -913,7 +910,7 @@ static int smiapp_read_nvm(struct smiapp_sensor *sensor,
 
 		for (i = 0; i < SMIAPP_NVM_PAGE_SIZE; i++) {
 			rval = smiapp_read(
-				client,
+				sensor,
 				SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_0 + i,
 				&v);
 			if (rval)
@@ -924,7 +921,7 @@ static int smiapp_read_nvm(struct smiapp_sensor *sensor,
 	}
 
 out:
-	rval2 = smiapp_write(client, SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL, 0);
+	rval2 = smiapp_write(sensor, SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL, 0);
 	if (rval < 0)
 		return rval;
 	else
@@ -944,7 +941,7 @@ static int smiapp_change_cci_addr(struct smiapp_sensor *sensor)
 
 	client->addr = sensor->platform_data->i2c_addr_dfl;
 
-	rval = smiapp_write(client,
+	rval = smiapp_write(sensor,
 			    SMIAPP_REG_U8_CCI_ADDRESS_CONTROL,
 			    sensor->platform_data->i2c_addr_alt << 1);
 	if (rval)
@@ -953,7 +950,7 @@ static int smiapp_change_cci_addr(struct smiapp_sensor *sensor)
 	client->addr = sensor->platform_data->i2c_addr_alt;
 
 	/* verify addr change went ok */
-	rval = smiapp_read(client, SMIAPP_REG_U8_CCI_ADDRESS_CONTROL, &val);
+	rval = smiapp_read(sensor, SMIAPP_REG_U8_CCI_ADDRESS_CONTROL, &val);
 	if (rval)
 		return rval;
 
@@ -970,7 +967,6 @@ static int smiapp_change_cci_addr(struct smiapp_sensor *sensor)
  */
 static int smiapp_setup_flash_strobe(struct smiapp_sensor *sensor)
 {
-	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	struct smiapp_flash_strobe_parms *strobe_setup;
 	unsigned int ext_freq = sensor->platform_data->ext_clk;
 	u32 tmp;
@@ -1060,33 +1056,33 @@ static int smiapp_setup_flash_strobe(struct smiapp_sensor *sensor)
 	strobe_width_high_rs = (tmp + strobe_adjustment - 1) /
 				strobe_adjustment;
 
-	rval = smiapp_write(client, SMIAPP_REG_U8_FLASH_MODE_RS,
+	rval = smiapp_write(sensor, SMIAPP_REG_U8_FLASH_MODE_RS,
 			    strobe_setup->mode);
 	if (rval < 0)
 		goto out;
 
-	rval = smiapp_write(client, SMIAPP_REG_U8_FLASH_STROBE_ADJUSTMENT,
+	rval = smiapp_write(sensor, SMIAPP_REG_U8_FLASH_STROBE_ADJUSTMENT,
 			    strobe_adjustment);
 	if (rval < 0)
 		goto out;
 
 	rval = smiapp_write(
-		client, SMIAPP_REG_U16_TFLASH_STROBE_WIDTH_HIGH_RS_CTRL,
+		sensor, SMIAPP_REG_U16_TFLASH_STROBE_WIDTH_HIGH_RS_CTRL,
 		strobe_width_high_rs);
 	if (rval < 0)
 		goto out;
 
-	rval = smiapp_write(client, SMIAPP_REG_U16_TFLASH_STROBE_DELAY_RS_CTRL,
+	rval = smiapp_write(sensor, SMIAPP_REG_U16_TFLASH_STROBE_DELAY_RS_CTRL,
 			    strobe_setup->strobe_delay);
 	if (rval < 0)
 		goto out;
 
-	rval = smiapp_write(client, SMIAPP_REG_U16_FLASH_STROBE_START_POINT,
+	rval = smiapp_write(sensor, SMIAPP_REG_U16_FLASH_STROBE_START_POINT,
 			    strobe_setup->stobe_start_point);
 	if (rval < 0)
 		goto out;
 
-	rval = smiapp_write(client, SMIAPP_REG_U8_FLASH_TRIGGER_RS,
+	rval = smiapp_write(sensor, SMIAPP_REG_U8_FLASH_TRIGGER_RS,
 			    strobe_setup->trigger);
 
 out:
@@ -1148,7 +1144,7 @@ static int smiapp_power_on(struct smiapp_sensor *sensor)
 		}
 	}
 
-	rval = smiapp_write(client, SMIAPP_REG_U8_SOFTWARE_RESET,
+	rval = smiapp_write(sensor, SMIAPP_REG_U8_SOFTWARE_RESET,
 			    SMIAPP_SOFTWARE_RESET);
 	if (rval < 0) {
 		dev_err(&client->dev, "software reset failed\n");
@@ -1163,7 +1159,7 @@ static int smiapp_power_on(struct smiapp_sensor *sensor)
 		}
 	}
 
-	rval = smiapp_write(client, SMIAPP_REG_U16_COMPRESSION_MODE,
+	rval = smiapp_write(sensor, SMIAPP_REG_U16_COMPRESSION_MODE,
 			    SMIAPP_COMPRESSION_MODE_SIMPLE_PREDICTOR);
 	if (rval) {
 		dev_err(&client->dev, "compression mode set failed\n");
@@ -1171,28 +1167,28 @@ static int smiapp_power_on(struct smiapp_sensor *sensor)
 	}
 
 	rval = smiapp_write(
-		client, SMIAPP_REG_U16_EXTCLK_FREQUENCY_MHZ,
+		sensor, SMIAPP_REG_U16_EXTCLK_FREQUENCY_MHZ,
 		sensor->platform_data->ext_clk / (1000000 / (1 << 8)));
 	if (rval) {
 		dev_err(&client->dev, "extclk frequency set failed\n");
 		goto out_cci_addr_fail;
 	}
 
-	rval = smiapp_write(client, SMIAPP_REG_U8_CSI_LANE_MODE,
+	rval = smiapp_write(sensor, SMIAPP_REG_U8_CSI_LANE_MODE,
 			    sensor->platform_data->lanes - 1);
 	if (rval) {
 		dev_err(&client->dev, "csi lane mode set failed\n");
 		goto out_cci_addr_fail;
 	}
 
-	rval = smiapp_write(client, SMIAPP_REG_U8_FAST_STANDBY_CTRL,
+	rval = smiapp_write(sensor, SMIAPP_REG_U8_FAST_STANDBY_CTRL,
 			    SMIAPP_FAST_STANDBY_CTRL_IMMEDIATE);
 	if (rval) {
 		dev_err(&client->dev, "fast standby set failed\n");
 		goto out_cci_addr_fail;
 	}
 
-	rval = smiapp_write(client, SMIAPP_REG_U8_CSI_SIGNALLING_MODE,
+	rval = smiapp_write(sensor, SMIAPP_REG_U8_CSI_SIGNALLING_MODE,
 			    sensor->platform_data->csi_signalling_mode);
 	if (rval) {
 		dev_err(&client->dev, "csi signalling mode set failed\n");
@@ -1200,7 +1196,7 @@ static int smiapp_power_on(struct smiapp_sensor *sensor)
 	}
 
 	/* DPHY control done by sensor based on requested link rate */
-	rval = smiapp_write(client, SMIAPP_REG_U8_DPHY_CTRL,
+	rval = smiapp_write(sensor, SMIAPP_REG_U8_DPHY_CTRL,
 			    SMIAPP_DPHY_CTRL_UI);
 	if (rval < 0)
 		return rval;
@@ -1247,8 +1243,6 @@ out_xclk_fail:
 
 static void smiapp_power_off(struct smiapp_sensor *sensor)
 {
-	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
-
 	/*
 	 * Currently power/clock to lens are enable/disabled separately
 	 * but they are essentially the same signals. So if the sensor is
@@ -1257,7 +1251,7 @@ static void smiapp_power_off(struct smiapp_sensor *sensor)
 	 * will fail. So do a soft reset explicitly here.
 	 */
 	if (sensor->platform_data->i2c_addr_alt)
-		smiapp_write(client,
+		smiapp_write(sensor,
 			     SMIAPP_REG_U8_SOFTWARE_RESET,
 			     SMIAPP_SOFTWARE_RESET);
 
@@ -1315,7 +1309,7 @@ static int smiapp_start_streaming(struct smiapp_sensor *sensor)
 
 	mutex_lock(&sensor->mutex);
 
-	rval = smiapp_write(client, SMIAPP_REG_U16_CSI_DATA_FORMAT,
+	rval = smiapp_write(sensor, SMIAPP_REG_U16_CSI_DATA_FORMAT,
 			    (sensor->csi_format->width << 8) |
 			    sensor->csi_format->compressed);
 	if (rval)
@@ -1326,26 +1320,26 @@ static int smiapp_start_streaming(struct smiapp_sensor *sensor)
 		goto out;
 
 	/* Analog crop start coordinates */
-	rval = smiapp_write(client, SMIAPP_REG_U16_X_ADDR_START,
+	rval = smiapp_write(sensor, SMIAPP_REG_U16_X_ADDR_START,
 			    sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].left);
 	if (rval < 0)
 		goto out;
 
-	rval = smiapp_write(client, SMIAPP_REG_U16_Y_ADDR_START,
+	rval = smiapp_write(sensor, SMIAPP_REG_U16_Y_ADDR_START,
 			    sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].top);
 	if (rval < 0)
 		goto out;
 
 	/* Analog crop end coordinates */
 	rval = smiapp_write(
-		client, SMIAPP_REG_U16_X_ADDR_END,
+		sensor, SMIAPP_REG_U16_X_ADDR_END,
 		sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].left
 		+ sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].width - 1);
 	if (rval < 0)
 		goto out;
 
 	rval = smiapp_write(
-		client, SMIAPP_REG_U16_Y_ADDR_END,
+		sensor, SMIAPP_REG_U16_Y_ADDR_END,
 		sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].top
 		+ sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC].height - 1);
 	if (rval < 0)
@@ -1360,25 +1354,25 @@ static int smiapp_start_streaming(struct smiapp_sensor *sensor)
 	if (sensor->limits[SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY]
 	    == SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP) {
 		rval = smiapp_write(
-			client, SMIAPP_REG_U16_DIGITAL_CROP_X_OFFSET,
+			sensor, SMIAPP_REG_U16_DIGITAL_CROP_X_OFFSET,
 			sensor->scaler->crop[SMIAPP_PAD_SINK].left);
 		if (rval < 0)
 			goto out;
 
 		rval = smiapp_write(
-			client, SMIAPP_REG_U16_DIGITAL_CROP_Y_OFFSET,
+			sensor, SMIAPP_REG_U16_DIGITAL_CROP_Y_OFFSET,
 			sensor->scaler->crop[SMIAPP_PAD_SINK].top);
 		if (rval < 0)
 			goto out;
 
 		rval = smiapp_write(
-			client, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_WIDTH,
+			sensor, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_WIDTH,
 			sensor->scaler->crop[SMIAPP_PAD_SINK].width);
 		if (rval < 0)
 			goto out;
 
 		rval = smiapp_write(
-			client, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_HEIGHT,
+			sensor, SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_HEIGHT,
 			sensor->scaler->crop[SMIAPP_PAD_SINK].height);
 		if (rval < 0)
 			goto out;
@@ -1387,23 +1381,23 @@ static int smiapp_start_streaming(struct smiapp_sensor *sensor)
 	/* Scaling */
 	if (sensor->limits[SMIAPP_LIMIT_SCALING_CAPABILITY]
 	    != SMIAPP_SCALING_CAPABILITY_NONE) {
-		rval = smiapp_write(client, SMIAPP_REG_U16_SCALING_MODE,
+		rval = smiapp_write(sensor, SMIAPP_REG_U16_SCALING_MODE,
 				    sensor->scaling_mode);
 		if (rval < 0)
 			goto out;
 
-		rval = smiapp_write(client, SMIAPP_REG_U16_SCALE_M,
+		rval = smiapp_write(sensor, SMIAPP_REG_U16_SCALE_M,
 				    sensor->scale_m);
 		if (rval < 0)
 			goto out;
 	}
 
 	/* Output size from sensor */
-	rval = smiapp_write(client, SMIAPP_REG_U16_X_OUTPUT_SIZE,
+	rval = smiapp_write(sensor, SMIAPP_REG_U16_X_OUTPUT_SIZE,
 			    sensor->src->crop[SMIAPP_PAD_SRC].width);
 	if (rval < 0)
 		goto out;
-	rval = smiapp_write(client, SMIAPP_REG_U16_Y_OUTPUT_SIZE,
+	rval = smiapp_write(sensor, SMIAPP_REG_U16_Y_OUTPUT_SIZE,
 			    sensor->src->crop[SMIAPP_PAD_SRC].height);
 	if (rval < 0)
 		goto out;
@@ -1424,7 +1418,7 @@ static int smiapp_start_streaming(struct smiapp_sensor *sensor)
 		goto out;
 	}
 
-	rval = smiapp_write(client, SMIAPP_REG_U8_MODE_SELECT,
+	rval = smiapp_write(sensor, SMIAPP_REG_U8_MODE_SELECT,
 			    SMIAPP_MODE_SELECT_STREAMING);
 
 out:
@@ -1439,7 +1433,7 @@ static int smiapp_stop_streaming(struct smiapp_sensor *sensor)
 	int rval;
 
 	mutex_lock(&sensor->mutex);
-	rval = smiapp_write(client, SMIAPP_REG_U8_MODE_SELECT,
+	rval = smiapp_write(sensor, SMIAPP_REG_U8_MODE_SELECT,
 			    SMIAPP_MODE_SELECT_SOFTWARE_STANDBY);
 	if (rval)
 		goto out;
@@ -2203,50 +2197,50 @@ static int smiapp_identify_module(struct v4l2_subdev *subdev)
 	minfo->name = SMIAPP_NAME;
 
 	/* Module info */
-	rval = smiapp_read(client, SMIAPP_REG_U8_MANUFACTURER_ID,
+	rval = smiapp_read(sensor, SMIAPP_REG_U8_MANUFACTURER_ID,
 			   &minfo->manufacturer_id);
 	if (!rval)
-		rval = smiapp_read(client, SMIAPP_REG_U16_MODEL_ID,
+		rval = smiapp_read(sensor, SMIAPP_REG_U16_MODEL_ID,
 				   &minfo->model_id);
 	if (!rval)
-		rval = smiapp_read(client, SMIAPP_REG_U8_REVISION_NUMBER_MAJOR,
+		rval = smiapp_read(sensor, SMIAPP_REG_U8_REVISION_NUMBER_MAJOR,
 				   &minfo->revision_number_major);
 	if (!rval)
-		rval = smiapp_read(client, SMIAPP_REG_U8_REVISION_NUMBER_MINOR,
+		rval = smiapp_read(sensor, SMIAPP_REG_U8_REVISION_NUMBER_MINOR,
 				   &minfo->revision_number_minor);
 	if (!rval)
-		rval = smiapp_read(client, SMIAPP_REG_U8_MODULE_DATE_YEAR,
+		rval = smiapp_read(sensor, SMIAPP_REG_U8_MODULE_DATE_YEAR,
 				   &minfo->module_year);
 	if (!rval)
-		rval = smiapp_read(client, SMIAPP_REG_U8_MODULE_DATE_MONTH,
+		rval = smiapp_read(sensor, SMIAPP_REG_U8_MODULE_DATE_MONTH,
 				   &minfo->module_month);
 	if (!rval)
-		rval = smiapp_read(client, SMIAPP_REG_U8_MODULE_DATE_DAY,
+		rval = smiapp_read(sensor, SMIAPP_REG_U8_MODULE_DATE_DAY,
 				   &minfo->module_day);
 
 	/* Sensor info */
 	if (!rval)
-		rval = smiapp_read(client,
+		rval = smiapp_read(sensor,
 				   SMIAPP_REG_U8_SENSOR_MANUFACTURER_ID,
 				   &minfo->sensor_manufacturer_id);
 	if (!rval)
-		rval = smiapp_read(client, SMIAPP_REG_U16_SENSOR_MODEL_ID,
+		rval = smiapp_read(sensor, SMIAPP_REG_U16_SENSOR_MODEL_ID,
 				   &minfo->sensor_model_id);
 	if (!rval)
-		rval = smiapp_read(client,
+		rval = smiapp_read(sensor,
 				   SMIAPP_REG_U8_SENSOR_REVISION_NUMBER,
 				   &minfo->sensor_revision_number);
 	if (!rval)
-		rval = smiapp_read(client,
+		rval = smiapp_read(sensor,
 				   SMIAPP_REG_U8_SENSOR_FIRMWARE_VERSION,
 				   &minfo->sensor_firmware_version);
 
 	/* SMIA */
 	if (!rval)
-		rval = smiapp_read(client, SMIAPP_REG_U8_SMIA_VERSION,
+		rval = smiapp_read(sensor, SMIAPP_REG_U8_SMIA_VERSION,
 				   &minfo->smia_version);
 	if (!rval)
-		rval = smiapp_read(client, SMIAPP_REG_U8_SMIAPP_VERSION,
+		rval = smiapp_read(sensor, SMIAPP_REG_U8_SMIAPP_VERSION,
 				   &minfo->smiapp_version);
 
 	if (rval) {
@@ -2415,7 +2409,7 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
 	if (sensor->limits[SMIAPP_LIMIT_BINNING_CAPABILITY]) {
 		u32 val;
 
-		rval = smiapp_read(client,
+		rval = smiapp_read(sensor,
 				   SMIAPP_REG_U8_BINNING_SUBTYPES, &val);
 		if (rval < 0) {
 			rval = -ENODEV;
@@ -2426,7 +2420,7 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
 
 		for (i = 0; i < sensor->nbinning_subtypes; i++) {
 			rval = smiapp_read(
-				client, SMIAPP_REG_U8_BINNING_TYPE_n(i), &val);
+				sensor, SMIAPP_REG_U8_BINNING_TYPE_n(i), &val);
 			if (rval < 0) {
 				rval = -ENODEV;
 				goto out_power_off;
@@ -2600,7 +2594,7 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
 	sensor->dev_init_done = true;
 
 	/* check flash capability */
-	rval = smiapp_read(client, SMIAPP_REG_U8_FLASH_MODE_CAPABILITY, &tmp);
+	rval = smiapp_read(sensor, SMIAPP_REG_U8_FLASH_MODE_CAPABILITY, &tmp);
 	sensor->flash_capability = tmp;
 	if (rval)
 		goto out_nvm_release;
drivers/media/video/smiapp/smiapp-quirk.c +1 -3
index fb018de..81c2be3 100644
@@ -28,9 +28,7 @@
 
 static int smiapp_write_8(struct smiapp_sensor *sensor, u16 reg, u8 val)
 {
-	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
-
-	return smiapp_write(client, (SMIA_REG_8BIT << 16) | reg, val);
+	return smiapp_write(sensor, (SMIA_REG_8BIT << 16) | reg, val);
 }
 
 static int smiapp_write_8s(struct smiapp_sensor *sensor,
drivers/media/video/smiapp/smiapp-regs.c +5 -2
index a5055f1..e5e5f43 100644
@@ -25,6 +25,7 @@
 #include <linux/delay.h>
 #include <linux/i2c.h>
 
+#include "smiapp.h"
 #include "smiapp-regs.h"
 
 static uint32_t float_to_u32_mul_1000000(struct i2c_client *client,
@@ -77,8 +78,9 @@ static uint32_t float_to_u32_mul_1000000(struct i2c_client *client,
  * Read a 8/16/32-bit i2c register.  The value is returned in 'val'.
  * Returns zero if successful, or non-zero otherwise.
  */
-int smiapp_read(struct i2c_client *client, u32 reg, u32 *val)
+int smiapp_read(struct smiapp_sensor *sensor, u32 reg, u32 *val)
 {
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	struct i2c_msg msg;
 	unsigned char data[4];
 	unsigned int len = (u8)(reg >> 16);
@@ -145,8 +147,9 @@ err:
  * Write to a 8/16-bit register.
  * Returns zero if successful, or non-zero otherwise.
  */
-int smiapp_write(struct i2c_client *client, u32 reg, u32 val)
+int smiapp_write(struct smiapp_sensor *sensor, u32 reg, u32 val)
 {
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	struct i2c_msg msg;
 	unsigned char data[6];
 	unsigned int retries;
drivers/media/video/smiapp/smiapp-regs.h +4 -2
index 58e8009..1edfd20 100644
@@ -40,7 +40,9 @@ struct smia_reg {
 	u32 val;			/* 8/16/32-bit value */
 };
 
-int smiapp_read(struct i2c_client *client, u32 reg, u32 *val);
-int smiapp_write(struct i2c_client *client, u32 reg, u32 val);
+struct smiapp_sensor;
+
+int smiapp_read(struct smiapp_sensor *sensor, u32 reg, u32 *val);
+int smiapp_write(struct smiapp_sensor *sensor, u32 reg, u32 val);
 
 #endif
Signature · 1 line
1.7.2.5
#3 lore raw

PATCH 3/10 smiapp: Quirk for sensors that only do 8-bit reads

In reply to Sakari Ailus

Some sensors implement only 8-bit read functionality and fail on wider reads. Add a quirk flag for such sensors.

---
 drivers/media/video/smiapp/smiapp-quirk.h |    1 +
 drivers/media/video/smiapp/smiapp-regs.c  |   73 +++++++++++++++++++++++++----
 drivers/media/video/smiapp/smiapp-regs.h  |    1 +
 3 files changed, 66 insertions(+), 9 deletions(-)
drivers/media/video/smiapp/smiapp-quirk.h +1 -0
index 7a1b3a0..de82cdf 100644
@@ -46,6 +46,7 @@ struct smiapp_quirk {
 
 /* op pix clock is for all lanes in total normally */
 #define SMIAPP_QUIRK_FLAG_OP_PIX_CLOCK_PER_LANE			(1 << 0)
+#define SMIAPP_QUIRK_FLAG_8BIT_READ_ONLY			(1 << 1)
 
 struct smiapp_reg_8 {
 	u16 reg;
drivers/media/video/smiapp/smiapp-regs.c +64 -9

98 lines not on this page · raw message

drivers/media/video/smiapp/smiapp-regs.h +1 -0
index 1edfd20..7f9013b 100644
@@ -43,6 +43,7 @@ struct smia_reg {
 struct smiapp_sensor;
 
 int smiapp_read(struct smiapp_sensor *sensor, u32 reg, u32 *val);
+int smiapp_read_8only(struct smiapp_sensor *sensor, u32 reg, u32 *val);
 int smiapp_write(struct smiapp_sensor *sensor, u32 reg, u32 val);
 
 #endif
Signature · 1 line
1.7.2.5
#4 lore raw

PATCH 4/10 smiapp: Use 8-bit reads only before identifying the sensor

In reply to Sakari Ailus

Some sensors only allow 8-bit access, so use safe 8-bit access before the sensor has been identified.

---
 drivers/media/video/smiapp/smiapp-core.c |   63 ++++++++++++++++--------------
 1 files changed, 34 insertions(+), 29 deletions(-)
drivers/media/video/smiapp/smiapp-core.c +34 -29
index de5c947..3bf086f 100644
@@ -2197,51 +2197,56 @@ static int smiapp_identify_module(struct v4l2_subdev *subdev)
 	minfo->name = SMIAPP_NAME;
 
 	/* Module info */
-	rval = smiapp_read(sensor, SMIAPP_REG_U8_MANUFACTURER_ID,
-			   &minfo->manufacturer_id);
+	rval = smiapp_read_8only(sensor, SMIAPP_REG_U8_MANUFACTURER_ID,
+				 &minfo->manufacturer_id);
 	if (!rval)
-		rval = smiapp_read(sensor, SMIAPP_REG_U16_MODEL_ID,
-				   &minfo->model_id);
+		rval = smiapp_read_8only(sensor, SMIAPP_REG_U16_MODEL_ID,
+					 &minfo->model_id);
 	if (!rval)
-		rval = smiapp_read(sensor, SMIAPP_REG_U8_REVISION_NUMBER_MAJOR,
-				   &minfo->revision_number_major);
+		rval = smiapp_read_8only(sensor,
+					 SMIAPP_REG_U8_REVISION_NUMBER_MAJOR,
+					 &minfo->revision_number_major);
 	if (!rval)
-		rval = smiapp_read(sensor, SMIAPP_REG_U8_REVISION_NUMBER_MINOR,
-				   &minfo->revision_number_minor);
+		rval = smiapp_read_8only(sensor,
+					 SMIAPP_REG_U8_REVISION_NUMBER_MINOR,
+					 &minfo->revision_number_minor);
 	if (!rval)
-		rval = smiapp_read(sensor, SMIAPP_REG_U8_MODULE_DATE_YEAR,
-				   &minfo->module_year);
+		rval = smiapp_read_8only(sensor,
+					 SMIAPP_REG_U8_MODULE_DATE_YEAR,
+					 &minfo->module_year);
 	if (!rval)
-		rval = smiapp_read(sensor, SMIAPP_REG_U8_MODULE_DATE_MONTH,
-				   &minfo->module_month);
+		rval = smiapp_read_8only(sensor,
+					 SMIAPP_REG_U8_MODULE_DATE_MONTH,
+					 &minfo->module_month);
 	if (!rval)
-		rval = smiapp_read(sensor, SMIAPP_REG_U8_MODULE_DATE_DAY,
-				   &minfo->module_day);
+		rval = smiapp_read_8only(sensor, SMIAPP_REG_U8_MODULE_DATE_DAY,
+					 &minfo->module_day);
 
 	/* Sensor info */
 	if (!rval)
-		rval = smiapp_read(sensor,
-				   SMIAPP_REG_U8_SENSOR_MANUFACTURER_ID,
-				   &minfo->sensor_manufacturer_id);
+		rval = smiapp_read_8only(sensor,
+					 SMIAPP_REG_U8_SENSOR_MANUFACTURER_ID,
+					 &minfo->sensor_manufacturer_id);
 	if (!rval)
-		rval = smiapp_read(sensor, SMIAPP_REG_U16_SENSOR_MODEL_ID,
-				   &minfo->sensor_model_id);
+		rval = smiapp_read_8only(sensor,
+					 SMIAPP_REG_U16_SENSOR_MODEL_ID,
+					 &minfo->sensor_model_id);
 	if (!rval)
-		rval = smiapp_read(sensor,
-				   SMIAPP_REG_U8_SENSOR_REVISION_NUMBER,
-				   &minfo->sensor_revision_number);
+		rval = smiapp_read_8only(sensor,
+					 SMIAPP_REG_U8_SENSOR_REVISION_NUMBER,
+					 &minfo->sensor_revision_number);
 	if (!rval)
-		rval = smiapp_read(sensor,
-				   SMIAPP_REG_U8_SENSOR_FIRMWARE_VERSION,
-				   &minfo->sensor_firmware_version);
+		rval = smiapp_read_8only(sensor,
+					 SMIAPP_REG_U8_SENSOR_FIRMWARE_VERSION,
+					 &minfo->sensor_firmware_version);
 
 	/* SMIA */
 	if (!rval)
-		rval = smiapp_read(sensor, SMIAPP_REG_U8_SMIA_VERSION,
-				   &minfo->smia_version);
+		rval = smiapp_read_8only(sensor, SMIAPP_REG_U8_SMIA_VERSION,
+					 &minfo->smia_version);
 	if (!rval)
-		rval = smiapp_read(sensor, SMIAPP_REG_U8_SMIAPP_VERSION,
-				   &minfo->smiapp_version);
+		rval = smiapp_read_8only(sensor, SMIAPP_REG_U8_SMIAPP_VERSION,
+					 &minfo->smiapp_version);
 
 	if (rval) {
 		dev_err(&client->dev, "sensor detection failed\n");
Signature · 1 line
1.7.2.5
#5 lore raw

PATCH 5/10 smiapp: Round minimum pre_pll up rather than down in ip_clk_freq check

In reply to Sakari Ailus

The pre_pll divisor must be such that ext_clk / pre_pll divisor does not result in a frequency that is greater than pll_ip_clk_freq. Fix this.

---
 drivers/media/video/smiapp-pll.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/media/video/smiapp-pll.c +3 -2
index a416e27..a2e41a2 100644
@@ -124,8 +124,9 @@ int smiapp_pll_calculate(struct device *dev, struct smiapp_pll_limits *limits,
 				   limits->min_pll_ip_freq_hz));
 	limits->min_pre_pll_clk_div =
 		max_t(uint16_t, limits->min_pre_pll_clk_div,
-		      clk_div_even(pll->ext_clk_freq_hz /
-				   limits->max_pll_ip_freq_hz));
+		      clk_div_even_up(
+			      DIV_ROUND_UP(pll->ext_clk_freq_hz,
+					   limits->max_pll_ip_freq_hz)));
 	dev_dbg(dev, "pre-pll check: min / max pre_pll_clk_div: %d / %d\n",
 		limits->min_pre_pll_clk_div, limits->max_pre_pll_clk_div);
 
Signature · 1 line
1.7.2.5
#6 lore raw

PATCH 6/10 smiapp: Initialise rval in smiapp_read_nvm()

In reply to Sakari Ailus

rval was not properly initialised in smiapp_read_nvm(). Do that.

---
 drivers/media/video/smiapp/smiapp-core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/media/video/smiapp/smiapp-core.c +1 -1
index 3bf086f..6524091 100644
@@ -873,7 +873,7 @@ static int smiapp_read_nvm(struct smiapp_sensor *sensor,
 			   unsigned char *nvm)
 {
 	u32 i, s, p, np, v;
-	int rval, rval2;
+	int rval = 0, rval2;
 
 	np = sensor->nvm_size / SMIAPP_NVM_PAGE_SIZE;
 	for (p = 0; p < np; p++) {
Signature · 1 line
1.7.2.5
#7 lore raw

PATCH 7/10 smiapp: Use non-binning limits if the binning limit is zero

In reply to Sakari Ailus

Some sensors do use binning but do not have valid limits in binning registers. Use non-binning limits in that case.

---
 drivers/media/video/smiapp/smiapp-core.c |   31 +++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 3 deletions(-)
drivers/media/video/smiapp/smiapp-core.c +28 -3
index 6524091..47d6901 100644
@@ -653,6 +653,7 @@ static int smiapp_get_all_limits(struct smiapp_sensor *sensor)
 
 static int smiapp_get_limits_binning(struct smiapp_sensor *sensor)
 {
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	static u32 const limits[] = {
 		SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN,
 		SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN,
@@ -671,11 +672,11 @@ static int smiapp_get_limits_binning(struct smiapp_sensor *sensor)
 		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN,
 		SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN,
 	};
+	unsigned int i;
+	int rval;
 
 	if (sensor->limits[SMIAPP_LIMIT_BINNING_CAPABILITY] ==
 	    SMIAPP_BINNING_CAPABILITY_NO) {
-		unsigned int i;
-
 		for (i = 0; i < ARRAY_SIZE(limits); i++)
 			sensor->limits[limits[i]] =
 				sensor->limits[limits_replace[i]];
@@ -683,7 +684,31 @@ static int smiapp_get_limits_binning(struct smiapp_sensor *sensor)
 		return 0;
 	}
 
-	return smiapp_get_limits(sensor, limits, ARRAY_SIZE(limits));
+	rval = smiapp_get_limits(sensor, limits, ARRAY_SIZE(limits));
+	if (rval < 0)
+		return rval;
+
+	/*
+	 * Sanity check whether the binning limits are valid. If not,
+	 * use the non-binning ones.
+	 */
+	if (sensor->limits[SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN]
+	    && sensor->limits[SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN]
+	    && sensor->limits[SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN])
+		return 0;
+
+	for (i = 0; i < ARRAY_SIZE(limits); i++) {
+		dev_dbg(&client->dev,
+			"replace limit 0x%8.8x \"%s\" = %d, 0x%x\n",
+			smiapp_reg_limits[limits[i]].addr,
+			smiapp_reg_limits[limits[i]].what,
+			sensor->limits[limits_replace[i]],
+			sensor->limits[limits_replace[i]]);
+		sensor->limits[limits[i]] =
+			sensor->limits[limits_replace[i]];
+	}
+
+	return 0;
 }
 
 static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor)
Signature · 1 line
1.7.2.5
#8 lore raw

PATCH 8/10 smiapp: Allow generic quirk registers

In reply to Sakari Ailus

Implement more generic quirk registers than just limit and capability registers. This comes with the expense of a little bit more access time so these should be only used when really needed.

---
 drivers/media/video/smiapp/smiapp-quirk.c |   46 +++++++++++++++++++++++++++++
 drivers/media/video/smiapp/smiapp-quirk.h |   10 ++++++
 drivers/media/video/smiapp/smiapp-regs.c  |    4 ++
 3 files changed, 60 insertions(+), 0 deletions(-)
drivers/media/video/smiapp/smiapp-quirk.c +46 -0
index 81c2be3..55e8795 100644
@@ -81,6 +81,52 @@ int smiapp_replace_limit_at(struct smiapp_sensor *sensor,
 	return -EINVAL;
 }
 
+bool smiapp_quirk_reg(struct smiapp_sensor *sensor,
+		      u32 reg, u32 *val)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	const struct smia_reg *sreg;
+
+	if (!sensor->minfo.quirk)
+		return false;
+
+	sreg = sensor->minfo.quirk->regs;
+
+	if (!sreg)
+		return false;
+
+	while (sreg->type) {
+		u16 type = reg >> 16;
+		u16 reg16 = reg;
+
+		if (sreg->type != type || sreg->reg != reg16) {
+			sreg++;
+			continue;
+		}
+
+		switch ((u8)type) {
+		case SMIA_REG_8BIT:
+			dev_dbg(&client->dev, "quirk: 0x%8.8x: 0x%2.2x\n",
+				reg, sreg->val);
+			break;
+		case SMIA_REG_16BIT:
+			dev_dbg(&client->dev, "quirk: 0x%8.8x: 0x%4.4x\n",
+				reg, sreg->val);
+			break;
+		case SMIA_REG_32BIT:
+			dev_dbg(&client->dev, "quirk: 0x%8.8x: 0x%8.8x\n",
+				reg, sreg->val);
+			break;
+		}
+
+		*val = sreg->val;
+
+		return true;
+	}
+
+	return false;
+}
+
 static int jt8ew9_limits(struct smiapp_sensor *sensor)
 {
 	if (sensor->minfo.revision_number_major < 0x03)
drivers/media/video/smiapp/smiapp-quirk.h +10 -0
index de82cdf..f4dcaab 100644
@@ -41,6 +41,7 @@ struct smiapp_quirk {
 	int (*post_poweron)(struct smiapp_sensor *sensor);
 	int (*pre_streamon)(struct smiapp_sensor *sensor);
 	int (*post_streamoff)(struct smiapp_sensor *sensor);
+	const struct smia_reg *regs;
 	unsigned long flags;
 };
 
@@ -55,6 +56,15 @@ struct smiapp_reg_8 {
 
 void smiapp_replace_limit(struct smiapp_sensor *sensor,
 			  u32 limit, u32 val);
+bool smiapp_quirk_reg(struct smiapp_sensor *sensor,
+		      u32 reg, u32 *val);
+
+#define SMIAPP_MK_QUIRK_REG(_reg, _val) \
+	{				\
+		.type = (_reg >> 16),	\
+		.reg = (u16)_reg,	\
+		.val = _val,		\
+	}
 
 #define smiapp_call_quirk(_sensor, _quirk, ...)				\
 	(_sensor->minfo.quirk &&					\
drivers/media/video/smiapp/smiapp-regs.c +4 -0
index 9c43064..b1812b1 100644
@@ -172,6 +172,9 @@ static int __smiapp_read(struct smiapp_sensor *sensor, u32 reg, u32 *val,
 	    && len != SMIA_REG_32BIT)
 		return -EINVAL;
 
+	if (smiapp_quirk_reg(sensor, reg, val))
+		goto found_quirk;
+
 	if (len == SMIA_REG_8BIT && !only8)
 		rval = ____smiapp_read(sensor, (u16)reg, len, val);
 	else
@@ -179,6 +182,7 @@ static int __smiapp_read(struct smiapp_sensor *sensor, u32 reg, u32 *val,
 	if (rval < 0)
 		return rval;
 
+found_quirk:
 	if (reg & SMIA_REG_FLAG_FLOAT)
 		*val = float_to_u32_mul_1000000(client, *val);
 
Signature · 1 line
1.7.2.5
#9 lore raw

PATCH 9/10 smiapp: Add support for 8-bit uncompressed formats

In reply to Sakari Ailus

Add support for uncompressed 8-bit raw bayer formats.

---
 drivers/media/video/smiapp/smiapp-core.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/media/video/smiapp/smiapp-core.c +4 -0
index 47d6901..ffc6eb7 100644
@@ -367,6 +367,10 @@ static const struct smiapp_csi_data_format smiapp_csi_data_formats[] = {
 	{ V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_RGGB, },
 	{ V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_BGGR, },
 	{ V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8, 10, 8, SMIAPP_PIXEL_ORDER_GBRG, },
+	{ V4L2_MBUS_FMT_SGRBG8_1X8, 8, 8, SMIAPP_PIXEL_ORDER_GRBG, },
+	{ V4L2_MBUS_FMT_SRGGB8_1X8, 8, 8, SMIAPP_PIXEL_ORDER_RGGB, },
+	{ V4L2_MBUS_FMT_SBGGR8_1X8, 8, 8, SMIAPP_PIXEL_ORDER_BGGR, },
+	{ V4L2_MBUS_FMT_SGBRG8_1X8, 8, 8, SMIAPP_PIXEL_ORDER_GBRG, },
 };
 
 const char *pixel_order_str[] = { "GRBG", "RGGB", "BGGR", "GBRG" };
Signature · 1 line
1.7.2.5
#10 lore raw

PATCH 10/10 smiapp: Use v4l2_ctrl_new_int_menu() instead of v4l2_ctrl_new_custom()

In reply to Sakari Ailus
---
 drivers/media/video/smiapp/smiapp-core.c |   17 ++++++-----------
 1 files changed, 6 insertions(+), 11 deletions(-)
drivers/media/video/smiapp/smiapp-core.c +6 -11
index ffc6eb7..f518026 100644
@@ -508,7 +508,7 @@ static const struct v4l2_ctrl_ops smiapp_ctrl_ops = {
 static int smiapp_init_controls(struct smiapp_sensor *sensor)
 {
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
-	struct v4l2_ctrl_config cfg;
+	unsigned int max;
 	int rval;
 
 	rval = v4l2_ctrl_handler_init(&sensor->pixel_array->ctrl_handler, 7);
@@ -572,17 +572,12 @@ static int smiapp_init_controls(struct smiapp_sensor *sensor)
 		goto error;
 	sensor->src->ctrl_handler.lock = &sensor->mutex;
 
-	memset(&cfg, 0, sizeof(cfg));
+	for (max = 0; sensor->platform_data->op_sys_clock[max + 1]; max++);
 
-	cfg.ops = &smiapp_ctrl_ops;
-	cfg.id = V4L2_CID_LINK_FREQ;
-	cfg.type = V4L2_CTRL_TYPE_INTEGER_MENU;
-	while (sensor->platform_data->op_sys_clock[cfg.max + 1])
-		cfg.max++;
-	cfg.qmenu_int = sensor->platform_data->op_sys_clock;
-
-	sensor->link_freq = v4l2_ctrl_new_custom(
-		&sensor->src->ctrl_handler, &cfg, NULL);
+	sensor->link_freq = v4l2_ctrl_new_int_menu(
+		&sensor->src->ctrl_handler, &smiapp_ctrl_ops,
+		V4L2_CID_LINK_FREQ, max, 0,
+		sensor->platform_data->op_sys_clock);
 
 	sensor->pixel_rate_csi = v4l2_ctrl_new_std(
 		&sensor->src->ctrl_handler, &smiapp_ctrl_ops,
Signature · 1 line
1.7.2.5