This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / ppc / ocp / ocp.c
1 /*
2  * ocp.c
3  *
4  *      The is drived from pci.c
5  *
6  *      Current Maintainer
7  *      Armin Kuster akuster@dslextreme.com
8  *      Jan, 2002
9  *
10  *
11  *
12  * This program is free software; you can redistribute  it and/or modify it
13  *  under  the terms of  the GNU General  Public License as published by the
14  *  Free Software Foundation;  either version 2 of the  License, or (at your
15  *  option) any later version.
16  *
17  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR   IMPLIED
18  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
19  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
20  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT,  INDIRECT,
21  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
23  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
25  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  *  You should have received a copy of the  GNU General Public License along
29  *  with this program; if not, write  to the Free Software Foundation, Inc.,
30  *  675 Mass Ave, Cambridge, MA 02139, USA.
31  */
32
33 #include <linux/list.h>
34 #include <linux/init.h>
35 #include <linux/module.h>
36 #include <linux/config.h>
37 #include <linux/stddef.h>
38 #include <linux/slab.h>
39 #include <linux/types.h>
40 #include <asm/io.h>
41 #include <asm/ocp.h>
42 #include <asm/errno.h>
43
44 /**
45  * ocp_get_num - This determines how many OCP devices of a given
46  * device are registered
47  * @device: OCP device such as HOST, PCI, GPT, UART, OPB, IIC, GPIO, EMAC, ZMII,
48  *
49  * The routine returns the number that devices which is registered
50  */
51 unsigned int ocp_get_num(unsigned int device)
52 {
53         unsigned int count = 0;
54         struct ocp_device *ocp;
55         struct list_head *ocp_l;
56
57         list_for_each(ocp_l, &ocp_devices) {
58                 ocp = list_entry(ocp_l, struct ocp_device, global_list);
59                 if (device == ocp->device)
60                         count++;
61         }
62         return count;
63 }
64
65 /**
66  * ocp_get_dev - get ocp driver pointer for ocp device and instance of it
67  * @device: OCP device such as PCI, GPT, UART, OPB, IIC, GPIO, EMAC, ZMII
68  * @dev_num: ocp device number whos paddr you want
69  *
70  * The routine returns ocp device pointer
71  * in list based on device and instance of that device
72  *
73  */
74 struct ocp_device *
75 ocp_get_dev(unsigned int device, int dev_num)
76 {
77         struct ocp_device *ocp;
78         struct list_head *ocp_l;
79         int count = 0;
80
81         list_for_each(ocp_l, &ocp_devices) {
82                 ocp = list_entry(ocp_l, struct ocp_device, global_list);
83                 if (device == ocp->device) {
84                         if (dev_num == count)
85                                 return ocp;
86                         count++;
87                 }
88         }
89         return NULL;
90 }
91
92 EXPORT_SYMBOL(ocp_get_dev);
93 EXPORT_SYMBOL(ocp_get_num);
94
95 #ifdef CONFIG_PM
96 int ocp_generic_suspend(struct ocp_device *pdev, u32 state)
97 {
98         ocp_force_power_off(pdev);
99         return 0;
100 }
101
102 int ocp_generic_resume(struct ocp_device *pdev)
103 {
104         ocp_force_power_on(pdev);
105 }
106
107 EXPORT_SYMBOL(ocp_generic_suspend);
108 EXPORT_SYMBOL(ocp_generic_resume);
109 #endif /* CONFIG_PM */