aboutsummaryrefslogtreecommitdiff
path: root/drivers/sdio/stack/platform/sdioplatformdriver.c
blob: d5520fc290837be6ec1c8d5b71846ad87a3f706f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@file: sdioplatformdriver.c

@abstract: Linux implementation module for SDIO pltaform driver

#notes:

@notice: Copyright (c), 2006 Atheros Communications, Inc.

@license:  This program is free software; you can redistribute it and/or modify
           it under the terms of the GNU General Public License version 2 as
           published by the Free Software Foundation.



 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation;
 *
 *  Software distributed under the License is distributed on an "AS
 *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 *  implied. See the License for the specific language governing
 *  rights and limitations under the License.
 *
 *  Portions of this code were developed with information supplied from the
 *  SD Card Association Simplified Specifications. The following conditions and disclaimers may apply:
 *
 *   The following conditions apply to the release of the SD simplified specification (�Simplified
 *   Specification�) by the SD Card Association. The Simplified Specification is a subset of the complete
 *   SD Specification which is owned by the SD Card Association. This Simplified Specification is provided
 *   on a non-confidential basis subject to the disclaimers below. Any implementation of the Simplified
 *   Specification may require a license from the SD Card Association or other third parties.
 *   Disclaimers:
 *   The information contained in the Simplified Specification is presented only as a standard
 *   specification for SD Cards and SD Host/Ancillary products and is provided "AS-IS" without any
 *   representations or warranties of any kind. No responsibility is assumed by the SD Card Association for
 *   any damages, any infringements of patents or other right of the SD Card Association or any third
 *   parties, which may result from its use. No license is granted by implication, estoppel or otherwise
 *   under any patent or other rights of the SD Card Association or any third party. Nothing herein shall
 *   be construed as an obligation by the SD Card Association to disclose or distribute any technical
 *   information, know-how or other confidential information to any third party.
 *
 *
 *  The initial developers of the original code are Seung Yi and Paul Lever
 *
 *  sdio@atheros.com
 *
 *

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

#define DESCRIPTION "SDIO Platform Driver"
#define AUTHOR "Atheros Communications, Inc."

//??for .h

struct sdioplatform_peripheral {
    struct list_head    node;
    struct sdioplatform_controller *controller;
    struct device       dev;
};
struct sdioplatform_driver {
    struct device_driver drv;
    int (*probe)(struct sdioplatform_peripheral *);
    void (*remove)(struct sdioplatform_peripheral *);
    int (*suspend)(struct sdioplatform_peripheral *, pm_message_t);
    int (*resume)(struct sdioplatform_peripheral *);
};


struct sdioplatform_controller {
    struct device       *dev;
};
struct sdioplatform_controller_driver {
    struct device_driver drv;
    int (*probe)(struct sdioplatform_controller *);
    void (*remove)(struct sdioplatform_controller *);
    int (*suspend)(struct sdioplatform_controller *, pm_message_t);
    int (*resume)(struct sdioplatform_controller *);
};



#define device_to_sdioplatform_peripheral(d)  container_of(d, struct sdioplatform_peripheral, dev)
#define driver_to_sdioplatform_driver(d)  container_of(d, struct sdioplatform_driver, drv)

#define device_to_sdioplatform_controller(d)  container_of(d, struct sdioplatform_controller, dev)
#define driver_to_sdioplatform_controller_driver(d)  container_of(d, struct sdioplatform_controller_driver, drv)

#define SDIOPLATFORM_ATTR(name, fmt, args...)                    \
static ssize_t sdio_##name##_show (struct device *dev, struct device_attribute *attr, char *buf) \
{                                   \
    struct sdioplatform_peripheral *peripheral = device_to_sdioplatform_peripheral(dev);  \
    return sprintf(buf, fmt, args);                 \
}

SDIOPLATFORM_ATTR(bus_id, "%s\n", bus_id);
#define SDIOPLATFORM_ATTR_RO(name) __ATTR(name, S_IRUGO, sdioplatform_##name##_show, NULL)

static struct device_attribute sdioplatform_dev_attrs[] = {
    SDIOPLATFORM_ATTR_RO(bus_id),
    __ATTR_NULL
};

static struct bus_type sdioplatform_bus_type = {
    .name       = "sdioplatform",
    .dev_attrs  = sdioplatform_dev_attrs,
    .match      = sdioplatform_bus_match,
    .hotplug    = NULL,
    .suspend    = sdioplatform_bus_suspend,
    .resume     = sdioplatform_bus_resume,
};


/* controller functions */
static int sdioplatform_controllerdrv_probe(struct device *dev)
{
    struct sdioplatform_controller_driver *drv = driver_to_sdioplatform_controller_driver(dev->driver);
    struct sdioplatform_controller *controller = device_to_sdioplatform_controller(dev);

    return drv->probe(controller);
}

static int sdioplatform_controllerdrv_remove(struct device *dev)
{
    struct sdioplatform_controller_driver *drv = driver_to_sdioplatform_controller_driver(dev->driver);
    struct sdioplatform_controller *controller = device_to_sdioplatform_controller(dev);

    return drv->remove(controller);
}

/*
 * sdioplatform_register_controller_driver - register a controller driver
 */
int sdioplatform_register_controller_driver(struct sdioplatform_controller_driver *drv)
{
    drv->drv.bus = &sdioplatform_bus_type;
    drv->drv.probe = sdioplatform_controllerdrv_probe;
    drv->drv.remove = sdioplatform_controllerdrv_remove;
    return driver_register(&drv->drv);
}

/*
 *  sdioplatform_unregister_controller_driver - unregister a controller driver
 */
void sdioplatform_unregister_controller_driver(struct sdioplatform_driver *drv)
{
    driver_unregister(&drv->drv);
}

/*
 * sdioplatform_add_controller - register a controller device
 */
int sdioplatform_add_controller(char *name, struct sdioplatform_controller *dev)
{
    if (!dev) {
        return -EINVAL;
    }
    strncpy(dev->dev.bus_id, BUS_ID_SIZE, name);
    return device_register(&dev->dev);
}

/*
 * sdioplatform_remove_controller - unregister a controller device
 */
int sdioplatform_remove_controller(char *name, struct sdioplatform_controller *dev)
{
    if (!dev) {
        return -EINVAL;
    }
    return device_unregister(&dev->dev);
}

/* peripheral functions */
static int sdioplatform_drv_probe(struct device *dev)
{
    struct sdioplatform_driver *drv = driver_to_sdioplatform_driver(dev->driver);
    struct sdioplatform_peripheral *peripheral = device_to_sdioplatform_peripheral(dev);

    return drv->probe(peripheral);
}

static int sdioplatform_controllerdrv_remove(struct device *dev)
{
    struct sdioplatform_controller_driver *drv = driver_to_sdioplatform_controller_driver(dev->driver);
    struct sdioplatform_controller *controller = device_to_sdioplatform_controller(dev);

    return drv->remove(controller);
}

/*
 * sdioplatform_register_driver - register a driver
 */
int sdioplatform_register_driver(struct sdioplatform_driver *drv)
{
    drv->drv.bus = &sdioplatform_bus_type;
    drv->drv.probe = sdioplatform_drv_probe;
    drv->drv.remove = sdioplatform_drv_remove;
    return driver_register(&drv->drv);
}

/*
 *  sdioplatform_unregister_driver - unregister a driver
 */
void sdioplatform_unregister_driver(struct sdioplatform_driver *drv)
{
    driver_unregister(&drv->drv);
}

/*
 * sdioplatform_add_peripheral - register a peripheral device
 */
int sdioplatform_add_peripheral(char *name, struct sdioplatform_peripheral *dev)
{
    if (!dev) {
        return -EINVAL;
    }
    strncpy(dev->dev.bus_id, BUS_ID_SIZE, name);
    return device_register(&dev->dev);
}

/*
 * sdioplatform_remove_peripheral - unregister a peripheral device
 */
int sdioplatform_remove_peripheral(char *name, struct sdioplatform_peripheral *dev)
{
    if (!dev) {
        return -EINVAL;
    }
    return device_unregister(&dev->dev);
}





static int sdioplatform_bus_match(struct device *dev, struct device_driver *drv)
{
    /* probes handle the matching */
    return 1;
}

static int sdioplatform_bus_suspend(struct device *dev, pm_message_t state)
{
    struct sdioplatform_driver *drv = driver_to_sdioplatform_driver(dev->driver);
    struct sdioplatform_peripheral *peripheral = device_to_sdioplatform_peripheral(dev);
    int ret = 0;

    if (peripheral->driver && drv->suspend) {
        ret = drv->suspend(peripheral, state);
    }
    return ret;
}

static int sdioplatform_bus_resume(struct device *dev)
{
    struct sdioplatform_driver *drv = driver_to_sdioplatform_driver(dev->driver);
    struct sdioplatform_peripheral *peripheral = device_to_sdioplatform_peripheral(dev);
    int ret = 0;

    if (peripheral->driver && drv->resume) {
        ret = drv->resume(card);
    }
    return ret;
}

/*
 * module init
*/
static int __init sdio_platformdriver_init(void) {
    int ret = bus_register(&sdioplatform_bus_type);
    return ret;
}

/*
 * module cleanup
*/
static void __exit sdio_platformdriver_cleanup(void) {
    REL_PRINT(SDDBG_TRACE, ("SDIO unloaded\n"));
    _SDIO_BusDriverCleanup();
}

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION(DESCRIPTION);
MODULE_AUTHOR(AUTHOR);

module_init(sdio_platformdriver_init);
module_exit(sdio_platformdriver_cleanup);
EXPORT_SYMBOL(sdioplatform_register_controller_driver);
EXPORT_SYMBOL(sdioplatform_unregister_controller_driver);
EXPORT_SYMBOL(sdioplatform_add_controller);
EXPORT_SYMBOL(sdioplatform_remove_controller);
EXPORT_SYMBOL(sdioplatform_register_driver);
EXPORT_SYMBOL(sdioplatform_unregister_driver);
EXPORT_SYMBOL(sdioplatform_add_peripheral);
EXPORT_SYMBOL(sdioplatform_remove_peripheral);