zephyr/include/drivers/spi/spi_k64.h
Jeff Blais 995a9ba72a arm: K64 SPI module driver
Support for Freescale/NXP K64 SPI modules, limited to:

- Master mode
- A single active set of clock and transfer attributes (CTAR0), which
includes non-adjustable delay parameters
- Tx FIFO fill and Rx FIFO drain interrupt handling
- Standard, continuous select and continuous SCK SPI transfer formats

Also, divide-by-zero code generation in this driver is prevented.
The 'volatile' attribute is added to some of the variables in the baud
rate and delay calculation functions of the K64 SPI driver in order to
prevent bad code generation by gcc toolchains for ARM seen when an
optimization setting above -O0 is used.
Specifically, a register is loaded with the constant 0 and is used as
the divisor in a following divide instruction, resulting in a
divide-by-zero exception.
This issue has been seen with gcc versions 4.8.1 (the VxWorks toolchain)
and 5.2.0 (the Zephyr SDK toolchain).

Change-Id: Ib5b2b748aad8fdfd5e8d40544e6e1abef3713abe
Signed-off-by: Jeff Blais <jeff.blais@windriver.com>
2016-03-09 15:50:16 +00:00

79 lines
2.9 KiB
C

/* spi_k64.h - Freescale K64 SPI controller driver utilities */
/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __SPI_K64_H__
#define __SPI_K64_H__
/*
* Device configuration
*
* Device-independent configuration:
* Bits [0 : 11] in the config parameter of the spi_configure() API are defined
* with the following fields.
*
* SCK polarity [ 0 ] - SCK inactive state (0 = low, 1 = high)
* SCK phase [ 1 ] - Data captured/changed on which SCK edge:
* - 0 = leading/following edges, respectively
* - 1 = following/leading edges, respectively
* loop_mode [ 2 ] - Not used/Unsupported
* transfer_mode [ 3 ] - First significant bit (0 = MSB, 1 = LSB)
* word_size [ 4 : 7 ] - Size of a data train in bits
* unused [ 8 : 11 ] - Unused word_size field bits
*
* Device-specific configuration:
* Bits [12 : 31] in the config parameter of the spi_configure() API are
* available, with the following fields defined for this device.
*
* PCS0-5 polarity [ 12 : 17 ] - Periph. Chip Select inactive state, MCR[PCSIS]
* - (0 = low, 1 = high)
* Continuous SCK [ 18 ] - Continuous serial clocking, MCR[CONT_SCKE]
* - (0 = disabled, 1 = enabled)
* Continuous PCS [ 19 ] - Continuous selection format, PUSHR[CONT]
* - (0 = disabled, 1 = enabled)
*
* Note that the number of valid PCS signals differs for each
* K64 SPI module:
* - SPI0 uses PCS0-5;
* - SPI1 uses PCS0-3;
* - SPI2 uses PCS0-1;
*/
/* PCS polarity access macros */
#define SPI_PCS_POL_MASK (0x3F << 12)
#define SPI_PCS_POL_GET(_in_) (((_in_) & SPI_PCS_POL_MASK) >> 12)
#define SPI_PCS_POL_SET(_in_) ((_in_) << 12)
/* Continuous SCK access macros */
#define SPI_CONT_SCK_MASK (0x1 << 18)
#define SPI_CONT_SCK_GET(_in_) (((_in_) & SPI_CONT_SCK_MASK) >> 18)
#define SPI_CONT_SCK_SET(_in_) ((_in_) << 18)
/* Continuous PCS access macros */
#define SPI_CONT_PCS_MASK (0x1 << 19)
#define SPI_CONT_PCS_GET(_in_) (((_in_) & SPI_CONT_PCS_MASK) >> 19)
#define SPI_CONT_PCS_SET(_in_) ((_in_) << 19)
/* K64 SPI word/frame size is limited to 16 bits, represented as: (size - 1) */
#define SPI_K64_WORD_SIZE_MAX (16)
#endif /* __SPI_K64_H__ */