[PATCH 105/107] staging: comedi: ni_stc.h: tidy up the cs5529_command_bits

H Hartley Sweeten hsweeten at visionengravers.com
Fri May 1 22:00:10 UTC 2015


For aesthetics, convert the enum into defines. Use the BIT() macro
to define the bits.

Signed-off-by: H Hartley Sweeten <hsweeten at visionengravers.com>
Cc: Ian Abbott <abbotti at mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
---
 drivers/staging/comedi/drivers/ni_mio_common.c | 12 ++++++------
 drivers/staging/comedi/drivers/ni_stc.h        | 25 ++++++++++++++-----------
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c
index 8a484fb..33f01e1 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -4512,7 +4512,7 @@ static int cs5529_do_conversion(struct comedi_device *dev,
 	int retval;
 	unsigned short status;
 
-	cs5529_command(dev, CSCMD_COMMAND | CSCMD_SINGLE_CONVERSION);
+	cs5529_command(dev, CS5529_CMD_CB | CS5529_CMD_SINGLE_CONV);
 	retval = cs5529_wait_for_idle(dev);
 	if (retval) {
 		dev_err(dev->class_dev,
@@ -4572,8 +4572,8 @@ static void cs5529_config_write(struct comedi_device *dev, unsigned int value,
 		       CAL_ADC_Config_Data_High_Word_67xx);
 	ni_ao_win_outw(dev, (value & 0xffff),
 		       CAL_ADC_Config_Data_Low_Word_67xx);
-	reg_select_bits &= CSCMD_REGISTER_SELECT_MASK;
-	cs5529_command(dev, CSCMD_COMMAND | reg_select_bits);
+	reg_select_bits &= CS5529_CMD_REG_MASK;
+	cs5529_command(dev, CS5529_CMD_CB | reg_select_bits);
 	if (cs5529_wait_for_idle(dev))
 		dev_err(dev->class_dev,
 			"timeout or signal in %s\n", __func__);
@@ -4587,14 +4587,14 @@ static int init_cs5529(struct comedi_device *dev)
 #if 1
 	/* do self-calibration */
 	cs5529_config_write(dev, config_bits | CS5529_CFG_CALIB_BOTH_SELF,
-			    CSCMD_CONFIG_REGISTER);
+			    CS5529_CFG_REG);
 	/* need to force a conversion for calibration to run */
 	cs5529_do_conversion(dev, NULL);
 #else
 	/* force gain calibration to 1 */
-	cs5529_config_write(dev, 0x400000, CSCMD_GAIN_REGISTER);
+	cs5529_config_write(dev, 0x400000, CS5529_GAIN_REG);
 	cs5529_config_write(dev, config_bits | CS5529_CFG_CALIB_OFFSET_SELF,
-			    CSCMD_CONFIG_REGISTER);
+			    CS5529_CFG_REG);
 	if (cs5529_wait_for_idle(dev))
 		dev_err(dev->class_dev,
 			"timeout or signal in %s\n", __func__);
diff --git a/drivers/staging/comedi/drivers/ni_stc.h b/drivers/staging/comedi/drivers/ni_stc.h
index 3d1fd9b..0013e30 100644
--- a/drivers/staging/comedi/drivers/ni_stc.h
+++ b/drivers/staging/comedi/drivers/ni_stc.h
@@ -677,6 +677,20 @@ enum AO_Misc_611x_Bits {
 	CLEAR_WG = 1,
 };
 
+#define CS5529_CMD_CB			BIT(7)
+#define CS5529_CMD_SINGLE_CONV		BIT(6)
+#define CS5529_CMD_CONT_CONV		BIT(5)
+#define CS5529_CMD_READ			BIT(4)
+#define CS5529_CMD_REG(x)		(((x) & 0x7) << 1)
+#define CS5529_CMD_REG_MASK		CS5529_CMD_REG(7)
+#define CS5529_CMD_PWR_SAVE		BIT(0)
+
+#define CS5529_OFFSET_REG		CS5529_CMD_REG(0)
+#define CS5529_GAIN_REG			CS5529_CMD_REG(1)
+#define CS5529_CONV_DATA_REG		CS5529_CMD_REG(3)
+#define CS5529_SETUP_REG		CS5529_CMD_REG(4)
+
+#define CS5529_CFG_REG			CS5529_CMD_REG(2)
 #define CS5529_CFG_AOUT(x)		BIT(22 + (x))
 #define CS5529_CFG_DOUT(x)		BIT(18 + (x))
 #define CS5529_CFG_LOW_PWR_MODE		BIT(16)
@@ -704,17 +718,6 @@ enum AO_Misc_611x_Bits {
 #define CS5529_CFG_CALIB_OFFSET_SYS	CS5529_CFG_CALIB(5)
 #define CS5529_CFG_CALIB_GAIN_SYS	CS5529_CFG_CALIB(6)
 
-enum cs5529_command_bits {
-	CSCMD_POWER_SAVE = 0x1,
-	CSCMD_REGISTER_SELECT_MASK = 0xe,
-	CSCMD_OFFSET_REGISTER = 0x0,
-	CSCMD_GAIN_REGISTER = 0x2,
-	CSCMD_CONFIG_REGISTER = 0x4,
-	CSCMD_READ = 0x10,
-	CSCMD_CONTINUOUS_CONVERSIONS = 0x20,
-	CSCMD_SINGLE_CONVERSION = 0x40,
-	CSCMD_COMMAND = 0x80,
-};
 enum cs5529_status_bits {
 	CSS_ADC_BUSY = 0x1,
 	CSS_OSC_DETECT = 0x2,	/* indicates adc error */
-- 
2.3.0



More information about the devel mailing list