mirror of
https://gitlab.com/manzerbredes/ina260-sysfs-driver.git
synced 2025-04-19 04:09:45 +00:00
Minor changes
This commit is contained in:
parent
216617cb72
commit
b50f9839d8
1 changed files with 20 additions and 20 deletions
40
ina260.c
40
ina260.c
|
@ -114,7 +114,7 @@ static ssize_t attr_store(struct kobject *_kobj,
|
|||
struct client_data *cdata=container_of(_kobj,struct client_data,kobj);
|
||||
int data;
|
||||
unsigned char reg=INA260_REG_CONFIGURATION;
|
||||
if(kstrtoint_from_user(buf, count, 10,&data))
|
||||
if(kstrtoint(buf, 0,&data))
|
||||
return -EINVAL;
|
||||
|
||||
if (INA260_IS_ATTR(mask_enable)){
|
||||
|
@ -219,7 +219,7 @@ static int ina260_write_field3(struct client_data *cdata, unsigned char reg, uns
|
|||
// Write bits:
|
||||
mask=~(0x7 << n);
|
||||
value &= mask; // clear bits
|
||||
value |= value3bits << n;
|
||||
value |= (value3bits << n);
|
||||
// Write register value:
|
||||
if(ina260_write_register(cdata,reg,value))
|
||||
return 1;
|
||||
|
@ -236,7 +236,7 @@ static int ina260_write_field1(struct client_data *cdata, unsigned char reg, uns
|
|||
// Set bit:
|
||||
mask=~(1<< n);
|
||||
value &= mask; // clear bit
|
||||
value |= bit << n;
|
||||
value |= (bit << n);
|
||||
// Write register value
|
||||
if(ina260_write_register(cdata,reg,value))
|
||||
return 1;
|
||||
|
@ -245,41 +245,40 @@ static int ina260_write_field1(struct client_data *cdata, unsigned char reg, uns
|
|||
|
||||
static ssize_t attr_field_store(struct kobject *_kobj,
|
||||
struct kobj_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
const char __user *buf, size_t count)
|
||||
{
|
||||
struct client_data *cdata=container_of(_kobj,struct client_data,kobj);
|
||||
int data=0, ret=count;
|
||||
unsigned char reg=INA260_REG_CONFIGURATION;
|
||||
// Extract user supplied value
|
||||
if(kstrtoint_from_user(buf, count, 10,&data))
|
||||
if(kstrtoint(buf, 0,&data))
|
||||
return -EINVAL;
|
||||
// Store:
|
||||
if(INA260_IS_ATTR(reset) && data!=0){
|
||||
ret=ina260_write_register(cdata, reg, 0xFFFF);
|
||||
ret=ina260_write_register(cdata, INA260_REG_CONFIGURATION, 0xFFFF); // Much quicker this way
|
||||
} else if(INA260_IS_ATTR(avg)){
|
||||
ret=ina260_write_field3(cdata,reg,9,data);
|
||||
ret=ina260_write_field3(cdata,INA260_REG_CONFIGURATION,9,data);
|
||||
} else if(INA260_IS_ATTR(mode)){
|
||||
ret=ina260_write_field3(cdata,reg,0,data);
|
||||
ret=ina260_write_field3(cdata,INA260_REG_CONFIGURATION,0,data);
|
||||
} else if(INA260_IS_ATTR(ishct)){
|
||||
ret=ina260_write_field3(cdata,reg,3,data);
|
||||
ret=ina260_write_field3(cdata,INA260_REG_CONFIGURATION,3,data);
|
||||
} else if(INA260_IS_ATTR(vbusct)){
|
||||
ret=ina260_write_field3(cdata,reg,6,data);
|
||||
ret=ina260_write_field3(cdata,INA260_REG_CONFIGURATION,6,data);
|
||||
} else if(INA260_IS_ATTR(ocl)){
|
||||
ret=ina260_write_field1(cdata,reg,15,data);
|
||||
ret=ina260_write_field1(cdata,INA260_REG_MASKENABLE,15,data);
|
||||
} else if(INA260_IS_ATTR(ucl)){
|
||||
ret=ina260_write_field1(cdata,reg,14,data);
|
||||
ret=ina260_write_field1(cdata,INA260_REG_MASKENABLE,14,data);
|
||||
} else if(INA260_IS_ATTR(bol)){
|
||||
ret=ina260_write_field1(cdata,reg,13,data);
|
||||
ret=ina260_write_field1(cdata,INA260_REG_MASKENABLE,13,data);
|
||||
} else if(INA260_IS_ATTR(bul)){
|
||||
ret=ina260_write_field1(cdata,reg,12,data);
|
||||
ret=ina260_write_field1(cdata,INA260_REG_MASKENABLE,12,data);
|
||||
} else if(INA260_IS_ATTR(pol)){
|
||||
ret=ina260_write_field1(cdata,reg,11,data);
|
||||
ret=ina260_write_field1(cdata,INA260_REG_MASKENABLE,11,data);
|
||||
} else if(INA260_IS_ATTR(cnvr)){
|
||||
ret=ina260_write_field1(cdata,reg,10,data);
|
||||
ret=ina260_write_field1(cdata,INA260_REG_MASKENABLE,10,data);
|
||||
} else if(INA260_IS_ATTR(apol)){
|
||||
ret=ina260_write_field1(cdata,reg,1,data);
|
||||
ret=ina260_write_field1(cdata,INA260_REG_MASKENABLE,1,data);
|
||||
} else if(INA260_IS_ATTR(len)){
|
||||
ret=ina260_write_field1(cdata,reg,0,data);
|
||||
ret=ina260_write_field1(cdata,INA260_REG_MASKENABLE,0,data);
|
||||
}
|
||||
return ret ? ret: count;
|
||||
}
|
||||
|
@ -425,11 +424,12 @@ static int ina260_probe_new(struct i2c_client *client){
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void ina260_remove(struct i2c_client *client){
|
||||
static int ina260_remove(struct i2c_client *client){
|
||||
struct client_data *p=i2c_get_clientdata(client);
|
||||
kobject_put(&p->kobj);
|
||||
kfree(p);
|
||||
printk("INA260 addr=0x%x remove from i2c bus %d\n",client->addr,client->adapter->nr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct i2c_driver ina260_driver = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue