aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorAlwin Beukers <alwin@broadcom.com>2011-10-12 14:51:26 -0400
committerJohn W. Linville <linville@tuxdriver.com>2011-10-14 14:48:19 -0400
commitef6ac17a20a424fdfb049ae475d62b92c192d1bc (patch)
tree72d66b705f1b16d8a8af65638b88e14200342ded /drivers/net
parentf53b170f465d52546c33faa962c3d2609a6bf5b3 (diff)
brcm80211: moved power conversion functions
Moved brcmu_mw_to_qdbm and brcmu_qdbm_to_mw functions into the only file using them. Names were adjusted accordingly. Reported-by: Johannes Berg <johannes@sipsolutions.net> Reviewed-by: Roland Vossen <rvossen@broadcom.com> Reviewed-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c88
-rw-r--r--drivers/net/wireless/brcm80211/brcmutil/utils.c86
-rw-r--r--drivers/net/wireless/brcm80211/include/brcmu_utils.h4
3 files changed, 86 insertions, 92 deletions
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
index 27a748e55036..db9176d2d86a 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
@@ -247,6 +247,90 @@ static const u32 __wl_cipher_suites[] = {
247 WLAN_CIPHER_SUITE_AES_CMAC, 247 WLAN_CIPHER_SUITE_AES_CMAC,
248}; 248};
249 249
250/* Quarter dBm units to mW
251 * Table starts at QDBM_OFFSET, so the first entry is mW for qdBm=153
252 * Table is offset so the last entry is largest mW value that fits in
253 * a u16.
254 */
255
256#define QDBM_OFFSET 153 /* Offset for first entry */
257#define QDBM_TABLE_LEN 40 /* Table size */
258
259/* Smallest mW value that will round up to the first table entry, QDBM_OFFSET.
260 * Value is ( mW(QDBM_OFFSET - 1) + mW(QDBM_OFFSET) ) / 2
261 */
262#define QDBM_TABLE_LOW_BOUND 6493 /* Low bound */
263
264/* Largest mW value that will round down to the last table entry,
265 * QDBM_OFFSET + QDBM_TABLE_LEN-1.
266 * Value is ( mW(QDBM_OFFSET + QDBM_TABLE_LEN - 1) +
267 * mW(QDBM_OFFSET + QDBM_TABLE_LEN) ) / 2.
268 */
269#define QDBM_TABLE_HIGH_BOUND 64938 /* High bound */
270
271static const u16 nqdBm_to_mW_map[QDBM_TABLE_LEN] = {
272/* qdBm: +0 +1 +2 +3 +4 +5 +6 +7 */
273/* 153: */ 6683, 7079, 7499, 7943, 8414, 8913, 9441, 10000,
274/* 161: */ 10593, 11220, 11885, 12589, 13335, 14125, 14962, 15849,
275/* 169: */ 16788, 17783, 18836, 19953, 21135, 22387, 23714, 25119,
276/* 177: */ 26607, 28184, 29854, 31623, 33497, 35481, 37584, 39811,
277/* 185: */ 42170, 44668, 47315, 50119, 53088, 56234, 59566, 63096
278};
279
280static u16 brcmf_qdbm_to_mw(u8 qdbm)
281{
282 uint factor = 1;
283 int idx = qdbm - QDBM_OFFSET;
284
285 if (idx >= QDBM_TABLE_LEN)
286 /* clamp to max u16 mW value */
287 return 0xFFFF;
288
289 /* scale the qdBm index up to the range of the table 0-40
290 * where an offset of 40 qdBm equals a factor of 10 mW.
291 */
292 while (idx < 0) {
293 idx += 40;
294 factor *= 10;
295 }
296
297 /* return the mW value scaled down to the correct factor of 10,
298 * adding in factor/2 to get proper rounding.
299 */
300 return (nqdBm_to_mW_map[idx] + factor / 2) / factor;
301}
302
303static u8 brcmf_mw_to_qdbm(u16 mw)
304{
305 u8 qdbm;
306 int offset;
307 uint mw_uint = mw;
308 uint boundary;
309
310 /* handle boundary case */
311 if (mw_uint <= 1)
312 return 0;
313
314 offset = QDBM_OFFSET;
315
316 /* move mw into the range of the table */
317 while (mw_uint < QDBM_TABLE_LOW_BOUND) {
318 mw_uint *= 10;
319 offset -= 40;
320 }
321
322 for (qdbm = 0; qdbm < QDBM_TABLE_LEN - 1; qdbm++) {
323 boundary = nqdBm_to_mW_map[qdbm] + (nqdBm_to_mW_map[qdbm + 1] -
324 nqdBm_to_mW_map[qdbm]) / 2;
325 if (mw_uint < boundary)
326 break;
327 }
328
329 qdbm += (u8) offset;
330
331 return qdbm;
332}
333
250/* function for reading/writing a single u32 from/to the dongle */ 334/* function for reading/writing a single u32 from/to the dongle */
251static int 335static int
252brcmf_exec_dcmd_u32(struct net_device *ndev, u32 cmd, u32 *par) 336brcmf_exec_dcmd_u32(struct net_device *ndev, u32 cmd, u32 *par)
@@ -1380,7 +1464,7 @@ brcmf_cfg80211_set_tx_power(struct wiphy *wiphy,
1380 else 1464 else
1381 txpwrmw = (u16) dbm; 1465 txpwrmw = (u16) dbm;
1382 err = brcmf_dev_intvar_set(ndev, "qtxpower", 1466 err = brcmf_dev_intvar_set(ndev, "qtxpower",
1383 (s32) (brcmu_mw_to_qdbm(txpwrmw))); 1467 (s32) (brcmf_mw_to_qdbm(txpwrmw)));
1384 if (err) 1468 if (err)
1385 WL_ERR("qtxpower error (%d)\n", err); 1469 WL_ERR("qtxpower error (%d)\n", err);
1386 cfg_priv->conf->tx_power = dbm; 1470 cfg_priv->conf->tx_power = dbm;
@@ -1409,7 +1493,7 @@ static s32 brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, s32 *dbm)
1409 } 1493 }
1410 1494
1411 result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE); 1495 result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE);
1412 *dbm = (s32) brcmu_qdbm_to_mw(result); 1496 *dbm = (s32) brcmf_qdbm_to_mw(result);
1413 1497
1414done: 1498done:
1415 WL_TRACE("Exit\n"); 1499 WL_TRACE("Exit\n");
diff --git a/drivers/net/wireless/brcm80211/brcmutil/utils.c b/drivers/net/wireless/brcm80211/brcmutil/utils.c
index 0bb104f784fe..1851f93c9355 100644
--- a/drivers/net/wireless/brcm80211/brcmutil/utils.c
+++ b/drivers/net/wireless/brcm80211/brcmutil/utils.c
@@ -498,89 +498,3 @@ uint brcmu_mkiovar(char *name, char *data, uint datalen, char *buf, uint buflen)
498} 498}
499EXPORT_SYMBOL(brcmu_mkiovar); 499EXPORT_SYMBOL(brcmu_mkiovar);
500 500
501/* Quarter dBm units to mW
502 * Table starts at QDBM_OFFSET, so the first entry is mW for qdBm=153
503 * Table is offset so the last entry is largest mW value that fits in
504 * a u16.
505 */
506
507#define QDBM_OFFSET 153 /* Offset for first entry */
508#define QDBM_TABLE_LEN 40 /* Table size */
509
510/* Smallest mW value that will round up to the first table entry, QDBM_OFFSET.
511 * Value is ( mW(QDBM_OFFSET - 1) + mW(QDBM_OFFSET) ) / 2
512 */
513#define QDBM_TABLE_LOW_BOUND 6493 /* Low bound */
514
515/* Largest mW value that will round down to the last table entry,
516 * QDBM_OFFSET + QDBM_TABLE_LEN-1.
517 * Value is ( mW(QDBM_OFFSET + QDBM_TABLE_LEN - 1) +
518 * mW(QDBM_OFFSET + QDBM_TABLE_LEN) ) / 2.
519 */
520#define QDBM_TABLE_HIGH_BOUND 64938 /* High bound */
521
522static const u16 nqdBm_to_mW_map[QDBM_TABLE_LEN] = {
523/* qdBm: +0 +1 +2 +3 +4 +5 +6 +7 */
524/* 153: */ 6683, 7079, 7499, 7943, 8414, 8913, 9441, 10000,
525/* 161: */ 10593, 11220, 11885, 12589, 13335, 14125, 14962, 15849,
526/* 169: */ 16788, 17783, 18836, 19953, 21135, 22387, 23714, 25119,
527/* 177: */ 26607, 28184, 29854, 31623, 33497, 35481, 37584, 39811,
528/* 185: */ 42170, 44668, 47315, 50119, 53088, 56234, 59566, 63096
529};
530
531u16 brcmu_qdbm_to_mw(u8 qdbm)
532{
533 uint factor = 1;
534 int idx = qdbm - QDBM_OFFSET;
535
536 if (idx >= QDBM_TABLE_LEN)
537 /* clamp to max u16 mW value */
538 return 0xFFFF;
539
540 /* scale the qdBm index up to the range of the table 0-40
541 * where an offset of 40 qdBm equals a factor of 10 mW.
542 */
543 while (idx < 0) {
544 idx += 40;
545 factor *= 10;
546 }
547
548 /* return the mW value scaled down to the correct factor of 10,
549 * adding in factor/2 to get proper rounding.
550 */
551 return (nqdBm_to_mW_map[idx] + factor / 2) / factor;
552}
553EXPORT_SYMBOL(brcmu_qdbm_to_mw);
554
555u8 brcmu_mw_to_qdbm(u16 mw)
556{
557 u8 qdbm;
558 int offset;
559 uint mw_uint = mw;
560 uint boundary;
561
562 /* handle boundary case */
563 if (mw_uint <= 1)
564 return 0;
565
566 offset = QDBM_OFFSET;
567
568 /* move mw into the range of the table */
569 while (mw_uint < QDBM_TABLE_LOW_BOUND) {
570 mw_uint *= 10;
571 offset -= 40;
572 }
573
574 for (qdbm = 0; qdbm < QDBM_TABLE_LEN - 1; qdbm++) {
575 boundary = nqdBm_to_mW_map[qdbm] + (nqdBm_to_mW_map[qdbm + 1] -
576 nqdBm_to_mW_map[qdbm]) / 2;
577 if (mw_uint < boundary)
578 break;
579 }
580
581 qdbm += (u8) offset;
582
583 return qdbm;
584}
585EXPORT_SYMBOL(brcmu_mw_to_qdbm);
586
diff --git a/drivers/net/wireless/brcm80211/include/brcmu_utils.h b/drivers/net/wireless/brcm80211/include/brcmu_utils.h
index 96f05d7a5d23..d716cd2a5206 100644
--- a/drivers/net/wireless/brcm80211/include/brcmu_utils.h
+++ b/drivers/net/wireless/brcm80211/include/brcmu_utils.h
@@ -212,10 +212,6 @@ extern char *brcmu_chipname(uint chipid, char *buf, uint len);
212extern struct brcmu_tlv *brcmu_parse_tlvs(void *buf, int buflen, 212extern struct brcmu_tlv *brcmu_parse_tlvs(void *buf, int buflen,
213 uint key); 213 uint key);
214 214
215/* power conversion */
216extern u16 brcmu_qdbm_to_mw(u8 qdbm);
217extern u8 brcmu_mw_to_qdbm(u16 mw);
218
219extern uint brcmu_mkiovar(char *name, char *data, uint datalen, 215extern uint brcmu_mkiovar(char *name, char *data, uint datalen,
220 char *buf, uint len); 216 char *buf, uint len);
221 217