NetBSD Problem Report #48933

From  Sat Jun 21 01:43:52 2014
Return-Path: <>
Received: from ( [])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "", Issuer "Postmaster" (verified OK))
	by (Postfix) with ESMTPS id EB97FA64F0
	for <>; Sat, 21 Jun 2014 01:43:52 +0000 (UTC)
Message-Id: <>
Date: Sat, 21 Jun 2014 01:43:51 +0000 (UTC)
Subject: Raspberry Pi i2c ioctl() does not allow just READ operation on the i2c bus
X-Send-Pr-Version: www-1.0

>Number:         48933
>Category:       port-arm
>Synopsis:       Raspberry Pi i2c ioctl() does not allow just READ operation on the i2c bus
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    port-arm-maintainer
>State:          feedback
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jun 21 01:45:00 +0000 2014
>Last-Modified:  Tue Aug 30 09:58:43 +0000 2022
>Originator:     Yunis Mustafa
>Release:        evbarm-earmhf/201405181900Z
NetBSD rpi 6.99.42 NetBSD 6.99.42 (RPI) #0: Sun May 18 20:34:46 UTC 2014 evbarm
i2c ioctl(I2C_IOCTL_EXEC, I2C_OP_READ) call always does an i2c write operation to the slave device before the i2c read operation. 

The i2c slave device I am working with NACKs read requests if it is busy. And the recommended recovery mechanism is to retry the read i2c operation again. But I am unable to because of this. And I couldn't find another mechanism to do just a read i2c operation without a leading write i2c operation. 

i2c bus protocal capture screenshots available for more information. However unsure how to upload that with this PR.

- Compile sample code below
- Setup the i2c bus capture (I used a saleae product)
- run "a.out /dev/iic[01]"
- Notice the write i2c operation before read i2c operation in the bus capture.

#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <dev/i2c/i2c_io.h>

main(int argc, char *argv[])
	int                 fd;
	i2c_ioctl_exec_t    iie;

	if (argc != 2) printf("Error: %s <i2cdev>\n", argv[0]);

	fd = open(argv[1], O_RDWR);
	if (fd == -1)
		printf("couldn't open %s", argv[1]);

    // Read
	iie.iie_op = I2C_OP_READ;
	iie.iie_addr = 0x11;
	iie.iie_cmd = NULL;
	iie.iie_cmdlen = 0;
	iie.iie_buf = dataBuf;
	iie.iie_buflen = 2;

	if (ioctl(fd, I2C_IOCTL_EXEC, &iie) == -1)
        perror("ioctl READ ");
        printf("ioctl READ Success %02x:%02x\n", dataBuf[0], dataBuf[1]);






State-Changed-From-To: open->feedback
State-Changed-When: Tue, 30 Aug 2022 09:58:43 +0000
Almost certainly fixed with
revision 1.5
date: 2015-01-24 00:27:31 +0000;  author: jakllsch;  state: Exp;  lines: +6 -2;  commitid: SrO2cxtsvt0I5d7y;
branches:  1.5.10;
If doing a read-only (that is, no initial command write phase) transfer,
do not send a 0-byte write to the device before performing data phase.


NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: gnats-precook-prs,v 1.4 2018/12/21 14:20:20 maya Exp $
$NetBSD:,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.