/* * device_open - open the specified device. * * Even if the target driver does not have an open * routine, this function does not return an error. By * using this mechanism, an application can check whether * the specific device exists or not. The open mode * should be handled by an each device driver if it is * needed. */ int device_open(const char *name, int mode, struct device **devp) { struct devops *ops; struct device *dev; int error; sched_lock(); if ((dev = device_lookup(name)) == NULL) { sched_unlock(); return ENXIO; } error = device_reference(dev); if (error) { sched_unlock(); return error; } sched_unlock(); ops = dev->driver->devops; assert(ops->open != NULL); error = (*ops->open)(dev, mode); *devp = dev; device_release(dev); return error; }
int device_destroy(struct device *dev) { sched_lock(); if (!device_valid(dev)) { sched_unlock(); return ENODEV; } dev->active = 0; device_release(dev); sched_unlock(); return 0; }
/* * device_close - close a device. * * Even if the target driver does not have close routine, * this function does not return any errors. */ int device_close(struct device *dev) { struct devops *ops; int error; if ((error = device_reference(dev)) != 0) return error; ops = dev->driver->devops; assert(ops->close != NULL); error = (*ops->close)(dev); device_release(dev); return error; }
int device_write(struct device *dev, struct uio *uio, int ioflags) { struct devops *ops; int error; if ((error = device_reference(dev)) != 0) return error; ops = dev->driver->devops; assert(ops->write != NULL); error = (*ops->write)(dev, uio, ioflags); device_release(dev); return error; }
/* * device_ioctl - I/O control request. * * A command and its argument are completely device dependent. * The ioctl routine of each driver must validate the user buffer * pointed by the arg value. */ int device_ioctl(struct device *dev, u_long cmd, void *arg) { struct devops *ops; int error; if ((error = device_reference(dev)) != 0) return error; ops = dev->driver->devops; assert(ops->ioctl != NULL); error = (*ops->ioctl)(dev, cmd, arg); device_release(dev); return error; }
static int alias_device_set_state(struct device *dev, bool state) { struct alias_device *alias; alias = container_of(dev, struct alias_device, dev); if (!alias->dep.dev) return -1; if (state) return device_claim(&alias->dep); device_release(&alias->dep); if (alias->update) alias_set_device(alias, alias->new_dep.dev); return 0; }
void temperature_destroy(Temperature *temperature) { device_release(temperature->p); }
void industrial_quad_relay_destroy(IndustrialQuadRelay *industrial_quad_relay) { device_release(industrial_quad_relay->p); }
void multi_touch_destroy(MultiTouch *multi_touch) { device_release(multi_touch->p); }
void led_strip_destroy(LEDStrip *led_strip) { device_release(led_strip->p); }
void io16_destroy(IO16 *io16) { device_release(io16->p); }
void motion_detector_v2_destroy(MotionDetectorV2 *motion_detector_v2) { device_release(motion_detector_v2->p); }
void oled_128x64_destroy(OLED128x64 *oled_128x64) { device_release(oled_128x64->p); }
void industrial_digital_in_4_destroy(IndustrialDigitalIn4 *industrial_digital_in_4) { device_release(industrial_digital_in_4->p); }
void sound_intensity_destroy(SoundIntensity *sound_intensity) { device_release(sound_intensity->p); }
void piezo_speaker_destroy(PiezoSpeaker *piezo_speaker) { device_release(piezo_speaker->p); }
void humidity_v2_destroy(HumidityV2 *humidity_v2) { device_release(humidity_v2->p); }
void distance_us_destroy(DistanceUS *distance_us) { device_release(distance_us->p); }
void joystick_destroy(Joystick *joystick) { device_release(joystick->p); }
void load_cell_destroy(LoadCell *load_cell) { device_release(load_cell->p); }
void co2_destroy(CO2 *co2) { device_release(co2->p); }
void motion_detector_destroy(MotionDetector *motion_detector) { device_release(motion_detector->p); }
void gps_destroy(GPS *gps) { device_release(gps->p); }
void analog_in_v2_destroy(AnalogInV2 *analog_in_v2) { device_release(analog_in_v2->p); }
void analog_out_destroy(AnalogOut *analog_out) { device_release(analog_out->p); }
void air_quality_destroy(AirQuality *air_quality) { device_release(air_quality->p); }
void temperature_ir_destroy(TemperatureIR *temperature_ir) { device_release(temperature_ir->p); }
void moisture_destroy(Moisture *moisture) { device_release(moisture->p); }
void ambient_light_v2_destroy(AmbientLightV2 *ambient_light_v2) { device_release(ambient_light_v2->p); }
void solid_state_relay_destroy(SolidStateRelay *solid_state_relay) { device_release(solid_state_relay->p); }