pwm->pwm = chip->base + i;
pwm->hwpwm = i;
pwm->polarity = polarity;
- mutex_init(&pwm->lock);
radix_tree_insert(&pwm_tree, pwm->pwm, pwm);
}
if (!pwm->chip->ops->set_polarity)
return -ENOSYS;
- mutex_lock(&pwm->lock);
-
- if (pwm_is_enabled(pwm)) {
- err = -EBUSY;
- goto unlock;
- }
+ if (pwm_is_enabled(pwm))
+ return -EBUSY;
err = pwm->chip->ops->set_polarity(pwm->chip, pwm, polarity);
if (err)
- goto unlock;
+ return err;
pwm->polarity = polarity;
-unlock:
- mutex_unlock(&pwm->lock);
- return err;
+ return 0;
}
EXPORT_SYMBOL_GPL(pwm_set_polarity);
if (!pwm)
return -EINVAL;
- mutex_lock(&pwm->lock);
-
if (!test_and_set_bit(PWMF_ENABLED, &pwm->flags)) {
err = pwm->chip->ops->enable(pwm->chip, pwm);
if (err)
clear_bit(PWMF_ENABLED, &pwm->flags);
}
- mutex_unlock(&pwm->lock);
-
return err;
}
EXPORT_SYMBOL_GPL(pwm_enable);
struct pwm_export {
struct device child;
struct pwm_device *pwm;
+ struct mutex lock;
};
static struct pwm_export *child_to_pwm_export(struct device *child)
struct device_attribute *attr,
const char *buf, size_t size)
{
- struct pwm_device *pwm = child_to_pwm_device(child);
+ struct pwm_export *export = child_to_pwm_export(child);
+ struct pwm_device *pwm = export->pwm;
unsigned int val;
int ret;
if (ret)
return ret;
+ mutex_lock(&export->lock);
ret = pwm_config(pwm, pwm_get_duty_cycle(pwm), val);
+ mutex_unlock(&export->lock);
return ret ? : size;
}
struct device_attribute *attr,
const char *buf, size_t size)
{
- struct pwm_device *pwm = child_to_pwm_device(child);
+ struct pwm_export *export = child_to_pwm_export(child);
+ struct pwm_device *pwm = export->pwm;
unsigned int val;
int ret;
if (ret)
return ret;
+ mutex_lock(&export->lock);
ret = pwm_config(pwm, val, pwm_get_period(pwm));
+ mutex_unlock(&export->lock);
return ret ? : size;
}
struct device_attribute *attr,
const char *buf, size_t size)
{
- struct pwm_device *pwm = child_to_pwm_device(child);
+ struct pwm_export *export = child_to_pwm_export(child);
+ struct pwm_device *pwm = export->pwm;
int val, ret;
ret = kstrtoint(buf, 0, &val);
if (ret)
return ret;
+ mutex_lock(&export->lock);
+
switch (val) {
case 0:
pwm_disable(pwm);
break;
}
+ mutex_unlock(&export->lock);
+
return ret ? : size;
}
struct device_attribute *attr,
const char *buf, size_t size)
{
- struct pwm_device *pwm = child_to_pwm_device(child);
+ struct pwm_export *export = child_to_pwm_export(child);
+ struct pwm_device *pwm = export->pwm;
enum pwm_polarity polarity;
int ret;
else
return -EINVAL;
+ mutex_lock(&export->lock);
ret = pwm_set_polarity(pwm, polarity);
+ mutex_unlock(&export->lock);
return ret ? : size;
}
}
export->pwm = pwm;
+ mutex_init(&export->lock);
export->child.release = pwm_export_release;
export->child.parent = parent;