1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /*
3 * Copyright 2021 NXP
4 *
5 */
6 #include <linux/kernel.h>
7 #include <linux/fsl/mc.h>
8
9 #include "fsl-mc-private.h"
10
fsl_mc_get_open_cmd_id(const char * type)11 static int fsl_mc_get_open_cmd_id(const char *type)
12 {
13 static const struct {
14 int cmd_id;
15 const char *type;
16 } dev_ids[] = {
17 { DPRTC_CMDID_OPEN, "dprtc" },
18 { DPRC_CMDID_OPEN, "dprc" },
19 { DPNI_CMDID_OPEN, "dpni" },
20 { DPIO_CMDID_OPEN, "dpio" },
21 { DPSW_CMDID_OPEN, "dpsw" },
22 { DPBP_CMDID_OPEN, "dpbp" },
23 { DPCON_CMDID_OPEN, "dpcon" },
24 { DPMCP_CMDID_OPEN, "dpmcp" },
25 { DPMAC_CMDID_OPEN, "dpmac" },
26 { DPSECI_CMDID_OPEN, "dpseci" },
27 { DPDMUX_CMDID_OPEN, "dpdmux" },
28 { DPDCEI_CMDID_OPEN, "dpdcei" },
29 { DPAIOP_CMDID_OPEN, "dpaiop" },
30 { DPCI_CMDID_OPEN, "dpci" },
31 { DPDMAI_CMDID_OPEN, "dpdmai" },
32 { DPDBG_CMDID_OPEN, "dpdbg" },
33 { 0, NULL }
34 };
35 int i;
36
37 for (i = 0; dev_ids[i].type; i++)
38 if (!strcmp(dev_ids[i].type, type))
39 return dev_ids[i].cmd_id;
40
41 return -1;
42 }
43
fsl_mc_obj_open(struct fsl_mc_io * mc_io,u32 cmd_flags,int obj_id,char * obj_type,u16 * token)44 int fsl_mc_obj_open(struct fsl_mc_io *mc_io,
45 u32 cmd_flags,
46 int obj_id,
47 char *obj_type,
48 u16 *token)
49 {
50 struct fsl_mc_command cmd = { 0 };
51 struct fsl_mc_obj_cmd_open *cmd_params;
52 int err = 0;
53 int cmd_id = fsl_mc_get_open_cmd_id(obj_type);
54
55 if (cmd_id == -1)
56 return -ENODEV;
57
58 /* prepare command */
59 cmd.header = mc_encode_cmd_header(cmd_id, cmd_flags, 0);
60 cmd_params = (struct fsl_mc_obj_cmd_open *)cmd.params;
61 cmd_params->obj_id = cpu_to_le32(obj_id);
62
63 /* send command to mc*/
64 err = mc_send_command(mc_io, &cmd);
65 if (err)
66 return err;
67
68 /* retrieve response parameters */
69 *token = mc_cmd_hdr_read_token(&cmd);
70
71 return err;
72 }
73 EXPORT_SYMBOL_GPL(fsl_mc_obj_open);
74
fsl_mc_obj_close(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)75 int fsl_mc_obj_close(struct fsl_mc_io *mc_io,
76 u32 cmd_flags,
77 u16 token)
78 {
79 struct fsl_mc_command cmd = { 0 };
80
81 /* prepare command */
82 cmd.header = mc_encode_cmd_header(OBJ_CMDID_CLOSE, cmd_flags,
83 token);
84
85 /* send command to mc*/
86 return mc_send_command(mc_io, &cmd);
87 }
88 EXPORT_SYMBOL_GPL(fsl_mc_obj_close);
89
fsl_mc_obj_reset(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)90 int fsl_mc_obj_reset(struct fsl_mc_io *mc_io,
91 u32 cmd_flags,
92 u16 token)
93 {
94 struct fsl_mc_command cmd = { 0 };
95
96 /* prepare command */
97 cmd.header = mc_encode_cmd_header(OBJ_CMDID_RESET, cmd_flags,
98 token);
99
100 /* send command to mc*/
101 return mc_send_command(mc_io, &cmd);
102 }
103 EXPORT_SYMBOL_GPL(fsl_mc_obj_reset);
104