Professional Documents
Culture Documents
Faraday and the Faraday Logo are trademarks of Faraday Technology Corporation in Taiwan and/or other countries.
Other company, product and service names may be trademarks or service marks of others.
All information contained in this document is subject to change without notice. The products described in this document are NOT intended for use in
implantation or other life support application where malfunction may result in injury or death to persons. The information contained in this document
does not affect or change Faraday's product specification or warranties. Nothing in this document shall operate as an express or implied license or
indemnity under the intellectual property rights of Faraday or third parties. All information contained in this document was obtained in specific
environments, and is presented as an illustration. The results obtained in other operating environments may vary.
THE INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED ON AN “AS IS” BASIS. In no event will Faraday be liable for damages
arising directly or indirectly from any use of the information contained in this document.
i
3.1.3 Driver Internals .......................................................................................... 38
3.1.4 Reference .................................................................................................. 40
3.2 MAC Driver.............................................................................................................40
3.2.1 Introduction................................................................................................ 40
3.2.2 MAC Driver Guide...................................................................................... 42
3.2.3 Driver Internals .......................................................................................... 47
3.2.4 Reference .................................................................................................. 49
3.3 Serial Driver............................................................................................................49
3.3.1 Introduction................................................................................................ 49
3.3.2 Serial Driver Guide .................................................................................... 50
3.3.3 Driver Internals .......................................................................................... 53
3.3.4 Reference .................................................................................................. 56
3.4 SD Driver................................................................................................................56
3.4.1 Introduction................................................................................................ 56
3.4.2 SD/MMC Driver Guide ............................................................................... 57
3.4.3 Driver Internals .......................................................................................... 59
3.4.4 User Applications for SD/MMC Driver ........................................................ 62
3.4.5 Make module method ................................................................................ 62
3.4.6 Reference .................................................................................................. 62
3.5 LCD Driver..............................................................................................................63
3.5.2 LCD Driver Guide ...................................................................................... 64
3.5.3 Driver Internals .......................................................................................... 68
3.5.4 Reference .................................................................................................. 72
3.6 PCI Driver...............................................................................................................72
3.6.1 Introduction................................................................................................ 72
3.6.2 PCI Driver Guide........................................................................................ 72
3.6.3 Verifying by Realtek 8139d Chip PCI Network Card .................................. 74
3.6.4 Driver Internals .......................................................................................... 77
3.6.5 Reference .................................................................................................. 78
3.7 Capture Application ................................................................................................78
3.7.1 Introduction................................................................................................ 78
3.7.2 Configuration Setting ................................................................................. 79
3.7.3 Work Flow.................................................................................................. 80
3.7.4 Result ........................................................................................................ 80
3.7.5 Reference .................................................................................................. 81
3.8 TV Encoder Driver Application................................................................................81
3.8.1 Introduction................................................................................................ 81
3.8.2 Configuration Setting ................................................................................. 81
3.8.3 Work Flow.................................................................................................. 82
ii
3.9 Audio Two-Way Application....................................................................................83
3.9.1 Introduction................................................................................................ 83
3.9.2 Configuration Setting ................................................................................. 83
3.9.3 Work Flow.................................................................................................. 84
3.10 Audio Player Application.........................................................................................84
3.10.1 Introduction................................................................................................ 84
3.10.2 Configuration Setting ................................................................................. 85
3.10.3 Work Flow.................................................................................................. 85
3.11 IDE Driver Guide ....................................................................................................87
3.11.1 Introduction................................................................................................ 87
3.11.2 IDE Driver Guide........................................................................................ 88
3.11.3 Driver Internals .......................................................................................... 93
3.11.4 Reference .................................................................................................. 95
3.12 USB OTG Device Driver .........................................................................................95
3.13 Output OSD Play Application................................................................................112
3.13.1 Introduction.............................................................................................. 112
3.13.2 Configuration Setting ............................................................................... 113
3.13.3 Work Flow................................................................................................ 113
3.14 MTD Driver ...........................................................................................................115
3.14.1 Introduction.............................................................................................. 115
3.14.2 Configuration Setting ............................................................................... 115
3.14.3 Work Flow................................................................................................ 117
3.15 Input OSD Function ..............................................................................................117
3.15.1 Introduction.............................................................................................. 117
3.15.2 Configuration Setting ............................................................................... 118
3.16 Color transform Application ..................................................................................118
3.16.1 Introduction.............................................................................................. 118
3.16.2 Work Flow................................................................................................ 118
3.17 RTC Function .......................................................................................................119
3.17.1 Introduction.............................................................................................. 119
3.17.2 Configuration Setting ............................................................................... 120
3.17.3 Source code ............................................................................................ 121
3.18 WatchDog Function ..............................................................................................121
3.18.1 Introduction.............................................................................................. 121
3.18.2 Configuration Setting ............................................................................... 123
3.18.3 Source code ............................................................................................ 123
3.19 I2C Function .........................................................................................................124
3.19.1 Introduction.............................................................................................. 124
3.19.2 Source code ............................................................................................ 126
iii
3.19.3 Access I2C-bus function in kernel mode.................................................. 126
3.19.4 Access I2C function in user mode............................................................ 128
Appendix A: Hardware Assignment ..........................................................................................................131
A.1: FIC8120 Board I/O Address Mapping and Interrupt Assignment..............................131
Appendix B: Load Image to Target SDRAM .............................................................................................134
B.1: Load Image to Target SDRAM by AXD....................................................................134
B.2: Load Image to Target SDRAM by Ethernet..............................................................134
B.3: Load Image to Target SDRAM by UART .................................................................134
Appendix C: Programming Flash ..............................................................................................................135
Appendix D: bootpImage Flow..................................................................................................................137
Appendix E: ramdisk Maintenance ...........................................................................................................139
E.1: Create a New ramdisk .............................................................................................139
E.2: Add/Remove Files from ramdisk Image ...................................................................139
iv
• LIST OF TABLES
v
Table A-2. I/O Address Assignment..................................................................................................132
Table C-1. Command List .................................................................................................................135
vi
• LIST OF FIGURES
vii
33. Figure 3-16. Kernel Configuration – CPE Serial Port Support ...........................................52
34. Figure 3-17. Linux Booting Message – Serial....................................................................53
35. Figure 3-18. UART Driver Architecture..............................................................................55
36. Figure 3-19. Kernel Configuration – File Systems .............................................................58
37. Figure 3-20. Kernel Configuration – MSDOS File Systems ...............................................58
38. Figure 3-21. SD Driver Auto-Load Script...........................................................................59
39. Figure 3-22. SD/MMC Driver Architecture .........................................................................60
40. Figure 3-23. Kernel Configuration – Character Devices ....................................................64
41. Figure 3-24. Kernel Configuration – Enable Virtual Terminal.............................................65
42. Figure 3-25. Kernel Configuration – Console Drivers ........................................................65
43. Figure 3-26. Kernel Configuration – Enable Faraday FTLCDC100 LCD Controller and set output
format ................................................................................................................................66
44. Figure 3-27. Kernel Configuration – Set LCD panel module..............................................67
45. Figure 3-28. Kernel Configuration – Enable 16 bpp Packed Pixels Support......................67
46. Figure 3-29. LCD Driver Architecture. ...............................................................................68
47. Figure 3-30. Kernel Configuration – General Setup ..........................................................73
48. Figure 3-31. Kernel Configuration – Enable PCI Support ..................................................73
49. Figure 3-32. Kernel Configuration – Network Device Support ...........................................74
50. Figure 3-33. Kernel Configuration – Ethernet (10 or 100 Mbit) ..........................................74
51. Figure 3-34. Kernel Configuration – RealTek PCI Card.....................................................75
52. Figure 3-35. Ethernet Card Initialize Status.......................................................................76
53. Figure 3-36. Verifying Connection of Ethernet by Ping......................................................76
54. Figure 3-37. PCI Driver Architecture .................................................................................77
55. Figure 3-38. Kernel Configuration for Capture Program ....................................................79
56. Figure 3-39. Kernel Configuration for TV Encoder Program ..............................................81
57. Figure 3-40. Kernel Configuration for TV Encoder Program (1).........................................82
58. Figure 3-41. Kernel Configuration for Audio Driver............................................................83
59. Figure 3-42. Kernel Configuration for Audio Driver............................................................85
60. Figure 3-43. Kernel Configuration – ATA/ATAPI/MFM/RLL Support .................................88
61. Figure 3-44. Kernel Configuration – IDE, ATA and ATAPI Block Devices .........................89
62. Figure 3-45. Kernel Configuration – Include IDE/ATA-2 DISK Support .............................89
63. Figure 3-46. Kernel Configuration – Faraday FTIDE020_S Support (PIO Mode) ..............90
64. Figure 3-47. Kernel Configuration – Faraday FTIDE020_S Support (DMA Mode) ............90
65. Figure 3-48. Linux Booting Message – IDE Driver with PIO Mode ....................................91
66. Figure 3-49. Linux Booting Message – IDE Driver with DMA Mode ..................................92
67. Figure 3-50. IDE Driver Architecture .................................................................................94
68. Figure 3-51. Kernel Configuration for GPIO Driver ..........................................................113
69. Figure 3-52. Kernel Configuration for MTD Driver ...........................................................115
viii
70. Figure 3-53. Kernel Configuration for MTD Memory Driver .............................................116
71. Figure 3-54. Kernel Configuration for MTD Mapping Driver ............................................116
72. Figure 3-55. Kernel Configuration for MTD JFFS2 File System.......................................117
73. Figure 3-56. Kernel Configuration for Input OSD Driver ..................................................118
74. Figure 3-57. Kernel Configuration for RTC Driver ...........................................................120
75. Figure 3-58. Kernel Configuration for RTC Driver ...........................................................123
76. Figure C-1. Physical Memory ..........................................................................................135
77. Figure D-1. Bus 16 bit width bootpImage Components ...................................................137
78. Figure D-2. Bootp Procedure ..........................................................................................137
ix
Chapter 1
Introduction
1
1.1 Version of the IP
Faraday’s MDC1 FIC8120 hardware environment is a highly efficient RISC-based platform for the purpose of
verifying and evaluating AMBA-based designs in the early development stage. The complete set of MDC1
FIC8120 platform consists of a main board (MB120) equipped with FIC8120 (FFA0AA016AA) chip and an
embedded Faraday FA526 CPU. This document contains the Linux programming guide for Faraday MDC1
FIC8120 platform. Please refer to FFA0AA016AA/FWAA198AA/MB120 documents for additional information.
There are two Linux versions involved in programming, the Linux, and the uClinux. The uClinux is a Linux
version without the Memory Management Unit (MMU). Faraday RISC FA526 is MMU-based CPU, while FA510
is not. Both FA526 and Faraday’s peripheral IP drivers have been ported to Linux. Chapter 1 of this document
contains the Linux user guide and the programming guide for peripheral IP drivers. Chapter 2 introduces
Linux distribution based on FA526. Chapter 3 introduces the programming guide of device drivers.
In Chapter 3, this document explains only the most basic device drivers; for further information on USB
device, Watchdog Timer, Real Time Clock, security engine, USB Host, and other latest drivers, please refer
to individual documents.
The required development environment of the host system developing Linux is listed as follows:
Hardware:
• Intel x86 compatible PC
• Standard 16550 UART
Software:
• Standard Linux distribution (RedHat 7.3 ~ 8.0 or above)
• FA526-based Linux distribution
2
The requirements of the target system developing Linux kernel and device drivers are listed as follows:
• Faraday MDC1 FIC8120
○ MB120 (including FIC8120)
○ 64 MB SDRAM on board
○ 32 MB Flash on board
3
Chapter 2
Linux Distribution Based on
FA526
5
2.1 Introduction
This chapter introduces FA526-based Linux architecture and implementations to help you understand and
install FA526-based Linux easily and quickly.
The FA526-Linux implements a Linux-2.4.19 software development environment for Faraday FA526
processor and peripheral IPs. With the information provided in this chapter, you can quickly install
FA526-Linux on Faraday MDC1 FIC8120 platform to implement your applications.
The following sections describe the system requirements as well as how to install FA526-Linux distribution.
The FA526-Linux distribution is a tar archive. The following is an example of how file name looks like:
arm-linux-20051230.tgz
The file name is a combination of “arm-linux-” and the released date, say “20051230”, which indicates that
this file is released on December 30, 2005.
6
2.1.2 Install FA526-Linux Distribution
The installation of FA526-Linux can be achieved by tar-archive extraction with the sequence stated below:
• Copy the file “arm-linux-20051230.tgz” to /usr/src directory
# cp arm-linux-20051230.tgz /usr/src
• Extract the file “arm-linux-20051230.tgz”
# cd /usr/src
# tar zxvf arm-linux-20051230.tgz
• Install toolchain (GCC-2.95.3, Binutils-2.11.2, and GLIBC-2.2.3) to directory /usr/local
# cp /usr/src/arm-linux/toolchain/arm-linux-toolchain.tgz /usr/local
# cd /usr/local
# tar zxvf arm-linux-toolchain.tgz
# rm -f arm-linux-toolchain.tgz
This step will extract the output files “GCC-2.95.3”, “Binutils-2.11.2”, and “GLIBC-2.2.3”
and stored in the directory /usr/local/arm.
• Add GCC execution path to shell environment
You can add the working path to your environment with the following command.
# export PATH=$PATH:/usr/local/arm/2.95.3/bin
For your convenience, you can edit the .bashrc file to add a line under BASH environment in
your home directory.
PATH=$PATH:/usr/local/arm/2.95.3/bin
After completing the installation steps, you can then build the FA526-Linux kernel or application.
7
2.1.3 FA526-Linux Directory Structure
Let us assume the top directory is /usr/src/arm-linux/. When you extract the tar archive like
“arm-linux-20051230.tgz” on /usr/src/arm-linux/, it builds a set of subdirectories as shown in Figure 2-1.
/usr/src
Arm-linux toolchain/
arm-linux-2.4.19/
user/
busybox-0.60.1
Customize Application
images/
ramdisk.gz
Customize Ramdisk
格式化: 不要貼齊格線
Table 2-2 lists the source directories and explains what type of files located in it. For example, the user
刪除: Table 2-2
application is located in /usr/src/arm-linux/user/ directory, while customized ramdisk is put in
格式化: 不使用拼字或文
/usr/src/arm-linux/images/ directory. 法檢查, 不要貼齊格線
格式化: 不要貼齊格線
Directory Description
8
2.2 Building and Developing FA526-Linux
This section explains how you can configure and build an FA526-Linux kernel for embedded system.
The structure of the FA526-Linux subdirectory is identical to that of standard Linux kernel version 2.4.19.
The following table shows the contents of the Linux kernel subdirectory. For the purpose of brevity, the
<TOPDIR> stands for the directory /usr/src/arm-linux/arm-linux-2.4.19.
This section tells you how to build the kernel image for FA526 architecture.
The first step to build Linux kernel is to configure kernel. The configuration file is located at
9
<TOPDIR>/.config for standard Linux.
10
In general, you may want to reconfigure FA526-Linux for one or more reasons stated below:
• Customized processor and board functionality: Modify UART clock, system clock, etc.
• Customized hardware devices: Add or remove particular devices.
• Customized kernel functionality: Add or remove a kernel feature such like network support.
There are two ways provided for Linux kernel to configure options mentioned above:
• Change to directory <TOPDIR>
1. Use menu display to select options for configuration:
# make menuconfig
2. Use GUI display to select options for configuration:
# make xconfig
Using GUI display to configure Linux kernel options is shown in Figure 2-2.
11
2. Figure 2-2. Linux Kernel Option Configuration Using GUI Display
Using menu display to select configuration options of Linux kernel is shown in Figure 2-3.
12
3. Figure 2-3. Linux Kernel Option Configuration Using Menu Display
13
The main options of FA526 system are as follows:
(CPE) ARM system type
Select CPE board to support Faraday CPE.
[*] Support FA526 processor
Set FA526 series processor option to support FA526 CPU.
(FIC8120) Platform environment
Choose setting from the following platforms:
A320: Faraday SoCreative! platform
FIC8120: Faraday MDC1 FIC8120 platform
FIE7000: Faraday FIE7000 platform
Please refer to A320/FIC8120/FIE7000 user guide for detailed information.
(110592000) System clock
The default system clock is 110 MHz for MDC1 FIC8120 platform. You must modify this clock based on
actual board setting. Please refer to A320/FIC8120/FIE7000 platform specification for more information.
(22118400) UART clock
The UART clock is 22.1184 MHz for MDC1 FIC8120 platform while the default UART clock is 22.1184 MHz
for FIC8120 platform. Please set UART clock based on actual board setting.
[ ] Disable I-Cache
[ ] Disable D-Cache
You can disable I-Cache and/or D-Cache by setting above configurations.
[ ] Disable Write Buffer
You can disable the cache write buffer by setting this configuration.
[ ] Force write through D-Cache
You can force FA526 cache to enter write-through mode. The default is write-back mode.
[ ] Idle mode support
You can use this configuration to enable CPU idle mode.
[ ] BTB support
You can use this configuration to enable branch target buffer (BTB).
14
2.2.2.2 Making the Kernel
If this is the first time for you to make Linux kernel, you may clean all object files and re-create the
dependency. If you modify the kernel configuration, you should also invoke “make dep” command. An
example is listed as follows:
# make clean
# make dep
FA526-Linux provides the shell-script “mkbootp.sh” for you to easily make the kernel.
# ./mkbootp.sh
It creates the final kernel image named bootpImage and kernel ELF file named vmlinux. You may modify
mkbootp.sh for one or more reasons stated below:
• Use customized ramdisk: Modify command “make bootpImage INITRD=<your ramdisk>” to specify
the name of your ramdisk. Please modify command “Default RAM disk size” to set your ramdisk size
格式化: 緊縮 0.3 pt
(refer to Figure 2-5). You can configure it with “make xconfig” command located at “Block devices”.
刪除: Figure 2-5
• Copy output image to specified directory: Modify the command “cp <source> <target>” in the
格式化: 不使用拼字或文
mkbootp.sh file to suit your requirement. 法檢查, 緊縮 0.3 pt
格式化: 緊縮 0.3 pt
15
5. Figure 2-5. Configuring the Size of RAM Disk
You can select either dynamic or static mode. When the dynamic mode is selected, ramdisk will link to
kernel image. When the static mode is selected, you can manipulate ramdisk start address and end
address by yourself, and therefore you must write ramdisk to these addresses manually.
16
2.2.2.3 Making IPCAM or IPTV Kernel
If your EVB is Faraday IPCAM, you must “cp IPCAM.config .config” , then run “make menuconfig” , don’t
need change any setting and then save again, run “make clean;make dep;./mkipcam.sh” , ramdisk name
is “IPCAM_V1_ramdisk.gz”and then we can get Linux image.
If your EVB is Faraday IPTV, you must “cp IPTV.config .config” , then run “make menuconfig” , don’t need
change any setting and then save again, run “make clean;make dep;./mkipcam.sh” , ramdisk name is
“IPCAM_V1_ramdisk.gz”and then we can get Linux image.
The FA526 ARMBOOT maintains the configuration file, faraday.h, to configure different hardware
environments. This file is located at /usr/src/arm-linux/armboot-1.1.0/faraday.h. You may want to
modify faraday.h for one or more reasons stated below, but in most case, you do not have to change its
values:
• Modify system clock. The default system clock is 44 MHz for MDC1 FIC8120 Platform.
• Modify UART clock. The UART clock is 22.1184 MHz for MDC1 FIC8120 Platform.
• Modify flash bank number. The flash bank number is 1 for MDC1 FIC8120 Platform.
17
#define SYSTEM_CLOCK 44000000 //44 MHz
#define UART_CLOCK 22118400 //22.1184 MHz ASIC version
#define CONFIG_FLASH_BANK 1 //bank 0,1,2,3,4,5,6,7
In addition to this, you may want to change MAC address to download Linux code to MediaCreative
platform. To this end, you must modify the definition - CONFIG_ETHADDR in
armboot-1.1.0/include/configs/config_cpe.h as shown in Figure 2-7, and the variable
ftmac100_mac_addr in armboot-1.1.0/drivers/ftmac100.c as shown is Figure 2-8.
static char ftmac100_mac_addr[] = {0x00, 0x40, 0x25, 0x00, 0x00, 0x01}; //MAC
Once you have modified MAC and IP, you can build ARMBOOT with the following commands:
# cd /usr/src/arm-linux/armboot-1.1.0
# make
It creates the file “armboot.bin” under the folder as shown in the first line. You should follow the
instruction to burn ARMBOOT into FIC8120’s flash, and write the specific image armboot.bin to the flash
address 0x80600000, with reference to the flash programming procedure provided in Appendix C.
18
FIC8120 Programming Guide
www.faraday-tech.com
19
2.3 FA526-Linux OS Loader – ARMBOOT
ARMBOOT is the famous OS loader in the Linux world. It is capable of loading image from terminal protocol
like kermit and booting Linux kernel. It also provides flash utilities and Ethernet TFTP transfer functions.
You can run the ARMBOOT code from flash or via ICE.
If the boot code (rominit.bin) and the ARMBOOT code are ready in EEPROM and flash, you can run
ARMBOOT from flash by keystroke ESC at the reset time. Please refer to Appendix E for information about
the CPE boot flow.
ARMBOOT maintains a number of environment variables for various functions. You can display them by the
following command.
CPE> printenv
20
You can set the environment value by the command “setenv name value” where “name” is the
environment variable name and “value” is the value you want to set. The following command is an example
to set IP address environment.
CPE> setenv ipaddr 192.168.52.48
The most commonly used commands in ARMBOOT are listed in Table 2-5. You can type “help” on the
ARMBOOT terminal to display the command list.
Command Description
21
2.3.4 ARMBOOT Flash Support
If you use ROM boot, you must define ROM init, if you use flash boot, you must define flash boot at
config_cpe.h file.
//#define PHYS_FLASH_1 0x80000000 /* Flash boot */
#define PHYS_FLASH_1 0x80400000 /* ROM boot */
Note: This armboot only support 16 bit flash, if you don’t use Faraday suggest flash type, you must check if
this program detect your flash type is ok.This program will show “yes” message such as :
FA526-Linux can be booted on the target system using either of the following two boot scenarios:
• Boot FA526-Linux via FA-ICE
• Boot FA526-Linux from ROM/Flash
You can load FA526-Linux kernel image to a specific address via FA-ICE and jump there. The procedure is
as follows:
• Load bootpImage to the address 0x2000000 (recommended) by AXD debugger. (Please refer
to Appendix B for the procedure.)
• Set PC to 0x2000000 on AXD debugger and run it.
You may wish to self-boot the Linux kernel from ROM/Flash automatically. To do this, specified boot code
and ARMBOOT code are required. The following procedure describes the way to boot FA526-Linux from
22
ROM/Flash automatically (case of 8-bit bus width).
• Prepare ROM code: Write the specific image rominit.bin to EEPROM.
• Prepare ARMBOOT code: Write the specific image armboot.bin to the flash address
0x80600000. You can refer to Appendix C for the flash programming procedure.
• Prepare Linux kernel image: Write the specific image mbootpImage to the flash address
0x80640000. You can refer to Appendix C for the flash programming procedure.
23
2.4.3 Booting FA526-Linux by ARMBOOT
In most parts of the development stage, you need to do iteration to modify code and/or download code
until you are satisfied with the result; under such condition, you need ARMBOOT to download and run code.
The required procedure is as follows:
• Set up tftp server on your Linux host, and set /etc/xinetd.d/tftp as shown in Figure 2-10.
• Use the Linux making shell (mkbootp.sh) within this package to compile code and generate
Linux code and put into the folder /tftpboot. To run Linux code, take the following steps:
1. Reset FIC8120 target
2. Select item “90) GO ARMBOOT”
3. Make sure IP addresses of Linux-Host and FIC8120 are correct, (printenv), as shown in
Figure 2-11.
4. Key in the command “tftp 0x2000000 mbootpImage” to download code as shown in
Figure 2-12.
5. Boot up Linux by the command “go 0x2000000”. You can see Linux boot-up message on
the screen as shown in Figure 2-13.
24
11. Figure 2-11. Environment Settings for ARMBOOT
25
13. Figure 2-13. Linux Message during Booting up
Since FA526-Linux uses MMU-based Linux kernel, it needs I/O memory mapping to access I/O peripheral.
The I/O address mapping on the FA526-Linux is defined in
“<TOPDIR>/arch/arm/mach-cpe/FIC8120.c” as shown in Figure 2-14. You can refer to the data
structure of map_desc in “<TOPDIR>/include/asm-arm/mach/map.h” as shown in Figure 2-15. The
most important item on map_desc is “virtual I/O address” and “physical I/O address” pair. Figure 2-14
26
shows an example of mapping virtual I/O address IO_ADDRESS (CPE_UART1_BASE) to physical I/O
address CPE_UART1_BASE for Faraday UART. The IO_ADDRESS() is defined in
“<TOPDIR>/include/asm/arch/cpe/FIC8120.h” as shown in Figure 2-16.
struct map_desc {
unsigned long virtual;
unsigned long physical;
unsigned long length;
int domain:4,
prot_read:1,
prot_write:1,
cacheable:1,
bufferable:1,
last:1;
};
27
2.5.2 Processor
28
Table 2-6. FA526 Processor Related Functions
29
Category Function Name Description
30
2.5.3 Timer
For Faraday FIC8120, all timer interrupts are IRQ. However, to ensure compatibility, you must use timer
2 in FIC8120. The related timer source files are listed in Table 2-7 below:
File Description
The layer relationship is demonstrated in Figure 2-17. Linux kernel boot-up procedure (main.c) calls
timer_init() to initialize timer function. Then setup_timer() is called to set up timer function and install
interrupt service routine. “cpe_time.c” provides low-level timer function to control the timer device.
main.c
timer.init0
setup-timer0
time.c time.h
fLib_Timer_xxx()
cpe_time.c
31
Table 2-8. Exception Handlers
USER Mode FIQ Mode IRQ Mode SVC Mode ABT Mode UNDEF Mode
FA526-Linux Distribution provides you with information on how to debug Linux kernel code and user
application programs.
AXD is used to debug Linux kernel on development host by FA-ICE (JTAG interface). AXD supports ELF
Dwarf-2 debug format that can also be generated by GCC compiler. The additional action you have to take
for debugging is to enable the “Include debugging information in kernel binary” option (make xconfig
-> General Setup -> kernel support for ELF binaries) on the kernel configuration.
32
• Launch “Load debug symbols” on AXD to load vmlinux image.
• You can debug Linux kernel now.
Note that the source level debugging supports C code only. Assembly code is not supported.
33
Chapter 3
Device Driver
This chapter serves as a guide to device driver programming for each component.
34
3.1 I2S Audio Driver
3.1.1 Introduction
Described below is the implementation of Faraday I2S audio driver on Linux operating system.
File Description
35
18. Figure 3-1. Kernel Configuration – Sound
36
19. Figure 3-2. Kernel Configuration – OSS Sound Modules
After booting the Linux kernel, you can play wave or mp3 audio file.
# madplay/audio/demo.mp3
37
The result will look like the one shown in Figure 3-3. You can listen to the music from the speaker that
connects to the audio line out.
This sub-section describes the Linux driver internal design including its features, architecture, and
functions.
The Open Sound System (OSS) driver supports several codec devices. The audio device is named
/dev/dsp. The user application uses /dev/dsp to play its music. The device number definition is as
follows.
• /dev/dsp • 14 • 3
38
Audio device driver uses the following features for performance and implementation:
AHB DMA: Audio driver uses AHB DMA to do data transfer for performance issue.
AHB ISR: When DMA completes the data transfer, interrupt service routine is triggered to do the next
transaction.
The Linux audio driver architecture is as shown in Figure 3-4. The file “fac97.c”/”fi2s.c” is the main
program of the audio driver. It uses the data structure “audio_driver” and registers the OSS driver by
the function “sound_install_audiodrv()”. After the registration is done, OSS layer uses its operation
to register device file system. The user application can use audio resource by /dev/dsp.
devfs_register_chrdev()
struct file_operations*
OSS Layer
sound_install_audiodrv()
struct audio_driver*
faudio.c
The most important task in the audio driver is to prepare audio driver structure and register OSS driver.
Table 3-3 describes the major functions the audio driver implements.
• ssp_open • This routine is called whenever audio port is opened. It enables I2S controller.
39
Major Function Description
• ssp_close • This routine is called to close audio driver and release audio resource.
• ssp_output_block • This routine is called to give data information for audio driver to send data to audio device.
• This routine is called to give data information for audio driver to receive data from audio
• ssp_start_input
device.
• ssp_prepare_for_o • This routine is called to set up SSP clock division prepared for output
utput
• ssp_prepare_for_ • This routine is called to set up SSP clock division prepared for input
input
• ssp_halt • This routine is called to halt SSP input or output transfer
• ssp_halt_input • This routine is called to halt SSP input transfer
• ssp_halt_output • This routine is called to halt SSP output transfer
• ssp_trigger • This routine is called to trigger SSP DMA transfer
• ssp_set_speed • This routine is called to set up audio device sample rate
• ssp_set_bit • This routine is called to set up data size and endianness
• ssp_interrupt_han • This routine is called when under-run or over-run event is triggered
dler
• dma_interrupt_ha • This routine is called when DMA transfer is completed and the interrupt service routine is
ndler triggered to do the next transaction
• ssp_record • This routine is called to record sound data
• ssp_play • This routine is called to play sound data
3.1.4 Reference
3.2.1 Introduction
Described below is the implementation of Faraday MAC driver on Linux operating system.
40
FIC8120 Programming Guide
www.faraday-tech.com
41
3.2.1.1 MAC I/O Resource Overview
Faraday’s MAC I/O resource and memory are briefly listed in Appendix A.
FA526-Linux provides the MAC driver to implement the network function. The related files on Linux are
shown in Table 3-4. Please note that <TOPDIR> is the top path of the kernel source tree.
File Description
To activate Faraday MAC function, you have to select some options in the kernel configuration menu.
These options include enabling Linux network support, Ethernet (10 or 100 Mb/s) and then Faraday
FTMAC100 support. Figure 3-6 shows the networking support on the kernel configuration (Main Menu
-> General Setup). Figure 3-9 shows the Faraday FTMAC100 support (Main Menu -> Network Device
Support -> Ethernet (10 or 100 Mb/s) -> Faraday FTMAC100 Support). The option “Faraday
FTMAC100-2” is reserved for selection in case two MACs are supported in future platforms. Presently
FIC8120 only supports one MAC. Depending on your requirement, you may select your specified
network protocol from the option “Networking options.”
After the configuration is finished, you can make your kernel for Faraday MAC driver support.
42
22. Figure 3-5. Kernel Configuration – General Setup
23. Figure 3-6. Kernel Configuration – General Setup -> Networking Support
43
24. Figure 3-7. Kernel Configuration – General Setup -> Networking Support (1)
25. Figure 3-8. Kernel Configuration – General Setup -> Networking Support (2)
44
26. Figure 3-9. Kernel Configuration for Faraday FTMAC100 Support
After compiling Linux kernel with these options, Linux will run and the terminal will show a booting
message as shown in Figure 3-10. You can see the FTMAC100 description in the booting message if it
works.
When the shell starts, you can do some network test. For example, you can execute the following
commands to set up the Ethernet MAC address and IP address:
# ifconfig eth0 hw ether 00:11:22:33:44:55
# ifconfig eth0 192.168.121.139
The results of these commands look like the one shown in Figure 3-11. Now, you can start to use
network function.
45
27. Figure 3-10. Linux Booting Message – MAC
46
3.2.3 Driver Internals
This section describes the Linux driver internal design including its features, architecture, and
functions.
Linux MAC driver uses the device name “/dev/eth” for user applications. You do not have to create
“/dev/eth” because it is dynamically created. The MAC device driver uses its DMA feature to transmit
or receive packets. It implements interrupt service routine to handle Rx FIFO data or error.
The Linux MAC driver architecture is as shown in Figure 3-12. The file “ftmac100.c” is the main program
of the network device driver. It implements network device operations and processes data from and to
the protocol layer. User application uses socket to program its network functions.
U s e r A p p lic a tio n
s o c k e t fu n c tio n
S o c k e t In te rfa c e
N e tw o rk P ro to c o l S ta c k s / n e t / *
n e tif_ rx ()
s tru c t n e t_ d e v ic e *
ftm a c 1 0 0 .c
R J45
The most important task of the MAC driver is to implement net_device operations. Table 3-5 describes
the major functions in "ftmac100.c”. You may refer to the source code to obtain more detailed
47
information.
48
Table 3-5. FMAC Driver Functions
You can use "ethtool" utility in file system to change the MAC media type in user space.
For example, "# ./ethtool -s eth0 speed 10 duplex half autoneg off".
3.2.4 Reference
3.3.1 Introduction
Described below is the implementation of Faraday serial driver on Linux operating system.
Faraday’s serial I/O resource and memory are briefly listed in Appendix A. Please refer to Table 3-6 for
UART clock setting.
49
Table 3-6. UART Clock
Platform
FIC8120
Device
FA526-Linux provides the UART driver to implement the tty/console driver. The related files on Linux
are shown in Table 3-7. Please note that <TOPDIR> is the top path of the kernel source tree.
File Description
To activate Faraday UART function, you have to select some options in the kernel configuration. These
options include enabling serial port, setting its baud rate to 38400 and selecting UART1 to be the kernel
console port. Figure 3-13 shows the UART clock setting on the kernel configuration (Main Menu ->
System Type). Figure 3-15 shows the serial port support (Main Menu -> Character Devices).
50
30. Figure 3-13. Kernel Configuration – System Type
51
32. Figure 3-15. Kernel Configuration – Character Devices
After compiling Linux kernel with these options, Linux will run and the terminal will show a booting
message as shown in Figure 3-17. You can see the Faraday UART description in the booting message
52
if it works. Note that the terminal on the host must be set to the same baud rate as the target.
• /dev/ttyS0 • 4 • 64
• /dev/ttyS1 • 4 • 65
53
• /dev/ttyS2 • 4 • 66
• /dev/ttyS3 • 4 • 67
The UART device driver does not use any DMA feature. It implements interrupt routine to service Rx FIFO
data.
54
3.3.3.2 Driver Architecture
The Linux UART driver architecture is as shown in Figure 3-18. The file “serial_cpe.c” is the main
program of the UART driver. It provides the data structure “tty_driver” and registers the tty driver by
the function “tty_register_driver()”. After registering the tty driver, the function
“register_chrdev()” is called to register the character device. After the registration is done, the user
program can use the UART function through “dev/ttyS0”.
fs/device.c
register_chrdev() /dev/ttyS0
struct file_operations*
tty_io.c
tty_register_driver()
struct tty_driver*
serial_cpe.c
The most important task of the UART driver is to prepare the tty_driver structure and register the tty
driver. Table 3-9 describes the “tty_driver” structure and the major functions implemented by
“serial_cpe.c”. You may browse the source code to get more details.
• rs_open • This routine is called whenever a serial port is opened. It enables interrupts for a serial
port.
• rs_close • This routine is called when the serial port gets closed.
• rs_write • This routine is called to write data to tty driver buffer before writing to UART.
55
Major Function Description
• rs_flush_chars • This routine is called by the kernel after writing a number of characters to the tty device
using put_char.
• rs_ioctl • This routine is called to set or get some control parameters.
• rs_write_room • This routine returns the number of characters the tty device will accept for writing.
• rs_chars_in_buffer • This routine returns the number of characters the tty device has buffered.
• rs_throttle • This routine tells the tty driver that the input buffers of the line discipline are close to full.
• rs_unthroottle • This routine tells the tty driver that the input buffers of the line discipline have enough
space.
• rs_send_xchar • This routine is used to send a high-priority XON-XOFF character to the device.
• rs_set_termios • This routine is used to notify the tty driver of a change of “termios”.
• rs_stop • This routine stops the tty driver from sending out characters to the tty device.
• rs_start • This routine enables the tty driver to start sending out characters to the device.
• rs_read_proc • This routine is used to read tty information from /proc file system.
• rs_write_proc • This routine is used to write tty information from /proc file system.
• rs_interrupt_single • Serial driver’s interrupt routine for a single port.
3.3.4 Reference
3.4 SD Driver
3.4.1 Introduction
Described below is the implementation of Faraday SD/MMC driver on Linux operating system, designed
to let you have a clear understanding of the SD/MMC driver design and its hardware information.
The I/O and interrupt resources of Faraday’s SD/MMC IP are listed in Appendix A.
56
3.4.1.2 Source File Overview
To activate the SD/MMC functions, you must provide Linux SD/MMC driver source code in FA526-Linux
kernel. The related files are shown in Table 3-10.
File Description
Linux SD/MMC driver is based on the device node “/dev/cpesda” for user applications. Detailed
information is shown in the following table.
• /dev/cpesda • 6 • 0
• /dev/cpesdb • 6 • 1
Please note that the SD/MMC driver supports hot-swap operation. You can insert and remove the
SD/MMC card at any time. However, you should never hot-swap the SD/MMC card when it is reading or
writing.
In order to be compatible with modern USB SD card reader on PC platform, the SD/MMC driver should
additionally add some options to support MSDOS and VFAT file system as shown in Figure 3-19 and
Figure 3-20.
57
36. Figure 3-19. Kernel Configuration – File Systems
After the kernel and user shell get started, you can execute script “./ffmpeg/mountsd_bat” to load SD
driver, create device node and mount the device. Please refer to Figure 3-21 for the contents of the
script “./ffmpeg/mountsd_bat”.
58
38. Figure 3-21. SD Driver Auto-Load Script
After that, you can change directory to /mnt/sddisk/ and then perform file read/write.
This section describes the Linux SD/MMC driver internal design including its features, architecture, and
operations.
59
U s e r A p p lic a tio n s
F ile S y ste m s
/d e v/cp e s d a
cpesd.c
S D C o n tro lle r
S D / M M C C a rd
• Register the driver as a block driver with major number 6 and initialize some
• sd_module_init()
standard parameters for block driver
• sd_module_cleanup() • Un-register the driver and release allocated resources
• sd_card_setup() • Initialize SD controller and re-read the SD/MMC card information
• sd_request() • Treat the block requests for the SD/MMC block driver
• sd_transfer()
• sd_revalidate() • Re-validate SD/MMC card status and get its information after mounted
• sd_dma_interrupt_handler() • Handle DMA interrupt
• sd_hotswap_interrupt_handler
• Handle SD/MMC card hot-swap interrupt
()
• sd_ioctl() • Specific IOCTL functions of SD/MMC block driver
• sd_open() • SD/MMC block driver startup function
• sd_release() • SD/MMC block driver release function
60
• sd_check_change() • SD/MMC block driver media check function
61
3.4.4 User Applications for SD/MMC Driver
After the kernel and user shell are started, you should check the device node “/dev/cpesda” for the
SD/MMC driver. If the device node does not exist, you should refer to the following commands to create
it:
# mknod /dev/cpesda b 6 0
Now, you can plug an SD or MMC card into the CPE SD/MMC slot. If the SD or MMC card is a new one,
you can use the “mkdosfs” command to format it.
# mkdosfs /dev/cpesda
“/dev/cpesda” is the same as many block devices and you can use many block commands such as
“mount/cp/mkdir/…” to access the SD or MMC cards.
# mount –t msdos /dev/cpesda /mnt
After that, you may read the file “/etc/inittab” from the SD/MMC card reader on PC.
Our Linux package SD driver type is module, so if you want to compiler driver again, please write “make
modules” after you compiler kernel ready. Or you can change xconfig SD driver setting from “M” to “*”
and compiler again, and our CPESD_DMA.o driver only change name form sd.o
3.4.6 Reference
62
3.5 LCD Driver
Described below is the implementation of Faraday FTLCDC100 LCD frame buffer driver on Linux
operation system.
63
3.5.1.1 LCD I/O Resource
To activate the LCD functions, you have to provide LCD frame buffer driver source code in FA526-Linux
kernel. The related files are shown in the following table. Please note that <TOPDIR> is the top path of
the kernel source tree.
File Description
• <TOPDIR>/drivers/video/pl110fb.h • Definitions related to Linux LCD driver
• <TOPDIR>/drivers/video/flcd.c • Main code of Linux LCD driver
To activate Faraday LCD function, you have to select some options in the kernel configuration menu.
Please refer to the following figures to set up LCD frame buffer driver (by the command “make
menuconfig”).
64
41. Figure 3-24. Kernel Configuration – Enable Virtual Terminal
65
43. Figure 3-26. Kernel Configuration – Enable Faraday FTLCDC100 LCD Controller and set output format
66
44. Figure 3-27. Kernel Configuration – Set LCD panel module
45. Figure 3-28. Kernel Configuration – Enable 16 bpp Packed Pixels Support
After configuration, you should make the kernel image, upload kernel to target system and boot it. With
the LCD frame buffer driver, you should see a penguin at the top left corner of the LCD monitor.
67
3.5.3 Driver Internals
This section describes the Linux LCD frame buffer driver internal design including its features,
architecture, and operations.
Linux LCD frame buffer driver is based on device node “/dev/fb*” for user applications. The detailed
information is shown in the following table.
• /dev/fb0 • 29 • 0
This section describes Linux LCD frame buffer driver architecture as shown in the following figure. The
file “flcd.c” is the main code of LCD frame buffer driver. It implements LCD function and processes data
between GUI system and frame buffer.
Low
Level Fbcon-afb.c Amifb.c Frame
Drivers Buffer
Devices
Fbcon-cfb8.c flcd.c
... ...
68
3.5.3.3 Driver Functions
• •
define FLCD_GET_DATA_SEP 0x46db t will get LCD flcd_data value
•
truct flcd_data
•
•
nsigned int phy_start_addr;
•
nsigned int user_start_addr;
•
nsigned int buf_len;
•
nsigned int frame_no;
•
nsigned int mp4_map_dma[CONFIG_PP_FRAME_NO];
•
;
• •
69
IOCTL Command Description
define FLCD_SET_FB_NUM 0x46dd t will set frame buffer to 0~n and display to LCD, it will be
trigger by interrupt happen
• •
define FLCD_SWITCH_MODE 0x46de t will switch to FLCD_MODE_YCBCR or FLCD MODE_RGB,
FLCD MODE_RGB = 0, FLCD_MODE_YCBCR = 1
• •
define FLCD_SET_SPECIAL_FB 0x46df t will set frame buffer to 0~n and display to LCD
• •
define FOSD_ON 0x46e6 t will enable OSD function
• •
define FOSD_OFF 0x46e7 t will disable OSD function
• •
define FOSD_SETPOS 0x46e1 t will set OSD position value
• •
define FOSD_SETDIM 0x46e2 t will set OSD dimension value
• •
define FOSD_SETSCAL 0x46e3 t will set OSD scaling value
• •
define LCD_SET_TRANSPARENT 0x46e4 t will set OSD transparency control level
• •
define FLCD_SET_STRING 0x46e5 t will set OSD string structure value
struct fosd_string {
unsigned int Str_row; // Character address in memory, start address is zero, second string
unsigned int display_mode; // RGB or YCbCr mode
unsigned int fg_color; // String foreground color
unsigned int bg_color; // String background color
unsigned char Str_OSD[30]; // String length, only support length 30
};
struct fosd_data {
unsigned int Hs; // Horizontal position
unsigned int VPos; // Vertical position
unsigned int HDim; // Horizontal dimension
unsigned int VDim; // Vertical dimension
unsigned int transparent_level; // Transparency control level
unsigned int HScal; // Horizontal scaling
unsigned int VScal; // Vertical scaling
70
struct fosd_string Str_Data[10]; // Display string, only support 10 string one frame
};
71
3.5.4 Reference
3.6.1 Introduction
Described below is the implementation of PCI driver on Linux operation system, designed to let you
have a clear understanding of the LCD frame buffer driver design and its hardware information.
Faraday’s PCI I/O resource and memory are briefly listed in Appendix A.
To activate the PCI functions, you have to provide PCI driver source code in FA526-Linux kernel. The
related files are shown in the following table. Please note that <TOPDIR> is the top path of the kernel
source tree.
File Description
72
3.6.2.1 Kernel for PCI Driver
To activate Faraday PCI function, you have to select some options in the kernel configuration menu.
Please refer to the following figures to set up PCI driver (by the command “make xconfig”).
After configuration, you should make the kernel image, upload kernel to target system and boot it.
73
3.6.3 Verifying by Realtek 8139d Chip PCI Network Card
We use a Realtek 8139d chip PCI network card to test whether PCI controller is functional. To support
this card, you have to select some options in the kernel configuration menu. Please refer to the
following figures to add support for Realtek 8139d chip PCI network card (by the command “make
xconfig”).
74
51. Figure 3-34. Kernel Configuration – RealTek PCI Card
After compiling Linux kernel with these options, Linux will run and the terminal will show a booting
message as shown in Figure 3-35. You can see the RTL8139 description in the booting message if it
works.
When the shell starts, you can do some network test. For example, you can execute the following
commands to set up the Ethernet MAC address and IP address:
# ifconfig eth0 hw ether 00:11:22:33:44:55
# ifconfig eth0 192.168.131.151
Then you can check connection status by “ifconfig” command. Try to ping another network device by
the following command:
# ping 192.168.131.40
The result will look like the one shown in Figure 3-36. Now, you can start to use the network function.
75
52. Figure 3-35. Ethernet Card Initialize Status
76
3.6.4 Driver Internals
This section describes the Linux PCI controller driver internal design including its features, architecture,
and operations.
The architecture of Linux PCI subsystem is shown in the following figure. The PCI subsystem in Linux
is divided into three logical parts:
• PCI Device Driver
• PCI BIOS
• PCI Fixup
Where the “PCI Device Driver” part searches the PCI system starting at Bus 0 and locates all PCI
devices and bridges in the system, building a linked list of data structures describing the topology of the
system. The “PCI BIOS” part provides services described in pci-bios specification. The “PCI Fixup” part
implements system specific part of PCI.
The file “ftpci.c” is the main code of PCI controller driver, which is system specific. Its primary function
is to initialize PCI controller and provide some basic functions to access PCI configuration space.
PCI
PCI device driver
driver
PCI card
PCI fixup
PCI fixup PCI card driver
driver
PCI
PCI bios
bios
Ftpci.c
Ftpci.c
PCI card
PCI card
77
3.6.4.2 Driver Functions
3.6.5 Reference
3.7.1 Introduction
78
3.7.2 Configuration Setting
Before you run this program, you must enable Faraday TV / LCD or VGA item and configure display
mode. After compiling Linux kernel with these options, Linux will run and the terminal will show a
booting message as shown below. You can see the message if it works.
79
3.7.3 Work Flow
init LCD
open("/dev/fb0", O_RDWR)
init capture
open("/dev/video0", O_RDWR)
ioctl(video_fd,VIDIOCGMBUF,&gb_buffers)
Yes
read_key= q? Exit
No
Once the data input is ready, you can capture the driver mode from CMOS censor or TV_in by copy
Y/U/V base address to LCD display and tune the address to meet 720x480 display size. If you wish to
capture the 640x480 image, you must copy the 640 bytes to LCD memory and shift 80 bytes address
to next line.
3.7.4 Result
# cd ffmpeg/
/ffmpeg # ./ffmpeg -focus 640x480
Main Thread ID = 20
Press [q] to stop previewing
0x84 q
0x85 /ffmpeg #
/ffmpeg #
80
3.7.5 Reference
3.8.1 Introduction
81
57. Figure 3-40. Kernel Configuration for TV Encoder Program (1)
Before running this program, you must enable Faraday TV encoder item with default display mode set
at YUV. After compiling Linux kernel with these options, Linux will run and the terminal will show a
booting message. The Video endpoint is linked with TV-out port. You can see the message if it works,
and the picture is displayed on TV screen too. (Please note that this is a software decode JPEG file, not
an MP4 hardware decode method.)
82
display_tv.sh file
• ./convert $1 tmp.miff
• ./24toycbcr 420 tmp.miff tmp.rgb
• ./tvshow tmp.rgb
Note: You must convert 24toycbcr and tvshow execution files to proceed.
3.9.1 Introduction
Before running this program, you must enable Faraday audio driver and compile Linux kernel with this
option. To use full duplex audio function, you have to create two devices /dev/dsp and /dev/dsp1. The
two devices can perform play and record function with the same sampling rate at the same time.
83
3.9.3 Work Flow
• Play audio from PC or DVD, and then plug the line in.
• Move to tmp directory and run audio.sh.
vrec2 -wS -t 20 -s 32000 -b 16 test.wav &
The audio program vrec2 uses /dev/dsp1 to be the driver device.
• Play audio like “vplay 32k.wav” from FIC8120 platform.
The audio program vplay uses /dev/dsp to be the driver device.
• Play the previously recorded “test.wav”.
Argument:
3.10.1 Introduction
Described below is the execution of Faraday Audio Player – mp3, AAC, WMA programs.
84
3.10.2 Configuration Setting
Before running this program, you must enable Faraday audio driver and compile Linux kernel with this
option.
Result
======================================
Faraday MPEG Audio Decoder (FMAD) V1.0
Demo Version
======================================
00:00:12, Layer 3, 128 kbps, 44100 kHz, stereo, Normal
85
Play AAC
Command
Play => ./faac 1.m4a /dev/dsp 0
Exit => Ctrl + C
Result
=====================================================
Faraday MPEG-4 AAC Decoder (FAAC-MP4) V1.0
Demo Version
=====================================================
1.m4a file info:
LC AAC 199.427 secs, 2 ch, 44100 Hz
44100 Hz, 2 ch, 138 kbps, 00:00:04
Play WMA
Command
Play => ./fwma test.wma /dev/dsp
Exit => Ctrl + C
Result
=====================================================
Faraday Windows Media Audio V8 Decoder (FWMA8) V0.1
=====================================================
44100 khz, stereo, 64 kbps, No DRM, 00 : 00 : 05
86
3.11 IDE Driver Guide
3.11.1 Introduction
This document describes how Faraday CPE platforms support IDE devices on Linux operating system.
You have to provide two interfaces to IDE device, but only one can be used at a time. Therefore, only
information necessary for enabling IDE devices on Faraday’s CPE platforms is provided below.
The I/O and interrupt resources for Faraday IDE controller on Faraday’s platforms – FIC8120 – is
described below. It is the responsibility of the IDE driver to allocate the resources. Please refer to Table
格式化: 使用拼字與文法檢查
3-17 and Table 3-18 for detailed information.
格式化: 使用拼字與文法檢查
刪除: Table 3-17
格式化: 使用拼字與文法檢查
Table 3-17. IDE Interrupt Number
格式化: 使用拼字與文法檢查
• IDE • 27 (IRQ)
Platform
FIC8120
Device
• IDE • 0x91400000
Linux kernel has provided thorough IDE driver source codes. Before reading them, you should have the
ATAPI specifications in hand. The related files are shown in the path “<TOPDIR>/drivers/ide/*.*”.
Please note that <TOPDIR> is the top path of the kernel source tree.
87
Table 3-19. IDE Source File List
File Description
To allow Faraday’s platforms, FIC8120, to support IDE devices, you have to select some options in the
kernel configuration menu (by the command “make xconfig”). Please refer to Figure 3-43 through
Figure 3-47 for the IDE driver setup.
88
61. Figure 3-44. Kernel Configuration – IDE, ATA and ATAPI Block Devices
89
63. Figure 3-46. Kernel Configuration – Faraday FTIDE020_S Support (PIO Mode)
64. Figure 3-47. Kernel Configuration – Faraday FTIDE020_S Support (DMA Mode)
90
After configuration, you should make the kernel image, upload the kernel to the target system and boot
it. With the IDE driver, you would read the booting messages as shown in Figure 3-48 with PIO mode
刪除: Figure 3-49
enabled and Figure 3-49 with DMA mode enabled.
65. Figure 3-48. Linux Booting Message – IDE Driver with PIO Mode
91
66. Figure 3-49. Linux Booting Message – IDE Driver with DMA Mode
After the kernel and user shell are started, you should check the device nodes ”/dev/hda* ~ /dev/hdb*”
for the IDE devices. If the device nodes do not exist, you should refer to the following commands to create
them:
# cd /dev
# mknod hda b 3 0
# mknod hda1 b 3 1
# mknod hdb b 3 64
# mknod hdb1 b 3 65
The device nodes accessed by applications depend on the IDE connection. If your IDE device is a
master device connected to the first connector of a cable, the IDE device will be presented in
“/dev/hda”. If there is an IDE hard disk without partitioning, you may use the “fdisk” command to
create partitions and “mkdosfs” command to format it for instant testing.
92
# fdisk /dev/hda
# mkdosfs /dev/hda1
# mount –t msdos /dev/hda1 /mnt
# umount /dev/hda1
This section describes the Linux IDE driver internal design including its features, architecture, and
operations.
Linux IDE driver is based on the device node “/dev/hd*” for user applications. Detailed information is
shown in Table 3-20.
• /dev/hda • 3 • 0
• /dev/hda1 • 3 • 1
• /dev/hdaX • 3 • X
• /dev/hdb • 3 • 64
• /dev/hdb1 • 3 • 65
• /dev/hdbX • 3 • X+64
• /dev/hdc • 22 • 0
• /dev/hdc1 • 22 • 1
• /dev/hdcX • 22 • X
• /dev/hdd • 22 • 64
• /dev/hdd1 • 22 • 65
• /dev/hddX • 22 • X+64
93
3.11.3.2 Driver Architecture
The Linux IDE driver architecture is as shown in Figure 3-50. The file “ide.c” is the main code of the IDE
driver. It implements IDE function and processes data between file systems and IDE controller. User
applications can access the data in the IDE devices directly via the IDE driver or file systems.
User Applications
File Systems
/dev/hd*
ide.c
IDE Controller
IDE Devices
As mentioned above, before tracing the IDE source code, please refer to the ATAPI specification and the
related Linux kernel documents. Table 3-21 lists the major functions in “cpeide.c”.
• Initializes IDE controller state and register the device information to hardware
• ide_probe_for_cpeide()
interface structure
• cpeide_tune_drive() • Routine to tune PIO mode for drives
94
Major Function Description
3.11.4 Reference
• ATA/ATAPI specification
• Linux Device Drivers, 2nd Edition
95
Major Function Description
z Remove Sequence:
FTC_usb_remove() Tear down the binding between this driver and the pci device
96
Major Function Description
97
vUsb_ep0rx() Process the event after receiving Control-Out packet
vUsb_ep0fail() Process the event after receiving error from HW (Detail please
reference HW datasheet)
98
<4> Select the “Support for USB gadgets” button
99
<8> Build a ram disk image, named the ramdisk as “ram.img”, and copy the ramdisk into your
Linux-image’s ramdisk
<9> After system have bootup, enter command “FOTG_ap e” to enable peripheral mode function
100
<4> Select the “Support for USB gadgets” button
101
3.12.3.3 Built-in FOTG200 with Peripheral mode only
<1> Select the “USB support” button
102
<4> Select the “Support for USB gadgets” button
103
<8> Build a ram disk image, named the ramdisk as “ram.img”, and copy the ramdisk into your
Linux-image’s ramdisk
<9> After system have bootup, enter command “FOTG_ap e” to enable peripheral mode function
104
<4> Select the “Support for USB gadgets” button
105
<8> Build a ram disk image, named the ramdisk as “ram.img”, and copy the ramdisk into your
Linux-image’s ramdisk
<9> Copy gadget and mass storage driver modules into your Linux-image’s ramdisk
<10> After system have bootup, insert driver modules first, then
enter command “FOTG_ap e” to enable peripheral mode function
106
<4> Select the “USB Mass Storage support” button as ‘y’
<5> Select the “USB Mass Storage verbose debug” button as ‘y’
107
<7> Select the “SCSI support” button as ‘y’
<8> Select the “SCSI disk support” button as ‘y’
<9> Keep the default value in “Maximum number of SCSI disks that can be loaded as modules”
filed
<10> After system have bootup, plug the mass storage device in, the message shown which device
node has inserted
<11> If “File systems”Æ”/dev file system support” selected as ‘y’, the following information
represents one partition is existing in scsi disk ‘sda’ and named as ‘sda1’
108
<12> If “File systems”Æ”/dev file system support” selected as ‘n’, the following information
represents one partition is existing in scsi disk ‘sda’ and named as ‘sda1’
109
3.12.5 FOTG200 Peripheral mode execution
<1> Remind that current FOTG200 peripheral mode only provides mass storage class
<2> Enable FOTG200 peripheral mode first, the steps already describe as above
<3> After plug EVB to PC via usb cable, the message will display as following
110
<4> One new removable drive is appeared in My Computer folder
111
3.12.6 Reference
● Faraday USB2.0 On-The-Go Controller Datasheet
● Linux Device Drivers, 2nd Edition
Available at website http://www.oreilly.com/catalog/linuxdrive3/
3.13.1 Introduction
112
3.13.2 Configuration Setting
Before running this program, you must enable both Faraday GPIO and LCD driver.
OSD Play
Command
Play => osdplay “directory” such as /mnt/sddisk
113
Result
(Select item 1)
====================================================
====================================================
00:09, Layer 3, 128 kbps, 44100 Hz, stereo, Normal kill 28 thread
play item 1
Run fwma /mnt/sddisk/1.wma
(Select item 2)
=====================================================
=====================================================
kill 29 threadreo, 64 kbps, No DRM, 00 : 00 : 02
play item 2
Run faac /mnt/sddisk/1.m4a
=====================================================
Faraday MPEG-4 AAC Decoder (FAAC-MP4) V1.0
Demo Version
=====================================================
/mnt/sddisk/1.m4a file info:
(Select item 0)
kill 30 thread, 138 kbps, 00:00:04
play item 0
Run fmad /mnt/sddisk/1.mp3
====================================================
====================================================
01:20, Layer 3, 128 kbps, 44100 Hz, stereo, Normal
114
• M4A file name must be “1.m4a”
• WMA file name must be “1.wma”
3.14.1 Introduction
115
70. Figure 3-53. Kernel Configuration for MTD Memory Driver
116
72. Figure 3-55. Kernel Configuration for MTD JFFS2 File System
Mount MTD
Command
• mkdir /mnt/mtd
• mount -t jffs2 /dev/mtdblock1 /mnt/mtd
Read/write enabled. When the read/write command is completed, the ramdisk must be un-mounted.
• umount /mnt/mtd
The default MTD ramdisk size is set at 1MB. If you were to boot from EEPROM, then you must erase
your address at 0x80500000 and size 0x100000 before you use MTD. If you were to boot from Flash,
then you must erase your address at 0x80100000.
3.15.1 Introduction
117
3.15.2 Configuration Setting
When you run ffmpeg function, input video and input OSD character will be merged together and put
into capture memory.
Note: Only support for D version FIC8120 later
3.16.1 Introduction
Described below is the method to use Color transform from RGB to YUV function. When you select LCD
YUV mode, if your video output GUI is RGB format, you must transfer RGB to YUV first. Now we can use
this function to transfer RGB to YUV, you only have to select a region for MP4 YUV output, and other
region we will be color transform from RGB to YUV.
You can update arm-linux-2.4.19\drivers\video\flcd.c file to enable this define and see the result,
118
• #ifdef CONFIG_TEST_COLORTRANS //test half RGB and YUV penguin
• *(volatile unsigned int *)(CPE_PMU_VA_BASE + 0x28) = (*(volatile unsigned int *)(CPE_PMU_VA_BASE +
0x28)) | (1 << 8);
•
• printk("Test color transform function data clampping (100,0~420,240)RGB -> YCbCr422\n");
• *(unsigned int *)(CPE_COLORTRANS_VA_BASE + 0x4) = (100/4)-1;
• *(unsigned int *)(CPE_COLORTRANS_VA_BASE + 0x8) = 0;
• *(unsigned int *)(CPE_COLORTRANS_VA_BASE + 0xc) = (420/4)-1;
• *(unsigned int *)(CPE_COLORTRANS_VA_BASE + 0x10) = (240/2)-1;
• *(unsigned int *)(CPE_COLORTRANS_VA_BASE + 0x0) = (*(unsigned int
*)(CPE_COLORTRANS_VA_BASE + 0x0)) | 0x13;
• #endif
• #ifdef CONFIG_D_VERSION //For D version LCD data clampping
•
• *(volatile unsigned int *)(CPE_PMU_VA_BASE + 0x28) = (*(volatile unsigned int *)(CPE_PMU_VA_BASE +
0x28)) | (1 << 8);
• *(unsigned int *)(CPE_COLORTRANS_VA_BASE + 0x0) = 0x2;
• #endif
Note: LCD driver must set YUV422 mode (driver/video/flcd.c must enable #define mode_422)
Only support for D version FIC8120 later
3.17.1 Introduction
Described below is the method which use Faraday RTC IP or S35390A chip to do RTC function. Typically,
a Linux RTC application (such as hwclock or clock) may access RTC through the following two interfaces:
/proc/driver/rtc or IOCTL to facilitate time setting and reading. Furthermore, Linux RTC drivers support
the use of hardware RTC alarm through standard synchronous blocking I/O interfaces such as read(),
or synchronous non-blocking I/O (select()). Though there’s no standard interface for RTC drivers, most
Linux RTC drivers try to mimic the behavior of standard PC RTC driver.
119
3.17.2 Configuration Setting
刪除: 57
/proc/driver/rtc interface
An RTC device can report its status from /proc file system. The de facto path of the virtual file
representing RTC is /proc/driver/rtc. To use it, one can simply use the “cat” command, just as follow:
# cat /proc/driver/rtc
rtc_time : 00:00:59
rtc_date : 1970-01-01
rtc_epoch : 1970
alrm_time : 08:03:00
alrm_date : N/A for CPE120
alarm_IRQ : no
#
/ioctl interface
RTC driver supports the basic functions of RTC: the set and read of RTC time, and you must check if
/dev directory must has rtc derive. If not, please mknod rtc c 10 135
Function Description
120
RTC_RD_TIME Read RTC Time
RTC_SET_TIME Set RTC Time
AP example:
This Section only list the related source codes of RTC driver.
刪除: 22
刪除: 23
3.18.1 Introduction
121
z Described below is the method which use Faraday WDT IP to automatically reset system when the system
is not responding. Usually it is equipped with a down-counting counter, with user-supplied reload values.
When the counter goes zero, most watchdog timer will issue a reset signal to the system. Hence the
system should periodically reload the counter value to prevent the reset of it. If the system is unable to
respond, or forms into a deadlock, or get trapped into a infinite loop etc. the watchdog timer can then
automatically reset the system (i.e. put the system back to a known state). If you want to use AP to run
IOCTL, you must create character device file /dev/wdt with (major, minor)=(10, 130)
122
3.18.2 Configuration Setting
刪除: 58
This Section only list the related source codes of WDT driver.
刪除: 24
Table 3-24. Source Code Directory Structure
123
3.19 I2C Function
3.19.1 Introduction
An Algorithm driver contains general code that can be used for a whole class of I2C adapters. Each
specific adapter driver depends on one algorithm driver.
A Driver contains the general code to access some type of device. Each detected device gets its own
data in the Client structure. Usually, Driver and Client are more closely integrated than Algorithm and
Adapter.
Included Bus Drivers
================
Base modules
------------
i2c-core.c: The basic I2C code, including the /proc interface
i2c-proc.c: The /proc interface for device (client) drivers
Algorithm drivers
-----------------
i2c-algo-faraday.c: An algorithm for I2C device in Faraday processors
Adapter drivers
---------------
i2c-faraday-adapter.c: (uses i2c-algo-faraday)
124
with hardware independent. It is not necessary for driver programmers to care how to implement
between device driver and bus driver.
As long as based on faraday bus driver, programmer will implement the device driver easily. That
will speed up development and simplify the complexity to develop I2C device driver on faraday board.
125
3.19.2 Source code
Before developing device driver, you should make sure the necessary module is built in kernel firstly.
Relative files in linux kernel are in the following directory :
i2c-algo-faraday.c : kernelsource_root/drivers/i2c/
i2c-core.c : kernelsource_root/drivers/i2c/
i2c-faraday-adap.c : kernelsource_root/drivers/i2c/
Makefile : replace the original kernelsource_root/drivers/i2c/Makefile
Config.in : replace the original kernelsource_root/drivers/i2c/Config.in
i2c-algo-faraday.h : kernelsource_root/include/linux/
i2c-id.h : replace the original kernelsource_root/include/linux/i2c-id.h
At the same time, remember to disable the file arch/arm/mach-cpe/Makefile like the following ,
avoiding to redefine problems between i2c-eeprom.c and original eeprom.c.
#obj-$(CONFIG_FIC8120_PLATFORM) +=eeprom.o
While executing the command “make menuconfig” under linux kernel-2.4.19, there are some
necessary options we need to enable like the following :
-> Character device-> I2C support
<*>I2C support
<*>I2C Faraday interfaces
<*> Faraday I2C device driver on FIC8120
<*>I2C /proc interface(required for hardware sensors)
With installing of I2C faraday bus driver, it provides two export subroutines below for device driver :
126
buf : data to write
size : data length to write
clockdiv : set i2c_bus speed( 0 means don’t’ care and use default i2c_bus)
default is 45 k
127
3.19.4 Access I2C function in user mode
We design a common interface(/dev/i2c-0) for accessing i2c device from userspace . We provide a
sample in C code like the following :
PS : I2C read and write will be determined by device address. if the last bit of device address is 1, the
system will recognize to read the byte. So you won’t specify the i2c action(read or write).
int file;
int adapter_nr = 0; /* probably dynamically determined */
char filename[20];
static char buf[10];
struct i2c_faraday_msg i2c_ap ; //structure defined in kernel/include/linux/i2c-algo-faraday.h
sprintf(filename,"/dev/i2c-%d",adapter_nr);
if ((file = open(filename,O_RDWR)) < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
i2c_ap.addr = EEPROM_ID_WRITE;
i2c_ap.waddr = addr; // device offset to write
i2c_ap.len = 6 ;
buf[0]=0x10;
buf[1]=0x20;
buf[2]=0x30;
buf[3]=0x40;
buf[4]=0x50;
buf[5]=0x60;
格式化: 德文 (德國)
128
i2c_ap.buf = &buf[0] ;
if (ioctl(fd,I2C_RDWR,&i2c_ap) < 0) {
printf("Error in ioctl I2C_SLAVE(%2x)\n",I2C_SLAVE);
return -1;
}
printf("i2c write byte successfully!\n");
129
Appendix
130
Appendix A: Hardware Assignment
131
IRQ Resource Interrupt Name FIQ Resource Interrupt Name
• 3 • i2c_intr • 3 • mac_int
• 2 • ssp_intr1 • 2 • ssp_intr1
• 1 • mpca_int0 • 1 • mpca_int3
• 0 • lcdc_intr • 0 • lcdc_intr
By Address Sorting
AHB Slave ID Base Size
132
By Address Sorting
APB Slave ID Base Size
133
Appendix B: Load Image to Target SDRAM
You can load images to target SDRAM in three ways, as detailed in Sections B.1, B.2 and B.3.
134
Appendix C: Programming Flash
The specified address mapped to flash is set to 0x80000000 by default. The physical memory mapping
is as shown in the following figure.
0x0
128 MB SDRAM
0x80000000
16 MB Flash
0x81000000
FA526-Linux Distribution provides ARMBOOT for you to easily program your flash module. The types
of flash module currently supported by ARMBOOT are as follows:
SST39VF080
SST39VF016
MX29LV008B
IntelE28F128
ARMBOOT provides some commands for flash programming. These commands are listed in the following
table:
Command Description
You can use these commands to program the flash. For example, when you want to write image
armboot.bin to flash, you may take the following actions:
Example(must depend on your start address and size):
• Load image to specified address 0x1000000. (You can refer to Appendix B for the
procedure.)
• Erase flash size 256K from 0x80100000 to 0x80CFFFFF by using ARMBOOT command
135
“erase”.
CPE> erase 0x80100000 0x80CFFFFF
• Copy image from 0x1000000 to 0x80100000 with size 0x501000 by using command “cp.b”.
CPE> cp.b 0x1000000 0x80100000 0x501000
136
Appendix D: bootpImage Flow
FA526-Linux provides bootpImage to run Linux kernel. The bootpImage comprises four components
刪除: Figure D-1
as depicted in Figure D-1 and listed below:
• Bootp Image: The code to copy “Decompressor” and “Compressed Kernel” to specified
SDRAM position, and to copy “Ramdisk” to another SDRAM position.
• Decompressor Image: The code in charge of decompressing “compressed kernel”.
• Compressed Kernel Image: The image of “compressed kernel”.
• Ramdisk Image: The file system image provided for Linux kernel.
Ramdisk (minix)
•
When FA52x jumps to 0x80240000 and runs the bootpImage code, the software operations will be as
follows:
• Bootp program copies Part A to 0x500000, Part B to 0x900000, and branches to 0x500000
刪除: Figure D-2
(that is, Decompressor). (See Figure D-2.)
0x80240000 0x500000
Bootp
Decompressor
Decompressor
copy
Part Compressed Kernel
Compressed Kernel
A 0x900000
Ramdisk (minix)
Part B Ramdisk (minix) copy
137
time.
• Linux kernel booting done. You can see the shell prompt on your terminal.
138
Appendix E: ramdisk Maintenance
Use the program “dd” to create your ramdisk. Assume you want to create a 4 MB ramdisk image named
“ramdisk.img”. The command will be as follows:
# dd if=/dev/zero of=ramdisk.img bs=4096k count=1
After creating ramdisk.image, you have to format it with the specified file system.
If the file system is EXT2, the command would be as follows:
# mkfs.ext2 ramdisk.img
If the file system is MINIX file system, the command would be as follows:
# mkfs.minix ramdisk.img
In order to add/remove files from ramdisk image, you must mount the image to the specified directory
first. The following example assumes that the mount point is /mnt/ramdisk.
# gunzip ramdisk.tgz
# mkdir /mnt/ramdisk
# mount –o loop ramdisk.img /mnt/ramdisk
You can use a command such as “cp” or “mv” to add or remove files from /mnt/ramdisk. After finishing
the addition or removal, you have to do un-mount.
# umount /mnt/ramdisk
# gzip ramdisk
After the specified ramdisk is ready, be sure to modify the file mkbootp.sh for the ramdisk.
139