mirror of
https://github.com/torvalds/linux.git
synced 2026-05-30 10:04:04 +02:00
hwmon: (max6639) : Configure based on DT property
Remove platform data & initialize with defaults configuration & overwrite based on DT properties. Signed-off-by: Naresh Solanki <naresh.solanki@9elements.com> Message-ID: <20241007090426.811736-1-naresh.solanki@9elements.com> [groeck: Dropped some unnecessary empty lines] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
79bc0af904
commit
7506ebcd66
|
|
@ -19,7 +19,6 @@
|
||||||
#include <linux/hwmon-sysfs.h>
|
#include <linux/hwmon-sysfs.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/mutex.h>
|
#include <linux/mutex.h>
|
||||||
#include <linux/platform_data/max6639.h>
|
|
||||||
#include <linux/regmap.h>
|
#include <linux/regmap.h>
|
||||||
#include <linux/util_macros.h>
|
#include <linux/util_macros.h>
|
||||||
|
|
||||||
|
|
@ -531,14 +530,49 @@ static int rpm_range_to_reg(int range)
|
||||||
return 1; /* default: 4000 RPM */
|
return 1; /* default: 4000 RPM */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int max6639_probe_child_from_dt(struct i2c_client *client,
|
||||||
|
struct device_node *child,
|
||||||
|
struct max6639_data *data)
|
||||||
|
|
||||||
|
{
|
||||||
|
struct device *dev = &client->dev;
|
||||||
|
u32 i;
|
||||||
|
int err, val;
|
||||||
|
|
||||||
|
err = of_property_read_u32(child, "reg", &i);
|
||||||
|
if (err) {
|
||||||
|
dev_err(dev, "missing reg property of %pOFn\n", child);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i > 1) {
|
||||||
|
dev_err(dev, "Invalid fan index reg %d\n", i);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = of_property_read_u32(child, "pulses-per-revolution", &val);
|
||||||
|
if (!err) {
|
||||||
|
if (val < 1 || val > 5) {
|
||||||
|
dev_err(dev, "invalid pulses-per-revolution %d of %pOFn\n", val, child);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
data->ppr[i] = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = of_property_read_u32(child, "max-rpm", &val);
|
||||||
|
if (!err)
|
||||||
|
data->rpm_range[i] = rpm_range_to_reg(val);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int max6639_init_client(struct i2c_client *client,
|
static int max6639_init_client(struct i2c_client *client,
|
||||||
struct max6639_data *data)
|
struct max6639_data *data)
|
||||||
{
|
{
|
||||||
struct max6639_platform_data *max6639_info =
|
struct device *dev = &client->dev;
|
||||||
dev_get_platdata(&client->dev);
|
const struct device_node *np = dev->of_node;
|
||||||
int i;
|
struct device_node *child;
|
||||||
int rpm_range = 1; /* default: 4000 RPM */
|
int i, err;
|
||||||
int err, ppr;
|
|
||||||
|
|
||||||
/* Reset chip to default values, see below for GCONFIG setup */
|
/* Reset chip to default values, see below for GCONFIG setup */
|
||||||
err = regmap_write(data->regmap, MAX6639_REG_GCONFIG, MAX6639_GCONFIG_POR);
|
err = regmap_write(data->regmap, MAX6639_REG_GCONFIG, MAX6639_GCONFIG_POR);
|
||||||
|
|
@ -546,21 +580,29 @@ static int max6639_init_client(struct i2c_client *client,
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
/* Fans pulse per revolution is 2 by default */
|
/* Fans pulse per revolution is 2 by default */
|
||||||
if (max6639_info && max6639_info->ppr > 0 &&
|
data->ppr[0] = 2;
|
||||||
max6639_info->ppr < 5)
|
data->ppr[1] = 2;
|
||||||
ppr = max6639_info->ppr;
|
|
||||||
else
|
|
||||||
ppr = 2;
|
|
||||||
|
|
||||||
data->ppr[0] = ppr;
|
/* default: 4000 RPM */
|
||||||
data->ppr[1] = ppr;
|
data->rpm_range[0] = 1;
|
||||||
|
data->rpm_range[1] = 1;
|
||||||
|
|
||||||
if (max6639_info)
|
for_each_child_of_node(np, child) {
|
||||||
rpm_range = rpm_range_to_reg(max6639_info->rpm_range);
|
if (strcmp(child->name, "fan"))
|
||||||
data->rpm_range[0] = rpm_range;
|
continue;
|
||||||
data->rpm_range[1] = rpm_range;
|
|
||||||
|
err = max6639_probe_child_from_dt(client, child, data);
|
||||||
|
if (err) {
|
||||||
|
of_node_put(child);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < MAX6639_NUM_CHANNELS; i++) {
|
for (i = 0; i < MAX6639_NUM_CHANNELS; i++) {
|
||||||
|
err = regmap_set_bits(data->regmap, MAX6639_REG_OUTPUT_MASK, BIT(1 - i));
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
/* Set Fan pulse per revolution */
|
/* Set Fan pulse per revolution */
|
||||||
err = max6639_set_ppr(data, i, data->ppr[i]);
|
err = max6639_set_ppr(data, i, data->ppr[i]);
|
||||||
if (err)
|
if (err)
|
||||||
|
|
@ -573,12 +615,7 @@ static int max6639_init_client(struct i2c_client *client,
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
/* Fans PWM polarity high by default */
|
/* Fans PWM polarity high by default */
|
||||||
if (max6639_info) {
|
err = regmap_write(data->regmap, MAX6639_REG_FAN_CONFIG2a(i), 0x00);
|
||||||
if (max6639_info->pwm_polarity == 0)
|
|
||||||
err = regmap_write(data->regmap, MAX6639_REG_FAN_CONFIG2a(i), 0x00);
|
|
||||||
else
|
|
||||||
err = regmap_write(data->regmap, MAX6639_REG_FAN_CONFIG2a(i), 0x02);
|
|
||||||
}
|
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0 */
|
|
||||||
#ifndef _LINUX_MAX6639_H
|
|
||||||
#define _LINUX_MAX6639_H
|
|
||||||
|
|
||||||
#include <linux/types.h>
|
|
||||||
|
|
||||||
/* platform data for the MAX6639 temperature sensor and fan control */
|
|
||||||
|
|
||||||
struct max6639_platform_data {
|
|
||||||
bool pwm_polarity; /* Polarity low (0) or high (1, default) */
|
|
||||||
int ppr; /* Pulses per rotation 1..4 (default == 2) */
|
|
||||||
int rpm_range; /* 2000, 4000 (default), 8000 or 16000 */
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* _LINUX_MAX6639_H */
|
|
||||||
Loading…
Reference in New Issue
Block a user