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

Configure Feed

Select the types of activity you want to include in your feed.

iio: light: tsl2563: Configure INT in one place

Introduce tsl2563_configure_irq() to configure INT in one place.

While at it, make use of TSL2563_INT_LEVEL and newly introduced
TSL2563_INT_MASK.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Ferry Toth <ftoth@exalondelft.nl>
Link: https://lore.kernel.org/r/20221207190348.9347-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Andy Shevchenko and committed by
Jonathan Cameron
aca68c02 3c183534

+25 -17
+25 -17
drivers/iio/light/tsl2563.c
··· 69 69 70 70 #define TSL2563_INT_DISABLED 0x00 71 71 #define TSL2563_INT_LEVEL 0x10 72 + #define TSL2563_INT_MASK 0x30 72 73 #define TSL2563_INT_PERSIST(n) ((n) & 0x0F) 73 74 74 75 struct tsl2563_gainlevel_coeff { ··· 209 208 210 209 *id = ret; 211 210 211 + return 0; 212 + } 213 + 214 + static int tsl2563_configure_irq(struct tsl2563_chip *chip, bool enable) 215 + { 216 + int ret; 217 + 218 + chip->intr &= ~TSL2563_INT_MASK; 219 + if (enable) 220 + chip->intr |= TSL2563_INT_LEVEL; 221 + 222 + ret = i2c_smbus_write_byte_data(chip->client, 223 + TSL2563_CMD | TSL2563_REG_INT, 224 + chip->intr); 225 + if (ret < 0) 226 + return ret; 227 + 228 + chip->int_enabled = enable; 212 229 return 0; 213 230 } 214 231 ··· 639 620 int ret = 0; 640 621 641 622 mutex_lock(&chip->lock); 642 - if (state && !(chip->intr & 0x30)) { 643 - chip->intr &= ~0x30; 644 - chip->intr |= 0x10; 623 + if (state && !(chip->intr & TSL2563_INT_MASK)) { 645 624 /* ensure the chip is actually on */ 646 625 cancel_delayed_work_sync(&chip->poweroff_work); 647 626 if (!tsl2563_get_power(chip)) { ··· 650 633 if (ret) 651 634 goto out; 652 635 } 653 - ret = i2c_smbus_write_byte_data(chip->client, 654 - TSL2563_CMD | TSL2563_REG_INT, 655 - chip->intr); 656 - chip->int_enabled = true; 636 + ret = tsl2563_configure_irq(chip, true); 657 637 } 658 638 659 - if (!state && (chip->intr & 0x30)) { 660 - chip->intr &= ~0x30; 661 - ret = i2c_smbus_write_byte_data(chip->client, 662 - TSL2563_CMD | TSL2563_REG_INT, 663 - chip->intr); 664 - chip->int_enabled = false; 639 + if (!state && (chip->intr & TSL2563_INT_MASK)) { 640 + ret = tsl2563_configure_irq(chip, false); 665 641 /* now the interrupt is not enabled, we can go to sleep */ 666 642 schedule_delayed_work(&chip->poweroff_work, 5 * HZ); 667 643 } ··· 678 668 if (ret < 0) 679 669 return ret; 680 670 681 - return !!(ret & 0x30); 671 + return !!(ret & TSL2563_INT_MASK); 682 672 } 683 673 684 674 static const struct iio_info tsl2563_info_no_irq = { ··· 806 796 if (!chip->int_enabled) 807 797 cancel_delayed_work_sync(&chip->poweroff_work); 808 798 /* Ensure that interrupts are disabled - then flush any bottom halves */ 809 - chip->intr &= ~0x30; 810 - i2c_smbus_write_byte_data(chip->client, TSL2563_CMD | TSL2563_REG_INT, 811 - chip->intr); 799 + tsl2563_configure_irq(chip, false); 812 800 tsl2563_set_power(chip, 0); 813 801 } 814 802