点击(此处)折叠或打开
-
KBUILD_EXTRA_SYMBOLS=/home/fang/ti-sdk-am335x-evm-06.00.00.00/board-support/linux-3.2.0-psp04.06.00.11/am335x_evm/Module.symvers
-
ifneq ($(KERNELRELEASE),)
-
obj-m := my_tty.o
-
else
-
KERNELDIR ?= /home/fang/ti-sdk-am335x-evm-06.00.00.00/board-support/linux-3.2.0-psp04.06.00.11/am335x_evm
-
PWD := $(shell pwd)
-
default:
-
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
-
cp *.ko /home/fang/ti-sdk-am335x-evm-06.00.00.00/filesystem/rootfs/test_modules
-
clean:
-
@rm -rf *.o *.mod.c *.mod.o *.ko *.order *.symvers .*.cmd .tmp_versions
- endif
my_tty.c
点击(此处)折叠或打开
-
#include <linux/module.h>
-
#include <linux/types.h>
-
#include <linux/sched.h>
-
#include <linux/tty.h>
-
#include <linux/tty_flip.h>
-
#include <linux/kernel.h>
-
#include <linux/string.h>
-
#include <linux/errno.h>
-
#include <linux/kd.h>
-
#include <linux/slab.h>
-
#include <linux/major.h>
-
#include <linux/mm.h>
-
#include <linux/console.h>
-
#include <linux/init.h>
-
#include <linux/mutex.h>
-
#include <linux/vt_kern.h>
-
#include <linux/selection.h>
-
#include <linux/tiocl.h>
-
#include <linux/kbd_kern.h>
-
#include <linux/consolemap.h>
-
#include <linux/timer.h>
-
#include <linux/interrupt.h>
-
#include <linux/workqueue.h>
-
#include <linux/pm.h>
-
#include <linux/font.h>
-
#include <linux/bitops.h>
-
#include <linux/notifier.h>
-
#include <linux/device.h>
-
#include <linux/io.h>
-
#include <asm/system.h>
-
#include <linux/uaccess.h>
-
#include <linux/kdb.h>
-
#include <linux/ctype.h>
-
-
static int con_open(struct tty_struct *, struct file *);
-
static void vc_init(struct vc_data *vc, unsigned int rows,
-
unsigned int cols, int do_clear);
-
static void gotoxy(struct vc_data *vc, int new_x, int new_y);
-
static void save_cur(struct vc_data *vc);
-
static void reset_terminal(struct vc_data *vc, int do_clear);
-
static void con_flush_chars(struct tty_struct *tty);
-
static int set_vesa_blanking(char __user *p);
-
static void set_cursor(struct vc_data *vc);
-
static void hide_cursor(struct vc_data *vc);
-
static void console_callback(struct work_struct *ignored);
-
static void blank_screen_t(unsigned long dummy);
-
static void set_palette(struct vc_data *vc);
-
-
-
struct tty_driver *console_driver;
-
-
/*
-
* /dev/ttyN handling
-
*/
-
-
static int con_write(struct tty_struct *tty, const unsigned char *buf, int count)
-
{
-
int retval;
-
printk(" %s %s line:%d\n", __func__,__FILE__,__LINE__);
-
return count;
-
}
-
-
static int con_put_char(struct tty_struct *tty, unsigned char ch)
-
{
-
printk(" %s %s line:%d\n", __func__,__FILE__,__LINE__);
-
return 0;
-
}
-
-
static int con_chars_in_buffer(struct tty_struct *tty)
-
{
-
printk(" %s %s line:%d\n", __func__,__FILE__,__LINE__);
-
return 0; /* we're not buffering */
-
}
-
-
/*
-
* con_throttle and con_unthrottle are only used for
-
* paste_selection(), which has to stuff in a large number of
-
* characters...
-
*/
-
static void con_throttle(struct tty_struct *tty)
-
{
-
printk(" %s %s line:%d\n", __func__,__FILE__,__LINE__);
-
}
-
-
static void con_unthrottle(struct tty_struct *tty)
-
{
-
printk(" %s %s line:%d\n", __func__,__FILE__,__LINE__);
-
}
-
-
/*
-
* Allocate the console screen memory.
-
*/
-
static int con_open(struct tty_struct *tty, struct file *filp)
-
{
-
unsigned int currcons = tty->index;
-
int ret = 0;
-
printk(" %s %s line:%d\n", __func__,__FILE__,__LINE__);
-
console_lock();
-
console_unlock();
-
return ret;
-
}
-
-
static void con_close(struct tty_struct *tty, struct file *filp)
-
{
-
printk(" %s %s line:%d\n", __func__,__FILE__,__LINE__);
-
/* Nothing to do - we defer to shutdown */
-
}
-
-
static void con_shutdown(struct tty_struct *tty)
-
{
-
struct vc_data *vc = tty->driver_data;
-
//BUG_ON(vc == NULL);
-
console_lock();
-
//vc->port.tty = NULL;
-
console_unlock();
-
tty_shutdown(tty);
-
}
-
static int con_write_room(struct tty_struct *tty)
-
{
-
printk(" %s %s line:%d\n", __func__,__FILE__,__LINE__);
-
if (tty->stopped)
-
return 0;
-
return 32768; /* No limit, really; we're not buffering */
-
}
-
static void con_stop(struct tty_struct *tty)
-
{
-
int console_num;
-
printk(" %s %s line:%d\n", __func__,__FILE__,__LINE__);
-
-
}
-
/*
-
* Turn the Scroll-Lock LED off when the console is started
-
*/
-
static void con_start(struct tty_struct *tty)
-
{
-
int console_num;
-
printk(" %s %s line:%d\n", __func__,__FILE__,__LINE__);
-
}
-
-
static int vt_resize(struct tty_struct *tty, struct winsize *ws)
-
{
-
struct vc_data *vc = tty->driver_data;
-
int ret;
-
-
console_lock();
-
printk(" %s %s line:%d\n", __func__,__FILE__,__LINE__);
-
console_unlock();
-
return 0;
-
}
-
static void con_flush_chars(struct tty_struct *tty)
-
{
-
printk(" %s %s line:%d\n", __func__,__FILE__,__LINE__);
-
}
-
-
-
-
-
/*
-
* We handle the console-specific ioctl's here. We allow the
-
* capability to modify any console, not just the fg_console.
-
*/
-
int vt_ioctl(struct tty_struct *tty,
-
unsigned int cmd, unsigned long arg)
-
{
-
return 0;
-
}
-
-
static const struct tty_operations con_ops = {
-
.open = con_open,
-
.close = con_close,
-
.write = con_write,
-
.write_room = con_write_room,
-
.put_char = con_put_char,
-
.flush_chars = con_flush_chars,
-
.chars_in_buffer = con_chars_in_buffer,
-
.ioctl = vt_ioctl,
-
#ifdef CONFIG_COMPAT
-
.compat_ioctl = vt_compat_ioctl,
-
#endif
-
.stop = con_stop,
-
.start = con_start,
-
.throttle = con_throttle,
-
.unthrottle = con_unthrottle,
-
.resize = vt_resize,
-
.shutdown = con_shutdown
-
};
-
-
static struct cdev vc0_cdev;
-
int default_utf8 = true;
-
int __init mytty_init(const struct file_operations *console_fops)
-
{
-
console_driver = alloc_tty_driver(MAX_NR_CONSOLES);
-
if (!console_driver)
-
panic("Couldn't allocate console driver\n");
-
console_driver->owner = THIS_MODULE;
-
console_driver->name = "tty_my";
-
console_driver->name_base = 1;
-
console_driver->major = TTY_MAJOR;
-
console_driver->minor_start = 128;
-
console_driver->type = TTY_DRIVER_TYPE_CONSOLE;
-
console_driver->init_termios = tty_std_termios;
-
if (default_utf8)
-
console_driver->init_termios.c_iflag |= IUTF8;
-
console_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS;
-
tty_set_operations(console_driver, &con_ops);
-
printk("console_driver ->num:%08x %s %s line:%d\n", console_driver->num,__func__,__FILE__,__LINE__);
-
if (tty_register_driver(console_driver))
-
panic("Couldn't register console driver\n");
-
-
return 0;
-
}
-
static void mytty_exit(void)
-
{
-
int i = 0;
-
tty_unregister_driver(console_driver);
-
for (i=0; i <console_driver->num; i++)
-
tty_unregister_device(console_driver, i);
-
}
-
-
module_init(mytty_init);
-
module_exit(mytty_exit);
-
- MODULE_LICENSE("GPL");
点击(此处)折叠或打开
-
insmod my_tty.ko
-
echo a>/dev/tty_my1
-
[ 165.343902] con_open /home/fang/ti-sdk-am335x-evm-06.00.00.00/board-support/linux-modules/3.2.0/ttydriver/my_tty.c line:99
-
[ 165.355804] con_write_room /home/fang/ti-sdk-am335x-evm-06.00.00.00/board-support/linux-modules/3.2.0/ttydriver/my_tty.c line:122
-
[ 165.368194] con_write /home/fang/ti-sdk-am335x-evm-06.00.00.00/board-support/linux-modules/3.2.0/ttydriver/my_tty.c line:61
-
[ 165.380035] con_write_room /home/fang/ti-sdk-am335x-evm-06.00.00.00/board-support/linux-modules/3.2.0/ttydriver/my_tty.c line:122
-
[ 165.392395] con_write /home/fang/ti-sdk-am335x-evm-06.00.00.00/board-support/linux-modules/3.2.0/ttydriver/my_tty.c line:61
-
[ 165.404235] con_flush_chars /home/fang/ti-sdk-am335x-evm-06.00.00.00/board-support/linux-modules/3.2.0/ttydriver/my_tty.c line:154
- [ 165.416748] con_close /home/fang/ti-sdk-am335x-evm-06.00.00.00/board-support/linux-modules/3.2.0/ttydriver/my_tty.c line:107