sysfs entry for v4l2src?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

sysfs entry for v4l2src?

Jump to solution
1,767 Views
gbiradar
Contributor IV

Hi Guys,

             I want to enable sysfs entry to my ov5640 camera. with sysfs i'm trying to control brightness,contrast values. i know about sysfs but adding support for camera i don't know if anyone has idea plaese share it.

regards,

Ganesh

0 Kudos
Reply
1 Solution
1,531 Views
gbiradar
Contributor IV

Hi alejandrolozano​,

well i have actually able to create sysfs entry able to pass some value to desired brightness level  but it is returning ov5640_write_reg fail.

Below is my code snippet  check.

static struct kobject *ov5640_mipi_kobj;

static ssize_t ov5640_mipi_brightness_set(struct device *dev, struct device_attribute *attr, char *buf,size_t size)

{

   int err;

  unsigned long val;

  if (strict_strtoul(buf, 10, &val))

                return -EINVAL;

  pr_info("GB : ov5640_mipi_brightness_set\n");

  switch(val){

  case 0 :      ov5640_write_reg(0x5001, 0xff);

                     ov5640_write_reg(0x5587, 0x40);

                     ov5640_write_reg(0x5580, 0x04);

                     ov5640_write_reg(0x5588, 0x01);

                     break;

..................

..................

}

static struct kobj_attribute brightness = __ATTR(brightness_ctrl, 0664, NULL, ov5640_mipi_brightness_set);

static struct attribute *attributes_ov5640_mipi[] = {

        &brightness.attr,

        NULL,

};

static struct attribute_group attr_group_ov5640_mipi = {

        .attrs = attributes_ov5640_mipi,

};

static int create_sysfs_interfaces(struct device *dev)

{

        int err;

        ov5640_mipi_kobj = kobject_create_and_add("ov5640_mipi_sensor", &dev->kobj);

        if(!ov5640_mipi_kobj)

                return -ENOMEM;

        err = sysfs_create_group(ov5640_mipi_kobj, &attr_group_ov5640_mipi);

        if (err)

        {

                kobject_put(ov5640_mipi_kobj);

                dev_err(dev, "%s:Unable to create interface\n", __func__);

                 return -1;

        }

  pr_info("GB : create_sysfs_interfaces\n");

  return 0;

}

$ echo 0 > /sys/bus/i2c/../devices/ov5640_brightness_set/brightness_ctrl

GB : ov5640_mipi_brightness_set

ov5640_write_reg:write reg error:reg=5001,val=ff

ov5640_write_reg:write reg error:reg=5587,val=40

ov5640_write_reg:write reg error:reg=5580,val=4

ov5640_write_reg:write reg error:reg=5588,val=1

View solution in original post

0 Kudos
Reply
4 Replies
1,531 Views
alejandrolozan1
NXP Employee
NXP Employee

Hi,

I think you can use as reference the code of drivers/media/platform/mxc/capture/mxc_v4l2_capture.c

There you can see the below example.

static ssize_t show_streaming(struct device *dev,

                        struct device_attribute *attr, char *buf)

{

        struct video_device *video_dev = container_of(dev,

                                                struct video_device, dev);

        cam_data *cam = video_get_drvdata(video_dev);

        if (cam->capture_on)

                return sprintf(buf, "stream on\n");

        else

                return sprintf(buf, "stream off\n");

}

static DEVICE_ATTR(fsl_v4l2_capture_property, S_IRUGO, show_streaming, NULL);

Please take a look at that file. You may find it very helpful.

Best Regards,

Alejandro

0 Kudos
Reply
1,532 Views
gbiradar
Contributor IV

Hi alejandrolozano​,

well i have actually able to create sysfs entry able to pass some value to desired brightness level  but it is returning ov5640_write_reg fail.

Below is my code snippet  check.

static struct kobject *ov5640_mipi_kobj;

static ssize_t ov5640_mipi_brightness_set(struct device *dev, struct device_attribute *attr, char *buf,size_t size)

{

   int err;

  unsigned long val;

  if (strict_strtoul(buf, 10, &val))

                return -EINVAL;

  pr_info("GB : ov5640_mipi_brightness_set\n");

  switch(val){

  case 0 :      ov5640_write_reg(0x5001, 0xff);

                     ov5640_write_reg(0x5587, 0x40);

                     ov5640_write_reg(0x5580, 0x04);

                     ov5640_write_reg(0x5588, 0x01);

                     break;

..................

..................

}

static struct kobj_attribute brightness = __ATTR(brightness_ctrl, 0664, NULL, ov5640_mipi_brightness_set);

static struct attribute *attributes_ov5640_mipi[] = {

        &brightness.attr,

        NULL,

};

static struct attribute_group attr_group_ov5640_mipi = {

        .attrs = attributes_ov5640_mipi,

};

static int create_sysfs_interfaces(struct device *dev)

{

        int err;

        ov5640_mipi_kobj = kobject_create_and_add("ov5640_mipi_sensor", &dev->kobj);

        if(!ov5640_mipi_kobj)

                return -ENOMEM;

        err = sysfs_create_group(ov5640_mipi_kobj, &attr_group_ov5640_mipi);

        if (err)

        {

                kobject_put(ov5640_mipi_kobj);

                dev_err(dev, "%s:Unable to create interface\n", __func__);

                 return -1;

        }

  pr_info("GB : create_sysfs_interfaces\n");

  return 0;

}

$ echo 0 > /sys/bus/i2c/../devices/ov5640_brightness_set/brightness_ctrl

GB : ov5640_mipi_brightness_set

ov5640_write_reg:write reg error:reg=5001,val=ff

ov5640_write_reg:write reg error:reg=5587,val=40

ov5640_write_reg:write reg error:reg=5580,val=4

ov5640_write_reg:write reg error:reg=5588,val=1

0 Kudos
Reply
1,531 Views
gbiradar
Contributor IV

update:

Camera will be powerdown mode so some application is run to allow the camera in active mode then the write error will not come

0 Kudos
Reply