xref: /netbsd-src/sys/dev/fdt/display_timing.c (revision c502e5635e67430cbf4e0f42a62b0373f16f5f77)
1*c502e563Sjmcneill /* $NetBSD: display_timing.c,v 1.1 2017/06/03 14:48:02 jmcneill Exp $ */
2*c502e563Sjmcneill 
3*c502e563Sjmcneill /*-
4*c502e563Sjmcneill  * Copyright (c) 2017 Jared McNeill <jmcneill@invisible.ca>
5*c502e563Sjmcneill  * All rights reserved.
6*c502e563Sjmcneill  *
7*c502e563Sjmcneill  * Redistribution and use in source and binary forms, with or without
8*c502e563Sjmcneill  * modification, are permitted provided that the following conditions
9*c502e563Sjmcneill  * are met:
10*c502e563Sjmcneill  * 1. Redistributions of source code must retain the above copyright
11*c502e563Sjmcneill  *    notice, this list of conditions and the following disclaimer.
12*c502e563Sjmcneill  * 2. Redistributions in binary form must reproduce the above copyright
13*c502e563Sjmcneill  *    notice, this list of conditions and the following disclaimer in the
14*c502e563Sjmcneill  *    documentation and/or other materials provided with the distribution.
15*c502e563Sjmcneill  *
16*c502e563Sjmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17*c502e563Sjmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18*c502e563Sjmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*c502e563Sjmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20*c502e563Sjmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21*c502e563Sjmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22*c502e563Sjmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23*c502e563Sjmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24*c502e563Sjmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*c502e563Sjmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*c502e563Sjmcneill  * SUCH DAMAGE.
27*c502e563Sjmcneill  */
28*c502e563Sjmcneill 
29*c502e563Sjmcneill #include <sys/cdefs.h>
30*c502e563Sjmcneill __KERNEL_RCSID(0, "$NetBSD: display_timing.c,v 1.1 2017/06/03 14:48:02 jmcneill Exp $");
31*c502e563Sjmcneill 
32*c502e563Sjmcneill #include <sys/param.h>
33*c502e563Sjmcneill #include <sys/systm.h>
34*c502e563Sjmcneill #include <sys/device.h>
35*c502e563Sjmcneill #include <sys/kmem.h>
36*c502e563Sjmcneill #include <sys/bus.h>
37*c502e563Sjmcneill 
38*c502e563Sjmcneill #include <dev/fdt/fdtvar.h>
39*c502e563Sjmcneill #include <dev/fdt/display_timing.h>
40*c502e563Sjmcneill 
41*c502e563Sjmcneill #define	GETPROP(n, v)	\
42*c502e563Sjmcneill 	of_getprop_uint32(phandle, (n), (v))
43*c502e563Sjmcneill 
44*c502e563Sjmcneill int
display_timing_parse(int phandle,struct display_timing * timing)45*c502e563Sjmcneill display_timing_parse(int phandle, struct display_timing *timing)
46*c502e563Sjmcneill {
47*c502e563Sjmcneill 	if (GETPROP("clock-frequency", &timing->clock_freq) ||
48*c502e563Sjmcneill 	    GETPROP("hactive", &timing->hactive) ||
49*c502e563Sjmcneill 	    GETPROP("vactive", &timing->vactive) ||
50*c502e563Sjmcneill 	    GETPROP("hfront-porch", &timing->hfront_porch) ||
51*c502e563Sjmcneill 	    GETPROP("hback-porch", &timing->hback_porch) ||
52*c502e563Sjmcneill 	    GETPROP("hsync-len", &timing->hsync_len) ||
53*c502e563Sjmcneill 	    GETPROP("vfront-porch", &timing->vfront_porch) ||
54*c502e563Sjmcneill 	    GETPROP("vback-porch", &timing->vback_porch) ||
55*c502e563Sjmcneill 	    GETPROP("vsync-len", &timing->vsync_len))
56*c502e563Sjmcneill 		return EINVAL;
57*c502e563Sjmcneill 
58*c502e563Sjmcneill 	return 0;
59*c502e563Sjmcneill }
60