^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Support for Vishay VCNL3020 proximity sensor on i2c bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Based on Vishay VCNL4000 driver code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * TODO: interrupts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/iio/iio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/iio/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define VCNL3020_PROD_ID 0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define VCNL_COMMAND 0x80 /* Command register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define VCNL_PROD_REV 0x81 /* Product ID and Revision ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define VCNL_PROXIMITY_RATE 0x82 /* Rate of Proximity Measurement */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define VCNL_LED_CURRENT 0x83 /* IR LED current for proximity mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define VCNL_PS_RESULT_HI 0x87 /* Proximity result register, MSB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define VCNL_PS_RESULT_LO 0x88 /* Proximity result register, LSB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define VCNL_PS_ICR 0x89 /* Interrupt Control Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define VCNL_PS_LO_THR_HI 0x8a /* High byte of low threshold value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define VCNL_PS_LO_THR_LO 0x8b /* Low byte of low threshold value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define VCNL_PS_HI_THR_HI 0x8c /* High byte of high threshold value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define VCNL_PS_HI_THR_LO 0x8d /* Low byte of high threshold value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define VCNL_ISR 0x8e /* Interrupt Status Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define VCNL_PS_MOD_ADJ 0x8f /* Proximity Modulator Timing Adjustment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* Bit masks for COMMAND register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define VCNL_PS_RDY BIT(5) /* proximity data ready? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define VCNL_PS_OD BIT(3) /* start on-demand proximity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * measurement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define VCNL_ON_DEMAND_TIMEOUT_US 100000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define VCNL_POLL_US 20000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * struct vcnl3020_data - vcnl3020 specific data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @regmap: device register map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * @dev: vcnl3020 device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * @rev: revision id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * @lock: lock for protecting access to device hardware registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct vcnl3020_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u8 rev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * struct vcnl3020_property - vcnl3020 property.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @name: property name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * @reg: i2c register offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @conversion_func: conversion function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct vcnl3020_property {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u32 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u32 (*conversion_func)(u32 *val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static u32 microamp_to_reg(u32 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * An example of conversion from uA to reg val:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * 200000 uA == 200 mA == 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return *val /= 10000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static struct vcnl3020_property vcnl3020_led_current_property = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .name = "vishay,led-current-microamp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .reg = VCNL_LED_CURRENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .conversion_func = microamp_to_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static int vcnl3020_get_and_apply_property(struct vcnl3020_data *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct vcnl3020_property prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) rc = device_property_read_u32(data->dev, prop.name, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (prop.conversion_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) prop.conversion_func(&val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) rc = regmap_write(data->regmap, prop.reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) dev_err(data->dev, "Error (%d) setting property (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) rc, prop.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static int vcnl3020_init(struct vcnl3020_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned int reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) rc = regmap_read(data->regmap, VCNL_PROD_REV, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) dev_err(data->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) "Error (%d) reading product revision\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (reg != VCNL3020_PROD_ID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) dev_err(data->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) "Product id (%x) did not match vcnl3020 (%x)\n", reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) VCNL3020_PROD_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) data->rev = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) mutex_init(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return vcnl3020_get_and_apply_property(data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) vcnl3020_led_current_property);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int vcnl3020_measure_proximity(struct vcnl3020_data *data, int *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) unsigned int reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) __be16 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) mutex_lock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) rc = regmap_write(data->regmap, VCNL_COMMAND, VCNL_PS_OD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* wait for data to become ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) rc = regmap_read_poll_timeout(data->regmap, VCNL_COMMAND, reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) reg & VCNL_PS_RDY, VCNL_POLL_US,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) VCNL_ON_DEMAND_TIMEOUT_US);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) dev_err(data->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) "Error (%d) reading vcnl3020 command register\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* high & low result bytes read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) rc = regmap_bulk_read(data->regmap, VCNL_PS_RESULT_HI, &res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) sizeof(res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) *val = be16_to_cpu(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) err_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) mutex_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static const struct iio_chan_spec vcnl3020_channels[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) .type = IIO_PROXIMITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static int vcnl3020_read_raw(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct iio_chan_spec const *chan, int *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int *val2, long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct vcnl3020_data *data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) switch (mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) case IIO_CHAN_INFO_RAW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) rc = vcnl3020_measure_proximity(data, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return IIO_VAL_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static const struct iio_info vcnl3020_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) .read_raw = vcnl3020_read_raw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static const struct regmap_config vcnl3020_regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .max_register = VCNL_PS_MOD_ADJ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int vcnl3020_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct vcnl3020_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct iio_dev *indio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) regmap = devm_regmap_init_i2c(client, &vcnl3020_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (IS_ERR(regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) dev_err(&client->dev, "regmap_init failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return PTR_ERR(regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (!indio_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) i2c_set_clientdata(client, indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) data->regmap = regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) data->dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) rc = vcnl3020_init(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) indio_dev->info = &vcnl3020_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) indio_dev->channels = vcnl3020_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) indio_dev->num_channels = ARRAY_SIZE(vcnl3020_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) indio_dev->name = "vcnl3020";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) indio_dev->modes = INDIO_DIRECT_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return devm_iio_device_register(&client->dev, indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static const struct of_device_id vcnl3020_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .compatible = "vishay,vcnl3020",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) MODULE_DEVICE_TABLE(of, vcnl3020_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static struct i2c_driver vcnl3020_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .name = "vcnl3020",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .of_match_table = vcnl3020_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .probe_new = vcnl3020_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) module_i2c_driver(vcnl3020_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) MODULE_AUTHOR("Ivan Mikhaylov <i.mikhaylov@yadro.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) MODULE_DESCRIPTION("Vishay VCNL3020 proximity sensor driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) MODULE_LICENSE("GPL");