From patchwork Tue Jan 9 09:33:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 123842 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3809487qgn; Tue, 9 Jan 2018 01:43:47 -0800 (PST) X-Google-Smtp-Source: ACJfBovKxrP906ukux+nH3mi82C7BM0VJaPG7qFGb+kUmhnIaANf53ax0D6fNTitUNptj9UD03AI X-Received: by 10.101.81.7 with SMTP id f7mr11792418pgq.449.1515491027793; Tue, 09 Jan 2018 01:43:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515491027; cv=none; d=google.com; s=arc-20160816; b=GtUwmKOnhirlXwfTBzsc/6SmtMMqwDK4vFNpmsZ2HCSjKeDK1uKEa/dWhdU4J6Ojr0 vgrtM55MrQTy6hv3kSxdk9GMn2nSql9DkQmFj4Banpq1IwJn8DFbLQXmJeuAVq1E3gaG V/2fpZIEeFoM+q+pXR4H8lkH5mG1XX9l8XX8izDDuVP2yxo8X3kW5S6PNtXgkL2C7+TZ E/H1ELVS5vs1tBapI8ITsZSQ5Fmzla4X9tVS/qD+n97v0JTODAAqQKzVGDwpCISR3+im 0Sb32smBQ3MWq1DJfHZeYRAifix5immMdEXSpT29hGODf62cyTCWkPGeAGECl7SITBeO Um/Q== 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:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=OLB1BLyT0nAbxqdl3kasNYfdciTU1uwgyue/HpQrslw=; b=GWrLkMajmbW2vMj+FIqUi6l4cN77aaCJ93ugN2xB8Bg/aCxd6Q2TwBW8Q3ZCLwPwvA ZTiB5td4Ue/Jwfz1nweWsjnXqlJqNt21kvAM50VSUU3mx93i56jvtzCsXE7e1Kpw61IQ dAfsRMgLOMuqLJ01IRxS5JXO0HnsFqoK4hksRUI4gDNHvQ6h/3f1QUetn3hLEnW4BI8L BfoCGiVehISY4Ta2ASCYXKv6K3n6VF8vRDoumPN9i6RID3fkDSw+8jUc74zSK3svrh9X o9qePS4RwwgZNh9nuC+owwRGAX51tpSSZA280l92H2XRDgRBdXs8hh7T1XM2u1vmqgqV rrXA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j5si9799476pfh.162.2018.01.09.01.43.47; Tue, 09 Jan 2018 01:43:47 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752580AbeAIJfJ (ORCPT + 28 others); Tue, 9 Jan 2018 04:35:09 -0500 Received: from mail.free-electrons.com ([62.4.15.54]:45713 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752642AbeAIJfC (ORCPT ); Tue, 9 Jan 2018 04:35:02 -0500 Received: by mail.free-electrons.com (Postfix, from userid 110) id 0302E20727; Tue, 9 Jan 2018 10:35:00 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 8CB862072D; Tue, 9 Jan 2018 10:34:49 +0100 (CET) From: Quentin Schulz To: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, robh+dt@kernel.org, mark.rutland@arm.com, wens@csie.org, sre@kernel.org, linux@armlinux.org.uk, maxime.ripard@free-electrons.com, lee.jones@linaro.org Cc: linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, thomas.petazzoni@free-electrons.com, linux-sunxi@googlegroups.com, Quentin Schulz Subject: [PATCH v2 03/16] iio: adc: axp20x_adc: make it possible to probe from DT Date: Tue, 9 Jan 2018 10:33:34 +0100 Message-Id: <5cf35ebd799555aca6201b86d635656266eda40c.1515486346.git-series.quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To prepare for a future patch that will add a DT node for the ADC, make axp20x_adc able to probe from DT and get the per-variant data from of_device_id.data since platform_device_id.driver_data won't be set when probing by DT. Leave the ability to probe via platform for driver compatibility with old DTs. Signed-off-by: Quentin Schulz --- drivers/iio/adc/axp20x_adc.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) -- git-series 0.9.1 diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c index 3fc1b06..f8c4c62 100644 --- a/drivers/iio/adc/axp20x_adc.c +++ b/drivers/iio/adc/axp20x_adc.c @@ -515,6 +515,13 @@ static const struct axp_data axp22x_data = { .maps = axp22x_maps, }; +static const struct of_device_id axp20x_adc_of_match[] = { + { .compatible = "x-powers,axp20x-adc", .data = (void *)&axp20x_data, }, + { .compatible = "x-powers,axp22x-adc", .data = (void *)&axp22x_data, }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, axp20x_adc_of_match); + static const struct platform_device_id axp20x_adc_id_match[] = { { .name = "axp20x-adc", .driver_data = (kernel_ulong_t)&axp20x_data, }, { .name = "axp22x-adc", .driver_data = (kernel_ulong_t)&axp22x_data, }, @@ -543,7 +550,16 @@ static int axp20x_probe(struct platform_device *pdev) indio_dev->dev.of_node = pdev->dev.of_node; indio_dev->modes = INDIO_DIRECT_MODE; - info->data = (struct axp_data *)platform_get_device_id(pdev)->driver_data; + if (!pdev->dev.of_node) { + const struct platform_device_id *tmp; + + tmp = platform_get_device_id(pdev); + info->data = (struct axp_data *)tmp->driver_data; + } else { + struct device *dev = &pdev->dev; + + info->data = (struct axp_data *)of_device_get_match_data(dev); + } indio_dev->name = platform_get_device_id(pdev)->name; indio_dev->info = info->data->iio_info; @@ -606,6 +622,7 @@ static int axp20x_remove(struct platform_device *pdev) static struct platform_driver axp20x_adc_driver = { .driver = { .name = "axp20x-adc", + .of_match_table = of_match_ptr(axp20x_adc_of_match), }, .id_table = axp20x_adc_id_match, .probe = axp20x_probe,