FreeBSD kernel IICBUS device code
iicoc_pci.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2003-2012 Broadcom Corporation
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD$");
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/module.h>
36#include <sys/bus.h>
37#include <sys/lock.h>
38#include <sys/mutex.h>
39#include <sys/rman.h>
40
41#include <dev/iicbus/iicbus.h>
42#include <dev/iicbus/iiconf.h>
43
44#include <dev/pci/pcireg.h>
45#include <dev/pci/pcivar.h>
46
47#include "iicbus_if.h"
48#include "iicoc.h"
49
50static int
52{
53 struct iicoc_softc *sc;
54
55 sc = device_get_softc(dev);
56 device_delete_children(dev);
57 bus_generic_detach(dev);
58 bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res);
59 mtx_destroy(&sc->sc_mtx);
60
61 return (0);
62}
63
64/*
65 * We add all the devices which we know about.
66 * The generic attach routine will attach them if they are alive.
67 */
68static int
70{
71 int bus;
72 struct iicoc_softc *sc;
73
74 sc = device_get_softc(dev);
75 bus = device_get_unit(dev);
76
77 sc->dev = dev;
78 mtx_init(&sc->sc_mtx, "iicoc", "iicoc", MTX_DEF);
79 sc->mem_rid = 0;
80 sc->mem_res = bus_alloc_resource_anywhere(dev,
81 SYS_RES_MEMORY, &sc->mem_rid, 0x100, RF_ACTIVE);
82
83 if (sc->mem_res == NULL) {
84 device_printf(dev, "Could not allocate bus resource.\n");
85 return (-1);
86 }
88 sc->iicbus = device_add_child(dev, "iicbus", -1);
89 if (sc->iicbus == NULL) {
90 device_printf(dev, "Could not allocate iicbus instance.\n");
91 bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid,
92 sc->mem_res);
93 mtx_destroy(&sc->sc_mtx);
94 return (-1);
95 }
96 bus_generic_attach(dev);
97
98 return (0);
99}
100
101static int
103{
104 struct iicoc_softc *sc;
105
106 sc = device_get_softc(dev);
107 if ((pci_get_vendor(dev) == 0x184e) &&
108 (pci_get_device(dev) == 0x1011)) {
110 sc->i2cfreq = XLP_I2C_FREQ;
111 sc->reg_shift = 2;
112 device_set_desc(dev, "Netlogic XLP I2C Controller");
113 return (BUS_PROBE_DEFAULT);
114 }
115 return (ENXIO);
116}
117
118static device_method_t iicoc_methods[] = {
119 /* device interface */
120 DEVMETHOD(device_probe, iicoc_probe),
121 DEVMETHOD(device_attach, iicoc_attach),
122 DEVMETHOD(device_detach, iicoc_detach),
123
124 /* iicbus interface */
125 DEVMETHOD(iicbus_callback, iicbus_null_callback),
128 DEVMETHOD(iicbus_stop, iicoc_iicbus_stop),
131 DEVMETHOD(iicbus_read, iicoc_iicbus_read),
133
134 DEVMETHOD_END
135};
136
137static driver_t iicoc_driver = {
138 "iicoc",
140 sizeof(struct iicoc_softc),
141};
142
int iicbus_null_callback(device_t dev, int index, caddr_t data)
Definition: iicbus.c:287
devclass_t iicoc_devclass
Definition: iicoc.c:51
int iicoc_iicbus_write(device_t dev, const char *buf, int len, int *sent, int timeout)
Definition: iicoc.c:218
int iicoc_iicbus_stop(device_t dev)
Definition: iicoc.c:204
int iicoc_iicbus_reset(device_t dev, u_char speed, u_char addr, u_char *oldadr)
Definition: iicoc.c:274
int iicoc_iicbus_repeated_start(device_t dev, u_char slave, int timeout)
Definition: iicoc.c:197
int iicoc_init(device_t dev)
Definition: iicoc.c:130
int iicoc_iicbus_start(device_t dev, u_char slave, int timeout)
Definition: iicoc.c:190
int iicoc_iicbus_read(device_t dev, char *buf, int len, int *read, int last, int delay)
Definition: iicoc.c:248
#define XLP_I2C_FREQ
Definition: iicoc.h:47
#define XLP_I2C_CLKFREQ
Definition: iicoc.h:46
static int iicoc_probe(device_t dev)
Definition: iicoc_pci.c:102
static driver_t iicoc_driver
Definition: iicoc_pci.c:137
DRIVER_MODULE(iicoc, pci, iicoc_driver, iicoc_devclass, 0, 0)
static int iicoc_detach(device_t dev)
Definition: iicoc_pci.c:51
__FBSDID("$FreeBSD$")
static device_method_t iicoc_methods[]
Definition: iicoc_pci.c:118
static int iicoc_attach(device_t dev)
Definition: iicoc_pci.c:69
int iicbus_transfer(device_t bus, struct iic_msg *msgs, uint32_t nmsgs)
Definition: iiconf.c:442
int iicbus_read(device_t bus, char *buf, int len, int *read, int last, int delay)
Definition: iiconf.c:339
int iicbus_write(device_t bus, const char *buf, int len, int *sent, int timeout)
Definition: iiconf.c:321
int iicbus_stop(device_t bus)
Definition: iiconf.c:298
int iicbus_repeated_start(device_t bus, u_char slave, int timeout)
Definition: iiconf.c:276
int iicbus_start(device_t bus, u_char slave, int timeout)
Definition: iiconf.c:254
int iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
Definition: iiconf.c:469
#define iicbus_reset(bus, speed, addr, oldaddr)
Definition: iiconf.h:135
device_t dev
Definition: ofw_iicbus_if.m:38
struct mtx sc_mtx
Definition: iicoc.h:90
device_t iicbus
Definition: iicoc.h:89
u_int clockfreq
Definition: iicoc.h:83
u_int reg_shift
Definition: iicoc.h:82
struct resource * mem_res
Definition: iicoc.h:85
int mem_rid
Definition: iicoc.h:86
u_int i2cfreq
Definition: iicoc.h:84
device_t dev
Definition: iicoc.h:81