Skip to content

Commit 4a56aea

Browse files
committed
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>
1 parent 03db842 commit 4a56aea

1 file changed

Lines changed: 29 additions & 48 deletions

File tree

drivers/input/touchscreen/rohm_bu21023.c

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,29 @@ static int rohm_ts_load_firmware(struct i2c_client *client,
727727
return error ? error : error2;
728728
}
729729

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+
730753
static ssize_t swap_xy_show(struct device *dev, struct device_attribute *attr,
731754
char *buf)
732755
{
@@ -748,22 +771,8 @@ static ssize_t swap_xy_store(struct device *dev, struct device_attribute *attr,
748771
if (error)
749772
return error;
750773

751-
error = mutex_lock_interruptible(&ts->input->mutex);
752-
if (error)
753-
return error;
754-
755-
if (val)
756-
ts->setup2 |= SWAP_XY;
757-
else
758-
ts->setup2 &= ~SWAP_XY;
759-
760-
if (ts->initialized)
761-
error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2,
762-
ts->setup2);
763-
764-
mutex_unlock(&ts->input->mutex);
765-
766-
return error ? error : count;
774+
error = rohm_ts_update_setting(ts, SWAP_XY, val);
775+
return error ?: count;
767776
}
768777

769778
static ssize_t inv_x_show(struct device *dev, struct device_attribute *attr,
@@ -787,22 +796,8 @@ static ssize_t inv_x_store(struct device *dev, struct device_attribute *attr,
787796
if (error)
788797
return error;
789798

790-
error = mutex_lock_interruptible(&ts->input->mutex);
791-
if (error)
792-
return error;
793-
794-
if (val)
795-
ts->setup2 |= INV_X;
796-
else
797-
ts->setup2 &= ~INV_X;
798-
799-
if (ts->initialized)
800-
error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2,
801-
ts->setup2);
802-
803-
mutex_unlock(&ts->input->mutex);
804-
805-
return error ? error : count;
799+
error = rohm_ts_update_setting(ts, INV_X, val);
800+
return error ?: count;
806801
}
807802

808803
static ssize_t inv_y_show(struct device *dev, struct device_attribute *attr,
@@ -826,22 +821,8 @@ static ssize_t inv_y_store(struct device *dev, struct device_attribute *attr,
826821
if (error)
827822
return error;
828823

829-
error = mutex_lock_interruptible(&ts->input->mutex);
830-
if (error)
831-
return error;
832-
833-
if (val)
834-
ts->setup2 |= INV_Y;
835-
else
836-
ts->setup2 &= ~INV_Y;
837-
838-
if (ts->initialized)
839-
error = i2c_smbus_write_byte_data(client, COMMON_SETUP2,
840-
ts->setup2);
841-
842-
mutex_unlock(&ts->input->mutex);
843-
844-
return error ? error : count;
824+
error = rohm_ts_update_setting(ts, INV_Y, val);
825+
return error ?: count;
845826
}
846827

847828
static DEVICE_ATTR_RW(swap_xy);

0 commit comments

Comments
 (0)