1/* Copyright (c) 2005 Advanced Micro Devices, Inc. 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining a copy 4 * of this software and associated documentation files (the "Software"), to 5 * deal in the Software without restriction, including without limitation the 6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 * sell copies of the Software, and to permit persons to whom the Software is 8 * furnished to do so, subject to the following conditions: 9 * 10 * The above copyright notice and this permission notice shall be included in 11 * all copies or substantial portions of the Software. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 * IN THE SOFTWARE. 20 * 21 * Neither the name of the Advanced Micro Devices, Inc. nor the names of its 22 * contributors may be used to endorse or promote products derived from this 23 * software without specific prior written permission. 24 * */ 25 26/* 27 * This file contains routines to write to and read from the I2C bus. 28 * */ 29 30/* INCLUDE ROUTINES FOR ACCESS.BUS, IF SPECIFIED */ 31/* This is for SC1200 systems. */ 32 33#if GFX_I2C_ACCESS 34#include "i2c_acc.c" 35#endif 36 37/* INCLUDE ROUTINES FOR CS5530 GPIOs, IF SPECIFIED */ 38/* This is for GXLV systems that use GPIOs on the CS5530 for I2C. */ 39 40#if GFX_I2C_GPIO 41#include "i2c_gpio.c" 42#endif 43 44/* WRAPPERS IF DYNAMIC SELECTION */ 45/* Extra layer to call either ACCESS.bus or GPIO routines. */ 46 47#if GFX_I2C_DYNAMIC 48 49/*--------------------------------------------------------------------------- 50 * gfx_i2c_reset 51 *--------------------------------------------------------------------------- 52 */ 53int 54gfx_i2c_reset(unsigned char busnum, short adr, char freq) 55{ 56 int status = GFX_STATUS_UNSUPPORTED; 57 58#if GFX_I2C_ACCESS 59 if (gfx_i2c_type & GFX_I2C_TYPE_ACCESS) 60 status = acc_i2c_reset(busnum, adr, freq); 61#endif 62#if GFX_I2C_GPIO 63 if (gfx_i2c_type & GFX_I2C_TYPE_GPIO) 64 status = gpio_i2c_reset(busnum, adr, freq); 65#endif 66 return (status); 67} 68 69/*--------------------------------------------------------------------------- 70 * gfx_i2c_select_gpio 71 *--------------------------------------------------------------------------- 72 */ 73int 74gfx_i2c_select_gpio(int clock, int data) 75{ 76#if GFX_I2C_ACCESS 77 if (gfx_i2c_type & GFX_I2C_TYPE_ACCESS) 78 acc_i2c_select_gpio(clock, data); 79#endif 80#if GFX_I2C_GPIO 81 if (gfx_i2c_type & GFX_I2C_TYPE_GPIO) 82 gpio_i2c_select_gpio(clock, data); 83#endif 84 return (0); 85} 86 87/*--------------------------------------------------------------------------- 88 * gfx_i2c_write 89 *--------------------------------------------------------------------------- 90 */ 91int 92gfx_i2c_write(unsigned char busnum, unsigned char chipadr, 93 unsigned char subadr, unsigned char bytes, unsigned char *data) 94{ 95 int status = -1; 96 97#if GFX_I2C_ACCESS 98 if (gfx_i2c_type & GFX_I2C_TYPE_ACCESS) 99 status = acc_i2c_write(busnum, chipadr, subadr, bytes, data); 100#endif 101#if GFX_I2C_GPIO 102 if (gfx_i2c_type & GFX_I2C_TYPE_GPIO) 103 status = gpio_i2c_write(busnum, chipadr, subadr, bytes, data); 104#endif 105 return (status); 106} 107 108/*--------------------------------------------------------------------------- 109 * gfx_i2c_read 110 *--------------------------------------------------------------------------- 111 */ 112int 113gfx_i2c_read(unsigned char busnum, unsigned char chipadr, 114 unsigned char subadr, unsigned char bytes, unsigned char *data) 115{ 116 int status = -1; 117 118#if GFX_I2C_ACCESS 119 if (gfx_i2c_type & GFX_I2C_TYPE_ACCESS) 120 status = acc_i2c_read(busnum, chipadr, subadr, bytes, data); 121#endif 122#if GFX_I2C_GPIO 123 if (gfx_i2c_type & GFX_I2C_TYPE_GPIO) 124 status = gpio_i2c_read(busnum, chipadr, subadr, bytes, data); 125#endif 126 return (status); 127} 128 129/*--------------------------------------------------------------------------- 130 * gfx_i2c_init 131 *--------------------------------------------------------------------------- 132 */ 133int 134gfx_i2c_init(void) 135{ 136 int status = -1; 137 138#if GFX_I2C_ACCESS 139 if (gfx_i2c_type & GFX_I2C_TYPE_ACCESS) 140 status = acc_i2c_init(); 141#endif 142#if GFX_I2C_GPIO 143 if (gfx_i2c_type & GFX_I2C_TYPE_GPIO) 144 status = gpio_i2c_init(); 145#endif 146 return (status); 147} 148 149/*--------------------------------------------------------------------------- 150 * gfx_i2c_cleanup 151 *--------------------------------------------------------------------------- 152 */ 153void 154gfx_i2c_cleanup(void) 155{ 156#if GFX_I2C_ACCESS 157 if (gfx_i2c_type & GFX_I2C_TYPE_ACCESS) 158 acc_i2c_cleanup(); 159#endif 160#if GFX_I2C_GPIO 161 if (gfx_i2c_type & GFX_I2C_TYPE_GPIO) 162 gpio_i2c_cleanup(); 163#endif 164} 165 166#endif /* GFX_I2C_DYNAMIC */ 167 168/* END OF FILE */ 169