xref: /freebsd-src/sys/dev/mmc/mmcbrvar.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1114b4164SWarner Losh /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4114b4164SWarner Losh  * Copyright (c) 2006 Bernd Walter.  All rights reserved.
5f86e6000SWarner Losh  * Copyright (c) 2006 M. Warner Losh <imp@FreeBSD.org>
6114b4164SWarner Losh  *
7114b4164SWarner Losh  * Redistribution and use in source and binary forms, with or without
8114b4164SWarner Losh  * modification, are permitted provided that the following conditions
9114b4164SWarner Losh  * are met:
10114b4164SWarner Losh  * 1. Redistributions of source code must retain the above copyright
11114b4164SWarner Losh  *    notice, this list of conditions and the following disclaimer.
12114b4164SWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
13114b4164SWarner Losh  *    notice, this list of conditions and the following disclaimer in the
14114b4164SWarner Losh  *    documentation and/or other materials provided with the distribution.
15114b4164SWarner Losh  *
16114b4164SWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17114b4164SWarner Losh  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18114b4164SWarner Losh  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19114b4164SWarner Losh  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20114b4164SWarner Losh  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21114b4164SWarner Losh  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22114b4164SWarner Losh  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23114b4164SWarner Losh  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24114b4164SWarner Losh  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25114b4164SWarner Losh  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26114b4164SWarner Losh  *
2714eced72SWarner Losh  * Portions of this software may have been developed with reference to
2814eced72SWarner Losh  * the SD Simplified Specification.  The following disclaimer may apply:
2914eced72SWarner Losh  *
3014eced72SWarner Losh  * The following conditions apply to the release of the simplified
3114eced72SWarner Losh  * specification ("Simplified Specification") by the SD Card Association and
3214eced72SWarner Losh  * the SD Group. The Simplified Specification is a subset of the complete SD
3314eced72SWarner Losh  * Specification which is owned by the SD Card Association and the SD
3414eced72SWarner Losh  * Group. This Simplified Specification is provided on a non-confidential
3514eced72SWarner Losh  * basis subject to the disclaimers below. Any implementation of the
3614eced72SWarner Losh  * Simplified Specification may require a license from the SD Card
3714eced72SWarner Losh  * Association, SD Group, SD-3C LLC or other third parties.
3814eced72SWarner Losh  *
3914eced72SWarner Losh  * Disclaimers:
4014eced72SWarner Losh  *
4114eced72SWarner Losh  * The information contained in the Simplified Specification is presented only
4214eced72SWarner Losh  * as a standard specification for SD Cards and SD Host/Ancillary products and
4314eced72SWarner Losh  * is provided "AS-IS" without any representations or warranties of any
4414eced72SWarner Losh  * kind. No responsibility is assumed by the SD Group, SD-3C LLC or the SD
4514eced72SWarner Losh  * Card Association for any damages, any infringements of patents or other
4614eced72SWarner Losh  * right of the SD Group, SD-3C LLC, the SD Card Association or any third
4714eced72SWarner Losh  * parties, which may result from its use. No license is granted by
4814eced72SWarner Losh  * implication, estoppel or otherwise under any patent or other rights of the
4914eced72SWarner Losh  * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing
5014eced72SWarner Losh  * herein shall be construed as an obligation by the SD Group, the SD-3C LLC
5114eced72SWarner Losh  * or the SD Card Association to disclose or distribute any technical
5214eced72SWarner Losh  * information, know-how or other confidential information to any third party.
53114b4164SWarner Losh  */
54114b4164SWarner Losh 
55114b4164SWarner Losh #ifndef DEV_MMC_MMCBRVAR_H
56114b4164SWarner Losh #define	DEV_MMC_MMCBRVAR_H
57114b4164SWarner Losh 
587aa65846SMarius Strobl #include <dev/mmc/mmcreg.h>
59aca38eabSMarius Strobl 
60114b4164SWarner Losh #include "mmcbr_if.h"
61114b4164SWarner Losh 
62114b4164SWarner Losh enum mmcbr_device_ivars {
63114b4164SWarner Losh     MMCBR_IVAR_BUS_MODE,
64114b4164SWarner Losh     MMCBR_IVAR_BUS_WIDTH,
65114b4164SWarner Losh     MMCBR_IVAR_CHIP_SELECT,
66114b4164SWarner Losh     MMCBR_IVAR_CLOCK,
67114b4164SWarner Losh     MMCBR_IVAR_F_MIN,
68114b4164SWarner Losh     MMCBR_IVAR_F_MAX,
69114b4164SWarner Losh     MMCBR_IVAR_HOST_OCR,
70114b4164SWarner Losh     MMCBR_IVAR_MODE,
71114b4164SWarner Losh     MMCBR_IVAR_OCR,
72114b4164SWarner Losh     MMCBR_IVAR_POWER_MODE,
73aca38eabSMarius Strobl     MMCBR_IVAR_RETUNE_REQ,
74114b4164SWarner Losh     MMCBR_IVAR_VDD,
750f34084fSMarius Strobl     MMCBR_IVAR_VCCQ,
76bd2bbf24SWarner Losh     MMCBR_IVAR_CAPS,
77c18f1e26SAlexander Motin     MMCBR_IVAR_TIMING,
7872dec079SMarius Strobl     MMCBR_IVAR_MAX_DATA,
7972dec079SMarius Strobl     MMCBR_IVAR_MAX_BUSY_TIMEOUT
80114b4164SWarner Losh };
81114b4164SWarner Losh 
82114b4164SWarner Losh /*
8372dec079SMarius Strobl  * Simplified accessors for bridge devices
84114b4164SWarner Losh  */
85114b4164SWarner Losh #define	MMCBR_ACCESSOR(var, ivar, type)					\
86114b4164SWarner Losh 	__BUS_ACCESSOR(mmcbr, var, MMCBR, ivar, type)
87114b4164SWarner Losh 
MMCBR_ACCESSOR(bus_mode,BUS_MODE,int)88114b4164SWarner Losh MMCBR_ACCESSOR(bus_mode, BUS_MODE, int)
89114b4164SWarner Losh MMCBR_ACCESSOR(bus_width, BUS_WIDTH, int)
90114b4164SWarner Losh MMCBR_ACCESSOR(chip_select, CHIP_SELECT, int)
91114b4164SWarner Losh MMCBR_ACCESSOR(clock, CLOCK, int)
92114b4164SWarner Losh MMCBR_ACCESSOR(f_max, F_MAX, int)
93114b4164SWarner Losh MMCBR_ACCESSOR(f_min, F_MIN, int)
94114b4164SWarner Losh MMCBR_ACCESSOR(host_ocr, HOST_OCR, int)
95114b4164SWarner Losh MMCBR_ACCESSOR(mode, MODE, int)
96114b4164SWarner Losh MMCBR_ACCESSOR(ocr, OCR, int)
97114b4164SWarner Losh MMCBR_ACCESSOR(power_mode, POWER_MODE, int)
98114b4164SWarner Losh MMCBR_ACCESSOR(vdd, VDD, int)
990f34084fSMarius Strobl MMCBR_ACCESSOR(vccq, VCCQ, int)
100bd2bbf24SWarner Losh MMCBR_ACCESSOR(caps, CAPS, int)
101c18f1e26SAlexander Motin MMCBR_ACCESSOR(timing, TIMING, int)
1023a4a2557SAlexander Motin MMCBR_ACCESSOR(max_data, MAX_DATA, int)
10372dec079SMarius Strobl MMCBR_ACCESSOR(max_busy_timeout, MAX_BUSY_TIMEOUT, u_int)
104114b4164SWarner Losh 
105114b4164SWarner Losh static int __inline
1067f6921aeSMarius Strobl mmcbr_get_retune_req(device_t dev)
1077f6921aeSMarius Strobl {
1087f6921aeSMarius Strobl 	uintptr_t v;
1097f6921aeSMarius Strobl 
1107f6921aeSMarius Strobl 	if (__predict_false(BUS_READ_IVAR(device_get_parent(dev), dev,
1117f6921aeSMarius Strobl 	    MMCBR_IVAR_RETUNE_REQ, &v) != 0))
1127f6921aeSMarius Strobl 		return (retune_req_none);
1137f6921aeSMarius Strobl 	return ((int)v);
1147f6921aeSMarius Strobl }
1157f6921aeSMarius Strobl 
1167f6921aeSMarius Strobl /*
1177f6921aeSMarius Strobl  * Convenience wrappers for the mmcbr interface
1187f6921aeSMarius Strobl  */
1197f6921aeSMarius Strobl static int __inline
mmcbr_update_ios(device_t dev)120114b4164SWarner Losh mmcbr_update_ios(device_t dev)
121114b4164SWarner Losh {
122b440e965SMarius Strobl 
123114b4164SWarner Losh 	return (MMCBR_UPDATE_IOS(device_get_parent(dev), dev));
124114b4164SWarner Losh }
125114b4164SWarner Losh 
12640fab6e7SWarner Losh static int __inline
mmcbr_tune(device_t dev,bool hs400)127aca38eabSMarius Strobl mmcbr_tune(device_t dev, bool hs400)
128aca38eabSMarius Strobl {
129aca38eabSMarius Strobl 
130aca38eabSMarius Strobl 	return (MMCBR_TUNE(device_get_parent(dev), dev, hs400));
131aca38eabSMarius Strobl }
132aca38eabSMarius Strobl 
133aca38eabSMarius Strobl static int __inline
mmcbr_retune(device_t dev,bool reset)134aca38eabSMarius Strobl mmcbr_retune(device_t dev, bool reset)
135aca38eabSMarius Strobl {
136aca38eabSMarius Strobl 
137aca38eabSMarius Strobl 	return (MMCBR_RETUNE(device_get_parent(dev), dev, reset));
138aca38eabSMarius Strobl }
139aca38eabSMarius Strobl 
140aca38eabSMarius Strobl static int __inline
mmcbr_switch_vccq(device_t dev)1410f34084fSMarius Strobl mmcbr_switch_vccq(device_t dev)
1420f34084fSMarius Strobl {
1430f34084fSMarius Strobl 
1440f34084fSMarius Strobl 	return (MMCBR_SWITCH_VCCQ(device_get_parent(dev), dev));
1450f34084fSMarius Strobl }
1460f34084fSMarius Strobl 
1470f34084fSMarius Strobl static int __inline
mmcbr_get_ro(device_t dev)14840fab6e7SWarner Losh mmcbr_get_ro(device_t dev)
14940fab6e7SWarner Losh {
150b440e965SMarius Strobl 
15140fab6e7SWarner Losh 	return (MMCBR_GET_RO(device_get_parent(dev), dev));
15240fab6e7SWarner Losh }
15340fab6e7SWarner Losh 
154114b4164SWarner Losh #endif /* DEV_MMC_MMCBRVAR_H */
155