Skip to content

Commit 1867a1b

Browse files
committed
drivers: hwmon: max31827: refactor enum chips to struct max31827_chip_info
Introduced chip_info structure to replace enum chips Signed-off-by: John Erasmus Mari Geronimo <johnerasmusmari.geronimo@analog.com>
1 parent ff26ad5 commit 1867a1b

File tree

1 file changed

+43
-44
lines changed

1 file changed

+43
-44
lines changed

drivers/hwmon/max31827.c

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
#define MAX31827_M_DGR_TO_16_BIT(x) (((x) << 4) / 1000)
4848
#define MAX31827_DEVICE_ENABLE(x) ((x) ? 0xA : 0x0)
4949

50-
enum chips { max31827 = 1, max31828, max31829 };
51-
5250
enum max31827_cnv {
5351
MAX31827_CNV_1_DIV_64_HZ = 1,
5452
MAX31827_CNV_1_DIV_32_HZ,
@@ -90,6 +88,13 @@ static const u16 max31827_conv_times[] = {
9088
[MAX31827_RES_12_BIT] = MAX31827_12_BIT_CNV_TIME,
9189
};
9290

91+
struct max31827_state;
92+
93+
struct max31827_chip_info {
94+
u32 alarm_pol_default : 1;
95+
u32 fault_q_default;
96+
};
97+
9398
struct max31827_state {
9499
/*
95100
* Prevent simultaneous access to the i2c client.
@@ -99,6 +104,7 @@ struct max31827_state {
99104
bool enable;
100105
unsigned int resolution;
101106
unsigned int update_interval;
107+
const struct max31827_chip_info *chip_info;
102108
};
103109

104110
static const struct regmap_config max31827_regmap = {
@@ -485,21 +491,12 @@ static struct attribute *max31827_attrs[] = {
485491
};
486492
ATTRIBUTE_GROUPS(max31827);
487493

488-
static const struct i2c_device_id max31827_i2c_ids[] = {
489-
{ "max31827", max31827 },
490-
{ "max31828", max31828 },
491-
{ "max31829", max31829 },
492-
{ }
493-
};
494-
MODULE_DEVICE_TABLE(i2c, max31827_i2c_ids);
495-
496494
static int max31827_init_client(struct max31827_state *st,
497495
struct device *dev)
498496
{
499497
struct fwnode_handle *fwnode;
500498
unsigned int res = 0;
501499
u32 data, lsb_idx;
502-
enum chips type;
503500
bool prop;
504501
int ret;
505502

@@ -516,8 +513,6 @@ static int max31827_init_client(struct max31827_state *st,
516513
prop = fwnode_property_read_bool(fwnode, "adi,timeout-enable");
517514
res |= FIELD_PREP(MAX31827_CONFIGURATION_TIMEOUT_MASK, !prop);
518515

519-
type = (enum chips)(uintptr_t)device_get_match_data(dev);
520-
521516
if (fwnode_property_present(fwnode, "adi,alarm-pol")) {
522517
ret = fwnode_property_read_u32(fwnode, "adi,alarm-pol", &data);
523518
if (ret)
@@ -528,19 +523,8 @@ static int max31827_init_client(struct max31827_state *st,
528523
/*
529524
* Set default value.
530525
*/
531-
switch (type) {
532-
case max31827:
533-
case max31828:
534-
res |= FIELD_PREP(MAX31827_CONFIGURATION_ALRM_POL_MASK,
535-
MAX31827_ALRM_POL_LOW);
536-
break;
537-
case max31829:
538-
res |= FIELD_PREP(MAX31827_CONFIGURATION_ALRM_POL_MASK,
539-
MAX31827_ALRM_POL_HIGH);
540-
break;
541-
default:
542-
return -EOPNOTSUPP;
543-
}
526+
res |= FIELD_PREP(MAX31827_CONFIGURATION_ALRM_POL_MASK,
527+
st->chip_info->alarm_pol_default);
544528
}
545529

546530
if (fwnode_property_present(fwnode, "adi,fault-q")) {
@@ -564,19 +548,8 @@ static int max31827_init_client(struct max31827_state *st,
564548
/*
565549
* Set default value.
566550
*/
567-
switch (type) {
568-
case max31827:
569-
res |= FIELD_PREP(MAX31827_CONFIGURATION_FLT_Q_MASK,
570-
MAX31827_FLT_Q_1);
571-
break;
572-
case max31828:
573-
case max31829:
574-
res |= FIELD_PREP(MAX31827_CONFIGURATION_FLT_Q_MASK,
575-
MAX31827_FLT_Q_4);
576-
break;
577-
default:
578-
return -EOPNOTSUPP;
579-
}
551+
res |= FIELD_PREP(MAX31827_CONFIGURATION_FLT_Q_MASK,
552+
st->chip_info->fault_q_default);
580553
}
581554

582555
return regmap_write(st->regmap, MAX31827_CONFIGURATION_REG, res);
@@ -597,7 +570,7 @@ static const struct hwmon_ops max31827_hwmon_ops = {
597570
.write = max31827_write,
598571
};
599572

600-
static const struct hwmon_chip_info max31827_chip_info = {
573+
static const struct hwmon_chip_info max31827_hwmon_chip_info = {
601574
.ops = &max31827_hwmon_ops,
602575
.info = max31827_info,
603576
};
@@ -616,6 +589,8 @@ static int max31827_probe(struct i2c_client *client)
616589
if (!st)
617590
return -ENOMEM;
618591

592+
st->chip_info = (struct max31827_chip_info *)(uintptr_t)device_get_match_data(dev);
593+
619594
mutex_init(&st->lock);
620595

621596
st->regmap = devm_regmap_init_i2c(client, &max31827_regmap);
@@ -632,24 +607,47 @@ static int max31827_probe(struct i2c_client *client)
632607
return err;
633608

634609
hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, st,
635-
&max31827_chip_info,
610+
&max31827_hwmon_chip_info,
636611
max31827_groups);
637612

638613
return PTR_ERR_OR_ZERO(hwmon_dev);
639614
}
640615

616+
static const struct max31827_chip_info max31827 = {
617+
.alarm_pol_default = MAX31827_ALRM_POL_LOW,
618+
.fault_q_default = MAX31827_FLT_Q_1,
619+
};
620+
621+
static const struct max31827_chip_info max31828 = {
622+
.alarm_pol_default = MAX31827_ALRM_POL_LOW,
623+
.fault_q_default = MAX31827_FLT_Q_4,
624+
};
625+
626+
static const struct max31827_chip_info max31829 = {
627+
.alarm_pol_default = MAX31827_ALRM_POL_HIGH,
628+
.fault_q_default = MAX31827_FLT_Q_4,
629+
};
630+
631+
static const struct i2c_device_id max31827_i2c_ids[] = {
632+
{ "max31827", (kernel_ulong_t)&max31827 },
633+
{ "max31828", (kernel_ulong_t)&max31828 },
634+
{ "max31829", (kernel_ulong_t)&max31829 },
635+
{ }
636+
};
637+
MODULE_DEVICE_TABLE(i2c, max31827_i2c_ids);
638+
641639
static const struct of_device_id max31827_of_match[] = {
642640
{
643641
.compatible = "adi,max31827",
644-
.data = (void *)max31827
642+
.data = (void *)&max31827
645643
},
646644
{
647645
.compatible = "adi,max31828",
648-
.data = (void *)max31828
646+
.data = (void *)&max31828
649647
},
650648
{
651649
.compatible = "adi,max31829",
652-
.data = (void *)max31829
650+
.data = (void *)&max31829
653651
},
654652
{ }
655653
};
@@ -666,6 +664,7 @@ static struct i2c_driver max31827_driver = {
666664
};
667665
module_i2c_driver(max31827_driver);
668666

667+
MODULE_AUTHOR("John Erasmus Mari Geronimo <johnerasmusmari.geronimo@analog.com>");
669668
MODULE_AUTHOR("Daniel Matyas <daniel.matyas@analog.com>");
670669
MODULE_DESCRIPTION("Maxim MAX31827 low-power temperature switch driver");
671670
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)