aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/lis3lv02d/lis3lv02d.c
diff options
context:
space:
mode:
authorDaniel Mack <zonque@gmail.com>2012-09-26 16:58:16 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-09-26 17:15:55 -0400
commitcbac1a8b89452f378a17cc2c673aca0e53af684d (patch)
treec52184fb2ef4129bbf4ca8a8b9c280ee4e0fd8a7 /drivers/misc/lis3lv02d/lis3lv02d.c
parente2b2ed8365e040b274dd23bdabd34ec3b0e43137 (diff)
drivers/misc/lis3lv02d: add generic DT matching code
Adds logic to parse lis3 properties from a device tree node and store them in a freshly allocated lis3lv02d_platform_data. Note that the actual match tables are left out here. This part should happen in the drivers that bind to the individual busses (SPI/I2C/PCI). Also adds some DT bindinds documentation. Signed-off-by: Daniel Mack <zonque@gmail.com> Cc: Rob Herring <robherring2@gmail.com> Cc: "AnilKumar, Chimata" <anilkumar@ti.com> Reviewed-by: Éric Piel <eric.piel@tremplin-utc.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc/lis3lv02d/lis3lv02d.c')
-rw-r--r--drivers/misc/lis3lv02d/lis3lv02d.c153
1 files changed, 153 insertions, 0 deletions
diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
index e670072fe24c..6877f1179875 100644
--- a/drivers/misc/lis3lv02d/lis3lv02d.c
+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
@@ -39,6 +39,7 @@
39#include <linux/miscdevice.h> 39#include <linux/miscdevice.h>
40#include <linux/pm_runtime.h> 40#include <linux/pm_runtime.h>
41#include <linux/atomic.h> 41#include <linux/atomic.h>
42#include <linux/of_device.h>
42#include "lis3lv02d.h" 43#include "lis3lv02d.h"
43 44
44#define DRIVER_NAME "lis3lv02d" 45#define DRIVER_NAME "lis3lv02d"
@@ -943,6 +944,154 @@ static void lis3lv02d_8b_configure(struct lis3lv02d *lis3,
943 } 944 }
944} 945}
945 946
947#ifdef CONFIG_OF
948static int lis3lv02d_init_dt(struct lis3lv02d *lis3)
949{
950 struct lis3lv02d_platform_data *pdata;
951 struct device_node *np = lis3->of_node;
952 u32 val;
953
954 if (!lis3->of_node)
955 return 0;
956
957 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
958 if (!pdata)
959 return -ENOMEM;
960
961 if (of_get_property(np, "st,click-single-x", NULL))
962 pdata->click_flags |= LIS3_CLICK_SINGLE_X;
963 if (of_get_property(np, "st,click-double-x", NULL))
964 pdata->click_flags |= LIS3_CLICK_DOUBLE_X;
965
966 if (of_get_property(np, "st,click-single-y", NULL))
967 pdata->click_flags |= LIS3_CLICK_SINGLE_Y;
968 if (of_get_property(np, "st,click-double-y", NULL))
969 pdata->click_flags |= LIS3_CLICK_DOUBLE_Y;
970
971 if (of_get_property(np, "st,click-single-z", NULL))
972 pdata->click_flags |= LIS3_CLICK_SINGLE_Z;
973 if (of_get_property(np, "st,click-double-z", NULL))
974 pdata->click_flags |= LIS3_CLICK_DOUBLE_Z;
975
976 if (!of_property_read_u32(np, "st,click-threshold-x", &val))
977 pdata->click_thresh_x = val;
978 if (!of_property_read_u32(np, "st,click-threshold-y", &val))
979 pdata->click_thresh_y = val;
980 if (!of_property_read_u32(np, "st,click-threshold-z", &val))
981 pdata->click_thresh_z = val;
982
983 if (!of_property_read_u32(np, "st,click-time-limit", &val))
984 pdata->click_time_limit = val;
985 if (!of_property_read_u32(np, "st,click-latency", &val))
986 pdata->click_latency = val;
987 if (!of_property_read_u32(np, "st,click-window", &val))
988 pdata->click_window = val;
989
990 if (of_get_property(np, "st,irq1-disable", NULL))
991 pdata->irq_cfg |= LIS3_IRQ1_DISABLE;
992 if (of_get_property(np, "st,irq1-ff-wu-1", NULL))
993 pdata->irq_cfg |= LIS3_IRQ1_FF_WU_1;
994 if (of_get_property(np, "st,irq1-ff-wu-2", NULL))
995 pdata->irq_cfg |= LIS3_IRQ1_FF_WU_2;
996 if (of_get_property(np, "st,irq1-data-ready", NULL))
997 pdata->irq_cfg |= LIS3_IRQ1_DATA_READY;
998 if (of_get_property(np, "st,irq1-click", NULL))
999 pdata->irq_cfg |= LIS3_IRQ1_CLICK;
1000
1001 if (of_get_property(np, "st,irq2-disable", NULL))
1002 pdata->irq_cfg |= LIS3_IRQ2_DISABLE;
1003 if (of_get_property(np, "st,irq2-ff-wu-1", NULL))
1004 pdata->irq_cfg |= LIS3_IRQ2_FF_WU_1;
1005 if (of_get_property(np, "st,irq2-ff-wu-2", NULL))
1006 pdata->irq_cfg |= LIS3_IRQ2_FF_WU_2;
1007 if (of_get_property(np, "st,irq2-data-ready", NULL))
1008 pdata->irq_cfg |= LIS3_IRQ2_DATA_READY;
1009 if (of_get_property(np, "st,irq2-click", NULL))
1010 pdata->irq_cfg |= LIS3_IRQ2_CLICK;
1011
1012 if (of_get_property(np, "st,irq-open-drain", NULL))
1013 pdata->irq_cfg |= LIS3_IRQ_OPEN_DRAIN;
1014 if (of_get_property(np, "st,irq-active-low", NULL))
1015 pdata->irq_cfg |= LIS3_IRQ_ACTIVE_LOW;
1016
1017 if (!of_property_read_u32(np, "st,wu-duration-1", &val))
1018 pdata->duration1 = val;
1019 if (!of_property_read_u32(np, "st,wu-duration-2", &val))
1020 pdata->duration2 = val;
1021
1022 if (of_get_property(np, "st,wakeup-x-lo", NULL))
1023 pdata->wakeup_flags |= LIS3_WAKEUP_X_LO;
1024 if (of_get_property(np, "st,wakeup-x-hi", NULL))
1025 pdata->wakeup_flags |= LIS3_WAKEUP_X_HI;
1026 if (of_get_property(np, "st,wakeup-y-lo", NULL))
1027 pdata->wakeup_flags |= LIS3_WAKEUP_Y_LO;
1028 if (of_get_property(np, "st,wakeup-y-hi", NULL))
1029 pdata->wakeup_flags |= LIS3_WAKEUP_Y_HI;
1030 if (of_get_property(np, "st,wakeup-z-lo", NULL))
1031 pdata->wakeup_flags |= LIS3_WAKEUP_Z_LO;
1032 if (of_get_property(np, "st,wakeup-z-hi", NULL))
1033 pdata->wakeup_flags |= LIS3_WAKEUP_Z_HI;
1034
1035 if (!of_property_read_u32(np, "st,highpass-cutoff-hz", &val)) {
1036 switch (val) {
1037 case 1:
1038 pdata->hipass_ctrl = LIS3_HIPASS_CUTFF_1HZ;
1039 break;
1040 case 2:
1041 pdata->hipass_ctrl = LIS3_HIPASS_CUTFF_2HZ;
1042 break;
1043 case 4:
1044 pdata->hipass_ctrl = LIS3_HIPASS_CUTFF_4HZ;
1045 break;
1046 case 8:
1047 pdata->hipass_ctrl = LIS3_HIPASS_CUTFF_8HZ;
1048 break;
1049 }
1050 }
1051
1052 if (of_get_property(np, "st,hipass1-disable", NULL))
1053 pdata->hipass_ctrl |= LIS3_HIPASS1_DISABLE;
1054 if (of_get_property(np, "st,hipass2-disable", NULL))
1055 pdata->hipass_ctrl |= LIS3_HIPASS2_DISABLE;
1056
1057 if (of_get_property(np, "st,axis-x", &val))
1058 pdata->axis_x = val;
1059 if (of_get_property(np, "st,axis-y", &val))
1060 pdata->axis_y = val;
1061 if (of_get_property(np, "st,axis-z", &val))
1062 pdata->axis_z = val;
1063
1064 if (of_get_property(np, "st,default-rate", NULL))
1065 pdata->default_rate = val;
1066
1067 if (of_get_property(np, "st,min-limit-x", &val))
1068 pdata->st_min_limits[0] = val;
1069 if (of_get_property(np, "st,min-limit-y", &val))
1070 pdata->st_min_limits[1] = val;
1071 if (of_get_property(np, "st,min-limit-z", &val))
1072 pdata->st_min_limits[2] = val;
1073
1074 if (of_get_property(np, "st,max-limit-x", &val))
1075 pdata->st_max_limits[0] = val;
1076 if (of_get_property(np, "st,max-limit-y", &val))
1077 pdata->st_max_limits[1] = val;
1078 if (of_get_property(np, "st,max-limit-z", &val))
1079 pdata->st_max_limits[2] = val;
1080
1081
1082 lis3->pdata = pdata;
1083
1084 return 0;
1085}
1086
1087#else
1088static int lis3lv02d_init_dt(struct lis3lv02d *lis3)
1089{
1090 return 0;
1091}
1092#endif
1093EXPORT_SYMBOL_GPL(lis3lv02d_init_dt);
1094
946/* 1095/*
947 * Initialise the accelerometer and the various subsystems. 1096 * Initialise the accelerometer and the various subsystems.
948 * Should be rather independent of the bus system. 1097 * Should be rather independent of the bus system.
@@ -953,6 +1102,10 @@ int lis3lv02d_init_device(struct lis3lv02d *lis3)
953 irq_handler_t thread_fn; 1102 irq_handler_t thread_fn;
954 int irq_flags = 0; 1103 int irq_flags = 0;
955 1104
1105 err = lis3lv02d_init_dt(lis3);
1106 if (err < 0)
1107 return err;
1108
956 lis3->whoami = lis3lv02d_read_8(lis3, WHO_AM_I); 1109 lis3->whoami = lis3lv02d_read_8(lis3, WHO_AM_I);
957 1110
958 switch (lis3->whoami) { 1111 switch (lis3->whoami) {