Module Name: src Committed By: macallan Date: Thu Mar 31 00:01:08 UTC 2011
Modified Files: src/sys/arch/sgimips/dev: crmfb.c crmfbreg.h Log Message: add DDC2 support. Not too useful yet. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/sys/arch/sgimips/dev/crmfb.c cvs rdiff -u -r1.12 -r1.13 src/sys/arch/sgimips/dev/crmfbreg.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/sgimips/dev/crmfb.c diff -u src/sys/arch/sgimips/dev/crmfb.c:1.29 src/sys/arch/sgimips/dev/crmfb.c:1.30 --- src/sys/arch/sgimips/dev/crmfb.c:1.29 Wed Mar 30 19:16:35 2011 +++ src/sys/arch/sgimips/dev/crmfb.c Thu Mar 31 00:01:08 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: crmfb.c,v 1.29 2011/03/30 19:16:35 macallan Exp $ */ +/* $NetBSD: crmfb.c,v 1.30 2011/03/31 00:01:08 macallan Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca> @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: crmfb.c,v 1.29 2011/03/30 19:16:35 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crmfb.c,v 1.30 2011/03/31 00:01:08 macallan Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -54,6 +54,12 @@ #include <dev/rasops/rasops.h> #include <dev/wscons/wsdisplay_vconsvar.h> +#include <dev/i2c/i2cvar.h> +#include <dev/i2c/i2c_bitbang.h> +#include <dev/i2c/ddcvar.h> +#include <dev/videomode/videomode.h> +#include <dev/videomode/edidvar.h> + #include <arch/sgimips/dev/crmfbreg.h> /*#define CRMFB_DEBUG*/ @@ -120,6 +126,8 @@ struct crmfb_softc { device_t sc_dev; struct vcons_data sc_vd; + struct i2c_controller sc_i2c; + int sc_dir; bus_space_tag_t sc_iot; bus_space_handle_t sc_ioh; @@ -182,6 +190,33 @@ static void crmfb_cursor(void *, int, int, int); static void crmfb_putchar(void *, int, int, u_int, long); +/* I2C glue */ +static int crmfb_i2c_acquire_bus(void *, int); +static void crmfb_i2c_release_bus(void *, int); +static int crmfb_i2c_send_start(void *, int); +static int crmfb_i2c_send_stop(void *, int); +static int crmfb_i2c_initiate_xfer(void *, i2c_addr_t, int); +static int crmfb_i2c_read_byte(void *, uint8_t *, int); +static int crmfb_i2c_write_byte(void *, uint8_t, int); + +/* I2C bitbang glue */ +static void crmfb_i2cbb_set_bits(void *, uint32_t); +static void crmfb_i2cbb_set_dir(void *, uint32_t); +static uint32_t crmfb_i2cbb_read(void *); + +static const struct i2c_bitbang_ops crmfb_i2cbb_ops = { + crmfb_i2cbb_set_bits, + crmfb_i2cbb_set_dir, + crmfb_i2cbb_read, + { + CRMFB_I2C_SDA, + CRMFB_I2C_SCL, + 0, + 1 + } +}; +static void crmfb_setup_ddc(struct crmfb_softc *); + CFATTACH_DECL_NEW(crmfb, sizeof(struct crmfb_softc), crmfb_match, crmfb_attach, NULL, NULL); @@ -223,6 +258,8 @@ if (rv) panic("crmfb_attach: can't map rendering engine"); + //crmfb_setup_ddc(sc); + /* determine mode configured by firmware */ d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_HCMAP); sc->sc_width = (d >> CRMFB_VT_HCMAP_ON_SHIFT) & 0xfff; @@ -351,6 +388,7 @@ #ifdef CRMFB_DEBUG crmfb_test_mte(sc); #endif + crmfb_setup_ddc(sc); return; } @@ -1435,3 +1473,108 @@ } } } + +static void +crmfb_setup_ddc(struct crmfb_softc *sc) +{ + int i; + char edid_data[128]; + struct edid_info ei; + + memset(edid_data, 0, 128); + sc->sc_i2c.ic_cookie = sc; + sc->sc_i2c.ic_acquire_bus = crmfb_i2c_acquire_bus; + sc->sc_i2c.ic_release_bus = crmfb_i2c_release_bus; + sc->sc_i2c.ic_send_start = crmfb_i2c_send_start; + sc->sc_i2c.ic_send_stop = crmfb_i2c_send_stop; + sc->sc_i2c.ic_initiate_xfer = crmfb_i2c_initiate_xfer; + sc->sc_i2c.ic_read_byte = crmfb_i2c_read_byte; + sc->sc_i2c.ic_write_byte = crmfb_i2c_write_byte; + sc->sc_i2c.ic_exec = NULL; + i = 0; + while (edid_data[1] == 0 && i++ < 10) + ddc_read_edid(&sc->sc_i2c, edid_data, 128); + if (i > 1) + aprint_debug_dev(sc->sc_dev, + "had to try %d times to get EDID data\n", i); + if (i < 11) { + edid_parse(edid_data, &ei); + edid_print(&ei); + } +} + +/* I2C bitbanging */ +static void +crmfb_i2cbb_set_bits(void *cookie, uint32_t bits) +{ + struct crmfb_softc *sc = cookie; + + bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_I2C_VGA, bits ^ 3); +} + +static void +crmfb_i2cbb_set_dir(void *cookie, uint32_t dir) +{ + + /* Nothing to do */ +} + +static uint32_t +crmfb_i2cbb_read(void *cookie) +{ + struct crmfb_softc *sc = cookie; + + return bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_I2C_VGA) ^ 3; +} + +/* higher level I2C stuff */ +static int +crmfb_i2c_acquire_bus(void *cookie, int flags) +{ + + /* private bus */ + return 0; +} + +static void +crmfb_i2c_release_bus(void *cookie, int flags) +{ + + /* private bus */ +} + +static int +crmfb_i2c_send_start(void *cookie, int flags) +{ + + return i2c_bitbang_send_start(cookie, flags, &crmfb_i2cbb_ops); +} + +static int +crmfb_i2c_send_stop(void *cookie, int flags) +{ + + return i2c_bitbang_send_stop(cookie, flags, &crmfb_i2cbb_ops); +} + +static int +crmfb_i2c_initiate_xfer(void *cookie, i2c_addr_t addr, int flags) +{ + + return i2c_bitbang_initiate_xfer(cookie, addr, flags, + &crmfb_i2cbb_ops); +} + +static int +crmfb_i2c_read_byte(void *cookie, uint8_t *valp, int flags) +{ + + return i2c_bitbang_read_byte(cookie, valp, flags, &crmfb_i2cbb_ops); +} + +static int +crmfb_i2c_write_byte(void *cookie, uint8_t val, int flags) +{ + + return i2c_bitbang_write_byte(cookie, val, flags, &crmfb_i2cbb_ops); +} Index: src/sys/arch/sgimips/dev/crmfbreg.h diff -u src/sys/arch/sgimips/dev/crmfbreg.h:1.12 src/sys/arch/sgimips/dev/crmfbreg.h:1.13 --- src/sys/arch/sgimips/dev/crmfbreg.h:1.12 Wed Mar 30 18:25:31 2011 +++ src/sys/arch/sgimips/dev/crmfbreg.h Thu Mar 31 00:01:08 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: crmfbreg.h,v 1.12 2011/03/30 18:25:31 macallan Exp $ */ +/* $NetBSD: crmfbreg.h,v 1.13 2011/03/31 00:01:08 macallan Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca> @@ -74,8 +74,8 @@ #define CRMFB_DOTCLOCK_TUPI 0x02000000 /* ? */ #define CRMFB_I2C_VGA 0x00000008 -#define CRMFB_I2C_SDA 0x00000001 -#define CRMFB_I2C_SCL 0x00000002 +#define CRMFB_I2C_SDA 0x00000001 /* these bits are */ +#define CRMFB_I2C_SCL 0x00000002 /* low active */ #define CRMFB_SYSCLK 0x0000000c