From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Looijmans Subject: Re: [PATCH v2] sound/soc/adi/axi-spdif.c: Support programmable master clock Date: Thu, 11 Dec 2014 07:44:13 +0100 Message-ID: <54893D3D.8050100@topic.nl> References: <54806D4E.8040504@topic.nl> <1417783029-22492-1-git-send-email-mike.looijmans@topic.nl> <548813AC.1080105@metafoo.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: <548813AC.1080105@metafoo.de> Sender: linux-kernel-owner@vger.kernel.org To: Lars-Peter Clausen Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org List-Id: alsa-devel@alsa-project.org =EF=BB=BFOn 12/10/2014 10:34 AM, Lars-Peter Clausen wrote: > On 12/05/2014 01:37 PM, Mike Looijmans wrote: >> If the master clock supports programmable rates, program it to gener= ate >> the desired frequency. Only apply constraints when the clock is fixe= d. >> This allows proper clock generation for both 44100 and 48000 Hz base= d >> sampling rates if the platform supports it. >> >> The clock frequency must be set before enabling it. Enabling the clo= ck >> was done in "startup", but that occurs before "hw_params" where the = rate >> is known. Enabling a programmable clock without first setting a vali= d >> frequency may harm the system. Move the clock start to the hw_params >> routine, and keep track of whether the clock has been started, becau= se >> shutdown may be called without having called hw_params first. >> Starting the clock and enabling the SPDIF output AFTER programming t= he >> dividers is a more logical order anyway. >> >> To detect if the source clock is fixed, the driver calls clk_round_r= ate >> for two frequencies. If the results are equal, or if the call return= s >> an error, the driver assumes the clock is fixed. >> >> Signed-off-by: Mike Looijmans > > Hi, > > Sorry for the delay. > > [...] >> >> + /* Try to set the master clock */ >> + clk_set_rate(spdif->clk_ref, rate * 128); >> + >> clkdiv =3D DIV_ROUND_CLOSEST(clk_get_rate(spdif->clk_ref), >> rate * 64 * 2) - 1; >> clkdiv <<=3D AXI_SPDIF_CTRL_CLKDIV_OFFSET; >> @@ -103,6 +108,14 @@ static int axi_spdif_hw_params(struct snd_pcm_s= ubstream >> *substream, >> regmap_update_bits(spdif->regmap, AXI_SPDIF_REG_CTRL, >> AXI_SPDIF_CTRL_CLKDIV_MASK, clkdiv); >> >> + ret =3D clk_prepare_enable(spdif->clk_ref); > > I'm still not convinced this is the right place. I do see your point.= But it > just feels wrong to enable the clock in hw_params. It's a bit of a di= lemma. > the startup callback is to early, hw_params is the wrong place and we= can't > put it in the trigger callback as the trigger callback can not sleep. The clock interface suggests that we should do the clk_prepare in hw_pa= rams=20 and the clk_enable in trigger then, since clk_prepare may sleep but clk= _enable=20 cannot. Which would complicate the clock state housekeeping because I'd= have=20 to keep track of prepare and enable states separately. (Imagine the housekeeping on a board that could have two codecs running= on one=20 DAI using the clock generated by a third codec... I never even bothered= to=20 submit that...) > But in any way hwparmas can be called multiple times, so you need to = handle > the case where the clock is already enabled. A simple "if (spdif->clk_ref_running)" check would fix that. I wasn't a= ware of=20 that though, I thought there'd be a shutdown before another hw_params. >> + if (ret) >> + return ret; >> + spdif->clk_ref_running =3D true; >> + >> + regmap_update_bits(spdif->regmap, AXI_SPDIF_REG_CTRL, >> + AXI_SPDIF_CTRL_TXEN, AXI_SPDIF_CTRL_TXEN); > > This should probably be moved to the trigger callback though. I'll create a v3. Met vriendelijke groet / kind regards, Mike Looijmans System Expert TOPIC Embedded Systems Eindhovenseweg 32-C, NL-5683 KH Best Postbus 440, NL-5680 AK Best Telefoon: (+31) (0) 499 33 69 79 Telefax: (+31) (0) 499 33 69 70 E-mail: mike.looijmans@topic.nl Website: www.topic.nl Please consider the environment before printing this e-mail Topic zoekt gedreven (embedded) software specialisten! http://topic.nl/vacatures/topic-zoekt-software-engineers/