Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/char/ns8250/ns8250.c

    r5b68e0c r5f6e25e  
    111111        /** The fibril mutex for synchronizing the access to the device. */
    112112        fibril_mutex_t mutex;
    113         /** True if device is removed. */
    114         bool removed;
    115113} ns8250_t;
    116114
     
    221219
    222220static int ns8250_add_device(ddf_dev_t *dev);
    223 static int ns8250_dev_remove(ddf_dev_t *dev);
    224221
    225222/** The serial port device driver's standard operations. */
    226223static driver_ops_t ns8250_ops = {
    227         .add_device = &ns8250_add_device,
    228         .dev_remove = &ns8250_dev_remove
     224        .add_device = &ns8250_add_device
    229225};
    230226
     
    616612}
    617613
    618 /** Deinitialize the serial port device.
    619  *
    620  * @param ns            Serial port device
    621  */
    622 static void ns8250_port_cleanup(ns8250_t *ns)
    623 {
    624         /* Disable FIFO */
    625         pio_write_8(ns->port + 2, 0x00);
    626         /* Disable DTR, RTS, OUT1, OUT2 (int. enable) */
    627         pio_write_8(ns->port + 4, 0x00);
    628         /* Disable all interrupts from the port */
    629         ns8250_port_interrupts_disable(ns->port);
    630 }
    631 
    632614/** Read the data from the serial port device and store them to the input
    633615 * buffer.
     
    787769}
    788770
    789 static int ns8250_dev_remove(ddf_dev_t *dev)
    790 {
    791         ns8250_t *ns = NS8250_FROM_DEV(dev);
    792         int rc;
    793        
    794         fibril_mutex_lock(&ns->mutex);
    795         if (ns->client_connected) {
    796                 fibril_mutex_unlock(&ns->mutex);
    797                 return EBUSY;
    798         }
    799         ns->removed = true;
    800         fibril_mutex_unlock(&ns->mutex);
    801        
    802         rc = ddf_fun_unbind(ns->fun);
    803         if (rc != EOK) {
    804                 ddf_msg(LVL_ERROR, "Failed to unbind function.");
    805                 return rc;
    806         }
    807        
    808         ddf_fun_destroy(ns->fun);
    809        
    810         ns8250_port_cleanup(ns);
    811         ns8250_unregister_interrupt_handler(ns);
    812         ns8250_dev_cleanup(ns);
    813         return EOK;
    814 }
    815 
    816771/** Open the device.
    817772 *
     
    823778static int ns8250_open(ddf_fun_t *fun)
    824779{
    825         ns8250_t *ns = NS8250(fun);
     780        ns8250_t *data = (ns8250_t *) fun->dev->driver_data;
    826781        int res;
    827782       
    828         fibril_mutex_lock(&ns->mutex);
    829         if (ns->client_connected) {
     783        fibril_mutex_lock(&data->mutex);
     784        if (data->client_connected) {
    830785                res = ELIMIT;
    831         } else if (ns->removed) {
    832                 res = ENXIO;
    833786        } else {
    834787                res = EOK;
    835                 ns->client_connected = true;
    836         }
    837         fibril_mutex_unlock(&ns->mutex);
     788                data->client_connected = true;
     789        }
     790        fibril_mutex_unlock(&data->mutex);
    838791       
    839792        return res;
Note: See TracChangeset for help on using the changeset viewer.