《TQ2440移植linux3.0笔记》
1、基础配置
- 解包linux-3.0:
tar xvf linux-3.0
- 复制内核自带的mini2440的配置文件
cp arch/arm/configs/mini2440_defconfig .config
- 向内核打包,使系统能够支持yaffs文件系统
- 图形化配置内核:
make menuconfig
指定默认命令行参数:
console=ttySAC0 root=/dev/nfs nfsroot=192.168.0.252:/yaffs2 ip=192.168.0.250:192.168.0.252:192.168.0.250:255.255.255.0
192.168.0.252是PC的ip地址
192.168.0.250是开发板的ip地址
255.255.255.0是掩码
/yaffs是我的文件系统,因为本实验是挂载的网络文件系统yaffs2
~~
到此,图形化配置完成,下面开始修改源码。
2、Makefile和机器码修改
- 修改顶层Makefile
- 修改机器码和u-boot相匹配,TQ2440 u-boot的机器码是168
vim arch/arm/tools/mach-types
3、添加dm9000网卡支持
设置DM9000的一些参数,目的是为了能够通过网络挂载文件系统
~
gedit arch/arm/mach-s3c2440/mach-smdk2440.c
添加头文件:
#include <mach/regs-mem.h>
#include <linux/dm9000.h>
添加结构:
static struct resource s3c_dm9k_resource[] = {
[0] = {
.start = S3C2410_CS4,
.end = S3C2410_CS4 + 3,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = S3C2410_CS4 + 4,
.end = S3C2410_CS4 + 4 + 3,
.flags = IORESOURCE_MEM,
},
[2] = {
.start = IRQ_EINT7,
.end = IRQ_EINT7,
.flags = IORESOURCE_IRQ | IRQF_TRIGGER_RISING,
}
};
static struct dm9000_plat_data s3c_dm9k_platdata = {
.flags = DM9000_PLATF_16BITONLY,
};
struct platform_device s3c_device_dm9000 = {
.name = "dm9000",
.id = 0,
.num_resources = ARRAY_SIZE(s3c_dm9k_resource),
.resource = s3c_dm9k_resource,
.dev = {
.platform_data = &s3c_dm9k_platdata,
}
};
结果如下:
//------------------- 下面这是初始化网络相关的,不然挂载会出错 ------------------------//
bwscon = *(volatile unsigned int *)S3C2410_BWSCON;
*((volatile unsigned int *)S3C2410_BWSCON) = (bwscon & ~(3<<16)) | \
S3C2410_BWSCON_DW4_16 | \
S3C2410_BWSCON_WS4 | \
S3C2410_BWSCON_ST4;
*((volatile unsigned int *)S3C2410_BANKCON4) = 0X1F7C;
到此,本文件修改完成。
3、NAND支持并分区
gedit arch/arm/plat-s3c24xx/commod-smdk.c
~
设置nand分区如下:
//----------------------------------------- NAND FLASH 分区表设置 ---------------------------------//
/* NAND parititon from 2.4.18-swl5 */
static struct mtd_partition smdk_default_nand_part[] = {
[0] = {
.name = "bootloader",
.offset = 0x00000000,
.size = 0x00040000, //256K
},
[1] = {
.name = "linux kernel",
.offset = 0x00200000,
.size = 0x00300000, //3M
},
[2] = {
.name = "file system",
.offset = 0x00500000,
.size = 0x0FA00000, //250M
}
};
最后,make zImage 编译内核。
将开发板拨到NOR启动,按t选项测试刚编译的内核
信息如图,内核启动测试成功:
4、LCD触摸屏支持
~~~~~~~~ LCD触摸屏的linux代码文件是:s3c2410_ts.c,是以平台设备的方式向内核进行注册,实验的时候发现在dev目录下不生成event0设备文件,内核启动时也没有初始化信息打印出来,平台设备会用到probe函数进行驱动和设备的匹配,就是因为没有匹配上,所以触摸屏没有初始化,我们该用普通模块的形式进行注册。
配置内核支持触摸屏
Device Drivers —>
Input device support —>
[] Touchscreens —>
<> Samsung S3C2410/generic touchscreen input driver
配置显示设备
Device Drivers —>
Graphics support —>
[*] Bootup logo —> 这个选项勾选之后,会在系统启动时显示一个LOGO
修改源文件:
drivers/input/touchscreen/s3c2410_ts.c
如下:
/**
* filename : drivers/input/touchscreen/s3c2410_ts.c
* autor : kun
* time :
* desc : tq2440 w43触摸屏驱动代码
*/
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/gpio.h>
#include <linux/input.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <plat/adc.h>
#include <plat/regs-adc.h>
#include <plat/ts.h>
/* For ts.dev.id.version */
#define S3C2410TSVERSION 0x0101
#define WAIT4INT(x) (((x)<<8) | \
S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
S3C2410_ADCTSC_XY_PST(3))
#define AUTOPST (S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
S3C2410_ADCTSC_AUTO_PST | S3C2410_ADCTSC_XY_PST(0))
static char *tq2440ts_name = "TQ2440 TouchScreen";
static struct input_dev *dev;
static long xp;
static long yp;
static int count;
static void __iomem *base_addr;
/*
static inline void tq2440_ts_connect(void)
{
s3c2410_gpio_cfgpin(S3C2410_GPG12, S3C2410_GPG12_XMON);
s3c2410_gpio_cfgpin(S3C2410_GPG13, S3C2410_GPG13_nXPON);
s3c2410_gpio_cfgpin(S3C2410_GPG14, S3C2410_GPG14_YMON);
s3c2410_gpio_cfgpin(S3C2410_GPG15, S3C2410_GPG15_nYPON);
}
*/
static void touch_timer_fire(unsigned long data)
{
unsigned long data0;
unsigned long data1;
int updown;
data0 = ioread32(base_addr + S3C2410_ADCDAT0);
data1 = ioread32(base_addr + S3C2410_ADCDAT1);
updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
if (updown)
{
if (count != 0) // 四次转换后得到的adc值在除以4,这样得到的坐标更准确
{
unsigned int tmp;
tmp = xp; // 交换x y坐标,目的:屏的坐标体系和linux坐标体系不一样
xp = yp;
yp = tmp;
xp >>= 2; // 左移两位,就是除以四
yp >>= 2;
// 上报坐标
input_report_abs(dev, ABS_X, xp); //x 坐标
input_report_abs(dev, ABS_Y, yp); //y 坐标
input_report_key(dev, BTN_TOUCH, 1); //触摸屏按键事件
input_report_abs(dev, ABS_PRESSURE, 1); //上报触摸屏按压事件
// 同步事件
input_sync(dev);
/**
* 用于测试触摸屏
*/
printk("x = %ld, y = %ld \n", xp, yp);
xp = yp = count = 0; //清零,为下次做准备
}
// 开启XY坐标自动转换
iowrite32(1 << 2, S3C2410_ADCTSC + base_addr);
// 使能ADC转换
iowrite32(ioread32(S3C2410_ADCCON + base_addr) | (1 << 0), S3C2410_ADCCON + base_addr);
}
else
{
count = 0;
input_report_key(dev, BTN_TOUCH, 0);
input_report_abs(dev, ABS_PRESSURE, 0);
input_sync(dev);
iowrite32(WAIT4INT(0), base_addr + S3C2410_ADCTSC);
}
}
static struct timer_list touch_timer =
TIMER_INITIALIZER(touch_timer_fire, 0, 0);
/**
* [stylus_updown description]:触摸屏触摸与释放中断处理程序
* @param irq 中断源
* @param dev_id request_irq的第四个参数
* @return 中断执行结果
*/
static irqreturn_t stylus_updown(int irq, void *dev_id)
{
unsigned long data0;
unsigned long data1;
int updown;
data0 = ioread32(base_addr + S3C2410_ADCDAT0);
data1 = ioread32(base_addr + S3C2410_ADCDAT1);
updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
if (updown)
{
touch_timer_fire(0);
}
return IRQ_HANDLED;
}
/**
* [stylus_action description]:adc中断处理程序
* @param irq 中断源
* @param dev_id request_irq的第四个参数
* @return 中断事件执行结果
*/
static irqreturn_t stylus_action(int irq, void *dev_id)
{
unsigned long data0;
unsigned long data1;
data0 = ioread32(base_addr + S3C2410_ADCDAT0);
data1 = ioread32(base_addr + S3C2410_ADCDAT1);
xp += data0 & S3C2410_ADCDAT0_XPDATA_MASK;
yp += data1 & S3C2410_ADCDAT1_YPDATA_MASK;
count++;
if (count < (1 << 2))
{
iowrite32(S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST, base_addr + S3C2410_ADCTSC);
iowrite32(ioread32(base_addr + S3C2410_ADCCON) | S3C2410_ADCCON_ENABLE_START, base_addr + S3C2410_ADCCON);
}
else
{
mod_timer(&touch_timer, jiffies + 1);
iowrite32(WAIT4INT(1), base_addr + S3C2410_ADCTSC);
}
return IRQ_HANDLED;
}
static struct clk *adc_clock;
static int __init tq2440ts_init(void)
{
struct input_dev *input_dev;
adc_clock = clk_get(NULL, "adc");
if (!adc_clock)
{
printk(KERN_ERR "failed to get adc clock source\n");
return -ENOENT;
}
clk_enable(adc_clock);
base_addr = ioremap(S3C2410_PA_ADC, 0x20);
if (base_addr == NULL)
{
printk(KERN_ERR "Failed to remap register block\n");
return -ENOMEM;
}
/* Configure GPIOs */
// tq2440_ts_connect();
iowrite32(S3C2410_ADCCON_PRSCEN | S3C2410_ADCCON_PRSCVL(0xFF), base_addr + S3C2410_ADCCON);
iowrite32(0xffff, base_addr + S3C2410_ADCDLY);
iowrite32(WAIT4INT(0), base_addr + S3C2410_ADCTSC);
/* Initialise input stuff */
input_dev = input_allocate_device();
if (!input_dev)
{
printk(KERN_ERR "Unable to allocate the input device !!\n");
return -ENOMEM;
}
dev = input_dev;
dev->evbit[0] = BIT(EV_SYN) | BIT(EV_KEY) | BIT(EV_ABS);
dev->keybit[BITS_TO_LONGS(BTN_TOUCH)] = BIT(BTN_TOUCH);
// 设置触摸屏可能发生的事件
input_set_abs_params(dev, ABS_X, 0, 0x3FF, 0, 0);
input_set_abs_params(dev, ABS_Y, 0, 0x3FF, 0, 0);
input_set_abs_params(dev, ABS_PRESSURE, 0, 1, 0, 0);
dev->name = tq2440ts_name;
dev->id.bustype = BUS_RS232;
dev->id.vendor = 0xDEAD;
dev->id.product = 0xBEEF;
dev->id.version = S3C2410TSVERSION;
if (request_irq(IRQ_ADC, stylus_action, IRQF_SHARED | IRQF_SAMPLE_RANDOM, tq2440ts_name, dev))
{
printk(KERN_ERR "tq2440_ts.c: Could not allocate ts IRQ_ADC !\n");
iounmap(base_addr);
return -EIO;
}
if (request_irq(IRQ_TC, stylus_updown, IRQF_SAMPLE_RANDOM, tq2440ts_name, dev))
{
printk(KERN_ERR "tq2440_ts.c: Could not allocate ts IRQ_ADC !\n");
iounmap(base_addr);
return -EIO;
}
printk(KERN_INFO "%s successfully loaded\n", tq2440ts_name);
input_register_device(dev);
return 0;
}
static void __exit tq2440ts_exit(void)
{
disable_irq(IRQ_ADC);
disable_irq(IRQ_TC);
free_irq(IRQ_TC, dev);
free_irq(IRQ_ADC, dev);
if (adc_clock)
{
clk_disable(adc_clock);
clk_put(adc_clock);
adc_clock = NULL;
}
input_unregister_device(dev);
iounmap(base_addr);
}
module_init(tq2440ts_init);
module_exit(tq2440ts_exit);
MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>, "
"Ben Dooks <ben@simtec.co.uk>, "
"Simtec Electronics <linux@simtec.co.uk>");
MODULE_DESCRIPTION("S3C24XX Touchscreen driver");
MODULE_LICENSE("GPL v2");
~~~~~~~~ 修改
arch/arm/mach-s3c2440/mach-smdk2440.c
中的lcd描述设备结构和帧缓冲描述结构,并在函数smdk2440_machine_init设置相应的平台设备数据。
//------------------------------- LCD -------------------------------//
static struct s3c2410fb_display smdk2440_lcd_cfg __initdata = {
.lcdcon5 = S3C2410_LCDCON5_FRM565 |
S3C2410_LCDCON5_INVVLINE |
S3C2410_LCDCON5_INVVFRAME |
S3C2410_LCDCON5_PWREN |
S3C2410_LCDCON5_HWSWP,
.type = S3C2410_LCDCON1_TFT,
.width = 480,
.height = 272,
.pixclock = 40000, /* HCLK 100 MHz, divisor 10 */
.xres = 480,
.yres = 272,
.bpp = 16,
.left_margin = 19,
.right_margin = 10,
.hsync_len = 30,
.upper_margin = 4,
.lower_margin = 2,
.vsync_len = 8,
};
//------------------------------- LCD帧缓冲 ----------------------//
static struct s3c2410fb_mach_info smdk2440_fb_info __initdata = {
.displays = &smdk2440_lcd_cfg,
.num_displays = 1,
.default_display = 0,
#if 0
/* currently setup by downloader */
.gpccon = 0xaaaaaaaa,
.gpccon_mask = 0xffffffff,
.gpcup = 0x0000ffff,
.gpcup_mask = 0xffffffff,
.gpdcon = 0xaaaaaaaa,
.gpdcon_mask = 0xffffffff,
.gpdup = 0x0000faff,
.gpdup_mask = 0xffffffff,
#endif
// .lpcsel = ((0xCE6) & ~7) | 1<<4,
};
~~~~~~~~ 重新编译内核,启动norflash的u-boot,选择t测试zImage下载内核。
测试帧缓冲:
~~~~~~~~ 准备好一张bmp格式的图片,使用软件Image2lcd制作一个480*272的bin文件,放到NFS文件系统中(我的叫test.bin),执行命令:cat test.bin > /dev/fb0
,就会看到触摸屏显示了自己的图像。
测试LCD触摸:
~~~~~~~~ 执行命令cat /dev/event0
,触摸lcd,就会有乱码打印出来。(在函数touch_timer_fire中,如果不注释掉printk函数,触摸LCD就会打印出坐标信息)。
5、IIC-驱动支持
**传送门:http://blog.csdn.net/qq153471503/article/details/79403732 **
6、SPI-驱动支持
**传送门:http://blog.csdn.net/qq153471503/article/details/79425330 **