blob: 561969bb511eee17a1af26bf81d5abada7c72a08 [file] [log] [blame]
Paul Walmsley21325b252012-10-21 01:01:12 -06001/*
2 * OMAP2+ common Clock Management (CM) IP block functions
3 *
4 * Copyright (C) 2012 Texas Instruments, Inc.
5 * Paul Walmsley <paul@pwsan.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * XXX This code should eventually be moved to a CM driver.
12 */
13
14#include <linux/kernel.h>
15#include <linux/init.h>
16
17#include "cm2xxx.h"
18#include "cm3xxx.h"
19#include "cm44xx.h"
20
21/*
22 * cm_ll_data: function pointers to SoC-specific implementations of
23 * common CM functions
24 */
25static struct cm_ll_data null_cm_ll_data;
26static struct cm_ll_data *cm_ll_data = &null_cm_ll_data;
27
28/**
Paul Walmsleyc4ceedc2012-10-29 20:56:29 -060029 * cm_split_idlest_reg - split CM_IDLEST reg addr into its components
30 * @idlest_reg: CM_IDLEST* virtual address
31 * @prcm_inst: pointer to an s16 to return the PRCM instance offset
32 * @idlest_reg_id: pointer to a u8 to return the CM_IDLESTx register ID
33 *
34 * Given an absolute CM_IDLEST register address @idlest_reg, passes
35 * the PRCM instance offset and IDLEST register ID back to the caller
36 * via the @prcm_inst and @idlest_reg_id. Returns -EINVAL upon error,
37 * or 0 upon success. XXX This function is only needed until absolute
38 * register addresses are removed from the OMAP struct clk records.
39 */
40int cm_split_idlest_reg(void __iomem *idlest_reg, s16 *prcm_inst,
41 u8 *idlest_reg_id)
42{
43 if (!cm_ll_data->split_idlest_reg) {
44 WARN_ONCE(1, "cm: %s: no low-level function defined\n",
45 __func__);
46 return -EINVAL;
47 }
48
49 return cm_ll_data->split_idlest_reg(idlest_reg, prcm_inst,
50 idlest_reg_id);
51}
52
53/**
54 * cm_wait_module_ready - wait for a module to leave idle or standby
55 * @prcm_mod: PRCM module offset
56 * @idlest_id: CM_IDLESTx register ID (i.e., x = 1, 2, 3)
57 * @idlest_shift: shift of the bit in the CM_IDLEST* register to check
58 *
59 * Wait for the PRCM to indicate that the module identified by
60 * (@prcm_mod, @idlest_id, @idlest_shift) is clocked. Return 0 upon
61 * success, -EBUSY if the module doesn't enable in time, or -EINVAL if
62 * no per-SoC wait_module_ready() function pointer has been registered
63 * or if the idlest register is unknown on the SoC.
64 */
65int cm_wait_module_ready(s16 prcm_mod, u8 idlest_id, u8 idlest_shift)
66{
67 if (!cm_ll_data->wait_module_ready) {
68 WARN_ONCE(1, "cm: %s: no low-level function defined\n",
69 __func__);
70 return -EINVAL;
71 }
72
73 return cm_ll_data->wait_module_ready(prcm_mod, idlest_id, idlest_shift);
74}
75
76/**
Paul Walmsley21325b252012-10-21 01:01:12 -060077 * cm_register - register per-SoC low-level data with the CM
78 * @cld: low-level per-SoC OMAP CM data & function pointers to register
79 *
80 * Register per-SoC low-level OMAP CM data and function pointers with
81 * the OMAP CM common interface. The caller must keep the data
82 * pointed to by @cld valid until it calls cm_unregister() and
83 * it returns successfully. Returns 0 upon success, -EINVAL if @cld
84 * is NULL, or -EEXIST if cm_register() has already been called
85 * without an intervening cm_unregister().
86 */
87int cm_register(struct cm_ll_data *cld)
88{
89 if (!cld)
90 return -EINVAL;
91
92 if (cm_ll_data != &null_cm_ll_data)
93 return -EEXIST;
94
95 cm_ll_data = cld;
96
97 return 0;
98}
99
100/**
101 * cm_unregister - unregister per-SoC low-level data & function pointers
102 * @cld: low-level per-SoC OMAP CM data & function pointers to unregister
103 *
104 * Unregister per-SoC low-level OMAP CM data and function pointers
105 * that were previously registered with cm_register(). The
106 * caller may not destroy any of the data pointed to by @cld until
107 * this function returns successfully. Returns 0 upon success, or
108 * -EINVAL if @cld is NULL or if @cld does not match the struct
109 * cm_ll_data * previously registered by cm_register().
110 */
111int cm_unregister(struct cm_ll_data *cld)
112{
113 if (!cld || cm_ll_data != cld)
114 return -EINVAL;
115
116 cm_ll_data = &null_cm_ll_data;
117
118 return 0;
119}