All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roman Volkov <v1ron@mail.ru>
To: Clemens Ladisch <clemens@ladisch.de>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH v3 01/16] ALSA: Oxygen: Add the separate SPI waiting function
Date: Sun, 19 Jan 2014 12:10:06 +0400	[thread overview]
Message-ID: <20140119121006.3ee8bde7@v1ron-desktop> (raw)
In-Reply-To: <52DA56E9.2020703@ladisch.de>

В Sat, 18 Jan 2014 11:26:49 +0100
Clemens Ladisch <clemens@ladisch.de> пишет:

> > This function performs waiting when the SPI bus completes
> > a transaction. Timeout error checking introduced and
> > the timeout increased to 400 from 40.  
> 
> Why 400?  SPI does not allow the codec to delay reads.

Yes. AFAIK, every SPI transaction will take almost the same time,
depending on the SPI clock and the number of bits to transfer,
regardless of what we're performing, reading or writing.

400 us is just the maximum time, exceeding this will cause an error.
Okay, lets calculate, in worst case (3 bytes to transfer, 1280ns clock):

1280 * 8 * 3 = 30270ns, 30,72 us. Perhaps plus some time to initiate
the transfer.

400us is greater than 40 by 10 times, but the function never waits 400
us, it always returns earlier than in 40-50 us. I always prefer to
increase these timeouts much longer than needed, this guarantees
that I never get false-positives and this wait is safe. Even if the
error occured, 400us is very small amount of time.

> > +	for (count = 100; count > 0; count--) {
> > +		if ((oxygen_read8(chip, OXYGEN_SPI_CONTROL) &
> > +						OXYGEN_SPI_BUSY)
> > == 0)
> > +			return 0;
> > +		udelay(4);
> > +		--count;
> > +	}  
> 
> This loop waits for 200 µs.
> 

Ah... Thanks.
Also why I prefer higher timeouts:
http://stackoverflow.com/questions/8352812/linux-kernel-udelay-returns-too-early
Even if a mistake or a bug, this works as needed :) This driver
currently works on my PC, if the test succeeded, this decreases my
attention :)

> The SPI transaction will not be finished for the first 30 µs or so, so
> polling is not needed for that time.

We may switch the context and force CPU to
execute useful code, using something like usleep, msleep. However,
this may block the thread for too long time. Please suggest
something how to optimize this.

> With the wait coming after the transaction, it makes more sense to
> have the busy check not before but after the udelay.

Okay, this will be:

for (count = 100; count > 0; count--) {
	udelay(4);
	if ((oxygen_read8(chip, OXYGEN_SPI_CONTROL) &
					OXYGEN_SPI_BUSY) == 0)
		return 0;
}

-- 
Kind regards,
Roman Volkov,
v1ron@mail.ru
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  reply	other threads:[~2014-01-19  8:10 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-17 15:08 [PATCH v3 01/16] ALSA: Oxygen: Add the separate SPI waiting function Roman Volkov
2014-01-17 15:08 ` [PATCH v3 02/16] ALSA: Oxygen: Modify the SPI writing function Roman Volkov
2014-01-17 15:08 ` [PATCH v3 03/16] ALSA: Oxygen: Add mute mask for the OXYGEN_PLAY_ROUTING register Roman Volkov
2014-01-17 15:08 ` [PATCH v3 04/16] ALSA: Oxygen: Add CS4245_SPI_READ constant Roman Volkov
2014-01-18 10:29   ` Clemens Ladisch
2014-01-17 15:08 ` [PATCH v3 05/16] ALSA: Oxygen: Export oxygen_update_dac_routing symbol Roman Volkov
2014-01-17 15:08 ` [PATCH v3 06/16] ALSA: Oxygen: Change description of the xonar_dg.c file Roman Volkov
2014-01-17 15:08 ` [PATCH v3 07/16] ALSA: Oxygen: Additional definitions for the Xonar DG/DGX card Roman Volkov
2014-01-17 15:08 ` [PATCH v3 08/16] ALSA: Oxygen: Add new CS4245 SPI functions Roman Volkov
2014-01-18 10:36   ` Clemens Ladisch
2014-01-17 15:08 ` [PATCH v3 09/16] ALSA: Oxygen: Modify initialization functions Roman Volkov
2014-01-18 10:50   ` Clemens Ladisch
2014-01-20 14:14     ` Roman Volkov
2014-01-17 15:08 ` [PATCH v3 10/16] ALSA: Oxygen: Modify DAC/ADC parameters function Roman Volkov
2014-01-17 15:08 ` [PATCH v3 11/16] ALSA: Oxygen: Modify adjust_dg_dac_routing function Roman Volkov
2014-01-17 15:08 ` [PATCH v3 12/16] ALSA: Oxygen: Modify CS4245 register dumping function Roman Volkov
2014-01-17 15:08 ` [PATCH v3 13/16] ALSA: Oxygen: Modify suspend, resume, and cleanup functions Roman Volkov
2014-01-17 15:08 ` [PATCH v3 14/16] ALSA: Oxygen: Remove code from the xonar_dg.c file Roman Volkov
2014-01-18 11:08   ` Clemens Ladisch
2014-01-17 15:08 ` [PATCH v3 15/16] ALSA: Oxygen: Additional declarations for the new mixer implementation Roman Volkov
2014-01-17 15:08 ` [PATCH v3 16/16] ALSA: Oxygen: The " Roman Volkov
2014-01-18 10:26 ` [PATCH v3 01/16] ALSA: Oxygen: Add the separate SPI waiting function Clemens Ladisch
2014-01-19  8:10   ` Roman Volkov [this message]
2014-01-19  9:39     ` Clemens Ladisch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140119121006.3ee8bde7@v1ron-desktop \
    --to=v1ron@mail.ru \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.