Back to home page

LXR

 
 

    


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

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