4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
26 * SD card host support. This is the API that host drivers access.
29 #include <sys/types.h>
31 #include <sys/cmn_err.h>
32 #include <sys/varargs.h>
34 #include <sys/sunddi.h>
35 #include <sys/sdcard/sda.h>
36 #include <sys/sdcard/sda_impl.h>
43 sda_host_init_ops(struct dev_ops
*devops
)
49 sda_host_fini_ops(struct dev_ops
*devops
)
55 sda_host_alloc(dev_info_t
*dip
, int nslot
, sda_ops_t
*ops
, ddi_dma_attr_t
*dma
)
59 if (ops
->so_version
!= SDA_OPS_VERSION
) {
63 h
= kmem_zalloc(sizeof (*h
), KM_SLEEP
);
65 h
->h_slots
= kmem_zalloc(sizeof (sda_slot_t
) * nslot
, KM_SLEEP
);
69 /* initialize each slot */
70 for (int i
= 0; i
< nslot
; i
++) {
71 sda_slot_t
*slot
= &h
->h_slots
[i
];
84 sda_host_free(sda_host_t
*h
)
86 for (int i
= 0; i
< h
->h_nslot
; i
++) {
87 sda_slot_fini(&h
->h_slots
[i
]);
90 kmem_free(h
->h_slots
, sizeof (sda_slot_t
) * h
->h_nslot
);
91 kmem_free(h
, sizeof (*h
));
95 sda_host_set_private(sda_host_t
*h
, int num
, void *private)
97 h
->h_slots
[num
].s_prv
= private;
101 sda_host_attach(sda_host_t
*h
)
106 for (int i
= 0; i
< h
->h_nslot
; i
++) {
108 sda_slot_attach(&h
->h_slots
[i
]);
111 * Initiate card detection.
113 sda_host_detect(h
, i
);
116 return (DDI_SUCCESS
);
120 sda_host_detach(sda_host_t
*h
)
125 for (int i
= 0; i
< h
->h_nslot
; i
++) {
126 sda_slot_detach(&h
->h_slots
[i
]);
131 sda_host_suspend(sda_host_t
*h
)
133 for (int i
= 0; i
< h
->h_nslot
; i
++) {
134 sda_slot_suspend(&h
->h_slots
[i
]);
139 sda_host_resume(sda_host_t
*h
)
141 for (int i
= 0; i
< h
->h_nslot
; i
++) {
142 sda_slot_resume(&h
->h_slots
[i
]);
147 sda_host_transfer(sda_host_t
*h
, int num
, sda_err_t errno
)
149 sda_slot_transfer(&h
->h_slots
[num
], errno
);
153 sda_host_detect(sda_host_t
*h
, int num
)
155 sda_slot_detect(&h
->h_slots
[num
]);
159 sda_host_fault(sda_host_t
*h
, int num
, sda_fault_t fail
)
161 sda_slot_fault(&h
->h_slots
[num
], fail
);
165 sda_host_log(sda_host_t
*h
, int snum
, const char *fmt
, ...)
171 sda_slot_log(&h
->h_slots
[snum
], fmt
, ap
);
173 sda_slot_log(NULL
, fmt
, ap
);