Linux IEEE 802.15.4 and 6LoWPAN development
 help / color / mirror / Atom feed
From: Alexander Aring <alex.aring@gmail.com>
To: linux-wpan@vger.kernel.org
Cc: kernel@pengutronix.de, Alexander Aring <alex.aring@gmail.com>
Subject: [PATCHv2 wpan-next 14/16] at86rf230: rework tx cca energy detection level
Date: Wed,  6 May 2015 13:40:26 +0200	[thread overview]
Message-ID: <1430912428-17284-15-git-send-email-alex.aring@gmail.com> (raw)
In-Reply-To: <1430912428-17284-1-git-send-email-alex.aring@gmail.com>

This patch reworks the cca energy detection level handling. This
contains a calculation which works on all transceiver types and
add support for dump cca energy detection levels.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 drivers/net/ieee802154/at86rf230.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index 10cb6a4..165c4cd 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -51,7 +51,6 @@ struct at86rf2xx_chip_data {
 	const s32 *tx_powers_table;
 
 	int (*set_channel)(struct at86rf230_local *, u8, u8);
-	int (*get_desense_steps)(struct at86rf230_local *, s32);
 	int (*set_txpower)(struct at86rf230_local *, s32);
 	int (*get_txpowers)(struct at86rf230_local *, s32 *, u32);
 };
@@ -1319,28 +1318,32 @@ at86rf230_set_cca_mode(struct ieee802154_hw *hw,
 }
 
 static int
-at86rf212_get_desens_steps(struct at86rf230_local *lp, s32 level)
+at86rf230_set_cca_ed_level(struct ieee802154_hw *hw, s32 mbm)
 {
-	return (level - lp->data->rssi_base_val) * 100 / 207;
-}
+	struct at86rf230_local *lp = hw->priv;
+	s32 level = mbm / 100;
 
-static int
-at86rf23x_get_desens_steps(struct at86rf230_local *lp, s32 level)
-{
-	return (level - lp->data->rssi_base_val) / 2;
+	/* backwards compatible for old interface, should be removed */
+	if (level < lp->data->rssi_base_val ||
+	    level > lp->data->rssi_base_val + 2 * 0xF)
+		return -EINVAL;
+
+	return at86rf230_write_subreg(lp, SR_CCA_ED_THRES,
+				      (level - lp->data->rssi_base_val) / 2);
 }
 
+#define AT86RF230_MAX_ED_LEVELS_IDX 0xF
+
 static int
-at86rf230_set_cca_ed_level(struct ieee802154_hw *hw, s32 mbm)
+at86rf230_get_cca_ed_levels(struct ieee802154_hw *hw, s32 *mbm, u32 idx)
 {
 	struct at86rf230_local *lp = hw->priv;
-	s32 level = mbm / 100;
 
-	if (level < lp->data->rssi_base_val || level > 30)
-		return -EINVAL;
+	if (idx > AT86RF230_MAX_ED_LEVELS_IDX)
+		return 1;
 
-	return at86rf230_write_subreg(lp, SR_CCA_ED_THRES,
-				      lp->data->get_desense_steps(lp, level));
+	*mbm = (lp->data->rssi_base_val + 2 * idx) * 100;
+	return 0;
 }
 
 static int
@@ -1413,6 +1416,7 @@ static const struct ieee802154_ops at86rf230_ops = {
 	.set_hw_addr_filt = at86rf230_set_hw_addr_filt,
 	.set_txpower = at86rf230_set_txpower,
 	.get_tx_powers = at86rf230_get_txpowers,
+	.get_cca_ed_levels = at86rf230_get_cca_ed_levels,
 	.set_lbt = at86rf230_set_lbt,
 	.set_cca_mode = at86rf230_set_cca_mode,
 	.set_cca_ed_level = at86rf230_set_cca_ed_level,
@@ -1432,7 +1436,6 @@ static struct at86rf2xx_chip_data at86rf233_data = {
 	.rssi_base_val = -91,
 	.tx_powers_table = at86rf233_powers,
 	.set_channel = at86rf23x_set_channel,
-	.get_desense_steps = at86rf23x_get_desens_steps,
 	.set_txpower = at86rf23x_set_txpower,
 	.get_txpowers = at86rf23x_get_txpowers,
 };
@@ -1448,7 +1451,6 @@ static struct at86rf2xx_chip_data at86rf231_data = {
 	.rssi_base_val = -91,
 	.tx_powers_table = at86rf231_powers,
 	.set_channel = at86rf23x_set_channel,
-	.get_desense_steps = at86rf23x_get_desens_steps,
 	.set_txpower = at86rf23x_set_txpower,
 	.get_txpowers = at86rf23x_get_txpowers,
 };
@@ -1463,7 +1465,6 @@ static struct at86rf2xx_chip_data at86rf212_data = {
 	.t_p_ack = 545,
 	.rssi_base_val = -100,
 	.set_channel = at86rf212_set_channel,
-	.get_desense_steps = at86rf212_get_desens_steps,
 	.set_txpower = at86rf212_set_txpower,
 	.get_txpowers = at86rf212_get_txpowers,
 };
-- 
2.3.7


  parent reply	other threads:[~2015-05-06 11:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 01/16] ieee802154: change transmit power to s32 Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 02/16] ieee802154: change transmit power to mbm Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 03/16] ieee802154: change cca ed level " Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 04/16] ieee802154: introduce wpan_phy_supported Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 05/16] ieee802154: add several phy supported handling Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 06/16] mac802154: check for really changes Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 07/16] mac802154: remove check if operation is supported Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 08/16] ieee802154: add iftypes capability Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 09/16] ieee802154: add support for get tx powers Alexander Aring
2015-05-06 12:02   ` Phoebe Buckheister
2015-05-06 13:19     ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 10/16] ieee802154: add support for get cca ed levels Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 11/16] at86rf230: set cca_modes supported flags Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 12/16] at86rf230: add reset states of tx power level Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 13/16] at86rf230: rework tx power support Alexander Aring
2015-05-06 11:40 ` Alexander Aring [this message]
2015-05-06 11:40 ` [PATCHv2 wpan-next 15/16] ieee802154: check transmit power before driver layer Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 16/16] nl802154: add support for dump phy capabilities Alexander Aring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1430912428-17284-15-git-send-email-alex.aring@gmail.com \
    --to=alex.aring@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-wpan@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox