Changeset c05642d in mainline for uspace/drv/char/ns8250/ns8250.c


Ignore:
Timestamp:
2011-09-07T00:03:26Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5081276
Parents:
bb74dabe (diff), 038b289 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    rbb74dabe rc05642d  
    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;
    114 
    115 /** Create per-device soft-state structure.
    116  *
    117  * @return      Pointer to soft-state structure.
    118  */
    119 static ns8250_t *ns8250_new(void)
    120 {
    121         ns8250_t *ns;
    122        
    123         ns = (ns8250_t *) calloc(1, sizeof(ns8250_t));
    124         if (ns == NULL)
    125                 return NULL;
    126        
    127         fibril_mutex_initialize(&ns->mutex);
    128         return ns;
    129 }
    130 
    131 /** Delete soft-state structure.
    132  *
    133  * @param ns    The driver data structure.
    134  */
    135 static void ns8250_delete(ns8250_t *ns)
    136 {
    137         assert(ns != NULL);
    138         free(ns);
    139 }
    140116
    141117/** Find out if there is some incomming data available on the serial port.
     
    245221
    246222static int ns8250_add_device(ddf_dev_t *dev);
     223static int ns8250_dev_remove(ddf_dev_t *dev);
    247224
    248225/** The serial port device driver's standard operations. */
    249226static driver_ops_t ns8250_ops = {
    250         .add_device = &ns8250_add_device
     227        .add_device = &ns8250_add_device,
     228        .dev_remove = &ns8250_dev_remove
    251229};
    252230
     
    638616}
    639617
     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
    640632/** Read the data from the serial port device and store them to the input
    641633 * buffer.
     
    721713       
    722714        /* Allocate soft-state for the device */
    723         ns = ns8250_new();
     715        ns = ddf_dev_data_alloc(dev, sizeof(ns8250_t));
    724716        if (ns == NULL) {
    725717                rc = ENOMEM;
     
    727719        }
    728720       
     721        fibril_mutex_initialize(&ns->mutex);
    729722        ns->dev = dev;
    730         dev->driver_data = ns;
    731723       
    732724        rc = ns8250_dev_initialize(ns);
     
    792784        if (need_cleanup)
    793785                ns8250_dev_cleanup(ns);
    794         if (ns != NULL)
    795                 ns8250_delete(ns);
    796786        return rc;
     787}
     788
     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;
    797814}
    798815
     
    806823static int ns8250_open(ddf_fun_t *fun)
    807824{
    808         ns8250_t *data = (ns8250_t *) fun->dev->driver_data;
     825        ns8250_t *ns = NS8250(fun);
    809826        int res;
    810827       
    811         fibril_mutex_lock(&data->mutex);
    812         if (data->client_connected) {
     828        fibril_mutex_lock(&ns->mutex);
     829        if (ns->client_connected) {
    813830                res = ELIMIT;
     831        } else if (ns->removed) {
     832                res = ENXIO;
    814833        } else {
    815834                res = EOK;
    816                 data->client_connected = true;
    817         }
    818         fibril_mutex_unlock(&data->mutex);
     835                ns->client_connected = true;
     836        }
     837        fibril_mutex_unlock(&ns->mutex);
    819838       
    820839        return res;
Note: See TracChangeset for help on using the changeset viewer.