Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * tsl4531.c - Support for TAOS TSL4531 ambient light sensor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2013 Peter Meerwald <pmeerw@pmeerw.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * IIO driver for the TSL4531x family
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *   TSL45311/TSL45313: 7-bit I2C slave address 0x39
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *   TSL45315/TSL45317: 7-bit I2C slave address 0x29
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * TODO: single cycle measurement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/iio/iio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/iio/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define TSL4531_DRV_NAME "tsl4531"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define TSL4531_COMMAND BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define TSL4531_CONTROL (TSL4531_COMMAND | 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define TSL4531_CONFIG (TSL4531_COMMAND | 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define TSL4531_DATA (TSL4531_COMMAND | 0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define TSL4531_ID (TSL4531_COMMAND | 0x0a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /* operating modes in control register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define TSL4531_MODE_POWERDOWN 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define TSL4531_MODE_SINGLE_ADC 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define TSL4531_MODE_NORMAL 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /* integration time control in config register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define TSL4531_TCNTRL_400MS 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define TSL4531_TCNTRL_200MS 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define TSL4531_TCNTRL_100MS 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) /* part number in id register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define TSL45311_ID 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define TSL45313_ID 0x9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define TSL45315_ID 0xa
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define TSL45317_ID 0xb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define TSL4531_ID_SHIFT 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) struct tsl4531_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	int int_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static IIO_CONST_ATTR_INT_TIME_AVAIL("0.1 0.2 0.4");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static struct attribute *tsl4531_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	&iio_const_attr_integration_time_available.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static const struct attribute_group tsl4531_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	.attrs = tsl4531_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static const struct iio_chan_spec tsl4531_channels[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		.type = IIO_LIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			BIT(IIO_CHAN_INFO_SCALE) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			BIT(IIO_CHAN_INFO_INT_TIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static int tsl4531_read_raw(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 				struct iio_chan_spec const *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 				int *val, int *val2, long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct tsl4531_data *data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	switch (mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	case IIO_CHAN_INFO_RAW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		ret = i2c_smbus_read_word_data(data->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			TSL4531_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		*val = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return IIO_VAL_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	case IIO_CHAN_INFO_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		/* 0.. 1x, 1 .. 2x, 2 .. 4x */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		*val = 1 << data->int_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return IIO_VAL_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	case IIO_CHAN_INFO_INT_TIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (data->int_time == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			*val2 = 400000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		else if (data->int_time == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			*val2 = 200000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		else if (data->int_time == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			*val2 = 100000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		*val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		return IIO_VAL_INT_PLUS_MICRO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int tsl4531_write_raw(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			     struct iio_chan_spec const *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			     int val, int val2, long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct tsl4531_data *data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	int int_time, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	switch (mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	case IIO_CHAN_INFO_INT_TIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		if (val != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if (val2 == 400000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			int_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		else if (val2 == 200000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			int_time = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		else if (val2 == 100000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			int_time = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		mutex_lock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		ret = i2c_smbus_write_byte_data(data->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			TSL4531_CONFIG, int_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			data->int_time = int_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		mutex_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static const struct iio_info tsl4531_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	.read_raw = tsl4531_read_raw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	.write_raw = tsl4531_write_raw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	.attrs = &tsl4531_attribute_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int tsl4531_check_id(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	int ret = i2c_smbus_read_byte_data(client, TSL4531_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	switch (ret >> TSL4531_ID_SHIFT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	case TSL45311_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	case TSL45313_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	case TSL45315_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	case TSL45317_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static int tsl4531_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			  const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct tsl4531_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct iio_dev *indio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (!indio_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	i2c_set_clientdata(client, indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	mutex_init(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	ret = tsl4531_check_id(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		dev_err(&client->dev, "no TSL4531 sensor\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	ret = i2c_smbus_write_byte_data(data->client, TSL4531_CONTROL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		TSL4531_MODE_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	ret = i2c_smbus_write_byte_data(data->client, TSL4531_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		TSL4531_TCNTRL_400MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	indio_dev->info = &tsl4531_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	indio_dev->channels = tsl4531_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	indio_dev->num_channels = ARRAY_SIZE(tsl4531_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	indio_dev->name = TSL4531_DRV_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	indio_dev->modes = INDIO_DIRECT_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	return iio_device_register(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static int tsl4531_powerdown(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return i2c_smbus_write_byte_data(client, TSL4531_CONTROL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		TSL4531_MODE_POWERDOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static int tsl4531_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	iio_device_unregister(i2c_get_clientdata(client));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	tsl4531_powerdown(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int tsl4531_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	return tsl4531_powerdown(to_i2c_client(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static int tsl4531_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	return i2c_smbus_write_byte_data(to_i2c_client(dev), TSL4531_CONTROL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		TSL4531_MODE_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static SIMPLE_DEV_PM_OPS(tsl4531_pm_ops, tsl4531_suspend, tsl4531_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #define TSL4531_PM_OPS (&tsl4531_pm_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #define TSL4531_PM_OPS NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static const struct i2c_device_id tsl4531_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	{ "tsl4531", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) MODULE_DEVICE_TABLE(i2c, tsl4531_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static struct i2c_driver tsl4531_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		.name   = TSL4531_DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		.pm	= TSL4531_PM_OPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	.probe  = tsl4531_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	.remove = tsl4531_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	.id_table = tsl4531_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) module_i2c_driver(tsl4531_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) MODULE_DESCRIPTION("TAOS TSL4531 ambient light sensors driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) MODULE_LICENSE("GPL");