/************************************************************************** * * Copyright (c) 2013 Alcatel-Lucent * * Alcatel Lucent licenses this file to You under the Apache License, * Version 2.0 (the "License"); you may not use this file except in * compliance with the License. A copy of the License is contained the * file LICENSE at the top level of this repository. * You may also obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ************************************************************************** * * i2c.c: * * This file contains all of the generic code to support a target * with one or more I-Squared-C interface masters. * It assumes that somewhere in target-specific space there are three * i2c interface functions: i2cRead(), i2cWrite() and i2cCtrl(). * * Original author: Ed Sutter (ed.sutter@alcatel-lucent.com) * */ #include "config.h" #include "cli.h" #include "i2c.h" #include "genlib.h" #include "stddefs.h" int i2cVerbose; char *I2cHelp[] = { "I-Squared-C Interface Access", "[options] {init | show | read addr len | write addr data}", #if INCLUDE_VERBOSEHELP "Options:", " -b burst", " -i{##} interface", " -w{data} pre-write data as part of read (uses repeated start)", " -v verbose", #endif 0, }; int I2cCmd(int argc, char *argv[]) { char *next; uchar buf[256]; int i, wtot, opt, interface, len, rslt, addr, burst, ret, rwctrl; rslt = 0; wtot = 0; burst = 0; rwctrl = 0; interface = 0; i2cVerbose = 0; ret = CMD_SUCCESS; while((opt=getopt(argc,argv,"bi:vw:")) != -1) { switch(opt) { case 'i': interface = atoi(optarg); break; case 'b': burst = 1; /* Do multiple accesses within one START/STOP */ break; case 'w': /* Pre-write in a read */ burst = 1; rwctrl = REPEATED_START; for(wtot=1; wtot sizeof(buf)) { len = sizeof(buf); } if(burst) { addr |= rwctrl; rslt = i2cRead(interface,addr,buf,len); } else { for(i=0; i