33 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35 #include <linux/errno.h>
37 #include <linux/module.h>
38 #include <linux/kernel.h>
40 #include <linux/slab.h>
42 #include <linux/string.h>
43 #include <linux/types.h>
48 #define MEDIA_NUM_DEVICES 256
49 #define MEDIA_NAME "media"
51 static dev_t media_dev_t;
60 static void media_devnode_release(
struct device *
cd)
79 static struct bus_type media_bus_type = {
84 size_t sz, loff_t *off)
88 if (!mdev->
fops->read)
90 if (!media_devnode_is_registered(mdev))
92 return mdev->
fops->read(filp, buf, sz, off);
95 static ssize_t media_write(
struct file *filp,
const char __user *buf,
96 size_t sz, loff_t *off)
100 if (!mdev->
fops->write)
102 if (!media_devnode_is_registered(mdev))
104 return mdev->
fops->write(filp, buf, sz, off);
107 static unsigned int media_poll(
struct file *filp,
112 if (!media_devnode_is_registered(mdev))
114 if (!mdev->
fops->poll)
116 return mdev->
fops->poll(filp, poll);
119 static long media_ioctl(
struct file *filp,
unsigned int cmd,
unsigned long arg)
123 if (!mdev->
fops->ioctl)
126 if (!media_devnode_is_registered(mdev))
129 return mdev->
fops->ioctl(filp, cmd, arg);
148 if (!media_devnode_is_registered(mdev)) {
158 if (mdev->
fops->open) {
159 ret = mdev->
fops->open(filp);
170 static int media_release(
struct inode *inode,
struct file *filp)
175 if (mdev->
fops->release)
176 mdev->
fops->release(filp);
188 .write = media_write,
190 .unlocked_ioctl = media_ioctl,
191 .release = media_release,
220 pr_err(
"could not get a free minor\n");
224 set_bit(minor, media_devnode_nums);
231 mdev->
cdev.owner = mdev->
fops->owner;
235 pr_err(
"%s: cdev_add failed\n", __func__);
240 mdev->
dev.bus = &media_bus_type;
242 mdev->
dev.release = media_devnode_release;
248 pr_err(
"%s: device_register failed\n", __func__);
276 if (!media_devnode_is_registered(mdev))
288 static int __init media_devnode_init(
void)
292 pr_info(
"Linux media interface: v0.10\n");
296 pr_warn(
"unable to allocate major\n");
303 pr_warn(
"bus_register failed\n");
310 static void __exit media_devnode_exit(
void)