static int __devinit isl29018_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct isl29018_chip *chip; int err; chip = kzalloc(sizeof (struct isl29018_chip), GFP_KERNEL); if (!chip) { dev_err(&client->dev, "Memory allocation fails\n"); err = -ENOMEM; goto exit; } i2c_set_clientdata(client, chip); chip->pdata = client->dev.platform_data; chip->client = client; mutex_init(&chip->lock); chip->range = ISL29018_DEFAULT_RANGE; chip->adc_bit = ISL29018_DEFAULT_RESOLUTION; chip->enable_ls = 0; err = isl29018_chip_init(client); if (err) goto exit_free; chip->indio_dev = iio_allocate_device(); if (!chip->indio_dev) { dev_err(&client->dev, "iio allocation fails\n"); goto exit_free; } chip->indio_dev->attrs = &isl29108_group; chip->indio_dev->dev.parent = &client->dev; chip->indio_dev->dev_data = (void *)(chip); chip->indio_dev->driver_module = THIS_MODULE; chip->indio_dev->modes = INDIO_DIRECT_MODE; err = iio_device_register(chip->indio_dev); if (err) { dev_err(&client->dev, "iio registration fails\n"); goto exit_iio_free; } chip->early_suspend.suspend = isl29018_early_suspend; chip->early_suspend.resume = isl29018_late_resume; register_early_suspend(&(chip->early_suspend)); if (chip->pdata && chip->pdata->power_off) chip->pdata->power_off(); return 0; exit_iio_free: iio_free_device(chip->indio_dev); exit_free: kfree(chip); exit: return err; }
static int isl29018_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct isl29018_chip *chip; struct iio_dev *indio_dev; int err; indio_dev = iio_device_alloc(sizeof(*chip)); if (indio_dev == NULL) { dev_err(&client->dev, "iio allocation fails\n"); err = -ENOMEM; goto exit; } chip = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); chip->dev = &client->dev; mutex_init(&chip->lock); chip->lux_scale = 1; chip->range = 1000; chip->adc_bit = 16; chip->suspended = false; chip->regmap = devm_regmap_init_i2c(client, &isl29018_regmap_config); if (IS_ERR(chip->regmap)) { err = PTR_ERR(chip->regmap); dev_err(chip->dev, "regmap initialization failed: %d\n", err); goto exit; } err = isl29018_chip_init(chip); if (err) goto exit_iio_free; indio_dev->info = &isl29108_info; indio_dev->channels = isl29018_channels; indio_dev->num_channels = ARRAY_SIZE(isl29018_channels); indio_dev->name = id->name; indio_dev->dev.parent = &client->dev; indio_dev->modes = INDIO_DIRECT_MODE; err = iio_device_register(indio_dev); if (err) { dev_err(&client->dev, "iio registration fails\n"); goto exit_iio_free; } return 0; exit_iio_free: iio_device_free(indio_dev); exit: return err; }
static int isl29018_resume(struct device *dev) { struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev)); int err; mutex_lock(&chip->lock); err = isl29018_chip_init(chip); if (!err) chip->suspended = false; mutex_unlock(&chip->lock); return err; }
static int isl29018_resume(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct isl29018_chip *chip = iio_priv(indio_dev); struct i2c_client *client = chip->client; int err; mutex_lock(&chip->lock); err = isl29018_chip_init(client); if (!err) chip->suspended = false; mutex_unlock(&chip->lock); return err; }
static int __devinit isl29018_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct isl29018_chip *chip; struct iio_dev *indio_dev; int err; indio_dev = iio_allocate_device(sizeof(*chip)); if (indio_dev == NULL) { dev_err(&client->dev, "iio allocation fails\n"); err = -ENOMEM; goto exit; } chip = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); chip->client = client; mutex_init(&chip->lock); chip->lux_scale = 1; chip->range = 1000; chip->adc_bit = 16; err = isl29018_chip_init(client); if (err) goto exit_iio_free; indio_dev->info = &isl29108_info; indio_dev->channels = isl29018_channels; indio_dev->num_channels = ARRAY_SIZE(isl29018_channels); indio_dev->name = id->name; indio_dev->dev.parent = &client->dev; indio_dev->modes = INDIO_DIRECT_MODE; err = iio_device_register(indio_dev); if (err) { dev_err(&client->dev, "iio registration fails\n"); goto exit_iio_free; } return 0; exit_iio_free: iio_free_device(indio_dev); exit: return err; }
static bool isl29018_read_lux(struct i2c_client *client, int *hb_lux, int *lb_lux) { int lux_data; bool status = 0; int lsb = 0; int msb = 0; struct isl29018_chip *chip = i2c_get_clientdata(client); if(!chip->enable_ls || chip->suspend) return true; /* Set mode */ status = isl29018_write_data(client, ISL29018_REG_ADD_COMMAND1, COMMMAND1_OPMODE_ALS_ONCE, COMMMAND1_OPMODE_MASK, COMMMAND1_OPMODE_SHIFT); if (!status) { dev_err(&client->dev, "Error in setting operating mode\n"); return false; } msleep(CONVERSION_TIME_MS); if(!chip->enable_ls || chip->suspend) return true; lsb = i2c_smbus_read_byte_data(client, ISL29018_REG_ADD_DATA_LSB); if (lsb < 0) { dev_err(&client->dev, "Error in reading LSB DATA\n"); return false; } msb = i2c_smbus_read_byte_data(client, ISL29018_REG_ADD_DATA_MSB); if (msb < 0) { dev_err(&client->dev, "Error in reading MSB DATA\n"); return false; } lux_data = ((msb << 8) | lsb); if (lux_data > 0) { *hb_lux = msb; *lb_lux = lsb; return true; } else { printk("isl29018_read_lux error / re-init chip... lux:%#x", lux_data); isl29018_chip_init(client); } return false; }