-
Notifications
You must be signed in to change notification settings - Fork 845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for MAX31875 #2635
base: main
Are you sure you want to change the base?
Add support for MAX31875 #2635
Conversation
7165f8f
to
4e669bc
Compare
Why the new PR? Should we close #2600? |
I've created this separate PR that introduces an alternative method to add driver support for the MAX31875. This involves using the existing MAX31827 driver to support the MAX31875. |
4e669bc
to
31e479a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most of the complexity could go away with a chi_info struture where you have things like different register masks per device. Then accessing it in the code would be for example: st->info->cfg_reg
.
Anyways, i think we can support this new device in the existing driver so I'll close the other PR
|
||
maintainers: | ||
- Daniel Matyas <daniel.matyas@analog.com> | ||
- John Erasmus Mari Geronimo <johnerasmusmari.geronimo@analog.com> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should mention this change in the commit message. You'll likely be asked why if we can have a fallback device for this one (one of the devices that the driver already supports). So you should also mention in the commit message why that is not possible.
Also speaking about the commit message, you're only stating the obvious there :). Give a small description of the HW.
31e479a
to
c810a02
Compare
…_info Introduced chip_info structure to replace enum chips Signed-off-by: John Erasmus Mari Geronimo <[email protected]>
Add max31875 to dt-bindings of max31827 MAX31875 is low-power I2C temperature sensor similar to MAX31827 Signed-off-by: John Erasmus Mari Geronimo <[email protected]>
2995aed
to
4b56b21
Compare
Add support for MAX31875 Low-Power I2C Temperature Sensor in MAX31827 driver Signed-off-by: John Erasmus Mari Geronimo <[email protected]>
4b56b21
to
1a82903
Compare
V2
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, the chip info structure grew quite a bit but IMHO, it's still better than all the if() else stuff we had before.
Take my inputs and send this upstream.
struct max31827_state; | ||
|
||
struct max31827_chip_info { | ||
u32 alarm_pol_default : 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the bit assignment. Just make it u8 and don't overcomplicate :). Arguably, you could also already add the hwmon_info struture in this patch.
{ "max31829", max31829 }, | ||
{ } | ||
}; | ||
MODULE_DEVICE_TABLE(i2c, max31827_i2c_ids); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I agree with moving this to it's natural place, this change is not strictly needed. So, bear in mind that you can get some comments about this.
static const struct of_device_id max31827_of_match[] = { | ||
{ | ||
.compatible = "adi,max31827", | ||
.data = (void *)max31827 | ||
.data = (void *)&max31827 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for the void cast...
@@ -616,6 +589,8 @@ static int max31827_probe(struct i2c_client *client) | |||
if (!st) | |||
return -ENOMEM; | |||
|
|||
st->chip_info = (struct max31827_chip_info *)(uintptr_t)device_get_match_data(dev); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just do device_get_match_data()
and drop the casts (they are not fine either way)... Also take the opportunity to add some error checking:
if (!st->chip_info)
return -ENODEV;
long (*from_16_bit_to_m_dgr)(unsigned int x); | ||
unsigned int (*from_m_dgr_to_16_bit)(long x); | ||
int (*shutdown)(struct max31827_state *st, unsigned int *cnv_rate); | ||
int (*wakeup)(struct max31827_state *st, unsigned int cnv_rate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I did not realized at all that this would need so much fields. That said, I think you can make this much better. See some examples below and then see what you can do...
*val = !!uval; | ||
uval = max31827_field_get(st->chip_info->shutdown_mask, | ||
uval); | ||
*val = st->chip_info->is_enabled(uval); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example... In here, you already have an is_enabled()
callback per chip. Hence, just implement it in a different way per chip so that you don't really need config_reg
or shutdown_mask
per chip_info. Do you see my point? And if the function is pretty much the same for all the variants and you'r worried about code repetition, just implement a core function that accepts a config_reg
and a shutdown_mask
and build on top of it. Example:
bool __max31827_is_enabled(struct max31827_state *st, unsigned int reg, unsigned int mask)
{
//core generic implementation
}
// This is the per chip callback
bool maxxxxx_is_enabled(struct max31827_state *st, unsigned int reg, unsigned int mask)
{
return __max31827_is_enabled(st, MAXXXXX_REG_CFGm MAXXXX_SHUTDOWN_MASK)
}
See the idea? You might be able to reduce the number of fields significantly...
@@ -234,7 +372,7 @@ static int max31827_read(struct device *dev, enum hwmon_sensor_types type, | |||
*/ | |||
|
|||
ret = regmap_update_bits(st->regmap, | |||
MAX31827_CONFIGURATION_REG, | |||
st->chip_info->config_reg, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I see you still need config_reg
in a lot other places but the above point still stands. You could also negate the enable state in proper variant callback (which is the only thing you're doing now in the is_enabled() function which is a bit odd)
Think about it and see if we can reduce the number of fields somehow.
@@ -503,15 +641,19 @@ static int max31827_init_client(struct max31827_state *st, | |||
fwnode = dev_fwnode(dev); | |||
|
|||
st->enable = true; | |||
res |= MAX31827_DEVICE_ENABLE(1); | |||
res |= st->chip_info->device_enable(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe an init_client callback per chip (in the same way I explained above) would also reduce things a bit...
PR Description
PR Type
PR Checklist