/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
C | 861 lines | 732 code | 98 blank | 31 comment | 72 complexity | d1581d4baaf31cd24542d6b378964217 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
- /*
- *
- *
- * Copyright (C) 2005 Mike Isely <isely@pobox.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
- #include <linux/string.h>
- #include <linux/slab.h>
- #include "pvrusb2-sysfs.h"
- #include "pvrusb2-hdw.h"
- #include "pvrusb2-debug.h"
- #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
- #include "pvrusb2-debugifc.h"
- #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
- #define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__)
- struct pvr2_sysfs {
- struct pvr2_channel channel;
- struct device *class_dev;
- #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
- struct pvr2_sysfs_debugifc *debugifc;
- #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
- struct pvr2_sysfs_ctl_item *item_first;
- struct pvr2_sysfs_ctl_item *item_last;
- struct device_attribute attr_v4l_minor_number;
- struct device_attribute attr_v4l_radio_minor_number;
- struct device_attribute attr_unit_number;
- struct device_attribute attr_bus_info;
- struct device_attribute attr_hdw_name;
- struct device_attribute attr_hdw_desc;
- int v4l_minor_number_created_ok;
- int v4l_radio_minor_number_created_ok;
- int unit_number_created_ok;
- int bus_info_created_ok;
- int hdw_name_created_ok;
- int hdw_desc_created_ok;
- };
- #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
- struct pvr2_sysfs_debugifc {
- struct device_attribute attr_debugcmd;
- struct device_attribute attr_debuginfo;
- int debugcmd_created_ok;
- int debuginfo_created_ok;
- };
- #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
- struct pvr2_sysfs_ctl_item {
- struct device_attribute attr_name;
- 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;
- struct device_attribute attr_custom;
- struct pvr2_ctrl *cptr;
- int ctl_id;
- struct pvr2_sysfs *chptr;
- struct pvr2_sysfs_ctl_item *item_next;
- struct attribute *attr_gen[8];
- struct attribute_group grp;
- int created_ok;
- char name[80];
- };
- struct pvr2_sysfs_class {
- struct class class;
- };
- static ssize_t show_name(struct device *class_dev,
- struct device_attribute *attr,
- char *buf)
- {
- struct pvr2_sysfs_ctl_item *cip;
- const char *name;
- cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_name);
- name = pvr2_ctrl_get_desc(cip->cptr);
- pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s",
- cip->chptr, cip->ctl_id, name);
- if (!name) return -EINVAL;
- return scnprintf(buf, PAGE_SIZE, "%s\n", name);
- }
- static ssize_t show_type(struct device *class_dev,
- struct device_attribute *attr,
- char *buf)
- {
- struct pvr2_sysfs_ctl_item *cip;
- const char *name;
- enum pvr2_ctl_type tp;
- cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_type);
- tp = pvr2_ctrl_get_type(cip->cptr);
- switch (tp) {
- case pvr2_ctl_int: name = "integer"; break;
- case pvr2_ctl_enum: name = "enum"; break;
- case pvr2_ctl_bitmask: name = "bitmask"; break;
- case pvr2_ctl_bool: name = "boolean"; break;
- default: name = "?"; break;
- }
- pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",
- cip->chptr, cip->ctl_id, name);
- if (!name) return -EINVAL;
- return scnprintf(buf, PAGE_SIZE, "%s\n", name);
- }
- static ssize_t show_min(struct device *class_dev,
- struct device_attribute *attr,
- char *buf)
- {
- struct pvr2_sysfs_ctl_item *cip;
- long val;
- cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_min);
- val = pvr2_ctrl_get_min(cip->cptr);
- pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld",
- cip->chptr, cip->ctl_id, val);
- return scnprintf(buf, PAGE_SIZE, "%ld\n", val);
- }
- static ssize_t show_max(struct device *class_dev,
- struct device_attribute *attr,
- char *buf)
- {
- struct pvr2_sysfs_ctl_item *cip;
- long val;
- cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_max);
- val = pvr2_ctrl_get_max(cip->cptr);
- pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld",
- cip->chptr, cip->ctl_id, val);
- 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;
- unsigned int cnt = 0;
- cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_def);
- ret = pvr2_ctrl_get_def(cip->cptr, &val);
- if (ret < 0) return ret;
- ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val,
- buf, PAGE_SIZE - 1, &cnt);
- pvr2_sysfs_trace("pvr2_sysfs(%p) show_def(cid=%d) is %.*s (%d)",
- cip->chptr, cip->ctl_id, cnt, buf, val);
- buf[cnt] = '\n';
- return cnt + 1;
- }
- static ssize_t show_val_norm(struct device *class_dev,
- struct device_attribute *attr,
- char *buf)
- {
- struct pvr2_sysfs_ctl_item *cip;
- int val;
- int ret;
- unsigned int cnt = 0;
- cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
- ret = pvr2_ctrl_get_value(cip->cptr, &val);
- if (ret < 0) return ret;
- ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val,
- buf, PAGE_SIZE - 1, &cnt);
- pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
- cip->chptr, cip->ctl_id, cnt, buf, val);
- buf[cnt] = '\n';
- return cnt+1;
- }
- static ssize_t show_val_custom(struct device *class_dev,
- struct device_attribute *attr,
- char *buf)
- {
- struct pvr2_sysfs_ctl_item *cip;
- int val;
- int ret;
- unsigned int cnt = 0;
- cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
- ret = pvr2_ctrl_get_value(cip->cptr, &val);
- if (ret < 0) return ret;
- ret = pvr2_ctrl_custom_value_to_sym(cip->cptr, ~0, val,
- buf, PAGE_SIZE - 1, &cnt);
- pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
- cip->chptr, cip->ctl_id, cnt, buf, val);
- buf[cnt] = '\n';
- return cnt+1;
- }
- static ssize_t show_enum(struct device *class_dev,
- struct device_attribute *attr,
- char *buf)
- {
- struct pvr2_sysfs_ctl_item *cip;
- long val;
- unsigned int bcnt, ccnt, ecnt;
- cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_enum);
- ecnt = pvr2_ctrl_get_cnt(cip->cptr);
- bcnt = 0;
- for (val = 0; val < ecnt; val++) {
- pvr2_ctrl_get_valname(cip->cptr, val, buf + bcnt,
- PAGE_SIZE - bcnt, &ccnt);
- if (!ccnt) continue;
- bcnt += ccnt;
- if (bcnt >= PAGE_SIZE) break;
- buf[bcnt] = '\n';
- bcnt++;
- }
- pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",
- cip->chptr, cip->ctl_id);
- return bcnt;
- }
- static ssize_t show_bits(struct device *class_dev,
- struct device_attribute *attr,
- char *buf)
- {
- struct pvr2_sysfs_ctl_item *cip;
- int valid_bits, msk;
- unsigned int bcnt, ccnt;
- cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_bits);
- valid_bits = pvr2_ctrl_get_mask(cip->cptr);
- bcnt = 0;
- for (msk = 1; valid_bits; msk <<= 1) {
- if (!(msk & valid_bits)) continue;
- valid_bits &= ~msk;
- pvr2_ctrl_get_valname(cip->cptr, msk, buf + bcnt,
- PAGE_SIZE - bcnt, &ccnt);
- bcnt += ccnt;
- if (bcnt >= PAGE_SIZE) break;
- buf[bcnt] = '\n';
-