Received: by 10.223.176.5 with SMTP id f5csp3830771wra; Mon, 29 Jan 2018 20:46:13 -0800 (PST) X-Google-Smtp-Source: AH8x224SQgUqsE52oz0VUFj128crZTWzvaJglJXu9StRVqPqB0gW3AG8XBFP2Z2d1dkBBeAOUJsQ X-Received: by 10.99.180.6 with SMTP id s6mr22186365pgf.5.1517287573035; Mon, 29 Jan 2018 20:46:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517287573; cv=none; d=google.com; s=arc-20160816; b=taT9WvXw7sMsnuoDswHMmU9RsTorl1bCzWhG5rBI4pZObEfOborPl7F6e9QbTO6Fhu 74NFZnpbhlrJmMJmZ1UZKybZVpHOP8wD7lJm1V4STtkIaPYNnsL0tenAXYcA5zhkqWzc TkGmltJp+Alku5P/yJAizDrpkp2MR6qxZl43FJQ8VL2LF92fHuRQAG5Q9o3g0Y+1+p13 qQmG9ktvsuEZ70BZ+0LhQdRKNDSYdtnOIpRrZODscdbnOPNe5dS/4H7kw51parubqKgF LJaYDCk87aNF6g6Gjo56KAK+B22Hl77JpJFlUX8UoRGLwUhJ1p0iAZ51t+AQsoe5kfwE 0ObQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=Hg4HJPIoTM+im+0kSS02rbJOBvk7rcthQRcnxYKAfH4=; b=X4K/MFMaHG2fA5Iai/TrnLNM9TKjcUezfxd/FyGg+G5HQlTQR3lsCoIdNONRWHKnEL WyhbBWM1qfL8Li5NiGW8kBdmkW6CEhVE9K0SHTesPPOzpDbrAnEWV51gOKvUdq3z5jQh Gc9F8tJOyQ8feubQw06xLqrmoVULhOEy6PqGcKbxv6l16BKxKfyQaN4E9jVtoSd3rkaq VOz/EPy37p07AmXln+jjIOPPg3/yfkHAMiMLN2pMyMr0BhoXr7Xs7uvfepmM+avsuDFF LWukZbdCU9YWz4ftF3U27Pd8LayFAkEe9Xz+PVkXQ4RGMLqPnMy2YNKIOVuOZVixiEXX b25w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=X1wwKhds; 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 i8-v6si3119736plr.97.2018.01.29.20.45.58; Mon, 29 Jan 2018 20:46:13 -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=X1wwKhds; 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 S1752652AbeA3Epf (ORCPT + 99 others); Mon, 29 Jan 2018 23:45:35 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:33021 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752076AbeA3Epd (ORCPT ); Mon, 29 Jan 2018 23:45:33 -0500 Received: by mail-qk0-f196.google.com with SMTP id i141so8579630qke.0 for ; Mon, 29 Jan 2018 20:45:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=Hg4HJPIoTM+im+0kSS02rbJOBvk7rcthQRcnxYKAfH4=; b=X1wwKhdscFmFOT6eNUwlD9KFLpaVeorcfgPeJ40SecZmRPfmig+5aA5FHEcTaz1tDf q9RfjLCulrF+YyvQg2FeTIxSNrxSiE+o4d5m9yw/5lHHqRZF8to25/VGtxLkJTYI5euG 4Vrq2QJ06BNkRkK3sAbIph90s7fSeG1dBDc749gGEx3CGHFiyttRq/3lEh3hAh8bUlq+ YHHaO/4TOPDneEf+81UQyLBkZKc1F7TBw+G19ZW+pRlERM0ooUtqZ+gVoUfLAxCABDb9 HMc2Ge8vbsQOGqBfKsXW3h3ltuHblT4RTjvty9iBSr76/SF3bsmM/Led1er52TvREmK1 SKXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=Hg4HJPIoTM+im+0kSS02rbJOBvk7rcthQRcnxYKAfH4=; b=aSJQ2aFy0IdKICoiaemRm6Qs1+07fmBdSo3IssfaGUFVGcTYee0MHVj9UFyNzOFCAR k3PHKUDQwB+yqvSNJ5tB6RJ/edeNSUeCbMavjAJ93wmoLR9Abj+b9NGhsDp1iQbth9r7 qdAY7xn+sP/5YaQ9O9KDNYmdJH42k4Ok2yR9mL/Qa06rtBTrWIeQY+ueCRb8Ad5uxx53 cmNFwmuGqbvqrRlSL/jXZLGRrmtPE/bJJkpXxBcnzx9wwNKhNjraOFRUXoK5CNOoGDy0 xSQY1tbUvV6To7JJNK6ncCxmgJW3pc2vGrD7IP7k/HFrEElE0jNghfPl1P5Y9nZbWWJ8 L1xw== X-Gm-Message-State: AKwxyte+cpcZtZw8JZHzayAogP+Gzfyo3PmYV6ikm9PeXXM5Cfk1YijO 5REOTQN4Kf2085XQCXDsvGQn77CsTqVWF3Zi5To= X-Received: by 10.55.217.20 with SMTP id u20mr37880705qki.52.1517287532569; Mon, 29 Jan 2018 20:45:32 -0800 (PST) MIME-Version: 1.0 Received: by 10.200.49.93 with HTTP; Mon, 29 Jan 2018 20:45:12 -0800 (PST) In-Reply-To: <1498083022-24907-1-git-send-email-jk@ozlabs.org> References: <1497864405-26990-4-git-send-email-jk@ozlabs.org> <1498083022-24907-1-git-send-email-jk@ozlabs.org> From: Joel Stanley Date: Tue, 30 Jan 2018 15:15:12 +1030 X-Google-Sender-Auth: KInD0OhBPastgU8qyZsfYz4fI9k Message-ID: Subject: Re: [PATCH v2 3/3] fsi/master-gpio: Add external mode To: Jeremy Kerr Cc: Linux Kernel Mailing List , Christopher Bostic , Greg KH Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jeremy, On Thu, Jun 22, 2017 at 7:40 AM, Jeremy Kerr wrote: > 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 relevent > information to Documentation/ABI/ > > Signed-off-by: Jeremy Kerr > Reviewed-by: Joel Stanley This one never made it into Greg's tree (I assume because we didn't cc him). Can you resend with Greg on cc please? Cheers, Joel > --- > .../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 > > 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 0000000..9667bb4 > --- /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: June 2017 > +KernelVersion: 4.12 > +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 a6d602e..b54c213 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); > } > > -- > 2.7.4 >