Commit 86793395 authored by Valentin Vidic's avatar Valentin Vidic Committed by Greg Kroah-Hartman

staging: pi433: replace simple switch statements

Use const array to map switch cases to resulting values.
Signed-off-by: default avatarValentin Vidic <Valentin.Vidic@CARNet.hr>
Reviewed-by: default avatarMarcus Wolf <Marcus.Wolf@Wolf-Entwicklungen.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 983000d7
...@@ -111,27 +111,22 @@ static inline int rf69_read_mod_write(struct spi_device *spi, u8 reg, ...@@ -111,27 +111,22 @@ static inline int rf69_read_mod_write(struct spi_device *spi, u8 reg,
int rf69_set_mode(struct spi_device *spi, enum mode mode) int rf69_set_mode(struct spi_device *spi, enum mode mode)
{ {
switch (mode) { static const u8 mode_map[] = {
case transmit: [transmit] = OPMODE_MODE_TRANSMIT,
return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE, [receive] = OPMODE_MODE_RECEIVE,
OPMODE_MODE_TRANSMIT); [synthesizer] = OPMODE_MODE_SYNTHESIZER,
case receive: [standby] = OPMODE_MODE_STANDBY,
return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE, [mode_sleep] = OPMODE_MODE_SLEEP,
OPMODE_MODE_RECEIVE); };
case synthesizer:
return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE, if (unlikely(mode >= ARRAY_SIZE(mode_map))) {
OPMODE_MODE_SYNTHESIZER);
case standby:
return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE,
OPMODE_MODE_STANDBY);
case mode_sleep:
return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE,
OPMODE_MODE_SLEEP);
default:
dev_dbg(&spi->dev, "set: illegal input param"); dev_dbg(&spi->dev, "set: illegal input param");
return -EINVAL; return -EINVAL;
} }
return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE,
mode_map[mode]);
// we are using packet mode, so this check is not really needed // we are using packet mode, so this check is not really needed
// but waiting for mode ready is necessary when going from sleep because the FIFO may not be immediately available from previous mode // but waiting for mode ready is necessary when going from sleep because the FIFO may not be immediately available from previous mode
//while (_mode == RF69_MODE_SLEEP && (READ_REG(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady //while (_mode == RF69_MODE_SLEEP && (READ_REG(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady
...@@ -145,19 +140,19 @@ int rf69_set_data_mode(struct spi_device *spi, u8 data_mode) ...@@ -145,19 +140,19 @@ int rf69_set_data_mode(struct spi_device *spi, u8 data_mode)
int rf69_set_modulation(struct spi_device *spi, enum modulation modulation) int rf69_set_modulation(struct spi_device *spi, enum modulation modulation)
{ {
switch (modulation) { static const u8 modulation_map[] = {
case OOK: [OOK] = DATAMODUL_MODULATION_TYPE_OOK,
return rf69_read_mod_write(spi, REG_DATAMODUL, [FSK] = DATAMODUL_MODULATION_TYPE_FSK,
MASK_DATAMODUL_MODULATION_TYPE, };
DATAMODUL_MODULATION_TYPE_OOK);
case FSK: if (unlikely(modulation >= ARRAY_SIZE(modulation_map))) {
return rf69_read_mod_write(spi, REG_DATAMODUL,
MASK_DATAMODUL_MODULATION_TYPE,
DATAMODUL_MODULATION_TYPE_FSK);
default:
dev_dbg(&spi->dev, "set: illegal input param"); dev_dbg(&spi->dev, "set: illegal input param");
return -EINVAL; return -EINVAL;
} }
return rf69_read_mod_write(spi, REG_DATAMODUL,
MASK_DATAMODUL_MODULATION_TYPE,
modulation_map[modulation]);
} }
static enum modulation rf69_get_modulation(struct spi_device *spi) static enum modulation rf69_get_modulation(struct spi_device *spi)
...@@ -373,43 +368,30 @@ int rf69_set_output_power_level(struct spi_device *spi, u8 power_level) ...@@ -373,43 +368,30 @@ int rf69_set_output_power_level(struct spi_device *spi, u8 power_level)
int rf69_set_pa_ramp(struct spi_device *spi, enum pa_ramp pa_ramp) int rf69_set_pa_ramp(struct spi_device *spi, enum pa_ramp pa_ramp)
{ {
switch (pa_ramp) { static const u8 pa_ramp_map[] = {
case ramp3400: [ramp3400] = PARAMP_3400,
return rf69_write_reg(spi, REG_PARAMP, PARAMP_3400); [ramp2000] = PARAMP_2000,
case ramp2000: [ramp1000] = PARAMP_1000,
return rf69_write_reg(spi, REG_PARAMP, PARAMP_2000); [ramp500] = PARAMP_500,
case ramp1000: [ramp250] = PARAMP_250,
return rf69_write_reg(spi, REG_PARAMP, PARAMP_1000); [ramp125] = PARAMP_125,
case ramp500: [ramp100] = PARAMP_100,
return rf69_write_reg(spi, REG_PARAMP, PARAMP_500); [ramp62] = PARAMP_62,
case ramp250: [ramp50] = PARAMP_50,
return rf69_write_reg(spi, REG_PARAMP, PARAMP_250); [ramp40] = PARAMP_40,
case ramp125: [ramp31] = PARAMP_31,
return rf69_write_reg(spi, REG_PARAMP, PARAMP_125); [ramp25] = PARAMP_25,
case ramp100: [ramp20] = PARAMP_20,
return rf69_write_reg(spi, REG_PARAMP, PARAMP_100); [ramp15] = PARAMP_15,
case ramp62: [ramp10] = PARAMP_10,
return rf69_write_reg(spi, REG_PARAMP, PARAMP_62); };
case ramp50:
return rf69_write_reg(spi, REG_PARAMP, PARAMP_50); if (unlikely(pa_ramp >= ARRAY_SIZE(pa_ramp_map))) {
case ramp40:
return rf69_write_reg(spi, REG_PARAMP, PARAMP_40);
case ramp31:
return rf69_write_reg(spi, REG_PARAMP, PARAMP_31);
case ramp25:
return rf69_write_reg(spi, REG_PARAMP, PARAMP_25);
case ramp20:
return rf69_write_reg(spi, REG_PARAMP, PARAMP_20);
case ramp15:
return rf69_write_reg(spi, REG_PARAMP, PARAMP_15);
case ramp12:
return rf69_write_reg(spi, REG_PARAMP, PARAMP_12);
case ramp10:
return rf69_write_reg(spi, REG_PARAMP, PARAMP_10);
default:
dev_dbg(&spi->dev, "set: illegal input param"); dev_dbg(&spi->dev, "set: illegal input param");
return -EINVAL; return -EINVAL;
} }
return rf69_write_reg(spi, REG_PARAMP, pa_ramp_map[pa_ramp]);
} }
int rf69_set_antenna_impedance(struct spi_device *spi, int rf69_set_antenna_impedance(struct spi_device *spi,
...@@ -428,32 +410,23 @@ int rf69_set_antenna_impedance(struct spi_device *spi, ...@@ -428,32 +410,23 @@ int rf69_set_antenna_impedance(struct spi_device *spi,
int rf69_set_lna_gain(struct spi_device *spi, enum lna_gain lna_gain) int rf69_set_lna_gain(struct spi_device *spi, enum lna_gain lna_gain)
{ {
switch (lna_gain) { static const u8 lna_gain_map[] = {
case automatic: [automatic] = LNA_GAIN_AUTO,
return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, [max] = LNA_GAIN_MAX,
LNA_GAIN_AUTO); [max_minus_6] = LNA_GAIN_MAX_MINUS_6,
case max: [max_minus_12] = LNA_GAIN_MAX_MINUS_12,
return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, [max_minus_24] = LNA_GAIN_MAX_MINUS_24,
LNA_GAIN_MAX); [max_minus_36] = LNA_GAIN_MAX_MINUS_36,
case max_minus_6: [max_minus_48] = LNA_GAIN_MAX_MINUS_48,
return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, };
LNA_GAIN_MAX_MINUS_6);
case max_minus_12: if (unlikely(lna_gain >= ARRAY_SIZE(lna_gain_map))) {
return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN,
LNA_GAIN_MAX_MINUS_12);
case max_minus_24:
return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN,
LNA_GAIN_MAX_MINUS_24);
case max_minus_36:
return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN,
LNA_GAIN_MAX_MINUS_36);
case max_minus_48:
return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN,
LNA_GAIN_MAX_MINUS_48);
default:
dev_dbg(&spi->dev, "set: illegal input param"); dev_dbg(&spi->dev, "set: illegal input param");
return -EINVAL; return -EINVAL;
} }
return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN,
lna_gain_map[lna_gain]);
} }
static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg, static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,
...@@ -516,43 +489,24 @@ int rf69_set_bandwidth_during_afc(struct spi_device *spi, ...@@ -516,43 +489,24 @@ int rf69_set_bandwidth_during_afc(struct spi_device *spi,
int rf69_set_ook_threshold_dec(struct spi_device *spi, int rf69_set_ook_threshold_dec(struct spi_device *spi,
enum threshold_decrement threshold_decrement) enum threshold_decrement threshold_decrement)
{ {
switch (threshold_decrement) { static const u8 td_map[] = {
case dec_every8th: [dec_every8th] = OOKPEAK_THRESHDEC_EVERY_8TH,
return rf69_read_mod_write(spi, REG_OOKPEAK, [dec_every4th] = OOKPEAK_THRESHDEC_EVERY_4TH,
MASK_OOKPEAK_THRESDEC, [dec_every2nd] = OOKPEAK_THRESHDEC_EVERY_2ND,
OOKPEAK_THRESHDEC_EVERY_8TH); [dec_once] = OOKPEAK_THRESHDEC_ONCE,
case dec_every4th: [dec_twice] = OOKPEAK_THRESHDEC_TWICE,
return rf69_read_mod_write(spi, REG_OOKPEAK, [dec_4times] = OOKPEAK_THRESHDEC_4_TIMES,
MASK_OOKPEAK_THRESDEC, [dec_8times] = OOKPEAK_THRESHDEC_8_TIMES,
OOKPEAK_THRESHDEC_EVERY_4TH); [dec_16times] = OOKPEAK_THRESHDEC_16_TIMES,
case dec_every2nd: };
return rf69_read_mod_write(spi, REG_OOKPEAK,
MASK_OOKPEAK_THRESDEC, if (unlikely(threshold_decrement >= ARRAY_SIZE(td_map))) {
OOKPEAK_THRESHDEC_EVERY_2ND);
case dec_once:
return rf69_read_mod_write(spi, REG_OOKPEAK,
MASK_OOKPEAK_THRESDEC,
OOKPEAK_THRESHDEC_ONCE);
case dec_twice:
return rf69_read_mod_write(spi, REG_OOKPEAK,
MASK_OOKPEAK_THRESDEC,
OOKPEAK_THRESHDEC_TWICE);
case dec_4times:
return rf69_read_mod_write(spi, REG_OOKPEAK,
MASK_OOKPEAK_THRESDEC,
OOKPEAK_THRESHDEC_4_TIMES);
case dec_8times:
return rf69_read_mod_write(spi, REG_OOKPEAK,
MASK_OOKPEAK_THRESDEC,
OOKPEAK_THRESHDEC_8_TIMES);
case dec_16times:
return rf69_read_mod_write(spi, REG_OOKPEAK,
MASK_OOKPEAK_THRESDEC,
OOKPEAK_THRESHDEC_16_TIMES);
default:
dev_dbg(&spi->dev, "set: illegal input param"); dev_dbg(&spi->dev, "set: illegal input param");
return -EINVAL; return -EINVAL;
} }
return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC,
td_map[threshold_decrement]);
} }
int rf69_set_dio_mapping(struct spi_device *spi, u8 dio_number, u8 value) int rf69_set_dio_mapping(struct spi_device *spi, u8 dio_number, u8 value)
...@@ -749,23 +703,21 @@ int rf69_disable_crc(struct spi_device *spi) ...@@ -749,23 +703,21 @@ int rf69_disable_crc(struct spi_device *spi)
int rf69_set_address_filtering(struct spi_device *spi, int rf69_set_address_filtering(struct spi_device *spi,
enum address_filtering address_filtering) enum address_filtering address_filtering)
{ {
switch (address_filtering) { static const u8 af_map[] = {
case filtering_off: [filtering_off] = PACKETCONFIG1_ADDRESSFILTERING_OFF,
return rf69_read_mod_write(spi, REG_PACKETCONFIG1, [node_address] = PACKETCONFIG1_ADDRESSFILTERING_NODE,
MASK_PACKETCONFIG1_ADDRESSFILTERING, [node_or_broadcast_address] =
PACKETCONFIG1_ADDRESSFILTERING_OFF); PACKETCONFIG1_ADDRESSFILTERING_NODEBROADCAST,
case node_address: };
return rf69_read_mod_write(spi, REG_PACKETCONFIG1,
MASK_PACKETCONFIG1_ADDRESSFILTERING, if (unlikely(address_filtering >= ARRAY_SIZE(af_map))) {
PACKETCONFIG1_ADDRESSFILTERING_NODE);
case node_or_broadcast_address:
return rf69_read_mod_write(spi, REG_PACKETCONFIG1,
MASK_PACKETCONFIG1_ADDRESSFILTERING,
PACKETCONFIG1_ADDRESSFILTERING_NODEBROADCAST);
default:
dev_dbg(&spi->dev, "set: illegal input param"); dev_dbg(&spi->dev, "set: illegal input param");
return -EINVAL; return -EINVAL;
} }
return rf69_read_mod_write(spi, REG_PACKETCONFIG1,
MASK_PACKETCONFIG1_ADDRESSFILTERING,
af_map[address_filtering]);
} }
int rf69_set_payload_length(struct spi_device *spi, u8 payload_length) int rf69_set_payload_length(struct spi_device *spi, u8 payload_length)
...@@ -824,17 +776,18 @@ int rf69_set_fifo_threshold(struct spi_device *spi, u8 threshold) ...@@ -824,17 +776,18 @@ int rf69_set_fifo_threshold(struct spi_device *spi, u8 threshold)
int rf69_set_dagc(struct spi_device *spi, enum dagc dagc) int rf69_set_dagc(struct spi_device *spi, enum dagc dagc)
{ {
switch (dagc) { static const u8 dagc_map[] = {
case normal_mode: [normal_mode] = DAGC_NORMAL,
return rf69_write_reg(spi, REG_TESTDAGC, DAGC_NORMAL); [improve] = DAGC_IMPROVED_LOWBETA0,
case improve: [improve_for_low_modulation_index] = DAGC_IMPROVED_LOWBETA1,
return rf69_write_reg(spi, REG_TESTDAGC, DAGC_IMPROVED_LOWBETA0); };
case improve_for_low_modulation_index:
return rf69_write_reg(spi, REG_TESTDAGC, DAGC_IMPROVED_LOWBETA1); if (unlikely(dagc >= ARRAY_SIZE(dagc_map))) {
default:
dev_dbg(&spi->dev, "set: illegal input param"); dev_dbg(&spi->dev, "set: illegal input param");
return -EINVAL; return -EINVAL;
} }
return rf69_write_reg(spi, REG_TESTDAGC, dagc_map[dagc]);
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment