Skip to content

Commit a6cdeef

Browse files
MikeLooijmansgroeck
authored andcommitted
hwmon: (max6650) Add devicetree support
Parse devicetree parameters for voltage and prescaler setting. This allows using multiple max6550 devices with varying settings, and also makes it possible to instantiate and configure the device using devicetree. Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 88de8e1 commit a6cdeef

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

drivers/hwmon/max6650.c

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <linux/hwmon.h>
4040
#include <linux/hwmon-sysfs.h>
4141
#include <linux/err.h>
42+
#include <linux/of_device.h>
4243

4344
/*
4445
* Insmod parameters
@@ -48,7 +49,7 @@
4849
static int fan_voltage;
4950
/* prescaler: Possible values are 1, 2, 4, 8, 16 or 0 for don't change */
5051
static int prescaler;
51-
/* clock: The clock frequency of the chip the driver should assume */
52+
/* clock: The clock frequency of the chip (max6651 can be clocked externally) */
5253
static int clock = 254000;
5354

5455
module_param(fan_voltage, int, S_IRUGO);
@@ -133,6 +134,19 @@ static const u8 tach_reg[] = {
133134
MAX6650_REG_TACH3,
134135
};
135136

137+
static const struct of_device_id max6650_dt_match[] = {
138+
{
139+
.compatible = "maxim,max6650",
140+
.data = (void *)1
141+
},
142+
{
143+
.compatible = "maxim,max6651",
144+
.data = (void *)4
145+
},
146+
{ },
147+
};
148+
MODULE_DEVICE_TABLE(of, max6650_dt_match);
149+
136150
static struct max6650_data *max6650_update_device(struct device *dev)
137151
{
138152
struct max6650_data *data = dev_get_drvdata(dev);
@@ -566,6 +580,17 @@ static int max6650_init_client(struct max6650_data *data,
566580
struct device *dev = &client->dev;
567581
int config;
568582
int err = -EIO;
583+
u32 voltage;
584+
u32 prescale;
585+
586+
if (of_property_read_u32(dev->of_node, "maxim,fan-microvolt",
587+
&voltage))
588+
voltage = fan_voltage;
589+
else
590+
voltage /= 1000000; /* Microvolts to volts */
591+
if (of_property_read_u32(dev->of_node, "maxim,fan-prescale",
592+
&prescale))
593+
prescale = prescaler;
569594

570595
config = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG);
571596

@@ -574,7 +599,7 @@ static int max6650_init_client(struct max6650_data *data,
574599
return err;
575600
}
576601

577-
switch (fan_voltage) {
602+
switch (voltage) {
578603
case 0:
579604
break;
580605
case 5:
@@ -584,14 +609,10 @@ static int max6650_init_client(struct max6650_data *data,
584609
config |= MAX6650_CFG_V12;
585610
break;
586611
default:
587-
dev_err(dev, "illegal value for fan_voltage (%d)\n",
588-
fan_voltage);
612+
dev_err(dev, "illegal value for fan_voltage (%d)\n", voltage);
589613
}
590614

591-
dev_info(dev, "Fan voltage is set to %dV.\n",
592-
(config & MAX6650_CFG_V12) ? 12 : 5);
593-
594-
switch (prescaler) {
615+
switch (prescale) {
595616
case 0:
596617
break;
597618
case 1:
@@ -614,10 +635,11 @@ static int max6650_init_client(struct max6650_data *data,
614635
| MAX6650_CFG_PRESCALER_16;
615636
break;
616637
default:
617-
dev_err(dev, "illegal value for prescaler (%d)\n", prescaler);
638+
dev_err(dev, "illegal value for prescaler (%d)\n", prescale);
618639
}
619640

620-
dev_info(dev, "Prescaler is set to %d.\n",
641+
dev_info(dev, "Fan voltage: %dV, prescaler: %d.\n",
642+
(config & MAX6650_CFG_V12) ? 12 : 5,
621643
1 << (config & MAX6650_CFG_PRESCALER_MASK));
622644

623645
/*
@@ -651,6 +673,8 @@ static int max6650_probe(struct i2c_client *client,
651673
const struct i2c_device_id *id)
652674
{
653675
struct device *dev = &client->dev;
676+
const struct of_device_id *of_id =
677+
of_match_device(of_match_ptr(max6650_dt_match), dev);
654678
struct max6650_data *data;
655679
struct device *hwmon_dev;
656680
int err;
@@ -661,7 +685,7 @@ static int max6650_probe(struct i2c_client *client,
661685

662686
data->client = client;
663687
mutex_init(&data->update_lock);
664-
data->nr_fans = id->driver_data;
688+
data->nr_fans = of_id ? (int)(uintptr_t)of_id->data : id->driver_data;
665689

666690
/*
667691
* Initialize the max6650 chip
@@ -691,6 +715,7 @@ MODULE_DEVICE_TABLE(i2c, max6650_id);
691715
static struct i2c_driver max6650_driver = {
692716
.driver = {
693717
.name = "max6650",
718+
.of_match_table = of_match_ptr(max6650_dt_match),
694719
},
695720
.probe = max6650_probe,
696721
.id_table = max6650_id,

0 commit comments

Comments
 (0)