From: "Christian Gmeiner" <christian@visual-page.de>
To: linux-hotplug@vger.kernel.org
Subject: Coding problem with sysfs
Date: Wed, 02 Jun 2004 09:21:53 +0000 [thread overview]
Message-ID: <002c01c44883$2717bfc0$0600a8c0@blackbox> (raw)
[-- Attachment #1: Type: text/plain, Size: 1717 bytes --]
Hi Mailling list.
i have tried to wirte a sysfs patch for the dvb-driver. It seems very nice,
but i am _not_ able
to access and work with the devices.
Now i have run some tests:
1. Only register the adapter, the other functions are commented out
vdr root # ls -R /sys/class/dvb
/sys/class/dvb:
adapter0
/sys/class/dvb/adapter0:
frontend name
And i can access the infos:
vdr root # cat /sys/class/dvb/adapter0/frontend
STV0299/TSA5059/SL1935 based
vdr root # cat /sys/class/dvb/adapter0/name
KNC1 DVB-S
Looks nice....
2. Enabled full sysfs support
vdr root # ls -R /sys/class/dvb
/sys/class/dvb:
adapter0
/sys/class/dvb/adapter0:
demux0 dvr0 frontend frontend0 name net0
/sys/class/dvb/adapter0/demux0:
adap dev
/sys/class/dvb/adapter0/dvr0:
adap dev
/sys/class/dvb/adapter0/frontend0:
adap dev
/sys/class/dvb/adapter0/net0:
adap dev
vdr root # ls -Rl /dev/dvb
/dev/dvb:
total 0
drwxr-xr-x 2 root root 0 Jun 1 00:10 adapter0
/dev/dvb/adapter0:
total 0
crw-rw---- 1 root video 250, 7 Jun 1 00:10 adapter0
crw-rw---- 1 root video 250, 4 Jun 1 00:10 demux0
crw-rw---- 1 root video 250, 5 Jun 1 00:10 dvr0
crw-rw---- 1 root video 250, 3 Jun 1 00:10 frontend0
crw-rw---- 1 root video 250, 7 Jun 1 00:10 net0
Ok... /dev/dvb/adapter0/adapter0 shouldn't exist and i have an other problem
vdr root # ls /dev/dvb/adapter0/frontend0
/dev/dvb/adapter0/frontend0
vdr root # cat /dev/dvb/adapter0/frontend0
cat: /dev/dvb/adapter0/frontend0: No such device or address
If i am using devfs i get here:
vdr root # cat /dev/dvb/adapter0/frontend0
cat: /dev/dvb/adapter0/frontend0: invalid arguments
Maybe somebody can help me.
Atteched are the needed sysfs files.
Thanks,
Christian Gmeiner
[-- Attachment #2: dvb_sysfs.c --]
[-- Type: application/octet-stream, Size: 5159 bytes --]
/*
*
* dvb_sysfs.c -- interface to the sysfs filesystem
* Copyright (C) 2004 Christian Gmeiner <christian@visual-page.de>
* Copyright (C) 2004 Eric Donohue <epd3j@hotmail.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, or (at your option) any later version.
*
* 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/version.h>
#include "dvb_sysfs.h"
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,46)
#ifndef DVB_SYSFS_DIR
#define DVB_SYSFS_DIR "dvb" //-> /sys/class/dvb/...
#endif
static struct class dvb_class = {
.name = DVB_SYSFS_DIR
};
static ssize_t show_name(struct class_device *cd, char *buf)
{
struct dvb_adapter *adap = container_of(cd, struct dvb_adapter, class_dev);
sprintf(buf, "%s\n", adap->name);
return strlen(buf) + 1;
}
static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
static ssize_t show_frontend(struct class_device *cd, char *buf)
{
struct dvb_adapter *adap = container_of(cd, struct dvb_adapter, class_dev);
sprintf(buf, "%s\n", adap->frontend);
return strlen(buf) + 1;
}
static CLASS_DEVICE_ATTR(frontend, S_IRUGO, show_frontend, NULL);
static ssize_t show_devnum(struct class_device *cd, char *buf)
{
struct dvb_device *dvbdev = container_of(cd, struct dvb_device, class_dev);
dev_t dev = MKDEV(DVB_MAJOR, nums2minor(dvbdev->adapter->num, dvbdev->type, dvbdev->id));
return print_dev_t(buf, dev);
}
static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_devnum, NULL);
static ssize_t show_adap(struct class_device *cd, char *buf)
{
struct dvb_device *dvbdev = container_of(cd, struct dvb_device, class_dev);
sprintf(buf, "adapter%d\n", dvbdev->adapter->num);
return strlen(buf) + 1;
}
static CLASS_DEVICE_ATTR(adap, S_IRUGO, show_adap, NULL);
static struct class_device_attribute *dvb_adapter_attrs[] = {
&class_device_attr_name,
&class_device_attr_frontend,
NULL
};
static struct class_device_attribute *dvb_device_attrs[] = {
&class_device_attr_dev,
&class_device_attr_adap,
NULL
};
static void dvb_sysfs_register_adapter(struct dvb_adapter *adap)
{
char name[64] = "";
int i;
adap->class_dev.class = &dvb_class;
adap->class_dev.dev = NULL;
adap->class_dev.class_data = adap;
sprintf(name,"adapter%d", adap->num);
strcpy(adap->class_dev.class_id, name);
if(class_device_register(&adap->class_dev))
printk(KERN_ERR "Unable to register dvb class device\n");
for(i = 0; dvb_adapter_attrs[i]; i++)
class_device_create_file(&(adap->class_dev), dvb_adapter_attrs[i]);
}
static void dvb_sysfs_unregister_adapter(struct dvb_adapter *adap)
{
class_device_unregister(&(adap->class_dev));
}
static void dvb_sysfs_register_device(struct dvb_device *dvbdev)
{
int i;
char name[64] = "";
struct class_device *class_dev = &(dvbdev->class_dev);
sprintf(name,"%s%d", dnames[dvbdev->type], dvbdev->adapter->num);
class_dev->class = &dvb_class;
class_dev->class_data = dvbdev;
strcpy(class_dev->class_id, name);
kobject_init(&class_dev->kobj);
strcpy(class_dev->kobj.name, name);
class_dev->kobj.parent = &dvbdev->adapter->class_dev.kobj;
class_dev->kobj.kset = dvbdev->adapter->class_dev.kobj.kset;
class_dev->kobj.ktype = dvbdev->adapter->class_dev.kobj.ktype;
class_dev->kobj.dentry = dvbdev->adapter->class_dev.kobj.dentry;
kobject_register(&class_dev->kobj);
for (i = 0; dvb_device_attrs[i]; i++)
class_device_create_file(class_dev, dvb_device_attrs[i]);
}
static void dvb_sysfs_unregister_device(struct dvb_device *dvbdev)
{
kobject_unregister(&dvbdev->class_dev.kobj);
}
static int dvb_sysfs_init(void)
{
printk("DVB: Using sysfs funtions\n");
if (class_register(&dvb_class) != 0) {
printk("DVB: adapter class failed to register properly");
return -1;
}
return 0;
}
static void dvb_sysfs_exit(void)
{
class_unregister(&dvb_class);
}
struct dvb_registrar_s dvb_sysfs_registrar =
{
.register_adapter = &dvb_sysfs_register_adapter,
.unregister_adapter = &dvb_sysfs_unregister_adapter,
.register_device = &dvb_sysfs_register_device,
.unregister_device = &dvb_sysfs_unregister_device,
.dvbdev_init = &dvb_sysfs_init,
.dvbdev_exit = &dvb_sysfs_exit,
};
#else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,46) */
struct dvb_registrar_s dvb_sysfs_registrar =
{
.register_adapter = NULL,
.unregister_adapter = NULL,
.register_device = NULL,
.unregister_device = NULL,
.dvbdev_init = NULL,
.dvbdev_exit = NULL,
};
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,46) */
[-- Attachment #3: dvbdev.h --]
[-- Type: application/octet-stream, Size: 2542 bytes --]
/*
* dvbdev.h
*
* Copyright (C) 2000 Ralph Metzler & Marcus Metzler
* for convergence integrated media GmbH
* Copyright (C) 2004 Christian Gmeiner <christian@visual-page.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Lesser Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* 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 Lesser 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.
*
*/
#ifndef _DVBDEV_H_
#define _DVBDEV_H_
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/poll.h>
#include <linux/device.h>
#define DVB_MAJOR 250
#define DVB_DEVICE_VIDEO 0
#define DVB_DEVICE_AUDIO 1
#define DVB_DEVICE_SEC 2
#define DVB_DEVICE_FRONTEND 3
#define DVB_DEVICE_DEMUX 4
#define DVB_DEVICE_DVR 5
#define DVB_DEVICE_CA 6
#define DVB_DEVICE_NET 7
#define DVB_DEVICE_OSD 8
struct dvb_adapter {
int num;
struct list_head list_head;
struct list_head device_list;
const char *name;
char frontend[64];
u8 proposed_mac [6];
struct module *module;
// SysFs
struct class_device class_dev;
};
struct dvb_device {
struct list_head list_head;
struct file_operations *fops;
struct dvb_adapter *adapter;
int type;
u32 id;
/* in theory, 'users' can vanish now,
but I don't want to change too much now... */
int readers;
int writers;
int users;
/* don't really need those !? -- FIXME: use video_usercopy */
int (*kernel_ioctl)(struct inode *inode, struct file *file,
unsigned int cmd, void *arg);
void *priv;
// SysFs
struct class_device class_dev;
};
#include "dvb_registration.h"
// generic functions
extern int dvb_generic_open (struct inode *inode, struct file *file);
extern int dvb_generic_release (struct inode *inode, struct file *file);
extern int dvb_generic_ioctl (struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg);
#endif /* _DVBDEV_H_ */
next reply other threads:[~2004-06-02 9:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-02 9:21 Christian Gmeiner [this message]
2004-06-04 21:05 ` Coding problem with sysfs Greg KH
2004-06-05 0:30 ` Christian Gmeiner
2004-06-05 15:40 ` Greg KH
2004-06-05 16:23 ` Christian Gmeiner
2004-06-07 23:38 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='002c01c44883$2717bfc0$0600a8c0@blackbox' \
--to=christian@visual-page.de \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).