Home | History | Annotate | Line # | Download | only in i2c
ddc.c revision 1.1.8.2
      1  1.1.8.2  tron /* $NetBSD: ddc.c,v 1.1.8.2 2006/05/24 15:50:08 tron Exp $ */
      2  1.1.8.2  tron 
      3  1.1.8.2  tron /*-
      4  1.1.8.2  tron  * Copyright (c) 2006 Itronix Inc.
      5  1.1.8.2  tron  * All rights reserved.
      6  1.1.8.2  tron  *
      7  1.1.8.2  tron  * Written by Garrett D'Amore for Itronix Inc.
      8  1.1.8.2  tron  *
      9  1.1.8.2  tron  * Redistribution and use in source and binary forms, with or without
     10  1.1.8.2  tron  * modification, are permitted provided that the following conditions
     11  1.1.8.2  tron  * are met:
     12  1.1.8.2  tron  * 1. Redistributions of source code must retain the above copyright
     13  1.1.8.2  tron  *    notice, this list of conditions and the following disclaimer.
     14  1.1.8.2  tron  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1.8.2  tron  *    notice, this list of conditions and the following disclaimer in the
     16  1.1.8.2  tron  *    documentation and/or other materials provided with the distribution.
     17  1.1.8.2  tron  * 3. The name of Itronix Inc. may not be used to endorse
     18  1.1.8.2  tron  *    or promote products derived from this software without specific
     19  1.1.8.2  tron  *    prior written permission.
     20  1.1.8.2  tron  *
     21  1.1.8.2  tron  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND ANY EXPRESS
     22  1.1.8.2  tron  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     23  1.1.8.2  tron  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1.8.2  tron  * ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
     25  1.1.8.2  tron  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1.8.2  tron  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     27  1.1.8.2  tron  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  1.1.8.2  tron  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  1.1.8.2  tron  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     30  1.1.8.2  tron  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     31  1.1.8.2  tron  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1.8.2  tron  */
     33  1.1.8.2  tron 
     34  1.1.8.2  tron #include <sys/cdefs.h>
     35  1.1.8.2  tron __KERNEL_RCSID(0, "$NetBSD: ddc.c,v 1.1.8.2 2006/05/24 15:50:08 tron Exp $");
     36  1.1.8.2  tron 
     37  1.1.8.2  tron #include <sys/param.h>
     38  1.1.8.2  tron #include <sys/systm.h>
     39  1.1.8.2  tron #include <sys/device.h>
     40  1.1.8.2  tron #include <sys/kernel.h>
     41  1.1.8.2  tron 
     42  1.1.8.2  tron #include <machine/bus.h>
     43  1.1.8.2  tron #include <dev/i2c/i2cvar.h>
     44  1.1.8.2  tron #include <dev/i2c/ddcreg.h>
     45  1.1.8.2  tron #include <dev/i2c/ddcvar.h>
     46  1.1.8.2  tron 
     47  1.1.8.2  tron /*
     48  1.1.8.2  tron  * VESA Display Data Channel I2C client, used to access EDID
     49  1.1.8.2  tron  * information.
     50  1.1.8.2  tron  *
     51  1.1.8.2  tron  * Note that this only supports DDC version 2, which uses normal I2C.
     52  1.1.8.2  tron  * The older DDCv1 standard used sync signaling to provide the I2C
     53  1.1.8.2  tron  * clock, and is typically not used on reasonably recent monitors.
     54  1.1.8.2  tron  */
     55  1.1.8.2  tron 
     56  1.1.8.2  tron struct ddc_softc {
     57  1.1.8.2  tron 	struct device	sc_dev;
     58  1.1.8.2  tron 	i2c_tag_t	sc_tag;
     59  1.1.8.2  tron 	int		sc_address;
     60  1.1.8.2  tron };
     61  1.1.8.2  tron 
     62  1.1.8.2  tron static int ddc_match(struct device *, struct cfdata *, void *);
     63  1.1.8.2  tron static void ddc_attach(struct device *, struct device *, void *);
     64  1.1.8.2  tron 
     65  1.1.8.2  tron CFATTACH_DECL(ddc, sizeof (struct ddc_softc),
     66  1.1.8.2  tron     ddc_match, ddc_attach, NULL, NULL);
     67  1.1.8.2  tron 
     68  1.1.8.2  tron static int
     69  1.1.8.2  tron ddc_match(struct device *parent, struct cfdata *cf, void *aux)
     70  1.1.8.2  tron {
     71  1.1.8.2  tron 	struct i2c_attach_args *ia = aux;
     72  1.1.8.2  tron 
     73  1.1.8.2  tron 	if (ia->ia_addr == DDC_ADDR)
     74  1.1.8.2  tron 		return 1;
     75  1.1.8.2  tron 	return 0;
     76  1.1.8.2  tron }
     77  1.1.8.2  tron 
     78  1.1.8.2  tron static void
     79  1.1.8.2  tron ddc_attach(struct device *parent, struct device *self, void *aux)
     80  1.1.8.2  tron {
     81  1.1.8.2  tron 	struct ddc_softc *sc = device_private(self);
     82  1.1.8.2  tron 	struct i2c_attach_args *ia = aux;
     83  1.1.8.2  tron 
     84  1.1.8.2  tron 	sc->sc_address = ia->ia_addr;
     85  1.1.8.2  tron 
     86  1.1.8.2  tron 	aprint_naive(": DDC\n");
     87  1.1.8.2  tron 	aprint_normal(": DDC\n");
     88  1.1.8.2  tron }
     89  1.1.8.2  tron 
     90  1.1.8.2  tron /* XXX: add cdev ops? */
     91  1.1.8.2  tron 
     92  1.1.8.2  tron int
     93  1.1.8.2  tron ddc_read_edid(i2c_tag_t tag, uint8_t *dest, size_t len)
     94  1.1.8.2  tron {
     95  1.1.8.2  tron 	uint8_t		wbuf[2];
     96  1.1.8.2  tron 
     97  1.1.8.2  tron 	if (iic_acquire_bus(tag, I2C_F_POLL) != 0)
     98  1.1.8.2  tron 		return -1;
     99  1.1.8.2  tron 
    100  1.1.8.2  tron 	wbuf[0] = DDC_EDID_START;	/* start address */
    101  1.1.8.2  tron 
    102  1.1.8.2  tron 	if (iic_exec(tag, I2C_OP_READ_WITH_STOP, DDC_ADDR, wbuf, 1, dest,
    103  1.1.8.2  tron 		len, I2C_F_POLL)) {
    104  1.1.8.2  tron 		iic_release_bus(tag, I2C_F_POLL);
    105  1.1.8.2  tron 		return -1;
    106  1.1.8.2  tron 	}
    107  1.1.8.2  tron 	iic_release_bus(tag, I2C_F_POLL);
    108  1.1.8.2  tron 	return 0;
    109  1.1.8.2  tron }
    110