2410 RTC driver analysis

Source: Internet
Author: User

First, the RTC device is an on-chip device that uses platform_device to represent the device (that is, the RTC object of platform_device) the device has been registered into the system during device initialization (refer to the driver process of the device on SOC 2410 (RTC, watchdog, etc )), therefore, after the RTC driver is registered to the system in the RTC driver initialization, the system will probe to this RTC device, and finally call the probe function of our RTC driver.

Next we will focus on the analysis of the RTC driver 2410.

First, initialize the function and exit the function:

Static void _ init s3c2410_rtc_init (void)

{

Printk (banner );

 

/*

* In this case, the RTC driver is registered into the system. At the same time, the system searches for the matching RTC device and calls

* S3c2410_rtcdrv probe function.

*/

Return platform_driver_register (& s3c2410_rtcdrv );

}

Static void _ exit s3c2410_rtc_exit (void)

{

/* Uninstall the RTC driver, and then the RTC device will not be able to use it */

Platform_driver_unregister (& s3c2410_rtcdrv );

}

Static struct platform_driver s3c2410_rtcdrv = {

. Probe = s3c2410_rtc_probe,

. Remove = s3c2410_rtc_remove,

. Suspend = s3c2410_rtc_suspend,

. Resume = s3c2410_rtc_resume,

. Driver = {

. Name = "s3c2410-rtc", // This string must be the same as the RTC device definition, the system will match correctly.

. Owner = this_module,

},

};

After the system registers the RTC device to the system, it finds all the devices on the corresponding bus and compares them with the driver, if the system finds a matching RTC device, it will call the s3c2410_rtc_probe function of the RTC driver. Note that the RTC device is registered to the system during system initialization.

Static int s3c2410_rtc_probe (struct platform_device * pdev/* RTC device */)

{

Struct resource * res;

Int ret;

 

Pr_debug ("% s: Probe = % P/N", _ FUNCTION __, pdev );

 

/*

* Get the tick of the device to interrupt the resource. You can see through the view of platform_get_irq that you actually get by searching for the pdev resource. * The pdev resource is specified when building the platform_device object, to Devs. view in C

*/

S3c2410_rtc_tickno = platform_get_irq (pdev, 1 );

If (s3c2410_rtc_tickno <0 ){

Dev_err (& pdev-> Dev, "No IRQ for RTC tick/N ");

Return-enoent;

}

 

/*

* Get the RTC interrupt resource of the device. View platform_get_irq. We can see that we actually get it by searching pdev resources. * The pdev resources are specified when building the platform_device object, to Devs. view in C

*/

S3c2410_rtc_alarmno = platform_get_irq (pdev, 0 );

If (s3c2410_rtc_alarmno <0 ){

Dev_err (& pdev-> Dev, "No IRQ for alarm/N ");

Return-enoent;

}

 

Pr_debug ("s3c2410_rtc: Tick IRQ % d, alarm IRQ % d/N ",

S3c2410_rtc_tickno, s3c2410_rtc_alarmno );

 

/*

* Get the memory resources of the device. You can view platform_get_irq. Actually, you can find the resources of pdev. * The resources of pdev are specified when you build the platform_device object. You can go to Devs. view in C

*/

Res = platform_get_resource (pdev, ioresource_mem, 0 );

If (RES = NULL ){

Dev_err (& pdev-> Dev, "failed to get memory region resource/N ");

Return-enoent;

}

/*

* Check whether the specified memory can be used.

*/

S3c2410_rtc_mem = request_mem_region (res-> Start, res-> end-res-> Start + 1,

Pdev-> name );

 

If (s3c2410_rtc_mem = NULL ){

Dev_err (& pdev-> Dev, "failed to reserve memory region/N ");

Ret =-enoent;

Goto exit_err;

}

/*

* Re-map the specified memory area to map the original physical address to the corresponding virtual address. In this way, you can use this * virtual address to directly access the original physical address, here is the register address range mapped to RTC.

*/

S3c2410_rtc_base = ioremap (res-> Start, res-> end-res-> Start + 1 );

If (s3c2410_rtc_base = NULL ){

Dev_err (& pdev-> Dev, "failed ioremap ()/n ");

Ret =-einval;

Goto exit_err;

}

 

S3c2410_rtc_mem = res;

Pr_debug ("s3c2410_rtc_base = % P/N", s3c2410_rtc_base );

 

Pr_debug ("s3c2410_rtc: rtccon = % 02x/N", readb (s3c2410_rtccon ));

 

/* Correctly initialize the RTC device */

S3c2410_rtc_enable (pdev, 1 );

 

Pr_debug ("s3c2410_rtc: rtccon = % 02x/N", readb (s3c2410_rtccon ));

/* Set the device frequency */

S3c2410_rtc_setfreq (s3c2410_rtc_freq );

 

/* Register the operation functions of the RTC device. These operation functions will be called for future access to the device */

Register_rtc (& s3c2410_rtcops );

Return 0;

 

Exit_err:

Dev_err (& pdev-> Dev, "error % d during initialisation/N", RET );

 

Return ret;

}

 

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.