From patchwork Wed Oct 11 06:35:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 824242 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yBkqf0MRbz9t7X for ; Wed, 11 Oct 2017 17:39:58 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755430AbdJKGib (ORCPT ); Wed, 11 Oct 2017 02:38:31 -0400 Received: from esa4.microchip.iphmx.com ([68.232.154.123]:31561 "EHLO esa4.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750766AbdJKGia (ORCPT ); Wed, 11 Oct 2017 02:38:30 -0400 X-IronPort-AV: E=Sophos;i="5.43,360,1503385200"; d="scan'208";a="7573945" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 10 Oct 2017 23:38:29 -0700 Received: from eh-station.mchp-main.com (10.10.76.4) by chn-sv-exch06.mchp-main.com (10.10.76.107) with Microsoft SMTP Server id 14.3.352.0; Tue, 10 Oct 2017 23:38:28 -0700 From: Eugen Hristev To: , , , , , , , , CC: Subject: [PATCH v2 0/5] iio: adc: at91-sama5d2_adc: add DMA support Date: Wed, 11 Oct 2017 09:35:27 +0300 Message-ID: <1507703732-29175-1-git-send-email-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This patch implements the DMA support for the ADC in sama5d2 SoC. After discussing on the mailing list, this approach is based on triggered kfifo buffer, with DMA support added on top of it. Thus, the trigger is enabled by the buffer. The ADC itself will not have an IRQ enabled if using DMA. With DMA, the channels are enabled, and DMA controller is configured to read from the data ready registers. When DMA starts, the trigger will start the conversion (external trigger configured), then the registers will have the conversion data ready, the ADC will trigger the DMA controller to read from the registers, the DMA will copy the data into the software buffer, and trigger the DMA IRQ. In the bottom half, the trigger polled and the data from the DMA buffer is pushed to buffer. The DMA will use a cyclic buffer to write to one half, and the software can read from the other half. The DMA operation doesn't stop until the buffer is disabled. The DMA coherent area is allocated when DMA is initially started, and deallocated only if the watermark is changed to 1 (no more DMA usage). The coherent area is large enough to cope with maximum fifo size for all possible channels enabled. The fifo size is set to 128 conversions by default in the driver. The implementation uses the user watermark to decide whether DMA will be used or not. For watermark 1, DMA will not be used. If watermark is greater, DMA will be used. Sysfs attributes are created to indicate whether the DMA is used, with hwfifo_enabled, and the current DMA watermark is readable in hwfifo_watermark. Minimum and maximum values are in hwfifo_watermark_min and hwfifo_watermark_max. Devicetree binding added for dma as well. Modified devicetree for sama5d2 SoC to add connected DMA channel. A different commit modifies the driver to use the highest ADC clock to demonstrate the capabilities of the DMA support at best sampling rate. A different commit addresses the issue of not clearing the DRDY irq in direct mode. This is required to avoid erroneous overrun warnings. Changes in v2: - No longer add last timestamp to all samples. Now, compute an interval between samples w.r.t. start and end time of the transfer and number of samples. Then distribute them each in the time interval. - Add warning for conversion overrun. This helps user identify cases when the watermark needs adjustment : the software is too slow in reading data from the ADC. - Protection around watermark is not needed, changing of the watermark cannot be done while the buffer is enabled. When buffer is disabled, all DMA resources are freed anyway. - Added validation on trigger to be used by own device - Best sample rate I could obtain using the low frequency clock was about 4k samples/second, with a watermark of 100. To get up to 50k samples/second the ADC frequency must be increased to max. - Addressed other comments from mailing list review. Feedback is appreciated - Added [PATCH v2 4/5] iio: adc: at91-sama5d2_adc: ack DRDY irq in direct - Added [PATCH v2 5/5] iio: adc: at91-sama5d2_adc: use max sample rate Eugen Hristev (5): dt-bindings: iio: at91-sama5d2_adc: add optional dma property ARM: dts: at91: sama5d2: added dma property for ADC device iio: adc: at91-sama5d2_adc: add support for DMA iio: adc: at91-sama5d2_adc: ack DRDY irq in direct mode iio: adc: at91-sama5d2_adc: use max sample rate .../bindings/iio/adc/at91-sama5d2_adc.txt | 7 + arch/arm/boot/dts/sama5d2.dtsi | 2 + drivers/iio/adc/Kconfig | 1 + drivers/iio/adc/at91-sama5d2_adc.c | 437 ++++++++++++++++++++- 4 files changed, 428 insertions(+), 19 deletions(-)