[alsa-devel] [PATCH] ASoC: nau8825: jack connection decision with different insertion logic

John Hsu KCHSU0 at nuvoton.com
Thu Jun 30 09:51:51 CEST 2016


Hi
On 6/29/2016 11:45 AM, Anatol Pomozov wrote:
> Hi
>
> On Tue, Jun 28, 2016 at 8:20 PM, John Hsu <KCHSU0 at nuvoton.com> wrote:
>   
>> The original design only covers the jack insertion logic is active low.
>> Add more condition to cover no matter the logic is active low and high.
>>
>> Signed-off-by: John Hsu <KCHSU0 at nuvoton.com>
>> ---
>>  sound/soc/codecs/nau8825.c | 12 ++++++++++--
>>  1 file changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/sound/soc/codecs/nau8825.c b/sound/soc/codecs/nau8825.c
>> index 3f30e6e..a2f0d03 100644
>> --- a/sound/soc/codecs/nau8825.c
>> +++ b/sound/soc/codecs/nau8825.c
>> @@ -1345,10 +1345,18 @@ EXPORT_SYMBOL_GPL(nau8825_enable_jack_detect);
>>
>>  static bool nau8825_is_jack_inserted(struct regmap *regmap)
>>  {
>> -       int status;
>> +       int status, jkdet, res;
>>
>>         regmap_read(regmap, NAU8825_REG_I2C_DEVICE_ID, &status);
>> -       return !(status & NAU8825_GPIO2JD1);
>> +       regmap_read(regmap, NAU8825_REG_JACK_DET_CTRL, &jkdet);
>> +
>> +       /* return jack connection status according to jack insertion logic
>> +        * active high or active low.
>> +        */
>> +       res = !(status & NAU8825_GPIO2JD1) * !(jkdet & NAU8825_JACK_POLARITY) +
>> +               (status & NAU8825_GPIO2JD1) * (jkdet & NAU8825_JACK_POLARITY);
>>     
>
> It makes more sense to use a more boolean-like expression. Something like
>
>       return !!(status & NAU8825_GPIO2JD1) == !!(jkdet & NAU8825_JACK_POLARITY);
> (hope I translated expression above correctly)
>
> or even better to introduce readable bool flags:
>       bool active_high = !!(jkdet & NAU8825_JACK_POLARITY);
>       bool is_high = !!(status & NAU8825_GPIO2JD1);
>       return active_high == is_high;
>
>   

Yes, it'll be more readable. I have a question. Why to add !! in
front of bit wise operation? What does it mean?



More information about the Alsa-devel mailing list