Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp7155679ybn; Mon, 30 Sep 2019 09:25:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJJ4v6nUYKp3kvIMbBkfkzeZdHG2wdz7GNEeBDnhOrmLSBWMNuKVFWrbFmP8cuTuQonhgA X-Received: by 2002:a50:eb44:: with SMTP id z4mr20136048edp.207.1569860741205; Mon, 30 Sep 2019 09:25:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569860741; cv=none; d=google.com; s=arc-20160816; b=bNaSiWpBDs6Z3UggZLeDW/yA3zYh7yq1giOgBIrjs8eACpm3b0Xw39JdbMAKeBIVvY zcAm7a08JEX92U6Gww10Z3A3LnMW/PPriGSd/FYWA2cTRJGIlx48ZCxF5lXPGQvg6Aoe hFoz23aTc+z3Bpcg1x898es7TpZYSbcRkNjtsDvN38lQXIPx6jztdYSOz39acyV1iqfO 9kRcAfjgInH+hzem9dDnuFK9zbXkbKhBD/69ZJsrKUCImGMQhACtka4FtfpfIl96tnye +W222tAiIHFog8DB8977fxz2T67CPxYBTflHqPtohi2zMLi60GQx2USfEZieWyFiiu/u txQQ== 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 :in-reply-to:references:mime-version:dkim-signature; bh=pMMecHlbii45iWOZHo2zW6iaJVDnPkjK3dSHl9V+w9k=; b=RMgGFwf05FrGxU09oyVJUR2AHX377gwSKzYVvHjDHuwCCRDJjn/RfLpgd6LHdIJJum NxuXHfkAc6m7A85Oncgvp0SyQ2sYyowzBZYx82c4RKfHI6lPXZ8IhUsDo1/hchRwEqHv xxazghXbV8Sq/rTriFuXtDeOXHu+UJLW9r7c1+7XOV58i25SR+3mp8jIgB6JOSI/i0by +BwifQ45BRhxKovE8RHyGO5MTicG5gaOWKOqVpQbFUz6wqOmEvuc56AiiwxFdMoBw6kD qZtQ+X+7eiYFJQXXp06/M+DTLLLilwgSC7FXvQGrt5y+HxVBWEsF77zGkbdVrGv7lbtG m5cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gxg51sWY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11si7023592ejb.240.2019.09.30.09.25.17; Mon, 30 Sep 2019 09:25:41 -0700 (PDT) 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=pass header.i=@chromium.org header.s=google header.b=gxg51sWY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732259AbfI3QYq (ORCPT + 99 others); Mon, 30 Sep 2019 12:24:46 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:33948 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727767AbfI3QYq (ORCPT ); Mon, 30 Sep 2019 12:24:46 -0400 Received: by mail-io1-f66.google.com with SMTP id q1so39950654ion.1 for ; Mon, 30 Sep 2019 09:24:45 -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=pMMecHlbii45iWOZHo2zW6iaJVDnPkjK3dSHl9V+w9k=; b=gxg51sWYMWs5I+Rs64CCmaLYCptrQXOXaDSFiT6envy1JZaR2Ggqn1tMrfH3/x6wZh nmHLnHuGstb3DY9wlIP9IHKb8Wim8b7I1KVeQjIlNdzzME0Q6ZyNNgdSTt8OOawfFyT2 /ZSC/X8fAZFAxIluTHfm1WpCf5zR1GZNw8fvk= 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=pMMecHlbii45iWOZHo2zW6iaJVDnPkjK3dSHl9V+w9k=; b=iMh0v6H//x+SM5l4rVeKaqiUXRhg4Uuyhyo+TgdfZqbXkn55sfJYWM0+AwfbUa+aop 13BmhWJJG/gOEQfqcvJ1W4Zzv5QfRsLYiGKsZNFbiIJIDj+awzzOxtIn2Kk37HDkU+aE jObGlWSwa3BYX0zh3ToaYRsF1gi0dth0VGqq0bVOznwBiwIIj28317YYaIovqmfWGMic DVINyO+lxbt3CkPr/U9fYfmQVeu5n+27+/fnzCFwQSDmatCuezzHl1eWkWNfuhB0tiD8 XC6OoiWwWNCoy6ThVLdLh+mI/UI+w4WUeFpcsti+/8CiILk40oxgGV9BFoYQZj3+Xq6m kaOA== X-Gm-Message-State: APjAAAU3R00F4Yd53/icRMPOYdSyOZaBUle+cyPYE/47394xV5+IV2VE +I9QAZDbJPHvjAUYklaB+hbeuIn+NDiCwHuiocB0yg== X-Received: by 2002:a6b:5907:: with SMTP id n7mr21653958iob.145.1569860685182; Mon, 30 Sep 2019 09:24:45 -0700 (PDT) MIME-Version: 1.0 References: <20190922175021.53449-1-gwendal@chromium.org> <20190922175021.53449-2-gwendal@chromium.org> <411716b0-818b-9060-7055-8ff9523c0c45@collabora.com> In-Reply-To: <411716b0-818b-9060-7055-8ff9523c0c45@collabora.com> From: Gwendal Grignou Date: Mon, 30 Sep 2019 09:24:34 -0700 Message-ID: Subject: Re: [PATCH 01/13] mfd: cros_ec: Add sensor_count and make check_features public To: Enric Balletbo i Serra Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Lee Jones , Benson Leung , Doug Anderson , Guenter Roeck , Fabien Lahoudere , linux-kernel , linux-iio 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 Sounds good to me, I will make the change in rev2. On Mon, Sep 30, 2019 at 6:15 AM Enric Balletbo i Serra wrote: > > Hi Gwendal, > > Many thanks for the patches. > > On 22/9/19 19:50, Gwendal Grignou wrote: > > Add a new function to return the number of MEMS sensors available in a > > ChromeOS Embedded Controller. > > It uses MOTIONSENSE_CMD_DUMP if available or a specific memory map ACPI > > registers to find out. > > > > Also, make check_features public as it can be useful for other drivers > > to know whant the Embedded Controller supports. > > > > Signed-off-by: Gwendal Grignou > > --- > > drivers/mfd/cros_ec_dev.c | 61 ++++++++++++++++++++++++++++++++++++- > > include/linux/mfd/cros_ec.h | 17 +++++++++++ > > 2 files changed, 77 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c > > index 6e6dfd6c1871..3be80183ccaa 100644 > > --- a/drivers/mfd/cros_ec_dev.c > > +++ b/drivers/mfd/cros_ec_dev.c > > @@ -112,7 +112,7 @@ static const struct mfd_cell cros_ec_vbc_cells[] = { > > { .name = "cros-ec-vbc", } > > }; > > > > -static int cros_ec_check_features(struct cros_ec_dev *ec, int feature) > > +int cros_ec_check_features(struct cros_ec_dev *ec, int feature) > > { > > struct cros_ec_command *msg; > > int ret; > > @@ -143,12 +143,71 @@ static int cros_ec_check_features(struct cros_ec_dev *ec, int feature) > > > > return ec->features[feature / 32] & EC_FEATURE_MASK_0(feature); > > } > > +EXPORT_SYMBOL_GPL(cros_ec_check_features); > > > > static void cros_ec_class_release(struct device *dev) > > { > > kfree(to_cros_ec_dev(dev)); > > } > > > > +int cros_ec_get_sensor_count(struct cros_ec_dev *ec) > > +{ > > + /* > > + * Issue a command to get the number of sensor reported. > > + * If not supported, check for legacy mode. > > + */ > > + int ret, sensor_count; > > + struct ec_params_motion_sense *params; > > + struct ec_response_motion_sense *resp; > > + struct cros_ec_command *msg; > > + struct cros_ec_device *ec_dev = ec->ec_dev; > > + u8 status; > > + > > + msg = kzalloc(sizeof(struct cros_ec_command) + > > + max(sizeof(*params), sizeof(*resp)), GFP_KERNEL); > > + if (msg == NULL) > > + return -ENOMEM; > > + > > + msg->version = 1; > > + msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset; > > + msg->outsize = sizeof(*params); > > + msg->insize = sizeof(*resp); > > + > > + params = (struct ec_params_motion_sense *)msg->data; > > + params->cmd = MOTIONSENSE_CMD_DUMP; > > + > > + ret = cros_ec_cmd_xfer(ec->ec_dev, msg); > > + if (ret < 0) { > > + sensor_count = ret; > > + } else if (msg->result != EC_RES_SUCCESS) { > > + sensor_count = -EPROTO; > > + } else { > > + resp = (struct ec_response_motion_sense *)msg->data; > > + sensor_count = resp->dump.sensor_count; > > + } > > + kfree(msg); > > + > > + /* > > + * Check legacy mode: Let's find out if sensors are accessible > > + * via LPC interface. > > + */ > > + if (sensor_count == -EPROTO && > > + ec->cmd_offset == 0 && > > + ec_dev->cmd_readmem) { > > + ret = ec_dev->cmd_readmem(ec_dev, EC_MEMMAP_ACC_STATUS, > > + 1, &status); > > + if ((ret >= 0) && > > + (status & EC_MEMMAP_ACC_STATUS_PRESENCE_BIT)) { > > + /* > > + * We have 2 sensors, one in the lid, one in the base. > > + */ > > + sensor_count = 2; > > + } > > + } > > + return sensor_count; > > +} > > +EXPORT_SYMBOL_GPL(cros_ec_get_sensor_count); > > + > > static void cros_ec_sensors_register(struct cros_ec_dev *ec) > > { > > /* > > diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h > > index 61c2875c2a40..578e0bbcafdc 100644 > > --- a/include/linux/mfd/cros_ec.h > > +++ b/include/linux/mfd/cros_ec.h > > @@ -32,4 +32,21 @@ struct cros_ec_dev { > > > > #define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev) > > > > +/** > > + * cros_ec_check_features - Test for the presence of EC features > > + * > > + * Call this function to test whether the ChromeOS EC supports a feature. > > + * > > + * @ec_dev: EC device > > + * @msg: One of ec_feature_code values > > + * @return: 1 if supported, 0 if not > > + */ > > +int cros_ec_check_features(struct cros_ec_dev *ec, int feature); > > + > > +/* > > + * Return the number of MEMS sensors supported. > > + * Return < 0 in case of error. > > + */ > > +int cros_ec_get_sensor_count(struct cros_ec_dev *ec); > > + > > I am wondering if we should take this opportunity to move these two functions > from drivers/mfd/cros_ec_dev to drivers/platform/chrome/cros_ec_proto.c and > include/linux/platform_data/cros_ec_proto.h > > I think this part is more suitable for core part that actually resides in > platform/chrome than the mfd device itself. What do you think? Do you see any > problem on doing this? > > Thanks, > Enric > > > #endif /* __LINUX_MFD_CROS_EC_H */ > >