Lines Matching +full:light +full:- +full:sensor

1 // SPDX-License-Identifier: GPL-2.0
3 * cros_ec_light_prox - Driver for light and prox sensors behing CrosEC.
24 * We only represent one entry for light or proximity. EC is merging different
25 * light sensors to return the what the eye would see. For proximity, we
26 * currently support only one light source.
46 int idx = chan->scan_index; in cros_ec_light_prox_read()
48 mutex_lock(&st->core.cmd_lock); in cros_ec_light_prox_read()
52 if (chan->type == IIO_PROXIMITY) { in cros_ec_light_prox_read()
60 ret = -EINVAL; in cros_ec_light_prox_read()
64 if (chan->type == IIO_LIGHT) { in cros_ec_light_prox_read()
70 * The data coming from the light sensor is in cros_ec_light_prox_read()
71 * pre-processed and represents the ambient light in cros_ec_light_prox_read()
77 ret = -EINVAL; in cros_ec_light_prox_read()
81 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET; in cros_ec_light_prox_read()
82 st->core.param.sensor_offset.flags = 0; in cros_ec_light_prox_read()
84 ret = cros_ec_motion_send_host_cmd(&st->core, 0); in cros_ec_light_prox_read()
89 st->core.calib[0].offset = in cros_ec_light_prox_read()
90 st->core.resp->sensor_offset.offset[0]; in cros_ec_light_prox_read()
92 *val = st->core.calib[idx].offset; in cros_ec_light_prox_read()
101 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; in cros_ec_light_prox_read()
102 st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE; in cros_ec_light_prox_read()
104 ret = cros_ec_motion_send_host_cmd(&st->core, 0); in cros_ec_light_prox_read()
108 val64 = st->core.resp->sensor_range.ret; in cros_ec_light_prox_read()
114 ret = cros_ec_sensors_core_read(&st->core, chan, val, val2, in cros_ec_light_prox_read()
119 mutex_unlock(&st->core.cmd_lock); in cros_ec_light_prox_read()
130 int idx = chan->scan_index; in cros_ec_light_prox_write()
132 mutex_lock(&st->core.cmd_lock); in cros_ec_light_prox_write()
136 st->core.calib[idx].offset = val; in cros_ec_light_prox_write()
138 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET; in cros_ec_light_prox_write()
139 st->core.param.sensor_offset.flags = MOTION_SENSE_SET_OFFSET; in cros_ec_light_prox_write()
140 st->core.param.sensor_offset.offset[0] = in cros_ec_light_prox_write()
141 st->core.calib[0].offset; in cros_ec_light_prox_write()
142 st->core.param.sensor_offset.temp = in cros_ec_light_prox_write()
144 ret = cros_ec_motion_send_host_cmd(&st->core, 0); in cros_ec_light_prox_write()
147 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; in cros_ec_light_prox_write()
148 st->core.curr_range = (val << 16) | (val2 / 100); in cros_ec_light_prox_write()
149 st->core.param.sensor_range.data = st->core.curr_range; in cros_ec_light_prox_write()
150 ret = cros_ec_motion_send_host_cmd(&st->core, 0); in cros_ec_light_prox_write()
152 st->core.range_updated = true; in cros_ec_light_prox_write()
155 ret = cros_ec_sensors_core_write(&st->core, chan, val, val2, in cros_ec_light_prox_write()
160 mutex_unlock(&st->core.cmd_lock); in cros_ec_light_prox_write()
173 struct device *dev = &pdev->dev; in cros_ec_light_prox_probe()
181 return -ENOMEM; in cros_ec_light_prox_probe()
190 indio_dev->info = &cros_ec_light_prox_info; in cros_ec_light_prox_probe()
192 state->core.type = state->core.resp->info.type; in cros_ec_light_prox_probe()
193 state->core.loc = state->core.resp->info.location; in cros_ec_light_prox_probe()
194 channel = state->channels; in cros_ec_light_prox_probe()
197 channel->info_mask_shared_by_all = in cros_ec_light_prox_probe()
199 channel->info_mask_shared_by_all_available = in cros_ec_light_prox_probe()
201 channel->scan_type.realbits = CROS_EC_SENSOR_BITS; in cros_ec_light_prox_probe()
202 channel->scan_type.storagebits = CROS_EC_SENSOR_BITS; in cros_ec_light_prox_probe()
203 channel->scan_type.shift = 0; in cros_ec_light_prox_probe()
204 channel->scan_index = 0; in cros_ec_light_prox_probe()
205 channel->ext_info = cros_ec_sensors_ext_info; in cros_ec_light_prox_probe()
206 channel->scan_type.sign = 'u'; in cros_ec_light_prox_probe()
208 /* Sensor specific */ in cros_ec_light_prox_probe()
209 switch (state->core.type) { in cros_ec_light_prox_probe()
211 channel->type = IIO_LIGHT; in cros_ec_light_prox_probe()
212 channel->info_mask_separate = in cros_ec_light_prox_probe()
218 channel->type = IIO_PROXIMITY; in cros_ec_light_prox_probe()
219 channel->info_mask_separate = in cros_ec_light_prox_probe()
225 dev_warn(dev, "Unknown motion sensor\n"); in cros_ec_light_prox_probe()
226 return -EINVAL; in cros_ec_light_prox_probe()
231 channel->type = IIO_TIMESTAMP; in cros_ec_light_prox_probe()
232 channel->channel = -1; in cros_ec_light_prox_probe()
233 channel->scan_index = 1; in cros_ec_light_prox_probe()
234 channel->scan_type.sign = 's'; in cros_ec_light_prox_probe()
235 channel->scan_type.realbits = 64; in cros_ec_light_prox_probe()
236 channel->scan_type.storagebits = 64; in cros_ec_light_prox_probe()
238 indio_dev->channels = state->channels; in cros_ec_light_prox_probe()
240 indio_dev->num_channels = CROS_EC_LIGHT_PROX_MAX_CHANNELS; in cros_ec_light_prox_probe()
242 state->core.read_ec_sensors_data = cros_ec_sensors_read_cmd; in cros_ec_light_prox_probe()
249 .name = "cros-ec-prox",
252 .name = "cros-ec-light",
260 .name = "cros-ec-light-prox",
268 MODULE_DESCRIPTION("ChromeOS EC light/proximity sensors driver");