Page MenuHomeFreeBSD

TMP461: Add thermal sensor driver
ClosedPublic

Authored by hum_semihalf.com on Nov 3 2021, 11:57 AM.

Details

Summary

Add driver for TMP461 thermal sensor. Register new sysctl node
of integer type for device. Read register and fill sysctl with
valid temperature.

Diff Detail

Repository
R10 FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

contact_artur-rojek.eu added inline comments.
sys/dev/iicbus/tmp461.c
193

This is a good opportunity to create a system global helper for integer sign extend, instead of creating yet another duplicate local implementation.
As per discussion on #freebsd-dev, sys/sys/libkern.h seems like an appropriate place for such a helper.

As discussed on IRC, I propose that such a helper should have three arguments:

  • the bitfield to extract from (32/64 bit?)
  • the index of the least significant bit of the field to extract
  • the number of bits in the field.

This roughly corresponds to the sbfx and ufbx instructions on ARM and is as flexible as needed. Both signed and unsigned versions should be provided.

Maybe a corresponding narrowing/insertion function (corresponding to the bfi instruction) would be nice, too.

Move signed -> unsigned helper function to libkern.h.

@hum_semihalf.com
What Robert has in mind is something more akin to this (I allowed myself to replace the number of bits with an index to the most significant bit):

static __inline int32_t
signed_extend32(uint32_t bitmap, int msb, int lsb)
{

	return ((int32_t)(bitmap << (31 - msb)) >> (31 - msb + lsb));
}

This way we cover situations where the embedded value does not start at the beginning of the bit field.
Please also provide the remaining versions of those helpers.
On another note, these should go into a separate commit.

Remove conversion helper function, as it is separate commit.

This revision was not accepted when it landed; it landed in state Needs Review.Thu, Dec 2, 9:00 AM
This revision was automatically updated to reflect the committed changes.