From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755090AbeARInu (ORCPT ); Thu, 18 Jan 2018 03:43:50 -0500 Received: from mail-cys01nam02on0134.outbound.protection.outlook.com ([104.47.37.134]:14796 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754788AbeARInr (ORCPT ); Thu, 18 Jan 2018 03:43:47 -0500 Authentication-Results: spf=pass (sender IP is 117.103.190.43) 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: , , , , , , , Subject: [PATCH v5 03/12] [media] cxd2880: Add common files for the driver Date: Thu, 18 Jan 2018 17:47:38 +0900 Message-ID: <20180118084738.21058-1-Yasunari.Takiguchi@sony.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180118084016.20689-1-Yasunari.Takiguchi@sony.com> References: <20180118084016.20689-1-Yasunari.Takiguchi@sony.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [43.25.41.74] X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:117.103.190.43;IPV:NLI;CTRY:JP;EFV:NLI;SFV:NSPM;SFS:(10019020)(39860400002)(39380400002)(346002)(376002)(396003)(2980300002)(438002)(189003)(199004)(6116002)(5890100001)(956003)(8936002)(50226002)(2950100002)(478600001)(72206003)(1076002)(5660300001)(16526018)(8676002)(48376002)(106466001)(2906002)(356003)(316002)(86152003)(305945005)(59450400001)(246002)(110136005)(66066001)(26005)(36756003)(47776003)(51416003)(4326008)(7736002)(107886003)(2876002)(39060400002)(86362001)(49486002)(76176011)(106002)(54906003)(50466002)(512794004)(2201001)(7636002)(3846002)(16586007);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR1301MB2023;H:jp.sony.com;FPR:;SPF:Pass;PTR:jpyokxeg103.jp.sony.com;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2NAM02FT003;1:ZYOEUf9O8zOJBbDkgekePMUqQraHVMPw2WKI+EMrCrRJj7F0yfccKEpGZLHYe8QLC3tuyyVbBXu4c6dA49Dm6awdq2KOA3wvDwP7HciiqMLk+wSOqDjCNuuw1yBdfM9J X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 05f03225-2241-4410-dfd0-08d55e4f958b X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(4608076)(4534125)(4602075)(4627221)(201703031133081)(201702281549075)(2017052603307)(7193020);SRVR:CY4PR1301MB2023; X-Microsoft-Exchange-Diagnostics: 1;CY4PR1301MB2023;3:CMavJzI7xGe6SyDbCVg5G8Rn8aFwXBRGMev6I78z8ZOpNthy44QgOzVMG6fSrNaDxwBLwy5/XmCMJBveuLXVMvqSn/KVB9Gp8u8PPFo+Eih1eId1WVhk2G+ygrfp7apMJU7NODydRQJoBJv34Md4yO7Mbb33eXj/T5JrTJETGi2tUMfj2e0n9rAMDVnhU3SvAWEKfF2edSoSqFrGi+AYrQYqW92wr7XzEp7FfWMDaYG5yBwilYbGK6JMahJ34ehuDZHnuGaHfzW8IPtbl+kbR3O/KzkAb25nwyGKHlczF4Yf7UAsS40tGOIaaWFPBOPUvXUL8JRQQcRmozFtEVx1az+l4g8Gn31VXX3zN8PVVsg=;25:zpY76jJbgu/V3sOGecObcihcss5f02tGocuWCzg+Ohnpokh6c6AoZrvlV2orkLfamfkcUM+YKkiXDVg5KEPXq/PrrTF83+IKHusPAMjLZRr36bYX5/Gsqbsxed3xCdYQJ90lhVY1iXfFSM+T8Vd/B5QcPg+/b/rVpoMfBSB8EQV7/4auZJAMGG5tiypq0fcTM/jxoKOexqRGWp1V//t5y5pEso4oy3Lx8I7TzCi7w73FS3UYHUBLl85W7rX5YYw6b8KXPFyocLOTtVCq+begjvYy+XKkQO4RFjKZh5AfuWtLne5UTreMIDWlQ2ZBNeiXH8d85AcCHxA8FcEwHjliAA== X-MS-TrafficTypeDiagnostic: CY4PR1301MB2023: X-Microsoft-Exchange-Diagnostics: 1;CY4PR1301MB2023;31:4axE6zet9xlHdqIXg8ByXGfXmYp91pZT+XNAGvT7gzMml+3VFVf9pdLOFOPLgnX2DHOLyJaPuA9pSq/9KEAQhYI8j1196HPMi2JdDbiwGwpFbDh6Nxv9LagiufFtCvv9wVrsHP6BxhOX/JDSriKz8m58NG4u8Qu1G+yGXChT6wuyLJmYY/8AuB0aGcnek1+xQy65whScH4JAhe1/sTFfEYk8YDneh8UI2KrIvxT73es=;20:ne7YKYUUf/obM18cDLbLhYmK+QD/tZs17+mIDAdZkzKkNryYI4eVM6chPz7kSXaus3VkBQ/+H6aISGSAkI9Rgw+zGLY8jRFg6haC0YCdmgSfUQqKmz5GVgTmg/4fLz+catqQDRoU1X1wRix2ifta5OEsrQUh1GvctQwwUbQPfjRLsW10s/7/10a/vFkDPrTKMEGXiQATErjtAHXQ+fTUUM8JwQOc5cWZEh2VcaZLLRmo6HQUlkr7Sk9lNsiqXTtGaebFpmusIpxMd7qpM2YmWf54yLnIIPxQSz2b9O6vo1SmQCXf1qsI7nJR9cz2EFsORLgTx1T3xUj4dX+1vz2d4RJtFcPVPTqAidn932Puifailr7SEP7lWNwxTB7YXrdNvXA39iqV6Af70r3GiBukqoIXMG0zcGU+zrutQBQ9WK+e479NCjBVzOvJPPr50kAIOQSLk8+4vUy95Yju0pedDR9gsR080YXjCIB9QCyuMA8yD1CHoHWXgpmu9GnB20+2 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(182409339516656); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(5005006)(8121501046)(10201501046)(3231023)(11241501184)(944501161)(3002001)(93006095)(93004095)(6055026)(6041268)(20161123564045)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011);SRVR:CY4PR1301MB2023;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:CY4PR1301MB2023; X-Microsoft-Exchange-Diagnostics: 1;CY4PR1301MB2023;4:ZbFnrtJB4j8TswK1B++Pjtu1s84u+Vcq2HBCJ7dAOOX7qpXwqGH4czBpuaNrJCoGI5r7FVjIa1uz+q6X7BXhfdtjLKfi5faO5wY1DaJW5IUJ9Tm79/JB20nqrR/DdF9Z/c5Q7Grkl8ZoAIV5t8BuqP3PdS0y1oViUWfYFR1K7IRfhWgrRrCCdjMBHRFsLVMZXbyIRIkBvd1feyTiaZiv/afncFZnw2XnuCNVkDFh3GE4ZXaxznuXEupCv60+sDEBd/IxwcNGRJJiTdRZBeXV7oeySeLIoUIJDvN8PqcEGQUsAabGmeaaRCFG1zsE/soE X-Forefront-PRVS: 05568D1FF7 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY4PR1301MB2023;23:1fjNy0hci+pcPtmXtNuS4pQMz0HVBIh+4vNVA2W?= =?us-ascii?Q?DXISBEMrO7eHwQBMRnJe0j9XKOI8TBr7F8F5RI9PoXrYO4xKKtGib44CYa0N?= =?us-ascii?Q?4pTo7LSZswednsW5XyyFlyvXses7nhbOUHTjV30PesFJKRAfmlRoAKHqhi6o?= =?us-ascii?Q?gwDtISK27M+Cy+jMQEL68X6NGckxHSJi7/rnm6yUoKEVkuETNsCn5PgawpDi?= =?us-ascii?Q?JmbOJNvPtR388kZaxKJ2HcIuETROX7Z5OLokkK7PqfuqRaH8flBOhSSk/1IQ?= =?us-ascii?Q?Y/LoG49SDVaeP9nWMcq9s+oUsUTVcpzBfkUVX4roxZ1pgkBhF3VSVv6d48M0?= =?us-ascii?Q?3h7EG5KCfkPyeyZl6RcPvYqVlQz7oP+nax1xOfJKSqDfey+GaAb/J2vzGlph?= =?us-ascii?Q?ewDR/jGD7icgDLXJTUugBPyxtHtQmizo1SDa+p1mkYXobHFqUe4VizpajSAk?= =?us-ascii?Q?kYsVYzjehEHvktt0QT4J2jUJysZQlPeO+/idtLL3AEqp5h/VEz1rVe+lgLqU?= =?us-ascii?Q?yhAzKp8LxE9OUClwmnsht3olz8CPziDC9O1iix6pIerLRFEdSH6ificH7CSz?= =?us-ascii?Q?0Rd3zXWN4NJ43pcKzFP0sTX+tS2HacNmtXt67BWw3Tec2BLg18fxk6g3p7kz?= =?us-ascii?Q?LeVogFP7/+N08UoMMPU6P0k6zuCi1B5xW/+VqO7uZOP0PETr3O/1lvYZn/uX?= =?us-ascii?Q?0bEex59L9TPNhUXPrvxeLjH593DUEQSpBskztWjvEiVY0KPn+lgWxqN3CD67?= =?us-ascii?Q?oAuQS8QtjTiS5HV8opVt+58Z9+wxqjlf61k+n5OgJxq7JtJoub9UGqM38km2?= =?us-ascii?Q?78SguGnRI3PbjbcbVWZu84czzkGHoZ1zUBjq2l1f6HyVZu5i5EfhEdvDzPdk?= =?us-ascii?Q?40BTWedm4UChP8oXZr+JPbv4Wavo3T7ZWVcQbtHxyyD0cQ0S0DrCzXOz41UU?= =?us-ascii?Q?UMuExZIAnWpMrHguEc5c6dxth7sgFaudvz1RZLzY8up/EvR5GEWS9K++NTdh?= =?us-ascii?Q?S3bPkEkA0Vb7Qlt2grSN8cjQP4XPA4SWsbuBLNPeCPcsRUw2KtrVwjPJGm2H?= =?us-ascii?Q?ErIeck1rtetNTiOskrxeUQFN8j8I3KjdJop/wcAP7ppyN/i1zLIAuCjxmHJQ?= =?us-ascii?Q?ILSaO4hBu1UYOmR11HDFbzFMKDZuIEi85ypV+btIn0o15I3dQNL6WZwC/xAX?= =?us-ascii?Q?Zs8ppOCwYTm/zsFTntoBl8FAsfyPyThHl0TFh?= X-Microsoft-Exchange-Diagnostics: 1;CY4PR1301MB2023;6:bJmH4VPcpJDB/F5sDMahSZSTtlDwEIg0xkMaFILEdMBgYpNNiP3VqdKw+YTzXjGFFYuazrX6ysXl6ihTNAYjzQ78DII95m+b8DE6Ha+NkfpGwKjChkeP0arqODfwLz/Un7w3D+ffOiE+hIb3e9pzVtFa1aAaloH/zoPx/lWRia56cebw5vjKWzHjQLaafcwCTNSbz4LaEWRG5II1Fx7QahgZ4YWOjj8M6VNfMpAyM1gWG6lCInAmRGXkB6ZxByR+TVms/vi1qOLAt9tz7LNebAJRKSu60HLQoY3gEdg2K1c81GsNEW7ymtx/UbHXs1ght8BOTRwERGN9RzvQcKxJ9QdJXLWDn3B7mDbwV/+ZvxQ=;5:MfmbzCeCmIV965DIGUdkUWI3OLPeTEMik8rw8xQhou7tSOzPbAOcAoHbKgUmWHjIOhPPkOOjZoBvyclrRiOfKNL6T/7X2sagBWcpBI52aWSgcD2Eq3mibuWYYcDtfQkNg3JSV2iQ6RjPzW8FxFxA+uu0FuUYXTmdWmwtfFii/Gc=;24:yc8+VgyIlOPIiGtukPy35ouQ3LXcpVLJoUmuIroSuUrU9jZJlMS1i6kiKD27fCgXX7H7NCUSZa2zpl0Jy7YTPhMLZHquNkG74q2deU9ypTk=;7:BVeICfBknfhSFMSwIf0gFkbbEvEQ3eM2ABk2l6Vv0+xytwz9v6u11WDJ2mJHYQJGit3wEHa85oL1GI2uGLTNOBcxZa5Ya4/LEu2oWLTPeLDb/z/pqye/yHOn3UYtkjd7uJL4ELS7W46y8XC3up4UCcnVz+fRn+3yaPXRKpjue+GeUQss+GLjxuk4BizjrP/gd3OYBmx4AbRKYD9ISKtEdTU/G05fAbLXmVOP2vfxwKrDRVZnlc8WnsFiTt77lBU8 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 08:43:43.8286 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05f03225-2241-4410-dfd0-08d55e4f958b 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.43];Helo=[jp.sony.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1301MB2023 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yasunari Takiguchi These are common files for the driver for the Sony CXD2880 DVB-T2/T tuner + demodulator. These contains helper functions for the driver. 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 --- [Change list] Changes in V5 Using SPDX-License-Identifier drivers/media/dvb-frontends/cxd2880/cxd2880_io.c -modified return not to use ret parameter. drivers/media/dvb-frontends/cxd2880/cxd2880_common.c -removed unnecessary parentheses drivers/media/dvb-frontends/cxd2880/cxd2880_common.h -removed function proto type about cxd2880_stopwatch -removed CXD2880_ARG_UNUSED #drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c -cxd2880_stopwatch_port.c file was removed from V5. Changes in V4 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c -removed unnecessary initialization at variable declaration -modified how to write consecutive registers Changes in V3 drivers/media/dvb-frontends/cxd2880/cxd2880.h -no change drivers/media/dvb-frontends/cxd2880/cxd2880_common.c -changed MASKUPPER/MASKLOWER with GENMASK drivers/media/dvb-frontends/cxd2880/cxd2880_common.h -removed definition NULL and SONY_SLEEP -changed CXD2880_SLEEP to usleep_range -changed cxd2880_atomic_set to atomic_set -removed cxd2880_atomic struct and cxd2880_atomic_read -changed stop-watch function -modified return code drivers/media/dvb-frontends/cxd2880/cxd2880_io.c -removed unnecessary cast -modified return code -changed hexadecimal code to lower case. drivers/media/dvb-frontends/cxd2880/cxd2880_io.h -modified return code drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c -changed CXD2880_SLEEP to usleep_range -changed stop-watch function -modified return code #drivers/media/dvb-frontends/cxd2880/cxd2880_stdlib.h -cxd2880_stdlib.h file was removed from V3. drivers/media/dvb-frontends/cxd2880/cxd2880.h | 29 ++++++++++ .../media/dvb-frontends/cxd2880/cxd2880_common.c | 21 +++++++ .../media/dvb-frontends/cxd2880/cxd2880_common.h | 19 +++++++ drivers/media/dvb-frontends/cxd2880/cxd2880_io.c | 66 ++++++++++++++++++++++ drivers/media/dvb-frontends/cxd2880/cxd2880_io.h | 54 ++++++++++++++++++ 5 files changed, 189 insertions(+) create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880.h create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.c create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.h create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880.h b/drivers/media/dvb-frontends/cxd2880/cxd2880.h new file mode 100644 index 000000000000..4ea3510aab66 --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * cxd2880.h + * Sony CXD2880 DVB-T2/T tuner + demodulator driver public definitions + * + * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation + */ + +#ifndef CXD2880_H +#define CXD2880_H + +struct cxd2880_config { + struct spi_device *spi; + struct mutex *spi_mutex; /* For SPI access exclusive control */ +}; + +#if IS_REACHABLE(CONFIG_DVB_CXD2880) +extern struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe, + struct cxd2880_config *cfg); +#else +static inline struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe, + struct cxd2880_config *cfg) +{ + pr_warn("%s: driver disabled by Kconfig\n", __func__); + return NULL; +} +#endif /* CONFIG_DVB_CXD2880 */ + +#endif /* CXD2880_H */ diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c new file mode 100644 index 000000000000..d6f5af6609c1 --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * cxd2880_common.c + * Sony CXD2880 DVB-T2/T tuner + demodulator driver + * common functions + * + * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation + */ + +#include "cxd2880_common.h" + +int cxd2880_convert2s_complement(u32 value, u32 bitlen) +{ + if (!bitlen || bitlen >= 32) + return (int)value; + + if (value & (u32)(1 << (bitlen - 1))) + return (int)(GENMASK(31, bitlen) | value); + else + return (int)(GENMASK(bitlen - 1, 0) & value); +} diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_common.h b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.h new file mode 100644 index 000000000000..b05bce71ab35 --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * cxd2880_common.h + * Sony CXD2880 DVB-T2/T tuner + demodulator driver common definitions + * + * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation + */ + +#ifndef CXD2880_COMMON_H +#define CXD2880_COMMON_H + +#include +#include +#include +#include + +int cxd2880_convert2s_complement(u32 value, u32 bitlen); + +#endif diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_io.c b/drivers/media/dvb-frontends/cxd2880/cxd2880_io.c new file mode 100644 index 000000000000..9d932bccfa6c --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_io.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * cxd2880_io.c + * Sony CXD2880 DVB-T2/T tuner + demodulator driver + * register I/O interface functions + * + * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation + */ + +#include "cxd2880_io.h" + +int cxd2880_io_common_write_one_reg(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + u8 sub_address, u8 data) +{ + if (!io) + return -EINVAL; + + return io->write_regs(io, tgt, sub_address, &data, 1); +} + +int cxd2880_io_set_reg_bits(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + u8 sub_address, u8 data, u8 mask) +{ + int ret; + + if (!io) + return -EINVAL; + + if (mask == 0x00) + return 0; + + if (mask != 0xff) { + u8 rdata = 0x00; + + ret = io->read_regs(io, tgt, sub_address, &rdata, 1); + if (ret) + return ret; + + data = (data & mask) | (rdata & (mask ^ 0xff)); + } + + return io->write_reg(io, tgt, sub_address, data); +} + +int cxd2880_io_write_multi_regs(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + const struct cxd2880_reg_value reg_value[], + u8 size) +{ + int ret; + int i; + + if (!io) + return -EINVAL; + + for (i = 0; i < size ; i++) { + ret = io->write_reg(io, tgt, reg_value[i].addr, + reg_value[i].value); + if (ret) + return ret; + } + + return 0; +} diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_io.h b/drivers/media/dvb-frontends/cxd2880/cxd2880_io.h new file mode 100644 index 000000000000..ba550278881d --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_io.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * cxd2880_io.h + * Sony CXD2880 DVB-T2/T tuner + demodulator driver + * register I/O interface definitions + * + * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation + */ + +#ifndef CXD2880_IO_H +#define CXD2880_IO_H + +#include "cxd2880_common.h" + +enum cxd2880_io_tgt { + CXD2880_IO_TGT_SYS, + CXD2880_IO_TGT_DMD +}; + +struct cxd2880_reg_value { + u8 addr; + u8 value; +}; + +struct cxd2880_io { + int (*read_regs)(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, u8 sub_address, + u8 *data, u32 size); + int (*write_regs)(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, u8 sub_address, + const u8 *data, u32 size); + int (*write_reg)(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, u8 sub_address, + u8 data); + void *if_object; + u8 i2c_address_sys; + u8 i2c_address_demod; + u8 slave_select; + void *user; +}; + +int cxd2880_io_common_write_one_reg(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + u8 sub_address, u8 data); + +int cxd2880_io_set_reg_bits(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + u8 sub_address, u8 data, u8 mask); + +int cxd2880_io_write_multi_regs(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + const struct cxd2880_reg_value reg_value[], + u8 size); +#endif -- 2.15.1 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Subject: [PATCH v5 03/12] [media] cxd2880: Add common files for the driver Date: Thu, 18 Jan 2018 17:47:38 +0900 Message-ID: <20180118084738.21058-1-Yasunari.Takiguchi@sony.com> References: <20180118084016.20689-1-Yasunari.Takiguchi@sony.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <20180118084016.20689-1-Yasunari.Takiguchi-7U/KSKJipcs@public.gmane.org> Sender: devicetree-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: tbird20d-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, Yasunari.Takiguchi-7U/KSKJipcs@public.gmane.org, Masayuki.Yamamoto-7U/KSKJipcs@public.gmane.org, Hideki.Nozawa-7U/KSKJipcs@public.gmane.org, Kota.Yonezawa-7U/KSKJipcs@public.gmane.org, Toshihiko.Matsumoto-7U/KSKJipcs@public.gmane.org, Satoshi.C.Watanabe-7U/KSKJipcs@public.gmane.org List-Id: devicetree@vger.kernel.org From: Yasunari Takiguchi These are common files for the driver for the Sony CXD2880 DVB-T2/T tuner + demodulator. These contains helper functions for the driver. 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 --- [Change list] Changes in V5 Using SPDX-License-Identifier drivers/media/dvb-frontends/cxd2880/cxd2880_io.c -modified return not to use ret parameter. drivers/media/dvb-frontends/cxd2880/cxd2880_common.c -removed unnecessary parentheses drivers/media/dvb-frontends/cxd2880/cxd2880_common.h -removed function proto type about cxd2880_stopwatch -removed CXD2880_ARG_UNUSED #drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c -cxd2880_stopwatch_port.c file was removed from V5. Changes in V4 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c -removed unnecessary initialization at variable declaration -modified how to write consecutive registers Changes in V3 drivers/media/dvb-frontends/cxd2880/cxd2880.h -no change drivers/media/dvb-frontends/cxd2880/cxd2880_common.c -changed MASKUPPER/MASKLOWER with GENMASK drivers/media/dvb-frontends/cxd2880/cxd2880_common.h -removed definition NULL and SONY_SLEEP -changed CXD2880_SLEEP to usleep_range -changed cxd2880_atomic_set to atomic_set -removed cxd2880_atomic struct and cxd2880_atomic_read -changed stop-watch function -modified return code drivers/media/dvb-frontends/cxd2880/cxd2880_io.c -removed unnecessary cast -modified return code -changed hexadecimal code to lower case. drivers/media/dvb-frontends/cxd2880/cxd2880_io.h -modified return code drivers/media/dvb-frontends/cxd2880/cxd2880_stopwatch_port.c -changed CXD2880_SLEEP to usleep_range -changed stop-watch function -modified return code #drivers/media/dvb-frontends/cxd2880/cxd2880_stdlib.h -cxd2880_stdlib.h file was removed from V3. drivers/media/dvb-frontends/cxd2880/cxd2880.h | 29 ++++++++++ .../media/dvb-frontends/cxd2880/cxd2880_common.c | 21 +++++++ .../media/dvb-frontends/cxd2880/cxd2880_common.h | 19 +++++++ drivers/media/dvb-frontends/cxd2880/cxd2880_io.c | 66 ++++++++++++++++++++++ drivers/media/dvb-frontends/cxd2880/cxd2880_io.h | 54 ++++++++++++++++++ 5 files changed, 189 insertions(+) create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880.h create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.c create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_common.h create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.c create mode 100644 drivers/media/dvb-frontends/cxd2880/cxd2880_io.h diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880.h b/drivers/media/dvb-frontends/cxd2880/cxd2880.h new file mode 100644 index 000000000000..4ea3510aab66 --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * cxd2880.h + * Sony CXD2880 DVB-T2/T tuner + demodulator driver public definitions + * + * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation + */ + +#ifndef CXD2880_H +#define CXD2880_H + +struct cxd2880_config { + struct spi_device *spi; + struct mutex *spi_mutex; /* For SPI access exclusive control */ +}; + +#if IS_REACHABLE(CONFIG_DVB_CXD2880) +extern struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe, + struct cxd2880_config *cfg); +#else +static inline struct dvb_frontend *cxd2880_attach(struct dvb_frontend *fe, + struct cxd2880_config *cfg) +{ + pr_warn("%s: driver disabled by Kconfig\n", __func__); + return NULL; +} +#endif /* CONFIG_DVB_CXD2880 */ + +#endif /* CXD2880_H */ diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c new file mode 100644 index 000000000000..d6f5af6609c1 --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * cxd2880_common.c + * Sony CXD2880 DVB-T2/T tuner + demodulator driver + * common functions + * + * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation + */ + +#include "cxd2880_common.h" + +int cxd2880_convert2s_complement(u32 value, u32 bitlen) +{ + if (!bitlen || bitlen >= 32) + return (int)value; + + if (value & (u32)(1 << (bitlen - 1))) + return (int)(GENMASK(31, bitlen) | value); + else + return (int)(GENMASK(bitlen - 1, 0) & value); +} diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_common.h b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.h new file mode 100644 index 000000000000..b05bce71ab35 --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_common.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * cxd2880_common.h + * Sony CXD2880 DVB-T2/T tuner + demodulator driver common definitions + * + * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation + */ + +#ifndef CXD2880_COMMON_H +#define CXD2880_COMMON_H + +#include +#include +#include +#include + +int cxd2880_convert2s_complement(u32 value, u32 bitlen); + +#endif diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_io.c b/drivers/media/dvb-frontends/cxd2880/cxd2880_io.c new file mode 100644 index 000000000000..9d932bccfa6c --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_io.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * cxd2880_io.c + * Sony CXD2880 DVB-T2/T tuner + demodulator driver + * register I/O interface functions + * + * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation + */ + +#include "cxd2880_io.h" + +int cxd2880_io_common_write_one_reg(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + u8 sub_address, u8 data) +{ + if (!io) + return -EINVAL; + + return io->write_regs(io, tgt, sub_address, &data, 1); +} + +int cxd2880_io_set_reg_bits(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + u8 sub_address, u8 data, u8 mask) +{ + int ret; + + if (!io) + return -EINVAL; + + if (mask == 0x00) + return 0; + + if (mask != 0xff) { + u8 rdata = 0x00; + + ret = io->read_regs(io, tgt, sub_address, &rdata, 1); + if (ret) + return ret; + + data = (data & mask) | (rdata & (mask ^ 0xff)); + } + + return io->write_reg(io, tgt, sub_address, data); +} + +int cxd2880_io_write_multi_regs(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + const struct cxd2880_reg_value reg_value[], + u8 size) +{ + int ret; + int i; + + if (!io) + return -EINVAL; + + for (i = 0; i < size ; i++) { + ret = io->write_reg(io, tgt, reg_value[i].addr, + reg_value[i].value); + if (ret) + return ret; + } + + return 0; +} diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_io.h b/drivers/media/dvb-frontends/cxd2880/cxd2880_io.h new file mode 100644 index 000000000000..ba550278881d --- /dev/null +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_io.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * cxd2880_io.h + * Sony CXD2880 DVB-T2/T tuner + demodulator driver + * register I/O interface definitions + * + * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation + */ + +#ifndef CXD2880_IO_H +#define CXD2880_IO_H + +#include "cxd2880_common.h" + +enum cxd2880_io_tgt { + CXD2880_IO_TGT_SYS, + CXD2880_IO_TGT_DMD +}; + +struct cxd2880_reg_value { + u8 addr; + u8 value; +}; + +struct cxd2880_io { + int (*read_regs)(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, u8 sub_address, + u8 *data, u32 size); + int (*write_regs)(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, u8 sub_address, + const u8 *data, u32 size); + int (*write_reg)(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, u8 sub_address, + u8 data); + void *if_object; + u8 i2c_address_sys; + u8 i2c_address_demod; + u8 slave_select; + void *user; +}; + +int cxd2880_io_common_write_one_reg(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + u8 sub_address, u8 data); + +int cxd2880_io_set_reg_bits(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + u8 sub_address, u8 data, u8 mask); + +int cxd2880_io_write_multi_regs(struct cxd2880_io *io, + enum cxd2880_io_tgt tgt, + const struct cxd2880_reg_value reg_value[], + u8 size); +#endif -- 2.15.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html