Received: by 10.223.185.116 with SMTP id b49csp3581678wrg; Mon, 26 Feb 2018 02:29:30 -0800 (PST) X-Google-Smtp-Source: AH8x224pNikoRqGPkw7G3J2CCE/wHOoor9gytz1yhuJSDYmBp5Kh1jXIZFMhkJ6Ds30gtDo68zf6 X-Received: by 10.101.67.137 with SMTP id m9mr7825027pgp.301.1519640970134; Mon, 26 Feb 2018 02:29:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519640970; cv=none; d=google.com; s=arc-20160816; b=higk6Mh2V+etYtBEUXkgaoKO8FkLPE0tvNH2/PHCXjF9tX69Pt/xziyGJfFcpOEyBY KNskXd6ppqiTV6sJ0BQx40io8iGsE/O5FwtfkSUIi5ymO+MRQbYxr38bWgUkUKx+TKfm KGvgQKjTOOoDRYvzFK4T3SnJPRQ4uKWqVHMMx4tNGxopuUrDEcA+74AZlVxFL6Ef6wB2 KvHHo7bOz6Fq1eEsx0HENrDR4lj7QkRn+P0gu5tBNlRnPErZkc4p6mARuhOf0itfwe/R x6M4PlMRi0bLwTNB7xMW68Ntp1VvPPp+biRbTB/Jc3JVcYVvyvy5HSEeqS4ui3UmWw+b Hcog== 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:arc-authentication-results; bh=nAOiV8FaceXSmKS5PhnQ/EvJPLbHimhJk63ecvcDSdo=; b=vIier8TLm42gFh5Obe2Wg2PGap+RrpvZ+/z+uBcpLFG98dBeDe6FlDrv5qUuZ7XEFX JMm9g7O60zgpqPbmrFAIwjb43TPoH5bHKiOnUskkV+AsmwTG6nckJfdZjmxrgZfe81FX fffAUOndq0rzSMbUTflT7Aq91o6RW31QaLXgG3LOq7MEejtMAJO0OhG+PL+hG/K1/dF4 FhGeMF/3ywIa9VJfuMo8a2KvS0YiHnGNkrRk6JSxMtgAD+5BSfhAS/pOgO98Y6PVtyct TWvalWKJ4VH6rgWrQWqeWkOdc98ZKSSZmM5ac4XsG79q+5gf1sk0wcb4fOaPR/nN+fOo s7WA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i4si5397095pgr.266.2018.02.26.02.29.15; Mon, 26 Feb 2018 02:29:30 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752757AbeBZK1o (ORCPT + 99 others); Mon, 26 Feb 2018 05:27:44 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:48346 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752613AbeBZK0S (ORCPT ); Mon, 26 Feb 2018 05:26:18 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 3F5D0277264 From: Enric Balletbo i Serra To: lee.jones@linaro.org Cc: groeck@chromium.org, andy.shevchenko@gmail.com, kernel@collabora.com, gwendal@chromium.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/8] mfd: cros_ec_dev: Register cros_ec_accel_legacy driver as a subdevice. Date: Mon, 26 Feb 2018 11:26:03 +0100 Message-Id: <20180226102606.15093-6-enric.balletbo@collabora.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180226102606.15093-1-enric.balletbo@collabora.com> References: <20180226102606.15093-1-enric.balletbo@collabora.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 = ec->ec_dev; + u8 status; + int i, ret; + struct cros_ec_sensor_platform + sensor_platforms[CROS_EC_SENSOR_LEGACY_NUM]; + + /* + * EC that need legacy support are the main EC, directly connected to + * the AP. + */ + if (ec->cmd_offset != 0) + return; + + /* + * Check if EC supports direct memory reads and if EC has + * accelerometers. + */ + if (!ec_dev->cmd_readmem) + return; + + ret = ec_dev->cmd_readmem(ec_dev, EC_MEMMAP_ACC_STATUS, 1, &status); + if (ret < 0) { + 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 = 0; i < CROS_EC_SENSOR_LEGACY_NUM; i++) { + cros_ec_accel_legacy_cells[i].name = "cros-ec-accel-legacy"; + sensor_platforms[i].sensor_num = i; + cros_ec_accel_legacy_cells[i].id = i; + cros_ec_accel_legacy_cells[i].platform_data = + &sensor_platforms[i]; + cros_ec_accel_legacy_cells[i].pdata_size = + sizeof(struct cros_ec_sensor_platform); + } + ret = mfd_add_devices(ec->dev, PLATFORM_DEVID_AUTO, + cros_ec_accel_legacy_cells, + CROS_EC_SENSOR_LEGACY_NUM, + 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 = { .name = "cros-ec-rtc", }; @@ -440,6 +497,9 @@ static int ec_device_probe(struct platform_device *pdev) /* 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)) { -- 2.16.1