Changeset 5b68e0c in mainline for uspace/drv/char/ns8250/ns8250.c


Ignore:
Timestamp:
2011-09-02T22:02:55Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f480d7e
Parents:
fb4c877
Message:

ns8250 device removal support.

File:
1 edited

Legend:

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

    rfb4c877 r5b68e0c  
    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;
    113115} ns8250_t;
    114116
     
    219221
    220222static int ns8250_add_device(ddf_dev_t *dev);
     223static int ns8250_dev_remove(ddf_dev_t *dev);
    221224
    222225/** The serial port device driver's standard operations. */
    223226static driver_ops_t ns8250_ops = {
    224         .add_device = &ns8250_add_device
     227        .add_device = &ns8250_add_device,
     228        .dev_remove = &ns8250_dev_remove
    225229};
    226230
     
    612616}
    613617
     618/** Deinitialize the serial port device.
     619 *
     620 * @param ns            Serial port device
     621 */
     622static 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
    614632/** Read the data from the serial port device and store them to the input
    615633 * buffer.
     
    769787}
    770788
     789static 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
    771816/** Open the device.
    772817 *
     
    778823static int ns8250_open(ddf_fun_t *fun)
    779824{
    780         ns8250_t *data = (ns8250_t *) fun->dev->driver_data;
     825        ns8250_t *ns = NS8250(fun);
    781826        int res;
    782827       
    783         fibril_mutex_lock(&data->mutex);
    784         if (data->client_connected) {
     828        fibril_mutex_lock(&ns->mutex);
     829        if (ns->client_connected) {
    785830                res = ELIMIT;
     831        } else if (ns->removed) {
     832                res = ENXIO;
    786833        } else {
    787834                res = EOK;
    788                 data->client_connected = true;
    789         }
    790         fibril_mutex_unlock(&data->mutex);
     835                ns->client_connected = true;
     836        }
     837        fibril_mutex_unlock(&ns->mutex);
    791838       
    792839        return res;
Note: See TracChangeset for help on using the changeset viewer.