static ssize_t light_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct bh1721_data *bh1721 = dev_get_drvdata(dev); bool new_value; if (sysfs_streq(buf, "1")) new_value = true; else if (sysfs_streq(buf, "0")) new_value = false; else { pr_err("%s: invalid value %d\n", __func__, *buf); return -EINVAL; } mutex_lock(&bh1721->power_lock); printk("[Light Sensor] new_value = %d, old state = %d\n", new_value, (bh1721->power_state & LIGHT_ENABLED) ? 1 : 0); if (new_value && !(bh1721->power_state & LIGHT_ENABLED)) { bh1721->power_state |= LIGHT_ENABLED; bh1721_light_enable(bh1721); bh1721->als_buf_initialized = false; } else if (!new_value && (bh1721->power_state & LIGHT_ENABLED)) { bh1721_light_disable(bh1721); bh1721->power_state &= ~LIGHT_ENABLED; } mutex_unlock(&bh1721->power_lock); return size; }
static ssize_t poll_delay_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct bh1721_data *bh1721 = dev_get_drvdata(dev); int64_t new_delay; int err; err = strict_strtoll(buf, 10, &new_delay); if (err < 0) return err; printk("[Light Sensor] new delay = %lldns, old delay = %lldns\n", new_delay, ktime_to_ns(bh1721->light_poll_delay)); mutex_lock(&bh1721->power_lock); if (new_delay != ktime_to_ns(bh1721->light_poll_delay)) { bh1721->light_poll_delay = ns_to_ktime(new_delay); if (bh1721->power_state & LIGHT_ENABLED) { bh1721_light_disable(bh1721); bh1721_light_enable(bh1721); } } mutex_unlock(&bh1721->power_lock); return size; }
static int bh1721_suspend(struct device *dev) { /* We disable power only if proximity is disabled. If proximity is enabled, we leave power on because proximity is allowed to wake up device. We remove power without changing bh1721->power_state because we use that state in resume */ struct i2c_client *client = to_i2c_client(dev); struct bh1721_data *bh1721 = i2c_get_clientdata(client); if (bh1721->power_state & LIGHT_ENABLED) bh1721_light_disable(bh1721); return 0; }
static int bh1721_suspend(struct device *dev) { /* We disable power only if proximity is disabled. If proximity is enabled, we leave power on because proximity is allowed to wake up device. We remove power without changing bh1721->power_state because we use that state in resume */ struct i2c_client *client = to_i2c_client(dev); struct bh1721_data *bh1721 = i2c_get_clientdata(client); if (bh1721->power_state & LIGHT_ENABLED) bh1721_light_disable(bh1721); #if defined(CONFIG_TARGET_LOCALE_KOR_LGU) if (bh1721->resetpin_down) bh1721->resetpin_down(); #endif return 0; }
static int bh1721_i2c_remove(struct i2c_client *client) { struct bh1721_data *bh1721 = i2c_get_clientdata(client); sysfs_remove_group(&bh1721->light_input_dev->dev.kobj, &light_attribute_group); input_unregister_device(bh1721->light_input_dev); if (bh1721->power_state) { bh1721->power_state = 0; if (bh1721->power_state & LIGHT_ENABLED) bh1721_light_disable(bh1721); } destroy_workqueue(bh1721->wq); mutex_destroy(&bh1721->power_lock); kfree(bh1721); return 0; }
static int bh1721_i2c_remove(struct i2c_client *client) { struct bh1721_data *bh1721 = i2c_get_clientdata(client); sysfs_remove_group(&bh1721->light_input_dev->dev.kobj, &light_attribute_group); input_unregister_device(bh1721->light_input_dev); device_remove_file(switch_cmd_dev, &dev_attr_lightsensor_file_cmd); device_remove_file(switch_cmd_dev, &dev_attr_lightsensor_file_illuminance); device_remove_file(switch_cmd_dev, &dev_attr_lightsensor_file_state); device_destroy(lightsensor_class,0); class_destroy(lightsensor_class); if (bh1721->power_state) { bh1721->power_state = 0; if (bh1721->power_state & LIGHT_ENABLED) bh1721_light_disable(bh1721); } destroy_workqueue(bh1721->wq); mutex_destroy(&bh1721->power_lock); kfree(bh1721); return 0; }