diff options
author | Jajambo Liao <jajambol@nvidia.com> | 2013-12-24 00:04:09 -0500 |
---|---|---|
committer | David Pu <dpu@nvidia.com> | 2017-07-27 19:09:19 -0400 |
commit | bb7565b1ab361b03792598bc81207e9f75801402 (patch) | |
tree | d3918a3f33e018264a961eef5c1115270a960a74 /drivers/input/touchscreen/rm31080a_ts.c | |
parent | a4b824bb9cd14f2b7be981f982332449c014f68e (diff) |
input: touch: raydium: add DT support to Raydium spi touch
Add device tree support to Raydium touch drivers
Bug 1405258
Change-Id: Ie93df28303866fcae73ddfb4ac191c7339adbe83
Signed-off-by: Jajambo Liao <jajambol@nvidia.com>
Reviewed-on: http://git-master/r/344059
Reviewed-by: Jordan Nien <jnien@nvidia.com>
Reviewed-by: Xiaohui Tao <xtao@nvidia.com>
Reviewed-by: Robert Collins <rcollins@nvidia.com>
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>
Diffstat (limited to 'drivers/input/touchscreen/rm31080a_ts.c')
-rw-r--r-- | drivers/input/touchscreen/rm31080a_ts.c | 111 |
1 files changed, 107 insertions, 4 deletions
diff --git a/drivers/input/touchscreen/rm31080a_ts.c b/drivers/input/touchscreen/rm31080a_ts.c index 25e299529..786dbe49f 100644 --- a/drivers/input/touchscreen/rm31080a_ts.c +++ b/drivers/input/touchscreen/rm31080a_ts.c | |||
@@ -25,6 +25,9 @@ | |||
25 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
26 | #include <linux/fb.h> | 26 | #include <linux/fb.h> |
27 | #include <linux/gpio.h> | 27 | #include <linux/gpio.h> |
28 | #include <linux/of.h> | ||
29 | #include <linux/of_device.h> | ||
30 | #include <linux/of_gpio.h> | ||
28 | #include <linux/sched.h> /* wake_up_process() */ | 31 | #include <linux/sched.h> /* wake_up_process() */ |
29 | #include <linux/kthread.h> /* kthread_create(),kthread_run() */ | 32 | #include <linux/kthread.h> /* kthread_create(),kthread_run() */ |
30 | #include <linux/uaccess.h> /* copy_to_user() */ | 33 | #include <linux/uaccess.h> /* copy_to_user() */ |
@@ -839,6 +842,74 @@ static u32 rm_tch_ctrl_configure(void) | |||
839 | return u32Flag; | 842 | return u32Flag; |
840 | } | 843 | } |
841 | 844 | ||
845 | static struct rm_spi_ts_platform_data *rm_ts_parse_dt(struct device *dev, | ||
846 | int irq) | ||
847 | { | ||
848 | struct rm_spi_ts_platform_data *pdata; | ||
849 | struct device_node *np = dev->of_node; | ||
850 | const char *str; | ||
851 | int ret, val, irq_gpio; | ||
852 | |||
853 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
854 | if (!pdata) | ||
855 | return ERR_PTR(-ENOMEM); | ||
856 | |||
857 | pdata->gpio_reset = of_get_named_gpio_flags(np, "reset-gpio", 0, NULL); | ||
858 | if (!gpio_is_valid(pdata->gpio_reset)) { | ||
859 | dev_err(dev, "Invalid reset-gpio\n"); | ||
860 | return ERR_PTR(-EINVAL); | ||
861 | } | ||
862 | ret = gpio_request(pdata->gpio_reset, "reset-gpio"); | ||
863 | if (ret < 0) { | ||
864 | dev_err(dev, "gpio_request fail\n"); | ||
865 | return ERR_PTR(-EINVAL); | ||
866 | } | ||
867 | gpio_direction_output(pdata->gpio_reset, 0); | ||
868 | |||
869 | ret = of_property_read_u32(np, "interrupts", &irq_gpio); | ||
870 | if (!gpio_is_valid(irq_gpio)) { | ||
871 | dev_err(dev, "Invalid irq-gpio\n"); | ||
872 | ret = -EINVAL; | ||
873 | goto exit_release_reset_gpio; | ||
874 | } | ||
875 | |||
876 | ret = gpio_request(irq_gpio, "irq-gpio"); | ||
877 | if (ret < 0) { | ||
878 | dev_err(dev, "irq_request fail\n"); | ||
879 | ret = -EINVAL; | ||
880 | goto exit_release_reset_gpio; | ||
881 | } | ||
882 | gpio_direction_input(irq_gpio); | ||
883 | |||
884 | ret = of_property_read_u32(np, "config", &val); | ||
885 | if (ret < 0) | ||
886 | goto exit_release_all_gpio; | ||
887 | pdata->config = val; | ||
888 | ret = of_property_read_u32(np, "platform-id", &val); | ||
889 | if (ret < 0) | ||
890 | goto exit_release_all_gpio; | ||
891 | pdata->platform_id = val; | ||
892 | ret = of_property_read_string(np, "name-of-clock", &str); | ||
893 | if (ret < 0) | ||
894 | goto exit_release_all_gpio; | ||
895 | pdata->name_of_clock = (char *)str; | ||
896 | |||
897 | ret = of_property_read_string(np, "name-of-clock-con", &str); | ||
898 | if (ret < 0) | ||
899 | goto exit_release_all_gpio; | ||
900 | pdata->name_of_clock_con = (char *)str; | ||
901 | |||
902 | return pdata; | ||
903 | |||
904 | exit_release_all_gpio: | ||
905 | gpio_free(irq_gpio); | ||
906 | |||
907 | exit_release_reset_gpio: | ||
908 | gpio_free(pdata->gpio_reset); | ||
909 | return ERR_PTR(ret); | ||
910 | |||
911 | } | ||
912 | |||
842 | int KRL_CMD_CONFIG_1V8_Handler(u8 CMD, u8 OnOff, struct rm_tch_ts *ts) | 913 | int KRL_CMD_CONFIG_1V8_Handler(u8 CMD, u8 OnOff, struct rm_tch_ts *ts) |
843 | { | 914 | { |
844 | int ret = FAIL; | 915 | int ret = FAIL; |
@@ -2629,6 +2700,17 @@ struct rm_tch_ts *rm_tch_input_init(struct device *dev, unsigned int irq, | |||
2629 | ts->input = input_dev; | 2700 | ts->input = input_dev; |
2630 | ts->irq = irq; | 2701 | ts->irq = irq; |
2631 | 2702 | ||
2703 | |||
2704 | if (dev->of_node) { | ||
2705 | pr_info("Load platform data from DT.\n"); | ||
2706 | pdata = rm_ts_parse_dt(dev, irq); | ||
2707 | if (IS_ERR(pdata)) { | ||
2708 | dev_err(&g_spi->dev, "Raydium - failed to parse dt\n"); | ||
2709 | err = -EINVAL; | ||
2710 | goto err_free_mem; | ||
2711 | } | ||
2712 | dev->platform_data = pdata; | ||
2713 | } | ||
2632 | pdata = dev->platform_data; | 2714 | pdata = dev->platform_data; |
2633 | 2715 | ||
2634 | if (pdata->name_of_clock || pdata->name_of_clock_con) { | 2716 | if (pdata->name_of_clock || pdata->name_of_clock_con) { |
@@ -2733,13 +2815,23 @@ struct rm_tch_ts *rm_tch_input_init(struct device *dev, unsigned int irq, | |||
2733 | ts->bops = bops; | 2815 | ts->bops = bops; |
2734 | ts->dev = dev; | 2816 | ts->dev = dev; |
2735 | ts->irq = irq; | 2817 | ts->irq = irq; |
2736 | 2818 | if (dev->of_node) { | |
2819 | pr_info("Load platform data from DT.\n"); | ||
2820 | pdata = rm_ts_parse_dt(dev, irq); | ||
2821 | if (IS_ERR(pdata)) { | ||
2822 | dev_err(&g_spi->dev, "Raydium - failed to parse dt\n"); | ||
2823 | err = -EINVAL; | ||
2824 | goto err_free_mem; | ||
2825 | } | ||
2826 | dev->platform_data = pdata; | ||
2827 | } | ||
2737 | pdata = dev->platform_data; | 2828 | pdata = dev->platform_data; |
2738 | if (pdata->name_of_clock || pdata->name_of_clock_con) { | 2829 | if (pdata->name_of_clock || pdata->name_of_clock_con) { |
2739 | ts->clk = clk_get_sys(pdata->name_of_clock, | 2830 | ts->clk = clk_get_sys(pdata->name_of_clock, |
2740 | pdata->name_of_clock_con); | 2831 | pdata->name_of_clock_con); |
2741 | if (IS_ERR(ts->clk)) { | 2832 | if (IS_ERR(ts->clk)) { |
2742 | dev_err(&g_spi->dev, "Raydium - failed to get touch_clk: (%s, %s)\n", | 2833 | dev_err(&g_spi->dev, |
2834 | "Raydium - failed to get touch_clk: (%s, %s)\n", | ||
2743 | pdata->name_of_clock, pdata->name_of_clock_con); | 2835 | pdata->name_of_clock, pdata->name_of_clock_con); |
2744 | err = -EINVAL; | 2836 | err = -EINVAL; |
2745 | goto err_free_ts_mem; | 2837 | goto err_free_ts_mem; |
@@ -2788,8 +2880,10 @@ struct rm_tch_ts *rm_tch_input_init(struct device *dev, unsigned int irq, | |||
2788 | __set_bit(EV_SYN, ts->input[index]->evbit); | 2880 | __set_bit(EV_SYN, ts->input[index]->evbit); |
2789 | 2881 | ||
2790 | __set_bit(EV_ABS, ts->input[index]->evbit); | 2882 | __set_bit(EV_ABS, ts->input[index]->evbit); |
2791 | input_set_abs_params(ts->input[index], ABS_MT_PRESSURE, 0, 0xFF, 0, 0); | 2883 | input_set_abs_params(ts->input[index], |
2792 | input_set_abs_params(ts->input[index], ABS_MT_TRACKING_ID, 0, 32, 0, 0); | 2884 | ABS_MT_PRESSURE, 0, 0xFF, 0, 0); |
2885 | input_set_abs_params(ts->input[index], | ||
2886 | ABS_MT_TRACKING_ID, 0, 32, 0, 0); | ||
2793 | 2887 | ||
2794 | if (index != INPUT_DEVICE_FOR_FINGER) { | 2888 | if (index != INPUT_DEVICE_FOR_FINGER) { |
2795 | __set_bit(EV_KEY, ts->input[index]->evbit); | 2889 | __set_bit(EV_KEY, ts->input[index]->evbit); |
@@ -3280,11 +3374,20 @@ err_spi_speed: | |||
3280 | return ret; | 3374 | return ret; |
3281 | } | 3375 | } |
3282 | 3376 | ||
3377 | static const struct of_device_id rm_ts_dt_match[] = { | ||
3378 | { .compatible = "raydium,rm_ts_spidev" }, | ||
3379 | { }, | ||
3380 | }; | ||
3381 | MODULE_DEVICE_TABLE(of, rm_ts_dt_match); | ||
3382 | |||
3283 | static struct spi_driver rm_tch_spi_driver = { | 3383 | static struct spi_driver rm_tch_spi_driver = { |
3284 | .driver = { | 3384 | .driver = { |
3285 | .name = "rm_ts_spidev", | 3385 | .name = "rm_ts_spidev", |
3286 | .bus = &spi_bus_type, | 3386 | .bus = &spi_bus_type, |
3287 | .owner = THIS_MODULE, | 3387 | .owner = THIS_MODULE, |
3388 | #ifdef CONFIG_OF | ||
3389 | .of_match_table = rm_ts_dt_match, | ||
3390 | #endif | ||
3288 | #if !defined(CONFIG_HAS_EARLYSUSPEND) | 3391 | #if !defined(CONFIG_HAS_EARLYSUSPEND) |
3289 | #ifdef CONFIG_PM | 3392 | #ifdef CONFIG_PM |
3290 | .pm = &rm_tch_pm_ops, | 3393 | .pm = &rm_tch_pm_ops, |