static int mma7660_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct mma7660_data *mma7660; int err; Xaverage = Yaverage = Zaverage = RawDataNum = 0; mma7660 = kzalloc(sizeof(struct mma7660_data), GFP_KERNEL); if (!mma7660) { rk28printk("[mma7660]:alloc data failed.\n"); err = -ENOMEM; goto exit_alloc_data_failed; } INIT_WORK(&mma7660->work, mma7660_work_func); INIT_DELAYED_WORK(&mma7660->delaywork, mma7660_delaywork_func); mma7660->client = client; //mma7660->swap_xy = i2c_set_clientdata(client, mma7660); this_client = client; err = mma7660_init_client(client); if (err < 0) { rk28printk(KERN_ERR "mma7660_probe: mma7660_init_client failed\n"); goto exit_request_gpio_irq_failed; } mma7660->input_dev = input_allocate_device(); if (!mma7660->input_dev) { err = -ENOMEM; rk28printk(KERN_ERR "mma7660_probe: Failed to allocate input device\n"); goto exit_input_allocate_device_failed; } set_bit(EV_ABS, mma7660->input_dev->evbit); /* x-axis acceleration */ input_set_abs_params(mma7660->input_dev, ABS_X, -1500, 1500, 0, 0); /* y-axis acceleration */ input_set_abs_params(mma7660->input_dev, ABS_Y, -1500, 1500, 0, 0); /* z-axis acceleration */ input_set_abs_params(mma7660->input_dev, ABS_Z, -1500, 1500, 0, 0); mma7660->input_dev->name = "gsensor"; mma7660->input_dev->dev.parent = &client->dev; err = input_register_device(mma7660->input_dev); if (err < 0) { rk28printk(KERN_ERR "mma7660_probe: Unable to register input device: %s\n", mma7660->input_dev->name); goto exit_input_register_device_failed; } mma7660_device.parent = &client->dev; err = misc_register(&mma7660_device); if (err < 0) { rk28printk(KERN_ERR "mma7660_probe: mmad_device register failed\n"); goto exit_misc_device_register_mma7660_device_failed; } err = gsensor_sysfs_init(); if (err < 0) { rk28printk(KERN_ERR "mma7660_probe: gsensor sysfs init failed\n"); goto exit_gsensor_sysfs_init_failed; } #ifdef CONFIG_HAS_EARLYSUSPEND mma7660_early_suspend.suspend = mma7660_suspend; mma7660_early_suspend.resume = mma7660_resume; mma7660_early_suspend.level = 0x2; register_early_suspend(&mma7660_early_suspend); #endif rk28printk(KERN_INFO "mma7660 probe ok\n"); mma7660->status = -1; #if 1 mma7660_start(client, MMA7660_RATE_32); #endif return 0; exit_gsensor_sysfs_init_failed: misc_deregister(&mma7660_device); exit_misc_device_register_mma7660_device_failed: input_unregister_device(mma7660->input_dev); exit_input_register_device_failed: input_free_device(mma7660->input_dev); exit_input_allocate_device_failed: free_irq(client->irq, mma7660); exit_request_gpio_irq_failed: kfree(mma7660); exit_alloc_data_failed: ; return err; }
static int mma7660_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct mma7660_data *mma7660; int err; mma7660 = kzalloc(sizeof(struct mma7660_data), GFP_KERNEL); if (!mma7660) { WPRINTK("[mma7660]:alloc data failed.\n"); err = -ENOMEM; goto exit_alloc_data_failed; } mma7660->mma7660_wq = create_singlethread_workqueue("mma7660_wq"); if (!mma7660->mma7660_wq ) { err = -ENOMEM; goto err_create_workqueue_failed; } INIT_WORK(&mma7660->work, mma7660_work_func); // INIT_DELAYED_WORK(&mma7660->delaywork, mma7660_delaywork_func); mma7660->client = client; i2c_set_clientdata(client, mma7660); this_client = client; /* err = mma7660_init_client(client); if (err < 0) { WPRINTK(KERN_ERR "mma7660_probe: mma7660_init_client failed\n"); goto exit_request_gpio_irq_failed; } */ mma7660->input_dev = input_allocate_device(); if (!mma7660->input_dev) { err = -ENOMEM; WPRINTK(KERN_ERR "mma7660_probe: Failed to allocate input device\n"); goto exit_input_allocate_device_failed; } set_bit(EV_ABS, mma7660->input_dev->evbit); /* x-axis acceleration */ input_set_abs_params(mma7660->input_dev, ABS_X, -MMA7660_RANGE, MMA7660_RANGE, 0, 0); /* y-axis acceleration */ input_set_abs_params(mma7660->input_dev, ABS_Y, -MMA7660_RANGE, MMA7660_RANGE, 0, 0); /* z-axis acceleration */ input_set_abs_params(mma7660->input_dev, ABS_Z, -MMA7660_RANGE, MMA7660_RANGE, 0, 0); mma7660->input_dev->name = "gsensor"; mma7660->input_dev->dev.parent = &client->dev; err = input_register_device(mma7660->input_dev); if (err < 0) { WPRINTK(KERN_ERR "mma7660_probe: Unable to register input device: %s\n", mma7660->input_dev->name); goto exit_input_register_device_failed; } mma7660_device.parent = &client->dev; err = misc_register(&mma7660_device); if (err < 0) { pr_err("mma7660_probe: misc device register failed\n"); goto exit_misc_device_register_mma7660_device_failed; } err = gsensor_sysfs_init(); if (err < 0) { pr_err("mma7660_probe: gsensor sysfs init failed\n"); goto exit_gsensor_sysfs_init_failed; } hrtimer_init(&mma7660->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); mma7660->timer.function = mma7660_timer_func; hrtimer_start(&mma7660->timer, ktime_set(10, 0), HRTIMER_MODE_REL); #ifdef CONFIG_HAS_EARLYSUSPEND mma7660->early_suspend.level = 50 + 1; mma7660->early_suspend.suspend = mma7660_early_suspend; mma7660->early_suspend.resume = mma7660_late_resume; register_early_suspend(&mma7660->early_suspend); #endif pr_info("mma7660 probe ok\n"); mma7660->status = -1; #if 0 mma7660_start(client, MMA7660_RATE_32); #endif return 0; exit_gsensor_sysfs_init_failed: misc_deregister(&mma7660_device); exit_misc_device_register_mma7660_device_failed: input_unregister_device(mma7660->input_dev); exit_input_register_device_failed: input_free_device(mma7660->input_dev); exit_input_allocate_device_failed: destroy_workqueue(mma7660->mma7660_wq); //free_irq(client->irq, mma7660); //exit_request_gpio_irq_failed: // kfree(mma7660); err_create_workqueue_failed: kfree(mma7660); exit_alloc_data_failed: pr_info("mma7660 probe failed!\n"); return err; }
static int mma8452_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct mma8452_data *mma8452; struct mma8452_platform_data *pdata = pdata = client->dev.platform_data; int err; char devid; mmaprintkf("%s enter\n",__FUNCTION__); mma8452 = kzalloc(sizeof(struct mma8452_data), GFP_KERNEL); if (!mma8452) { mmaprintk("[mma8452]:alloc data failed.\n"); err = -ENOMEM; goto exit_alloc_data_failed; } INIT_WORK(&mma8452->work, mma8452_work_func); INIT_DELAYED_WORK(&mma8452->delaywork, mma8452_delaywork_func); memset(&(mma8452->sense_data), 0, sizeof(struct mma8452_axis) ); mutex_init(&(mma8452->sense_data_mutex) ); atomic_set(&(mma8452->data_ready), 0); init_waitqueue_head(&(mma8452->data_ready_wq) ); mma8452->start_count = 0; mutex_init(&(mma8452->operation_mutex) ); mma8452->status = MMA8452_CLOSE; mma8452->client = client; i2c_set_clientdata(client, mma8452); this_client = client; devid = mma8452_get_devid(this_client); if ((MMA8452_DEVID != devid) && (MMA8451_DEVID != devid)) { pr_info("mma8452: invalid devid\n"); goto exit_invalid_devid; } err = mma8452_init_client(client); if (err < 0) { mmaprintk(KERN_ERR "mma8452_probe: mma8452_init_client failed\n"); goto exit_request_gpio_irq_failed; } mma8452->input_dev = input_allocate_device(); if (!mma8452->input_dev) { err = -ENOMEM; mmaprintk(KERN_ERR "mma8452_probe: Failed to allocate input device\n"); goto exit_input_allocate_device_failed; } set_bit(EV_ABS, mma8452->input_dev->evbit); /* x-axis acceleration */ input_set_abs_params(mma8452->input_dev, ABS_X, -2000, 2000, 0, 0); //2g full scale range /* y-axis acceleration */ input_set_abs_params(mma8452->input_dev, ABS_Y, -2000, 2000, 0, 0); //2g full scale range /* z-axis acceleration */ input_set_abs_params(mma8452->input_dev, ABS_Z, -2000, 2000, 0, 0); //2g full scale range // mma8452->input_dev->name = "compass"; mma8452->input_dev->name = "gsensor"; mma8452->input_dev->dev.parent = &client->dev; err = input_register_device(mma8452->input_dev); if (err < 0) { mmaprintk(KERN_ERR "mma8452_probe: Unable to register input device: %s\n", mma8452->input_dev->name); goto exit_input_register_device_failed; } mma8452_device.parent = &client->dev; err = misc_register(&mma8452_device); if (err < 0) { mmaprintk(KERN_ERR "mma8452_probe: mmad_device register failed\n"); goto exit_misc_device_register_mma8452_device_failed; } err = gsensor_sysfs_init(); if (err < 0) { mmaprintk(KERN_ERR "mma8452_probe: gsensor sysfs init failed\n"); goto exit_gsensor_sysfs_init_failed; } #ifdef CONFIG_HAS_EARLYSUSPEND mma8452_early_suspend.suspend = mma8452_suspend; mma8452_early_suspend.resume = mma8452_resume; mma8452_early_suspend.level = 0x2; register_early_suspend(&mma8452_early_suspend); #endif printk(KERN_INFO "mma8452 probe ok\n"); #if 0 // mma8452_start_test(this_client); mma8452_start(client, MMA8452_RATE_12P5); #endif return 0; exit_gsensor_sysfs_init_failed: misc_deregister(&mma8452_device); exit_misc_device_register_mma8452_device_failed: input_unregister_device(mma8452->input_dev); exit_input_register_device_failed: input_free_device(mma8452->input_dev); exit_input_allocate_device_failed: free_irq(client->irq, mma8452); exit_request_gpio_irq_failed: cancel_delayed_work_sync(&mma8452->delaywork); cancel_work_sync(&mma8452->work); exit_invalid_devid: kfree(mma8452); exit_alloc_data_failed: ; mmaprintk("%s error\n",__FUNCTION__); return -1; }
static int lis3dh_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct lis3dh_data *lis3dh; struct lis3dh_platform_data *pdata = pdata = client->dev.platform_data; int liRet = -1; char devid; stprintkf("%s enter\n",__FUNCTION__); lis3dh = kzalloc(sizeof(struct lis3dh_data), GFP_KERNEL); if (!lis3dh) { stprintk("[lis3dh]:alloc data failed.\n"); liRet = -ENOMEM; goto exit_alloc_data_failed; } else { //nothig } INIT_WORK(&lis3dh->work, lis3dh_work_func); INIT_DELAYED_WORK(&lis3dh->delaywork, lis3dh_delaywork_func); memset(&(lis3dh->sense_data), 0, sizeof(struct lis3dh_axis) ); mutex_init(&(lis3dh->sense_data_mutex) ); atomic_set(&(lis3dh->data_ready), 0); init_waitqueue_head(&(lis3dh->data_ready_wq) ); lis3dh->start_count = 0; mutex_init(&(lis3dh->operation_mutex) ); lis3dh->status = LIS3DH_CLOSE; lis3dh->client = client; i2c_set_clientdata(client, lis3dh); this_client = client; devid = lis3dh_get_devid(lis3dh); if (devid != WHOAMI_LIS3DH_ACC) { pr_info("lis3dh: invalid devid\n"); goto exit_invalid_devid; } else { //nothing } liRet = lis3dh_init_device(lis3dh); if (devid < 0) { pr_info("lis3dh: init err\n"); goto exit_invalid_devid; } else { //nothing } liRet = lis3dh_init_client(client); if (liRet < 0) { stprintk(KERN_ERR "lis3dh_probe: lis3dh_init_client failed\n"); goto exit_request_irq_failed; } else { //nothing } lis3dh->input_dev = input_allocate_device(); if (!lis3dh->input_dev) { liRet = -ENOMEM; stprintk(KERN_ERR "lis3dh_probe: Failed to allocate input device\n"); goto exit_input_allocate_device_failed; } else { //nothing } set_bit(EV_ABS, lis3dh->input_dev->evbit); /* x-axis acceleration */ input_set_abs_params(lis3dh->input_dev, ABS_X, -LIS3DH_RANGE, LIS3DH_RANGE, 0, 0); //2g full scale range /* y-axis acceleration */ input_set_abs_params(lis3dh->input_dev, ABS_Y, -LIS3DH_RANGE, LIS3DH_RANGE, 0, 0); //2g full scale range /* z-axis acceleration */ input_set_abs_params(lis3dh->input_dev, ABS_Z, -LIS3DH_RANGE, LIS3DH_RANGE, 0, 0); //2g full scale range lis3dh->input_dev->name = "gsensor"; lis3dh->input_dev->dev.parent = &client->dev; liRet = input_register_device(lis3dh->input_dev); if (liRet < 0) { stprintk(KERN_ERR "lis3dh_probe: Unable to register input device: %s\n",lis3dh->input_dev->name); goto exit_input_register_device_failed; } else { //nothing } lis3dh_device.parent = &client->dev; liRet = misc_register(&lis3dh_device); if (liRet < 0) { stprintk(KERN_ERR"lis3dh_probe: mmad_device register failed\n"); goto exit_misc_device_failed; } else { //nothing } liRet = gsensor_sysfs_init(); if (liRet < 0) { stprintk(KERN_ERR "lis3dh_probe: gsensor sysfs init failed\n"); goto exit_gsensor_sysfs_init_failed; } else { //nothing } #ifdef CONFIG_HAS_EARLYSUSPEND lis3dh_early_suspend.suspend = lis3dh_suspend; lis3dh_early_suspend.resume = lis3dh_resume; lis3dh_early_suspend.level = 0x2; register_early_suspend(&lis3dh_early_suspend); #endif printk(KERN_INFO "lis3dh probe ok\n"); return 0; exit_gsensor_sysfs_init_failed: misc_deregister(&lis3dh_device); exit_misc_device_failed: input_unregister_device(lis3dh->input_dev); exit_input_register_device_failed: input_free_device(lis3dh->input_dev); exit_input_allocate_device_failed: free_irq(client->irq, lis3dh); exit_request_irq_failed: cancel_delayed_work_sync(&lis3dh->delaywork); cancel_work_sync(&lis3dh->work); exit_invalid_devid: kfree(lis3dh); exit_alloc_data_failed: stprintk("%s error\n",__FUNCTION__); return -1; }