1/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nsc/gfx/gfx_i2c.c,v 1.1 2002/12/10 15:12:25 alanh Exp $ */
2/*
3 * $Workfile: gfx_i2c.c $
4 *
5 * This file contains routines to write to and read from the I2C bus.
6 *
7 * NSC_LIC_ALTERNATIVE_PREAMBLE
8 *
9 * Revision 1.0
10 *
11 * National Semiconductor Alternative GPL-BSD License
12 *
13 * National Semiconductor Corporation licenses this software
14 * ("Software"):
15 *
16 *      Durango
17 *
18 * under one of the two following licenses, depending on how the
19 * Software is received by the Licensee.
20 *
21 * If this Software is received as part of the Linux Framebuffer or
22 * other GPL licensed software, then the GPL license designated
23 * NSC_LIC_GPL applies to this Software; in all other circumstances
24 * then the BSD-style license designated NSC_LIC_BSD shall apply.
25 *
26 * END_NSC_LIC_ALTERNATIVE_PREAMBLE */
27
28/* NSC_LIC_BSD
29 *
30 * National Semiconductor Corporation Open Source License for Durango
31 *
32 * (BSD License with Export Notice)
33 *
34 * Copyright (c) 1999-2001
35 * National Semiconductor Corporation.
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 *   * Redistributions of source code must retain the above copyright
43 *     notice, this list of conditions and the following disclaimer.
44 *
45 *   * Redistributions in binary form must reproduce the above
46 *     copyright notice, this list of conditions and the following
47 *     disclaimer in the documentation and/or other materials provided
48 *     with the distribution.
49 *
50 *   * Neither the name of the National Semiconductor Corporation nor
51 *     the names of its contributors may be used to endorse or promote
52 *     products derived from this software without specific prior
53 *     written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
56 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
57 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
58 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
59 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY
60 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
62 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
64 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
65 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY
66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
67 * OF SUCH DAMAGE.
68 *
69 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
70 * YOUR JURISDICTION. It is licensee's responsibility to comply with
71 * any export regulations applicable in licensee's jurisdiction. Under
72 * CURRENT (2001) U.S. export regulations this software
73 * is eligible for export from the U.S. and can be downloaded by or
74 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed
75 * destinations which include Cuba, Iraq, Libya, North Korea, Iran,
76 * Syria, Sudan, Afghanistan and any other country to which the U.S.
77 * has embargoed goods and services.
78 *
79 * END_NSC_LIC_BSD */
80
81/* NSC_LIC_GPL
82 *
83 * National Semiconductor Corporation Gnu General Public License for Durango
84 *
85 * (GPL License with Export Notice)
86 *
87 * Copyright (c) 1999-2001
88 * National Semiconductor Corporation.
89 * All rights reserved.
90 *
91 * Redistribution and use in source and binary forms, with or without
92 * modification, are permitted under the terms of the GNU General
93 * Public License as published by the Free Software Foundation; either
94 * version 2 of the License, or (at your option) any later version
95 *
96 * In addition to the terms of the GNU General Public License, neither
97 * the name of the National Semiconductor Corporation nor the names of
98 * its contributors may be used to endorse or promote products derived
99 * from this software without specific prior written permission.
100 *
101 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
102 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
103 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
104 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
105 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY
106 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
107 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
108 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
109 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
110 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
111 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY
112 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
113 * OF SUCH DAMAGE. See the GNU General Public License for more details.
114 *
115 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
116 * YOUR JURISDICTION. It is licensee's responsibility to comply with
117 * any export regulations applicable in licensee's jurisdiction. Under
118 * CURRENT (2001) U.S. export regulations this software
119 * is eligible for export from the U.S. and can be downloaded by or
120 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed
121 * destinations which include Cuba, Iraq, Libya, North Korea, Iran,
122 * Syria, Sudan, Afghanistan and any other country to which the U.S.
123 * has embargoed goods and services.
124 *
125 * You should have received a copy of the GNU General Public License
126 * along with this file; if not, write to the Free Software Foundation,
127 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
128 *
129 * END_NSC_LIC_GPL */
130
131/* INCLUDE ROUTINES FOR ACCESS.BUS, IF SPECIFIED */
132/* This is for SC1200 systems. */
133
134#if GFX_I2C_ACCESS
135#include "i2c_acc.c"
136#endif
137
138/* INCLUDE ROUTINES FOR CS5530 GPIOs, IF SPECIFIED */
139/* This is for GXLV systems that use GPIOs on the CS5530 for I2C. */
140
141#if GFX_I2C_GPIO
142#include "i2c_gpio.c"
143#endif
144
145/* WRAPPERS IF DYNAMIC SELECTION */
146/* Extra layer to call either ACCESS.bus or GPIO routines. */
147
148#if GFX_I2C_DYNAMIC
149
150/*---------------------------------------------------------------------------
151 * gfx_i2c_reset
152 *---------------------------------------------------------------------------
153 */
154int
155gfx_i2c_reset(unsigned char busnum, short adr, char freq)
156{
157   int status = GFX_STATUS_UNSUPPORTED;
158
159#if GFX_I2C_ACCESS
160   if (gfx_i2c_type & GFX_I2C_TYPE_ACCESS)
161      status = acc_i2c_reset(busnum, adr, freq);
162#endif
163#if GFX_I2C_GPIO
164   if (gfx_i2c_type & GFX_I2C_TYPE_GPIO)
165      status = gpio_i2c_reset(busnum, adr, freq);
166#endif
167   return (status);
168}
169
170/*---------------------------------------------------------------------------
171 * gfx_i2c_select_gpio
172 *---------------------------------------------------------------------------
173 */
174int
175gfx_i2c_select_gpio(int clock, int data)
176{
177#if GFX_I2C_ACCESS
178   if (gfx_i2c_type & GFX_I2C_TYPE_ACCESS)
179      acc_i2c_select_gpio(clock, data);
180#endif
181#if GFX_I2C_GPIO
182   if (gfx_i2c_type & GFX_I2C_TYPE_GPIO)
183      gpio_i2c_select_gpio(clock, data);
184#endif
185   return (0);
186}
187
188/*---------------------------------------------------------------------------
189 * gfx_i2c_write
190 *---------------------------------------------------------------------------
191 */
192int
193gfx_i2c_write(unsigned char busnum, unsigned char chipadr,
194	      unsigned char subadr, unsigned char bytes, unsigned char *data)
195{
196   int status = -1;
197
198#if GFX_I2C_ACCESS
199   if (gfx_i2c_type & GFX_I2C_TYPE_ACCESS)
200      status = acc_i2c_write(busnum, chipadr, subadr, bytes, data);
201#endif
202#if GFX_I2C_GPIO
203   if (gfx_i2c_type & GFX_I2C_TYPE_GPIO)
204      status = gpio_i2c_write(busnum, chipadr, subadr, bytes, data);
205#endif
206   return (status);
207}
208
209/*---------------------------------------------------------------------------
210 * gfx_i2c_read
211 *---------------------------------------------------------------------------
212 */
213int
214gfx_i2c_read(unsigned char busnum, unsigned char chipadr,
215	     unsigned char subadr, unsigned char bytes, unsigned char *data)
216{
217   int status = -1;
218
219#if GFX_I2C_ACCESS
220   if (gfx_i2c_type & GFX_I2C_TYPE_ACCESS)
221      status = acc_i2c_read(busnum, chipadr, subadr, bytes, data);
222#endif
223#if GFX_I2C_GPIO
224   if (gfx_i2c_type & GFX_I2C_TYPE_GPIO)
225      status = gpio_i2c_read(busnum, chipadr, subadr, bytes, data);
226#endif
227   return (status);
228}
229
230/*---------------------------------------------------------------------------
231 * gfx_i2c_init
232 *---------------------------------------------------------------------------
233 */
234int
235gfx_i2c_init(void)
236{
237   int status = -1;
238
239#if GFX_I2C_ACCESS
240   if (gfx_i2c_type & GFX_I2C_TYPE_ACCESS)
241      status = acc_i2c_init();
242#endif
243#if GFX_I2C_GPIO
244   if (gfx_i2c_type & GFX_I2C_TYPE_GPIO)
245      status = gpio_i2c_init();
246#endif
247   return (status);
248}
249
250/*---------------------------------------------------------------------------
251 * gfx_i2c_cleanup
252 *---------------------------------------------------------------------------
253 */
254void
255gfx_i2c_cleanup(void)
256{
257#if GFX_I2C_ACCESS
258   if (gfx_i2c_type & GFX_I2C_TYPE_ACCESS)
259      acc_i2c_cleanup();
260#endif
261#if GFX_I2C_GPIO
262   if (gfx_i2c_type & GFX_I2C_TYPE_GPIO)
263      gpio_i2c_cleanup();
264#endif
265}
266
267#endif /* GFX_I2C_DYNAMIC */
268
269/* END OF FILE */
270