1 /* Copyright (c) 2009, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/time.h>
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
23 #include <linux/spinlock.h>
24 #include <linux/hrtimer.h>
25 #include <linux/clk.h>
26 #include <mach/hardware.h>
27 #include <linux/io.h>
28 #include <linux/debugfs.h>
29
30 #include <asm/system.h>
31 #include <asm/mach-types.h>
32 #include <linux/semaphore.h>
33 #include <linux/uaccess.h>
34
35 #include "mdp.h"
36 #include "msm_fb.h"
37 #include "mdp4.h"
38
39
40 #define MDP4_DEBUG_BUF 128
41
42
43 static char mdp4_debug_buf[MDP4_DEBUG_BUF];
44 static ulong mdp4_debug_offset;
45 static ulong mdp4_base_addr;
46
mdp4_offset_set(void * data,u64 val)47 static int mdp4_offset_set(void *data, u64 val)
48 {
49 mdp4_debug_offset = (int)val;
50 return 0;
51 }
52
mdp4_offset_get(void * data,u64 * val)53 static int mdp4_offset_get(void *data, u64 *val)
54 {
55 *val = (u64)mdp4_debug_offset;
56 return 0;
57 }
58
59 DEFINE_SIMPLE_ATTRIBUTE(
60 mdp4_offset_fops,
61 mdp4_offset_get,
62 mdp4_offset_set,
63 "%llx\n");
64
65
mdp4_debugfs_release(struct inode * inode,struct file * file)66 static int mdp4_debugfs_release(struct inode *inode, struct file *file)
67 {
68 return 0;
69 }
70
mdp4_debugfs_write(struct file * file,const char __user * buff,size_t count,loff_t * ppos)71 static ssize_t mdp4_debugfs_write(
72 struct file *file,
73 const char __user *buff,
74 size_t count,
75 loff_t *ppos)
76 {
77 int cnt;
78 unsigned int data;
79
80 printk(KERN_INFO "%s: offset=%d count=%d *ppos=%d\n",
81 __func__, (int)mdp4_debug_offset, (int)count, (int)*ppos);
82
83 if (count > sizeof(mdp4_debug_buf))
84 return -EFAULT;
85
86 if (copy_from_user(mdp4_debug_buf, buff, count))
87 return -EFAULT;
88
89
90 mdp4_debug_buf[count] = 0; /* end of string */
91
92 cnt = sscanf(mdp4_debug_buf, "%x", &data);
93 if (cnt < 1) {
94 printk(KERN_ERR "%s: sscanf failed cnt=%d" , __func__, cnt);
95 return -EINVAL;
96 }
97
98 writel(&data, mdp4_base_addr + mdp4_debug_offset);
99
100 return 0;
101 }
102
mdp4_debugfs_read(struct file * file,char __user * buff,size_t count,loff_t * ppos)103 static ssize_t mdp4_debugfs_read(
104 struct file *file,
105 char __user *buff,
106 size_t count,
107 loff_t *ppos)
108 {
109 int len = 0;
110 unsigned int data;
111
112 printk(KERN_INFO "%s: offset=%d count=%d *ppos=%d\n",
113 __func__, (int)mdp4_debug_offset, (int)count, (int)*ppos);
114
115 if (*ppos)
116 return 0; /* the end */
117
118 data = readl(mdp4_base_addr + mdp4_debug_offset);
119
120 len = snprintf(mdp4_debug_buf, 4, "%x\n", data);
121
122 if (len > 0) {
123 if (len > count)
124 len = count;
125 if (copy_to_user(buff, mdp4_debug_buf, len))
126 return -EFAULT;
127 }
128
129 printk(KERN_INFO "%s: len=%d\n", __func__, len);
130
131 if (len < 0)
132 return 0;
133
134 *ppos += len; /* increase offset */
135
136 return len;
137 }
138
139 static const struct file_operations mdp4_debugfs_fops = {
140 .open = nonseekable_open,
141 .release = mdp4_debugfs_release,
142 .read = mdp4_debugfs_read,
143 .write = mdp4_debugfs_write,
144 .llseek = no_llseek,
145 };
146
mdp4_debugfs_init(void)147 int mdp4_debugfs_init(void)
148 {
149 struct dentry *dent = debugfs_create_dir("mdp4", NULL);
150
151 if (IS_ERR(dent)) {
152 printk(KERN_ERR "%s(%d): debugfs_create_dir fail, error %ld\n",
153 __FILE__, __LINE__, PTR_ERR(dent));
154 return -1;
155 }
156
157 if (debugfs_create_file("offset", 0644, dent, 0, &mdp4_offset_fops)
158 == NULL) {
159 printk(KERN_ERR "%s(%d): debugfs_create_file: offset fail\n",
160 __FILE__, __LINE__);
161 return -1;
162 }
163
164 if (debugfs_create_file("regs", 0644, dent, 0, &mdp4_debugfs_fops)
165 == NULL) {
166 printk(KERN_ERR "%s(%d): debugfs_create_file: regs fail\n",
167 __FILE__, __LINE__);
168 return -1;
169 }
170
171 mdp4_debug_offset = 0;
172 mdp4_base_addr = (ulong) msm_mdp_base; /* defined at msm_fb_def.h */
173
174 return 0;
175 }
176