Changeset c05642d in mainline for uspace/drv/char/ns8250/ns8250.c
- Timestamp:
- 2011-09-07T00:03:26Z (13 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/ns8250/ns8250.c
rbb74dabe rc05642d 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 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 }140 116 141 117 /** Find out if there is some incomming data available on the serial port. … … 245 221 246 222 static int ns8250_add_device(ddf_dev_t *dev); 223 static int ns8250_dev_remove(ddf_dev_t *dev); 247 224 248 225 /** The serial port device driver's standard operations. */ 249 226 static driver_ops_t ns8250_ops = { 250 .add_device = &ns8250_add_device 227 .add_device = &ns8250_add_device, 228 .dev_remove = &ns8250_dev_remove 251 229 }; 252 230 … … 638 616 } 639 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 640 632 /** Read the data from the serial port device and store them to the input 641 633 * buffer. … … 721 713 722 714 /* Allocate soft-state for the device */ 723 ns = ns8250_new();715 ns = ddf_dev_data_alloc(dev, sizeof(ns8250_t)); 724 716 if (ns == NULL) { 725 717 rc = ENOMEM; … … 727 719 } 728 720 721 fibril_mutex_initialize(&ns->mutex); 729 722 ns->dev = dev; 730 dev->driver_data = ns;731 723 732 724 rc = ns8250_dev_initialize(ns); … … 792 784 if (need_cleanup) 793 785 ns8250_dev_cleanup(ns); 794 if (ns != NULL)795 ns8250_delete(ns);796 786 return rc; 787 } 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; 797 814 } 798 815 … … 806 823 static int ns8250_open(ddf_fun_t *fun) 807 824 { 808 ns8250_t * data = (ns8250_t *) fun->dev->driver_data;825 ns8250_t *ns = NS8250(fun); 809 826 int res; 810 827 811 fibril_mutex_lock(& data->mutex);812 if ( data->client_connected) {828 fibril_mutex_lock(&ns->mutex); 829 if (ns->client_connected) { 813 830 res = ELIMIT; 831 } else if (ns->removed) { 832 res = ENXIO; 814 833 } else { 815 834 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); 819 838 820 839 return res;
Note:
See TracChangeset
for help on using the changeset viewer.