Home | History | Annotate | Line # | Download | only in fdt
fdt_spi.c revision 1.3.2.1
      1  1.3.2.1  thorpej /* $NetBSD: fdt_spi.c,v 1.3.2.1 2021/08/09 00:30:09 thorpej Exp $ */
      2      1.1      tnn 
      3      1.1      tnn /*
      4      1.1      tnn  * Copyright (c) 2019 The NetBSD Foundation, Inc.
      5      1.1      tnn  * All rights reserved.
      6      1.1      tnn  *
      7      1.1      tnn  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1      tnn  * by Tobias Nygren.
      9      1.1      tnn  *
     10      1.1      tnn  * Redistribution and use in source and binary forms, with or without
     11      1.1      tnn  * modification, are permitted provided that the following conditions
     12      1.1      tnn  * are met:
     13      1.1      tnn  * 1. Redistributions of source code must retain the above copyright
     14      1.1      tnn  *    notice, this list of conditions and the following disclaimer.
     15      1.1      tnn  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1      tnn  *    notice, this list of conditions and the following disclaimer in the
     17      1.1      tnn  *    documentation and/or other materials provided with the distribution.
     18      1.1      tnn  *
     19      1.1      tnn  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.1      tnn  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.1      tnn  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.1      tnn  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.1      tnn  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.1      tnn  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.1      tnn  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.1      tnn  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.1      tnn  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.1      tnn  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.1      tnn  * POSSIBILITY OF SUCH DAMAGE.
     30      1.1      tnn  */
     31      1.1      tnn 
     32      1.1      tnn #include <sys/cdefs.h>
     33  1.3.2.1  thorpej __KERNEL_RCSID(0, "$NetBSD: fdt_spi.c,v 1.3.2.1 2021/08/09 00:30:09 thorpej Exp $");
     34      1.1      tnn 
     35      1.1      tnn #include <sys/param.h>
     36      1.1      tnn #include <sys/device.h>
     37      1.1      tnn #include <sys/bus.h>
     38      1.1      tnn #include <sys/kmem.h>
     39      1.1      tnn #include <sys/queue.h>
     40      1.1      tnn #include <dev/spi/spivar.h>
     41      1.1      tnn #include <libfdt.h>
     42      1.1      tnn #include <dev/fdt/fdtvar.h>
     43      1.1      tnn 
     44      1.1      tnn struct fdtbus_spi_controller {
     45  1.3.2.1  thorpej 	struct spi_controller *spi_ctlr;
     46      1.1      tnn 	int spi_phandle;
     47  1.3.2.1  thorpej 
     48      1.1      tnn 	LIST_ENTRY(fdtbus_spi_controller) spi_next;
     49      1.1      tnn };
     50      1.1      tnn 
     51      1.1      tnn static LIST_HEAD(, fdtbus_spi_controller) fdtbus_spi_controllers =
     52      1.1      tnn     LIST_HEAD_INITIALIZER(fdtbus_spi_controllers);
     53      1.1      tnn 
     54      1.1      tnn int
     55  1.3.2.1  thorpej fdtbus_register_spi_controller(struct spi_controller *ctlr, int phandle)
     56      1.1      tnn {
     57      1.1      tnn 	struct fdtbus_spi_controller *spi;
     58      1.1      tnn 
     59      1.1      tnn 	spi = kmem_alloc(sizeof(*spi), KM_SLEEP);
     60  1.3.2.1  thorpej 	spi->spi_ctlr = ctlr;
     61      1.1      tnn 	spi->spi_phandle = phandle;
     62      1.1      tnn 
     63      1.1      tnn 	LIST_INSERT_HEAD(&fdtbus_spi_controllers, spi, spi_next);
     64      1.1      tnn 
     65      1.1      tnn 	return 0;
     66      1.1      tnn }
     67      1.1      tnn 
     68  1.3.2.1  thorpej #if 0
     69      1.1      tnn static struct spi_controller *
     70      1.1      tnn fdtbus_get_spi_controller(int phandle)
     71      1.1      tnn {
     72      1.1      tnn 	struct fdtbus_spi_controller *spi;
     73      1.1      tnn 
     74      1.1      tnn 	LIST_FOREACH(spi, &fdtbus_spi_controllers, spi_next) {
     75      1.1      tnn 		if (spi->spi_phandle == phandle) {
     76  1.3.2.1  thorpej 			return spi->spi_ctlr;
     77      1.1      tnn 		}
     78      1.1      tnn 	}
     79      1.1      tnn 	return NULL;
     80      1.1      tnn }
     81  1.3.2.1  thorpej #endif
     82