Skip to content

Commit 35839f7

Browse files
jwrdegoedebentiss
authored andcommitted
HID: logitech-hidpp: make hidpp10_set_register_bit a bit more generic
Make hidpp10_set_register_bit() take a mask and value for the register byte being changed, rather then making it only set a single bit. While at it also at defines for the bits which we will be using. Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 0610430 commit 35839f7

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

drivers/hid/hid-logitech-hidpp.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,14 +491,16 @@ static void hidpp_scroll_counter_handle_scroll(struct input_dev *input_dev,
491491
#define HIDPP_GET_LONG_REGISTER 0x83
492492

493493
/**
494-
* hidpp10_set_register_bit() - Sets a single bit in a HID++ 1.0 register.
494+
* hidpp10_set_register - Modify a HID++ 1.0 register.
495495
* @hidpp_dev: the device to set the register on.
496496
* @register_address: the address of the register to modify.
497497
* @byte: the byte of the register to modify. Should be less than 3.
498+
* @mask: mask of the bits to modify
499+
* @value: new values for the bits in mask
498500
* Return: 0 if successful, otherwise a negative error code.
499501
*/
500-
static int hidpp10_set_register_bit(struct hidpp_device *hidpp_dev,
501-
u8 register_address, u8 byte, u8 bit)
502+
static int hidpp10_set_register(struct hidpp_device *hidpp_dev,
503+
u8 register_address, u8 byte, u8 mask, u8 value)
502504
{
503505
struct hidpp_report response;
504506
int ret;
@@ -514,7 +516,8 @@ static int hidpp10_set_register_bit(struct hidpp_device *hidpp_dev,
514516

515517
memcpy(params, response.rap.params, 3);
516518

517-
params[byte] |= BIT(bit);
519+
params[byte] &= ~mask;
520+
params[byte] |= value & mask;
518521

519522
return hidpp_send_rap_command_sync(hidpp_dev,
520523
REPORT_ID_HIDPP_SHORT,
@@ -523,20 +526,28 @@ static int hidpp10_set_register_bit(struct hidpp_device *hidpp_dev,
523526
params, 3, &response);
524527
}
525528

526-
527-
#define HIDPP_REG_GENERAL 0x00
529+
#define HIDPP_REG_ENABLE_REPORTS 0x00
530+
#define HIDPP_ENABLE_CONSUMER_REPORT BIT(0)
531+
#define HIDPP_ENABLE_WHEEL_REPORT BIT(2)
532+
#define HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT BIT(3)
533+
#define HIDPP_ENABLE_BAT_REPORT BIT(4)
534+
#define HIDPP_ENABLE_HWHEEL_REPORT BIT(5)
528535

529536
static int hidpp10_enable_battery_reporting(struct hidpp_device *hidpp_dev)
530537
{
531-
return hidpp10_set_register_bit(hidpp_dev, HIDPP_REG_GENERAL, 0, 4);
538+
return hidpp10_set_register(hidpp_dev, HIDPP_REG_ENABLE_REPORTS, 0,
539+
HIDPP_ENABLE_BAT_REPORT, HIDPP_ENABLE_BAT_REPORT);
532540
}
533541

534542
#define HIDPP_REG_FEATURES 0x01
543+
#define HIDPP_ENABLE_SPECIAL_BUTTON_FUNC BIT(1)
544+
#define HIDPP_ENABLE_FAST_SCROLL BIT(6)
535545

536546
/* On HID++ 1.0 devices, high-res scroll was called "scrolling acceleration". */
537547
static int hidpp10_enable_scrolling_acceleration(struct hidpp_device *hidpp_dev)
538548
{
539-
return hidpp10_set_register_bit(hidpp_dev, HIDPP_REG_FEATURES, 0, 6);
549+
return hidpp10_set_register(hidpp_dev, HIDPP_REG_FEATURES, 0,
550+
HIDPP_ENABLE_FAST_SCROLL, HIDPP_ENABLE_FAST_SCROLL);
540551
}
541552

542553
#define HIDPP_REG_BATTERY_STATUS 0x07

0 commit comments

Comments
 (0)