pxa27x_keypad.c (f9f6def88ace892f9f90f639664f0e203bafdb22) | pxa27x_keypad.c (9eb521394ea9a50feaf8a9c70b689e4b86ff1b93) |
---|---|
1/* 2 * linux/drivers/input/keyboard/pxa27x_keypad.c 3 * 4 * Driver for the pxa27x matrix keyboard controller. 5 * 6 * Created: Feb 22, 2007 7 * Author: Rodolfo Giometti <giometti@linux.it> 8 * --- 86 unchanged lines hidden (view full) --- 95 96#define keypad_readl(off) __raw_readl(keypad->mmio_base + (off)) 97#define keypad_writel(off, v) __raw_writel((v), keypad->mmio_base + (off)) 98 99#define MAX_MATRIX_KEY_NUM (MAX_MATRIX_KEY_ROWS * MAX_MATRIX_KEY_COLS) 100#define MAX_KEYPAD_KEYS (MAX_MATRIX_KEY_NUM + MAX_DIRECT_KEY_NUM) 101 102struct pxa27x_keypad { | 1/* 2 * linux/drivers/input/keyboard/pxa27x_keypad.c 3 * 4 * Driver for the pxa27x matrix keyboard controller. 5 * 6 * Created: Feb 22, 2007 7 * Author: Rodolfo Giometti <giometti@linux.it> 8 * --- 86 unchanged lines hidden (view full) --- 95 96#define keypad_readl(off) __raw_readl(keypad->mmio_base + (off)) 97#define keypad_writel(off, v) __raw_writel((v), keypad->mmio_base + (off)) 98 99#define MAX_MATRIX_KEY_NUM (MAX_MATRIX_KEY_ROWS * MAX_MATRIX_KEY_COLS) 100#define MAX_KEYPAD_KEYS (MAX_MATRIX_KEY_NUM + MAX_DIRECT_KEY_NUM) 101 102struct pxa27x_keypad { |
103 struct pxa27x_keypad_platform_data *pdata; | 103 const struct pxa27x_keypad_platform_data *pdata; |
104 105 struct clk *clk; 106 struct input_dev *input_dev; 107 void __iomem *mmio_base; 108 109 int irq; 110 111 unsigned short keycodes[MAX_KEYPAD_KEYS]; 112 int rotary_rel_code[2]; 113 114 /* state row bits of each column scan */ 115 uint32_t matrix_key_state[MAX_MATRIX_KEY_COLS]; 116 uint32_t direct_key_state; 117 118 unsigned int direct_key_mask; 119}; 120 121#ifdef CONFIG_OF | 104 105 struct clk *clk; 106 struct input_dev *input_dev; 107 void __iomem *mmio_base; 108 109 int irq; 110 111 unsigned short keycodes[MAX_KEYPAD_KEYS]; 112 int rotary_rel_code[2]; 113 114 /* state row bits of each column scan */ 115 uint32_t matrix_key_state[MAX_MATRIX_KEY_COLS]; 116 uint32_t direct_key_state; 117 118 unsigned int direct_key_mask; 119}; 120 121#ifdef CONFIG_OF |
122static int pxa27x_keypad_matrix_key_parse_dt(struct pxa27x_keypad *keypad) | 122static int pxa27x_keypad_matrix_key_parse_dt(struct pxa27x_keypad *keypad, 123 struct pxa27x_keypad_platform_data *pdata) |
123{ 124 struct input_dev *input_dev = keypad->input_dev; 125 struct device *dev = input_dev->dev.parent; | 124{ 125 struct input_dev *input_dev = keypad->input_dev; 126 struct device *dev = input_dev->dev.parent; |
126 struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | |
127 u32 rows, cols; 128 int error; 129 130 error = matrix_keypad_parse_of_params(dev, &rows, &cols); 131 if (error) 132 return error; 133 134 if (rows > MAX_MATRIX_KEY_ROWS || cols > MAX_MATRIX_KEY_COLS) { --- 9 unchanged lines hidden (view full) --- 144 pdata->matrix_key_cols, 145 keypad->keycodes, input_dev); 146 if (error) 147 return error; 148 149 return 0; 150} 151 | 127 u32 rows, cols; 128 int error; 129 130 error = matrix_keypad_parse_of_params(dev, &rows, &cols); 131 if (error) 132 return error; 133 134 if (rows > MAX_MATRIX_KEY_ROWS || cols > MAX_MATRIX_KEY_COLS) { --- 9 unchanged lines hidden (view full) --- 144 pdata->matrix_key_cols, 145 keypad->keycodes, input_dev); 146 if (error) 147 return error; 148 149 return 0; 150} 151 |
152static int pxa27x_keypad_direct_key_parse_dt(struct pxa27x_keypad *keypad) | 152static int pxa27x_keypad_direct_key_parse_dt(struct pxa27x_keypad *keypad, 153 struct pxa27x_keypad_platform_data *pdata) |
153{ 154 struct input_dev *input_dev = keypad->input_dev; 155 struct device *dev = input_dev->dev.parent; | 154{ 155 struct input_dev *input_dev = keypad->input_dev; 156 struct device *dev = input_dev->dev.parent; |
156 struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | |
157 struct device_node *np = dev->of_node; 158 const __be16 *prop; 159 unsigned short code; 160 unsigned int proplen, size; 161 int i; 162 int error; 163 164 error = of_property_read_u32(np, "marvell,direct-key-count", --- 39 unchanged lines hidden (view full) --- 204 code = be16_to_cpup(prop + i); 205 keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = code; 206 __set_bit(code, input_dev->keybit); 207 } 208 209 return 0; 210} 211 | 157 struct device_node *np = dev->of_node; 158 const __be16 *prop; 159 unsigned short code; 160 unsigned int proplen, size; 161 int i; 162 int error; 163 164 error = of_property_read_u32(np, "marvell,direct-key-count", --- 39 unchanged lines hidden (view full) --- 204 code = be16_to_cpup(prop + i); 205 keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = code; 206 __set_bit(code, input_dev->keybit); 207 } 208 209 return 0; 210} 211 |
212static int pxa27x_keypad_rotary_parse_dt(struct pxa27x_keypad *keypad) | 212static int pxa27x_keypad_rotary_parse_dt(struct pxa27x_keypad *keypad, 213 struct pxa27x_keypad_platform_data *pdata) |
213{ 214 const __be32 *prop; 215 int i, relkey_ret; 216 unsigned int code, proplen; 217 const char *rotaryname[2] = { 218 "marvell,rotary0", "marvell,rotary1"}; 219 const char relkeyname[] = {"marvell,rotary-rel-key"}; 220 struct input_dev *input_dev = keypad->input_dev; 221 struct device *dev = input_dev->dev.parent; | 214{ 215 const __be32 *prop; 216 int i, relkey_ret; 217 unsigned int code, proplen; 218 const char *rotaryname[2] = { 219 "marvell,rotary0", "marvell,rotary1"}; 220 const char relkeyname[] = {"marvell,rotary-rel-key"}; 221 struct input_dev *input_dev = keypad->input_dev; 222 struct device *dev = input_dev->dev.parent; |
222 struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | |
223 struct device_node *np = dev->of_node; 224 225 relkey_ret = of_property_read_u32(np, relkeyname, &code); 226 /* if can read correct rotary key-code, we do not need this. */ 227 if (relkey_ret == 0) { 228 unsigned short relcode; 229 230 /* rotary0 taks lower half, rotary1 taks upper half. */ --- 51 unchanged lines hidden (view full) --- 282 return 0; 283} 284 285static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) 286{ 287 struct input_dev *input_dev = keypad->input_dev; 288 struct device *dev = input_dev->dev.parent; 289 struct device_node *np = dev->of_node; | 223 struct device_node *np = dev->of_node; 224 225 relkey_ret = of_property_read_u32(np, relkeyname, &code); 226 /* if can read correct rotary key-code, we do not need this. */ 227 if (relkey_ret == 0) { 228 unsigned short relcode; 229 230 /* rotary0 taks lower half, rotary1 taks upper half. */ --- 51 unchanged lines hidden (view full) --- 282 return 0; 283} 284 285static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) 286{ 287 struct input_dev *input_dev = keypad->input_dev; 288 struct device *dev = input_dev->dev.parent; 289 struct device_node *np = dev->of_node; |
290 struct pxa27x_keypad_platform_data *pdata; |
|
290 int error; 291 | 291 int error; 292 |
292 keypad->pdata = devm_kzalloc(dev, sizeof(*keypad->pdata), 293 GFP_KERNEL); 294 if (!keypad->pdata) { | 293 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 294 if (!pdata) { |
295 dev_err(dev, "failed to allocate memory for pdata\n"); 296 return -ENOMEM; 297 } 298 | 295 dev_err(dev, "failed to allocate memory for pdata\n"); 296 return -ENOMEM; 297 } 298 |
299 error = pxa27x_keypad_matrix_key_parse_dt(keypad); | 299 error = pxa27x_keypad_matrix_key_parse_dt(keypad, pdata); |
300 if (error) { 301 dev_err(dev, "failed to parse matrix key\n"); 302 return error; 303 } 304 | 300 if (error) { 301 dev_err(dev, "failed to parse matrix key\n"); 302 return error; 303 } 304 |
305 error = pxa27x_keypad_direct_key_parse_dt(keypad); | 305 error = pxa27x_keypad_direct_key_parse_dt(keypad, pdata); |
306 if (error) { 307 dev_err(dev, "failed to parse direct key\n"); 308 return error; 309 } 310 | 306 if (error) { 307 dev_err(dev, "failed to parse direct key\n"); 308 return error; 309 } 310 |
311 error = pxa27x_keypad_rotary_parse_dt(keypad); | 311 error = pxa27x_keypad_rotary_parse_dt(keypad, pdata); |
312 if (error) { 313 dev_err(dev, "failed to parse rotary key\n"); 314 return error; 315 } 316 317 error = of_property_read_u32(np, "marvell,debounce-interval", | 312 if (error) { 313 dev_err(dev, "failed to parse rotary key\n"); 314 return error; 315 } 316 317 error = of_property_read_u32(np, "marvell,debounce-interval", |
318 &keypad->pdata->debounce_interval); | 318 &pdata->debounce_interval); |
319 if (error) { 320 dev_err(dev, "failed to parse debpunce-interval\n"); 321 return error; 322 } 323 324 /* 325 * The keycodes may not only includes matrix key but also the direct 326 * key or rotary key. 327 */ 328 input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); 329 | 319 if (error) { 320 dev_err(dev, "failed to parse debpunce-interval\n"); 321 return error; 322 } 323 324 /* 325 * The keycodes may not only includes matrix key but also the direct 326 * key or rotary key. 327 */ 328 input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); 329 |
330 keypad->pdata = pdata; |
|
330 return 0; 331} 332 333#else 334 335static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) 336{ 337 dev_info(keypad->input_dev->dev.parent, "missing platform data\n"); 338 339 return -EINVAL; 340} 341 342#endif 343 344static int pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad) 345{ | 331 return 0; 332} 333 334#else 335 336static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) 337{ 338 dev_info(keypad->input_dev->dev.parent, "missing platform data\n"); 339 340 return -EINVAL; 341} 342 343#endif 344 345static int pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad) 346{ |
346 struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | 347 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; |
347 struct input_dev *input_dev = keypad->input_dev; 348 const struct matrix_keymap_data *keymap_data = 349 pdata ? pdata->matrix_keymap_data : NULL; 350 unsigned short keycode; 351 int i; 352 int error; 353 354 error = matrix_keypad_build_keymap(keymap_data, NULL, --- 52 unchanged lines hidden (view full) --- 407 408 __clear_bit(KEY_RESERVED, input_dev->keybit); 409 410 return 0; 411} 412 413static void pxa27x_keypad_scan_matrix(struct pxa27x_keypad *keypad) 414{ | 348 struct input_dev *input_dev = keypad->input_dev; 349 const struct matrix_keymap_data *keymap_data = 350 pdata ? pdata->matrix_keymap_data : NULL; 351 unsigned short keycode; 352 int i; 353 int error; 354 355 error = matrix_keypad_build_keymap(keymap_data, NULL, --- 52 unchanged lines hidden (view full) --- 408 409 __clear_bit(KEY_RESERVED, input_dev->keybit); 410 411 return 0; 412} 413 414static void pxa27x_keypad_scan_matrix(struct pxa27x_keypad *keypad) 415{ |
415 struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | 416 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; |
416 struct input_dev *input_dev = keypad->input_dev; 417 int row, col, num_keys_pressed = 0; 418 uint32_t new_state[MAX_MATRIX_KEY_COLS]; 419 uint32_t kpas = keypad_readl(KPAS); 420 421 num_keys_pressed = KPAS_MUKP(kpas); 422 423 memset(new_state, 0, sizeof(new_state)); --- 85 unchanged lines hidden (view full) --- 509 } else { 510 input_report_rel(dev, keypad->rotary_rel_code[r], delta); 511 input_sync(dev); 512 } 513} 514 515static void pxa27x_keypad_scan_rotary(struct pxa27x_keypad *keypad) 516{ | 417 struct input_dev *input_dev = keypad->input_dev; 418 int row, col, num_keys_pressed = 0; 419 uint32_t new_state[MAX_MATRIX_KEY_COLS]; 420 uint32_t kpas = keypad_readl(KPAS); 421 422 num_keys_pressed = KPAS_MUKP(kpas); 423 424 memset(new_state, 0, sizeof(new_state)); --- 85 unchanged lines hidden (view full) --- 510 } else { 511 input_report_rel(dev, keypad->rotary_rel_code[r], delta); 512 input_sync(dev); 513 } 514} 515 516static void pxa27x_keypad_scan_rotary(struct pxa27x_keypad *keypad) 517{ |
517 struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | 518 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; |
518 uint32_t kprec; 519 520 /* read and reset to default count value */ 521 kprec = keypad_readl(KPREC); 522 keypad_writel(KPREC, DEFAULT_KPREC); 523 524 if (pdata->enable_rotary0) 525 report_rotary_event(keypad, 0, rotary_delta(kprec)); 526 527 if (pdata->enable_rotary1) 528 report_rotary_event(keypad, 1, rotary_delta(kprec >> 16)); 529} 530 531static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad) 532{ | 519 uint32_t kprec; 520 521 /* read and reset to default count value */ 522 kprec = keypad_readl(KPREC); 523 keypad_writel(KPREC, DEFAULT_KPREC); 524 525 if (pdata->enable_rotary0) 526 report_rotary_event(keypad, 0, rotary_delta(kprec)); 527 528 if (pdata->enable_rotary1) 529 report_rotary_event(keypad, 1, rotary_delta(kprec >> 16)); 530} 531 532static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad) 533{ |
533 struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | 534 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; |
534 struct input_dev *input_dev = keypad->input_dev; 535 unsigned int new_state; 536 uint32_t kpdk, bits_changed; 537 int i; 538 539 kpdk = keypad_readl(KPDK); 540 541 if (pdata->enable_rotary0 || pdata->enable_rotary1) --- 23 unchanged lines hidden (view full) --- 565 } 566 } 567 input_sync(input_dev); 568 keypad->direct_key_state = new_state; 569} 570 571static void clear_wakeup_event(struct pxa27x_keypad *keypad) 572{ | 535 struct input_dev *input_dev = keypad->input_dev; 536 unsigned int new_state; 537 uint32_t kpdk, bits_changed; 538 int i; 539 540 kpdk = keypad_readl(KPDK); 541 542 if (pdata->enable_rotary0 || pdata->enable_rotary1) --- 23 unchanged lines hidden (view full) --- 566 } 567 } 568 input_sync(input_dev); 569 keypad->direct_key_state = new_state; 570} 571 572static void clear_wakeup_event(struct pxa27x_keypad *keypad) 573{ |
573 struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | 574 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; |
574 575 if (pdata->clear_wakeup_event) 576 (pdata->clear_wakeup_event)(); 577} 578 579static irqreturn_t pxa27x_keypad_irq_handler(int irq, void *dev_id) 580{ 581 struct pxa27x_keypad *keypad = dev_id; --- 7 unchanged lines hidden (view full) --- 589 if (kpc & KPC_MI) 590 pxa27x_keypad_scan_matrix(keypad); 591 592 return IRQ_HANDLED; 593} 594 595static void pxa27x_keypad_config(struct pxa27x_keypad *keypad) 596{ | 575 576 if (pdata->clear_wakeup_event) 577 (pdata->clear_wakeup_event)(); 578} 579 580static irqreturn_t pxa27x_keypad_irq_handler(int irq, void *dev_id) 581{ 582 struct pxa27x_keypad *keypad = dev_id; --- 7 unchanged lines hidden (view full) --- 590 if (kpc & KPC_MI) 591 pxa27x_keypad_scan_matrix(keypad); 592 593 return IRQ_HANDLED; 594} 595 596static void pxa27x_keypad_config(struct pxa27x_keypad *keypad) 597{ |
597 struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | 598 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; |
598 unsigned int mask = 0, direct_key_num = 0; 599 unsigned long kpc = 0; 600 601 /* clear pending interrupt bit */ 602 keypad_readl(KPC); 603 604 /* enable matrix keys with automatic scan */ 605 if (pdata->matrix_key_rows && pdata->matrix_key_cols) { --- 102 unchanged lines hidden (view full) --- 708#endif 709 710static SIMPLE_DEV_PM_OPS(pxa27x_keypad_pm_ops, 711 pxa27x_keypad_suspend, pxa27x_keypad_resume); 712 713 714static int pxa27x_keypad_probe(struct platform_device *pdev) 715{ | 599 unsigned int mask = 0, direct_key_num = 0; 600 unsigned long kpc = 0; 601 602 /* clear pending interrupt bit */ 603 keypad_readl(KPC); 604 605 /* enable matrix keys with automatic scan */ 606 if (pdata->matrix_key_rows && pdata->matrix_key_cols) { --- 102 unchanged lines hidden (view full) --- 709#endif 710 711static SIMPLE_DEV_PM_OPS(pxa27x_keypad_pm_ops, 712 pxa27x_keypad_suspend, pxa27x_keypad_resume); 713 714 715static int pxa27x_keypad_probe(struct platform_device *pdev) 716{ |
716 struct pxa27x_keypad_platform_data *pdata = pdev->dev.platform_data; | 717 const struct pxa27x_keypad_platform_data *pdata = 718 dev_get_platdata(&pdev->dev); |
717 struct device_node *np = pdev->dev.of_node; 718 struct pxa27x_keypad *keypad; 719 struct input_dev *input_dev; 720 struct resource *res; 721 int irq, error; 722 723 /* Driver need build keycode from device tree or pdata */ 724 if (!np && !pdata) --- 63 unchanged lines hidden (view full) --- 788 error = pxa27x_keypad_build_keycode(keypad); 789 else 790 error = pxa27x_keypad_build_keycode_from_dt(keypad); 791 if (error) { 792 dev_err(&pdev->dev, "failed to build keycode\n"); 793 goto failed_put_clk; 794 } 795 | 719 struct device_node *np = pdev->dev.of_node; 720 struct pxa27x_keypad *keypad; 721 struct input_dev *input_dev; 722 struct resource *res; 723 int irq, error; 724 725 /* Driver need build keycode from device tree or pdata */ 726 if (!np && !pdata) --- 63 unchanged lines hidden (view full) --- 790 error = pxa27x_keypad_build_keycode(keypad); 791 else 792 error = pxa27x_keypad_build_keycode_from_dt(keypad); 793 if (error) { 794 dev_err(&pdev->dev, "failed to build keycode\n"); 795 goto failed_put_clk; 796 } 797 |
796 /* If device tree is supported, pdata will be allocated. */ 797 pdata = keypad->pdata; 798 | |
799 if ((pdata->enable_rotary0 && keypad->rotary_rel_code[0] != -1) || 800 (pdata->enable_rotary1 && keypad->rotary_rel_code[1] != -1)) { 801 input_dev->evbit[0] |= BIT_MASK(EV_REL); 802 } 803 804 error = request_irq(irq, pxa27x_keypad_irq_handler, 0, 805 pdev->name, keypad); 806 if (error) { --- 74 unchanged lines hidden --- | 798 if ((pdata->enable_rotary0 && keypad->rotary_rel_code[0] != -1) || 799 (pdata->enable_rotary1 && keypad->rotary_rel_code[1] != -1)) { 800 input_dev->evbit[0] |= BIT_MASK(EV_REL); 801 } 802 803 error = request_irq(irq, pxa27x_keypad_irq_handler, 0, 804 pdev->name, keypad); 805 if (error) { --- 74 unchanged lines hidden --- |