lkml.org 
[lkml]   [2014]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 7/8] hwmon: thermal: Read PWM FAN configuration from device tree
Date
Code for reading PWM FAN configuration data via device tree.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
---
Changes for v2:
- Rename pwm_fan_max_states to pwm_fan_cooling_levels
- Moving pwm_fan_of_get_cooling_data() call after setting end enabling PWM FAN
- pwm_fan_of_get_cooling_data() now can fail - preserving old behaviour
- Remove unnecessary dev_err() call
---
drivers/hwmon/pwm-fan.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 870e100..8e68308 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -30,7 +30,10 @@
struct pwm_fan_ctx {
struct mutex lock;
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)
@@ -100,6 +103,47 @@ static struct attribute *pwm_fan_attrs[] = {

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;
+ struct property *pp;
+ int len, num, i;
+
+ pp = of_find_property(np, "cooling-levels", &len);
+ if (!pp) {
+ dev_err(dev, "Property: 'cooling-levels' not found\n");
+ return -EINVAL;
+ }
+
+ if (len == 0) {
+ dev_err(dev, "Length wrong value!\n");
+ return -EINVAL;
+ }
+
+ ctx->pwm_fan_cooling_levels = devm_kzalloc(dev, len, GFP_KERNEL);
+ if (!ctx->pwm_fan_cooling_levels)
+ return -ENOMEM;
+
+ num = len / sizeof(u32);
+ if (of_property_read_u32_array(np, pp->name,
+ ctx->pwm_fan_cooling_levels, num)) {
+ dev_err(dev, "Property: %s cannot be read!\n", pp->name);
+ return -EINVAL;
+ }
+
+ 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)
{
struct device *hwmon;
@@ -145,6 +189,8 @@ static int pwm_fan_probe(struct platform_device *pdev)
pwm_disable(ctx->pwm);
return PTR_ERR(hwmon);
}
+
+ pwm_fan_of_get_cooling_data(&pdev->dev, ctx);
return 0;
}

--
2.0.0.rc2


\
 
 \ /
  Last update: 2014-12-22 17:41    [W:0.588 / U:0.584 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site