Lines Matching refs:dev
30 __FBSDID("$FreeBSD: releng/11.0/sys/dev/iicbus/iicoc.c 296137 2016-02-27 03:38:01Z jhibbits $");
43 #include <dev/iicbus/iiconf.h>
44 #include <dev/iicbus/iicbus.h>
45 #include <dev/iicbus/iicoc.h>
47 #include <dev/pci/pcireg.h>
48 #include <dev/pci/pcivar.h>
61 static int iicoc_start(device_t dev, u_char slave, int timeout);
62 static int iicoc_stop(device_t dev);
63 static int iicoc_read(device_t dev, char *buf,
65 static int iicoc_write(device_t dev, const char *buf,
67 static int iicoc_repeated_start(device_t dev, u_char slave, int timeout);
70 device_t dev; /* Self */
83 iicoc_dev_write(device_t dev, int reg, int value)
87 sc = device_get_softc(dev);
92 iicoc_dev_read(device_t dev, int reg)
97 sc = device_get_softc(dev);
103 iicoc_wait_on_status(device_t dev, uint8_t bit)
109 status = iicoc_dev_read(dev, OC_I2C_STATUS_REG);
116 iicoc_rd_cmd(device_t dev, uint8_t cmd)
120 iicoc_dev_write(dev, OC_I2C_CMD_REG, cmd);
121 if (iicoc_wait_on_status(dev, OC_STATUS_TIP) < 0) {
122 device_printf(dev, "read: Timeout waiting for TIP clear.\n");
125 data = iicoc_dev_read(dev, OC_I2C_DATA_REG);
130 iicoc_wr_cmd(device_t dev, uint8_t data, uint8_t cmd)
133 iicoc_dev_write(dev, OC_I2C_DATA_REG, data);
134 iicoc_dev_write(dev, OC_I2C_CMD_REG, cmd);
135 if (iicoc_wait_on_status(dev, OC_STATUS_TIP) < 0) {
136 device_printf(dev, "write: Timeout waiting for TIP clear.\n");
143 iicoc_wr_ack_cmd(device_t dev, uint8_t data, uint8_t cmd)
145 if (iicoc_wr_cmd(dev, data, cmd) < 0)
148 if (iicoc_dev_read(dev, OC_I2C_STATUS_REG) & OC_STATUS_NACK) {
149 device_printf(dev, "write: I2C command ACK Error.\n");
156 iicoc_init(device_t dev)
161 sc = device_get_softc(dev);
162 value = iicoc_dev_read(dev, OC_I2C_CTRL_REG);
163 iicoc_dev_write(dev, OC_I2C_CTRL_REG,
166 iicoc_dev_write(dev, OC_I2C_PRESCALE_LO_REG, value & 0xff);
167 iicoc_dev_write(dev, OC_I2C_PRESCALE_HI_REG, value >> 8);
168 value = iicoc_dev_read(dev, OC_I2C_CTRL_REG);
169 iicoc_dev_write(dev, OC_I2C_CTRL_REG, value | OC_CONTROL_EN);
171 value = iicoc_dev_read(dev, OC_I2C_CTRL_REG);
177 iicoc_probe(device_t dev)
181 sc = device_get_softc(dev);
182 if ((pci_get_vendor(dev) == 0x184e) &&
183 (pci_get_device(dev) == 0x1011)) {
187 device_set_desc(dev, "Netlogic XLP I2C Controller");
199 iicoc_attach(device_t dev)
204 sc = device_get_softc(dev);
205 bus = device_get_unit(dev);
207 sc->dev = dev;
210 sc->mem_res = bus_alloc_resource_anywhere(dev,
214 device_printf(dev, "Could not allocate bus resource.\n");
217 iicoc_init(dev);
218 sc->iicbus = device_add_child(dev, "iicbus", -1);
220 device_printf(dev, "Could not allocate iicbus instance.\n");
223 bus_generic_attach(dev);
229 iicoc_detach(device_t dev)
231 bus_generic_detach(dev);
232 device_delete_children(dev);
238 iicoc_start(device_t dev, u_char slave, int timeout)
243 sc = device_get_softc(dev);
248 if (iicoc_wait_on_status(dev, OC_STATUS_BUSY) < 0)
252 if (iicoc_wr_ack_cmd(dev, slave, OC_COMMAND_START)) {
253 device_printf(dev,
260 if (iicoc_dev_read(dev, OC_I2C_STATUS_REG) & OC_STATUS_AL) {
261 device_printf(dev, "I2C Bus Arbitration Lost, Aborting.\n");
269 iicoc_dev_write(dev, OC_I2C_CMD_REG, OC_COMMAND_STOP);
270 iicoc_wait_on_status(dev, OC_STATUS_BUSY); /* wait for idle */
276 iicoc_stop(device_t dev)
281 sc = device_get_softc(dev);
283 iicoc_dev_write(dev, OC_I2C_CMD_REG, OC_COMMAND_STOP);
284 iicoc_wait_on_status(dev, OC_STATUS_BUSY); /* wait for idle */
291 iicoc_write(device_t dev, const char *buf, int len,
299 if (iicoc_wr_ack_cmd(dev, value, OC_COMMAND_WRITE)) {
300 device_printf(dev, "I2C write slave offset failed.\n");
307 if (iicoc_wr_cmd(dev, value, OC_COMMAND_WRITE)) {
308 device_printf(dev, "I2C write data byte %d failed.\n",
321 iicoc_read(device_t dev, char *buf, int len, int *read, int last,
330 data = iicoc_rd_cmd(dev, cmd);
332 device_printf(dev,
347 iicoc_reset(device_t dev, u_char speed, u_char addr, u_char *oldadr)
352 sc = device_get_softc(dev);
354 error = iicoc_init(dev);
360 iicoc_repeated_start(device_t dev, u_char slave, int timeout)