video: rockchip: hdmi: contrast uboot and kernel resolution
[firefly-linux-kernel-4.4.55.git] / drivers / video / rockchip / hdmi / rockchip-hdmi-cec.c
index f7e25f8442455c71b339db13dfb4ff892017b927..4bfe2413e66bd0b463865b8bd58656257ec8cb14 100644 (file)
@@ -1,34 +1,48 @@
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/workqueue.h>
 #include <linux/delay.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
 #include <linux/errno.h>
+#include <linux/firmware.h>
+#include <linux/ioctl.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/pagemap.h>
+#include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/workqueue.h>
-#include <linux/firmware.h>
 #include "rockchip-hdmi-cec.h"
-#include "linux/ioctl.h"
-#include "linux/pagemap.h"
 
 static struct cec_device *cec_dev;
 
 static int cecreadframe(struct cec_framedata *frame)
 {
-       if (frame == NULL || !cec_dev ||
-           cec_dev->readframe == NULL || !cec_dev->enable)
-               return -1;
-       else
-               return cec_dev->readframe(cec_dev->hdmi, frame);
+       int ret = -1;
+
+       if (frame && cec_dev && cec_dev->readframe && cec_dev->enable) {
+               mutex_lock(&cec_dev->hdmi->pclk_lock);
+               ret = cec_dev->readframe(cec_dev->hdmi, frame);
+               mutex_unlock(&cec_dev->hdmi->pclk_lock);
+       }
+       return ret;
 }
 
 static int cecsendframe(struct cec_framedata *frame)
 {
-       if (frame == NULL || !cec_dev || cec_dev->readframe == NULL)
-               return -1;
-       else
-               return cec_dev->sendframe(cec_dev->hdmi, frame);
+       int ret = -1;
+
+       if (frame && cec_dev && cec_dev->sendframe) {
+               mutex_lock(&cec_dev->hdmi->pclk_lock);
+               ret = cec_dev->sendframe(cec_dev->hdmi, frame);
+               mutex_unlock(&cec_dev->hdmi->pclk_lock);
+       }
+       return ret;
+}
+
+static void cecsetlogicaddr(int addr)
+{
+       if (cec_dev && cec_dev->setceclogicaddr) {
+               mutex_lock(&cec_dev->hdmi->pclk_lock);
+               cec_dev->setceclogicaddr(cec_dev->hdmi, addr);
+               mutex_unlock(&cec_dev->hdmi->pclk_lock);
+       }
 }
 
 static void cecworkfunc(struct work_struct *work)
@@ -42,14 +56,12 @@ static void cecworkfunc(struct work_struct *work)
                break;
        case EVENT_RX_FRAME:
                list_node = kmalloc(sizeof(*list_node), GFP_KERNEL);
-               if (list_node == NULL) {
-                       pr_err("HDMI CEC: list kmalloc fail! ");
+               if (!list_node)
                        return;
-               }
                cecreadframe(&list_node->cecframe);
                if (cec_dev->enable) {
                        mutex_lock(&cec_dev->cec_lock);
-                       list_add_tail(&(list_node->framelist),
+                       list_add_tail(&list_node->framelist,
                                      &cec_dev->ceclist);
                        sysfs_notify(&cec_dev->device.this_device->kobj,
                                     NULL, "stat");
@@ -72,6 +84,9 @@ void rockchip_hdmi_cec_submit_work(int event, int delay, void *data)
 
        CECDBG("%s event %04x delay %d\n", __func__, event, delay);
 
+       if (!cec_dev)
+               return;
+
        work = kmalloc(sizeof(*work), GFP_ATOMIC);
 
        if (work) {
@@ -119,7 +134,7 @@ static ssize_t cec_enable_store(struct device *dev,
 {
        int ret;
 
-       ret = kstrtoint(buf, 0, &(cec_dev->enable));
+       ret = kstrtoint(buf, 0, &cec_dev->enable);
        return count;
 }
 
@@ -135,7 +150,7 @@ static ssize_t cec_phy_store(struct device *dev,
 {
        int ret;
 
-       ret = kstrtoint(buf, 0, &(cec_dev->address_phy));
+       ret = kstrtoint(buf, 0, &cec_dev->address_phy);
        return count;
 }
 
@@ -151,7 +166,7 @@ static ssize_t cec_logic_store(struct device *dev,
 {
        int ret;
 
-       ret = kstrtoint(buf, 0, &(cec_dev->address_logic));
+       ret = kstrtoint(buf, 0, &cec_dev->address_logic);
        return count;
 }
 
@@ -172,9 +187,9 @@ static ssize_t  cec_state_show(struct device *dev,
 }
 
 static struct device_attribute cec_attrs[] = {
-       __ATTR(logic, 0666, cec_logic_show, cec_logic_store),
-       __ATTR(phy, 0666, cec_phy_show, cec_phy_store),
-       __ATTR(enable, 0666, cec_enable_show, cec_enable_store),
+       __ATTR(logic, S_IRUGO | S_IWUSR, cec_logic_show, cec_logic_store),
+       __ATTR(phy, S_IRUGO | S_IWUSR, cec_phy_show, cec_phy_store),
+       __ATTR(enable, S_IRUGO | S_IWUSR, cec_enable_show, cec_enable_store),
        __ATTR(stat, S_IRUGO, cec_state_show, NULL),
 };
 
@@ -190,9 +205,7 @@ static long cec_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case HDMI_IOCTL_CECSETLA:
                ret = copy_from_user(&cec_dev->address_logic,
                                     argp, sizeof(int));
-               if (cec_dev->setceclogicaddr)
-                       cec_dev->setceclogicaddr(cec_dev->hdmi,
-                                                cec_dev->address_logic);
+               cecsetlogicaddr(cec_dev->address_logic);
                break;
        case HDMI_IOCTL_CECSEND:
                ret = copy_from_user(&cecsendtemp, argp,
@@ -206,10 +219,10 @@ static long cec_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                ret = copy_from_user(&cec_dev->enable, argp, sizeof(int));
                break;
        case HDMI_IOCTL_CECPHY:
-               ret = copy_to_user(argp, &(cec_dev->address_phy), sizeof(int));
+               ret = copy_to_user(argp, &cec_dev->address_phy, sizeof(int));
                break;
        case HDMI_IOCTL_CECLOGIC:
-               ret = copy_to_user(argp, &(cec_dev->address_logic),
+               ret = copy_to_user(argp, &cec_dev->address_logic,
                                   sizeof(int));
                break;
        case HDMI_IOCTL_CECREAD:
@@ -227,7 +240,7 @@ static long cec_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case HDMI_IOCTL_CECCLEARLA:
                break;
        case HDMI_IOCTL_CECWAKESTATE:
-               ret = copy_to_user(argp, &(cec_dev->hdmi->sleep), sizeof(int));
+               ret = copy_to_user(argp, &cec_dev->hdmi->sleep, sizeof(int));
                break;
 
        default:
@@ -252,10 +265,9 @@ int rockchip_hdmi_cec_init(struct hdmi *hdmi,
        int ret, i;
 
        cec_dev = kmalloc(sizeof(*cec_dev), GFP_KERNEL);
-       if (!cec_dev) {
-               pr_err("HDMI CEC: kmalloc fail!");
+       if (!cec_dev)
                return -ENOMEM;
-       }
+
        memset(cec_dev, 0, sizeof(struct cec_device));
        mutex_init(&cec_dev->cec_lock);
        INIT_LIST_HEAD(&cec_dev->ceclist);
@@ -265,7 +277,7 @@ int rockchip_hdmi_cec_init(struct hdmi *hdmi,
        cec_dev->readframe = readframe;
        cec_dev->setceclogicaddr = setceclogicaddr;
        cec_dev->workqueue = create_singlethread_workqueue("hdmi-cec");
-       if (cec_dev->workqueue == NULL) {
+       if (!cec_dev->workqueue) {
                pr_err("HDMI CEC: create workqueue failed.\n");
                return -1;
        }