Linux2.6.21 reading core notes at91_i2c

Source: Internet
Author: User
Linux 2.6.21 read core notes at91_i2c-Linux general technology-Linux programming and kernel information. The following is a detailed description. In the use of linux 2.6.21 in at91rm9200 (Atmel), it seems that i2c is not very good and sometimes unreliable!
Errors may occur after thousands of reads and writes. However, note the following:

A. at91rm9200 datasheet Page396 requirements are as follows:
• Program the PIO controller:
? Dedicate TWD and TWCK as peripheral lines.
? Define TWD and TWCK as open-drain.
In linux 2.6.21, how does one implement kernel?
2.6.21 is different from 2.4.18 in many systems, such as initializing this part 2.4.18 in kernel_source_root/drivers/i2c/, while 2.6.21 in kernel_source_root/Arch/arm/Mach-at91/At91rm9200_devices.c.

/*--------------------------------------------------------------------
* TWI (i2c)
*--------------------------------------------------------------------*/

# If defined (CONFIG_I2C_AT91) | defined (CONFIG_I2C_AT91_MODULE)

Static struct resource twi_resources [] = {
[0] = {
. Start = AT91RM9200_BASE_TWI,
. End = AT91RM9200_BASE_TWI + SZ_16K-1,
. Flags = IORESOURCE_MEM,
},
[1] = {
. Start = AT91RM9200_ID_TWI,
. End = AT91RM9200_ID_TWI,
. Flags = IORESOURCE_IRQ,
},
};

Static struct platform_device at91rm9200_twi_device = {
. Name = "at91_i2c ",
. Id =-1,
. Resource = twi_resources,
. Num_resources = ARRAY_SIZE (twi_resources ),
};

Void _ init at91_add_device_i2c (void)
{
/* Pins used for TWI interface */
At91_set_A_periph (AT91_PIN_PA25, 0);/* TWD */
At91_set_multi_drive (AT91_PIN_PA25, 1 );

At91_set_A_periph (AT91_PIN_PA26, 0);/* TWCK */
At91_set_multi_drive (AT91_PIN_PA26, 1 );

Platform_device_register (& at91rm9200_twi_device );
}
# Else
Void _ init at91_add_device_i2c (void ){}
# Endif

The at91_add_device_i2c () function completes the initialization of at91 i2c. Let's give the definition of the two functions.

/*
* Mux the pin to the "A" internal peripheral role.
*/
Int _ init_or_module at91_set_A_periph (unsigned pin, int use_pullup)
{
Void _ iomem * pio = pin_to_controller (pin );
Unsigned mask = pin_to_mask (pin );

If (! Pio)
Return-EINVAL;

_ Raw_writel (mask, pio + PIO_IDR );
_ Raw_writel (mask, pio + (use_pullup? PIO_PUER: PIO_PUDR ));
_ Raw_writel (mask, pio + PIO_ASR );
_ Raw_writel (mask, pio + PIO_PDR );
Return 0;
}
Obviously: at91_set_A_periph assigns the pin the PeriphA function and marks it by use_pullup.

Int _ init_or_module at91_set_multi_drive (unsigned pin, int is_on)
{
Void _ iomem * pio = pin_to_controller (pin );
Unsigned mask = pin_to_mask (pin );

If (! Pio)
Return-EINVAL;

_ Raw_writel (mask, pio + (is_on? PIO_MDER: PIO_MDDR ));
Return 0;
}
While at91_set_multi_drive (unsigned pin, int is_on) sets whether the pin can be used in multiple functions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.