Received: by 10.213.65.68 with SMTP id h4csp787310imn; Tue, 20 Mar 2018 15:36:59 -0700 (PDT) X-Google-Smtp-Source: AG47ELs6cCFVJGFYhHZnOxWdZcOCsDS02CqFE6VxzkmeCI874ac1sU5+tI/oA680SRqZi/uQhNa2 X-Received: by 2002:a17:902:8601:: with SMTP id f1-v6mr18289049plo.379.1521585419001; Tue, 20 Mar 2018 15:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521585418; cv=none; d=google.com; s=arc-20160816; b=ZGp6yaE9VCAM4Z3IuORbeGjvdL7d1FG73Y1mrjgztiyunbTdGvayEEsXJH7Cjp120r IJbhFuBqKxFGhpAdyRmPtd5Ot+rXbEKuA2C1orjrwkBxOwh5T4XMJaCRE0a9rQkOp0hY nOslQjatJl5ORUrDxJZMdag5sm4ooIKOPBATlJDyAcR9T0rlty6pLmZiIF65xXLHe4W+ mOlrBDwCl9d5Ygx2DF8LBYwfYAoc/7osvFeECjEqYiH3+RwT+Kf5YvgW7fGPQPEQg3Y+ ym3bysIM4AEIvKv9rReE6sk4CnEPeMU/2CIVTjrnonyjFNWp3S+rJRTUfeyS0pzVA/6a ARFw== 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=s4DfVh0KMM2B4RTTXIfjp85Zm1OJ5RqOkIdyBZmuEj0=; b=uK15iV4jgIeEBiJnL9ldBqyT/CkIMm15XzOFE87IWVxu1xnQRJP96GNKVL6BHVwCQA O8fXTcFWWp3hgxEk7T8SPq8AImOnBrFhSYZzFWf66LiTH0NiLYnd1Wroje/2sIbgbfbo uP6YkD8Ld0o8wyO2BzqqhwJ7UsMLEPd4R63EOFgYig3mSOwo6d8vb1i1FIwcHcEduplG WmlT3PzdsMaqzfRgvwM2ylXeZLN/mKWAtDgv8MbJpLKxslbB2U4BMLBYOdozaxInRyRH 5Q1616SEl/kL8CabQ4lx1v0ZUdVwk1juHPoHjrDuSpbxVgAZHttjiYryuFYa0vf2vlQv 7ESw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HQZqDVwX; 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 a68si1788652pgc.467.2018.03.20.15.36.44; Tue, 20 Mar 2018 15:36:58 -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=HQZqDVwX; 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 S1752101AbeCTWeC (ORCPT + 99 others); Tue, 20 Mar 2018 18:34:02 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33337 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751714AbeCTWbz (ORCPT ); Tue, 20 Mar 2018 18:31:55 -0400 Received: by mail-pf0-f194.google.com with SMTP id 123so1240711pfe.0; Tue, 20 Mar 2018 15:31:55 -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=s4DfVh0KMM2B4RTTXIfjp85Zm1OJ5RqOkIdyBZmuEj0=; b=HQZqDVwXwyB13jwhpvYlChmxKhH5bLlQuIBRLe33BBUM9jSXKcfuVgwLUy03wXu8rG /SylCsjyih++rlxnLnhXHX7VdsrFxF4qFbGienohIAs6Y3Lw609DaY0DdkOYVeKQwvFf 3X5uhl/u7hhKjhq5Xf91SmJXrIuKZfd1BipnnEIwSrwJ5arP6mgt/S+ruUh+Ga/DOJuh RZmjCX3qJiQnzI2Iimwvk5JUz5WoHCVzMrVQuheu6qdmFj+p4Ktybk6tCVsXDRNGRRtx aK7XDLGr9F22jFESlwS+A7hKbImkgmYqLbrFNo1moFYJfLjWPKilnwgluqlVYmwAyIUK gaBw== 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=s4DfVh0KMM2B4RTTXIfjp85Zm1OJ5RqOkIdyBZmuEj0=; b=PJYa8CKlPM0HXF5EDtI7cYcOk/cbpOmyldjeCOzh3Xq66aXMB6koJ7xohnQdAWFWEX sSriOIr5+3F8nB4H9Gh3LPxdF3EE5Hrpb4ODodVafuwvsvyKO6pK+dKlgd1GvzrqxCe6 90nfXoHSHK14ZsP48t9KaaDf1GaiTikY2TlZoVFKuLW+m7hpv1PjGenAqWH1hr67H0Hj 0+xpL/PmvM3kbDYEv+EClEhp9G9CNg0kdlsEwv++y8vqwilqND926LJ/fIdGgzVZOpBZ vDx3Zlv75Qq3szcKdg2/b9YvKKf8N55t6aCX71hhH5aNmqushCulxcoATV9wEgKjeDFV Xt6A== X-Gm-Message-State: AElRT7Ec/LhGIY3lmZkmpDVnOaxvup9klS5dj69fcMnNQCnu3uNlsqTX Xl6jUI1ivNc+p6sAtPjrMeUrcAKQ X-Received: by 10.101.69.198 with SMTP id m6mr12521606pgr.244.1521585114312; Tue, 20 Mar 2018 15:31:54 -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 r20sm6108360pff.165.2018.03.20.15.31.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Mar 2018 15:31:52 -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 v2 09/14] platform/chrome: chromeos_laptop - parse DMI IRQ data once Date: Tue, 20 Mar 2018 15:31:33 -0700 Message-Id: <20180320223138.234724-10-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.16.2.804.g6dcf76e118-goog In-Reply-To: <20180320223138.234724-1-dmitry.torokhov@gmail.com> References: <20180320223138.234724-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.804.g6dcf76e118-goog