leds:leds-qpnp-vibrator-ldo: remove device attributes

Currently the driver exposes few device attributes
(duration, state, activate) which are the same as
the ones being exposed in transient LED trigger.
Remove them in the driver and transient LED trigger
can be enabled when they are required.

Change-Id: I45a2d7dfcf44e64f797852b06b79a2ba2b666a7f
Signed-off-by: Xubin Bai <quic_xubibai@quicinc.com>
This commit is contained in:
Xubin Bai 2022-03-15 09:32:13 +08:00 committed by Gerrit - the friendly Code Review server
parent 8acdbd1706
commit 47517f21fb

View file

@ -44,11 +44,8 @@ struct vib_ldo_chip {
struct led_classdev cdev;
struct regmap *regmap;
struct mutex lock;
struct hrtimer stop_timer;
struct hrtimer overdrive_timer;
struct work_struct vib_work;
struct work_struct overdrive_work;
u16 base;
int vmax_uV;
int overdrive_volt_uV;
@ -172,39 +169,6 @@ static int qpnp_vibrator_play_on(struct vib_ldo_chip *chip)
return ret;
}
static void qpnp_vib_work(struct work_struct *work)
{
struct vib_ldo_chip *chip = container_of(work, struct vib_ldo_chip,
vib_work);
int ret = 0;
if (chip->state) {
if (!chip->vib_enabled)
ret = qpnp_vibrator_play_on(chip);
if (ret == 0)
hrtimer_start(&chip->stop_timer,
ms_to_ktime(chip->vib_play_ms),
HRTIMER_MODE_REL);
} else {
if (!chip->disable_overdrive) {
hrtimer_cancel(&chip->overdrive_timer);
cancel_work_sync(&chip->overdrive_work);
}
qpnp_vib_ldo_enable(chip, false);
}
}
static enum hrtimer_restart vib_stop_timer(struct hrtimer *timer)
{
struct vib_ldo_chip *chip = container_of(timer, struct vib_ldo_chip,
stop_timer);
chip->state = 0;
schedule_work(&chip->vib_work);
return HRTIMER_NORESTART;
}
static void qpnp_vib_overdrive_work(struct work_struct *work)
{
struct vib_ldo_chip *chip = container_of(work, struct vib_ldo_chip,
@ -239,103 +203,6 @@ static enum hrtimer_restart vib_overdrive_timer(struct hrtimer *timer)
return HRTIMER_NORESTART;
}
static ssize_t qpnp_vib_show_state(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct led_classdev *cdev = dev_get_drvdata(dev);
struct vib_ldo_chip *chip = container_of(cdev, struct vib_ldo_chip,
cdev);
return scnprintf(buf, PAGE_SIZE, "%d\n", chip->vib_enabled);
}
static ssize_t qpnp_vib_store_state(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
/* At present, nothing to do with setting state */
return count;
}
static ssize_t qpnp_vib_show_duration(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct led_classdev *cdev = dev_get_drvdata(dev);
struct vib_ldo_chip *chip = container_of(cdev, struct vib_ldo_chip,
cdev);
ktime_t time_rem;
s64 time_ms = 0;
if (hrtimer_active(&chip->stop_timer)) {
time_rem = hrtimer_get_remaining(&chip->stop_timer);
time_ms = ktime_to_ms(time_rem);
}
return scnprintf(buf, PAGE_SIZE, "%lld\n", time_ms);
}
static ssize_t qpnp_vib_store_duration(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct led_classdev *cdev = dev_get_drvdata(dev);
struct vib_ldo_chip *chip = container_of(cdev, struct vib_ldo_chip,
cdev);
u32 val;
int ret;
ret = kstrtouint(buf, 0, &val);
if (ret < 0)
return ret;
/* setting 0 on duration is NOP for now */
if (val <= 0)
return count;
if (val < QPNP_VIB_MIN_PLAY_MS)
val = QPNP_VIB_MIN_PLAY_MS;
if (val > QPNP_VIB_MAX_PLAY_MS)
val = QPNP_VIB_MAX_PLAY_MS;
mutex_lock(&chip->lock);
chip->vib_play_ms = val;
mutex_unlock(&chip->lock);
return count;
}
static ssize_t qpnp_vib_show_activate(struct device *dev,
struct device_attribute *attr, char *buf)
{
/* For now nothing to show */
return scnprintf(buf, PAGE_SIZE, "%d\n", 0);
}
static ssize_t qpnp_vib_store_activate(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct led_classdev *cdev = dev_get_drvdata(dev);
struct vib_ldo_chip *chip = container_of(cdev, struct vib_ldo_chip,
cdev);
u32 val;
int ret;
ret = kstrtouint(buf, 0, &val);
if (ret < 0)
return ret;
if (val != 0 && val != 1)
return count;
mutex_lock(&chip->lock);
hrtimer_cancel(&chip->stop_timer);
chip->state = val;
pr_debug("state = %d, time = %llums\n", chip->state, chip->vib_play_ms);
mutex_unlock(&chip->lock);
schedule_work(&chip->vib_work);
return count;
}
static ssize_t qpnp_vib_show_vmax(struct device *dev,
struct device_attribute *attr, char *buf)
{
@ -367,15 +234,11 @@ static ssize_t qpnp_vib_store_vmax(struct device *dev,
mutex_lock(&chip->lock);
chip->vmax_uV = data;
mutex_unlock(&chip->lock);
return ret;
return count;
}
static struct device_attribute qpnp_vib_attrs[] = {
__ATTR(state, 0664, qpnp_vib_show_state, qpnp_vib_store_state),
__ATTR(duration, 0664, qpnp_vib_show_duration, qpnp_vib_store_duration),
__ATTR(activate, 0664, qpnp_vib_show_activate, qpnp_vib_store_activate),
__ATTR(vmax_mv, 0664, qpnp_vib_show_vmax, qpnp_vib_store_vmax),
};
static struct device_attribute qpnp_vib_attrs =
__ATTR(vmax_mv, 0644, qpnp_vib_show_vmax, qpnp_vib_store_vmax);
static int qpnp_vib_parse_dt(struct device *dev, struct vib_ldo_chip *chip)
{
@ -413,15 +276,36 @@ static int qpnp_vib_parse_dt(struct device *dev, struct vib_ldo_chip *chip)
return ret;
}
/* Dummy functions for brightness */
static enum led_brightness qpnp_vib_brightness_get(struct led_classdev *cdev)
{
return 0;
struct vib_ldo_chip *chip = container_of(cdev, struct vib_ldo_chip,
cdev);
return chip->state;
}
static void qpnp_vib_brightness_set(struct led_classdev *cdev,
enum led_brightness level)
{
struct vib_ldo_chip *chip = container_of(cdev, struct vib_ldo_chip,
cdev);
int ret = 0;
chip->state = level;
if (chip->state) {
ret = qpnp_vibrator_play_on(chip);
if (ret < 0)
pr_err("set vibrator-on failed, ret=%d\n", ret);
} else {
if (!chip->disable_overdrive) {
hrtimer_cancel(&chip->overdrive_timer);
cancel_work_sync(&chip->overdrive_work);
}
qpnp_vib_ldo_enable(chip, false);
}
pr_debug("vibrator state=%d\n", chip->state);
}
static int qpnp_vibrator_ldo_suspend(struct device *dev)
@ -433,8 +317,6 @@ static int qpnp_vibrator_ldo_suspend(struct device *dev)
hrtimer_cancel(&chip->overdrive_timer);
cancel_work_sync(&chip->overdrive_work);
}
hrtimer_cancel(&chip->stop_timer);
cancel_work_sync(&chip->vib_work);
qpnp_vib_ldo_enable(chip, false);
mutex_unlock(&chip->lock);
@ -447,7 +329,7 @@ static int qpnp_vibrator_ldo_probe(struct platform_device *pdev)
{
struct device_node *of_node = pdev->dev.of_node;
struct vib_ldo_chip *chip;
int i, ret;
int ret;
u32 base;
ret = of_property_read_u32(of_node, "reg", &base);
@ -475,11 +357,8 @@ static int qpnp_vibrator_ldo_probe(struct platform_device *pdev)
chip->base = (uint16_t)base;
chip->vib_play_ms = QPNP_VIB_PLAY_MS;
mutex_init(&chip->lock);
INIT_WORK(&chip->vib_work, qpnp_vib_work);
INIT_WORK(&chip->overdrive_work, qpnp_vib_overdrive_work);
hrtimer_init(&chip->stop_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
chip->stop_timer.function = vib_stop_timer;
hrtimer_init(&chip->overdrive_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
chip->overdrive_timer.function = vib_overdrive_timer;
dev_set_drvdata(&pdev->dev, chip);
@ -494,14 +373,12 @@ static int qpnp_vibrator_ldo_probe(struct platform_device *pdev)
goto fail;
}
for (i = 0; i < ARRAY_SIZE(qpnp_vib_attrs); i++) {
ret = sysfs_create_file(&chip->cdev.dev->kobj,
&qpnp_vib_attrs[i].attr);
if (ret < 0) {
dev_err(&pdev->dev, "Error in creating sysfs file, ret=%d\n",
ret);
goto sysfs_fail;
}
ret = sysfs_create_file(&chip->cdev.dev->kobj,
&qpnp_vib_attrs.attr);
if (ret < 0) {
dev_err(&pdev->dev, "Error in creating sysfs file, ret=%d\n",
ret);
goto sysfs_fail;
}
pr_info("Vibrator LDO successfully registered: uV = %d, overdrive = %s\n",
@ -510,9 +387,8 @@ static int qpnp_vibrator_ldo_probe(struct platform_device *pdev)
return 0;
sysfs_fail:
for (--i; i >= 0; i--)
sysfs_remove_file(&chip->cdev.dev->kobj,
&qpnp_vib_attrs[i].attr);
sysfs_remove_file(&chip->cdev.dev->kobj,
&qpnp_vib_attrs.attr);
fail:
mutex_destroy(&chip->lock);
dev_set_drvdata(&pdev->dev, NULL);
@ -527,8 +403,6 @@ static int qpnp_vibrator_ldo_remove(struct platform_device *pdev)
hrtimer_cancel(&chip->overdrive_timer);
cancel_work_sync(&chip->overdrive_work);
}
hrtimer_cancel(&chip->stop_timer);
cancel_work_sync(&chip->vib_work);
mutex_destroy(&chip->lock);
dev_set_drvdata(&pdev->dev, NULL);