2017-12-09 18:03:04

by Simon Sandström

[permalink] [raw]
Subject: [PATCH 0/3] staging: pi433: Refactor usage of dev_dbg and #ifdef DEBUG

These patches refactors the usage of dev_dbg and #ifdef DEBUG in rf69.c.
All dev_dbg() calls that just prints the function name are removed, since
we have ftrace. For all other calls the #ifdef DEBUG block around them are
removed.

There are still two more defines used in rf69.c: DEBUG_FIFO_ACCESS and
DEBUG_VALUES. Perhaps they should be removed as well?

- Simon

---

Simon Sandström (3):
staging: pi433: Remove indentation on #ifdef blocks
staging: pi433: Remove function entry dev_dbg()
staging: pi433: Remove unnecessary #ifdef DEBUG around dev_dbg

drivers/staging/pi433/rf69.c | 232 ++++++-------------------------------------
1 file changed, 32 insertions(+), 200 deletions(-)

--
2.11.0


2017-12-09 18:03:08

by Simon Sandström

[permalink] [raw]
Subject: [PATCH 1/3] staging: pi433: Remove indentation on #ifdef blocks

ifdef blocks should not increase indentation level.

Signed-off-by: Simon Sandström <[email protected]>
---
drivers/staging/pi433/rf69.c | 314 +++++++++++++++++++++----------------------
1 file changed, 153 insertions(+), 161 deletions(-)

diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index 8b6d68f10e8a..39920240c05c 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -64,9 +64,9 @@ static inline int rf69_read_mod_write(struct spi_device *spi, u8 reg, u8 mask, u

int rf69_set_mode(struct spi_device *spi, enum mode mode)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: mode");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: mode");
+#endif

switch (mode) {
case transmit: return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE, OPMODE_MODE_TRANSMIT);
@@ -91,9 +91,9 @@ int rf69_set_data_mode(struct spi_device *spi, u8 data_mode)

int rf69_set_modulation(struct spi_device *spi, enum modulation modulation)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: modulation");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: modulation");
+#endif

switch (modulation) {
case OOK: return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_TYPE, DATAMODUL_MODULATION_TYPE_OOK);
@@ -108,9 +108,9 @@ enum modulation rf69_get_modulation(struct spi_device *spi)
{
u8 currentValue;

- #ifdef DEBUG
- dev_dbg(&spi->dev, "get: mode");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "get: mode");
+#endif

currentValue = rf69_read_reg(spi, REG_DATAMODUL);

@@ -124,9 +124,9 @@ enum modulation rf69_get_modulation(struct spi_device *spi)
int rf69_set_modulation_shaping(struct spi_device *spi,
enum mod_shaping mod_shaping)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: mod shaping");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: mod shaping");
+#endif

switch (rf69_get_modulation(spi)) {
case FSK:
@@ -162,9 +162,9 @@ int rf69_set_bit_rate(struct spi_device *spi, u16 bitRate)
u8 msb;
u8 lsb;

- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: bit rate");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: bit rate");
+#endif

// check input value
bitRate_min = F_OSC / 8388608; // 8388608 = 2^23;
@@ -199,9 +199,9 @@ int rf69_set_deviation(struct spi_device *spi, u32 deviation)
u8 lsb;
u64 factor = 1000000; // to improve precision of calculation

- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: deviation");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: deviation");
+#endif

// TODO: Dependency to bitrate
if (deviation < 600 || deviation > 500000) {
@@ -248,9 +248,9 @@ int rf69_set_frequency(struct spi_device *spi, u32 frequency)
u8 lsb;
u64 factor = 1000000; // to improve precision of calculation

- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: frequency");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: frequency");
+#endif

// calculat f step
f_step = F_OSC * factor;
@@ -297,9 +297,9 @@ int rf69_disable_amplifier(struct spi_device *spi, u8 amplifier_mask)

int rf69_set_output_power_level(struct spi_device *spi, u8 powerLevel)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: power level");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: power level");
+#endif

// TODO: Dependency to PA0,1,2 setting
powerLevel += 18;
@@ -316,9 +316,9 @@ int rf69_set_output_power_level(struct spi_device *spi, u8 powerLevel)

int rf69_set_pa_ramp(struct spi_device *spi, enum paRamp paRamp)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: pa ramp");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: pa ramp");
+#endif

switch (paRamp) {
case ramp3400: return rf69_write_reg(spi, REG_PARAMP, PARAMP_3400);
@@ -345,9 +345,9 @@ int rf69_set_pa_ramp(struct spi_device *spi, enum paRamp paRamp)

int rf69_set_antenna_impedance(struct spi_device *spi, enum antennaImpedance antennaImpedance)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: antenna impedance");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: antenna impedance");
+#endif

switch (antennaImpedance) {
case fiftyOhm: return rf69_clear_bit(spi, REG_LNA, MASK_LNA_ZIN);
@@ -360,9 +360,9 @@ int rf69_set_antenna_impedance(struct spi_device *spi, enum antennaImpedance ant

int rf69_set_lna_gain(struct spi_device *spi, enum lnaGain lnaGain)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: lna gain");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: lna gain");
+#endif

switch (lnaGain) {
case automatic: return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, LNA_GAIN_AUTO);
@@ -382,9 +382,9 @@ enum lnaGain rf69_get_lna_gain(struct spi_device *spi)
{
u8 currentValue;

- #ifdef DEBUG
- dev_dbg(&spi->dev, "get: lna gain");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "get: lna gain");
+#endif

currentValue = rf69_read_reg(spi, REG_LNA);

@@ -419,18 +419,18 @@ int rf69_set_dc_cut_off_frequency_intern(struct spi_device *spi, u8 reg, enum dc

int rf69_set_dc_cut_off_frequency(struct spi_device *spi, enum dccPercent dccPercent)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: cut off freq");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: cut off freq");
+#endif

return rf69_set_dc_cut_off_frequency_intern(spi, REG_RXBW, dccPercent);
}

int rf69_set_dc_cut_off_frequency_during_afc(struct spi_device *spi, enum dccPercent dccPercent)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: cut off freq during afc");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: cut off freq during afc");
+#endif

return rf69_set_dc_cut_off_frequency_intern(spi, REG_AFCBW, dccPercent);
}
@@ -481,27 +481,27 @@ static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,

int rf69_set_bandwidth(struct spi_device *spi, enum mantisse mantisse, u8 exponent)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: band width");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: band width");
+#endif

return rf69_set_bandwidth_intern(spi, REG_RXBW, mantisse, exponent);
}

int rf69_set_bandwidth_during_afc(struct spi_device *spi, enum mantisse mantisse, u8 exponent)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: band width during afc");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: band width during afc");
+#endif

return rf69_set_bandwidth_intern(spi, REG_AFCBW, mantisse, exponent);
}

int rf69_set_ook_threshold_type(struct spi_device *spi, enum thresholdType thresholdType)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: threshold type");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: threshold type");
+#endif

switch (thresholdType) {
case fixed: return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESTYPE, OOKPEAK_THRESHTYPE_FIXED);
@@ -515,9 +515,9 @@ int rf69_set_ook_threshold_type(struct spi_device *spi, enum thresholdType thres

int rf69_set_ook_threshold_step(struct spi_device *spi, enum thresholdStep thresholdStep)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: threshold step");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: threshold step");
+#endif

switch (thresholdStep) {
case step_0_5db: return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESSTEP, OOKPEAK_THRESHSTEP_0_5_DB);
@@ -536,9 +536,9 @@ int rf69_set_ook_threshold_step(struct spi_device *spi, enum thresholdStep thres

int rf69_set_ook_threshold_dec(struct spi_device *spi, enum thresholdDecrement thresholdDecrement)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: threshold decrement");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: threshold decrement");
+#endif

switch (thresholdDecrement) {
case dec_every8th: return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC, OOKPEAK_THRESHDEC_EVERY_8TH);
@@ -562,9 +562,9 @@ int rf69_set_dio_mapping(struct spi_device *spi, u8 DIONumber, u8 value)
u8 regaddr;
u8 regValue;

- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: DIO mapping");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: DIO mapping");
+#endif

switch (DIONumber) {
case 0:
@@ -602,9 +602,9 @@ int rf69_set_dio_mapping(struct spi_device *spi, u8 DIONumber, u8 value)

bool rf69_get_flag(struct spi_device *spi, enum flag flag)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "get: flag");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "get: flag");
+#endif

switch (flag) {
case modeSwitchCompleted: return (rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_MODE_READY);
@@ -630,9 +630,9 @@ bool rf69_get_flag(struct spi_device *spi, enum flag flag)

int rf69_reset_flag(struct spi_device *spi, enum flag flag)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "reset: flag");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "reset: flag");
+#endif

switch (flag) {
case rssiExceededThreshold: return rf69_write_reg(spi, REG_IRQFLAGS1, MASK_IRQFLAGS1_RSSI);
@@ -646,9 +646,9 @@ int rf69_reset_flag(struct spi_device *spi, enum flag flag)

int rf69_set_rssi_threshold(struct spi_device *spi, u8 threshold)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: rssi threshold");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: rssi threshold");
+#endif

/* no value check needed - u8 exactly matches register size */

@@ -657,9 +657,9 @@ int rf69_set_rssi_threshold(struct spi_device *spi, u8 threshold)

int rf69_set_rx_start_timeout(struct spi_device *spi, u8 timeout)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: start timeout");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: start timeout");
+#endif

/* no value check needed - u8 exactly matches register size */

@@ -668,9 +668,9 @@ int rf69_set_rx_start_timeout(struct spi_device *spi, u8 timeout)

int rf69_set_rssi_timeout(struct spi_device *spi, u8 timeout)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: rssi timeout");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: rssi timeout");
+#endif

/* no value check needed - u8 exactly matches register size */

@@ -682,9 +682,9 @@ int rf69_set_preamble_length(struct spi_device *spi, u16 preambleLength)
int retval;
u8 msb, lsb;

- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: preamble length");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: preamble length");
+#endif

/* no value check needed - u16 exactly matches register size */

@@ -713,9 +713,9 @@ int rf69_disable_sync(struct spi_device *spi)

int rf69_set_fifo_fill_condition(struct spi_device *spi, enum fifoFillCondition fifoFillCondition)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: fifo fill condition");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: fifo fill condition");
+#endif

switch (fifoFillCondition) {
case always: return rf69_set_bit(spi, REG_SYNC_CONFIG, MASK_SYNC_CONFIG_FIFO_FILL_CONDITION);
@@ -728,9 +728,9 @@ int rf69_set_fifo_fill_condition(struct spi_device *spi, enum fifoFillCondition

int rf69_set_sync_size(struct spi_device *spi, u8 syncSize)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: sync size");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: sync size");
+#endif

// check input value
if (syncSize > 0x07) {
@@ -744,9 +744,9 @@ int rf69_set_sync_size(struct spi_device *spi, u8 syncSize)

int rf69_set_sync_tolerance(struct spi_device *spi, u8 syncTolerance)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: sync tolerance");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: sync tolerance");
+#endif

// check input value
if (syncTolerance > 0x07) {
@@ -762,9 +762,9 @@ int rf69_set_sync_values(struct spi_device *spi, u8 syncValues[8])
{
int retval = 0;

- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: sync values");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: sync values");
+#endif

retval += rf69_write_reg(spi, REG_SYNCVALUE1, syncValues[0]);
retval += rf69_write_reg(spi, REG_SYNCVALUE2, syncValues[1]);
@@ -780,9 +780,9 @@ int rf69_set_sync_values(struct spi_device *spi, u8 syncValues[8])

int rf69_set_packet_format(struct spi_device *spi, enum packetFormat packetFormat)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: packet format");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: packet format");
+#endif

switch (packetFormat) {
case packetLengthVar: return rf69_set_bit(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_PAKET_FORMAT_VARIABLE);
@@ -805,9 +805,9 @@ int rf69_disable_crc(struct spi_device *spi)

int rf69_set_adressFiltering(struct spi_device *spi, enum addressFiltering addressFiltering)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: address filtering");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: address filtering");
+#endif

switch (addressFiltering) {
case filteringOff: return rf69_read_mod_write(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_ADDRESSFILTERING, PACKETCONFIG1_ADDRESSFILTERING_OFF);
@@ -821,45 +821,45 @@ int rf69_set_adressFiltering(struct spi_device *spi, enum addressFiltering addre

int rf69_set_payload_length(struct spi_device *spi, u8 payloadLength)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: payload length");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: payload length");
+#endif

return rf69_write_reg(spi, REG_PAYLOAD_LENGTH, payloadLength);
}

u8 rf69_get_payload_length(struct spi_device *spi)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "get: payload length");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "get: payload length");
+#endif

return (u8)rf69_read_reg(spi, REG_PAYLOAD_LENGTH);
}

int rf69_set_node_address(struct spi_device *spi, u8 nodeAddress)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: node address");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: node address");
+#endif

return rf69_write_reg(spi, REG_NODEADRS, nodeAddress);
}

int rf69_set_broadcast_address(struct spi_device *spi, u8 broadcastAddress)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: broadcast address");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: broadcast address");
+#endif

return rf69_write_reg(spi, REG_BROADCASTADRS, broadcastAddress);
}

int rf69_set_tx_start_condition(struct spi_device *spi, enum txStartCondition txStartCondition)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: start condition");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: start condition");
+#endif

switch (txStartCondition) {
case fifoLevel: return rf69_clear_bit(spi, REG_FIFO_THRESH, MASK_FIFO_THRESH_TXSTART);
@@ -874,9 +874,9 @@ int rf69_set_fifo_threshold(struct spi_device *spi, u8 threshold)
{
int retval;

- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: fifo threshold");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: fifo threshold");
+#endif

/* check input value */
if (threshold & 0x80) {
@@ -897,9 +897,9 @@ int rf69_set_fifo_threshold(struct spi_device *spi, u8 threshold)

int rf69_set_dagc(struct spi_device *spi, enum dagc dagc)
{
- #ifdef DEBUG
- dev_dbg(&spi->dev, "set: dagc");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "set: dagc");
+#endif

switch (dagc) {
case normalMode: return rf69_write_reg(spi, REG_TESTDAGC, DAGC_NORMAL);
@@ -915,17 +915,17 @@ int rf69_set_dagc(struct spi_device *spi, enum dagc dagc)

int rf69_read_fifo (struct spi_device *spi, u8 *buffer, unsigned int size)
{
- #ifdef DEBUG_FIFO_ACCESS
- int i;
- #endif
+#ifdef DEBUG_FIFO_ACCESS
+ int i;
+#endif
struct spi_transfer transfer;
u8 local_buffer[FIFO_SIZE + 1];
int retval;

if (size > FIFO_SIZE) {
- #ifdef DEBUG
- dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer \n");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer\n");
+#endif
return -EMSGSIZE;
}

@@ -950,26 +950,26 @@ int rf69_read_fifo (struct spi_device *spi, u8 *buffer, unsigned int size)

int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size)
{
- #ifdef DEBUG_FIFO_ACCESS
- int i;
- #endif
+#ifdef DEBUG_FIFO_ACCESS
+ int i;
+#endif
char spi_address = REG_FIFO | WRITE_BIT;
u8 local_buffer[FIFO_SIZE + 1];

if (size > FIFO_SIZE) {
- #ifdef DEBUG
- dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer \n");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer\n");
+#endif
return -EMSGSIZE;
}

local_buffer[0] = spi_address;
memcpy(&local_buffer[1], buffer, size);

- #ifdef DEBUG_FIFO_ACCESS
- for (i = 0; i < size; i++)
- dev_dbg(&spi->dev, "0x%x\n", buffer[i]);
- #endif
+#ifdef DEBUG_FIFO_ACCESS
+ for (i = 0; i < size; i++)
+ dev_dbg(&spi->dev, "0x%x\n", buffer[i]);
+#endif

return spi_write (spi, local_buffer, size + 1);
}
@@ -982,19 +982,16 @@ u8 rf69_read_reg(struct spi_device *spi, u8 addr)

retval = spi_w8r8(spi, addr);

- #ifdef DEBUG_VALUES
- if (retval < 0)
- /* should never happen, since we already checked,
- * that module is connected. Therefore no error
- * handling, just an optional error message...
- */
- dev_dbg(&spi->dev, "read 0x%x FAILED\n",
- addr);
- else
- dev_dbg(&spi->dev, "read 0x%x from reg 0x%x\n",
- retval,
- addr);
- #endif
+#ifdef DEBUG_VALUES
+ if (retval < 0)
+ /* should never happen, since we already checked,
+ * that module is connected. Therefore no error
+ * handling, just an optional error message...
+ */
+ dev_dbg(&spi->dev, "read 0x%x FAILED\n", addr);
+ else
+ dev_dbg(&spi->dev, "read 0x%x from reg 0x%x\n", retval, addr);
+#endif

return retval;
}
@@ -1009,22 +1006,17 @@ int rf69_write_reg(struct spi_device *spi, u8 addr, u8 value)

retval = spi_write(spi, &buffer, 2);

- #ifdef DEBUG_VALUES
- if (retval < 0)
- /* should never happen, since we already checked,
- * that module is connected. Therefore no error
- * handling, just an optional error message...
- */
- dev_dbg(&spi->dev, "write 0x%x to 0x%x FAILED\n",
- value,
- addr);
- else
- dev_dbg(&spi->dev, "wrote 0x%x to reg 0x%x\n",
- value,
- addr);
- #endif
+#ifdef DEBUG_VALUES
+ if (retval < 0)
+ /* should never happen, since we already checked,
+ * that module is connected. Therefore no error
+ * handling, just an optional error message...
+ */
+ dev_dbg(&spi->dev, "write 0x%x to 0x%x FAILED\n", value, addr);
+ else
+ dev_dbg(&spi->dev, "wrote 0x%x to reg 0x%x\n", value, addr);
+#endif

return retval;
}

-
--
2.11.0

2017-12-09 18:03:10

by Simon Sandström

[permalink] [raw]
Subject: [PATCH 2/3] staging: pi433: Remove function entry dev_dbg()

ftrace can be used to trace function calls, so there is no need to use
dev_dbg() here.

Signed-off-by: Simon Sandström <[email protected]>
---
drivers/staging/pi433/rf69.c | 156 -------------------------------------------
1 file changed, 156 deletions(-)

diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index 39920240c05c..04a74423c325 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -64,10 +64,6 @@ static inline int rf69_read_mod_write(struct spi_device *spi, u8 reg, u8 mask, u

int rf69_set_mode(struct spi_device *spi, enum mode mode)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: mode");
-#endif
-
switch (mode) {
case transmit: return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE, OPMODE_MODE_TRANSMIT);
case receive: return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE, OPMODE_MODE_RECEIVE);
@@ -91,10 +87,6 @@ int rf69_set_data_mode(struct spi_device *spi, u8 data_mode)

int rf69_set_modulation(struct spi_device *spi, enum modulation modulation)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: modulation");
-#endif
-
switch (modulation) {
case OOK: return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_TYPE, DATAMODUL_MODULATION_TYPE_OOK);
case FSK: return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODULATION_TYPE, DATAMODUL_MODULATION_TYPE_FSK);
@@ -108,10 +100,6 @@ enum modulation rf69_get_modulation(struct spi_device *spi)
{
u8 currentValue;

-#ifdef DEBUG
- dev_dbg(&spi->dev, "get: mode");
-#endif
-
currentValue = rf69_read_reg(spi, REG_DATAMODUL);

switch (currentValue & MASK_DATAMODUL_MODULATION_TYPE >> 3) { // TODO improvement: change 3 to define
@@ -124,10 +112,6 @@ enum modulation rf69_get_modulation(struct spi_device *spi)
int rf69_set_modulation_shaping(struct spi_device *spi,
enum mod_shaping mod_shaping)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: mod shaping");
-#endif
-
switch (rf69_get_modulation(spi)) {
case FSK:
switch (mod_shaping) {
@@ -162,10 +146,6 @@ int rf69_set_bit_rate(struct spi_device *spi, u16 bitRate)
u8 msb;
u8 lsb;

-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: bit rate");
-#endif
-
// check input value
bitRate_min = F_OSC / 8388608; // 8388608 = 2^23;
if (bitRate < bitRate_min) {
@@ -199,10 +179,6 @@ int rf69_set_deviation(struct spi_device *spi, u32 deviation)
u8 lsb;
u64 factor = 1000000; // to improve precision of calculation

-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: deviation");
-#endif
-
// TODO: Dependency to bitrate
if (deviation < 600 || deviation > 500000) {
dev_dbg(&spi->dev, "set_deviation: illegal input param");
@@ -248,10 +224,6 @@ int rf69_set_frequency(struct spi_device *spi, u32 frequency)
u8 lsb;
u64 factor = 1000000; // to improve precision of calculation

-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: frequency");
-#endif
-
// calculat f step
f_step = F_OSC * factor;
do_div(f_step, 524288); // 524288 = 2^19
@@ -297,10 +269,6 @@ int rf69_disable_amplifier(struct spi_device *spi, u8 amplifier_mask)

int rf69_set_output_power_level(struct spi_device *spi, u8 powerLevel)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: power level");
-#endif
-
// TODO: Dependency to PA0,1,2 setting
powerLevel += 18;

@@ -316,10 +284,6 @@ int rf69_set_output_power_level(struct spi_device *spi, u8 powerLevel)

int rf69_set_pa_ramp(struct spi_device *spi, enum paRamp paRamp)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: pa ramp");
-#endif
-
switch (paRamp) {
case ramp3400: return rf69_write_reg(spi, REG_PARAMP, PARAMP_3400);
case ramp2000: return rf69_write_reg(spi, REG_PARAMP, PARAMP_2000);
@@ -345,10 +309,6 @@ int rf69_set_pa_ramp(struct spi_device *spi, enum paRamp paRamp)

int rf69_set_antenna_impedance(struct spi_device *spi, enum antennaImpedance antennaImpedance)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: antenna impedance");
-#endif
-
switch (antennaImpedance) {
case fiftyOhm: return rf69_clear_bit(spi, REG_LNA, MASK_LNA_ZIN);
case twohundretOhm: return rf69_set_bit(spi, REG_LNA, MASK_LNA_ZIN);
@@ -360,10 +320,6 @@ int rf69_set_antenna_impedance(struct spi_device *spi, enum antennaImpedance ant

int rf69_set_lna_gain(struct spi_device *spi, enum lnaGain lnaGain)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: lna gain");
-#endif
-
switch (lnaGain) {
case automatic: return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, LNA_GAIN_AUTO);
case max: return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, LNA_GAIN_MAX);
@@ -382,10 +338,6 @@ enum lnaGain rf69_get_lna_gain(struct spi_device *spi)
{
u8 currentValue;

-#ifdef DEBUG
- dev_dbg(&spi->dev, "get: lna gain");
-#endif
-
currentValue = rf69_read_reg(spi, REG_LNA);

switch (currentValue & MASK_LNA_CURRENT_GAIN >> 3) { // improvement: change 3 to define
@@ -419,19 +371,11 @@ int rf69_set_dc_cut_off_frequency_intern(struct spi_device *spi, u8 reg, enum dc

int rf69_set_dc_cut_off_frequency(struct spi_device *spi, enum dccPercent dccPercent)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: cut off freq");
-#endif
-
return rf69_set_dc_cut_off_frequency_intern(spi, REG_RXBW, dccPercent);
}

int rf69_set_dc_cut_off_frequency_during_afc(struct spi_device *spi, enum dccPercent dccPercent)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: cut off freq during afc");
-#endif
-
return rf69_set_dc_cut_off_frequency_intern(spi, REG_AFCBW, dccPercent);
}

@@ -481,28 +425,16 @@ static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,

int rf69_set_bandwidth(struct spi_device *spi, enum mantisse mantisse, u8 exponent)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: band width");
-#endif
-
return rf69_set_bandwidth_intern(spi, REG_RXBW, mantisse, exponent);
}

int rf69_set_bandwidth_during_afc(struct spi_device *spi, enum mantisse mantisse, u8 exponent)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: band width during afc");
-#endif
-
return rf69_set_bandwidth_intern(spi, REG_AFCBW, mantisse, exponent);
}

int rf69_set_ook_threshold_type(struct spi_device *spi, enum thresholdType thresholdType)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: threshold type");
-#endif
-
switch (thresholdType) {
case fixed: return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESTYPE, OOKPEAK_THRESHTYPE_FIXED);
case peak: return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESTYPE, OOKPEAK_THRESHTYPE_PEAK);
@@ -515,10 +447,6 @@ int rf69_set_ook_threshold_type(struct spi_device *spi, enum thresholdType thres

int rf69_set_ook_threshold_step(struct spi_device *spi, enum thresholdStep thresholdStep)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: threshold step");
-#endif
-
switch (thresholdStep) {
case step_0_5db: return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESSTEP, OOKPEAK_THRESHSTEP_0_5_DB);
case step_1_0db: return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESSTEP, OOKPEAK_THRESHSTEP_1_0_DB);
@@ -536,10 +464,6 @@ int rf69_set_ook_threshold_step(struct spi_device *spi, enum thresholdStep thres

int rf69_set_ook_threshold_dec(struct spi_device *spi, enum thresholdDecrement thresholdDecrement)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: threshold decrement");
-#endif
-
switch (thresholdDecrement) {
case dec_every8th: return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC, OOKPEAK_THRESHDEC_EVERY_8TH);
case dec_every4th: return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC, OOKPEAK_THRESHDEC_EVERY_4TH);
@@ -562,10 +486,6 @@ int rf69_set_dio_mapping(struct spi_device *spi, u8 DIONumber, u8 value)
u8 regaddr;
u8 regValue;

-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: DIO mapping");
-#endif
-
switch (DIONumber) {
case 0:
mask = MASK_DIO0; shift = SHIFT_DIO0; regaddr = REG_DIOMAPPING1;
@@ -602,10 +522,6 @@ int rf69_set_dio_mapping(struct spi_device *spi, u8 DIONumber, u8 value)

bool rf69_get_flag(struct spi_device *spi, enum flag flag)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "get: flag");
-#endif
-
switch (flag) {
case modeSwitchCompleted: return (rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_MODE_READY);
case readyToReceive: return (rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_RX_READY);
@@ -630,10 +546,6 @@ bool rf69_get_flag(struct spi_device *spi, enum flag flag)

int rf69_reset_flag(struct spi_device *spi, enum flag flag)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "reset: flag");
-#endif
-
switch (flag) {
case rssiExceededThreshold: return rf69_write_reg(spi, REG_IRQFLAGS1, MASK_IRQFLAGS1_RSSI);
case syncAddressMatch: return rf69_write_reg(spi, REG_IRQFLAGS1, MASK_IRQFLAGS1_SYNC_ADDRESS_MATCH);
@@ -646,10 +558,6 @@ int rf69_reset_flag(struct spi_device *spi, enum flag flag)

int rf69_set_rssi_threshold(struct spi_device *spi, u8 threshold)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: rssi threshold");
-#endif
-
/* no value check needed - u8 exactly matches register size */

return rf69_write_reg(spi, REG_RSSITHRESH, threshold);
@@ -657,10 +565,6 @@ int rf69_set_rssi_threshold(struct spi_device *spi, u8 threshold)

int rf69_set_rx_start_timeout(struct spi_device *spi, u8 timeout)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: start timeout");
-#endif
-
/* no value check needed - u8 exactly matches register size */

return rf69_write_reg(spi, REG_RXTIMEOUT1, timeout);
@@ -668,10 +572,6 @@ int rf69_set_rx_start_timeout(struct spi_device *spi, u8 timeout)

int rf69_set_rssi_timeout(struct spi_device *spi, u8 timeout)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: rssi timeout");
-#endif
-
/* no value check needed - u8 exactly matches register size */

return rf69_write_reg(spi, REG_RXTIMEOUT2, timeout);
@@ -682,10 +582,6 @@ int rf69_set_preamble_length(struct spi_device *spi, u16 preambleLength)
int retval;
u8 msb, lsb;

-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: preamble length");
-#endif
-
/* no value check needed - u16 exactly matches register size */

/* calculate reg settings */
@@ -713,10 +609,6 @@ int rf69_disable_sync(struct spi_device *spi)

int rf69_set_fifo_fill_condition(struct spi_device *spi, enum fifoFillCondition fifoFillCondition)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: fifo fill condition");
-#endif
-
switch (fifoFillCondition) {
case always: return rf69_set_bit(spi, REG_SYNC_CONFIG, MASK_SYNC_CONFIG_FIFO_FILL_CONDITION);
case afterSyncInterrupt: return rf69_clear_bit(spi, REG_SYNC_CONFIG, MASK_SYNC_CONFIG_FIFO_FILL_CONDITION);
@@ -728,10 +620,6 @@ int rf69_set_fifo_fill_condition(struct spi_device *spi, enum fifoFillCondition

int rf69_set_sync_size(struct spi_device *spi, u8 syncSize)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: sync size");
-#endif
-
// check input value
if (syncSize > 0x07) {
dev_dbg(&spi->dev, "set: illegal input param");
@@ -744,10 +632,6 @@ int rf69_set_sync_size(struct spi_device *spi, u8 syncSize)

int rf69_set_sync_tolerance(struct spi_device *spi, u8 syncTolerance)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: sync tolerance");
-#endif
-
// check input value
if (syncTolerance > 0x07) {
dev_dbg(&spi->dev, "set: illegal input param");
@@ -762,10 +646,6 @@ int rf69_set_sync_values(struct spi_device *spi, u8 syncValues[8])
{
int retval = 0;

-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: sync values");
-#endif
-
retval += rf69_write_reg(spi, REG_SYNCVALUE1, syncValues[0]);
retval += rf69_write_reg(spi, REG_SYNCVALUE2, syncValues[1]);
retval += rf69_write_reg(spi, REG_SYNCVALUE3, syncValues[2]);
@@ -780,10 +660,6 @@ int rf69_set_sync_values(struct spi_device *spi, u8 syncValues[8])

int rf69_set_packet_format(struct spi_device *spi, enum packetFormat packetFormat)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: packet format");
-#endif
-
switch (packetFormat) {
case packetLengthVar: return rf69_set_bit(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_PAKET_FORMAT_VARIABLE);
case packetLengthFix: return rf69_clear_bit(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_PAKET_FORMAT_VARIABLE);
@@ -805,10 +681,6 @@ int rf69_disable_crc(struct spi_device *spi)

int rf69_set_adressFiltering(struct spi_device *spi, enum addressFiltering addressFiltering)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: address filtering");
-#endif
-
switch (addressFiltering) {
case filteringOff: return rf69_read_mod_write(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_ADDRESSFILTERING, PACKETCONFIG1_ADDRESSFILTERING_OFF);
case nodeAddress: return rf69_read_mod_write(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_ADDRESSFILTERING, PACKETCONFIG1_ADDRESSFILTERING_NODE);
@@ -821,46 +693,26 @@ int rf69_set_adressFiltering(struct spi_device *spi, enum addressFiltering addre

int rf69_set_payload_length(struct spi_device *spi, u8 payloadLength)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: payload length");
-#endif
-
return rf69_write_reg(spi, REG_PAYLOAD_LENGTH, payloadLength);
}

u8 rf69_get_payload_length(struct spi_device *spi)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "get: payload length");
-#endif
-
return (u8)rf69_read_reg(spi, REG_PAYLOAD_LENGTH);
}

int rf69_set_node_address(struct spi_device *spi, u8 nodeAddress)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: node address");
-#endif
-
return rf69_write_reg(spi, REG_NODEADRS, nodeAddress);
}

int rf69_set_broadcast_address(struct spi_device *spi, u8 broadcastAddress)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: broadcast address");
-#endif
-
return rf69_write_reg(spi, REG_BROADCASTADRS, broadcastAddress);
}

int rf69_set_tx_start_condition(struct spi_device *spi, enum txStartCondition txStartCondition)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: start condition");
-#endif
-
switch (txStartCondition) {
case fifoLevel: return rf69_clear_bit(spi, REG_FIFO_THRESH, MASK_FIFO_THRESH_TXSTART);
case fifoNotEmpty: return rf69_set_bit(spi, REG_FIFO_THRESH, MASK_FIFO_THRESH_TXSTART);
@@ -874,10 +726,6 @@ int rf69_set_fifo_threshold(struct spi_device *spi, u8 threshold)
{
int retval;

-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: fifo threshold");
-#endif
-
/* check input value */
if (threshold & 0x80) {
dev_dbg(&spi->dev, "set: illegal input param");
@@ -897,10 +745,6 @@ int rf69_set_fifo_threshold(struct spi_device *spi, u8 threshold)

int rf69_set_dagc(struct spi_device *spi, enum dagc dagc)
{
-#ifdef DEBUG
- dev_dbg(&spi->dev, "set: dagc");
-#endif
-
switch (dagc) {
case normalMode: return rf69_write_reg(spi, REG_TESTDAGC, DAGC_NORMAL);
case improve: return rf69_write_reg(spi, REG_TESTDAGC, DAGC_IMPROVED_LOWBETA0);
--
2.11.0

2017-12-09 18:03:35

by Simon Sandström

[permalink] [raw]
Subject: [PATCH 3/3] staging: pi433: Remove unnecessary #ifdef DEBUG around dev_dbg

dev_dbg() already depends on DEBUG.

Signed-off-by: Simon Sandström <[email protected]>
---
drivers/staging/pi433/rf69.c | 4 ----
1 file changed, 4 deletions(-)

diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index 04a74423c325..6e38e6a515a4 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -767,9 +767,7 @@ int rf69_read_fifo (struct spi_device *spi, u8 *buffer, unsigned int size)
int retval;

if (size > FIFO_SIZE) {
-#ifdef DEBUG
dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer\n");
-#endif
return -EMSGSIZE;
}

@@ -801,9 +799,7 @@ int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size)
u8 local_buffer[FIFO_SIZE + 1];

if (size > FIFO_SIZE) {
-#ifdef DEBUG
dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer\n");
-#endif
return -EMSGSIZE;
}

--
2.11.0

2017-12-09 18:08:33

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 3/3] staging: pi433: Remove unnecessary #ifdef DEBUG around dev_dbg

On Sat, 2017-12-09 at 19:02 +0100, Simon Sandstr?m wrote:
> dev_dbg() already depends on DEBUG.

Not quite.

It depends on CONFIG_DYNAMIC_DEBUG or DEBUG

In any case, this patch is fine.

> Signed-off-by: Simon Sandstr?m <[email protected]>
> ---
> drivers/staging/pi433/rf69.c | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
> index 04a74423c325..6e38e6a515a4 100644
> --- a/drivers/staging/pi433/rf69.c
> +++ b/drivers/staging/pi433/rf69.c
> @@ -767,9 +767,7 @@ int rf69_read_fifo (struct spi_device *spi, u8 *buffer, unsigned int size)
> int retval;
>
> if (size > FIFO_SIZE) {
> -#ifdef DEBUG
> dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer\n");
> -#endif
> return -EMSGSIZE;
> }
>
> @@ -801,9 +799,7 @@ int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size)
> u8 local_buffer[FIFO_SIZE + 1];
>
> if (size > FIFO_SIZE) {
> -#ifdef DEBUG
> dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer\n");
> -#endif
> return -EMSGSIZE;
> }
>