framerate_adapter: add framerate_adapter function. [1/1]
authorshilong.yang <shilong.yang@amlogic.com>
Mon, 8 Jun 2020 12:43:32 +0000 (20:43 +0800)
committershilong.yang <shilong.yang@amlogic.com>
Tue, 21 Jul 2020 02:51:37 +0000 (10:51 +0800)
PD#SWPL-26471

Problem:
seed uevent to android systemcontral.

Solution:
add kobject_uevent_env function in the media_modules.

Verify:
franklin

Change-Id: Id9fbcb20fd964648b9d7966d0e2d2b6547a2814c
Signed-off-by: shilong.yang <shilong.yang@amlogic.com>
drivers/Makefile
drivers/framerate_adapter/Makefile [new file with mode: 0644]
drivers/framerate_adapter/video_framerate_adapter.c [new file with mode: 0644]
drivers/framerate_adapter/video_framerate_adapter.h [new file with mode: 0644]

index 1acca52ac6774e7d1808180702b0333df14774b2..84560e8acf075207103ce0f23879015c086c99ae 100644 (file)
@@ -4,3 +4,5 @@ obj-y   +=      frame_sink/
 obj-y  +=      stream_input/
 obj-y  +=      amvdec_ports/
 obj-y  +=      fake_video_out/
+obj-y  +=      framerate_adapter/
+
diff --git a/drivers/framerate_adapter/Makefile b/drivers/framerate_adapter/Makefile
new file mode 100644 (file)
index 0000000..fc1998b
--- /dev/null
@@ -0,0 +1 @@
+obj-m   +=      video_framerate_adapter.o
diff --git a/drivers/framerate_adapter/video_framerate_adapter.c b/drivers/framerate_adapter/video_framerate_adapter.c
new file mode 100644 (file)
index 0000000..f920954
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * drivers/framerate_adapter/video_framerate_adapter.c
+ *
+ * Copyright (C) 2020 Amlogic, Inc. All rights reserved.
+ *
+ * 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.
+ *
+ */
+#include <linux/slab.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include "video_framerate_adapter.h"
+
+#define CLASS_NAME     "framerate_adapter"
+#define DEV_NAME       "framerate_dev"
+
+#ifndef VIDEOFRAME_MAJOR
+#define VIDEOFRAME_MAJOR 550
+#endif
+
+struct frame_rate_dev_s* frame_rate_dev;
+
+ void vframe_rate_uevent(int duration)
+{
+       char *configured[2];
+       char framerate[40] = {0};
+
+       sprintf(framerate, "FRAME_RATE_HINT=%lu",
+               (unsigned long)duration);
+       configured[0] = framerate;
+       configured[1] = NULL;
+       kobject_uevent_env(&frame_rate_dev->dev->kobj,
+               KOBJ_CHANGE, configured);
+
+       pr_info("%s: sent uevent %s\n", __func__, configured[0]);
+}
+
+EXPORT_SYMBOL(vframe_rate_uevent);
+
+static const struct file_operations frame_rate_fops = {
+       .owner = THIS_MODULE
+};
+
+static struct class_attribute frame_rate_class_attrs[] = {
+       __ATTR_NULL
+};
+
+static struct class frame_rate_class = {
+       .name = CLASS_NAME,
+       .class_attrs = frame_rate_class_attrs,
+};
+
+static int frame_rate_driver_init(void)
+{
+       int ret = -1;
+
+       frame_rate_dev = kzalloc(sizeof(struct frame_rate_dev_s), GFP_KERNEL);
+       if (IS_ERR_OR_NULL(frame_rate_dev))
+               return -ENOMEM;
+
+       frame_rate_dev->dev_no = MKDEV(VIDEOFRAME_MAJOR, 100);
+
+       ret = register_chrdev_region(frame_rate_dev->dev_no, 1, DEV_NAME);
+       if (ret < 0) {
+               pr_err("Can't get major number %d.\n", VIDEOFRAME_MAJOR);
+               goto err_4;
+       }
+
+       cdev_init(&frame_rate_dev->cdev, &frame_rate_fops);
+       frame_rate_dev->cdev.owner = THIS_MODULE;
+
+       ret = cdev_add(&frame_rate_dev->cdev, frame_rate_dev->dev_no, 1);
+       if (ret) {
+               pr_err("Error %d adding cdev fail.\n", ret);
+               goto err_3;
+       }
+
+       ret = class_register(&frame_rate_class);
+       if (ret < 0) {
+               pr_err("Failed in creating class.\n");
+               goto err_2;
+       }
+
+       frame_rate_dev->dev = device_create(&frame_rate_class, NULL,
+               frame_rate_dev->dev_no, NULL, DEV_NAME);
+       if (IS_ERR_OR_NULL(frame_rate_dev->dev)) {
+               pr_err("Create device failed.\n");
+               ret = -ENODEV;
+               goto err_1;
+       }
+       pr_info("Registered frame rate driver success.\n");
+       return 0;
+
+err_1:
+       device_destroy(&frame_rate_class, frame_rate_dev->dev_no);
+err_2:
+       class_unregister(&frame_rate_class);
+err_3:
+       cdev_del(&frame_rate_dev->cdev);
+err_4:
+       unregister_chrdev_region(frame_rate_dev->dev_no, 1);
+       kfree(frame_rate_dev);
+       return ret;
+}
+
+static void frame_rate_driver_exit(void)
+{
+       device_destroy(&frame_rate_class, frame_rate_dev->dev_no);
+       class_unregister(&frame_rate_class);
+       cdev_del(&frame_rate_dev->cdev);
+       unregister_chrdev_region(frame_rate_dev->dev_no, 1);
+       kfree(frame_rate_dev);
+}
+
+static int __init frame_rate_module_init(void)
+{
+       int ret = -1;
+
+       ret = frame_rate_driver_init();
+       if (ret) {
+               pr_info("Error %d frame_rate_module_init init fail.\n", ret);
+       }
+       return ret;
+}
+
+static void __exit frame_rate_module_exit(void)
+{
+       frame_rate_driver_exit();
+       pr_info("frame_rate_module_exit\n");
+}
+
+module_init(frame_rate_module_init);
+module_exit(frame_rate_module_exit);
+
+MODULE_AUTHOR("<shilong.yang@amlogic.com>");
+MODULE_DESCRIPTION("framerate adapter");
+MODULE_LICENSE("GPL");
diff --git a/drivers/framerate_adapter/video_framerate_adapter.h b/drivers/framerate_adapter/video_framerate_adapter.h
new file mode 100644 (file)
index 0000000..1748843
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * drivers/framerate_adapter/video_framerate_adaper.h
+ *
+ * Copyright (C) 2020 Amlogic, Inc. All rights reserved.
+ *
+ * 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.
+ *
+*/
+
+#ifndef VIDEOFRAMERATEADAPTER_H
+#define VIDEOFRAMERATEADAPTER_H
+
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/cdev.h>
+
+
+struct frame_rate_dev_s  {
+       struct cdev cdev;
+       struct device *dev;
+       dev_t dev_no;
+};
+
+#endif
+