srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 1 | /* |
| 2 | * HID Sensors Driver |
| 3 | * Copyright (c) 2012, Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | * |
| 18 | */ |
| 19 | #include <linux/device.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/irq.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/hid-sensor-hub.h> |
| 26 | #include <linux/iio/iio.h> |
| 27 | #include <linux/iio/sysfs.h> |
| 28 | #include <linux/iio/buffer.h> |
| 29 | #include <linux/iio/trigger_consumer.h> |
| 30 | #include <linux/iio/triggered_buffer.h> |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 31 | #include "../common/hid-sensors/hid-sensor-trigger.h" |
| 32 | |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 33 | enum magn_3d_channel { |
| 34 | CHANNEL_SCAN_INDEX_X, |
| 35 | CHANNEL_SCAN_INDEX_Y, |
| 36 | CHANNEL_SCAN_INDEX_Z, |
| 37 | MAGN_3D_CHANNEL_MAX, |
| 38 | }; |
| 39 | |
| 40 | struct magn_3d_state { |
| 41 | struct hid_sensor_hub_callbacks callbacks; |
Alexander Holler | e07c6d1 | 2012-12-15 12:45:00 +0000 | [diff] [blame] | 42 | struct hid_sensor_common common_attributes; |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 43 | struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX]; |
| 44 | u32 magn_val[MAGN_3D_CHANNEL_MAX]; |
Srinivas Pandruvada | 92463fd | 2014-04-19 00:22:00 +0100 | [diff] [blame] | 45 | int scale_pre_decml; |
| 46 | int scale_post_decml; |
| 47 | int scale_precision; |
| 48 | int value_offset; |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | static const u32 magn_3d_addresses[MAGN_3D_CHANNEL_MAX] = { |
| 52 | HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS, |
| 53 | HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS, |
| 54 | HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS |
| 55 | }; |
| 56 | |
| 57 | /* Channel definitions */ |
| 58 | static const struct iio_chan_spec magn_3d_channels[] = { |
| 59 | { |
| 60 | .type = IIO_MAGN, |
| 61 | .modified = 1, |
| 62 | .channel2 = IIO_MOD_X, |
Jonathan Cameron | ecbe18f | 2013-02-27 19:03:04 +0000 | [diff] [blame] | 63 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | |
| 64 | BIT(IIO_CHAN_INFO_SCALE) | |
| 65 | BIT(IIO_CHAN_INFO_SAMP_FREQ) | |
| 66 | BIT(IIO_CHAN_INFO_HYSTERESIS), |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 67 | .scan_index = CHANNEL_SCAN_INDEX_X, |
| 68 | }, { |
| 69 | .type = IIO_MAGN, |
| 70 | .modified = 1, |
| 71 | .channel2 = IIO_MOD_Y, |
Jonathan Cameron | ecbe18f | 2013-02-27 19:03:04 +0000 | [diff] [blame] | 72 | .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 pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 76 | .scan_index = CHANNEL_SCAN_INDEX_Y, |
| 77 | }, { |
| 78 | .type = IIO_MAGN, |
| 79 | .modified = 1, |
| 80 | .channel2 = IIO_MOD_Z, |
Jonathan Cameron | ecbe18f | 2013-02-27 19:03:04 +0000 | [diff] [blame] | 81 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | |
| 82 | BIT(IIO_CHAN_INFO_SCALE) | |
| 83 | BIT(IIO_CHAN_INFO_SAMP_FREQ) | |
| 84 | BIT(IIO_CHAN_INFO_HYSTERESIS), |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 85 | .scan_index = CHANNEL_SCAN_INDEX_Z, |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | /* Adjust channel real bits based on report descriptor */ |
| 90 | static void magn_3d_adjust_channel_bit_mask(struct iio_chan_spec *channels, |
| 91 | int channel, int size) |
| 92 | { |
| 93 | channels[channel].scan_type.sign = 's'; |
| 94 | /* Real storage bits will change based on the report desc. */ |
| 95 | channels[channel].scan_type.realbits = size * 8; |
| 96 | /* Maximum size of a sample to capture is u32 */ |
| 97 | channels[channel].scan_type.storagebits = sizeof(u32) * 8; |
| 98 | } |
| 99 | |
| 100 | /* Channel read_raw handler */ |
| 101 | static int magn_3d_read_raw(struct iio_dev *indio_dev, |
| 102 | struct iio_chan_spec const *chan, |
| 103 | int *val, int *val2, |
| 104 | long mask) |
| 105 | { |
| 106 | struct magn_3d_state *magn_state = iio_priv(indio_dev); |
| 107 | int report_id = -1; |
| 108 | u32 address; |
| 109 | int ret; |
| 110 | int ret_type; |
| 111 | |
| 112 | *val = 0; |
| 113 | *val2 = 0; |
| 114 | switch (mask) { |
| 115 | case 0: |
| 116 | report_id = |
| 117 | magn_state->magn[chan->scan_index].report_id; |
| 118 | address = magn_3d_addresses[chan->scan_index]; |
| 119 | if (report_id >= 0) |
| 120 | *val = sensor_hub_input_attr_get_raw_value( |
| 121 | magn_state->common_attributes.hsdev, |
| 122 | HID_USAGE_SENSOR_COMPASS_3D, address, |
| 123 | report_id); |
| 124 | else { |
| 125 | *val = 0; |
| 126 | return -EINVAL; |
| 127 | } |
| 128 | ret_type = IIO_VAL_INT; |
| 129 | break; |
| 130 | case IIO_CHAN_INFO_SCALE: |
Srinivas Pandruvada | 92463fd | 2014-04-19 00:22:00 +0100 | [diff] [blame] | 131 | *val = magn_state->scale_pre_decml; |
| 132 | *val2 = magn_state->scale_post_decml; |
| 133 | ret_type = magn_state->scale_precision; |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 134 | break; |
| 135 | case IIO_CHAN_INFO_OFFSET: |
Srinivas Pandruvada | 92463fd | 2014-04-19 00:22:00 +0100 | [diff] [blame] | 136 | *val = magn_state->value_offset; |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 137 | ret_type = IIO_VAL_INT; |
| 138 | break; |
| 139 | case IIO_CHAN_INFO_SAMP_FREQ: |
| 140 | ret = hid_sensor_read_samp_freq_value( |
| 141 | &magn_state->common_attributes, val, val2); |
| 142 | ret_type = IIO_VAL_INT_PLUS_MICRO; |
| 143 | break; |
| 144 | case IIO_CHAN_INFO_HYSTERESIS: |
| 145 | ret = hid_sensor_read_raw_hyst_value( |
| 146 | &magn_state->common_attributes, val, val2); |
| 147 | ret_type = IIO_VAL_INT_PLUS_MICRO; |
| 148 | break; |
| 149 | default: |
| 150 | ret_type = -EINVAL; |
| 151 | break; |
| 152 | } |
| 153 | |
| 154 | return ret_type; |
| 155 | } |
| 156 | |
| 157 | /* Channel write_raw handler */ |
| 158 | static int magn_3d_write_raw(struct iio_dev *indio_dev, |
| 159 | struct iio_chan_spec const *chan, |
| 160 | int val, |
| 161 | int val2, |
| 162 | long mask) |
| 163 | { |
| 164 | struct magn_3d_state *magn_state = iio_priv(indio_dev); |
| 165 | int ret = 0; |
| 166 | |
| 167 | switch (mask) { |
| 168 | case IIO_CHAN_INFO_SAMP_FREQ: |
| 169 | ret = hid_sensor_write_samp_freq_value( |
| 170 | &magn_state->common_attributes, val, val2); |
| 171 | break; |
| 172 | case IIO_CHAN_INFO_HYSTERESIS: |
| 173 | ret = hid_sensor_write_raw_hyst_value( |
| 174 | &magn_state->common_attributes, val, val2); |
| 175 | break; |
| 176 | default: |
| 177 | ret = -EINVAL; |
| 178 | } |
| 179 | |
| 180 | return ret; |
| 181 | } |
| 182 | |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 183 | static const struct iio_info magn_3d_info = { |
| 184 | .driver_module = THIS_MODULE, |
| 185 | .read_raw = &magn_3d_read_raw, |
| 186 | .write_raw = &magn_3d_write_raw, |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | /* Function to push data to buffer */ |
Lars-Peter Clausen | 8c60c7e | 2013-09-15 17:50:00 +0100 | [diff] [blame] | 190 | static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *data, |
| 191 | int len) |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 192 | { |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 193 | dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); |
Lars-Peter Clausen | 8c60c7e | 2013-09-15 17:50:00 +0100 | [diff] [blame] | 194 | iio_push_to_buffers(indio_dev, data); |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* Callback handler to send event after all samples are received and captured */ |
| 198 | static int magn_3d_proc_event(struct hid_sensor_hub_device *hsdev, |
| 199 | unsigned usage_id, |
| 200 | void *priv) |
| 201 | { |
| 202 | struct iio_dev *indio_dev = platform_get_drvdata(priv); |
| 203 | struct magn_3d_state *magn_state = iio_priv(indio_dev); |
| 204 | |
Srinivas Pandruvada | 56ff6be | 2014-04-19 00:22:00 +0100 | [diff] [blame^] | 205 | dev_dbg(&indio_dev->dev, "magn_3d_proc_event\n"); |
| 206 | if (atomic_read(&magn_state->common_attributes.data_ready)) |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 207 | hid_sensor_push_data(indio_dev, |
Lars-Peter Clausen | 8c60c7e | 2013-09-15 17:50:00 +0100 | [diff] [blame] | 208 | magn_state->magn_val, |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 209 | sizeof(magn_state->magn_val)); |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | /* Capture samples in local storage */ |
| 215 | static int magn_3d_capture_sample(struct hid_sensor_hub_device *hsdev, |
| 216 | unsigned usage_id, |
| 217 | size_t raw_len, char *raw_data, |
| 218 | void *priv) |
| 219 | { |
| 220 | struct iio_dev *indio_dev = platform_get_drvdata(priv); |
| 221 | struct magn_3d_state *magn_state = iio_priv(indio_dev); |
| 222 | int offset; |
| 223 | int ret = -EINVAL; |
| 224 | |
| 225 | switch (usage_id) { |
| 226 | case HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS: |
| 227 | case HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS: |
| 228 | case HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS: |
| 229 | offset = usage_id - HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS; |
| 230 | magn_state->magn_val[CHANNEL_SCAN_INDEX_X + offset] = |
| 231 | *(u32 *)raw_data; |
| 232 | ret = 0; |
| 233 | break; |
| 234 | default: |
| 235 | break; |
| 236 | } |
| 237 | |
| 238 | return ret; |
| 239 | } |
| 240 | |
| 241 | /* Parse report which is specific to an usage id*/ |
| 242 | static int magn_3d_parse_report(struct platform_device *pdev, |
| 243 | struct hid_sensor_hub_device *hsdev, |
| 244 | struct iio_chan_spec *channels, |
| 245 | unsigned usage_id, |
| 246 | struct magn_3d_state *st) |
| 247 | { |
| 248 | int ret; |
| 249 | int i; |
| 250 | |
| 251 | for (i = 0; i <= CHANNEL_SCAN_INDEX_Z; ++i) { |
| 252 | ret = sensor_hub_input_get_attribute_info(hsdev, |
| 253 | HID_INPUT_REPORT, |
| 254 | usage_id, |
| 255 | HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS + i, |
| 256 | &st->magn[CHANNEL_SCAN_INDEX_X + i]); |
| 257 | if (ret < 0) |
| 258 | break; |
| 259 | magn_3d_adjust_channel_bit_mask(channels, |
| 260 | CHANNEL_SCAN_INDEX_X + i, |
| 261 | st->magn[CHANNEL_SCAN_INDEX_X + i].size); |
| 262 | } |
| 263 | dev_dbg(&pdev->dev, "magn_3d %x:%x, %x:%x, %x:%x\n", |
| 264 | st->magn[0].index, |
| 265 | st->magn[0].report_id, |
| 266 | st->magn[1].index, st->magn[1].report_id, |
| 267 | st->magn[2].index, st->magn[2].report_id); |
| 268 | |
Srinivas Pandruvada | 92463fd | 2014-04-19 00:22:00 +0100 | [diff] [blame] | 269 | st->scale_precision = hid_sensor_format_scale( |
| 270 | HID_USAGE_SENSOR_COMPASS_3D, |
| 271 | &st->magn[CHANNEL_SCAN_INDEX_X], |
| 272 | &st->scale_pre_decml, &st->scale_post_decml); |
| 273 | |
Srinivas Pandruvada | 2461fc9 | 2013-11-06 00:11:00 +0000 | [diff] [blame] | 274 | /* Set Sensitivity field ids, when there is no individual modifier */ |
| 275 | if (st->common_attributes.sensitivity.index < 0) { |
| 276 | sensor_hub_input_get_attribute_info(hsdev, |
| 277 | HID_FEATURE_REPORT, usage_id, |
| 278 | HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS | |
| 279 | HID_USAGE_SENSOR_DATA_ORIENTATION, |
| 280 | &st->common_attributes.sensitivity); |
| 281 | dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n", |
| 282 | st->common_attributes.sensitivity.index, |
| 283 | st->common_attributes.sensitivity.report_id); |
| 284 | } |
| 285 | |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 286 | return ret; |
| 287 | } |
| 288 | |
| 289 | /* Function to initialize the processing for usage id */ |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 290 | static int hid_magn_3d_probe(struct platform_device *pdev) |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 291 | { |
| 292 | int ret = 0; |
| 293 | static char *name = "magn_3d"; |
| 294 | struct iio_dev *indio_dev; |
| 295 | struct magn_3d_state *magn_state; |
| 296 | struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; |
| 297 | struct iio_chan_spec *channels; |
| 298 | |
Sachin Kamat | 907c0a0 | 2013-08-02 11:08:00 +0100 | [diff] [blame] | 299 | indio_dev = devm_iio_device_alloc(&pdev->dev, |
| 300 | sizeof(struct magn_3d_state)); |
| 301 | if (indio_dev == NULL) |
| 302 | return -ENOMEM; |
| 303 | |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 304 | platform_set_drvdata(pdev, indio_dev); |
| 305 | |
| 306 | magn_state = iio_priv(indio_dev); |
| 307 | magn_state->common_attributes.hsdev = hsdev; |
| 308 | magn_state->common_attributes.pdev = pdev; |
| 309 | |
| 310 | ret = hid_sensor_parse_common_attributes(hsdev, |
| 311 | HID_USAGE_SENSOR_COMPASS_3D, |
| 312 | &magn_state->common_attributes); |
| 313 | if (ret) { |
| 314 | dev_err(&pdev->dev, "failed to setup common attributes\n"); |
Sachin Kamat | 907c0a0 | 2013-08-02 11:08:00 +0100 | [diff] [blame] | 315 | return ret; |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 316 | } |
| 317 | |
Axel Lin | 64ebe95 | 2012-10-27 16:03:00 +0100 | [diff] [blame] | 318 | channels = kmemdup(magn_3d_channels, sizeof(magn_3d_channels), |
| 319 | GFP_KERNEL); |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 320 | if (!channels) { |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 321 | dev_err(&pdev->dev, "failed to duplicate channels\n"); |
Sachin Kamat | 907c0a0 | 2013-08-02 11:08:00 +0100 | [diff] [blame] | 322 | return -ENOMEM; |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | ret = magn_3d_parse_report(pdev, hsdev, channels, |
| 326 | HID_USAGE_SENSOR_COMPASS_3D, magn_state); |
| 327 | if (ret) { |
| 328 | dev_err(&pdev->dev, "failed to setup attributes\n"); |
| 329 | goto error_free_dev_mem; |
| 330 | } |
| 331 | |
| 332 | indio_dev->channels = channels; |
| 333 | indio_dev->num_channels = ARRAY_SIZE(magn_3d_channels); |
| 334 | indio_dev->dev.parent = &pdev->dev; |
| 335 | indio_dev->info = &magn_3d_info; |
| 336 | indio_dev->name = name; |
| 337 | indio_dev->modes = INDIO_DIRECT_MODE; |
| 338 | |
| 339 | ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, |
| 340 | NULL, NULL); |
| 341 | if (ret) { |
| 342 | dev_err(&pdev->dev, "failed to initialize trigger buffer\n"); |
| 343 | goto error_free_dev_mem; |
| 344 | } |
Srinivas Pandruvada | 56ff6be | 2014-04-19 00:22:00 +0100 | [diff] [blame^] | 345 | atomic_set(&magn_state->common_attributes.data_ready, 0); |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 346 | ret = hid_sensor_setup_trigger(indio_dev, name, |
| 347 | &magn_state->common_attributes); |
| 348 | if (ret < 0) { |
| 349 | dev_err(&pdev->dev, "trigger setup failed\n"); |
| 350 | goto error_unreg_buffer_funcs; |
| 351 | } |
| 352 | |
| 353 | ret = iio_device_register(indio_dev); |
| 354 | if (ret) { |
| 355 | dev_err(&pdev->dev, "device register failed\n"); |
| 356 | goto error_remove_trigger; |
| 357 | } |
| 358 | |
| 359 | magn_state->callbacks.send_event = magn_3d_proc_event; |
| 360 | magn_state->callbacks.capture_sample = magn_3d_capture_sample; |
| 361 | magn_state->callbacks.pdev = pdev; |
| 362 | ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_COMPASS_3D, |
| 363 | &magn_state->callbacks); |
| 364 | if (ret < 0) { |
| 365 | dev_err(&pdev->dev, "callback reg failed\n"); |
| 366 | goto error_iio_unreg; |
| 367 | } |
| 368 | |
| 369 | return ret; |
| 370 | |
| 371 | error_iio_unreg: |
| 372 | iio_device_unregister(indio_dev); |
| 373 | error_remove_trigger: |
Srinivas Pandruvada | ec7f68e | 2013-10-30 22:48:00 +0000 | [diff] [blame] | 374 | hid_sensor_remove_trigger(&magn_state->common_attributes); |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 375 | error_unreg_buffer_funcs: |
| 376 | iio_triggered_buffer_cleanup(indio_dev); |
| 377 | error_free_dev_mem: |
| 378 | kfree(indio_dev->channels); |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 379 | return ret; |
| 380 | } |
| 381 | |
| 382 | /* Function to deinitialize the processing for usage id */ |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 383 | static int hid_magn_3d_remove(struct platform_device *pdev) |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 384 | { |
| 385 | struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; |
| 386 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); |
Srinivas Pandruvada | ec7f68e | 2013-10-30 22:48:00 +0000 | [diff] [blame] | 387 | struct magn_3d_state *magn_state = iio_priv(indio_dev); |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 388 | |
| 389 | sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_COMPASS_3D); |
| 390 | iio_device_unregister(indio_dev); |
Srinivas Pandruvada | ec7f68e | 2013-10-30 22:48:00 +0000 | [diff] [blame] | 391 | hid_sensor_remove_trigger(&magn_state->common_attributes); |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 392 | iio_triggered_buffer_cleanup(indio_dev); |
| 393 | kfree(indio_dev->channels); |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 394 | |
| 395 | return 0; |
| 396 | } |
| 397 | |
Alexander Holler | a67c385 | 2013-07-10 09:32:00 +0100 | [diff] [blame] | 398 | static struct platform_device_id hid_magn_3d_ids[] = { |
| 399 | { |
| 400 | /* Format: HID-SENSOR-usage_id_in_hex_lowercase */ |
| 401 | .name = "HID-SENSOR-200083", |
| 402 | }, |
| 403 | { /* sentinel */ } |
| 404 | }; |
| 405 | MODULE_DEVICE_TABLE(platform, hid_magn_3d_ids); |
| 406 | |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 407 | static struct platform_driver hid_magn_3d_platform_driver = { |
Alexander Holler | a67c385 | 2013-07-10 09:32:00 +0100 | [diff] [blame] | 408 | .id_table = hid_magn_3d_ids, |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 409 | .driver = { |
Alexander Holler | a67c385 | 2013-07-10 09:32:00 +0100 | [diff] [blame] | 410 | .name = KBUILD_MODNAME, |
srinivas pandruvada | bc1d57ba | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 411 | .owner = THIS_MODULE, |
| 412 | }, |
| 413 | .probe = hid_magn_3d_probe, |
| 414 | .remove = hid_magn_3d_remove, |
| 415 | }; |
| 416 | module_platform_driver(hid_magn_3d_platform_driver); |
| 417 | |
| 418 | MODULE_DESCRIPTION("HID Sensor Magnetometer 3D"); |
| 419 | MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@intel.com>"); |
| 420 | MODULE_LICENSE("GPL"); |