From patchwork Mon Feb 12 05:15:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 127923 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp2878685ljc; Sun, 11 Feb 2018 21:16:52 -0800 (PST) X-Google-Smtp-Source: AH8x226XdBwsPF/5YeI1GKCXpVXsfctAuC7FrwovoPDeCC9aAvGMxzmrzsrRhhgObT6mXcRO5cg0 X-Received: by 10.99.97.211 with SMTP id v202mr8368041pgb.193.1518412612610; Sun, 11 Feb 2018 21:16:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518412612; cv=none; d=google.com; s=arc-20160816; b=R+fb9AzPbbcduM16BU09xLOmjoP/1G3q+Q7VTvqYhI38tDQfF80LyngGjOaBu6lCBL yLMaw61Dva/wVE2C/bp0M4aKxxlPw47iXWrxvkJQxB5S2+rx17K0zG6Lq7qK+S7324Z1 UMkxAMdtiJwYky/XKLvGuYQEA7wEFDjzcMlNDj00JwYQcLhk1n6SfUxVPjI3kkmiLD9k gMVpPrBlsOM9ViGqBISL2SFpDbZiOITd/HtJtrTV34CNIGMnw3C8e50duHFwyzzz8RHw pL8oO+dCo2LbpdKzHZr2DpHoeNPdQx7zDBT938qUyk5+96EpYO0PW17hr2s0issVzbhz TSUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=uYtq4eCpeJZw90RqiXOLUxaA9pm0b4nxqHFXVsUEChE=; b=lmpfjxJGq+eo5DB3UzCRTIBdGBdLXF/pu+TAfBoRIay0oRu8erXrISx8aihABxnNJO cVhN6LJ6PGS3dcnk0SmXvVmgcl0oFopi0YXCp8AtUzu2jlYMpJfUNw1547fv1K4ev28K 7sSNIDxoeRloT8g+94t6h20nU4PcISnBCc+jd8+kLsJZEyAl3S10r/Wm04JjMCwWUQ4G Nsk5vib5GPLby++tlnrnBHKwfUEEIqaUOwgIQ5phBXzONCiiUBH3+VoG5gjVtz4I0j74 BZJVD2XZ8r47HserlX0YwJnWSdhKQ4qe0OBN6SZ8NhE/KXDzCzKO3SdbHo5XvXhHtiNE hslw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=t9QAqrAi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q75si5779712pfq.220.2018.02.11.21.16.52; Sun, 11 Feb 2018 21:16:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=t9QAqrAi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753825AbeBLFQr (ORCPT + 13 others); Mon, 12 Feb 2018 00:16:47 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:45251 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751263AbeBLFQk (ORCPT ); Mon, 12 Feb 2018 00:16:40 -0500 Received: by mail-pl0-f65.google.com with SMTP id p5so4533586plo.12; Sun, 11 Feb 2018 21:16:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=uYtq4eCpeJZw90RqiXOLUxaA9pm0b4nxqHFXVsUEChE=; b=t9QAqrAiL9pQBEcT2y3Nq9X03ZS4xtJivZ+fRmG2JfBGwAd4EOnYpfxCBwV354wxpB PYro+T8Utkhy0P/+ncjEzyFDfD5zgoy58uYJSRzi2z8qQo2ZKKUbEGDIWLddHIWyssvy WXAdP/32RI1LHWZ95iE3IK1dKWDF6LKD7/ZAMRECCTezUb9TSVA2gkP76JX41cEZacwh VyxNfyvSL5FAMvfrKMBcQnBrglEH+JWOcw9IciyztQgk66Z3JaPc+nirGxg7Ezl/sy+K L0VcJy+NNKKh9BygN6PKtL43vqBcZI7zzFRl6M8KbCI1u9nGffS4gCSkMV5JUDCV3lkq yJIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=uYtq4eCpeJZw90RqiXOLUxaA9pm0b4nxqHFXVsUEChE=; b=l8EsRJt18ff0yoMEwDafmak7CFT2WOoYvhXAUfh+JMtIRw8reB1W24CxI4hmIJo3WO nabpjlanuJfaZZznsLD9RsfHc4//eNN/sLjt/y2mJGMdEKkgoxpldO/8PsrUGsCaD97N avnjjwTBy7aKC6Bg5JLkF1/ST+0irrF0r87B3HmtchFckYIluVdiv0HM+7M0ipBsd6j2 fAUEiKyI0dyb63PwwtHG9p8IdP8+mGKTy6uHUyvBND1QT7b++QgAqrdJq/KWSBD/fHc0 tqIdzSx+GvA7J5DpqJtVEdcEB1rlgaW7YzgtUEGGUzupvp7KKaZhDkjIbtU5rvf+joYw 7ZQA== X-Gm-Message-State: APf1xPAPRRVfssnfa5ivPlxLd0cLnhbaC6bxjbGaZ8xNZqO5lKrs5ZZT zYcMiK8dFXFhoC9kg/SJFNQ= X-Received: by 2002:a17:902:14b:: with SMTP id 69-v6mr9891282plb.209.1518412599950; Sun, 11 Feb 2018 21:16:39 -0800 (PST) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id e12sm21661068pgu.48.2018.02.11.21.16.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 11 Feb 2018 21:16:39 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Mon, 12 Feb 2018 15:46:31 +1030 From: Joel Stanley To: Greg Kroah-Hartman , Rob Herring , Mark Rutland Cc: Jeremy Kerr , Christopher Bostic , Brad Bishop , Edward James , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 03/10] fsi: master-gpio: Add external mode Date: Mon, 12 Feb 2018 15:45:42 +1030 Message-Id: <20180212051549.8575-4-joel@jms.id.au> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180212051549.8575-1-joel@jms.id.au> References: <20180212051549.8575-1-joel@jms.id.au> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jeremy Kerr This change introduces an 'external mode' for GPIO-based FSI masters, allowing the clock and data lines to be driven by an external source. For example, external mode is selected by a user when an external debug device is attached to the FSI pins. To do this, we need to set specific states for the trans, mux and enable GPIOs, and prevent access to clk & data from the FSI core code (by returning EBUSY). External mode is controlled by a sysfs attribute, so add the relevant information to Documentation/ABI/ Signed-off-by: Jeremy Kerr Reviewed-by: Joel Stanley Signed-off-by: Joel Stanley --- .../ABI/testing/sysfs-driver-fsi-master-gpio | 10 +++ drivers/fsi/fsi-master-gpio.c | 78 +++++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-fsi-master-gpio -- 2.15.1 diff --git a/Documentation/ABI/testing/sysfs-driver-fsi-master-gpio b/Documentation/ABI/testing/sysfs-driver-fsi-master-gpio new file mode 100644 index 000000000000..1f29c8843cfd --- /dev/null +++ b/Documentation/ABI/testing/sysfs-driver-fsi-master-gpio @@ -0,0 +1,10 @@ +What: /sys/bus/platform/devices/[..]/fsi-master-gpio/external_mode +Date: Feb 2018 +KernelVersion: 4.17 +Contact: jk@ozlabs.org +Description: + Controls access arbitration for GPIO-based FSI master. A + value of 0 (the default) sets normal mode, where the + driver performs FSI bus transactions, 1 sets external mode, + where the FSI bus is driven externally (for example, by + a debug device). diff --git a/drivers/fsi/fsi-master-gpio.c b/drivers/fsi/fsi-master-gpio.c index a6d602e89c11..b54c213f3dcb 100644 --- a/drivers/fsi/fsi-master-gpio.c +++ b/drivers/fsi/fsi-master-gpio.c @@ -59,6 +59,7 @@ struct fsi_master_gpio { struct gpio_desc *gpio_trans; /* Voltage translator */ struct gpio_desc *gpio_enable; /* FSI enable */ struct gpio_desc *gpio_mux; /* Mux control */ + bool external_mode; }; #define CREATE_TRACE_POINTS @@ -411,6 +412,12 @@ static int fsi_master_gpio_xfer(struct fsi_master_gpio *master, uint8_t slave, int rc; spin_lock_irqsave(&master->cmd_lock, flags); + + if (master->external_mode) { + spin_unlock_irqrestore(&master->cmd_lock, flags); + return -EBUSY; + } + serial_out(master, cmd); echo_delay(master); rc = poll_for_response(master, slave, resp_len, resp); @@ -469,6 +476,10 @@ static int fsi_master_gpio_break(struct fsi_master *_master, int link) trace_fsi_master_gpio_break(master); spin_lock_irqsave(&master->cmd_lock, flags); + if (master->external_mode) { + spin_unlock_irqrestore(&master->cmd_lock, flags); + return -EBUSY; + } set_sda_output(master, 1); sda_out(master, 1); clock_toggle(master, FSI_PRE_BREAK_CLOCKS); @@ -497,25 +508,84 @@ static void fsi_master_gpio_init(struct fsi_master_gpio *master) clock_zeros(master, FSI_INIT_CLOCKS); } +static void fsi_master_gpio_init_external(struct fsi_master_gpio *master) +{ + gpiod_direction_output(master->gpio_mux, 0); + gpiod_direction_output(master->gpio_trans, 0); + gpiod_direction_output(master->gpio_enable, 1); + gpiod_direction_input(master->gpio_clk); + gpiod_direction_input(master->gpio_data); +} + static int fsi_master_gpio_link_enable(struct fsi_master *_master, int link) { struct fsi_master_gpio *master = to_fsi_master_gpio(_master); unsigned long flags; + int rc = -EBUSY; if (link != 0) return -ENODEV; spin_lock_irqsave(&master->cmd_lock, flags); - gpiod_set_value(master->gpio_enable, 1); + if (!master->external_mode) { + gpiod_set_value(master->gpio_enable, 1); + rc = 0; + } spin_unlock_irqrestore(&master->cmd_lock, flags); - return 0; + return rc; +} + +static ssize_t external_mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct fsi_master_gpio *master = dev_get_drvdata(dev); + + return snprintf(buf, PAGE_SIZE - 1, "%u\n", + master->external_mode ? 1 : 0); +} + +static ssize_t external_mode_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct fsi_master_gpio *master = dev_get_drvdata(dev); + unsigned long flags, val; + bool external_mode; + int err; + + err = kstrtoul(buf, 0, &val); + if (err) + return err; + + external_mode = !!val; + + spin_lock_irqsave(&master->cmd_lock, flags); + + if (external_mode == master->external_mode) { + spin_unlock_irqrestore(&master->cmd_lock, flags); + return count; + } + + master->external_mode = external_mode; + if (master->external_mode) + fsi_master_gpio_init_external(master); + else + fsi_master_gpio_init(master); + spin_unlock_irqrestore(&master->cmd_lock, flags); + + fsi_master_rescan(&master->master); + + return count; } +static DEVICE_ATTR(external_mode, 0664, + external_mode_show, external_mode_store); + static int fsi_master_gpio_probe(struct platform_device *pdev) { struct fsi_master_gpio *master; struct gpio_desc *gpio; + int rc; master = devm_kzalloc(&pdev->dev, sizeof(*master), GFP_KERNEL); if (!master) @@ -572,6 +642,10 @@ static int fsi_master_gpio_probe(struct platform_device *pdev) fsi_master_gpio_init(master); + rc = device_create_file(&pdev->dev, &dev_attr_external_mode); + if (rc) + return rc; + return fsi_master_register(&master->master); }