mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-11 13:27:06 +09:00
rk: ddr_freq: move video_state to plat-rk and better support release
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
110
arch/arm/plat-rk/video_state.c
Normal file
110
arch/arm/plat-rk/video_state.c
Normal file
@@ -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");
|
||||
Reference in New Issue
Block a user