Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1257425ybl; Fri, 23 Aug 2019 16:20:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqwrT1gvtcDu1JM9qVNfILWCsXLrqbaDyZ92n0HAzorq9VgSFZ3b+RdbRSchtexzRj8pDYMN X-Received: by 2002:a63:fe52:: with SMTP id x18mr6329984pgj.344.1566602431425; Fri, 23 Aug 2019 16:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566602431; cv=none; d=google.com; s=arc-20160816; b=fQSL//eq4uSkuzZ3Usg8alNR0ANvc04lmo+aO2anCOWYzYuRCCzt3pF6gxnhDL+u+8 imDu9vPP6Z2YPCqk8E6WCsKu1lg5P60RPjEEJ4ARI94GQL7K62TWrruI28LnadTQRdJW lPNNG+1LzWo/NSOOrL6REtgHU+upIrJLAplc3HdfiMePGYy4G45t+CQsb34E8BeqVBDa 31PFtJAHOLMb1ZQGYkXy7z0C7c7OaBKo8p+fhfGA8mklhQsFEaAbVNCWWCuefXD14UL3 M2wvYakWwRIkm7Eu1ZFv9u3Z4CAXL2eFLue8ddx4C1Sx45ysYEKg4t1XY9NJwEe9qEHG bRUA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PHIxRCBSrcPIs5XBqzIO8rancIcUKeKMV9fhf5l5BXE=; b=AwRGdGd+I1X7nuDY6YKdzqak6KgH+/3MwEylHsrDk/QVydGH86lagXRbUhQMG33UR3 YAShTh5QhOeihyXRwft3Axzwd8+Dw80ZSjnULUCKCXLto6Eg4HfHEYzDXuKO2NpRSYfe hPrjy2878/ixHS7/x2tLp60w6A0d64KyZdNxe+sNAM9ZJhsv095XAjEweTV9aqUkd6Qg 09Af7uMWx1YuE3ukrYivVlLsJzINR1+t0AIIvmTHK7pS3lnGaCWZcna0WdMWs5V16mw1 ji3aSHcBfXjoSNEvYgpuARth4bPTGrHc9mBfae8/fboRap4rEaY51jA8M17+bl/QJXYx mDRw== 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 q4si2865719pgv.106.2019.08.23.16.20.16; Fri, 23 Aug 2019 16:20:31 -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; 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 S2394933AbfHWMy3 (ORCPT + 99 others); Fri, 23 Aug 2019 08:54:29 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:46422 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727894AbfHWMy2 (ORCPT ); Fri, 23 Aug 2019 08:54:28 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 4FC4328D33D From: Enric Balletbo i Serra To: linux-kernel@vger.kernel.org Cc: Jonathan Corbet , Krzysztof Kozlowski , Will Deacon , MyungJoo Ham , Chanwoo Choi , Benson Leung , Guenter Roeck , Jonathan Cameron , Dmitry Torokhov , Mauro Carvalho Chehab , Lee Jones , Sebastian Reichel , Thierry Reding , Alexandre Belloni , Liam Girdwood , Mark Brown , Neil Armstrong , Greg Kroah-Hartman , Collabora kernel ML , Andy Shevchenko , Gwendal Grignou Subject: [PATCH v6 08/11] mfd: cros_ec: Add convenience struct to define dedicated CrOS EC MCUs Date: Fri, 23 Aug 2019 14:53:28 +0200 Message-Id: <20190823125331.5070-9-enric.balletbo@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190823125331.5070-1-enric.balletbo@collabora.com> References: <20190823125331.5070-1-enric.balletbo@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the increasing use of dedicated CrOS EC MCUs, it takes a fair amount of boiler plate code to add those devices, add a struct that can be used to specify a dedicated CrOS EC MCU so we can just add a new item to it to define a new dedicated MCU. Signed-off-by: Enric Balletbo i Serra Acked-by: Andy Shevchenko Reviewed-by: Gwendal Grignou Tested-by: Gwendal Grignou --- Changes in v6: - Add a break statement once the MCU type has been determined (Lee Jones) Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/mfd/cros_ec_dev.c | 88 ++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c index 148f39c79f41..31da038effc0 100644 --- a/drivers/mfd/cros_ec_dev.c +++ b/drivers/mfd/cros_ec_dev.c @@ -23,6 +23,41 @@ static struct class cros_class = { .name = "chromeos", }; +/** + * cros_feature_to_name - CrOS feature id to name/short description. + * @id: The feature identifier. + * @name: Device name associated with the feature id. + * @desc: Short name that will be displayed. + */ +struct cros_feature_to_name { + unsigned int id; + const char *name; + const char *desc; +}; + +static const struct cros_feature_to_name cros_mcu_devices[] = { + { + .id = EC_FEATURE_FINGERPRINT, + .name = CROS_EC_DEV_FP_NAME, + .desc = "Fingerprint", + }, + { + .id = EC_FEATURE_ISH, + .name = CROS_EC_DEV_ISH_NAME, + .desc = "Integrated Sensor Hub", + }, + { + .id = EC_FEATURE_SCP, + .name = CROS_EC_DEV_SCP_NAME, + .desc = "System Control Processor", + }, + { + .id = EC_FEATURE_TOUCHPAD, + .name = CROS_EC_DEV_TP_NAME, + .desc = "Touchpad", + }, +}; + static int cros_ec_check_features(struct cros_ec_dev *ec, int feature) { struct cros_ec_command *msg; @@ -279,6 +314,7 @@ static int ec_device_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct cros_ec_platform *ec_platform = dev_get_platdata(dev); struct cros_ec_dev *ec = kzalloc(sizeof(*ec), GFP_KERNEL); + int i; if (!ec) return retval; @@ -291,47 +327,21 @@ static int ec_device_probe(struct platform_device *pdev) ec->features[1] = -1U; /* Not cached yet */ device_initialize(&ec->class_dev); - /* Check whether this is actually a Fingerprint MCU rather than an EC */ - if (cros_ec_check_features(ec, EC_FEATURE_FINGERPRINT)) { - dev_info(dev, "CrOS Fingerprint MCU detected.\n"); + for (i = 0; i < ARRAY_SIZE(cros_mcu_devices); i++) { /* - * Help userspace differentiating ECs from FP MCU, - * regardless of the probing order. + * Check whether this is actually a dedicated MCU rather + * than an standard EC. */ - ec_platform->ec_name = CROS_EC_DEV_FP_NAME; - } - - /* - * Check whether this is actually an Integrated Sensor Hub (ISH) - * rather than an EC. - */ - if (cros_ec_check_features(ec, EC_FEATURE_ISH)) { - dev_info(dev, "CrOS ISH MCU detected.\n"); - /* - * Help userspace differentiating ECs from ISH MCU, - * regardless of the probing order. - */ - ec_platform->ec_name = CROS_EC_DEV_ISH_NAME; - } - - /* Check whether this is actually a Touchpad MCU rather than an EC */ - if (cros_ec_check_features(ec, EC_FEATURE_TOUCHPAD)) { - dev_info(dev, "CrOS Touchpad MCU detected.\n"); - /* - * Help userspace differentiating ECs from TP MCU, - * regardless of the probing order. - */ - ec_platform->ec_name = CROS_EC_DEV_TP_NAME; - } - - /* Check whether this is actually a SCP rather than an EC. */ - if (cros_ec_check_features(ec, EC_FEATURE_SCP)) { - dev_info(dev, "CrOS SCP MCU detected.\n"); - /* - * Help userspace differentiating ECs from SCP, - * regardless of the probing order. - */ - ec_platform->ec_name = CROS_EC_DEV_SCP_NAME; + if (cros_ec_check_features(ec, cros_mcu_devices[i].id)) { + dev_info(dev, "CrOS %s MCU detected\n", + cros_mcu_devices[i].desc); + /* + * Help userspace differentiating ECs from other MCU, + * regardless of the probing order. + */ + ec_platform->ec_name = cros_mcu_devices[i].name; + break; + } } /* -- 2.20.1