1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
// IBM_PROLOG_BEGIN_TAG
// This is an automatically generated prolog.
//
// $Source: src/usr/i2c/i2c.C $
//
// IBM CONFIDENTIAL
//
// COPYRIGHT International Business Machines Corp. 2011
//
// p1
//
// Object Code Only (OCO) source materials
// Licensed Internal Code Source Materials
// IBM HostBoot Licensed Internal Code
//
// The source code for this program is not published or other-
// wise divested of its trade secrets, irrespective of what has
// been deposited with the U.S. Copyright Office.
//
// Origin: 30
//
// IBM_PROLOG_END
/**
* @file i2c.C
*
* @brief Implementation of the i2c device driver
*
*/
// ----------------------------------------------
// Includes
// ----------------------------------------------
#include <string.h>
#include <trace/interface.H>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <targeting/targetservice.H>
#include <devicefw/driverif.H>
#include <i2c/i2creasoncodes.H>
#include "i2c.H"
// ----------------------------------------------
// Trace definition
trace_desc_t* g_trac_i2c = NULL;
TRAC_INIT( & g_trac_i2c, "I2C", 4096 );
namespace I2C
{
// Register the perform Op with the routing code for Procs.
DEVICE_REGISTER_ROUTE( DeviceFW::WILDCARD,
DeviceFW::I2C,
TARGETING::TYPE_PROC,
i2cPerformOp );
// TODO - This will be added back in once the bug in the registration
// code has been fixed. Right now it will not compile with 2 registrations
// to the same function.
// Register the perform Op with the routing code for Memory Buffers.
//DEVICE_REGISTER_ROUTE( DeviceFW::WILDCARD,
// DeviceFW::I2C,
// TARGETING::TYPE_MEMBUF,
// i2cPerformOp );
// ------------------------------------------------------------------
// i2cPerformOp
// ------------------------------------------------------------------
errlHndl_t i2cPerformOp( DeviceFW::OperationType i_opType,
TARGETING::Target * i_target,
void * io_buffer,
size_t & io_buflen,
int64_t i_accessType,
va_list i_args )
{
errlHndl_t err = NULL;
uint64_t addr = va_arg( i_args, uint64_t );
TRACFCOMP( g_trac_i2c,
ENTER_MRK"i2cPerformOp()" );
// --------------------------------------------------------------
// NOTE: There are attributes that can be read for targetted
// devices (slaves). But since we don't have any of those
// targets yet, there isn't a way to test reading those
// attributes yet. I assume those will be added as full device
// driver testing is started on Simics.
// --------------------------------------------------------------
if( i_opType == DeviceFW::READ )
{
err = i2cRead( i_target,
addr,
io_buffer,
io_buflen );
}
else if( i_opType == DeviceFW::WRITE )
{
err = i2cWrite( i_target,
addr,
io_buffer,
io_buflen );
}
else
{
TRACFCOMP( g_trac_i2c,
ERR_MRK"i2cPerformOp() - Unknown Operation Type!" );
/*@
* @errortype
* @reasoncode I2C_INVALID_OP_TYPE
* @severity ERRL_SEV_UNRECOVERABLE
* @moduleid I2C_PERFORM_OP
* @userdata1 i_opType
* @userdata2 addr
* @devdesc Invalid Operation type.
*/
err = new ERRORLOG::ErrlEntry( ERRORLOG::ERRL_SEV_UNRECOVERABLE,
I2C_PERFORM_OP,
I2C_INVALID_OP_TYPE,
i_opType,
addr );
}
TRACFCOMP( g_trac_i2c,
EXIT_MRK"i2cPerformOp() - %s",
((NULL == err) ? "No Error" : "With Error") );
return err;
} // end i2cPerformOp
// ------------------------------------------------------------------
// i2cRead
// ------------------------------------------------------------------
errlHndl_t i2cRead ( TARGETING::Target * i_target,
uint64_t i_addr,
void * o_buffer,
size_t & i_size )
{
errlHndl_t err = NULL;
TRACFCOMP( g_trac_i2c,
ENTER_MRK"i2cRead()" );
do
{
// TODO - Functionality still needs to be added.
err = i2cSetup( i_target,
i_addr,
i_size,
true,
true );
} while( 0 );
TRACFCOMP( g_trac_i2c,
EXIT_MRK"i2cRead()" );
return err;
} // end i2cRead
// ------------------------------------------------------------------
// i2cWrite
// ------------------------------------------------------------------
errlHndl_t i2cWrite ( TARGETING::Target * i_target,
uint64_t i_addr,
void * i_buffer,
size_t & io_size )
{
errlHndl_t err = NULL;
TRACFCOMP( g_trac_i2c,
ENTER_MRK"i2cWrite()" );
do
{
// TODO - Functionality still needs to be added.
err = i2cSetup( i_target,
i_addr,
io_size,
true,
false );
} while( 0 );
TRACFCOMP( g_trac_i2c,
EXIT_MRK"i2cWrite()" );
return err;
} // end i2cWrite
// ------------------------------------------------------------------
// i2cSetup
// ------------------------------------------------------------------
errlHndl_t i2cSetup ( TARGETING::Target * i_target,
uint64_t i_addr,
size_t & i_size,
bool i_withStop,
bool i_readNotWrite )
{
errlHndl_t err = NULL;
TRACFCOMP( g_trac_i2c,
ENTER_MRK"i2cSetup()" );
do
{
// TODO - Functionality still needs to be added.
} while( 0 );
TRACFCOMP( g_trac_i2c,
EXIT_MRK"i2cSetup()" );
return err;
} // end i2cSetup
} // end namespace I2C
|