mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-25 17:27:01 +00:00
debug the onlp code for ag7648 in github
This commit is contained in:
1
packages/platforms/delta/x86-64/x86-64-delta-ag7648/onlp/builds/src/module/src/debug.c
Normal file → Executable file
1
packages/platforms/delta/x86-64/x86-64-delta-ag7648/onlp/builds/src/module/src/debug.c
Normal file → Executable file
@@ -1,4 +1,3 @@
|
||||
#include "x86_64_delta_ag7648_int.h"
|
||||
|
||||
#if X86_64_DELTA_AG7648_CONFIG_INCLUDE_DEBUG == 1
|
||||
|
||||
|
||||
@@ -33,94 +33,6 @@
|
||||
#include <AIM/aim.h>
|
||||
#include "platform_lib.h"
|
||||
|
||||
int deviceNodeWrite(char *filename, char *buffer, int buf_size, int data_len)
|
||||
{
|
||||
int fd;
|
||||
int len;
|
||||
|
||||
if ((buffer == NULL) || (buf_size < 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((fd = open(filename, O_WRONLY, S_IWUSR)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((len = write(fd, buffer, buf_size)) < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((close(fd) == -1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((len > buf_size) || (data_len != 0 && len != data_len)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int deviceNodeWriteInt(char *filename, int value, int data_len)
|
||||
{
|
||||
char buf[8] = {0};
|
||||
sprintf(buf, "%d", value);
|
||||
|
||||
return deviceNodeWrite(filename, buf, sizeof(buf)-1, data_len);
|
||||
}
|
||||
|
||||
int deviceNodeReadBinary(char *filename, char *buffer, int buf_size, int data_len)
|
||||
{
|
||||
int fd;
|
||||
int len;
|
||||
|
||||
if ((buffer == NULL) || (buf_size < 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((fd = open(filename, O_RDONLY)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((len = read(fd, buffer, buf_size)) < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((close(fd) == -1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((len > buf_size) || (data_len != 0 && len != data_len)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int deviceNodeReadString(char *filename, char *buffer, int buf_size, int data_len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (data_len >= buf_size || data_len < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = deviceNodeReadBinary(filename, buffer, buf_size-1, data_len);
|
||||
|
||||
if (ret == 0) {
|
||||
if (data_len) {
|
||||
buffer[data_len] = '\0';
|
||||
}
|
||||
else {
|
||||
buffer[buf_size-1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define I2C_PSU_MODEL_NAME_LEN 13
|
||||
|
||||
psu_type_t get_psu_type(int id, char* modelname, int modelname_len)
|
||||
|
||||
@@ -332,7 +332,7 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256])
|
||||
else
|
||||
sprintf(sfp_name, "QSFP%d", port);
|
||||
for(i=0;i<8;i++){
|
||||
if (i2c_devname_read_block(sfp_name, (32*i), (char*)(data+32*i), 32) < 0)
|
||||
if (i2c_devname_read_block(sfp_name, (32*i), (uint8_t*)(data+32*i), 32) < 0)
|
||||
{
|
||||
AIM_LOG_ERROR("Unable to read the port %d eeprom\r\n", port);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
|
||||
@@ -78,15 +78,16 @@ onlp_sysi_platform_info_get(onlp_platform_info_t* pi)
|
||||
int
|
||||
onlp_sysi_onie_data_get(uint8_t** data, int* size)
|
||||
{
|
||||
|
||||
int i,re_cnt;
|
||||
uint8_t* rdata = aim_zmalloc(256);
|
||||
|
||||
int i,re_cnt;
|
||||
|
||||
if(!rdata){
|
||||
AIM_LOG_ERROR("Unable to malloc memory \r\n");
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
}
|
||||
for(i=0;i<8;i++){
|
||||
re_cnt=3;
|
||||
while(re_cnt){
|
||||
if (i2c_devname_read_block("ID_EEPROM", i * 32, (char *)(rdata + i * 32), 32) < 0)
|
||||
if (i2c_devname_read_block("ID_EEPROM", i * 32, (rdata + i * 32), 32) < 0)
|
||||
{
|
||||
re_cnt--;
|
||||
continue;
|
||||
@@ -95,11 +96,11 @@ onlp_sysi_onie_data_get(uint8_t** data, int* size)
|
||||
}
|
||||
if(re_cnt==0){
|
||||
AIM_LOG_ERROR("Unable to read the %d reg \r\n",i);
|
||||
return ONLP_STATUS_E_INTERNAL;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
*data = rdata;
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
@@ -144,6 +145,16 @@ onlp_sysi_oids_get(onlp_oid_t* table, int max)
|
||||
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
onlp_sysi_onie_info_get(onlp_onie_info_t* onie)
|
||||
{
|
||||
if(onie){
|
||||
onie->platform_name = aim_strdup(ONIE_PLATFORM_NAME);
|
||||
}
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
onlp_sysi_platform_manage_fans(void)
|
||||
|
||||
20
packages/platforms/delta/x86-64/x86-64-delta-ag7648/onlp/builds/src/module/src/thermali.c
Normal file → Executable file
20
packages/platforms/delta/x86-64/x86-64-delta-ag7648/onlp/builds/src/module/src/thermali.c
Normal file → Executable file
@@ -41,17 +41,6 @@
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define OPEN_READ_FILE(fd,fullpath,data,nbytes,len) \
|
||||
DEBUG_PRINT("[Debug][%s][%d][openfile: %s]\n", __FUNCTION__, __LINE__, fullpath); \
|
||||
if ((fd = open(fullpath, O_RDONLY)) == -1) \
|
||||
return ONLP_STATUS_E_INTERNAL; \
|
||||
if ((len = read(fd, r_data, nbytes)) <= 0){ \
|
||||
close(fd); \
|
||||
return ONLP_STATUS_E_INTERNAL;} \
|
||||
DEBUG_PRINT("[Debug][%s][%d][read data: %s]\n", __FUNCTION__, __LINE__, r_data); \
|
||||
if (close(fd) == -1) \
|
||||
return ONLP_STATUS_E_INTERNAL
|
||||
|
||||
enum onlp_thermal_id
|
||||
{
|
||||
THERMAL_RESERVED = 0,
|
||||
@@ -125,8 +114,8 @@ onlp_thermali_init(void)
|
||||
int
|
||||
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
|
||||
{
|
||||
int fd, len, nbytes = 10, temp_base=1, local_id;
|
||||
char r_data[10] = {0};
|
||||
int len, nbytes = 10, temp_base=1, local_id;
|
||||
uint8_t r_data[10]={0};
|
||||
char fullpath[50] = {0};
|
||||
VALIDATE(id);
|
||||
|
||||
@@ -139,9 +128,10 @@ onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
|
||||
/* get fullpath */
|
||||
sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]);
|
||||
|
||||
OPEN_READ_FILE(fd, fullpath, r_data, nbytes, len);
|
||||
//OPEN_READ_FILE(fd, fullpath, r_data, nbytes, len);
|
||||
onlp_file_read(r_data,nbytes,&len, fullpath);
|
||||
|
||||
info->mcelsius = atoi(r_data) / temp_base;
|
||||
info->mcelsius =ONLPLIB_ATOI((char*)r_data) / temp_base;
|
||||
|
||||
DEBUG_PRINT("\n[Debug][%s][%d][save data: %d]\n", __FUNCTION__, __LINE__, info->mcelsius);
|
||||
|
||||
|
||||
@@ -33,8 +33,7 @@
|
||||
#include <pthread.h>
|
||||
#include "x86_64_delta_ag7648_log.h"
|
||||
#include "x86_64_delta_i2c.h"
|
||||
#include "x86_64_delta_i2c_dev.h"
|
||||
|
||||
#include <onlplib/i2c.h>
|
||||
struct i2c_device_info i2c_device_list[]={
|
||||
{"RTC",0X0,0X69},
|
||||
{"TMP1_CLOSE_TO_CPU",0X2,0X4d},
|
||||
@@ -119,6 +118,7 @@ struct i2c_device_info i2c_device_list[]={
|
||||
#define I2C_DATA_C 3
|
||||
#define I2C_DATA_QUICK 4
|
||||
|
||||
uint32_t i2c_flag=ONLP_I2C_F_FORCE;
|
||||
|
||||
static pthread_mutex_t i2c_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
@@ -132,153 +132,6 @@ void I2C_UNPROTECT (void)
|
||||
pthread_mutex_unlock (&i2c_mutex);
|
||||
}
|
||||
|
||||
static int open_i2cbus_dev(int i2cbus, char *filename, int quiet)
|
||||
{
|
||||
int file;
|
||||
|
||||
sprintf(filename, "/dev/i2c-%d", i2cbus);
|
||||
file = open(filename, O_RDWR);
|
||||
|
||||
if (file < 0 && !quiet) {
|
||||
if (errno == ENOENT) {
|
||||
fprintf(stderr, "Error: Could not open file "
|
||||
"`/dev/i2c-%d: %s'\n",i2cbus, strerror(ENOENT));
|
||||
} else {
|
||||
fprintf(stderr, "Error: Could not open file "
|
||||
"`%s': %s\n", filename, strerror(errno));
|
||||
if (errno == EACCES)
|
||||
fprintf(stderr, "Run as root?\n");
|
||||
}
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
static int set_slave_addr(int file, int address, int force)
|
||||
{
|
||||
/* hack */
|
||||
force = 1; /* force always, it will break th i2c driver's behave */
|
||||
|
||||
|
||||
/* With force, let the user read from/write to the registers
|
||||
even when a driver is also running */
|
||||
if (ioctl(file, force ? I2C_SLAVE_FORCE : I2C_SLAVE, address) < 0) {
|
||||
if (errno != EBUSY) {
|
||||
fprintf(stderr,
|
||||
"Error: Could not set address to 0x%02x: %s\n",
|
||||
address, strerror(errno));
|
||||
return -errno;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int i2c_dev_read (int i2cbus, int dev, int reg, int mode)
|
||||
{
|
||||
int file;
|
||||
char filename[20];
|
||||
int force = 0;
|
||||
int res = 0;
|
||||
|
||||
file = open_i2cbus_dev(i2cbus, filename, 0);
|
||||
if (file < 0) return -1;
|
||||
|
||||
if (set_slave_addr(file, dev, force))return -1;
|
||||
|
||||
switch (mode) {
|
||||
case I2C_DATA_W:
|
||||
res = i2c_smbus_read_word_data(file, reg);
|
||||
break;
|
||||
case I2C_DATA_C:
|
||||
if (reg >= 0) {
|
||||
res = i2c_smbus_write_byte(file, reg);
|
||||
if (res < 0) break;
|
||||
}
|
||||
res = i2c_smbus_read_byte(file);
|
||||
break;
|
||||
default:
|
||||
res = i2c_smbus_read_byte_data(file, reg);
|
||||
break;
|
||||
}
|
||||
close(file);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int i2c_dev_write (int i2cbus, int dev, int reg, int value, int mode)
|
||||
{
|
||||
int file;
|
||||
char filename[20];
|
||||
int force = 0;
|
||||
int res = 0;
|
||||
|
||||
file = open_i2cbus_dev(i2cbus, filename, 0);
|
||||
if (file < 0) return -1;
|
||||
|
||||
if (set_slave_addr(file, dev, force)) return -1;
|
||||
|
||||
switch (mode) {
|
||||
case I2C_DATA_W:
|
||||
res = i2c_smbus_write_word_data(file, reg, value);
|
||||
break;
|
||||
case I2C_DATA_C:
|
||||
res = i2c_smbus_write_byte (file, reg);
|
||||
break;
|
||||
case I2C_DATA_QUICK:
|
||||
res = i2c_smbus_write_quick(file, I2C_SMBUS_WRITE);
|
||||
break;
|
||||
default:
|
||||
res = i2c_smbus_write_byte_data(file, reg, value);
|
||||
break;
|
||||
|
||||
}
|
||||
close(file);
|
||||
usleep (5000);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int i2c_block_read (int i2cbus, int dev, int reg, char *buff, int buff_len)
|
||||
{
|
||||
int file;
|
||||
char filename[20];
|
||||
int force = 0;
|
||||
int res = 0;
|
||||
|
||||
file = open_i2cbus_dev(i2cbus, filename, 0);
|
||||
|
||||
if (file < 0) return -1;
|
||||
|
||||
if (set_slave_addr(file, dev, force)) return -1;
|
||||
|
||||
res = i2c_smbus_read_i2c_block_data (file, reg, buff_len, (__u8 *)buff);
|
||||
|
||||
close(file);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int i2c_block_write (int i2cbus, int dev, int reg, char *buff, int buff_len)
|
||||
{
|
||||
int file;
|
||||
char filename[20];
|
||||
int force = 0;
|
||||
int res = 0;
|
||||
|
||||
file = open_i2cbus_dev(i2cbus, filename, 0);
|
||||
|
||||
if (file < 0) return -1;
|
||||
|
||||
if (set_slave_addr(file, dev, force)) return -1;
|
||||
|
||||
res = i2c_smbus_write_i2c_block_data (file, reg, buff_len, (__u8 *)buff);
|
||||
|
||||
close(file);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
i2c_device_info_t *i2c_dev_find_by_name (char *name)
|
||||
{
|
||||
i2c_device_info_t *i2c_dev = i2c_device_list;
|
||||
@@ -304,7 +157,7 @@ int i2c_devname_read_byte (char *name, int reg)
|
||||
|
||||
I2C_PROTECT();
|
||||
|
||||
ret=i2c_dev_read (i2c_dev->i2cbus, i2c_dev->addr, reg, I2C_DATA_B);
|
||||
ret=onlp_i2c_readb(i2c_dev->i2cbus, i2c_dev->addr, reg, i2c_flag);
|
||||
|
||||
I2C_UNPROTECT();
|
||||
|
||||
@@ -320,7 +173,7 @@ int i2c_devname_write_byte (char *name, int reg, int value)
|
||||
|
||||
I2C_PROTECT();
|
||||
|
||||
ret=i2c_dev_write (i2c_dev->i2cbus, i2c_dev->addr, reg, value, I2C_DATA_B);
|
||||
ret=onlp_i2c_writeb (i2c_dev->i2cbus, i2c_dev->addr, reg, value, i2c_flag);
|
||||
|
||||
I2C_UNPROTECT();
|
||||
|
||||
@@ -336,7 +189,7 @@ int i2c_devname_read_word (char *name, int reg)
|
||||
|
||||
I2C_PROTECT();
|
||||
|
||||
ret=i2c_dev_read (i2c_dev->i2cbus, i2c_dev->addr, reg, I2C_DATA_W);
|
||||
ret=onlp_i2c_readw(i2c_dev->i2cbus, i2c_dev->addr, reg, i2c_flag);
|
||||
|
||||
I2C_UNPROTECT();
|
||||
|
||||
@@ -352,14 +205,14 @@ int i2c_devname_write_word (char *name, int reg, int value)
|
||||
|
||||
I2C_PROTECT();
|
||||
|
||||
ret=i2c_dev_write (i2c_dev->i2cbus, i2c_dev->addr, reg, value, I2C_DATA_W);
|
||||
ret=onlp_i2c_writew (i2c_dev->i2cbus, i2c_dev->addr, reg, value, i2c_flag);
|
||||
|
||||
I2C_UNPROTECT();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int i2c_devname_read_block (char *name, int reg, char *buff, int buff_size)
|
||||
int i2c_devname_read_block (char *name, int reg, uint8_t*buff, int buff_size)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
@@ -369,7 +222,7 @@ int i2c_devname_read_block (char *name, int reg, char *buff, int buff_size)
|
||||
|
||||
I2C_PROTECT();
|
||||
|
||||
ret = i2c_block_read (i2c_dev->i2cbus, i2c_dev->addr, reg, buff, buff_size);
|
||||
ret =onlp_i2c_block_read (i2c_dev->i2cbus, i2c_dev->addr, reg, buff_size, buff, i2c_flag);
|
||||
|
||||
I2C_UNPROTECT();
|
||||
|
||||
@@ -377,20 +230,3 @@ int i2c_devname_read_block (char *name, int reg, char *buff, int buff_size)
|
||||
|
||||
}
|
||||
|
||||
int i2c_devname_write_block (char *name, int reg, char *buff, int buff_size)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
i2c_device_info_t *i2c_dev = i2c_dev_find_by_name (name);
|
||||
|
||||
if(i2c_dev==NULL) return -1;
|
||||
|
||||
I2C_PROTECT();
|
||||
|
||||
ret = i2c_block_write (i2c_dev->i2cbus, i2c_dev->addr, reg, buff, buff_size);
|
||||
|
||||
I2C_UNPROTECT();
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ extern int i2c_devname_read_word(char *name, int reg);
|
||||
extern int i2c_devname_write_word(char *name, int reg, int value);
|
||||
|
||||
|
||||
extern int i2c_devname_read_block (char *name, int reg, char *buff, int buff_size);
|
||||
extern int i2c_devname_write_block(char *name, int reg, char *buff, int buff_size);
|
||||
extern int i2c_devname_read_block (char *name, int reg, uint8_t*buff, int buff_size);
|
||||
//extern int i2c_devname_write_block(char *name, int reg, char *buff, int buff_size);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,209 +0,0 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
* Copyright 2016 Accton Technology Corporation.
|
||||
* Copyright 2017 Delta Networks, Inc
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************/
|
||||
|
||||
#ifndef __X86_64_DELTA_I2C_DEV_H__
|
||||
#define __X86_64_DELTA_I2C_DEV_H__
|
||||
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "x86_64_delta_ag7648_log.h"
|
||||
|
||||
/* -- i2c.h -- */
|
||||
|
||||
//#include <linux/i2c.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
#if 0
|
||||
static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command,
|
||||
int size, union i2c_smbus_data *data)
|
||||
{
|
||||
struct i2c_smbus_ioctl_data args;
|
||||
|
||||
args.read_write = read_write;
|
||||
args.command = command;
|
||||
args.size = size;
|
||||
args.data = data;
|
||||
return ioctl(file,I2C_SMBUS,&args);
|
||||
}
|
||||
|
||||
|
||||
static inline __s32 i2c_smbus_write_quick(int file, __u8 value)
|
||||
{
|
||||
return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
|
||||
}
|
||||
|
||||
static inline __s32 i2c_smbus_read_byte(int file)
|
||||
{
|
||||
union i2c_smbus_data data;
|
||||
if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))
|
||||
return -1;
|
||||
else
|
||||
return 0x0FF & data.byte;
|
||||
}
|
||||
|
||||
static inline __s32 i2c_smbus_write_byte(int file, __u8 value)
|
||||
{
|
||||
return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
|
||||
I2C_SMBUS_BYTE,NULL);
|
||||
}
|
||||
|
||||
static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)
|
||||
{
|
||||
union i2c_smbus_data data;
|
||||
if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
|
||||
I2C_SMBUS_BYTE_DATA,&data))
|
||||
return -1;
|
||||
else
|
||||
return 0x0FF & data.byte;
|
||||
}
|
||||
|
||||
static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command,
|
||||
__u8 value)
|
||||
{
|
||||
union i2c_smbus_data data;
|
||||
data.byte = value;
|
||||
return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
|
||||
I2C_SMBUS_BYTE_DATA, &data);
|
||||
}
|
||||
|
||||
static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)
|
||||
{
|
||||
union i2c_smbus_data data;
|
||||
if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
|
||||
I2C_SMBUS_WORD_DATA,&data))
|
||||
return -1;
|
||||
else
|
||||
return 0x0FFFF & data.word;
|
||||
}
|
||||
|
||||
static inline __s32 i2c_smbus_write_word_data(int file, __u8 command,
|
||||
__u16 value)
|
||||
{
|
||||
union i2c_smbus_data data;
|
||||
data.word = value;
|
||||
return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
|
||||
I2C_SMBUS_WORD_DATA, &data);
|
||||
}
|
||||
|
||||
static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)
|
||||
{
|
||||
union i2c_smbus_data data;
|
||||
data.word = value;
|
||||
if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
|
||||
I2C_SMBUS_PROC_CALL,&data))
|
||||
return -1;
|
||||
else
|
||||
return 0x0FFFF & data.word;
|
||||
}
|
||||
|
||||
|
||||
/* Returns the number of read bytes */
|
||||
static inline __s32 i2c_smbus_read_block_data(int file, __u8 command,
|
||||
__u8 *values)
|
||||
{
|
||||
union i2c_smbus_data data;
|
||||
int i;
|
||||
if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
|
||||
I2C_SMBUS_BLOCK_DATA,&data))
|
||||
return -1;
|
||||
else {
|
||||
for (i = 1; i <= data.block[0]; i++)
|
||||
values[i-1] = data.block[i];
|
||||
return data.block[0];
|
||||
}
|
||||
}
|
||||
|
||||
static inline __s32 i2c_smbus_write_block_data(int file, __u8 command,
|
||||
__u8 length, const __u8 *values)
|
||||
{
|
||||
union i2c_smbus_data data;
|
||||
int i;
|
||||
if (length > 32)
|
||||
length = 32;
|
||||
for (i = 1; i <= length; i++)
|
||||
data.block[i] = values[i-1];
|
||||
data.block[0] = length;
|
||||
return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
|
||||
I2C_SMBUS_BLOCK_DATA, &data);
|
||||
}
|
||||
|
||||
/* Returns the number of read bytes */
|
||||
/* Until kernel 2.6.22, the length is hardcoded to 32 bytes. If you
|
||||
ask for less than 32 bytes, your code will only work with kernels
|
||||
2.6.23 and later. */
|
||||
static inline __s32 i2c_smbus_read_i2c_block_data(int file, __u8 command,
|
||||
__u8 length, __u8 *values)
|
||||
{
|
||||
union i2c_smbus_data data;
|
||||
int i;
|
||||
|
||||
if (length > 32)
|
||||
length = 32;
|
||||
data.block[0] = length;
|
||||
if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
|
||||
length == 32 ? I2C_SMBUS_I2C_BLOCK_BROKEN :
|
||||
I2C_SMBUS_I2C_BLOCK_DATA,&data))
|
||||
return -1;
|
||||
else {
|
||||
for (i = 1; i <= data.block[0]; i++)
|
||||
values[i-1] = data.block[i];
|
||||
return data.block[0];
|
||||
}
|
||||
}
|
||||
|
||||
static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command,
|
||||
__u8 length,
|
||||
const __u8 *values)
|
||||
{
|
||||
union i2c_smbus_data data;
|
||||
int i;
|
||||
if (length > 32)
|
||||
length = 32;
|
||||
for (i = 1; i <= length; i++)
|
||||
data.block[i] = values[i-1];
|
||||
data.block[0] = length;
|
||||
return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
|
||||
I2C_SMBUS_I2C_BLOCK_BROKEN, &data);
|
||||
}
|
||||
|
||||
/* Returns the number of read bytes */
|
||||
static inline __s32 i2c_smbus_block_process_call(int file, __u8 command,
|
||||
__u8 length, __u8 *values)
|
||||
{
|
||||
union i2c_smbus_data data;
|
||||
int i;
|
||||
if (length > 32)
|
||||
length = 32;
|
||||
for (i = 1; i <= length; i++)
|
||||
data.block[i] = values[i-1];
|
||||
data.block[0] = length;
|
||||
if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
|
||||
I2C_SMBUS_BLOCK_PROC_CALL,&data))
|
||||
return -1;
|
||||
else {
|
||||
for (i = 1; i <= data.block[0]; i++)
|
||||
values[i-1] = data.block[i];
|
||||
return data.block[0];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user