From nobody Sat Nov 23 22:44:40 2024 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 144A117E01B; Mon, 18 Nov 2024 10:10:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731924604; cv=none; b=mkvzTTm7kGM0c4qILeVr0xrOBZWXo3x3ZW0XOWeM4KoVsY7HTkcHoF35cIkgSfutOXW1tMVhpZK7OQXLOtgZ7wDUAu2p67afjwFsWRYxEPqij9QRyY8CIvPLvwaiCfRfbCiizs4dlH0d59eXjuvfElx3Qd2ZWriWfLGx3qscpzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731924604; c=relaxed/simple; bh=gES/YI8J+uY43qFcYFJFQDdZCjIIvFKdVHt8Cx7j4Ks=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mz+RVnwbbB3XZ2TKBIhsxDoDl8pwyL3B28vWhl6ppdZE1WQzz2iVQsd7uzWogqujofBYVYpZ5dgzWPaho4nNE8Imnt+R2xVE0kjTGJ9dKs7BZTdhn676ghdbL8m6mEESKA1Dz5uiGkMBGIl8g9tn8mq+uXdFeKvNJYAQLlft84s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GPco839/; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GPco839/" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a9ed7d8d4e0so295340866b.1; Mon, 18 Nov 2024 02:10:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731924601; x=1732529401; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=n7VSA4VpES10XaA8gB1WdvZsXgmDNfsDCe5+S5WIIkA=; b=GPco839/KyBONRxrQ5zWKXot949TXU9qtzC+erfZEsq/KpmVQC08De+QDkibWc6V5O e0u4WYxXqzsCtGNRa38yq48OaEaOpPCSlUXjNo2kby3sVHDejkRvXBqPu8zkubGTAFEY Co2FS4k6VAjSGwaIo4c4AO4KBXvMAwuGtmoXvAnWAhzOXiNTE7zi821KJdb21Wuse6mA 6mES9s0i+rqH4QyPpuPHlip3Mr2NPbnqZtJHFKxORkFbEcFBmjxwQZX1pcndhzuK0NEd Px9S7gEDWqTbzfLrWArZBM+y5BCUsekMyefTbvdMLA0sXdDMT5s1wrJIdsVY4tSiAekl MCqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731924601; x=1732529401; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n7VSA4VpES10XaA8gB1WdvZsXgmDNfsDCe5+S5WIIkA=; b=AHXfLYIMJuJcnNXJR7gOk5oYytFLTDhYEFsG3C7sbJQE1xSkKJsrca0FaD0RcPQC2a xMJedAzMNmw/W7ewmgPNCnlWZmxeir/OsrhwT5mGVI4wEXuXsBUCRIEnuYkLdRYidcCi 56bfdrLGlOpk7WsUPBkfsX8GpcCYymNZAgFiOiigtrHqKmMVrv4XwDl8c2s05uklKN9G LXLEBwW3+J3NCTjOqKUDOss4ckxOHkKbibXDh+CwL2e7ud/LewrOUQCHBEnSa+WkMLdJ 36Ni6LJ+qPFxGS6Avnp566jCul2FuovLv+OwbjBmpiEHygI7PxjyVQN+8ca1AIdKC1O1 BgXA== X-Forwarded-Encrypted: i=1; AJvYcCXB/iJKs+R21lvJXzDCsJr7qg7lzxbKPOCNg1tnVX2t9QE8NfQzzJpfShdMLyuv9I7fsYeo0vwWTEKa6NcphA==@vger.kernel.org, AJvYcCXQbLcoBqa+6dwTZ+gAUbnvubo5n1IMDw72Qwy+1h3vH1czES/5EU27+7JR+bIGZbA+PNj49/RA4YFn@vger.kernel.org, AJvYcCXoAbziDOCfkcFHoswkVn6E+PePK88zjiYN2MZmwUMxLNma0SJcKfYwdzgRThUD/2iGoiZNq/06IJ4DApI2GpaYnYU=@vger.kernel.org, AJvYcCXtUIkhUhZxdWhOByVQ9/wRpjffV1WFvkQ4PUWPi0t3unjvetOlozfVUTm9hVJ58PL3JFTuKURhOT8J2GlE@vger.kernel.org X-Gm-Message-State: AOJu0Yyl95ztngrkC5KJtbxQSPvrEP2flXBK2CtfHH6Lr8eWPSr2nKW8 rPDehfSaC/6XJhWQW6ERQFGqEmCD/ROV39/iNcQ0d0mfPRpheTs2r7Vk1g== X-Google-Smtp-Source: AGHT+IFVn+W6t7IcvDHzZ8JEBQMCSTtIpGFYZyel7ibDDUcP897/DW1p4IYqqtYfdKiVpsTwnCY1Iw== X-Received: by 2002:a17:906:daca:b0:a99:88ab:c7cb with SMTP id a640c23a62f3a-aa48347e0fbmr879397366b.33.1731924601276; Mon, 18 Nov 2024 02:10:01 -0800 (PST) Received: from [127.0.1.1] ([46.53.242.72]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-aa20e046932sm518546366b.170.2024.11.18.02.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2024 02:10:00 -0800 (PST) From: Dzmitry Sankouski Date: Mon, 18 Nov 2024 13:09:53 +0300 Subject: [PATCH v3 1/2] power: supply: max17042: make interrupt shared Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241118-b4-max17042-v3-1-9bcaeda42a06@gmail.com> References: <20241118-b4-max17042-v3-0-9bcaeda42a06@gmail.com> In-Reply-To: <20241118-b4-max17042-v3-0-9bcaeda42a06@gmail.com> To: Hans de Goede , Krzysztof Kozlowski , Marek Szyprowski , Sebastian Krzyszkowiak , Purism Kernel Team , Sebastian Reichel , Rob Herring , Conor Dooley , Alim Akhtar , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Bjorn Andersson , Konrad Dybcio Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, imx@lists.linux.dev, linux-arm-msm@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1731924598; l=1055; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=gES/YI8J+uY43qFcYFJFQDdZCjIIvFKdVHt8Cx7j4Ks=; b=r/k4DDMvo/iWEzDXWTNKTdhAJ+2yN2gMZDbBBo0/+qpXaIxtBxrxlSbcICNM9WInILIvXpnR+ +H8C6RzzOzvBbSTtw42c+JXXlJIvIZMBNAH/oZfjB9gXGMlrJC/ZiNZ X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Fuelgauge blocks often are incorporated in bigger chip, which may use only 1 line for interrupts. Make interrupt shared. Signed-off-by: Dzmitry Sankouski Reviewed-by: Hans de Goede --- drivers/power/supply/max17042_battery.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply= /max17042_battery.c index 496c3e1f2ee6..99bf6915aa23 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -1103,14 +1103,7 @@ static int max17042_probe(struct i2c_client *client) } =20 if (client->irq) { - unsigned int flags =3D IRQF_ONESHOT; - - /* - * On ACPI systems the IRQ may be handled by ACPI-event code, - * so we need to share (if the ACPI code is willing to share). - */ - if (acpi_id) - flags |=3D IRQF_SHARED | IRQF_PROBE_SHARED; + unsigned int flags =3D IRQF_ONESHOT | IRQF_SHARED | IRQF_PROBE_SHARED; =20 ret =3D devm_request_threaded_irq(&client->dev, client->irq, NULL, --=20 2.39.2 From nobody Sat Nov 23 22:44:40 2024 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 079731946B8; Mon, 18 Nov 2024 10:10:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731924607; cv=none; b=DxrKXrmBGIprxnEOlsjXAgxp52uAh+KnYxrYNCPV54NGiRQmobCpzx9clrEQ/QzkZ1aNqHWqx8myrgJMlp2o7bw/IadTBkA922Rm4CnYvqtf38h/SXEYgINSGnR4/RHepNDPwX3fRrg9qJICOncrwl6mh8GurrdUUNcP1f+CS4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731924607; c=relaxed/simple; bh=08avkvJXc6YpLMi35Ewq9sInOmvPK/XUfpBoJCW4Zgo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o1t2G5JZOM4fVj5HspTiom3GmFQrXj7ncRv0EEZyvIBp3L7mF0cHpqBTEnIA6Eu9/LbrTMynWTg/sXIcBJ+AWScoA1cypVPijE8AvcJKoCJR5eG2PTXvI0rWnHBN8dR3wf1VeQSLNUPj49KpEgC/fvlTPsE0HvQVBCfItzPsHok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cmOcnvvF; arc=none smtp.client-ip=209.85.208.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cmOcnvvF" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2fb4af0b6beso20999761fa.3; Mon, 18 Nov 2024 02:10:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731924603; x=1732529403; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9fOyYhW/88qHGGmM9QOYNQJqLo1yTsoyhwIyniU1DSY=; b=cmOcnvvFay3INRxclkkyVeCeevPXKk3aHnqR8HmOP55pB4/FpZg/2IFlkzGy8KiGvp j/H7ZA/j8Mvk/i9F4JJzA0Pr9SyflC6MX+/2c6L+a1tz3TurxmoJ35IBOm7xwgODK4n4 k7FSOpAPnGmTWAS8RP9HsRgBNo32UWfNOCOw9razWYCvPuZgqiZet5eUmn+IPZm8wvhR LWZGX8OCLpKfaPXFv4gcG403GPA51WjtaPeH1rOsRP3wPZRqAganDGYlT0zqPWhAC4Qd kysK2Ik5lDvGtbsfJs033WgbQSLtzIdmSgXqgWK3i/zVKW8M7UM2Z8YPLvVlUw0EYJaZ RXCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731924603; x=1732529403; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9fOyYhW/88qHGGmM9QOYNQJqLo1yTsoyhwIyniU1DSY=; b=WeXfCbpPlyfSgKYKo7pOXB+epSRTOSvHUh77u4M3F5ACHVHUTodn/wYnZw+HMNbho/ aLV/86FhzwSMF/Jgo3UBYJikUzuFxnkT5/AXv2D1VSYv4kALhhlShVeMKM6c3CzCmnk2 W9h+QUtSJaGmPJb4H41oF0oo3M4LPKnw1igoO4bY4hc3aYYLyY+NiwbhRQMQSxVGxtHb UsPWqovgsARETiMg4WGmnKSVOEZT9HjFYieBUgR9MhsF2Sd1WPxwQ8SYljnC6cX+9/Rz aBLqE1phvOZ/GmznV4vXFrFQ6S3GlHu8WRadvQ20rkq7HjRtqiP4lYNw4aYkkAe1LMkg 5nFg== X-Forwarded-Encrypted: i=1; AJvYcCUSEmMiKwLXHXSs5BI/h2KzcQNbPu8TM+um6x38JT0fHlrAex6RwgntTq71vwHcdoVffi1Dx8LqtpqDpdgbEA==@vger.kernel.org, AJvYcCVJl3LFInkI96IS+DeO+wdjj5kw3sk4urGBfRyV+VvXYZQQhD8kYhVkI6+UJx2HI3c/UYv8Ax0zJmMPecz/0jfNrpE=@vger.kernel.org, AJvYcCXL3DOUbHHm9vfYiJ1QX14N+rhZPp4jguIP/L2CsOdVLgAkbHUnQe2UoqpCqr4hjXY3fD1r9YbwFCB7@vger.kernel.org, AJvYcCXMg1bj7VOyftlLJhS0oXSc4I6lUQDARFrhTWbyktuv3c5R463jSxc/nxIUIxxW7prOZ7H0Y4bDgVVevf7Q@vger.kernel.org X-Gm-Message-State: AOJu0YxgBrM6fo6Eu9tWer+566EJVS1GSyuDWPh8HRIvpksqga9BAzzZ H5qRgPGnrymP/0REose5jsOb8yVBAB0AQzCWyJeUFG/TRbwJsuV1 X-Google-Smtp-Source: AGHT+IEsM+bEYVWPcdxMX4ty+jlvxNzXr16PKephGvFY1LmTwDkGEiU9Vu06vwaLgV1jjEKcvAJWkw== X-Received: by 2002:a05:6512:2391:b0:53d:a6c8:fb95 with SMTP id 2adb3069b0e04-53dab29efffmr5766910e87.19.1731924602776; Mon, 18 Nov 2024 02:10:02 -0800 (PST) Received: from [127.0.1.1] ([46.53.242.72]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-aa20e046932sm518546366b.170.2024.11.18.02.10.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2024 02:10:02 -0800 (PST) From: Dzmitry Sankouski Date: Mon, 18 Nov 2024 13:09:54 +0300 Subject: [PATCH v3 2/2] power: supply: max17042: add platform driver variant Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241118-b4-max17042-v3-2-9bcaeda42a06@gmail.com> References: <20241118-b4-max17042-v3-0-9bcaeda42a06@gmail.com> In-Reply-To: <20241118-b4-max17042-v3-0-9bcaeda42a06@gmail.com> To: Hans de Goede , Krzysztof Kozlowski , Marek Szyprowski , Sebastian Krzyszkowiak , Purism Kernel Team , Sebastian Reichel , Rob Herring , Conor Dooley , Alim Akhtar , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Bjorn Andersson , Konrad Dybcio Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, imx@lists.linux.dev, linux-arm-msm@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1731924598; l=7718; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=08avkvJXc6YpLMi35Ewq9sInOmvPK/XUfpBoJCW4Zgo=; b=Tb5f0aAMBx2MGt3QTrkgclj08UpXH0InARdTWId9PBKICIi4GRNuva4CIHo0xUUNPX4OG64yq tgZv4Ji6Oe6DCAShAYu8XgKwIixcAaIg1oTLpWOdRFCFDU6SObAAzr3 X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Maxim PMICs may include fuel gauge with additional features, which is out of single Linux power supply driver scope. For example, in max77705 PMIC fuelgauge has additional registers, like IIN_REG, VSYS_REG, ISYS_REG. Those needed to measure PMIC input current, system voltage and current respectively. Those measurements cannot be bound to any of fuelgauge properties. The solution here add and option to use max17042 driver as a MFD sub device, thus allowing any additional functionality be implemented as another sub device. This will help to reduce code duplication in MFD fuel gauge drivers. Signed-off-by: Dzmitry Sankouski --- Changes in v3: - pass dev pointer in max17042_probe - remove prints --- drivers/power/supply/max17042_battery.c | 114 ++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------= ----------- 1 file changed, 90 insertions(+), 24 deletions(-) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply= /max17042_battery.c index 99bf6915aa23..d11bf37aaae2 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -1029,14 +1030,12 @@ static const struct power_supply_desc max17042_no_c= urrent_sense_psy_desc =3D { .num_properties =3D ARRAY_SIZE(max17042_battery_props) - 2, }; =20 -static int max17042_probe(struct i2c_client *client) +static int max17042_probe(struct i2c_client *client, struct device *dev, + enum max170xx_chip_type chip_type) { - const struct i2c_device_id *id =3D i2c_client_get_device_id(client); struct i2c_adapter *adapter =3D client->adapter; const struct power_supply_desc *max17042_desc =3D &max17042_psy_desc; struct power_supply_config psy_cfg =3D {}; - const struct acpi_device_id *acpi_id =3D NULL; - struct device *dev =3D &client->dev; struct max17042_chip *chip; int ret; int i; @@ -1045,33 +1044,24 @@ static int max17042_probe(struct i2c_client *client) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) return -EIO; =20 - chip =3D devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip =3D devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; =20 chip->client =3D client; - if (id) { - chip->chip_type =3D id->driver_data; - } else { - acpi_id =3D acpi_match_device(dev->driver->acpi_match_table, dev); - if (!acpi_id) - return -ENODEV; - - chip->chip_type =3D acpi_id->driver_data; - } chip->regmap =3D devm_regmap_init_i2c(client, &max17042_regmap_config); if (IS_ERR(chip->regmap)) { - dev_err(&client->dev, "Failed to initialize regmap\n"); + dev_err(dev, "Failed to initialize regmap\n"); return -EINVAL; } =20 chip->pdata =3D max17042_get_pdata(chip); if (!chip->pdata) { - dev_err(&client->dev, "no platform data provided\n"); + dev_err(dev, "no platform data provided\n"); return -EINVAL; } =20 - i2c_set_clientdata(client, chip); + dev_set_drvdata(dev, chip); psy_cfg.drv_data =3D chip; psy_cfg.of_node =3D dev->of_node; =20 @@ -1095,17 +1085,17 @@ static int max17042_probe(struct i2c_client *client) regmap_write(chip->regmap, MAX17042_LearnCFG, 0x0007); } =20 - chip->battery =3D devm_power_supply_register(&client->dev, max17042_desc, + chip->battery =3D devm_power_supply_register(dev, max17042_desc, &psy_cfg); if (IS_ERR(chip->battery)) { - dev_err(&client->dev, "failed: power supply register\n"); + dev_err(dev, "failed: power supply register\n"); return PTR_ERR(chip->battery); } =20 if (client->irq) { unsigned int flags =3D IRQF_ONESHOT | IRQF_SHARED | IRQF_PROBE_SHARED; =20 - ret =3D devm_request_threaded_irq(&client->dev, client->irq, + ret =3D devm_request_threaded_irq(dev, client->irq, NULL, max17042_thread_handler, flags, chip->battery->desc->name, @@ -1118,7 +1108,7 @@ static int max17042_probe(struct i2c_client *client) } else { client->irq =3D 0; if (ret !=3D -EBUSY) - dev_err(&client->dev, "Failed to get IRQ\n"); + dev_err(dev, "Failed to get IRQ\n"); } } /* Not able to update the charge threshold when exceeded? -> disable */ @@ -1127,7 +1117,7 @@ static int max17042_probe(struct i2c_client *client) =20 regmap_read(chip->regmap, MAX17042_STATUS, &val); if (val & STATUS_POR_BIT) { - ret =3D devm_work_autocancel(&client->dev, &chip->work, + ret =3D devm_work_autocancel(dev, &chip->work, max17042_init_worker); if (ret) return ret; @@ -1139,6 +1129,38 @@ static int max17042_probe(struct i2c_client *client) return 0; } =20 +static int max17042_i2c_probe(struct i2c_client *client) +{ + const struct i2c_device_id *id =3D i2c_client_get_device_id(client); + const struct acpi_device_id *acpi_id =3D NULL; + struct device *dev =3D &client->dev; + enum max170xx_chip_type chip_type; + + if (id) { + chip_type =3D id->driver_data; + } else { + acpi_id =3D acpi_match_device(dev->driver->acpi_match_table, dev); + if (!acpi_id) + return -ENODEV; + + chip_type =3D acpi_id->driver_data; + } + + return max17042_probe(client, dev, chip_type); +} + +static int max17042_platform_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct i2c_client *i2c =3D dev_get_platdata(dev); + const struct platform_device_id *id =3D platform_get_device_id(pdev); + + if (!i2c) + return -EINVAL; + + return max17042_probe(i2c, dev, id->driver_data); +} + #ifdef CONFIG_PM_SLEEP static int max17042_suspend(struct device *dev) { @@ -1204,6 +1226,16 @@ static const struct i2c_device_id max17042_id[] =3D { }; MODULE_DEVICE_TABLE(i2c, max17042_id); =20 +static const struct platform_device_id max17042_platform_id[] =3D { + { "max17042", MAXIM_DEVICE_TYPE_MAX17042 }, + { "max17047", MAXIM_DEVICE_TYPE_MAX17047 }, + { "max17050", MAXIM_DEVICE_TYPE_MAX17050 }, + { "max17055", MAXIM_DEVICE_TYPE_MAX17055 }, + { "max77849-battery", MAXIM_DEVICE_TYPE_MAX17047 }, + { } +}; +MODULE_DEVICE_TABLE(platform, max17042_platform_id); + static struct i2c_driver max17042_i2c_driver =3D { .driver =3D { .name =3D "max17042", @@ -1211,10 +1243,44 @@ static struct i2c_driver max17042_i2c_driver =3D { .of_match_table =3D of_match_ptr(max17042_dt_match), .pm =3D &max17042_pm_ops, }, - .probe =3D max17042_probe, + .probe =3D max17042_i2c_probe, .id_table =3D max17042_id, }; -module_i2c_driver(max17042_i2c_driver); + +static struct platform_driver max17042_platform_driver =3D { + .driver =3D { + .name =3D "max17042", + .acpi_match_table =3D ACPI_PTR(max17042_acpi_match), + .of_match_table =3D of_match_ptr(max17042_dt_match), + .pm =3D &max17042_pm_ops, + }, + .probe =3D max17042_platform_probe, + .id_table =3D max17042_platform_id, +}; + +static int __init __driver_max17042_platform_init(void) +{ + int ret =3D 0; + + ret =3D platform_driver_register(&max17042_platform_driver); + + if (ret) { + platform_driver_unregister(&max17042_platform_driver); + return ret; + } + + ret =3D i2c_add_driver(&max17042_i2c_driver); + + return ret; +} +module_init(__driver_max17042_platform_init); + +static void __exit __driver_max17042_platform_exit(void) +{ + i2c_del_driver(&max17042_i2c_driver); + platform_driver_unregister(&max17042_platform_driver); +} +module_exit(__driver_max17042_platform_exit); =20 MODULE_AUTHOR("MyungJoo Ham "); MODULE_DESCRIPTION("MAX17042 Fuel Gauge"); --=20 2.39.2