예제 #1
0
int sensor_common_read_file_int(char *file_path)
{
    struct file *file_p;
    int vfs_read_retval = 0;
    mm_segment_t old_fs; 
    char read_buf[32];
    //unsigned short read_value;
    int read_value;

    if (NULL==file_path)
    {
        SENSOR_LOG_ERROR("file_path is NULL\n");
        goto error;
    }

    memset(read_buf, 0, 32);

    file_p = filp_open(file_path, O_RDONLY, 0);
    if (IS_ERR(file_p))
    {
        SENSOR_LOG_ERROR("[open file <%s>failed]\n",file_path);
        goto error;
    }

    old_fs = get_fs();
    set_fs(KERNEL_DS);
    
    vfs_read_retval = vfs_read(file_p, (char*)read_buf, 16, &file_p->f_pos);
    if (vfs_read_retval < 0)
    {
        SENSOR_LOG_ERROR("[read file <%s>failed]\n",file_path);
        goto error;
    }

    set_fs(old_fs);
    filp_close(file_p, NULL);

    //SENSOR_LOG_ERROR("read_buf is %s\n",read_buf);

    read_value = simple_strtol(read_buf, NULL, 10);

    //SENSOR_LOG_ERROR("read_value is %d\n",read_value);

    /*
    if (kstrto16(read_buf, 10, &read_value) < 0)
    {
        SENSOR_LOG_ERROR("[kstrtou16 %s failed]\n",read_buf);
        goto error;
    }
    */

    //SENSOR_LOG_ERROR("[the content of %s is %s]\n", file_path, read_buf);

    return read_value;

error:
    return 0;
}
예제 #2
0
static int sensor_compass_int_pin_init(int pin_num)
{
    int ret = 0;

    ret = gpio_request(pin_num, "compass_int");
    if (ret)    
    {
        SENSOR_LOG_INFO("gpio %d is busy and then to free it\n",COMPASS_INT_PIN);
        
        gpio_free(pin_num);
        ret = gpio_request(pin_num, "compass_int");
        if (ret) 
        {
            SENSOR_LOG_INFO("gpio %d is busy and then to free it\n",COMPASS_INT_PIN);
            return ret;
        }
    }
    else
    {
        SENSOR_LOG_INFO("gpio %d get success\n",COMPASS_INT_PIN);
    }

    ret = gpio_tlmm_config(GPIO_CFG(pin_num, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
    if (ret < 0)
    {
        SENSOR_LOG_ERROR("gpio_tlmm_config failed ret = %d",ret);
    }
    
    return ret;
}
예제 #3
0
int sensor_common_read_file_char(char *file_path, char *save_buf)
{
    struct file *file_p;
    int vfs_read_retval = 0;
    mm_segment_t old_fs; 
    char read_buf[32];

    if (NULL==file_path)
    {
        SENSOR_LOG_ERROR("file_path is NULL\n");
        goto error;
    }

    memset(read_buf, 0, 32);

    file_p = filp_open(file_path, O_RDONLY, 0);
    if (IS_ERR(file_p))
    {
        SENSOR_LOG_ERROR("[open file <%s>failed]\n",file_path);
        goto error;
    }

    old_fs = get_fs();
    set_fs(KERNEL_DS);
    
    vfs_read_retval = vfs_read(file_p, (char*)read_buf, 16, &file_p->f_pos);
    if (vfs_read_retval < 0)
    {
        SENSOR_LOG_ERROR("[read file <%s>failed]\n",file_path);
        goto error;
    }

    set_fs(old_fs);
    filp_close(file_p, NULL);

    SENSOR_LOG_ERROR("read_buf is %s\n",read_buf);

    return sprintf(save_buf, "%s",read_buf);


error:
    return 0;
}
예제 #4
0
static int maxq616_power_init(struct maxq616_chip *chip)
{
	int rc;

    chip->power = regulator_get(&(chip->client->dev), "vdd-chip");

	if (IS_ERR(chip->power))
    {
		rc = PTR_ERR(chip->power);
		SENSOR_LOG_ERROR("Regulator get failed chip->power rc=%d\n", rc);
		return rc;
	}

	if (regulator_count_voltages(chip->power) > 0)
    {
		rc = regulator_set_voltage(chip->power, 1800000, 1800000);
		if (rc)
        {
			SENSOR_LOG_ERROR("Regulator set chip->power failed rc=%d\n", rc);
			goto error_set_voltage;
		}
	}
    
    rc = regulator_set_optimum_mode(chip->power, 600000);
    if (rc < 0)
    {
        SENSOR_LOG_ERROR("Regulator chip->power set_opt failed rc=%d\n", rc);
        goto error_set_optimum;
    }
    
    SENSOR_LOG_INFO("success\n");
    return 0;

error_set_optimum:
    regulator_set_voltage(chip->power, 0, 1800000);
    regulator_put(chip->power);

error_set_voltage:
	regulator_put(chip->power);
    SENSOR_LOG_INFO("failed\n");
	return rc;
}
예제 #5
0
static int maxq616_power_on(struct maxq616_chip *chip, bool enable)
{
	int rc;
    if (enable == chip->power_on)
    {
        SENSOR_LOG_INFO("double %s power, retern here\n",enable? "enable" : "disable");
        return 0;
    }
    else
    {
        SENSOR_LOG_INFO("%s power\n",enable? "enable" : "disable");
    }

    if (enable)
    {
        rc = regulator_enable(chip->power);
        if (rc)
        {
            SENSOR_LOG_ERROR("Regulator chip->power enable failed rc=%d\n", rc);
            goto err_power_enable_failed;
        }
        chip->power_on = true;
    }
    else
    {
        rc = regulator_disable(chip->power);
        if (rc)
        {
            SENSOR_LOG_ERROR("Regulator chip->power enable failed rc=%d\n", rc);
            goto err_power_disable_failed;
        }
        chip->power_on = false;
    }
    
    return 0;

err_power_enable_failed:
err_power_disable_failed:
    return rc;

}
예제 #6
0
static int sensor_temp_humidity_create_sysfs_interfaces(struct device *dev)
{
    int i;
    for (i = 0; i < ARRAY_SIZE(attrs_sensor_temp_humidity); i++)
     if (device_create_file(dev, attrs_sensor_temp_humidity + i))
         goto error;
    return 0;

error:
    for ( ; i >= 0; i--)
    device_remove_file(dev, attrs_sensor_temp_humidity + i);
    SENSOR_LOG_ERROR("Unable to create interface\n");
    return -1;
}
예제 #7
0
/*
 "Unknown", "Charging", "Discharging", "Not charging", "Full"
     0          1             2              3           4
 */
static ssize_t attr_charge_state(struct device *dev,struct device_attribute *attr, char *buf)
{

    char *charge_status[5] = {"Unknown", "Charging", "Discharging", "Not charging", "Full"};
    char save_buf[32];
    int charge_state = 0;
    int i = 0;

    sensor_common_read_file_char(PATH_CHARGE_STATE, save_buf);

    for (i=0; i<5; i++)
    {
        SENSOR_LOG_ERROR("charge_status[%d] is %s\n",i,charge_status[i]);
        if (0 == strncmp(save_buf, charge_status[i], strlen(charge_status[i])))
        {
            charge_state = i;
            break;
        }
    }
   
    return sprintf(buf, "%d\n",charge_state);
}
static int __devinit hall_device_probe(struct i2c_client *client,
                  const struct i2c_device_id *id)
{
    int ret = 0;
	static struct hall_device_chip *chip;

    SENSOR_LOG_INFO("prob start\n");

    chip = kzalloc(sizeof(struct hall_device_chip), GFP_KERNEL);
    if (!chip) {
        ret = -ENOMEM;
        goto malloc_failed;
    }

	chip->client = client;
	i2c_set_clientdata(client, chip);

    hall_device_chip_data_init(chip);

    hall_device_parse_dt(chip);

    SENSOR_LOG_INFO("hall_device_int_s is %d",chip->irq_s.irq_pin);
    SENSOR_LOG_INFO("hall_device_int_n is %d",chip->irq_n.irq_pin);

	mutex_init(&chip->lock);


    hall_device_class   = class_create(THIS_MODULE, "hall_device");

    chip->hall_device_dev = device_create(hall_device_class, NULL, hall_device_dev_t, &hall_device_driver ,"hall_device");
    if (IS_ERR(chip->hall_device_dev)) 
    {
       ret = PTR_ERR(chip->hall_device_dev);
       goto create_hall_device_dev_failed;
    }

	dev_set_drvdata(chip->hall_device_dev, chip);


    ret = gpio_request(chip->irq_s.irq_pin, "chip->irq_s.irq_pin");
    if (ret)    
    {
        SENSOR_LOG_INFO("gpio %d is busy and then to free it\n",chip->irq_s.irq_pin);
        
        gpio_free(chip->irq_s.irq_pin);
        ret = gpio_request(chip->irq_s.irq_pin, "chip->irq_s.irq_pin");
        if (ret) 
        {
            SENSOR_LOG_INFO("gpio %d is busy and then to free it\n",chip->irq_s.irq_pin);
            return ret;
        }
    }
    
    ret = gpio_tlmm_config(GPIO_CFG(chip->irq_s.irq_pin, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA), GPIO_CFG_ENABLE);

    chip->irq_s.irq_num = gpio_to_irq(chip->irq_s.irq_pin);
    INIT_WORK(&chip->irq_work_s, hall_device_irq_work_s);
    ret = request_threaded_irq(chip->irq_s.irq_num, NULL, &hall_device_irq_s, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT, "hall_device_irq_s", chip);
    if (ret) {
        SENSOR_LOG_ERROR("Failed to request irq %d\n", chip->irq_s.irq_num);
        goto irq_s_register_fail;
    }


    ret = gpio_request(chip->irq_n.irq_pin, "chip->irq_n.irq_pin");
    if (ret)    
    {
        SENSOR_LOG_INFO("gpio %d is busy and then to free it\n",chip->irq_n.irq_pin);
        
        gpio_free(chip->irq_n.irq_pin);
        ret = gpio_request(chip->irq_n.irq_pin, "chip->irq_n.irq_pin");
        if (ret) 
        {
            SENSOR_LOG_INFO("gpio %d is busy and then to free it\n",chip->irq_n.irq_pin);
            return ret;
        }
    }
    
    ret = gpio_tlmm_config(GPIO_CFG(chip->irq_n.irq_pin, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA), GPIO_CFG_ENABLE);

    chip->irq_n.irq_num = gpio_to_irq(chip->irq_n.irq_pin);
    INIT_WORK(&chip->irq_work_n, hall_device_irq_work_n);
    ret = request_threaded_irq(chip->irq_n.irq_num , NULL, &hall_device_irq_n, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT, "hall_device_irq_n", chip);
    if (ret) {
        SENSOR_LOG_ERROR("Failed to request irq %d\n", chip->irq_n.irq_num );
        goto irq_n_register_fail;
    }

    chip->idev = input_allocate_device();
    if (!chip->idev) 
    {
        SENSOR_LOG_ERROR("no memory for idev\n");
        ret = -ENODEV;
        goto input_alloc_failed;
    }
    chip->idev->name = "hall_device";
    chip->idev->id.bustype = BUS_I2C;

    set_bit(EV_REL,     chip->idev->evbit);
    set_bit(REL_RX,     chip->idev->relbit);  //NEAR
    set_bit(REL_RY,     chip->idev->relbit);  //FAR


    ret = input_register_device(chip->idev);
    if (ret) {
        input_free_device(chip->idev);
        SENSOR_LOG_ERROR("cant register input '%s'\n",chip->idev->name);
        goto input_register_failed;
    }

    create_sysfs_interfaces(chip->hall_device_dev);

    hall_device_irq_enable(&(chip->irq_s), false, true);
    hall_device_irq_enable(&(chip->irq_n), false, true);

    wake_lock_init(&chip->wakeup_wakelock.lock, WAKE_LOCK_SUSPEND, chip->wakeup_wakelock.name);
    hrtimer_init(&chip->unlock_wakelock_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
    chip->unlock_wakelock_timer.function = hall_device_unlock_wakelock_work_func;


    SENSOR_LOG_INFO("prob success\n");

    return 0;

input_register_failed:
    input_free_device(chip->idev);
input_alloc_failed:
malloc_failed:
irq_n_register_fail:
irq_s_register_fail:
create_hall_device_dev_failed:
    chip->hall_device_dev = NULL;
    class_destroy(hall_device_class);
    SENSOR_LOG_INFO("prob failed\n");

    return -1;

}