<div dir="ltr">I have modified the hid-sensor-accel_3d.c driver to add the custom fields - CHANNEL_SCAN_DATA_MOTION and HID_USAGE_SENSOR_DATA_CUSTOM_VALUEX ( X = 2,3,4).<div>Below are my modifications : </div><div><br></div><div><div>enum accel_3d_channel {</div><div><span class="" style="white-space:pre">        </span>CHANNEL_SCAN_INDEX_X,</div><div><span class="" style="white-space:pre">        </span>CHANNEL_SCAN_INDEX_Y,</div><div><span class="" style="white-space:pre">        </span>CHANNEL_SCAN_INDEX_Z,</div><div><span class="" style="white-space:pre">        </span><b>CHANNEL_SCAN_DATA_MOTION,</b></div><div><b><span class="" style="white-space:pre">        </span>CHANNEL_CUSTOM_VALUE_2,</b></div><div><b><span class="" style="white-space:pre">        </span>CHANNEL_CUSTOM_VALUE_3,</b></div><div><b>        CHANNEL_CUSTOM_VALUE_4,</b></div><div><span class="" style="white-space:pre">        </span>ACCEL_3D_CHANNEL_MAX,</div></div><div><br></div><div><div>static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = {</div><div><span class="" style="white-space:pre">        </span>HID_USAGE_SENSOR_ACCEL_X_AXIS,</div><div><span class="" style="white-space:pre">        </span>HID_USAGE_SENSOR_ACCEL_Y_AXIS,</div><div><span class="" style="white-space:pre">        </span>HID_USAGE_SENSOR_ACCEL_Z_AXIS,<span class="" style="white-space:pre">        </span></div><div><span class="" style="white-space:pre">        </span><b>HID_USAGE_SENSOR_DATA_MOTION_STATE,</b></div><div><b><span class="" style="white-space:pre">        </span>HID_USAGE_SENSOR_DATA_CUSTOM_VALUE2,<span class="" style="white-space:pre">                        </span></b></div><div><b><span class="" style="white-space:pre">        </span>HID_USAGE_SENSOR_DATA_CUSTOM_VALUE3,<span class="" style="white-space:pre">                        </span></b></div><div><b><span class="" style="white-space:pre">        </span>HID_USAGE_SENSOR_DATA_CUSTOM_VALUE4</b><span class="" style="white-space:pre">                        </span></div><div>};</div></div><div><br></div><div><br></div><div><br></div><div><div>/* Channel definitions */</div><div>static const struct iio_chan_spec accel_3d_channels[] = {</div><div><span class="" style="white-space:pre">        </span>{</div></div><div>..</div><div>..</div><div>..</div><div><div><b>{</b></div><div><b><span class="" style="white-space:pre">                </span>.type = IIO_ACCEL,</b></div><div><b><span class="" style="white-space:pre">                </span>.modified = 1,</b></div><div><b><span class="" style="white-space:pre">                </span>.channel2 = IIO_MOD_X,</b></div><div><b><span class="" style="white-space:pre">                </span>.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),</b></div><div><b><span class="" style="white-space:pre">                </span>.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |</b></div><div><b><span class="" style="white-space:pre">                </span>BIT(IIO_CHAN_INFO_SCALE) |</b></div><div><b><span class="" style="white-space:pre">                </span>BIT(IIO_CHAN_INFO_SAMP_FREQ) |</b></div><div><b><span class="" style="white-space:pre">                </span>BIT(IIO_CHAN_INFO_HYSTERESIS),</b></div><div><b><span class="" style="white-space:pre">                </span>.scan_index = CHANNEL_SCAN_DATA_MOTION,</b></div><div><b><span class="" style="white-space:pre">        </span>},</b></div><div><span class="" style="white-space:pre">        </span><b>{</b></div><div><b><span class="" style="white-space:pre">                </span>.type = IIO_ACCEL,</b></div><div><b><span class="" style="white-space:pre">                </span>.modified = 1,</b></div><div><b><span class="" style="white-space:pre">                </span>.channel2 = IIO_MOD_X,</b></div><div><b><span class="" style="white-space:pre">                </span>.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),</b></div><div><b><span class="" style="white-space:pre">                </span>.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |</b></div><div><b><span class="" style="white-space:pre">                </span>BIT(IIO_CHAN_INFO_SCALE) |</b></div><div><b><span class="" style="white-space:pre">                </span>BIT(IIO_CHAN_INFO_SAMP_FREQ) |</b></div><div><b><span class="" style="white-space:pre">                </span>BIT(IIO_CHAN_INFO_HYSTERESIS),</b></div><div><b><span class="" style="white-space:pre">                </span>.scan_index = CHANNEL_CUSTOM_VALUE_2,</b></div><div><b><span class="" style="white-space:pre">        </span>},</b></div><div><b><span class="" style="white-space:pre">        </span>{</b></div><div><b><span class="" style="white-space:pre">                </span>.type = IIO_ACCEL,</b></div><div><b><span class="" style="white-space:pre">                </span>.modified = 1,</b></div><div><b><span class="" style="white-space:pre">                </span>.channel2 = IIO_MOD_X,</b></div><div><b><span class="" style="white-space:pre">                </span>.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),</b></div><div><b><span class="" style="white-space:pre">                </span>.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |</b></div><div><b><span class="" style="white-space:pre">                </span>BIT(IIO_CHAN_INFO_SCALE) |</b></div><div><b><span class="" style="white-space:pre">                </span>BIT(IIO_CHAN_INFO_SAMP_FREQ) |</b></div><div><b><span class="" style="white-space:pre">                </span>BIT(IIO_CHAN_INFO_HYSTERESIS),</b></div><div><b><span class="" style="white-space:pre">                </span>.scan_index = CHANNEL_CUSTOM_VALUE_3,</b></div><div><b><span class="" style="white-space:pre">        </span>},</b></div><div><b><span class="" style="white-space:pre">        </span>{</b></div><div><b><span class="" style="white-space:pre">                </span>.type = IIO_ACCEL,</b></div><div><b><span class="" style="white-space:pre">                </span>.modified = 1,</b></div><div><b><span class="" style="white-space:pre">                </span>.channel2 = IIO_MOD_X,</b></div><div><b><span class="" style="white-space:pre">                </span>.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),</b></div><div><b><span class="" style="white-space:pre">                </span>.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |</b></div><div><b><span class="" style="white-space:pre">                </span>BIT(IIO_CHAN_INFO_SCALE) |</b></div><div><b><span class="" style="white-space:pre">                </span>BIT(IIO_CHAN_INFO_SAMP_FREQ) |</b></div><div><b><span class="" style="white-space:pre">                </span>BIT(IIO_CHAN_INFO_HYSTERESIS),</b></div><div><b><span class="" style="white-space:pre">                </span>.scan_index = CHANNEL_CUSTOM_VALUE_4,</b></div><div><b><span class="" style="white-space:pre">        </span>}</b></div></div><div><b><br></b></div><div><b><br></b></div><div><b><br></b></div><div><div style>/* Capture samples in local storage */</div><div style>static int accel_3d_capture_sample(struct hid_sensor_hub_device *hsdev,</div><div style><span class="" style="white-space:pre">                                </span>unsigned usage_id,</div><div style><span class="" style="white-space:pre">                                </span>size_t raw_len, char *raw_data,</div><div style><span class="" style="white-space:pre">                                </span>void *priv)</div><div style>{</div><div style><span class="" style="white-space:pre">        </span>struct iio_dev *indio_dev = platform_get_drvdata(priv);</div><div style><span class="" style="white-space:pre">        </span>struct accel_3d_state *accel_state = iio_priv(indio_dev);</div><div style><span class="" style="white-space:pre">        </span>int offset;</div><div style><span class="" style="white-space:pre">        </span>int ret = -EINVAL;</div><div style><br></div><div style><span class="" style="white-space:pre">        </span>switch (usage_id) {</div><div style><span class="" style="white-space:pre">        </span>case HID_USAGE_SENSOR_ACCEL_X_AXIS:</div><div style><span class="" style="white-space:pre">        </span>case HID_USAGE_SENSOR_ACCEL_Y_AXIS:</div><div style><span class="" style="white-space:pre">        </span>case HID_USAGE_SENSOR_ACCEL_Z_AXIS:</div><div style><b><span class="" style="white-space:pre">        </span>case HID_USAGE_SENSOR_DATA_MOTION_STATE:</b></div><div style><b>        case HID_USAGE_SENSOR_DATA_CUSTOM_VALUE2:</b></div><div style><b> <span class="" style="white-space:pre">        </span>case HID_USAGE_SENSOR_DATA_CUSTOM_VALUE3:</b></div><div style><b> <span class="" style="white-space:pre">        </span>case HID_USAGE_SENSOR_DATA_CUSTOM_VALUE4:</b></div><div style><span class="" style="white-space:pre">                </span>offset = usage_id - HID_USAGE_SENSOR_ACCEL_X_AXIS;</div><div style="font-weight:bold"><br></div></div><div><b><br></b></div><div><br></div><div><div>/* Parse report which is specific to an usage id*/</div><div>static int accel_3d_parse_report(struct platform_device *pdev,</div><div><span class="" style="white-space:pre">                                </span>struct hid_sensor_hub_device *hsdev,</div><div><span class="" style="white-space:pre">                                </span>struct iio_chan_spec *channels,</div><div><span class="" style="white-space:pre">                                </span>unsigned usage_id,</div><div><span class="" style="white-space:pre">                                </span>struct accel_3d_state *st)</div><div>{</div><div><span class="" style="white-space:pre">        </span>int ret;</div><div><span class="" style="white-space:pre">        </span>int i;</div><div><br></div><div><span class="" style="white-space:pre">        </span><b>for (i = 0; i &lt;= CHANNEL_CUSTOM_VALUE_4; ++i) {  //previously &lt; CHANNEL_SCAN_INDEX_Z</b></div><div><span class="" style="white-space:pre">                </span>ret = sensor_hub_input_get_attribute_info(hsdev,</div><div><br></div></div><div><br></div><div><br></div><div>After build /insmod i get the following dmesg : </div><div><br></div><div><b>hid_sensor_accel_3d:HID-SENSOR-200073.3 auto : failed to setup attributes</b></div><div><b>hid_sensor_accel_3d:HID-SENSOR-200073.3 auto.failed with error -1</b><br></div><div><br></div><div><br></div><div>I am not getting what else I have to modify to avoid this error .If i remove the portion in bold(and use this original code :<a href="http://lxr.free-electrons.com/source/drivers/iio/accel/hid-sensor-accel-3d.c">http://lxr.free-electrons.com/source/drivers/iio/accel/hid-sensor-accel-3d.c</a>) I can happily insert the module without any error and can interact with the driver using my application.</div><div><br></div></div>