diff options
Diffstat (limited to 'drivers/misc/lis3lv02d')
| -rw-r--r-- | drivers/misc/lis3lv02d/lis3lv02d.c | 27 | 
1 files changed, 18 insertions, 9 deletions
| diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c index dd65cedf3b12..70c5bb1e6f49 100644 --- a/drivers/misc/lis3lv02d/lis3lv02d.c +++ b/drivers/misc/lis3lv02d/lis3lv02d.c @@ -208,7 +208,7 @@ static int lis3_3dc_rates[16] = {0, 1, 10, 25, 50, 100, 200, 400, 1600, 5000};  static int lis3_3dlh_rates[4] = {50, 100, 400, 1000};  /* ODR is Output Data Rate */ -static int lis3lv02d_get_odr(struct lis3lv02d *lis3) +static int lis3lv02d_get_odr_index(struct lis3lv02d *lis3)  {  	u8 ctrl;  	int shift; @@ -216,15 +216,23 @@ static int lis3lv02d_get_odr(struct lis3lv02d *lis3)  	lis3->read(lis3, CTRL_REG1, &ctrl);  	ctrl &= lis3->odr_mask;  	shift = ffs(lis3->odr_mask) - 1; -	return lis3->odrs[(ctrl >> shift)]; +	return (ctrl >> shift);  }  static int lis3lv02d_get_pwron_wait(struct lis3lv02d *lis3)  { -	int div = lis3lv02d_get_odr(lis3); +	int odr_idx = lis3lv02d_get_odr_index(lis3); +	int div = lis3->odrs[odr_idx]; -	if (WARN_ONCE(div == 0, "device returned spurious data")) +	if (div == 0) { +		if (odr_idx == 0) { +			/* Power-down mode, not sampling no need to sleep */ +			return 0; +		} + +		dev_err(&lis3->pdev->dev, "Error unknown odrs-index: %d\n", odr_idx);  		return -ENXIO; +	}  	/* LIS3 power on delay is quite long */  	msleep(lis3->pwron_delay / div); @@ -816,9 +824,12 @@ static ssize_t lis3lv02d_rate_show(struct device *dev,  			struct device_attribute *attr, char *buf)  {  	struct lis3lv02d *lis3 = dev_get_drvdata(dev); +	int odr_idx;  	lis3lv02d_sysfs_poweron(lis3); -	return sprintf(buf, "%d\n", lis3lv02d_get_odr(lis3)); + +	odr_idx = lis3lv02d_get_odr_index(lis3); +	return sprintf(buf, "%d\n", lis3->odrs[odr_idx]);  }  static ssize_t lis3lv02d_rate_set(struct device *dev, @@ -1162,16 +1173,14 @@ int lis3lv02d_init_device(struct lis3lv02d *lis3)  		break;  	default:  		pr_err("unknown sensor type 0x%X\n", lis3->whoami); -		return -EINVAL; +		return -ENODEV;  	}  	lis3->reg_cache = kzalloc(max(sizeof(lis3_wai8_regs),  				     sizeof(lis3_wai12_regs)), GFP_KERNEL); -	if (lis3->reg_cache == NULL) { -		printk(KERN_ERR DRIVER_NAME "out of memory\n"); +	if (lis3->reg_cache == NULL)  		return -ENOMEM; -	}  	mutex_init(&lis3->mutex);  	atomic_set(&lis3->wake_thread, 0); | 
