FreeBSD Bugzilla – Attachment 239475 Details for
Bug 268961
comms/owfs add FreeBSD I2C support to DS2482
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Add FreeBSD I2C support
patch-module_owlib_src_c_ow__ds2482.c (text/plain), 2.64 KB, created by
Bjoern A. Zeeb
on 2023-01-14 23:09:14 UTC
(
hide
)
Description:
Add FreeBSD I2C support
Filename:
MIME Type:
Creator:
Bjoern A. Zeeb
Created:
2023-01-14 23:09:14 UTC
Size:
2.64 KB
patch
obsolete
>--- module/owlib/src/c/ow_ds2482.c.orig 2020-08-23 13:35:09 UTC >+++ module/owlib/src/c/ow_ds2482.c >@@ -40,9 +40,53 @@ > #include "ow_connection.h" > > #if OW_I2C >+#if defined(__FreeBSD__) >+/* For ioctls. */ >+#include <dev/iicbus/iic.h> >+ >+static inline int i2c_smbus_read_byte(int fd) >+{ >+ ssize_t len; >+ uint8_t buf; >+ >+ buf = 0; >+ len = read(fd, &buf, 1); >+ LEVEL_DEBUG("%s: %zd buf [ %#04x ]", __func__, len, buf); >+ if (len != 1) >+ return (-1); >+ return (buf); >+} >+ >+static inline int i2c_smbus_write_byte(int fd, uint8_t buf) >+{ >+ ssize_t len; >+ >+ len = write(fd, &buf, 1); >+ LEVEL_DEBUG("%s: %zd buf [ %#04x ]", __func__, len, buf); >+ if (len != 1) >+ return (-1); >+ return (0); >+} >+ >+static inline int i2c_smbus_write_byte_data(int fd, uint8_t command, uint8_t value) >+{ >+ ssize_t len; >+ uint8_t buf[2]; >+ >+ buf[0] = command; >+ buf[1] = value; >+ >+ len = write(fd, buf, 2); >+ LEVEL_DEBUG("%s: %zd buf [ %#04x, %#04x ]", __func__, len, buf[0], buf[1]); >+ if (len != 2) >+ return (-1); >+ return (0); >+} >+#else > // Header taken from lm-sensors code > // specifically lm-sensors-2.10.0 > #include "i2c-dev.h" >+#endif > > enum ds2482_address { > ds2482_any=-2, >@@ -389,7 +433,12 @@ static GOOD_OR_BAD DS2482_detect_single(int lowindex, > for (i2c_index = lowindex; i2c_index <= highindex; ++i2c_index) { > int trial_address = test_address[i2c_index] ; > /* set the candidate address */ >+#if defined(__FreeBSD__) >+ uint8_t _addr = trial_address << 1; >+ if (ioctl(file_descriptor, I2CSADDR, &_addr) < 0) { >+#else > if (ioctl(file_descriptor, I2C_SLAVE, trial_address) < 0) { >+#endif > ERROR_CONNECT("Cound not set trial i2c address to %.2X", trial_address); > } else { > BYTE c; >@@ -419,7 +468,7 @@ static GOOD_OR_BAD DS2482_detect_single(int lowindex, > || BAD(DS2482_readstatus(&c, file_descriptor, DS2482_Chip_reset_usec)) // pause .5 usec then read status > || (c != (DS2482_REG_STS_LL | DS2482_REG_STS_RST)) // make sure status is properly set > ) { >- LEVEL_CONNECT("i2c device at %s address %.2X cannot be reset. Not a DS2482.", i2c_device, trial_address); >+ LEVEL_CONNECT("i2c device at %s address %.2X cannot be reset. Not a DS2482 (%#x != %#x).", i2c_device, trial_address, c, (DS2482_REG_STS_LL | DS2482_REG_STS_RST)); > in->pown->file_descriptor = FILE_DESCRIPTOR_BAD ; > continue; > } >@@ -464,7 +513,12 @@ static GOOD_OR_BAD DS2482_redetect(const struct parsed > } > > /* address is known */ >+#if defined(__FreeBSD__) >+ uint8_t _addr = address << 1; >+ if (ioctl(file_descriptor, I2CSADDR, &_addr) < 0) { >+#else > if (ioctl(file_descriptor, I2C_SLAVE, address) < 0) { >+#endif > ERROR_CONNECT("Cound not set i2c address to %.2X", address); > } else { > BYTE c;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 268961
: 239475