^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright 2013-2016 Freescale Semiconductor Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/fsl/mc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "fsl-mc-private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * dpmcp_open() - Open a control session for the specified object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * @mc_io: Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * @dpmcp_id: DPMCP unique ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * @token: Returned token; use in subsequent API calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * This function can be used to open a control session for an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * already created object; an object may have been declared in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * the DPL or by calling the dpmcp_create function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * This function returns a unique authentication token,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * associated with the specific object ID and the specific MC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * portal; this token must be used in all subsequent commands for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * this specific object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Return: '0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int dpmcp_open(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int dpmcp_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u16 *token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct dpmcp_cmd_open *cmd_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) cmd_flags, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) cmd_params = (struct dpmcp_cmd_open *)cmd.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) cmd_params->dpmcp_id = cpu_to_le32(dpmcp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) err = mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* retrieve response parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *token = mc_cmd_hdr_read_token(&cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * dpmcp_close() - Close the control session of the object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * @mc_io: Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @token: Token of DPMCP object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * After this function is called, no further operations are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * allowed on the object without opening a new control session.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * Return: '0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int dpmcp_close(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u16 token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * @mc_io: Pointer to MC portal's I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * @token: Token of DPMCP object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * Return: '0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int dpmcp_reset(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u32 cmd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u16 token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct fsl_mc_command cmd = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* prepare command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) cmd_flags, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* send command to mc*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return mc_send_command(mc_io, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }