1 | /*===============================================================*\ |
---|
2 | | Project: RTEMS generic MPC5200 BSP | |
---|
3 | +-----------------------------------------------------------------+ |
---|
4 | | Partially based on the code references which are named below. | |
---|
5 | | Adaptions, modifications, enhancements and any recent parts of | |
---|
6 | | the code are: | |
---|
7 | | Copyright (c) 2005 | |
---|
8 | | Embedded Brains GmbH | |
---|
9 | | Obere Lagerstr. 30 | |
---|
10 | | D-82178 Puchheim | |
---|
11 | | Germany | |
---|
12 | | rtems@embedded-brains.de | |
---|
13 | +-----------------------------------------------------------------+ |
---|
14 | | The license and distribution terms for this file may be | |
---|
15 | | found in the file LICENSE in this distribution or at | |
---|
16 | | | |
---|
17 | | http://www.rtems.com/license/LICENSE. | |
---|
18 | | | |
---|
19 | +-----------------------------------------------------------------+ |
---|
20 | | this file configures the pcf8563 RTC for a PM520 board | |
---|
21 | \*===============================================================*/ |
---|
22 | /* |
---|
23 | * This file contains the RTC driver table for Motorola MCF5206eLITE |
---|
24 | * ColdFire evaluation board. |
---|
25 | * |
---|
26 | * Copyright (C) 2000 OKTET Ltd., St.-Petersburg, Russia |
---|
27 | * Author: Victor V. Vengerov <vvv@oktet.ru> |
---|
28 | * |
---|
29 | * The license and distribution terms for this file may be |
---|
30 | * found in the file LICENSE in this distribution or at |
---|
31 | * |
---|
32 | * http://www.rtems.com/license/LICENSE. |
---|
33 | * |
---|
34 | * @(#) todcfg.c,v 1.4 2005/01/22 04:12:39 ralf Exp |
---|
35 | */ |
---|
36 | |
---|
37 | #include <bsp.h> |
---|
38 | #include "../include/i2c.h" |
---|
39 | #include <libchip/rtc.h> |
---|
40 | #include "../tod/pcf8563.h" |
---|
41 | |
---|
42 | /* Forward function declaration */ |
---|
43 | boolean mpc5200_pcf8563_probe(int minor); |
---|
44 | |
---|
45 | extern rtc_fns pcf8563_fns; |
---|
46 | |
---|
47 | /* The following table configures the RTC drivers used in this BSP */ |
---|
48 | rtc_tbl RTC_Table[] = { |
---|
49 | { |
---|
50 | "/dev/rtc", /* sDeviceName */ |
---|
51 | RTC_CUSTOM, /* deviceType */ |
---|
52 | &pcf8563_fns, /* pDeviceFns */ |
---|
53 | mpc5200_pcf8563_probe, /* deviceProbe */ |
---|
54 | NULL, /* pDeviceParams */ |
---|
55 | 0x01, /* ulCtrlPort1, for PCF8563-I2C bus number */ |
---|
56 | PCF8563_I2C_ADDRESS, /* ulDataPort, for PCF8563-I2C device addr */ |
---|
57 | NULL, /* getRegister - not applicable to PCF8563 */ |
---|
58 | NULL /* setRegister - not applicable to PCF8563 */ |
---|
59 | } |
---|
60 | }; |
---|
61 | |
---|
62 | /* Some information used by the RTC driver */ |
---|
63 | |
---|
64 | #define NUM_RTCS (sizeof(RTC_Table)/sizeof(rtc_tbl)) |
---|
65 | |
---|
66 | size_t RTC_Count = NUM_RTCS; |
---|
67 | |
---|
68 | rtems_device_minor_number RTC_Minor; |
---|
69 | |
---|
70 | /* mpc5200_pcf8563_probe -- |
---|
71 | * RTC presence probe function. Return TRUE, if device is present. |
---|
72 | * Device presence checked by probe access to RTC device over I2C bus. |
---|
73 | * |
---|
74 | * PARAMETERS: |
---|
75 | * minor - minor RTC device number |
---|
76 | * |
---|
77 | * RETURNS: |
---|
78 | * TRUE, if RTC device is present |
---|
79 | */ |
---|
80 | boolean |
---|
81 | mpc5200_pcf8563_probe(int minor) |
---|
82 | { |
---|
83 | int try = 0; |
---|
84 | i2c_message_status status; |
---|
85 | rtc_tbl *rtc; |
---|
86 | i2c_bus_number bus; |
---|
87 | i2c_address addr; |
---|
88 | |
---|
89 | if (minor >= NUM_RTCS) |
---|
90 | return FALSE; |
---|
91 | |
---|
92 | rtc = RTC_Table + minor; |
---|
93 | |
---|
94 | bus = rtc->ulCtrlPort1; |
---|
95 | addr = rtc->ulDataPort; |
---|
96 | do { |
---|
97 | status = i2c_wrbyte(bus, addr, 0); |
---|
98 | if (status == I2C_NO_DEVICE) |
---|
99 | return FALSE; |
---|
100 | try++; |
---|
101 | } while ((try < 15) && (status != I2C_SUCCESSFUL)); |
---|
102 | if (status == I2C_SUCCESSFUL) |
---|
103 | return TRUE; |
---|
104 | else |
---|
105 | return FALSE; |
---|
106 | } |
---|