make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / drivers / i2c / xilinx_iic / xiic_options.c
1 /*-----------------------------------------------------------------------------
2 *     $Date: 2005/04/11 02:50:21 $
3 *     $RCSfile: xiic_options.c,v $
4 *----------------------------------------------------------------------------*/
5
6 /******************************************************************************
7 *
8 *     XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
9 *     SOLELY FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR
10 *     XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION
11 *     AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION
12 *     OR STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS
13 *     IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
14 *     AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
15 *     FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY
16 *     WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
17 *     IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
18 *     REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
19 *     INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 *     FOR A PARTICULAR PURPOSE.
21 *     
22 *     (c) Copyright 2002 Xilinx, Inc.
23 *     All rights reserved.
24 *
25 ******************************************************************************/
26 /*****************************************************************************/
27 /**
28 *
29 * @file xiic_options.c
30 *
31 * Contains options functions for the XIic component. This file is not required
32 * unless the functions in this file are called.
33 *
34 * <pre>
35 * MODIFICATION HISTORY:
36 *
37 * Ver   Who  Date     Changes
38 * ----- --- ------- -----------------------------------------------
39 * 1.01b jhl 3/26/02 repartioned the driver
40 * </pre>
41 *
42 ****************************************************************************/
43
44 /***************************** Include Files *******************************/
45
46 #include "xiic.h"
47 #include "xiic_i.h"
48 #include "xio.h"
49
50 /************************** Constant Definitions ***************************/
51
52 /**************************** Type Definitions *****************************/
53
54 /***************** Macros (Inline Functions) Definitions *******************/
55
56 /************************** Function Prototypes ****************************/
57
58 /************************** Variable Definitions **************************/
59
60 /*****************************************************************************/
61 /**
62 *
63 * This function sets the options for the IIC device driver. The options control
64 * how the device behaves relative to the IIC bus. If an option applies to
65 * how messages are sent or received on the IIC bus, it must be set prior to
66 * calling functions which send or receive data.
67 *
68 * To set multiple options, the values must be ORed together. To not change
69 * existing options, read/modify/write with the current options using
70 * XIic_GetOptions().
71 *
72 * <b>USAGE EXAMPLE:</b>
73 *
74 * Read/modify/write to enable repeated start:
75 * <pre>
76 *   u8 Options;
77 *   Options = XIic_GetOptions(&Iic);
78 *   XIic_SetOptions(&Iic, Options | XII_REPEATED_START_OPTION);
79 * </pre>
80 *
81 * Disabling General Call:
82 * <pre>
83 *   Options = XIic_GetOptions(&Iic);
84 *   XIic_SetOptions(&Iic, Options &= ~XII_GENERAL_CALL_OPTION);
85 * </pre>
86 *
87 * @param    InstancePtr is a pointer to the XIic instance to be worked on.
88 *
89 * @param    NewOptions are the options to be set.  See xiic.h for a list of
90 *           the available options.
91 *
92 * @return
93 *
94 * None.
95 *
96 * @note
97 *
98 * Sending or receiving messages with repeated start enabled, and then
99 * disabling repeated start, will not take effect until another master
100 * transaction is completed. i.e. After using repeated start, the bus will
101 * continue to be throttled after repeated start is disabled until a master
102 * transaction occurs allowing the IIC to release the bus.
103 * <br><br>
104 * Options enabled will have a 1 in its appropriate bit position.
105 *
106 ****************************************************************************/
107 void
108 XIic_SetOptions(XIic * InstancePtr, u32 NewOptions)
109 {
110         u8 CntlReg;
111
112         XASSERT_VOID(InstancePtr != NULL);
113
114         XIic_mEnterCriticalRegion(InstancePtr->BaseAddress);
115
116         /* Update the options in the instance and get the contents of the control
117          * register such that the general call option can be modified
118          */
119         InstancePtr->Options = NewOptions;
120         CntlReg = XIo_In8(InstancePtr->BaseAddress + XIIC_CR_REG_OFFSET);
121
122         /* The general call option is the only option that maps directly to
123          * a hardware register feature
124          */
125         if (NewOptions & XII_GENERAL_CALL_OPTION) {
126                 CntlReg |= XIIC_CR_GENERAL_CALL_MASK;
127         } else {
128                 CntlReg &= ~XIIC_CR_GENERAL_CALL_MASK;
129         }
130
131         /* Write the new control register value to the register */
132
133         XIo_Out8(InstancePtr->BaseAddress + XIIC_CR_REG_OFFSET, CntlReg);
134
135         XIic_mExitCriticalRegion(InstancePtr->BaseAddress);
136 }
137
138 /*****************************************************************************/
139 /**
140 *
141 * This function gets the current options for the IIC device. Options control
142 * the how the device behaves on the IIC bus. See SetOptions for more information
143 * on options.
144 *
145 * @param    InstancePtr is a pointer to the XIic instance to be worked on.
146 *
147 * @return
148 *
149 * The options of the IIC device. See xiic.h for a list of available options.
150 *
151 * @note
152 *
153 * Options enabled will have a 1 in its appropriate bit position.
154 *
155 ****************************************************************************/
156 u32
157 XIic_GetOptions(XIic * InstancePtr)
158 {
159         XASSERT_NONVOID(InstancePtr != NULL);
160
161         return InstancePtr->Options;
162 }