int initialize_magnetic_sensor(struct ssp_data *data) { int iRet; struct input_dev *input_dev; /* allocate input_device */ input_dev = input_allocate_device(); if (input_dev == NULL) return ERROR; input_dev->name = MODULE_NAME; input_set_capability(input_dev, EV_REL, REL_RX); input_set_capability(input_dev, EV_REL, REL_RY); input_set_capability(input_dev, EV_REL, REL_RZ); input_set_drvdata(input_dev, data); /* register input_device */ iRet = input_register_device(input_dev); if (iRet < 0) { input_free_device(input_dev); return ERROR; } iRet = sensors_create_symlink(&input_dev->dev.kobj, input_dev->name); if (iRet < 0) goto err_creat_symlink; iRet = device_create_file(&input_dev->dev, &dev_attr_mag_poll_delay); if (iRet < 0) goto err_creat_file; iRet = sensors_register(data->mag_device, data, mag_attrs, MODULE_NAME); if (iRet < 0) goto err_sensor_register; data->mag_input_dev = input_dev; return SUCCESS; err_sensor_register: device_remove_file(&input_dev->dev, &dev_attr_mag_poll_delay); err_creat_file: sensors_remove_symlink(&input_dev->dev.kobj, input_dev->name); err_creat_symlink: input_unregister_device(input_dev); pr_err("[SSP]: %s - fail!\n", __func__); return ERROR; }
static int cm3323_input_init(struct cm3323_p *data) { int ret = 0; struct input_dev *dev; /* allocate lightsensor input_device */ dev = input_allocate_device(); if (!dev) return -ENOMEM; dev->name = MODULE_NAME; dev->id.bustype = BUS_I2C; input_set_capability(dev, EV_REL, REL_RED); input_set_capability(dev, EV_REL, REL_GREEN); input_set_capability(dev, EV_REL, REL_BLUE); input_set_capability(dev, EV_REL, REL_WHITE); input_set_drvdata(dev, data); ret = input_register_device(dev); if (ret < 0) { input_free_device(data->input); return ret; } ret = sensors_create_symlink(&dev->dev.kobj, dev->name); if (ret < 0) { input_unregister_device(dev); return ret; } ret = sysfs_create_group(&dev->dev.kobj, &light_attribute_group); if (ret < 0) { sensors_remove_symlink(&data->input->dev.kobj, data->input->name); input_unregister_device(dev); return ret; } data->input = dev; return 0; }
static int ak09911c_input_init(struct ak09911c_p *data) { int ret = 0; struct input_dev *dev; dev = input_allocate_device(); if (!dev) return -ENOMEM; dev->name = MODULE_NAME; dev->id.bustype = BUS_I2C; input_set_capability(dev, EV_REL, REL_X); input_set_capability(dev, EV_REL, REL_Y); input_set_capability(dev, EV_REL, REL_Z); input_set_drvdata(dev, data); ret = input_register_device(dev); if (ret < 0) { input_free_device(dev); return ret; } ret = sensors_create_symlink(&dev->dev.kobj, dev->name); if (ret < 0) { input_unregister_device(dev); return ret; } /* sysfs node creation */ ret = sysfs_create_group(&dev->dev.kobj, &ak09911c_attribute_group); if (ret < 0) { sensors_remove_symlink(&data->input->dev.kobj, data->input->name); input_unregister_device(dev); return ret; } data->input = dev; return 0; }
static int bma254_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = 0; struct bma254_data *bma254; struct input_dev *dev; #ifdef CONFIG_BMA254_SMART_ALERT int err = 0; struct bma254_platform_data *pdata; #endif pr_info("%s, is called\n", __func__); if (client == NULL) { pr_err("%s, client doesn't exist\n", __func__); ret = -ENOMEM; return ret; } #ifdef CONFIG_SENSORS_POWERCONTROL ret = bma254_regulator_onoff(&client->dev, true); if (ret) { pr_err("%s, Power Up Failed\n", __func__); return ret; } #endif if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("%s,client not i2c capable\n", __func__); return -ENOMEM; } ret = i2c_smbus_read_word_data(client, BMA254_CHIP_ID); if ((ret & 0x00ff) != 0xfa) { pr_err("%s,i2c failed(%x)\n", __func__, ret & 0x00ff); ret = -ENOMEM; return ret; } else { pr_err("%s,chip id %x\n", __func__, ret & 0x00ff); } bma254 = kzalloc(sizeof(struct bma254_data), GFP_KERNEL); if (!bma254) { pr_err("%s, kzalloc error\n", __func__); ret = -ENOMEM; return ret; } #ifdef CONFIG_BMA254_SMART_ALERT if(client->dev.of_node) { pdata = devm_kzalloc(&client->dev, sizeof(struct bma254_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&client->dev, "Failed to allocate memory \n"); kfree(bma254); return -ENOMEM; } }else{ pr_err("%s,this_node is empty\n", __func__); kfree(bma254); return -ENODEV; } bma254->pdata = pdata; #endif ret = bma254_parse_dt(bma254, &client->dev); if (ret) { pr_err("%s, get gpio is failed\n", __func__); goto parse_dt_err; } i2c_set_clientdata(client, bma254); bma254->client = client; bma254_activate(bma254, false); dev = input_allocate_device(); if (!dev){ goto input_allocate_device_err; } dev->name = "accelerometer"; dev->id.bustype = BUS_I2C; #if !defined(CONFIG_MACH_VICTORLTE) && !defined(CONFIG_MACH_VICTOR3GDSDTV_LTN) dev->dev.parent = &client->dev; #endif #ifdef REPORT_ABS input_set_capability(dev, EV_ABS, ABS_MISC); input_set_abs_params(dev, ABS_X, ABSMIN, ABSMAX, 0, 0); input_set_abs_params(dev, ABS_Y, ABSMIN, ABSMAX, 0, 0); input_set_abs_params(dev, ABS_Z, ABSMIN, ABSMAX, 0, 0); #else input_set_capability(dev, EV_REL, REL_X); input_set_capability(dev, EV_REL, REL_Y); input_set_capability(dev, EV_REL, REL_Z); #endif input_set_drvdata(dev, bma254); ret = input_register_device(dev); if (ret < 0) { pr_err("%s,sysfs_create_group failed\n", __func__); goto input_register_device_err; } bma254->input = dev; #ifdef CONFIG_BMA254_SMART_ALERT pr_info("%s: HW_rev success %d\n", __func__, system_rev); INIT_WORK(&bma254->alert_work, bma254_work_func_alert); wake_lock_init(&bma254->reactive_wake_lock, WAKE_LOCK_SUSPEND, "reactive_wake_lock"); err = bma254_setup_irq(bma254); if (err) { bma254->pin_check_fail = true; pr_err("%s: could not setup irq\n", __func__); goto err_setup_irq; } mutex_init(&bma254->data_mutex); #endif ret = sensors_create_symlink(&dev->dev.kobj, dev->name); if (ret < 0) { input_unregister_device(dev); return ret; } ret = sysfs_create_group(&bma254->input->dev.kobj, &bma254_attribute_group); if (ret < 0) { pr_err("%s,sysfs_create_group failed\n", __func__); sensors_remove_symlink(&bma254->input->dev.kobj, bma254->input->name); goto sysfs_create_group_err; } INIT_DELAYED_WORK(&bma254->work, bma254_work_func); bma254->delay = MAX_DELAY; bma254->enable = 0; ret = sensors_register(bma254->dev, bma254, bma254_attrs, "accelerometer_sensor"); if (ret < 0) { pr_info("%s: could not sensors_register\n", __func__); goto sensors_register_err; } #ifdef CONFIG_SENSORS_POWERCONTROL bma254_regulator_onoff(&client->dev, false); #endif pr_info("[SENSOR]: %s - Probe done!(chip pos : %d)\n", __func__, bma254->position); return 0; sensors_register_err: sysfs_remove_group(&bma254->input->dev.kobj, &bma254_attribute_group); sensors_remove_symlink(&bma254->input->dev.kobj, bma254->input->name); sysfs_create_group_err: input_unregister_device(bma254->input); #ifdef CONFIG_BMA254_SMART_ALERT err_setup_irq: wake_lock_destroy(&bma254->reactive_wake_lock); #endif input_register_device_err: input_free_device(dev); input_allocate_device_err: parse_dt_err: kfree(bma254); pr_err("[SENSOR]: %s - Probe fail!\n", __func__); #ifdef CONFIG_SENSORS_POWERCONTROL bma254_regulator_onoff(&client->dev, false); #endif return ret; }
static int cm36686_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = -ENODEV; struct cm36686_data *cm36686 = NULL; struct cm36686_platform_data *pdata = NULL; int err; pr_info("[SENSOR] %s: Probe Start!\n", __func__); if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("[SENSOR] %s: i2c functionality check failed!\n", __func__); return ret; } cm36686 = kzalloc(sizeof(struct cm36686_data), GFP_KERNEL); if (!cm36686) { pr_err ("[SENSOR] %s: failed to alloc memory for RGB sensor module data\n", __func__); return -ENOMEM; } if(client->dev.of_node) { pdata = devm_kzalloc (&client->dev , sizeof(struct cm36686_platform_data ), GFP_KERNEL); if(!pdata) { dev_err(&client->dev, "Failed to allocate memory\n"); if(cm36686) kfree(cm36686); return -ENOMEM; } err = cm36686_parse_dt(&client->dev, pdata); if(err) goto err_devicetree; } else pdata = client->dev.platform_data; if (!pdata) { pr_err("%s: missing pdata!\n", __func__); if(cm36686) kfree(cm36686); return ret; } prox_regulator_onoff(&client->dev,1); cm36686->pdata = pdata; cm36686->i2c_client = client; i2c_set_clientdata(client, cm36686); mutex_init(&cm36686->power_lock); mutex_init(&cm36686->read_lock); /* wake lock init for proximity sensor */ wake_lock_init(&cm36686->prx_wake_lock, WAKE_LOCK_SUSPEND, "prx_wake_lock"); #if defined(CONFIG_SENSORS_CM36686_LEDA_EN_GPIO) /* setup leden_gpio */ ret = cm36686_setup_leden_gpio(cm36686); if (ret) { pr_err("%s: could not setup leden_gpio\n", __func__); goto err_setup_leden_gpio; } cm36686_leden_gpio_onoff(cm36686, 1); #else prox_led_onoff(cm36686, 1); #endif /* Check if the device is there or not. */ ret = cm36686_i2c_write_word(cm36686, REG_CS_CONF1, 0x0001); if (ret < 0) { pr_err("[SENSOR] %s: cm36686 is not connected.(%d)\n", __func__, ret); goto err_setup_reg; } /* setup initial registers */ ret = cm36686_setup_reg(cm36686); if (ret < 0) { pr_err("[SENSOR] %s: could not setup regs\n", __func__); goto err_setup_reg; } #if defined(CONFIG_SENSORS_CM36686_LEDA_EN_GPIO) cm36686_leden_gpio_onoff(cm36686, 0); #else prox_led_onoff(cm36686, 0); #endif /* allocate proximity input_device */ cm36686->proximity_input_dev = input_allocate_device(); if (!cm36686->proximity_input_dev) { pr_err("%s: could not allocate proximity input device\n", __func__); goto err_input_allocate_device_proximity; } input_set_drvdata(cm36686->proximity_input_dev, cm36686); cm36686->proximity_input_dev->name = "proximity_sensor"; input_set_capability(cm36686->proximity_input_dev, EV_ABS, ABS_DISTANCE); input_set_abs_params(cm36686->proximity_input_dev, ABS_DISTANCE, 0, 1, 0, 0); ret = input_register_device(cm36686->proximity_input_dev); if (ret < 0) { input_free_device(cm36686->proximity_input_dev); pr_err("[SENSOR] %s: could not register input device\n", __func__); goto err_input_register_device_proximity; } ret = sensors_create_symlink(&cm36686->proximity_input_dev->dev.kobj, cm36686->proximity_input_dev->name); if (ret < 0) { pr_err("[SENSOR] %s: create_symlink error\n", __func__); goto err_sensors_create_symlink_prox; } ret = sysfs_create_group(&cm36686->proximity_input_dev->dev.kobj, &proximity_attribute_group); if (ret) { pr_err("[SENSOR] %s: could not create sysfs group\n", __func__); goto err_sysfs_create_group_proximity; } /* setup irq */ ret = cm36686_setup_irq(cm36686); if (ret) { pr_err("%s: could not setup irq\n", __func__); goto err_setup_irq; } /* For factory test mode, we use timer to get average proximity data. */ /* prox_timer settings. we poll for light values using a timer. */ hrtimer_init(&cm36686->prox_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); cm36686->prox_poll_delay = ns_to_ktime(2000 * NSEC_PER_MSEC);/*2 sec*/ cm36686->prox_timer.function = cm36686_prox_timer_func; /* the timer just fires off a work queue request. we need a thread to read the i2c (can be slow and blocking). */ cm36686->prox_wq = create_singlethread_workqueue("cm36686_prox_wq"); if (!cm36686->prox_wq) { ret = -ENOMEM; pr_err("[SENSOR] %s: could not create prox workqueue\n", __func__); goto err_create_prox_workqueue; } /* this is the thread function we run on the work queue */ INIT_WORK(&cm36686->work_prox, cm36686_work_func_prox); /* allocate lightsensor input_device */ cm36686->light_input_dev = input_allocate_device(); if (!cm36686->light_input_dev) { pr_err("%s: could not allocate light input device\n", __func__); goto err_input_allocate_device_light; } input_set_drvdata(cm36686->light_input_dev, cm36686); cm36686->light_input_dev->name = "light_sensor"; input_set_capability(cm36686->light_input_dev, EV_REL, REL_MISC); input_set_capability(cm36686->light_input_dev, EV_REL, REL_DIAL); input_set_capability(cm36686->light_input_dev, EV_REL, REL_WHEEL); ret = input_register_device(cm36686->light_input_dev); if (ret < 0) { input_free_device(cm36686->light_input_dev); pr_err("%s: could not register input device\n", __func__); goto err_input_register_device_light; } ret = sensors_create_symlink(&cm36686->light_input_dev->dev.kobj, cm36686->light_input_dev->name); if (ret < 0) { pr_err("[SENSOR] %s: create_symlink error\n", __func__); goto err_sensors_create_symlink_light; } ret = sysfs_create_group(&cm36686->light_input_dev->dev.kobj, &light_attribute_group); if (ret) { pr_err("[SENSOR] %s: could not create sysfs group\n", __func__); goto err_sysfs_create_group_light; } /* light_timer settings. we poll for light values using a timer. */ hrtimer_init(&cm36686->light_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); cm36686->light_poll_delay = ns_to_ktime(200 * NSEC_PER_MSEC); cm36686->light_timer.function = cm36686_light_timer_func; /* the timer just fires off a work queue request. we need a thread to read the i2c (can be slow and blocking). */ cm36686->light_wq = create_singlethread_workqueue("cm36686_light_wq"); if (!cm36686->light_wq) { ret = -ENOMEM; pr_err("[SENSOR] %s: could not create light workqueue\n", __func__); goto err_create_light_workqueue; } /* this is the thread function we run on the work queue */ INIT_WORK(&cm36686->work_light, cm36686_work_func_light); /* set sysfs for proximity sensor */ ret = sensors_register(cm36686->proximity_dev, cm36686, prox_sensor_attrs, "proximity_sensor"); if (ret) { pr_err("[SENSOR] %s: cound not register\ proximity sensor device(%d).\n", __func__, ret); goto prox_sensor_register_failed; } /* set sysfs for light sensor */ ret = sensors_register(cm36686->light_dev, cm36686, light_sensor_attrs, "light_sensor"); if (ret) { pr_err("[SENSOR] %s: cound not register\ light sensor device(%d).\n", __func__, ret); goto light_sensor_register_failed; } pr_info("[SENSOR] %s is success.\n", __func__); goto done; err_devicetree: printk("\n error in device tree"); /* error, unwind it all */ light_sensor_register_failed: sensors_unregister(cm36686->proximity_dev, prox_sensor_attrs); prox_sensor_register_failed: destroy_workqueue(cm36686->light_wq); err_create_light_workqueue: sysfs_remove_group(&cm36686->light_input_dev->dev.kobj, &light_attribute_group); err_sysfs_create_group_light: sensors_remove_symlink(&cm36686->light_input_dev->dev.kobj, cm36686->light_input_dev->name); err_sensors_create_symlink_light: input_unregister_device(cm36686->light_input_dev); err_input_register_device_light: err_input_allocate_device_light: destroy_workqueue(cm36686->prox_wq); err_create_prox_workqueue: free_irq(cm36686->irq, cm36686); gpio_free(cm36686->pdata->irq); err_setup_irq: sysfs_remove_group(&cm36686->proximity_input_dev->dev.kobj, &proximity_attribute_group); err_sysfs_create_group_proximity: sensors_remove_symlink(&cm36686->proximity_input_dev->dev.kobj, cm36686->proximity_input_dev->name); err_sensors_create_symlink_prox: input_unregister_device(cm36686->proximity_input_dev); err_input_register_device_proximity: err_input_allocate_device_proximity: err_setup_reg: #if defined(CONFIG_SENSORS_CM36686_LEDA_EN_GPIO) cm36686_leden_gpio_onoff(cm36686, 0); gpio_free(cm36686->pdata->leden_gpio); err_setup_leden_gpio: #else prox_led_onoff(cm36686, 0); #endif wake_lock_destroy(&cm36686->prx_wake_lock); mutex_destroy(&cm36686->read_lock); mutex_destroy(&cm36686->power_lock); kfree(cm36686); prox_regulator_onoff(&client->dev,0); done: return ret; }
static int gp2a_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = 0; struct input_dev *input_dev; struct gp2a_data *gp2a; struct gp2a_platform_data *pdata = client->dev.platform_data; pr_info("%s, start\n", __func__); ret = gp2a_regulator_onoff(&client->dev, true); if (ret) { pr_err("%s, Power Up Failed\n", __func__); return ret; } if (client->dev.of_node) { pdata = devm_kzalloc(&client->dev, sizeof(struct gp2a_platform_data), GFP_KERNEL); if (!pdata) { pr_err("%s,Failed to allocate memory\n", __func__); return -ENOMEM; } ret = gp2a_parse_dt(&client->dev, pdata); if (ret < 0) return ret; ret = gp2a_request_gpio(pdata); if (ret < 0) return ret; } if (!pdata) { pr_err("%s,missing pdata\n", __func__); return -ENOMEM; } if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("%s,i2c functionality failed\n", __func__); return -ENOMEM; } gp2a = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL); if (!gp2a) { pr_err("%s,failed memory alloc\n", __func__); return -ENOMEM; } gp2a->pdata = pdata; gp2a->i2c_client = client; i2c_set_clientdata(client, gp2a); wake_lock_init(&gp2a->prx_wake_lock, WAKE_LOCK_SUSPEND, "prx_wake_lock"); mutex_init(&gp2a->power_lock); input_dev = input_allocate_device(); if (!input_dev) { pr_err("%s,could not allocate input device\n", __func__); goto err_input_allocate_device_proximity; } gp2a->input = input_dev; input_dev->name = "proximity_sensor"; input_set_capability(input_dev, EV_ABS, ABS_DISTANCE); input_set_abs_params(input_dev, ABS_DISTANCE, 0, 1, 0, 0); input_set_drvdata(input_dev, gp2a); ret = input_register_device(input_dev); if (ret < 0) { pr_err("%s,could not register input device\n", __func__); goto err_input_register_device_proximity; } ret = sensors_create_symlink(&input_dev->dev.kobj, input_dev->name); if (ret < 0) { pr_err("%s,create sysfs symlink error\n", __func__); goto err_sysfs_create_symlink_proximity; } ret = sysfs_create_group(&input_dev->dev.kobj, &proximity_attribute_group); if (ret) { pr_err("%s,create sysfs group error\n", __func__); goto err_sysfs_create_group_proximity; } INIT_WORK(&gp2a->work_prox, gp2a_prox_work_func); gp2a_leda_onoff(gp2a, 1); ret = gp2a_setup_irq(gp2a); if (ret) { pr_err("%s,could not setup irq\n", __func__); goto err_setup_irq; } gp2a_leda_onoff(gp2a, 0); ret = sensors_register(gp2a->dev, gp2a, proxi_attrs, "proximity_sensor"); if (ret < 0) { pr_info("%s,could not sensors_register\n", __func__); goto exit_gp2a_sensors_register; } pr_info("%s done\n", __func__); goto done; exit_gp2a_sensors_register: free_irq(gp2a->irq, gp2a); gpio_free(gp2a->pdata->p_out); err_setup_irq: gp2a_leda_onoff(gp2a, 0); sysfs_remove_group(&gp2a->input->dev.kobj, &proximity_attribute_group); err_sysfs_create_group_proximity: sensors_remove_symlink(&gp2a->input->dev.kobj, gp2a->input->name); err_sysfs_create_symlink_proximity: input_unregister_device(gp2a->input); err_input_register_device_proximity: input_free_device(input_dev); err_input_allocate_device_proximity: mutex_destroy(&gp2a->power_lock); wake_lock_destroy(&gp2a->prx_wake_lock); kfree(gp2a); done: gp2a_regulator_onoff(&client->dev, false); return ret; }
static int gp2a_probe(struct i2c_client *client, const struct i2c_device_id *id) { int err = 0; struct gp2a_data *data; u8 value; pr_info("%s, is called\n", __func__); if (client == NULL) { pr_err("%s, client doesn't exist\n", __func__); err = -ENOMEM; return err; } data = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL); if (!data) { pr_err("%s, kzalloc error\n", __func__); err = -ENOMEM; return err; } err = gp2a_parse_dt(data, &client->dev); if (err) { pr_err("%s, get gpio is failed\n", __func__); goto gp2a_parse_dt_err; } data->client = client; data->light_delay = MAX_DELAY; bShutdown = false; i2c_set_clientdata(client, data); sensor_power_on_vdd(data, 1); value = 0x00; err = gp2a_i2c_write(data, (u8) (COMMAND1), &value); if (err < 0) { pr_err("%s failed : threre is no such device.\n", __func__); goto i2c_fail_err; } data->light_input_dev = input_allocate_device(); if (!data->light_input_dev) { pr_err("%s input_allocate_device error\n", __func__); err = -ENOMEM; goto input_allocate_light_device_err; } data->light_input_dev->name = "light_sensor"; input_set_capability(data->light_input_dev, EV_REL, REL_MAX); input_set_capability(data->light_input_dev, EV_REL, REL_MISC); input_set_drvdata(data->light_input_dev, data); err = input_register_device(data->light_input_dev); if (err < 0) { pr_err("%s input_register_device light error\n", __func__); goto input_register_device_err; } err = sensors_create_symlink(&data->light_input_dev->dev.kobj, data->light_input_dev->name); if (err < 0) { pr_err("%s sensors_create_symlink light error\n", __func__); goto sensors_create_symlink_err; } err = sysfs_create_group(&data->light_input_dev->dev.kobj, &gp2a_light_attribute_group); if (err) { pr_err("%s sysfs_create_group light error\n", __func__); goto sysfs_create_group_light_err; } err = gp2a_setup_irq(data); if (err) { pr_err("%s: could not setup irq\n", __func__); goto err_setup_irq; } data->prox_input_dev = input_allocate_device(); if (!data->prox_input_dev) { pr_err("%s input_allocate_device error\n", __func__); err = -ENOMEM; goto input_allocate_prox_device_err; } data->prox_input_dev->name = "proximity_sensor"; input_set_capability(data->prox_input_dev, EV_ABS, ABS_DISTANCE); input_set_capability(data->prox_input_dev, EV_ABS, ABS_MAX); input_set_abs_params(data->prox_input_dev, ABS_DISTANCE, 0, 1, 0, 0); input_set_abs_params(data->prox_input_dev, ABS_MAX, 0, 1, 0, 0); input_set_drvdata(data->prox_input_dev, data); err = input_register_device(data->prox_input_dev); if (err < 0) { pr_err("%s input_register_device prox error\n", __func__); goto input_register_prox_device_err; } err = sensors_create_symlink(&data->prox_input_dev->dev.kobj, data->prox_input_dev->name); if (err < 0) { pr_err("%s sensors_create_symlink light error\n", __func__); goto sensors_create_symlink_light_err; } err = sysfs_create_group(&data->prox_input_dev->dev.kobj, &gp2a_prox_attribute_group); if (err) { pr_err("%s sysfs_create_group prox error\n", __func__); goto sysfs_create_group_prox_err; } err = sensors_register(data->light_sensor_device, data, light_sensor_attrs, "light_sensor"); if (err) { pr_err("%s: cound not register prox sensor device(%d).\n", __func__, err); goto sensors_register_light_err; } err = sensors_register(data->prox_sensor_device, data, prox_sensor_attrs, "proximity_sensor"); if (err) { pr_err("%s: cound not register prox sensor device(%d).\n", __func__, err); goto sensors_register_prox_err; } mutex_init(&data->light_mutex); mutex_init(&data->data_mutex); INIT_DELAYED_WORK(&data->light_work, gp2a_work_func_light); wake_lock_init(&data->prx_wake_lock, WAKE_LOCK_SUSPEND, "prx_wake_lock"); INIT_WORK(&data->proximity_work, gp2a_work_func_prox); INIT_DELAYED_WORK(&data->prox_avg_work, gp2a_work_avg_prox); goto done; mutex_destroy(&data->light_mutex); mutex_destroy(&data->data_mutex); sensors_unregister(data->prox_sensor_device, prox_sensor_attrs); sensors_register_prox_err: sensors_unregister(data->light_sensor_device, light_sensor_attrs); sensors_register_light_err: sysfs_remove_group(&data->prox_input_dev->dev.kobj, &gp2a_prox_attribute_group); sysfs_create_group_prox_err: sensors_remove_symlink(&data->prox_input_dev->dev.kobj, data->prox_input_dev->name); sensors_create_symlink_err: input_unregister_device(data->prox_input_dev); input_register_prox_device_err: input_free_device(data->prox_input_dev); input_allocate_prox_device_err: gpio_free(data->gpio); err_setup_irq: sysfs_remove_group(&data->light_input_dev->dev.kobj, &gp2a_light_attribute_group); sysfs_create_group_light_err: sensors_remove_symlink(&data->light_input_dev->dev.kobj, data->light_input_dev->name); sensors_create_symlink_light_err: input_unregister_device(data->light_input_dev); input_register_device_err: input_free_device(data->light_input_dev); input_allocate_light_device_err: i2c_fail_err: gp2a_parse_dt_err: sensor_power_on_vdd(data, 0); kfree(data); bShutdown = true; done: return err; }
static int uv_probe(struct platform_device *pdev) { struct uv_info *uv; struct uv_platform_data *pdata = pdev->dev.platform_data; int ret = 0; pr_info("%s: is started\n", __func__); if (!pdata) { pr_err("%s: pdata is NULL\n", __func__); return -ENODEV; } /* allocate memory */ uv = kzalloc(sizeof(struct uv_info), GFP_KERNEL); if (uv == NULL) { pr_err("%s: Failed to allocate memory\n", __func__); return -ENOMEM; } uv->pdata = pdata; /* Setup for ADC */ /* alloc platform device for adc client */ uv->pdev_uv_adc = platform_device_alloc("uv-adc", -1); if (!uv->pdev_uv_adc) { pr_err("%s: could not allocation uv-adc\n", __func__); goto err_alloc_pdev; } if (pdata->adc_ap_init && pdata->adc_ap_exit) { uv->pdata->adc_ap_init = pdata->adc_ap_init; uv->pdata->adc_ap_exit = pdata->adc_ap_exit; ret = pdata->adc_ap_init(uv->pdev_uv_adc); if (!ret) { ret = -1; goto err_setup_adc; } } if (pdata->power_on) { uv->pdata->power_on = pdata->power_on; uv->pdata->power_on(false); } uv->onoff = false; if (pdata->get_adc_value) uv->pdata->get_adc_value = pdata->get_adc_value; mutex_init(&uv->power_lock); mutex_init(&uv->read_lock); /* allocate uv input device */ uv->uv_input_dev = input_allocate_device(); if (!uv->uv_input_dev) { pr_err("%s: could not allocate input device\n", __func__); goto err_input_allocate_device_uv; } input_set_drvdata(uv->uv_input_dev, uv); uv->uv_input_dev->name = "uv_sensor"; input_set_capability(uv->uv_input_dev, EV_REL, REL_MISC); ret = input_register_device(uv->uv_input_dev); if (ret < 0) { pr_err("%s: could not register input device\n", __func__); input_free_device(uv->uv_input_dev); goto err_input_register_device_uv; } ret = sysfs_create_group(&uv->uv_input_dev->dev.kobj, &uv_attribute_group); if (ret) { pr_err("%s: could not create sysfs group\n", __func__); goto err_sysfs_create_group_uv; } /* timer init */ hrtimer_init(&uv->uv_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); uv->uv_poll_delay = ns_to_ktime(200 * NSEC_PER_MSEC); uv->uv_timer.function = uv_timer_func; /* workqueue init */ uv->uv_wq = create_singlethread_workqueue("uv_wq"); if (!uv->uv_wq) { ret = -ENOMEM; pr_err("%s: could not create uv workqueue\n", __func__); goto err_create_uv_workqueue; } INIT_WORK(&uv->work_uv, work_func_uv); /* sysfs for uv sensor */ ret = sensors_register(uv->uv_dev, uv, uv_sensor_attrs, "uv_sensor"); if (ret) { pr_err("%s: could not register uv device(%d)\n", __func__, ret); goto err_sensor_register_failed; } ret = sensors_create_symlink(&uv->uv_input_dev->dev.kobj, uv->uv_input_dev->name); if (ret < 0) { pr_err("%s, sensors_create_symlinks failed!(%d)\n", __func__, ret); goto err_uv_input__sysfs_create_link; } #ifdef CONFIG_HAS_EARLYSUSPEND uv->early_suspend.suspend = ssp_early_suspend; uv->early_suspend.resume = ssp_late_resume; register_early_suspend(&uv->early_suspend); #endif platform_set_drvdata(pdev, uv); pr_info("%s, success\n", __func__); return 0; err_uv_input__sysfs_create_link: sensors_unregister(uv->uv_dev, uv_sensor_attrs); err_sensor_register_failed: destroy_workqueue(uv->uv_wq); err_create_uv_workqueue: sysfs_remove_group(&uv->uv_input_dev->dev.kobj, &uv_attribute_group); err_sysfs_create_group_uv: input_unregister_device(uv->uv_input_dev); err_input_register_device_uv: err_input_allocate_device_uv: mutex_destroy(&uv->read_lock); mutex_destroy(&uv->power_lock); if (uv->pdata->adc_ap_exit) uv->pdata->adc_ap_exit(uv->pdev_uv_adc); err_setup_adc: if (uv->pdev_uv_adc) platform_device_put(uv->pdev_uv_adc); err_alloc_pdev: kfree(uv); return ret; }
static int mlx90615_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = -ENODEV; struct mlx90615_data *mlx90615 = NULL; pr_info("[BODYTEMP] %s is called.\n", __func__); /* Check i2c functionality */ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("[BODYTEMP] %s: i2c functionality check failed!\n", __func__); return ret; } mlx90615 = kzalloc(sizeof(struct mlx90615_data), GFP_KERNEL); if (!mlx90615) { pr_err("[BODYTEMP] %s: failed to alloc memory mlx90615_data\n", __func__); return -ENOMEM; } if (client-> dev.of_node) pr_info("[BODYTEMP] %s : of node\n", __func__); else { pr_err("[BODYTEMP] %s : no of node\n", __func__); goto err_setup_reg; } ret = mlx90615_parse_dt(&client->dev, mlx90615); if (ret) { pr_err("[BODYTEMP] %s : parse dt error\n", __func__); //goto err_parse_dt; } mlx90615->i2c_client = client; mlx90615->always_on = 0; i2c_set_clientdata(client, mlx90615); mutex_init(&mlx90615->power_lock); mutex_init(&mlx90615->read_lock); #if 0 /* Check if the device is there or not. */ ret = i2c_master_send(mlx90615->i2c_client, CMD_READ_ID_REG, MLX90615_CMD_LENGTH); if (ret < 0) { pr_err("[BODYTEMP] %s: failed i2c_master_send (err = %d)\n", __func__, ret); /* goto err_i2c_master_send;*/ } #endif /* allocate mlx90615 input_device */ mlx90615->input = input_allocate_device(); if (!mlx90615->input) { pr_err("[BODYTEMP] %s: could not allocate input device\n", __func__); goto err_input_allocate_device; } mlx90615->input->name = "bodytemp_sensor"; input_set_capability(mlx90615->input, EV_REL, EVENT_TYPE_AMBIENT_TEMP); input_set_capability(mlx90615->input, EV_REL, EVENT_TYPE_OBJECT_TEMP); input_set_drvdata(mlx90615->input, mlx90615); ret = input_register_device(mlx90615->input); if (ret < 0) { input_free_device(mlx90615->input); pr_err("[BODYTEMP] %s: could not register input device\n", __func__); goto err_input_register_device; } ret = sensors_create_symlink(&mlx90615->input->dev.kobj, mlx90615->input->name); if (ret < 0) { input_unregister_device(mlx90615->input); goto err_sysfs_create_symlink; } ret = sysfs_create_group(&mlx90615->input->dev.kobj, &mlx90615_attribute_group); if (ret) { pr_err("[BODYTEMP] %s: could not create sysfs group\n", __func__); goto err_sysfs_create_group; } ret = sensors_register(mlx90615->mlx90615_dev, mlx90615, bodytemp_sensor_attrs, "bodytemp_sensor"); if (ret) { pr_err("[BODYTEMP] %s: cound not register sensor device(%d).\n", __func__, ret); goto err_sysfs_create_symlink; } /* Timer settings. We poll for mlx90615 values using a timer. */ hrtimer_init(&mlx90615->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); mlx90615->poll_delay = ns_to_ktime(DEFAULT_DELAY * NSEC_PER_MSEC); mlx90615->timer.function = timer_func; /* Timer just fires off a work queue request. We need a thread to read the i2c (can be slow and blocking). */ mlx90615->mlx90615_wq = create_singlethread_workqueue("mlx90615_bidytemp_wq"); if (!mlx90615->mlx90615_wq) { ret = -ENOMEM; pr_err("[BODYTEMP] %s: could not create mlx90615 workqueue\n", __func__); goto err_create_workqueue; } /* This is the thread function we run on the work queue */ INIT_WORK(&mlx90615->work_mlx90615, mlx90615_work_func); pr_info("[BODYTEMP] %s is success.\n", __func__); goto done; err_create_workqueue: sysfs_remove_group(&mlx90615->input->dev.kobj, &mlx90615_attribute_group); /* sensors_classdev_unregister(mlx90615->mlx90615_dev);*/ destroy_workqueue(mlx90615->mlx90615_wq); err_sysfs_create_group: input_unregister_device(mlx90615->input); err_sysfs_create_symlink: sensors_remove_symlink(&mlx90615->input->dev.kobj, mlx90615->input->name); err_input_register_device: err_input_allocate_device: mutex_destroy(&mlx90615->read_lock); mutex_destroy(&mlx90615->power_lock); err_setup_reg: //err_parse_dt: kfree(mlx90615); done: return ret; }