|
@@ -26,6 +26,7 @@
|
|
struct pwm_export {
|
|
struct pwm_export {
|
|
struct device child;
|
|
struct device child;
|
|
struct pwm_device *pwm;
|
|
struct pwm_device *pwm;
|
|
|
|
+ struct mutex lock;
|
|
};
|
|
};
|
|
|
|
|
|
static struct pwm_export *child_to_pwm_export(struct device *child)
|
|
static struct pwm_export *child_to_pwm_export(struct device *child)
|
|
@@ -53,7 +54,8 @@ static ssize_t period_store(struct device *child,
|
|
struct device_attribute *attr,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t size)
|
|
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;
|
|
unsigned int val;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
@@ -61,7 +63,9 @@ static ssize_t period_store(struct device *child,
|
|
if (ret)
|
|
if (ret)
|
|
return ret;
|
|
return ret;
|
|
|
|
|
|
|
|
+ mutex_lock(&export->lock);
|
|
ret = pwm_config(pwm, pwm_get_duty_cycle(pwm), val);
|
|
ret = pwm_config(pwm, pwm_get_duty_cycle(pwm), val);
|
|
|
|
+ mutex_unlock(&export->lock);
|
|
|
|
|
|
return ret ? : size;
|
|
return ret ? : size;
|
|
}
|
|
}
|
|
@@ -79,7 +83,8 @@ static ssize_t duty_cycle_store(struct device *child,
|
|
struct device_attribute *attr,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t size)
|
|
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;
|
|
unsigned int val;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
@@ -87,7 +92,9 @@ static ssize_t duty_cycle_store(struct device *child,
|
|
if (ret)
|
|
if (ret)
|
|
return ret;
|
|
return ret;
|
|
|
|
|
|
|
|
+ mutex_lock(&export->lock);
|
|
ret = pwm_config(pwm, val, pwm_get_period(pwm));
|
|
ret = pwm_config(pwm, val, pwm_get_period(pwm));
|
|
|
|
+ mutex_unlock(&export->lock);
|
|
|
|
|
|
return ret ? : size;
|
|
return ret ? : size;
|
|
}
|
|
}
|
|
@@ -105,13 +112,16 @@ static ssize_t enable_store(struct device *child,
|
|
struct device_attribute *attr,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t size)
|
|
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;
|
|
int val, ret;
|
|
|
|
|
|
ret = kstrtoint(buf, 0, &val);
|
|
ret = kstrtoint(buf, 0, &val);
|
|
if (ret)
|
|
if (ret)
|
|
return ret;
|
|
return ret;
|
|
|
|
|
|
|
|
+ mutex_lock(&export->lock);
|
|
|
|
+
|
|
switch (val) {
|
|
switch (val) {
|
|
case 0:
|
|
case 0:
|
|
pwm_disable(pwm);
|
|
pwm_disable(pwm);
|
|
@@ -124,6 +134,8 @@ static ssize_t enable_store(struct device *child,
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ mutex_unlock(&export->lock);
|
|
|
|
+
|
|
return ret ? : size;
|
|
return ret ? : size;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -151,7 +163,8 @@ static ssize_t polarity_store(struct device *child,
|
|
struct device_attribute *attr,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t size)
|
|
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;
|
|
enum pwm_polarity polarity;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
@@ -162,7 +175,9 @@ static ssize_t polarity_store(struct device *child,
|
|
else
|
|
else
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
+ mutex_lock(&export->lock);
|
|
ret = pwm_set_polarity(pwm, polarity);
|
|
ret = pwm_set_polarity(pwm, polarity);
|
|
|
|
+ mutex_unlock(&export->lock);
|
|
|
|
|
|
return ret ? : size;
|
|
return ret ? : size;
|
|
}
|
|
}
|
|
@@ -203,6 +218,7 @@ static int pwm_export_child(struct device *parent, struct pwm_device *pwm)
|
|
}
|
|
}
|
|
|
|
|
|
export->pwm = pwm;
|
|
export->pwm = pwm;
|
|
|
|
+ mutex_init(&export->lock);
|
|
|
|
|
|
export->child.release = pwm_export_release;
|
|
export->child.release = pwm_export_release;
|
|
export->child.parent = parent;
|
|
export->child.parent = parent;
|