Commit 2e5219c7 authored by Lukasz Majewski's avatar Lukasz Majewski Committed by Guenter Roeck

hwmon: (pwm-fan) Read PWM FAN configuration from device tree

This patch provides code for reading PWM FAN configuration data via
device tree. The pwm-fan can work with full speed when configuration
is not provided. However, errors are propagated when wrong DT bindings
are found.
Additionally the struct pwm_fan_ctx has been extended.
Signed-off-by: default avatarLukasz Majewski <l.majewski@samsung.com>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent cb85ca33
...@@ -30,7 +30,10 @@ ...@@ -30,7 +30,10 @@
struct pwm_fan_ctx { struct pwm_fan_ctx {
struct mutex lock; struct mutex lock;
struct pwm_device *pwm; struct pwm_device *pwm;
unsigned char pwm_value; unsigned int pwm_value;
unsigned int pwm_fan_state;
unsigned int pwm_fan_max_state;
unsigned int *pwm_fan_cooling_levels;
}; };
static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
...@@ -100,6 +103,46 @@ static struct attribute *pwm_fan_attrs[] = { ...@@ -100,6 +103,46 @@ static struct attribute *pwm_fan_attrs[] = {
ATTRIBUTE_GROUPS(pwm_fan); ATTRIBUTE_GROUPS(pwm_fan);
int pwm_fan_of_get_cooling_data(struct device *dev, struct pwm_fan_ctx *ctx)
{
struct device_node *np = dev->of_node;
int num, i, ret;
if (!of_find_property(np, "cooling-levels", NULL))
return 0;
ret = of_property_count_u32_elems(np, "cooling-levels");
if (ret <= 0) {
dev_err(dev, "Wrong data!\n");
return ret ? : -EINVAL;
}
num = ret;
ctx->pwm_fan_cooling_levels = devm_kzalloc(dev, num * sizeof(u32),
GFP_KERNEL);
if (!ctx->pwm_fan_cooling_levels)
return -ENOMEM;
ret = of_property_read_u32_array(np, "cooling-levels",
ctx->pwm_fan_cooling_levels, num);
if (ret) {
dev_err(dev, "Property 'cooling-levels' cannot be read!\n");
return ret;
}
for (i = 0; i < num; i++) {
if (ctx->pwm_fan_cooling_levels[i] > MAX_PWM) {
dev_err(dev, "PWM fan state[%d]:%d > %d\n", i,
ctx->pwm_fan_cooling_levels[i], MAX_PWM);
return -EINVAL;
}
}
ctx->pwm_fan_max_state = num - 1;
return 0;
}
static int pwm_fan_probe(struct platform_device *pdev) static int pwm_fan_probe(struct platform_device *pdev)
{ {
struct device *hwmon; struct device *hwmon;
...@@ -145,6 +188,11 @@ static int pwm_fan_probe(struct platform_device *pdev) ...@@ -145,6 +188,11 @@ static int pwm_fan_probe(struct platform_device *pdev)
pwm_disable(ctx->pwm); pwm_disable(ctx->pwm);
return PTR_ERR(hwmon); return PTR_ERR(hwmon);
} }
ret = pwm_fan_of_get_cooling_data(&pdev->dev, ctx);
if (ret)
return ret;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment