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.

Input: rohm_bu21023 - factor out settings update code

The code to toggle axis swapping and inversion is repetitive and can
be factored out.

Link: https://lore.kernel.org/r/20240609235134.614592-1-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+29 -48
+29 -48
drivers/input/touchscreen/rohm_bu21023.c
··· 727 727 return error ? error : error2; 728 728 } 729 729 730 + static int rohm_ts_update_setting(struct rohm_ts_data *ts, 731 + unsigned int setting_bit, bool on) 732 + { 733 + int error; 734 + 735 + error = mutex_lock_interruptible(&ts->input->mutex); 736 + if (error) 737 + return error; 738 + 739 + if (on) 740 + ts->setup2 |= setting_bit; 741 + else 742 + ts->setup2 &= ~setting_bit; 743 + 744 + if (ts->initialized) 745 + error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2, 746 + ts->setup2); 747 + 748 + mutex_unlock(&ts->input->mutex); 749 + 750 + return error; 751 + } 752 + 730 753 static ssize_t swap_xy_show(struct device *dev, struct device_attribute *attr, 731 754 char *buf) 732 755 { ··· 771 748 if (error) 772 749 return error; 773 750 774 - error = mutex_lock_interruptible(&ts->input->mutex); 775 - if (error) 776 - return error; 777 - 778 - if (val) 779 - ts->setup2 |= SWAP_XY; 780 - else 781 - ts->setup2 &= ~SWAP_XY; 782 - 783 - if (ts->initialized) 784 - error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2, 785 - ts->setup2); 786 - 787 - mutex_unlock(&ts->input->mutex); 788 - 789 - return error ? error : count; 751 + error = rohm_ts_update_setting(ts, SWAP_XY, val); 752 + return error ?: count; 790 753 } 791 754 792 755 static ssize_t inv_x_show(struct device *dev, struct device_attribute *attr, ··· 796 787 if (error) 797 788 return error; 798 789 799 - error = mutex_lock_interruptible(&ts->input->mutex); 800 - if (error) 801 - return error; 802 - 803 - if (val) 804 - ts->setup2 |= INV_X; 805 - else 806 - ts->setup2 &= ~INV_X; 807 - 808 - if (ts->initialized) 809 - error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2, 810 - ts->setup2); 811 - 812 - mutex_unlock(&ts->input->mutex); 813 - 814 - return error ? error : count; 790 + error = rohm_ts_update_setting(ts, INV_X, val); 791 + return error ?: count; 815 792 } 816 793 817 794 static ssize_t inv_y_show(struct device *dev, struct device_attribute *attr, ··· 821 826 if (error) 822 827 return error; 823 828 824 - error = mutex_lock_interruptible(&ts->input->mutex); 825 - if (error) 826 - return error; 827 - 828 - if (val) 829 - ts->setup2 |= INV_Y; 830 - else 831 - ts->setup2 &= ~INV_Y; 832 - 833 - if (ts->initialized) 834 - error = i2c_smbus_write_byte_data(client, COMMON_SETUP2, 835 - ts->setup2); 836 - 837 - mutex_unlock(&ts->input->mutex); 838 - 839 - return error ? error : count; 829 + error = rohm_ts_update_setting(ts, INV_Y, val); 830 + return error ?: count; 840 831 } 841 832 842 833 static DEVICE_ATTR_RW(swap_xy);