Received: by 10.213.65.68 with SMTP id h4csp239175imn; Mon, 12 Mar 2018 12:13:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELtdBAaGUQ5tygDBtMwGbDrYO9zwMcvhYO+W5KRjT18ORZCkAWodNGRAmjrnEpP983jqEJsQ X-Received: by 2002:a17:902:690b:: with SMTP id j11-v6mr9315951plk.124.1520882024012; Mon, 12 Mar 2018 12:13:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520882023; cv=none; d=google.com; s=arc-20160816; b=LH88mJsJv6cL5Sm3Od6nCVAp4bETDWToBLJqwtnBSZmDQc536ZsHqhDAca5Ez2zh2i KJ2spkGGmoA2CA+mCh8wZ5xmWtp1gBDWLj7nDLzq0DMp0eu3zGIp/xDLR9qintnGP6wT BLM26t7CFOWqhHPyiO35VkuDmkgn5OqpwV6B4Z5r0O14OkFg/n937bOnLLuR2Fl29gBP VMB/PkVqqwE1uMgFhW4o6+8dn0Oxi+6NbJc5StaTmKVUiTISgqCysAWBrcBRGNdSVKcm xXJ/JlINOHuZbPBNTc+oxcie4KtOqzA38WK3WT4wJUYwZZOz3OregB5GpAk54TxhgOzX UKIQ== 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=YkQV3X8wOCYJZpxTrSagmd18vL6LlC88/cIsk7ZiD2E=; b=qyDRqcwOntKgbR6ny4WJOjQy3XDGt5JsAL8WyPqbaWOvMd1NGpI+ASPTnKv3kOkIUQ GyurS+c1rZyK/OayBapbrPqMs4qtk40786WCueScMqsvs2DTQI1rokN2eYR6c0Djfv9C +jo1Xywwl58QH5ogGh3nOLmEZ2kWw8DVuivig9FmSDtwpuHtDBs1eNBINLpn6LbIkHYl 44zt/BYGWsebk3M6iv+wBlRle6IgynzYSzn31Rp0xHG+xHfmQx48L8C8jK5P279Gyvy3 zC1uF+tbp+lRyS1vaAVi9wJuEQu3MBX3UIj+H+fKcPMehpeOiuVCEnxBxOppSgz2rO7s 5d4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lw5i1g7o; 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 g1si5452553pgo.257.2018.03.12.12.13.29; Mon, 12 Mar 2018 12:13:43 -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=lw5i1g7o; 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 S932619AbeCLTLW (ORCPT + 99 others); Mon, 12 Mar 2018 15:11:22 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:32838 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751478AbeCLTJV (ORCPT ); Mon, 12 Mar 2018 15:09:21 -0400 Received: by mail-pl0-f65.google.com with SMTP id c11-v6so9888382plo.0; Mon, 12 Mar 2018 12:09:21 -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=YkQV3X8wOCYJZpxTrSagmd18vL6LlC88/cIsk7ZiD2E=; b=lw5i1g7o1zQP/ho75drDDpb9hZMya9cmnEFBG3eJ4vaCitlOUk6fm63cAEOyX+5Xkp 9jTO1DXyuBJ9Jgma7+Iyl15o6gHvidpe44Nj5CySUalEuclZraS0YBg1JY2rVhURkNUg vL/WW0WdvRJrUqG+Ew8F+k90sf3et05ZRNO3Ebm8v4Hguy72lXG6zbkpFsU/JD1W47jF 3VTyQqz+xPRXHhUHIn+ZJSqPPO78uBZT2pctnb8HvR5clY3sR9nlyvcZk25t5zfTYkuO DnVeDP1PTBPy4Tpc2Ixv9HqsTXMvPkt/9M1oa1kldWGCkfIa6scWFKTVDgo84Psq/wc5 /M/Q== 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=YkQV3X8wOCYJZpxTrSagmd18vL6LlC88/cIsk7ZiD2E=; b=t0oJLKZ/fZGil50DwQ3pGBDrv0yMk65YRZv//1wWf1O/YexlwS4uzeUO0kLslTH0K1 arO6HfM9rC/9ffL4XFV4p8wBpTkT68H4c87RfnIVmETYvICul/Ifdogat/QePHil/+GI SKGKKM9zpu30OJj7bg9SI8C0RuHddtg0y/IVjjZb/O1ZMNMtOwvCXebfRX994KNULM4L 5syBr28zRxRJzeA6mKpnEnsH80VWcJZ+WIb+FEO4ljZPU4bK3bUtuBRhqZvRL3wDPVje 41+wkJ6UpxPJZrFoKqA7RDG35Fjx4pEymeP43AcQwRRI25ueJxzmtaQS3J4yB75Zq2zm wRtQ== X-Gm-Message-State: AElRT7E2YkJwy1hVbEV0/UHY1rDqbQVo9TgrClOlg1BaWpY7GE8CFfFQ sl/5PRFyyaCnoUUEhi8jQRWnRaHh X-Received: by 2002:a17:902:2e83:: with SMTP id r3-v6mr9412675plb.84.1520881760515; Mon, 12 Mar 2018 12:09:20 -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.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 12:09:19 -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 08/14] platform/chrome: chromeos_laptop - rework i2c peripherals initialization Date: Mon, 12 Mar 2018 12:09:01 -0700 Message-Id: <20180312190907.174301-9-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 having separate setup() functions responsible for instantiating i2c client for each peripheral, let's generalize the behavior and use common code for instantiating all i2c peripherals. Signed-off-by: Dmitry Torokhov --- drivers/platform/chrome/chromeos_laptop.c | 467 +++++++++++----------- 1 file changed, 235 insertions(+), 232 deletions(-) diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c index 96e962ff38e87..2a81ae4c15c93 100644 --- a/drivers/platform/chrome/chromeos_laptop.c +++ b/drivers/platform/chrome/chromeos_laptop.c @@ -25,10 +25,6 @@ #define MAX_I2C_DEVICE_DEFERRALS 5 -static struct i2c_client *als; -static struct i2c_client *tp; -static struct i2c_client *ts; - static const char *i2c_adapter_names[] = { "SMBus I801 adapter", "i915 gmbus vga", @@ -50,12 +46,17 @@ enum i2c_peripheral_state { UNPROBED = 0, PROBED, TIMEDOUT, + FAILED, }; struct i2c_peripheral { - int (*add)(enum i2c_adapter_type type); + struct i2c_board_info board_info; + unsigned short alt_addr; + const char *dmi_name; enum i2c_adapter_type type; + enum i2c_peripheral_state state; + struct i2c_client *client; int tries; }; @@ -67,59 +68,6 @@ struct chromeos_laptop { static struct chromeos_laptop *cros_laptop; -static struct i2c_board_info cyapa_device = { - I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), - .flags = I2C_CLIENT_WAKE, -}; - -static struct i2c_board_info elantech_device = { - I2C_BOARD_INFO("elan_i2c", ELAN_TP_I2C_ADDR), - .flags = I2C_CLIENT_WAKE, -}; - -static struct i2c_board_info isl_als_device = { - I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR), -}; - -static struct i2c_board_info tsl2583_als_device = { - I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR), -}; - -static struct i2c_board_info tsl2563_als_device = { - I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR), -}; - -static int mxt_t19_keys[] = { - KEY_RESERVED, - KEY_RESERVED, - KEY_RESERVED, - KEY_RESERVED, - KEY_RESERVED, - BTN_LEFT -}; - -static struct mxt_platform_data atmel_224s_tp_platform_data = { - .irqflags = IRQF_TRIGGER_FALLING, - .t19_num_keys = ARRAY_SIZE(mxt_t19_keys), - .t19_keymap = mxt_t19_keys, -}; - -static struct i2c_board_info atmel_224s_tp_device = { - I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR), - .platform_data = &atmel_224s_tp_platform_data, - .flags = I2C_CLIENT_WAKE, -}; - -static struct mxt_platform_data atmel_1664s_platform_data = { - .irqflags = IRQF_TRIGGER_FALLING, -}; - -static struct i2c_board_info atmel_1664s_device = { - I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR), - .platform_data = &atmel_1664s_platform_data, - .flags = I2C_CLIENT_WAKE, -}; - static int chromeos_laptop_get_irq_from_dmi(const char *dmi_name) { const struct dmi_device *dmi_dev; @@ -140,29 +88,15 @@ static int chromeos_laptop_get_irq_from_dmi(const char *dmi_name) return dev_data->instance; } -static struct i2c_client *__add_probed_i2c_device( - const char *name, - int bus, - struct i2c_board_info *info, - const unsigned short *alt_addr_list) +static struct i2c_client * +chromes_laptop_instantiate_i2c_device(int bus, + struct i2c_board_info *info, + unsigned short alt_addr) { struct i2c_adapter *adapter; struct i2c_client *client = NULL; const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END }; - if (bus < 0) - return NULL; - - /* - * If a name is specified, look for irq platform information stashed - * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware. - */ - if (name) { - info->irq = chromeos_laptop_get_irq_from_dmi(name); - if (info->irq < 0) - return NULL; - } - adapter = i2c_get_adapter(bus); if (!adapter) { pr_err("failed to get i2c adapter %d\n", bus); @@ -175,10 +109,13 @@ static struct i2c_client *__add_probed_i2c_device( * structure gets assigned primary address. */ client = i2c_new_probed_device(adapter, info, addr_list, NULL); - if (!client && alt_addr_list) { + if (!client && alt_addr) { struct i2c_board_info dummy_info = { I2C_BOARD_INFO("dummy", info->addr), }; + const unsigned short alt_addr_list[] = { + alt_addr, I2C_CLIENT_END + }; struct i2c_client *dummy; dummy = i2c_new_probed_device(adapter, &dummy_info, @@ -244,115 +181,53 @@ static int find_i2c_adapter_num(enum i2c_adapter_type type) return adapter->nr; } -/* - * Takes a list of addresses in addrs as such : - * { addr1, ... , addrn, I2C_CLIENT_END }; - * add_probed_i2c_device will use i2c_new_probed_device - * and probe for devices at all of the addresses listed. - * Returns NULL if no devices found. - * See Documentation/i2c/instantiating-devices for more information. - */ -static struct i2c_client *add_probed_i2c_device( - const char *name, - enum i2c_adapter_type type, - struct i2c_board_info *info, - const unsigned short *addrs) +static int chromeos_laptop_add_peripheral(struct i2c_peripheral *i2c_dev) { - return __add_probed_i2c_device(name, - find_i2c_adapter_num(type), - info, - addrs); -} + struct i2c_client *client; + int bus; + int irq; -/* - * Probes for a device at a single address, the one provided by - * info->addr. - * Returns NULL if no device found. - */ -static struct i2c_client *add_i2c_device(const char *name, - enum i2c_adapter_type type, - struct i2c_board_info *info) -{ - return __add_probed_i2c_device(name, - find_i2c_adapter_num(type), - info, - NULL); -} - -static int setup_cyapa_tp(enum i2c_adapter_type type) -{ - if (tp) - return 0; - - /* add cyapa touchpad */ - tp = add_i2c_device("trackpad", type, &cyapa_device); - return (!tp) ? -EAGAIN : 0; -} - -static int setup_atmel_224s_tp(enum i2c_adapter_type type) -{ - const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR, - I2C_CLIENT_END }; - if (tp) - return 0; - - /* add atmel mxt touchpad */ - tp = add_probed_i2c_device("trackpad", type, - &atmel_224s_tp_device, addr_list); - return (!tp) ? -EAGAIN : 0; -} - -static int setup_elantech_tp(enum i2c_adapter_type type) -{ - if (tp) - return 0; - - /* add elantech touchpad */ - tp = add_i2c_device("trackpad", type, &elantech_device); - return (!tp) ? -EAGAIN : 0; -} - -static int setup_atmel_1664s_ts(enum i2c_adapter_type type) -{ - const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR, - I2C_CLIENT_END }; - if (ts) - return 0; - - /* add atmel mxt touch device */ - ts = add_probed_i2c_device("touchscreen", type, - &atmel_1664s_device, addr_list); - return (!ts) ? -EAGAIN : 0; -} - -static int setup_isl29018_als(enum i2c_adapter_type type) -{ - if (als) - return 0; + /* + * Check that the i2c adapter is present. + * -EPROBE_DEFER if missing as the adapter may appear much + * later. + */ + bus = find_i2c_adapter_num(i2c_dev->type); + if (bus < 0) + return bus == -ENODEV ? -EPROBE_DEFER : bus; - /* add isl29018 light sensor */ - als = add_i2c_device("lightsensor", type, &isl_als_device); - return (!als) ? -EAGAIN : 0; -} + 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; + } -static int setup_tsl2583_als(enum i2c_adapter_type type) -{ - if (als) - return 0; + i2c_dev->board_info.irq = irq; + } - /* add tsl2583 light sensor */ - als = add_i2c_device(NULL, type, &tsl2583_als_device); - return (!als) ? -EAGAIN : 0; -} + client = chromes_laptop_instantiate_i2c_device(bus, + &i2c_dev->board_info, + i2c_dev->alt_addr); + if (!client) { + /* + * Set -EPROBE_DEFER a limited num of times + * if device is not successfully added. + */ + if (++i2c_dev->tries < MAX_I2C_DEVICE_DEFERRALS) { + return -EPROBE_DEFER; + } else { + /* Ran out of tries. */ + pr_notice("ran out of tries for device.\n"); + i2c_dev->state = TIMEDOUT; + return -EIO; + } + } -static int setup_tsl2563_als(enum i2c_adapter_type type) -{ - if (als) - return 0; + i2c_dev->client = client; + i2c_dev->state = PROBED; - /* add tsl2563 light sensor */ - als = add_i2c_device(NULL, type, &tsl2563_als_device); - return (!als) ? -EAGAIN : 0; + return 0; } static int __init chromeos_laptop_dmi_matched(const struct dmi_system_id *id) @@ -366,47 +241,22 @@ static int __init chromeos_laptop_dmi_matched(const struct dmi_system_id *id) static int chromeos_laptop_probe(struct platform_device *pdev) { + struct i2c_peripheral *i2c_dev; int i; int ret = 0; for (i = 0; i < MAX_I2C_PERIPHERALS; i++) { - struct i2c_peripheral *i2c_dev; - i2c_dev = &cros_laptop->i2c_peripherals[i]; /* No more peripherals. */ - if (i2c_dev->add == NULL) + if (!i2c_dev->board_info.addr) break; - if (i2c_dev->state == TIMEDOUT || i2c_dev->state == PROBED) + if (i2c_dev->state != UNPROBED) continue; - /* - * Check that the i2c adapter is present. - * -EPROBE_DEFER if missing as the adapter may appear much - * later. - */ - if (find_i2c_adapter_num(i2c_dev->type) == -ENODEV) { + if (chromeos_laptop_add_peripheral(i2c_dev) == -EPROBE_DEFER) ret = -EPROBE_DEFER; - continue; - } - - /* Add the device. */ - if (i2c_dev->add(i2c_dev->type) == -EAGAIN) { - /* - * Set -EPROBE_DEFER a limited num of times - * if device is not successfully added. - */ - if (++i2c_dev->tries < MAX_I2C_DEVICE_DEFERRALS) { - ret = -EPROBE_DEFER; - } else { - /* Ran out of tries. */ - pr_notice("ran out of tries for device.\n"); - i2c_dev->state = TIMEDOUT; - } - } else { - i2c_dev->state = PROBED; - } } return ret; @@ -415,91 +265,237 @@ static int chromeos_laptop_probe(struct platform_device *pdev) static struct chromeos_laptop samsung_series_5_550 = { .i2c_peripherals = { /* Touchpad. */ - { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS }, + { + .board_info = { + I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), + .flags = I2C_CLIENT_WAKE, + }, + .dmi_name = "trackpad", + .type = I2C_ADAPTER_SMBUS, + }, /* Light Sensor. */ - { .add = setup_isl29018_als, I2C_ADAPTER_SMBUS }, + { + .board_info = { + I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR), + }, + .dmi_name = "lightsensor", + .type = I2C_ADAPTER_SMBUS, + }, }, }; static struct chromeos_laptop samsung_series_5 = { .i2c_peripherals = { /* Light Sensor. */ - { .add = setup_tsl2583_als, I2C_ADAPTER_SMBUS }, + { + .board_info = { + I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR), + }, + .type = I2C_ADAPTER_SMBUS, + }, }, }; +static struct mxt_platform_data atmel_1664s_platform_data = { + .irqflags = IRQF_TRIGGER_FALLING, +}; + +static int chromebook_pixel_tp_keys[] = { + KEY_RESERVED, + KEY_RESERVED, + KEY_RESERVED, + KEY_RESERVED, + KEY_RESERVED, + BTN_LEFT +}; + +static struct mxt_platform_data chromebook_pixel_tp_platform_data = { + .irqflags = IRQF_TRIGGER_FALLING, + .t19_num_keys = ARRAY_SIZE(chromebook_pixel_tp_keys), + .t19_keymap = chromebook_pixel_tp_keys, +}; + static struct chromeos_laptop chromebook_pixel = { .i2c_peripherals = { /* Touch Screen. */ - { .add = setup_atmel_1664s_ts, I2C_ADAPTER_PANEL }, + { + .board_info = { + I2C_BOARD_INFO("atmel_mxt_ts", + ATMEL_TS_I2C_ADDR), + .platform_data = &atmel_1664s_platform_data, + .flags = I2C_CLIENT_WAKE, + }, + .dmi_name = "touchscreen", + .type = I2C_ADAPTER_PANEL, + .alt_addr = ATMEL_TS_I2C_BL_ADDR, + }, /* Touchpad. */ - { .add = setup_atmel_224s_tp, I2C_ADAPTER_VGADDC }, + { + .board_info = { + I2C_BOARD_INFO("atmel_mxt_tp", + ATMEL_TP_I2C_ADDR), + .platform_data = + &chromebook_pixel_tp_platform_data, + .flags = I2C_CLIENT_WAKE, + }, + .dmi_name = "trackpad", + .type = I2C_ADAPTER_VGADDC, + .alt_addr = ATMEL_TP_I2C_BL_ADDR, + }, /* Light Sensor. */ - { .add = setup_isl29018_als, I2C_ADAPTER_PANEL }, + { + .board_info = { + I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR), + }, + .dmi_name = "lightsensor", + .type = I2C_ADAPTER_PANEL, + }, }, }; static struct chromeos_laptop hp_chromebook_14 = { .i2c_peripherals = { /* Touchpad. */ - { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, + { + .board_info = { + I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), + .flags = I2C_CLIENT_WAKE, + }, + .dmi_name = "trackpad", + .type = I2C_ADAPTER_DESIGNWARE_0, + }, }, }; static struct chromeos_laptop dell_chromebook_11 = { .i2c_peripherals = { /* Touchpad. */ - { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, + { + .board_info = { + I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), + .flags = I2C_CLIENT_WAKE, + }, + .dmi_name = "trackpad", + .type = I2C_ADAPTER_DESIGNWARE_0, + }, /* Elan Touchpad option. */ - { .add = setup_elantech_tp, I2C_ADAPTER_DESIGNWARE_0 }, + { + .board_info = { + I2C_BOARD_INFO("elan_i2c", ELAN_TP_I2C_ADDR), + .flags = I2C_CLIENT_WAKE, + }, + .dmi_name = "trackpad", + .type = I2C_ADAPTER_DESIGNWARE_0, + }, }, }; static struct chromeos_laptop toshiba_cb35 = { .i2c_peripherals = { /* Touchpad. */ - { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, + { + .board_info = { + I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), + .flags = I2C_CLIENT_WAKE, + }, + .dmi_name = "trackpad", + .type = I2C_ADAPTER_DESIGNWARE_0, + }, }, }; static struct chromeos_laptop acer_c7_chromebook = { .i2c_peripherals = { /* Touchpad. */ - { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS }, + { + .board_info = { + I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), + .flags = I2C_CLIENT_WAKE, + }, + .dmi_name = "trackpad", + .type = I2C_ADAPTER_SMBUS, + }, }, }; static struct chromeos_laptop acer_ac700 = { .i2c_peripherals = { /* Light Sensor. */ - { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS }, + { + .board_info = { + I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR), + }, + .type = I2C_ADAPTER_SMBUS, + }, }, }; static struct chromeos_laptop acer_c720 = { .i2c_peripherals = { /* Touchscreen. */ - { .add = setup_atmel_1664s_ts, I2C_ADAPTER_DESIGNWARE_1 }, + { + .board_info = { + I2C_BOARD_INFO("atmel_mxt_ts", + ATMEL_TS_I2C_ADDR), + .platform_data = &atmel_1664s_platform_data, + .flags = I2C_CLIENT_WAKE, + }, + .dmi_name = "touchscreen", + .type = I2C_ADAPTER_DESIGNWARE_1, + .alt_addr = ATMEL_TS_I2C_BL_ADDR, + }, /* Touchpad. */ - { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, + { + .board_info = { + I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), + .flags = I2C_CLIENT_WAKE, + }, + .dmi_name = "trackpad", + .type = I2C_ADAPTER_DESIGNWARE_0, + }, /* Elan Touchpad option. */ - { .add = setup_elantech_tp, I2C_ADAPTER_DESIGNWARE_0 }, + { + .board_info = { + I2C_BOARD_INFO("elan_i2c", ELAN_TP_I2C_ADDR), + .flags = I2C_CLIENT_WAKE, + }, + .dmi_name = "trackpad", + .type = I2C_ADAPTER_DESIGNWARE_0, + }, /* Light Sensor. */ - { .add = setup_isl29018_als, I2C_ADAPTER_DESIGNWARE_1 }, + { + .board_info = { + I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR), + }, + .dmi_name = "lightsensor", + .type = I2C_ADAPTER_DESIGNWARE_1, + }, }, }; static struct chromeos_laptop hp_pavilion_14_chromebook = { .i2c_peripherals = { /* Touchpad. */ - { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS }, + { + .board_info = { + I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), + .flags = I2C_CLIENT_WAKE, + }, + .dmi_name = "trackpad", + .type = I2C_ADAPTER_SMBUS, + }, }, }; static struct chromeos_laptop cr48 = { .i2c_peripherals = { /* Light Sensor. */ - { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS }, + { + .board_info = { + I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR), + }, + .type = I2C_ADAPTER_SMBUS, + }, }, }; @@ -637,15 +633,22 @@ static int __init chromeos_laptop_init(void) static void __exit chromeos_laptop_exit(void) { - if (als) - i2c_unregister_device(als); - if (tp) - i2c_unregister_device(tp); - if (ts) - i2c_unregister_device(ts); + struct i2c_peripheral *i2c_dev; + int i; platform_device_unregister(cros_platform_device); platform_driver_unregister(&cros_platform_driver); + + for (i = 0; i < MAX_I2C_PERIPHERALS; i++) { + i2c_dev = &cros_laptop->i2c_peripherals[i]; + + /* No more peripherals */ + if (!i2c_dev->board_info.type) + break; + + if (i2c_dev->state == PROBED) + i2c_unregister_device(i2c_dev->client); + } } module_init(chromeos_laptop_init); -- 2.16.2.660.g709887971b-goog