Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: adc: aspeed: completes the bitfield declare.

This patch completes the declare of ADC register bitfields and uses the
same prefix ASPEED_ADC_* for these bitfields. In addition, tidy up space
alignment of the codes.

Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
Link: https://lore.kernel.org/r/20210831071458.2334-4-billy_tsai@aspeedtech.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Billy Tsai and committed by
Jonathan Cameron
26a9f730 2bdb2f00

+46 -16
+46 -16
drivers/iio/adc/aspeed_adc.c
··· 3 3 * Aspeed AST2400/2500 ADC 4 4 * 5 5 * Copyright (C) 2017 Google, Inc. 6 + * Copyright (C) 2021 Aspeed Technology Inc. 6 7 */ 7 8 8 9 #include <linux/clk.h> ··· 17 16 #include <linux/reset.h> 18 17 #include <linux/spinlock.h> 19 18 #include <linux/types.h> 19 + #include <linux/bitfield.h> 20 20 21 21 #include <linux/iio/iio.h> 22 22 #include <linux/iio/driver.h> ··· 30 28 #define ASPEED_REG_INTERRUPT_CONTROL 0x04 31 29 #define ASPEED_REG_VGA_DETECT_CONTROL 0x08 32 30 #define ASPEED_REG_CLOCK_CONTROL 0x0C 33 - #define ASPEED_REG_MAX 0xC0 31 + #define ASPEED_REG_COMPENSATION_TRIM 0xC4 32 + /* 33 + * The register offset between 0xC8~0xCC can be read and won't affect the 34 + * hardware logic in each version of ADC. 35 + */ 36 + #define ASPEED_REG_MAX 0xD0 34 37 35 - #define ASPEED_OPERATION_MODE_POWER_DOWN (0x0 << 1) 36 - #define ASPEED_OPERATION_MODE_STANDBY (0x1 << 1) 37 - #define ASPEED_OPERATION_MODE_NORMAL (0x7 << 1) 38 - 39 - #define ASPEED_ENGINE_ENABLE BIT(0) 40 - 41 - #define ASPEED_ADC_CTRL_INIT_RDY BIT(8) 38 + #define ASPEED_ADC_ENGINE_ENABLE BIT(0) 39 + #define ASPEED_ADC_OP_MODE GENMASK(3, 1) 40 + #define ASPEED_ADC_OP_MODE_PWR_DOWN 0 41 + #define ASPEED_ADC_OP_MODE_STANDBY 1 42 + #define ASPEED_ADC_OP_MODE_NORMAL 7 43 + #define ASPEED_ADC_CTRL_COMPENSATION BIT(4) 44 + #define ASPEED_ADC_AUTO_COMPENSATION BIT(5) 45 + /* 46 + * Bit 6 determines not only the reference voltage range but also the dividing 47 + * circuit for battery sensing. 48 + */ 49 + #define ASPEED_ADC_REF_VOLTAGE GENMASK(7, 6) 50 + #define ASPEED_ADC_REF_VOLTAGE_2500mV 0 51 + #define ASPEED_ADC_REF_VOLTAGE_1200mV 1 52 + #define ASPEED_ADC_REF_VOLTAGE_EXT_HIGH 2 53 + #define ASPEED_ADC_REF_VOLTAGE_EXT_LOW 3 54 + #define ASPEED_ADC_BAT_SENSING_DIV BIT(6) 55 + #define ASPEED_ADC_BAT_SENSING_DIV_2_3 0 56 + #define ASPEED_ADC_BAT_SENSING_DIV_1_3 1 57 + #define ASPEED_ADC_CTRL_INIT_RDY BIT(8) 58 + #define ASPEED_ADC_CH7_MODE BIT(12) 59 + #define ASPEED_ADC_CH7_NORMAL 0 60 + #define ASPEED_ADC_CH7_BAT 1 61 + #define ASPEED_ADC_BAT_SENSING_ENABLE BIT(13) 62 + #define ASPEED_ADC_CTRL_CHANNEL GENMASK(31, 16) 63 + #define ASPEED_ADC_CTRL_CHANNEL_ENABLE(ch) FIELD_PREP(ASPEED_ADC_CTRL_CHANNEL, BIT(ch)) 42 64 43 65 #define ASPEED_ADC_INIT_POLLING_TIME 500 44 66 #define ASPEED_ADC_INIT_TIMEOUT 500000 ··· 252 226 253 227 if (model_data->wait_init_sequence) { 254 228 /* Enable engine in normal mode. */ 255 - writel(ASPEED_OPERATION_MODE_NORMAL | ASPEED_ENGINE_ENABLE, 229 + writel(FIELD_PREP(ASPEED_ADC_OP_MODE, 230 + ASPEED_ADC_OP_MODE_NORMAL) | 231 + ASPEED_ADC_ENGINE_ENABLE, 256 232 data->base + ASPEED_REG_ENGINE_CONTROL); 257 233 258 234 /* Wait for initial sequence complete. */ ··· 273 245 if (ret) 274 246 goto clk_enable_error; 275 247 276 - adc_engine_control_reg_val = GENMASK(31, 16) | 277 - ASPEED_OPERATION_MODE_NORMAL | ASPEED_ENGINE_ENABLE; 248 + adc_engine_control_reg_val = 249 + ASPEED_ADC_CTRL_CHANNEL | 250 + FIELD_PREP(ASPEED_ADC_OP_MODE, ASPEED_ADC_OP_MODE_NORMAL) | 251 + ASPEED_ADC_ENGINE_ENABLE; 278 252 writel(adc_engine_control_reg_val, 279 - data->base + ASPEED_REG_ENGINE_CONTROL); 253 + data->base + ASPEED_REG_ENGINE_CONTROL); 280 254 281 255 model_data = of_device_get_match_data(&pdev->dev); 282 256 indio_dev->name = model_data->model_name; ··· 294 264 return 0; 295 265 296 266 iio_register_error: 297 - writel(ASPEED_OPERATION_MODE_POWER_DOWN, 298 - data->base + ASPEED_REG_ENGINE_CONTROL); 267 + writel(FIELD_PREP(ASPEED_ADC_OP_MODE, ASPEED_ADC_OP_MODE_PWR_DOWN), 268 + data->base + ASPEED_REG_ENGINE_CONTROL); 299 269 clk_disable_unprepare(data->clk_scaler->clk); 300 270 clk_enable_error: 301 271 poll_timeout_error: ··· 313 283 struct aspeed_adc_data *data = iio_priv(indio_dev); 314 284 315 285 iio_device_unregister(indio_dev); 316 - writel(ASPEED_OPERATION_MODE_POWER_DOWN, 317 - data->base + ASPEED_REG_ENGINE_CONTROL); 286 + writel(FIELD_PREP(ASPEED_ADC_OP_MODE, ASPEED_ADC_OP_MODE_PWR_DOWN), 287 + data->base + ASPEED_REG_ENGINE_CONTROL); 318 288 clk_disable_unprepare(data->clk_scaler->clk); 319 289 reset_control_assert(data->rst); 320 290 clk_hw_unregister_divider(data->clk_scaler);