summaryrefslogtreecommitdiffstats
path: root/libopenbmc_intf
diff options
context:
space:
mode:
authorYong Li <yong.b.li@linux.intel.com>2017-11-17 14:34:18 +0800
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-12-04 22:08:21 +0000
commit86101ea3548ef0e185d77b61a7a1712015bd2bde (patch)
tree43c2bf17b0aac44441cb19a23f5906f1f66f1d4a /libopenbmc_intf
parent8102f929622362b7c0f2a8b7619f299f88755daa (diff)
downloadtalos-skeleton-86101ea3548ef0e185d77b61a7a1712015bd2bde.tar.gz
talos-skeleton-86101ea3548ef0e185d77b61a7a1712015bd2bde.zip
Add lseek to support GPIO read/write
GPIO api does not support repeat read(read multi times after one open). A workaround is close and reopen the device before the second read. The root cause is that the file descriptor is not moved to beginning of the file, this patch can fix this issue Change-Id: I40e5602669c9ab6f0dddf5aa77040466cbfa3738 Signed-off-by: Yong Li <yong.b.li@linux.intel.com>
Diffstat (limited to 'libopenbmc_intf')
-rw-r--r--libopenbmc_intf/gpio.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/libopenbmc_intf/gpio.c b/libopenbmc_intf/gpio.c
index 0dfb260..291f9c3 100644
--- a/libopenbmc_intf/gpio.c
+++ b/libopenbmc_intf/gpio.c
@@ -19,6 +19,12 @@ int gpio_writec(GPIO* gpio, char value)
int rc = GPIO_OK;
char buf[1];
buf[0] = value;
+
+ if (lseek(gpio->fd, 0, SEEK_SET) == -1)
+ {
+ return GPIO_ERROR;
+ }
+
if (write(gpio->fd, buf, 1) != 1)
{
rc = GPIO_WRITE_ERROR;
@@ -36,6 +42,12 @@ int gpio_write(GPIO* gpio, uint8_t value)
{
buf[0]='1';
}
+
+ if (lseek(gpio->fd, 0, SEEK_SET) == -1)
+ {
+ return GPIO_ERROR;
+ }
+
if (write(gpio->fd, buf, 1) != 1)
{
rc = GPIO_WRITE_ERROR;
@@ -54,6 +66,11 @@ int gpio_read(GPIO* gpio, uint8_t *value)
}
else
{
+ if (lseek(gpio->fd, 0, SEEK_SET) == -1)
+ {
+ return GPIO_ERROR;
+ }
+
if (read(gpio->fd,&buf,1) != 1)
{
r = GPIO_READ_ERROR;
OpenPOWER on IntegriCloud