Skip to content

Commit

Permalink
Merge pull request #6 from HenryHu/master
Browse files Browse the repository at this point in the history
Port ddccontrol to FreeBSD
  • Loading branch information
larstobi committed Apr 12, 2017
2 parents bb63342 + 56050fb commit 79fbfe9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
8 changes: 7 additions & 1 deletion configure.ac
Expand Up @@ -38,7 +38,13 @@ AC_ARG_ENABLE(i2cdev,

if test "x$support_i2c_dev" = "xyes" ; then
AC_DEFINE_UNQUOTED(HAVE_I2C_DEV, 1, [Define if ddccontrol is built with /dev/i2c-* support.])
AC_CHECK_HEADERS([linux/types.h], [], [AC_MSG_ERROR([Linux kernel header files not found, please install them.], [1])], [])

AC_CANONICAL_HOST
case $host_os in
linux*)
AC_CHECK_HEADERS([linux/types.h], [], [AC_MSG_ERROR([Linux kernel header files not found, please install them.], [1])], [])
;;
esac

support_i2c_dev_works=no
AC_MSG_CHECKING([if linux/i2c-dev.h works with non-kernel linux/types.h])
Expand Down
2 changes: 1 addition & 1 deletion src/ddccontrol/Makefile.am
Expand Up @@ -5,5 +5,5 @@ LDADD = ../lib/libddccontrol.la

bin_PROGRAMS = ddccontrol
ddccontrol_SOURCES = main.c
ddccontrol_LDFLAGS = $(LIBXML2_LDFLAGS)
ddccontrol_LDFLAGS = $(LIBXML2_LDFLAGS) $(LIBINTL)
AM_CFLAGS = $(LIBXML2_CFLAGS)
24 changes: 23 additions & 1 deletion src/lib/ddcci.c
Expand Up @@ -274,7 +274,11 @@ static int i2c_write(struct monitor* mon, unsigned int addr, unsigned char *buf,
msg_rdwr.msgs = &i2cmsg;
msg_rdwr.nmsgs = 1;

#ifdef __FreeBSD__
i2cmsg.slave = addr << 1;
#else
i2cmsg.addr = addr;
#endif
i2cmsg.flags = 0;
i2cmsg.len = len;
i2cmsg.buf = buf;
Expand All @@ -292,6 +296,10 @@ static int i2c_write(struct monitor* mon, unsigned int addr, unsigned char *buf,
dumphex(stderr, "Send", buf, len);
}

#ifdef __FreeBSD__
i = len; // FreeBSD ioctl() returns 0
#endif

return i;
}
#endif
Expand Down Expand Up @@ -355,7 +363,11 @@ static int i2c_read(struct monitor* mon, unsigned int addr, unsigned char *buf,
msg_rdwr.msgs = &i2cmsg;
msg_rdwr.nmsgs = 1;

#ifdef __FreeBSD__
i2cmsg.slave = addr << 1;
#else
i2cmsg.addr = addr;
#endif
i2cmsg.flags = I2C_M_RD;
i2cmsg.len = len;
i2cmsg.buf = buf;
Expand All @@ -373,6 +385,10 @@ static int i2c_read(struct monitor* mon, unsigned int addr, unsigned char *buf,
dumphex(stderr, "Recv", buf, i);
}

#ifdef __FreeBSD__
i = len; // FreeBSD ioctl() returns 0
#endif

return i;
}
#endif
Expand Down Expand Up @@ -1185,9 +1201,15 @@ struct monitorlist* ddcci_probe() {

dirp = opendir("/dev/");

#ifdef __FreeBSD__
const char *prefix = "iic";
#else
const char *prefix = "i2c-";
#endif
int prefix_len = strlen(prefix);
while ((direntp = readdir(dirp)) != NULL)
{
if (!strncmp(direntp->d_name, "i2c-", 4))
if (!strncmp(direntp->d_name, prefix, prefix_len))
{
filename = malloc(strlen(direntp->d_name)+12);

Expand Down
13 changes: 13 additions & 0 deletions src/lib/i2c-dev.h
Expand Up @@ -24,6 +24,18 @@
/* If linux/i2c-dev.h is usable, use it, otherwise, define
* the required constants and structures. */

#ifdef __FreeBSD__

#include <sys/types.h>
#include <dev/iicbus/iic.h>

#define I2C_M_RD IIC_M_RD
#define I2C_RDWR I2CRDWR

#define i2c_msg iic_msg
#define i2c_rdwr_ioctl_data iic_rdwr_data

#else
#if HAVE_BUGGY_I2C_DEV
#include <linux/types.h>

Expand Down Expand Up @@ -57,5 +69,6 @@ struct i2c_rdwr_ioctl_data {
#include <linux/i2c-dev.h>

#endif
#endif // __FreeBSD__

#endif //DDCCONTROL_I2C_DEV_H

0 comments on commit 79fbfe9

Please sign in to comment.