^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) * Sensortek STK3310/STK3311 Ambient Light and Proximity Sensor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2015, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * IIO driver for STK3310/STK3311. 7-bit I2C address: 0x48.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^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/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/iio/events.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/iio/iio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/iio/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define STK3310_REG_STATE 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define STK3310_REG_PSCTRL 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define STK3310_REG_ALSCTRL 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define STK3310_REG_INT 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define STK3310_REG_THDH_PS 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define STK3310_REG_THDL_PS 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define STK3310_REG_FLAG 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define STK3310_REG_PS_DATA_MSB 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define STK3310_REG_PS_DATA_LSB 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define STK3310_REG_ALS_DATA_MSB 0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define STK3310_REG_ALS_DATA_LSB 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define STK3310_REG_ID 0x3E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define STK3310_MAX_REG 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define STK3310_STATE_EN_PS BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define STK3310_STATE_EN_ALS BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define STK3310_STATE_STANDBY 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define STK3310_CHIP_ID_VAL 0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define STK3311_CHIP_ID_VAL 0x1D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define STK3311X_CHIP_ID_VAL 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define STK3335_CHIP_ID_VAL 0x51
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define STK3310_PSINT_EN 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define STK3310_PS_MAX_VAL 0xFFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define STK3310_DRIVER_NAME "stk3310"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define STK3310_REGMAP_NAME "stk3310_regmap"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define STK3310_EVENT "stk3310_event"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define STK3310_SCALE_AVAILABLE "6.4 1.6 0.4 0.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define STK3310_IT_AVAILABLE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) "0.000185 0.000370 0.000741 0.001480 0.002960 0.005920 0.011840 " \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) "0.023680 0.047360 0.094720 0.189440 0.378880 0.757760 1.515520 " \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) "3.031040 6.062080"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define STK3310_REGFIELD(name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) data->reg_##name = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) devm_regmap_field_alloc(&client->dev, regmap, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) stk3310_reg_field_##name); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (IS_ERR(data->reg_##name)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) dev_err(&client->dev, "reg field alloc failed.\n"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return PTR_ERR(data->reg_##name); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static const struct reg_field stk3310_reg_field_state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) REG_FIELD(STK3310_REG_STATE, 0, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static const struct reg_field stk3310_reg_field_als_gain =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) REG_FIELD(STK3310_REG_ALSCTRL, 4, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static const struct reg_field stk3310_reg_field_ps_gain =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) REG_FIELD(STK3310_REG_PSCTRL, 4, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static const struct reg_field stk3310_reg_field_als_it =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) REG_FIELD(STK3310_REG_ALSCTRL, 0, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static const struct reg_field stk3310_reg_field_ps_it =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) REG_FIELD(STK3310_REG_PSCTRL, 0, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static const struct reg_field stk3310_reg_field_int_ps =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) REG_FIELD(STK3310_REG_INT, 0, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static const struct reg_field stk3310_reg_field_flag_psint =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) REG_FIELD(STK3310_REG_FLAG, 4, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static const struct reg_field stk3310_reg_field_flag_nf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) REG_FIELD(STK3310_REG_FLAG, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* Estimate maximum proximity values with regard to measurement scale. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static const int stk3310_ps_max[4] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) STK3310_PS_MAX_VAL / 640,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) STK3310_PS_MAX_VAL / 160,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) STK3310_PS_MAX_VAL / 40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) STK3310_PS_MAX_VAL / 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static const int stk3310_scale_table[][2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {6, 400000}, {1, 600000}, {0, 400000}, {0, 100000}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* Integration time in seconds, microseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static const int stk3310_it_table[][2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {0, 185}, {0, 370}, {0, 741}, {0, 1480},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {0, 2960}, {0, 5920}, {0, 11840}, {0, 23680},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {0, 47360}, {0, 94720}, {0, 189440}, {0, 378880},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {0, 757760}, {1, 515520}, {3, 31040}, {6, 62080},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct stk3310_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) bool als_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) bool ps_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) u64 timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct regmap_field *reg_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct regmap_field *reg_als_gain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct regmap_field *reg_ps_gain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct regmap_field *reg_als_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct regmap_field *reg_ps_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct regmap_field *reg_int_ps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct regmap_field *reg_flag_psint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct regmap_field *reg_flag_nf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static const struct iio_event_spec stk3310_events[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* Proximity event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .type = IIO_EV_TYPE_THRESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .dir = IIO_EV_DIR_RISING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .mask_separate = BIT(IIO_EV_INFO_VALUE) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) BIT(IIO_EV_INFO_ENABLE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /* Out-of-proximity event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .type = IIO_EV_TYPE_THRESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .dir = IIO_EV_DIR_FALLING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .mask_separate = BIT(IIO_EV_INFO_VALUE) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) BIT(IIO_EV_INFO_ENABLE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static const struct iio_chan_spec stk3310_channels[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .type = IIO_LIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .info_mask_separate =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) BIT(IIO_CHAN_INFO_RAW) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) BIT(IIO_CHAN_INFO_SCALE) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) BIT(IIO_CHAN_INFO_INT_TIME),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .type = IIO_PROXIMITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .info_mask_separate =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) BIT(IIO_CHAN_INFO_RAW) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) BIT(IIO_CHAN_INFO_SCALE) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) BIT(IIO_CHAN_INFO_INT_TIME),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .event_spec = stk3310_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .num_event_specs = ARRAY_SIZE(stk3310_events),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static IIO_CONST_ATTR(in_illuminance_scale_available, STK3310_SCALE_AVAILABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static IIO_CONST_ATTR(in_proximity_scale_available, STK3310_SCALE_AVAILABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static IIO_CONST_ATTR(in_illuminance_integration_time_available,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) STK3310_IT_AVAILABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static IIO_CONST_ATTR(in_proximity_integration_time_available,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) STK3310_IT_AVAILABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static struct attribute *stk3310_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) &iio_const_attr_in_illuminance_scale_available.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) &iio_const_attr_in_proximity_scale_available.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) &iio_const_attr_in_illuminance_integration_time_available.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) &iio_const_attr_in_proximity_integration_time_available.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) NULL,
^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 const struct attribute_group stk3310_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .attrs = stk3310_attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static int stk3310_get_index(const int table[][2], int table_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int val, int val2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) for (i = 0; i < table_size; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (val == table[i][0] && val2 == table[i][1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^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) static int stk3310_read_event(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) const struct iio_chan_spec *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) enum iio_event_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) enum iio_event_direction dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) enum iio_event_info info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int *val, int *val2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) __be16 buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct stk3310_data *data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (info != IIO_EV_INFO_VALUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* Only proximity interrupts are implemented at the moment. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (dir == IIO_EV_DIR_RISING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) reg = STK3310_REG_THDH_PS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) else if (dir == IIO_EV_DIR_FALLING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) reg = STK3310_REG_THDL_PS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) mutex_lock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) ret = regmap_bulk_read(data->regmap, reg, &buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) mutex_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) dev_err(&data->client->dev, "register read failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) *val = be16_to_cpu(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return IIO_VAL_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int stk3310_write_event(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) const struct iio_chan_spec *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) enum iio_event_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) enum iio_event_direction dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) enum iio_event_info info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) int val, int val2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) __be16 buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct stk3310_data *data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ret = regmap_field_read(data->reg_ps_gain, &index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (val < 0 || val > stk3310_ps_max[index])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (dir == IIO_EV_DIR_RISING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) reg = STK3310_REG_THDH_PS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) else if (dir == IIO_EV_DIR_FALLING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) reg = STK3310_REG_THDL_PS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) buf = cpu_to_be16(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) ret = regmap_bulk_write(data->regmap, reg, &buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) dev_err(&client->dev, "failed to set PS threshold!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static int stk3310_read_event_config(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) const struct iio_chan_spec *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) enum iio_event_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) enum iio_event_direction dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) unsigned int event_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct stk3310_data *data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ret = regmap_field_read(data->reg_int_ps, &event_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return event_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static int stk3310_write_event_config(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) const struct iio_chan_spec *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) enum iio_event_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) enum iio_event_direction dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct stk3310_data *data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (state < 0 || state > 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* Set INT_PS value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) mutex_lock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ret = regmap_field_write(data->reg_int_ps, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) dev_err(&client->dev, "failed to set interrupt mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) mutex_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static int stk3310_read_raw(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct iio_chan_spec const *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int *val, int *val2, long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) __be16 buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct stk3310_data *data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (chan->type != IIO_LIGHT && chan->type != IIO_PROXIMITY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) switch (mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) case IIO_CHAN_INFO_RAW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (chan->type == IIO_LIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) reg = STK3310_REG_ALS_DATA_MSB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) reg = STK3310_REG_PS_DATA_MSB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) mutex_lock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) ret = regmap_bulk_read(data->regmap, reg, &buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) dev_err(&client->dev, "register read failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) mutex_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) *val = be16_to_cpu(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) mutex_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return IIO_VAL_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) case IIO_CHAN_INFO_INT_TIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (chan->type == IIO_LIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) ret = regmap_field_read(data->reg_als_it, &index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) ret = regmap_field_read(data->reg_ps_it, &index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) *val = stk3310_it_table[index][0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) *val2 = stk3310_it_table[index][1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return IIO_VAL_INT_PLUS_MICRO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) case IIO_CHAN_INFO_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (chan->type == IIO_LIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) ret = regmap_field_read(data->reg_als_gain, &index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) ret = regmap_field_read(data->reg_ps_gain, &index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) *val = stk3310_scale_table[index][0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) *val2 = stk3310_scale_table[index][1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return IIO_VAL_INT_PLUS_MICRO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static int stk3310_write_raw(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) struct iio_chan_spec const *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) int val, int val2, long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct stk3310_data *data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (chan->type != IIO_LIGHT && chan->type != IIO_PROXIMITY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) switch (mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) case IIO_CHAN_INFO_INT_TIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) index = stk3310_get_index(stk3310_it_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) ARRAY_SIZE(stk3310_it_table),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) val, val2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (index < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) mutex_lock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (chan->type == IIO_LIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) ret = regmap_field_write(data->reg_als_it, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ret = regmap_field_write(data->reg_ps_it, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) dev_err(&data->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) "sensor configuration failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) mutex_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) case IIO_CHAN_INFO_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) index = stk3310_get_index(stk3310_scale_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) ARRAY_SIZE(stk3310_scale_table),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) val, val2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (index < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) mutex_lock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (chan->type == IIO_LIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) ret = regmap_field_write(data->reg_als_gain, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) ret = regmap_field_write(data->reg_ps_gain, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) dev_err(&data->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) "sensor configuration failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) mutex_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static const struct iio_info stk3310_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) .read_raw = stk3310_read_raw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) .write_raw = stk3310_write_raw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) .attrs = &stk3310_attribute_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) .read_event_value = stk3310_read_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) .write_event_value = stk3310_write_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) .read_event_config = stk3310_read_event_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) .write_event_config = stk3310_write_event_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static int stk3310_set_state(struct stk3310_data *data, u8 state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) /* 3-bit state; 0b100 is not supported. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (state > 7 || state == 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) mutex_lock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) ret = regmap_field_write(data->reg_state, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) dev_err(&client->dev, "failed to change sensor state\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) } else if (state != STK3310_STATE_STANDBY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /* Don't reset the 'enabled' flags if we're going in standby */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) data->ps_enabled = !!(state & STK3310_STATE_EN_PS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) data->als_enabled = !!(state & STK3310_STATE_EN_ALS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) mutex_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) static int stk3310_init(struct iio_dev *indio_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) int chipid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) u8 state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct stk3310_data *data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) ret = regmap_read(data->regmap, STK3310_REG_ID, &chipid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (chipid != STK3310_CHIP_ID_VAL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) chipid != STK3311_CHIP_ID_VAL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) chipid != STK3311X_CHIP_ID_VAL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) chipid != STK3335_CHIP_ID_VAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) dev_err(&client->dev, "invalid chip id: 0x%x\n", chipid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) state = STK3310_STATE_EN_ALS | STK3310_STATE_EN_PS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) ret = stk3310_set_state(data, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) dev_err(&client->dev, "failed to enable sensor");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /* Enable PS interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) ret = regmap_field_write(data->reg_int_ps, STK3310_PSINT_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) dev_err(&client->dev, "failed to enable interrupts!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static bool stk3310_is_volatile_reg(struct device *dev, unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) switch (reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) case STK3310_REG_ALS_DATA_MSB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) case STK3310_REG_ALS_DATA_LSB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) case STK3310_REG_PS_DATA_LSB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) case STK3310_REG_PS_DATA_MSB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) case STK3310_REG_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static const struct regmap_config stk3310_regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) .name = STK3310_REGMAP_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) .reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) .val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) .max_register = STK3310_MAX_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) .cache_type = REGCACHE_RBTREE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) .volatile_reg = stk3310_is_volatile_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static int stk3310_regmap_init(struct stk3310_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) regmap = devm_regmap_init_i2c(client, &stk3310_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (IS_ERR(regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) dev_err(&client->dev, "regmap initialization failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return PTR_ERR(regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) data->regmap = regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) STK3310_REGFIELD(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) STK3310_REGFIELD(als_gain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) STK3310_REGFIELD(ps_gain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) STK3310_REGFIELD(als_it);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) STK3310_REGFIELD(ps_it);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) STK3310_REGFIELD(int_ps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) STK3310_REGFIELD(flag_psint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) STK3310_REGFIELD(flag_nf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static irqreturn_t stk3310_irq_handler(int irq, void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) struct iio_dev *indio_dev = private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct stk3310_data *data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) data->timestamp = iio_get_time_ns(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) return IRQ_WAKE_THREAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) static irqreturn_t stk3310_irq_event_handler(int irq, void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) unsigned int dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) u64 event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) struct iio_dev *indio_dev = private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) struct stk3310_data *data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) /* Read FLAG_NF to figure out what threshold has been met. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) mutex_lock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) ret = regmap_field_read(data->reg_flag_nf, &dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) dev_err(&data->client->dev, "register read failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) event = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) IIO_EV_TYPE_THRESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) (dir ? IIO_EV_DIR_FALLING :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) IIO_EV_DIR_RISING));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) iio_push_event(indio_dev, event, data->timestamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) /* Reset the interrupt flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) ret = regmap_field_write(data->reg_flag_psint, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) dev_err(&data->client->dev, "failed to reset interrupts\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) mutex_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static int stk3310_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) struct iio_dev *indio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) struct stk3310_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if (!indio_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) dev_err(&client->dev, "iio allocation failed!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) data = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) i2c_set_clientdata(client, indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) mutex_init(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) ret = stk3310_regmap_init(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) indio_dev->info = &stk3310_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) indio_dev->name = STK3310_DRIVER_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) indio_dev->modes = INDIO_DIRECT_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) indio_dev->channels = stk3310_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) indio_dev->num_channels = ARRAY_SIZE(stk3310_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) ret = stk3310_init(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (client->irq > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) ret = devm_request_threaded_irq(&client->dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) stk3310_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) stk3310_irq_event_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) IRQF_TRIGGER_FALLING |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) STK3310_EVENT, indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) dev_err(&client->dev, "request irq %d failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) goto err_standby;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) ret = iio_device_register(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) dev_err(&client->dev, "device_register failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) goto err_standby;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) err_standby:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) stk3310_set_state(data, STK3310_STATE_STANDBY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) static int stk3310_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) struct iio_dev *indio_dev = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) iio_device_unregister(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) return stk3310_set_state(iio_priv(indio_dev), STK3310_STATE_STANDBY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) static int stk3310_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) struct stk3310_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) return stk3310_set_state(data, STK3310_STATE_STANDBY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) static int stk3310_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) u8 state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) struct stk3310_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) if (data->ps_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) state |= STK3310_STATE_EN_PS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) if (data->als_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) state |= STK3310_STATE_EN_ALS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) return stk3310_set_state(data, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) static SIMPLE_DEV_PM_OPS(stk3310_pm_ops, stk3310_suspend, stk3310_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) #define STK3310_PM_OPS (&stk3310_pm_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) #define STK3310_PM_OPS NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) static const struct i2c_device_id stk3310_i2c_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) {"STK3310", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) {"STK3311", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) {"STK3335", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) MODULE_DEVICE_TABLE(i2c, stk3310_i2c_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) static const struct acpi_device_id stk3310_acpi_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) {"STK3310", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) {"STK3311", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) {"STK3335", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) MODULE_DEVICE_TABLE(acpi, stk3310_acpi_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) static const struct of_device_id stk3310_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) { .compatible = "sensortek,stk3310", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) { .compatible = "sensortek,stk3311", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) { .compatible = "sensortek,stk3335", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) MODULE_DEVICE_TABLE(of, stk3310_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) static struct i2c_driver stk3310_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) .name = "stk3310",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) .of_match_table = stk3310_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) .pm = STK3310_PM_OPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) .acpi_match_table = ACPI_PTR(stk3310_acpi_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) .probe = stk3310_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) .remove = stk3310_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) .id_table = stk3310_i2c_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) module_i2c_driver(stk3310_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) MODULE_AUTHOR("Tiberiu Breana <tiberiu.a.breana@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) MODULE_DESCRIPTION("STK3310 Ambient Light and Proximity Sensor driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) MODULE_LICENSE("GPL v2");