From patchwork Mon Jan 13 12:07:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 11329993 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6691A92A for ; Mon, 13 Jan 2020 12:07:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3AADD2084D for ; Mon, 13 Jan 2020 12:07:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="UpulOZ/D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728755AbgAMMHU (ORCPT ); Mon, 13 Jan 2020 07:07:20 -0500 Received: from esa4.microchip.iphmx.com ([68.232.154.123]:48181 "EHLO esa4.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728738AbgAMMHU (ORCPT ); Mon, 13 Jan 2020 07:07:20 -0500 Received-SPF: Pass (esa4.microchip.iphmx.com: domain of Eugen.Hristev@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa4.microchip.iphmx.com; envelope-from="Eugen.Hristev@microchip.com"; x-sender="Eugen.Hristev@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com -exists:%{i}.spf.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa4.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa4.microchip.iphmx.com; envelope-from="Eugen.Hristev@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa4.microchip.iphmx.com; spf=Pass smtp.mailfrom=Eugen.Hristev@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: fVJd0b1CloIcHjHJPApKxKNMuM9bVv8Z3YH9zpjpFEfVegyPCR63ApH/ZdyQPIO62O6OsnQc4X +6Y744YPClMM2BrpFCNZXrJvLdc4MsX0/aeGzIPuUhrVkKvlaFkzK0g76nVp1XFwEgzju9Kvbj DM0bbGveehVNLBP1zSnNbiTG25lMzCghRMXK4UjarYugx3I572C247jYP1aUEvkJ4szIeAU447 7p6NiNB5Cd+85X/4gPlpqY/h7KnkgqME3dEa8yEG6GnTHI6VpyyO/0BSm1kJhh/TJ+BLufKiUf XCY= X-IronPort-AV: E=Sophos;i="5.69,428,1571727600"; d="scan'208";a="60892615" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Jan 2020 05:07:18 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 13 Jan 2020 05:07:10 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 13 Jan 2020 05:07:10 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uk0nH+n5Cbv9ZeVC7nwOKsso/GxNl61QKiEfjspbTToqL3JQ6cz39zYYWEJJBGN7g3nMVmqaS7vqbAP54qBE2Pt/LQj3Nk+C7cPQubRqwn4sYLGAbCmrC7jM882SvJ+BGV+mhp2XTTPB2UsKi5MUDXfK7YQ2EV+8xdd1p3NabkA9ifvaQpNCPqq3TAX3t/pODJowBzbuWtst83fwVB/zXIBet+06857SiL+NN/6feqVQLVoqX61Gn0WADDRmpF3eqSuCdkJxa8ynNPXFgrtC2RFdDdAAoiZjLYbeTCQxyxa6bznQEoKhq0DEDLIZbbPkLLpJ/1nKx15QxDIhz68isA== 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-SenderADCheck; bh=qhs6f7oQUwU0gOwRfNxmUhiZW5v8xRmmgy/AsreIpWU=; b=GNZPXt3rM1qDSSkpHPOno1kf669k7IRbhjqxGtQ4bgRAcwVR78t9LXZlMJ29u5BKptAIh+wN6XYIdi40sKZpSf41+KQPcnp+mO3r+YHGeAsgdiqvwS27fMul9hJMrETQ1QUs4qqml47qFW4DJWjEFTn7r+w5u4MeDops27QF+GzcijbYlDN29PMRvOHO2xSDuVUD55cyfI37C5piQ6BrjmQ5WNtUPoY9/TccQHJdWTZkkOOjQe/quu8GbO0q5oZcLZANGrQEqAw4ArrnaR4mxCwIx6EMgWNZGtLXqRvNwZuMgNquhMy8bjpwmwwZdLGZCgaM20tZP2jaVlxne4zg7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qhs6f7oQUwU0gOwRfNxmUhiZW5v8xRmmgy/AsreIpWU=; b=UpulOZ/DK8bL2AEp7eg9x2pTpJLy/mWMpX78G2/wOli5qXUnVqJlyrIB9PHQj6O6dhVKfOgqgqXb8ueb1CzScDeCk5GQGMexTRErSfPsDdglUoXBxybEc7aot4OQ1PJG3FVswumSUIFd+XfYqdK9VSiGQ+gUl8GlCtW8LouhHu8= Received: from DM5PR11MB1242.namprd11.prod.outlook.com (10.168.108.8) by DM5PR11MB0011.namprd11.prod.outlook.com (10.164.155.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2623.16; Mon, 13 Jan 2020 12:07:09 +0000 Received: from DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e5f6:d07d:d7de:ce79]) by DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e5f6:d07d:d7de:ce79%6]) with mapi id 15.20.2623.015; Mon, 13 Jan 2020 12:07:09 +0000 From: To: , , , CC: , Subject: [PATCH v2 1/3] iio: adc: at91-sama5d2_adc: fix differential channels in triggered mode Thread-Topic: [PATCH v2 1/3] iio: adc: at91-sama5d2_adc: fix differential channels in triggered mode Thread-Index: AQHVygn64v98utrynU+d9NR0RxZ56Q== Date: Mon, 13 Jan 2020 12:07:09 +0000 Message-ID: <1578917098-9674-2-git-send-email-eugen.hristev@microchip.com> References: <1578917098-9674-1-git-send-email-eugen.hristev@microchip.com> In-Reply-To: <1578917098-9674-1-git-send-email-eugen.hristev@microchip.com> Accept-Language: en-US, ro-RO Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b0b41806-c7a0-45e4-58f0-08d798211dad x-ms-traffictypediagnostic: DM5PR11MB0011: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6430; x-forefront-prvs: 028166BF91 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(366004)(396003)(136003)(39860400002)(346002)(189003)(199004)(8936002)(4326008)(71200400001)(8676002)(81166006)(81156014)(5660300002)(91956017)(478600001)(86362001)(76116006)(66946007)(6506007)(54906003)(110136005)(6486002)(186003)(316002)(36756003)(26005)(2906002)(107886003)(66446008)(6512007)(66476007)(66556008)(64756008)(2616005);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR11MB0011;H:DM5PR11MB1242.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: LgDJQNNd3KiwO5xLeb6rASKkkBrmeCHhUco0jh2YVk4xM5130wJn0gZ66M1F4MiB1Pc+4ls+ZBbK8qsPhMDFSKlg5zzyC/gKmNrxUk56cYZ7aL93YehLWaIiDR7T4WaZEjZTFc6X+WzdN7IRExCOHjCU571lcr7SZJIW46W4h3GjcrpeaZwn3nMaqbXgDUPHdZw5ETVVvxo0fTuJojjWWmwIgkOymnhULG8qgQLTvD7BLKsLNz70g1KO+E7FbyX/Ot7wFxuG3886VoWjRV2E8OObSXQK/Yqo1yDGLdADWgfxKRqrDCFH8EvltgjClYfE9BjsfhPWiYoKJU/0qUVDGQ9vyWGPon+D4sTX5wEcU0dx27Cqm0d/P6k6mLE0WodXb+9VMiC6JZ9wfcqil/cvWAqBuUx7SxXU2NJADpn65fEwDIh0fS/2qNsIJJf75MwQ MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: b0b41806-c7a0-45e4-58f0-08d798211dad X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jan 2020 12:07:09.0479 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 3L22SPLk5w/983hIWbDBlRcImC1ULPpf9U0qjWHBsOqpY7OCLTbR7ll50MhrQeWsIzozDkV64KpfbQze5VJmIAS7fHNg0djSLu3PXJl7aaw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB0011 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Eugen Hristev The differential channels require writing the channel offset register (COR). Otherwise they do not work in differential mode. The configuration of COR is missing in triggered mode. Fixes: 5e1a1da0f8c9 ("iio: adc: at91-sama5d2_adc: add hw trigger and buffer support") Signed-off-by: Eugen Hristev --- Changes in v2: - moved to the start of the list drivers/iio/adc/at91-sama5d2_adc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c index e1850f3..2a6950a 100644 --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c @@ -723,6 +723,7 @@ static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) for_each_set_bit(bit, indio->active_scan_mask, indio->num_channels) { struct iio_chan_spec const *chan = at91_adc_chan_get(indio, bit); + u32 cor; if (!chan) continue; @@ -732,6 +733,20 @@ static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) continue; if (state) { + cor = at91_adc_readl(st, AT91_SAMA5D2_COR); + + if (chan->differential) + cor |= (BIT(chan->channel) | + BIT(chan->channel2)) << + AT91_SAMA5D2_COR_DIFF_OFFSET; + else + cor &= ~(BIT(chan->channel) << + AT91_SAMA5D2_COR_DIFF_OFFSET); + + at91_adc_writel(st, AT91_SAMA5D2_COR, cor); + } + + if (state) { at91_adc_writel(st, AT91_SAMA5D2_CHER, BIT(chan->channel)); /* enable irq only if not using DMA */ From patchwork Mon Jan 13 12:07:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 11329999 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5409013BD for ; Mon, 13 Jan 2020 12:07:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2915B2084D for ; Mon, 13 Jan 2020 12:07:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="Yc8ecUFt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728643AbgAMMH1 (ORCPT ); Mon, 13 Jan 2020 07:07:27 -0500 Received: from esa5.microchip.iphmx.com ([216.71.150.166]:38215 "EHLO esa5.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728777AbgAMMHU (ORCPT ); Mon, 13 Jan 2020 07:07:20 -0500 Received-SPF: Pass (esa5.microchip.iphmx.com: domain of Eugen.Hristev@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa5.microchip.iphmx.com; envelope-from="Eugen.Hristev@microchip.com"; x-sender="Eugen.Hristev@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com -exists:%{i}.spf.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa5.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa5.microchip.iphmx.com; envelope-from="Eugen.Hristev@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa5.microchip.iphmx.com; spf=Pass smtp.mailfrom=Eugen.Hristev@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: ZCjRH3ot3t9XUY/GF/hsjOh8elWliTWwct4jXf3oaa5QEPnmStTmdAdubTZGfZ1EYQzH0baYoA tRToZ3T6uVmnjwW4+L5avcjCL2qO84KHWUbvmzO1ahDsF2K1LAF7bIKw7muAzuvLnrKZyw9NC/ 4/6mo3uZYLyXMNY9ysu90+96A2xIMUNfIjs+nDIV2WvGCcLZo64t2JG0RMxrdeebR3sZkA8Bra 4oLLfFw6aeTo2eHa4XhLmxjZbMJLqoJZcZor0zm31wuvhNXAGBchhOzEe9tqhKqcTYfQcbJ3eY R/0= X-IronPort-AV: E=Sophos;i="5.69,428,1571727600"; d="scan'208";a="61710735" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Jan 2020 05:07:18 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 13 Jan 2020 05:07:11 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 13 Jan 2020 05:07:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cwuNYomTCwD1Q3K4b624QFhGWEdCK4obyjgRmQkn3quRyQYopkNc6O9crubJBFXKuOn5yLWbMGnVSUZTFH9BL5fIm/QFv22Y2GkoYIpccAQ988HiMg0XD30V53X8UbZTevMfX56Nxcw7+9NRmgqMt5FfyjHb8MgVFpAYdMAQm+8iOGASUyaH5XYUpIfySVlLJN70FGv0ipHqEHz7QITiOatBjXK1GyXaXrC95imKfoqAHxEgXva1Lek6PhWbg0FbxugFGpl0/lxAM4qfuivbG3vErIQb9lCV60pR0Ft5mJnJlQ1Fc5JZx/+wqYVmsFfxQ6AcWQHb+6BhNXK0ZtlELw== 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-SenderADCheck; bh=WE/O7I+g4DONLHXyuItIsEvDX2S6uQeePfMwFmfRw9U=; b=UVxA5OiJkBryVViSc8z8CWG7bHPunJnJ3oVSMQAhYvE++TeUlp5WlEi2z4jm/XTj4vuxy8upLQiZgDfRqHfNGG1qExyJsZ21GgLHEkT1duUCJrzGoZuWpg7tCKrfCuMpWpaNR1sk5wzdj2qHR9cfw554jHNDBCDag8YIzgeydeYF/AMWONkAlT9tEOtwybXuWXWegJjyoc9tiOk5vwjYSoBz7aGCKgtJ1LMyLtZfLus231gpQ9jFSKbGov2bgDRhXvyqbEt13xHlI6Jgm6F98orkzEwnfDFM+jQZuUP9oRUb92IJbPxBpjqP6nwCrLPiRxxqgyz0WrURF89PAseAfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WE/O7I+g4DONLHXyuItIsEvDX2S6uQeePfMwFmfRw9U=; b=Yc8ecUFtZ/fmRVlHVHurki/q8ORGif4xfEmulm/lNPjx2POKi6GSLmldzu8f4lts9ejfQT0AExonupH2i/7NaoDHX2hzecXcVLu9/aG3pXjIXBk1fTznYYZf+8lRBUed+5Bk82N1quMWgchXJpMSdxeaR+K18+ca98RON0t4U8I= Received: from DM5PR11MB1242.namprd11.prod.outlook.com (10.168.108.8) by DM5PR11MB0011.namprd11.prod.outlook.com (10.164.155.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2623.16; Mon, 13 Jan 2020 12:07:10 +0000 Received: from DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e5f6:d07d:d7de:ce79]) by DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e5f6:d07d:d7de:ce79%6]) with mapi id 15.20.2623.015; Mon, 13 Jan 2020 12:07:10 +0000 From: To: , , , CC: , Subject: [PATCH v2 2/3] iio: adc: at91-sama5d2_adc: handle unfinished conversions Thread-Topic: [PATCH v2 2/3] iio: adc: at91-sama5d2_adc: handle unfinished conversions Thread-Index: AQHVygn79EXDODWs2EKzXEoIhEzLMw== Date: Mon, 13 Jan 2020 12:07:09 +0000 Message-ID: <1578917098-9674-3-git-send-email-eugen.hristev@microchip.com> References: <1578917098-9674-1-git-send-email-eugen.hristev@microchip.com> In-Reply-To: <1578917098-9674-1-git-send-email-eugen.hristev@microchip.com> Accept-Language: en-US, ro-RO Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8f6589ab-d19d-47d0-3378-08d798211df3 x-ms-traffictypediagnostic: DM5PR11MB0011: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 028166BF91 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(366004)(396003)(136003)(39860400002)(346002)(189003)(199004)(8936002)(4326008)(71200400001)(8676002)(81166006)(81156014)(5660300002)(91956017)(478600001)(86362001)(76116006)(66946007)(6506007)(54906003)(110136005)(6486002)(186003)(316002)(36756003)(26005)(2906002)(107886003)(66446008)(6512007)(66476007)(66556008)(64756008)(2616005);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR11MB0011;H:DM5PR11MB1242.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: QBukSAnNrmJ0Ru8jabAHXNyYjAHC7hkx+FM0/yqRE6B7fJQ6pbuzIxUY5vFlMlLxag1ZtW9sTplq/XU2+j3iyH3PLhhh5SahzwZuzVwND/SHx6UykIaoKZdcRHDGmq76bmFhjNfKhck8OM/DKqfPj5d7t81GNz8lIXeh6vAmVGHhcinVV42X4j+s43okvr6R47bzQtSWZ5wiW3TowST3qF/SbWQhKxhsysLqtqtkbsi200x9f/2T6cVs9IGEZiQULgpeRQqpVh/+sgrnR7xIOzbDNFx5e3q2sBV5kgff5Zouq67O5AVH0Ph2x9Ygih1ja7CFeredHj84QHF28AaRO80qT6T7HK1iNQvyiXcSS4A3fH9r8j2ju5RLNcN5hCaoe0RcJmpGtq6P0xQjhX2DsCpRTRLsic01WTxjyJ2MQhHsheVF790uTXyVG8Oekuk+ MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 8f6589ab-d19d-47d0-3378-08d798211df3 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jan 2020 12:07:09.5177 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: PgEujsXIHVf5J1ui2zt8xUgYRCnKLboTbeGI4q2WM6vP8Gv78+605ZbrvA4n2FqH6PcJHf5D9FgxGmVxZcA2L2c1pMKskwXcFOHQZTzE2co= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB0011 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Eugen Hristev It can happen that on IRQ trigger, not all conversions are done if we are enabling multiple channels. The IRQ is triggered on first EOC (end of channel), but it can happen that not all channels are done. This leads into erroneous reports to userspace (zero values or previous values). To solve this, in trigger handler, check if the mask of done channels is the same as the mask of active scan channels. If it's the same, proceed and push to buffers. Otherwise, use usleep to sleep until the conversion is done or we timeout. Normally, it should happen that in a short time fashion, all channels are ready, since the first IRQ triggered. If a hardware fault happens (for example the clock suddently dissappears), the handler will not be completed, in which case we do not report anything to userspace anymore. Also, change from using the EOC interrupts to DRDY interrupt. This helps with the fact that not 'n' interrupt statuses are enabled, each being able to trigger an interrupt, and instead only data ready interrupt can wake up the CPU. Like this, when data is ready, check in handler which and how many channels are done. While the DRDY is raised, other IRQs cannot occur. Once the channel data is being read, we ack the IRQ and finish the conversion. Signed-off-by: Eugen Hristev --- Changes in v2: - move start of conversion to threaded irq, removed specific at91 pollfunc - add timeout to channel mask readiness check in trigger handler - use DRDY irq instead of EOC irqs. - move enable irq after DRDY has been acked in reenable_trigger drivers/iio/adc/at91-sama5d2_adc.c | 62 ++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c index 2a6950a..454a493 100644 --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -100,6 +101,8 @@ #define AT91_SAMA5D2_IER_YRDY BIT(21) /* Interrupt Enable Register - TS pressure measurement ready */ #define AT91_SAMA5D2_IER_PRDY BIT(22) +/* Interrupt Enable Register - Data ready */ +#define AT91_SAMA5D2_IER_DRDY BIT(24) /* Interrupt Enable Register - general overrun error */ #define AT91_SAMA5D2_IER_GOVRE BIT(25) /* Interrupt Enable Register - Pen detect */ @@ -486,6 +489,21 @@ static inline int at91_adc_of_xlate(struct iio_dev *indio_dev, return at91_adc_chan_xlate(indio_dev, iiospec->args[0]); } +static unsigned int at91_adc_active_scan_mask_to_reg(struct iio_dev *indio_dev) +{ + u32 mask = 0; + u8 bit; + + for_each_set_bit(bit, indio_dev->active_scan_mask, + indio_dev->num_channels) { + struct iio_chan_spec const *chan = + at91_adc_chan_get(indio_dev, bit); + mask |= BIT(chan->channel); + } + + return mask & GENMASK(11, 0); +} + static void at91_adc_config_emr(struct at91_adc_state *st) { /* configure the extended mode register */ @@ -746,24 +764,19 @@ static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) at91_adc_writel(st, AT91_SAMA5D2_COR, cor); } - if (state) { + if (state) at91_adc_writel(st, AT91_SAMA5D2_CHER, BIT(chan->channel)); - /* enable irq only if not using DMA */ - if (!st->dma_st.dma_chan) { - at91_adc_writel(st, AT91_SAMA5D2_IER, - BIT(chan->channel)); - } - } else { - /* disable irq only if not using DMA */ - if (!st->dma_st.dma_chan) { - at91_adc_writel(st, AT91_SAMA5D2_IDR, - BIT(chan->channel)); - } + else at91_adc_writel(st, AT91_SAMA5D2_CHDR, BIT(chan->channel)); - } } + /* enable irq only if not using DMA */ + if (state && !st->dma_st.dma_chan) + at91_adc_writel(st, AT91_SAMA5D2_IER, AT91_SAMA5D2_IER_DRDY); + /* disable irq only if not using DMA */ + if (!state && !st->dma_st.dma_chan) + at91_adc_writel(st, AT91_SAMA5D2_IDR, AT91_SAMA5D2_IER_DRDY); return 0; } @@ -777,10 +790,10 @@ static int at91_adc_reenable_trigger(struct iio_trigger *trig) if (st->dma_st.dma_chan) return 0; - enable_irq(st->irq); - /* Needed to ACK the DRDY interruption */ at91_adc_readl(st, AT91_SAMA5D2_LCDR); + + enable_irq(st->irq); return 0; } @@ -1015,6 +1028,22 @@ static void at91_adc_trigger_handler_nodma(struct iio_dev *indio_dev, int i = 0; int val; u8 bit; + u32 mask = at91_adc_active_scan_mask_to_reg(indio_dev); + unsigned int timeout = 50; + + /* + * Check if the conversion is ready. If not, wait a little bit, and + * in case of timeout exit with an error. + */ + while ((at91_adc_readl(st, AT91_SAMA5D2_ISR) & mask) != mask && + timeout) { + usleep_range(50, 100); + timeout--; + } + + /* Cannot read data, not ready. Continue without reporting data */ + if (!timeout) + return; for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev->num_channels) { @@ -1281,7 +1310,8 @@ static irqreturn_t at91_adc_interrupt(int irq, void *private) status = at91_adc_readl(st, AT91_SAMA5D2_XPOSR); status = at91_adc_readl(st, AT91_SAMA5D2_YPOSR); status = at91_adc_readl(st, AT91_SAMA5D2_PRESSR); - } else if (iio_buffer_enabled(indio) && !st->dma_st.dma_chan) { + } else if (iio_buffer_enabled(indio) && + (status & AT91_SAMA5D2_IER_DRDY)) { /* triggered buffer without DMA */ disable_irq_nosync(irq); iio_trigger_poll(indio->trig); From patchwork Mon Jan 13 12:07:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 11329997 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A0A9092A for ; Mon, 13 Jan 2020 12:07:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6B5A821734 for ; Mon, 13 Jan 2020 12:07:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="OF45fcqQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728794AbgAMMHU (ORCPT ); Mon, 13 Jan 2020 07:07:20 -0500 Received: from esa5.microchip.iphmx.com ([216.71.150.166]:38215 "EHLO esa5.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726127AbgAMMHU (ORCPT ); Mon, 13 Jan 2020 07:07:20 -0500 Received-SPF: Pass (esa5.microchip.iphmx.com: domain of Eugen.Hristev@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa5.microchip.iphmx.com; envelope-from="Eugen.Hristev@microchip.com"; x-sender="Eugen.Hristev@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com -exists:%{i}.spf.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa5.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa5.microchip.iphmx.com; envelope-from="Eugen.Hristev@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa5.microchip.iphmx.com; spf=Pass smtp.mailfrom=Eugen.Hristev@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dkim=pass (signature verified) header.i=@microchiptechnology.onmicrosoft.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: 8aWN5G6meKVa7JsVJ3Ff67Cc9qKBajT2XRnRH0JxP6A9d7WiPJXNT1Rnz6gTZcmmmme/vzqyzf v0VwAAnV4fdkdtlD4eGbJ7h2smR5JNuFqbQkrqmV1nS3o9H+q4hd93GZKM24MZRIuWz2KwfxlU ivDTf/f+sXTbymPbbDTPOA51PZg6Kkvm83SLA2ZtgTX23sdZmOMXje8i8GMm19vwR3su9J3Ind +yYkMaOxy5Oed2H3ZpAbiuUVXYU/d/1+fnnEs+0qsEjk2emC/U5TZgj5mW0eOY8YbQIcwJARG0 vvo= X-IronPort-AV: E=Sophos;i="5.69,428,1571727600"; d="scan'208";a="61710734" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Jan 2020 05:07:18 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 13 Jan 2020 05:07:11 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 13 Jan 2020 05:07:11 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LYV6YozcXtV4RTHMbOlL7X2RbCXEq7br8y7uuAwBkFYytn3+rB1NkeHOnaSCeKhQKzwCwMtbr/JsjEbG0BOgQudcKAlRIzbY5iFOBW9hu01wBBZTVjq4UStjRKvfgVpnJDlhivG93IAq3Y5R50n9ct3Z2WNi65tPDT/kBxmE5JSG43dm95okXmhQI7m9nehckVsMINys3QURWNCkAJ/A4MPrpSORltcxUVkyANzPui3nSHVqOk0PLErQj6kywAJ7m4GarQIIlWWCjm+3PiqyIOVMEUoumsIVWonsC7CxjmGVKQq36gNNJxMlAQfVZbpJD/YXp0DyIuxLX852sEaw6g== 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-SenderADCheck; bh=rJg5WVr18AtTM6Sf2grIxv9KqnZwhGCvyXv8KouozHw=; b=KLia3Zo0wLJ94bnryV5KMVlGExElAS6LM1vKW/XNb/cTXVeh21BGUgyf3bDIe5EOj+sODMO/Uld1tgPf28PAMTg9P/s2epRqPHdwOLSaFjW3jZUBg/DH8M1eUTNwQcINsOuD6SoYYBEtHSQdJlKuQ5Di1JsXaJpki8IcITABxdlJjNrdfKj/YyEhlqlUfwuPfwDpwT9wvAqbmeHpm4p1ZnNquPSzM6UbWjJapX1AB1LR4RwVUbbfzD+u7JycCULg+sruOLzjcY8shyFlPU72xzKq2LBoqnOzJcbFB0cF9xYWdeSZHrtGQ5BinERJvGEYehI07qEH8hTQWwmU4RM6jw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rJg5WVr18AtTM6Sf2grIxv9KqnZwhGCvyXv8KouozHw=; b=OF45fcqQmzv/gwCaygxCOukESb8rBVMaEUsaNhhlkYu9fMec3xXdmXin6uSVVTxaPQPJNOFqDrYhu31hLyOXz48CyV6W31INjaGXW/85QcBS/XYwEe+KT2KAomrUXCsOOsBysWictpQEO8qQJcGkuifIY81IxZQUJTBT0K6V3Xo= Received: from DM5PR11MB1242.namprd11.prod.outlook.com (10.168.108.8) by DM5PR11MB1498.namprd11.prod.outlook.com (10.172.36.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2623.9; Mon, 13 Jan 2020 12:07:10 +0000 Received: from DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e5f6:d07d:d7de:ce79]) by DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e5f6:d07d:d7de:ce79%6]) with mapi id 15.20.2623.015; Mon, 13 Jan 2020 12:07:10 +0000 From: To: , , , CC: , Subject: [PATCH v2 3/3] iio: adc: at91-sama5d2_adc: update for other trigger usage Thread-Topic: [PATCH v2 3/3] iio: adc: at91-sama5d2_adc: update for other trigger usage Thread-Index: AQHVygn7rEZ0ai+1ZkerXwetHJ8ZDg== Date: Mon, 13 Jan 2020 12:07:10 +0000 Message-ID: <1578917098-9674-4-git-send-email-eugen.hristev@microchip.com> References: <1578917098-9674-1-git-send-email-eugen.hristev@microchip.com> In-Reply-To: <1578917098-9674-1-git-send-email-eugen.hristev@microchip.com> Accept-Language: en-US, ro-RO Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-originating-ip: [94.177.32.156] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 18bc91d8-529d-49d7-3928-08d798211e40 x-ms-traffictypediagnostic: DM5PR11MB1498: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 028166BF91 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(136003)(39860400002)(346002)(376002)(366004)(199004)(189003)(66446008)(316002)(54906003)(110136005)(2616005)(36756003)(86362001)(6486002)(478600001)(6506007)(6512007)(186003)(91956017)(76116006)(2906002)(26005)(4326008)(107886003)(5660300002)(8936002)(8676002)(81166006)(81156014)(71200400001)(66946007)(64756008)(66556008)(66476007);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR11MB1498;H:DM5PR11MB1242.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 3knBqUFcJNg+hqkdsEnZN/pKCUKUaqygxeIWVeuRdqasKfIQrdePJELBChlFQA0gtjZRIxKKrva54/2ntnx81GKISD1QcuVJpUdAC4VmyphlXNGvlN1b5+ad0lnGuN0szhWn1kK+1WwXmUadEAgoQzdTF5DW9MHCbxMxI74FRLAjsZOOz32zwCU8Na29RyQA3JPH6xCp27r7Z4rgBEFCF871Pi3qo4S28pFl0NFereiomhXi2LLhzhHSiSdHorWHWC8yvd/uNnwutyyv9QMDYLiv8VrqgfeRTxVGa2b/byHzpVzrmmep5mCz3U9CENFSZhBEGP6L4fcLIwfpDnWSC/qrShybQX1FBUB/Iw0vqoUW6r/syjY7VPvY9GDbyNzwyuugNw3BhmrsMklGnW5y6EuMN3gSpq1xKX4VCHwsU5zetwDDoDGWDlzFtVA2UJwf MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 18bc91d8-529d-49d7-3928-08d798211e40 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jan 2020 12:07:10.0284 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: sPk5g9MYEL2o37BAehyysHgVTPfwl/kUumbV54amTU4J8b7gU4ltjrDolYFLBngzklM46CHApk1nNE7aV1J7/gzri1rGBZbUpdztp89CiRA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1498 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Eugen Hristev This change will allow the at91-sama5d2_adc driver to use other triggers than it's own. In particular, tested with the sysfs trigger. To be able to achieve this functionality, some changes were required: 1) Do not enable/disable channels when enabling/disabling the trigger. This is because the trigger is enabled/disabled only for our trigger (obviously). We need channels enabled/disabled regardless of what trigger is being used. 2) Cope with DMA : DMA cannot be used when using another type of trigger. Other triggers work through pollfunc, so we get polled anyway on every trigger. Thus we have to obtain data at every trigger. 3) When to start conversion? The usual pollfunc (store time from subsystem) would be in hard irq and this would be a good way, but current iio subsystem recommends to have it in the threaded irq. Thus adding software start code in this handler. 4) Buffer config: we need to setup buffer regardless of our own device's trigger. We may get one attached later. 5) IRQ handling: we use our own device IRQ only if it's our own trigger and we do not use DMA . If we use DMA, we use the DMA controller's IRQ. Signed-off-by: Eugen Hristev --- Changes in v2: - adapt to the situation of having the previous two patches ahead in the series drivers/iio/adc/at91-sama5d2_adc.c | 140 +++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 67 deletions(-) diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c index 454a493..34df043 100644 --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c @@ -728,7 +728,6 @@ static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) struct iio_dev *indio = iio_trigger_get_drvdata(trig); struct at91_adc_state *st = iio_priv(indio); u32 status = at91_adc_readl(st, AT91_SAMA5D2_TRGR); - u8 bit; /* clear TRGMOD */ status &= ~AT91_SAMA5D2_TRGR_TRGMOD_MASK; @@ -739,45 +738,6 @@ static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) /* set/unset hw trigger */ at91_adc_writel(st, AT91_SAMA5D2_TRGR, status); - for_each_set_bit(bit, indio->active_scan_mask, indio->num_channels) { - struct iio_chan_spec const *chan = at91_adc_chan_get(indio, bit); - u32 cor; - - if (!chan) - continue; - /* these channel types cannot be handled by this trigger */ - if (chan->type == IIO_POSITIONRELATIVE || - chan->type == IIO_PRESSURE) - continue; - - if (state) { - cor = at91_adc_readl(st, AT91_SAMA5D2_COR); - - if (chan->differential) - cor |= (BIT(chan->channel) | - BIT(chan->channel2)) << - AT91_SAMA5D2_COR_DIFF_OFFSET; - else - cor &= ~(BIT(chan->channel) << - AT91_SAMA5D2_COR_DIFF_OFFSET); - - at91_adc_writel(st, AT91_SAMA5D2_COR, cor); - } - - if (state) - at91_adc_writel(st, AT91_SAMA5D2_CHER, - BIT(chan->channel)); - else - at91_adc_writel(st, AT91_SAMA5D2_CHDR, - BIT(chan->channel)); - } - /* enable irq only if not using DMA */ - if (state && !st->dma_st.dma_chan) - at91_adc_writel(st, AT91_SAMA5D2_IER, AT91_SAMA5D2_IER_DRDY); - /* disable irq only if not using DMA */ - if (!state && !st->dma_st.dma_chan) - at91_adc_writel(st, AT91_SAMA5D2_IDR, AT91_SAMA5D2_IER_DRDY); - return 0; } @@ -901,9 +861,22 @@ static int at91_adc_dma_start(struct iio_dev *indio_dev) return 0; } +static bool at91_adc_buffer_check_use_irq(struct iio_dev *indio, + struct at91_adc_state *st) +{ + /* if using DMA, we do not use our own IRQ (we use DMA-controller) */ + if (st->dma_st.dma_chan) + return false; + /* if the trigger is not ours, then it has its own IRQ */ + if (iio_trigger_validate_own_device(indio->trig, indio)) + return false; + return true; +} + static int at91_adc_buffer_postenable(struct iio_dev *indio_dev) { int ret; + u8 bit; struct at91_adc_state *st = iio_priv(indio_dev); /* check if we are enabling triggered buffer or the touchscreen */ @@ -921,9 +894,40 @@ static int at91_adc_buffer_postenable(struct iio_dev *indio_dev) ret = at91_adc_dma_start(indio_dev); if (ret) { dev_err(&indio_dev->dev, "buffer postenable failed\n"); + iio_triggered_buffer_predisable(indio_dev); return ret; } + for_each_set_bit(bit, indio_dev->active_scan_mask, + indio_dev->num_channels) { + struct iio_chan_spec const *chan = + at91_adc_chan_get(indio_dev, bit); + u32 cor; + + if (!chan) + continue; + /* these channel types cannot be handled by this trigger */ + if (chan->type == IIO_POSITIONRELATIVE || + chan->type == IIO_PRESSURE) + continue; + + cor = at91_adc_readl(st, AT91_SAMA5D2_COR); + + if (chan->differential) + cor |= (BIT(chan->channel) | BIT(chan->channel2)) << + AT91_SAMA5D2_COR_DIFF_OFFSET; + else + cor &= ~(BIT(chan->channel) << + AT91_SAMA5D2_COR_DIFF_OFFSET); + + at91_adc_writel(st, AT91_SAMA5D2_COR, cor); + + at91_adc_writel(st, AT91_SAMA5D2_CHER, BIT(chan->channel)); + } + + if (at91_adc_buffer_check_use_irq(indio_dev, st)) + at91_adc_writel(st, AT91_SAMA5D2_IER, AT91_SAMA5D2_IER_DRDY); + return iio_triggered_buffer_postenable(indio_dev); } @@ -944,21 +948,11 @@ static int at91_adc_buffer_predisable(struct iio_dev *indio_dev) if (!(indio_dev->currentmode & INDIO_ALL_TRIGGERED_MODES)) return -EINVAL; - /* continue with the triggered buffer */ - ret = iio_triggered_buffer_predisable(indio_dev); - if (ret < 0) - dev_err(&indio_dev->dev, "buffer predisable failed\n"); - - if (!st->dma_st.dma_chan) - return ret; - - /* if we are using DMA we must clear registers and end DMA */ - dmaengine_terminate_sync(st->dma_st.dma_chan); - /* - * For each enabled channel we must read the last converted value + * For each enable channel we must disable it in hardware. + * In the case of DMA, we must read the last converted value * to clear EOC status and not get a possible interrupt later. - * This value is being read by DMA from LCDR anyway + * This value is being read by DMA from LCDR anyway, so it's not lost. */ for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev->num_channels) { @@ -971,12 +965,28 @@ static int at91_adc_buffer_predisable(struct iio_dev *indio_dev) if (chan->type == IIO_POSITIONRELATIVE || chan->type == IIO_PRESSURE) continue; + + at91_adc_writel(st, AT91_SAMA5D2_CHDR, BIT(chan->channel)); + if (st->dma_st.dma_chan) at91_adc_readl(st, chan->address); } + if (at91_adc_buffer_check_use_irq(indio_dev, st)) + at91_adc_writel(st, AT91_SAMA5D2_IDR, AT91_SAMA5D2_IER_DRDY); + /* read overflow register to clear possible overflow status */ at91_adc_readl(st, AT91_SAMA5D2_OVER); + + /* continue with the triggered buffer */ + ret = iio_triggered_buffer_predisable(indio_dev); + if (ret < 0) + dev_err(&indio_dev->dev, "buffer predisable failed\n"); + + /* if we are using DMA we must clear registers and end DMA */ + if (st->dma_st.dma_chan) + dmaengine_terminate_sync(st->dma_st.dma_chan); + return ret; } @@ -1131,6 +1141,13 @@ static irqreturn_t at91_adc_trigger_handler(int irq, void *p) struct iio_dev *indio_dev = pf->indio_dev; struct at91_adc_state *st = iio_priv(indio_dev); + /* + * If it's not our trigger, start a conversion now, as we are + * actually polling the trigger now. + */ + if (iio_trigger_validate_own_device(indio_dev->trig, indio_dev)) + at91_adc_writel(st, AT91_SAMA5D2_CR, AT91_SAMA5D2_CR_START); + if (st->dma_st.dma_chan) at91_adc_trigger_handler_dma(indio_dev); else @@ -1143,20 +1160,9 @@ static irqreturn_t at91_adc_trigger_handler(int irq, void *p) static int at91_adc_buffer_init(struct iio_dev *indio) { - struct at91_adc_state *st = iio_priv(indio); - - if (st->selected_trig->hw_trig) { - return devm_iio_triggered_buffer_setup(&indio->dev, indio, - &iio_pollfunc_store_time, - &at91_adc_trigger_handler, &at91_buffer_setup_ops); - } - /* - * we need to prepare the buffer ops in case we will get - * another buffer attached (like a callback buffer for the touchscreen) - */ - indio->setup_ops = &at91_buffer_setup_ops; - - return 0; + return devm_iio_triggered_buffer_setup(&indio->dev, indio, + &iio_pollfunc_store_time, + &at91_adc_trigger_handler, &at91_buffer_setup_ops); } static unsigned at91_adc_startup_time(unsigned startup_time_min,