aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/misc
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@codeaurora.org>2013-12-15 06:46:21 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2013-12-15 06:58:38 -0500
commit21014b80257846a5561b0d0e8fed47a65edebf46 (patch)
tree6ab1c876cc80a954d6a9978303712d1bb175cd11 /drivers/input/misc
parent12a5a8fdfbab14427df0eb6e6c05559444ee2c73 (diff)
Input: pm8xxx-vibrator - migrate to regmap APIs
Use the regmap APIs for this driver instead of custom pm8xxx APIs. This breaks this driver's dependency on the pm8xxx APIs and allows us to easily port it to other bus protocols in the future. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/misc')
-rw-r--r--drivers/input/misc/pm8xxx-vibrator.c61
1 files changed, 14 insertions, 47 deletions
diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c
index 50be8abb7d0c..28251560249d 100644
--- a/drivers/input/misc/pm8xxx-vibrator.c
+++ b/drivers/input/misc/pm8xxx-vibrator.c
@@ -17,7 +17,7 @@
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/input.h> 18#include <linux/input.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/mfd/pm8xxx/core.h> 20#include <linux/regmap.h>
21 21
22#define VIB_DRV 0x4A 22#define VIB_DRV 0x4A
23 23
@@ -35,7 +35,7 @@
35 * struct pm8xxx_vib - structure to hold vibrator data 35 * struct pm8xxx_vib - structure to hold vibrator data
36 * @vib_input_dev: input device supporting force feedback 36 * @vib_input_dev: input device supporting force feedback
37 * @work: work structure to set the vibration parameters 37 * @work: work structure to set the vibration parameters
38 * @dev: device supporting force feedback 38 * @regmap: regmap for register read/write
39 * @speed: speed of vibration set from userland 39 * @speed: speed of vibration set from userland
40 * @active: state of vibrator 40 * @active: state of vibrator
41 * @level: level of vibration to set in the chip 41 * @level: level of vibration to set in the chip
@@ -44,7 +44,7 @@
44struct pm8xxx_vib { 44struct pm8xxx_vib {
45 struct input_dev *vib_input_dev; 45 struct input_dev *vib_input_dev;
46 struct work_struct work; 46 struct work_struct work;
47 struct device *dev; 47 struct regmap *regmap;
48 int speed; 48 int speed;
49 int level; 49 int level;
50 bool active; 50 bool active;
@@ -52,42 +52,6 @@ struct pm8xxx_vib {
52}; 52};
53 53
54/** 54/**
55 * pm8xxx_vib_read_u8 - helper to read a byte from pmic chip
56 * @vib: pointer to vibrator structure
57 * @data: placeholder for data to be read
58 * @reg: register address
59 */
60static int pm8xxx_vib_read_u8(struct pm8xxx_vib *vib,
61 u8 *data, u16 reg)
62{
63 int rc;
64
65 rc = pm8xxx_readb(vib->dev->parent, reg, data);
66 if (rc < 0)
67 dev_warn(vib->dev, "Error reading pm8xxx reg 0x%x(0x%x)\n",
68 reg, rc);
69 return rc;
70}
71
72/**
73 * pm8xxx_vib_write_u8 - helper to write a byte to pmic chip
74 * @vib: pointer to vibrator structure
75 * @data: data to write
76 * @reg: register address
77 */
78static int pm8xxx_vib_write_u8(struct pm8xxx_vib *vib,
79 u8 data, u16 reg)
80{
81 int rc;
82
83 rc = pm8xxx_writeb(vib->dev->parent, reg, data);
84 if (rc < 0)
85 dev_warn(vib->dev, "Error writing pm8xxx reg 0x%x(0x%x)\n",
86 reg, rc);
87 return rc;
88}
89
90/**
91 * pm8xxx_vib_set - handler to start/stop vibration 55 * pm8xxx_vib_set - handler to start/stop vibration
92 * @vib: pointer to vibrator structure 56 * @vib: pointer to vibrator structure
93 * @on: state to set 57 * @on: state to set
@@ -95,14 +59,14 @@ static int pm8xxx_vib_write_u8(struct pm8xxx_vib *vib,
95static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on) 59static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on)
96{ 60{
97 int rc; 61 int rc;
98 u8 val = vib->reg_vib_drv; 62 unsigned int val = vib->reg_vib_drv;
99 63
100 if (on) 64 if (on)
101 val |= ((vib->level << VIB_DRV_SEL_SHIFT) & VIB_DRV_SEL_MASK); 65 val |= ((vib->level << VIB_DRV_SEL_SHIFT) & VIB_DRV_SEL_MASK);
102 else 66 else
103 val &= ~VIB_DRV_SEL_MASK; 67 val &= ~VIB_DRV_SEL_MASK;
104 68
105 rc = pm8xxx_vib_write_u8(vib, val, VIB_DRV); 69 rc = regmap_write(vib->regmap, VIB_DRV, val);
106 if (rc < 0) 70 if (rc < 0)
107 return rc; 71 return rc;
108 72
@@ -118,9 +82,9 @@ static void pm8xxx_work_handler(struct work_struct *work)
118{ 82{
119 struct pm8xxx_vib *vib = container_of(work, struct pm8xxx_vib, work); 83 struct pm8xxx_vib *vib = container_of(work, struct pm8xxx_vib, work);
120 int rc; 84 int rc;
121 u8 val; 85 unsigned int val;
122 86
123 rc = pm8xxx_vib_read_u8(vib, &val, VIB_DRV); 87 rc = regmap_read(vib->regmap, VIB_DRV, &val);
124 if (rc < 0) 88 if (rc < 0)
125 return; 89 return;
126 90
@@ -184,27 +148,30 @@ static int pm8xxx_vib_probe(struct platform_device *pdev)
184 struct pm8xxx_vib *vib; 148 struct pm8xxx_vib *vib;
185 struct input_dev *input_dev; 149 struct input_dev *input_dev;
186 int error; 150 int error;
187 u8 val; 151 unsigned int val;
188 152
189 vib = devm_kzalloc(&pdev->dev, sizeof(*vib), GFP_KERNEL); 153 vib = devm_kzalloc(&pdev->dev, sizeof(*vib), GFP_KERNEL);
190 if (!vib) 154 if (!vib)
191 return -ENOMEM; 155 return -ENOMEM;
192 156
157 vib->regmap = dev_get_regmap(pdev->dev.parent, NULL);
158 if (!vib->regmap)
159 return -ENODEV;
160
193 input_dev = devm_input_allocate_device(&pdev->dev); 161 input_dev = devm_input_allocate_device(&pdev->dev);
194 if (!input_dev) 162 if (!input_dev)
195 return -ENOMEM; 163 return -ENOMEM;
196 164
197 INIT_WORK(&vib->work, pm8xxx_work_handler); 165 INIT_WORK(&vib->work, pm8xxx_work_handler);
198 vib->dev = &pdev->dev;
199 vib->vib_input_dev = input_dev; 166 vib->vib_input_dev = input_dev;
200 167
201 /* operate in manual mode */ 168 /* operate in manual mode */
202 error = pm8xxx_vib_read_u8(vib, &val, VIB_DRV); 169 error = regmap_read(vib->regmap, VIB_DRV, &val);
203 if (error < 0) 170 if (error < 0)
204 return error; 171 return error;
205 172
206 val &= ~VIB_DRV_EN_MANUAL_MASK; 173 val &= ~VIB_DRV_EN_MANUAL_MASK;
207 error = pm8xxx_vib_write_u8(vib, val, VIB_DRV); 174 error = regmap_write(vib->regmap, VIB_DRV, val);
208 if (error < 0) 175 if (error < 0)
209 return error; 176 return error;
210 177