Home | History | Annotate | Line # | Download | only in fdt
fdtvar.h revision 1.21
      1 /* $NetBSD: fdtvar.h,v 1.21 2017/06/29 17:04:17 jmcneill Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2015 Jared D. McNeill <jmcneill (at) 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 #include <sys/termios.h>
     35 
     36 #include <dev/i2c/i2cvar.h>
     37 #include <dev/clk/clk.h>
     38 
     39 #include <dev/clock_subr.h>
     40 
     41 #include <dev/ofw/openfirm.h>
     42 
     43 struct fdt_attach_args {
     44 	const char *faa_name;
     45 	bus_space_tag_t faa_bst;
     46 	bus_space_tag_t faa_a4x_bst;
     47 	bus_dma_tag_t faa_dmat;
     48 	int faa_phandle;
     49 	int faa_quiet;
     50 };
     51 
     52 /* flags for fdtbus_intr_establish */
     53 #define FDT_INTR_MPSAFE	__BIT(0)
     54 
     55 struct fdtbus_interrupt_controller_func {
     56 	void *	(*establish)(device_t, u_int *, int, int,
     57 			     int (*)(void *), void *);
     58 	void	(*disestablish)(device_t, void *);
     59 	bool	(*intrstr)(device_t, u_int *, char *, size_t);
     60 };
     61 
     62 struct fdtbus_i2c_controller_func {
     63 	i2c_tag_t (*get_tag)(device_t);
     64 };
     65 
     66 struct fdtbus_gpio_controller;
     67 
     68 struct fdtbus_gpio_pin {
     69 	struct fdtbus_gpio_controller *gp_gc;
     70 	void *gp_priv;
     71 };
     72 
     73 struct fdtbus_gpio_controller_func {
     74 	void *	(*acquire)(device_t, const void *, size_t, int);
     75 	void	(*release)(device_t, void *);
     76 	int	(*read)(device_t, void *, bool);
     77 	void	(*write)(device_t, void *, int, bool);
     78 };
     79 
     80 struct fdtbus_pinctrl_controller;
     81 
     82 struct fdtbus_pinctrl_pin {
     83 	struct fdtbus_pinctrl_controller *pp_pc;
     84 	void *pp_priv;
     85 };
     86 
     87 struct fdtbus_pinctrl_controller_func {
     88 	int (*set_config)(void *);
     89 };
     90 
     91 struct fdtbus_regulator_controller;
     92 
     93 struct fdtbus_regulator {
     94 	struct fdtbus_regulator_controller *reg_rc;
     95 };
     96 
     97 struct fdtbus_regulator_controller_func {
     98 	int	(*acquire)(device_t);
     99 	void	(*release)(device_t);
    100 	int	(*enable)(device_t, bool);
    101 	int	(*set_voltage)(device_t, u_int, u_int);
    102 	int	(*get_voltage)(device_t, u_int *);
    103 };
    104 
    105 struct fdtbus_clock_controller_func {
    106 	struct clk *	(*decode)(device_t, const void *, size_t);
    107 };
    108 
    109 struct fdtbus_reset_controller;
    110 
    111 struct fdtbus_reset {
    112 	struct fdtbus_reset_controller *rst_rc;
    113 	void *rst_priv;
    114 };
    115 
    116 struct fdtbus_reset_controller_func {
    117 	void *	(*acquire)(device_t, const void *, size_t);
    118 	void	(*release)(device_t, void *);
    119 	int	(*reset_assert)(device_t, void *);
    120 	int	(*reset_deassert)(device_t, void *);
    121 };
    122 
    123 struct fdtbus_dma_controller;
    124 
    125 struct fdtbus_dma {
    126 	struct fdtbus_dma_controller *dma_dc;
    127 	void *dma_priv;
    128 };
    129 
    130 enum fdtbus_dma_dir {
    131 	FDT_DMA_READ,		/* device -> memory */
    132 	FDT_DMA_WRITE		/* memory -> device */
    133 };
    134 
    135 struct fdtbus_dma_opt {
    136 	int opt_bus_width;		/* Bus width */
    137 	int opt_burst_len;		/* Burst length */
    138 	int opt_swap;			/* Enable data swapping */
    139 	int opt_dblbuf;			/* Enable double buffering */
    140 	int opt_wrap_len;		/* Address wrap-around window */
    141 };
    142 
    143 struct fdtbus_dma_req {
    144 	bus_dma_segment_t *dreq_segs;	/* Memory */
    145 	int dreq_nsegs;
    146 
    147 	bus_addr_t dreq_dev_phys;	/* Device */
    148 	int dreq_sel;			/* Device selector */
    149 
    150 	enum fdtbus_dma_dir dreq_dir;	/* Transfer direction */
    151 
    152 	int dreq_block_irq;		/* Enable IRQ at end of block */
    153 	int dreq_block_multi;		/* Enable multiple block transfers */
    154 	int dreq_flow;			/* Enable flow control */
    155 
    156 	struct fdtbus_dma_opt dreq_mem_opt;	/* Memory options */
    157 	struct fdtbus_dma_opt dreq_dev_opt;	/* Device options */
    158 };
    159 
    160 struct fdtbus_dma_controller_func {
    161 	void *	(*acquire)(device_t, const void *, size_t,
    162 			   void (*)(void *), void *);
    163 	void	(*release)(device_t, void *);
    164 	int	(*transfer)(device_t, void *, struct fdtbus_dma_req *);
    165 	void	(*halt)(device_t, void *);
    166 };
    167 
    168 struct fdtbus_power_controller;
    169 
    170 struct fdtbus_power_controller_func {
    171 	void 	(*reset)(device_t);
    172 	void	(*poweroff)(device_t);
    173 };
    174 
    175 struct fdtbus_phy_controller;
    176 
    177 struct fdtbus_phy {
    178 	struct fdtbus_phy_controller *phy_pc;
    179 	void *phy_priv;
    180 };
    181 
    182 struct fdtbus_phy_controller_func {
    183 	void *	(*acquire)(device_t, const void *, size_t);
    184 	void	(*release)(device_t, void *);
    185 	int	(*enable)(device_t, void *, bool);
    186 };
    187 
    188 struct fdt_console {
    189 	int	(*match)(int);
    190 	void	(*consinit)(struct fdt_attach_args *, u_int);
    191 };
    192 
    193 struct fdt_console_info {
    194 	const struct fdt_console *ops;
    195 };
    196 
    197 #define	_FDT_CONSOLE_REGISTER(name)	\
    198 	__link_set_add_rodata(fdt_consoles, __CONCAT(name,_consinfo));
    199 
    200 #define	FDT_CONSOLE(_name, _ops)					\
    201 static const struct fdt_console_info __CONCAT(_name,_consinfo) = {	\
    202 	.ops = (_ops)							\
    203 };									\
    204 _FDT_CONSOLE_REGISTER(_name)
    205 
    206 TAILQ_HEAD(fdt_conslist, fdt_console_info);
    207 
    208 int		fdtbus_register_interrupt_controller(device_t, int,
    209 		    const struct fdtbus_interrupt_controller_func *);
    210 int		fdtbus_register_i2c_controller(device_t, int,
    211 		    const struct fdtbus_i2c_controller_func *);
    212 int		fdtbus_register_gpio_controller(device_t, int,
    213 		    const struct fdtbus_gpio_controller_func *);
    214 int		fdtbus_register_pinctrl_config(void *, int,
    215 		    const struct fdtbus_pinctrl_controller_func *);
    216 int		fdtbus_register_regulator_controller(device_t, int,
    217 		    const struct fdtbus_regulator_controller_func *);
    218 int		fdtbus_register_clock_controller(device_t, int,
    219 		    const struct fdtbus_clock_controller_func *);
    220 int		fdtbus_register_reset_controller(device_t, int,
    221 		    const struct fdtbus_reset_controller_func *);
    222 int		fdtbus_register_dma_controller(device_t, int,
    223 		    const struct fdtbus_dma_controller_func *);
    224 int		fdtbus_register_power_controller(device_t, int,
    225 		    const struct fdtbus_power_controller_func *);
    226 int		fdtbus_register_phy_controller(device_t, int,
    227 		    const struct fdtbus_phy_controller_func *);
    228 
    229 int		fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
    230 int		fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
    231 int		fdtbus_get_phandle(int, const char *);
    232 int		fdtbus_get_phandle_from_native(int);
    233 i2c_tag_t	fdtbus_get_i2c_tag(int);
    234 void *		fdtbus_intr_establish(int, u_int, int, int,
    235 		    int (*func)(void *), void *arg);
    236 void		fdtbus_intr_disestablish(int, void *);
    237 bool		fdtbus_intr_str(int, u_int, char *, size_t);
    238 struct fdtbus_gpio_pin *fdtbus_gpio_acquire(int, const char *, int);
    239 void		fdtbus_gpio_release(struct fdtbus_gpio_pin *);
    240 int		fdtbus_gpio_read(struct fdtbus_gpio_pin *);
    241 void		fdtbus_gpio_write(struct fdtbus_gpio_pin *, int);
    242 int		fdtbus_gpio_read_raw(struct fdtbus_gpio_pin *);
    243 void		fdtbus_gpio_write_raw(struct fdtbus_gpio_pin *, int);
    244 int		fdtbus_pinctrl_set_config_index(int, u_int);
    245 int		fdtbus_pinctrl_set_config(int, const char *);
    246 struct fdtbus_regulator *fdtbus_regulator_acquire(int, const char *);
    247 void		fdtbus_regulator_release(struct fdtbus_regulator *);
    248 int		fdtbus_regulator_enable(struct fdtbus_regulator *);
    249 int		fdtbus_regulator_disable(struct fdtbus_regulator *);
    250 int		fdtbus_regulator_set_voltage(struct fdtbus_regulator *,
    251 		    u_int, u_int);
    252 int		fdtbus_regulator_get_voltage(struct fdtbus_regulator *,
    253 		    u_int *);
    254 
    255 struct fdtbus_dma *fdtbus_dma_get(int, const char *, void (*)(void *), void *);
    256 struct fdtbus_dma *fdtbus_dma_get_index(int, u_int, void (*)(void *),
    257 		    void *);
    258 void		fdtbus_dma_put(struct fdtbus_dma *);
    259 int		fdtbus_dma_transfer(struct fdtbus_dma *,
    260 		    struct fdtbus_dma_req *);
    261 void		fdtbus_dma_halt(struct fdtbus_dma *);
    262 
    263 struct clk *	fdtbus_clock_get(int, const char *);
    264 struct clk *	fdtbus_clock_get_index(int, u_int);
    265 
    266 struct fdtbus_reset *fdtbus_reset_get(int, const char *);
    267 struct fdtbus_reset *fdtbus_reset_get_index(int, u_int);
    268 void		fdtbus_reset_put(struct fdtbus_reset *);
    269 int		fdtbus_reset_assert(struct fdtbus_reset *);
    270 int		fdtbus_reset_deassert(struct fdtbus_reset *);
    271 
    272 struct fdtbus_phy *fdtbus_phy_get(int, const char *);
    273 struct fdtbus_phy *fdtbus_phy_get_index(int, u_int);
    274 void		fdtbus_phy_put(struct fdtbus_phy *);
    275 int		fdtbus_phy_enable(struct fdtbus_phy *, bool);
    276 
    277 int		fdtbus_todr_attach(device_t, int, todr_chip_handle_t);
    278 
    279 void		fdtbus_power_reset(void);
    280 void		fdtbus_power_poweroff(void);
    281 
    282 bool		fdtbus_set_data(const void *);
    283 const void *	fdtbus_get_data(void);
    284 int		fdtbus_phandle2offset(int);
    285 int		fdtbus_offset2phandle(int);
    286 bool		fdtbus_get_path(int, char *, size_t);
    287 
    288 const struct fdt_console *fdtbus_get_console(void);
    289 
    290 const char *	fdtbus_get_stdout_path(void);
    291 int		fdtbus_get_stdout_phandle(void);
    292 int		fdtbus_get_stdout_speed(void);
    293 tcflag_t	fdtbus_get_stdout_flags(void);
    294 
    295 bool		fdtbus_status_okay(int);
    296 
    297 int		fdtbus_print(void *, const char *);
    298 
    299 #endif /* _DEV_FDT_FDTVAR_H */
    300