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

Input: pxa27x-keypad - drop support for platform data

There are no in-kernel users of pxa27x_keypad_platform_data in the
kernel, and the driver supports configuration via device tree, so drop
support of static platform data and move properties parsing from
OF-specific methods to generic ones.

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

+119 -328
+119 -255
drivers/input/keyboard/pxa27x_keypad.c
··· 21 21 #include <linux/io.h> 22 22 #include <linux/device.h> 23 23 #include <linux/platform_device.h> 24 + #include <linux/property.h> 24 25 #include <linux/clk.h> 25 26 #include <linux/err.h> 26 27 #include <linux/input/matrix_keypad.h> 27 28 #include <linux/slab.h> 28 29 #include <linux/of.h> 29 30 30 - #include <linux/platform_data/keypad-pxa27x.h> 31 31 /* 32 32 * Keypad Controller registers 33 33 */ ··· 100 100 #define keypad_readl(off) __raw_readl(keypad->mmio_base + (off)) 101 101 #define keypad_writel(off, v) __raw_writel((v), keypad->mmio_base + (off)) 102 102 103 + #define MAX_MATRIX_KEY_ROWS 8 104 + #define MAX_MATRIX_KEY_COLS 8 105 + #define MAX_DIRECT_KEY_NUM 8 106 + #define MAX_ROTARY_ENCODERS 2 107 + 103 108 #define MAX_MATRIX_KEY_NUM (MAX_MATRIX_KEY_ROWS * MAX_MATRIX_KEY_COLS) 104 109 #define MAX_KEYPAD_KEYS (MAX_MATRIX_KEY_NUM + MAX_DIRECT_KEY_NUM) 105 110 106 - struct pxa27x_keypad { 107 - const struct pxa27x_keypad_platform_data *pdata; 111 + struct pxa27x_keypad_rotary { 112 + unsigned short *key_codes; 113 + int rel_code; 114 + bool enabled; 115 + }; 108 116 117 + struct pxa27x_keypad { 109 118 struct clk *clk; 110 119 struct input_dev *input_dev; 111 120 void __iomem *mmio_base; 112 121 113 122 int irq; 114 123 115 - unsigned short keycodes[MAX_KEYPAD_KEYS]; 116 - int rotary_rel_code[2]; 117 - 124 + unsigned int matrix_key_rows; 125 + unsigned int matrix_key_cols; 118 126 unsigned int row_shift; 127 + 128 + unsigned int direct_key_num; 129 + unsigned int direct_key_mask; 130 + bool direct_key_low_active; 131 + 132 + /* key debounce interval */ 133 + unsigned int debounce_interval; 134 + 135 + unsigned short keycodes[MAX_KEYPAD_KEYS]; 119 136 120 137 /* state row bits of each column scan */ 121 138 u32 matrix_key_state[MAX_MATRIX_KEY_COLS]; 122 139 u32 direct_key_state; 123 140 124 - unsigned int direct_key_mask; 141 + struct pxa27x_keypad_rotary rotary[MAX_ROTARY_ENCODERS]; 125 142 }; 126 143 127 - #ifdef CONFIG_OF 128 - static int pxa27x_keypad_matrix_key_parse_dt(struct pxa27x_keypad *keypad, 129 - struct pxa27x_keypad_platform_data *pdata) 144 + static int pxa27x_keypad_matrix_key_parse(struct pxa27x_keypad *keypad) 130 145 { 131 146 struct input_dev *input_dev = keypad->input_dev; 132 147 struct device *dev = input_dev->dev.parent; 133 - u32 rows, cols; 134 148 int error; 135 149 136 - error = matrix_keypad_parse_properties(dev, &rows, &cols); 150 + error = matrix_keypad_parse_properties(dev, &keypad->matrix_key_rows, 151 + &keypad->matrix_key_cols); 137 152 if (error) 138 153 return error; 139 154 140 - if (rows > MAX_MATRIX_KEY_ROWS || cols > MAX_MATRIX_KEY_COLS) { 155 + if (keypad->matrix_key_rows > MAX_MATRIX_KEY_ROWS || 156 + keypad->matrix_key_cols > MAX_MATRIX_KEY_COLS) { 141 157 dev_err(dev, "rows or cols exceeds maximum value\n"); 142 158 return -EINVAL; 143 159 } 144 160 145 - pdata->matrix_key_rows = rows; 146 - pdata->matrix_key_cols = cols; 161 + keypad->row_shift = get_count_order(keypad->matrix_key_cols); 147 162 148 163 error = matrix_keypad_build_keymap(NULL, NULL, 149 - pdata->matrix_key_rows, 150 - pdata->matrix_key_cols, 164 + keypad->matrix_key_rows, 165 + keypad->matrix_key_cols, 151 166 keypad->keycodes, input_dev); 152 167 if (error) 153 168 return error; ··· 170 155 return 0; 171 156 } 172 157 173 - static int pxa27x_keypad_direct_key_parse_dt(struct pxa27x_keypad *keypad, 174 - struct pxa27x_keypad_platform_data *pdata) 158 + static int pxa27x_keypad_direct_key_parse(struct pxa27x_keypad *keypad) 175 159 { 176 160 struct input_dev *input_dev = keypad->input_dev; 177 161 struct device *dev = input_dev->dev.parent; 178 - struct device_node *np = dev->of_node; 179 - const __be16 *prop; 180 162 unsigned short code; 181 - unsigned int proplen, size; 163 + int count; 182 164 int i; 183 165 int error; 184 166 185 - error = of_property_read_u32(np, "marvell,direct-key-count", 186 - &pdata->direct_key_num); 167 + error = device_property_read_u32(dev, "marvell,direct-key-count", 168 + &keypad->direct_key_num); 187 169 if (error) { 188 170 /* 189 171 * If do not have marvel,direct-key-count defined, ··· 189 177 return error == -EINVAL ? 0 : error; 190 178 } 191 179 192 - error = of_property_read_u32(np, "marvell,direct-key-mask", 193 - &pdata->direct_key_mask); 180 + error = device_property_read_u32(dev, "marvell,direct-key-mask", 181 + &keypad->direct_key_mask); 194 182 if (error) { 195 183 if (error != -EINVAL) 196 184 return error; 197 185 198 186 /* 199 187 * If marvell,direct-key-mask is not defined, driver will use 200 - * default value. Default value is set when configure the keypad. 188 + * a default value based on number of direct keys set up. 189 + * The default value is calculated in pxa27x_keypad_config(). 201 190 */ 202 - pdata->direct_key_mask = 0; 191 + keypad->direct_key_mask = 0; 203 192 } 204 193 205 - pdata->direct_key_low_active = of_property_read_bool(np, 206 - "marvell,direct-key-low-active"); 194 + keypad->direct_key_low_active = 195 + device_property_read_bool(dev, "marvell,direct-key-low-active"); 207 196 208 - prop = of_get_property(np, "marvell,direct-key-map", &proplen); 209 - if (!prop) 197 + count = device_property_count_u16(dev, "marvell,direct-key-map"); 198 + if (count <= 0 || count > MAX_DIRECT_KEY_NUM) 210 199 return -EINVAL; 211 200 212 - if (proplen % sizeof(u16)) 213 - return -EINVAL; 201 + error = device_property_read_u16_array(dev, "marvell,direct-key-map", 202 + &keypad->keycodes[MAX_MATRIX_KEY_NUM], 203 + count); 214 204 215 - size = proplen / sizeof(u16); 216 - 217 - /* Only MAX_DIRECT_KEY_NUM is accepted.*/ 218 - if (size > MAX_DIRECT_KEY_NUM) 219 - return -EINVAL; 220 - 221 - for (i = 0; i < size; i++) { 222 - code = be16_to_cpup(prop + i); 223 - keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = code; 205 + for (i = 0; i < count; i++) { 206 + code = keypad->keycodes[MAX_MATRIX_KEY_NUM + i]; 224 207 __set_bit(code, input_dev->keybit); 225 208 } 226 209 227 210 return 0; 228 211 } 229 212 230 - static int pxa27x_keypad_rotary_parse_dt(struct pxa27x_keypad *keypad, 231 - struct pxa27x_keypad_platform_data *pdata) 213 + static int pxa27x_keypad_rotary_parse(struct pxa27x_keypad *keypad) 232 214 { 233 - const __be32 *prop; 234 - int i, relkey_ret; 235 - unsigned int code, proplen; 236 - const char *rotaryname[2] = { 237 - "marvell,rotary0", "marvell,rotary1"}; 238 - const char relkeyname[] = {"marvell,rotary-rel-key"}; 215 + static const char * const rotaryname[] = { "marvell,rotary0", "marvell,rotary1" }; 239 216 struct input_dev *input_dev = keypad->input_dev; 240 217 struct device *dev = input_dev->dev.parent; 241 - struct device_node *np = dev->of_node; 218 + struct pxa27x_keypad_rotary *encoder; 219 + unsigned int code; 220 + int i; 221 + int error; 242 222 243 - relkey_ret = of_property_read_u32(np, relkeyname, &code); 244 - /* if can read correct rotary key-code, we do not need this. */ 245 - if (relkey_ret == 0) { 246 - unsigned short relcode; 223 + error = device_property_read_u32(dev, "marvell,rotary-rel-key", &code); 224 + if (!error) { 225 + for (i = 0; i < MAX_ROTARY_ENCODERS; i++, code >>= 16) { 226 + encoder = &keypad->rotary[i]; 227 + encoder->enabled = true; 228 + encoder->rel_code = code & 0xffff; 229 + input_set_capability(input_dev, EV_REL, encoder->rel_code); 230 + } 247 231 248 - /* rotary0 taks lower half, rotary1 taks upper half. */ 249 - relcode = code & 0xffff; 250 - pdata->rotary0_rel_code = (code & 0xffff); 251 - __set_bit(relcode, input_dev->relbit); 252 - 253 - relcode = code >> 16; 254 - pdata->rotary1_rel_code = relcode; 255 - __set_bit(relcode, input_dev->relbit); 232 + return 0; 256 233 } 257 234 258 - for (i = 0; i < 2; i++) { 259 - prop = of_get_property(np, rotaryname[i], &proplen); 235 + for (i = 0; i < MAX_ROTARY_ENCODERS; i++) { 236 + encoder = &keypad->rotary[i]; 237 + 260 238 /* 261 239 * If the prop is not set, it means keypad does not need 262 240 * initialize the rotaryX. 263 241 */ 264 - if (!prop) 242 + if (!device_property_present(dev, rotaryname[i])) 265 243 continue; 266 244 267 - code = be32_to_cpup(prop); 245 + error = device_property_read_u32(dev, rotaryname[i], &code); 246 + if (error) 247 + return error; 248 + 268 249 /* 269 250 * Not all up/down key code are valid. 270 251 * Now we depends on direct-rel-code. 271 252 */ 272 - if ((!(code & 0xffff) || !(code >> 16)) && relkey_ret) { 273 - return relkey_ret; 274 - } else { 275 - unsigned int n = MAX_MATRIX_KEY_NUM + (i << 1); 276 - unsigned short keycode; 253 + if (!(code & 0xffff) || !(code >> 16)) 254 + return -EINVAL; 277 255 278 - keycode = code & 0xffff; 279 - keypad->keycodes[n] = keycode; 280 - __set_bit(keycode, input_dev->keybit); 256 + encoder->enabled = true; 257 + encoder->rel_code = -1; 258 + encoder->key_codes = &keypad->keycodes[MAX_MATRIX_KEY_NUM + i * 2]; 259 + encoder->key_codes[0] = code & 0xffff; 260 + encoder->key_codes[1] = code >> 16; 281 261 282 - keycode = code >> 16; 283 - keypad->keycodes[n + 1] = keycode; 284 - __set_bit(keycode, input_dev->keybit); 285 - 286 - if (i == 0) 287 - pdata->rotary0_rel_code = -1; 288 - else 289 - pdata->rotary1_rel_code = -1; 290 - } 291 - if (i == 0) 292 - pdata->enable_rotary0 = 1; 293 - else 294 - pdata->enable_rotary1 = 1; 262 + input_set_capability(input_dev, EV_KEY, encoder->key_codes[0]); 263 + input_set_capability(input_dev, EV_KEY, encoder->key_codes[1]); 295 264 } 296 - 297 - keypad->rotary_rel_code[0] = pdata->rotary0_rel_code; 298 - keypad->rotary_rel_code[1] = pdata->rotary1_rel_code; 299 265 300 266 return 0; 301 267 } 302 268 303 - static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) 269 + static int pxa27x_keypad_parse_properties(struct pxa27x_keypad *keypad) 304 270 { 305 271 struct input_dev *input_dev = keypad->input_dev; 306 272 struct device *dev = input_dev->dev.parent; 307 - struct device_node *np = dev->of_node; 308 - struct pxa27x_keypad_platform_data *pdata; 309 273 int error; 310 274 311 - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 312 - if (!pdata) { 313 - dev_err(dev, "failed to allocate memory for pdata\n"); 314 - return -ENOMEM; 315 - } 316 - 317 - error = pxa27x_keypad_matrix_key_parse_dt(keypad, pdata); 275 + error = pxa27x_keypad_matrix_key_parse(keypad); 318 276 if (error) { 319 277 dev_err(dev, "failed to parse matrix key\n"); 320 278 return error; 321 279 } 322 280 323 - error = pxa27x_keypad_direct_key_parse_dt(keypad, pdata); 281 + error = pxa27x_keypad_direct_key_parse(keypad); 324 282 if (error) { 325 283 dev_err(dev, "failed to parse direct key\n"); 326 284 return error; 327 285 } 328 286 329 - error = pxa27x_keypad_rotary_parse_dt(keypad, pdata); 287 + error = pxa27x_keypad_rotary_parse(keypad); 330 288 if (error) { 331 289 dev_err(dev, "failed to parse rotary key\n"); 332 290 return error; 333 291 } 334 292 335 - error = of_property_read_u32(np, "marvell,debounce-interval", 336 - &pdata->debounce_interval); 293 + error = device_property_read_u32(dev, "marvell,debounce-interval", 294 + &keypad->debounce_interval); 337 295 if (error) { 338 296 dev_err(dev, "failed to parse debounce-interval\n"); 339 297 return error; ··· 315 333 */ 316 334 input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); 317 335 318 - keypad->pdata = pdata; 319 - return 0; 320 - } 321 - 322 - #else 323 - 324 - static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) 325 - { 326 - dev_info(keypad->input_dev->dev.parent, "missing platform data\n"); 327 - 328 - return -EINVAL; 329 - } 330 - 331 - #endif 332 - 333 - static int pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad) 334 - { 335 - const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; 336 - struct input_dev *input_dev = keypad->input_dev; 337 - unsigned short keycode; 338 - int i; 339 - int error; 340 - 341 - error = matrix_keypad_build_keymap(pdata->matrix_keymap_data, NULL, 342 - pdata->matrix_key_rows, 343 - pdata->matrix_key_cols, 344 - keypad->keycodes, input_dev); 345 - if (error) 346 - return error; 347 - 348 - /* 349 - * The keycodes may not only include matrix keys but also the direct 350 - * or rotary keys. 351 - */ 352 - input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); 353 - 354 - /* For direct keys. */ 355 - for (i = 0; i < pdata->direct_key_num; i++) { 356 - keycode = pdata->direct_key_map[i]; 357 - keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = keycode; 358 - __set_bit(keycode, input_dev->keybit); 359 - } 360 - 361 - if (pdata->enable_rotary0) { 362 - if (pdata->rotary0_up_key && pdata->rotary0_down_key) { 363 - keycode = pdata->rotary0_up_key; 364 - keypad->keycodes[MAX_MATRIX_KEY_NUM + 0] = keycode; 365 - __set_bit(keycode, input_dev->keybit); 366 - 367 - keycode = pdata->rotary0_down_key; 368 - keypad->keycodes[MAX_MATRIX_KEY_NUM + 1] = keycode; 369 - __set_bit(keycode, input_dev->keybit); 370 - 371 - keypad->rotary_rel_code[0] = -1; 372 - } else { 373 - keypad->rotary_rel_code[0] = pdata->rotary0_rel_code; 374 - __set_bit(pdata->rotary0_rel_code, input_dev->relbit); 375 - } 376 - } 377 - 378 - if (pdata->enable_rotary1) { 379 - if (pdata->rotary1_up_key && pdata->rotary1_down_key) { 380 - keycode = pdata->rotary1_up_key; 381 - keypad->keycodes[MAX_MATRIX_KEY_NUM + 2] = keycode; 382 - __set_bit(keycode, input_dev->keybit); 383 - 384 - keycode = pdata->rotary1_down_key; 385 - keypad->keycodes[MAX_MATRIX_KEY_NUM + 3] = keycode; 386 - __set_bit(keycode, input_dev->keybit); 387 - 388 - keypad->rotary_rel_code[1] = -1; 389 - } else { 390 - keypad->rotary_rel_code[1] = pdata->rotary1_rel_code; 391 - __set_bit(pdata->rotary1_rel_code, input_dev->relbit); 392 - } 393 - } 394 - 395 - __clear_bit(KEY_RESERVED, input_dev->keybit); 396 - 397 336 return 0; 398 337 } 399 338 400 339 static void pxa27x_keypad_scan_matrix(struct pxa27x_keypad *keypad) 401 340 { 402 - const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; 403 341 struct input_dev *input_dev = keypad->input_dev; 404 342 int row, col, num_keys_pressed = 0; 405 343 u32 new_state[MAX_MATRIX_KEY_COLS]; ··· 337 435 row = KPAS_RP(kpas); 338 436 339 437 /* if invalid row/col, treat as no key pressed */ 340 - if (col >= pdata->matrix_key_cols || 341 - row >= pdata->matrix_key_rows) 438 + if (col >= keypad->matrix_key_cols || 439 + row >= keypad->matrix_key_rows) 342 440 goto scan; 343 441 344 442 new_state[col] = BIT(row); ··· 361 459 new_state[7] = (kpasmkp3 >> 16) & KPASMKP_MKC_MASK; 362 460 } 363 461 scan: 364 - for (col = 0; col < pdata->matrix_key_cols; col++) { 462 + for (col = 0; col < keypad->matrix_key_cols; col++) { 365 463 u32 bits_changed; 366 464 int code; 367 465 ··· 369 467 if (bits_changed == 0) 370 468 continue; 371 469 372 - for (row = 0; row < pdata->matrix_key_rows; row++) { 470 + for (row = 0; row < keypad->matrix_key_rows; row++) { 373 471 if ((bits_changed & BIT(row)) == 0) 374 472 continue; 375 473 ··· 398 496 399 497 static void report_rotary_event(struct pxa27x_keypad *keypad, int r, int delta) 400 498 { 499 + struct pxa27x_keypad_rotary *encoder = &keypad->rotary[r]; 401 500 struct input_dev *dev = keypad->input_dev; 402 501 403 - if (delta == 0) 502 + if (!encoder->enabled || delta == 0) 404 503 return; 405 504 406 - if (keypad->rotary_rel_code[r] == -1) { 407 - int code = MAX_MATRIX_KEY_NUM + 2 * r + (delta > 0 ? 0 : 1); 408 - unsigned char keycode = keypad->keycodes[code]; 505 + if (encoder->rel_code == -1) { 506 + int idx = delta > 0 ? 0 : 1; 507 + int code = MAX_MATRIX_KEY_NUM + 2 * r + idx; 508 + unsigned char keycode = encoder->key_codes[idx]; 409 509 410 510 /* simulate a press-n-release */ 411 511 input_event(dev, EV_MSC, MSC_SCAN, code); ··· 417 513 input_report_key(dev, keycode, 0); 418 514 input_sync(dev); 419 515 } else { 420 - input_report_rel(dev, keypad->rotary_rel_code[r], delta); 516 + input_report_rel(dev, encoder->rel_code, delta); 421 517 input_sync(dev); 422 518 } 423 519 } 424 520 425 521 static void pxa27x_keypad_scan_rotary(struct pxa27x_keypad *keypad) 426 522 { 427 - const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; 428 523 u32 kprec; 524 + int i; 429 525 430 526 /* read and reset to default count value */ 431 527 kprec = keypad_readl(KPREC); 432 528 keypad_writel(KPREC, DEFAULT_KPREC); 433 529 434 - if (pdata->enable_rotary0) 530 + for (i = 0; i < MAX_ROTARY_ENCODERS; i++) { 435 531 report_rotary_event(keypad, 0, rotary_delta(kprec)); 436 - 437 - if (pdata->enable_rotary1) 438 - report_rotary_event(keypad, 1, rotary_delta(kprec >> 16)); 532 + kprec >>= 16; 533 + } 439 534 } 440 535 441 536 static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad) 442 537 { 443 - const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; 444 538 struct input_dev *input_dev = keypad->input_dev; 445 539 unsigned int new_state; 446 540 u32 kpdk, bits_changed; ··· 446 544 447 545 kpdk = keypad_readl(KPDK); 448 546 449 - if (pdata->enable_rotary0 || pdata->enable_rotary1) 547 + if (keypad->rotary[0].enabled || keypad->rotary[1].enabled) 450 548 pxa27x_keypad_scan_rotary(keypad); 451 549 452 550 /* 453 551 * The KPDR_DK only output the key pin level, so it relates to board, 454 552 * and low level may be active. 455 553 */ 456 - if (pdata->direct_key_low_active) 554 + if (keypad->direct_key_low_active) 457 555 new_state = ~KPDK_DK(kpdk) & keypad->direct_key_mask; 458 556 else 459 557 new_state = KPDK_DK(kpdk) & keypad->direct_key_mask; ··· 463 561 if (bits_changed == 0) 464 562 return; 465 563 466 - for (i = 0; i < pdata->direct_key_num; i++) { 564 + for (i = 0; i < keypad->direct_key_num; i++) { 467 565 if (bits_changed & BIT(i)) { 468 566 int code = MAX_MATRIX_KEY_NUM + i; 469 567 ··· 476 574 keypad->direct_key_state = new_state; 477 575 } 478 576 479 - static void clear_wakeup_event(struct pxa27x_keypad *keypad) 480 - { 481 - const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; 482 - 483 - if (pdata->clear_wakeup_event) 484 - (pdata->clear_wakeup_event)(); 485 - } 486 - 487 577 static irqreturn_t pxa27x_keypad_irq_handler(int irq, void *dev_id) 488 578 { 489 579 struct pxa27x_keypad *keypad = dev_id; 490 580 unsigned long kpc = keypad_readl(KPC); 491 - 492 - clear_wakeup_event(keypad); 493 581 494 582 if (kpc & KPC_DI) 495 583 pxa27x_keypad_scan_direct(keypad); ··· 492 600 493 601 static void pxa27x_keypad_config(struct pxa27x_keypad *keypad) 494 602 { 495 - const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; 496 603 unsigned int mask = 0, direct_key_num = 0; 497 604 unsigned long kpc = 0; 498 605 ··· 499 608 keypad_readl(KPC); 500 609 501 610 /* enable matrix keys with automatic scan */ 502 - if (pdata->matrix_key_rows && pdata->matrix_key_cols) { 611 + if (keypad->matrix_key_rows && keypad->matrix_key_cols) { 503 612 kpc |= KPC_ASACT | KPC_MIE | KPC_ME | KPC_MS_ALL; 504 - kpc |= KPC_MKRN(pdata->matrix_key_rows) | 505 - KPC_MKCN(pdata->matrix_key_cols); 613 + kpc |= KPC_MKRN(keypad->matrix_key_rows) | 614 + KPC_MKCN(keypad->matrix_key_cols); 506 615 } 507 616 508 617 /* enable rotary key, debounce interval same as direct keys */ 509 - if (pdata->enable_rotary0) { 618 + if (keypad->rotary[0].enabled) { 510 619 mask |= 0x03; 511 620 direct_key_num = 2; 512 621 kpc |= KPC_REE0; 513 622 } 514 623 515 - if (pdata->enable_rotary1) { 624 + if (keypad->rotary[1].enabled) { 516 625 mask |= 0x0c; 517 626 direct_key_num = 4; 518 627 kpc |= KPC_REE1; 519 628 } 520 629 521 - if (pdata->direct_key_num > direct_key_num) 522 - direct_key_num = pdata->direct_key_num; 630 + if (keypad->direct_key_num > direct_key_num) 631 + direct_key_num = keypad->direct_key_num; 523 632 524 633 /* 525 634 * Direct keys usage may not start from KP_DKIN0, check the platfrom 526 635 * mask data to config the specific. 527 636 */ 528 - if (pdata->direct_key_mask) 529 - keypad->direct_key_mask = pdata->direct_key_mask; 530 - else 637 + if (!keypad->direct_key_mask) 531 638 keypad->direct_key_mask = GENMASK(direct_key_num - 1, 0) & ~mask; 532 639 533 640 /* enable direct key */ ··· 534 645 535 646 keypad_writel(KPC, kpc | KPC_RE_ZERO_DEB); 536 647 keypad_writel(KPREC, DEFAULT_KPREC); 537 - keypad_writel(KPKDI, pdata->debounce_interval); 648 + keypad_writel(KPKDI, keypad->debounce_interval); 538 649 } 539 650 540 651 static int pxa27x_keypad_open(struct input_dev *dev) ··· 608 719 static DEFINE_SIMPLE_DEV_PM_OPS(pxa27x_keypad_pm_ops, 609 720 pxa27x_keypad_suspend, pxa27x_keypad_resume); 610 721 611 - 612 722 static int pxa27x_keypad_probe(struct platform_device *pdev) 613 723 { 614 - const struct pxa27x_keypad_platform_data *pdata = 615 - dev_get_platdata(&pdev->dev); 616 - struct device_node *np = pdev->dev.of_node; 617 724 struct pxa27x_keypad *keypad; 618 725 struct input_dev *input_dev; 619 - int irq, error; 620 - 621 - /* Driver need build keycode from device tree or pdata */ 622 - if (!np && !pdata) 623 - return -EINVAL; 726 + int irq; 727 + int error; 624 728 625 729 irq = platform_get_irq(pdev, 0); 626 730 if (irq < 0) ··· 628 746 if (!input_dev) 629 747 return -ENOMEM; 630 748 631 - keypad->pdata = pdata; 632 749 keypad->input_dev = input_dev; 633 750 keypad->irq = irq; 634 751 ··· 656 775 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); 657 776 input_set_capability(input_dev, EV_MSC, MSC_SCAN); 658 777 659 - if (pdata) { 660 - error = pxa27x_keypad_build_keycode(keypad); 661 - } else { 662 - error = pxa27x_keypad_build_keycode_from_dt(keypad); 663 - /* 664 - * Data that we get from DT resides in dynamically 665 - * allocated memory so we need to update our pdata 666 - * pointer. 667 - */ 668 - pdata = keypad->pdata; 669 - } 778 + error = pxa27x_keypad_parse_properties(keypad); 670 779 if (error) { 671 - dev_err(&pdev->dev, "failed to build keycode\n"); 780 + dev_err(&pdev->dev, "failed to parse keypad properties\n"); 672 781 return error; 673 - } 674 - 675 - keypad->row_shift = get_count_order(pdata->matrix_key_cols); 676 - 677 - if ((pdata->enable_rotary0 && keypad->rotary_rel_code[0] != -1) || 678 - (pdata->enable_rotary1 && keypad->rotary_rel_code[1] != -1)) { 679 - input_dev->evbit[0] |= BIT_MASK(EV_REL); 680 782 } 681 783 682 784 error = devm_request_irq(&pdev->dev, irq, pxa27x_keypad_irq_handler,
-73
include/linux/platform_data/keypad-pxa27x.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef __ASM_ARCH_PXA27x_KEYPAD_H 3 - #define __ASM_ARCH_PXA27x_KEYPAD_H 4 - 5 - #include <linux/input.h> 6 - #include <linux/input/matrix_keypad.h> 7 - 8 - #define MAX_MATRIX_KEY_ROWS (8) 9 - #define MAX_MATRIX_KEY_COLS (8) 10 - #define MATRIX_ROW_SHIFT (3) 11 - #define MAX_DIRECT_KEY_NUM (8) 12 - 13 - /* pxa3xx keypad platform specific parameters 14 - * 15 - * NOTE: 16 - * 1. direct_key_num indicates the number of keys in the direct keypad 17 - * _plus_ the number of rotary-encoder sensor inputs, this can be 18 - * left as 0 if only rotary encoders are enabled, the driver will 19 - * automatically calculate this 20 - * 21 - * 2. direct_key_map is the key code map for the direct keys, if rotary 22 - * encoder(s) are enabled, direct key 0/1(2/3) will be ignored 23 - * 24 - * 3. rotary can be either interpreted as a relative input event (e.g. 25 - * REL_WHEEL/REL_HWHEEL) or specific keys (e.g. UP/DOWN/LEFT/RIGHT) 26 - * 27 - * 4. matrix key and direct key will use the same debounce_interval by 28 - * default, which should be sufficient in most cases 29 - * 30 - * pxa168 keypad platform specific parameter 31 - * 32 - * NOTE: 33 - * clear_wakeup_event callback is a workaround required to clear the 34 - * keypad interrupt. The keypad wake must be cleared in addition to 35 - * reading the MI/DI bits in the KPC register. 36 - */ 37 - struct pxa27x_keypad_platform_data { 38 - 39 - /* code map for the matrix keys */ 40 - const struct matrix_keymap_data *matrix_keymap_data; 41 - unsigned int matrix_key_rows; 42 - unsigned int matrix_key_cols; 43 - 44 - /* direct keys */ 45 - int direct_key_num; 46 - unsigned int direct_key_map[MAX_DIRECT_KEY_NUM]; 47 - /* the key output may be low active */ 48 - int direct_key_low_active; 49 - /* give board a chance to choose the start direct key */ 50 - unsigned int direct_key_mask; 51 - 52 - /* rotary encoders 0 */ 53 - int enable_rotary0; 54 - int rotary0_rel_code; 55 - int rotary0_up_key; 56 - int rotary0_down_key; 57 - 58 - /* rotary encoders 1 */ 59 - int enable_rotary1; 60 - int rotary1_rel_code; 61 - int rotary1_up_key; 62 - int rotary1_down_key; 63 - 64 - /* key debounce interval */ 65 - unsigned int debounce_interval; 66 - 67 - /* clear wakeup event requirement for pxa168 */ 68 - void (*clear_wakeup_event)(void); 69 - }; 70 - 71 - extern void pxa_set_keypad_info(struct pxa27x_keypad_platform_data *info); 72 - 73 - #endif /* __ASM_ARCH_PXA27x_KEYPAD_H */