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: cros_ec_keyb - factor out column processing

Factor out column processing and eagerly skip processing columns that do
not have any changes in them.

Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://patch.msgid.link/20260222003717.471977-7-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+27 -20
+27 -20
drivers/input/keyboard/cros_ec_keyb.c
··· 254 254 input_report_key(idev, code, state); 255 255 } 256 256 257 + static void cros_ec_keyb_process_col(struct cros_ec_keyb *ckdev, int col, 258 + u8 col_state, u8 changed) 259 + { 260 + for (int row = 0; row < ckdev->rows; row++) { 261 + if (changed & BIT(row)) { 262 + u8 key_state = col_state & BIT(row); 263 + 264 + dev_dbg(ckdev->dev, "changed: [r%d c%d]: byte %02x\n", 265 + row, col, key_state); 266 + 267 + if (ckdev->has_fn_map) 268 + cros_ec_keyb_process_key_fn_map(ckdev, row, col, 269 + key_state); 270 + else 271 + cros_ec_keyb_process_key_plain(ckdev, row, col, 272 + key_state); 273 + } 274 + } 275 + } 276 + 257 277 /* 258 278 * Compares the new keyboard state to the old one and produces key 259 279 * press/release events accordingly. The keyboard state is one byte ··· 281 261 */ 282 262 static void cros_ec_keyb_process(struct cros_ec_keyb *ckdev, u8 *kb_state, int len) 283 263 { 284 - int col, row; 285 - int new_state; 286 - int old_state; 287 - 288 264 if (ckdev->ghost_filter && cros_ec_keyb_has_ghosting(ckdev, kb_state)) { 289 265 /* 290 266 * Simple-minded solution: ignore this state. The obvious ··· 291 275 return; 292 276 } 293 277 294 - for (col = 0; col < ckdev->cols; col++) { 295 - for (row = 0; row < ckdev->rows; row++) { 296 - new_state = kb_state[col] & BIT(row); 297 - old_state = ckdev->old_kb_state[col] & BIT(row); 278 + for (int col = 0; col < ckdev->cols; col++) { 279 + u8 changed = kb_state[col] ^ ckdev->old_kb_state[col]; 298 280 299 - if (new_state == old_state) 300 - continue; 301 - 302 - dev_dbg(ckdev->dev, "changed: [r%d c%d]: byte %02x\n", 303 - row, col, new_state); 304 - 305 - if (ckdev->has_fn_map) 306 - cros_ec_keyb_process_key_fn_map(ckdev, row, col, new_state); 307 - else 308 - cros_ec_keyb_process_key_plain(ckdev, row, col, new_state); 309 - } 310 - ckdev->old_kb_state[col] = kb_state[col]; 281 + if (changed) 282 + cros_ec_keyb_process_col(ckdev, col, kb_state[col], 283 + changed); 311 284 } 285 + 286 + memcpy(ckdev->old_kb_state, kb_state, sizeof(ckdev->old_kb_state)); 312 287 input_sync(ckdev->idev); 313 288 } 314 289