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