2 * arch/arm/mach-omap2/debobs.c
6 * Copyright (C) 2008 Nokia Corporation
8 * Written by Peter De Schrijver <peter.de-schrijver@nokia.com>
10 * This file is subject to the terms and conditions of the GNU General
11 * Public License. See the file "COPYING" in the main directory of this
12 * archive for more details.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/debugfs.h>
28 #include <linux/uaccess.h>
29 #include <linux/module.h>
30 #include <linux/gpio.h>
32 #include <plat/control.h>
34 #include <plat/board.h>
36 #define ETK_GPIO_BEGIN 12
37 #define ETK_GPIO(i) (ETK_GPIO_BEGIN + i)
38 #define NUM_OF_DEBOBS_PADS 18
40 static int debobs_initialized
;
42 enum debobs_pad_mode
{
49 static char *debobs_pad_mode_names
[] = {
62 enum debobs_pad_mode mode
;
64 struct obs wakeup_obs
;
67 static struct debobs_pad debobs_pads
[NUM_OF_DEBOBS_PADS
];
69 static int debobs_mode_open(struct inode
*inode
, struct file
*file
)
71 file
->private_data
= inode
->i_private
;
76 static ssize_t
debobs_mode_read(struct file
*file
, char __user
*user_buf
,
77 size_t count
, loff_t
*ppos
)
81 int pad_number
= (int)file
->private_data
;
82 struct debobs_pad
*e
= &debobs_pads
[pad_number
];
84 size
= snprintf(buffer
, sizeof(buffer
), "%s\n",
85 debobs_pad_mode_names
[e
->mode
]);
86 return simple_read_from_buffer(user_buf
, count
, ppos
, buffer
, size
);
89 static ssize_t
debobs_mode_write(struct file
*file
, const char __user
*user_buf
,
90 size_t count
, loff_t
*ppos
)
93 int buf_size
, i
, pad_number
;
94 u16 muxmode
= OMAP34XX_MUX_MODE7
;
96 memset(buffer
, 0, sizeof(buffer
));
97 buf_size
= min(count
, (sizeof(buffer
)-1));
99 if (copy_from_user(buffer
, user_buf
, buf_size
))
102 pad_number
= (int)file
->private_data
;
104 for (i
= 0; i
< NO_MODE
; i
++) {
105 if (!strnicmp(debobs_pad_mode_names
[i
],
107 strlen(debobs_pad_mode_names
[i
]))) {
110 muxmode
= OMAP34XX_MUX_MODE0
;
113 muxmode
= OMAP34XX_MUX_MODE4
;
116 muxmode
= OMAP34XX_MUX_MODE7
;
119 omap_ctrl_writew(muxmode
,
120 OMAP343X_PADCONF_ETK(pad_number
));
121 debobs_pads
[pad_number
].mode
= i
;
130 static const struct file_operations debobs_mode_fops
= {
131 .open
= debobs_mode_open
,
132 .read
= debobs_mode_read
,
133 .write
= debobs_mode_write
,
136 static int debobs_get(void *data
, u64
*val
)
138 struct obs
*o
= data
;
145 static int debobs_set(void *data
, u64 val
)
147 struct obs
*o
= data
;
149 val
&= BIT(o
->mask
) - 1;
151 omap_ctrl_writeb(val
, o
->offset
);
157 DEFINE_SIMPLE_ATTRIBUTE(debobs_fops
, debobs_get
, debobs_set
, "%llu\n");
159 static inline int __init
_new_debobs_pad(struct debobs_pad
*pad
, char *name
,
160 int number
, struct dentry
*root
)
165 d
= debugfs_create_dir(name
, root
);
169 omap_ctrl_writew(OMAP34XX_MUX_MODE4
, OMAP343X_PADCONF_ETK(number
));
170 gpio_direction_input(ETK_GPIO(number
));
171 gpio_export(ETK_GPIO(number
), 1);
172 (void) debugfs_create_file("mode", S_IRUGO
| S_IWUGO
, d
,
173 (void *)number
, &debobs_mode_fops
);
176 o
->offset
= OMAP343X_CONTROL_DEBOBS(number
);
177 o
->value
= omap_ctrl_readw(o
->offset
);
179 (void) debugfs_create_file("coreobs", S_IRUGO
| S_IWUGO
, d
, o
,
182 o
= &pad
->wakeup_obs
;
183 o
->offset
= OMAP343X_CONTROL_WKUP_DEBOBSMUX(number
);
184 o
->value
= omap_ctrl_readb(o
->offset
);
186 (void) debugfs_create_file("wakeupobs", S_IRUGO
| S_IWUGO
, d
, o
,
192 /* Public functions */
194 void debug_gpio_set(unsigned gpio
, int value
)
196 if (!debobs_initialized
)
199 WARN_ON(gpio
>= NUM_OF_DEBOBS_PADS
);
200 if (gpio
< NUM_OF_DEBOBS_PADS
)
201 __gpio_set_value(ETK_GPIO(gpio
), value
);
204 int debug_gpio_get(unsigned gpio
)
206 if (!debobs_initialized
)
209 WARN_ON(gpio
>= NUM_OF_DEBOBS_PADS
);
210 if (gpio
< NUM_OF_DEBOBS_PADS
)
211 return __gpio_get_value(ETK_GPIO(gpio
));
216 int __init
init_debobs(void)
218 struct dentry
*debobs_root
;
222 debobs_root
= debugfs_create_dir("debobs", NULL
);
223 if (IS_ERR(debobs_root
))
224 return PTR_ERR(debobs_root
);
226 for (i
= 0; i
< NUM_OF_DEBOBS_PADS
; i
++) {
227 snprintf(name
, sizeof(name
), "hw_dbg%d", i
);
228 if (!gpio_request(ETK_GPIO(i
), name
)) {
229 err
= _new_debobs_pad(&debobs_pads
[i
], name
, i
,
232 gpio_free(ETK_GPIO(i
));
235 debobs_initialized
= 1;
240 late_initcall_sync(init_debobs
);