← back to drohn__my_sensor

Function bodies 28 total

All specs Real LLM only Function bodies
my_sensor_power_on function · c · L22-L31 (10 LOC)
archive/my_sensor.c
static int my_sensor_power_on(struct my_sensor *sensor)
{
    if (sensor->vdd)
        regulator_enable(sensor->vdd);
    if (sensor->reset_gpio)
        gpiod_set_value_cansleep(sensor->reset_gpio, 1);
    msleep(10); // Allow sensor to stabilize
    return 0;
}
my_sensor_power_off function · c · L32-L40 (9 LOC)
archive/my_sensor.c
static int my_sensor_power_off(struct my_sensor *sensor)
{
    if (sensor->reset_gpio)
        gpiod_set_value_cansleep(sensor->reset_gpio, 0);
    if (sensor->vdd)
        regulator_disable(sensor->vdd);
    return 0;
}
my_sensor_s_stream function · c · L41-L54 (14 LOC)
archive/my_sensor.c
static int my_sensor_s_stream(struct v4l2_subdev *sd, int enable)
{
    struct my_sensor *sensor = container_of(sd, struct my_sensor, sd);

    if (enable) {
        // Write I2C registers to start streaming
        sensor->streaming = true;
    } else {
        // Write I2C registers to stop streaming
        sensor->streaming = false;
    }
    return 0;
}
my_sensor_set_fmt function · c · L55-L66 (12 LOC)
archive/my_sensor.c
static int my_sensor_set_fmt(struct v4l2_subdev *sd,
                 struct v4l2_subdev_pad_config *cfg,
                 struct v4l2_subdev_format *format)
{
    // Set pixel format, resolution, etc.
    format->format.code = MEDIA_BUS_FMT_SRGGB10_1X10; // Example: RAW10
    format->format.width = 1920;
    format->format.height = 1080;
    format->format.field = V4L2_FIELD_NONE;
    return 0;
}
my_sensor_probe function · c · L80-L104 (25 LOC)
archive/my_sensor.c
static int my_sensor_probe(struct i2c_client *client,
               const struct i2c_device_id *id)
{
    struct my_sensor *sensor;
    struct v4l2_subdev *sd;

    sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL);
    if (!sensor)
        return -ENOMEM;

    sensor->client = client;
    sensor->vdd = devm_regulator_get(&client->dev, "vdd");
    sensor->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW);

    my_sensor_power_on(sensor);

    sd = &sensor->sd;
    v4l2_i2c_subdev_init(sd, client, &my_sensor_subdev_ops);
    sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
    sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;

    dev_info(&client->dev, "my_sensor driver probed\n");
    return 0;
}
my_sensor_remove function · c · L105-L114 (10 LOC)
archive/my_sensor.c
static int my_sensor_remove(struct i2c_client *client)
{
    struct v4l2_subdev *sd = i2c_get_clientdata(client);
    struct my_sensor *sensor = container_of(sd, struct my_sensor, sd);

    my_sensor_power_off(sensor);
    v4l2_device_unregister_subdev(sd);
    return 0;
}
canon_write_reg function · c · L71-L85 (15 LOC)
canon.c
static int canon_write_reg(struct i2c_client *client, u16 reg, u16 val)
{
	u8 buf[4] = {
		reg & 0xff, (reg >> 8) & 0xff,
		val & 0xff, (val >> 8) & 0xff,
	};
	int ret = i2c_master_send(client, buf, sizeof(buf));

	if (ret != sizeof(buf)) {
		dev_err(&client->dev, "i2c write reg 0x%04x failed: %d\n",
			reg, ret);
		return ret < 0 ? ret : -EIO;
	}
	return 0;
}
Repobility's GitHub App fixes findings like these · https://github.com/apps/repobility-bot
canon_read_reg function · c · L86-L104 (19 LOC)
canon.c
static int canon_read_reg(struct i2c_client *client, u16 reg, u16 *val)
{
	u8 addr[2] = { reg & 0xff, (reg >> 8) & 0xff };
	u8 data[2];
	struct i2c_msg msgs[2] = {
		{ .addr = client->addr, .flags = 0,           .len = 2, .buf = addr },
		{ .addr = client->addr, .flags = I2C_M_RD,    .len = 2, .buf = data },
	};
	int ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));

	if (ret != ARRAY_SIZE(msgs)) {
		dev_err(&client->dev, "i2c read reg 0x%04x failed: %d\n",
			reg, ret);
		return ret < 0 ? ret : -EIO;
	}
	*val = (u16)data[0] | ((u16)data[1] << 8);
	return 0;
}
canon_spad_power_on function · c · L110-L125 (16 LOC)
canon.c
static int canon_spad_power_on(struct canon_spad *sensor)
{
	/* 1. Assert LL_LT_EN */
	gpiod_set_value_cansleep(sensor->en_gpio, 1);
	msleep(100);

	/* 2. Assert LL_LT_SHTDN_L (deassert shutdown) */
	gpiod_set_value_cansleep(sensor->shtdn_gpio, 1);
	msleep(2000); /* sensor needs ~1.5s after SHTDN_L deassertion before I2C ready */

	/* 3. Assert SYS_FRAME_REF */
	gpiod_set_value_cansleep(sensor->fsync_gpio, 1);
	msleep(10);

	return 0;
}
canon_spad_power_off function · c · L126-L132 (7 LOC)
canon.c
static void canon_spad_power_off(struct canon_spad *sensor)
{
	gpiod_set_value_cansleep(sensor->fsync_gpio, 0);
	gpiod_set_value_cansleep(sensor->shtdn_gpio, 0);
	gpiod_set_value_cansleep(sensor->en_gpio, 0);
}
canon_spad_init_regs function · c · L138-L153 (16 LOC)
canon.c
static int canon_spad_init_regs(struct i2c_client *client)
{
	/* MIPI lane count: hardware is wired 4-lane (CSI_C+CSI_D).
	 * Sensor operates in 4-lane mode by default; no lane-select register write needed. */
	int ret;

	ret  = canon_write_reg(client, REG_FRAME_SYNC_EN,      0x0001);
	ret |= canon_write_reg(client, REG_EXPOSURE_MODE,      0x0001); /* SemiAuto */
	ret |= canon_write_reg(client, REG_ENABLE,             0x0001);
	ret |= canon_write_reg(client, REG_SYNC_MODE_SELECT,   0x0000); /* InternalTrigger/Stream */
	ret |= canon_write_reg(client, REG_RESET,              0x0000);
	ret |= canon_write_reg(client, REG_OPERATION_MODE,     0x0002); /* Trigger Mode */
	ret |= canon_write_reg(client, REG_INTERRUPT_STATUS,   0x0001);

	return ret ? -EIO : 0;
}
canon_spad_start_streaming function · c · L154-L164 (11 LOC)
canon.c
static int canon_spad_start_streaming(struct canon_spad *sensor)
{
	struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd);
	int ret;

	ret = canon_spad_init_regs(client);
	if (ret)
		dev_err(&client->dev, "failed to init sensor registers\n");
	return ret;
}
canon_spad_stop_streaming function · c · L165-L172 (8 LOC)
canon.c
static int canon_spad_stop_streaming(struct canon_spad *sensor)
{
	struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd);

	/* TODO: confirm stop sequence from datasheet */
	return canon_write_reg(client, REG_OPERATION_MODE, 0x0001); /* back to Idle */
}
canon_spad_s_stream function · c · L178-L197 (20 LOC)
canon.c
static int canon_spad_s_stream(struct v4l2_subdev *sd, int enable)
{
	struct canon_spad *sensor = container_of(sd, struct canon_spad, sd);
	int ret = 0;

	mutex_lock(&sensor->lock);
	if (sensor->streaming == (bool)enable)
		goto out;

	if (enable)
		ret = canon_spad_start_streaming(sensor);
	else
		ret = canon_spad_stop_streaming(sensor);

	if (!ret)
		sensor->streaming = enable;
out:
	mutex_unlock(&sensor->lock);
	return ret;
}
canon_spad_get_fmt function · c · L198-L209 (12 LOC)
canon.c
static int canon_spad_get_fmt(struct v4l2_subdev *sd,
			      struct v4l2_subdev_state *state,
			      struct v4l2_subdev_format *fmt)
{
	struct canon_spad *sensor = container_of(sd, struct canon_spad, sd);

	mutex_lock(&sensor->lock);
	fmt->format = sensor->fmt;
	mutex_unlock(&sensor->lock);
	return 0;
}
If a scraper extracted this row, it came from Repobility (https://repobility.com)
canon_spad_set_fmt function · c · L210-L230 (21 LOC)
canon.c
static int canon_spad_set_fmt(struct v4l2_subdev *sd,
			      struct v4l2_subdev_state *state,
			      struct v4l2_subdev_format *fmt)
{
	struct canon_spad *sensor = container_of(sd, struct canon_spad, sd);

	/* Only one mode — force fixed format */
	fmt->format.width     = CANON_SPAD_WIDTH;
	fmt->format.height    = CANON_SPAD_HEIGHT;
	fmt->format.code      = MEDIA_BUS_FMT_Y12_1X12;
	fmt->format.field     = V4L2_FIELD_NONE;
	fmt->format.colorspace = V4L2_COLORSPACE_RAW;

	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
		mutex_lock(&sensor->lock);
		sensor->fmt = fmt->format;
		mutex_unlock(&sensor->lock);
	}
	return 0;
}
canon_spad_enum_mbus_code function · c · L231-L240 (10 LOC)
canon.c
static int canon_spad_enum_mbus_code(struct v4l2_subdev *sd,
				     struct v4l2_subdev_state *state,
				     struct v4l2_subdev_mbus_code_enum *code)
{
	if (code->index > 0)
		return -EINVAL;
	code->code = MEDIA_BUS_FMT_Y12_1X12;
	return 0;
}
canon_spad_enum_frame_size function · c · L241-L251 (11 LOC)
canon.c
static int canon_spad_enum_frame_size(struct v4l2_subdev *sd,
				      struct v4l2_subdev_state *state,
				      struct v4l2_subdev_frame_size_enum *fse)
{
	if (fse->index > 0 || fse->code != MEDIA_BUS_FMT_Y12_1X12)
		return -EINVAL;
	fse->min_width  = fse->max_width  = CANON_SPAD_WIDTH;
	fse->min_height = fse->max_height = CANON_SPAD_HEIGHT;
	return 0;
}
canon_spad_init_controls function · c · L273-L302 (30 LOC)
canon.c
static int canon_spad_init_controls(struct canon_spad *sensor)
{
	struct v4l2_ctrl_handler *hdlr = &sensor->ctrl_handler;
	int ret;

	ret = v4l2_ctrl_handler_init(hdlr, 2);
	if (ret)
		return ret;

	sensor->pixel_rate = v4l2_ctrl_new_std(hdlr, NULL,
		V4L2_CID_PIXEL_RATE,
		CANON_SPAD_PIXEL_RATE, CANON_SPAD_PIXEL_RATE, 1,
		CANON_SPAD_PIXEL_RATE);

	sensor->link_freq = v4l2_ctrl_new_int_menu(hdlr, NULL,
		V4L2_CID_LINK_FREQ,
		ARRAY_SIZE(canon_spad_link_freqs) - 1, 0,
		canon_spad_link_freqs);
	if (sensor->link_freq)
		sensor->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;

	if (hdlr->error) {
		ret = hdlr->error;
		v4l2_ctrl_handler_free(hdlr);
		return ret;
	}

	sensor->sd.ctrl_handler = hdlr;
	return 0;
}
canon_spad_probe function · c · L308-L391 (84 LOC)
canon.c
static int canon_spad_probe(struct i2c_client *client)
{
	struct device *dev = &client->dev;
	struct canon_spad *sensor;
	u16 status;
	int ret;

	sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
	if (!sensor)
		return -ENOMEM;

	/* GPIOs — names must match DTS gpio-names entries */
	sensor->en_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
	if (IS_ERR(sensor->en_gpio))
		return dev_err_probe(dev, PTR_ERR(sensor->en_gpio),
				     "failed to get enable GPIO\n");

	sensor->shtdn_gpio = devm_gpiod_get(dev, "shutdown", GPIOD_OUT_LOW);
	if (IS_ERR(sensor->shtdn_gpio))
		return dev_err_probe(dev, PTR_ERR(sensor->shtdn_gpio),
				     "failed to get shutdown GPIO\n");

	sensor->fsync_gpio = devm_gpiod_get(dev, "fsync", GPIOD_OUT_LOW);
	if (IS_ERR(sensor->fsync_gpio))
		return dev_err_probe(dev, PTR_ERR(sensor->fsync_gpio),
				     "failed to get fsync GPIO\n");

	mutex_init(&sensor->lock);

	/* Default format */
	sensor->fmt.width      = CANON_SPAD_WIDTH;
	sensor->fmt.height  
canon_spad_remove function · c · L392-L406 (15 LOC)
canon.c
static int canon_spad_remove(struct i2c_client *client)
{
	struct v4l2_subdev *sd = i2c_get_clientdata(client);
	struct canon_spad *sensor = container_of(sd, struct canon_spad, sd);

	v4l2_async_unregister_subdev(sd);
	media_entity_cleanup(&sd->entity);
	v4l2_ctrl_handler_free(&sensor->ctrl_handler);
	canon_spad_power_off(sensor);
	pm_runtime_disable(&client->dev);
	mutex_destroy(&sensor->lock);

	return 0;
}
my_mipi_start_streaming function · c · L18-L25 (8 LOC)
my_sensor.c
static int my_mipi_start_streaming(struct my_mipi *sensor)
{
	// TODO: Write registers to start the sensor streaming
	pr_info("my_mipi: starting stream\n");
	sensor->streaming = true;
	return 0;
}
my_mipi_stop_streaming function · c · L26-L33 (8 LOC)
my_sensor.c
static int my_mipi_stop_streaming(struct my_mipi *sensor)
{
	// TODO: Write registers to stop the sensor streaming
	pr_info("my_mipi: stopping stream\n");
	sensor->streaming = false;
	return 0;
}
Generated by Repobility's multi-pass static-analysis pipeline (https://repobility.com)
my_mipi_s_stream function · c · L36-L41 (6 LOC)
my_sensor.c
static int my_mipi_s_stream(struct v4l2_subdev *sd, int enable)
{
	struct my_mipi *sensor = container_of(sd, struct my_mipi, sd);
	return enable ? my_mipi_start_streaming(sensor)
		      : my_mipi_stop_streaming(sensor);
}
my_mipi_set_fmt function · c · L42-L56 (15 LOC)
my_sensor.c
static int my_mipi_set_fmt(struct v4l2_subdev *sd,
			   struct v4l2_subdev_state *state,
			   struct v4l2_subdev_format *fmt)
{
	struct my_mipi *sensor = container_of(sd, struct my_mipi, sd);

	// Just accept whatever for now
	sensor->fmt = fmt->format;
	fmt->format = sensor->fmt;

	pr_info("my_mipi: set format %ux%u code=0x%x\n",
		fmt->format.width, fmt->format.height, fmt->format.code);
	return 0;
}
my_mipi_get_fmt function · c · L57-L65 (9 LOC)
my_sensor.c
static int my_mipi_get_fmt(struct v4l2_subdev *sd,
			   struct v4l2_subdev_state *state,
			   struct v4l2_subdev_format *fmt)
{
	struct my_mipi *sensor = container_of(sd, struct my_mipi, sd);
	fmt->format = sensor->fmt;
	return 0;
}
my_mipi_probe function · c · L82-L112 (31 LOC)
my_sensor.c
static int my_mipi_probe(struct i2c_client *client)
{
	struct my_mipi *sensor;
	struct v4l2_subdev *sd;

	pr_info("my_mipi: probing sensor at %s\n", client->name);

	sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL);
	if (!sensor)
		return -ENOMEM;

	/* Init default format */
	sensor->fmt.width  = 1920;
	sensor->fmt.height = 1080;
	sensor->fmt.code   = MEDIA_BUS_FMT_SRGGB10_1X10;
	sensor->fmt.field  = V4L2_FIELD_NONE;

	/* Init subdev */
	sd = &sensor->sd;
	v4l2_i2c_subdev_init(sd, client, &my_mipi_subdev_ops);

	/* Media entity setup */
	sensor->pad.flags = MEDIA_PAD_FL_SOURCE;
	sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
	sd->entity.ops = NULL;
	if (media_entity_pads_init(&sd->entity, 1, &sensor->pad))
		return -ENOMEM;

	pr_info("my_mipi: probe successful\n");
	return 0;
}
my_mipi_remove function · c · L113-L125 (13 LOC)
my_sensor.c
static int my_mipi_remove(struct i2c_client *client)
{
	struct v4l2_subdev *sd = i2c_get_clientdata(client);
	//struct my_mipi *sensor = container_of(sd, struct my_mipi, sd);

	v4l2_async_unregister_subdev(sd);
	media_entity_cleanup(&sd->entity);
	pr_info("my_mipi: removed\n");

        return 0;

}