Changeset 5b68e0c in mainline for uspace/drv/char/ns8250/ns8250.c
- Timestamp:
- 2011-09-02T22:02:55Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f480d7e
- Parents:
- fb4c877
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/ns8250/ns8250.c
rfb4c877 r5b68e0c 111 111 /** The fibril mutex for synchronizing the access to the device. */ 112 112 fibril_mutex_t mutex; 113 /** True if device is removed. */ 114 bool removed; 113 115 } ns8250_t; 114 116 … … 219 221 220 222 static int ns8250_add_device(ddf_dev_t *dev); 223 static int ns8250_dev_remove(ddf_dev_t *dev); 221 224 222 225 /** The serial port device driver's standard operations. */ 223 226 static driver_ops_t ns8250_ops = { 224 .add_device = &ns8250_add_device 227 .add_device = &ns8250_add_device, 228 .dev_remove = &ns8250_dev_remove 225 229 }; 226 230 … … 612 616 } 613 617 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 614 632 /** Read the data from the serial port device and store them to the input 615 633 * buffer. … … 769 787 } 770 788 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 771 816 /** Open the device. 772 817 * … … 778 823 static int ns8250_open(ddf_fun_t *fun) 779 824 { 780 ns8250_t * data = (ns8250_t *) fun->dev->driver_data;825 ns8250_t *ns = NS8250(fun); 781 826 int res; 782 827 783 fibril_mutex_lock(& data->mutex);784 if ( data->client_connected) {828 fibril_mutex_lock(&ns->mutex); 829 if (ns->client_connected) { 785 830 res = ELIMIT; 831 } else if (ns->removed) { 832 res = ENXIO; 786 833 } else { 787 834 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); 791 838 792 839 return res;
Note:
See TracChangeset
for help on using the changeset viewer.