summaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorGigi Joseph <gigi.joseph@gmail.com>2015-01-08 22:45:02 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-01-12 08:04:10 -0500
commit46d0d33350e9b32642d745a8b46a954910196b4d (patch)
tree9428c3075ecda272e3cfd84ea00fe30015061d49 /drivers/misc
parent2e5df413becf6bd3854d1eb4f96542a53848bb27 (diff)
ti-st: add device tree support
When using device tree, driver configuration data need to be read from device node. Add support for getting the platform data information from the device tree information stored in the .dtb file in case it exists. Signed-off-by: Eyal Reizer <eyalr@ti.com> Signed-off-by: bvijay <bvijay@ti.com> Diff rendering mode:inlineside by side Signed-off-by: Gigi Joseph <gigi.joseph@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/ti-st/st_kim.c97
-rw-r--r--drivers/misc/ti-st/st_ll.c17
2 files changed, 104 insertions, 10 deletions
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index e4b7ee4f57b8..68a0b582d81a 100644
--- a/drivers/misc/ti-st/st_kim.c
+++ b/drivers/misc/ti-st/st_kim.c
@@ -36,7 +36,8 @@
36#include <linux/skbuff.h> 36#include <linux/skbuff.h>
37#include <linux/ti_wilink_st.h> 37#include <linux/ti_wilink_st.h>
38#include <linux/module.h> 38#include <linux/module.h>
39 39#include <linux/of.h>
40#include <linux/of_device.h>
40 41
41#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */ 42#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */
42static struct platform_device *st_kim_devices[MAX_ST_DEVICES]; 43static struct platform_device *st_kim_devices[MAX_ST_DEVICES];
@@ -44,6 +45,9 @@ static struct platform_device *st_kim_devices[MAX_ST_DEVICES];
44/**********************************************************************/ 45/**********************************************************************/
45/* internal functions */ 46/* internal functions */
46 47
48struct ti_st_plat_data *dt_pdata;
49static struct ti_st_plat_data *get_platform_data(struct device *dev);
50
47/** 51/**
48 * st_get_plat_device - 52 * st_get_plat_device -
49 * function which returns the reference to the platform device 53 * function which returns the reference to the platform device
@@ -462,7 +466,12 @@ long st_kim_start(void *kim_data)
462 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 466 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
463 467
464 pr_info(" %s", __func__); 468 pr_info(" %s", __func__);
465 pdata = kim_gdata->kim_pdev->dev.platform_data; 469 if (kim_gdata->kim_pdev->dev.of_node) {
470 pr_debug("use device tree data");
471 pdata = dt_pdata;
472 } else {
473 pdata = kim_gdata->kim_pdev->dev.platform_data;
474 }
466 475
467 do { 476 do {
468 /* platform specific enabling code here */ 477 /* platform specific enabling code here */
@@ -522,12 +531,18 @@ long st_kim_stop(void *kim_data)
522{ 531{
523 long err = 0; 532 long err = 0;
524 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 533 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
525 struct ti_st_plat_data *pdata = 534 struct ti_st_plat_data *pdata;
526 kim_gdata->kim_pdev->dev.platform_data;
527 struct tty_struct *tty = kim_gdata->core_data->tty; 535 struct tty_struct *tty = kim_gdata->core_data->tty;
528 536
529 reinit_completion(&kim_gdata->ldisc_installed); 537 reinit_completion(&kim_gdata->ldisc_installed);
530 538
539 if (kim_gdata->kim_pdev->dev.of_node) {
540 pr_debug("use device tree data");
541 pdata = dt_pdata;
542 } else
543 pdata = kim_gdata->kim_pdev->dev.platform_data;
544
545
531 if (tty) { /* can be called before ldisc is installed */ 546 if (tty) { /* can be called before ldisc is installed */
532 /* Flush any pending characters in the driver and discipline. */ 547 /* Flush any pending characters in the driver and discipline. */
533 tty_ldisc_flush(tty); 548 tty_ldisc_flush(tty);
@@ -715,13 +730,53 @@ static const struct file_operations list_debugfs_fops = {
715 * board-*.c file 730 * board-*.c file
716 */ 731 */
717 732
733static const struct of_device_id kim_of_match[] = {
734{
735 .compatible = "kim",
736 },
737 {}
738};
739MODULE_DEVICE_TABLE(of, kim_of_match);
740
741static struct ti_st_plat_data *get_platform_data(struct device *dev)
742{
743 struct device_node *np = dev->of_node;
744 const u32 *dt_property;
745 int len;
746
747 dt_pdata = kzalloc(sizeof(*dt_pdata), GFP_KERNEL);
748
749 if (!dt_pdata)
750 pr_err("Can't allocate device_tree platform data\n");
751
752 dt_property = of_get_property(np, "dev_name", &len);
753 if (dt_property)
754 memcpy(&dt_pdata->dev_name, dt_property, len);
755 of_property_read_u32(np, "nshutdown_gpio",
756 (u32 *)&dt_pdata->nshutdown_gpio);
757 of_property_read_u32(np, "flow_cntrl", (u32 *)&dt_pdata->flow_cntrl);
758 of_property_read_u32(np, "baud_rate", (u32 *)&dt_pdata->baud_rate);
759
760 return dt_pdata;
761}
762
718static struct dentry *kim_debugfs_dir; 763static struct dentry *kim_debugfs_dir;
719static int kim_probe(struct platform_device *pdev) 764static int kim_probe(struct platform_device *pdev)
720{ 765{
721 struct kim_data_s *kim_gdata; 766 struct kim_data_s *kim_gdata;
722 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 767 struct ti_st_plat_data *pdata;
723 int err; 768 int err;
724 769
770 if (pdev->dev.of_node)
771 pdata = get_platform_data(&pdev->dev);
772 else
773 pdata = pdev->dev.platform_data;
774
775 if (pdata == NULL) {
776 dev_err(&pdev->dev, "Platform Data is missing\n");
777 return -ENXIO;
778 }
779
725 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) { 780 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) {
726 /* multiple devices could exist */ 781 /* multiple devices could exist */
727 st_kim_devices[pdev->id] = pdev; 782 st_kim_devices[pdev->id] = pdev;
@@ -806,9 +861,16 @@ err_core_init:
806static int kim_remove(struct platform_device *pdev) 861static int kim_remove(struct platform_device *pdev)
807{ 862{
808 /* free the GPIOs requested */ 863 /* free the GPIOs requested */
809 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 864 struct ti_st_plat_data *pdata;
810 struct kim_data_s *kim_gdata; 865 struct kim_data_s *kim_gdata;
811 866
867 if (pdev->dev.of_node) {
868 pr_debug("use device tree data");
869 pdata = dt_pdata;
870 } else {
871 pdata = pdev->dev.platform_data;
872 }
873
812 kim_gdata = platform_get_drvdata(pdev); 874 kim_gdata = platform_get_drvdata(pdev);
813 875
814 /* Free the Bluetooth/FM/GPIO 876 /* Free the Bluetooth/FM/GPIO
@@ -826,12 +888,22 @@ static int kim_remove(struct platform_device *pdev)
826 888
827 kfree(kim_gdata); 889 kfree(kim_gdata);
828 kim_gdata = NULL; 890 kim_gdata = NULL;
891 kfree(dt_pdata);
892 dt_pdata = NULL;
893
829 return 0; 894 return 0;
830} 895}
831 896
832static int kim_suspend(struct platform_device *pdev, pm_message_t state) 897static int kim_suspend(struct platform_device *pdev, pm_message_t state)
833{ 898{
834 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 899 struct ti_st_plat_data *pdata;
900
901 if (pdev->dev.of_node) {
902 pr_debug("use device tree data");
903 pdata = dt_pdata;
904 } else {
905 pdata = pdev->dev.platform_data;
906 }
835 907
836 if (pdata->suspend) 908 if (pdata->suspend)
837 return pdata->suspend(pdev, state); 909 return pdata->suspend(pdev, state);
@@ -841,7 +913,14 @@ static int kim_suspend(struct platform_device *pdev, pm_message_t state)
841 913
842static int kim_resume(struct platform_device *pdev) 914static int kim_resume(struct platform_device *pdev)
843{ 915{
844 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 916 struct ti_st_plat_data *pdata;
917
918 if (pdev->dev.of_node) {
919 pr_debug("use device tree data");
920 pdata = dt_pdata;
921 } else {
922 pdata = pdev->dev.platform_data;
923 }
845 924
846 if (pdata->resume) 925 if (pdata->resume)
847 return pdata->resume(pdev); 926 return pdata->resume(pdev);
@@ -858,6 +937,8 @@ static struct platform_driver kim_platform_driver = {
858 .resume = kim_resume, 937 .resume = kim_resume,
859 .driver = { 938 .driver = {
860 .name = "kim", 939 .name = "kim",
940 .owner = THIS_MODULE,
941 .of_match_table = of_match_ptr(kim_of_match),
861 }, 942 },
862}; 943};
863 944
diff --git a/drivers/misc/ti-st/st_ll.c b/drivers/misc/ti-st/st_ll.c
index 93b4d67cc4a3..518e1b7f2f95 100644
--- a/drivers/misc/ti-st/st_ll.c
+++ b/drivers/misc/ti-st/st_ll.c
@@ -26,6 +26,7 @@
26#include <linux/ti_wilink_st.h> 26#include <linux/ti_wilink_st.h>
27 27
28/**********************************************************************/ 28/**********************************************************************/
29
29/* internal functions */ 30/* internal functions */
30static void send_ll_cmd(struct st_data_s *st_data, 31static void send_ll_cmd(struct st_data_s *st_data,
31 unsigned char cmd) 32 unsigned char cmd)
@@ -53,7 +54,13 @@ static void ll_device_want_to_sleep(struct st_data_s *st_data)
53 54
54 /* communicate to platform about chip asleep */ 55 /* communicate to platform about chip asleep */
55 kim_data = st_data->kim_data; 56 kim_data = st_data->kim_data;
56 pdata = kim_data->kim_pdev->dev.platform_data; 57 if (kim_data->kim_pdev->dev.of_node) {
58 pr_debug("use device tree data");
59 pdata = dt_pdata;
60 } else {
61 pdata = kim_data->kim_pdev->dev.platform_data;
62 }
63
57 if (pdata->chip_asleep) 64 if (pdata->chip_asleep)
58 pdata->chip_asleep(NULL); 65 pdata->chip_asleep(NULL);
59} 66}
@@ -86,7 +93,13 @@ static void ll_device_want_to_wakeup(struct st_data_s *st_data)
86 93
87 /* communicate to platform about chip wakeup */ 94 /* communicate to platform about chip wakeup */
88 kim_data = st_data->kim_data; 95 kim_data = st_data->kim_data;
89 pdata = kim_data->kim_pdev->dev.platform_data; 96 if (kim_data->kim_pdev->dev.of_node) {
97 pr_debug("use device tree data");
98 pdata = dt_pdata;
99 } else {
100 pdata = kim_data->kim_pdev->dev.platform_data;
101 }
102
90 if (pdata->chip_awake) 103 if (pdata->chip_awake)
91 pdata->chip_awake(NULL); 104 pdata->chip_awake(NULL);
92} 105}