2 * linux/drivers/mfd/mcp-core.c
4 * Copyright (C) 2001 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License.
10 * Generic MCP (Multimedia Communications Port) layer. All MCP locking
11 * is solely held within this file.
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/errno.h>
16 #include <linux/smp.h>
17 #include <linux/device.h>
18 #include <linux/slab.h>
19 #include <linux/string.h>
20 #include <linux/mfd/mcp.h>
22 #include <asm/system.h>
25 #define to_mcp(d) container_of(d, struct mcp, attached_device)
26 #define to_mcp_driver(d) container_of(d, struct mcp_driver, drv)
28 static int mcp_bus_match(struct device
*dev
, struct device_driver
*drv
)
33 static int mcp_bus_probe(struct device
*dev
)
35 struct mcp
*mcp
= to_mcp(dev
);
36 struct mcp_driver
*drv
= to_mcp_driver(dev
->driver
);
38 return drv
->probe(mcp
);
41 static int mcp_bus_remove(struct device
*dev
)
43 struct mcp
*mcp
= to_mcp(dev
);
44 struct mcp_driver
*drv
= to_mcp_driver(dev
->driver
);
50 static int mcp_bus_suspend(struct device
*dev
, pm_message_t state
)
52 struct mcp
*mcp
= to_mcp(dev
);
56 struct mcp_driver
*drv
= to_mcp_driver(dev
->driver
);
58 ret
= drv
->suspend(mcp
, state
);
63 static int mcp_bus_resume(struct device
*dev
)
65 struct mcp
*mcp
= to_mcp(dev
);
69 struct mcp_driver
*drv
= to_mcp_driver(dev
->driver
);
71 ret
= drv
->resume(mcp
);
76 static struct bus_type mcp_bus_type
= {
78 .match
= mcp_bus_match
,
79 .probe
= mcp_bus_probe
,
80 .remove
= mcp_bus_remove
,
81 .suspend
= mcp_bus_suspend
,
82 .resume
= mcp_bus_resume
,
86 * mcp_set_telecom_divisor - set the telecom divisor
87 * @mcp: MCP interface structure
88 * @div: SIB clock divisor
90 * Set the telecom divisor on the MCP interface. The resulting
91 * sample rate is SIBCLOCK/div.
93 void mcp_set_telecom_divisor(struct mcp
*mcp
, unsigned int div
)
97 spin_lock_irqsave(&mcp
->lock
, flags
);
98 mcp
->ops
->set_telecom_divisor(mcp
, div
);
99 spin_unlock_irqrestore(&mcp
->lock
, flags
);
101 EXPORT_SYMBOL(mcp_set_telecom_divisor
);
104 * mcp_set_audio_divisor - set the audio divisor
105 * @mcp: MCP interface structure
106 * @div: SIB clock divisor
108 * Set the audio divisor on the MCP interface.
110 void mcp_set_audio_divisor(struct mcp
*mcp
, unsigned int div
)
114 spin_lock_irqsave(&mcp
->lock
, flags
);
115 mcp
->ops
->set_audio_divisor(mcp
, div
);
116 spin_unlock_irqrestore(&mcp
->lock
, flags
);
118 EXPORT_SYMBOL(mcp_set_audio_divisor
);
121 * mcp_reg_write - write a device register
122 * @mcp: MCP interface structure
123 * @reg: 4-bit register index
124 * @val: 16-bit data value
126 * Write a device register. The MCP interface must be enabled
127 * to prevent this function hanging.
129 void mcp_reg_write(struct mcp
*mcp
, unsigned int reg
, unsigned int val
)
133 spin_lock_irqsave(&mcp
->lock
, flags
);
134 mcp
->ops
->reg_write(mcp
, reg
, val
);
135 spin_unlock_irqrestore(&mcp
->lock
, flags
);
137 EXPORT_SYMBOL(mcp_reg_write
);
140 * mcp_reg_read - read a device register
141 * @mcp: MCP interface structure
142 * @reg: 4-bit register index
144 * Read a device register and return its value. The MCP interface
145 * must be enabled to prevent this function hanging.
147 unsigned int mcp_reg_read(struct mcp
*mcp
, unsigned int reg
)
152 spin_lock_irqsave(&mcp
->lock
, flags
);
153 val
= mcp
->ops
->reg_read(mcp
, reg
);
154 spin_unlock_irqrestore(&mcp
->lock
, flags
);
158 EXPORT_SYMBOL(mcp_reg_read
);
161 * mcp_enable - enable the MCP interface
162 * @mcp: MCP interface to enable
164 * Enable the MCP interface. Each call to mcp_enable will need
165 * a corresponding call to mcp_disable to disable the interface.
167 void mcp_enable(struct mcp
*mcp
)
170 spin_lock_irqsave(&mcp
->lock
, flags
);
171 if (mcp
->use_count
++ == 0)
172 mcp
->ops
->enable(mcp
);
173 spin_unlock_irqrestore(&mcp
->lock
, flags
);
175 EXPORT_SYMBOL(mcp_enable
);
178 * mcp_disable - disable the MCP interface
179 * @mcp: MCP interface to disable
181 * Disable the MCP interface. The MCP interface will only be
182 * disabled once the number of calls to mcp_enable matches the
183 * number of calls to mcp_disable.
185 void mcp_disable(struct mcp
*mcp
)
189 spin_lock_irqsave(&mcp
->lock
, flags
);
190 if (--mcp
->use_count
== 0)
191 mcp
->ops
->disable(mcp
);
192 spin_unlock_irqrestore(&mcp
->lock
, flags
);
194 EXPORT_SYMBOL(mcp_disable
);
196 static void mcp_release(struct device
*dev
)
198 struct mcp
*mcp
= container_of(dev
, struct mcp
, attached_device
);
203 struct mcp
*mcp_host_alloc(struct device
*parent
, size_t size
)
207 mcp
= kzalloc(sizeof(struct mcp
) + size
, GFP_KERNEL
);
209 spin_lock_init(&mcp
->lock
);
210 device_initialize(&mcp
->attached_device
);
211 mcp
->attached_device
.parent
= parent
;
212 mcp
->attached_device
.bus
= &mcp_bus_type
;
213 mcp
->attached_device
.dma_mask
= parent
->dma_mask
;
214 mcp
->attached_device
.release
= mcp_release
;
218 EXPORT_SYMBOL(mcp_host_alloc
);
220 int mcp_host_add(struct mcp
*mcp
)
222 dev_set_name(&mcp
->attached_device
, "mcp0");
223 return device_add(&mcp
->attached_device
);
225 EXPORT_SYMBOL(mcp_host_add
);
227 void mcp_host_del(struct mcp
*mcp
)
229 device_del(&mcp
->attached_device
);
231 EXPORT_SYMBOL(mcp_host_del
);
233 void mcp_host_free(struct mcp
*mcp
)
235 put_device(&mcp
->attached_device
);
237 EXPORT_SYMBOL(mcp_host_free
);
239 int mcp_driver_register(struct mcp_driver
*mcpdrv
)
241 mcpdrv
->drv
.bus
= &mcp_bus_type
;
242 return driver_register(&mcpdrv
->drv
);
244 EXPORT_SYMBOL(mcp_driver_register
);
246 void mcp_driver_unregister(struct mcp_driver
*mcpdrv
)
248 driver_unregister(&mcpdrv
->drv
);
250 EXPORT_SYMBOL(mcp_driver_unregister
);
252 static int __init
mcp_init(void)
254 return bus_register(&mcp_bus_type
);
257 static void __exit
mcp_exit(void)
259 bus_unregister(&mcp_bus_type
);
262 module_init(mcp_init
);
263 module_exit(mcp_exit
);
265 MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
266 MODULE_DESCRIPTION("Core multimedia communications port driver");
267 MODULE_LICENSE("GPL");
This page took 0.03588 seconds and 6 git commands to generate.