Skip to content

Commit a445c7f

Browse files
olofjdtor
authored andcommitted
Input: tegra-kbc - add device tree bindings
This adds a simple device tree binding to the tegra keyboard controller. Also, mark the default keymap as __devinitdata since it is not referenced after boot. Signed-off-by: Olof Johansson <olof@lixom.net> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
1 parent 5245db4 commit a445c7f

2 files changed

Lines changed: 102 additions & 8 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
* Tegra keyboard controller
2+
3+
Required properties:
4+
- compatible: "nvidia,tegra20-kbc"
5+
6+
Optional properties:
7+
- debounce-delay: delay in milliseconds per row scan for debouncing
8+
- repeat-delay: delay in milliseconds before repeat starts
9+
- ghost-filter: enable ghost filtering for this device
10+
- wakeup-source: configure keyboard as a wakeup source for suspend/resume
11+
12+
Example:
13+
14+
keyboard: keyboard {
15+
compatible = "nvidia,tegra20-kbc";
16+
reg = <0x7000e200 0x100>;
17+
ghost-filter;
18+
};

‎drivers/input/keyboard/tegra-kbc.c‎

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/delay.h>
2727
#include <linux/io.h>
2828
#include <linux/interrupt.h>
29+
#include <linux/of.h>
2930
#include <linux/clk.h>
3031
#include <linux/slab.h>
3132
#include <mach/clk.h>
@@ -82,7 +83,7 @@ struct tegra_kbc {
8283
struct clk *clk;
8384
};
8485

85-
static const u32 tegra_kbc_default_keymap[] = {
86+
static const u32 tegra_kbc_default_keymap[] __devinitdata = {
8687
KEY(0, 2, KEY_W),
8788
KEY(0, 3, KEY_S),
8889
KEY(0, 4, KEY_A),
@@ -217,7 +218,8 @@ static const u32 tegra_kbc_default_keymap[] = {
217218
KEY(31, 4, KEY_HELP),
218219
};
219220

220-
static const struct matrix_keymap_data tegra_kbc_default_keymap_data = {
221+
static const
222+
struct matrix_keymap_data tegra_kbc_default_keymap_data __devinitdata = {
221223
.keymap = tegra_kbc_default_keymap,
222224
.keymap_size = ARRAY_SIZE(tegra_kbc_default_keymap),
223225
};
@@ -576,6 +578,56 @@ tegra_kbc_check_pin_cfg(const struct tegra_kbc_platform_data *pdata,
576578
return true;
577579
}
578580

581+
#ifdef CONFIG_OF
582+
static struct tegra_kbc_platform_data * __devinit
583+
tegra_kbc_dt_parse_pdata(struct platform_device *pdev)
584+
{
585+
struct tegra_kbc_platform_data *pdata;
586+
struct device_node *np = pdev->dev.of_node;
587+
588+
if (!np)
589+
return NULL;
590+
591+
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
592+
if (!pdata)
593+
return NULL;
594+
595+
if (!of_property_read_u32(np, "debounce-delay", &prop))
596+
pdata->debounce_cnt = prop;
597+
598+
if (!of_property_read_u32(np, "repeat-delay", &prop))
599+
pdata->repeat_cnt = prop;
600+
601+
if (of_find_property(np, "needs-ghost-filter", NULL))
602+
pdata->use_ghost_filter = true;
603+
604+
if (of_find_property(np, "wakeup-source", NULL))
605+
pdata->wakeup = true;
606+
607+
/*
608+
* All currently known keymaps with device tree support use the same
609+
* pin_cfg, so set it up here.
610+
*/
611+
for (i = 0; i < KBC_MAX_ROW; i++) {
612+
pdata->pin_cfg[i].num = i;
613+
pdata->pin_cfg[i].is_row = true;
614+
}
615+
616+
for (i = 0; i < KBC_MAX_COL; i++) {
617+
pdata->pin_cfg[KBC_MAX_ROW + i].num = i;
618+
pdata->pin_cfg[KBC_MAX_ROW + i].is_row = false;
619+
}
620+
621+
return pdata;
622+
}
623+
#else
624+
static inline struct tegra_kbc_platform_data *tegra_kbc_dt_parse_pdata(
625+
struct platform_device *pdev)
626+
{
627+
return NULL;
628+
}
629+
#endif
630+
579631
static int __devinit tegra_kbc_probe(struct platform_device *pdev)
580632
{
581633
const struct tegra_kbc_platform_data *pdata = pdev->dev.platform_data;
@@ -590,21 +642,28 @@ static int __devinit tegra_kbc_probe(struct platform_device *pdev)
590642
unsigned int scan_time_rows;
591643

592644
if (!pdata)
593-
return -EINVAL;
645+
pdata = tegra_kbc_dt_parse_pdata(pdev);
594646

595-
if (!tegra_kbc_check_pin_cfg(pdata, &pdev->dev, &num_rows))
647+
if (!pdata)
596648
return -EINVAL;
597649

650+
if (!tegra_kbc_check_pin_cfg(pdata, &pdev->dev, &num_rows)) {
651+
err = -EINVAL;
652+
goto err_free_pdata;
653+
}
654+
598655
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
599656
if (!res) {
600657
dev_err(&pdev->dev, "failed to get I/O memory\n");
601-
return -ENXIO;
658+
err = -ENXIO;
659+
goto err_free_pdata;
602660
}
603661

604662
irq = platform_get_irq(pdev, 0);
605663
if (irq < 0) {
606664
dev_err(&pdev->dev, "failed to get keyboard IRQ\n");
607-
return -ENXIO;
665+
err = -ENXIO;
666+
goto err_free_pdata;
608667
}
609668

610669
kbc = kzalloc(sizeof(*kbc), GFP_KERNEL);
@@ -706,6 +765,9 @@ static int __devinit tegra_kbc_probe(struct platform_device *pdev)
706765
err_free_mem:
707766
input_free_device(input_dev);
708767
kfree(kbc);
768+
err_free_pdata:
769+
if (!pdev->dev.platform_data)
770+
kfree(pdata);
709771

710772
return err;
711773
}
@@ -715,6 +777,8 @@ static int __devexit tegra_kbc_remove(struct platform_device *pdev)
715777
struct tegra_kbc *kbc = platform_get_drvdata(pdev);
716778
struct resource *res;
717779

780+
platform_set_drvdata(pdev, NULL);
781+
718782
free_irq(kbc->irq, pdev);
719783
clk_put(kbc->clk);
720784

@@ -723,9 +787,14 @@ static int __devexit tegra_kbc_remove(struct platform_device *pdev)
723787
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
724788
release_mem_region(res->start, resource_size(res));
725789

726-
kfree(kbc);
790+
/*
791+
* If we do not have platform data attached to the device we
792+
* allocated it ourselves and thus need to free it.
793+
*/
794+
if (!pdev->dev.platform_data)
795+
kfree(kbc->pdata);
727796

728-
platform_set_drvdata(pdev, NULL);
797+
kfree(kbc);
729798

730799
return 0;
731800
}
@@ -793,13 +862,20 @@ static int tegra_kbc_resume(struct device *dev)
793862

794863
static SIMPLE_DEV_PM_OPS(tegra_kbc_pm_ops, tegra_kbc_suspend, tegra_kbc_resume);
795864

865+
static const struct of_device_id tegra_kbc_of_match[] = {
866+
{ .compatible = "nvidia,tegra20-kbc", },
867+
{ },
868+
};
869+
MODULE_DEVICE_TABLE(of, tegra_kbc_of_match);
870+
796871
static struct platform_driver tegra_kbc_driver = {
797872
.probe = tegra_kbc_probe,
798873
.remove = __devexit_p(tegra_kbc_remove),
799874
.driver = {
800875
.name = "tegra-kbc",
801876
.owner = THIS_MODULE,
802877
.pm = &tegra_kbc_pm_ops,
878+
.of_match_table = tegra_kbc_of_match,
803879
},
804880
};
805881
module_platform_driver(tegra_kbc_driver);

0 commit comments

Comments
 (0)