13 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
18 #include <linux/input.h>
19 #include <linux/slab.h>
24 #define VIB_DRV_SEL_MASK 0xf8
25 #define VIB_DRV_SEL_SHIFT 0x03
26 #define VIB_DRV_EN_MANUAL_MASK 0xfc
28 #define VIB_MAX_LEVEL_mV (3100)
29 #define VIB_MIN_LEVEL_mV (1200)
30 #define VIB_MAX_LEVELS (VIB_MAX_LEVEL_mV - VIB_MIN_LEVEL_mV)
32 #define MAX_FF_SPEED 0xff
60 static int pm8xxx_vib_read_u8(
struct pm8xxx_vib *vib,
65 rc = pm8xxx_readb(vib->
dev->parent, reg, data);
67 dev_warn(vib->
dev,
"Error reading pm8xxx reg 0x%x(0x%x)\n",
78 static int pm8xxx_vib_write_u8(
struct pm8xxx_vib *vib,
83 rc = pm8xxx_writeb(vib->
dev->parent, reg, data);
85 dev_warn(vib->
dev,
"Error writing pm8xxx reg 0x%x(0x%x)\n",
95 static int pm8xxx_vib_set(
struct pm8xxx_vib *vib,
bool on)
105 rc = pm8xxx_vib_write_u8(vib, val,
VIB_DRV);
123 rc = pm8xxx_vib_read_u8(vib, &val,
VIB_DRV);
141 pm8xxx_vib_set(vib, vib->
active);
150 static void pm8xxx_vib_close(
struct input_dev *
dev)
152 struct pm8xxx_vib *vib = input_get_drvdata(dev);
156 pm8xxx_vib_set(vib,
false);
167 static int pm8xxx_vib_play_effect(
struct input_dev *dev,
void *data,
170 struct pm8xxx_vib *vib = input_get_drvdata(dev);
185 struct input_dev *input_dev;
190 input_dev = input_allocate_device();
191 if (!vib || !input_dev) {
192 dev_err(&pdev->
dev,
"couldn't allocate memory\n");
202 error = pm8xxx_vib_read_u8(vib, &val,
VIB_DRV);
206 error = pm8xxx_vib_write_u8(vib, val,
VIB_DRV);
212 input_dev->name =
"pm8xxx_vib_ffmemless";
213 input_dev->id.version = 1;
214 input_dev->dev.parent = &pdev->
dev;
215 input_dev->close = pm8xxx_vib_close;
216 input_set_drvdata(input_dev, vib);
220 pm8xxx_vib_play_effect);
223 "couldn't register vibrator as FF device\n");
227 error = input_register_device(input_dev);
229 dev_err(&pdev->
dev,
"couldn't register input device\n");
230 goto err_destroy_memless;
233 platform_set_drvdata(pdev, vib);
237 input_ff_destroy(input_dev);
239 input_free_device(input_dev);
247 struct pm8xxx_vib *vib = platform_get_drvdata(pdev);
252 platform_set_drvdata(pdev,
NULL);
257 #ifdef CONFIG_PM_SLEEP
258 static int pm8xxx_vib_suspend(
struct device *dev)
263 pm8xxx_vib_set(vib,
false);
272 .probe = pm8xxx_vib_probe,
275 .name =
"pm8xxx-vib",
277 .pm = &pm8xxx_vib_pm_ops,