From patchwork Thu Mar 27 15:05:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3898131 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A63E39F2B6 for ; Thu, 27 Mar 2014 15:06:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D43F920225 for ; Thu, 27 Mar 2014 15:06:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0180F20203 for ; Thu, 27 Mar 2014 15:06:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754594AbaC0PGR (ORCPT ); Thu, 27 Mar 2014 11:06:17 -0400 Received: from mail-pd0-f179.google.com ([209.85.192.179]:52128 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753304AbaC0PGR (ORCPT ); Thu, 27 Mar 2014 11:06:17 -0400 Received: by mail-pd0-f179.google.com with SMTP id w10so3494364pde.10 for ; Thu, 27 Mar 2014 08:06:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:content-type :mime-version:content-transfer-encoding; bh=cGmA4izLFtDIvTJwyBV0uCIt84LymXilNPxjFjyRmQc=; b=RYnm1fLKD5VSpmOCMOu0TYpb9R7mp/0rOTwOE8sJB58UoaR2Fm079clBYeZwN4EaV+ P94MMzypy8rGB8qTdVmTLvifhhqvjRrjN/6OVf8AF6U5aPlp92UCAv4rdyv9CeZYcbCe qVSciUQTK9ddtM2I45MBHrJ09aVV6e3qIIgDNXAsWqHWTzIxWmd9JjzL84D8sKGWSnEr 5eM732XYbLKtaGboeHG4Swizd7VgKu4vghTFwozQx2yfH3v1PeZRiU9gFs/gAMGWC+sv Wv4SmNAITE77BiEfFF5zr7CSgj40oty0CQO2e5C/xWOM2tJQrkw6eghoeYdnEFshulC5 ILZA== X-Gm-Message-State: ALoCoQlCysTlAJK+jBKpqgQbt9I27wNhG0RpAuHcwKqwjPcAvlvBSHUtZY4uw8Y8NIaBdx86zSrO X-Received: by 10.66.153.80 with SMTP id ve16mr2237406pab.143.1395932776031; Thu, 27 Mar 2014 08:06:16 -0700 (PDT) Received: from [10.145.55.57] ([60.245.65.194]) by mx.google.com with ESMTPSA id sy2sm10128086pbc.28.2014.03.27.08.06.07 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 27 Mar 2014 08:06:14 -0700 (PDT) Message-ID: <1395932757.17331.1.camel@phoenix> Subject: [PATCH RFT] spi: mpc512x-psc: Refactor to use core message parsing From: Axel Lin To: Mark Brown Cc: Gerhard Sittig , Anatolij Gustschin , linux-spi@vger.kernel.org Date: Thu, 27 Mar 2014 23:05:57 +0800 X-Mailer: Evolution 3.8.4-0ubuntu1 Mime-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Refactor to use default implementation of transfer_one_message() which provides standard handling of delays and chip select management. Signed-off-by: Axel Lin --- Hi Gerhard and Anatolij, I don't have this h/w. I'd appreciate if you can test this patch. Thanks, Axel drivers/spi/spi-mpc512x-psc.c | 58 +++++++++++++------------------------------ 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c index 3822eef..a944769 100644 --- a/drivers/spi/spi-mpc512x-psc.c +++ b/drivers/spi/spi-mpc512x-psc.c @@ -265,50 +265,25 @@ static int mpc512x_psc_spi_transfer_rxtx(struct spi_device *spi, return 0; } -static int mpc512x_psc_spi_msg_xfer(struct spi_master *master, - struct spi_message *m) +static void mpc512x_psc_spi_set_cs(struct spi_device *spi, bool enable) { - struct spi_device *spi; - unsigned cs_change; - int status; - struct spi_transfer *t; - - spi = m->spi; - cs_change = 1; - status = 0; - list_for_each_entry(t, &m->transfers, transfer_list) { - if (t->bits_per_word || t->speed_hz) { - status = mpc512x_psc_spi_transfer_setup(spi, t); - if (status < 0) - break; - } - - if (cs_change) - mpc512x_psc_spi_activate_cs(spi); - cs_change = t->cs_change; - - status = mpc512x_psc_spi_transfer_rxtx(spi, t); - if (status) - break; - m->actual_length += t->len; - - if (t->delay_usecs) - udelay(t->delay_usecs); - - if (cs_change) - mpc512x_psc_spi_deactivate_cs(spi); - } - - m->status = status; - m->complete(m->context); - - if (status || !cs_change) + if (enable) + mpc512x_psc_spi_activate_cs(spi); + else mpc512x_psc_spi_deactivate_cs(spi); +} + +static int mpc51x_psc_spi_transfer_one(struct spi_master *master, + struct spi_device *spi, + struct spi_transfer *t) +{ + int status; - mpc512x_psc_spi_transfer_setup(spi, NULL); + status = mpc512x_psc_spi_transfer_setup(spi, t); + if (status < 0) + return status; - spi_finalize_current_message(master); - return status; + return mpc512x_psc_spi_transfer_rxtx(spi, t); } static int mpc512x_psc_spi_prep_xfer_hw(struct spi_master *master) @@ -494,7 +469,8 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST; master->setup = mpc512x_psc_spi_setup; master->prepare_transfer_hardware = mpc512x_psc_spi_prep_xfer_hw; - master->transfer_one_message = mpc512x_psc_spi_msg_xfer; + master->set_cs = mpc512x_psc_spi_set_cs; + master->transfer_one = mpc51x_psc_spi_transfer_one; master->unprepare_transfer_hardware = mpc512x_psc_spi_unprep_xfer_hw; master->cleanup = mpc512x_psc_spi_cleanup; master->dev.of_node = dev->of_node;