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