iiconf.c (e3c42ad8097161a15da0d08118ec5d525b763dc1) iiconf.c (422d05da14fe063e5d187d81a328fa7b362d069f)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 1998 Nicolas Souchu
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

--- 123 unchanged lines hidden (view full) ---

132 *
133 * Allocate the device to perform transfers.
134 *
135 * how : IIC_WAIT or IIC_DONTWAIT
136 */
137int
138iicbus_request_bus(device_t bus, device_t dev, int how)
139{
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 1998 Nicolas Souchu
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

--- 123 unchanged lines hidden (view full) ---

132 *
133 * Allocate the device to perform transfers.
134 *
135 * how : IIC_WAIT or IIC_DONTWAIT
136 */
137int
138iicbus_request_bus(device_t bus, device_t dev, int how)
139{
140 struct iic_reqbus_data reqdata;
140 struct iicbus_softc *sc = (struct iicbus_softc *)device_get_softc(bus);
141 int error = 0;
142
143 IICBUS_LOCK(sc);
144
145 for (;;) {
146 if (sc->owner == NULL)
147 break;

--- 22 unchanged lines hidden (view full) ---

170 /*
171 * Drop the lock around the call to the bus driver, it
172 * should be allowed to sleep in the IIC_WAIT case.
173 * Drivers might also need to grab locks that would
174 * cause a LOR if our lock is held.
175 */
176 IICBUS_UNLOCK(sc);
177 /* Ask the underlying layers if the request is ok */
141 struct iicbus_softc *sc = (struct iicbus_softc *)device_get_softc(bus);
142 int error = 0;
143
144 IICBUS_LOCK(sc);
145
146 for (;;) {
147 if (sc->owner == NULL)
148 break;

--- 22 unchanged lines hidden (view full) ---

171 /*
172 * Drop the lock around the call to the bus driver, it
173 * should be allowed to sleep in the IIC_WAIT case.
174 * Drivers might also need to grab locks that would
175 * cause a LOR if our lock is held.
176 */
177 IICBUS_UNLOCK(sc);
178 /* Ask the underlying layers if the request is ok */
179 reqdata.dev = dev;
180 reqdata.bus = bus;
181 reqdata.flags = how | IIC_REQBUS_DEV;
178 error = IICBUS_CALLBACK(device_get_parent(bus),
182 error = IICBUS_CALLBACK(device_get_parent(bus),
179 IIC_REQUEST_BUS, (caddr_t)&how);
183 IIC_REQUEST_BUS, (caddr_t)&reqdata);
180 IICBUS_LOCK(sc);
181
182 if (error != 0) {
183 sc->owner = NULL;
184 sc->owncount = 0;
185 wakeup_one(sc);
186 device_unbusy(sc->busydev);
187 }

--- 8 unchanged lines hidden (view full) ---

196/*
197 * iicbus_release_bus()
198 *
199 * Release the device allocated with iicbus_request_dev()
200 */
201int
202iicbus_release_bus(device_t bus, device_t dev)
203{
184 IICBUS_LOCK(sc);
185
186 if (error != 0) {
187 sc->owner = NULL;
188 sc->owncount = 0;
189 wakeup_one(sc);
190 device_unbusy(sc->busydev);
191 }

--- 8 unchanged lines hidden (view full) ---

200/*
201 * iicbus_release_bus()
202 *
203 * Release the device allocated with iicbus_request_dev()
204 */
205int
206iicbus_release_bus(device_t bus, device_t dev)
207{
208 struct iic_reqbus_data reqdata;
204 struct iicbus_softc *sc = (struct iicbus_softc *)device_get_softc(bus);
205
206 IICBUS_LOCK(sc);
207
208 if (sc->owner != dev) {
209 IICBUS_UNLOCK(sc);
210 return (IIC_EBUSBSY);
211 }
212
213 if (--sc->owncount == 0) {
214 /* Drop the lock while informing the low-level driver. */
215 IICBUS_UNLOCK(sc);
209 struct iicbus_softc *sc = (struct iicbus_softc *)device_get_softc(bus);
210
211 IICBUS_LOCK(sc);
212
213 if (sc->owner != dev) {
214 IICBUS_UNLOCK(sc);
215 return (IIC_EBUSBSY);
216 }
217
218 if (--sc->owncount == 0) {
219 /* Drop the lock while informing the low-level driver. */
220 IICBUS_UNLOCK(sc);
216 IICBUS_CALLBACK(device_get_parent(bus), IIC_RELEASE_BUS, NULL);
221 reqdata.dev = dev;
222 reqdata.bus = bus;
223 reqdata.flags = IIC_REQBUS_DEV;
224 IICBUS_CALLBACK(device_get_parent(bus), IIC_RELEASE_BUS,
225 (caddr_t)&reqdata);
217 IICBUS_LOCK(sc);
218 sc->owner = NULL;
219 wakeup_one(sc);
220 device_unbusy(sc->busydev);
221 }
222 IICBUS_UNLOCK(sc);
223 return (0);
224}

--- 362 unchanged lines hidden ---
226 IICBUS_LOCK(sc);
227 sc->owner = NULL;
228 wakeup_one(sc);
229 device_unbusy(sc->busydev);
230 }
231 IICBUS_UNLOCK(sc);
232 return (0);
233}

--- 362 unchanged lines hidden ---