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