blob: 4c5e594024f8ca0c9a0d91fda8e695446f2a5de3 [file] [log] [blame]
Thomas Gleixnera61127c2019-05-29 16:57:49 -07001// SPDX-License-Identifier: GPL-2.0-only
srinivas pandruvada45fe6f72012-09-05 13:56:00 +01002/*
3 * HID Sensors Driver
4 * Copyright (c) 2012, Intel Corporation.
srinivas pandruvada45fe6f72012-09-05 13:56:00 +01005 */
6#include <linux/device.h>
7#include <linux/platform_device.h>
8#include <linux/module.h>
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/slab.h>
Srinivas Pandruvadac6399452014-04-19 00:22:00 +010012#include <linux/delay.h>
srinivas pandruvada45fe6f72012-09-05 13:56:00 +010013#include <linux/hid-sensor-hub.h>
14#include <linux/iio/iio.h>
15#include <linux/iio/sysfs.h>
16#include <linux/iio/buffer.h>
srinivas pandruvada45fe6f72012-09-05 13:56:00 +010017#include "../common/hid-sensors/hid-sensor-trigger.h"
18
srinivas pandruvada45fe6f72012-09-05 13:56:00 +010019enum accel_3d_channel {
20 CHANNEL_SCAN_INDEX_X,
21 CHANNEL_SCAN_INDEX_Y,
22 CHANNEL_SCAN_INDEX_Z,
23 ACCEL_3D_CHANNEL_MAX,
24};
25
26struct accel_3d_state {
27 struct hid_sensor_hub_callbacks callbacks;
Alexander Hollere07c6d12012-12-15 12:45:00 +000028 struct hid_sensor_common common_attributes;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +010029 struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX];
Srinivas Pandruvadaa96cd0f2016-11-28 14:41:16 -080030 /* Reserve for 3 channels + padding + timestamp */
31 u32 accel_val[ACCEL_3D_CHANNEL_MAX + 3];
Srinivas Pandruvada73a24982014-04-19 00:22:00 +010032 int scale_pre_decml;
33 int scale_post_decml;
34 int scale_precision;
35 int value_offset;
Srinivas Pandruvadaa96cd0f2016-11-28 14:41:16 -080036 int64_t timestamp;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +010037};
38
39static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = {
40 HID_USAGE_SENSOR_ACCEL_X_AXIS,
41 HID_USAGE_SENSOR_ACCEL_Y_AXIS,
42 HID_USAGE_SENSOR_ACCEL_Z_AXIS
43};
44
45/* Channel definitions */
46static const struct iio_chan_spec accel_3d_channels[] = {
47 {
48 .type = IIO_ACCEL,
49 .modified = 1,
50 .channel2 = IIO_MOD_X,
Srinivas Pandruvadac6399452014-04-19 00:22:00 +010051 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
Jonathan Cameronecbe18f2013-02-27 19:03:04 +000052 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
53 BIT(IIO_CHAN_INFO_SCALE) |
54 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
55 BIT(IIO_CHAN_INFO_HYSTERESIS),
srinivas pandruvada45fe6f72012-09-05 13:56:00 +010056 .scan_index = CHANNEL_SCAN_INDEX_X,
57 }, {
58 .type = IIO_ACCEL,
59 .modified = 1,
60 .channel2 = IIO_MOD_Y,
Srinivas Pandruvadac6399452014-04-19 00:22:00 +010061 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
Jonathan Cameronecbe18f2013-02-27 19:03:04 +000062 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
63 BIT(IIO_CHAN_INFO_SCALE) |
64 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
65 BIT(IIO_CHAN_INFO_HYSTERESIS),
srinivas pandruvada45fe6f72012-09-05 13:56:00 +010066 .scan_index = CHANNEL_SCAN_INDEX_Y,
67 }, {
68 .type = IIO_ACCEL,
69 .modified = 1,
70 .channel2 = IIO_MOD_Z,
Srinivas Pandruvadac6399452014-04-19 00:22:00 +010071 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
Jonathan Cameronecbe18f2013-02-27 19:03:04 +000072 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
73 BIT(IIO_CHAN_INFO_SCALE) |
74 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
75 BIT(IIO_CHAN_INFO_HYSTERESIS),
srinivas pandruvada45fe6f72012-09-05 13:56:00 +010076 .scan_index = CHANNEL_SCAN_INDEX_Z,
Srinivas Pandruvadaa96cd0f2016-11-28 14:41:16 -080077 },
78 IIO_CHAN_SOFT_TIMESTAMP(3)
srinivas pandruvada45fe6f72012-09-05 13:56:00 +010079};
80
Song Hongyan0e377f32017-01-05 18:24:04 +080081/* Channel definitions */
82static const struct iio_chan_spec gravity_channels[] = {
83 {
84 .type = IIO_GRAVITY,
85 .modified = 1,
86 .channel2 = IIO_MOD_X,
87 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
88 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
89 BIT(IIO_CHAN_INFO_SCALE) |
90 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
91 BIT(IIO_CHAN_INFO_HYSTERESIS),
92 .scan_index = CHANNEL_SCAN_INDEX_X,
93 }, {
94 .type = IIO_GRAVITY,
95 .modified = 1,
96 .channel2 = IIO_MOD_Y,
97 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
98 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
99 BIT(IIO_CHAN_INFO_SCALE) |
100 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
101 BIT(IIO_CHAN_INFO_HYSTERESIS),
102 .scan_index = CHANNEL_SCAN_INDEX_Y,
103 }, {
104 .type = IIO_GRAVITY,
105 .modified = 1,
106 .channel2 = IIO_MOD_Z,
107 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
108 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
109 BIT(IIO_CHAN_INFO_SCALE) |
110 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
111 BIT(IIO_CHAN_INFO_HYSTERESIS),
112 .scan_index = CHANNEL_SCAN_INDEX_Z,
113 }
114};
115
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100116/* Adjust channel real bits based on report descriptor */
117static void accel_3d_adjust_channel_bit_mask(struct iio_chan_spec *channels,
118 int channel, int size)
119{
120 channels[channel].scan_type.sign = 's';
121 /* Real storage bits will change based on the report desc. */
122 channels[channel].scan_type.realbits = size * 8;
123 /* Maximum size of a sample to capture is u32 */
124 channels[channel].scan_type.storagebits = sizeof(u32) * 8;
125}
126
127/* Channel read_raw handler */
128static int accel_3d_read_raw(struct iio_dev *indio_dev,
129 struct iio_chan_spec const *chan,
130 int *val, int *val2,
131 long mask)
132{
133 struct accel_3d_state *accel_state = iio_priv(indio_dev);
134 int report_id = -1;
135 u32 address;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100136 int ret_type;
Hans de Goede0145b502018-10-31 15:20:05 +0100137 s32 min;
Song Hongyan0e377f32017-01-05 18:24:04 +0800138 struct hid_sensor_hub_device *hsdev =
139 accel_state->common_attributes.hsdev;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100140
141 *val = 0;
142 *val2 = 0;
143 switch (mask) {
Rodrigo Siqueira67464a52018-03-06 09:02:57 -0300144 case IIO_CHAN_INFO_RAW:
Srinivas Pandruvadac6399452014-04-19 00:22:00 +0100145 hid_sensor_power_state(&accel_state->common_attributes, true);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100146 report_id = accel_state->accel[chan->scan_index].report_id;
Hans de Goede0145b502018-10-31 15:20:05 +0100147 min = accel_state->accel[chan->scan_index].logical_minimum;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100148 address = accel_3d_addresses[chan->scan_index];
149 if (report_id >= 0)
150 *val = sensor_hub_input_attr_get_raw_value(
Srinivas Pandruvadac6399452014-04-19 00:22:00 +0100151 accel_state->common_attributes.hsdev,
Song Hongyan0e377f32017-01-05 18:24:04 +0800152 hsdev->usage, address, report_id,
Hans de Goede0145b502018-10-31 15:20:05 +0100153 SENSOR_HUB_SYNC,
154 min < 0);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100155 else {
156 *val = 0;
Srinivas Pandruvadac6399452014-04-19 00:22:00 +0100157 hid_sensor_power_state(&accel_state->common_attributes,
158 false);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100159 return -EINVAL;
160 }
Srinivas Pandruvadac6399452014-04-19 00:22:00 +0100161 hid_sensor_power_state(&accel_state->common_attributes, false);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100162 ret_type = IIO_VAL_INT;
163 break;
164 case IIO_CHAN_INFO_SCALE:
Srinivas Pandruvada73a24982014-04-19 00:22:00 +0100165 *val = accel_state->scale_pre_decml;
166 *val2 = accel_state->scale_post_decml;
167 ret_type = accel_state->scale_precision;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100168 break;
169 case IIO_CHAN_INFO_OFFSET:
Srinivas Pandruvada73a24982014-04-19 00:22:00 +0100170 *val = accel_state->value_offset;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100171 ret_type = IIO_VAL_INT;
172 break;
173 case IIO_CHAN_INFO_SAMP_FREQ:
Sachin Kamat2f084c12014-03-07 07:44:00 +0000174 ret_type = hid_sensor_read_samp_freq_value(
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100175 &accel_state->common_attributes, val, val2);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100176 break;
177 case IIO_CHAN_INFO_HYSTERESIS:
Sachin Kamat2f084c12014-03-07 07:44:00 +0000178 ret_type = hid_sensor_read_raw_hyst_value(
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100179 &accel_state->common_attributes, val, val2);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100180 break;
181 default:
182 ret_type = -EINVAL;
183 break;
184 }
185
186 return ret_type;
187}
188
189/* Channel write_raw handler */
190static int accel_3d_write_raw(struct iio_dev *indio_dev,
191 struct iio_chan_spec const *chan,
192 int val,
193 int val2,
194 long mask)
195{
196 struct accel_3d_state *accel_state = iio_priv(indio_dev);
197 int ret = 0;
198
199 switch (mask) {
200 case IIO_CHAN_INFO_SAMP_FREQ:
201 ret = hid_sensor_write_samp_freq_value(
202 &accel_state->common_attributes, val, val2);
203 break;
204 case IIO_CHAN_INFO_HYSTERESIS:
205 ret = hid_sensor_write_raw_hyst_value(
206 &accel_state->common_attributes, val, val2);
207 break;
208 default:
209 ret = -EINVAL;
210 }
211
212 return ret;
213}
214
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100215static const struct iio_info accel_3d_info = {
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100216 .read_raw = &accel_3d_read_raw,
217 .write_raw = &accel_3d_write_raw,
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100218};
219
220/* Function to push data to buffer */
Srinivas Pandruvadaa96cd0f2016-11-28 14:41:16 -0800221static void hid_sensor_push_data(struct iio_dev *indio_dev, void *data,
222 int len, int64_t timestamp)
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100223{
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100224 dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n");
Srinivas Pandruvadaa96cd0f2016-11-28 14:41:16 -0800225 iio_push_to_buffers_with_timestamp(indio_dev, data, timestamp);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100226}
227
228/* Callback handler to send event after all samples are received and captured */
229static int accel_3d_proc_event(struct hid_sensor_hub_device *hsdev,
230 unsigned usage_id,
231 void *priv)
232{
233 struct iio_dev *indio_dev = platform_get_drvdata(priv);
234 struct accel_3d_state *accel_state = iio_priv(indio_dev);
235
Srinivas Pandruvada56ff6be2014-04-19 00:22:00 +0100236 dev_dbg(&indio_dev->dev, "accel_3d_proc_event\n");
Srinivas Pandruvadaa96cd0f2016-11-28 14:41:16 -0800237 if (atomic_read(&accel_state->common_attributes.data_ready)) {
238 if (!accel_state->timestamp)
239 accel_state->timestamp = iio_get_time_ns(indio_dev);
240
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100241 hid_sensor_push_data(indio_dev,
Srinivas Pandruvadaa96cd0f2016-11-28 14:41:16 -0800242 accel_state->accel_val,
243 sizeof(accel_state->accel_val),
244 accel_state->timestamp);
245
246 accel_state->timestamp = 0;
247 }
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100248
249 return 0;
250}
251
252/* Capture samples in local storage */
253static int accel_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
254 unsigned usage_id,
255 size_t raw_len, char *raw_data,
256 void *priv)
257{
258 struct iio_dev *indio_dev = platform_get_drvdata(priv);
259 struct accel_3d_state *accel_state = iio_priv(indio_dev);
260 int offset;
261 int ret = -EINVAL;
262
263 switch (usage_id) {
264 case HID_USAGE_SENSOR_ACCEL_X_AXIS:
265 case HID_USAGE_SENSOR_ACCEL_Y_AXIS:
266 case HID_USAGE_SENSOR_ACCEL_Z_AXIS:
267 offset = usage_id - HID_USAGE_SENSOR_ACCEL_X_AXIS;
268 accel_state->accel_val[CHANNEL_SCAN_INDEX_X + offset] =
269 *(u32 *)raw_data;
270 ret = 0;
271 break;
Srinivas Pandruvadaa96cd0f2016-11-28 14:41:16 -0800272 case HID_USAGE_SENSOR_TIME_TIMESTAMP:
273 accel_state->timestamp =
274 hid_sensor_convert_timestamp(
275 &accel_state->common_attributes,
276 *(int64_t *)raw_data);
277 break;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100278 default:
279 break;
280 }
281
282 return ret;
283}
284
285/* Parse report which is specific to an usage id*/
286static int accel_3d_parse_report(struct platform_device *pdev,
287 struct hid_sensor_hub_device *hsdev,
288 struct iio_chan_spec *channels,
289 unsigned usage_id,
290 struct accel_3d_state *st)
291{
292 int ret;
293 int i;
294
295 for (i = 0; i <= CHANNEL_SCAN_INDEX_Z; ++i) {
296 ret = sensor_hub_input_get_attribute_info(hsdev,
297 HID_INPUT_REPORT,
298 usage_id,
299 HID_USAGE_SENSOR_ACCEL_X_AXIS + i,
300 &st->accel[CHANNEL_SCAN_INDEX_X + i]);
301 if (ret < 0)
302 break;
303 accel_3d_adjust_channel_bit_mask(channels,
304 CHANNEL_SCAN_INDEX_X + i,
305 st->accel[CHANNEL_SCAN_INDEX_X + i].size);
306 }
307 dev_dbg(&pdev->dev, "accel_3d %x:%x, %x:%x, %x:%x\n",
308 st->accel[0].index,
309 st->accel[0].report_id,
310 st->accel[1].index, st->accel[1].report_id,
311 st->accel[2].index, st->accel[2].report_id);
312
Srinivas Pandruvada73a24982014-04-19 00:22:00 +0100313 st->scale_precision = hid_sensor_format_scale(
Song Hongyan0e377f32017-01-05 18:24:04 +0800314 hsdev->usage,
Srinivas Pandruvada73a24982014-04-19 00:22:00 +0100315 &st->accel[CHANNEL_SCAN_INDEX_X],
316 &st->scale_pre_decml, &st->scale_post_decml);
317
Srinivas Pandruvada64528d02013-10-30 22:48:00 +0000318 /* Set Sensitivity field ids, when there is no individual modifier */
319 if (st->common_attributes.sensitivity.index < 0) {
320 sensor_hub_input_get_attribute_info(hsdev,
321 HID_FEATURE_REPORT, usage_id,
322 HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
323 HID_USAGE_SENSOR_DATA_ACCELERATION,
324 &st->common_attributes.sensitivity);
325 dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
326 st->common_attributes.sensitivity.index,
327 st->common_attributes.sensitivity.report_id);
328 }
329
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100330 return ret;
331}
332
333/* Function to initialize the processing for usage id */
Greg Kroah-Hartmanfc526922012-12-21 13:21:43 -0800334static int hid_accel_3d_probe(struct platform_device *pdev)
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100335{
336 int ret = 0;
Julia Lawall40f4b1f2017-05-04 22:10:52 +0200337 const char *name;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100338 struct iio_dev *indio_dev;
339 struct accel_3d_state *accel_state;
Song Hongyan0e377f32017-01-05 18:24:04 +0800340 const struct iio_chan_spec *channel_spec;
341 int channel_size;
342
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100343 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100344
Sachin Kamat6b545ee2013-07-23 07:47:00 +0100345 indio_dev = devm_iio_device_alloc(&pdev->dev,
346 sizeof(struct accel_3d_state));
347 if (indio_dev == NULL)
348 return -ENOMEM;
349
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100350 platform_set_drvdata(pdev, indio_dev);
351
352 accel_state = iio_priv(indio_dev);
353 accel_state->common_attributes.hsdev = hsdev;
354 accel_state->common_attributes.pdev = pdev;
355
Song Hongyan0e377f32017-01-05 18:24:04 +0800356 if (hsdev->usage == HID_USAGE_SENSOR_ACCEL_3D) {
357 name = "accel_3d";
358 channel_spec = accel_3d_channels;
359 channel_size = sizeof(accel_3d_channels);
Srinivas Pandruvada862d1d82017-03-29 16:23:35 -0700360 indio_dev->num_channels = ARRAY_SIZE(accel_3d_channels);
Song Hongyan0e377f32017-01-05 18:24:04 +0800361 } else {
362 name = "gravity";
363 channel_spec = gravity_channels;
364 channel_size = sizeof(gravity_channels);
Srinivas Pandruvada862d1d82017-03-29 16:23:35 -0700365 indio_dev->num_channels = ARRAY_SIZE(gravity_channels);
Song Hongyan0e377f32017-01-05 18:24:04 +0800366 }
367 ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage,
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100368 &accel_state->common_attributes);
369 if (ret) {
370 dev_err(&pdev->dev, "failed to setup common attributes\n");
Sachin Kamat6b545ee2013-07-23 07:47:00 +0100371 return ret;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100372 }
Song Hongyan0e377f32017-01-05 18:24:04 +0800373 indio_dev->channels = kmemdup(channel_spec, channel_size, GFP_KERNEL);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100374
Fabio Estevamb136faf2015-05-13 15:06:09 -0300375 if (!indio_dev->channels) {
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100376 dev_err(&pdev->dev, "failed to duplicate channels\n");
Sachin Kamat6b545ee2013-07-23 07:47:00 +0100377 return -ENOMEM;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100378 }
Fabio Estevamb136faf2015-05-13 15:06:09 -0300379 ret = accel_3d_parse_report(pdev, hsdev,
Song Hongyan0e377f32017-01-05 18:24:04 +0800380 (struct iio_chan_spec *)indio_dev->channels,
381 hsdev->usage, accel_state);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100382 if (ret) {
383 dev_err(&pdev->dev, "failed to setup attributes\n");
384 goto error_free_dev_mem;
385 }
386
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100387 indio_dev->info = &accel_3d_info;
388 indio_dev->name = name;
389 indio_dev->modes = INDIO_DIRECT_MODE;
390
Srinivas Pandruvada56ff6be2014-04-19 00:22:00 +0100391 atomic_set(&accel_state->common_attributes.data_ready, 0);
Alexandru Ardelean067fda12020-04-24 07:34:18 +0300392
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100393 ret = hid_sensor_setup_trigger(indio_dev, name,
394 &accel_state->common_attributes);
395 if (ret < 0) {
396 dev_err(&pdev->dev, "trigger setup failed\n");
Alexandru Ardelean067fda12020-04-24 07:34:18 +0300397 goto error_free_dev_mem;
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100398 }
399
400 ret = iio_device_register(indio_dev);
401 if (ret) {
402 dev_err(&pdev->dev, "device register failed\n");
403 goto error_remove_trigger;
404 }
405
406 accel_state->callbacks.send_event = accel_3d_proc_event;
407 accel_state->callbacks.capture_sample = accel_3d_capture_sample;
408 accel_state->callbacks.pdev = pdev;
Song Hongyan0e377f32017-01-05 18:24:04 +0800409 ret = sensor_hub_register_callback(hsdev, hsdev->usage,
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100410 &accel_state->callbacks);
411 if (ret < 0) {
412 dev_err(&pdev->dev, "callback reg failed\n");
413 goto error_iio_unreg;
414 }
415
416 return ret;
417
418error_iio_unreg:
419 iio_device_unregister(indio_dev);
420error_remove_trigger:
Alexandru Ardelean067fda12020-04-24 07:34:18 +0300421 hid_sensor_remove_trigger(indio_dev, &accel_state->common_attributes);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100422error_free_dev_mem:
423 kfree(indio_dev->channels);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100424 return ret;
425}
426
427/* Function to deinitialize the processing for usage id */
Greg Kroah-Hartmanfc526922012-12-21 13:21:43 -0800428static int hid_accel_3d_remove(struct platform_device *pdev)
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100429{
430 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
431 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
Srinivas Pandruvadaec7f68e2013-10-30 22:48:00 +0000432 struct accel_3d_state *accel_state = iio_priv(indio_dev);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100433
Song Hongyan0e377f32017-01-05 18:24:04 +0800434 sensor_hub_remove_callback(hsdev, hsdev->usage);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100435 iio_device_unregister(indio_dev);
Alexandru Ardelean067fda12020-04-24 07:34:18 +0300436 hid_sensor_remove_trigger(indio_dev, &accel_state->common_attributes);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100437 kfree(indio_dev->channels);
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100438
439 return 0;
440}
441
Krzysztof Kozlowski76ec50a2015-05-02 00:53:30 +0900442static const struct platform_device_id hid_accel_3d_ids[] = {
Alexander Holler66c721f2013-07-10 09:31:00 +0100443 {
444 /* Format: HID-SENSOR-usage_id_in_hex_lowercase */
445 .name = "HID-SENSOR-200073",
446 },
Song Hongyan0e377f32017-01-05 18:24:04 +0800447 { /* gravity sensor */
448 .name = "HID-SENSOR-20007b",
449 },
Alexander Holler66c721f2013-07-10 09:31:00 +0100450 { /* sentinel */ }
451};
452MODULE_DEVICE_TABLE(platform, hid_accel_3d_ids);
453
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100454static struct platform_driver hid_accel_3d_platform_driver = {
Alexander Holler66c721f2013-07-10 09:31:00 +0100455 .id_table = hid_accel_3d_ids,
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100456 .driver = {
Alexander Holler66c721f2013-07-10 09:31:00 +0100457 .name = KBUILD_MODNAME,
Srinivas Pandruvadacbbcc932015-01-07 10:55:54 -0800458 .pm = &hid_sensor_pm_ops,
srinivas pandruvada45fe6f72012-09-05 13:56:00 +0100459 },
460 .probe = hid_accel_3d_probe,
461 .remove = hid_accel_3d_remove,
462};
463module_platform_driver(hid_accel_3d_platform_driver);
464
465MODULE_DESCRIPTION("HID Sensor Accel 3D");
466MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@intel.com>");
467MODULE_LICENSE("GPL");