V4L/DVB (8899): pvrusb2: Implement default value retrieval in sysfs interface
authorMike Isely <isely@pobox.com>
Sun, 31 Aug 2008 23:57:54 +0000 (20:57 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sun, 12 Oct 2008 11:36:57 +0000 (09:36 -0200)
Signed-off-by: Mike Isely <isely@pobox.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/pvrusb2/pvrusb2-sysfs.c

index 46a8c39..ac01b11 100644 (file)
@@ -65,6 +65,7 @@ struct pvr2_sysfs_ctl_item {
        struct device_attribute attr_type;
        struct device_attribute attr_min;
        struct device_attribute attr_max;
+       struct device_attribute attr_def;
        struct device_attribute attr_enum;
        struct device_attribute attr_bits;
        struct device_attribute attr_val;
@@ -145,6 +146,24 @@ static ssize_t show_max(struct device *class_dev,
        return scnprintf(buf, PAGE_SIZE, "%ld\n", val);
 }
 
+static ssize_t show_def(struct device *class_dev,
+                       struct device_attribute *attr,
+                       char *buf)
+{
+       struct pvr2_sysfs_ctl_item *cip;
+       int val;
+       int ret;
+       cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_def);
+       ret = pvr2_ctrl_get_def(cip->cptr, &val);
+       pvr2_sysfs_trace("pvr2_sysfs(%p) show_def(cid=%d) is %d, stat=%d",
+                        cip->chptr, cip->ctl_id, val, ret);
+       if (ret < 0) {
+               /* Keep checkpatch.pl quiet */
+               return ret;
+       }
+       return scnprintf(buf, PAGE_SIZE, "%d\n", val);
+}
+
 static ssize_t show_val_norm(struct device *class_dev,
                             struct device_attribute *attr,
                             char *buf)
@@ -320,6 +339,10 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
        cip->attr_max.attr.mode = S_IRUGO;
        cip->attr_max.show = show_max;
 
+       cip->attr_def.attr.name = "def_val";
+       cip->attr_def.attr.mode = S_IRUGO;
+       cip->attr_def.show = show_def;
+
        cip->attr_val.attr.name = "cur_val";
        cip->attr_val.attr.mode = S_IRUGO;
 
@@ -343,6 +366,7 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
        cip->attr_gen[acnt++] = &cip->attr_name.attr;
        cip->attr_gen[acnt++] = &cip->attr_type.attr;
        cip->attr_gen[acnt++] = &cip->attr_val.attr;
+       cip->attr_gen[acnt++] = &cip->attr_def.attr;
        cip->attr_val.show = show_val_norm;
        cip->attr_val.store = store_val_norm;
        if (pvr2_ctrl_has_custom_symbols(cptr)) {