spibusvar.h revision 331506
1153761Swollman/*-
2233446Sedwin * Copyright (c) 2006 M. Warner Losh
3192886Sedwin * All rights reserved.
4192886Sedwin *
564499Swollman * Redistribution and use in source and binary forms, with or without
62742Swollman * modification, are permitted provided that the following conditions
72742Swollman * are met:
82742Swollman * 1. Redistributions of source code must retain the above copyright
92742Swollman *    notice, this list of conditions and the following disclaimer.
10158421Swollman * 2. Redistributions in binary form must reproduce the above copyright
112742Swollman *    notice, this list of conditions and the following disclaimer in the
12158421Swollman *    documentation and/or other materials provided with the distribution.
13158421Swollman *
142742Swollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1586222Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1620094Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1720094Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1820094Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1920094Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2020094Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21158421Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22158421Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2320094Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2443543Swollman * SUCH DAMAGE.
252742Swollman *
2643543Swollman * $FreeBSD: stable/11/sys/dev/spibus/spibusvar.h 331506 2018-03-24 23:23:31Z ian $
2743543Swollman */
2843543Swollman
2943543Swollman#define SPIBUS_IVAR(d) (struct spibus_ivar *) device_get_ivars(d)
30121098Swollman#define SPIBUS_SOFTC(d) (struct spibus_softc *) device_get_softc(d)
31121098Swollman
32121098Swollmanstruct spibus_softc
33121098Swollman{
3443543Swollman	device_t	dev;
3543543Swollman};
3643543Swollman
3743543Swollman#define	SPIBUS_MODE_NONE	0
3843543Swollman#define	SPIBUS_MODE_CPHA	1
3943543Swollman#define	SPIBUS_MODE_CPOL	2
402742Swollman#define	SPIBUS_MODE_CPOL_CPHA	3
412742Swollman
4219878Swollmanstruct spibus_ivar
43114173Swollman{
44114173Swollman	uint32_t	cs;
45114173Swollman	uint32_t	mode;
46114173Swollman	uint32_t	clock;
47114173Swollman};
48114173Swollman
49114173Swollman#define	SPIBUS_CS_HIGH	(1U << 31)
50114173Swollman
51114173Swollmanenum {
52114173Swollman	SPIBUS_IVAR_CS,		/* chip select that we're on */
53114173Swollman	SPIBUS_IVAR_MODE,	/* SPI mode (0-3) */
54114173Swollman	SPIBUS_IVAR_CLOCK,	/* maximum clock freq for device */
55114173Swollman};
56114173Swollman
572742Swollman#define SPIBUS_ACCESSOR(A, B, T)					\
582742Swollmanstatic inline int							\
5958787Sruspibus_get_ ## A(device_t dev, T *t)					\
602742Swollman{									\
61149514Swollman	return BUS_READ_IVAR(device_get_parent(dev), dev,		\
6214343Swollman	    SPIBUS_IVAR_ ## B, (uintptr_t *) t);			\
639908Swollman}
649908Swollman
659908SwollmanSPIBUS_ACCESSOR(cs,		CS,		uint32_t)
669908SwollmanSPIBUS_ACCESSOR(mode,		MODE,		uint32_t)
679908SwollmanSPIBUS_ACCESSOR(clock,		CLOCK,		uint32_t)
689908Swollman
699908Swollmanextern driver_t spibus_driver;
709908Swollmanextern devclass_t spibus_devclass;
719908Swollmanextern driver_t ofw_spibus_driver;
729908Swollmanextern devclass_t ofw_spibus_devclass;
7314343Swollman