static inline int bma250_calibration_end(struct device *dev)
{
	int rc = 0;
	struct driver_data *dd = dev_get_drvdata(dev);

	/* power down */
	bma250_power_down(dd);
	dev_dbg(dev, "%s: -> power down.\n", __func__);

	if (dd->recovery_power && dd->ip_dev->users) {
		/* power up & reset*/
		rc = bma250_power_up(dd);
		if (rc)
			goto calib_end_error;

		/* re-schedule by a delay */
		rc = bma250_config(dd, TRUE, TRUE);
		if (rc)
			goto calib_end_error;
		schedule_delayed_work(&dd->work_data, dd->delay_jiffies);

		dev_dbg(dev, "%s: -> power up.\n", __func__);
	}
	return rc;

calib_end_error:
	dev_err(dev, "%s: Calibration end failure.(%d)\n",
		__func__, rc);
	return -EIO;
}
Ejemplo n.º 2
0
static int bma250_suspend(struct i2c_client *ic_dev, pm_message_t mesg)
{
    struct driver_data *dd = bma250_ic_get_data(ic_dev);

    if (dd->ip_dev->users)
        bma250_power_down(dd);

    return 0;
}
Ejemplo n.º 3
0
static int bma250_suspend(struct device *dev)
{
	struct driver_data *dd = dev_get_drvdata(dev);

	bma250_power_down(dd);
	if (dd->pdata && dd->pdata->teardown)
		dd->pdata->teardown(&dd->ic_dev->dev);

	return 0;
}
Ejemplo n.º 4
0
static int bma250_config(struct driver_data *dd)
{
    int rc;

    rc = bma250_bw_handler(dd);
    if (rc)
        goto config_error;

    rc = bma250_range_handler(dd);
    if (rc)
        goto config_error;

    schedule_delayed_work(&dd->work_data, dd->delay_jiffies);
    return rc;

config_error:
    bma250_power_down(dd);
    return rc;
}
Ejemplo n.º 5
0
static int __devexit bma250_remove(struct i2c_client *ic_dev)
{
    struct driver_data *dd = bma250_ic_get_data(ic_dev);
    int                 rc;

    rc = bma250_power_down(dd);
    if (rc)
        dev_err(&dd->ip_dev->dev,
                "%s: power down failed with error %d\n",
                __func__, rc);
    remove_sysfs_interfaces(&dd->ip_dev->dev);
    input_unregister_device(dd->ip_dev);
    bma250_remove_dbfs_entry(dd);
    bma250_ic_set_data(ic_dev, NULL);
    mutex_lock(&bma250_dd_lock);
    list_del(&dd->next_dd);
    mutex_unlock(&bma250_dd_lock);
    kfree(dd);
    return 0;
}
Ejemplo n.º 6
0
static int __devinit bma250_probe(struct i2c_client *ic_dev,
                                  const struct i2c_device_id *id)
{
    struct driver_data *dd;
    int                 rc;
    struct bma250_platform_data *pdata = ic_dev->dev.platform_data;

    if (!pdata || !pdata->hw_config || !pdata->setup || !pdata->teardown)
        return -ENODEV;

    dd = kzalloc(sizeof(struct driver_data), GFP_KERNEL);
    if (!dd) {
        rc = -ENOMEM;
        goto probe_exit;
    }

    mutex_lock(&bma250_dd_lock);
    list_add_tail(&dd->next_dd, &dd_list);
    mutex_unlock(&bma250_dd_lock);
    dd->ic_dev = ic_dev;

    INIT_DELAYED_WORK(&dd->work_data, bma250_work_f);

    dd->pdata = pdata;

    /* initial configuration */
    dd->rate = pdata->rate;
    dd->delay_jiffies = msecs_to_jiffies(dd->rate);
    dd->bw_sel = pdata->reg->bw_sel;
    dd->range = pdata->reg->range;

    rc = bma250_power_up(dd);
    if (rc)
        goto probe_err_cfg;
    rc = bma250_hwid(dd);
    bma250_power_down(dd);
    if (rc)
        goto probe_err_cfg;

    bma250_create_dbfs_entry(dd);
    bma250_ic_set_data(ic_dev, dd);

    dd->ip_dev = input_allocate_device();
    if (!dd->ip_dev) {
        rc = -ENOMEM;
        goto probe_err_reg;
    }
    input_set_drvdata(dd->ip_dev, dd);
    dd->ip_dev->open       = bma250_open;
    dd->ip_dev->close      = bma250_release;
    dd->ip_dev->name       = BMA250_NAME;
    dd->ip_dev->id.vendor  = BMA250_VENDORID;
    dd->ip_dev->id.product = 1;
    dd->ip_dev->id.version = 1;
    __set_bit(EV_ABS,       dd->ip_dev->evbit);
    __set_bit(ABS_X,        dd->ip_dev->absbit);
    __set_bit(ABS_Y,        dd->ip_dev->absbit);
    __set_bit(ABS_Z,        dd->ip_dev->absbit);
    __set_bit(ABS_MISC,     dd->ip_dev->absbit);
    input_set_abs_params(dd->ip_dev, ABS_X, -4096, 4095, 0, 0);
    input_set_abs_params(dd->ip_dev, ABS_Y, -4096, 4095, 0, 0);
    input_set_abs_params(dd->ip_dev, ABS_Z, -4096, 4095, 0, 0);
    input_set_abs_params(dd->ip_dev, ABS_MISC, -80, 175, 0, 0);

    rc = input_register_device(dd->ip_dev);
    if (rc) {
        input_free_device(dd->ip_dev);
        goto probe_err_reg;
    }

    rc = add_sysfs_interfaces(&dd->ip_dev->dev);
    if (rc)
        goto probe_err_sysfs;

    return rc;

probe_err_sysfs:
    input_unregister_device(dd->ip_dev);
probe_err_reg:
    bma250_remove_dbfs_entry(dd);
    bma250_ic_set_data(ic_dev, NULL);
probe_err_cfg:
    mutex_lock(&bma250_dd_lock);
    list_del(&dd->next_dd);
    mutex_unlock(&bma250_dd_lock);
    kfree(dd);
probe_exit:
    return rc;
}
Ejemplo n.º 7
0
static void bma250_release(struct input_dev *dev)
{
    struct driver_data *dd = input_get_drvdata(dev);

    bma250_power_down(dd);
}