xref: /netbsd-src/sys/dev/wscons/wsdisplay_util.c (revision 814a779807a6d31c293aff50a5fc6824fcb72030)
1*814a7798Sthorpej /*	$NetBSD: wsdisplay_util.c,v 1.3 2020/06/11 02:39:31 thorpej Exp $ */
28db9d73aSmacallan 
38db9d73aSmacallan /*-
4719e71a8Smacallan  * Copyright (c) 2011 Michael Lorenz
58db9d73aSmacallan  * All rights reserved.
68db9d73aSmacallan  *
78db9d73aSmacallan  * Redistribution and use in source and binary forms, with or without
88db9d73aSmacallan  * modification, are permitted provided that the following conditions
98db9d73aSmacallan  * are met:
108db9d73aSmacallan  * 1. Redistributions of source code must retain the above copyright
118db9d73aSmacallan  *    notice, this list of conditions and the following disclaimer.
128db9d73aSmacallan  * 2. Redistributions in binary form must reproduce the above copyright
138db9d73aSmacallan  *    notice, this list of conditions and the following disclaimer in the
148db9d73aSmacallan  *    documentation and/or other materials provided with the distribution.
158db9d73aSmacallan  *
168db9d73aSmacallan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
178db9d73aSmacallan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
188db9d73aSmacallan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
198db9d73aSmacallan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
208db9d73aSmacallan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
218db9d73aSmacallan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
228db9d73aSmacallan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
238db9d73aSmacallan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
248db9d73aSmacallan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
258db9d73aSmacallan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
268db9d73aSmacallan  * POSSIBILITY OF SUCH DAMAGE.
278db9d73aSmacallan  */
288db9d73aSmacallan 
298db9d73aSmacallan /* some utility functions for use with wsdisplay */
30719e71a8Smacallan 
318db9d73aSmacallan #include <sys/param.h>
328db9d73aSmacallan #include <sys/stdint.h>
338db9d73aSmacallan #include <sys/systm.h>
348db9d73aSmacallan #include <sys/buf.h>
358db9d73aSmacallan #include <sys/device.h>
368db9d73aSmacallan #include <dev/cons.h>
378db9d73aSmacallan 
388db9d73aSmacallan #include <dev/wscons/wsdisplayvar.h>
39719e71a8Smacallan #include <dev/rasops/rasops.h>
408db9d73aSmacallan #include <dev/wscons/wsconsio.h>
418db9d73aSmacallan 
428db9d73aSmacallan int
wsdisplayio_get_edid(device_t dev,struct wsdisplayio_edid_info * d)438db9d73aSmacallan wsdisplayio_get_edid(device_t dev, struct wsdisplayio_edid_info *d)
448db9d73aSmacallan {
458db9d73aSmacallan 	prop_data_t edid_data;
468db9d73aSmacallan 	int edid_size;
478db9d73aSmacallan 
488db9d73aSmacallan 	edid_data = prop_dictionary_get(device_properties(dev), "EDID");
498db9d73aSmacallan 	if (edid_data != NULL) {
508db9d73aSmacallan 		edid_size = prop_data_size(edid_data);
518db9d73aSmacallan 		/* less than 128 bytes is bogus */
528db9d73aSmacallan 		if (edid_size < 128)
538db9d73aSmacallan 			return ENODEV;
548db9d73aSmacallan 		d->data_size = edid_size;
558db9d73aSmacallan 		if (d->buffer_size < edid_size)
568db9d73aSmacallan 			return EAGAIN;
57*814a7798Sthorpej 		return copyout(prop_data_value(edid_data),
588db9d73aSmacallan 			       d->edid_data, edid_size);
598db9d73aSmacallan 	}
608db9d73aSmacallan 	return ENODEV;
618db9d73aSmacallan }
62719e71a8Smacallan 
63719e71a8Smacallan /* convenience function to fill in stuff from rasops_info */
64719e71a8Smacallan int
wsdisplayio_get_fbinfo(struct rasops_info * ri,struct wsdisplayio_fbinfo * fbi)65719e71a8Smacallan wsdisplayio_get_fbinfo(struct rasops_info *ri, struct wsdisplayio_fbinfo *fbi)
66719e71a8Smacallan {
67719e71a8Smacallan 	fbi->fbi_width = ri->ri_width;
68719e71a8Smacallan 	fbi->fbi_height = ri->ri_height;
69719e71a8Smacallan 	fbi->fbi_stride = ri->ri_stride;
70719e71a8Smacallan 	fbi->fbi_bitsperpixel = ri->ri_depth;
71719e71a8Smacallan 	if (ri->ri_depth > 8) {
72719e71a8Smacallan 		fbi->fbi_pixeltype = WSFB_RGB;
73719e71a8Smacallan 		fbi->fbi_subtype.fbi_rgbmasks.red_offset = ri->ri_rpos;
74719e71a8Smacallan 		fbi->fbi_subtype.fbi_rgbmasks.red_size = ri->ri_rnum;
75719e71a8Smacallan 		fbi->fbi_subtype.fbi_rgbmasks.green_offset = ri->ri_gpos;
76719e71a8Smacallan 		fbi->fbi_subtype.fbi_rgbmasks.green_size = ri->ri_gnum;
77719e71a8Smacallan 		fbi->fbi_subtype.fbi_rgbmasks.blue_offset = ri->ri_bpos;
78719e71a8Smacallan 		fbi->fbi_subtype.fbi_rgbmasks.blue_size = ri->ri_bnum;
79719e71a8Smacallan 		fbi->fbi_subtype.fbi_rgbmasks.alpha_offset = 0;
80719e71a8Smacallan 		fbi->fbi_subtype.fbi_rgbmasks.alpha_size = 0;
81719e71a8Smacallan 	} else {
82719e71a8Smacallan 		fbi->fbi_pixeltype = WSFB_CI;
83719e71a8Smacallan 		fbi->fbi_subtype.fbi_cmapinfo.cmap_entries = 1 << ri->ri_depth;
84719e71a8Smacallan 	}
85719e71a8Smacallan 	fbi->fbi_flags = 0;
86719e71a8Smacallan 	fbi->fbi_fbsize = ri->ri_stride * ri->ri_height;
87719e71a8Smacallan 	fbi->fbi_fboffset = 0;
88719e71a8Smacallan 	return 0;
89719e71a8Smacallan }
90