Skip to content

Introduce calibration API for the MSPI subsystem #91569

Open
@natto1784

Description

@natto1784

Problem Description

Some MSPI controllers may need to be calibrated with non deterministic values. This calibration is different from the configuration that happens using the existing APIs, as these may require some mechanism to determine whether the calibration was successful or not. An example of this would be verifying the JEDEC ID for verifying correct calibration.

Proposed Change (Summary)

This proposal includes adding an API to calibrate the controller by supplying a callback mechanism to check and re-calibrate as needed. If this API is not implemented for a controller, it will simply return 0 for success as calibration is not needed. The API is intended to be used by MSPI device peripherals such as flash as well as user applications.

Proposed Change (Detailed)

Introduction of the API with following new types and symbols

/**
 * @typedef mspi_calibration_callback_t
 * @brief Define the calibration callback function signature
 *
 * @param Opaque data (void pointer)
 *
 * @retval 0 if successful.
 * @retval Negative value if unsuccessful
 */
typedef void (*mspi_calibration_callback_t)(void *calibration_callback_data);

typedef int (*mspi_api_calibrate)(const struct device *controller, mspi_calibration_callback_t cb,
				  void *cb_data);

__subsystem struct mspi_driver_api {
	mspi_api_config config;
	mspi_api_dev_config dev_config;
	mspi_api_get_channel_status get_channel_status;
	mspi_api_transceive transceive;
	mspi_api_register_callback register_callback;
	mspi_api_xip_config xip_config;
	mspi_api_scramble_config scramble_config;
	mspi_api_timing_config timing_config;
        /* NEW */
	mspi_api_calibrate calibrate;
};


/**
 * @brief Calibrate controller
 *
 * This routine provides a way for the the caller to calibrate the controller based on a callback
 * function. This function can be used to determine whether the calibration is successful and
 * recalibrate as needed.
 *
 * @param controller Pointer to the device structure for the driver instance.
 * @param cb Pointer to the callback function to determine whether calibration was successful or
 * not.
 * @param cb_data Opaque pointer to the data to be passed to the callback function
 *
 * @retval 0 If successful or unneeded
 * @retval -ENOTSUP Failed to calibrate
 */
static inline int mspi_calibrate(const struct device *controller, mspi_calibration_callback_t cb,
				 void *cb_data)
{
	const struct mspi_driver_api *api = (const struct mspi_driver_api *)controller->api;

	if (!api->calibrate) {
		return 0;
	}

	return api->calibrate(controller, cb, cb_data);
}

Dependencies

No response

Concerns and Unresolved Questions

No response

Alternatives Considered

We can add MSPI controller specific calibration code in the MSPI devices (peripherals) using compile time macros but that would be undesirable in the long run.

Metadata

Metadata

Assignees

Labels

RFCRequest For Comments: want input from the communityarea: MSPI

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions