diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-03-27 11:32:29 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-03-27 11:32:29 -0300 |
commit | 50953e0640b3473dcb409d5d0d938c2742c93b0d (patch) | |
tree | 3b0dc374e61564fbbd8adff92c8fae16fdeb423a /drivers/staging/iio/light/tsl2563.c | |
parent | f92c97c8bd77992ff8bd6ef29a23dc82dca799cb (diff) | |
parent | 626cf236608505d376e4799adb4f7eb00a8594af (diff) | |
download | op-kernel-dev-50953e0640b3473dcb409d5d0d938c2742c93b0d.zip op-kernel-dev-50953e0640b3473dcb409d5d0d938c2742c93b0d.tar.gz |
Merge branch 'poll' into staging/for_v3.4
* poll: (5970 commits)
poll: add poll_requested_events() and poll_does_not_wait() functions
crc32: select an algorithm via Kconfig
crc32: add self-test code for crc32c
crypto: crc32c should use library implementation
crc32: bolt on crc32c
crc32: add note about this patchset to crc32.c
crc32: optimize loop counter for x86
crc32: add slice-by-8 algorithm to existing code
crc32: make CRC_*_BITS definition correspond to actual bit counts
crc32: fix mixing of endian-specific types
crc32: miscellaneous cleanups
crc32: simplify unit test code
crc32: move long comment about crc32 fundamentals to Documentation/
crc32: remove two instances of trailing whitespaces
checkpatch: check for quoted strings broken across lines
checkpatch: whitespace - add/remove blank lines
checkpatch: warn on use of yield()
checkpatch: add --strict tests for braces, comments and casts
checkpatch: add [] to type extensions
checkpatch: high precedence operators do not require additional parentheses in #defines
...
Diffstat (limited to 'drivers/staging/iio/light/tsl2563.c')
-rw-r--r-- | drivers/staging/iio/light/tsl2563.c | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c index ffca85e..546c95a 100644 --- a/drivers/staging/iio/light/tsl2563.c +++ b/drivers/staging/iio/light/tsl2563.c @@ -118,7 +118,7 @@ struct tsl2563_chip { struct delayed_work poweroff_work; /* Remember state for suspend and resume functions */ - pm_message_t state; + bool suspended; struct tsl2563_gainlevel_coeff const *gainlevel; @@ -315,7 +315,7 @@ static int tsl2563_get_adc(struct tsl2563_chip *chip) int retry = 1; int ret = 0; - if (chip->state.event != PM_EVENT_ON) + if (chip->suspended) goto out; if (!chip->int_enabled) { @@ -708,7 +708,6 @@ static int __devinit tsl2563_probe(struct i2c_client *client, struct tsl2563_chip *chip; struct tsl2563_platform_data *pdata = client->dev.platform_data; int err = 0; - int ret; u8 id = 0; indio_dev = iio_allocate_device(sizeof(*chip)); @@ -722,13 +721,15 @@ static int __devinit tsl2563_probe(struct i2c_client *client, err = tsl2563_detect(chip); if (err) { - dev_err(&client->dev, "device not found, error %d\n", -err); + dev_err(&client->dev, "detect error %d\n", -err); goto fail1; } err = tsl2563_read_id(chip, &id); - if (err) + if (err) { + dev_err(&client->dev, "read id error %d\n", -err); goto fail1; + } mutex_init(&chip->lock); @@ -751,40 +752,52 @@ static int __devinit tsl2563_probe(struct i2c_client *client, indio_dev->num_channels = ARRAY_SIZE(tsl2563_channels); indio_dev->dev.parent = &client->dev; indio_dev->modes = INDIO_DIRECT_MODE; + if (client->irq) indio_dev->info = &tsl2563_info; else indio_dev->info = &tsl2563_info_no_irq; + if (client->irq) { - ret = request_threaded_irq(client->irq, + err = request_threaded_irq(client->irq, NULL, &tsl2563_event_handler, IRQF_TRIGGER_RISING | IRQF_ONESHOT, "tsl2563_event", indio_dev); - if (ret) - goto fail2; + if (err) { + dev_err(&client->dev, "irq request error %d\n", -err); + goto fail1; + } } + err = tsl2563_configure(chip); - if (err) - goto fail3; + if (err) { + dev_err(&client->dev, "configure error %d\n", -err); + goto fail2; + } INIT_DELAYED_WORK(&chip->poweroff_work, tsl2563_poweroff_work); + /* The interrupt cannot yet be enabled so this is fine without lock */ schedule_delayed_work(&chip->poweroff_work, 5 * HZ); - ret = iio_device_register(indio_dev); - if (ret) + err = iio_device_register(indio_dev); + if (err) { + dev_err(&client->dev, "iio registration error %d\n", -err); goto fail3; + } return 0; + fail3: + cancel_delayed_work(&chip->poweroff_work); + flush_scheduled_work(); +fail2: if (client->irq) free_irq(client->irq, indio_dev); -fail2: - iio_free_device(indio_dev); fail1: - kfree(chip); + iio_free_device(indio_dev); return err; } @@ -810,9 +823,10 @@ static int tsl2563_remove(struct i2c_client *client) return 0; } -static int tsl2563_suspend(struct i2c_client *client, pm_message_t state) +#ifdef CONFIG_PM_SLEEP +static int tsl2563_suspend(struct device *dev) { - struct tsl2563_chip *chip = i2c_get_clientdata(client); + struct tsl2563_chip *chip = i2c_get_clientdata(to_i2c_client(dev)); int ret; mutex_lock(&chip->lock); @@ -821,16 +835,16 @@ static int tsl2563_suspend(struct i2c_client *client, pm_message_t state) if (ret) goto out; - chip->state = state; + chip->suspended = true; out: mutex_unlock(&chip->lock); return ret; } -static int tsl2563_resume(struct i2c_client *client) +static int tsl2563_resume(struct device *dev) { - struct tsl2563_chip *chip = i2c_get_clientdata(client); + struct tsl2563_chip *chip = i2c_get_clientdata(to_i2c_client(dev)); int ret; mutex_lock(&chip->lock); @@ -843,13 +857,19 @@ static int tsl2563_resume(struct i2c_client *client) if (ret) goto out; - chip->state.event = PM_EVENT_ON; + chip->suspended = false; out: mutex_unlock(&chip->lock); return ret; } +static SIMPLE_DEV_PM_OPS(tsl2563_pm_ops, tsl2563_suspend, tsl2563_resume); +#define TSL2563_PM_OPS (&tsl2563_pm_ops) +#else +#define TSL2563_PM_OPS NULL +#endif + static const struct i2c_device_id tsl2563_id[] = { { "tsl2560", 0 }, { "tsl2561", 1 }, @@ -862,9 +882,8 @@ MODULE_DEVICE_TABLE(i2c, tsl2563_id); static struct i2c_driver tsl2563_i2c_driver = { .driver = { .name = "tsl2563", + .pm = TSL2563_PM_OPS, }, - .suspend = tsl2563_suspend, - .resume = tsl2563_resume, .probe = tsl2563_probe, .remove = __devexit_p(tsl2563_remove), .id_table = tsl2563_id, |