From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8FCFECE58D for ; Fri, 11 Oct 2019 17:16:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A3E482089F for ; Fri, 11 Oct 2019 17:16:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ibCIyeQZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728685AbfJKRQ5 (ORCPT ); Fri, 11 Oct 2019 13:16:57 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:41400 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728472AbfJKRQ5 (ORCPT ); Fri, 11 Oct 2019 13:16:57 -0400 Received: by mail-ot1-f68.google.com with SMTP id g13so8584360otp.8 for ; Fri, 11 Oct 2019 10:16:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=c54Sf5bdA43HxJScKIGOKmUhMh5dpQA3LfDJg06NTjU=; b=ibCIyeQZ59aicL/AwiZNtx9IadS7RNmCcWg/spdm5FPHOb2nnW46vpIKW+R4UTEE9/ NABa5WBZPxW8Dh/5I1QYv0/rh/akkCquTPolPaY5g2lzqsVrSTM21DZbMEryR14X3ZG/ 5P0ZQia3WwVQnIDRQMNu+sVwX0gPAwsBlH2ak= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=c54Sf5bdA43HxJScKIGOKmUhMh5dpQA3LfDJg06NTjU=; b=HBV6VdsZUB54RJ+hzCW4sJCu+WtMCNxcbt17/61bPXCuHF/CzK8qHU+knKmUxPTKgq WEGyFu+2RHlHOd58P1b2mdEqDm1RpqhA2VoSKz/no/OIZ6rVAiqlSS0EhnMcptd0HFNp TJ/3PbMXnej+tlU8cytpxtUNlOLBnaZNAFgORkVnWmdxh8BRa3H03SHTUJ6LqtM30018 0BiivbqvX4tLXulaxXqqZGE6OBbXOs1S9UivGAFxVMN/fYh+8EppQPOoBE+8l+6a7RJi 0yq2XwiDaTn348G//d6RM9odwwHb2JACSA1BzRgsgl0sQIZUE64sgFB4T1TTU8dmnzW+ uoFg== X-Gm-Message-State: APjAAAWxghlOBHKSdZ2Ej1gQJ/8TNdrjdCvLT5fqGEXAA6DEWK14HjQc yiYkzbUr62NT+cGJXo/6Y3RS+37DEys= X-Google-Smtp-Source: APXvYqzme/8Bf1mkgPstASva2O/3lFc/FhsX/BKNwah3cztfN3aoRHQX9riOVolUOlGctkGYBCsSiA== X-Received: by 2002:a9d:4619:: with SMTP id y25mr13749835ote.68.1570814215219; Fri, 11 Oct 2019 10:16:55 -0700 (PDT) Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com. [209.85.167.178]) by smtp.gmail.com with ESMTPSA id w13sm2757751oih.54.2019.10.11.10.16.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Oct 2019 10:16:55 -0700 (PDT) Received: by mail-oi1-f178.google.com with SMTP id a15so8656158oic.0 for ; Fri, 11 Oct 2019 10:16:54 -0700 (PDT) X-Received: by 2002:aca:4c91:: with SMTP id z139mr12855041oia.171.1570814213895; Fri, 11 Oct 2019 10:16:53 -0700 (PDT) MIME-Version: 1.0 References: <20191008161749.1.I4476e6e2b1026ff388eb11813310264e25aa9cc9@changeid> <8a4d9abb-7230-7e65-ceb7-e2983c8486cc@collabora.com> In-Reply-To: <8a4d9abb-7230-7e65-ceb7-e2983c8486cc@collabora.com> From: Nick Crews Date: Fri, 11 Oct 2019 11:16:42 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4] wilco_ec: Add Dell's USB PowerShare Policy control To: Enric Balletbo i Serra Cc: Daniel Campello , LKML , Benson Leung , Raul E Rangel 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 Many thanks Enric! On Fri, Oct 11, 2019 at 9:08 AM Enric Balletbo i Serra wrote: > > Hi Daniel, Nick > > On 9/10/19 17:00, Nick Crews wrote: > > On Tue, Oct 8, 2019 at 4:18 PM Daniel Campello wrote: > >> > >> USB PowerShare is a policy which affects charging via the special > >> USB PowerShare port (marked with a small lightning bolt or battery icon) > >> when in low power states: > >> - In S0, the port will always provide power. > >> - In S0ix, if usb_charge is enabled, then power will be supplied to > >> the port when on AC or if battery is > 50%. Else no power is supplied. > >> - In S5, if usb_charge is enabled, then power will be supplied to > >> the port when on AC. Else no power is supplied. > >> > >> Signed-off-by: Daniel Campello > >> Signed-off-by: Nick Crews > >> --- > >> > >> v4 changes: > >> - Renamed from usb_power_share to usb_charge to match existing feature > >> in other platforms in the kernel (i.e., sony-laptop, samsung-laptop, > >> lg-laptop) > > > > Daniel and I put in considerable effort trying to get this integrated > > with the USB subsystem. However, it was becoming much too > > complicated, so we hoped that if we made this more consistent > > with the three existing examples it would be acceptable. > > > > Agree, let's land as is for now. Prefixed the patch subject with > "platform/chrome: ", replaced tabs for space in the documentation (to be > coherent with the rest of the file) and queued for autobuilders to play with. If > all goes well will be applied for 5.5. > > Thanks, > Enric > > > > Thanks for the thoughts, > > Nick > > > >> v3 changes: > >> - Drop a silly blank line > >> - Use val > 1 instead of val != 0 && val != 1 > >> v2 changes: > >> - Move documentation to Documentation/ABI/testing/sysfs-platform-wilco-ec > >> - Zero out reserved bytes in requests. > >> > >> .../ABI/testing/sysfs-platform-wilco-ec | 17 ++++ > >> drivers/platform/chrome/wilco_ec/sysfs.c | 91 +++++++++++++++++++ > >> 2 files changed, 108 insertions(+) > >> > >> diff --git a/Documentation/ABI/testing/sysfs-platform-wilco-ec b/Documentation/ABI/testing/sysfs-platform-wilco-ec > >> index 8827a734f933..bb7ba67cae97 100644 > >> --- a/Documentation/ABI/testing/sysfs-platform-wilco-ec > >> +++ b/Documentation/ABI/testing/sysfs-platform-wilco-ec > >> @@ -31,6 +31,23 @@ Description: > >> Output will a version string be similar to the example below: > >> 08B6 > >> > >> +What: /sys/bus/platform/devices/GOOG000C\:00/usb_charge > >> +Date: October 2019 > >> +KernelVersion: 5.5 > >> +Description: > >> + Control the USB PowerShare Policy. USB PowerShare is a policy > >> + which affects charging via the special USB PowerShare port > >> + (marked with a small lightning bolt or battery icon) when in > >> + low power states: > >> + - In S0, the port will always provide power. > >> + - In S0ix, if usb_charge is enabled, then power will be > >> + supplied to the port when on AC or if battery is > 50%. > >> + Else no power is supplied. > >> + - In S5, if usb_charge is enabled, then power will be supplied > >> + to the port when on AC. Else no power is supplied. > >> + > >> + Input should be either "0" or "1". > >> + > >> What: /sys/bus/platform/devices/GOOG000C\:00/version > >> Date: May 2019 > >> KernelVersion: 5.3 > >> diff --git a/drivers/platform/chrome/wilco_ec/sysfs.c b/drivers/platform/chrome/wilco_ec/sysfs.c > >> index 3b86a21005d3..f0d174b6bb21 100644 > >> --- a/drivers/platform/chrome/wilco_ec/sysfs.c > >> +++ b/drivers/platform/chrome/wilco_ec/sysfs.c > >> @@ -23,6 +23,26 @@ struct boot_on_ac_request { > >> u8 reserved7; > >> } __packed; > >> > >> +#define CMD_USB_CHARGE 0x39 > >> + > >> +enum usb_charge_op { > >> + USB_CHARGE_GET = 0, > >> + USB_CHARGE_SET = 1, > >> +}; > >> + > >> +struct usb_charge_request { > >> + u8 cmd; /* Always CMD_USB_CHARGE */ > >> + u8 reserved; > >> + u8 op; /* One of enum usb_charge_op */ > >> + u8 val; /* When setting, either 0 or 1 */ > >> +} __packed; > >> + > >> +struct usb_charge_response { > >> + u8 reserved; > >> + u8 status; /* Set by EC to 0 on success, other value on failure */ > >> + u8 val; /* When getting, set by EC to either 0 or 1 */ > >> +} __packed; > >> + > >> #define CMD_EC_INFO 0x38 > >> enum get_ec_info_op { > >> CMD_GET_EC_LABEL = 0, > >> @@ -131,12 +151,83 @@ static ssize_t model_number_show(struct device *dev, > >> > >> static DEVICE_ATTR_RO(model_number); > >> > >> +static int send_usb_charge(struct wilco_ec_device *ec, > >> + struct usb_charge_request *rq, > >> + struct usb_charge_response *rs) > >> +{ > >> + struct wilco_ec_message msg; > >> + int ret; > >> + > >> + memset(&msg, 0, sizeof(msg)); > >> + msg.type = WILCO_EC_MSG_LEGACY; > >> + msg.request_data = rq; > >> + msg.request_size = sizeof(*rq); > >> + msg.response_data = rs; > >> + msg.response_size = sizeof(*rs); > >> + ret = wilco_ec_mailbox(ec, &msg); > >> + if (ret < 0) > >> + return ret; > >> + if (rs->status) > >> + return -EIO; > >> + > >> + return 0; > >> +} > >> + > >> +static ssize_t usb_charge_show(struct device *dev, > >> + struct device_attribute *attr, char *buf) > >> +{ > >> + struct wilco_ec_device *ec = dev_get_drvdata(dev); > >> + struct usb_charge_request rq; > >> + struct usb_charge_response rs; > >> + int ret; > >> + > >> + memset(&rq, 0, sizeof(rq)); > >> + rq.cmd = CMD_USB_CHARGE; > >> + rq.op = USB_CHARGE_GET; > >> + > >> + ret = send_usb_charge(ec, &rq, &rs); > >> + if (ret < 0) > >> + return ret; > >> + > >> + return sprintf(buf, "%d\n", rs.val); > >> +} > >> + > >> +static ssize_t usb_charge_store(struct device *dev, > >> + struct device_attribute *attr, > >> + const char *buf, size_t count) > >> +{ > >> + struct wilco_ec_device *ec = dev_get_drvdata(dev); > >> + struct usb_charge_request rq; > >> + struct usb_charge_response rs; > >> + int ret; > >> + u8 val; > >> + > >> + ret = kstrtou8(buf, 10, &val); > >> + if (ret < 0) > >> + return ret; > >> + if (val > 1) > >> + return -EINVAL; > >> + > >> + memset(&rq, 0, sizeof(rq)); > >> + rq.cmd = CMD_USB_CHARGE; > >> + rq.op = USB_CHARGE_SET; > >> + rq.val = val; > >> + > >> + ret = send_usb_charge(ec, &rq, &rs); > >> + if (ret < 0) > >> + return ret; > >> + > >> + return count; > >> +} > >> + > >> +static DEVICE_ATTR_RW(usb_charge); > >> > >> static struct attribute *wilco_dev_attrs[] = { > >> &dev_attr_boot_on_ac.attr, > >> &dev_attr_build_date.attr, > >> &dev_attr_build_revision.attr, > >> &dev_attr_model_number.attr, > >> + &dev_attr_usb_charge.attr, > >> &dev_attr_version.attr, > >> NULL, > >> }; > >> -- > >> 2.23.0.581.g78d2f28ef7-goog > >>