#include <linux/module.h>
#include <linux/kernel.h>
#include <asm/uaccess.h> //copy_to_use, copy_from_user
#include <linux/serial_core.h>
#include <asm/plat-s3c/regs-serial.h> //寄存器宏
#include <asm/io.h> //readl, readb, writel, writeb
#define iobase S3C24XX_VA_UART1
#define UART_ULCON1 iobase
#define UART_UCON1 iobase + 0x4
#define UART_UFCON1 iobase + 0x8
#define UART_UTRSTAT1 iobase + 0x10
#define UART_UTXH1 iobase + 0x20
#define UART_URXH1 iobase + 0x24
#define UART_UBRDIV1 iobase + 0x28
MODULE_DESCRIPTION("s3c2440 serial driver");
int sunsea_open(struct inode *inode, struct file *filp)
writel(26, UART_UBRDIV1);
ssize_t sunsea_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
char wbuf[BUFSIZE] = {0};
copy_from_user(wbuf, buf, count);
state = readl(UART_UTRSTAT1);
writeb(wbuf[i], UART_UTXH1);
ssize_t sunsea_read(struct file *filp, char __user *buf, size_t count, loff_t *f_ops)
state = readl(UART_UTRSTAT1);
rbuf[0] = readb(UART_URXH1);
copy_to_user(buf, rbuf, 1);
set_current_state(TASK_INTERRUPTIBLE);
int sunsea_release(struct inode *inode, struct file *filp)
struct file_operations ttyS0_fops =
.release = sunsea_release,
printk("s3c2440 serial module loaded!/n");
rc = register_chrdev(ttyS0_MAJOR, "ttyS0", &ttyS0_fops);
printk("Error: register ttyS0 device error!/n") ;
unregister_chrdev(ttyS0_MAJOR, "ttyS0");
printk("s3c2440 serial module exit!/n");
module_init(sunsea_init);
module_exit(sunsea_exit);