arch/mips/cavium-octeon/executive/cvmx-spi.c

Source file repositories/reference/linux-study-clean/arch/mips/cavium-octeon/executive/cvmx-spi.c

File Facts

System
Linux kernel
Corpus path
arch/mips/cavium-octeon/executive/cvmx-spi.c
Extension
.c
Size
22046 bytes
Lines
669
Domain
Architecture Layer
Bucket
arch/mips
Inferred role
Architecture Layer: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

if (function_p) {		\
			res = function_p(args); \
			if (res)		\
				return res;	\
		}				\
	} while (0)

#if CVMX_ENABLE_DEBUG_PRINTS
static const char *modes[] =
    { "UNKNOWN", "TX Halfplex", "Rx Halfplex", "Duplex" };
#endif

/* Default callbacks, can be overridden
 *  using cvmx_spi_get_callbacks/cvmx_spi_set_callbacks
 */
static cvmx_spi_callbacks_t cvmx_spi_callbacks = {
	.reset_cb = cvmx_spi_reset_cb,
	.calendar_setup_cb = cvmx_spi_calendar_setup_cb,
	.clock_detect_cb = cvmx_spi_clock_detect_cb,
	.training_cb = cvmx_spi_training_cb,
	.calendar_sync_cb = cvmx_spi_calendar_sync_cb,
	.interface_up_cb = cvmx_spi_interface_up_cb
};

/*
 * Get current SPI4 initialization callbacks
 *
 * @callbacks:	Pointer to the callbacks structure.to fill
 *
 * Returns Pointer to cvmx_spi_callbacks_t structure.
 */
void cvmx_spi_get_callbacks(cvmx_spi_callbacks_t *callbacks)
{
	memcpy(callbacks, &cvmx_spi_callbacks, sizeof(cvmx_spi_callbacks));
}

/*
 * Set new SPI4 initialization callbacks
 *
 * @new_callbacks:  Pointer to an updated callbacks structure.
 */
void cvmx_spi_set_callbacks(cvmx_spi_callbacks_t *new_callbacks)
{
	memcpy(&cvmx_spi_callbacks, new_callbacks, sizeof(cvmx_spi_callbacks));
}

/*
 * Initialize and start the SPI interface.
 *
 * @interface: The identifier of the packet interface to configure and
 *		    use as a SPI interface.
 * @mode:      The operating mode for the SPI interface. The interface
 *		    can operate as a full duplex (both Tx and Rx data paths
 *		    active) or as a halfplex (either the Tx data path is
 *		    active or the Rx data path is active, but not both).
 * @timeout:   Timeout to wait for clock synchronization in seconds
 * @num_ports: Number of SPI ports to configure
 *
 * Returns Zero on success, negative of failure.
 */
int cvmx_spi_start_interface(int interface, cvmx_spi_mode_t mode, int timeout,
			     int num_ports)
{
	int res = -1;

	if (!(OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX)))
		return res;

	/* Callback to perform SPI4 reset */
	INVOKE_CB(cvmx_spi_callbacks.reset_cb, interface, mode);

	/* Callback to perform calendar setup */
	INVOKE_CB(cvmx_spi_callbacks.calendar_setup_cb, interface, mode,
		  num_ports);

	/* Callback to perform clock detection */
	INVOKE_CB(cvmx_spi_callbacks.clock_detect_cb, interface, mode, timeout);

	/* Callback to perform SPI4 link training */
	INVOKE_CB(cvmx_spi_callbacks.training_cb, interface, mode, timeout);

	/* Callback to perform calendar sync */
	INVOKE_CB(cvmx_spi_callbacks.calendar_sync_cb, interface, mode,
		  timeout);

	/* Callback to handle interface coming up */
	INVOKE_CB(cvmx_spi_callbacks.interface_up_cb, interface, mode);

	return res;
}

Annotation

Implementation Notes