Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / drivers / mca / mca-device.c
blobe7adf89fae412d49c74a56b2df0028ed20264165
1 /* -*- mode: c; c-basic-offset: 8 -*- */
3 /*
4 * MCA device support functions
6 * These functions support the ongoing device access API.
8 * (C) 2002 James Bottomley <James.Bottomley@HansenPartnership.com>
10 **-----------------------------------------------------------------------------
11 **
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License as published by
14 ** the Free Software Foundation; either version 2 of the License, or
15 ** (at your option) any later version.
17 ** This program is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ** GNU General Public License for more details.
22 ** You should have received a copy of the GNU General Public License
23 ** along with this program; if not, write to the Free Software
24 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 **-----------------------------------------------------------------------------
29 #include <linux/module.h>
30 #include <linux/device.h>
31 #include <linux/mca.h>
32 #include <linux/string.h>
34 /**
35 * mca_device_read_stored_pos - read POS register from stored data
36 * @mca_dev: device to read from
37 * @reg: register to read from
39 * Fetch a POS value that was stored at boot time by the kernel
40 * when it scanned the MCA space. The register value is returned.
41 * Missing or invalid registers report 0.
43 unsigned char mca_device_read_stored_pos(struct mca_device *mca_dev, int reg)
45 if(reg < 0 || reg >= 8)
46 return 0;
48 return mca_dev->pos[reg];
50 EXPORT_SYMBOL(mca_device_read_stored_pos);
52 /**
53 * mca_device_read_pos - read POS register from card
54 * @mca_dev: device to read from
55 * @reg: register to read from
57 * Fetch a POS value directly from the hardware to obtain the
58 * current value. This is much slower than
59 * mca_device_read_stored_pos and may not be invoked from
60 * interrupt context. It handles the deep magic required for
61 * onboard devices transparently.
63 unsigned char mca_device_read_pos(struct mca_device *mca_dev, int reg)
65 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
67 return mca_bus->f.mca_read_pos(mca_dev, reg);
69 return mca_dev->pos[reg];
71 EXPORT_SYMBOL(mca_device_read_pos);
74 /**
75 * mca_device_write_pos - read POS register from card
76 * @mca_dev: device to write pos register to
77 * @reg: register to write to
78 * @byte: byte to write to the POS registers
80 * Store a POS value directly to the hardware. You should not
81 * normally need to use this function and should have a very good
82 * knowledge of MCA bus before you do so. Doing this wrongly can
83 * damage the hardware.
85 * This function may not be used from interrupt context.
88 void mca_device_write_pos(struct mca_device *mca_dev, int reg,
89 unsigned char byte)
91 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
93 mca_bus->f.mca_write_pos(mca_dev, reg, byte);
95 EXPORT_SYMBOL(mca_device_write_pos);
97 /**
98 * mca_device_transform_irq - transform the ADF obtained IRQ
99 * @mca_device: device whose irq needs transforming
100 * @irq: input irq from ADF
102 * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
103 * etc. definitions. In systems with more than one bus, these need
104 * to be transformed through bus mapping functions to get the real
105 * system global quantities.
107 * This function transforms the interrupt number and returns the
108 * transformed system global interrupt
110 int mca_device_transform_irq(struct mca_device *mca_dev, int irq)
112 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
114 return mca_bus->f.mca_transform_irq(mca_dev, irq);
116 EXPORT_SYMBOL(mca_device_transform_irq);
119 * mca_device_transform_ioport - transform the ADF obtained I/O port
120 * @mca_device: device whose port needs transforming
121 * @ioport: input I/O port from ADF
123 * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
124 * etc. definitions. In systems with more than one bus, these need
125 * to be transformed through bus mapping functions to get the real
126 * system global quantities.
128 * This function transforms the I/O port number and returns the
129 * transformed system global port number.
131 * This transformation can be assumed to be linear for port ranges.
133 int mca_device_transform_ioport(struct mca_device *mca_dev, int port)
135 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
137 return mca_bus->f.mca_transform_ioport(mca_dev, port);
139 EXPORT_SYMBOL(mca_device_transform_ioport);
142 * mca_device_transform_memory - transform the ADF obtained memory
143 * @mca_device: device whose memory region needs transforming
144 * @mem: memory region start from ADF
146 * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
147 * etc. definitions. In systems with more than one bus, these need
148 * to be transformed through bus mapping functions to get the real
149 * system global quantities.
151 * This function transforms the memory region start and returns the
152 * transformed system global memory region (physical).
154 * This transformation can be assumed to be linear for region ranges.
156 void *mca_device_transform_memory(struct mca_device *mca_dev, void *mem)
158 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
160 return mca_bus->f.mca_transform_memory(mca_dev, mem);
162 EXPORT_SYMBOL(mca_device_transform_memory);
166 * mca_device_claimed - check if claimed by driver
167 * @mca_dev: device to check
169 * Returns 1 if the slot has been claimed by a driver
172 int mca_device_claimed(struct mca_device *mca_dev)
174 return mca_dev->driver_loaded;
176 EXPORT_SYMBOL(mca_device_claimed);
179 * mca_device_set_claim - set the claim value of the driver
180 * @mca_dev: device to set value for
181 * @val: claim value to set (1 claimed, 0 unclaimed)
183 void mca_device_set_claim(struct mca_device *mca_dev, int val)
185 mca_dev->driver_loaded = val;
187 EXPORT_SYMBOL(mca_device_set_claim);
190 * mca_device_status - get the status of the device
191 * @mca_device: device to get
193 * returns an enumeration of the device status:
195 * MCA_ADAPTER_NORMAL adapter is OK.
196 * MCA_ADAPTER_NONE no adapter at device (should never happen).
197 * MCA_ADAPTER_DISABLED adapter is disabled.
198 * MCA_ADAPTER_ERROR adapter cannot be initialised.
200 enum MCA_AdapterStatus mca_device_status(struct mca_device *mca_dev)
202 return mca_dev->status;
204 EXPORT_SYMBOL(mca_device_status);
207 * mca_device_set_name - set the name of the device
208 * @mca_device: device to set the name of
209 * @name: name to set
211 void mca_device_set_name(struct mca_device *mca_dev, const char *name)
213 if(!mca_dev)
214 return;
216 strlcpy(mca_dev->name, name, sizeof(mca_dev->name));
218 EXPORT_SYMBOL(mca_device_set_name);