iicbus_if.m revision 276278
1139749Simp#- 238774Snsouch# Copyright (c) 1998 Nicolas Souchu 338774Snsouch# All rights reserved. 438774Snsouch# 538774Snsouch# Redistribution and use in source and binary forms, with or without 638774Snsouch# modification, are permitted provided that the following conditions 738774Snsouch# are met: 838774Snsouch# 1. Redistributions of source code must retain the above copyright 938774Snsouch# notice, this list of conditions and the following disclaimer. 1038774Snsouch# 2. Redistributions in binary form must reproduce the above copyright 1138774Snsouch# notice, this list of conditions and the following disclaimer in the 1238774Snsouch# documentation and/or other materials provided with the distribution. 1338774Snsouch# 1438774Snsouch# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1538774Snsouch# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1638774Snsouch# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1738774Snsouch# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1838774Snsouch# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1938774Snsouch# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2038774Snsouch# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2138774Snsouch# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2238774Snsouch# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2338774Snsouch# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2438774Snsouch# SUCH DAMAGE. 2538774Snsouch# 2650477Speter# $FreeBSD: stable/10/sys/dev/iicbus/iicbus_if.m 276278 2014-12-27 02:37:52Z ian $ 2738774Snsouch# 2838774Snsouch 2959093Sdfr#include <sys/bus.h> 30160372Simp#include <dev/iicbus/iic.h> 3159093Sdfr 3241012SnsouchINTERFACE iicbus; 3338774Snsouch 34276278SianCODE { 35276278Sian static u_int 36276278Sian iicbus_default_frequency(device_t bus, u_char speed) 37276278Sian { 38276278Sian 39276278Sian return (100000); 40276278Sian } 41276278Sian}; 42276278Sian 4338774Snsouch# 4440782Snsouch# Interpret interrupt 4538774Snsouch# 4638774SnsouchMETHOD int intr { 4738774Snsouch device_t dev; 4838774Snsouch int event; 4938774Snsouch char *buf; 5038774Snsouch}; 5138774Snsouch 5238774Snsouch# 5340782Snsouch# iicbus callback 5440782Snsouch# 5540782SnsouchMETHOD int callback { 5640782Snsouch device_t dev; 5740782Snsouch int index; 5840782Snsouch caddr_t data; 5940782Snsouch}; 6040782Snsouch 6140782Snsouch# 6238774Snsouch# Send REPEATED_START condition 6338774Snsouch# 6438774SnsouchMETHOD int repeated_start { 6538774Snsouch device_t dev; 6638774Snsouch u_char slave; 6740782Snsouch int timeout; 6838774Snsouch}; 6938774Snsouch 7038774Snsouch# 7138774Snsouch# Send START condition 7238774Snsouch# 7338774SnsouchMETHOD int start { 7438774Snsouch device_t dev; 7538774Snsouch u_char slave; 7640782Snsouch int timeout; 7738774Snsouch}; 7838774Snsouch 7938774Snsouch# 8038774Snsouch# Send STOP condition 8138774Snsouch# 8238774SnsouchMETHOD int stop { 8338774Snsouch device_t dev; 8438774Snsouch}; 8538774Snsouch 8638774Snsouch# 8738774Snsouch# Read from I2C bus 8838774Snsouch# 8938774SnsouchMETHOD int read { 9038774Snsouch device_t dev; 9138774Snsouch char *buf; 9238774Snsouch int len; 9338774Snsouch int *bytes; 9440782Snsouch int last; 9540782Snsouch int delay; 9638774Snsouch}; 9738774Snsouch 9838774Snsouch# 9938774Snsouch# Write to the I2C bus 10038774Snsouch# 10138774SnsouchMETHOD int write { 10238774Snsouch device_t dev; 103164901Simp const char *buf; 10438774Snsouch int len; 10538774Snsouch int *bytes; 10640782Snsouch int timeout; 10738774Snsouch}; 10838774Snsouch 10938774Snsouch# 11038774Snsouch# Reset I2C bus 11138774Snsouch# 11238774SnsouchMETHOD int reset { 11338774Snsouch device_t dev; 11438774Snsouch u_char speed; 11540782Snsouch u_char addr; 11640782Snsouch u_char *oldaddr; 11738774Snsouch}; 118160372Simp 119160372Simp# 120160372Simp# Generalized Read/Write interface 121160372Simp# 122160372SimpMETHOD int transfer { 123160372Simp device_t dev; 124160372Simp struct iic_msg *msgs; 125160372Simp uint32_t nmsgs; 126160372Simp}; 127276278Sian 128276278Sian# 129276278Sian# Return the frequency in Hz for the bus running at the given 130276278Sian# symbolic speed. Only the IIC_SLOW speed has meaning, it is always 131276278Sian# 100KHz. The UNKNOWN, FAST, and FASTEST rates all map to the 132276278Sian# configured bus frequency, or 100KHz when not otherwise configured. 133276278Sian# 134276278SianMETHOD u_int get_frequency { 135276278Sian device_t dev; 136276278Sian u_char speed; 137276278Sian} DEFAULT iicbus_default_frequency; 138