Linux-2.6.32.2 kernel porting on mini2440 (XII) --- porting I2C EEPROM driver

Publisher:Serendipitous55Latest update time:2016-12-04 Source: eefocusKeywords:Linux Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Migration environment 

1. Host environment: CentOS 5.5 under VMare, 1G memory.

2. Integrated development environment: Eclipse IDE

3. Compilation environment: arm-linux-gcc v4.4.3, arm-none-linux-gnueabi-gcc v4.5.1.

4. Development board: mini2440, 2M nor flash, 128M nand flash.

5.u-boot version: u-boot-2009.08

6. Linux version: linux-2.6.32.2

7. References:

Complete Handbook of Embedded Linux Application Development, edited by Wei Dongshan.

Mini2440 Linux Porting Development Practical Guide

【1】Configure I2C driver in the kernel

Linux-2.6.32.2 provides a complete driver for the I2C interface of S2C2440, so we only need to configure it in the kernel to use it.
Tip: In fact, the default mini2440_defconfig of the Linux-2.6.32.2 kernel has already configured the I2C driver, we just open it here to see the specific configuration path.

Execute make menuconfig in the kernel source code directory to enter the kernel configuration main menu, and select the following submenus in turn:

Device Drivers --->
    <*> I2C support --->
        I2C Hardware Bus support --->

            <*> S3C2410 I2C Driver

We can see that "<*> S3C2410 I2C Driver" has been selected. The S3C2410 here can also be applied to S3C2440 because their I2C port and register definitions are exactly the same. The driver source code corresponding to the above configuration is: linux-2.6.32.2/drivers/i2c/busses/i2c-s3c2410.c.

After confirming the above configuration, exit and save.

【2】Compilation test

After recompiling, copy uImage to /nfsboot/kernel, then restart the development board. You can see the following startup information in the console terminal:

... ...

SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
NET: Registered protocol family 2

... ...

To facilitate user testing, Mini2440 has an EEPROM chip, AT24C08, mounted on the I2C bus. By writing and reading the chip, we can test the I2C bus driver.

Here, the friendly official provides a command line test program named "i2c", which is modified based on the open source eeprog software. The download address of eeprog software is: http://codesink.org/eeprog.html . The I2c test code is located in the CD/linux example code/examples/i2c. Copy it to the linux host/root/linux-test/codetest directory, then enter the directory and execute make Makefile to generate the test program executable code;

[root@localhost i2c]# make
arm-linux-gcc -Wall -O2 -c -o eeprog.o eeprog.c
arm-linux-gcc -Wall -O2 -c -o 24cXX.o 24cXX.c
arm-linux-gcc -Wall -O2 -o i2c eeprog.o 24cXX.o
[root@localhost i2c]#Then 
copy the generated i2c to /nfsboot/nfs

[root@localhost i2c]# cp i2c /nfsboot/nfs

Then execute the command i2c –w in the serial terminal to write data (0x00-0xff) to the 24C08 device of the board:

[root@mini2440 sdcard]#cd ../nfs
[root@mini2440 nfs]#ls
adc_test backlight_test i2c tstest
[root@mini2440 nfs]#./i2c -w
Open /dev/i2c/0 with 8bit mode
Error eeprom_open: No such file or directory
Error at line 90: unable to open eeprom device file (check that the file exists
and that it's readable)
        sysmsg: No such file or directory

An error occurred and there is no file called I2C/0.

[root@mini2440 nfs]#ls /dev
adc ptyv1 ttype
apm_bios ptyv2 ttypf
backlight ptyv3 ttyq0
console ptyv4 ttyq1
cpu_dma_latency ptyv5 ttyq2
device ptyv6 ttyq3
event0 ptyv7 ttyq4
fb0 ptyv8 ttyq5
full ptyv9 ttyq6
i2c-0 ptyva ttyq 7
kmem ptyvb ttyq8
kmsg ptyvc ttyq9
mem    

You can see the device file i2c-0.

To modify the code in the i2c source code, you need to add the writable attribute to it before modifying it

[root@localhost i2c]# chmod a+w eeprog.c

Then open the i2c source file and get eeprog.c, locate around line 87, and modify it as follows:

 fprintf(stderr, "Open /dev/i2c-0 with 8bit mode\n");
 die_if(eeprom_open("/dev/i2c-0", 0x50, EEPROM_TYPE_8BIT_ADDR, &e) < 0, 
   "unable to open eeprom device file "
   "(check that the file exists and that it's readable)");
 switch(op)

Then recompile.

[root@localhost i2c]# make
arm-linux-gcc -Wall -O2 -c -o eeprog.o eeprog.c
arm-linux-gcc -Wall -O2 -o i2c eeprog.o 24cXX.o
[root@localhost i2c]# cp i2c /nfsboot/nfs
cp: Do you want to overwrite "/nfsboot/nfs/i2c"? y
[root@localhost i2c]# 
Execute the i2c -w command again

[root@mini2440 nfs]#./i2c -w
Open /dev/i2c-0 with 8bit mode
  Writing 0x00-0xff into 24C08

 0000| 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
 0010| 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
 0020| 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
 0030| 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f
 0040| 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
 0050| 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f
 0060| 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
 0070| 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f
 0080| 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f
 0090| 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f
 00a0| a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af
 00b0| b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf
 00c0| c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf
 00d0| d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df
 00e0| e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef
 00f0| f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff

[root@mini2440 nfs]#

Type in the command line: i2c –r to read the output from the 24C08 device on the board

[root@mini2440 nfs]#./i2c -r
Open /dev/i2c-0 with 8bit mode
  Reading 256 bytes from 0x0

 0000| 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
 0010| 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
 0020| 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
 0030| 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f
 0040| 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
 0050| 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f
 0060| 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
 0070| 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f
 0080| 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f
 0090| 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f
 00a0| a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af
 00b0| b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf
 00c0| c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf
 00d0| d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df
 00e0| e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef
 00f0| f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff

[root@mini2440 nfs]#

Next, port the UDA1341 audio driver.


Keywords:Linux Reference address:Linux-2.6.32.2 kernel porting on mini2440 (XII) --- porting I2C EEPROM driver

Previous article:Linux-2.6.32.2 kernel porting on mini2440 (Thirteen) --- porting UDA1341 audio driver
Next article:Linux-2.6.32.2 kernel transplantation on mini2440 (XI) --- transplantation of SD card driver

Recommended ReadingLatest update time:2024-11-16 12:56

TQ2440 linux i2c driver - at24c02 (eeprom)
1. Development environment: (1) Development board: TQ2440 development board (2) PC system: Ubuntu 13.04-amd64 (3) Interleaved compiler: arm-linux-gcc version-4.3.3 (4)linux kernel:linux 2.6.30。4 2. Introduction to the i2c system (Here are some words about the structure, taken from the Internet) I2C is a peripheral b
[Microcontroller]
TQ2440 linux i2c driver - at24c02 (eeprom)
U-boot-2014.04 ported to MINI2440 (9) nor flash boot and nand flash boot
On mini2440, NOR flash boot and NAND flash boot can meet different needs. Here we transplant. NOR boot transplant is relatively simple, because there is no need to redirect the code. NAND boot is relatively complex. Here we start with NOR and get to the point:        1. Modify to support NOR flash boot        Step
[Microcontroller]
ARM Linux startup one: assembly startup to start_kernel
Describe the general process of arm linux startup, taking S5PV210 (Cortex A8) as an example, this article describes the first stage.        1. ARM Linux boot        After uboot boots arm linux (uImage image) to SDRAM, it interprets the 64-byte header of the uImage image through the bootm command, obtains the entry a
[Microcontroller]
Software simulation I2C read and write X1226 program
Written in C51, the program has passed the test and has been successfully used in the project. It is suitable for all 51 core microcontrollers and can be transplanted to other microcontrollers with very few modifications. I have transplanted it to the 430 microcontroller.     Disclaimer: This code is origina
[Microcontroller]
OK6410A Development Board (VIII) 34 linux-5.11 OK6410A Memory Management Phase II
B __turn_mmu_on symbol - setup_arch- paging_init- bootmem_init- memblock_allow_resize returns ----At this point, memblock initialization is complete, and the era of memblock memory manager based on the virtual memory era has begun process __turn_mmu_on mcr p15, 0, r0, c1, c0, 0 @ write control reg // memory manage
[Microcontroller]
22. Linux-RTC driver analysis and use
    The rtc driver in linux is located under drivers/rtc, which contains RTC drivers for many development platforms. We are mainly using S3C24xx here, so its RTC driver is rtc-s3c.c 1. Enter ./drivers/rtc/rtc-s3c.c     Or first enter the entry function, as shown below:     A platform device driver named "s3c2410-r
[Microcontroller]
22. Linux-RTC driver analysis and use
Design of Smart Phone System Based on Embedded Linux
With the rapid development of the handheld communication device market, the functions of mobile phones are gradually increasing. Now mobile phones are no longer just handheld devices for voice communication, but have become embedded communication platforms that integrate additional functions such as SMS, MMS, Intern
[Microcontroller]
Design of Smart Phone System Based on Embedded Linux
Record the tiny6410 jlink command line debugging linux-2.6.38 kernel
1. First start nandflash uboot- linux kernel- file system and enter the file system command line 2\Start JLinkGDBServer -device ARM11 3 Start arm-none-eabi-gdb vmlinux Enter this command line target remote localhost:2331 monitor halt monitor reset b start_kernel list cont
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号