From patchwork Thu Aug 4 13:38:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sylwester Nawrocki/Kernel \\(PLT\\) /SRPOL/Staff Engineer/Samsung Electronics" X-Patchwork-Id: 9263671 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D822D60839 for ; Thu, 4 Aug 2016 13:41:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8DD728406 for ; Thu, 4 Aug 2016 13:41:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD9CB2840C; Thu, 4 Aug 2016 13:41:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3B43128407 for ; Thu, 4 Aug 2016 13:41:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bVIsX-0005m0-LN; Thu, 04 Aug 2016 13:40:05 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bVIsA-0005ak-0C for linux-arm-kernel@lists.infradead.org; Thu, 04 Aug 2016 13:39:43 +0000 Received: from epcpsbgm1new.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OBE013KD0GKDQE0@mailout3.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 04 Aug 2016 22:39:20 +0900 (KST) X-AuditID: cbfee61a-f78ff6d000001462-6e-57a34587a147 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1new.samsung.com (EPCPMTA) with SMTP id A1.E8.05218.78543A75; Thu, 4 Aug 2016 22:39:20 +0900 (KST) Received: from AMDC1344.digital.local ([106.116.147.32]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OBE000Y20L4R530@mmp1.samsung.com>; Thu, 04 Aug 2016 22:39:19 +0900 (KST) From: Sylwester Nawrocki To: broonie@kernel.org Subject: [PATCH 1/8] ASoC: L3 bus: Add default gpio ops Date: Thu, 04 Aug 2016 15:38:41 +0200 Message-id: <1470317928-25365-2-git-send-email-s.nawrocki@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1470317928-25365-1-git-send-email-s.nawrocki@samsung.com> References: <1470317928-25365-1-git-send-email-s.nawrocki@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprKLMWRmVeSWpSXmKPExsVy+t9jAd0O18XhBlOuMVlcuXiIyWLjjPWs FlMfPmGzOH9+A7vFpsfXWC1mnN/HZHH4TTurA7vHhs9NbB6bVnWyeWxeUu/Rt2UVo8fnTXIB rFFcNimpOZllqUX6dglcGd/ezmYp+CdfMeHHZZYGxs+SXYycHBICJhKzLi5gh7DFJC7cW8/W xcjFISSwlFHixOyTrBDOL0aJb68msoFUsQkYSvQe7WMEsUWAOm7P6WQGsZkFjjBK7F0LNklY wFziT2sHmM0ioCqx5tosJhCbV8BN4uHLP8wQ2+QkTh6bDLSAg4NTwF3ixRYPkLAQUMnXV8dY JzDyLmBkWMUokVqQXFCclJ5rmJdarlecmFtcmpeul5yfu4kRHFjPpHYwHtzlfohRgINRiYf3 gumicCHWxLLiytxDjBIczEoivL+dFocL8aYkVlalFuXHF5XmpBYfYpTmYFES5338f12YkEB6 YklqdmpqQWoRTJaJg1OqgdHxZOHV19v0prS65h0yPi1Uuf0sk8Gxp0pfvjIUn/18Np7vnZ5D SkAOj4PNk8Jrn2++mZreOOe3/bz0lOjbS+RnM/ddW648dY17T/oNvXCH46XWmTMnztpnYPHj /95blx9a9P18dIw3iP1Mrk+SR1mWg9x0+ydXm32dTwSmeFv7n2HUevVk0wIlluKMREMt5qLi RAB92W52KAIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160804_063942_228369_7F4D1A78 X-CRM114-Status: GOOD ( 13.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, linux-samsung-soc@vger.kernel.org, b.zolnierkie@samsung.com, krzk@kernel.org, Sylwester Nawrocki , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This adds aptional GPIO bit-bang based callback implementations for setting CLK, DATA and MODE L3 bus lines. It is added here to avoid possible duplicate implementations across users of the bus. Signed-off-by: Sylwester Nawrocki --- include/sound/l3.h | 15 ++++++++--- sound/soc/codecs/l3.c | 71 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/include/sound/l3.h b/include/sound/l3.h index 423a08f..1471da2 100644 --- a/include/sound/l3.h +++ b/include/sound/l3.h @@ -2,9 +2,15 @@ #define _L3_H_ 1 struct l3_pins { - void (*setdat)(int); - void (*setclk)(int); - void (*setmode)(int); + void (*setdat)(struct l3_pins *, int); + void (*setclk)(struct l3_pins *, int); + void (*setmode)(struct l3_pins *, int); + + int gpio_data; + int gpio_clk; + int gpio_mode; + int use_gpios; + int data_hold; int data_setup; int clock_high; @@ -13,6 +19,9 @@ struct l3_pins { int mode_setup; }; +struct device; + int l3_write(struct l3_pins *adap, u8 addr, u8 *data, int len); +int l3_set_gpio_ops(struct device *dev, struct l3_pins *adap); #endif diff --git a/sound/soc/codecs/l3.c b/sound/soc/codecs/l3.c index 5353af5..a10ea3c 100644 --- a/sound/soc/codecs/l3.c +++ b/sound/soc/codecs/l3.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include @@ -32,11 +34,11 @@ static void sendbyte(struct l3_pins *adap, unsigned int byte) int i; for (i = 0; i < 8; i++) { - adap->setclk(0); + adap->setclk(adap, 0); udelay(adap->data_hold); - adap->setdat(byte & 1); + adap->setdat(adap, byte & 1); udelay(adap->data_setup); - adap->setclk(1); + adap->setclk(adap, 1); udelay(adap->clock_high); byte >>= 1; } @@ -55,10 +57,10 @@ static void sendbytes(struct l3_pins *adap, const u8 *buf, for (i = 0; i < len; i++) { if (i) { udelay(adap->mode_hold); - adap->setmode(0); + adap->setmode(adap, 0); udelay(adap->mode); } - adap->setmode(1); + adap->setmode(adap, 1); udelay(adap->mode_setup); sendbyte(adap, buf[i]); } @@ -66,26 +68,71 @@ static void sendbytes(struct l3_pins *adap, const u8 *buf, int l3_write(struct l3_pins *adap, u8 addr, u8 *data, int len) { - adap->setclk(1); - adap->setdat(1); - adap->setmode(1); + adap->setclk(adap, 1); + adap->setdat(adap, 1); + adap->setmode(adap, 1); udelay(adap->mode); - adap->setmode(0); + adap->setmode(adap, 0); udelay(adap->mode_setup); sendbyte(adap, addr); udelay(adap->mode_hold); sendbytes(adap, data, len); - adap->setclk(1); - adap->setdat(1); - adap->setmode(0); + adap->setclk(adap, 1); + adap->setdat(adap, 1); + adap->setmode(adap, 0); return len; } EXPORT_SYMBOL_GPL(l3_write); + +static void l3_set_clk(struct l3_pins *adap, int val) +{ + gpio_set_value(adap->gpio_clk, val); +} + +static void l3_set_data(struct l3_pins *adap, int val) +{ + gpio_set_value(adap->gpio_data, val); +} + +static void l3_set_mode(struct l3_pins *adap, int val) +{ + gpio_set_value(adap->gpio_mode, val); +} + +int l3_set_gpio_ops(struct device *dev, struct l3_pins *adap) +{ + int ret; + + if (!adap->use_gpios) + return -EINVAL; + + ret = devm_gpio_request_one(dev, adap->gpio_data, + GPIOF_OUT_INIT_LOW, "l3_data"); + if (ret < 0) + return ret; + adap->setdat = l3_set_data; + + ret = devm_gpio_request_one(dev, adap->gpio_clk, + GPIOF_OUT_INIT_LOW, "l3_clk"); + if (ret < 0) + return ret; + adap->setclk = l3_set_clk; + + ret = devm_gpio_request_one(dev, adap->gpio_mode, + GPIOF_OUT_INIT_LOW, "l3_mode"); + if (ret < 0) + return ret; + adap->setmode = l3_set_mode; + + return 0; +} +EXPORT_SYMBOL_GPL(l3_set_gpio_ops); + MODULE_DESCRIPTION("L3 bit-banging driver"); MODULE_AUTHOR("Christian Pellegrin "); MODULE_LICENSE("GPL");