<div dir="ltr">Do I need to define the all the Usage Tags in the input report of a sensor to retrieve minimum any one field or Only a Usage Tag which I wanted to retrieve is enough.<div>e.g for an input report of an accelerometer which has the below fields(added new one in Bold),</div><div><br></div><div>HID_USAGE_SENSOR_ACCEL_X_AXIS<br></div><div>HID_USAGE_SENSOR_ACCEL_Y_AXIS<br></div><div>HID_USAGE_SENSOR_ACCEL_Z_AXIS<br></div><div><div><b>HID_USAGE_SENSOR_DATA_MOTION_STATE,</b></div><div><b>HID_USAGE_SENSOR_DATA_CUSTOM_VALUE_2</b></div><div><b>HID_USAGE_SENSOR_DATA_CUSTOM_VALUE_3</b></div></div><div><b>HID_USAGE_SENSOR_DATA_CUSTOM_VALUE_4</b></div><div><br></div><div> I want to retrieve Custom_Value_4 do I also need to define parameters for Data_Motion_state, Custom_Value2,Custom_Value3 as well apart from Custom_Value4 in the below structure.</div><div><br></div><div><div>enum accel_3d_channel {.. }</div></div><div>struct accel_3d_state {.. }<br></div><div>static const struct iio_chan_spec accel_3d_channels[] = { ..}<br></div><div><br></div><div>I did so but was getting error - "failed to setup attributes" but after I modified the code in the function : accel_3d_parse_report() like below to accommodate all the non Contigous Usage Tags and associated them with their channels - *_SCAN_INDEX_* . I did not get this error but some other error (listed at the end of the mail)</div><div><br></div><div><br></div><div>//First Three channel X,Y and Z whose Usage Tags are contionus - 0x200453/54/55</div><div><div>for (i = 0; i <= CHANNEL_SCAN_INDEX_Z; ++i) {</div><div> </div><div><span class="" style="white-space:pre">                                </span>ret = sensor_hub_input_get_attribute_info(hsdev,</div><div><span class="" style="white-space:pre">                                </span>HID_INPUT_REPORT,</div><div><span class="" style="white-space:pre">                                </span>usage_id,</div><div><span class="" style="white-space:pre">                                </span>HID_USAGE_SENSOR_ACCEL_X_AXIS + i,</div><div><span class="" style="white-space:pre">                                </span>&st->accel[CHANNEL_SCAN_INDEX_X + i]); </div><div><span class="" style="white-space:pre">                </span></div><div> <span class="" style="white-space:pre">        </span>accel_3d_adjust_channel_bit_mask(channels,</div><div><span class="" style="white-space:pre">                                </span>CHANNEL_SCAN_INDEX_X + i,</div><div><span class="" style="white-space:pre">                                </span>st->accel[CHANNEL_SCAN_INDEX_X + i].size);</div><div><span class="" style="white-space:pre">        </span>}</div><div><br></div><div>//Fourth channel For Data Motion - 0x200451<br></div><div><span class="" style="white-space:pre">        </span>ret = sensor_hub_input_get_attribute_info(hsdev,</div><div><span class="" style="white-space:pre">                                </span>HID_INPUT_REPORT,</div><div><span class="" style="white-space:pre">                                </span>usage_id,</div><div><span class="" style="white-space:pre">                                </span>HID_USAGE_SENSOR_DATA_MOTION_STATE, // For CHANNEL_SCAN_DATA_MOTION</div><div><span class="" style="white-space:pre">                                </span>&st->accel[CHANNEL_SCAN_INDEX_X + i]);</div><div><span class="" style="white-space:pre">        </span></div><div><span class="" style="white-space:pre">                </span>accel_3d_adjust_channel_bit_mask(channels,</div><div><span class="" style="white-space:pre">                                </span>CHANNEL_SCAN_INDEX_X + i,</div><div><span class="" style="white-space:pre">                                </span>st->accel[CHANNEL_SCAN_INDEX_X + i].size);</div><div><br></div><div>//Last Three Channel for Custom Value 2,3,4 - 0x200545/46/47<br></div><div><span class="" style="white-space:pre">        </span>for (i = 0; i <= 2; ++i) {</div><div><br></div><div><span class="" style="white-space:pre">                                </span>ret = sensor_hub_input_get_attribute_info(hsdev,</div><div><span class="" style="white-space:pre">                                </span>HID_INPUT_REPORT,</div><div><span class="" style="white-space:pre">                                </span>usage_id,</div><div><span class="" style="white-space:pre">                                </span>HID_USAGE_SENSOR_DATA_CUSTOM_VALUE_2 + i,</div><div><span class="" style="white-space:pre">                                </span>&st->accel[CHANNEL_SCAN_INDEX_X + i + 4]); //start after CHANNEL_SCAN_DATA_MOTION Channel</div><div><span class="" style="white-space:pre">                </span></div><div><span class="" style="white-space:pre">                </span>accel_3d_adjust_channel_bit_mask(channels,</div><div><span class="" style="white-space:pre">                                </span>CHANNEL_SCAN_INDEX_X + i + 4,</div><div><span class="" style="white-space:pre">                                </span>st->accel[CHANNEL_SCAN_INDEX_X + i].size);</div><div><span class="" style="white-space:pre">        </span>}</div></div><div><br></div><div><br></div><div><br></div><div>But now I am getting a different error : </div><div><br></div><div><div>[13778.127716] iio iio:device4: tried to double register : in_accel_x_index</div><div>[13778.127899] hid_sensor_accel_3d HID-SENSOR-200073.3.auto: failed to initialize trigger buffer</div><div>[13778.143676] hid_sensor_accel_3d: probe of HID-SENSOR-200073.3.auto failed with error -16</div></div><div><br></div><div>I am still figuring out where else Do I have to modify the code in order to receive the above custom values ..</div><div>Thanks,</div><div>S</div><div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 26, 2015 at 6:54 PM, Daniel Baluta <span dir="ltr"><<a href="mailto:daniel.baluta@gmail.com" target="_blank">daniel.baluta@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">+ linux-iio list.<br>
<div><div class="h5"><br>
On Thu, Feb 26, 2015 at 8:04 AM, s.rawat <<a href="mailto:imsaurabhrawat@gmail.com">imsaurabhrawat@gmail.com</a>> wrote:<br>
> I have modified the hid-sensor-accel_3d.c driver to add the custom fields -<br>
> CHANNEL_SCAN_DATA_MOTION and HID_USAGE_SENSOR_DATA_CUSTOM_VALUEX ( X =<br>
> 2,3,4).<br>
> Below are my modifications :<br>
><br>
> enum accel_3d_channel {<br>
> CHANNEL_SCAN_INDEX_X,<br>
> CHANNEL_SCAN_INDEX_Y,<br>
> CHANNEL_SCAN_INDEX_Z,<br>
> CHANNEL_SCAN_DATA_MOTION,<br>
> CHANNEL_CUSTOM_VALUE_2,<br>
> CHANNEL_CUSTOM_VALUE_3,<br>
> CHANNEL_CUSTOM_VALUE_4,<br>
> ACCEL_3D_CHANNEL_MAX,<br>
><br>
> static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = {<br>
> HID_USAGE_SENSOR_ACCEL_X_AXIS,<br>
> HID_USAGE_SENSOR_ACCEL_Y_AXIS,<br>
> HID_USAGE_SENSOR_ACCEL_Z_AXIS,<br>
> HID_USAGE_SENSOR_DATA_MOTION_STATE,<br>
> HID_USAGE_SENSOR_DATA_CUSTOM_VALUE2,<br>
> HID_USAGE_SENSOR_DATA_CUSTOM_VALUE3,<br>
> HID_USAGE_SENSOR_DATA_CUSTOM_VALUE4<br>
> };<br>
><br>
><br>
><br>
> /* Channel definitions */<br>
> static const struct iio_chan_spec accel_3d_channels[] = {<br>
> {<br>
> ..<br>
> ..<br>
> ..<br>
> {<br>
> .type = IIO_ACCEL,<br>
> .modified = 1,<br>
> .channel2 = IIO_MOD_X,<br>
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),<br>
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |<br>
> BIT(IIO_CHAN_INFO_SCALE) |<br>
> BIT(IIO_CHAN_INFO_SAMP_FREQ) |<br>
> BIT(IIO_CHAN_INFO_HYSTERESIS),<br>
> .scan_index = CHANNEL_SCAN_DATA_MOTION,<br>
> },<br>
> {<br>
> .type = IIO_ACCEL,<br>
> .modified = 1,<br>
> .channel2 = IIO_MOD_X,<br>
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),<br>
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |<br>
> BIT(IIO_CHAN_INFO_SCALE) |<br>
> BIT(IIO_CHAN_INFO_SAMP_FREQ) |<br>
> BIT(IIO_CHAN_INFO_HYSTERESIS),<br>
> .scan_index = CHANNEL_CUSTOM_VALUE_2,<br>
> },<br>
> {<br>
> .type = IIO_ACCEL,<br>
> .modified = 1,<br>
> .channel2 = IIO_MOD_X,<br>
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),<br>
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |<br>
> BIT(IIO_CHAN_INFO_SCALE) |<br>
> BIT(IIO_CHAN_INFO_SAMP_FREQ) |<br>
> BIT(IIO_CHAN_INFO_HYSTERESIS),<br>
> .scan_index = CHANNEL_CUSTOM_VALUE_3,<br>
> },<br>
> {<br>
> .type = IIO_ACCEL,<br>
> .modified = 1,<br>
> .channel2 = IIO_MOD_X,<br>
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),<br>
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |<br>
> BIT(IIO_CHAN_INFO_SCALE) |<br>
> BIT(IIO_CHAN_INFO_SAMP_FREQ) |<br>
> BIT(IIO_CHAN_INFO_HYSTERESIS),<br>
> .scan_index = CHANNEL_CUSTOM_VALUE_4,<br>
> }<br>
><br>
><br>
><br>
> /* Capture samples in local storage */<br>
> static int accel_3d_capture_sample(struct hid_sensor_hub_device *hsdev,<br>
> unsigned usage_id,<br>
> size_t raw_len, char *raw_data,<br>
> void *priv)<br>
> {<br>
> struct iio_dev *indio_dev = platform_get_drvdata(priv);<br>
> struct accel_3d_state *accel_state = iio_priv(indio_dev);<br>
> int offset;<br>
> int ret = -EINVAL;<br>
><br>
> switch (usage_id) {<br>
> case HID_USAGE_SENSOR_ACCEL_X_AXIS:<br>
> case HID_USAGE_SENSOR_ACCEL_Y_AXIS:<br>
> case HID_USAGE_SENSOR_ACCEL_Z_AXIS:<br>
> case HID_USAGE_SENSOR_DATA_MOTION_STATE:<br>
> case HID_USAGE_SENSOR_DATA_CUSTOM_VALUE2:<br>
> case HID_USAGE_SENSOR_DATA_CUSTOM_VALUE3:<br>
> case HID_USAGE_SENSOR_DATA_CUSTOM_VALUE4:<br>
> offset = usage_id - HID_USAGE_SENSOR_ACCEL_X_AXIS;<br>
><br>
><br>
><br>
> /* Parse report which is specific to an usage id*/<br>
> static int accel_3d_parse_report(struct platform_device *pdev,<br>
> struct hid_sensor_hub_device *hsdev,<br>
> struct iio_chan_spec *channels,<br>
> unsigned usage_id,<br>
> struct accel_3d_state *st)<br>
> {<br>
> int ret;<br>
> int i;<br>
><br>
> for (i = 0; i <= CHANNEL_CUSTOM_VALUE_4; ++i) { //previously <<br>
> CHANNEL_SCAN_INDEX_Z<br>
> ret = sensor_hub_input_get_attribute_info(hsdev,<br>
><br>
><br>
><br>
> After build /insmod i get the following dmesg :<br>
><br>
> hid_sensor_accel_3d:HID-SENSOR-200073.3 auto : failed to setup attributes<br>
> hid_sensor_accel_3d:HID-SENSOR-200073.3 auto.failed with error -1<br>
><br>
><br>
> I am not getting what else I have to modify to avoid this error .If i remove<br>
> the portion in bold(and use this original code<br>
> :<a href="http://lxr.free-electrons.com/source/drivers/iio/accel/hid-sensor-accel-3d.c" target="_blank">http://lxr.free-electrons.com/source/drivers/iio/accel/hid-sensor-accel-3d.c</a>)<br>
> I can happily insert the module without any error and can interact with the<br>
> driver using my application.<br>
><br>
><br>
</div></div>> _______________________________________________<br>
> Kernelnewbies mailing list<br>
> <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
><br>
</blockquote></div><br></div></div>