Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754334AbbKMJvm (ORCPT ); Fri, 13 Nov 2015 04:51:42 -0500 Received: from mail-bl2on0127.outbound.protection.outlook.com ([65.55.169.127]:13644 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752944AbbKMJvf (ORCPT ); Fri, 13 Nov 2015 04:51:35 -0500 X-Greylist: delayed 959 seconds by postgrey-1.27 at vger.kernel.org; Fri, 13 Nov 2015 04:51:35 EST Authentication-Results: spf=permerror (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=freescale.com; Date: Fri, 13 Nov 2015 17:39:36 +0800 From: Haibo Chen To: Lars-Peter Clausen CC: , , , , , , , , , , , , , , Subject: Re: [PATCH v2 1/4] iio: adc: add IMX7D ADC driver support Message-ID: <20151113093934.GA21068@b51421-server.ap.freescale.net> References: <1447075704-4605-1-git-send-email-haibo.chen@freescale.com> <1447075704-4605-2-git-send-email-haibo.chen@freescale.com> <56420606.4070505@metafoo.de> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <56420606.4070505@metafoo.de> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BN1BFFO11FD028;1:/Ngy7fQ+S3bcflYC256CipHpyTCHkXhIEg6zsAzH1bJ42yMyocaK0jpfeBppeeKYYZumePkqxDTag6DDguKh0BViCFiC2nzV9akUslPHgUHEk1w2fL5gIIoAQSXrpR2Tb5u9Std1b5P0SfEPDGIjActHOAUVNwGy1vTpbwTbCmzJk/CO0zoVKHk6ifT/bmdw3jBbHCdXv6v7v/ooU/ZMnT6OQpA9PcwteUAwvQlNfO/wC+2kgqV5crPwIIPtbq6uMUkf/5zsm3VAwk6CV37PnJYpdnZE+1/uB4F8AY7jsrzFGAnBbsWii4D71zDRtGOh6c8aeGqSYAIS5GjOhmG6y9+/Bngi86EKKaE52LhJw+i/gWaqSojcpJAqkV2BlkkjnOct3rcYHNbC0PLHle/rjg== X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(448002)(189002)(377454003)(199003)(24454002)(479174004)(87936001)(54356999)(83506001)(2950100001)(77096005)(106466001)(85326001)(104016004)(81156007)(97736004)(50986999)(86362001)(189998001)(50466002)(4001350100001)(5001960100002)(5008740100001)(6806005)(46406003)(575784001)(23726002)(33656002)(110136002)(69596002)(19580405001)(5003600100002)(11100500001)(5007970100001)(47776003)(76176999)(97756001)(19580395003)(92566002)(7059030);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR0301MB0718;H:az84smr01.freescale.net;FPR:;SPF:PermError;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB0718;2:nHax2aRVtd9sExE36JqHlyf65fJuJbJdHxw/GZNdGoX1kcy9HO/NCvd1vUJE5WMn/MCK+bCGkwL96etZqOjqFH75qCbuUqemGgAlEpjvUZ6NsdGaPpMvggjQLtbeJfK+vRxGvyYfq9ib/ASFrT1bs94w2vecPUtgyAwh9+k8TJY=;3:Hgk7j0MjcIsidRc+J0bwUFm2JJ1HYunOGwbH6Vj19bR1En9fsWP4OqCLIn1Wyx8JPoyvHmSRQ2j1YeVOcrcXZmxrnIdD1KepqUnv2KnrKiMUh9EdnE7OjqzmSX1A+8wn+0DNHGs6XMm30a6dIe3uFVjk7oEZiZER2G2qXAVNqfXEK/Mhpx9U/2fnTgz5w5NXISYZDb07EkRrWpAmB2Rnb046Huqn9mKCUodz4psbZLo=;25:TGki1quVwlMUrG5BWOdwEDPBpn3nTPhFauPPjBdHKdxlcxXJfyTiW3/pLnJ7Yl91b1As7l1vUJZ+bO42XKfdQI983npVTGvHAT4WVTYExGAf0HdVFHBppYP7/yCQc2xmbhqRs8nlxjg1r4mDBP9G6jsPan0FyjTv7p24afSR8DGzJ/qSRCLD3Jr0NFZaDlilUirK51nBj+X/APk16i3xVSicVQSRarAoErECzvSzbElYWIeAveDbZUggVXgbSuFUFFSC6ScTyE9/kT0rHmccMQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB0718; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB0718;20:ZZcctUPuH3ipDxiQ2wHti/6Y277PKbjq96HEIy/nTGmv28AMR7kLwjmhY6MBWrNRGuH5i+so/6uv56M0KVe2SkLOD89kUmk0TVinSOKbOor4roaNfBjGv74Y8judL4A3vqKFqjUClF8IjDIzUlyrWF0/KRyK+IwSsCYK4QEmVJ+A/o1NX3HJofPclFT1GDGBwQdz6GZMR0Z8nzUeppxVG41vzIuUW8OdaDVJ4vwNflgbI46CSQDTalT7xApkr5BMcAiP9NXluRp/9G6oC4PTRw6pR+/tDrbrrJ0kpUOfnXiDqu5Xq7Pum86NI1scuyk/g4fxmY/KBygnotWu2zRxpzCP+pmKO7i+JwkXaaJpuys=;4:vngO+P9gyVFhBizUnwnMgKs3ROARRTzgJ5aO09yVWgeOCSWEaK0jkbY7E9TSJxJ0+1QlGdcCpoaC49VlJ7acSQ8iSRI+ZtFb+HJu3XOJmBnmSeJZGJQ1Px9dmFpec/TZK5kFK9Lde5A/AVPNOM3YO4DgJOobBTB/+kpPJW/cCrOyG0jDd0ctM8ohAzz702aP2YadYlSL0nLa3cB4efPt7gOPegoJM/W4E9RTGCqVrecTqg7IN88gorRsXR5cQpgYp8/V/Xqj5Ywzx4Bm05ZfHXkjQMdECQfV9seGyCpEx8n6WGyEdeZhyRXYPU6Inoz7oDJ+90IzD6ehCKyBkb3dKQib7fupxFJ1jaBgR959WimsKo5ZSIBCrEwxcEnP/oBn X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(3002001)(10201501046);SRVR:DM2PR0301MB0718;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB0718; X-Forefront-PRVS: 0759F7A50A X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2PR0301MB0718;23:b2DiQ50wtxtBOFll3G3ENJ1BPAzURkN6CtQLhFT?= =?us-ascii?Q?86cjXRMStGxT9wGzqEyMYvGSoHE5kDTeEP13DNxn+jv6rPMQui04al0YfZVm?= =?us-ascii?Q?HzLoAGtoKMBf7IOrGuw0yBy+IOvkIz/1ODvJ8Tn+pZ5irdOcF8d8N1Snw8WG?= =?us-ascii?Q?R6QYAJJb5s5enWKbAvwPc/YnnNRo2XBgn+56xGkAJt/LZGn3IxnS3tLKtD09?= =?us-ascii?Q?vmwPUzZg11Ruh19ETO06WbygdSV+8ZH6tJ6hCmUP8GC86VU/suLdoId/WvVQ?= =?us-ascii?Q?h2/3K+23E74wGaZgUTHBFy+2OStoSuPXTglP8spg5d4sKdlQD0tWv8CpTOCl?= =?us-ascii?Q?q4b32r26HZS6q9W8ZMGOb2Jt088Pm7me4tJCYdwTLtDaDX4bTu2rrDctJflu?= =?us-ascii?Q?zEme6KYSQg0nTI9SCbE65Z7H7XDgsdUg5dPeNRZHh6QmQk1eoZAdJ6oKdqtd?= =?us-ascii?Q?IgH4QIAfJ/jhbHLzQh3a8QW02OzFwXPcUb5ukD35V+VFStoNVxaU6oZwFEMO?= =?us-ascii?Q?9fuHyPSycK1kdcg+ghfeN9y8yzdMSX0M7hsdi5wdARv509j9NxCZhmvlGYAb?= =?us-ascii?Q?SGmyiaBtcHFJbjgA2XLeROrTmpFocFDkZEH6W87ylFK8BnptlCf9rqKQLXvt?= =?us-ascii?Q?xL8D/OijJQzeA68/Ku0VvPYYEtZwjaOi6nW5Pe3u3kWNyGvbVhQOE0ojoLLU?= =?us-ascii?Q?BYjITdi1SSZsii6OhlMwP2kEAYHB2u/D1WbzQOEwRNfYikn0oAuvElPr4dVN?= =?us-ascii?Q?I7/GSf2usMUZLJOdW7fXCx7H3hrE7O7n57lUYCANvub0BqYBqxMpfhbaLYvL?= =?us-ascii?Q?DxMO7yMuAgKHaOZGqWnSVXnRM+Bufpf80PURlJwjO5zxAWrV5e3atV9W1F/5?= =?us-ascii?Q?jZjdzSRLLt33Eg57vtYKzABOdoOwbfnbKBCuKrK2F8vttesbEBzqQk8WQeYu?= =?us-ascii?Q?VDCwzdEjFFhulMszoV0CzrFLT1umF49nJGMQEi+XJdNx/l+j5Txflk5/+VIF?= =?us-ascii?Q?kxBR9FTaywu+kn5Eu3lv60tZOB9XxBqzA5sGCuGTcj6J+QrnNdmdT2qoN/yQ?= =?us-ascii?Q?l/PFGsA/tpQJRPmjbrVc/0BiskMo81sWhEPX7eR/Z0dmUxvGyij7inwY9fYU?= =?us-ascii?Q?Zge8HQXWWNgL+raA//zsLsyU/8dv86Her?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB0718;5:nx/KkpHFRsMQ70ow3blBLUTHjEtjPP03RHZQHEAYITTMnsHbOsdqX66ZRYczf1mbeas8YZ/ztEp8tAMPmxxhtOBrh8gDbixX3qbM+kXoMx6w5l701Uoq9EV4dwXwCJKw1CotJPoLZ9/0PBQ2KXWWbw==;24:RbfRcJSd0hX9FzOSaK5NysiQta2ySMcXjG4o5OFEkHp8HGstSLOSp+rAuf9RTgID9JRkv6SMqlY/T/kFv4TpaFHtVeOsLyuoEbInYK1CV2k=;20:FnrkELYTqUzFE9oeAijbZzEGct7pzdf8E5VV5MGQlTUw4Y4cFy2NmFOHtVs6DSSIj1Xu8ABaUZRxEVd58gd+AA== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2015 09:35:33.5061 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB0718 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5943 Lines: 193 On Tue, Nov 10, 2015 at 03:58:14PM +0100, Lars-Peter Clausen wrote: > On 11/09/2015 02:28 PM, Haibo Chen wrote: > > Freescale i.MX7D soc contains a new ADC IP. This patch add this ADC > > driver support, and the driver only support ADC software trigger. > > > > Signed-off-by: Haibo Chen > > Looks pretty good, a few comments inline. > > [...] > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > I don't think you need all of these. > > [...] Yes, I will remove delay.h slab.h of_irq.h and of_platform.h > > +static void imx7d_adc_feature_config(struct imx7d_adc *info) > > +{ > > + info->adc_feature.clk_pre_div = IMX7D_ADC_ANALOG_CLK_PRE_DIV_4; > > + info->adc_feature.avg_num = IMX7D_ADC_AVERAGE_NUM_32; > > + info->adc_feature.core_time_unit = 1; > > + info->adc_feature.average_en = true; > > What's the plan for these? Right now they are always initialized to the same > static value. > In future, we can get these values from dts file, currently we just use the static value. > > > +} > [...] > > +static int imx7d_adc_read_raw(struct iio_dev *indio_dev, > > + struct iio_chan_spec const *chan, > > + int *val, > > + int *val2, > > + long mask) > > +{ > > + struct imx7d_adc *info = iio_priv(indio_dev); > > + > > + u32 channel; > > + long ret; > > + > > + switch (mask) { > > + case IIO_CHAN_INFO_RAW: > > + mutex_lock(&indio_dev->mlock); > > + reinit_completion(&info->completion); > > + > > + channel = (chan->channel) & 0x0f; > > + info->channel = channel; > > + imx7d_adc_channel_set(info); > > How about just passing channel directy adc_channel_set() instead of doing it > implicitly through the info struct? > I think there is no difference, besides, using this parameter info struct can keep align with other functions. eg. imx7d_adc_sample_set(), imx7d_adc_hw_init(), imx7d_adc_get_sample_rate(), all these functions have the same parameter. > [...] > > +static irqreturn_t imx7d_adc_isr(int irq, void *dev_id) > > +{ > > + struct imx7d_adc *info = (struct imx7d_adc *)dev_id; > > + int status; > > + > > + status = readl(info->regs + IMX7D_REG_ADC_INT_STATUS); > > + if (status & IMX7D_REG_ADC_INT_STATUS_CHANNEL_INT_STATUS) { > > + info->value = imx7d_adc_read_data(info); > > + complete(&info->completion); > > + } > > + writel(0, info->regs + IMX7D_REG_ADC_INT_STATUS); > > Is the hardware really this broken? If the interrupt happens between reading > the status register and clearing it here it will be missed. > I think interrupt can't happen between reading the status register and clearing it. Because in function imx7d_adc_read_raw(), we call the function imx7d_adc_channel_set(info), in this function, we config the register REG_ADC_CH_A\B\C\D_CFG1 and REG_ADC_CH_A\B\C\D_CFG2, only when these registers is configed, ADC start a conversion. Once the conversion complete, ADC trigger an interrupt, and call the imx7d_adc_isr(). > > + > > + return IRQ_HANDLED; > > You should only return IRQ_HANDLED if you actually handled are interrupt. > Here in the interrupt, we just handle the channel conversion finished flag, for other flag, ignore them this time, Will add other flag in future. > > +} > [...] > > + > > +static int imx7d_adc_probe(struct platform_device *pdev) > > +{ > > + struct imx7d_adc *info; > > + struct iio_dev *indio_dev; > > + struct resource *mem; > > + int irq; > > + int ret; > > + u32 channels; > > + > > + indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct imx7d_adc)); > > + if (!indio_dev) { > > + dev_err(&pdev->dev, "Failed allocating iio device\n"); > > + return -ENOMEM; > > + } > > + > > + info = iio_priv(indio_dev); > > + info->dev = &pdev->dev; > > + > > + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); > > + info->regs = devm_ioremap_resource(&pdev->dev, mem); > > + if (IS_ERR(info->regs)) { > > + ret = PTR_ERR(info->regs); > > + dev_err(&pdev->dev, "failed to remap adc memory: %d\n", ret); > > + return ret; > > + } > > + > > + irq = platform_get_irq(pdev, 0); > > + if (irq < 0) { > > + dev_err(&pdev->dev, "no irq resource?\n"); > > + return irq; > > + } > > + > > + ret = devm_request_irq(info->dev, irq, > > + imx7d_adc_isr, 0, > > + dev_name(&pdev->dev), info); > > This is too early. Completion is not initialized, clocks are not enabled, etc... > You are right, I will move the request irq function down. > > + if (ret < 0) { > > + dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq); > > + return ret; > > + } > > + > [...] > > + ret = of_property_read_u32(pdev->dev.of_node, > > Extra space. > > > + "num-channels", &channels); > > What decides how many channels are in use? > The board decides the channel number. In dts file, there is a line: num-channels = <4>; > > + if (ret) > > + channels = ARRAY_SIZE(imx7d_adc_iio_channels); > > + > > + indio_dev->name = dev_name(&pdev->dev); > > + indio_dev->dev.parent = &pdev->dev; > > + indio_dev->dev.of_node = pdev->dev.of_node; > > + indio_dev->info = &imx7d_adc_iio_info; > > + indio_dev->modes = INDIO_DIRECT_MODE; > > + indio_dev->channels = imx7d_adc_iio_channels; > > + indio_dev->num_channels = (int)channels; > > I don't think you need the case here. > Sorry, can't get your point, you mean I should not indio_dev-> ? > >[...] -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/