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