Skip to content

Commit 09f6109

Browse files
committed
Merge tag 'iio-fixes-for-5.3a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus
Jonathan writes: First set of IIO fixes in the 5.3 cycle. * cros_ec_accel_legacy - Fix a false double entry for channel scale as both per channel and shared. * gyro_adc - Fix uninitialized return code that got detected by GCC 9.0 having be previously missed. * ingenic_adc - Set the clock divider on probe to avoid an issue seen with false button press detections on JZ4725B SoCs. * max9611 - Backwards parameters in GENMASK. * mpu6050 - Enforce the fact only certain scan modes are actually possible. One counter fix also picked up for William, * generic-counter.rst - Fix some references. * tag 'iio-fixes-for-5.3a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: iio: adc: gyroadc: fix uninitialized return code docs: generic-counter.rst: fix broken references for ABI file iio: imu: mpu6050: add missing available scan masks iio: cros_ec_accel_legacy: Fix incorrect channel setting IIO: Ingenic JZ47xx: Set clock divider on probe iio: adc: max9611: Fix misuse of GENMASK macro
2 parents 8f9e86e + 90c6260 commit 09f6109

6 files changed

Lines changed: 102 additions & 6 deletions

File tree

‎Documentation/driver-api/generic-counter.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Userspace Interface
233233
Several sysfs attributes are generated by the Generic Counter interface,
234234
and reside under the /sys/bus/counter/devices/counterX directory, where
235235
counterX refers to the respective counter device. Please see
236-
Documentation/ABI/testing/sys-bus-counter-generic-sysfs for detailed
236+
Documentation/ABI/testing/sysfs-bus-counter for detailed
237237
information on each Generic Counter interface sysfs attribute.
238238

239239
Through these sysfs attributes, programs and scripts may interact with
@@ -325,7 +325,7 @@ sysfs attributes, where Y is the unique ID of the respective Count:
325325

326326
For a more detailed breakdown of the available Generic Counter interface
327327
sysfs attributes, please refer to the
328-
Documentation/ABI/testing/sys-bus-counter file.
328+
Documentation/ABI/testing/sysfs-bus-counter file.
329329

330330
The Signals and Counts associated with the Counter device are registered
331331
to the system as well by the counter_register function. The

‎drivers/iio/accel/cros_ec_accel_legacy.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ static const struct iio_chan_spec_ext_info cros_ec_accel_legacy_ext_info[] = {
319319
.modified = 1, \
320320
.info_mask_separate = \
321321
BIT(IIO_CHAN_INFO_RAW) | \
322-
BIT(IIO_CHAN_INFO_SCALE) | \
323322
BIT(IIO_CHAN_INFO_CALIBBIAS), \
324323
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE), \
325324
.ext_info = cros_ec_accel_legacy_ext_info, \

‎drivers/iio/adc/ingenic-adc.c‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/iio/iio.h>
1212
#include <linux/io.h>
1313
#include <linux/iopoll.h>
14+
#include <linux/kernel.h>
1415
#include <linux/module.h>
1516
#include <linux/mutex.h>
1617
#include <linux/platform_device.h>
@@ -22,8 +23,11 @@
2223
#define JZ_ADC_REG_ADTCH 0x18
2324
#define JZ_ADC_REG_ADBDAT 0x1c
2425
#define JZ_ADC_REG_ADSDAT 0x20
26+
#define JZ_ADC_REG_ADCLK 0x28
2527

2628
#define JZ_ADC_REG_CFG_BAT_MD BIT(4)
29+
#define JZ_ADC_REG_ADCLK_CLKDIV_LSB 0
30+
#define JZ_ADC_REG_ADCLK_CLKDIV10US_LSB 16
2731

2832
#define JZ_ADC_AUX_VREF 3300
2933
#define JZ_ADC_AUX_VREF_BITS 12
@@ -34,13 +38,16 @@
3438
#define JZ4740_ADC_BATTERY_HIGH_VREF (7500 * 0.986)
3539
#define JZ4740_ADC_BATTERY_HIGH_VREF_BITS 12
3640

41+
struct ingenic_adc;
42+
3743
struct ingenic_adc_soc_data {
3844
unsigned int battery_high_vref;
3945
unsigned int battery_high_vref_bits;
4046
const int *battery_raw_avail;
4147
size_t battery_raw_avail_size;
4248
const int *battery_scale_avail;
4349
size_t battery_scale_avail_size;
50+
int (*init_clk_div)(struct device *dev, struct ingenic_adc *adc);
4451
};
4552

4653
struct ingenic_adc {
@@ -151,13 +158,50 @@ static const int jz4740_adc_battery_scale_avail[] = {
151158
JZ_ADC_BATTERY_LOW_VREF, JZ_ADC_BATTERY_LOW_VREF_BITS,
152159
};
153160

161+
static int jz4725b_adc_init_clk_div(struct device *dev, struct ingenic_adc *adc)
162+
{
163+
struct clk *parent_clk;
164+
unsigned long parent_rate, rate;
165+
unsigned int div_main, div_10us;
166+
167+
parent_clk = clk_get_parent(adc->clk);
168+
if (!parent_clk) {
169+
dev_err(dev, "ADC clock has no parent\n");
170+
return -ENODEV;
171+
}
172+
parent_rate = clk_get_rate(parent_clk);
173+
174+
/*
175+
* The JZ4725B ADC works at 500 kHz to 8 MHz.
176+
* We pick the highest rate possible.
177+
* In practice we typically get 6 MHz, half of the 12 MHz EXT clock.
178+
*/
179+
div_main = DIV_ROUND_UP(parent_rate, 8000000);
180+
div_main = clamp(div_main, 1u, 64u);
181+
rate = parent_rate / div_main;
182+
if (rate < 500000 || rate > 8000000) {
183+
dev_err(dev, "No valid divider for ADC main clock\n");
184+
return -EINVAL;
185+
}
186+
187+
/* We also need a divider that produces a 10us clock. */
188+
div_10us = DIV_ROUND_UP(rate, 100000);
189+
190+
writel(((div_10us - 1) << JZ_ADC_REG_ADCLK_CLKDIV10US_LSB) |
191+
(div_main - 1) << JZ_ADC_REG_ADCLK_CLKDIV_LSB,
192+
adc->base + JZ_ADC_REG_ADCLK);
193+
194+
return 0;
195+
}
196+
154197
static const struct ingenic_adc_soc_data jz4725b_adc_soc_data = {
155198
.battery_high_vref = JZ4725B_ADC_BATTERY_HIGH_VREF,
156199
.battery_high_vref_bits = JZ4725B_ADC_BATTERY_HIGH_VREF_BITS,
157200
.battery_raw_avail = jz4725b_adc_battery_raw_avail,
158201
.battery_raw_avail_size = ARRAY_SIZE(jz4725b_adc_battery_raw_avail),
159202
.battery_scale_avail = jz4725b_adc_battery_scale_avail,
160203
.battery_scale_avail_size = ARRAY_SIZE(jz4725b_adc_battery_scale_avail),
204+
.init_clk_div = jz4725b_adc_init_clk_div,
161205
};
162206

163207
static const struct ingenic_adc_soc_data jz4740_adc_soc_data = {
@@ -167,6 +211,7 @@ static const struct ingenic_adc_soc_data jz4740_adc_soc_data = {
167211
.battery_raw_avail_size = ARRAY_SIZE(jz4740_adc_battery_raw_avail),
168212
.battery_scale_avail = jz4740_adc_battery_scale_avail,
169213
.battery_scale_avail_size = ARRAY_SIZE(jz4740_adc_battery_scale_avail),
214+
.init_clk_div = NULL, /* no ADCLK register on JZ4740 */
170215
};
171216

172217
static int ingenic_adc_read_avail(struct iio_dev *iio_dev,
@@ -317,6 +362,15 @@ static int ingenic_adc_probe(struct platform_device *pdev)
317362
return ret;
318363
}
319364

365+
/* Set clock dividers. */
366+
if (soc_data->init_clk_div) {
367+
ret = soc_data->init_clk_div(dev, adc);
368+
if (ret) {
369+
clk_disable_unprepare(adc->clk);
370+
return ret;
371+
}
372+
}
373+
320374
/* Put hardware in a known passive state. */
321375
writeb(0x00, adc->base + JZ_ADC_REG_ENABLE);
322376
writeb(0xff, adc->base + JZ_ADC_REG_CTRL);

‎drivers/iio/adc/max9611.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
#define MAX9611_TEMP_MAX_POS 0x7f80
8484
#define MAX9611_TEMP_MAX_NEG 0xff80
8585
#define MAX9611_TEMP_MIN_NEG 0xd980
86-
#define MAX9611_TEMP_MASK GENMASK(7, 15)
86+
#define MAX9611_TEMP_MASK GENMASK(15, 7)
8787
#define MAX9611_TEMP_SHIFT 0x07
8888
#define MAX9611_TEMP_RAW(_r) ((_r) >> MAX9611_TEMP_SHIFT)
8989
#define MAX9611_TEMP_SCALE_NUM 1000000

‎drivers/iio/adc/rcar-gyroadc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev)
382382
dev_err(dev,
383383
"Only %i channels supported with %pOFn, but reg = <%i>.\n",
384384
num_channels, child, reg);
385-
return ret;
385+
return -EINVAL;
386386
}
387387
}
388388

@@ -391,7 +391,7 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev)
391391
dev_err(dev,
392392
"Channel %i uses different ADC mode than the rest.\n",
393393
reg);
394-
return ret;
394+
return -EINVAL;
395395
}
396396

397397
/* Channel is valid, grab the regulator. */

‎drivers/iio/imu/inv_mpu6050/inv_mpu_core.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,25 @@ static const struct iio_chan_spec inv_mpu_channels[] = {
845845
INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z),
846846
};
847847

848+
static const unsigned long inv_mpu_scan_masks[] = {
849+
/* 3-axis accel */
850+
BIT(INV_MPU6050_SCAN_ACCL_X)
851+
| BIT(INV_MPU6050_SCAN_ACCL_Y)
852+
| BIT(INV_MPU6050_SCAN_ACCL_Z),
853+
/* 3-axis gyro */
854+
BIT(INV_MPU6050_SCAN_GYRO_X)
855+
| BIT(INV_MPU6050_SCAN_GYRO_Y)
856+
| BIT(INV_MPU6050_SCAN_GYRO_Z),
857+
/* 6-axis accel + gyro */
858+
BIT(INV_MPU6050_SCAN_ACCL_X)
859+
| BIT(INV_MPU6050_SCAN_ACCL_Y)
860+
| BIT(INV_MPU6050_SCAN_ACCL_Z)
861+
| BIT(INV_MPU6050_SCAN_GYRO_X)
862+
| BIT(INV_MPU6050_SCAN_GYRO_Y)
863+
| BIT(INV_MPU6050_SCAN_GYRO_Z),
864+
0,
865+
};
866+
848867
static const struct iio_chan_spec inv_icm20602_channels[] = {
849868
IIO_CHAN_SOFT_TIMESTAMP(INV_ICM20602_SCAN_TIMESTAMP),
850869
{
@@ -871,6 +890,28 @@ static const struct iio_chan_spec inv_icm20602_channels[] = {
871890
INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_ICM20602_SCAN_ACCL_Z),
872891
};
873892

893+
static const unsigned long inv_icm20602_scan_masks[] = {
894+
/* 3-axis accel + temp (mandatory) */
895+
BIT(INV_ICM20602_SCAN_ACCL_X)
896+
| BIT(INV_ICM20602_SCAN_ACCL_Y)
897+
| BIT(INV_ICM20602_SCAN_ACCL_Z)
898+
| BIT(INV_ICM20602_SCAN_TEMP),
899+
/* 3-axis gyro + temp (mandatory) */
900+
BIT(INV_ICM20602_SCAN_GYRO_X)
901+
| BIT(INV_ICM20602_SCAN_GYRO_Y)
902+
| BIT(INV_ICM20602_SCAN_GYRO_Z)
903+
| BIT(INV_ICM20602_SCAN_TEMP),
904+
/* 6-axis accel + gyro + temp (mandatory) */
905+
BIT(INV_ICM20602_SCAN_ACCL_X)
906+
| BIT(INV_ICM20602_SCAN_ACCL_Y)
907+
| BIT(INV_ICM20602_SCAN_ACCL_Z)
908+
| BIT(INV_ICM20602_SCAN_GYRO_X)
909+
| BIT(INV_ICM20602_SCAN_GYRO_Y)
910+
| BIT(INV_ICM20602_SCAN_GYRO_Z)
911+
| BIT(INV_ICM20602_SCAN_TEMP),
912+
0,
913+
};
914+
874915
/*
875916
* The user can choose any frequency between INV_MPU6050_MIN_FIFO_RATE and
876917
* INV_MPU6050_MAX_FIFO_RATE, but only these frequencies are matched by the
@@ -1130,9 +1171,11 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
11301171
if (chip_type == INV_ICM20602) {
11311172
indio_dev->channels = inv_icm20602_channels;
11321173
indio_dev->num_channels = ARRAY_SIZE(inv_icm20602_channels);
1174+
indio_dev->available_scan_masks = inv_icm20602_scan_masks;
11331175
} else {
11341176
indio_dev->channels = inv_mpu_channels;
11351177
indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels);
1178+
indio_dev->available_scan_masks = inv_mpu_scan_masks;
11361179
}
11371180

11381181
indio_dev->info = &mpu_info;

0 commit comments

Comments
 (0)