Received: by 10.213.65.68 with SMTP id h4csp238556imn; Mon, 12 Mar 2018 12:12:38 -0700 (PDT) X-Google-Smtp-Source: AG47ELtFNeEXwOWRISfj4Bii85HkRrpNrxTxy9YH4O/6CwA/7Oo4HFROKfS3vEKdh/iPLm2aSao/ X-Received: by 10.98.198.146 with SMTP id x18mr9007952pfk.22.1520881958734; Mon, 12 Mar 2018 12:12:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520881958; cv=none; d=google.com; s=arc-20160816; b=A0uej1jbYBVN8PCPnPOINuhRcl99n/xf8CR7DOAj/A8OgfQUFi93VFpxTs9waDvUXi Sk+S8cFSnAYicMbJrBWOtazw//XqrxvkBa/7fjyOQ7VcRtIvAy/Qe6rhIiIqyDRA8uEy MyVVXxj1a6Wki2FHSjtPL1zGbaofOE0ymtsUr0nfHlo+rnG7jd8xfFFZrvhNaRM0jhtH 7UC3V+kO+4cRA+VWZpuHrTSPPLQKKfshsUf9p/YmRaVVgVQL1LedTF9WWy9ZpwOdQ/qR Rpcx6ePI677kIve++1CPv1mwIrx92BiTJE3VA4DeSrhsB5q5gEs6X64XtQu4sTuTfn3X SWog== 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:dkim-signature:arc-authentication-results; bh=RCLn0cWrqvKH/AiWPtHT4/uU/4Zmp2sqcgGmCmupdbc=; b=eOywXz+D6MefgRu778xyMupsumjuZxT3E2Mw9D4JFzutBD/9mOdXkkMyd2wp6nKApO ywxjqoGbkK+x1tPh2CJZ03xXDsflIEwjDMV2Rioj+wQdKx/8Mclvy6ssnzzM7qKS8ZVr Bxtq/CjAmqJb/szRBw9YelIaGJYFARRdJfWRzR8SKeWkbwNrKJ7WRKijGujUnKhGQjCh rtnoCl3HgdHdvhIjsDNpW8IkfJxkE5ikMA2hVxMul9vSoon7LNoMU7nB1DMPEoZwpZQb he6zieCDcWGJG1diA+vC6UXu/O7IxALn/VrHhSpgZ2i0CyCJALvwabFNmVMLIYSCBsR7 VUZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cPADOxQU; 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 f13si5363700pgo.250.2018.03.12.12.12.23; Mon, 12 Mar 2018 12:12:38 -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=cPADOxQU; 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 S932586AbeCLTK5 (ORCPT + 99 others); Mon, 12 Mar 2018 15:10:57 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:39684 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932486AbeCLTJW (ORCPT ); Mon, 12 Mar 2018 15:09:22 -0400 Received: by mail-pl0-f65.google.com with SMTP id s13-v6so9875580plq.6; Mon, 12 Mar 2018 12:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RCLn0cWrqvKH/AiWPtHT4/uU/4Zmp2sqcgGmCmupdbc=; b=cPADOxQUARZlZwDzcrQ/HrVnjZ4dPYHCusFP+BhdIuxyOY9scxJzZL6fDhigVbS3Ur L1L0kaxc0qrabbwZaV9aBjAYz8lva5NjoAVNUWTE3bASiVCj9++zuIrcYRh9TYL3HSb1 g6wtex+D1GZgZO0oc2Ck7s3HA1AJXUMGc8FrNDE2zhchgssynXs6g3aVLGdz2QVx2pHD RGBY8ufDtUVspTXki2KQ2DLT7LSBlnEK0R8YGnIR49rnKuYG+Uei6BDHOkrZGlb23D2X ug8PfVh2iXvqlfezeD2HfZACIJFFaPbVUGho/eYvL1mk9GidV5h0x78Q51Xi9FxVqVDX styg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RCLn0cWrqvKH/AiWPtHT4/uU/4Zmp2sqcgGmCmupdbc=; b=NgkCSNv0tq/Ei53JSPKGvdePYy4y9g1JB6agNDCrpvF/FeVTPpfseXL7RGTCBZ45CD kL5uSF+Wx0+fkmPKhQ6nheOyhGH76zQHXFOCoAKHNpolBiJg6LIK4bY9I+3ZTMnIwyIk ROoJ4ZOJ/Gw4AbPHbW14nDHQweiFlVpbDLj3Mro99+hMvSwq85aMi23oSMKFY6za0sZq wkapMBb7DKkQSuhOXmqLvz9TLi0DnGLgkJtsz8pQgtesCCMN00P/T7YWUpTuw3919qpl pOAG6pKKFWUTqMJKaGiZCcGiMdTjtxn8Xrzbc5cNu5dUxBdlHrfBmbMo1VaMuV1Ob1QG gKYQ== X-Gm-Message-State: AElRT7Hlizr1+Z7b0RrUu5vZrnYSXEwQN7J9J+E71bkdt8v5fepMCy9+ WAq6EgyxYxLnLCu9TbP6C6/n7CDr X-Received: by 2002:a17:902:8f8f:: with SMTP id z15-v6mr9316838plo.315.1520881761389; Mon, 12 Mar 2018 12:09:21 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:0:1000:1511:8de6:27a8:ed13:2ef5]) by smtp.gmail.com with ESMTPSA id s67sm18038477pfg.104.2018.03.12.12.09.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 12:09:20 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Benson Leung Cc: Nick Dyer , Olof Johansson , linux-kernel@vger.kernel.org Subject: [PATCH 09/14] platform/chrome: chromeos_laptop - parse DMI IRQ data once Date: Mon, 12 Mar 2018 12:09:02 -0700 Message-Id: <20180312190907.174301-10-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.16.2.660.g709887971b-goog In-Reply-To: <20180312190907.174301-1-dmitry.torokhov@gmail.com> References: <20180312190907.174301-1-dmitry.torokhov@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of trying to parse DMI IRQ data every time we try to instantiate a device, let's do it once, when we identify the device we are working with. This allows us to mark chromeos_laptop_get_irq_from_dmi() as __init and discard it once module is initialized. Signed-off-by: Dmitry Torokhov --- drivers/platform/chrome/chromeos_laptop.c | 120 ++++++++++++---------- 1 file changed, 64 insertions(+), 56 deletions(-) diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c index 2a81ae4c15c93..d6d2bc6f3aaf0 100644 --- a/drivers/platform/chrome/chromeos_laptop.c +++ b/drivers/platform/chrome/chromeos_laptop.c @@ -68,26 +68,6 @@ struct chromeos_laptop { static struct chromeos_laptop *cros_laptop; -static int chromeos_laptop_get_irq_from_dmi(const char *dmi_name) -{ - const struct dmi_device *dmi_dev; - const struct dmi_dev_onboard *dev_data; - - dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, dmi_name, NULL); - if (!dmi_dev) { - pr_err("failed to find DMI device '%s'\n", dmi_name); - return -ENOENT; - } - - dev_data = dmi_dev->device_data; - if (!dev_data) { - pr_err("failed to get data from DMI for '%s'\n", dmi_name); - return -EINVAL; - } - - return dev_data->instance; -} - static struct i2c_client * chromes_laptop_instantiate_i2c_device(int bus, struct i2c_board_info *info, @@ -185,7 +165,6 @@ static int chromeos_laptop_add_peripheral(struct i2c_peripheral *i2c_dev) { struct i2c_client *client; int bus; - int irq; /* * Check that the i2c adapter is present. @@ -196,16 +175,6 @@ static int chromeos_laptop_add_peripheral(struct i2c_peripheral *i2c_dev) if (bus < 0) return bus == -ENODEV ? -EPROBE_DEFER : bus; - if (i2c_dev->dmi_name) { - irq = chromeos_laptop_get_irq_from_dmi(i2c_dev->dmi_name); - if (irq < 0) { - i2c_dev->state = FAILED; - return irq; - } - - i2c_dev->board_info.irq = irq; - } - client = chromes_laptop_instantiate_i2c_device(bus, &i2c_dev->board_info, i2c_dev->alt_addr); @@ -230,15 +199,6 @@ static int chromeos_laptop_add_peripheral(struct i2c_peripheral *i2c_dev) return 0; } -static int __init chromeos_laptop_dmi_matched(const struct dmi_system_id *id) -{ - cros_laptop = (void *)id->driver_data; - pr_debug("DMI Matched %s\n", id->ident); - - /* Indicate to dmi_scan that processing is done. */ - return 1; -} - static int chromeos_laptop_probe(struct platform_device *pdev) { struct i2c_peripheral *i2c_dev; @@ -499,10 +459,6 @@ static struct chromeos_laptop cr48 = { }, }; -#define _CBDD(board_) \ - .callback = chromeos_laptop_dmi_matched, \ - .driver_data = (void *)&board_ - static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { { .ident = "Samsung Series 5 550", @@ -510,14 +466,14 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"), DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"), }, - _CBDD(samsung_series_5_550), + .driver_data = (void *)&samsung_series_5_550, }, { .ident = "Samsung Series 5", .matches = { DMI_MATCH(DMI_PRODUCT_NAME, "Alex"), }, - _CBDD(samsung_series_5), + .driver_data = (void *)&samsung_series_5, }, { .ident = "Chromebook Pixel", @@ -525,7 +481,7 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"), DMI_MATCH(DMI_PRODUCT_NAME, "Link"), }, - _CBDD(chromebook_pixel), + .driver_data = (void *)&chromebook_pixel, }, { .ident = "Wolf", @@ -533,7 +489,7 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"), DMI_MATCH(DMI_PRODUCT_NAME, "Wolf"), }, - _CBDD(dell_chromebook_11), + .driver_data = (void *)&dell_chromebook_11, }, { .ident = "HP Chromebook 14", @@ -541,7 +497,7 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"), DMI_MATCH(DMI_PRODUCT_NAME, "Falco"), }, - _CBDD(hp_chromebook_14), + .driver_data = (void *)&hp_chromebook_14, }, { .ident = "Toshiba CB35", @@ -549,42 +505,42 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"), DMI_MATCH(DMI_PRODUCT_NAME, "Leon"), }, - _CBDD(toshiba_cb35), + .driver_data = (void *)&toshiba_cb35, }, { .ident = "Acer C7 Chromebook", .matches = { DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"), }, - _CBDD(acer_c7_chromebook), + .driver_data = (void *)&acer_c7_chromebook, }, { .ident = "Acer AC700", .matches = { DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"), }, - _CBDD(acer_ac700), + .driver_data = (void *)&acer_ac700, }, { .ident = "Acer C720", .matches = { DMI_MATCH(DMI_PRODUCT_NAME, "Peppy"), }, - _CBDD(acer_c720), + .driver_data = (void *)&acer_c720, }, { .ident = "HP Pavilion 14 Chromebook", .matches = { DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"), }, - _CBDD(hp_pavilion_14_chromebook), + .driver_data = (void *)&hp_pavilion_14_chromebook, }, { .ident = "Cr-48", .matches = { DMI_MATCH(DMI_PRODUCT_NAME, "Mario"), }, - _CBDD(cr48), + .driver_data = (void *)&cr48, }, { } }; @@ -599,15 +555,67 @@ static struct platform_driver cros_platform_driver = { .probe = chromeos_laptop_probe, }; +static int __init chromeos_laptop_get_irq_from_dmi(const char *dmi_name) +{ + const struct dmi_device *dmi_dev; + const struct dmi_dev_onboard *dev_data; + + dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, dmi_name, NULL); + if (!dmi_dev) { + pr_err("failed to find DMI device '%s'\n", dmi_name); + return -ENOENT; + } + + dev_data = dmi_dev->device_data; + if (!dev_data) { + pr_err("failed to get data from DMI for '%s'\n", dmi_name); + return -EINVAL; + } + + return dev_data->instance; +} + +static struct chromeos_laptop * __init +chromeos_laptop_prepare(const struct dmi_system_id *id) +{ + struct i2c_peripheral *i2c_dev; + int irq; + int i; + + cros_laptop = (void *)id->driver_data; + + for (i = 0; i < MAX_I2C_PERIPHERALS; i++) { + i2c_dev = &cros_laptop->i2c_peripherals[i]; + + if (!i2c_dev->dmi_name) + continue; + + irq = chromeos_laptop_get_irq_from_dmi(i2c_dev->dmi_name); + if (irq < 0) + return ERR_PTR(irq); + } + + return cros_laptop; +} + + static int __init chromeos_laptop_init(void) { + const struct dmi_system_id *dmi_id; int ret; - if (!dmi_check_system(chromeos_laptop_dmi_table)) { + dmi_id = dmi_first_match(chromeos_laptop_dmi_table); + if (!dmi_id) { pr_debug("unsupported system\n"); return -ENODEV; } + pr_debug("DMI Matched %s\n", dmi_id->ident); + + cros_laptop = chromeos_laptop_prepare(dmi_id->driver_data); + if (IS_ERR(cros_laptop)) + return PTR_ERR(cros_laptop); + ret = platform_driver_register(&cros_platform_driver); if (ret) return ret; -- 2.16.2.660.g709887971b-goog