GNU Linux-libre 4.19.286-gnu1
[releases.git] / drivers / staging / fsl-dpaa2 / rtc / dprtc.c
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
9 #include "dprtc.h"
10 #include "dprtc-cmd.h"
11
12 /**
13  * dprtc_open() - Open a control session for the specified object.
14  * @mc_io:      Pointer to MC portal's I/O object
15  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
16  * @dprtc_id:   DPRTC unique ID
17  * @token:      Returned token; use in subsequent API calls
18  *
19  * This function can be used to open a control session for an
20  * already created object; an object may have been declared in
21  * the DPL or by calling the dprtc_create function.
22  * This function returns a unique authentication token,
23  * associated with the specific object ID and the specific MC
24  * portal; this token must be used in all subsequent commands for
25  * this specific object
26  *
27  * Return:      '0' on Success; Error code otherwise.
28  */
29 int dprtc_open(struct fsl_mc_io *mc_io,
30                u32 cmd_flags,
31                int dprtc_id,
32                u16 *token)
33 {
34         struct dprtc_cmd_open *cmd_params;
35         struct fsl_mc_command cmd = { 0 };
36         int err;
37
38         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_OPEN,
39                                           cmd_flags,
40                                           0);
41         cmd_params = (struct dprtc_cmd_open *)cmd.params;
42         cmd_params->dprtc_id = cpu_to_le32(dprtc_id);
43
44         err = mc_send_command(mc_io, &cmd);
45         if (err)
46                 return err;
47
48         *token = mc_cmd_hdr_read_token(&cmd);
49
50         return 0;
51 }
52
53 /**
54  * dprtc_close() - Close the control session of the object
55  * @mc_io:      Pointer to MC portal's I/O object
56  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
57  * @token:      Token of DPRTC object
58  *
59  * After this function is called, no further operations are
60  * allowed on the object without opening a new control session.
61  *
62  * Return:      '0' on Success; Error code otherwise.
63  */
64 int dprtc_close(struct fsl_mc_io *mc_io,
65                 u32 cmd_flags,
66                 u16 token)
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_create() - Create the DPRTC object.
78  * @mc_io:      Pointer to MC portal's I/O object
79  * @dprc_token: Parent container token; '0' for default container
80  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
81  * @cfg:        Configuration structure
82  * @obj_id:     Returned object id
83  *
84  * Create the DPRTC object, allocate required resources and
85  * perform required initialization.
86  *
87  * The function accepts an authentication token of a parent
88  * container that this object should be assigned to. The token
89  * can be '0' so the object will be assigned to the default container.
90  * The newly created object can be opened with the returned
91  * object id and using the container's associated tokens and MC portals.
92  *
93  * Return:      '0' on Success; Error code otherwise.
94  */
95 int dprtc_create(struct fsl_mc_io *mc_io,
96                  u16 dprc_token,
97                  u32 cmd_flags,
98                  const struct dprtc_cfg *cfg,
99                  u32 *obj_id)
100 {
101         struct fsl_mc_command cmd = { 0 };
102         int err;
103
104         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_CREATE,
105                                           cmd_flags,
106                                           dprc_token);
107
108         err = mc_send_command(mc_io, &cmd);
109         if (err)
110                 return err;
111
112         *obj_id = mc_cmd_read_object_id(&cmd);
113
114         return 0;
115 }
116
117 /**
118  * dprtc_destroy() - Destroy the DPRTC object and release all its resources.
119  * @mc_io:      Pointer to MC portal's I/O object
120  * @dprc_token: Parent container token; '0' for default container
121  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
122  * @object_id:  The object id; it must be a valid id within the container that
123  * created this object;
124  *
125  * The function accepts the authentication token of the parent container that
126  * created the object (not the one that currently owns the object). The object
127  * is searched within parent using the provided 'object_id'.
128  * All tokens to the object must be closed before calling destroy.
129  *
130  * Return:      '0' on Success; error code otherwise.
131  */
132 int dprtc_destroy(struct fsl_mc_io *mc_io,
133                   u16 dprc_token,
134                   u32 cmd_flags,
135                   u32 object_id)
136 {
137         struct dprtc_cmd_destroy *cmd_params;
138         struct fsl_mc_command cmd = { 0 };
139
140         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_DESTROY,
141                                           cmd_flags,
142                                           dprc_token);
143         cmd_params = (struct dprtc_cmd_destroy *)cmd.params;
144         cmd_params->object_id = cpu_to_le32(object_id);
145
146         return mc_send_command(mc_io, &cmd);
147 }
148
149 /**
150  * dprtc_enable() - Enable the DPRTC.
151  * @mc_io:      Pointer to MC portal's I/O object
152  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
153  * @token:      Token of DPRTC object
154  *
155  * Return:      '0' on Success; Error code otherwise.
156  */
157 int dprtc_enable(struct fsl_mc_io *mc_io,
158                  u32 cmd_flags,
159                  u16 token)
160 {
161         struct fsl_mc_command cmd = { 0 };
162
163         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_ENABLE, cmd_flags,
164                                           token);
165
166         return mc_send_command(mc_io, &cmd);
167 }
168
169 /**
170  * dprtc_disable() - Disable the DPRTC.
171  * @mc_io:      Pointer to MC portal's I/O object
172  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
173  * @token:      Token of DPRTC object
174  *
175  * Return:      '0' on Success; Error code otherwise.
176  */
177 int dprtc_disable(struct fsl_mc_io *mc_io,
178                   u32 cmd_flags,
179                   u16 token)
180 {
181         struct fsl_mc_command cmd = { 0 };
182
183         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_DISABLE,
184                                           cmd_flags,
185                                           token);
186
187         return mc_send_command(mc_io, &cmd);
188 }
189
190 /**
191  * dprtc_is_enabled() - Check if the DPRTC is enabled.
192  * @mc_io:      Pointer to MC portal's I/O object
193  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
194  * @token:      Token of DPRTC object
195  * @en:         Returns '1' if object is enabled; '0' otherwise
196  *
197  * Return:      '0' on Success; Error code otherwise.
198  */
199 int dprtc_is_enabled(struct fsl_mc_io *mc_io,
200                      u32 cmd_flags,
201                      u16 token,
202                      int *en)
203 {
204         struct dprtc_rsp_is_enabled *rsp_params;
205         struct fsl_mc_command cmd = { 0 };
206         int err;
207
208         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_IS_ENABLED, cmd_flags,
209                                           token);
210
211         err = mc_send_command(mc_io, &cmd);
212         if (err)
213                 return err;
214
215         rsp_params = (struct dprtc_rsp_is_enabled *)cmd.params;
216         *en = dprtc_get_field(rsp_params->en, ENABLE);
217
218         return 0;
219 }
220
221 /**
222  * dprtc_reset() - Reset the DPRTC, returns the object to initial state.
223  * @mc_io:      Pointer to MC portal's I/O object
224  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
225  * @token:      Token of DPRTC object
226  *
227  * Return:      '0' on Success; Error code otherwise.
228  */
229 int dprtc_reset(struct fsl_mc_io *mc_io,
230                 u32 cmd_flags,
231                 u16 token)
232 {
233         struct fsl_mc_command cmd = { 0 };
234
235         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_RESET,
236                                           cmd_flags,
237                                           token);
238
239         return mc_send_command(mc_io, &cmd);
240 }
241
242 /**
243  * dprtc_set_irq_enable() - Set overall interrupt state.
244  * @mc_io:      Pointer to MC portal's I/O object
245  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
246  * @token:      Token of DPRTC object
247  * @irq_index:  The interrupt index to configure
248  * @en:         Interrupt state - enable = 1, disable = 0
249  *
250  * Allows GPP software to control when interrupts are generated.
251  * Each interrupt can have up to 32 causes.  The enable/disable control's the
252  * overall interrupt state. if the interrupt is disabled no causes will cause
253  * an interrupt.
254  *
255  * Return:      '0' on Success; Error code otherwise.
256  */
257 int dprtc_set_irq_enable(struct fsl_mc_io *mc_io,
258                          u32 cmd_flags,
259                          u16 token,
260                          u8 irq_index,
261                          u8 en)
262 {
263         struct dprtc_cmd_set_irq_enable *cmd_params;
264         struct fsl_mc_command cmd = { 0 };
265
266         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_SET_IRQ_ENABLE,
267                                           cmd_flags,
268                                           token);
269         cmd_params = (struct dprtc_cmd_set_irq_enable *)cmd.params;
270         cmd_params->irq_index = irq_index;
271         cmd_params->en = en;
272
273         return mc_send_command(mc_io, &cmd);
274 }
275
276 /**
277  * dprtc_get_irq_enable() - Get overall interrupt state
278  * @mc_io:      Pointer to MC portal's I/O object
279  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
280  * @token:      Token of DPRTC object
281  * @irq_index:  The interrupt index to configure
282  * @en:         Returned interrupt state - enable = 1, disable = 0
283  *
284  * Return:      '0' on Success; Error code otherwise.
285  */
286 int dprtc_get_irq_enable(struct fsl_mc_io *mc_io,
287                          u32 cmd_flags,
288                          u16 token,
289                          u8 irq_index,
290                          u8 *en)
291 {
292         struct dprtc_rsp_get_irq_enable *rsp_params;
293         struct dprtc_cmd_get_irq *cmd_params;
294         struct fsl_mc_command cmd = { 0 };
295         int err;
296
297         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_GET_IRQ_ENABLE,
298                                           cmd_flags,
299                                           token);
300         cmd_params = (struct dprtc_cmd_get_irq *)cmd.params;
301         cmd_params->irq_index = irq_index;
302
303         err = mc_send_command(mc_io, &cmd);
304         if (err)
305                 return err;
306
307         rsp_params = (struct dprtc_rsp_get_irq_enable *)cmd.params;
308         *en = rsp_params->en;
309
310         return 0;
311 }
312
313 /**
314  * dprtc_set_irq_mask() - Set interrupt mask.
315  * @mc_io:      Pointer to MC portal's I/O object
316  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
317  * @token:      Token of DPRTC object
318  * @irq_index:  The interrupt index to configure
319  * @mask:       Event mask to trigger interrupt;
320  *              each bit:
321  *                      0 = ignore event
322  *                      1 = consider event for asserting IRQ
323  *
324  * Every interrupt can have up to 32 causes and the interrupt model supports
325  * masking/unmasking each cause independently
326  *
327  * Return:      '0' on Success; Error code otherwise.
328  */
329 int dprtc_set_irq_mask(struct fsl_mc_io *mc_io,
330                        u32 cmd_flags,
331                        u16 token,
332                        u8 irq_index,
333                        u32 mask)
334 {
335         struct dprtc_cmd_set_irq_mask *cmd_params;
336         struct fsl_mc_command cmd = { 0 };
337
338         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_SET_IRQ_MASK,
339                                           cmd_flags,
340                                           token);
341         cmd_params = (struct dprtc_cmd_set_irq_mask *)cmd.params;
342         cmd_params->mask = cpu_to_le32(mask);
343         cmd_params->irq_index = irq_index;
344
345         return mc_send_command(mc_io, &cmd);
346 }
347
348 /**
349  * dprtc_get_irq_mask() - Get interrupt mask.
350  * @mc_io:      Pointer to MC portal's I/O object
351  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
352  * @token:      Token of DPRTC object
353  * @irq_index:  The interrupt index to configure
354  * @mask:       Returned event mask to trigger interrupt
355  *
356  * Every interrupt can have up to 32 causes and the interrupt model supports
357  * masking/unmasking each cause independently
358  *
359  * Return:      '0' on Success; Error code otherwise.
360  */
361 int dprtc_get_irq_mask(struct fsl_mc_io *mc_io,
362                        u32 cmd_flags,
363                        u16 token,
364                        u8 irq_index,
365                        u32 *mask)
366 {
367         struct dprtc_rsp_get_irq_mask *rsp_params;
368         struct dprtc_cmd_get_irq *cmd_params;
369         struct fsl_mc_command cmd = { 0 };
370         int err;
371
372         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_GET_IRQ_MASK,
373                                           cmd_flags,
374                                           token);
375         cmd_params = (struct dprtc_cmd_get_irq *)cmd.params;
376         cmd_params->irq_index = irq_index;
377
378         err = mc_send_command(mc_io, &cmd);
379         if (err)
380                 return err;
381
382         rsp_params = (struct dprtc_rsp_get_irq_mask *)cmd.params;
383         *mask = le32_to_cpu(rsp_params->mask);
384
385         return 0;
386 }
387
388 /**
389  * dprtc_get_irq_status() - Get the current status of any pending interrupts.
390  *
391  * @mc_io:      Pointer to MC portal's I/O object
392  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
393  * @token:      Token of DPRTC object
394  * @irq_index:  The interrupt index to configure
395  * @status:     Returned interrupts status - one bit per cause:
396  *                      0 = no interrupt pending
397  *                      1 = interrupt pending
398  *
399  * Return:      '0' on Success; Error code otherwise.
400  */
401 int dprtc_get_irq_status(struct fsl_mc_io *mc_io,
402                          u32 cmd_flags,
403                          u16 token,
404                          u8 irq_index,
405                          u32 *status)
406 {
407         struct dprtc_cmd_get_irq_status *cmd_params;
408         struct dprtc_rsp_get_irq_status *rsp_params;
409         struct fsl_mc_command cmd = { 0 };
410         int err;
411
412         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_GET_IRQ_STATUS,
413                                           cmd_flags,
414                                           token);
415         cmd_params = (struct dprtc_cmd_get_irq_status *)cmd.params;
416         cmd_params->status = cpu_to_le32(*status);
417         cmd_params->irq_index = irq_index;
418
419         err = mc_send_command(mc_io, &cmd);
420         if (err)
421                 return err;
422
423         rsp_params = (struct dprtc_rsp_get_irq_status *)cmd.params;
424         *status = le32_to_cpu(rsp_params->status);
425
426         return 0;
427 }
428
429 /**
430  * dprtc_clear_irq_status() - Clear a pending interrupt's status
431  *
432  * @mc_io:      Pointer to MC portal's I/O object
433  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
434  * @token:      Token of DPRTC object
435  * @irq_index:  The interrupt index to configure
436  * @status:     Bits to clear (W1C) - one bit per cause:
437  *                      0 = don't change
438  *                      1 = clear status bit
439  *
440  * Return:      '0' on Success; Error code otherwise.
441  */
442 int dprtc_clear_irq_status(struct fsl_mc_io *mc_io,
443                            u32 cmd_flags,
444                            u16 token,
445                            u8 irq_index,
446                            u32 status)
447 {
448         struct dprtc_cmd_clear_irq_status *cmd_params;
449         struct fsl_mc_command cmd = { 0 };
450
451         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_CLEAR_IRQ_STATUS,
452                                           cmd_flags,
453                                           token);
454         cmd_params = (struct dprtc_cmd_clear_irq_status *)cmd.params;
455         cmd_params->irq_index = irq_index;
456         cmd_params->status = cpu_to_le32(status);
457
458         return mc_send_command(mc_io, &cmd);
459 }
460
461 /**
462  * dprtc_get_attributes - Retrieve DPRTC attributes.
463  *
464  * @mc_io:      Pointer to MC portal's I/O object
465  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
466  * @token:      Token of DPRTC object
467  * @attr:       Returned object's attributes
468  *
469  * Return:      '0' on Success; Error code otherwise.
470  */
471 int dprtc_get_attributes(struct fsl_mc_io *mc_io,
472                          u32 cmd_flags,
473                          u16 token,
474                          struct dprtc_attr *attr)
475 {
476         struct dprtc_rsp_get_attributes *rsp_params;
477         struct fsl_mc_command cmd = { 0 };
478         int err;
479
480         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_GET_ATTR,
481                                           cmd_flags,
482                                           token);
483
484         err = mc_send_command(mc_io, &cmd);
485         if (err)
486                 return err;
487
488         rsp_params = (struct dprtc_rsp_get_attributes *)cmd.params;
489         attr->id = le32_to_cpu(rsp_params->id);
490
491         return 0;
492 }
493
494 /**
495  * dprtc_set_clock_offset() - Sets the clock's offset
496  * (usually relative to another clock).
497  *
498  * @mc_io:      Pointer to MC portal's I/O object
499  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
500  * @token:      Token of DPRTC object
501  * @offset:     New clock offset (in nanoseconds).
502  *
503  * Return:      '0' on Success; Error code otherwise.
504  */
505 int dprtc_set_clock_offset(struct fsl_mc_io *mc_io,
506                            u32 cmd_flags,
507                            u16 token,
508                            int64_t offset)
509 {
510         struct dprtc_cmd_set_clock_offset *cmd_params;
511         struct fsl_mc_command cmd = { 0 };
512
513         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_SET_CLOCK_OFFSET,
514                                           cmd_flags,
515                                           token);
516         cmd_params = (struct dprtc_cmd_set_clock_offset *)cmd.params;
517         cmd_params->offset = cpu_to_le64(offset);
518
519         return mc_send_command(mc_io, &cmd);
520 }
521
522 /**
523  * dprtc_set_freq_compensation() - Sets a new frequency compensation value.
524  *
525  * @mc_io:              Pointer to MC portal's I/O object
526  * @cmd_flags:          Command flags; one or more of 'MC_CMD_FLAG_'
527  * @token:              Token of DPRTC object
528  * @freq_compensation:  The new frequency compensation value to set.
529  *
530  * Return:      '0' on Success; Error code otherwise.
531  */
532 int dprtc_set_freq_compensation(struct fsl_mc_io *mc_io,
533                                 u32 cmd_flags,
534                                 u16 token,
535                                 u32 freq_compensation)
536 {
537         struct dprtc_get_freq_compensation *cmd_params;
538         struct fsl_mc_command cmd = { 0 };
539
540         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_SET_FREQ_COMPENSATION,
541                                           cmd_flags,
542                                           token);
543         cmd_params = (struct dprtc_get_freq_compensation *)cmd.params;
544         cmd_params->freq_compensation = cpu_to_le32(freq_compensation);
545
546         return mc_send_command(mc_io, &cmd);
547 }
548
549 /**
550  * dprtc_get_freq_compensation() - Retrieves the frequency compensation value
551  *
552  * @mc_io:              Pointer to MC portal's I/O object
553  * @cmd_flags:          Command flags; one or more of 'MC_CMD_FLAG_'
554  * @token:              Token of DPRTC object
555  * @freq_compensation:  Frequency compensation value
556  *
557  * Return:      '0' on Success; Error code otherwise.
558  */
559 int dprtc_get_freq_compensation(struct fsl_mc_io *mc_io,
560                                 u32 cmd_flags,
561                                 u16 token,
562                                 u32 *freq_compensation)
563 {
564         struct dprtc_get_freq_compensation *rsp_params;
565         struct fsl_mc_command cmd = { 0 };
566         int err;
567
568         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_GET_FREQ_COMPENSATION,
569                                           cmd_flags,
570                                           token);
571
572         err = mc_send_command(mc_io, &cmd);
573         if (err)
574                 return err;
575
576         rsp_params = (struct dprtc_get_freq_compensation *)cmd.params;
577         *freq_compensation = le32_to_cpu(rsp_params->freq_compensation);
578
579         return 0;
580 }
581
582 /**
583  * dprtc_get_time() - Returns the current RTC time.
584  *
585  * @mc_io:      Pointer to MC portal's I/O object
586  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
587  * @token:      Token of DPRTC object
588  * @time:       Current RTC time.
589  *
590  * Return:      '0' on Success; Error code otherwise.
591  */
592 int dprtc_get_time(struct fsl_mc_io *mc_io,
593                    u32 cmd_flags,
594                    u16 token,
595                    uint64_t *time)
596 {
597         struct dprtc_time *rsp_params;
598         struct fsl_mc_command cmd = { 0 };
599         int err;
600
601         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_GET_TIME,
602                                           cmd_flags,
603                                           token);
604
605         err = mc_send_command(mc_io, &cmd);
606         if (err)
607                 return err;
608
609         rsp_params = (struct dprtc_time *)cmd.params;
610         *time = le64_to_cpu(rsp_params->time);
611
612         return 0;
613 }
614
615 /**
616  * dprtc_set_time() - Updates current RTC time.
617  *
618  * @mc_io:      Pointer to MC portal's I/O object
619  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
620  * @token:      Token of DPRTC object
621  * @time:       New RTC time.
622  *
623  * Return:      '0' on Success; Error code otherwise.
624  */
625 int dprtc_set_time(struct fsl_mc_io *mc_io,
626                    u32 cmd_flags,
627                    u16 token,
628                    uint64_t time)
629 {
630         struct dprtc_time *cmd_params;
631         struct fsl_mc_command cmd = { 0 };
632
633         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_SET_TIME,
634                                           cmd_flags,
635                                           token);
636         cmd_params = (struct dprtc_time *)cmd.params;
637         cmd_params->time = cpu_to_le64(time);
638
639         return mc_send_command(mc_io, &cmd);
640 }
641
642 /**
643  * dprtc_set_alarm() - Defines and sets alarm.
644  *
645  * @mc_io:      Pointer to MC portal's I/O object
646  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
647  * @token:      Token of DPRTC object
648  * @time:       In nanoseconds, the time when the alarm
649  *                      should go off - must be a multiple of
650  *                      1 microsecond
651  *
652  * Return:      '0' on Success; Error code otherwise.
653  */
654 int dprtc_set_alarm(struct fsl_mc_io *mc_io,
655                     u32 cmd_flags,
656                     u16 token, uint64_t time)
657 {
658         struct dprtc_time *cmd_params;
659         struct fsl_mc_command cmd = { 0 };
660
661         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_SET_ALARM,
662                                           cmd_flags,
663                                           token);
664         cmd_params = (struct dprtc_time *)cmd.params;
665         cmd_params->time = cpu_to_le64(time);
666
667         return mc_send_command(mc_io, &cmd);
668 }
669
670 /**
671  * dprtc_get_api_version() - Get Data Path Real Time Counter API version
672  * @mc_io:      Pointer to MC portal's I/O object
673  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
674  * @major_ver:  Major version of data path real time counter API
675  * @minor_ver:  Minor version of data path real time counter API
676  *
677  * Return:  '0' on Success; Error code otherwise.
678  */
679 int dprtc_get_api_version(struct fsl_mc_io *mc_io,
680                           u32 cmd_flags,
681                           u16 *major_ver,
682                           u16 *minor_ver)
683 {
684         struct dprtc_rsp_get_api_version *rsp_params;
685         struct fsl_mc_command cmd = { 0 };
686         int err;
687
688         cmd.header = mc_encode_cmd_header(DPRTC_CMDID_GET_API_VERSION,
689                                           cmd_flags,
690                                           0);
691
692         err = mc_send_command(mc_io, &cmd);
693         if (err)
694                 return err;
695
696         rsp_params = (struct dprtc_rsp_get_api_version *)cmd.params;
697         *major_ver = le16_to_cpu(rsp_params->major);
698         *minor_ver = le16_to_cpu(rsp_params->minor);
699
700         return 0;
701 }