1 /* $NetBSD: fdtvar.h,v 1.2 2015/12/16 12:17:45 jmcneill Exp $ */ 2 3 /*- 4 * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _DEV_FDT_FDTVAR_H 30 #define _DEV_FDT_FDTVAR_H 31 32 #include <sys/types.h> 33 #include <sys/bus.h> 34 35 #include <dev/i2c/i2cvar.h> 36 37 #include <dev/ofw/openfirm.h> 38 39 struct fdt_attach_args { 40 const char *faa_name; 41 bus_space_tag_t faa_bst; 42 bus_space_tag_t faa_a4x_bst; 43 bus_dma_tag_t faa_dmat; 44 int faa_phandle; 45 46 const char **faa_init; 47 int faa_ninit; 48 }; 49 50 /* flags for fdtbus_intr_establish */ 51 #define FDT_INTR_MPSAFE __BIT(0) 52 53 struct fdtbus_interrupt_controller_func { 54 void * (*establish)(device_t, int, u_int, int, int, 55 int (*)(void *), void *); 56 void (*disestablish)(device_t, void *); 57 bool (*intrstr)(device_t, int, u_int, char *, size_t); 58 }; 59 60 struct fdtbus_i2c_controller_func { 61 i2c_tag_t (*get_tag)(device_t); 62 }; 63 64 struct fdtbus_gpio_controller; 65 66 struct fdtbus_gpio_pin { 67 struct fdtbus_gpio_controller *gp_gc; 68 void *gp_priv; 69 }; 70 71 struct fdtbus_gpio_controller_func { 72 void * (*acquire)(device_t, const void *, size_t, int); 73 void (*release)(device_t, void *); 74 int (*read)(device_t, void *); 75 void (*write)(device_t, void *, int); 76 }; 77 78 struct fdtbus_regulator_controller; 79 80 struct fdtbus_regulator { 81 struct fdtbus_regulator_controller *reg_rc; 82 }; 83 84 struct fdtbus_regulator_controller_func { 85 int (*acquire)(device_t); 86 void (*release)(device_t); 87 int (*enable)(device_t, bool); 88 }; 89 90 int fdtbus_register_interrupt_controller(device_t, int, 91 const struct fdtbus_interrupt_controller_func *); 92 int fdtbus_register_i2c_controller(device_t, int, 93 const struct fdtbus_i2c_controller_func *); 94 int fdtbus_register_gpio_controller(device_t, int, 95 const struct fdtbus_gpio_controller_func *); 96 int fdtbus_register_regulator_controller(device_t, int, 97 const struct fdtbus_regulator_controller_func *); 98 99 int fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *); 100 int fdtbus_get_phandle(int, const char *); 101 i2c_tag_t fdtbus_get_i2c_tag(int); 102 void * fdtbus_intr_establish(int, u_int, int, int, 103 int (*func)(void *), void *arg); 104 void fdtbus_intr_disestablish(int, void *); 105 bool fdtbus_intr_str(int, u_int, char *, size_t); 106 struct fdtbus_gpio_pin *fdtbus_gpio_acquire(int, const char *, int); 107 void fdtbus_gpio_release(struct fdtbus_gpio_pin *); 108 int fdtbus_gpio_read(struct fdtbus_gpio_pin *); 109 void fdtbus_gpio_write(struct fdtbus_gpio_pin *, int); 110 struct fdtbus_regulator *fdtbus_regulator_acquire(int, const char *); 111 void fdtbus_regulator_release(struct fdtbus_regulator *); 112 int fdtbus_regulator_enable(struct fdtbus_regulator *); 113 int fdtbus_regulator_disable(struct fdtbus_regulator *); 114 115 bool fdtbus_set_data(const void *); 116 const void * fdtbus_get_data(void); 117 int fdtbus_phandle2offset(int); 118 int fdtbus_offset2phandle(int); 119 120 #endif /* _DEV_FDT_FDTVAR_H */ 121