Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1256585ybl; Fri, 23 Aug 2019 16:19:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2WAgC3sBkvl9sgE19jeyWjiuJFx7yUbxO3Grmkp6BYxYAGjtGyaySKN3aRleBHZxbn/zZ X-Received: by 2002:a17:902:1a7:: with SMTP id b36mr7285821plb.115.1566602363522; Fri, 23 Aug 2019 16:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566602363; cv=none; d=google.com; s=arc-20160816; b=UxGH7UaHJ5zn47m4l2EgCoBT0vNUh/tmBEmnJBDoBin4FNc6B14/plttBlBMtBswIX H2KBt9UEnxjyzjYdfFj96nIN5FmiM9KqCAY+e+yGKYKEpCj8JfsKn21n8nKJj5Eh6IUk YAZtTLnDwOvu9YiTjIp+w4H4W+hHqVElifJxsK7GvzuQb57vGsPAiMClvVcnnP9MIlqW m5Quh/IkrNNZeOWRpPhJLrlsFprr7f8pDql9QRaFP6F8JjWwvUrKz4ueErfyIbKYee6g gld00K6lk0n1hK+vM2BGz0xcFG6pGhQDqRy0Cs7TXJXpKiZUQN31LOE/uOsFGMx8kLeo JzcA== 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=Kqu0e/V3GZAJld9zgpMbraXFTWAUjorB2PRtfLKUW8c=; b=n19r9kvO0JbWzRKaFdtNexPKJPPGv45Zg5cZPl+13bdnsaRp3N68lGAghf853ae2da VUNMKZ10ZIS36KyuYMKCDNHs8GQxapBF5Y0XHipZpR/4E3qAb11F3vEr13VgqQxSQ/xk 1AQJR9PnyYXya6Qv0z0XQ64xIHjKqdICiTTOZDGurljCujo2u6jimiL0Tj22z3+jTbWW Xgw1nvXMm9QNUR2XeJmlYF+rRIOkmIm8hDhOZJblkkIoST5IGt/e/nufYMYX+sX6e/Vv fHYVNLEWfTZjJi0UhGAbuZGbaK34cDQlQtRv89c5Qi/hbMfU/AtC+beAoOtePYaj26Np orgA== 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 k1si3707109pll.393.2019.08.23.16.19.08; Fri, 23 Aug 2019 16:19:23 -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 S2394943AbfHWMyd (ORCPT + 99 others); Fri, 23 Aug 2019 08:54:33 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:46444 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727894AbfHWMyc (ORCPT ); Fri, 23 Aug 2019 08:54:32 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 1CCC528D382 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 09/11] mfd: cros_ec: Add convenience struct to define autodetectable CrOS EC subdevices Date: Fri, 23 Aug 2019 14:53:29 +0200 Message-Id: <20190823125331.5070-10-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 The CrOS EC is gaining lots of subdevices that are autodetectable by sending the EC_FEATURE_GET_CMD, it takes fair amount of boiler plate code to add those devices. So, add a struct that can be used to quickly add new subdevices without having to duplicate code. Signed-off-by: Enric Balletbo i Serra Acked-by: Andy Shevchenko Reviewed-by: Gwendal Grignou Tested-by: Gwendal Grignou Acked-for-MFD-by: Lee Jones --- Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: - Use mfd_add_hotplug_devices helper (Gwendal) Changes in v2: None drivers/mfd/cros_ec_dev.c | 131 +++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 58 deletions(-) diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c index 31da038effc0..90eb02c56b77 100644 --- a/drivers/mfd/cros_ec_dev.c +++ b/drivers/mfd/cros_ec_dev.c @@ -35,6 +35,18 @@ struct cros_feature_to_name { const char *desc; }; +/** + * cros_feature_to_cells - CrOS feature id to mfd cells association. + * @id: The feature identifier. + * @mfd_cells: Pointer to the array of mfd cells that needs to be added. + * @num_cells: Number of mfd cells into the array. + */ +struct cros_feature_to_cells { + unsigned int id; + const struct mfd_cell *mfd_cells; + unsigned int num_cells; +}; + static const struct cros_feature_to_name cros_mcu_devices[] = { { .id = EC_FEATURE_FINGERPRINT, @@ -58,6 +70,48 @@ static const struct cros_feature_to_name cros_mcu_devices[] = { }, }; +static const struct mfd_cell cros_ec_cec_cells[] = { + { .name = "cros-ec-cec", }, +}; + +static const struct mfd_cell cros_ec_rtc_cells[] = { + { .name = "cros-ec-rtc", }, +}; + +static const struct mfd_cell cros_usbpd_charger_cells[] = { + { .name = "cros-usbpd-charger", }, + { .name = "cros-usbpd-logger", }, +}; + +static const struct cros_feature_to_cells cros_subdevices[] = { + { + .id = EC_FEATURE_CEC, + .mfd_cells = cros_ec_cec_cells, + .num_cells = ARRAY_SIZE(cros_ec_cec_cells), + }, + { + .id = EC_FEATURE_RTC, + .mfd_cells = cros_ec_rtc_cells, + .num_cells = ARRAY_SIZE(cros_ec_rtc_cells), + }, + { + .id = EC_FEATURE_USB_PD, + .mfd_cells = cros_usbpd_charger_cells, + .num_cells = ARRAY_SIZE(cros_usbpd_charger_cells), + }, +}; + +static const struct mfd_cell cros_ec_platform_cells[] = { + { .name = "cros-ec-chardev", }, + { .name = "cros-ec-debugfs", }, + { .name = "cros-ec-lightbar", }, + { .name = "cros-ec-sysfs", }, +}; + +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) { struct cros_ec_command *msg; @@ -283,30 +337,6 @@ static void cros_ec_accel_legacy_register(struct cros_ec_dev *ec) dev_err(ec_dev->dev, "failed to add EC sensors\n"); } -static const struct mfd_cell cros_ec_cec_cells[] = { - { .name = "cros-ec-cec" } -}; - -static const struct mfd_cell cros_ec_rtc_cells[] = { - { .name = "cros-ec-rtc" } -}; - -static const struct mfd_cell cros_usbpd_charger_cells[] = { - { .name = "cros-usbpd-charger" }, - { .name = "cros-usbpd-logger" }, -}; - -static const struct mfd_cell cros_ec_platform_cells[] = { - { .name = "cros-ec-chardev" }, - { .name = "cros-ec-debugfs" }, - { .name = "cros-ec-lightbar" }, - { .name = "cros-ec-sysfs" }, -}; - -static const struct mfd_cell cros_ec_vbc_cells[] = { - { .name = "cros-ec-vbc" } -}; - static int ec_device_probe(struct platform_device *pdev) { int retval = -ENOMEM; @@ -368,42 +398,27 @@ static int ec_device_probe(struct platform_device *pdev) /* Workaroud for older EC firmware */ cros_ec_accel_legacy_register(ec); - /* Check whether this EC instance has CEC host command support */ - if (cros_ec_check_features(ec, EC_FEATURE_CEC)) { - retval = mfd_add_devices(ec->dev, PLATFORM_DEVID_AUTO, - cros_ec_cec_cells, - ARRAY_SIZE(cros_ec_cec_cells), - NULL, 0, NULL); - if (retval) - dev_err(ec->dev, - "failed to add cros-ec-cec device: %d\n", - retval); - } - - /* Check whether this EC instance has RTC host command support */ - if (cros_ec_check_features(ec, EC_FEATURE_RTC)) { - retval = mfd_add_devices(ec->dev, PLATFORM_DEVID_AUTO, - cros_ec_rtc_cells, - ARRAY_SIZE(cros_ec_rtc_cells), - NULL, 0, NULL); - if (retval) - dev_err(ec->dev, - "failed to add cros-ec-rtc device: %d\n", - retval); - } - - /* Check whether this EC instance has the PD charge manager */ - if (cros_ec_check_features(ec, EC_FEATURE_USB_PD)) { - retval = mfd_add_devices(ec->dev, PLATFORM_DEVID_AUTO, - cros_usbpd_charger_cells, - ARRAY_SIZE(cros_usbpd_charger_cells), - NULL, 0, NULL); - if (retval) - dev_err(ec->dev, - "failed to add cros-usbpd-charger device: %d\n", - retval); + /* + * The following subdevices can be detected by sending the + * EC_FEATURE_GET_CMD Embedded Controller device. + */ + for (i = 0; i < ARRAY_SIZE(cros_subdevices); i++) { + if (cros_ec_check_features(ec, cros_subdevices[i].id)) { + retval = mfd_add_hotplug_devices(ec->dev, + cros_subdevices[i].mfd_cells, + cros_subdevices[i].num_cells); + if (retval) + dev_err(ec->dev, + "failed to add %s subdevice: %d\n", + cros_subdevices[i].mfd_cells->name, + retval); + } } + /* + * The following subdevices cannot be detected by sending the + * EC_FEATURE_GET_CMD to the Embedded Controller device. + */ retval = mfd_add_devices(ec->dev, PLATFORM_DEVID_AUTO, cros_ec_platform_cells, ARRAY_SIZE(cros_ec_platform_cells), -- 2.20.1