blob: b07eff7e3ca161a32751cc014e72bae7d54ddc3e [file] [log] [blame]
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001/*
2 * Copyright (C) 2013-2015 Freescale Semiconductor
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <fsl-mc/fsl_mc_sys.h>
8#include <fsl-mc/fsl_mc_cmd.h>
9#include <fsl-mc/fsl_dpio.h>
10
11int dpio_open(struct fsl_mc_io *mc_io, int dpio_id, uint16_t *token)
12{
13 struct mc_command cmd = { 0 };
14 int err;
15
16 /* prepare command */
17 cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
18 MC_CMD_PRI_LOW, 0);
19 DPIO_CMD_OPEN(cmd, dpio_id);
20
21 /* send command to mc*/
22 err = mc_send_command(mc_io, &cmd);
23 if (err)
24 return err;
25
26 /* retrieve response parameters */
27 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
28
29 return 0;
30}
31
32int dpio_close(struct fsl_mc_io *mc_io, uint16_t token)
33{
34 struct mc_command cmd = { 0 };
35
36 /* prepare command */
37 cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
38 MC_CMD_PRI_HIGH, token);
39
40 /* send command to mc*/
41 return mc_send_command(mc_io, &cmd);
42}
43
44int dpio_enable(struct fsl_mc_io *mc_io, uint16_t token)
45{
46 struct mc_command cmd = { 0 };
47
48 /* prepare command */
49 cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
50 MC_CMD_PRI_LOW, token);
51
52 /* send command to mc*/
53 return mc_send_command(mc_io, &cmd);
54}
55
56int dpio_disable(struct fsl_mc_io *mc_io, uint16_t token)
57{
58 struct mc_command cmd = { 0 };
59
60 /* prepare command */
61 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
62 MC_CMD_PRI_LOW,
63 token);
64
65 /* send command to mc*/
66 return mc_send_command(mc_io, &cmd);
67}
68
69int dpio_reset(struct fsl_mc_io *mc_io, uint16_t token)
70{
71 struct mc_command cmd = { 0 };
72
73 /* prepare command */
74 cmd.header = mc_encode_cmd_header(DPIO_CMDID_RESET,
75 MC_CMD_PRI_LOW, token);
76
77 /* send command to mc*/
78 return mc_send_command(mc_io, &cmd);
79}
80
81int dpio_get_attributes(struct fsl_mc_io *mc_io,
82 uint16_t token,
83 struct dpio_attr *attr)
84{
85 struct mc_command cmd = { 0 };
86 int err;
87
88 /* prepare command */
89 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
90 MC_CMD_PRI_LOW,
91 token);
92
93 /* send command to mc*/
94 err = mc_send_command(mc_io, &cmd);
95 if (err)
96 return err;
97
98 /* retrieve response parameters */
99 DPIO_RSP_GET_ATTR(cmd, attr);
100
101 return 0;
102}