Home | History | Annotate | Line # | Download | only in ti
      1 /* $NetBSD: ti_lcdc.h,v 1.3 2021/12/19 12:44:57 riastradh Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2019 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 _ARM_TI_TI_LCDC_H
     30 #define _ARM_TI_TI_LCDC_H
     31 
     32 #include <sys/workqueue.h>
     33 
     34 #include <drm/drm_encoder.h>
     35 #include <drm/drm_fb_helper.h>
     36 #include <drm/drm_gem_cma_helper.h>
     37 
     38 #define DRIVER_AUTHOR		"NetBSD"
     39 
     40 #define DRIVER_NAME		"tilcdc"
     41 #define DRIVER_DESC		"TI LCDC"
     42 #define DRIVER_DATE		"20191103"
     43 
     44 #define DRIVER_MAJOR		1
     45 #define DRIVER_MINOR		0
     46 #define DRIVER_PATCHLEVEL	0
     47 
     48 struct tilcdc_softc;
     49 struct tilcdc_framebuffer;
     50 
     51 struct tilcdc_vblank {
     52 	void			*priv;
     53 	void			(*enable_vblank)(void *);
     54 	void			(*disable_vblank)(void *);
     55 	uint32_t		(*get_vblank_counter)(void *);
     56 };
     57 
     58 struct tilcdc_crtc {
     59 	struct drm_crtc		base;
     60 	struct tilcdc_softc	*sc;
     61 };
     62 
     63 struct tilcdc_encoder {
     64 	struct drm_encoder	base;
     65 	struct tilcdc_softc	*sc;
     66 };
     67 
     68 struct tilcdc_softc {
     69 	device_t		sc_dev;
     70 	struct drm_device	*sc_ddev;
     71 
     72 	bus_space_tag_t		sc_bst;
     73 	bus_space_handle_t	sc_bsh;
     74 	bus_dma_tag_t		sc_dmat;
     75 
     76 	struct clk		*sc_clk;
     77 	int			sc_phandle;
     78 
     79 	struct lwp			*sc_task_thread;
     80 	SIMPLEQ_HEAD(, tilcdc_drm_task)	sc_tasks;
     81 	struct workqueue		*sc_task_wq;
     82 
     83 	bool			sc_dev_registered;
     84 
     85 	struct tilcdc_crtc	sc_crtc;
     86 	struct tilcdc_encoder	sc_encoder;
     87 	struct tilcdc_vblank	sc_vbl;
     88 
     89 	struct fdt_device_ports	sc_ports;
     90 };
     91 
     92 struct tilcdc_framebuffer {
     93 	struct drm_framebuffer	base;
     94 	struct drm_gem_cma_object *obj;
     95 };
     96 
     97 struct tilcdc_fbdev {
     98 	struct drm_fb_helper	helper;
     99 };
    100 
    101 struct tilcdcfb_attach_args {
    102 	struct drm_device	*tfa_drm_dev;
    103 	struct drm_fb_helper	*tfa_fb_helper;
    104 	struct drm_fb_helper_surface_size tfa_fb_sizes;
    105 	bus_space_tag_t		tfa_fb_bst;
    106 	bus_dma_tag_t		tfa_fb_dmat;
    107 	uint32_t		tfa_fb_linebytes;
    108 };
    109 
    110 struct tilcdc_drm_task {
    111 	union {
    112 		SIMPLEQ_ENTRY(tilcdc_drm_task)	queue;
    113 		struct work			work;
    114 	}		tdt_u;
    115 	void		(*tdt_fn)(struct tilcdc_drm_task *);
    116 };
    117 
    118 #define tilcdc_private(ddev)		(ddev)->dev_private
    119 #define	to_tilcdc_framebuffer(x)	container_of(x, struct tilcdc_framebuffer, base)
    120 #define	to_tilcdc_crtc(x)		container_of(x, struct tilcdc_crtc, base)
    121 
    122 #define	RD4(sc, reg)			\
    123 	bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
    124 #define	WR4(sc, reg, val)		\
    125 	bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
    126 
    127 void	tilcdc_task_init(struct tilcdc_drm_task *,
    128 	    void (*)(struct tilcdc_drm_task *));
    129 void	tilcdc_task_schedule(device_t, struct tilcdc_drm_task *);
    130 
    131 #endif /* _ARM_TI_TI_LCDC_H */
    132