From patchwork Sun Sep 4 00:04:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Seidel X-Patchwork-Id: 9312311 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BACB16075E for ; Sun, 4 Sep 2016 00:23:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A045F288E7 for ; Sun, 4 Sep 2016 00:23:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FCD72891D; Sun, 4 Sep 2016 00:23:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ADB8A288E7 for ; Sun, 4 Sep 2016 00:23:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752139AbcIDAXB (ORCPT ); Sat, 3 Sep 2016 20:23:01 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36640 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752101AbcIDAXB (ORCPT ); Sat, 3 Sep 2016 20:23:01 -0400 Received: by mail-wm0-f67.google.com with SMTP id l65so134028wmf.3 for ; Sat, 03 Sep 2016 17:23:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mseidel-net.20150623.gappssmtp.com; s=20150623; h=sender:date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Cs9ltPy8jSTse7LuX1Lqu4RjCPsUXfW3UImRZvA88Tc=; b=MiAm9dHaXBb0IXBOY0qy4rqyEGn4JDci9ddhJ5gwH6pZMyupK4jpaoedeiV0be5o26 2Y0gHp0Qgjgg/BzScWtw5/jXrLsy8IFFZsoBgoiKDgPmzxjfeC2G0EQfPJSFqeuJ5sIT QUiE+npu94B7hWVd4Z2eVYddQvjBuS6q0pQ3oJfkx0QvnlLhYcRlfC4ktJ+B7ruSodRG PnIenSMl4MAR6rFUNCHxXkwz9ITKdlvtkzeguQDpxJJ2yvGNU+RYMQDRyv1QswTaFUsr dL7C5WxOPcQAUPc+R0N6dSY7plry52c8ytH5+L/fs5uvswUJl6xIYwyRZxMWDuCk2o1u rMsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Cs9ltPy8jSTse7LuX1Lqu4RjCPsUXfW3UImRZvA88Tc=; b=WdRSxnrOoQX94sV4v2EmrqxermbVD5JjJxv84y96l7eHl5JXCmi48jVgJDLGdZz048 bkNaRC2wiCKe5P+yU9cF/dqGMaZQofTvX34IekyUmmguOmgBPVHWdBt45E0d1WRcyjOb JyiedQmKA0LC4SmRj3VWitFw3MLVlPR1AWXRGLUpqHLv29jwZlPLvERgTU1FxM8U7kuT 1o2feKc+m8HlzqywydCnCliOY96+jza4d7gwxzmYpkCSNOM9wPQdbxi04idl/JkihN3O 8p/0Agp4etJ6Le22m4t2bXq0vENSs4idaRxuQJ4LXF/lb7RQMIFfHFATUFc00hJ7VkUO JYUg== X-Gm-Message-State: AE9vXwNHjmtbJCBXrAuZyDDUw+XfpglNgHa7A3Y46gzucm4pAaxZZ/2zPx2eGgbUCGb59w== X-Received: by 10.28.210.82 with SMTP id j79mr8828772wmg.10.1472947497656; Sat, 03 Sep 2016 17:04:57 -0700 (PDT) Received: from vm (ip-109-91-124-173.hsi12.unitymediagroup.de. [109.91.124.173]) by smtp.gmail.com with ESMTPSA id bc10sm18060669wjc.32.2016.09.03.17.04.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Sep 2016 17:04:57 -0700 (PDT) Date: Sun, 4 Sep 2016 02:04:49 +0200 From: Matthias Seidel To: Mark Brown Cc: linux-spi@vger.kernel.org Subject: [PATCH v2 1/2] spi: dw: fix multiple slaves with different baudrates Message-ID: <20160904020449.217e13f4@vm> In-Reply-To: <20160903110118.GT3950@sirena.org.uk> References: <84f71116-1c79-6769-d537-860ac6ea0de9@mseidel.net> <20160903110118.GT3950@sirena.org.uk> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add current master clock to dws struct and compare it against the requestedtransfer speed. Update clock divider only if necessary. Signed-off-by: Matthias Seidel --- v2 First time for me, Thunderbird messed up the tabs, sorry. --- The current implementation stores the transfer speed in the chip struct. If there are multiple slaves which need different clock speeds, the clk_div only gets updated the first time for each slave as speed_hz is 0. After that the comparison always shows the transfer-speed to be equal to the chipspeed and the divider is not updated. --- drivers/spi/spi-dw.c | 15 +++++++-------- drivers/spi/spi-dw.h | 1 + 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index c09bb74..c85e4b3 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c @@ -283,7 +283,6 @@ static int dw_spi_transfer_one(struct spi_master *master, struct chip_data *chip = spi_get_ctldata(spi); u8 imask = 0; u16 txlevel = 0; - u16 clk_div; u32 cr0; int ret; @@ -298,13 +297,13 @@ static int dw_spi_transfer_one(struct spi_master *master, spi_enable_chip(dws, 0); /* Handle per transfer options for bpw and speed */ - if (transfer->speed_hz != chip->speed_hz) { - /* clk_div doesn't support odd number */ - clk_div = (dws->max_freq / transfer->speed_hz + 1) & 0xfffe; - - chip->speed_hz = transfer->speed_hz; - chip->clk_div = clk_div; - + if (transfer->speed_hz != dws->current_freq) { + if (transfer->speed_hz != chip->speed_hz) { + /* clk_div doesn't support odd number */ + chip->clk_div = (dws->max_freq / transfer->speed_hz + 1) & 0xfffe; + chip->speed_hz = transfer->speed_hz; + } + dws->current_freq = transfer->speed_hz; spi_set_clk(dws, chip->clk_div); } if (transfer->bits_per_word == 8) { diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h index 61bc3cb..c21ca02 100644 --- a/drivers/spi/spi-dw.h +++ b/drivers/spi/spi-dw.h @@ -123,6 +123,7 @@ struct dw_spi { u8 n_bytes; /* current is a 1/2 bytes op */ u32 dma_width; irqreturn_t (*transfer_handler)(struct dw_spi *dws); + u32 current_freq; /* frequency in hz */ /* DMA info */ int dma_inited;