Skip to content

Commit f6c8e16

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 f6c8e16

File tree

1 file changed

+44
-39
lines changed

1 file changed

+44
-39
lines changed

drivers/hwmon/max31827.c

Lines changed: 44 additions & 39 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,17 @@ static const u16 max31827_conv_times[] = {
9088
[MAX31827_RES_12_BIT] = MAX31827_12_BIT_CNV_TIME,
9189
};
9290

91+
struct max31827_state;
92+
static const struct max31827_chip_info max31827;
93+
static const struct max31827_chip_info max31828;
94+
static const struct max31827_chip_info max31829;
95+
static const struct max31827_chip_info max31875;
96+
97+
struct max31827_chip_info {
98+
u8 alarm_pol_default;
99+
u32 fault_q_default;
100+
};
101+
93102
struct max31827_state {
94103
/*
95104
* Prevent simultaneous access to the i2c client.
@@ -99,6 +108,7 @@ struct max31827_state {
99108
bool enable;
100109
unsigned int resolution;
101110
unsigned int update_interval;
111+
const struct max31827_chip_info *chip_info;
102112
};
103113

104114
static const struct regmap_config max31827_regmap = {
@@ -486,9 +496,9 @@ static struct attribute *max31827_attrs[] = {
486496
ATTRIBUTE_GROUPS(max31827);
487497

488498
static const struct i2c_device_id max31827_i2c_ids[] = {
489-
{ "max31827", max31827 },
490-
{ "max31828", max31828 },
491-
{ "max31829", max31829 },
499+
{ "max31827", (kernel_ulong_t)&max31827 },
500+
{ "max31828", (kernel_ulong_t)&max31828 },
501+
{ "max31829", (kernel_ulong_t)&max31829 },
492502
{ }
493503
};
494504
MODULE_DEVICE_TABLE(i2c, max31827_i2c_ids);
@@ -499,7 +509,6 @@ static int max31827_init_client(struct max31827_state *st,
499509
struct fwnode_handle *fwnode;
500510
unsigned int res = 0;
501511
u32 data, lsb_idx;
502-
enum chips type;
503512
bool prop;
504513
int ret;
505514

@@ -516,8 +525,6 @@ static int max31827_init_client(struct max31827_state *st,
516525
prop = fwnode_property_read_bool(fwnode, "adi,timeout-enable");
517526
res |= FIELD_PREP(MAX31827_CONFIGURATION_TIMEOUT_MASK, !prop);
518527

519-
type = (enum chips)(uintptr_t)device_get_match_data(dev);
520-
521528
if (fwnode_property_present(fwnode, "adi,alarm-pol")) {
522529
ret = fwnode_property_read_u32(fwnode, "adi,alarm-pol", &data);
523530
if (ret)
@@ -528,19 +535,8 @@ static int max31827_init_client(struct max31827_state *st,
528535
/*
529536
* Set default value.
530537
*/
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-
}
538+
res |= FIELD_PREP(MAX31827_CONFIGURATION_ALRM_POL_MASK,
539+
st->chip_info->alarm_pol_default);
544540
}
545541

546542
if (fwnode_property_present(fwnode, "adi,fault-q")) {
@@ -564,19 +560,8 @@ static int max31827_init_client(struct max31827_state *st,
564560
/*
565561
* Set default value.
566562
*/
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-
}
563+
res |= FIELD_PREP(MAX31827_CONFIGURATION_FLT_Q_MASK,
564+
st->chip_info->fault_q_default);
580565
}
581566

582567
return regmap_write(st->regmap, MAX31827_CONFIGURATION_REG, res);
@@ -597,11 +582,26 @@ static const struct hwmon_ops max31827_hwmon_ops = {
597582
.write = max31827_write,
598583
};
599584

600-
static const struct hwmon_chip_info max31827_chip_info = {
585+
static const struct hwmon_chip_info max31827_hwmon_chip_info = {
601586
.ops = &max31827_hwmon_ops,
602587
.info = max31827_info,
603588
};
604589

590+
static const struct max31827_chip_info max31827 = {
591+
.alarm_pol_default = MAX31827_ALRM_POL_LOW,
592+
.fault_q_default = MAX31827_FLT_Q_1,
593+
};
594+
595+
static const struct max31827_chip_info max31828 = {
596+
.alarm_pol_default = MAX31827_ALRM_POL_LOW,
597+
.fault_q_default = MAX31827_FLT_Q_4,
598+
};
599+
600+
static const struct max31827_chip_info max31829 = {
601+
.alarm_pol_default = MAX31827_ALRM_POL_HIGH,
602+
.fault_q_default = MAX31827_FLT_Q_4,
603+
};
604+
605605
static int max31827_probe(struct i2c_client *client)
606606
{
607607
struct device *dev = &client->dev;
@@ -616,6 +616,10 @@ static int max31827_probe(struct i2c_client *client)
616616
if (!st)
617617
return -ENOMEM;
618618

619+
st->chip_info = device_get_match_data(dev);
620+
if (!st->chip_info)
621+
return -ENODEV;
622+
619623
mutex_init(&st->lock);
620624

621625
st->regmap = devm_regmap_init_i2c(client, &max31827_regmap);
@@ -632,7 +636,7 @@ static int max31827_probe(struct i2c_client *client)
632636
return err;
633637

634638
hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, st,
635-
&max31827_chip_info,
639+
&max31827_hwmon_chip_info,
636640
max31827_groups);
637641

638642
return PTR_ERR_OR_ZERO(hwmon_dev);
@@ -641,15 +645,15 @@ static int max31827_probe(struct i2c_client *client)
641645
static const struct of_device_id max31827_of_match[] = {
642646
{
643647
.compatible = "adi,max31827",
644-
.data = (void *)max31827
648+
.data = &max31827
645649
},
646650
{
647651
.compatible = "adi,max31828",
648-
.data = (void *)max31828
652+
.data = &max31828
649653
},
650654
{
651655
.compatible = "adi,max31829",
652-
.data = (void *)max31829
656+
.data = &max31829
653657
},
654658
{ }
655659
};
@@ -666,6 +670,7 @@ static struct i2c_driver max31827_driver = {
666670
};
667671
module_i2c_driver(max31827_driver);
668672

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

0 commit comments

Comments
 (0)