rk: ddr_freq: move video_state to plat-rk and better support release
author黄涛 <huangtao@rock-chips.com>
Tue, 16 Oct 2012 03:23:50 +0000 (11:23 +0800)
committer黄涛 <huangtao@rock-chips.com>
Tue, 16 Oct 2012 03:24:06 +0000 (11:24 +0800)
arch/arm/mach-rk2928/Makefile
arch/arm/mach-rk2928/video_state.c [deleted file]
arch/arm/mach-rk30/Makefile
arch/arm/mach-rk30/video_state.c [deleted file]
arch/arm/plat-rk/Makefile
arch/arm/plat-rk/video_state.c [new file with mode: 0644]

index d20a4987ea83330b5f60050efdf85b640c64ed15..33c3f0c03560e16c87906cd68c0108eed0eaaeb9 100755 (executable)
@@ -8,7 +8,7 @@ obj-y += iomux.o
 obj-y += ../plat-rk/clock.o
 obj-y += clock_data.o
 obj-y += ddr.o
-obj-$(CONFIG_DDR_FREQ) += ddr_freq.o video_state.o
+obj-$(CONFIG_DDR_FREQ) += ddr_freq.o
 obj-$(CONFIG_CPU_FREQ) += cpufreq.o
 obj-$(CONFIG_DVFS) += dvfs.o
 obj-$(CONFIG_PM) += pm.o
diff --git a/arch/arm/mach-rk2928/video_state.c b/arch/arm/mach-rk2928/video_state.c
deleted file mode 100755 (executable)
index a792aea..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/* arch/arm/mach-rk30/video_state.c
- *
- * Copyright (C) 2012 ROCKCHIP, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * 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/poll.h>
-#include <linux/slab.h>
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/spinlock.h>
-#include <linux/fs.h>
-#include <linux/miscdevice.h>
-#include <linux/sched.h>
-#include <mach/ddr.h>
-#include <linux/cpu.h>
-#include <linux/clk.h>
-
-
-#ifdef CONFIG_DDR_SDRAM_FREQ
-#define DDR_FREQ          (CONFIG_DDR_SDRAM_FREQ)
-#else
-#define DDR_FREQ 400
-#endif
-
-
-int rk_video_state=0;
-static struct clk * ddr_clk;
-
-
-#define VIDEO_STATE_NAME               "video_state"
-#define BUFFER_SIZE                    16
-
-MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>");
-MODULE_DESCRIPTION("Key chord input driver");
-MODULE_SUPPORTED_DEVICE("video_state");
-MODULE_LICENSE("GPL");
-
-/*
- * video_state_read is used to read video_state events from the driver
- */
-static ssize_t video_state_read(struct file *file, char __user *buffer,
-               size_t count, loff_t *ppos)
-{
-       return count;
-}
-
-/*
- * video_state_write is used to configure the driver
- */
-static ssize_t video_state_write(struct file *file, const char __user *buffer,
-               size_t count, loff_t *ppos)
-{
-       char *parameters= 0;
-       int vedeo_state;
-       int set_rate=0;
-       int set_rate_old=0;
-
-       if(DDR_FREQ<=333)       
-               return count;
-       //if (count < sizeof(struct input_keychord))
-       //      return -EINVAL;
-       parameters = kzalloc(count, GFP_KERNEL);
-       if (!parameters)
-               return -ENOMEM;
-
-       /* read list of keychords from userspace */
-       if (copy_from_user(parameters, buffer, count)) {
-               kfree(parameters);
-               return -EFAULT;
-       }
-       sscanf(parameters, "%d", &vedeo_state);
-
-       //printk("video_state %d\n",vedeo_state);
-       switch(vedeo_state)
-       {
-               case 0:
-                       rk_video_state=0;
-                       set_rate=DDR_FREQ;
-               break;
-               case 1:
-                       rk_video_state=1;
-                       set_rate=330;
-               break;
-               default:
-                       rk_video_state=0;
-                       return -EFAULT; 
-       }
-       set_rate_old=clk_get_rate(ddr_clk);
-       set_rate=clk_round_rate(ddr_clk,set_rate*1000*1000);
-       if(set_rate_old!=set_rate)
-       {
-               clk_set_rate(ddr_clk,set_rate);
-               //printk("ddr rate=%d\n",set_rate/(1000*1000));
-       }       
-       kfree(parameters);
-       return count;
-}
-
-static unsigned int video_state_poll(struct file *file, poll_table *wait)
-{
-       return 0;
-}
-
-static int video_state_open(struct inode *inode, struct file *file)
-{
-
-
-       return 0;
-}
-
-static int video_state_release(struct inode *inode, struct file *file)
-{
-       return 0;
-}
-
-static const struct file_operations video_state_fops = {
-       .owner          = THIS_MODULE,
-       .open           = video_state_open,
-       .release        = video_state_release,
-       .read           = video_state_read,
-       .write          = video_state_write,
-       .poll           = video_state_poll,
-};
-
-static struct miscdevice video_state = {
-       .fops           = &video_state_fops,
-       .name           = VIDEO_STATE_NAME,
-       .minor          = MISC_DYNAMIC_MINOR,
-};
-
-
-static int __init video_state_init(void)
-{
-       ddr_clk=clk_get(NULL,"ddr");
-       if(IS_ERR(ddr_clk))
-               return -1;
-
-       
-       return misc_register(&video_state);
-}
-
-static void __exit video_state_exit(void)
-{
-       misc_deregister(&video_state);
-}
-
-module_init(video_state_init);
-module_exit(video_state_exit);
-
-
-
index 71a2aa7ef01b451f1789b38b422cc3115e6ba270..9a6c0b15416cad7075e28e8b688ed3801ad939b3 100755 (executable)
@@ -23,7 +23,7 @@ CFLAGS_pm.o += -mthumb
 obj-$(CONFIG_CPU_IDLE) += cpuidle.o
 obj-$(CONFIG_CPU_FREQ) += cpufreq.o
 obj-$(CONFIG_DVFS) += dvfs.o
-obj-$(CONFIG_DDR_FREQ) += ddr_freq.o video_state.o
+obj-$(CONFIG_DDR_FREQ) += ddr_freq.o
 obj-$(CONFIG_RK30_I2C_INSRAM) += i2c_sram.o
 CFLAGS_i2c_sram.o += -mthumb
 
diff --git a/arch/arm/mach-rk30/video_state.c b/arch/arm/mach-rk30/video_state.c
deleted file mode 100755 (executable)
index 9e0589b..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/* arch/arm/mach-rk30/video_state.c
- *
- * Copyright (C) 2012 ROCKCHIP, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * 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/poll.h>
-#include <linux/slab.h>
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/spinlock.h>
-#include <linux/fs.h>
-#include <linux/miscdevice.h>
-#include <linux/sched.h>
-#include <mach/ddr.h>
-#include <linux/cpu.h>
-#include <linux/clk.h>
-
-
-#ifdef CONFIG_DDR_SDRAM_FREQ
-#define DDR_FREQ          (CONFIG_DDR_SDRAM_FREQ)
-#else
-#define DDR_FREQ 400
-#endif
-
-
-int rk_video_state=0;
-static struct clk * ddr_clk;
-
-
-#define VIDEO_STATE_NAME               "video_state"
-#define BUFFER_SIZE                    16
-
-MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>");
-MODULE_DESCRIPTION("Key chord input driver");
-MODULE_SUPPORTED_DEVICE("video_state");
-MODULE_LICENSE("GPL");
-
-/*
- * video_state_read is used to read video_state events from the driver
- */
-static ssize_t video_state_read(struct file *file, char __user *buffer,
-               size_t count, loff_t *ppos)
-{
-       return count;
-}
-
-/*
- * video_state_write is used to configure the driver
- */
-static ssize_t video_state_write(struct file *file, const char __user *buffer,
-               size_t count, loff_t *ppos)
-{
-       char *parameters= 0;
-       int vedeo_state;
-       int set_rate=0;
-       int set_rate_old=0;
-
-       if(DDR_FREQ<=333)       
-               return count;
-       //if (count < sizeof(struct input_keychord))
-       //      return -EINVAL;
-       parameters = kzalloc(count, GFP_KERNEL);
-       if (!parameters)
-               return -ENOMEM;
-
-       /* read list of keychords from userspace */
-       if (copy_from_user(parameters, buffer, count)) {
-               kfree(parameters);
-               return -EFAULT;
-       }
-       sscanf(parameters, "%d", &vedeo_state);
-
-       //printk("video_state %d\n",vedeo_state);
-       switch(vedeo_state)
-       {
-               case 0:
-                       rk_video_state=0;
-                       set_rate=DDR_FREQ;
-               break;
-               case 1:
-                       rk_video_state=1;
-                       set_rate=300;
-               break;
-               default:
-                       rk_video_state=0;
-                       return -EFAULT; 
-       }
-       set_rate_old=clk_get_rate(ddr_clk);
-       set_rate=clk_round_rate(ddr_clk,set_rate*1000*1000);
-       if(set_rate_old!=set_rate)
-       {
-               clk_set_rate(ddr_clk,set_rate);
-               //printk("ddr rate=%d\n",set_rate/(1000*1000));
-       }       
-       kfree(parameters);
-       return count;
-}
-
-static unsigned int video_state_poll(struct file *file, poll_table *wait)
-{
-       return 0;
-}
-
-static int video_state_open(struct inode *inode, struct file *file)
-{
-
-
-       return 0;
-}
-
-static int video_state_release(struct inode *inode, struct file *file)
-{
-       return 0;
-}
-
-static const struct file_operations video_state_fops = {
-       .owner          = THIS_MODULE,
-       .open           = video_state_open,
-       .release        = video_state_release,
-       .read           = video_state_read,
-       .write          = video_state_write,
-       .poll           = video_state_poll,
-};
-
-static struct miscdevice video_state = {
-       .fops           = &video_state_fops,
-       .name           = VIDEO_STATE_NAME,
-       .minor          = MISC_DYNAMIC_MINOR,
-};
-
-
-static int __init video_state_init(void)
-{
-       ddr_clk=clk_get(NULL,"ddr");
-       if(IS_ERR(ddr_clk))
-               return -1;
-
-       
-       return misc_register(&video_state);
-}
-
-static void __exit video_state_exit(void)
-{
-       misc_deregister(&video_state);
-}
-
-module_init(video_state_init);
-module_exit(video_state_exit);
-
-
-
index 1c295798bdcdb485350f6240093f234a3b16a263..630896ac33fb57503cd60130ad2a464ea3adec52 100644 (file)
@@ -12,3 +12,4 @@ obj-y += config.o
 obj-y += sram.o
 CFLAGS_sram.o += -mthumb
 obj-$(CONFIG_DDR_TEST) += memtester.o
+obj-$(CONFIG_DDR_FREQ) += video_state.o
diff --git a/arch/arm/plat-rk/video_state.c b/arch/arm/plat-rk/video_state.c
new file mode 100644 (file)
index 0000000..8b165e6
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2012 ROCKCHIP, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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/module.h>
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+#include <linux/clk.h>
+#include <linux/uaccess.h>
+#include <mach/ddr.h>
+
+#ifdef CONFIG_ARCH_RK2928
+#define VIDEO_DDR_RATE (330*1000*1000)
+#else
+#define VIDEO_DDR_RATE (300*1000*1000)
+#endif
+
+static struct clk *ddr_clk;
+static unsigned long ddr_rate;
+static char video_state = '0';
+
+static int video_state_open(struct inode *inode, struct file *file)
+{
+       ddr_rate = clk_get_rate(ddr_clk);
+       return 0;
+}
+
+static int video_state_release(struct inode *inode, struct file *file)
+{
+       clk_set_rate(ddr_clk, ddr_rate);
+       return 0;
+}
+
+static ssize_t video_state_read(struct file *file, char __user *buffer,
+                               size_t count, loff_t *ppos)
+{
+       if (copy_to_user(buffer, &video_state, 1))
+               return -EFAULT;
+       return 1;
+}
+
+static ssize_t video_state_write(struct file *file, const char __user *buffer,
+                                size_t count, loff_t *ppos)
+{
+       unsigned long rate = 0;
+
+       if (ddr_rate <= 333000000)
+               return count;
+       if (count < 1)
+               return count;
+       if (copy_from_user(&video_state, buffer, 1)) {
+               return -EFAULT;
+       }
+
+       switch (video_state) {
+       case '0':
+               rate = ddr_rate;
+               break;
+       case '1':
+               rate = VIDEO_DDR_RATE;
+               break;
+       default:
+               return -EINVAL;
+       }
+       clk_set_rate(ddr_clk, rate);
+       return count;
+}
+
+static const struct file_operations video_state_fops = {
+       .owner  = THIS_MODULE,
+       .open   = video_state_open,
+       .release= video_state_release,
+       .read   = video_state_read,
+       .write  = video_state_write,
+};
+
+static struct miscdevice video_state_dev = {
+       .fops   = &video_state_fops,
+       .name   = "video_state",
+       .minor  = MISC_DYNAMIC_MINOR,
+};
+
+static int __init video_state_init(void)
+{
+       ddr_clk = clk_get(NULL, "ddr");
+       if (IS_ERR(ddr_clk))
+               return PTR_ERR(ddr_clk);
+
+       return misc_register(&video_state_dev);
+}
+
+static void __exit video_state_exit(void)
+{
+       misc_deregister(&video_state_dev);
+       clk_put(ddr_clk);
+}
+
+module_init(video_state_init);
+module_exit(video_state_exit);
+MODULE_LICENSE("GPL");