Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b918120 authored by Florian Tobias Schandinat's avatar Florian Tobias Schandinat
Browse files

Merge branch 'viafb-aux' into viafb-next

parents 5b270d7b 5dc5f618
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -6,4 +6,7 @@ obj-$(CONFIG_FB_VIA) += viafb.o

viafb-y	:=viafbdev.o hw.o via_i2c.o dvi.o lcd.o ioctl.o accel.o \
	via_utility.o vt1636.o global.o tblDPASetting.o viamode.o \
	via-core.o via-gpio.o via_modesetting.o via_clock.o
	via-core.o via-gpio.o via_modesetting.o via_clock.o \
	via_aux.o via_aux_edid.o via_aux_vt1636.o via_aux_vt1632.o \
	via_aux_vt1631.o via_aux_vt1625.o via_aux_vt1622.o via_aux_vt1621.o \
	via_aux_sii164.o via_aux_ch7301.o
+88 −0
Original line number Diff line number Diff line
/*
 * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation;
 * either version 2, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
/*
 * infrastructure for devices connected via I2C
 */

#include <linux/slab.h>
#include "via_aux.h"


struct via_aux_bus *via_aux_probe(struct i2c_adapter *adap)
{
	struct via_aux_bus *bus;

	if (!adap)
		return NULL;

	bus = kmalloc(sizeof(*bus), GFP_KERNEL);
	if (!bus)
		return NULL;

	bus->adap = adap;
	INIT_LIST_HEAD(&bus->drivers);

	via_aux_edid_probe(bus);
	via_aux_vt1636_probe(bus);
	via_aux_vt1632_probe(bus);
	via_aux_vt1631_probe(bus);
	via_aux_vt1625_probe(bus);
	via_aux_vt1622_probe(bus);
	via_aux_vt1621_probe(bus);
	via_aux_sii164_probe(bus);
	via_aux_ch7301_probe(bus);

	return bus;
}

void via_aux_free(struct via_aux_bus *bus)
{
	struct via_aux_drv *pos, *n;

	if (!bus)
		return;

	list_for_each_entry_safe(pos, n, &bus->drivers, chain) {
		if (pos->cleanup)
			pos->cleanup(pos);

		list_del(&pos->chain);
		kfree(pos->data);
		kfree(pos);
	}

	kfree(bus);
}

const struct fb_videomode *via_aux_get_preferred_mode(struct via_aux_bus *bus)
{
	struct via_aux_drv *pos;
	const struct fb_videomode *mode = NULL;

	if (!bus)
		return NULL;

	list_for_each_entry(pos, &bus->drivers, chain) {
		if (pos->get_preferred_mode)
			mode = pos->get_preferred_mode(pos);
	}

	return mode;
}
+93 −0
Original line number Diff line number Diff line
/*
 * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation;
 * either version 2, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
/*
 * infrastructure for devices connected via I2C
 */

#ifndef __VIA_AUX_H__
#define __VIA_AUX_H__


#include <linux/list.h>
#include <linux/i2c.h>
#include <linux/fb.h>


struct via_aux_bus {
	struct i2c_adapter *adap;	/* the I2C device to access the bus */
	struct list_head drivers;	/* drivers for devices on this bus */
};

struct via_aux_drv {
	struct list_head chain;		/* chain to support multiple drivers */

	struct via_aux_bus *bus;	/* the I2C bus used */
	u8 addr;			/* the I2C slave address */

	const char *name;	/* human readable name of the driver */
	void *data;		/* private data of this driver */

	void (*cleanup)(struct via_aux_drv *drv);
	const struct fb_videomode* (*get_preferred_mode)
		(struct via_aux_drv *drv);
};


struct via_aux_bus *via_aux_probe(struct i2c_adapter *adap);
void via_aux_free(struct via_aux_bus *bus);
const struct fb_videomode *via_aux_get_preferred_mode(struct via_aux_bus *bus);


static inline bool via_aux_add(struct via_aux_drv *drv)
{
	struct via_aux_drv *data = kmalloc(sizeof(*data), GFP_KERNEL);

	if (!data)
		return false;

	*data = *drv;
	list_add_tail(&data->chain, &data->bus->drivers);
	return true;
}

static inline bool via_aux_read(struct via_aux_drv *drv, u8 start, u8 *buf,
	u8 len)
{
	struct i2c_msg msg[2] = {
		{.addr = drv->addr, .flags = 0, .len = 1, .buf = &start},
		{.addr = drv->addr, .flags = I2C_M_RD, .len = len, .buf = buf} };

	return i2c_transfer(drv->bus->adap, msg, 2) == 2;
}


/* probe functions of existing drivers - should only be called in via_aux.c */
void via_aux_ch7301_probe(struct via_aux_bus *bus);
void via_aux_edid_probe(struct via_aux_bus *bus);
void via_aux_sii164_probe(struct via_aux_bus *bus);
void via_aux_vt1636_probe(struct via_aux_bus *bus);
void via_aux_vt1632_probe(struct via_aux_bus *bus);
void via_aux_vt1631_probe(struct via_aux_bus *bus);
void via_aux_vt1625_probe(struct via_aux_bus *bus);
void via_aux_vt1622_probe(struct via_aux_bus *bus);
void via_aux_vt1621_probe(struct via_aux_bus *bus);


#endif /* __VIA_AUX_H__ */
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation;
 * either version 2, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
/*
 * driver for Chrontel CH7301 DVI Transmitter
 */

#include <linux/slab.h>
#include "via_aux.h"


static const char *name = "CH7301 DVI Transmitter";


static void probe(struct via_aux_bus *bus, u8 addr)
{
	struct via_aux_drv drv = {
		.bus	=	bus,
		.addr	=	addr,
		.name	=	name};
	u8 tmp;

	if (!via_aux_read(&drv, 0x4B, &tmp, 1) || tmp != 0x17)
		return;

	printk(KERN_INFO "viafb: Found %s at address 0x%x\n", name, addr);
	via_aux_add(&drv);
}

void via_aux_ch7301_probe(struct via_aux_bus *bus)
{
	probe(bus, 0x75);
	probe(bus, 0x76);
}
+97 −0
Original line number Diff line number Diff line
/*
 * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation;
 * either version 2, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
/*
 * generic EDID driver
 */

#include <linux/slab.h>
#include <linux/fb.h>
#include "via_aux.h"
#include "../edid.h"


static const char *name = "EDID";


static void query_edid(struct via_aux_drv *drv)
{
	struct fb_monspecs *spec = drv->data;
	unsigned char edid[EDID_LENGTH];
	bool valid = false;

	if (spec)
		fb_destroy_modedb(spec->modedb);
	else
		spec = kmalloc(sizeof(*spec), GFP_KERNEL);

	spec->version = spec->revision = 0;
	if (via_aux_read(drv, 0x00, edid, EDID_LENGTH)) {
		fb_edid_to_monspecs(edid, spec);
		valid = spec->version || spec->revision;
	}

	if (!valid) {
		kfree(spec);
		spec = NULL;
	} else
		printk(KERN_DEBUG "EDID: %s %s\n", spec->manufacturer, spec->monitor);

	drv->data = spec;
}

static const struct fb_videomode *get_preferred_mode(struct via_aux_drv *drv)
{
	struct fb_monspecs *spec = drv->data;
	int i;

	if (!spec || !spec->modedb || !(spec->misc & FB_MISC_1ST_DETAIL))
		return NULL;

	for (i = 0; i < spec->modedb_len; i++) {
		if (spec->modedb[i].flag & FB_MODE_IS_FIRST &&
			spec->modedb[i].flag & FB_MODE_IS_DETAILED)
			return &spec->modedb[i];
	}

	return NULL;
}

static void cleanup(struct via_aux_drv *drv)
{
	struct fb_monspecs *spec = drv->data;

	if (spec)
		fb_destroy_modedb(spec->modedb);
}

void via_aux_edid_probe(struct via_aux_bus *bus)
{
	struct via_aux_drv drv = {
		.bus	=	bus,
		.addr	=	0x50,
		.name	=	name,
		.cleanup	=	cleanup,
		.get_preferred_mode	=	get_preferred_mode};

	query_edid(&drv);

	/* as EDID devices can be connected/disconnected just add the driver */
	via_aux_add(&drv);
}
Loading