Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3340438pxb; Mon, 1 Nov 2021 12:03:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUt8fv+bV61IEmiN6uTqKQpG6w2Rty1gjGsrHTDzIyfPjO9Wrq8W3ilBPGLs4em5hBaP95 X-Received: by 2002:a50:8e05:: with SMTP id 5mr43379900edw.76.1635793399201; Mon, 01 Nov 2021 12:03:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635793399; cv=none; d=google.com; s=arc-20160816; b=m+Kcfwf/8eM9uN1UD4XQkpOOM4DrCIFZZiy6a3yT+dSNWs7xVdlQU/XiQvPsW7KSbz YMYfF2af/5AFW3TRUio1vkJmAOnaHMeB7J2fbT3D4wnK29qQ9zZ06agKWEpXe0paIF2L B6IIXv1pclpjM0oEBk7xS1/LV5328i47wBfopNA0r9d9KjNyXEwK9xCaAbIecxI/AKZS t0uhoG+mTPBkW3j4c/ByiDADlpxFkOVZPwkNourDVGLcDA72+dI1GIwVNNQBdyWnzHHn +OSNxYz6tzu7KSXONfqhS9U5HUahS67SZ/zTSz7lOQO3TTHqbzhHkKPS0OPo0zLq9i1m 2Mfg== 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=iYinJrPYeEwjd2EPn1DkCMOFKpBLlTfl9POTocMusBI=; b=vPv9khDiyQjjIqoAqUFskauKrIYcUnGA1Le4UID39+RI8pfa5yG0OatzrAKhTg6bkU 4YRoU0dwBzQ+xvKA7U3ingb3Kub1hxpXcr5zYk0aQsWHlKYZbPa08gUx9hLwfZKCxRdx PJAWauN7UQvD2Pgfp+UWcGKkazTb/8lemoLN13uK8lttqzqvFe9bkwvk/66XRotXIWx5 BfjT+ElRNejTZoh5hiOj0esC7/DYmpeGzKtbI8QwwGfHPZQvkfBFhYorYzoDL9pZ+dUw Ru4MO90P8mSsye2wG7ZIozQs1ZWg3NKy9zeeD7O+tg/Gf6HA0vRwGij0v7c2OxDXhXOB uFDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=anE7fQUO; 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 b15si31939930edd.19.2021.11.01.12.02.49; Mon, 01 Nov 2021 12:03:19 -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=anE7fQUO; 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 S232440AbhKAS7B (ORCPT + 99 others); Mon, 1 Nov 2021 14:59:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44508 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232193AbhKAS6x (ORCPT ); Mon, 1 Nov 2021 14:58:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635792955; 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=iYinJrPYeEwjd2EPn1DkCMOFKpBLlTfl9POTocMusBI=; b=anE7fQUO9OwLhUUJN/HqsK55UrRk8LEgrvIGM+5S+p7DltaEKTWqp3Cx/YTuxIMfUSbub9 XX8oOsnzrrOkM+5PfRosmF7oHkdMuYW6fB+M2bMIrpQAoZiNQf3gn8ONdK3pr7C9pfpsDO CZldQDIrrXeoQDxdHtUYkavzZRLCWbY= 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-383-lKzzuFAZOW690T99W4sc0w-1; Mon, 01 Nov 2021 14:55:51 -0400 X-MC-Unique: lKzzuFAZOW690T99W4sc0w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A802B8066EB; Mon, 1 Nov 2021 18:55:50 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71B5660C17; Mon, 1 Nov 2021 18:55:49 +0000 (UTC) From: Hans de Goede To: Lee Jones , Daniel Thompson , Jingoo Han Cc: Hans de Goede , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] backlight: lp855x: Add support ACPI enumeration Date: Mon, 1 Nov 2021 19:55:17 +0100 Message-Id: <20211101185518.306728-3-hdegoede@redhat.com> In-Reply-To: <20211101185518.306728-1-hdegoede@redhat.com> References: <20211101185518.306728-1-hdegoede@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Xiaomi Mi Pad 2 tablet uses an ACPI enumerated LP8556 backlight controller for its LCD-panel, with a Xiaomi specific ACPI HID of "XMCC0001", add support for this. Note the new "if (id)" check also fixes a NULL pointer deref when a user tries to manually bind the driver from sysfs. When CONFIG_ACPI is disabled acpi_match_device() will always return NULL, so the lp855x_parse_acpi() call will get optimized away. Signed-off-by: Hans de Goede --- drivers/video/backlight/lp855x_bl.c | 70 ++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c index d1d27d5eb0f2..f075ec84acfb 100644 --- a/drivers/video/backlight/lp855x_bl.c +++ b/drivers/video/backlight/lp855x_bl.c @@ -5,6 +5,7 @@ * Copyright (C) 2011 Texas Instruments */ +#include #include #include #include @@ -330,7 +331,7 @@ static int lp855x_parse_dt(struct lp855x *lp) { struct device *dev = lp->dev; struct device_node *node = dev->of_node; - struct lp855x_platform_data *pdata; + struct lp855x_platform_data *pdata = lp->pdata; int rom_length; if (!node) { @@ -338,10 +339,6 @@ static int lp855x_parse_dt(struct lp855x *lp) return -EINVAL; } - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); - if (!pdata) - return -ENOMEM; - of_property_read_string(node, "bl-name", &pdata->name); of_property_read_u8(node, "dev-ctrl", &pdata->device_control); of_property_read_u8(node, "init-brt", &pdata->initial_brightness); @@ -379,8 +376,31 @@ static int lp855x_parse_dt(struct lp855x *lp) } #endif +static int lp855x_parse_acpi(struct lp855x *lp) +{ + int ret; + + /* + * On ACPI the device has already been initialized by the firmware + * so we read back the settings from the registers. + */ + ret = i2c_smbus_read_byte_data(lp->client, lp->cfg->reg_brightness); + if (ret < 0) + return ret; + + lp->pdata->initial_brightness = ret; + + ret = i2c_smbus_read_byte_data(lp->client, lp->cfg->reg_devicectrl); + if (ret < 0) + return ret; + + lp->pdata->device_control = ret; + return 0; +} + static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) { + const struct acpi_device_id *acpi_id = NULL; struct device *dev = &cl->dev; struct lp855x *lp; int ret; @@ -394,10 +414,20 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) lp->client = cl; lp->dev = dev; - lp->chipname = id->name; - lp->chip_id = id->driver_data; lp->pdata = dev_get_platdata(dev); + if (id) { + lp->chipname = id->name; + lp->chip_id = id->driver_data; + } else { + acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); + if (!acpi_id) + return -ENODEV; + + lp->chipname = acpi_id->id; + lp->chip_id = acpi_id->driver_data; + } + switch (lp->chip_id) { case LP8550: case LP8551: @@ -415,9 +445,19 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) } if (!lp->pdata) { - ret = lp855x_parse_dt(lp); - if (ret < 0) - return ret; + lp->pdata = devm_kzalloc(dev, sizeof(*lp->pdata), GFP_KERNEL); + if (!lp->pdata) + return -ENOMEM; + + if (id) { + ret = lp855x_parse_dt(lp); + if (ret < 0) + return ret; + } else { + ret = lp855x_parse_acpi(lp); + if (ret < 0) + return ret; + } } if (lp->pdata->period_ns > 0) @@ -537,10 +577,20 @@ static const struct i2c_device_id lp855x_ids[] = { }; MODULE_DEVICE_TABLE(i2c, lp855x_ids); +#ifdef CONFIG_ACPI +static const struct acpi_device_id lp855x_acpi_match[] = { + /* Xiaomi specific HID used for the LP8556 on the Mi Pad 2 */ + { "XMCC0001", LP8556 }, + { } +}; +MODULE_DEVICE_TABLE(acpi, lp855x_acpi_match); +#endif + static struct i2c_driver lp855x_driver = { .driver = { .name = "lp855x", .of_match_table = of_match_ptr(lp855x_dt_ids), + .acpi_match_table = ACPI_PTR(lp855x_acpi_match), }, .probe = lp855x_probe, .remove = lp855x_remove, -- 2.31.1