From patchwork Wed Apr 7 16:04:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 91059 X-Patchwork-Delegate: tony@atomide.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o37G53D0005429 for ; Wed, 7 Apr 2010 16:05:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932614Ab0DGQFA (ORCPT ); Wed, 7 Apr 2010 12:05:00 -0400 Received: from smtp.nokia.com ([192.100.122.230]:58415 "EHLO mgw-mx03.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932570Ab0DGQE7 (ORCPT ); Wed, 7 Apr 2010 12:04:59 -0400 Received: from esebh105.NOE.Nokia.com (esebh105.ntc.nokia.com [172.21.138.211]) by mgw-mx03.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o37G4kbv004699 for ; Wed, 7 Apr 2010 19:04:57 +0300 Received: from esebh102.NOE.Nokia.com ([172.21.138.183]) by esebh105.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 7 Apr 2010 19:04:54 +0300 Received: from mgw-da02.ext.nokia.com ([147.243.128.26]) by esebh102.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Wed, 7 Apr 2010 19:04:53 +0300 Received: from localhost.localdomain (esdhcp04088.research.nokia.com [172.21.40.88]) by mgw-da02.ext.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o37G4YMt015130; Wed, 7 Apr 2010 19:04:49 +0300 From: felipe.balbi@nokia.com To: Linux OMAP Mailing List Cc: Felipe Balbi Subject: [RFC PATCH 11/37] cbus: handle possible errors on cbus_send/receive_bit Date: Wed, 7 Apr 2010 19:04:02 +0300 Message-Id: <1270656268-7034-12-git-send-email-felipe.balbi@nokia.com> X-Mailer: git-send-email 1.7.0.rc0.33.g7c3932 In-Reply-To: <1270656268-7034-1-git-send-email-felipe.balbi@nokia.com> References: <1270656268-7034-1-git-send-email-felipe.balbi@nokia.com> X-OriginalArrivalTime: 07 Apr 2010 16:04:53.0937 (UTC) FILETIME=[0F8FBA10:01CAD66C] X-Nokia-AV: Clean Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 07 Apr 2010 16:05:05 +0000 (UTC) diff --git a/drivers/cbus/cbus.c b/drivers/cbus/cbus.c index 285bf23..0791251 100644 --- a/drivers/cbus/cbus.c +++ b/drivers/cbus/cbus.c @@ -47,35 +47,44 @@ struct cbus_host { /* host lock */ - spinlock_t lock; + spinlock_t lock; - int clk_gpio; - int dat_gpio; - int sel_gpio; + struct device *dev; + + int clk_gpio; + int dat_gpio; + int sel_gpio; }; static struct cbus_host *cbus_host; -static void cbus_send_bit(struct cbus_host *host, int bit, int set_to_input) +static int cbus_send_bit(struct cbus_host *host, int bit, int set_to_input) { + int ret = 0; + gpio_set_value(host->dat_gpio, bit ? 1 : 0); gpio_set_value(host->clk_gpio, 1); /* The data bit is read on the rising edge of CLK */ if (set_to_input) - gpio_direction_input(host->dat_gpio); + ret = gpio_direction_input(host->dat_gpio); gpio_set_value(host->clk_gpio, 0); + + return ret; } -static u8 cbus_receive_bit(struct cbus_host *host) +static int cbus_receive_bit(struct cbus_host *host) { - u8 ret; + int ret; gpio_set_value(host->clk_gpio, 1); ret = gpio_get_value(host->dat_gpio); + if (ret < 0) + goto out; gpio_set_value(host->clk_gpio, 0); +out: return ret; } @@ -83,6 +92,7 @@ static int cbus_transfer(struct cbus_host *host, unsigned rw, unsigned dev, unsigned reg, unsigned data) { unsigned long flags; + int ret = 0; int i; /* We don't want interrupts disturbing our transfer */ @@ -95,11 +105,20 @@ static int cbus_transfer(struct cbus_host *host, unsigned rw, unsigned dev, gpio_direction_output(host->dat_gpio, 1); /* Send the device address */ - for (i = 3; i > 0; i--) - cbus_send_bit(host, dev & (1 << (i - 1)), 0); + for (i = 3; i > 0; i--) { + ret = cbus_send_bit(host, dev & (1 << (i - 1)), 0); + if (ret < 0) { + dev_dbg(host->dev, "failed sending device addr\n"); + goto out; + } + } /* Send the rw flag */ - cbus_send_bit(host, rw, 0); + ret = cbus_send_bit(host, rw, 0); + if (ret < 0) { + dev_dbg(host->dev, "failed sending read/write flag\n"); + goto out; + } /* Send the register address */ for (i = 5; i > 0; i--) { @@ -108,21 +127,38 @@ static int cbus_transfer(struct cbus_host *host, unsigned rw, unsigned dev, if (rw && i == 1) set_to_input = 1; - cbus_send_bit(host, reg & (1 << (i - 1)), set_to_input); + ret = cbus_send_bit(host, reg & (1 << (i - 1)), set_to_input); + if (ret < 0) { + dev_dbg(host->dev, "failed sending register addr\n"); + goto out; + } } if (!rw) { - for (i = 16; i > 0; i--) - cbus_send_bit(host, data & (1 << (i - 1)), 0); + for (i = 16; i > 0; i--) { + ret = cbus_send_bit(host, data & (1 << (i - 1)), 0); + if (ret < 0) { + dev_dbg(host->dev, "failed sending data\n"); + goto out; + } + } } else { gpio_set_value(host->clk_gpio, 1); for (i = 16; i > 0; i--) { u8 bit = cbus_receive_bit(host); + if (bit < 0) { + dev_dbg(host->dev, "failed receiving data\n"); + goto out; + } + if (bit) data |= 1 << (i - 1); } + + /* return the data received */ + ret = data; } /* Indicate end of transfer, SEL goes up until next transfer */ @@ -130,9 +166,10 @@ static int cbus_transfer(struct cbus_host *host, unsigned rw, unsigned dev, gpio_set_value(host->clk_gpio, 1); gpio_set_value(host->clk_gpio, 0); +out: spin_unlock_irqrestore(&host->lock, flags); - return data; + return ret; } /* @@ -168,6 +205,7 @@ static int __init cbus_bus_probe(struct platform_device *pdev) chost->clk_gpio = pdata->clk_gpio; chost->dat_gpio = pdata->dat_gpio; chost->sel_gpio = pdata->sel_gpio; + chost->dev = &pdev->dev; ret = gpio_request(chost->clk_gpio, "CBUS clk"); if (ret < 0)