Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1359298pxb; Sat, 30 Oct 2021 11:33:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCh2ns4lEMFZD9HKLKr1C3LN8YjuhNmhzZtjpjFj5dYHOGeu+WNN+F0IOdLGCEx3RQXWcp X-Received: by 2002:a17:906:f195:: with SMTP id gs21mr20561480ejb.308.1635618793384; Sat, 30 Oct 2021 11:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635618793; cv=none; d=google.com; s=arc-20160816; b=ZW8UwETgDX6KOXXckhNELZ8GRmw6kxDBKzJUgrUxAZh66QXoIdu1IHzMBHvjWLd46L 7JpdZVj3d3UF2+ecbsA+dzWpQAyTgN/HtgRFknltnEd6BRn2v3DdKy3twj4+K0M7BFco N4aZiFXkviMU9YN0j7rbDA/OJfWNKyA5YzgNWizrmCvo20AvaspS/VUoqZ0YZ/8eHHqB I+URqFSsmo5e2UmE8DHHF2YdX9VK2Qz0TfVcylRGQxn+o6l02rSGDJt/BLadIUj6Kx4H L9J57A+rDIXh1PyIAmduPFMhJemYxZwr0POYm2ZYms+S76YnLaRLdlUwNg5LMb7t5a2t OGdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EUspNMepzsV3gt9zAr51OvvfE1pc4mjqmhHE949y10A=; b=J0dDfy/AysRfIld42w363gYUdCWnNCBzo00ne2DZB2gpLo5ISqlV9KeW8+ccaAJNjj iQIagDCwToFWBwABE6gVGoIR5OcPUwufnbq0rSUaNQIaREKrFt3lgBeHTvybvG6h6f26 rm9XbYBRsnHSb0ol0VpQYyDuv+XBgNqv7xyM/x5ljZYCVYfC989LFjRmK/7aoOH+VpQo 6pU7d1b6JmKLBkC71iDSlhrazyWQGUnPYxgWoYuAx0xObk1BgUr1W6k20hwssa7rYrPv V2yAupr7PedMiEoJbOvuk1qECzVD4ZPwFbHExWEDaHJUWvpzpvNzbvlbOgkJLYuqK/+x 55sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R9JtdvUq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qa42si15240170ejc.738.2021.10.30.11.32.20; Sat, 30 Oct 2021 11:33:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R9JtdvUq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232221AbhJ3Sbq (ORCPT + 99 others); Sat, 30 Oct 2021 14:31:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37754 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232135AbhJ3Sb0 (ORCPT ); Sat, 30 Oct 2021 14:31:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618535; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EUspNMepzsV3gt9zAr51OvvfE1pc4mjqmhHE949y10A=; b=R9JtdvUqOybZ0mW1j0/16+h2wVw4tMvP2qFco4W7Z6jCgbZcyRacaYLdXodblHF0xMg7BP 60UNisq3M48/MmjDZj1JNsQvrby4ZXeHeRcKWe1NysgFBQhHedUi1P4QZZ0TRQQk0CchHY DtLsUkWVSIcWZwLn8aeVjVi8axQUGZE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-209-bnG8VKYiNyujiy2At0-kPA-1; Sat, 30 Oct 2021 14:28:53 -0400 X-MC-Unique: bnG8VKYiNyujiy2At0-kPA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B5048018AC; Sat, 30 Oct 2021 18:28:51 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id B83845F4E1; Sat, 30 Oct 2021 18:28:48 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH 11/13] i2c: cht-wc: Add support for devices using a bq25890 charger Date: Sat, 30 Oct 2021 20:28:11 +0200 Message-Id: <20211030182813.116672-12-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The i2c-controller on the Cherry Trail - Whiskey Cove PMIC is special in that it is always connected to the I2C charger IC of the board on which the PMIC is used; and the charger IC is not described in ACPI, so the i2c-cht-wc code needs to instantiate an i2c-client for it itself. So far there has been a rudimentary check to make sure the ACPI tables are at least somewhat as expected by checking for the presence of an INT33FE device and sofar the code has assumed that if this INT33FE device is present that the used charger then is a bq24290i. But some boards with an INT33FE device in their ACPI tables use a different charger IC and some boards don't have an INT33FE device at all. Since the information about the used charger + fuel-gauge + other chips is necessary in other places too, the kernel now adds a "intel,cht-wc-setup" string property to the Whiskey Cove PMIC i2c-client based on DMI matching, which reliably describes the board's setup of the PMIC. Switch to using the "intel,cht-wc-setup" property and add support for instantiating an i2c-client for either a bq24292i or a bq25890 charger. This has been tested on a GPD pocket (which uses the old bq24292i setup) and on a Xiaomi Mi Pad 2 with a bq25890 charger. Signed-off-by: Hans de Goede --- drivers/i2c/busses/i2c-cht-wc.c | 77 +++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/drivers/i2c/busses/i2c-cht-wc.c b/drivers/i2c/busses/i2c-cht-wc.c index 1cf68f85b2e1..e7d62af6c39d 100644 --- a/drivers/i2c/busses/i2c-cht-wc.c +++ b/drivers/i2c/busses/i2c-cht-wc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #define CHT_WC_I2C_CTRL 0x5e24 @@ -304,18 +305,55 @@ static struct bq24190_platform_data bq24190_pdata = { .regulator_init_data = &bq24190_vbus_init_data, }; +static struct i2c_board_info bq24190_board_info = { + .type = "bq24190", + .addr = 0x6b, + .dev_name = "bq24190", + .swnode = &bq24190_node, + .platform_data = &bq24190_pdata, +}; + +static struct regulator_consumer_supply bq25890_vbus_consumer = { + .supply = "vbus", + .dev_name = "cht_wcove_pwrsrc", +}; + +static const struct regulator_init_data bq25890_vbus_init_data = { + .constraints = { + .valid_ops_mask = REGULATOR_CHANGE_STATUS, + }, + .consumer_supplies = &bq25890_vbus_consumer, + .num_consumer_supplies = 1, +}; + +static struct bq25890_platform_data bq25890_pdata = { + .regulator_init_data = &bq25890_vbus_init_data, +}; + +static const struct property_entry bq25890_props[] = { + PROPERTY_ENTRY_BOOL("ti,skip-init"), + { } +}; + +static const struct software_node bq25890_node = { + .properties = bq25890_props, +}; + +static struct i2c_board_info bq25890_board_info = { + .type = "bq25890", + .addr = 0x6a, + .dev_name = "bq25890", + .swnode = &bq25890_node, + .platform_data = &bq25890_pdata, +}; + static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev) { struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent); + struct i2c_board_info *board_info = NULL; struct cht_wc_i2c_adap *adap; - struct i2c_board_info board_info = { - .type = "bq24190", - .addr = 0x6b, - .dev_name = "bq24190", - .swnode = &bq24190_node, - .platform_data = &bq24190_pdata, - }; int ret, reg, irq; + const char *str; irq = platform_get_irq(pdev, 0); if (irq < 0) @@ -379,17 +417,20 @@ static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev) if (ret) goto remove_irq_domain; - /* - * Normally the Whiskey Cove PMIC is paired with a TI bq24292i charger, - * connected to this i2c bus, and a max17047 fuel-gauge and a fusb302 - * USB Type-C controller connected to another i2c bus. In this setup - * the max17047 and fusb302 devices are enumerated through an INT33FE - * ACPI device. If this device is present register an i2c-client for - * the TI bq24292i charger. - */ - if (acpi_dev_present("INT33FE", NULL, -1)) { - board_info.irq = adap->client_irq; - adap->client = i2c_new_client_device(&adap->adapter, &board_info); + ret = device_property_read_string(pdev->dev.parent, "intel,cht-wc-setup", &str); + if (ret) + dev_warn(&pdev->dev, "intel,cht-wc-setup not set, not instantiating charger device\n"); + else if (!strcmp(str, "bq24292i,max17047,fusb302,pi3usb30532")) + board_info = &bq24190_board_info; + else if (!strcmp(str, "bq25890,bq27520")) + board_info = &bq25890_board_info; + else + dev_warn(&pdev->dev, "Unknown intel,cht-wc-setup value: '%s', not instantiating charger device\n", + str); + + if (board_info) { + board_info->irq = adap->client_irq; + adap->client = i2c_new_client_device(&adap->adapter, board_info); if (IS_ERR(adap->client)) { ret = PTR_ERR(adap->client); goto del_adapter; -- 2.31.1