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