Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp280659imm; Mon, 4 Jun 2018 17:40:39 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI0FPqydS570Mn3kJnQVioME120j0YVfshWlHkT0nZqw+6CGNvOqkVFAJt8Yt6uRPJoIkgL X-Received: by 2002:a62:154a:: with SMTP id 71-v6mr14215301pfv.170.1528159239376; Mon, 04 Jun 2018 17:40:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528159239; cv=none; d=google.com; s=arc-20160816; b=1AI/XKu/1vocXDU8FGBKZwOYMxW8p2DIi+su5HhMMr/isVEMF+AcUcHAK1z0AzReMP C0kTxCxj0sbdKw972VhR1TlBwXhKDspNZoId4V6O9Xu8LUCPSjZKk8wGMS6XA/XT1wxd Jv6EGBXtu4U7waPhadOffPlEh5xTANqk4R4nBcKzhRbZq9jqgJGHNFUmcJR0xHYc2PpN JG7jPRbVj7S0KBgPpAMDcawEfuqc59JUAZj4EL1V5J5RfefvIkQ+reNGW51r4RvzyfHT Z+5NfDVjEiMVGpWfNmBizw4v/C6BOnyoKrVV16J9CYHjy8Z+nsreNon5bBnZyMapGBfr CKxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references:message-id :in-reply-to:date:mime-version:dkim-signature :arc-authentication-results; bh=UK5Vl5ZOoJVcQg/OIp+gbvJLJRJMsWICAgCizPGyNZw=; b=wYvwoT28K3Hp619MkWzxtYCx+LslmvyTBnV5xNL2IZW83VnfZ0tpB/mvlk/p+bxDQ4 rpLUinZusz78Yw5sTcpkBxh5KyFY9vAxlX6EcwIY+4IIR7xDcC3JrFygDrCH8LekMivz HQzOd0sKDRQSN5mm0gHw7vbixide4T7t+5ibwE/u6+3vCdl0XmyETGSpiqoz9+ble89g YfLzcFhFTEz9x0GY5qA0J2CBBCgcGo6GIr9TrEKtkKMn/zkPm2Yfg6kfmmAfDv9C2GyW PVn38PYdawmV7fjShOMWzxToAuX7AnAKy5Bz2sILfB3NPJY5yNR7iOCKp6+fimppVXLu wEYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=D+9U1OPb; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v72-v6si5981222pfa.103.2018.06.04.17.40.24; Mon, 04 Jun 2018 17:40:39 -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=@google.com header.s=20161025 header.b=D+9U1OPb; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751317AbeFEAj7 (ORCPT + 99 others); Mon, 4 Jun 2018 20:39:59 -0400 Received: from mail-qk0-f201.google.com ([209.85.220.201]:33076 "EHLO mail-qk0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751046AbeFEAj6 (ORCPT ); Mon, 4 Jun 2018 20:39:58 -0400 Received: by mail-qk0-f201.google.com with SMTP id x186-v6so700738qkb.0 for ; Mon, 04 Jun 2018 17:39:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:in-reply-to:message-id:references:subject:from:to :cc; bh=UK5Vl5ZOoJVcQg/OIp+gbvJLJRJMsWICAgCizPGyNZw=; b=D+9U1OPbJ3m8Rucp4u9G72SBtbWvokAtagoEIaCeXs2PP5mrYPoVFYh1E1kebCxG/P 5fJmbyrXkvoxZESruDs2K9zXbGizvHlTVnSMtc7hWEwuQgFDVgZN/jS75aCYem7EVYDo YWdOaeoqPsLLq/P6kEtuojZynL7bwg4wdtZSCjnwyzV8W0uekM9Ydy83BQodTSXQnsRP neS5LW5wvy61ci90wTzKP46HGALobgH3jjnYPbRuL9qNLtgRCjWO9OdBzzjFDzG6k2WC kn0B2hSPUR827xP/VwHdGHJpiADTvJwO/cB6dtcquZFBbxkb4dYWGYfey0h4aP6tCXUr s3vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc; bh=UK5Vl5ZOoJVcQg/OIp+gbvJLJRJMsWICAgCizPGyNZw=; b=RPa0hf+aMef8VrzDhjpmYw1hfedbHC4Wb7042C2p/kkMivp8tkZWFbY9XIN2AAAD0E FweDaX2WJdpNbskbbp2Jtueg+Ua52Hm+ucW2BnvCQEM75v2YFAJEn6yr/Eritw5mvcfl YgzshN4KRMIKf1izZG1cLQ+3ZbnGjKDUm3PVIrO1S6XHSzVEyNAeO7qtf/blJ9czZETF 3zf4Pj6+/KlzWSTJfmNNndiIIZ2isolQyyWh6GjJS621mvqkKo3tjb6tEeLsgMJT1Fat +YOuKn133xrqRb8/bFFd7tkT4HwvOK69vGHKEualSWcS4O69hfRsAVRpTZcOidvu+o+2 DlvQ== X-Gm-Message-State: APt69E1eh6H5XL8u7ymaMhmgxXnOHdMm/5DnzureHCPrMLRCgnho4AIP UXPYHN39Z8upNrVPEHJgsFsyNiFt8bbAb4VGLQONNLqC4bQfDKdymCK4nrifTtFEyhYeqNvEEyy 92T7zcnCeGtxeHk/zU7Ef9+bo3U/MMThvPPYbv136VK1Sy+qETAuPcvENn8abrl4+lBN6y0IhiC U= MIME-Version: 1.0 X-Received: by 2002:a37:1f27:: with SMTP id f39-v6mr13190343qkf.19.1528159197019; Mon, 04 Jun 2018 17:39:57 -0700 (PDT) Date: Mon, 4 Jun 2018 17:39:28 -0700 In-Reply-To: Message-Id: <20180605003928.245020-1-egranata@google.com> References: X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog Subject: [PATCH v2] cros_ec: cleanup dependency chain for cros_ec modules From: Enrico Granata To: linux-kernel@vger.kernel.org Cc: egranata@chromium.org, bleung@chromium.org, olof@lixom.net, lee.jones@linaro.org 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 From: Enrico Granata If one builds the Chrome EC support as modules, there is no explicit dependency chain amongst the several modules (LPC, CHARDEV, CORE, ...) This makes it possible - for instance - to rmmod cros_ec_core, even though cros_ec_dev actively uses it for data transport to the EC chip. This commit makes two changes in an attempt to address this: a) moves cros_ec_proto.c as part of the CORE module; this removes the possibility of unloading cros_ec_core while cros_ec_dev is using it; b) enables cros_ec_core to explicitly register a runtime dependency on the kernel module that is using its cmd and pkt transfer functions Series-to: LKML Series-cc: gwendal@google.com Signed-off-by: Enrico Granata --- drivers/mfd/Kconfig | 1 - drivers/mfd/Makefile | 2 +- drivers/mfd/cros_ec.c | 17 ++++++++++++++++- .../{platform/chrome => mfd}/cros_ec_proto.c | 0 drivers/platform/chrome/Kconfig | 5 ----- drivers/platform/chrome/Makefile | 1 - drivers/platform/chrome/cros_ec_lpc.c | 1 + include/linux/mfd/cros_ec.h | 2 ++ 8 files changed, 20 insertions(+), 9 deletions(-) rename drivers/{platform/chrome => mfd}/cros_ec_proto.c (100%) diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index b860eb5aa194..a8daa2072ae6 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -194,7 +194,6 @@ config MFD_CROS_EC tristate "ChromeOS Embedded Controller" select MFD_CORE select CHROME_PLATFORMS - select CROS_EC_PROTO depends on X86 || ARM || ARM64 || COMPILE_TEST help If you say Y here you get support for the ChromeOS Embedded diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index d9d2cf0d32ef..20537bd27695 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -12,7 +12,7 @@ obj-$(CONFIG_MFD_SM501) += sm501.o obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o obj-$(CONFIG_MFD_BCM590XX) += bcm590xx.o obj-$(CONFIG_MFD_BD9571MWV) += bd9571mwv.o -cros_ec_core-objs := cros_ec.o +cros_ec_core-objs := cros_ec.o cros_ec_proto.o cros_ec_core-$(CONFIG_ACPI) += cros_ec_acpi_gpe.o obj-$(CONFIG_MFD_CROS_EC) += cros_ec_core.o obj-$(CONFIG_MFD_CROS_EC_I2C) += cros_ec_i2c.o diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c index d61024141e2b..109e9cb1e289 100644 --- a/drivers/mfd/cros_ec.c +++ b/drivers/mfd/cros_ec.c @@ -168,9 +168,21 @@ int cros_ec_register(struct cros_ec_device *ec_dev) */ err = cros_ec_sleep_event(ec_dev, 0); if (err < 0) - dev_dbg(ec_dev->dev, "Error %d clearing sleep event to ec", + dev_dbg(dev, "Error %d clearing sleep event to ec", err); + if (ec_dev->xfer_fcn_owner != NULL) { + err = try_module_get(ec_dev->xfer_fcn_owner); + if (err < 0) { + dev_err(dev, "Error %d acquiring transfer module", err); + return err; + } + dev_info(dev, "Transfer module %p get successfully", + ec_dev->xfer_fcn_owner); + } else { + dev_warn(dev, "No transfer module registered"); + } + dev_info(dev, "Chrome EC device registered\n"); cros_ec_acpi_install_gpe_handler(dev); @@ -193,6 +205,9 @@ int cros_ec_remove(struct cros_ec_device *ec_dev) if (ec_dev->irq) free_irq(ec_dev->irq, ec_dev); + if (ec_dev->xfer_fcn_owner != NULL) + module_put(ec_dev->xfer_fcn_owner); + return 0; } EXPORT_SYMBOL(cros_ec_remove); diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/mfd/cros_ec_proto.c similarity index 100% rename from drivers/platform/chrome/cros_ec_proto.c rename to drivers/mfd/cros_ec_proto.c diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig index e728a96cabfd..a050c9e8b506 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -65,11 +65,6 @@ config CROS_EC_LPC_MEC If you have a ChromeOS Embedded Controller Microchip EC variant choose Y here. -config CROS_EC_PROTO - bool - help - ChromeOS EC communication protocol helpers. - config CROS_KBD_LED_BACKLIGHT tristate "Backlight LED support for Chrome OS keyboards" depends on LEDS_CLASS && ACPI diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile index ff3b369911f0..0b5e26ca9c96 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -8,5 +8,4 @@ obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o cros_ec_lpcs-objs := cros_ec_lpc.o cros_ec_lpc_reg.o cros_ec_lpcs-$(CONFIG_CROS_EC_LPC_MEC) += cros_ec_lpc_mec.o obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o -obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c index 3682e1539251..8f02b188bd3f 100644 --- a/drivers/platform/chrome/cros_ec_lpc.c +++ b/drivers/platform/chrome/cros_ec_lpc.c @@ -282,6 +282,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev) ec_dev->phys_name = dev_name(dev); ec_dev->cmd_xfer = cros_ec_cmd_xfer_lpc; ec_dev->pkt_xfer = cros_ec_pkt_xfer_lpc; + ec_dev->xfer_fcn_owner = THIS_MODULE; ec_dev->cmd_readmem = cros_ec_lpc_readmem; ec_dev->din_size = sizeof(struct ec_host_response) + sizeof(struct ec_response_get_protocol_info); diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h index 2d4e23c9ea0a..5239107e5091 100644 --- a/include/linux/mfd/cros_ec.h +++ b/include/linux/mfd/cros_ec.h @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -139,6 +140,7 @@ struct cros_ec_device { int dout_size; bool wake_enabled; bool suspended; + struct module *xfer_fcn_owner; int (*cmd_xfer)(struct cros_ec_device *ec, struct cros_ec_command *msg); int (*pkt_xfer)(struct cros_ec_device *ec, -- 2.17.1.1185.g55be947832-goog