History log of /u-boot/drivers/spi/omap3_spi.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# d678a59d 18-May-2024 Tom Rini <trini@konsulko.com>

Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""

When bringing in the series 'arm: dts: am62-beagleplay: Fix Beagleplay
Ethernet"' I failed to notice that b4 noticed it was based on next and
so took that as the base commit and merged that part of next to master.

This reverts commit c8ffd1356d42223cbb8c86280a083cc3c93e6426, reversing
changes made to 2ee6f3a5f7550de3599faef9704e166e5dcace35.

Reported-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 7d2bf7c2 01-May-2024 Tom Rini <trini@konsulko.com>

spi: Remove <common.h> and add needed includes

Remove <common.h> from this driver directory and when needed
add missing include files directly.

Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: William Zhang <william.zhang@broadcom.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# a94a4071 01-Nov-2023 Nishanth Menon <nm@ti.com>

tree-wide: Replace http:// link with https:// link for ti.com

Replace instances of http://www.ti.com with https://www.ti.com

Signed-off-by: Nishanth Menon <nm@ti.com>

# fb93bd8d 29-May-2023 Julien Panis <jpanis@baylibre.com>

drivers: spi: omap3_spi: Initialize mode for all channels

At first SPI transfers, multiple chip selects can be
enabled simultaneously. This is due to chip select
polarity, which is not properly initialized for all
channels. This patch fixes the issue.

Signed-off-by: Julien Panis <jpanis@baylibre.com>

# d466f620 08-Dec-2022 Pengfei Fan <fanpengfei1@eswincomputing.com>

drivers: spi: fix some typos

Fix some typos in spi drivers

Signed-off-by: Pengfei Fan <fanpengfei1@eswincomputing.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>

# 414cc151 07-Aug-2021 Simon Glass <sjg@chromium.org>

treewide: Simply conditions with the new OF_REAL

Use this new Kconfig to simplify the compilation conditions where
appropriate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f3f83ad4 28-Nov-2020 Vignesh Raghavendra <vigneshr@ti.com>

spi: omap3_spi: Fix speed and mode selection

McSPI IP provides per CS specific speed and mode selection. Therefore it
is possible to apply these settings only after CS is known. But
set_speed and set_mode can be called without bus being claimed, this
would lead driver to set up wrong CS (or previously used CS).

Fix this by apply set_speed and set_mode only if bus is already claimed.

Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>

# 8a8d24bd 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ..._platdata variables to just ..._plat

Try to maintain some consistency between these variables by using _plat as
a suffix for them.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

Signed-off-by: Simon Glass <sjg@chromium.org>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

Signed-off-by: Simon Glass <sjg@chromium.org>

# afd4f15a 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

spi: omap3_spi: Read platform data in ofdata_to_platdata()

Add an ofdata_to_platdata() callback to access dts in U-boot and
access all platform data in it. This prepares the driver for supporting
both device tree as well as static platform data structures in SPL.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 41cf3cb3 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

arm: mach-omap2: am33xx: Add device structure for spi

Add platform data and a device structure for the spi device
present on am335x-icev2. This requires moving all omap3_spi
platform data structures and symbols to an omap3_spi.h so that
the board file can access them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 2548493a 16-Jul-2020 Masahiro Yamada <masahiroy@kernel.org>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 7208396b 24-Jul-2020 Tom Rini <trini@konsulko.com>

Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"

This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing
changes made to 56d37f1c564107e27d873181d838571b7d7860e7.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>

# 60e7fa8b 16-Jul-2020 Masahiro Yamada <masahiroy@kernel.org>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@konsulko.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@konsulko.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 7d2bf7c2 01-May-2024 Tom Rini <trini@konsulko.com>

spi: Remove <common.h> and add needed includes

Remove <common.h> from this driver directory and when needed
add missing include files directly.

Reviewed-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: William Zhang <william.zhang@broadcom.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# a94a4071 01-Nov-2023 Nishanth Menon <nm@ti.com>

tree-wide: Replace http:// link with https:// link for ti.com

Replace instances of http://www.ti.com with https://www.ti.com

Signed-off-by: Nishanth Menon <nm@ti.com>

# fb93bd8d 29-May-2023 Julien Panis <jpanis@baylibre.com>

drivers: spi: omap3_spi: Initialize mode for all channels

At first SPI transfers, multiple chip selects can be
enabled simultaneously. This is due to chip select
polarity, which is not properly initialized for all
channels. This patch fixes the issue.

Signed-off-by: Julien Panis <jpanis@baylibre.com>

# d466f620 08-Dec-2022 Pengfei Fan <fanpengfei1@eswincomputing.com>

drivers: spi: fix some typos

Fix some typos in spi drivers

Signed-off-by: Pengfei Fan <fanpengfei1@eswincomputing.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>

# 414cc151 07-Aug-2021 Simon Glass <sjg@chromium.org>

treewide: Simply conditions with the new OF_REAL

Use this new Kconfig to simplify the compilation conditions where
appropriate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f3f83ad4 28-Nov-2020 Vignesh Raghavendra <vigneshr@ti.com>

spi: omap3_spi: Fix speed and mode selection

McSPI IP provides per CS specific speed and mode selection. Therefore it
is possible to apply these settings only after CS is known. But
set_speed and set_mode can be called without bus being claimed, this
would lead driver to set up wrong CS (or previously used CS).

Fix this by apply set_speed and set_mode only if bus is already claimed.

Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>

# 8a8d24bd 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ..._platdata variables to just ..._plat

Try to maintain some consistency between these variables by using _plat as
a suffix for them.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

Signed-off-by: Simon Glass <sjg@chromium.org>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

Signed-off-by: Simon Glass <sjg@chromium.org>

# afd4f15a 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

spi: omap3_spi: Read platform data in ofdata_to_platdata()

Add an ofdata_to_platdata() callback to access dts in U-boot and
access all platform data in it. This prepares the driver for supporting
both device tree as well as static platform data structures in SPL.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 41cf3cb3 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

arm: mach-omap2: am33xx: Add device structure for spi

Add platform data and a device structure for the spi device
present on am335x-icev2. This requires moving all omap3_spi
platform data structures and symbols to an omap3_spi.h so that
the board file can access them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 2548493a 16-Jul-2020 Masahiro Yamada <masahiroy@kernel.org>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 7208396b 24-Jul-2020 Tom Rini <trini@konsulko.com>

Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"

This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing
changes made to 56d37f1c564107e27d873181d838571b7d7860e7.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>

# 60e7fa8b 16-Jul-2020 Masahiro Yamada <masahiroy@kernel.org>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@konsulko.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@konsulko.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# a94a4071 01-Nov-2023 Nishanth Menon <nm@ti.com>

tree-wide: Replace http:// link with https:// link for ti.com

Replace instances of http://www.ti.com with https://www.ti.com

Signed-off-by: Nishanth Menon <nm@ti.com>

# fb93bd8d 29-May-2023 Julien Panis <jpanis@baylibre.com>

drivers: spi: omap3_spi: Initialize mode for all channels

At first SPI transfers, multiple chip selects can be
enabled simultaneously. This is due to chip select
polarity, which is not properly initialized for all
channels. This patch fixes the issue.

Signed-off-by: Julien Panis <jpanis@baylibre.com>

# d466f620 08-Dec-2022 Pengfei Fan <fanpengfei1@eswincomputing.com>

drivers: spi: fix some typos

Fix some typos in spi drivers

Signed-off-by: Pengfei Fan <fanpengfei1@eswincomputing.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>

# 414cc151 07-Aug-2021 Simon Glass <sjg@chromium.org>

treewide: Simply conditions with the new OF_REAL

Use this new Kconfig to simplify the compilation conditions where
appropriate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f3f83ad4 28-Nov-2020 Vignesh Raghavendra <vigneshr@ti.com>

spi: omap3_spi: Fix speed and mode selection

McSPI IP provides per CS specific speed and mode selection. Therefore it
is possible to apply these settings only after CS is known. But
set_speed and set_mode can be called without bus being claimed, this
would lead driver to set up wrong CS (or previously used CS).

Fix this by apply set_speed and set_mode only if bus is already claimed.

Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>

# 8a8d24bd 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ..._platdata variables to just ..._plat

Try to maintain some consistency between these variables by using _plat as
a suffix for them.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

Signed-off-by: Simon Glass <sjg@chromium.org>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

Signed-off-by: Simon Glass <sjg@chromium.org>

# afd4f15a 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

spi: omap3_spi: Read platform data in ofdata_to_platdata()

Add an ofdata_to_platdata() callback to access dts in U-boot and
access all platform data in it. This prepares the driver for supporting
both device tree as well as static platform data structures in SPL.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 41cf3cb3 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

arm: mach-omap2: am33xx: Add device structure for spi

Add platform data and a device structure for the spi device
present on am335x-icev2. This requires moving all omap3_spi
platform data structures and symbols to an omap3_spi.h so that
the board file can access them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 2548493a 16-Jul-2020 Masahiro Yamada <masahiroy@kernel.org>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 7208396b 24-Jul-2020 Tom Rini <trini@konsulko.com>

Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"

This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing
changes made to 56d37f1c564107e27d873181d838571b7d7860e7.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>

# 60e7fa8b 16-Jul-2020 Masahiro Yamada <masahiroy@kernel.org>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@konsulko.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@konsulko.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# fb93bd8d 29-May-2023 Julien Panis <jpanis@baylibre.com>

drivers: spi: omap3_spi: Initialize mode for all channels

At first SPI transfers, multiple chip selects can be
enabled simultaneously. This is due to chip select
polarity, which is not properly initialized for all
channels. This patch fixes the issue.

Signed-off-by: Julien Panis <jpanis@baylibre.com>

# d466f620 08-Dec-2022 Pengfei Fan <fanpengfei1@eswincomputing.com>

drivers: spi: fix some typos

Fix some typos in spi drivers

Signed-off-by: Pengfei Fan <fanpengfei1@eswincomputing.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>

# 414cc151 07-Aug-2021 Simon Glass <sjg@chromium.org>

treewide: Simply conditions with the new OF_REAL

Use this new Kconfig to simplify the compilation conditions where
appropriate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f3f83ad4 28-Nov-2020 Vignesh Raghavendra <vigneshr@ti.com>

spi: omap3_spi: Fix speed and mode selection

McSPI IP provides per CS specific speed and mode selection. Therefore it
is possible to apply these settings only after CS is known. But
set_speed and set_mode can be called without bus being claimed, this
would lead driver to set up wrong CS (or previously used CS).

Fix this by apply set_speed and set_mode only if bus is already claimed.

Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>

# 8a8d24bd 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ..._platdata variables to just ..._plat

Try to maintain some consistency between these variables by using _plat as
a suffix for them.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

Signed-off-by: Simon Glass <sjg@chromium.org>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

Signed-off-by: Simon Glass <sjg@chromium.org>

# afd4f15a 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

spi: omap3_spi: Read platform data in ofdata_to_platdata()

Add an ofdata_to_platdata() callback to access dts in U-boot and
access all platform data in it. This prepares the driver for supporting
both device tree as well as static platform data structures in SPL.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 41cf3cb3 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

arm: mach-omap2: am33xx: Add device structure for spi

Add platform data and a device structure for the spi device
present on am335x-icev2. This requires moving all omap3_spi
platform data structures and symbols to an omap3_spi.h so that
the board file can access them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 2548493a 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 7208396b 24-Jul-2020 Tom Rini <trini@konsulko.com>

Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"

This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing
changes made to 56d37f1c564107e27d873181d838571b7d7860e7.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>

# 60e7fa8b 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@konsulko.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@konsulko.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# d466f620 08-Dec-2022 Pengfei Fan <fanpengfei1@eswincomputing.com>

drivers: spi: fix some typos

Fix some typos in spi drivers

Signed-off-by: Pengfei Fan <fanpengfei1@eswincomputing.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>

# 414cc151 07-Aug-2021 Simon Glass <sjg@chromium.org>

treewide: Simply conditions with the new OF_REAL

Use this new Kconfig to simplify the compilation conditions where
appropriate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f3f83ad4 28-Nov-2020 Vignesh Raghavendra <vigneshr@ti.com>

spi: omap3_spi: Fix speed and mode selection

McSPI IP provides per CS specific speed and mode selection. Therefore it
is possible to apply these settings only after CS is known. But
set_speed and set_mode can be called without bus being claimed, this
would lead driver to set up wrong CS (or previously used CS).

Fix this by apply set_speed and set_mode only if bus is already claimed.

Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>

# 8a8d24bd 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ..._platdata variables to just ..._plat

Try to maintain some consistency between these variables by using _plat as
a suffix for them.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

Signed-off-by: Simon Glass <sjg@chromium.org>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

Signed-off-by: Simon Glass <sjg@chromium.org>

# afd4f15a 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

spi: omap3_spi: Read platform data in ofdata_to_platdata()

Add an ofdata_to_platdata() callback to access dts in U-boot and
access all platform data in it. This prepares the driver for supporting
both device tree as well as static platform data structures in SPL.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 41cf3cb3 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

arm: mach-omap2: am33xx: Add device structure for spi

Add platform data and a device structure for the spi device
present on am335x-icev2. This requires moving all omap3_spi
platform data structures and symbols to an omap3_spi.h so that
the board file can access them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 2548493a 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 7208396b 24-Jul-2020 Tom Rini <trini@konsulko.com>

Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"

This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing
changes made to 56d37f1c564107e27d873181d838571b7d7860e7.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>

# 60e7fa8b 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@konsulko.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@konsulko.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 414cc151 07-Aug-2021 Simon Glass <sjg@chromium.org>

treewide: Simply conditions with the new OF_REAL

Use this new Kconfig to simplify the compilation conditions where
appropriate.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f3f83ad4 28-Nov-2020 Vignesh Raghavendra <vigneshr@ti.com>

spi: omap3_spi: Fix speed and mode selection

McSPI IP provides per CS specific speed and mode selection. Therefore it
is possible to apply these settings only after CS is known. But
set_speed and set_mode can be called without bus being claimed, this
would lead driver to set up wrong CS (or previously used CS).

Fix this by apply set_speed and set_mode only if bus is already claimed.

Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>

# 8a8d24bd 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ..._platdata variables to just ..._plat

Try to maintain some consistency between these variables by using _plat as
a suffix for them.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

Signed-off-by: Simon Glass <sjg@chromium.org>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

Signed-off-by: Simon Glass <sjg@chromium.org>

# afd4f15a 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

spi: omap3_spi: Read platform data in ofdata_to_platdata()

Add an ofdata_to_platdata() callback to access dts in U-boot and
access all platform data in it. This prepares the driver for supporting
both device tree as well as static platform data structures in SPL.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 41cf3cb3 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

arm: mach-omap2: am33xx: Add device structure for spi

Add platform data and a device structure for the spi device
present on am335x-icev2. This requires moving all omap3_spi
platform data structures and symbols to an omap3_spi.h so that
the board file can access them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 2548493a 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 7208396b 24-Jul-2020 Tom Rini <trini@konsulko.com>

Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"

This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing
changes made to 56d37f1c564107e27d873181d838571b7d7860e7.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>

# 60e7fa8b 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@ti.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@ti.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f3f83ad4 28-Nov-2020 Vignesh Raghavendra <vigneshr@ti.com>

spi: omap3_spi: Fix speed and mode selection

McSPI IP provides per CS specific speed and mode selection. Therefore it
is possible to apply these settings only after CS is known. But
set_speed and set_mode can be called without bus being claimed, this
would lead driver to set up wrong CS (or previously used CS).

Fix this by apply set_speed and set_mode only if bus is already claimed.

Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>

# 8a8d24bd 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ..._platdata variables to just ..._plat

Try to maintain some consistency between these variables by using _plat as
a suffix for them.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

Signed-off-by: Simon Glass <sjg@chromium.org>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

Signed-off-by: Simon Glass <sjg@chromium.org>

# afd4f15a 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

spi: omap3_spi: Read platform data in ofdata_to_platdata()

Add an ofdata_to_platdata() callback to access dts in U-boot and
access all platform data in it. This prepares the driver for supporting
both device tree as well as static platform data structures in SPL.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 41cf3cb3 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

arm: mach-omap2: am33xx: Add device structure for spi

Add platform data and a device structure for the spi device
present on am335x-icev2. This requires moving all omap3_spi
platform data structures and symbols to an omap3_spi.h so that
the board file can access them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 2548493a 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 7208396b 24-Jul-2020 Tom Rini <trini@konsulko.com>

Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"

This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing
changes made to 56d37f1c564107e27d873181d838571b7d7860e7.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>

# 60e7fa8b 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@ti.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@ti.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# f3f83ad4 28-Nov-2020 Vignesh Raghavendra <vigneshr@ti.com>

spi: omap3_spi: Fix speed and mode selection

McSPI IP provides per CS specific speed and mode selection. Therefore it
is possible to apply these settings only after CS is known. But
set_speed and set_mode can be called without bus being claimed, this
would lead driver to set up wrong CS (or previously used CS).

Fix this by apply set_speed and set_mode only if bus is already claimed.

Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>

# 8a8d24bd 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ..._platdata variables to just ..._plat

Try to maintain some consistency between these variables by using _plat as
a suffix for them.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

Signed-off-by: Simon Glass <sjg@chromium.org>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

Signed-off-by: Simon Glass <sjg@chromium.org>

# afd4f15a 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

spi: omap3_spi: Read platform data in ofdata_to_platdata()

Add an ofdata_to_platdata() callback to access dts in U-boot and
access all platform data in it. This prepares the driver for supporting
both device tree as well as static platform data structures in SPL.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 41cf3cb3 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

arm: mach-omap2: am33xx: Add device structure for spi

Add platform data and a device structure for the spi device
present on am335x-icev2. This requires moving all omap3_spi
platform data structures and symbols to an omap3_spi.h so that
the board file can access them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 2548493a 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 7208396b 24-Jul-2020 Tom Rini <trini@konsulko.com>

Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"

This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing
changes made to 56d37f1c564107e27d873181d838571b7d7860e7.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>

# 60e7fa8b 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@ti.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@ti.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 8a8d24bd 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ..._platdata variables to just ..._plat

Try to maintain some consistency between these variables by using _plat as
a suffix for them.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d1998a9f 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename ofdata_to_platdata() to of_to_plat()

This name is far too long. Rename it to remove the 'data' bits. This makes
it consistent with the platdata->plat rename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c69cda25 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename dev_get_platdata() to dev_get_plat()

Rename this to be consistent with the change from 'platdata'.

Signed-off-by: Simon Glass <sjg@chromium.org>

# caa4daa2 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename 'platdata' variables to just 'plat'

We use 'priv' for private data but often use 'platdata' for platform data.
We can't really use 'pdata' since that is ambiguous (it could mean private
or platform data).

Rename some of the latter variables to end with 'plat' for consistency.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 41575d8e 03-Dec-2020 Simon Glass <sjg@chromium.org>

dm: treewide: Rename auto_alloc_size members to be shorter

This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

Signed-off-by: Simon Glass <sjg@chromium.org>

# afd4f15a 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

spi: omap3_spi: Read platform data in ofdata_to_platdata()

Add an ofdata_to_platdata() callback to access dts in U-boot and
access all platform data in it. This prepares the driver for supporting
both device tree as well as static platform data structures in SPL.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 41cf3cb3 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

arm: mach-omap2: am33xx: Add device structure for spi

Add platform data and a device structure for the spi device
present on am335x-icev2. This requires moving all omap3_spi
platform data structures and symbols to an omap3_spi.h so that
the board file can access them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 2548493a 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 7208396b 24-Jul-2020 Tom Rini <trini@konsulko.com>

Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"

This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing
changes made to 56d37f1c564107e27d873181d838571b7d7860e7.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>

# 60e7fa8b 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@ti.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@ti.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# afd4f15a 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

spi: omap3_spi: Read platform data in ofdata_to_platdata()

Add an ofdata_to_platdata() callback to access dts in U-boot and
access all platform data in it. This prepares the driver for supporting
both device tree as well as static platform data structures in SPL.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 41cf3cb3 13-Sep-2020 Faiz Abbas <faiz_abbas@ti.com>

arm: mach-omap2: am33xx: Add device structure for spi

Add platform data and a device structure for the spi device
present on am335x-icev2. This requires moving all omap3_spi
platform data structures and symbols to an omap3_spi.h so that
the board file can access them.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>

# 2548493a 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 7208396b 24-Jul-2020 Tom Rini <trini@konsulko.com>

Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"

This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing
changes made to 56d37f1c564107e27d873181d838571b7d7860e7.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>

# 60e7fa8b 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@ti.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@ti.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 2548493a 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 7208396b 24-Jul-2020 Tom Rini <trini@konsulko.com>

Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"

This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing
changes made to 56d37f1c564107e27d873181d838571b7d7860e7.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>

# 60e7fa8b 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@ti.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@ti.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 7208396b 24-Jul-2020 Tom Rini <trini@konsulko.com>

Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"

This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing
changes made to 56d37f1c564107e27d873181d838571b7d7860e7.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>

# 60e7fa8b 16-Jul-2020 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: convert devfdt_get_addr() to dev_read_addr()

When you enable CONFIG_OF_LIVE, you will end up with a lot of
conversions.

To generate this commit, I used coccinelle excluding drivers/core/,
include/dm/, and test/

The semantic patch that makes this change is as follows:

<smpl>
@@
expression dev;
@@
-devfdt_get_addr(dev)
+dev_read_addr(dev)
</smpl>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@ti.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@ti.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 5d128129 27-May-2020 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Drop nondm code

Now all boards are using this omap3 spi driver in
dm model, so drop the nondm code.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@ti.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@ti.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# 56c40460 04-Jun-2020 Lukasz Majewski <lukma@denx.de>

spi: Convert CONFIG_DM_SPI* to CONFIG_$(SPL_TPL_)DM_SPI*

This change allows more fine tuning of driver model based SPI support in
SPL and TPL. It is now possible to explicitly enable/disable the DM_SPI
support in SPL and TPL via Kconfig option.

Before this change it was necessary to use:
/* SPI Flash Configs */
#if defined(CONFIG_SPL_BUILD)
#undef CONFIG_DM_SPI
#undef CONFIG_DM_SPI_FLASH
#undef CONFIG_SPI_FLASH_MTD
#endif

in the ./include/configs/<board>.h, which is error prone and shall be
avoided when we strive to switch to Kconfig.

The goal of this patch:

Provide distinction for DM_SPI support in both U-Boot proper and SPL (TPL).
Valid use case is when U-Boot proper wants to use DM_SPI, but SPL must
still support non DM driver.

Another use case is the conversion of non DM/DTS SPI driver to support
DM/DTS. When such driver needs to work in both SPL and U-Boot proper, the
distinction is needed in Kconfig (also if SPL version of the driver
supports OF_PLATDATA).

In the end of the day one would have to support following use cases (in
single driver file - e.g. mxs_spi.c):

- U-Boot proper driver supporting DT/DTS
- U-Boot proper driver without DT/DTS support (deprecated)
- SPL driver without DT/DTS support
- SPL (and TPL) driver with DT/DTS (when the SoC has enough resources to
run full blown DT/DTS)
- SPL driver with DT/DTS and SPL_OF_PLATDATA (when one have constrained
environment with no fitImage and OF_LIBFDT support).

Some boards do require SPI support (with DM) in SPL (TPL) and some only
have DM_SPI{_FLASH} defined to allow compiling SPL.

This patch converts #ifdef CONFIG_DM_SPI* to #if CONFIG_IS_ENABLED(DM_SPI)
and provides corresponding defines in Kconfig.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #da850-evm
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
[trini: Fixup a few platforms]
Signed-off-by: Tom Rini <trini@konsulko.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@ti.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@ti.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# cd93d625 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop linux/bitops.h from common header

Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@ti.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@ti.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# b8b88e6a 18-Feb-2019 David Rivshin <DRivshin@allworx.com>

spi: omap3: fix set_wordlen() reading from incorrect address for CHCONF

_omap3_spi_set_wordlen() indexed the regs->channel[] array with the
old wordlen (instead of the chipselect number) when reading the current
CHCONF register value. This meant it read from the wrong memory location,
modified that value, and then wrote it back to the correct CHCONF
register. The end result is that most slave configuration settings would
be lost, such as clock divisor, clock/chipselect polarities, etc.

Fixes: 77b8d04854f4 ("spi: omap3: Convert to driver model")
Signed-off-by: David Rivshin <drivshin@allworx.com>

# e2cae514 20-Nov-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: Remove unused spi_init

Remove spi_init definition which never used on
respective code since from many years.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>

# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>

# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>

# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>

# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>

# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>

# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>

# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>

# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>

# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

# a4a99fff 08-Aug-2012 Tom Rini <trini@ti.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>

# 4c0620bf 08-Aug-2012 Tom Rini <trini@ti.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>

# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>

# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>

# c0eaffa0 26-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix claim/release bus within DM

The claim/release bus function must not reset the whole SPI core because
settings regarding wordlen, clock-frequency and so on made by
set_wordlen, set_mode, set_speed get lost with this action. Resulting in
a non-functional SPI.

Without DM the failure didn't came up since after the spi_reset within
claim bus all the setup (wordlen, mode, ...) was called, in DM they are
called by the spi uclass.

We change now the things as following for having a working SPI instance
in DM:

- move the spi_reset(...) to the probe call in DM for having a known
hardware state after probe. Without DM we don't have a probe call, so we
issue the reset as before during the claim_bus call.

- in release bus we just reset the modulctrl to the reset-value (spi-
slave)

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>


# 9cddf70e 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: fix set_speed and set_mode dm callbacks

commit 84807922874e03895bbf15c4472a2dcee8fbbd03
("spi: omap3: Skip set_mode, set_speed from claim") did break SPI
support on my AM335x board.

The named commit:

- ignored the responsible arguments (speed, mode)
The set speed/mode function must use the supplied function arguments to
work properly. With this commit we take those arguments and transfer
them to the priv-data.

- used wrong udevice pointer for getting priv data
the udevice-pointer within function argument is already the spi-bus
device, so it is wrong looking here for some parent (ocp-bus in this
case) and getting priv-pointer from there.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>


# b1d2b529 02-Jun-2018 Hannes Schmelzer <oe5hpm@oevsv.at>

spi: omap3: pre-initialize bus-speed with max. slave-speed

Otherwise the frequency is zero and the clock divider cannot be setup by
'omap3_spi_set_speed' function.

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
Reviewed-by: Jagan Teki <jagan@openedev.com>


# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>


# 63018a3e 22-Mar-2018 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

omap3: spi: Correct ti, pindir-d0-out-d1-in parsing

The ti,pindir-d0-out-d1-in property is not expected to have a value
according to the device-tree binding, so treat it as a boolean not a
uint property.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Reviewed-by: Jagan Teki <jagan@openedev.com>


# b2b41d27 14-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Fix redeclared error

omap3_spi_set_speed|mode redeclared bus symbol, fix the same.

error:
drivers/spi/omap3_spi.c: In function ‘omap3_spi_set_speed’:
drivers/spi/omap3_spi.c:650:18: error: ‘bus’ redeclared as different kind of symbol
struct udevice *bus = dev->parent;

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>


# 84807922 06-Mar-2018 Jagan Teki <jagan@amarulasolutions.com>

spi: omap3: Skip set_mode, set_speed from claim

set_mode, set_seed functions has separate function pointers
in dm_spi_ops, so use them in relevent one instead of
calling from claim_bus.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>


# 042de609 12-Nov-2017 Heinrich Schuchardt <xypron.glpk@gmx.de>

omap3: spi: the symbol for Hertz is Hz

fix typo

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a821c4af 17-May-2017 Simon Glass <sjg@chromium.org>

dm: Rename dev_addr..() functions

These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

1. dev_read_addr...() - works on devices, supports flat/live tree
2. devfdt_get_addr...() - current functions, flat tree only
3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 25eaa288 12-May-2017 Tom Rini <trini@konsulko.com>

omap: spi: Drop CONFIG_OMAP3_SPI_D0_D1_SWAPPED support

This particular quirk is not enabled in any config files today. It does
however exist and is handled correctly in device trees and via
CONFIG_DM_SPI. So we drop the symbol now and add a comment to indicate
that any (new) boards that require this quirk need to enable DM_SPI
instead.

Signed-off-by: Tom Rini <trini@konsulko.com>


# 2f542058 03-May-2017 Suniel Mahesh <suniel.spartan@gmail.com>

drivers: spi: Remove duplicate .probe method

.probe method has been assigned twice when declaring
a driver with U_BOOT_DRIVER(). Removed one of them.
Here is the last commit which had the duplicate entry:
"spi: omap3: Convert to driver model"
(sha1: 77b8d04854f486741471ad02b93b473b5b3d72f8)

Signed-off-by: Suniel Mahesh <suniel.spartan@gmail.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>


# e160f7d4 17-Jan-2017 Simon Glass <sjg@chromium.org>

dm: core: Replace of_offset with accessor

At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 5f89a15e 19-May-2016 Martin Hejnfelt <mh@newtec.dk>

omap3: Fix SPI registers on am33xx and am43xx

When the base registers are read from device tree the base is not
0x48030100 as the driver expects, but 0x48030000, resulting in
non functioning SPI. To deal with this, use same idea as how this
is done in the linux kernel (drivers/spi/spi-omap2-mcspi.c) and
add a structure with a field that is used to shift the registers
on these systems.

v2: Fixed commit subject line to correct cpu

Signed-off-by: Martin Hejnfelt <mh@newtec.dk>


# 41bccb81 15-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Fix multiple definition of 'priv'

Global definition of priv seems no-sense to use it
for non-dm case and pass the pointer to functions
which are common to both dm and non-dm.

So, fix this by removing omap3_spi_slave from non-dm
and make visible to omap3_spi_priv for both dm and non-dm.

Cc: Christophe Ricard <christophe-h.ricard@st.com>
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>


# 77b8d048 14-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Convert to driver model

After this conversion the driver will able to support both dm and non-dm
and code is more extensible like we can remove the non-dm part simply
without touching anycode if all the boards which are using this driver
become dm driven.

Cc: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
Tested-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Set priv->wordlen, Add Kconfig entry and file credit for dm conversion]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>


# 03661d85 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Make local functions as static

Attach static on local defined functions.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>


# 682c1723 01-Mar-2016 Jagan Teki <jteki@openedev.com>

spi: omap3: Move headers code inside the driver

Header file have macro's and register definition and some unneeded
function proto types which becomes tunned further in future patches
and entire driver code resides in one file for more readability.

Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Jagan Teki <jteki@openedev.com>
[Fixes on code styles, Remove omap3_spi_txrx|write|read in header]
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>


# 3963919e 17-Jan-2016 Christophe Ricard <christophe.ricard@gmail.com>

spi: omap3: Remove unused variable irqstatus in omap3_spi_txrx

Remove unused variable irqstatus in omap3_spi_txrx

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>


# 611c9ba2 01-Apr-2015 David Dueck <davidcdueck@googlemail.com>

spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when
transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

Signed-off-by: David Dueck <davidcdueck@googlemail.com>
CC: Tom Rini <trini@konsulko.com>
CC: Stefan Roese <sr@denx.de>
CC: Andy Pont <andy.pont@sdcsystems.com>
Tested-by: David Dueck <davidcdueck@googlemail.com>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>


# ce6889a9 09-Mar-2014 Vasili Galka <vvv444@gmail.com>

drivers/spi/omap3: Bug fix of premature write transfer completion

The logic determining SPI "write" transfer completion was faulty. At
certain conditions (e.g. slow SPI clock freq) the transfers were
interrupted before completion. Both EOT and TXS flags of channel
status registeer shall be checked to ensure that all data was
transferred. Tested on AM3359 chip.

Signed-off-by: Vasili Galka <vasili@visionmap.com>


# 5753d09b 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though
omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length,
and implement it in omap3_spi driver to support the full range of
possible word lengths.
This implementation is backwards compatible by defaulting to the old
behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions,
but since they are not used anywhere else, no collateral changes are required.

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>


# 54a759c8 16-Oct-2013 Nikita Kiryanov <nikita@compulab.co.il>

spi: omap3: remove semicolon from #define

Remove unnecessary semicolon from #define SPI_WAIT_TIMEOUT

Cc: Tom Rini <trini@ti.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>


# 93e14596 04-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: replace leading SPACEs by TABs

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Drop changes for PEP 4 following python tools]
Signed-off-by: Tom Rini <trini@ti.com>


# 3765b3e7 07-Oct-2013 Wolfgang Denk <wd@denx.de>

Coding Style cleanup: remove trailing white space

Signed-off-by: Wolfgang Denk <wd@denx.de>


# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>


# d3504fee 18-Mar-2013 Simon Glass <sjg@chromium.org>

spi: Use spi_alloc_slave() in each SPI driver

Rather than each driver having its own way to allocate a SPI slave,
use the new allocation function everywhere. This will make it easier
to extend the interface without breaking drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>


# cc1182be 17-Nov-2012 ajoy <akdas75@yahoo.in>

OMAP3 SPI : Fixed bugs related to SPI transfer

Added posted writes (read after writes) to effect the
change immediately for channel confiuration and channel
enable register

Disable the channel to purge receieve data in TX_ONLY
mode transfer otherwise rx data will get affected by
the next immediate RX_ONLY mode transfer

Wait for the EOT bit to be set after last byte has been
loaded to TX shift register in the the TX_ONLY mode.This
ensures TX data has been completely shifted out

Disable the channel in RX_ONLY mode before reading the
last data from RXX register to prevent the SPI slave
to transmit next word

Signed-off-by: Ajoy Kumar Das <akdas75@yahoo.in>
Cc: Tom Rini <trini@ti.com>
Cc: jacopo mondi <j.mondi@voltaelectronics.com>


# 22cbeed4 17-Oct-2012 Peter Korsgaard <peter.korsgaard@barco.com>

omap3_spi: introduce CONFIG_OMAP3_SPI_D0_D1_SWAPPED

D0/D1 Swapped or not is a board property, not anything specific to
the am33xx SoC, so add a custom define for it.

At the same time correct the bit handling for the swapped mode
(DPE0 should be cleared and SI/DPE1 set).

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>


# a4a99fff 08-Aug-2012 Tom Rini <trini@ti.com>

am335x evm: Enable support for spi0

Signed-off-by: Tom Rini <trini@ti.com>


# 4c0620bf 08-Aug-2012 Tom Rini <trini@ti.com>

am33xx: Add support, update omap3 McSPI driver

Signed-off-by: Tom Rini <trini@ti.com>


# 08b5ab07 01-Mar-2011 jacopo mondi <j.mondi@voltaelectronics.com>

omap3_spi: receive transmit mode

Implementation of receive-transmit mode for
omap3 MCSPI.

Introduces full duplex communication, needed by
some spi devices (such as enc28j60).

Signed-off-by: jacopo mondi <mondi@cs.unibo.it> <j.mondi@voltaelectronics.com>


# 53736baa 11-Dec-2010 Dirk Behme <dirk.behme@googlemail.com>

OMAP3: SPI driver

CC: Ruslan N. Araslanov <byaaka@yandex.ru>
Signed-off-by: Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>