Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935200AbcCPSdc (ORCPT ); Wed, 16 Mar 2016 14:33:32 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:52803 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934609AbcCPSda (ORCPT ); Wed, 16 Mar 2016 14:33:30 -0400 Subject: Re: Nokia N900 - audio TPA6130A2 problems To: Ivaylo Dimitrov , Sebastian Reichel , =?UTF-8?Q?Pali_Roh=c3=a1r?= References: <201507251228.27128@pali> <201601050034.12810@pali> <20160306152339.GA428@earth> <201603121342.33099@pali> <56E68B71.2030202@ti.com> <20160316133319.GR8413@pali> <20160316144709.GA3389@earth> <56E9A42B.3010209@gmail.com> CC: Peter Ujfalusi , Jarkko Nikula , Tony Lindgren , Lars-Peter Clausen , , , Pavel Machek , Aaro Koskinen , Nishanth Menon , From: Grygorii Strashko Message-ID: <56E9A6D9.7000003@ti.com> Date: Wed, 16 Mar 2016 20:32:57 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <56E9A42B.3010209@gmail.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3494 Lines: 98 On 03/16/2016 08:21 PM, Ivaylo Dimitrov wrote: > Hi, > > On 16.03.2016 16:47, Sebastian Reichel wrote: >> Hi, >> >> On Wed, Mar 16, 2016 at 02:33:19PM +0100, Pali Roh?r wrote: >>> Hi! We found out that tpa6130a2 device is being initialized before >>> i2c_2 bus is initialized. So that is reason why tpa6130a2 fails... >> >> What do you mean by initialize? A call to tpa6130a2_probe()? In that >> case I wonder about client->adapter. Is it NULL? >> > > This is (a part of) the log when tpa6130a2 fails to initialize: > > Jan 1 08:03:07 Nokia-N900 kernel: [ 1.928344] twl 1-0048: PIH (irq > 23) chaining IRQs 340..348 > Jan 1 08:03:07 Nokia-N900 kernel: [ 1.934326] twl 1-0048: power (irq > 345) chaining IRQs 348..355 > Jan 1 08:03:07 Nokia-N900 kernel: [ 2.498504] twl4030_gpio > twl4030-gpio: gpio (irq 340) chaining IRQs 356..373 > Jan 1 08:03:07 Nokia-N900 kernel: [ 2.858215] twl4030_usb > 48070000.i2c:twl@48:twl4030-usb: Initialized TWL4030 USB module > Jan 1 08:03:07 Nokia-N900 kernel: [ 2.888702] input: > twl4030_pwrbutton as > /devices/platform/68000000.ocp/48070000.i2c/i2c-1/1-0048/48070000.i2c:twl@48:pwrbutton/input/input0 > > Jan 1 08:03:07 Nokia-N900 kernel: [ 2.903594] input: TWL4030 Keypad > as > /devices/platform/68000000.ocp/48070000.i2c/i2c-1/1-0048/48070000.i2c:twl@48:keypad/input/input1 > > Jan 1 08:03:07 Nokia-N900 kernel: [ 3.148040] > 48070000.i2c:twl@48:madc supply vusb3v1 not found, using dummy regulator > Jan 1 08:03:07 Nokia-N900 kernel: [ 6.997985] omap_i2c 48070000.i2c: > bus 1 rev3.3 at 2200 kHz > Jan 1 08:03:07 Nokia-N900 kernel: [ 7.010528] tpa6130a2 2-0060: > Write failed > Jan 1 08:03:07 Nokia-N900 kernel: [ 7.015563] omap_i2c 48072000.i2c: > bus 2 rev3.3 at 100 kHz > Jan 1 08:03:07 Nokia-N900 kernel: [ 7.023742] omap_i2c 48060000.i2c: > bus 3 rev3.3 at 400 kHz > > Now, it is either tpa6130a2 probe() is called before i2c-2 is > initialized or i2c driver first probes devices on the bus and only then > logs successful probe ("omap_i2c 48072000.i2c: bus 2 rev3.3 at 100 kHz") > in our case. No-no :) take a look on i2c-omap.c r = i2c_add_numbered_adapter(adap); ^^^^ here you see messages from tpa6130a2 (create i2c devices & probe if drivers are ready) if (r) { dev_err(omap->dev, "failure adding adapter\n"); goto err_unuse_clocks; } dev_info(omap->dev, "bus %d rev%d.%d at %d kHz\n", adap->nr, major, minor, omap->speed); ^^^^ and here "omap_i2c 48072000.i2c: bus 2 rev3.3 at 100 kHz" so everything is ok with probe order > >> --------------- >> >> I just had another look at the driver and I think there is a race >> condition for tpa6130a2_add_controls() and tpa6130a2_stereo_enable(). >> >> As far as I can see both functions check for "tpa6130a2_client != >> NULL". tpa6130a2_client is set before the probe function has finished, >> though. Simplified probe: >> >> ... >> tpa6130a2_client = client; >> set_default_regs(); >> acquire_power_gpio(); >> acquire_regulator(); >> tpa6130a2_power(1); // needs tpa6130a2_client >> check_device(); >> tpa6130a2_power(0); // needs tpa6130a2_client >> ... >> >> If tpa6130a2_add_controls() or tpa6130a2_stereo_enable() is called >> after tpa6130a2 probe has started, but before probe has completed, >> tpa6130a2_client is set, but not yet initialized. The race condition >> can be fixed easily by moving the tpa6130a2_client assignment directly >> after the regulator acquisition. >> -- regards, -grygorii