diff options
Diffstat (limited to 'drivers/input/keyboard/tegra-kbc.c')
-rw-r--r-- | drivers/input/keyboard/tegra-kbc.c | 478 |
1 files changed, 149 insertions, 329 deletions
diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c index c76f96872d31..d89e7d392d1e 100644 --- a/drivers/input/keyboard/tegra-kbc.c +++ b/drivers/input/keyboard/tegra-kbc.c | |||
@@ -29,9 +29,16 @@ | |||
29 | #include <linux/of.h> | 29 | #include <linux/of.h> |
30 | #include <linux/clk.h> | 30 | #include <linux/clk.h> |
31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
32 | #include <linux/input/tegra_kbc.h> | 32 | #include <linux/input/matrix_keypad.h> |
33 | #include <mach/clk.h> | 33 | #include <mach/clk.h> |
34 | 34 | ||
35 | #define KBC_MAX_GPIO 24 | ||
36 | #define KBC_MAX_KPENT 8 | ||
37 | |||
38 | #define KBC_MAX_ROW 16 | ||
39 | #define KBC_MAX_COL 8 | ||
40 | #define KBC_MAX_KEY (KBC_MAX_ROW * KBC_MAX_COL) | ||
41 | |||
35 | #define KBC_MAX_DEBOUNCE_CNT 0x3ffu | 42 | #define KBC_MAX_DEBOUNCE_CNT 0x3ffu |
36 | 43 | ||
37 | /* KBC row scan time and delay for beginning the row scan. */ | 44 | /* KBC row scan time and delay for beginning the row scan. */ |
@@ -67,10 +74,27 @@ | |||
67 | 74 | ||
68 | #define KBC_ROW_SHIFT 3 | 75 | #define KBC_ROW_SHIFT 3 |
69 | 76 | ||
77 | enum tegra_pin_type { | ||
78 | PIN_CFG_IGNORE, | ||
79 | PIN_CFG_COL, | ||
80 | PIN_CFG_ROW, | ||
81 | }; | ||
82 | |||
83 | struct tegra_kbc_pin_cfg { | ||
84 | enum tegra_pin_type type; | ||
85 | unsigned char num; | ||
86 | }; | ||
87 | |||
70 | struct tegra_kbc { | 88 | struct tegra_kbc { |
89 | struct device *dev; | ||
90 | unsigned int debounce_cnt; | ||
91 | unsigned int repeat_cnt; | ||
92 | struct tegra_kbc_pin_cfg pin_cfg[KBC_MAX_GPIO]; | ||
93 | const struct matrix_keymap_data *keymap_data; | ||
94 | bool wakeup; | ||
71 | void __iomem *mmio; | 95 | void __iomem *mmio; |
72 | struct input_dev *idev; | 96 | struct input_dev *idev; |
73 | unsigned int irq; | 97 | int irq; |
74 | spinlock_t lock; | 98 | spinlock_t lock; |
75 | unsigned int repoll_dly; | 99 | unsigned int repoll_dly; |
76 | unsigned long cp_dly_jiffies; | 100 | unsigned long cp_dly_jiffies; |
@@ -78,7 +102,6 @@ struct tegra_kbc { | |||
78 | bool use_fn_map; | 102 | bool use_fn_map; |
79 | bool use_ghost_filter; | 103 | bool use_ghost_filter; |
80 | bool keypress_caused_wake; | 104 | bool keypress_caused_wake; |
81 | const struct tegra_kbc_platform_data *pdata; | ||
82 | unsigned short keycode[KBC_MAX_KEY * 2]; | 105 | unsigned short keycode[KBC_MAX_KEY * 2]; |
83 | unsigned short current_keys[KBC_MAX_KPENT]; | 106 | unsigned short current_keys[KBC_MAX_KPENT]; |
84 | unsigned int num_pressed_keys; | 107 | unsigned int num_pressed_keys; |
@@ -87,147 +110,6 @@ struct tegra_kbc { | |||
87 | struct clk *clk; | 110 | struct clk *clk; |
88 | }; | 111 | }; |
89 | 112 | ||
90 | static const u32 tegra_kbc_default_keymap[] = { | ||
91 | KEY(0, 2, KEY_W), | ||
92 | KEY(0, 3, KEY_S), | ||
93 | KEY(0, 4, KEY_A), | ||
94 | KEY(0, 5, KEY_Z), | ||
95 | KEY(0, 7, KEY_FN), | ||
96 | |||
97 | KEY(1, 7, KEY_LEFTMETA), | ||
98 | |||
99 | KEY(2, 6, KEY_RIGHTALT), | ||
100 | KEY(2, 7, KEY_LEFTALT), | ||
101 | |||
102 | KEY(3, 0, KEY_5), | ||
103 | KEY(3, 1, KEY_4), | ||
104 | KEY(3, 2, KEY_R), | ||
105 | KEY(3, 3, KEY_E), | ||
106 | KEY(3, 4, KEY_F), | ||
107 | KEY(3, 5, KEY_D), | ||
108 | KEY(3, 6, KEY_X), | ||
109 | |||
110 | KEY(4, 0, KEY_7), | ||
111 | KEY(4, 1, KEY_6), | ||
112 | KEY(4, 2, KEY_T), | ||
113 | KEY(4, 3, KEY_H), | ||
114 | KEY(4, 4, KEY_G), | ||
115 | KEY(4, 5, KEY_V), | ||
116 | KEY(4, 6, KEY_C), | ||
117 | KEY(4, 7, KEY_SPACE), | ||
118 | |||
119 | KEY(5, 0, KEY_9), | ||
120 | KEY(5, 1, KEY_8), | ||
121 | KEY(5, 2, KEY_U), | ||
122 | KEY(5, 3, KEY_Y), | ||
123 | KEY(5, 4, KEY_J), | ||
124 | KEY(5, 5, KEY_N), | ||
125 | KEY(5, 6, KEY_B), | ||
126 | KEY(5, 7, KEY_BACKSLASH), | ||
127 | |||
128 | KEY(6, 0, KEY_MINUS), | ||
129 | KEY(6, 1, KEY_0), | ||
130 | KEY(6, 2, KEY_O), | ||
131 | KEY(6, 3, KEY_I), | ||
132 | KEY(6, 4, KEY_L), | ||
133 | KEY(6, 5, KEY_K), | ||
134 | KEY(6, 6, KEY_COMMA), | ||
135 | KEY(6, 7, KEY_M), | ||
136 | |||
137 | KEY(7, 1, KEY_EQUAL), | ||
138 | KEY(7, 2, KEY_RIGHTBRACE), | ||
139 | KEY(7, 3, KEY_ENTER), | ||
140 | KEY(7, 7, KEY_MENU), | ||
141 | |||
142 | KEY(8, 4, KEY_RIGHTSHIFT), | ||
143 | KEY(8, 5, KEY_LEFTSHIFT), | ||
144 | |||
145 | KEY(9, 5, KEY_RIGHTCTRL), | ||
146 | KEY(9, 7, KEY_LEFTCTRL), | ||
147 | |||
148 | KEY(11, 0, KEY_LEFTBRACE), | ||
149 | KEY(11, 1, KEY_P), | ||
150 | KEY(11, 2, KEY_APOSTROPHE), | ||
151 | KEY(11, 3, KEY_SEMICOLON), | ||
152 | KEY(11, 4, KEY_SLASH), | ||
153 | KEY(11, 5, KEY_DOT), | ||
154 | |||
155 | KEY(12, 0, KEY_F10), | ||
156 | KEY(12, 1, KEY_F9), | ||
157 | KEY(12, 2, KEY_BACKSPACE), | ||
158 | KEY(12, 3, KEY_3), | ||
159 | KEY(12, 4, KEY_2), | ||
160 | KEY(12, 5, KEY_UP), | ||
161 | KEY(12, 6, KEY_PRINT), | ||
162 | KEY(12, 7, KEY_PAUSE), | ||
163 | |||
164 | KEY(13, 0, KEY_INSERT), | ||
165 | KEY(13, 1, KEY_DELETE), | ||
166 | KEY(13, 3, KEY_PAGEUP), | ||
167 | KEY(13, 4, KEY_PAGEDOWN), | ||
168 | KEY(13, 5, KEY_RIGHT), | ||
169 | KEY(13, 6, KEY_DOWN), | ||
170 | KEY(13, 7, KEY_LEFT), | ||
171 | |||
172 | KEY(14, 0, KEY_F11), | ||
173 | KEY(14, 1, KEY_F12), | ||
174 | KEY(14, 2, KEY_F8), | ||
175 | KEY(14, 3, KEY_Q), | ||
176 | KEY(14, 4, KEY_F4), | ||
177 | KEY(14, 5, KEY_F3), | ||
178 | KEY(14, 6, KEY_1), | ||
179 | KEY(14, 7, KEY_F7), | ||
180 | |||
181 | KEY(15, 0, KEY_ESC), | ||
182 | KEY(15, 1, KEY_GRAVE), | ||
183 | KEY(15, 2, KEY_F5), | ||
184 | KEY(15, 3, KEY_TAB), | ||
185 | KEY(15, 4, KEY_F1), | ||
186 | KEY(15, 5, KEY_F2), | ||
187 | KEY(15, 6, KEY_CAPSLOCK), | ||
188 | KEY(15, 7, KEY_F6), | ||
189 | |||
190 | /* Software Handled Function Keys */ | ||
191 | KEY(20, 0, KEY_KP7), | ||
192 | |||
193 | KEY(21, 0, KEY_KP9), | ||
194 | KEY(21, 1, KEY_KP8), | ||
195 | KEY(21, 2, KEY_KP4), | ||
196 | KEY(21, 4, KEY_KP1), | ||
197 | |||
198 | KEY(22, 1, KEY_KPSLASH), | ||
199 | KEY(22, 2, KEY_KP6), | ||
200 | KEY(22, 3, KEY_KP5), | ||
201 | KEY(22, 4, KEY_KP3), | ||
202 | KEY(22, 5, KEY_KP2), | ||
203 | KEY(22, 7, KEY_KP0), | ||
204 | |||
205 | KEY(27, 1, KEY_KPASTERISK), | ||
206 | KEY(27, 3, KEY_KPMINUS), | ||
207 | KEY(27, 4, KEY_KPPLUS), | ||
208 | KEY(27, 5, KEY_KPDOT), | ||
209 | |||
210 | KEY(28, 5, KEY_VOLUMEUP), | ||
211 | |||
212 | KEY(29, 3, KEY_HOME), | ||
213 | KEY(29, 4, KEY_END), | ||
214 | KEY(29, 5, KEY_BRIGHTNESSDOWN), | ||
215 | KEY(29, 6, KEY_VOLUMEDOWN), | ||
216 | KEY(29, 7, KEY_BRIGHTNESSUP), | ||
217 | |||
218 | KEY(30, 0, KEY_NUMLOCK), | ||
219 | KEY(30, 1, KEY_SCROLLLOCK), | ||
220 | KEY(30, 2, KEY_MUTE), | ||
221 | |||
222 | KEY(31, 4, KEY_HELP), | ||
223 | }; | ||
224 | |||
225 | static const | ||
226 | struct matrix_keymap_data tegra_kbc_default_keymap_data = { | ||
227 | .keymap = tegra_kbc_default_keymap, | ||
228 | .keymap_size = ARRAY_SIZE(tegra_kbc_default_keymap), | ||
229 | }; | ||
230 | |||
231 | static void tegra_kbc_report_released_keys(struct input_dev *input, | 113 | static void tegra_kbc_report_released_keys(struct input_dev *input, |
232 | unsigned short old_keycodes[], | 114 | unsigned short old_keycodes[], |
233 | unsigned int old_num_keys, | 115 | unsigned int old_num_keys, |
@@ -357,18 +239,6 @@ static void tegra_kbc_set_fifo_interrupt(struct tegra_kbc *kbc, bool enable) | |||
357 | writel(val, kbc->mmio + KBC_CONTROL_0); | 239 | writel(val, kbc->mmio + KBC_CONTROL_0); |
358 | } | 240 | } |
359 | 241 | ||
360 | static void tegra_kbc_set_keypress_interrupt(struct tegra_kbc *kbc, bool enable) | ||
361 | { | ||
362 | u32 val; | ||
363 | |||
364 | val = readl(kbc->mmio + KBC_CONTROL_0); | ||
365 | if (enable) | ||
366 | val |= KBC_CONTROL_KEYPRESS_INT_EN; | ||
367 | else | ||
368 | val &= ~KBC_CONTROL_KEYPRESS_INT_EN; | ||
369 | writel(val, kbc->mmio + KBC_CONTROL_0); | ||
370 | } | ||
371 | |||
372 | static void tegra_kbc_keypress_timer(unsigned long data) | 242 | static void tegra_kbc_keypress_timer(unsigned long data) |
373 | { | 243 | { |
374 | struct tegra_kbc *kbc = (struct tegra_kbc *)data; | 244 | struct tegra_kbc *kbc = (struct tegra_kbc *)data; |
@@ -439,12 +309,11 @@ static irqreturn_t tegra_kbc_isr(int irq, void *args) | |||
439 | 309 | ||
440 | static void tegra_kbc_setup_wakekeys(struct tegra_kbc *kbc, bool filter) | 310 | static void tegra_kbc_setup_wakekeys(struct tegra_kbc *kbc, bool filter) |
441 | { | 311 | { |
442 | const struct tegra_kbc_platform_data *pdata = kbc->pdata; | ||
443 | int i; | 312 | int i; |
444 | unsigned int rst_val; | 313 | unsigned int rst_val; |
445 | 314 | ||
446 | /* Either mask all keys or none. */ | 315 | /* Either mask all keys or none. */ |
447 | rst_val = (filter && !pdata->wakeup) ? ~0 : 0; | 316 | rst_val = (filter && !kbc->wakeup) ? ~0 : 0; |
448 | 317 | ||
449 | for (i = 0; i < KBC_MAX_ROW; i++) | 318 | for (i = 0; i < KBC_MAX_ROW; i++) |
450 | writel(rst_val, kbc->mmio + KBC_ROW0_MASK_0 + i * 4); | 319 | writel(rst_val, kbc->mmio + KBC_ROW0_MASK_0 + i * 4); |
@@ -452,7 +321,6 @@ static void tegra_kbc_setup_wakekeys(struct tegra_kbc *kbc, bool filter) | |||
452 | 321 | ||
453 | static void tegra_kbc_config_pins(struct tegra_kbc *kbc) | 322 | static void tegra_kbc_config_pins(struct tegra_kbc *kbc) |
454 | { | 323 | { |
455 | const struct tegra_kbc_platform_data *pdata = kbc->pdata; | ||
456 | int i; | 324 | int i; |
457 | 325 | ||
458 | for (i = 0; i < KBC_MAX_GPIO; i++) { | 326 | for (i = 0; i < KBC_MAX_GPIO; i++) { |
@@ -468,13 +336,13 @@ static void tegra_kbc_config_pins(struct tegra_kbc *kbc) | |||
468 | row_cfg &= ~r_mask; | 336 | row_cfg &= ~r_mask; |
469 | col_cfg &= ~c_mask; | 337 | col_cfg &= ~c_mask; |
470 | 338 | ||
471 | switch (pdata->pin_cfg[i].type) { | 339 | switch (kbc->pin_cfg[i].type) { |
472 | case PIN_CFG_ROW: | 340 | case PIN_CFG_ROW: |
473 | row_cfg |= ((pdata->pin_cfg[i].num << 1) | 1) << r_shft; | 341 | row_cfg |= ((kbc->pin_cfg[i].num << 1) | 1) << r_shft; |
474 | break; | 342 | break; |
475 | 343 | ||
476 | case PIN_CFG_COL: | 344 | case PIN_CFG_COL: |
477 | col_cfg |= ((pdata->pin_cfg[i].num << 1) | 1) << c_shft; | 345 | col_cfg |= ((kbc->pin_cfg[i].num << 1) | 1) << c_shft; |
478 | break; | 346 | break; |
479 | 347 | ||
480 | case PIN_CFG_IGNORE: | 348 | case PIN_CFG_IGNORE: |
@@ -488,7 +356,6 @@ static void tegra_kbc_config_pins(struct tegra_kbc *kbc) | |||
488 | 356 | ||
489 | static int tegra_kbc_start(struct tegra_kbc *kbc) | 357 | static int tegra_kbc_start(struct tegra_kbc *kbc) |
490 | { | 358 | { |
491 | const struct tegra_kbc_platform_data *pdata = kbc->pdata; | ||
492 | unsigned int debounce_cnt; | 359 | unsigned int debounce_cnt; |
493 | u32 val = 0; | 360 | u32 val = 0; |
494 | 361 | ||
@@ -503,10 +370,10 @@ static int tegra_kbc_start(struct tegra_kbc *kbc) | |||
503 | tegra_kbc_config_pins(kbc); | 370 | tegra_kbc_config_pins(kbc); |
504 | tegra_kbc_setup_wakekeys(kbc, false); | 371 | tegra_kbc_setup_wakekeys(kbc, false); |
505 | 372 | ||
506 | writel(pdata->repeat_cnt, kbc->mmio + KBC_RPT_DLY_0); | 373 | writel(kbc->repeat_cnt, kbc->mmio + KBC_RPT_DLY_0); |
507 | 374 | ||
508 | /* Keyboard debounce count is maximum of 12 bits. */ | 375 | /* Keyboard debounce count is maximum of 12 bits. */ |
509 | debounce_cnt = min(pdata->debounce_cnt, KBC_MAX_DEBOUNCE_CNT); | 376 | debounce_cnt = min(kbc->debounce_cnt, KBC_MAX_DEBOUNCE_CNT); |
510 | val = KBC_DEBOUNCE_CNT_SHIFT(debounce_cnt); | 377 | val = KBC_DEBOUNCE_CNT_SHIFT(debounce_cnt); |
511 | val |= KBC_FIFO_TH_CNT_SHIFT(1); /* set fifo interrupt threshold to 1 */ | 378 | val |= KBC_FIFO_TH_CNT_SHIFT(1); /* set fifo interrupt threshold to 1 */ |
512 | val |= KBC_CONTROL_FIFO_CNT_INT_EN; /* interrupt on FIFO threshold */ | 379 | val |= KBC_CONTROL_FIFO_CNT_INT_EN; /* interrupt on FIFO threshold */ |
@@ -573,21 +440,20 @@ static void tegra_kbc_close(struct input_dev *dev) | |||
573 | return tegra_kbc_stop(kbc); | 440 | return tegra_kbc_stop(kbc); |
574 | } | 441 | } |
575 | 442 | ||
576 | static bool | 443 | static bool tegra_kbc_check_pin_cfg(const struct tegra_kbc *kbc, |
577 | tegra_kbc_check_pin_cfg(const struct tegra_kbc_platform_data *pdata, | 444 | unsigned int *num_rows) |
578 | struct device *dev, unsigned int *num_rows) | ||
579 | { | 445 | { |
580 | int i; | 446 | int i; |
581 | 447 | ||
582 | *num_rows = 0; | 448 | *num_rows = 0; |
583 | 449 | ||
584 | for (i = 0; i < KBC_MAX_GPIO; i++) { | 450 | for (i = 0; i < KBC_MAX_GPIO; i++) { |
585 | const struct tegra_kbc_pin_cfg *pin_cfg = &pdata->pin_cfg[i]; | 451 | const struct tegra_kbc_pin_cfg *pin_cfg = &kbc->pin_cfg[i]; |
586 | 452 | ||
587 | switch (pin_cfg->type) { | 453 | switch (pin_cfg->type) { |
588 | case PIN_CFG_ROW: | 454 | case PIN_CFG_ROW: |
589 | if (pin_cfg->num >= KBC_MAX_ROW) { | 455 | if (pin_cfg->num >= KBC_MAX_ROW) { |
590 | dev_err(dev, | 456 | dev_err(kbc->dev, |
591 | "pin_cfg[%d]: invalid row number %d\n", | 457 | "pin_cfg[%d]: invalid row number %d\n", |
592 | i, pin_cfg->num); | 458 | i, pin_cfg->num); |
593 | return false; | 459 | return false; |
@@ -597,7 +463,7 @@ tegra_kbc_check_pin_cfg(const struct tegra_kbc_platform_data *pdata, | |||
597 | 463 | ||
598 | case PIN_CFG_COL: | 464 | case PIN_CFG_COL: |
599 | if (pin_cfg->num >= KBC_MAX_COL) { | 465 | if (pin_cfg->num >= KBC_MAX_COL) { |
600 | dev_err(dev, | 466 | dev_err(kbc->dev, |
601 | "pin_cfg[%d]: invalid column number %d\n", | 467 | "pin_cfg[%d]: invalid column number %d\n", |
602 | i, pin_cfg->num); | 468 | i, pin_cfg->num); |
603 | return false; | 469 | return false; |
@@ -608,7 +474,7 @@ tegra_kbc_check_pin_cfg(const struct tegra_kbc_platform_data *pdata, | |||
608 | break; | 474 | break; |
609 | 475 | ||
610 | default: | 476 | default: |
611 | dev_err(dev, | 477 | dev_err(kbc->dev, |
612 | "pin_cfg[%d]: invalid entry type %d\n", | 478 | "pin_cfg[%d]: invalid entry type %d\n", |
613 | pin_cfg->type, pin_cfg->num); | 479 | pin_cfg->type, pin_cfg->num); |
614 | return false; | 480 | return false; |
@@ -618,154 +484,140 @@ tegra_kbc_check_pin_cfg(const struct tegra_kbc_platform_data *pdata, | |||
618 | return true; | 484 | return true; |
619 | } | 485 | } |
620 | 486 | ||
621 | #ifdef CONFIG_OF | 487 | static int tegra_kbc_parse_dt(struct tegra_kbc *kbc) |
622 | static struct tegra_kbc_platform_data *tegra_kbc_dt_parse_pdata( | ||
623 | struct platform_device *pdev) | ||
624 | { | 488 | { |
625 | struct tegra_kbc_platform_data *pdata; | 489 | struct device_node *np = kbc->dev->of_node; |
626 | struct device_node *np = pdev->dev.of_node; | ||
627 | u32 prop; | 490 | u32 prop; |
628 | int i; | 491 | int i; |
629 | 492 | u32 num_rows = 0; | |
630 | if (!np) | 493 | u32 num_cols = 0; |
631 | return NULL; | 494 | u32 cols_cfg[KBC_MAX_GPIO]; |
632 | 495 | u32 rows_cfg[KBC_MAX_GPIO]; | |
633 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); | 496 | int proplen; |
634 | if (!pdata) | 497 | int ret; |
635 | return NULL; | ||
636 | 498 | ||
637 | if (!of_property_read_u32(np, "nvidia,debounce-delay-ms", &prop)) | 499 | if (!of_property_read_u32(np, "nvidia,debounce-delay-ms", &prop)) |
638 | pdata->debounce_cnt = prop; | 500 | kbc->debounce_cnt = prop; |
639 | 501 | ||
640 | if (!of_property_read_u32(np, "nvidia,repeat-delay-ms", &prop)) | 502 | if (!of_property_read_u32(np, "nvidia,repeat-delay-ms", &prop)) |
641 | pdata->repeat_cnt = prop; | 503 | kbc->repeat_cnt = prop; |
642 | 504 | ||
643 | if (of_find_property(np, "nvidia,needs-ghost-filter", NULL)) | 505 | if (of_find_property(np, "nvidia,needs-ghost-filter", NULL)) |
644 | pdata->use_ghost_filter = true; | 506 | kbc->use_ghost_filter = true; |
645 | 507 | ||
646 | if (of_find_property(np, "nvidia,wakeup-source", NULL)) | 508 | if (of_find_property(np, "nvidia,wakeup-source", NULL)) |
647 | pdata->wakeup = true; | 509 | kbc->wakeup = true; |
648 | 510 | ||
649 | /* | 511 | if (!of_get_property(np, "nvidia,kbc-row-pins", &proplen)) { |
650 | * All currently known keymaps with device tree support use the same | 512 | dev_err(kbc->dev, "property nvidia,kbc-row-pins not found\n"); |
651 | * pin_cfg, so set it up here. | 513 | return -ENOENT; |
652 | */ | ||
653 | for (i = 0; i < KBC_MAX_ROW; i++) { | ||
654 | pdata->pin_cfg[i].num = i; | ||
655 | pdata->pin_cfg[i].type = PIN_CFG_ROW; | ||
656 | } | 514 | } |
515 | num_rows = proplen / sizeof(u32); | ||
657 | 516 | ||
658 | for (i = 0; i < KBC_MAX_COL; i++) { | 517 | if (!of_get_property(np, "nvidia,kbc-col-pins", &proplen)) { |
659 | pdata->pin_cfg[KBC_MAX_ROW + i].num = i; | 518 | dev_err(kbc->dev, "property nvidia,kbc-col-pins not found\n"); |
660 | pdata->pin_cfg[KBC_MAX_ROW + i].type = PIN_CFG_COL; | 519 | return -ENOENT; |
661 | } | 520 | } |
521 | num_cols = proplen / sizeof(u32); | ||
662 | 522 | ||
663 | return pdata; | 523 | if (!of_get_property(np, "linux,keymap", &proplen)) { |
664 | } | 524 | dev_err(kbc->dev, "property linux,keymap not found\n"); |
665 | #else | 525 | return -ENOENT; |
666 | static inline struct tegra_kbc_platform_data *tegra_kbc_dt_parse_pdata( | 526 | } |
667 | struct platform_device *pdev) | ||
668 | { | ||
669 | return NULL; | ||
670 | } | ||
671 | #endif | ||
672 | 527 | ||
673 | static int tegra_kbd_setup_keymap(struct tegra_kbc *kbc) | 528 | if (!num_rows || !num_cols || ((num_rows + num_cols) > KBC_MAX_GPIO)) { |
674 | { | 529 | dev_err(kbc->dev, |
675 | const struct tegra_kbc_platform_data *pdata = kbc->pdata; | 530 | "keypad rows/columns not porperly specified\n"); |
676 | const struct matrix_keymap_data *keymap_data = pdata->keymap_data; | 531 | return -EINVAL; |
677 | unsigned int keymap_rows = KBC_MAX_KEY; | 532 | } |
678 | int retval; | ||
679 | 533 | ||
680 | if (keymap_data && pdata->use_fn_map) | 534 | /* Set all pins as non-configured */ |
681 | keymap_rows *= 2; | 535 | for (i = 0; i < KBC_MAX_GPIO; i++) |
536 | kbc->pin_cfg[i].type = PIN_CFG_IGNORE; | ||
682 | 537 | ||
683 | retval = matrix_keypad_build_keymap(keymap_data, NULL, | 538 | ret = of_property_read_u32_array(np, "nvidia,kbc-row-pins", |
684 | keymap_rows, KBC_MAX_COL, | 539 | rows_cfg, num_rows); |
685 | kbc->keycode, kbc->idev); | 540 | if (ret < 0) { |
686 | if (retval == -ENOSYS || retval == -ENOENT) { | 541 | dev_err(kbc->dev, "Rows configurations are not proper\n"); |
687 | /* | 542 | return -EINVAL; |
688 | * If there is no OF support in kernel or keymap | 543 | } |
689 | * property is missing, use default keymap. | 544 | |
690 | */ | 545 | ret = of_property_read_u32_array(np, "nvidia,kbc-col-pins", |
691 | retval = matrix_keypad_build_keymap( | 546 | cols_cfg, num_cols); |
692 | &tegra_kbc_default_keymap_data, NULL, | 547 | if (ret < 0) { |
693 | keymap_rows, KBC_MAX_COL, | 548 | dev_err(kbc->dev, "Cols configurations are not proper\n"); |
694 | kbc->keycode, kbc->idev); | 549 | return -EINVAL; |
550 | } | ||
551 | |||
552 | for (i = 0; i < num_rows; i++) { | ||
553 | kbc->pin_cfg[rows_cfg[i]].type = PIN_CFG_ROW; | ||
554 | kbc->pin_cfg[rows_cfg[i]].num = i; | ||
695 | } | 555 | } |
696 | 556 | ||
697 | return retval; | 557 | for (i = 0; i < num_cols; i++) { |
558 | kbc->pin_cfg[cols_cfg[i]].type = PIN_CFG_COL; | ||
559 | kbc->pin_cfg[cols_cfg[i]].num = i; | ||
560 | } | ||
561 | |||
562 | return 0; | ||
698 | } | 563 | } |
699 | 564 | ||
700 | static int tegra_kbc_probe(struct platform_device *pdev) | 565 | static int tegra_kbc_probe(struct platform_device *pdev) |
701 | { | 566 | { |
702 | const struct tegra_kbc_platform_data *pdata = pdev->dev.platform_data; | ||
703 | struct tegra_kbc *kbc; | 567 | struct tegra_kbc *kbc; |
704 | struct input_dev *input_dev; | ||
705 | struct resource *res; | 568 | struct resource *res; |
706 | int irq; | ||
707 | int err; | 569 | int err; |
708 | int num_rows = 0; | 570 | int num_rows = 0; |
709 | unsigned int debounce_cnt; | 571 | unsigned int debounce_cnt; |
710 | unsigned int scan_time_rows; | 572 | unsigned int scan_time_rows; |
573 | unsigned int keymap_rows = KBC_MAX_KEY; | ||
711 | 574 | ||
712 | if (!pdata) | 575 | kbc = devm_kzalloc(&pdev->dev, sizeof(*kbc), GFP_KERNEL); |
713 | pdata = tegra_kbc_dt_parse_pdata(pdev); | 576 | if (!kbc) { |
577 | dev_err(&pdev->dev, "failed to alloc memory for kbc\n"); | ||
578 | return -ENOMEM; | ||
579 | } | ||
714 | 580 | ||
715 | if (!pdata) | 581 | kbc->dev = &pdev->dev; |
716 | return -EINVAL; | 582 | spin_lock_init(&kbc->lock); |
717 | 583 | ||
718 | if (!tegra_kbc_check_pin_cfg(pdata, &pdev->dev, &num_rows)) { | 584 | err = tegra_kbc_parse_dt(kbc); |
719 | err = -EINVAL; | 585 | if (err) |
720 | goto err_free_pdata; | 586 | return err; |
721 | } | 587 | |
588 | if (!tegra_kbc_check_pin_cfg(kbc, &num_rows)) | ||
589 | return -EINVAL; | ||
722 | 590 | ||
723 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 591 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
724 | if (!res) { | 592 | if (!res) { |
725 | dev_err(&pdev->dev, "failed to get I/O memory\n"); | 593 | dev_err(&pdev->dev, "failed to get I/O memory\n"); |
726 | err = -ENXIO; | 594 | return -ENXIO; |
727 | goto err_free_pdata; | ||
728 | } | 595 | } |
729 | 596 | ||
730 | irq = platform_get_irq(pdev, 0); | 597 | kbc->irq = platform_get_irq(pdev, 0); |
731 | if (irq < 0) { | 598 | if (kbc->irq < 0) { |
732 | dev_err(&pdev->dev, "failed to get keyboard IRQ\n"); | 599 | dev_err(&pdev->dev, "failed to get keyboard IRQ\n"); |
733 | err = -ENXIO; | 600 | return -ENXIO; |
734 | goto err_free_pdata; | ||
735 | } | 601 | } |
736 | 602 | ||
737 | kbc = kzalloc(sizeof(*kbc), GFP_KERNEL); | 603 | kbc->idev = devm_input_allocate_device(&pdev->dev); |
738 | input_dev = input_allocate_device(); | 604 | if (!kbc->idev) { |
739 | if (!kbc || !input_dev) { | 605 | dev_err(&pdev->dev, "failed to allocate input device\n"); |
740 | err = -ENOMEM; | 606 | return -ENOMEM; |
741 | goto err_free_mem; | ||
742 | } | 607 | } |
743 | 608 | ||
744 | kbc->pdata = pdata; | ||
745 | kbc->idev = input_dev; | ||
746 | kbc->irq = irq; | ||
747 | spin_lock_init(&kbc->lock); | ||
748 | setup_timer(&kbc->timer, tegra_kbc_keypress_timer, (unsigned long)kbc); | 609 | setup_timer(&kbc->timer, tegra_kbc_keypress_timer, (unsigned long)kbc); |
749 | 610 | ||
750 | res = request_mem_region(res->start, resource_size(res), pdev->name); | 611 | kbc->mmio = devm_request_and_ioremap(&pdev->dev, res); |
751 | if (!res) { | ||
752 | dev_err(&pdev->dev, "failed to request I/O memory\n"); | ||
753 | err = -EBUSY; | ||
754 | goto err_free_mem; | ||
755 | } | ||
756 | |||
757 | kbc->mmio = ioremap(res->start, resource_size(res)); | ||
758 | if (!kbc->mmio) { | 612 | if (!kbc->mmio) { |
759 | dev_err(&pdev->dev, "failed to remap I/O memory\n"); | 613 | dev_err(&pdev->dev, "Cannot request memregion/iomap address\n"); |
760 | err = -ENXIO; | 614 | return -EBUSY; |
761 | goto err_free_mem_region; | ||
762 | } | 615 | } |
763 | 616 | ||
764 | kbc->clk = clk_get(&pdev->dev, NULL); | 617 | kbc->clk = devm_clk_get(&pdev->dev, NULL); |
765 | if (IS_ERR(kbc->clk)) { | 618 | if (IS_ERR(kbc->clk)) { |
766 | dev_err(&pdev->dev, "failed to get keyboard clock\n"); | 619 | dev_err(&pdev->dev, "failed to get keyboard clock\n"); |
767 | err = PTR_ERR(kbc->clk); | 620 | return PTR_ERR(kbc->clk); |
768 | goto err_iounmap; | ||
769 | } | 621 | } |
770 | 622 | ||
771 | /* | 623 | /* |
@@ -774,37 +626,38 @@ static int tegra_kbc_probe(struct platform_device *pdev) | |||
774 | * the rows. There is an additional delay before the row scanning | 626 | * the rows. There is an additional delay before the row scanning |
775 | * starts. The repoll delay is computed in milliseconds. | 627 | * starts. The repoll delay is computed in milliseconds. |
776 | */ | 628 | */ |
777 | debounce_cnt = min(pdata->debounce_cnt, KBC_MAX_DEBOUNCE_CNT); | 629 | debounce_cnt = min(kbc->debounce_cnt, KBC_MAX_DEBOUNCE_CNT); |
778 | scan_time_rows = (KBC_ROW_SCAN_TIME + debounce_cnt) * num_rows; | 630 | scan_time_rows = (KBC_ROW_SCAN_TIME + debounce_cnt) * num_rows; |
779 | kbc->repoll_dly = KBC_ROW_SCAN_DLY + scan_time_rows + pdata->repeat_cnt; | 631 | kbc->repoll_dly = KBC_ROW_SCAN_DLY + scan_time_rows + kbc->repeat_cnt; |
780 | kbc->repoll_dly = DIV_ROUND_UP(kbc->repoll_dly, KBC_CYCLE_MS); | 632 | kbc->repoll_dly = DIV_ROUND_UP(kbc->repoll_dly, KBC_CYCLE_MS); |
781 | 633 | ||
782 | kbc->wakeup_key = pdata->wakeup_key; | 634 | kbc->idev->name = pdev->name; |
783 | kbc->use_fn_map = pdata->use_fn_map; | 635 | kbc->idev->id.bustype = BUS_HOST; |
784 | kbc->use_ghost_filter = pdata->use_ghost_filter; | 636 | kbc->idev->dev.parent = &pdev->dev; |
637 | kbc->idev->open = tegra_kbc_open; | ||
638 | kbc->idev->close = tegra_kbc_close; | ||
785 | 639 | ||
786 | input_dev->name = pdev->name; | 640 | if (kbc->keymap_data && kbc->use_fn_map) |
787 | input_dev->id.bustype = BUS_HOST; | 641 | keymap_rows *= 2; |
788 | input_dev->dev.parent = &pdev->dev; | ||
789 | input_dev->open = tegra_kbc_open; | ||
790 | input_dev->close = tegra_kbc_close; | ||
791 | 642 | ||
792 | err = tegra_kbd_setup_keymap(kbc); | 643 | err = matrix_keypad_build_keymap(kbc->keymap_data, NULL, |
644 | keymap_rows, KBC_MAX_COL, | ||
645 | kbc->keycode, kbc->idev); | ||
793 | if (err) { | 646 | if (err) { |
794 | dev_err(&pdev->dev, "failed to setup keymap\n"); | 647 | dev_err(&pdev->dev, "failed to setup keymap\n"); |
795 | goto err_put_clk; | 648 | return err; |
796 | } | 649 | } |
797 | 650 | ||
798 | __set_bit(EV_REP, input_dev->evbit); | 651 | __set_bit(EV_REP, kbc->idev->evbit); |
799 | input_set_capability(input_dev, EV_MSC, MSC_SCAN); | 652 | input_set_capability(kbc->idev, EV_MSC, MSC_SCAN); |
800 | 653 | ||
801 | input_set_drvdata(input_dev, kbc); | 654 | input_set_drvdata(kbc->idev, kbc); |
802 | 655 | ||
803 | err = request_irq(kbc->irq, tegra_kbc_isr, | 656 | err = devm_request_irq(&pdev->dev, kbc->irq, tegra_kbc_isr, |
804 | IRQF_NO_SUSPEND | IRQF_TRIGGER_HIGH, pdev->name, kbc); | 657 | IRQF_NO_SUSPEND | IRQF_TRIGGER_HIGH, pdev->name, kbc); |
805 | if (err) { | 658 | if (err) { |
806 | dev_err(&pdev->dev, "failed to request keyboard IRQ\n"); | 659 | dev_err(&pdev->dev, "failed to request keyboard IRQ\n"); |
807 | goto err_put_clk; | 660 | return err; |
808 | } | 661 | } |
809 | 662 | ||
810 | disable_irq(kbc->irq); | 663 | disable_irq(kbc->irq); |
@@ -812,60 +665,28 @@ static int tegra_kbc_probe(struct platform_device *pdev) | |||
812 | err = input_register_device(kbc->idev); | 665 | err = input_register_device(kbc->idev); |
813 | if (err) { | 666 | if (err) { |
814 | dev_err(&pdev->dev, "failed to register input device\n"); | 667 | dev_err(&pdev->dev, "failed to register input device\n"); |
815 | goto err_free_irq; | 668 | return err; |
816 | } | 669 | } |
817 | 670 | ||
818 | platform_set_drvdata(pdev, kbc); | 671 | platform_set_drvdata(pdev, kbc); |
819 | device_init_wakeup(&pdev->dev, pdata->wakeup); | 672 | device_init_wakeup(&pdev->dev, kbc->wakeup); |
820 | 673 | ||
821 | return 0; | 674 | return 0; |
822 | |||
823 | err_free_irq: | ||
824 | free_irq(kbc->irq, pdev); | ||
825 | err_put_clk: | ||
826 | clk_put(kbc->clk); | ||
827 | err_iounmap: | ||
828 | iounmap(kbc->mmio); | ||
829 | err_free_mem_region: | ||
830 | release_mem_region(res->start, resource_size(res)); | ||
831 | err_free_mem: | ||
832 | input_free_device(input_dev); | ||
833 | kfree(kbc); | ||
834 | err_free_pdata: | ||
835 | if (!pdev->dev.platform_data) | ||
836 | kfree(pdata); | ||
837 | |||
838 | return err; | ||
839 | } | 675 | } |
840 | 676 | ||
841 | static int tegra_kbc_remove(struct platform_device *pdev) | 677 | #ifdef CONFIG_PM_SLEEP |
678 | static void tegra_kbc_set_keypress_interrupt(struct tegra_kbc *kbc, bool enable) | ||
842 | { | 679 | { |
843 | struct tegra_kbc *kbc = platform_get_drvdata(pdev); | 680 | u32 val; |
844 | struct resource *res; | ||
845 | |||
846 | platform_set_drvdata(pdev, NULL); | ||
847 | |||
848 | free_irq(kbc->irq, pdev); | ||
849 | clk_put(kbc->clk); | ||
850 | |||
851 | input_unregister_device(kbc->idev); | ||
852 | iounmap(kbc->mmio); | ||
853 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
854 | release_mem_region(res->start, resource_size(res)); | ||
855 | |||
856 | /* | ||
857 | * If we do not have platform data attached to the device we | ||
858 | * allocated it ourselves and thus need to free it. | ||
859 | */ | ||
860 | if (!pdev->dev.platform_data) | ||
861 | kfree(kbc->pdata); | ||
862 | |||
863 | kfree(kbc); | ||
864 | 681 | ||
865 | return 0; | 682 | val = readl(kbc->mmio + KBC_CONTROL_0); |
683 | if (enable) | ||
684 | val |= KBC_CONTROL_KEYPRESS_INT_EN; | ||
685 | else | ||
686 | val &= ~KBC_CONTROL_KEYPRESS_INT_EN; | ||
687 | writel(val, kbc->mmio + KBC_CONTROL_0); | ||
866 | } | 688 | } |
867 | 689 | ||
868 | #ifdef CONFIG_PM_SLEEP | ||
869 | static int tegra_kbc_suspend(struct device *dev) | 690 | static int tegra_kbc_suspend(struct device *dev) |
870 | { | 691 | { |
871 | struct platform_device *pdev = to_platform_device(dev); | 692 | struct platform_device *pdev = to_platform_device(dev); |
@@ -954,7 +775,6 @@ MODULE_DEVICE_TABLE(of, tegra_kbc_of_match); | |||
954 | 775 | ||
955 | static struct platform_driver tegra_kbc_driver = { | 776 | static struct platform_driver tegra_kbc_driver = { |
956 | .probe = tegra_kbc_probe, | 777 | .probe = tegra_kbc_probe, |
957 | .remove = tegra_kbc_remove, | ||
958 | .driver = { | 778 | .driver = { |
959 | .name = "tegra-kbc", | 779 | .name = "tegra-kbc", |
960 | .owner = THIS_MODULE, | 780 | .owner = THIS_MODULE, |