sx9500.c (85a3685852d9ac7d92be9d824533c915a4597fa4) | sx9500.c (63de9f92cc35212c4fbf0caf6cb9d8cabe488214) |
---|---|
1/* 2 * Copyright (c) 2014 Intel Corporation 3 * 4 * Driver for Semtech's SX9500 capacitive proximity/button solution. 5 * Datasheet available at 6 * <http://www.semtech.com/images/datasheet/sx9500.pdf>. 7 * 8 * This program is free software; you can redistribute it and/or modify it --- 4 unchanged lines hidden (view full) --- 13#include <linux/kernel.h> 14#include <linux/slab.h> 15#include <linux/module.h> 16#include <linux/i2c.h> 17#include <linux/irq.h> 18#include <linux/acpi.h> 19#include <linux/gpio/consumer.h> 20#include <linux/regmap.h> | 1/* 2 * Copyright (c) 2014 Intel Corporation 3 * 4 * Driver for Semtech's SX9500 capacitive proximity/button solution. 5 * Datasheet available at 6 * <http://www.semtech.com/images/datasheet/sx9500.pdf>. 7 * 8 * This program is free software; you can redistribute it and/or modify it --- 4 unchanged lines hidden (view full) --- 13#include <linux/kernel.h> 14#include <linux/slab.h> 15#include <linux/module.h> 16#include <linux/i2c.h> 17#include <linux/irq.h> 18#include <linux/acpi.h> 19#include <linux/gpio/consumer.h> 20#include <linux/regmap.h> |
21#include <linux/pm.h> |
|
21 22#include <linux/iio/iio.h> 23#include <linux/iio/buffer.h> 24#include <linux/iio/sysfs.h> 25#include <linux/iio/events.h> 26#include <linux/iio/trigger.h> 27#include <linux/iio/triggered_buffer.h> 28#include <linux/iio/trigger_consumer.h> 29 30#define SX9500_DRIVER_NAME "sx9500" 31#define SX9500_IRQ_NAME "sx9500_event" | 22 23#include <linux/iio/iio.h> 24#include <linux/iio/buffer.h> 25#include <linux/iio/sysfs.h> 26#include <linux/iio/events.h> 27#include <linux/iio/trigger.h> 28#include <linux/iio/triggered_buffer.h> 29#include <linux/iio/trigger_consumer.h> 30 31#define SX9500_DRIVER_NAME "sx9500" 32#define SX9500_IRQ_NAME "sx9500_event" |
32#define SX9500_GPIO_NAME "sx9500_gpio" | |
33 | 33 |
34#define SX9500_GPIO_NAME "interrupt" 35 |
|
34/* Register definitions. */ 35#define SX9500_REG_IRQ_SRC 0x00 36#define SX9500_REG_STAT 0x01 37#define SX9500_REG_IRQ_MSK 0x03 38 39#define SX9500_REG_PROX_CTRL0 0x06 40#define SX9500_REG_PROX_CTRL1 0x07 41#define SX9500_REG_PROX_CTRL2 0x08 --- 42 unchanged lines hidden (view full) --- 84 /* 85 * Last reading of the proximity status for each channel. We 86 * only send an event to user space when this changes. 87 */ 88 bool prox_stat[SX9500_NUM_CHANNELS]; 89 bool event_enabled[SX9500_NUM_CHANNELS]; 90 bool trigger_enabled; 91 u16 *buffer; | 36/* Register definitions. */ 37#define SX9500_REG_IRQ_SRC 0x00 38#define SX9500_REG_STAT 0x01 39#define SX9500_REG_IRQ_MSK 0x03 40 41#define SX9500_REG_PROX_CTRL0 0x06 42#define SX9500_REG_PROX_CTRL1 0x07 43#define SX9500_REG_PROX_CTRL2 0x08 --- 42 unchanged lines hidden (view full) --- 86 /* 87 * Last reading of the proximity status for each channel. We 88 * only send an event to user space when this changes. 89 */ 90 bool prox_stat[SX9500_NUM_CHANNELS]; 91 bool event_enabled[SX9500_NUM_CHANNELS]; 92 bool trigger_enabled; 93 u16 *buffer; |
94 /* Remember enabled channels and sample rate during suspend. */ 95 unsigned int suspend_ctrl0; |
|
92}; 93 94static const struct iio_event_spec sx9500_events[] = { 95 { 96 .type = IIO_EV_TYPE_THRESH, 97 .dir = IIO_EV_DIR_EITHER, 98 .mask_separate = BIT(IIO_EV_INFO_ENABLE), 99 }, --- 513 unchanged lines hidden (view full) --- 613 int ret; 614 615 if (!client) 616 return -EINVAL; 617 618 dev = &client->dev; 619 620 /* data ready gpio interrupt pin */ | 96}; 97 98static const struct iio_event_spec sx9500_events[] = { 99 { 100 .type = IIO_EV_TYPE_THRESH, 101 .dir = IIO_EV_DIR_EITHER, 102 .mask_separate = BIT(IIO_EV_INFO_ENABLE), 103 }, --- 513 unchanged lines hidden (view full) --- 617 int ret; 618 619 if (!client) 620 return -EINVAL; 621 622 dev = &client->dev; 623 624 /* data ready gpio interrupt pin */ |
621 gpio = devm_gpiod_get_index(dev, SX9500_GPIO_NAME, 0); | 625 gpio = devm_gpiod_get_index(dev, SX9500_GPIO_NAME, 0, GPIOD_IN); |
622 if (IS_ERR(gpio)) { 623 dev_err(dev, "acpi gpio get index failed\n"); 624 return PTR_ERR(gpio); 625 } 626 | 626 if (IS_ERR(gpio)) { 627 dev_err(dev, "acpi gpio get index failed\n"); 628 return PTR_ERR(gpio); 629 } 630 |
627 ret = gpiod_direction_input(gpio); 628 if (ret) 629 return ret; 630 | |
631 ret = gpiod_to_irq(gpio); 632 633 dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); 634 635 return ret; 636} 637 638static int sx9500_probe(struct i2c_client *client, --- 80 unchanged lines hidden (view full) --- 719 iio_triggered_buffer_cleanup(indio_dev); 720 if (client->irq > 0) 721 iio_trigger_unregister(data->trig); 722 kfree(data->buffer); 723 724 return 0; 725} 726 | 631 ret = gpiod_to_irq(gpio); 632 633 dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); 634 635 return ret; 636} 637 638static int sx9500_probe(struct i2c_client *client, --- 80 unchanged lines hidden (view full) --- 719 iio_triggered_buffer_cleanup(indio_dev); 720 if (client->irq > 0) 721 iio_trigger_unregister(data->trig); 722 kfree(data->buffer); 723 724 return 0; 725} 726 |
727#ifdef CONFIG_PM_SLEEP 728static int sx9500_suspend(struct device *dev) 729{ 730 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 731 struct sx9500_data *data = iio_priv(indio_dev); 732 int ret; 733 734 mutex_lock(&data->mutex); 735 ret = regmap_read(data->regmap, SX9500_REG_PROX_CTRL0, 736 &data->suspend_ctrl0); 737 if (ret < 0) 738 goto out; 739 740 /* 741 * Scan period doesn't matter because when all the sensors are 742 * deactivated the device is in sleep mode. 743 */ 744 ret = regmap_write(data->regmap, SX9500_REG_PROX_CTRL0, 0); 745 746out: 747 mutex_unlock(&data->mutex); 748 return ret; 749} 750 751static int sx9500_resume(struct device *dev) 752{ 753 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 754 struct sx9500_data *data = iio_priv(indio_dev); 755 int ret; 756 757 mutex_lock(&data->mutex); 758 ret = regmap_write(data->regmap, SX9500_REG_PROX_CTRL0, 759 data->suspend_ctrl0); 760 mutex_unlock(&data->mutex); 761 762 return ret; 763} 764#endif /* CONFIG_PM_SLEEP */ 765 766static const struct dev_pm_ops sx9500_pm_ops = { 767 SET_SYSTEM_SLEEP_PM_OPS(sx9500_suspend, sx9500_resume) 768}; 769 |
|
727static const struct acpi_device_id sx9500_acpi_match[] = { 728 {"SSX9500", 0}, 729 { }, 730}; 731MODULE_DEVICE_TABLE(acpi, sx9500_acpi_match); 732 733static const struct i2c_device_id sx9500_id[] = { 734 {"sx9500", 0}, 735 {} 736}; 737MODULE_DEVICE_TABLE(i2c, sx9500_id); 738 739static struct i2c_driver sx9500_driver = { 740 .driver = { 741 .name = SX9500_DRIVER_NAME, 742 .acpi_match_table = ACPI_PTR(sx9500_acpi_match), | 770static const struct acpi_device_id sx9500_acpi_match[] = { 771 {"SSX9500", 0}, 772 { }, 773}; 774MODULE_DEVICE_TABLE(acpi, sx9500_acpi_match); 775 776static const struct i2c_device_id sx9500_id[] = { 777 {"sx9500", 0}, 778 {} 779}; 780MODULE_DEVICE_TABLE(i2c, sx9500_id); 781 782static struct i2c_driver sx9500_driver = { 783 .driver = { 784 .name = SX9500_DRIVER_NAME, 785 .acpi_match_table = ACPI_PTR(sx9500_acpi_match), |
786 .pm = &sx9500_pm_ops, |
|
743 }, 744 .probe = sx9500_probe, 745 .remove = sx9500_remove, 746 .id_table = sx9500_id, 747}; 748module_i2c_driver(sx9500_driver); 749 750MODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>"); 751MODULE_DESCRIPTION("Driver for Semtech SX9500 proximity sensor"); 752MODULE_LICENSE("GPL v2"); | 787 }, 788 .probe = sx9500_probe, 789 .remove = sx9500_remove, 790 .id_table = sx9500_id, 791}; 792module_i2c_driver(sx9500_driver); 793 794MODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>"); 795MODULE_DESCRIPTION("Driver for Semtech SX9500 proximity sensor"); 796MODULE_LICENSE("GPL v2"); |