Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:47

0001 /*
0002  * This file contains the RTC driver table for Motorola MCF5206eLITE
0003  * ColdFire evaluation board.
0004  *
0005  * Copyright (C) 2000 OKTET Ltd., St.-Petersburg, Russia
0006  * Author: Victor V. Vengerov <vvv@oktet.ru>
0007  *
0008  * The license and distribution terms for this file may be
0009  * found in the file LICENSE in this distribution or at
0010  *
0011  * http://www.rtems.org/license/LICENSE.
0012  */
0013 
0014 #include <i2c.h>
0015 #include <libchip/rtc.h>
0016 #include <ds1307.h>
0017 
0018 /* Forward function declaration */
0019 bool mcf5206elite_ds1307_probe(int minor);
0020 
0021 extern rtc_fns ds1307_fns;
0022 
0023 /* The following table configures the RTC drivers used in this BSP */
0024 rtc_tbl RTC_Table[] = {
0025     {
0026         "/dev/rtc",                /* sDeviceName */
0027         RTC_CUSTOM,                /* deviceType */
0028         &ds1307_fns,               /* pDeviceFns */
0029         mcf5206elite_ds1307_probe, /* deviceProbe */
0030         NULL,                      /* pDeviceParams */
0031         0x00,                      /* ulCtrlPort1, for DS1307-I2C bus number */
0032         DS1307_I2C_ADDRESS,        /* ulDataPort, for DS1307-I2C device addr */
0033         NULL,                      /* getRegister - not applicable to DS1307 */
0034         NULL                       /* setRegister - not applicable to DS1307 */
0035     }
0036 };
0037 
0038 /* Some information used by the RTC driver */
0039 
0040 #define NUM_RTCS (sizeof(RTC_Table)/sizeof(rtc_tbl))
0041 
0042 size_t RTC_Count = NUM_RTCS;
0043 
0044 /* mcf5206elite_ds1307_probe --
0045  *     RTC presence probe function. Return TRUE, if device is present.
0046  *     Device presence checked by probe access to RTC device over I2C bus.
0047  *
0048  * PARAMETERS:
0049  *     minor - minor RTC device number
0050  *
0051  * RETURNS:
0052  *     TRUE, if RTC device is present
0053  */
0054 bool
0055 mcf5206elite_ds1307_probe(int minor)
0056 {
0057     int try = 0;
0058     i2c_message_status status;
0059     rtc_tbl *rtc;
0060     i2c_bus_number bus;
0061     i2c_address addr;
0062 
0063     if (minor >= NUM_RTCS)
0064         return false;
0065 
0066     rtc = RTC_Table + minor;
0067 
0068     bus = rtc->ulCtrlPort1;
0069     addr = rtc->ulDataPort;
0070     do {
0071         status = i2c_wrbyte(bus, addr, 0);
0072         if (status == I2C_NO_DEVICE)
0073             return false;
0074         try++;
0075     } while ((try < 15) && (status != I2C_SUCCESSFUL));
0076     if (status == I2C_SUCCESSFUL)
0077         return true;
0078     else
0079         return false;
0080 }