From patchwork Thu Jan 20 01:02:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Hancock X-Patchwork-Id: 12718142 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23690C433EF for ; Thu, 20 Jan 2022 01:05:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PTC4BHjaEgJy1Pag2KKlp71mLgHC6vVyB0Ab55UjiY8=; b=UMUX3QH5RlXIOL QExhkagpsqwv3zGZuqN4iJvNCJDP7F8PDlfY+Un5pdba8gFh3vULUSEnQ7dNDjN5qGizmNgDHqW5h pGHSHb+kw9n1byzqz0LeDcfNQCNncqXESgtRPWF9HpUaQgFMwzpM+6YMpJjbbrdiEYQbNz7IELWAV FtYTh/o4GaLov/pdv0GWAGgt0C4Amu0BtvUHiKWsdBF1WzxH5qJ6FCHH2lLBzBJDq5ZGFU5Ezvypi /MZOCGuoSOQP8azFlGxBBMZwUTQiG+SMPdSdqkjnIBEROyXc1kRrrkXS8nMqCsWkCSZQ+hkLsjyYZ LTB9/x+uM3eySlC+WGgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nALry-008633-F6; Thu, 20 Jan 2022 01:04:06 +0000 Received: from mx0d-0054df01.pphosted.com ([67.231.150.19]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nALrC-0085ta-OI for linux-arm-kernel@lists.infradead.org; Thu, 20 Jan 2022 01:03:21 +0000 Received: from pps.filterd (m0209000.ppops.net [127.0.0.1]) by mx0c-0054df01.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20JNHfL4017531; Wed, 19 Jan 2022 20:03:07 -0500 Received: from can01-to1-obe.outbound.protection.outlook.com (mail-to1can01lp2056.outbound.protection.outlook.com [104.47.61.56]) by mx0c-0054df01.pphosted.com (PPS) with ESMTPS id 3dpmt68b92-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jan 2022 20:03:07 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cs8paROcCsrSCtN30FkgToJoDvSjmFOG8QanvfgORSfcV8GYzujOI0jcKCPyjLkN83ZCPFdGvax1/N6OTAl8s3sY9+MILv81mw7L2pP18bQ6UHtSTMYS9vvp5AyRyRxzdZDrCl2eqGSnpNF9ExVl9u7/Rayb+/3j8X1ht5V3llwHRD1oa73gD8UySIvi3ElkIA5gCVU7jwlopopjnSS4C4Z4qwKie23MDJQ0hdVO31RQn7WDnt5uaE5eUyVk8GbkWYzWvTvZwsKigxU9qf9LeC3IWF042TBIhn7WUMQ5+f8vKuFiEq2MKXkm7oNg7xzxmqkTBmJsmSoBkd6mq2UC6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KwlHAXbj05qn9RWsqcRK51QW6q2ZXHSzH6cPrjoys8U=; b=XcHTMhiEkkF67xiyFjGuPQze/Opv4dTEeuwgfNd7f+oX6xupSJj9FGhHvcQL2Bbc4YojZ8iDmwNeB+pnKk9cPkeYMHN7jaRkVdkGWsp5VSi6q8xVg+ZRpPF76TVZkL1i4Cr/7dF7Z9TYdUud8Q5sh+JfwYZERmwsEs5nRHlIHi5M248bcNA1xVK4WcQi5oyAvY6+3HYHHqhWkBN57tVFnGmos2zhJy/7/LfI60VM5I9vzPVV/bR2Mv7jGMcYqrKYmSvkIGD8kt4d0H9jMRN0+24HkrojtRMrzP6RGQCk+sX+72LTzg/OB9LeIQl6DWJmerXp/fjJ2Ud6suSXs0clmg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=calian.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KwlHAXbj05qn9RWsqcRK51QW6q2ZXHSzH6cPrjoys8U=; b=cwx6eFEh3kcbqVyNRT+q/qhgvYUGWZueHoJNT6Bw+mqUTG5J1oLHeAawV75UFlfEdXDEPwggLz3awDcwdn8AJr5Fx+grE+nUab5P5FXda5U+8UtVeqpfyuvC15ytcDaMLvVigFEVbpkbPhYOPEdYtf8LlBcufrFhnUBpxnEweQY= Received: from YT3PR01MB6274.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:6a::19) by YTOPR0101MB1065.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00:20::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Thu, 20 Jan 2022 01:03:06 +0000 Received: from YT3PR01MB6274.CANPRD01.PROD.OUTLOOK.COM ([fe80::6929:c39f:d893:b6c8]) by YT3PR01MB6274.CANPRD01.PROD.OUTLOOK.COM ([fe80::6929:c39f:d893:b6c8%2]) with mapi id 15.20.4888.014; Thu, 20 Jan 2022 01:03:06 +0000 From: Robert Hancock To: linux-iio@vger.kernel.org Cc: robh+dt@kernel.org, michal.simek@xilinx.com, anand.ashok.dumbre@xilinx.com, jic23@kernel.org, lars@metafoo.de, manish.narani@xilinx.com, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Robert Hancock Subject: [PATCH 4/4] iio: adc: xilinx-ams: Fix single channel switching sequence Date: Wed, 19 Jan 2022 19:02:46 -0600 Message-Id: <20220120010246.3794962-5-robert.hancock@calian.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220120010246.3794962-1-robert.hancock@calian.com> References: <20220120010246.3794962-1-robert.hancock@calian.com> X-ClientProxiedBy: CH2PR10CA0008.namprd10.prod.outlook.com (2603:10b6:610:4c::18) To YT3PR01MB6274.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:6a::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d791f610-5560-4f82-3bf2-08d9dbb09de8 X-MS-TrafficTypeDiagnostic: YTOPR0101MB1065:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ytiv9BbZ7kNlu8SBWUrOAVyo1x8Dh1ZseJ9jYhOWZb//CHvEhEtwqpZ2pEsxnHE3jfVeMC7GEqeA0MwzZat4cbpFhiL68OqTVpSsyOjdi+F6QgCmNqGB558KxI4FapZlWYm0RDHDmWV8ixWvKqv479YnoG+TGD16iXTF43fYthq/by/pgD2KL45eScUF9CWnmTk+1Kvaknrtmmz1c6XoHVE0sKsRMciXaaX8WrhKzfohkveNXHTJvWCR4etzSgNuyzUZaSW/C3Po/xzajLuKWUGW4LOmJ4yffUTj7//YxYqyvK3yiGylRellJdRnVJGmsShUnRM20oAHz77102IXHLz2Bm1mQjjc9K7BorrbppWwZ5u/0uRIklpKuRPioq0ExBPEiTb6RfLS9Fx2Onrtv/P2+5KnzkbEcUqj3JeDKOA1y8J9aG2YpmUwSL0KMeDQNcQJh4zOFj9SxSCM0Z4QHZQgDsuGfFRZatdKvlLjaF7krbrht98aFIp7VdrqR2hD5YOM8Tj5aGBtxp9RpwPVsNIlkCGuXFdkEqvb1aezPwod6HLK4lzB7BcecQr8EAF5UvSzjTLxnkePorbAETNHA9IVIMrLGPkSD8KgtN+7J8HahqZ/sxLRiJfy3Sk5/6nhdFZdHqdfylC8n5HQ7iO2M1B9s7CSpJAq7b0DXjo+IDNJ3ZUTiWOaJE7dmj9RC8mnenpV2dpjWAjxHKrxYS6yGg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:YT3PR01MB6274.CANPRD01.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(4636009)(366004)(2616005)(44832011)(4326008)(2906002)(66946007)(66476007)(66556008)(316002)(6916009)(1076003)(6512007)(38350700002)(26005)(36756003)(6506007)(6666004)(38100700002)(52116002)(5660300002)(83380400001)(6486002)(107886003)(86362001)(508600001)(8676002)(8936002)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /O/AMc1ZZC2v6y4QmLTgONtRBPed3WV1LkZHvLfZxzxnyaYxi39YKpUF19XkzIXc9yWH9N5Rvd30aEHZT8JfX0nDDXZY7pAm/L2r1MlMBI3ETY/1UEDesXoXPDiSLYqerQ7HpWGU/U38XRzbcpticcruGfcC+ANdLiVJClvWR8tHG7N+7osQ70eNQXZfZQ+UgzE+zX3sfwCJ8JTG8JI4Q2W+TGmiwA+KEMa+wewG4VgfJFQUJlrMgwyZyG7FWOgtmUd8DMyvhAGlCMlIYxvvSbXsY+05R0nPMH0b2LKuax77AO86I91dGt632jzxZGvS9btEamdNe940BFOMXoWn8a002DZAp/g/uU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gmxlGF0/mdGQOhtYTUEH16K+H38hAt64WlmoixuIxSY+XrzPjh6pUFWVasB1F3az0ysmWhWeM9wqvjF9zv4PPtVkU0pPGm//NhSZWDH6evP+4gps+6TREs4LDOd+p8eYp8xo32OqpqbFjuvbcmqDsoNk3yLlRI5YHKlI5a9SrlFoZkTiRPQp2SIWAnOo3ZksULQUMM+2b2XWR8KwhTUNPfprNUHQZJgqita9QwXI4e7hEQ9cwP2fXOKEdoC/XH3Pgi1okGFwW8luVtgiEF7g= X-OriginatorOrg: calian.com X-MS-Exchange-CrossTenant-Network-Message-Id: d791f610-5560-4f82-3bf2-08d9dbb09de8 X-MS-Exchange-CrossTenant-AuthSource: YT3PR01MB6274.CANPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2022 01:03:06.0855 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 23b57807-562f-49ad-92c4-3bb0f07a1fdf X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ADaFm85sbRVk8EENEhERg1RCxEDdnqCGZuqUKGdhSf9a+cr+bLwcJx1T3qJU3UrEOb0D52LGAztnSW4F04ptH4nKBjaneNXabkyZaWPESfo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: YTOPR0101MB1065 X-Proofpoint-GUID: 9gaOnxvw_GEtQ46BdxTXKgPM0VwoxRfz X-Proofpoint-ORIG-GUID: 9gaOnxvw_GEtQ46BdxTXKgPM0VwoxRfz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-19_12,2022-01-19_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 impostorscore=0 adultscore=0 spamscore=0 mlxlogscore=827 suspectscore=0 priorityscore=1501 malwarescore=0 clxscore=1015 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201200004 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220119_170318_973338_75F5935F X-CRM114-Status: GOOD ( 17.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Some of the AMS channels need to be read by switching into single-channel mode from the normal polling sequence. There was a logic issue in this switching code that could cause the first read of these channels to read back as zero. It appears that the sequencer should be set back to default mode before changing the channel selection, and the channel should be set before switching the sequencer back into single-channel mode. Also, write 1 to the EOC bit in the status register to clear it before waiting for it to become set, so that we actually wait for a new conversion to complete, and don't proceed based on a previous conversion completing. Fixes: d5c70627a794 ("iio: adc: Add Xilinx AMS driver") Signed-off-by: Robert Hancock --- drivers/iio/adc/xilinx-ams.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/xilinx-ams.c b/drivers/iio/adc/xilinx-ams.c index 199027c93cdc..7bf097fa10cb 100644 --- a/drivers/iio/adc/xilinx-ams.c +++ b/drivers/iio/adc/xilinx-ams.c @@ -530,14 +530,18 @@ static int ams_enable_single_channel(struct ams *ams, unsigned int offset) return -EINVAL; } - /* set single channel, sequencer off mode */ + /* put sysmon in a soft reset to change the sequence */ ams_ps_update_reg(ams, AMS_REG_CONFIG1, AMS_CONF1_SEQ_MASK, - AMS_CONF1_SEQ_SINGLE_CHANNEL); + AMS_CONF1_SEQ_DEFAULT); /* write the channel number */ ams_ps_update_reg(ams, AMS_REG_CONFIG0, AMS_CONF0_CHANNEL_NUM_MASK, channel_num); + /* set single channel, sequencer off mode */ + ams_ps_update_reg(ams, AMS_REG_CONFIG1, AMS_CONF1_SEQ_MASK, + AMS_CONF1_SEQ_SINGLE_CHANNEL); + return 0; } @@ -551,6 +555,8 @@ static int ams_read_vcc_reg(struct ams *ams, unsigned int offset, u32 *data) if (ret) return ret; + /* clear end-of-conversion flag, wait for next conversion to complete */ + writel(expect, ams->base + AMS_ISR_1); ret = readl_poll_timeout(ams->base + AMS_ISR_1, reg, (reg & expect), AMS_INIT_POLL_TIME_US, AMS_INIT_TIMEOUT_US); if (ret)