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: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
Lukasz Majewski 2015-02-26 14:59:36 +01:00 коммит произвёл Guenter Roeck
Родитель cb85ca332f
Коммит 2e5219c771
1 изменённых файлов: 49 добавлений и 1 удалений

Просмотреть файл

@ -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[] = {
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)
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;
} }