LCOV - code coverage report
Current view: top level - dev/i2c - i2c.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 39 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: i2c.c,v 1.16 2015/03/14 03:38:47 jsg Exp $    */
       2             : /*      $NetBSD: i2c.c,v 1.1 2003/09/30 00:35:31 thorpej Exp $  */
       3             : 
       4             : /*
       5             :  * Copyright (c) 2003 Wasabi Systems, Inc.
       6             :  * All rights reserved.
       7             :  *
       8             :  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
       9             :  *
      10             :  * Redistribution and use in source and binary forms, with or without
      11             :  * modification, are permitted provided that the following conditions
      12             :  * are met:
      13             :  * 1. Redistributions of source code must retain the above copyright
      14             :  *    notice, this list of conditions and the following disclaimer.
      15             :  * 2. Redistributions in binary form must reproduce the above copyright
      16             :  *    notice, this list of conditions and the following disclaimer in the
      17             :  *    documentation and/or other materials provided with the distribution.
      18             :  * 3. All advertising materials mentioning features or use of this software
      19             :  *    must display the following acknowledgement:
      20             :  *      This product includes software developed for the NetBSD Project by
      21             :  *      Wasabi Systems, Inc.
      22             :  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
      23             :  *    or promote products derived from this software without specific prior
      24             :  *    written permission.
      25             :  *
      26             :  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
      27             :  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
      28             :  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
      29             :  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
      30             :  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      31             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
      32             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
      33             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      34             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
      35             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      36             :  * POSSIBILITY OF SUCH DAMAGE.
      37             :  */
      38             : 
      39             : #include <sys/param.h>
      40             : #include <sys/systm.h>
      41             : #include <sys/device.h>
      42             : #include <sys/event.h>
      43             : 
      44             : #define _I2C_PRIVATE
      45             : #include <dev/i2c/i2cvar.h>
      46             : 
      47             : #define IICCF_ADDR      0
      48             : #define IICCF_SIZE      1
      49             : 
      50             : struct iic_softc {
      51             :         struct device sc_dev;
      52             :         i2c_tag_t sc_tag;
      53             : };
      54             : 
      55             : int     iic_match(struct device *, void *, void *);
      56             : void    iic_attach(struct device *, struct device *, void *);
      57             : int     iic_search(struct device *, void *, void *);
      58             : 
      59             : struct cfattach iic_ca = {
      60             :         sizeof (struct iic_softc),
      61             :         iic_match,
      62             :         iic_attach
      63             : };
      64             : 
      65             : struct cfdriver iic_cd = {
      66             :         NULL, "iic", DV_DULL
      67             : };
      68             : 
      69             : int
      70           0 : iicbus_print(void *aux, const char *pnp)
      71             : {
      72           0 :         struct i2cbus_attach_args *iba = aux;
      73             : 
      74           0 :         if (pnp != NULL)
      75           0 :                 printf("%s at %s", iba->iba_name, pnp);
      76             : 
      77           0 :         return (UNCONF);
      78             : }
      79             : 
      80             : int
      81           0 : iic_print(void *aux, const char *pnp)
      82             : {
      83           0 :         struct i2c_attach_args *ia = aux;
      84             : 
      85           0 :         if (pnp != NULL)
      86           0 :                 printf("\"%s\" at %s", ia->ia_name, pnp);
      87           0 :         printf(" addr 0x%x", ia->ia_addr);
      88             : 
      89           0 :         return (UNCONF);
      90             : }
      91             : 
      92             : int
      93           0 : iic_search(struct device *parent, void *arg, void *aux)
      94             : {
      95           0 :         struct iic_softc *sc = (void *) parent;
      96           0 :         struct cfdata *cf = arg;
      97           0 :         struct i2c_attach_args ia;
      98             : 
      99           0 :         if (cf->cf_loc[IICCF_ADDR] != -1) {
     100           0 :                 memset(&ia, 0, sizeof(ia));
     101           0 :                 ia.ia_tag = sc->sc_tag;
     102           0 :                 ia.ia_addr = cf->cf_loc[IICCF_ADDR];
     103           0 :                 ia.ia_size = cf->cf_loc[IICCF_SIZE];
     104           0 :                 ia.ia_name = "unknown";
     105             : 
     106           0 :                 if (cf->cf_attach->ca_match(parent, cf, &ia) > 0)
     107           0 :                         config_attach(parent, cf, &ia, iic_print);
     108             :         }
     109           0 :         return (0);
     110           0 : }
     111             : 
     112             : int
     113           0 : iic_match(struct device *parent, void *arg, void *aux)
     114             : {
     115           0 :         struct cfdata *cf = arg;
     116           0 :         struct i2cbus_attach_args *iba = aux;
     117             : 
     118             :         /* Just make sure we're looking for i2c. */
     119           0 :         return (strcmp(iba->iba_name, cf->cf_driver->cd_name) == 0);
     120             : }
     121             : 
     122             : void
     123           0 : iic_attach(struct device *parent, struct device *self, void *aux)
     124             : {
     125           0 :         struct iic_softc *sc = (void *) self;
     126           0 :         struct i2cbus_attach_args *iba = aux;
     127             : 
     128           0 :         sc->sc_tag = iba->iba_tag;
     129             : 
     130           0 :         printf("\n");
     131             : 
     132             :         /*
     133             :          * Attach all i2c devices described in the kernel
     134             :          * configuration file.
     135             :          */
     136           0 :         config_search(iic_search, self, NULL);
     137             : 
     138             :         /*
     139             :          * Scan for known device signatures.
     140             :          */
     141           0 :         if (iba->iba_bus_scan)
     142           0 :                 (iba->iba_bus_scan)(self, aux, iba->iba_bus_scan_arg);
     143             :         else
     144           0 :                 iic_scan(self, aux);
     145           0 : }

Generated by: LCOV version 1.13