<div dir="ltr"><div><br></div><div>Hi,</div><div><br></div><div>I recently found my dongle with the FC0012 again after having lost it for a couple of years, and noticed the tuner wasn't detecting on recent builds (by recent, it looks like at least a year and a half ago. :) )</div><div><br></div><div>There were a few other posts around that I saw with the same issue so I dug into the problem a bit.  It looks it was a behavioural regression in commit ba64a7459a43652354990855176a7d8dad5b9d54 </div><div>which was a actually bugfix in the GPIO direction setting code (see below for the commit comment).   The bugfix patch references <a href="http://lea.hamradio.si/~s57uuu/mischam/rtlsdr/ports.html">http://lea.hamradio.si/~s57uuu/mischam/rtlsdr/ports.html</a> which </div><div><br></div><div>The reason this regressed the FC0012 tuner support is that in tuner detection code, before the probe for the FC00012 there are a few lines:</div><div><br></div><div>        /* initialise GPIOs */</div><div>        rtlsdr_set_gpio_output(dev, 5);</div><div><br></div><div>        /* reset tuner before probing */</div><div>        rtlsdr_set_gpio_bit(dev, 5, 1);</div><div>        rtlsdr_set_gpio_bit(dev, 5, 0);</div><div><br></div><div>Looking at one of the early (ugly) patches I wrote trying to get the FC0012 working, This is the original code before cleaned up: <a href="https://gist.github.com/dbasden/2171926#file-rtlsdr-fc0012-diff-L123">https://gist.github.com/dbasden/2171926#file-rtlsdr-fc0012-diff-L123</a>  :</div><div><br></div><div>+<span style="white-space:pre">        </span>if (tuner_type == TUNER_FC0012) {</div><div>+<span style="white-space:pre">            </span>dump_rtl_regs();</div><div>+<span style="white-space:pre">             </span>DEBUGF("reset fs0012 tuner... ");</div><div>+<span style="white-space:pre">          </span>/* the fs0012 has it's RESET line hooked up to GPIO5</div><div>+<span style="white-space:pre">             </span> *</div><div>+<span style="white-space:pre">           </span> * If we don't set GPIO5 to an output and leave it floating,</div><div>+<span style="white-space:pre">             </span> * the tuner never comes up (just stays in RESET state)</div><div>+<span style="white-space:pre">              </span> *</div><div>+<span style="white-space:pre">           </span> * GPIO6 controls the V/U band filter, so we should set that</div><div>+<span style="white-space:pre">         </span> * to an output too</div><div>+<span style="white-space:pre">          </span> */ </div><div>+<span style="white-space:pre">                </span>r = rtl_read_reg(SYSB, GPD, 1);</div><div>+<span style="white-space:pre">              </span>r &= (~(0x30)); rtl_write_reg(SYSB, GPO, r, 1);</div><div>+<span style="white-space:pre">          </span>r = rtl_read_reg(SYSB, GPOE, 1);</div><div>+<span style="white-space:pre">             </span>r |= 0x30; rtl_write_reg(SYSB, GPOE, r, 1);</div><div>+</div><div>+<span style="white-space:pre">          </span>/* Do reset */</div><div>+<span style="white-space:pre">               </span>rtl_set_gpio_bit(5,1);</div><div>+<span style="white-space:pre">               </span>rtl_set_gpio_bit(5,0);</div><div>+<span style="white-space:pre">               </span>dump_rtl_regs();</div><div>+<span style="white-space:pre">     </span>}</div><div><br></div><div>This code was eventually abstracted out to The bug in the code above described in <a href="http://lea.hamradio.si/~s57uuu/mischam/rtlsdr/ports.html">http://lea.hamradio.si/~s57uuu/mischam/rtlsdr/ports.html</a>, linked to in the commit log of the ba64a7459a43652354990855176a7d8dad5b9d54 fixing the same bug.</div><div><br></div><div>The code was cleaned up eventually abstracted into rtl_sdr_set_output(), which had the same typo as my original code: I wrote back the GPD register to GPO.   This accidentally worked enough to fix the specific case I was wanting (to stop the RESET line of the FC0012 floating), but didn't actually write to the GPIO direction register.</div><div><br></div><div>Looking at some of the forum posts, and checking myself,  if the older code runs once, the tuner will be just fine until the dongle loses power.  Then as GPIO5 is not set up into a state for the FC0012 to be happy, it will not come up again.   This seems to have made the problem harder to debug (I don't know if I would have not known where to look if I had not already hit the problem when originally porting the driver)</div><div><br></div><div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><br class="gmail-Apple-interchange-newline">Digging through some more just now (I really don't have a great dev environment right now, and nothing to probe the hardware itself easily available), I checked the state of GPD, GPO and GPOE before the tuner probing, at it looks like the only real side effect from the code above being buggy would be to set bit 1<<4 low.   calling rtl_set_gpio_bit(4,0) brought up the FC0012 tuner. Re-reading the old and new code, it looks like it's an off-by-one error in GPIO numbering:</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"> * The original code set GPOE on 0x30,  which is (1<<4) | (1<<5).</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"> * These are referred to in the code above as "GPIO5" as the FC0012 RESET line and</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial">   "GPIO6" as the V/U band filter control.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"> * <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">rtlsdr_set_gpio_output(5) and </span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">rtl_set_gpio_bit</span>(5,0) are switching the V/U band filter, not the RESET line for the FC0012</div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial">Sorry, I don't have access to the datasheet for the RTL, so I'm not sure if bit 0 is GPIO0 or GPIO1.  In any case, it looks like the solution is to just fix the off-by-one error in the FC0012 probe code.  I'll post a patch.</div><div><br></div><div>Thanks,</div><div><br></div><div>David</div><div><br></div><div><br></div><div>(commit for bugfix where fc0012 tuner regressed.)</div><div><br></div><div> </div><div>commit ba64a7459a43652354990855176a7d8dad5b9d54</div><div>Author: Lucas Teske <<a href="mailto:lucas@teske.net.br">lucas@teske.net.br</a>></div><div>Date:   Wed Aug 17 20:31:33 2016 -0300</div><div><br></div><div>    lib: fix direction bit in GPIO code</div><div><br></div><div>    source: <a href="http://lea.hamradio.si/~s57uuu/mischam/rtlsdr/ports.html">http://lea.hamradio.si/~s57uuu/mischam/rtlsdr/ports.html</a></div><div><br></div><div>    * Removed unnecessary comment of old code.</div><div>    Signed-off-by: Fabian P. Schmidt <<a href="mailto:kerel-fs@gmx.de">kerel-fs@gmx.de</a>></div><div>    Signed-off-by: Steve Markgraf <<a href="mailto:steve@steve-m.de">steve@steve-m.de</a>></div><div><br></div><div>:040000 040000 12c5ea73db04c45699d7befa2c5916ae074a1999 2d08166fe31338f5ff90186272b40bc6ed3254fa M<span style="white-space:pre">    </span>src</div><div>(HEAD) davidb@grey:~/Personal/sdr/rtl-sdr$</div></div>