Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
0004  */
0005 /*
0006  * generic EDID driver
0007  */
0008 
0009 #include <linux/slab.h>
0010 #include <linux/fb.h>
0011 #include "via_aux.h"
0012 #include "../edid.h"
0013 
0014 
0015 static const char *name = "EDID";
0016 
0017 
0018 static void query_edid(struct via_aux_drv *drv)
0019 {
0020     struct fb_monspecs *spec = drv->data;
0021     unsigned char edid[EDID_LENGTH];
0022     bool valid = false;
0023 
0024     if (spec) {
0025         fb_destroy_modedb(spec->modedb);
0026     } else {
0027         spec = kmalloc(sizeof(*spec), GFP_KERNEL);
0028         if (!spec)
0029             return;
0030     }
0031 
0032     spec->version = spec->revision = 0;
0033     if (via_aux_read(drv, 0x00, edid, EDID_LENGTH)) {
0034         fb_edid_to_monspecs(edid, spec);
0035         valid = spec->version || spec->revision;
0036     }
0037 
0038     if (!valid) {
0039         kfree(spec);
0040         spec = NULL;
0041     } else
0042         printk(KERN_DEBUG "EDID: %s %s\n", spec->manufacturer, spec->monitor);
0043 
0044     drv->data = spec;
0045 }
0046 
0047 static const struct fb_videomode *get_preferred_mode(struct via_aux_drv *drv)
0048 {
0049     struct fb_monspecs *spec = drv->data;
0050     int i;
0051 
0052     if (!spec || !spec->modedb || !(spec->misc & FB_MISC_1ST_DETAIL))
0053         return NULL;
0054 
0055     for (i = 0; i < spec->modedb_len; i++) {
0056         if (spec->modedb[i].flag & FB_MODE_IS_FIRST &&
0057             spec->modedb[i].flag & FB_MODE_IS_DETAILED)
0058             return &spec->modedb[i];
0059     }
0060 
0061     return NULL;
0062 }
0063 
0064 static void cleanup(struct via_aux_drv *drv)
0065 {
0066     struct fb_monspecs *spec = drv->data;
0067 
0068     if (spec)
0069         fb_destroy_modedb(spec->modedb);
0070 }
0071 
0072 void via_aux_edid_probe(struct via_aux_bus *bus)
0073 {
0074     struct via_aux_drv drv = {
0075         .bus    =   bus,
0076         .addr   =   0x50,
0077         .name   =   name,
0078         .cleanup    =   cleanup,
0079         .get_preferred_mode =   get_preferred_mode};
0080 
0081     query_edid(&drv);
0082 
0083     /* as EDID devices can be connected/disconnected just add the driver */
0084     via_aux_add(&drv);
0085 }