/*-1* Copyright (c) 2016 Adrian Chadd <[email protected]>.2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer,9* without modification.10* 2. Redistributions in binary form must reproduce at minimum a disclaimer11* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any12* redistribution must be conditioned upon including a substantially13* similar Disclaimer requirement for further binary redistribution.14*15* NO WARRANTY16* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY19* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL20* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,21* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF22* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS23* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER24* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)25* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF26* THE POSSIBILITY OF SUCH DAMAGES.27*/28#ifndef __IF_BWN_UTIL_H__29#define __IF_BWN_UTIL_H__3031/* Hamming weight; used in the PHY routines */32static inline int33bwn_hweight32(uint32_t val)34{35int i, r = 0;36/* yes, could do it without a loop.. */37for (i = 0; i < 32; i++) {38r = r + (val & 1);39val = val >> 1;40}41return r;42}4344/* Clamp value; PHY code */45static inline int46bwn_clamp_val(int val, int lo, int hi)47{48if (val < lo)49return lo;50if (val > hi)51return hi;52return val;53}5455/* Q52 format - used in PHY routines */56#define INT_TO_Q52(i) ((i) << 2)57#define Q52_TO_INT(q52) ((q52) >> 2)58#define Q52_FMT "%u.%u"59#define Q52_ARG(q52) Q52_TO_INT(q52), ((((q52) & 0x3) * 100) / 4)6061extern unsigned int bwn_sqrt(struct bwn_mac *mac, unsigned int x);6263#endif /* __IF_BWN_UTIL_H__ */646566