dprtc.c (3eb66e91a25497065c5322b1268cbc3953642227) dprtc.c (d346c9e86d8685d7cdceddf5b2e9c4376334620c)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2016-2018 NXP
5 */
6
7#include <linux/fsl/mc.h>
8

--- 58 unchanged lines hidden (view full) ---

67{
68 struct fsl_mc_command cmd = { 0 };
69
70 cmd.header = mc_encode_cmd_header(DPRTC_CMDID_CLOSE, cmd_flags,
71 token);
72
73 return mc_send_command(mc_io, &cmd);
74}
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2016-2018 NXP
5 */
6
7#include <linux/fsl/mc.h>
8

--- 58 unchanged lines hidden (view full) ---

67{
68 struct fsl_mc_command cmd = { 0 };
69
70 cmd.header = mc_encode_cmd_header(DPRTC_CMDID_CLOSE, cmd_flags,
71 token);
72
73 return mc_send_command(mc_io, &cmd);
74}
75
76/**
77 * dprtc_set_freq_compensation() - Sets a new frequency compensation value.
78 *
79 * @mc_io: Pointer to MC portal's I/O object
80 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
81 * @token: Token of DPRTC object
82 * @freq_compensation: The new frequency compensation value to set.
83 *
84 * Return: '0' on Success; Error code otherwise.
85 */
86int dprtc_set_freq_compensation(struct fsl_mc_io *mc_io,
87 u32 cmd_flags,
88 u16 token,
89 u32 freq_compensation)
90{
91 struct dprtc_get_freq_compensation *cmd_params;
92 struct fsl_mc_command cmd = { 0 };
93
94 cmd.header = mc_encode_cmd_header(DPRTC_CMDID_SET_FREQ_COMPENSATION,
95 cmd_flags,
96 token);
97 cmd_params = (struct dprtc_get_freq_compensation *)cmd.params;
98 cmd_params->freq_compensation = cpu_to_le32(freq_compensation);
99
100 return mc_send_command(mc_io, &cmd);
101}
102
103/**
104 * dprtc_get_freq_compensation() - Retrieves the frequency compensation value
105 *
106 * @mc_io: Pointer to MC portal's I/O object
107 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
108 * @token: Token of DPRTC object
109 * @freq_compensation: Frequency compensation value
110 *
111 * Return: '0' on Success; Error code otherwise.
112 */
113int dprtc_get_freq_compensation(struct fsl_mc_io *mc_io,
114 u32 cmd_flags,
115 u16 token,
116 u32 *freq_compensation)
117{
118 struct dprtc_get_freq_compensation *rsp_params;
119 struct fsl_mc_command cmd = { 0 };
120 int err;
121
122 cmd.header = mc_encode_cmd_header(DPRTC_CMDID_GET_FREQ_COMPENSATION,
123 cmd_flags,
124 token);
125
126 err = mc_send_command(mc_io, &cmd);
127 if (err)
128 return err;
129
130 rsp_params = (struct dprtc_get_freq_compensation *)cmd.params;
131 *freq_compensation = le32_to_cpu(rsp_params->freq_compensation);
132
133 return 0;
134}
135
136/**
137 * dprtc_get_time() - Returns the current RTC time.
138 *
139 * @mc_io: Pointer to MC portal's I/O object
140 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
141 * @token: Token of DPRTC object
142 * @time: Current RTC time.
143 *
144 * Return: '0' on Success; Error code otherwise.
145 */
146int dprtc_get_time(struct fsl_mc_io *mc_io,
147 u32 cmd_flags,
148 u16 token,
149 uint64_t *time)
150{
151 struct dprtc_time *rsp_params;
152 struct fsl_mc_command cmd = { 0 };
153 int err;
154
155 cmd.header = mc_encode_cmd_header(DPRTC_CMDID_GET_TIME,
156 cmd_flags,
157 token);
158
159 err = mc_send_command(mc_io, &cmd);
160 if (err)
161 return err;
162
163 rsp_params = (struct dprtc_time *)cmd.params;
164 *time = le64_to_cpu(rsp_params->time);
165
166 return 0;
167}
168
169/**
170 * dprtc_set_time() - Updates current RTC time.
171 *
172 * @mc_io: Pointer to MC portal's I/O object
173 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
174 * @token: Token of DPRTC object
175 * @time: New RTC time.
176 *
177 * Return: '0' on Success; Error code otherwise.
178 */
179int dprtc_set_time(struct fsl_mc_io *mc_io,
180 u32 cmd_flags,
181 u16 token,
182 uint64_t time)
183{
184 struct dprtc_time *cmd_params;
185 struct fsl_mc_command cmd = { 0 };
186
187 cmd.header = mc_encode_cmd_header(DPRTC_CMDID_SET_TIME,
188 cmd_flags,
189 token);
190 cmd_params = (struct dprtc_time *)cmd.params;
191 cmd_params->time = cpu_to_le64(time);
192
193 return mc_send_command(mc_io, &cmd);
194}