linux在s3c2440上的移植(二)
来源:互联网 发布:世界杯直播软件 编辑:程序博客网 时间:2024/05/16 01:23
<四> LCD驱动的移植
内核中s3c2440 的LCD控制器驱动文件是:drivers/video/s3c2410fb.c,我们不需要修改
这个驱动,只需要在mach-cz2440.c中对LCD进行初始化。
1.定义所使用的LCD类型:
#define LCD480272 0
#define LCD800480 1
#define LCD_TYPE LCD480272 //4.3 inch lcd
在cz2440_devices[ ]平台设备结构体数组中加入lcd设备:
&s3c_device_lcd,
在cz2440_machine_init函数中加入设置lcd平台数据函数:
s3c24xx_fb_set_platdata(&cz2440_fb_info);
构建cz2440_fb_info结构体:
static struct s3c2410fb_mach_info cz2440_fb_info __initdata = {
.displays = &cz2440_lcd_cfg,
.num_displays = 1,
.default_display = 0,
};
构建LCD配置结构体cz2440_lcd_cfg:
/* LCD driver info */
static struct s3c2410fb_display cz2440_lcd_cfg __initdata = {
.lcdcon5 = S3C2410_LCDCON5_FRM565 |
S3C2410_LCDCON5_INVVLINE |
S3C2410_LCDCON5_INVVFRAME |
S3C2410_LCDCON5_PWREN |
S3C2410_LCDCON5_HWSWP,
.type = S3C2410_LCDCON1_TFT,
#if (LCD_TYPE == LCD480272)
.width = 480,
这个驱动,只需要在mach-cz2440.c中对LCD进行初始化。
1.定义所使用的LCD类型:
#define LCD480272 0
#define LCD800480 1
#define LCD_TYPE LCD480272 //4.3 inch lcd
在cz2440_devices[ ]平台设备结构体数组中加入lcd设备:
&s3c_device_lcd,
在cz2440_machine_init函数中加入设置lcd平台数据函数:
s3c24xx_fb_set_platdata(&cz2440_fb_info);
构建cz2440_fb_info结构体:
static struct s3c2410fb_mach_info cz2440_fb_info __initdata = {
.displays = &cz2440_lcd_cfg,
.num_displays = 1,
.default_display = 0,
};
构建LCD配置结构体cz2440_lcd_cfg:
/* LCD driver info */
static struct s3c2410fb_display cz2440_lcd_cfg __initdata = {
.lcdcon5 = S3C2410_LCDCON5_FRM565 |
S3C2410_LCDCON5_INVVLINE |
S3C2410_LCDCON5_INVVFRAME |
S3C2410_LCDCON5_PWREN |
S3C2410_LCDCON5_HWSWP,
.type = S3C2410_LCDCON1_TFT,
#if (LCD_TYPE == LCD480272)
.width = 480,
.height = 272,
.pixclock = (2*1000000000000LL)/80 * \
(8 + 43 + 2 + 480) * \
(12 + 4 + 10 + 272),
.xres = 480,
.yres = 272,
.bpp = 16,
.left_margin = 8,
.right_margin = 43,
.hsync_len = 2,
.upper_margin = 4,
.lower_margin = 12,
.vsync_len = 10,
#elif(LCD_TYPE == LCD800480)
.width = 800,
.height = 480,
.pixclock = (2*1000000000000LL)/60 * \
(48 + 40 + 40 + 800) * \
(3 + 13 + 29 + 480),
.xres = 800,
.yres = 480,
.bpp = 16,
.left_margin = 40,
.right_margin = 40,
.hsync_len = 48,
.upper_margin = 13,
.lower_margin = 29,
.vsync_len = 3,
#endif
};
.pixclock = (2*1000000000000LL)/80 * \
(8 + 43 + 2 + 480) * \
(12 + 4 + 10 + 272),
.xres = 480,
.yres = 272,
.bpp = 16,
.left_margin = 8,
.right_margin = 43,
.hsync_len = 2,
.upper_margin = 4,
.lower_margin = 12,
.vsync_len = 10,
#elif(LCD_TYPE == LCD800480)
.width = 800,
.height = 480,
.pixclock = (2*1000000000000LL)/60 * \
(48 + 40 + 40 + 800) * \
(3 + 13 + 29 + 480),
.xres = 800,
.yres = 480,
.bpp = 16,
.left_margin = 40,
.right_margin = 40,
.hsync_len = 48,
.upper_margin = 13,
.lower_margin = 29,
.vsync_len = 3,
#endif
};
2.配置内核,支持LCD:
Device Drivers:
Graphics Support --->
<*>support for frame buffer devices --->
[*] Enable frameware EDID
[*] Enable Vidoe Mode Handling Helpers
<*> S3C24X0 LCD framebuffer support
Console display driver support --->
<*> Framebuffer Console Support
[*] Bootup Logo --->
<*> Standard 224-color Linux logo
Device Drivers:
Graphics Support --->
<*>support for frame buffer devices --->
[*] Enable frameware EDID
[*] Enable Vidoe Mode Handling Helpers
<*> S3C24X0 LCD framebuffer support
Console display driver support --->
<*> Framebuffer Console Support
[*] Bootup Logo --->
<*> Standard 224-color Linux logo
启动时输出:
Console: switching to colour frame buffer device 40x30
fb0: s3c2410fb frame buffer device
Console: switching to colour frame buffer device 40x30
fb0: s3c2410fb frame buffer device
<五> HWMON(ADC)驱动移植
linux内核自带s3c2440 的ADC驱动,由于触摸屏驱动也依赖ADC驱动,所以要先把ADC
驱动加到内核中。
我们先来移植HWMON驱动,HWMON是Hardware Monitoring缩写,是用于检测设备状态
的一种设备,比如电脑上检测测风扇转速、CPU温度的设备,实际上就是一些传感器,ADC
也属于这样的设备。
驱动加到内核中。
我们先来移植HWMON驱动,HWMON是Hardware Monitoring缩写,是用于检测设备状态
的一种设备,比如电脑上检测测风扇转速、CPU温度的设备,实际上就是一些传感器,ADC
也属于这样的设备。
1.在mach-cz2440.c中添加HWMON设备:
加入必要的头文件:
#include <plat/hwmon.h>
在cz2440_devices[ ]结构中加入:
&s3c_device_adc,
&s3c_device_hwmon,
构建HWMON设备平台数据结构:
/* ADC */
static struct s3c_hwmon_pdata cz2440_hwmon_info __initdata = {
.in[0] = &(struct s3c_hwmon_chcfg) {
.name = "adc-ch0",
.mult = 3300,
.div = 512,
},
.in[1] = &(struct s3c_hwmon_chcfg) {
.name = "adc-ch1",
.mult = 3300,
.div = 1024,
},
.in[2] = &(struct s3c_hwmon_chcfg) {
.name = "adc-ch2",
.mult = 3300,
.div = 512,
},
.in[3] = &(struct s3c_hwmon_chcfg) {
.name = "adc-ch3",
.mult = 3300,
加入必要的头文件:
#include <plat/hwmon.h>
在cz2440_devices[ ]结构中加入:
&s3c_device_adc,
&s3c_device_hwmon,
构建HWMON设备平台数据结构:
/* ADC */
static struct s3c_hwmon_pdata cz2440_hwmon_info __initdata = {
.in[0] = &(struct s3c_hwmon_chcfg) {
.name = "adc-ch0",
.mult = 3300,
.div = 512,
},
.in[1] = &(struct s3c_hwmon_chcfg) {
.name = "adc-ch1",
.mult = 3300,
.div = 1024,
},
.in[2] = &(struct s3c_hwmon_chcfg) {
.name = "adc-ch2",
.mult = 3300,
.div = 512,
},
.in[3] = &(struct s3c_hwmon_chcfg) {
.name = "adc-ch3",
.mult = 3300,
.div = 1024,
},
};
},
};
在cz2440_machine_init函数中加入:
s3c_hwmon_set_platdata(&cz2440_hwmon_info);
s3c_hwmon_set_platdata(&cz2440_hwmon_info);
2.函数s3c_hwmon_set_platdata实现文件为:/arch/arm/plat-samsung/dev-hwmon.c
修改该目录下的Kconfig文件:在S3C_DEV_HWMON选项下加入default y,
config S3C_DEV_HWMON
bool
default y ->注意前面应该为TAB而不是空格(语法决定)
help
Compile in platform device definitions for HWMON
修改该目录下的Kconfig文件:在S3C_DEV_HWMON选项下加入default y,
config S3C_DEV_HWMON
bool
default y ->注意前面应该为TAB而不是空格(语法决定)
help
Compile in platform device definitions for HWMON
3.System Type --->
[*] ADC common driver support
Device Drivers --->
<*> Hardware Monitoring support --->
<*> Samsung built-in ADC
[*] Include raw channel attributes in sysfs
[*] ADC common driver support
Device Drivers --->
<*> Hardware Monitoring support --->
<*> Samsung built-in ADC
[*] Include raw channel attributes in sysfs
启动时打印:
s3c-adc s3c24xx-adc: attached adc driver
s3c-adc s3c24xx-adc: attached adc driver
查看设备:
#cd /sys/class/hwmon/hwmon0/device
在这个目录下有 8个名为adcx_raw的文件,分别对应s3c2440 的 8 路ADC
执行#cat adc0_raw 查看该通道的AD转换值
#cd /sys/class/hwmon/hwmon0/device
在这个目录下有 8个名为adcx_raw的文件,分别对应s3c2440 的 8 路ADC
执行#cat adc0_raw 查看该通道的AD转换值
<六> 触摸屏驱动移植
内核自带s3c2440 的触摸屏控制器驱动,属于input子系统的驱动,触摸屏驱动需要ADC
驱动的支持,触摸屏驱动文件为:drivers/input/touchscreen/s3c2410_ts.c
驱动的支持,触摸屏驱动文件为:drivers/input/touchscreen/s3c2410_ts.c
1.在mach-xc2440.c文件中加入对触摸屏驱动的支持
加入必要的头文件:
#include <plat/ts.h>
cz2440_devices[ ]结构体中加入:
&s3c_device_ts,
2.构建触摸屏设备的平台数据结构:
/* TouchPanel */
static struct s3c2410_ts_mach_info cz2440_ts_cfg __initdata = {
.delay = 10000,
.presc = 49,
.oversampling_shift = 2,
};
3.在cz2440_machine_init函数中加入:
s3c24xx_ts_set_platdata(&cz2440_ts_cfg);
修改s3c2410_ts.c文件:
在s3c2410ts_probe函数中,318 行开始
ts.input = input_dev;
ts.input->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_SYN);
ts.input->keybit[BITS_TO_LONGS(BTN_TOUCH)] = BIT(BTN_TOUCH);
input_set_abs_params(ts.input, ABS_X, 0, 0x3FF, 0, 0);
input_set_abs_params(ts.input, ABS_Y, 0, 0x3FF, 0, 0);
input_set_abs_params(ts.input, ABS_PRESSURE, 0, 1, 0, 0);
touch_timer_fire函数中:
input_report_abs(ts.input, ABS_X, ts.xp);
加入必要的头文件:
#include <plat/ts.h>
cz2440_devices[ ]结构体中加入:
&s3c_device_ts,
2.构建触摸屏设备的平台数据结构:
/* TouchPanel */
static struct s3c2410_ts_mach_info cz2440_ts_cfg __initdata = {
.delay = 10000,
.presc = 49,
.oversampling_shift = 2,
};
3.在cz2440_machine_init函数中加入:
s3c24xx_ts_set_platdata(&cz2440_ts_cfg);
修改s3c2410_ts.c文件:
在s3c2410ts_probe函数中,318 行开始
ts.input = input_dev;
ts.input->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_SYN);
ts.input->keybit[BITS_TO_LONGS(BTN_TOUCH)] = BIT(BTN_TOUCH);
input_set_abs_params(ts.input, ABS_X, 0, 0x3FF, 0, 0);
input_set_abs_params(ts.input, ABS_Y, 0, 0x3FF, 0, 0);
input_set_abs_params(ts.input, ABS_PRESSURE, 0, 1, 0, 0);
touch_timer_fire函数中:
input_report_abs(ts.input, ABS_X, ts.xp);
input_report_abs(ts.input, ABS_Y, ts.yp);
input_report_key(ts.input, BTN_TOUCH, 1);
input_report_abs(ts.input, ABS_PRESSURE, 1);
input_sync(ts.input);
input_report_key(ts.input, BTN_TOUCH, 0);
input_report_abs(ts.input, ABS_PRESSURE, 0);
input_sync(ts.input);
writel(WAIT4INT | INT_DOWN, ts.io + S3C2410_ADCTSC);
input_report_key(ts.input, BTN_TOUCH, 1);
input_report_abs(ts.input, ABS_PRESSURE, 1);
input_sync(ts.input);
input_report_key(ts.input, BTN_TOUCH, 0);
input_report_abs(ts.input, ABS_PRESSURE, 0);
input_sync(ts.input);
writel(WAIT4INT | INT_DOWN, ts.io + S3C2410_ADCTSC);
配置内核,支持触摸屏:
Device Drivers --->
Input devices support --->
<*> Event interface
[*] Touchscreens --->
<*> Samsung S3C2410/generic touchscreen input driver
启动时输出:
samsung-ts s3c2440-ts: driver attached, registering input device
input: S3C24XX TouchScreen as /devices/virtual/input/input0
Device Drivers --->
Input devices support --->
<*> Event interface
[*] Touchscreens --->
<*> Samsung S3C2410/generic touchscreen input driver
启动时输出:
samsung-ts s3c2440-ts: driver attached, registering input device
input: S3C24XX TouchScreen as /devices/virtual/input/input0
注意:
1. 内核自带的触摸屏驱动有BUG,需要修改才能正常使用,具体修改内容请参考XC2440 的
linux源码包中的文件。
2. Input子系统设备的设备名可能会随着内核中input设备的增加而改变,比如内核中加入一
个按键驱动,那么触摸屏的设备名可能会从event0变为event1。后面移植的input子系统
驱动也是同样的原理,这点注意
1. 内核自带的触摸屏驱动有BUG,需要修改才能正常使用,具体修改内容请参考XC2440 的
linux源码包中的文件。
2. Input子系统设备的设备名可能会随着内核中input设备的增加而改变,比如内核中加入一
个按键驱动,那么触摸屏的设备名可能会从event0变为event1。后面移植的input子系统
驱动也是同样的原理,这点注意
<七> 以太网卡驱动的移植
XC2440 开发板上使用的以太网卡芯片是DM9000A,内核中的驱动文件为:drivers/net/dm9000.c
1.在mach-cz2440.c文件中加入对dm9000 网卡的驱动支持,并
创建平台数据:
加入dm9000 头文件:
#include <linux/dm9000.h>
在cz2440_devices[ ]平台设备结构体数组中加入ethernet设备:
&cz2440_ethernet_device,
创建platform_device和platform_data:
/* DM9000A Net */
static struct resource cz2440_dm9k_resource[] = {
[0] = {
.start = S3C2410_CS4,
.end = S3C2410_CS4 + 3,
.flags = IORESOURCE_MEM
},
[1] = {
.start = S3C2410_CS4 + 4,
.end = S3C2410_CS4 + 7,
.flags = IORESOURCE_MEM
},
[2] = {
.start = IRQ_EINT(18),
.end = IRQ_EINT(18),
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
}
};
static struct dm9000_plat_data cz2440_dm9k_pdata = {
.flags =(DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
.dev_addr = { 0x08, 0x09, 0x0a, 0xa0, 0x90, 0x80 };
static struct platform_device cz2440_ethernet_device = {
.name = "dm9000",
创建平台数据:
加入dm9000 头文件:
#include <linux/dm9000.h>
在cz2440_devices[ ]平台设备结构体数组中加入ethernet设备:
&cz2440_ethernet_device,
创建platform_device和platform_data:
/* DM9000A Net */
static struct resource cz2440_dm9k_resource[] = {
[0] = {
.start = S3C2410_CS4,
.end = S3C2410_CS4 + 3,
.flags = IORESOURCE_MEM
},
[1] = {
.start = S3C2410_CS4 + 4,
.end = S3C2410_CS4 + 7,
.flags = IORESOURCE_MEM
},
[2] = {
.start = IRQ_EINT(18),
.end = IRQ_EINT(18),
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
}
};
static struct dm9000_plat_data cz2440_dm9k_pdata = {
.flags =(DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
.dev_addr = { 0x08, 0x09, 0x0a, 0xa0, 0x90, 0x80 };
static struct platform_device cz2440_ethernet_device = {
.name = "dm9000",
.id = -1,
.num_resources = ARRAY_SIZE(xc2440_dm9k_resource),
.resource = xc2440_dm9k_resource,
.dev = {
.platform_data = &xc2440_dm9k_pdata,
},
};
.num_resources = ARRAY_SIZE(xc2440_dm9k_resource),
.resource = xc2440_dm9k_resource,
.dev = {
.platform_data = &xc2440_dm9k_pdata,
},
};
2.配置内核,支持网卡:
Device Drivers --->
[*] Network device support --->
[*] Ethernet(10 or 100 Mbit) --->
<*> DM9000 support
(4) DM9000 maximum debug level
Device Drivers --->
[*] Network device support --->
[*] Ethernet(10 or 100 Mbit) --->
<*> DM9000 support
(4) DM9000 maximum debug level
启动时输出:
dm9000 Ethernet Driver, V1.31
eth0: dm9000e at c480c000,c4810004 IRQ 62 MAC: 08:09:0a:a0:90:80 (platform data)
dm9000 Ethernet Driver, V1.31
eth0: dm9000e at c480c000,c4810004 IRQ 62 MAC: 08:09:0a:a0:90:80 (platform data)
<八> USB Host驱动移植
内核里已经做好了很完善的USB Host驱动了,可以支持大多数USB设备(如U盘,USB
键盘鼠标等),同时也支持USB HUB
键盘鼠标等),同时也支持USB HUB
1.在mach-cz2440.c中添加USB Host驱动的支持:
cz2440_devices[ ]结构体中加入:
&s3c_device_ohci,
s3c_device_ohci结构体的实现文件为/arch/arm/plat-samsung/dev-usb.c,系统默认没有对它
的编译支持,修改同目录下的Kconfig文件:
config S3C_DEV_USB_HOST
bool
default y
help
Compile in platform device definition for USB host.
或修改arch/arm/mach-s3c2440/Kconfig文件:
config MACH_cz2440
bool "cz2440 development board with S3C2440 CPU module"
select CPU_S3C2440
select S3C_DEV_NAND
select S3C_DEV_USB_HOST
help
Say Y here if you are using the XC2440 development board.
cz2440_devices[ ]结构体中加入:
&s3c_device_ohci,
s3c_device_ohci结构体的实现文件为/arch/arm/plat-samsung/dev-usb.c,系统默认没有对它
的编译支持,修改同目录下的Kconfig文件:
config S3C_DEV_USB_HOST
bool
default y
help
Compile in platform device definition for USB host.
或修改arch/arm/mach-s3c2440/Kconfig文件:
config MACH_cz2440
bool "cz2440 development board with S3C2440 CPU module"
select CPU_S3C2440
select S3C_DEV_NAND
select S3C_DEV_USB_HOST
help
Say Y here if you are using the XC2440 development board.
2.配置内核,支持USB Host:
Device drivers --->
SCSI Device support --->
<*> SCSI device support
<*> SCSI disk support
[*] HID Devices --->
-*- Generic HID support
<*> USB Human Interface Device (full HID) support
[*] USB support --->
{*} Support for Host-side USB
[*] USB announce new devices
Device drivers --->
SCSI Device support --->
<*> SCSI device support
<*> SCSI disk support
[*] HID Devices --->
-*- Generic HID support
<*> USB Human Interface Device (full HID) support
[*] USB support --->
{*} Support for Host-side USB
[*] USB announce new devices
[*] USB device filesystem
<*> OHCI HCD support
<*> USB Mass Storage support
<*> OHCI HCD support
<*> USB Mass Storage support
注:USB Human Interface Device (full HID) support 是对USB鼠标键盘的支持
SCSI disk support 和USB Mass Storage support 是对U盘的支持
SCSI disk support 和USB Mass Storage support 是对U盘的支持
启动时输出:
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usbcore: registered new interface driver libusual
usb 1-1: configuration #1 chosen from 1 choice
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usbcore: registered new interface driver libusual
usb 1-1: configuration #1 chosen from 1 choice
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
<九> USB Device(Gadget)驱动移植
1.在mach-xc2440.c中添加USB gadget驱动的支持:
加入必要的头文件
加入必要的头文件
#include <plat/udc.h>
cz2440_devices[ ]结构体中加入:
&s3c_device_usbgadget,
构建USB gadget设备的平台数据结构:
/* USB device UDC support */
static void cz2440_udc_pullup(enum s3c2410_udc_cmd_e cmd)
{
switch (cmd) {
case S3C2410_UDC_P_ENABLE :
gpio_set_value(S3C2410_GPG(12), 1);
break;
case S3C2410_UDC_P_DISABLE :
gpio_set_value(S3C2410_GPG(12), 0);
break;
case S3C2410_UDC_P_RESET :
break;
default:
break;
}
}
static struct s3c2410_udc_mach_info cz2440_udc_cfg __initdata = {
.udc_command = xc2440_udc_pullup,
};
在xc2440_machine_init函数中加入:
s3c24xx_udc_set_platdata(&cz2440_udc_cfg);
cz2440_devices[ ]结构体中加入:
&s3c_device_usbgadget,
构建USB gadget设备的平台数据结构:
/* USB device UDC support */
static void cz2440_udc_pullup(enum s3c2410_udc_cmd_e cmd)
{
switch (cmd) {
case S3C2410_UDC_P_ENABLE :
gpio_set_value(S3C2410_GPG(12), 1);
break;
case S3C2410_UDC_P_DISABLE :
gpio_set_value(S3C2410_GPG(12), 0);
break;
case S3C2410_UDC_P_RESET :
break;
default:
break;
}
}
static struct s3c2410_udc_mach_info cz2440_udc_cfg __initdata = {
.udc_command = xc2440_udc_pullup,
};
在xc2440_machine_init函数中加入:
s3c24xx_udc_set_platdata(&cz2440_udc_cfg);
2.配置内核,支持USB gadget驱动:
Device Drivers --->
[*] USB support --->
<*> USB Gadget Support --->
Device Drivers --->
[*] USB support --->
<*> USB Gadget Support --->
USB Peripheral Controller (S3C2410 USB Device Controller) --->
S3C2410 USB Device Controller
<M> USB Gadget Drivers
<M> File-backed Storage Gadget
[*] File-backed Storage Gadget testing version
<M> Mass Storage Gadget
S3C2410 USB Device Controller
<M> USB Gadget Drivers
<M> File-backed Storage Gadget
[*] File-backed Storage Gadget testing version
<M> Mass Storage Gadget
内核启动输出:
s3c2440-usbgadget s3c2440-usbgadget: S3C2440: increasing FIFO to 128 bytes
s3c2440-usbgadget s3c2440-usbgadget: S3C2440: increasing FIFO to 128 bytes
3.编译模块:
#make M=drivers/usb/gadget modules
在drivers/usb/gadget目录下生成:g_file_storage.ko和g_mass_storage.ko两个模块文件,将
这两个文件下载到开发板的文件系统中,将文件放到:/lib/modules/2.6.37.4目录下
执行命令:#insmod /lib/modules/2.6.37.4/g_file_storage.ko file=/dev/sda1
[root@cz2440 /]# insmod /lib/modules/2.6.37.4/g_file_storage.ko file=/dev/sda1
g_file_storage gadget: No serial-number string provided!
g_file_storage gadget: File-backed Storage Gadget, version: 1 September 2010
g_file_storage gadget: Number of LUNs=1
g_file_storage gadget-lun0: ro=0, nofua=0, file: /dev/sda1
[root@XC2440 /]# g_file_storage gadget: full speed config #1
g_file_storage gadget: full speed config #1
#make M=drivers/usb/gadget modules
在drivers/usb/gadget目录下生成:g_file_storage.ko和g_mass_storage.ko两个模块文件,将
这两个文件下载到开发板的文件系统中,将文件放到:/lib/modules/2.6.37.4目录下
执行命令:#insmod /lib/modules/2.6.37.4/g_file_storage.ko file=/dev/sda1
[root@cz2440 /]# insmod /lib/modules/2.6.37.4/g_file_storage.ko file=/dev/sda1
g_file_storage gadget: No serial-number string provided!
g_file_storage gadget: File-backed Storage Gadget, version: 1 September 2010
g_file_storage gadget: Number of LUNs=1
g_file_storage gadget-lun0: ro=0, nofua=0, file: /dev/sda1
[root@XC2440 /]# g_file_storage gadget: full speed config #1
g_file_storage gadget: full speed config #1
<十> PWM驱动移植
蜂鸣器驱动和LCD背光驱动需要 2440的PWM驱动支持,它们分别使用timer0和timer1,
内核自带 2440的PWM驱动,文件位置为:arch/arm/plat-samsung/pwm.c.
内核自带 2440的PWM驱动,文件位置为:arch/arm/plat-samsung/pwm.c.
在mach-xc2440.c中添加PWM驱动的支持:
1.在cz2440_devices[ ]结构体中加入:
&s3c_device_timer[0],
&s3c_device_timer[1],
2.配置内核,支持按键PWM驱动:
System Type --->
[*] PWM device support
1.在cz2440_devices[ ]结构体中加入:
&s3c_device_timer[0],
&s3c_device_timer[1],
2.配置内核,支持按键PWM驱动:
System Type --->
[*] PWM device support
内核启动输出:
s3c24xx-pwm s3c24xx-pwm.0: tin at 25000000, tdiv at 25000000, tin=divclk, base 0
s3c24xx-pwm s3c24xx-pwm.1: tin at 25000000, tdiv at 25000000, tin=divclk, base 8
查看设备:
#cd /sys/devices/platform/
该目录下的s3c24xx-pwm.0 和 s3c24xx-pwm.1即为PWM设备文件
s3c24xx-pwm s3c24xx-pwm.0: tin at 25000000, tdiv at 25000000, tin=divclk, base 0
s3c24xx-pwm s3c24xx-pwm.1: tin at 25000000, tdiv at 25000000, tin=divclk, base 8
查看设备:
#cd /sys/devices/platform/
该目录下的s3c24xx-pwm.0 和 s3c24xx-pwm.1即为PWM设备文件
<十一> LCD背光驱动移植
LCD背光驱动基于PWM1(timer1),驱动文件为:
drivers/video/backlight/pwm_bl.c
drivers/video/backlight/pwm_bl.c
1.在mach-xc2440.c中添加LCD背光驱动的支持:
加入必要的头文件:
#include <linux/pwm_backlight.h>
#include <linux/gpio.h>
在cz2440_devices[ ]结构体中加入:
&cz2440_backlight_device,
构建LCD背光设备的平台数据结构:
/* LCD Backlight */
static int cz2440_backlight_init(struct device *dev)
{
gpio_request(S3C2410_GPB(1), "Backlight");
gpio_direction_output(S3C2410_GPB(1), 0);
s3c_gpio_setpull(S3C2410_GPB(1), S3C_GPIO_PULL_NONE);
s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPB1_TOUT1);
return 0;
}
static void cz2440_backlight_exit(struct device *dev)
{
gpio_direction_output(S3C2410_GPB(1), 1);
}
加入必要的头文件:
#include <linux/pwm_backlight.h>
#include <linux/gpio.h>
在cz2440_devices[ ]结构体中加入:
&cz2440_backlight_device,
构建LCD背光设备的平台数据结构:
/* LCD Backlight */
static int cz2440_backlight_init(struct device *dev)
{
gpio_request(S3C2410_GPB(1), "Backlight");
gpio_direction_output(S3C2410_GPB(1), 0);
s3c_gpio_setpull(S3C2410_GPB(1), S3C_GPIO_PULL_NONE);
s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPB1_TOUT1);
return 0;
}
static void cz2440_backlight_exit(struct device *dev)
{
gpio_direction_output(S3C2410_GPB(1), 1);
}
#if 0
static int cz2440_backlight_notify(struct device *dev, int brightness)
{
/*
* translate from CIELUV/CIELAB L*->brightness, E.G. from
* perceived luminance to light output. Assumes range 0..25600
*/
if (brightness < 0x800) {
static int cz2440_backlight_notify(struct device *dev, int brightness)
{
/*
* translate from CIELUV/CIELAB L*->brightness, E.G. from
* perceived luminance to light output. Assumes range 0..25600
*/
if (brightness < 0x800) {
/* Y = Yn * L / 903.3 */
brightness = (100*256 * brightness + 231245/2) / 231245;
} else {
/* Y = Yn * ((L + 16) / 116 )^3 */
int t = (brightness*4 + 16*1024 + 58)/116;
brightness = 25 * ((t * t * t + 0x100000/2) / 0x100000);
}
gpio_set_value(S3C2410_GPB(1), brightness);
return brightness;
}
brightness = (100*256 * brightness + 231245/2) / 231245;
} else {
/* Y = Yn * ((L + 16) / 116 )^3 */
int t = (brightness*4 + 16*1024 + 58)/116;
brightness = 25 * ((t * t * t + 0x100000/2) / 0x100000);
}
gpio_set_value(S3C2410_GPB(1), brightness);
return brightness;
}
#endif ->注:这部分代码要去掉才能正常驱动LCD背光
static struct platform_pwm_backlight_data cz2440_backlight_data = {
.pwm_id = 1,
.max_brightness = 24,
.dft_brightness = 4,
/* tcnt = 0x31 */
.pwm_period_ns = 48000,
.init = xc2440_backlight_init,
.exit = xc2440_backlight_exit,
// .notify = xc2440_backlight_notify, //mask by chenzhen ->注意:这部分代码要去掉,LCD背光驱动才能正常工作
};
static struct platform_device cz2440_backlight_device = {
.name = "pwm-backlight",
.dev = {
.parent = &s3c_device_timer[1].dev,
.platform_data = &xc2440_backlight_data,
},
.id = 1,
};
static struct platform_pwm_backlight_data cz2440_backlight_data = {
.pwm_id = 1,
.max_brightness = 24,
.dft_brightness = 4,
/* tcnt = 0x31 */
.pwm_period_ns = 48000,
.init = xc2440_backlight_init,
.exit = xc2440_backlight_exit,
// .notify = xc2440_backlight_notify, //mask by chenzhen ->注意:这部分代码要去掉,LCD背光驱动才能正常工作
};
static struct platform_device cz2440_backlight_device = {
.name = "pwm-backlight",
.dev = {
.parent = &s3c_device_timer[1].dev,
.platform_data = &xc2440_backlight_data,
},
.id = 1,
};
2.配置内核,支持LCD背光驱动:
Device Drivers --->
Graphics support --->
[*] Backlight & LCD device support --->
<*> Lowlevel Backlight control
<*> Generic PWM based Backlight Driver
Device Drivers --->
Graphics support --->
[*] Backlight & LCD device support --->
<*> Lowlevel Backlight control
<*> Generic PWM based Backlight Driver
3.查看设备:
/sys/class/backlight/pwm-backlight.1/brightness
操作设备:
#cat /sys/class/backlight/pwm-backlight.1/max_brightness (查看背光最大值)
#echo 15 > /sys/class/backlight/pwm-backlight.1/brightness (设置背光亮度)
/sys/class/backlight/pwm-backlight.1/brightness
操作设备:
#cat /sys/class/backlight/pwm-backlight.1/max_brightness (查看背光最大值)
#echo 15 > /sys/class/backlight/pwm-backlight.1/brightness (设置背光亮度)
<十二> 蜂鸣器驱动移植
蜂鸣器驱动基于PWM0(timer0) ,驱动文件为:drivers/input/misc/pwm-beeper.c,它属
于input设备。
于input设备。
1.在mach-cz2440.c中添加蜂鸣器驱动的支持:
在cz2440_devices[ ]结构体中加入:
&cz2440_beeper_device,
2.构建蜂鸣器设备的平台数据结构:
/* Buzzer */
static struct platform_device cz2440_beeper_device = {
.name = "pwm-beeper",
.dev = {
.parent = &s3c_device_timer[0].dev,
.platform_data = 0,
},
.id = 0,
};
在cz2440_devices[ ]结构体中加入:
&cz2440_beeper_device,
2.构建蜂鸣器设备的平台数据结构:
/* Buzzer */
static struct platform_device cz2440_beeper_device = {
.name = "pwm-beeper",
.dev = {
.parent = &s3c_device_timer[0].dev,
.platform_data = 0,
},
.id = 0,
};
3.配置内核,支持按键PWM驱动:
Device Drivers --->
Input device support --->
[*]Miscellaneous devices --->
<*>PWM beeper support
Device Drivers --->
Input device support --->
[*]Miscellaneous devices --->
<*>PWM beeper support
内核启动输出:
input: pwm-beeper as
/devices/platform/s3c24xx-pwm.0/pwm-beeper.0/input/input2
查看设备:
/dev/event2
input: pwm-beeper as
/devices/platform/s3c24xx-pwm.0/pwm-beeper.0/input/input2
查看设备:
/dev/event2
<十三> LED驱动移植
内核中带有GPIO控制LED的驱动,驱动文件为:drivers/leds/leds-gpio.c
在mach-xc2440.c中添加LED驱动的支持
在mach-xc2440.c中添加LED驱动的支持
1.加入必要的头文件:
#include <linux/leds.h>
在cz2440_devices[ ]结构体中加入:
&cz2440_device_led,
#include <linux/leds.h>
在cz2440_devices[ ]结构体中加入:
&cz2440_device_led,
2.构建LED设备的平台数据结构:
/* LEDS */
static struct gpio_led cz2440_leds[] = {
[0] = {
.name = "led1",
.gpio = S3C2410_GPF(0),
.active_low = 1,
},
[1] = {
.name = "led2",
.gpio = S3C2410_GPF(1),
.active_low = 1,
},
[2] = {
.name = "led3",
.gpio = S3C2410_GPF(2),
.active_low = 1,
},
[3] = {
.name = "led4",
.gpio = S3C2410_GPF(3),
.active_low = 1,
},
};
static struct gpio_led_platform_data cz2440_gpio_led_pdata = {
.num_leds = ARRAY_SIZE(cz2440_leds),
/* LEDS */
static struct gpio_led cz2440_leds[] = {
[0] = {
.name = "led1",
.gpio = S3C2410_GPF(0),
.active_low = 1,
},
[1] = {
.name = "led2",
.gpio = S3C2410_GPF(1),
.active_low = 1,
},
[2] = {
.name = "led3",
.gpio = S3C2410_GPF(2),
.active_low = 1,
},
[3] = {
.name = "led4",
.gpio = S3C2410_GPF(3),
.active_low = 1,
},
};
static struct gpio_led_platform_data cz2440_gpio_led_pdata = {
.num_leds = ARRAY_SIZE(cz2440_leds),
.leds = cz2440_leds,
};
static struct platform_device cz2440_device_led = {
.name = "leds-gpio",
.id = -1,
.dev = {
.platform_data = &cz2440_gpio_led_pdata,
},
};
};
static struct platform_device cz2440_device_led = {
.name = "leds-gpio",
.id = -1,
.dev = {
.platform_data = &cz2440_gpio_led_pdata,
},
};
3.配置内核,支持LED驱动:
Device Drivers --->
[*] LED Support --->
<*> LED Support for GPIO connected LEDs
[*] Platform device bindings for GPIO LEDs (NEW)
Device Drivers --->
[*] LED Support --->
<*> LED Support for GPIO connected LEDs
[*] Platform device bindings for GPIO LEDs (NEW)
查看设备:
/sys/class/leds/ledx (x为 0,1,2,3)
操作方法:
#echo 1 > /sys/class/leds/led0/brightness 让LED0 亮
#echo 0 > /sys/class/leds/led0/brightness 让LED0 灭
/sys/class/leds/ledx (x为 0,1,2,3)
操作方法:
#echo 1 > /sys/class/leds/led0/brightness 让LED0 亮
#echo 0 > /sys/class/leds/led0/brightness 让LED0 灭
<十四> 按键驱动移植:
内核中带有 GPIO 控制按键的驱动,属于 input 子系统驱动,驱动文件为:
drivers/input/keyboard/gpio-keys.c
内核中带有 GPIO 控制按键的驱动,属于 input 子系统驱动,驱动文件为:
drivers/input/keyboard/gpio-keys.c
1.在mach-xc2440.c中添加按键驱动的支持:
加入必要的头文件:
#include <linux/gpio_keys.h>
#include <linux/input.h>
2.在cz2440_devices[ ]结构体中加入:
&cz2440_device_button,
3.构建按键设备的平台数据结构:
/* Buttons */
static struct gpio_keys_button cz2440_buttons[] = {
{
.gpio = S3C2410_GPF(4), /* K1 */
.code = KEY_F1,
.desc = "Button 1",
.active_low = 1,
},
{
.gpio = S3C2410_GPF(5), /* K2 */
.code = KEY_F2,
.desc = "Button 2",
.active_low = 1,
},
{
.gpio = S3C2410_GPF(6), /* K3 */
.code = KEY_F3,
.desc = "Button 3",
.active_low = 1,
},
{
.gpio = S3C2410_GPF(7), /* K4 */
.code = KEY_POWER,
.desc = "Button 4",
.active_low = 1,
},
};
static struct gpio_keys_platform_data cz2440_button_data = {
.buttons = cz2440_buttons,
.nbuttons = ARRAY_SIZE(cz2440_buttons),
};
static struct platform_device cz2440_button_device = {
.name = "gpio-keys",
.id = -1,
.dev = {
.platform_data = &cz2440_button_data,
}
};
},
};
static struct gpio_keys_platform_data cz2440_button_data = {
.buttons = cz2440_buttons,
.nbuttons = ARRAY_SIZE(cz2440_buttons),
};
static struct platform_device cz2440_button_device = {
.name = "gpio-keys",
.id = -1,
.dev = {
.platform_data = &cz2440_button_data,
}
};
3.配置内核,支持按键驱动:
Device Drivers --->
Input devices support --->
[*]Keyboards --->
<*> GPIO Buttons
Device Drivers --->
Input devices support --->
[*]Keyboards --->
<*> GPIO Buttons
内核启动输出:
input: gpio-keys as /devices/platform/gpio-keys/input/input0
查看设备:
/dev/event0 (注意:原来设备名为event0的设备,设备名会变成event1)
input: gpio-keys as /devices/platform/gpio-keys/input/input0
查看设备:
/dev/event0 (注意:原来设备名为event0的设备,设备名会变成event1)
<十五> IIC总线驱动移植
cz2440开发板上使用的IIC设备为AT24C04和Camera,首先要让内核支持 2440的IIC总
线驱动,然后再将IIC设备挂接到IIC总线上。
1.在mach-xc2440.c中添加IIC总线驱动的支持:
加入必要的头文件:
#include <linux/i2c.h>
在cz2440_devices[ ]结构体中加入:
&s3c_device_i2c0,
在cz2440_machine_init函数中加入:
s3c_i2c0_set_platdata(NULL);
cz2440开发板上使用的IIC设备为AT24C04和Camera,首先要让内核支持 2440的IIC总
线驱动,然后再将IIC设备挂接到IIC总线上。
1.在mach-xc2440.c中添加IIC总线驱动的支持:
加入必要的头文件:
#include <linux/i2c.h>
在cz2440_devices[ ]结构体中加入:
&s3c_device_i2c0,
在cz2440_machine_init函数中加入:
s3c_i2c0_set_platdata(NULL);
2.配置内核,支持IIC总线驱动:
Device Drivers --->
<*>I2C support --->
[*] Enable compatibility bits for old user-space
<*> I2C device interface
[*] Autoselect pertinent helper modules
I2C Hardware Bus support --->
<*>S3C2410 I2C Driver
Device Drivers --->
<*>I2C support --->
[*] Enable compatibility bits for old user-space
<*> I2C device interface
[*] Autoselect pertinent helper modules
I2C Hardware Bus support --->
<*>S3C2410 I2C Driver
内核启动输出:
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 97 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
i2c /dev entries driver
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 97 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
i2c /dev entries driver
查看设备:
/dev/i2c-0
/dev/i2c-0
<十六> RTC驱动移植
内核源码自带RTC驱动,在mach-xc2440.c中添加RTC设备
1.cz2440_devices[ ]结构体中加入:
&s3c_device_rtc,
&s3c_device_rtc,
2.配置内核,支持RTC:
Device Drivers --->
<*>Real Time Clock --->
[*]Set system time from RTC on startup and resume
(rtc0) rtc used to set the system time
[*]/sys/class/rtc/rtcN(sysfs)
[*]/proc/driver/rtc(procfs for rtc0)
[*]/dev/rtcN(character drivers)
<*>Samsung S3C series SoC RTC
Device Drivers --->
<*>Real Time Clock --->
[*]Set system time from RTC on startup and resume
(rtc0) rtc used to set the system time
[*]/sys/class/rtc/rtcN(sysfs)
[*]/proc/driver/rtc(procfs for rtc0)
[*]/dev/rtcN(character drivers)
<*>Samsung S3C series SoC RTC
启动时输出:
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
<十七> Watch Dog驱动移植
内核源码自带Watch Dog驱动,在mach-xc2440.c中添加Watch Dog设备
1.cz2440_devices[ ]结构体中加入:
&s3c_device_wdt,
&s3c_device_wdt,
2.配置内核,支持Watch Dog:
Device Drivers --->
[ ] Watchdog Timer Support --->
--- Watchdog Timer Support
<*> S3C2410 Watchdog
Device Drivers --->
[ ] Watchdog Timer Support --->
--- Watchdog Timer Support
<*> S3C2410 Watchdog
启动时输出:
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
0 0
- linux在s3c2440上的移植(二)
- U-boot在S3C2440上的移植详解(二)
- U-boot在S3C2440上的移植详解(二)
- U-boot在S3C2440上的移植详解(二)
- Linux 2.6.26 在S3C2440上的移植
- u-boot在S3C2440上的移植问题及解决方法集锦(二)
- U-boot在S3C2440上的移植详解(一)
- U-boot在S3C2440上的移植详解(三)
- U-boot在S3C2440上的移植详解(四)
- U-boot在S3C2440上的移植详解(五)
- U-boot在S3C2440上的移植详解(六)
- RTEMS在S3C2440上的移植-(1)
- RTEMS在S3C2440上的移植-(2)
- RTEMS在S3C2440上的移植-(3)
- RTEMS在S3C2440上的移植-(4)
- RTEMS在S3C2440上的移植-(5)
- U-boot在S3C2440上的移植详解(一)
- U-boot在S3C2440上的移植详解(一)
- Java面向对象(一)
- 机器学习中分类与聚类的本质区别
- eclipse安装ADT慢的龟速问题
- 连接有道网页仿写有道词典
- GDB调试release程序
- linux在s3c2440上的移植(二)
- LZW算法和GIF数据压缩
- SQL to Mongo Mapping Chart
- 欢迎使用CSDN-markdown编辑器
- 有关cascade的结构体
- 基于android平台开发的计算器
- 精髓的git stash
- Android Studio创建库项目及引用
- GDB指定和修改搜素源码文件的路径(set substitute-path)