Merge tag 'char-misc-6.3-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc

Pull char/misc driver fixes from Greg KH:
"Here are a small set of various small driver changes for 6.3-rc6.
Included in here are:

- iio driver fixes for reported problems

- coresight hwtracing bugfix for reported problem

- small counter driver bugfixes

All have been in linux-next for a while with no reported problems"

* tag 'char-misc-6.3-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc:
coresight: etm4x: Do not access TRCIDR1 for identification
coresight-etm4: Fix for() loop drvdata->nr_addr_cmp range bug
iio: adc: ti-ads7950: Set `can_sleep` flag for GPIO chip
iio: adc: palmas_gpadc: fix NULL dereference on rmmod
counter: 104-quad-8: Fix Synapse action reported for Index signals
counter: 104-quad-8: Fix race condition between FLAG and CNTR reads
iio: adc: max11410: fix read_poll_timeout() usage
iio: dac: cio-dac: Fix max DAC write value check for 12-bit
iio: light: cm32181: Unregister second I2C client if present
iio: accel: kionix-kx022a: Get the timestamp from the driver's private data in the trigger_handler
iio: adc: ad7791: fix IRQ flags
iio: buffer: make sure O_NONBLOCK is respected
iio: buffer: correctly return bytes written in output buffers
iio: light: vcnl4000: Fix WARN_ON on uninitialized lock
iio: adis16480: select CONFIG_CRC32
drivers: iio: adc: ltc2497: fix LSB shift
iio: adc: qcom-spmi-adc5: Fix the channel name

+9 -22
drivers/counter/104-quad-8.c
··· 97 97 struct quad8_reg __iomem *reg; 98 98 }; 99 99 100 - /* Borrow Toggle flip-flop */ 101 - #define QUAD8_FLAG_BT BIT(0) 102 - /* Carry Toggle flip-flop */ 103 - #define QUAD8_FLAG_CT BIT(1) 104 100 /* Error flag */ 105 101 #define QUAD8_FLAG_E BIT(4) 106 102 /* Up/Down flag */ ··· 129 133 #define QUAD8_CMR_QUADRATURE_X2 0x10 130 134 #define QUAD8_CMR_QUADRATURE_X4 0x18 131 135 136 + /* Each Counter is 24 bits wide */ 137 + #define LS7267_CNTR_MAX GENMASK(23, 0) 138 + 132 139 static int quad8_signal_read(struct counter_device *counter, 133 140 struct counter_signal *signal, 134 141 enum counter_signal_level *level) ··· 155 156 { 156 157 struct quad8 *const priv = counter_priv(counter); 157 158 struct channel_reg __iomem *const chan = priv->reg->channel + count->id; 158 - unsigned int flags; 159 - unsigned int borrow; 160 - unsigned int carry; 161 159 unsigned long irqflags; 162 160 int i; 163 161 164 - flags = ioread8(&chan->control); 165 - borrow = flags & QUAD8_FLAG_BT; 166 - carry = !!(flags & QUAD8_FLAG_CT); 167 - 168 - /* Borrow XOR Carry effectively doubles count range */ 169 - *val = (unsigned long)(borrow ^ carry) << 24; 162 + *val = 0; 170 163 171 164 spin_lock_irqsave(&priv->lock, irqflags); 172 165 ··· 182 191 unsigned long irqflags; 183 192 int i; 184 193 185 - /* Only 24-bit values are supported */ 186 - if (val > 0xFFFFFF) 194 + if (val > LS7267_CNTR_MAX) 187 195 return -ERANGE; 188 196 189 197 spin_lock_irqsave(&priv->lock, irqflags); ··· 368 378 369 379 /* Handle Index signals */ 370 380 if (synapse->signal->id >= 16) { 371 - if (priv->preset_enable[count->id]) 381 + if (!priv->preset_enable[count->id]) 372 382 *action = COUNTER_SYNAPSE_ACTION_RISING_EDGE; 373 383 else 374 384 *action = COUNTER_SYNAPSE_ACTION_NONE; ··· 796 806 struct quad8 *const priv = counter_priv(counter); 797 807 unsigned long irqflags; 798 808 799 - /* Only 24-bit values are supported */ 800 - if (preset > 0xFFFFFF) 809 + if (preset > LS7267_CNTR_MAX) 801 810 return -ERANGE; 802 811 803 812 spin_lock_irqsave(&priv->lock, irqflags); ··· 823 834 *ceiling = priv->preset[count->id]; 824 835 break; 825 836 default: 826 - /* By default 0x1FFFFFF (25 bits unsigned) is maximum count */ 827 - *ceiling = 0x1FFFFFF; 837 + *ceiling = LS7267_CNTR_MAX; 828 838 break; 829 839 } 830 840 ··· 838 850 struct quad8 *const priv = counter_priv(counter); 839 851 unsigned long irqflags; 840 852 841 - /* Only 24-bit values are supported */ 842 - if (ceiling > 0xFFFFFF) 853 + if (ceiling > LS7267_CNTR_MAX) 843 854 return -ERANGE; 844 855 845 856 spin_lock_irqsave(&priv->lock, irqflags);
+10 -14
drivers/hwtracing/coresight/coresight-etm4x-core.c
··· 472 472 if (etm4x_sspcicrn_present(drvdata, i)) 473 473 etm4x_relaxed_write32(csa, config->ss_pe_cmp[i], TRCSSPCICRn(i)); 474 474 } 475 - for (i = 0; i < drvdata->nr_addr_cmp; i++) { 475 + for (i = 0; i < drvdata->nr_addr_cmp * 2; i++) { 476 476 etm4x_relaxed_write64(csa, config->addr_val[i], TRCACVRn(i)); 477 477 etm4x_relaxed_write64(csa, config->addr_acc[i], TRCACATRn(i)); 478 478 } ··· 1070 1070 struct csdev_access *csa) 1071 1071 { 1072 1072 u32 devarch = readl_relaxed(drvdata->base + TRCDEVARCH); 1073 - u32 idr1 = readl_relaxed(drvdata->base + TRCIDR1); 1074 1073 1075 1074 /* 1076 1075 * All ETMs must implement TRCDEVARCH to indicate that 1077 - * the component is an ETMv4. To support any broken 1078 - * implementations we fall back to TRCIDR1 check, which 1079 - * is not really reliable. 1076 + * the component is an ETMv4. Even though TRCIDR1 also 1077 + * contains the information, it is part of the "Trace" 1078 + * register and must be accessed with the OSLK cleared, 1079 + * with MMIO. But we cannot touch the OSLK until we are 1080 + * sure this is an ETM. So rely only on the TRCDEVARCH. 1080 1081 */ 1081 - if ((devarch & ETM_DEVARCH_ID_MASK) == ETM_DEVARCH_ETMv4x_ARCH) { 1082 - drvdata->arch = etm_devarch_to_arch(devarch); 1083 - } else { 1084 - pr_warn("CPU%d: ETM4x incompatible TRCDEVARCH: %x, falling back to TRCIDR1\n", 1085 - smp_processor_id(), devarch); 1086 - 1087 - if (ETM_TRCIDR1_ARCH_MAJOR(idr1) != ETM_TRCIDR1_ARCH_ETMv4) 1088 - return false; 1089 - drvdata->arch = etm_trcidr_to_arch(idr1); 1082 + if ((devarch & ETM_DEVARCH_ID_MASK) != ETM_DEVARCH_ETMv4x_ARCH) { 1083 + pr_warn_once("TRCDEVARCH doesn't match ETMv4 architecture\n"); 1084 + return false; 1090 1085 } 1091 1086 1087 + drvdata->arch = etm_devarch_to_arch(devarch); 1092 1088 *csa = CSDEV_ACCESS_IOMEM(drvdata->base); 1093 1089 return true; 1094 1090 }
+6 -14
drivers/hwtracing/coresight/coresight-etm4x.h
··· 753 753 * TRCDEVARCH - CoreSight architected register 754 754 * - Bits[15:12] - Major version 755 755 * - Bits[19:16] - Minor version 756 - * TRCIDR1 - ETM architected register 757 - * - Bits[11:8] - Major version 758 - * - Bits[7:4] - Minor version 759 - * We must rely on TRCDEVARCH for the version information, 760 - * however we don't want to break the support for potential 761 - * old implementations which might not implement it. Thus 762 - * we fall back to TRCIDR1 if TRCDEVARCH is not implemented 763 - * for memory mapped components. 756 + * 757 + * We must rely only on TRCDEVARCH for the version information. Even though, 758 + * TRCIDR1 also provides the architecture version, it is a "Trace" register 759 + * and as such must be accessed only with Trace power domain ON. This may 760 + * not be available at probe time. 761 + * 764 762 * Now to make certain decisions easier based on the version 765 763 * we use an internal representation of the version in the 766 764 * driver, as follows : ··· 782 784 { 783 785 return ETM_ARCH_VERSION(ETM_DEVARCH_ARCHID_ARCH_VER(devarch), 784 786 ETM_DEVARCH_REVISION(devarch)); 785 - } 786 - 787 - static inline u8 etm_trcidr_to_arch(u32 trcidr1) 788 - { 789 - return ETM_ARCH_VERSION(ETM_TRCIDR1_ARCH_MAJOR(trcidr1), 790 - ETM_TRCIDR1_ARCH_MINOR(trcidr1)); 791 787 } 792 788 793 789 enum etm_impdef_type {
+1 -1
drivers/iio/accel/kionix-kx022a.c
··· 864 864 if (ret < 0) 865 865 goto err_read; 866 866 867 - iio_push_to_buffers_with_timestamp(idev, data->buffer, pf->timestamp); 867 + iio_push_to_buffers_with_timestamp(idev, data->buffer, data->timestamp); 868 868 err_read: 869 869 iio_trigger_notify_done(idev->trig); 870 870
+1 -1
drivers/iio/adc/ad7791.c
··· 253 253 .has_registers = true, 254 254 .addr_shift = 4, 255 255 .read_mask = BIT(3), 256 - .irq_flags = IRQF_TRIGGER_LOW, 256 + .irq_flags = IRQF_TRIGGER_FALLING, 257 257 }; 258 258 259 259 static int ad7791_read_raw(struct iio_dev *indio_dev,
+2 -4
drivers/iio/adc/ltc2497.c
··· 28 28 struct ltc2497core_driverdata common_ddata; 29 29 struct i2c_client *client; 30 30 u32 recv_size; 31 - u32 sub_lsb; 32 31 /* 33 32 * DMA (thus cache coherency maintenance) may require the 34 33 * transfer buffers to live in their own cache lines. ··· 64 65 * equivalent to a sign extension. 65 66 */ 66 67 if (st->recv_size == 3) { 67 - *val = (get_unaligned_be24(st->data.d8) >> st->sub_lsb) 68 + *val = (get_unaligned_be24(st->data.d8) >> 6) 68 69 - BIT(ddata->chip_info->resolution + 1); 69 70 } else { 70 - *val = (be32_to_cpu(st->data.d32) >> st->sub_lsb) 71 + *val = (be32_to_cpu(st->data.d32) >> 6) 71 72 - BIT(ddata->chip_info->resolution + 1); 72 73 } 73 74 ··· 121 122 st->common_ddata.chip_info = chip_info; 122 123 123 124 resolution = chip_info->resolution; 124 - st->sub_lsb = 31 - (resolution + 1); 125 125 st->recv_size = BITS_TO_BYTES(resolution) + 1; 126 126 127 127 return ltc2497core_probe(dev, indio_dev);
+15 -7
drivers/iio/adc/max11410.c
··· 414 414 if (!ret) 415 415 return -ETIMEDOUT; 416 416 } else { 417 + int ret2; 418 + 417 419 /* Wait for status register Conversion Ready flag */ 418 - ret = read_poll_timeout(max11410_read_reg, ret, 419 - ret || (val & MAX11410_STATUS_CONV_READY_BIT), 420 + ret = read_poll_timeout(max11410_read_reg, ret2, 421 + ret2 || (val & MAX11410_STATUS_CONV_READY_BIT), 420 422 5000, MAX11410_CONVERSION_TIMEOUT_MS * 1000, 421 423 true, st, MAX11410_REG_STATUS, &val); 422 424 if (ret) 423 425 return ret; 426 + if (ret2) 427 + return ret2; 424 428 } 425 429 426 430 /* Read ADC Data */ ··· 855 851 856 852 static int max11410_calibrate(struct max11410_state *st, u32 cal_type) 857 853 { 858 - int ret, val; 854 + int ret, ret2, val; 859 855 860 856 ret = max11410_write_reg(st, MAX11410_REG_CAL_START, cal_type); 861 857 if (ret) 862 858 return ret; 863 859 864 860 /* Wait for status register Calibration Ready flag */ 865 - return read_poll_timeout(max11410_read_reg, ret, 866 - ret || (val & MAX11410_STATUS_CAL_READY_BIT), 867 - 50000, MAX11410_CALIB_TIMEOUT_MS * 1000, true, 868 - st, MAX11410_REG_STATUS, &val); 861 + ret = read_poll_timeout(max11410_read_reg, ret2, 862 + ret2 || (val & MAX11410_STATUS_CAL_READY_BIT), 863 + 50000, MAX11410_CALIB_TIMEOUT_MS * 1000, true, 864 + st, MAX11410_REG_STATUS, &val); 865 + if (ret) 866 + return ret; 867 + 868 + return ret2; 869 869 } 870 870 871 871 static int max11410_self_calibrate(struct max11410_state *st)
+1 -1
drivers/iio/adc/palmas_gpadc.c
··· 639 639 640 640 static int palmas_gpadc_remove(struct platform_device *pdev) 641 641 { 642 - struct iio_dev *indio_dev = dev_to_iio_dev(&pdev->dev); 642 + struct iio_dev *indio_dev = dev_get_drvdata(&pdev->dev); 643 643 struct palmas_gpadc *adc = iio_priv(indio_dev); 644 644 645 645 if (adc->wakeup1_enable || adc->wakeup2_enable)
+9 -1
drivers/iio/adc/qcom-spmi-adc5.c
··· 628 628 struct fwnode_handle *fwnode, 629 629 const struct adc5_data *data) 630 630 { 631 - const char *name = fwnode_get_name(fwnode), *channel_name; 631 + const char *channel_name; 632 + char *name; 632 633 u32 chan, value, varr[2]; 633 634 u32 sid = 0; 634 635 int ret; 635 636 struct device *dev = adc->dev; 637 + 638 + name = devm_kasprintf(dev, GFP_KERNEL, "%pfwP", fwnode); 639 + if (!name) 640 + return -ENOMEM; 641 + 642 + /* Cut the address part */ 643 + name[strchrnul(name, '@') - name] = '\0'; 636 644 637 645 ret = fwnode_property_read_u32(fwnode, "reg", &chan); 638 646 if (ret) {
+1
drivers/iio/adc/ti-ads7950.c
··· 634 634 st->chip.label = dev_name(&st->spi->dev); 635 635 st->chip.parent = &st->spi->dev; 636 636 st->chip.owner = THIS_MODULE; 637 + st->chip.can_sleep = true; 637 638 st->chip.base = -1; 638 639 st->chip.ngpio = TI_ADS7950_NUM_GPIOS; 639 640 st->chip.get_direction = ti_ads7950_get_direction;
+2 -2
drivers/iio/dac/cio-dac.c
··· 66 66 if (mask != IIO_CHAN_INFO_RAW) 67 67 return -EINVAL; 68 68 69 - /* DAC can only accept up to a 16-bit value */ 70 - if ((unsigned int)val > 65535) 69 + /* DAC can only accept up to a 12-bit value */ 70 + if ((unsigned int)val > 4095) 71 71 return -EINVAL; 72 72 73 73 priv->chan_out_states[chan->channel] = val;
+1
drivers/iio/imu/Kconfig
··· 47 47 depends on SPI 48 48 select IIO_ADIS_LIB 49 49 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER 50 + select CRC32 50 51 help 51 52 Say yes here to build support for Analog Devices ADIS16375, ADIS16480, 52 53 ADIS16485, ADIS16488 inertial sensors.
+12 -9
drivers/iio/industrialio-buffer.c
··· 203 203 break; 204 204 } 205 205 206 + if (filp->f_flags & O_NONBLOCK) { 207 + if (!written) 208 + ret = -EAGAIN; 209 + break; 210 + } 211 + 206 212 wait_woken(&wait, TASK_INTERRUPTIBLE, 207 213 MAX_SCHEDULE_TIMEOUT); 208 214 continue; 209 215 } 210 216 211 217 ret = rb->access->write(rb, n - written, buf + written); 212 - if (ret == 0 && (filp->f_flags & O_NONBLOCK)) 213 - ret = -EAGAIN; 218 + if (ret < 0) 219 + break; 214 220 215 - if (ret > 0) { 216 - written += ret; 217 - if (written != n && !(filp->f_flags & O_NONBLOCK)) 218 - continue; 219 - } 220 - } while (ret == 0); 221 + written += ret; 222 + 223 + } while (written != n); 221 224 remove_wait_queue(&rb->pollq, &wait); 222 225 223 - return ret < 0 ? ret : n; 226 + return ret < 0 ? ret : written; 224 227 } 225 228 226 229 /**
+12
drivers/iio/light/cm32181.c
··· 429 429 .attrs = &cm32181_attribute_group, 430 430 }; 431 431 432 + static void cm32181_unregister_dummy_client(void *data) 433 + { 434 + struct i2c_client *client = data; 435 + 436 + /* Unregister the dummy client */ 437 + i2c_unregister_device(client); 438 + } 439 + 432 440 static int cm32181_probe(struct i2c_client *client) 433 441 { 434 442 struct device *dev = &client->dev; ··· 468 460 client = i2c_acpi_new_device(dev, 1, &board_info); 469 461 if (IS_ERR(client)) 470 462 return PTR_ERR(client); 463 + 464 + ret = devm_add_action_or_reset(dev, cm32181_unregister_dummy_client, client); 465 + if (ret) 466 + return ret; 471 467 } 472 468 473 469 cm32181 = iio_priv(indio_dev);
+2 -1
drivers/iio/light/vcnl4000.c
··· 208 208 209 209 data->rev = ret & 0xf; 210 210 data->al_scale = 250000; 211 - mutex_init(&data->vcnl4000_lock); 212 211 213 212 return data->chip_spec->set_power_state(data, true); 214 213 }; ··· 1365 1366 data->client = client; 1366 1367 data->id = id->driver_data; 1367 1368 data->chip_spec = &vcnl4000_chip_spec_cfg[data->id]; 1369 + 1370 + mutex_init(&data->vcnl4000_lock); 1368 1371 1369 1372 ret = data->chip_spec->init(data); 1370 1373 if (ret < 0)