Skip to contentSkip to conversation

viafb auxiliary device support

PATCH New Florian Tobias Schandinat 1 participant 4 messages Feb 14, 2012 Framebuffer layer

lore
Share & tools
lore
#0 lore raw

cover viafb auxiliary device support

Hi all,

this patch series aims to add infrastructure to viafb to support devices that are connected via I2C. Even before these patches viafb had support for some of these but no structure, instead ranging from a single file for a device to various places in the code writing to such devices, probably even sometimes without knowing that it is talking to the correct device.
This patch series adds just the infrastructure to add such devices and a few stub driver which print the name of the chips, if detected. Even this is quite useful for debugging or recruiting testers. The long term goal is to move all existing support for such devices in those drivers and extend them to whatever is required.
The chip detection aside the only user visible change is that if no viafb_mode/viafb_mode1 is given on startup the initial resolution is derived from EDID data, if present for the desired configuration.

Best regards,

Florian Tobias Schandinat

Florian Tobias Schandinat (3):
viafb: add auxiliary device management infrastructure
viafb: fix I2C emulation on GPIO ports
viafb: add initial EDID support

 drivers/video/via/Makefile         |    5 ++-
 drivers/video/via/via_aux.c        |   88 ++++++++++++++++++++++++++++++++
 drivers/video/via/via_aux.h        |   93 ++++++++++++++++++++++++++++++++++
 drivers/video/via/via_aux_ch7301.c |   50 ++++++++++++++++++
 drivers/video/via/via_aux_edid.c   |   97 ++++++++++++++++++++++++++++++++++++
 drivers/video/via/via_aux_sii164.c |   54 ++++++++++++++++++++
 drivers/video/via/via_aux_vt1621.c |   44 ++++++++++++++++
 drivers/video/via/via_aux_vt1622.c |   50 ++++++++++++++++++
 drivers/video/via/via_aux_vt1625.c |   50 ++++++++++++++++++
 drivers/video/via/via_aux_vt1631.c |   46 +++++++++++++++++
 drivers/video/via/via_aux_vt1632.c |   54 ++++++++++++++++++++
 drivers/video/via/via_aux_vt1636.c |   46 +++++++++++++++++
 drivers/video/via/via_i2c.c        |   10 +++-
 drivers/video/via/viafbdev.c       |   53 +++++++++++++++++---
 drivers/video/via/viafbdev.h       |    6 ++
 15 files changed, 736 insertions(+), 10 deletions(-)
 create mode 100644 drivers/video/via/via_aux.c
 create mode 100644 drivers/video/via/via_aux.h
 create mode 100644 drivers/video/via/via_aux_ch7301.c
 create mode 100644 drivers/video/via/via_aux_edid.c
 create mode 100644 drivers/video/via/via_aux_sii164.c
 create mode 100644 drivers/video/via/via_aux_vt1621.c
 create mode 100644 drivers/video/via/via_aux_vt1622.c
 create mode 100644 drivers/video/via/via_aux_vt1625.c
 create mode 100644 drivers/video/via/via_aux_vt1631.c
 create mode 100644 drivers/video/via/via_aux_vt1632.c
 create mode 100644 drivers/video/via/via_aux_vt1636.c
Signature · 1 line
1.7.9
#1 lore raw

PATCH 1/3 viafb: add auxiliary device management infrastructure

This patch adds the basic infrastructure and a few stub drivers for devices that are connected via I2C busses. The infrastructure will be used to replace and extend the support that is scattered throughout viafb. The stub drivers are not very useful yet but they show how the infrastructure works, provide information about the chips integrated into a system and maybe gather some testers as it would be very difficult for a single person to get a sane test environment.
The only thing this actually does is probing the I2C busses which will hopefully not cause any regressions.

---
 drivers/video/via/Makefile         |    5 ++-
 drivers/video/via/via_aux.c        |   68 ++++++++++++++++++++++++++++
 drivers/video/via/via_aux.h        |   87 ++++++++++++++++++++++++++++++++++++
 drivers/video/via/via_aux_ch7301.c |   50 ++++++++++++++++++++
 drivers/video/via/via_aux_edid.c   |   40 ++++++++++++++++
 drivers/video/via/via_aux_sii164.c |   54 ++++++++++++++++++++++
 drivers/video/via/via_aux_vt1621.c |   44 ++++++++++++++++++
 drivers/video/via/via_aux_vt1622.c |   50 ++++++++++++++++++++
 drivers/video/via/via_aux_vt1625.c |   50 ++++++++++++++++++++
 drivers/video/via/via_aux_vt1631.c |   46 +++++++++++++++++++
 drivers/video/via/via_aux_vt1632.c |   54 ++++++++++++++++++++++
 drivers/video/via/via_aux_vt1636.c |   46 +++++++++++++++++++
 drivers/video/via/viafbdev.c       |   27 +++++++++++
 drivers/video/via/viafbdev.h       |    6 +++
 14 files changed, 626 insertions(+), 1 deletions(-)
 create mode 100644 drivers/video/via/via_aux.c
 create mode 100644 drivers/video/via/via_aux.h
 create mode 100644 drivers/video/via/via_aux_ch7301.c
 create mode 100644 drivers/video/via/via_aux_edid.c
 create mode 100644 drivers/video/via/via_aux_sii164.c
 create mode 100644 drivers/video/via/via_aux_vt1621.c
 create mode 100644 drivers/video/via/via_aux_vt1622.c
 create mode 100644 drivers/video/via/via_aux_vt1625.c
 create mode 100644 drivers/video/via/via_aux_vt1631.c
 create mode 100644 drivers/video/via/via_aux_vt1632.c
 create mode 100644 drivers/video/via/via_aux_vt1636.c
drivers/video/via/Makefile +4 -1
index 5108136..159f26e 100644
@@ -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
drivers/video/via/via_aux.c new file +68 -0

68 lines not on this page · raw message

drivers/video/via/via_aux.h new file +87 -0

87 lines not on this page · raw message

drivers/video/via/via_aux_ch7301.c new file +50 -0

50 lines not on this page · raw message

drivers/video/via/via_aux_edid.c new file +40 -0
new file mode 100644
index 0000000..547bff5
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2011 Florian Tobias Schandinat <[email protected]>
+ *
+ * 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 "via_aux.h"
+
+
+static const char *name = "EDID";
+
+
+void via_aux_edid_probe(struct via_aux_bus *bus)
+{
+	struct via_aux_drv drv = {
+		.bus	=	bus,
+		.addr	=	0x50,
+		.name	=	name};
+
+	/* as EDID devices can be connected/disconnected just add the driver */
+	via_aux_add(&drv);
+}
drivers/video/via/via_aux_sii164.c new file +54 -0

54 lines not on this page · raw message

drivers/video/via/via_aux_vt1621.c new file +44 -0

44 lines not on this page · raw message

drivers/video/via/via_aux_vt1622.c new file +50 -0

50 lines not on this page · raw message

drivers/video/via/via_aux_vt1625.c new file +50 -0

50 lines not on this page · raw message

drivers/video/via/via_aux_vt1631.c new file +46 -0

46 lines not on this page · raw message

drivers/video/via/via_aux_vt1632.c new file +54 -0

54 lines not on this page · raw message

drivers/video/via/via_aux_vt1636.c new file +46 -0

46 lines not on this page · raw message

drivers/video/via/viafbdev.c +27 -0
index a13c258..6d5b649 100644
@@ -24,6 +24,7 @@
 #include <linux/slab.h>
 #include <linux/stat.h>
 #include <linux/via-core.h>
+#include <linux/via_i2c.h>
 #include <asm/olpc.h>
 
 #define _MASTER_FILE
@@ -1729,6 +1730,29 @@ static struct viafb_pm_hooks viafb_fb_pm_hooks = {
 
 #endif
 
+static void __devinit i2c_bus_probe(struct viafb_shared *shared)
+{
+	/* should be always CRT */
+	printk(KERN_INFO "viafb: Probing I2C bus 0x26\n");
+	shared->i2c_26 = via_aux_probe(viafb_find_i2c_adapter(VIA_PORT_26));
+
+	/* seems to be usually DVP1 */
+	printk(KERN_INFO "viafb: Probing I2C bus 0x31\n");
+	shared->i2c_31 = via_aux_probe(viafb_find_i2c_adapter(VIA_PORT_31));
+
+	/* FIXME: what is this? */
+	printk(KERN_INFO "viafb: Probing I2C bus 0x2C\n");
+	shared->i2c_2C = via_aux_probe(viafb_find_i2c_adapter(VIA_PORT_2C));
+
+	printk(KERN_INFO "viafb: Finished I2C bus probing");
+}
+
+static void i2c_bus_free(struct viafb_shared *shared)
+{
+	via_aux_free(shared->i2c_26);
+	via_aux_free(shared->i2c_31);
+	via_aux_free(shared->i2c_2C);
+}
 
 int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
 {
@@ -1762,6 +1786,7 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
 		&viaparinfo->shared->lvds_setting_info2;
 	viaparinfo->chip_info = &viaparinfo->shared->chip_info;
 
+	i2c_bus_probe(viaparinfo->shared);
 	if (viafb_dual_fb)
 		viafb_SAMM_ON = 1;
 	parse_lcd_port();
@@ -1915,6 +1940,7 @@ out_fb1_release:
 	if (viafbinfo1)
 		framebuffer_release(viafbinfo1);
 out_fb_release:
+	i2c_bus_free(viaparinfo->shared);
 	framebuffer_release(viafbinfo);
 	return rc;
 }
@@ -1927,6 +1953,7 @@ void __devexit via_fb_pci_remove(struct pci_dev *pdev)
 	if (viafb_dual_fb)
 		unregister_framebuffer(viafbinfo1);
 	viafb_remove_proc(viaparinfo->shared);
+	i2c_bus_free(viaparinfo->shared);
 	framebuffer_release(viafbinfo);
 	if (viafb_dual_fb)
 		framebuffer_release(viafbinfo1);
drivers/video/via/viafbdev.h +6 -0
index d944063..f6b2ddf 100644
@@ -26,6 +26,7 @@
 #include <linux/fb.h>
 #include <linux/spinlock.h>
 
+#include "via_aux.h"
 #include "ioctl.h"
 #include "share.h"
 #include "chip.h"
@@ -48,6 +49,11 @@ struct viafb_shared {
 	struct proc_dir_entry *iga2_proc_entry;
 	struct viafb_dev *vdev;			/* Global dev info */
 
+	/* I2C busses that may have auxiliary devices */
+	struct via_aux_bus *i2c_26;
+	struct via_aux_bus *i2c_31;
+	struct via_aux_bus *i2c_2C;
+
 	/* All the information will be needed to set engine */
 	struct tmds_setting_information tmds_setting_info;
 	struct lvds_setting_information lvds_setting_info;
Signature · 1 line
1.7.9
#2 lore raw

PATCH 2/3 viafb: fix I2C emulation on GPIO ports

In reply to Florian Tobias Schandinat

This patch fixes the I2C emulation on GPIO ports by enabling it (software controlled) and disabling the output on a GPIO line before reading it.

---
 drivers/video/via/via_i2c.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
drivers/video/via/via_i2c.c +8 -2
index 78f1405..dd53058 100644
@@ -51,7 +51,7 @@ static void via_i2c_setscl(void *data, int state)
 		val |= 0x01;
 		break;
 	case VIA_PORT_GPIO:
-		val |= 0x80;
+		val |= 0x82;
 		break;
 	default:
 		printk(KERN_ERR "viafb_i2c: specify wrong i2c type.\n");
@@ -67,6 +67,9 @@ static int via_i2c_getscl(void *data)
 	int ret = 0;
 
 	spin_lock_irqsave(&i2c_vdev->reg_lock, flags);
+	if (adap_data->type == VIA_PORT_GPIO)
+		via_write_reg_mask(adap_data->io_port, adap_data->ioport_index,
+			0, 0x80);
 	if (via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x08)
 		ret = 1;
 	spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags);
@@ -80,6 +83,9 @@ static int via_i2c_getsda(void *data)
 	int ret = 0;
 
 	spin_lock_irqsave(&i2c_vdev->reg_lock, flags);
+	if (adap_data->type == VIA_PORT_GPIO)
+		via_write_reg_mask(adap_data->io_port, adap_data->ioport_index,
+			0, 0x40);
 	if (via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x04)
 		ret = 1;
 	spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags);
@@ -103,7 +109,7 @@ static void via_i2c_setsda(void *data, int state)
 		val |= 0x01;
 		break;
 	case VIA_PORT_GPIO:
-		val |= 0x40;
+		val |= 0x42;
 		break;
 	default:
 		printk(KERN_ERR "viafb_i2c: specify wrong i2c type.\n");
Signature · 1 line
1.7.9
#3 lore raw

PATCH 3/3 viafb: add initial EDID support

In reply to Florian Tobias Schandinat

This patch adds support for using EDID data on CRT and DVP1 for initial configuration if viafb_mode or viafb_mode1 are not present.

---
 drivers/video/via/via_aux.c      |   20 +++++++++++++
 drivers/video/via/via_aux.h      |    6 ++++
 drivers/video/via/via_aux_edid.c |   59 +++++++++++++++++++++++++++++++++++++-
 drivers/video/via/viafbdev.c     |   26 ++++++++++++----
 4 files changed, 103 insertions(+), 8 deletions(-)
drivers/video/via/via_aux.c +20 -0
index e728b9b..4a0a55c 100644
@@ -60,9 +60,29 @@ void via_aux_free(struct via_aux_bus *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;
+}
drivers/video/via/via_aux.h +6 -0
index 5a4867a..a8de3f0 100644
@@ -27,6 +27,7 @@
 
 #include <linux/list.h>
 #include <linux/i2c.h>
+#include <linux/fb.h>
 
 
 struct via_aux_bus {
@@ -42,11 +43,16 @@ struct via_aux_drv {
 
 	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)
drivers/video/via/via_aux_edid.c +58 -1

76 lines not on this page · raw message

drivers/video/via/viafbdev.c +19 -7
index 6d5b649..4791165 100644
@@ -1671,12 +1671,23 @@ static void viafb_remove_proc(struct viafb_shared *shared)
 }
 #undef IS_VT1636
 
-static int parse_mode(const char *str, u32 *xres, u32 *yres)
+static int parse_mode(const char *str, u32 devices, u32 *xres, u32 *yres)
 {
+	const struct fb_videomode *mode = NULL;
 	char *ptr;
 
 	if (!str) {
-		if (machine_is_olpc()) {
+		if (devices == VIA_CRT)
+			mode = via_aux_get_preferred_mode(
+				viaparinfo->shared->i2c_26);
+		else if (devices == VIA_DVP1)
+			mode = via_aux_get_preferred_mode(
+				viaparinfo->shared->i2c_31);
+
+		if (mode) {
+			*xres = mode->xres;
+			*yres = mode->yres;
+		} else if (machine_is_olpc()) {
 			*xres = 1200;
 			*yres = 900;
 		} else {
@@ -1829,10 +1840,11 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
 			viafb_second_size * 1024 * 1024;
 	}
 
-	parse_mode(viafb_mode, &default_xres, &default_yres);
+	parse_mode(viafb_mode, viaparinfo->shared->iga1_devices,
+		&default_xres, &default_yres);
 	if (viafb_SAMM_ON == 1)
-		parse_mode(viafb_mode1, &viafb_second_xres,
-			&viafb_second_yres);
+		parse_mode(viafb_mode1, viaparinfo->shared->iga2_devices,
+			&viafb_second_xres, &viafb_second_yres);
 
 	default_var.xres = default_xres;
 	default_var.yres = default_yres;
@@ -2060,9 +2072,9 @@ int __init viafb_init(void)
 	if (r < 0)
 		return r;
 #endif
-	if (parse_mode(viafb_mode, &dummy_x, &dummy_y)
+	if (parse_mode(viafb_mode, 0, &dummy_x, &dummy_y)
 		|| !viafb_get_best_mode(dummy_x, dummy_y, viafb_refresh)
-		|| parse_mode(viafb_mode1, &dummy_x, &dummy_y)
+		|| parse_mode(viafb_mode1, 0, &dummy_x, &dummy_y)
 		|| !viafb_get_best_mode(dummy_x, dummy_y, viafb_refresh1)
 		|| viafb_bpp < 0 || viafb_bpp > 32
 		|| viafb_bpp1 < 0 || viafb_bpp1 > 32
Signature · 1 line
1.7.9