Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752498AbdDNCW7 (ORCPT ); Thu, 13 Apr 2017 22:22:59 -0400 Received: from mail-sn1nam02on0134.outbound.protection.outlook.com ([104.47.36.134]:5166 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751473AbdDNCW4 (ORCPT ); Thu, 13 Apr 2017 22:22:56 -0400 Authentication-Results: spf=pass (sender IP is 117.103.190.44) smtp.mailfrom=sony.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=sony.com; From: To: , , CC: , , Yasunari Takiguchi , Masayuki Yamamoto , Hideki Nozawa , "Kota Yonezawa" , Toshihiko Matsumoto , Satoshi Watanabe Subject: [PATCH v2 05/15] [media] cxd2880: Add spi device IO routines Date: Fri, 14 Apr 2017 11:25:23 +0900 Message-ID: <20170414022523.17417-1-Yasunari.Takiguchi@sony.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170414015043.16731-1-Yasunari.Takiguchi@sony.com> References: <20170414015043.16731-1-Yasunari.Takiguchi@sony.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [43.25.42.176] X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:117.103.190.44;IPV:NLI;CTRY:JP;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(39410400002)(39400400002)(39850400002)(39860400002)(39840400002)(39450400003)(2980300002)(438002)(199003)(189002)(4326008)(189998001)(6116002)(3846002)(5003940100001)(76176999)(1076002)(2201001)(39060400002)(356003)(2950100002)(6306002)(86152003)(6666003)(54906002)(7736002)(107886003)(305945005)(38730400002)(36756003)(50986999)(575784001)(7636002)(86362001)(5660300001)(48376002)(47776003)(8676002)(50466002)(106466001)(50226002)(2906002)(8936002)(49486002)(2876002)(66066001)(2004002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR13MB1471;H:JPYOKXEG104.jp.sony.com;FPR:;SPF:Pass;MLV:ovrnspm;A:1;MX:1;PTR:jpyokxeg104.jp.sony.com;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;SN1NAM02FT051;1:kYDAEjSIufHSvqvz3k+1GnzR3ruKFHdn4vK+qeMtarvYDqUfsegxTJsM5QVHCKJsCwsRUp/qvDdw+GJmpXp/6SEhxLDdtKEuVl93FLhs8P34akaeO4pqEC+nJPEDxKk0uUBGScrabQhTr10jRYFYtFlukUZVAb/kY5iLvS270iWBjNXMDYypNsR9pl/+8r/MiAziGbFtignEjD0En6jxwRnt4CcrrhjYiviXE5gtSWb7CjO0o5f9NQw3fHc8RHh0tzBbPzuE41fUzIX5vVMNmAwz/9G71jXAbvA19fjY/FFBdDTNOi0MnnZmx0yQtMKmdLT8yfVsuu5ZMvG7CDfiCSDIxqWoBPlGlcB/5sbHNjE1C3APOR7SzMR6uD8axWY7TZmbIOG9QHejmytAtf58maZksf+RFi+c4gMCYD8aoV+SjJMxbwPgsdpHbWihptvfgmw4oKkussU6tvKQ/K/vVC05C89e+JivRQUtqw/hDcpWIoxMAem+u9dP5QtagD0dacEoP1LnI2LtPkGbVFltmbRHKnS4c+C3ET2Rv0k6aOLRevoChOA6zKacXDyuPC6l X-MS-Office365-Filtering-Correlation-Id: a61d3f92-ea66-496f-d341-08d482dd280a X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(8251501002)(2017030254075)(201703131423075)(201703031133081)(201702281549075);SRVR:MWHPR13MB1471; X-Microsoft-Exchange-Diagnostics: 1;MWHPR13MB1471;3:kEMi3xvyEx/vq0tSm1K7YpggfP8OgwPjoHeuRtd8A9s6Q4PqAueyZ8bywWkczc3GEfkvB2wnc6Y2B1N5sBoV3/mN44HdZ4GsZdbR3apWU+BMo1dGAr3CrL6c5oLLXF33pDwSsrn/prKACdvc5BQ197E2VRnh3TppSQL5Al5jfGyfiuUmo2iTm5iBk8InfnBW6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IVBnNFFIWs82pTpI4aEINzQ90rqmz6cw6rqhAlsGkdETOTCMtNnYTi7cTICjwy6YwQ== X-Microsoft-Exchange-Diagnostics: 1;MWHPR13MB1471;20:yKiq7IkuVBnMzPkF/zQXEzEJlismKfyTlywc1vln4uWN+muaTLK/8D5w6QfeV5zrIrRRMj2FIyUuB47MopjFIIPwk8iucH+oezbStScMInXl8rCcwCM8kYLkVCxfIJ+NZtA5AI18U/Y3zlJVpog8d5+5Vxy9VLBaPKLrFaM2RHSudbFvfwbYaZ0QUbi+QyhQVmLNDmuC7fetSvZ8shnBouEWfHpJYWdNkhSiV4TGl7e+g4UwQjXWLXMG2ir6lmVo7YloDn1D73abIqeDy0bOwArHZuSwWNQ+A7QcW+n0C2j3KjeLZ4ZnYSHFcM2jXtZseH48YBNH79sg4rR9Japl3b2/fqFjksJin5MwpCoggYkTOnFAc1zreVjPOC8/36Zx0IscjMSV339sAiegclmlTBTdoZlC3Yf5as10zGmE8fj+dVBKlJOcTR8lIeCAJ/hI09sJ9DG3hyAbfk3dmPjfyCiqxUmdnTAmABgQvkc1Sc2+ABfZkxm16kZh/YYY05TB X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(182409339516656)(22074186197030); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(13018025)(8121501046)(13015025)(5005006)(13017025)(13024025)(13023025)(93006095)(93004095)(3002001)(10201501046)(6055026)(6041248)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(20161123564025)(20161123562025)(20161123555025)(6072148);SRVR:MWHPR13MB1471;BCL:0;PCL:0;RULEID:;SRVR:MWHPR13MB1471; X-Microsoft-Exchange-Diagnostics: 1;MWHPR13MB1471;4:mA5zWsRGW8LSy//GRd5S4jkZdbIOt+qaL3mcsURwIC6bOvefzlReEBNzJ2q6lEW6CnXHRlZNZfbeeisKmEsTe+OWs+lX5QA44E85QNH44OG8jhWikcRnjAfJS1gXW7U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yIosdLL8f1/m6jKy88/LN6n6HPCIHSIWR+2JfTmcive0?= =?us-ascii?Q?S+VJgO0yTyWquCBMPbQYJHcA0p5ONPG7tPVKpwatz62EgfoiEx63TXFEmw7m?= =?us-ascii?Q?EORloD3ye+JUEPAIWmfROaEcckd9b73KUvUZ/bHRrA8DhAs4dCondh7NLs+Z?= =?us-ascii?Q?aTgXEtHOpZwty8=3D?= X-Microsoft-Exchange-Diagnostics: 1;MWHPR13MB1471;6:rC9QKZRq4WGS9Cx7THzK9nIlzKIo9tPpw1XL/9r5+MQwd/IUdu9xiZqMYR0dEyvCUnUvqoLZuVpHlw9XgIH85NE4Xy5ebPYK47TIw1L+3l/5iKbd3wYbcoVx320AIVjUbokEM7xhqne19t4FNWWjSNzY83j+ddfNBi7jkSVUazFXrjD3BpR5klU3KAL20Da8qCEC0Wofdeuw5Fq7uKxIoqj0ApZNGkfUER6y5ktFAV+ll9UzyH+SgT/1zI462hsoP060OyK0zEP3W2oW89zn70HTlDkogDbZ/fLKkv3+ER3WC7LsUjmpK5HC5PvV29VaR2pN9vkluyL+OSR9yJLbTR06tsQGQAx9zWzcqhe+NpozyUEL/PKRFy2qTVCxtigznbNjf6ye+siACy+7OknPGTQh3Wk2I+hN/4DdvlWAV/KQU8BrtstayBuNZMEodJGs1kK6DK1BtjM1hnF6lDRKHHMzvs/VGggx8dUwURpzfsE=;5:45H6IJRmqPljLAdCEvcAUTcDEoM+cQmoHD2dcgSg8WpaMxPJKsrAoRiWLjJ33nHbg6zbWFCF9pmT1lLMOG4n9YUrfx/TqfuWNmlYW9rNPn0CvMT0pG36eU5rDMMxIJK3FMWRaFkJEZhJQFsDyBtenlk2qqY0h61I/YASrVlilnM=;24:BYPlU18zSv+yCAo4gLZCBa+dilb0UOsYV1XxeA8dVc9I41/Y6n1OlacivrWZGQVbaPGwQjsVYwc3kFR7xsJkgGD63o1ikq7VxIPtKxd8Hm0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR13MB1471;7:WrAmvMrLc9cCUCAR6YxcEReKLjszdNGbKGAKHQBau2qCMAI/4vtmzG8HnHIQMD1MzaPMiugaznWkOOrqunwCrbuVig3IhpIGZVePKU4XM3IOGRNbHDQ+OhDV9L+M7bbyS7JHQ5EloGzaG+M+Tu7jSsU8ELt53j0MX3uFvJmcHCvBmR3tDJjUrbKw+fKsywWNdU98t5UKhQnib8EEjpd6HjqueudGQ4009QWIWJAqc2H6mDw6pjPASqRXZqKTNDTbySfHkz31vcCNt7VGkmyj65zOf7taLsjbA1BzL/UtamckKbMKjdo4lDtqpfxfoMnGKrwG1A7KLCMsYGxOWDr+kw== X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2017 02:22:53.2420 (UTC) X-MS-Exchange-CrossTenant-Id: 66c65d8a-9158-4521-a2d8-664963db48e4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=66c65d8a-9158-4521-a2d8-664963db48e4;Ip=[117.103.190.44];Helo=[JPYOKXEG104.jp.sony.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR13MB1471 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 15726 Lines: 469 From: Yasunari Takiguchi Add functions for initializing, reading and writing to the SPI device for the Sony CXD2880 DVB-T2/T tuner + demodulator. Signed-off-by: Yasunari Takiguchi Signed-off-by: Masayuki Yamamoto Signed-off-by: Hideki Nozawa Signed-off-by: Kota Yonezawa Signed-off-by: Toshihiko Matsumoto Signed-off-by: Satoshi Watanabe --- .../dvb-frontends/cxd2880/cxd2880_devio_spi.c | 147 +++++++++++++++++++++ .../dvb-frontends/cxd2880/cxd2880_devio_spi.h | 40 ++++++ drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h | 51 +++++++ .../dvb-frontends/cxd2880/cxd2880_spi_device.c | 130 ++++++++++++++++++ .../dvb-frontends/cxd2880/cxd2880_spi_device.h | 45 +++++++ 5 files changed, 413 insertions(+) create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c b/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c new file mode 100644 index 000000000000..516efade6bf5 --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.c @@ -0,0 +1,147 @@ +/* + * cxd2880_devio_spi.c + * Sony CXD2880 DVB-T2/T tuner + demodulator driver + * I/O interface via SPI + * + * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; version 2 of the License. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#include "cxd2880_devio_spi.h" +#include "cxd2880_stdlib.h" + +#define BURST_WRITE_MAX 128 + +static enum cxd2880_ret cxd2880_io_spi_read_reg(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + u8 sub_address, u8 *data, + u32 size) +{ + enum cxd2880_ret ret = CXD2880_RESULT_OK; + struct cxd2880_spi *spi = NULL; + u8 send_data[6]; + u8 *read_data_top = data; + + if ((!io) || (!io->if_object) || (!data)) + return CXD2880_RESULT_ERROR_ARG; + + if (sub_address + size > 0x100) + return CXD2880_RESULT_ERROR_RANGE; + + spi = (struct cxd2880_spi *)(io->if_object); + + if (tgt == CXD2880_IO_TGT_SYS) + send_data[0] = 0x0B; + else + send_data[0] = 0x0A; + + send_data[3] = 0; + send_data[4] = 0; + send_data[5] = 0; + + while (size > 0) { + send_data[1] = sub_address; + if (size > 255) + send_data[2] = 255; + else + send_data[2] = (u8)size; + + ret = + spi->write_read(spi, send_data, sizeof(send_data), + read_data_top, send_data[2]); + if (ret != CXD2880_RESULT_OK) + return ret; + + sub_address += send_data[2]; + read_data_top += send_data[2]; + size -= send_data[2]; + } + + return ret; +} + +static enum cxd2880_ret cxd2880_io_spi_write_reg(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + u8 sub_address, + const u8 *data, u32 size) +{ + enum cxd2880_ret ret = CXD2880_RESULT_OK; + struct cxd2880_spi *spi = NULL; + u8 send_data[BURST_WRITE_MAX + 4]; + const u8 *write_data_top = data; + + if ((!io) || (!io->if_object) || (!data)) + return CXD2880_RESULT_ERROR_ARG; + + if (size > BURST_WRITE_MAX) + return CXD2880_RESULT_ERROR_OVERFLOW; + + if (sub_address + size > 0x100) + return CXD2880_RESULT_ERROR_RANGE; + + spi = (struct cxd2880_spi *)(io->if_object); + + if (tgt == CXD2880_IO_TGT_SYS) + send_data[0] = 0x0F; + else + send_data[0] = 0x0E; + + while (size > 0) { + send_data[1] = sub_address; + if (size > 255) + send_data[2] = 255; + else + send_data[2] = (u8)size; + + cxd2880_memcpy(&send_data[3], write_data_top, send_data[2]); + + if (tgt == CXD2880_IO_TGT_SYS) { + send_data[3 + send_data[2]] = 0x00; + ret = spi->write(spi, send_data, send_data[2] + 4); + } else { + ret = spi->write(spi, send_data, send_data[2] + 3); + } + if (ret != CXD2880_RESULT_OK) + return ret; + + sub_address += send_data[2]; + write_data_top += send_data[2]; + size -= send_data[2]; + } + + return ret; +} + +enum cxd2880_ret cxd2880_io_spi_create(struct cxd2880_io *io, + struct cxd2880_spi *spi, u8 slave_select) +{ + if ((!io) || (!spi)) + return CXD2880_RESULT_ERROR_ARG; + + io->read_regs = cxd2880_io_spi_read_reg; + io->write_regs = cxd2880_io_spi_write_reg; + io->write_reg = cxd2880_io_common_write_one_reg; + io->if_object = spi; + io->i2c_address_sys = 0; + io->i2c_address_demod = 0; + io->slave_select = slave_select; + + return CXD2880_RESULT_OK; +} diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h b/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h new file mode 100644 index 000000000000..15934bf11935 --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_devio_spi.h @@ -0,0 +1,40 @@ +/* + * cxd2880_devio_spi.h + * Sony CXD2880 DVB-T2/T tuner + demodulator driver + * I/O interface via SPI + * + * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; version 2 of the License. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#ifndef CXD2880_DEVIO_SPI_H +#define CXD2880_DEVIO_SPI_H + +#include "cxd2880_common.h" +#include "cxd2880_io.h" +#include "cxd2880_spi.h" + +#include "cxd2880_tnrdmd.h" + +enum cxd2880_ret cxd2880_io_spi_create(struct cxd2880_io *io, + struct cxd2880_spi *spi, + u8 slave_select); + +#endif diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h b/drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h new file mode 100644 index 000000000000..81e5be747962 --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_spi.h @@ -0,0 +1,51 @@ +/* + * cxd2880_spi.h + * Sony CXD2880 DVB-T2/T tuner + demodulator driver + * SPI access definitions + * + * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; version 2 of the License. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#ifndef CXD2880_SPI_H +#define CXD2880_SPI_H + +#include "cxd2880_common.h" + +enum cxd2880_spi_mode { + CXD2880_SPI_MODE_0, + CXD2880_SPI_MODE_1, + CXD2880_SPI_MODE_2, + CXD2880_SPI_MODE_3 +}; + +struct cxd2880_spi { + enum cxd2880_ret (*read)(struct cxd2880_spi *spi, u8 *data, + u32 size); + enum cxd2880_ret (*write)(struct cxd2880_spi *spi, const u8 *data, + u32 size); + enum cxd2880_ret (*write_read)(struct cxd2880_spi *spi, + const u8 *tx_data, u32 tx_size, + u8 *rx_data, u32 rx_size); + u32 flags; + void *user; +}; + +#endif diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c b/drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c new file mode 100644 index 000000000000..af9ed40c900b --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.c @@ -0,0 +1,130 @@ +/* + * cxd2880_spi_device.c + * Sony CXD2880 DVB-T2/T tuner + demodulator driver + * SPI access functions + * + * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; version 2 of the License. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#include + +#include "cxd2880_spi_device.h" + +static enum cxd2880_ret cxd2880_spi_device_write(struct cxd2880_spi *spi, + const u8 *data, u32 size) +{ + struct cxd2880_spi_device *spi_device = NULL; + struct spi_message msg; + struct spi_transfer tx; + int result = 0; + + if ((!spi) || (!spi->user) || (!data) || (size == 0)) + return CXD2880_RESULT_ERROR_ARG; + + spi_device = (struct cxd2880_spi_device *)(spi->user); + + memset(&tx, 0, sizeof(tx)); + tx.tx_buf = data; + tx.len = size; + + spi_message_init(&msg); + spi_message_add_tail(&tx, &msg); + result = spi_sync(spi_device->spi, &msg); + + if (result < 0) + return CXD2880_RESULT_ERROR_IO; + + return CXD2880_RESULT_OK; +} + +static enum cxd2880_ret cxd2880_spi_device_write_read(struct cxd2880_spi *spi, + const u8 *tx_data, + u32 tx_size, + u8 *rx_data, + u32 rx_size) +{ + struct cxd2880_spi_device *spi_device = NULL; + int result = 0; + + if ((!spi) || (!spi->user) || (!tx_data) || + (tx_size == 0) || (!rx_data) || (rx_size == 0)) + return CXD2880_RESULT_ERROR_ARG; + + spi_device = (struct cxd2880_spi_device *)(spi->user); + + result = spi_write_then_read(spi_device->spi, tx_data, + tx_size, rx_data, rx_size); + if (result < 0) + return CXD2880_RESULT_ERROR_IO; + + return CXD2880_RESULT_OK; +} + +enum cxd2880_ret +cxd2880_spi_device_initialize(struct cxd2880_spi_device *spi_device, + enum cxd2880_spi_mode mode, + u32 speed_hz) +{ + int result = 0; + struct spi_device *spi = spi_device->spi; + + switch (mode) { + case CXD2880_SPI_MODE_0: + spi->mode = SPI_MODE_0; + break; + case CXD2880_SPI_MODE_1: + spi->mode = SPI_MODE_1; + break; + case CXD2880_SPI_MODE_2: + spi->mode = SPI_MODE_2; + break; + case CXD2880_SPI_MODE_3: + spi->mode = SPI_MODE_3; + break; + default: + return CXD2880_RESULT_ERROR_ARG; + } + + spi->max_speed_hz = speed_hz; + spi->bits_per_word = 8; + result = spi_setup(spi); + if (result != 0) { + pr_err("spi_setup failed %d\n", result); + return CXD2880_RESULT_ERROR_ARG; + } + + return CXD2880_RESULT_OK; +} + +enum cxd2880_ret cxd2880_spi_device_create_spi(struct cxd2880_spi *spi, + struct cxd2880_spi_device *spi_device) +{ + if ((!spi) || (!spi_device)) + return CXD2880_RESULT_ERROR_ARG; + + spi->read = NULL; + spi->write = cxd2880_spi_device_write; + spi->write_read = cxd2880_spi_device_write_read; + spi->flags = 0; + spi->user = spi_device; + + return CXD2880_RESULT_OK; +} diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h b/drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h new file mode 100644 index 000000000000..343d9161d537 --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_spi_device.h @@ -0,0 +1,45 @@ +/* + * cxd2880_spi_device.h + * Sony CXD2880 DVB-T2/T tuner + demodulator driver + * SPI access interface + * + * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; version 2 of the License. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#ifndef CXD2880_SPI_DEVICE_H +#define CXD2880_SPI_DEVICE_H + +#include "cxd2880_spi.h" + +struct cxd2880_spi_device { + struct spi_device *spi; +}; + +enum cxd2880_ret +cxd2880_spi_device_initialize(struct cxd2880_spi_device *spi_device, + enum cxd2880_spi_mode mode, + u32 speedHz); + +enum cxd2880_ret +cxd2880_spi_device_create_spi(struct cxd2880_spi *spi, + struct cxd2880_spi_device *spi_device); + +#endif /* CXD2880_SPI_DEVICE_H */ -- 2.11.0