From patchwork Wed Feb 5 14:22:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 11366381 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E0CC138D for ; Wed, 5 Feb 2020 14:20:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7796B217BA for ; Wed, 5 Feb 2020 14:20:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbgBEOUQ (ORCPT ); Wed, 5 Feb 2020 09:20:16 -0500 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:23554 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728165AbgBEOUP (ORCPT ); Wed, 5 Feb 2020 09:20:15 -0500 Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 015EK3o2008623; Wed, 5 Feb 2020 09:20:03 -0500 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 2xyhm91u3c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 05 Feb 2020 09:20:03 -0500 Received: from SCSQMBX10.ad.analog.com (scsqmbx10.ad.analog.com [10.77.17.5]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 015EJtTw055113 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Wed, 5 Feb 2020 09:19:55 -0500 Received: from SCSQMBX10.ad.analog.com (10.77.17.5) by SCSQMBX10.ad.analog.com (10.77.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 5 Feb 2020 06:19:53 -0800 Received: from zeus.spd.analog.com (10.64.82.11) by SCSQMBX10.ad.analog.com (10.77.17.5) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Wed, 5 Feb 2020 06:19:53 -0800 Received: from saturn.ad.analog.com ([10.48.65.124]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 015EJmEM000357; Wed, 5 Feb 2020 09:19:50 -0500 From: Alexandru Ardelean To: , CC: , Lars-Peter Clausen , Alexandru Ardelean Subject: [PATCH v3 2/2] input: adp5589: Add basic devicetree support Date: Wed, 5 Feb 2020 16:22:18 +0200 Message-ID: <20200205142218.15973-2-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200205142218.15973-1-alexandru.ardelean@analog.com> References: <20200205142218.15973-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-05_04:2020-02-04,2020-02-05 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 phishscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 suspectscore=0 bulkscore=0 adultscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002050112 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Lars-Peter Clausen Add very basic devicetree suppport to the adp5589 allowing the device to be registered from devicetree. Signed-off-by: Lars-Peter Clausen Signed-off-by: Alexandru Ardelean Reported-by: kbuild test robot Reported-by: Dan Carpenter --- drivers/input/keyboard/adp5589-keys.c | 33 ++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c index c6a801bcdf90..56f4ff7fa9c3 100644 --- a/drivers/input/keyboard/adp5589-keys.c +++ b/drivers/input/keyboard/adp5589-keys.c @@ -1008,6 +1008,25 @@ static void adp5589_keypad_remove(struct adp5589_kpad *kpad) } } +static int adp5589_i2c_get_driver_data(struct i2c_client *i2c, + const struct i2c_device_id *id) +{ + const struct of_device_id *match; + + if (id) + return id->driver_data; + + if (!IS_ENABLED(CONFIG_OF) || !i2c->dev.of_node) + return -ENODEV; + + match = of_match_node(i2c->dev.driver->of_match_table, + i2c->dev.of_node); + if (match) + return (uintptr_t)match->data; + + return -ENODEV; +} + static int adp5589_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1029,7 +1048,11 @@ static int adp5589_probe(struct i2c_client *client, kpad->client = client; - switch (id->driver_data) { + ret = adp5589_i2c_get_driver_data(client, id); + if (ret < 0) + return ret; + + switch (ret) { case ADP5585_02: kpad->support_row5 = true; /* fall through */ @@ -1129,6 +1152,13 @@ static int adp5589_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(adp5589_dev_pm_ops, adp5589_suspend, adp5589_resume); +static const struct of_device_id adp5589_of_match[] = { + { .compatible = "adi,adp5585", .data = (void *)ADP5585_01 }, + { .compatible = "adi,adp5585-02", .data = (void *)ADP5585_02 }, + { .compatible = "adi,adp5589", .data = (void *)ADP5589 }, + {} +}; + static const struct i2c_device_id adp5589_id[] = { {"adp5589-keys", ADP5589}, {"adp5585-keys", ADP5585_01}, @@ -1142,6 +1172,7 @@ static struct i2c_driver adp5589_driver = { .driver = { .name = KBUILD_MODNAME, .pm = &adp5589_dev_pm_ops, + .of_match_table = adp5589_of_match, }, .probe = adp5589_probe, .remove = adp5589_remove,