<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 - &quot;failed to setup attributes&quot; 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 &lt;= 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>&amp;st-&gt;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-&gt;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>&amp;st-&gt;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-&gt;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 &lt;= 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>&amp;st-&gt;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-&gt;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">&lt;<a href="mailto:daniel.baluta@gmail.com" target="_blank">daniel.baluta@gmail.com</a>&gt;</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 &lt;<a href="mailto:imsaurabhrawat@gmail.com">imsaurabhrawat@gmail.com</a>&gt; wrote:<br>
&gt; I have modified the hid-sensor-accel_3d.c driver to add the custom fields -<br>
&gt; CHANNEL_SCAN_DATA_MOTION and HID_USAGE_SENSOR_DATA_CUSTOM_VALUEX ( X =<br>
&gt; 2,3,4).<br>
&gt; Below are my modifications :<br>
&gt;<br>
&gt; enum accel_3d_channel {<br>
&gt; CHANNEL_SCAN_INDEX_X,<br>
&gt; CHANNEL_SCAN_INDEX_Y,<br>
&gt; CHANNEL_SCAN_INDEX_Z,<br>
&gt; CHANNEL_SCAN_DATA_MOTION,<br>
&gt; CHANNEL_CUSTOM_VALUE_2,<br>
&gt; CHANNEL_CUSTOM_VALUE_3,<br>
&gt;         CHANNEL_CUSTOM_VALUE_4,<br>
&gt; ACCEL_3D_CHANNEL_MAX,<br>
&gt;<br>
&gt; static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = {<br>
&gt; HID_USAGE_SENSOR_ACCEL_X_AXIS,<br>
&gt; HID_USAGE_SENSOR_ACCEL_Y_AXIS,<br>
&gt; HID_USAGE_SENSOR_ACCEL_Z_AXIS,<br>
&gt; HID_USAGE_SENSOR_DATA_MOTION_STATE,<br>
&gt; HID_USAGE_SENSOR_DATA_CUSTOM_VALUE2,<br>
&gt; HID_USAGE_SENSOR_DATA_CUSTOM_VALUE3,<br>
&gt; HID_USAGE_SENSOR_DATA_CUSTOM_VALUE4<br>
&gt; };<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; /* Channel definitions */<br>
&gt; static const struct iio_chan_spec accel_3d_channels[] = {<br>
&gt; {<br>
&gt; ..<br>
&gt; ..<br>
&gt; ..<br>
&gt; {<br>
&gt; .type = IIO_ACCEL,<br>
&gt; .modified = 1,<br>
&gt; .channel2 = IIO_MOD_X,<br>
&gt; .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),<br>
&gt; .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |<br>
&gt; BIT(IIO_CHAN_INFO_SCALE) |<br>
&gt; BIT(IIO_CHAN_INFO_SAMP_FREQ) |<br>
&gt; BIT(IIO_CHAN_INFO_HYSTERESIS),<br>
&gt; .scan_index = CHANNEL_SCAN_DATA_MOTION,<br>
&gt; },<br>
&gt; {<br>
&gt; .type = IIO_ACCEL,<br>
&gt; .modified = 1,<br>
&gt; .channel2 = IIO_MOD_X,<br>
&gt; .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),<br>
&gt; .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |<br>
&gt; BIT(IIO_CHAN_INFO_SCALE) |<br>
&gt; BIT(IIO_CHAN_INFO_SAMP_FREQ) |<br>
&gt; BIT(IIO_CHAN_INFO_HYSTERESIS),<br>
&gt; .scan_index = CHANNEL_CUSTOM_VALUE_2,<br>
&gt; },<br>
&gt; {<br>
&gt; .type = IIO_ACCEL,<br>
&gt; .modified = 1,<br>
&gt; .channel2 = IIO_MOD_X,<br>
&gt; .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),<br>
&gt; .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |<br>
&gt; BIT(IIO_CHAN_INFO_SCALE) |<br>
&gt; BIT(IIO_CHAN_INFO_SAMP_FREQ) |<br>
&gt; BIT(IIO_CHAN_INFO_HYSTERESIS),<br>
&gt; .scan_index = CHANNEL_CUSTOM_VALUE_3,<br>
&gt; },<br>
&gt; {<br>
&gt; .type = IIO_ACCEL,<br>
&gt; .modified = 1,<br>
&gt; .channel2 = IIO_MOD_X,<br>
&gt; .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),<br>
&gt; .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |<br>
&gt; BIT(IIO_CHAN_INFO_SCALE) |<br>
&gt; BIT(IIO_CHAN_INFO_SAMP_FREQ) |<br>
&gt; BIT(IIO_CHAN_INFO_HYSTERESIS),<br>
&gt; .scan_index = CHANNEL_CUSTOM_VALUE_4,<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; /* Capture samples in local storage */<br>
&gt; static int accel_3d_capture_sample(struct hid_sensor_hub_device *hsdev,<br>
&gt; unsigned usage_id,<br>
&gt; size_t raw_len, char *raw_data,<br>
&gt; void *priv)<br>
&gt; {<br>
&gt; struct iio_dev *indio_dev = platform_get_drvdata(priv);<br>
&gt; struct accel_3d_state *accel_state = iio_priv(indio_dev);<br>
&gt; int offset;<br>
&gt; int ret = -EINVAL;<br>
&gt;<br>
&gt; switch (usage_id) {<br>
&gt; case HID_USAGE_SENSOR_ACCEL_X_AXIS:<br>
&gt; case HID_USAGE_SENSOR_ACCEL_Y_AXIS:<br>
&gt; case HID_USAGE_SENSOR_ACCEL_Z_AXIS:<br>
&gt; case HID_USAGE_SENSOR_DATA_MOTION_STATE:<br>
&gt;         case HID_USAGE_SENSOR_DATA_CUSTOM_VALUE2:<br>
&gt;   case HID_USAGE_SENSOR_DATA_CUSTOM_VALUE3:<br>
&gt;   case HID_USAGE_SENSOR_DATA_CUSTOM_VALUE4:<br>
&gt; offset = usage_id - HID_USAGE_SENSOR_ACCEL_X_AXIS;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; /* Parse report which is specific to an usage id*/<br>
&gt; static int accel_3d_parse_report(struct platform_device *pdev,<br>
&gt; struct hid_sensor_hub_device *hsdev,<br>
&gt; struct iio_chan_spec *channels,<br>
&gt; unsigned usage_id,<br>
&gt; struct accel_3d_state *st)<br>
&gt; {<br>
&gt; int ret;<br>
&gt; int i;<br>
&gt;<br>
&gt; for (i = 0; i &lt;= CHANNEL_CUSTOM_VALUE_4; ++i) {  //previously &lt;<br>
&gt; CHANNEL_SCAN_INDEX_Z<br>
&gt; ret = sensor_hub_input_get_attribute_info(hsdev,<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; After build /insmod i get the following dmesg :<br>
&gt;<br>
&gt; hid_sensor_accel_3d:HID-SENSOR-200073.3 auto : failed to setup attributes<br>
&gt; hid_sensor_accel_3d:HID-SENSOR-200073.3 auto.failed with error -1<br>
&gt;<br>
&gt;<br>
&gt; I am not getting what else I have to modify to avoid this error .If i remove<br>
&gt; the portion in bold(and use this original code<br>
&gt; :<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>
&gt; I can happily insert the module without any error and can interact with the<br>
&gt; driver using my application.<br>
&gt;<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; Kernelnewbies mailing list<br>
&gt; <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
&gt; <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
&gt;<br>
</blockquote></div><br></div></div>