Received: by 10.213.65.68 with SMTP id h4csp324581imn; Tue, 20 Mar 2018 04:38:14 -0700 (PDT) X-Google-Smtp-Source: AG47ELtmdmw4AVNpUZ4B34YUQyEq7wsLz9G3rRfSOZRNAXpet0i79T2CIxd1/MvlS58h6+j8Wrih X-Received: by 10.101.71.141 with SMTP id e13mr5383844pgs.317.1521545894728; Tue, 20 Mar 2018 04:38:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521545894; cv=none; d=google.com; s=arc-20160816; b=ovQ4YwPilEJdj48VwwNODR1zrdYhBJUBgQ/94wgyV21Oc0Px5Z2/ujhEmelGrJvLaj IAGoLIeBqU6YpFFzpuPhNdDK6xkMM451MVqmq20YghIIiN/u7cCS1O+ry0gvQm5lEraa ETpwo1n0NaIfNXt8ynPhTRHL60pKZzhJfpSSm2UndJdpE/0Dtk+ZxeYoEZitfSeX8uHZ Op8Zb9bCHBeF5sjcbsZygYPE/gfSBLKBjYwc5QD4VlI76kWG3U+p+v7+fmB5n9bb60e/ kvjAge6eoeHbJ8bCQuYYiqRZNsjk/4W0fY7n9Lr/nID+HGTQpRH2va5YqBmKXkhiSQth oAfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=KwjGNAlQYygCVhU7qe7O0vJa4D17LQJIOZQaPtj0UxU=; b=ex1fL1MPL2uR7bHH+mAHpT737s3b1G4l9q3QF7dH3EuVzd5muyXcJ49BJOwU+AHxCb 8RoVjQ9OKaBoYmcFcAYPyxeOpjxFpkbCRpD7j8NyvlpfWB18U5MvVEHCzPKgx/AS36So NePMLNLH3gkgYt5Ik5vnSwd3xcMMf/G+bwfEEi2ocIJTehPZfuru1GBkec/zu8wwmxTZ VmZWCJvdC9gRDo3UzIHtFxr0RZ6gvZQ8HjaF+OpbSr+VvsvXu9bIgkBgThSgsJE6Vhhp 8ciG3HusCBp3XypoY3WQtT9/XTbs2+RKxihkMA8xp1Sc8qK2yD0BNvwpWchcYPQscHN/ tI1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TqDfMEm8; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p18si1040967pgv.334.2018.03.20.04.37.59; Tue, 20 Mar 2018 04:38:14 -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=@gmail.com header.s=20161025 header.b=TqDfMEm8; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752835AbeCTLhF (ORCPT + 99 others); Tue, 20 Mar 2018 07:37:05 -0400 Received: from mail-qk0-f180.google.com ([209.85.220.180]:42878 "EHLO mail-qk0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751913AbeCTLhD (ORCPT ); Tue, 20 Mar 2018 07:37:03 -0400 Received: by mail-qk0-f180.google.com with SMTP id b198so1183043qkg.9 for ; Tue, 20 Mar 2018 04:37:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=KwjGNAlQYygCVhU7qe7O0vJa4D17LQJIOZQaPtj0UxU=; b=TqDfMEm8FDO+pGvzpAg5Z2a+OK1xvdVV2k4zwRNXqNXa3vYU1SWifV23BttA7kVxQE S6odkeoZ0vNVJIS1CsNpDeis7WWMvcXqQCJRoL1emmAX+uaGObx8dk96ht/sv2jf3fBS KHDVl0p2ZOyrqhNdSE271At3Nfzi+Yj7LAtdIllYQcv2l6YaWUqgrCpXr8Tf9v2+8+lL iO9Ut1Sk8JwMQZtnKpOfI5AeBi2ipWKvuaCtJuILzRgNFHaQMqsPVixzHE4Ru5aW8nyg OO1hI7h3fdPjSubBKWdS3in/YM+d7/NhGIDX3fbQH8EHoeIS6Lhx60vpFj4dHijhxMH6 TJDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=KwjGNAlQYygCVhU7qe7O0vJa4D17LQJIOZQaPtj0UxU=; b=S0C97w+pcdq2ojxydCYXJ/KssU9hzG3D63wARQZP58P9+6uI5j8YFRyHF8eP45pGaB gppHkB72yWeLOrxmdlQ1oy4GivtSkRrWRp9sX9pZVpZ1xtawm+oJyUDZKglNyRYD7snP mFDYt0rK2b7AMVnIs37YIGYUetpuvT/KIJE0TDpqWFiPnKVeVS04Rb8YTRoyZduCCRQ6 mJgZuzGrGU1eQh3XKeZN23xAAj5ACLhsfxnPJxbEKMr4R+/NjgxinXaUxEqp7o/0qzZy 5KAlLN9eZdoXqYG+gh5FeKJoZYQgqQCNs0IqWzn9RpMOzeOA4OyyCGpCwv7MJEFvYhXG +1lw== X-Gm-Message-State: AElRT7Hmp1Xn06vS26UScX0uirCXtx0rxepwlOf9/IosNuEn8CMdmtYb AVdcyizGm9e+UJdIVGGnigHiCTkVWfucnzlDKiY= X-Received: by 10.55.41.26 with SMTP id p26mr8355350qkh.358.1521545822672; Tue, 20 Mar 2018 04:37:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.237.38.66 with HTTP; Tue, 20 Mar 2018 04:37:01 -0700 (PDT) In-Reply-To: <20180307160430.yjkhlhyenpzk37pr@dell> References: <20180226102606.15093-1-enric.balletbo@collabora.com> <20180226102606.15093-6-enric.balletbo@collabora.com> <20180307160430.yjkhlhyenpzk37pr@dell> From: Enric Balletbo Serra Date: Tue, 20 Mar 2018 12:37:01 +0100 Message-ID: Subject: Re: [PATCH v3 5/8] mfd: cros_ec_dev: Register cros_ec_accel_legacy driver as a subdevice. To: Lee Jones Cc: Enric Balletbo i Serra , Guenter Roeck , Andy Shevchenko , kernel@collabora.com, Gwendal Grignou , linux-kernel Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lee, 2018-03-07 17:04 GMT+01:00 Lee Jones : > On Mon, 26 Feb 2018, Enric Balletbo i Serra wrote: > >> With this patch, the cros_ec_ctl driver will register the legacy >> accelerometer driver (named cros_ec_accel_legacy) if it fails to >> register sensors through the usual path cros_ec_sensors_register(). >> This legacy device is present on Chromebook devices with older EC >> firmware only supporting deprecated EC commands (Glimmer based devices). >> >> Tested-by: Gwendal Grignou >> Signed-off-by: Enric Balletbo i Serra >> Reviewed-by: Gwendal Grignou >> Reviewed-by: Andy Shevchenko >> --- >> >> Changes in v3: >> - [5/8] Add the Reviewed-by Andy Shevchenko. >> >> Changes in v2: >> - [5/8] Add the Reviewed-by Gwendal. >> >> drivers/mfd/cros_ec_dev.c | 60 ++++++++++++++++++++++++++++++++++++++++= +++++++ >> 1 file changed, 60 insertions(+) >> >> diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c >> index 33fe1b439ee2..fd7f0068fb45 100644 >> --- a/drivers/mfd/cros_ec_dev.c >> +++ b/drivers/mfd/cros_ec_dev.c >> @@ -389,6 +389,63 @@ static void cros_ec_sensors_register(struct cros_ec= _dev *ec) >> kfree(msg); >> } >> >> +#define CROS_EC_SENSOR_LEGACY_NUM 2 >> +static struct mfd_cell cros_ec_accel_legacy_cells[CROS_EC_SENSOR_LEGACY= _NUM]; >> + >> +static void cros_ec_accel_legacy_register(struct cros_ec_dev *ec) >> +{ >> + struct cros_ec_device *ec_dev =3D ec->ec_dev; >> + u8 status; >> + int i, ret; >> + struct cros_ec_sensor_platform >> + sensor_platforms[CROS_EC_SENSOR_LEGACY_NUM]; > > I wish I had seen this struct before. Yuk! > > Why do you even need to know what 'number' the sensor is? > >> + /* >> + * EC that need legacy support are the main EC, directly connected= to > > Nit: "ECs" or "needs". If you choose "needs" you need to s/are/is/ as > well. > >> + * the AP. >> + */ >> + if (ec->cmd_offset !=3D 0) >> + return; >> + >> + /* >> + * Check if EC supports direct memory reads and if EC has >> + * accelerometers. >> + */ >> + if (!ec_dev->cmd_readmem) >> + return; >> + >> + ret =3D ec_dev->cmd_readmem(ec_dev, EC_MEMMAP_ACC_STATUS, 1, &stat= us); >> + if (ret < 0) { > > Is ret > 0 valid? > Yes, ret > 0 is valid. >> + dev_warn(ec->dev, "EC does not support direct reads.\n"); >> + return; >> + } >> + >> + /* Check if EC has accelerometers. */ >> + if (!(status & EC_MEMMAP_ACC_STATUS_PRESENCE_BIT)) { >> + dev_info(ec->dev, "EC does not have accelerometers.\n"); >> + return; >> + } >> + >> + /* >> + * Register 2 accelerometers >> + */ >> + for (i =3D 0; i < CROS_EC_SENSOR_LEGACY_NUM; i++) { >> + cros_ec_accel_legacy_cells[i].name =3D "cros-ec-accel-lega= cy"; >> + sensor_platforms[i].sensor_num =3D i; >> + cros_ec_accel_legacy_cells[i].id =3D i; >> + cros_ec_accel_legacy_cells[i].platform_data =3D >> + &sensor_platforms[i]; >> + cros_ec_accel_legacy_cells[i].pdata_size =3D >> + sizeof(struct cros_ec_sensor_platform); > > There is no dynamic information here. > > I'd rather you did this all statically. > Ok, I will create a static mfd_cell struct. >> + } >> + ret =3D mfd_add_devices(ec->dev, PLATFORM_DEVID_AUTO, >> + cros_ec_accel_legacy_cells, >> + CROS_EC_SENSOR_LEGACY_NUM, > > ARRAY_SIZE() is less fragile. > Ack. >> + NULL, 0, NULL); >> + if (ret) >> + dev_err(ec_dev->dev, "failed to add EC sensors\n"); >> +} >> + >> static const struct mfd_cell cros_ec_rtc_cell =3D { >> .name =3D "cros-ec-rtc", >> }; >> @@ -440,6 +497,9 @@ static int ec_device_probe(struct platform_device *p= dev) >> /* check whether this EC is a sensor hub. */ >> if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE)) >> cros_ec_sensors_register(ec); >> + else >> + /* Workaroud for older EC firmware */ >> + cros_ec_accel_legacy_register(ec); >> >> /* check whether this EC instance has RTC host command support */ >> if (cros_ec_check_features(ec, EC_FEATURE_RTC)) { > > -- > Lee Jones > Linaro Services Technical Lead > Linaro.org =E2=94=82 Open source software for ARM SoCs > Follow Linaro: Facebook | Twitter | Blog Thanks for the review. I'll prepare a new version of this patchset. Enric