Changes in uspace/drv/ns8250/ns8250.c [ebcb05a:33dbbd2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/ns8250/ns8250.c
rebcb05a r33dbbd2 1 1 /* 2 2 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 2011 Jiri Svoboda4 3 * All rights reserved. 5 4 * … … 53 52 #include <libarch/ddi.h> 54 53 55 #include <ddf/driver.h> 56 #include <ddf/interrupt.h> 57 #include <ddf/log.h> 58 #include <ops/char_dev.h> 54 #include <driver.h> 55 #include <char.h> 56 #include <resource.h> 59 57 60 58 #include <devman.h> … … 70 68 #define MAX_BAUD_RATE 115200 71 69 #define DLAB_MASK (1 << 7) 72 73 /** Obtain soft-state structure from function node */74 #define NS8250(fnode) ((ns8250_t *) ((fnode)->dev->driver_data))75 76 /** Obtain soft-state structure from device node */77 #define NS8250_FROM_DEV(dnode) ((ns8250_t *) ((dnode)->driver_data))78 70 79 71 /** The number of bits of one data unit send by the serial port. */ … … 94 86 95 87 /** The driver data for the serial port devices. */ 96 typedef struct ns8250 { 97 /** DDF device node */ 98 ddf_dev_t *dev; 99 /** DDF function node */ 100 ddf_fun_t *fun; 88 typedef struct ns8250_dev_data { 101 89 /** Is there any client conntected to the device? */ 102 90 bool client_connected; … … 111 99 /** The fibril mutex for synchronizing the access to the device. */ 112 100 fibril_mutex_t mutex; 113 } 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 nsThe driver data structure.134 */ 135 static void ns8250_delete(ns8250_t *ns)136 { 137 assert(ns != NULL);138 free(ns);101 } ns8250_dev_data_t; 102 103 /** Create driver data for a device. 104 * 105 * @return The driver data. 106 */ 107 static ns8250_dev_data_t *create_ns8250_dev_data(void) 108 { 109 ns8250_dev_data_t *data; 110 111 data = (ns8250_dev_data_t *) malloc(sizeof(ns8250_dev_data_t)); 112 if (NULL != data) { 113 memset(data, 0, sizeof(ns8250_dev_data_t)); 114 fibril_mutex_initialize(&data->mutex); 115 } 116 return data; 117 } 118 119 /** Delete driver data. 120 * 121 * @param data The driver data structure. 122 */ 123 static void delete_ns8250_dev_data(ns8250_dev_data_t *data) 124 { 125 if (data != NULL) 126 free(data); 139 127 } 140 128 … … 184 172 /** Read data from the serial port device. 185 173 * 186 * @param fun The serial port function174 * @param dev The serial port device. 187 175 * @param buf The ouput buffer for read data. 188 176 * @param count The number of bytes to be read. … … 191 179 * error number otherwise. 192 180 */ 193 static int ns8250_read(ddf_fun_t *fun, char *buf, size_t count) 194 { 195 ns8250_t *ns = NS8250(fun); 181 static int ns8250_read(device_t *dev, char *buf, size_t count) 182 { 196 183 int ret = EOK; 197 198 fibril_mutex_lock(&ns->mutex); 199 while (!buf_is_empty(&ns->input_buffer) && (size_t)ret < count) { 200 buf[ret] = (char)buf_pop_front(&ns->input_buffer); 184 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data; 185 186 fibril_mutex_lock(&data->mutex); 187 while (!buf_is_empty(&data->input_buffer) && (size_t)ret < count) { 188 buf[ret] = (char)buf_pop_front(&data->input_buffer); 201 189 ret++; 202 190 } 203 fibril_mutex_unlock(& ns->mutex);191 fibril_mutex_unlock(&data->mutex); 204 192 205 193 return ret; … … 208 196 /** Write a character to the serial port. 209 197 * 210 * @param ns Serial port device211 * @param c The character to be written 212 */ 213 static inline void ns8250_putchar(ns8250_ t *ns, uint8_t c)214 { 215 fibril_mutex_lock(& ns->mutex);216 ns8250_write_8( ns->port, c);217 fibril_mutex_unlock(& ns->mutex);198 * @param data The serial port device's driver data. 199 * @param c The character to be written. 200 */ 201 static inline void ns8250_putchar(ns8250_dev_data_t *data, uint8_t c) 202 { 203 fibril_mutex_lock(&data->mutex); 204 ns8250_write_8(data->port, c); 205 fibril_mutex_unlock(&data->mutex); 218 206 } 219 207 220 208 /** Write data to the serial port. 221 209 * 222 * @param fun The serial port function223 * @param buf The data to be written 224 * @param count The number of bytes to be written 225 * @return Zero on success 226 */ 227 static int ns8250_write(d df_fun_t *fun, char *buf, size_t count)228 { 229 ns8250_ t *ns = NS8250(fun);210 * @param dev The serial port device. 211 * @param buf The data to be written. 212 * @param count The number of bytes to be written. 213 * @return Zero on success. 214 */ 215 static int ns8250_write(device_t *dev, char *buf, size_t count) 216 { 217 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data; 230 218 size_t idx; 231 219 232 220 for (idx = 0; idx < count; idx++) 233 ns8250_putchar( ns, (uint8_t) buf[idx]);221 ns8250_putchar(data, (uint8_t) buf[idx]); 234 222 235 223 return 0; 236 224 } 237 225 238 static d df_dev_ops_t ns8250_dev_ops;226 static device_ops_t ns8250_dev_ops; 239 227 240 228 /** The character interface's callbacks. */ 241 static char_ dev_ops_t ns8250_char_dev_ops= {229 static char_iface_t ns8250_char_iface = { 242 230 .read = &ns8250_read, 243 231 .write = &ns8250_write 244 232 }; 245 233 246 static int ns8250_add_device(d df_dev_t *dev);234 static int ns8250_add_device(device_t *dev); 247 235 248 236 /** The serial port device driver's standard operations. */ … … 257 245 }; 258 246 259 /** Clean up the serial port soft-state 260 * 261 * @param ns Serial port device 262 */ 263 static void ns8250_dev_cleanup(ns8250_t *ns) 264 { 265 if (ns->dev->parent_phone > 0) { 266 async_hangup(ns->dev->parent_phone); 267 ns->dev->parent_phone = 0; 247 /** Clean up the serial port device structure. 248 * 249 * @param dev The device structure. 250 */ 251 static void ns8250_dev_cleanup(device_t *dev) 252 { 253 if (dev->driver_data != NULL) { 254 delete_ns8250_dev_data((ns8250_dev_data_t*) dev->driver_data); 255 dev->driver_data = NULL; 256 } 257 258 if (dev->parent_phone > 0) { 259 ipc_hangup(dev->parent_phone); 260 dev->parent_phone = 0; 268 261 } 269 262 } … … 271 264 /** Enable the i/o ports of the device. 272 265 * 273 * @param ns Serial port device 274 * @return True on success, false otherwise 275 */ 276 static bool ns8250_pio_enable(ns8250_t *ns) 277 { 278 ddf_msg(LVL_DEBUG, "ns8250_pio_enable %s", ns->dev->name); 266 * @param dev The serial port device. 267 * @return True on success, false otherwise. 268 */ 269 static bool ns8250_pio_enable(device_t *dev) 270 { 271 printf(NAME ": ns8250_pio_enable %s\n", dev->name); 272 273 ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data; 279 274 280 275 /* Gain control over port's registers. */ 281 if (pio_enable((void *) (uintptr_t) ns->io_addr, REG_COUNT,282 (void **) & ns->port)) {283 ddf_msg(LVL_ERROR, "Cannot map the port %#" PRIx32284 " for device %s.", ns->io_addr, ns->dev->name);276 if (pio_enable((void *) data->io_addr, REG_COUNT, 277 (void **) &data->port)) { 278 printf(NAME ": error - cannot gain the port %lx for device " 279 "%s.\n", data->io_addr, dev->name); 285 280 return false; 286 281 } … … 291 286 /** Probe the serial port device for its presence. 292 287 * 293 * @param ns Serial port device 294 * @return True if the device is present, false otherwise 295 */ 296 static bool ns8250_dev_probe(ns8250_t *ns) 297 { 298 ddf_msg(LVL_DEBUG, "ns8250_dev_probe %s", ns->dev->name); 299 300 ioport8_t *port_addr = ns->port; 288 * @param dev The serial port device. 289 * @return True if the device is present, false otherwise. 290 */ 291 static bool ns8250_dev_probe(device_t *dev) 292 { 293 printf(NAME ": ns8250_dev_probe %s\n", dev->name); 294 295 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data; 296 ioport8_t *port_addr = data->port; 301 297 bool res = true; 302 298 uint8_t olddata; … … 314 310 pio_write_8(port_addr + 4, olddata); 315 311 316 if (!res) { 317 ddf_msg(LVL_DEBUG, "Device %s is not present.", 318 ns->dev->name); 319 } 312 if (!res) 313 printf(NAME ": device %s is not present.\n", dev->name); 320 314 321 315 return res; … … 324 318 /** Initialize serial port device. 325 319 * 326 * @param ns Serial port device327 * @return Zero on success, negative error number otherwise 328 */ 329 static int ns8250_dev_initialize( ns8250_t *ns)330 { 331 ddf_msg(LVL_DEBUG, "ns8250_dev_initialize %s", ns->dev->name);320 * @param dev The serial port device. 321 * @return Zero on success, negative error number otherwise. 322 */ 323 static int ns8250_dev_initialize(device_t *dev) 324 { 325 printf(NAME ": ns8250_dev_initialize %s\n", dev->name); 332 326 333 327 int ret = EOK; … … 336 330 memset(&hw_resources, 0, sizeof(hw_resource_list_t)); 337 331 332 /* Allocate driver data for the device. */ 333 ns8250_dev_data_t *data = create_ns8250_dev_data(); 334 if (data == NULL) 335 return ENOMEM; 336 dev->driver_data = data; 337 338 338 /* Connect to the parent's driver. */ 339 ns->dev->parent_phone = devman_parent_device_connect(ns->dev->handle,339 dev->parent_phone = devman_parent_device_connect(dev->handle, 340 340 IPC_FLAG_BLOCKING); 341 if ( ns->dev->parent_phone < 0) {342 ddf_msg(LVL_ERROR, "Failed to connect to parent driver of"343 "device %s. ", ns->dev->name);344 ret = ns->dev->parent_phone;341 if (dev->parent_phone < 0) { 342 printf(NAME ": failed to connect to the parent driver of the " 343 "device %s.\n", dev->name); 344 ret = EPARTY; /* FIXME: use another EC */ 345 345 goto failed; 346 346 } 347 347 348 348 /* Get hw resources. */ 349 ret = hw_res_get_resource_list(ns->dev->parent_phone, &hw_resources);350 if (ret != EOK) {351 ddf_msg(LVL_ERROR, "Failed to get HW resources for device "352 "%s.", ns->dev->name);349 if (!get_hw_resources(dev->parent_phone, &hw_resources)) { 350 printf(NAME ": failed to get hw resources for the device " 351 "%s.\n", dev->name); 352 ret = EPARTY; /* FIXME: use another EC */ 353 353 goto failed; 354 354 } … … 363 363 switch (res->type) { 364 364 case INTERRUPT: 365 ns->irq = res->res.interrupt.irq;365 data->irq = res->res.interrupt.irq; 366 366 irq = true; 367 ddf_msg(LVL_NOTE, "Device %s was asigned irq = 0x%x.",368 ns->dev->name, ns->irq);367 printf(NAME ": the %s device was asigned irq = 0x%x.\n", 368 dev->name, data->irq); 369 369 break; 370 370 371 371 case IO_RANGE: 372 ns->io_addr = res->res.io_range.address;372 data->io_addr = res->res.io_range.address; 373 373 if (res->res.io_range.size < REG_COUNT) { 374 ddf_msg(LVL_ERROR, "I/O range assigned to"375 " device %s is too small.", ns->dev->name);376 ret = E LIMIT;374 printf(NAME ": i/o range assigned to the device " 375 "%s is too small.\n", dev->name); 376 ret = EPARTY; /* FIXME: use another EC */ 377 377 goto failed; 378 378 } 379 379 ioport = true; 380 ddf_msg(LVL_NOTE, "Device %s was asigned I/Oaddress = "381 "0x%x. ", ns->dev->name, ns->io_addr);382 380 printf(NAME ": the %s device was asigned i/o address = " 381 "0x%x.\n", dev->name, data->io_addr); 382 break; 383 383 384 384 default: … … 388 388 389 389 if (!irq || !ioport) { 390 ddf_msg(LVL_ERROR, "Missing HW resource(s) for device %s.",391 ns->dev->name);392 ret = E NOENT;390 printf(NAME ": missing hw resource(s) for the device %s.\n", 391 dev->name); 392 ret = EPARTY; /* FIXME: use another EC */ 393 393 goto failed; 394 394 } 395 395 396 hw_res_clean_resource_list(&hw_resources);396 clean_hw_resource_list(&hw_resources); 397 397 return ret; 398 398 399 399 failed: 400 ns8250_dev_cleanup( ns);401 hw_res_clean_resource_list(&hw_resources);400 ns8250_dev_cleanup(dev); 401 clean_hw_resource_list(&hw_resources); 402 402 return ret; 403 403 } … … 405 405 /** Enable interrupts on the serial port device. 406 406 * 407 * Interrupt when data is received 407 * Interrupt when data is received. 408 408 * 409 409 * @param port The base address of the serial port device's ports. 410 410 */ 411 411 static inline void ns8250_port_interrupts_enable(ioport8_t *port) 412 { 412 { 413 413 pio_write_8(port + 1, 0x1); /* Interrupt when data received. */ 414 414 pio_write_8(port + 4, 0xB); … … 417 417 /** Disable interrupts on the serial port device. 418 418 * 419 * @param port The base address of the serial port device's ports 419 * @param port The base address of the serial port device's ports. 420 420 */ 421 421 static inline void ns8250_port_interrupts_disable(ioport8_t *port) … … 426 426 /** Enable interrupts for the serial port device. 427 427 * 428 * @param ns Serial port device 429 * @return Zero on success, negative error number otherwise 430 */ 431 static int ns8250_interrupt_enable(ns8250_t *ns) 432 { 428 * @param dev The device. 429 * @return Zero on success, negative error number otherwise. 430 */ 431 static int ns8250_interrupt_enable(device_t *dev) 432 { 433 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data; 434 int res; 435 436 /* Enable interrupt globally. */ 437 res = interrupt_enable(data->irq); 438 if (res != EOK) 439 return res; 440 433 441 /* Enable interrupt on the serial port. */ 434 ns8250_port_interrupts_enable( ns->port);442 ns8250_port_interrupts_enable(data->port); 435 443 436 444 return EOK; … … 473 481 474 482 if (baud_rate < 50 || MAX_BAUD_RATE % baud_rate != 0) { 475 ddf_msg(LVL_ERROR, "Invalid baud rate %d requested.",476 baud_rate);483 printf(NAME ": error - somebody tried to set invalid baud rate " 484 "%d\n", baud_rate); 477 485 return EINVAL; 478 486 } … … 617 625 * Set the default parameters of the serial communication. 618 626 * 619 * @param ns Serial port device 620 */ 621 static void ns8250_initialize_port(ns8250_t *ns) 622 { 623 ioport8_t *port = ns->port; 627 * @param dev The serial port device. 628 */ 629 static void ns8250_initialize_port(device_t *dev) 630 { 631 ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data; 632 ioport8_t *port = data->port; 624 633 625 634 /* Disable interrupts. */ … … 641 650 * buffer. 642 651 * 643 * @param ns Serial port device 644 */ 645 static void ns8250_read_from_device(ns8250_t *ns) 646 { 647 ioport8_t *port = ns->port; 652 * @param dev The serial port device. 653 */ 654 static void ns8250_read_from_device(device_t *dev) 655 { 656 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data; 657 ioport8_t *port = data->port; 648 658 bool cont = true; 649 659 650 660 while (cont) { 651 fibril_mutex_lock(& ns->mutex);661 fibril_mutex_lock(&data->mutex); 652 662 653 663 cont = ns8250_received(port); … … 655 665 uint8_t val = ns8250_read_8(port); 656 666 657 if ( ns->client_connected) {658 if (!buf_push_back(& ns->input_buffer, val)) {659 ddf_msg(LVL_WARN, "Buffer overflow on "660 "%s. ", ns->dev->name);667 if (data->client_connected) { 668 if (!buf_push_back(&data->input_buffer, val)) { 669 printf(NAME ": buffer overflow on " 670 "%s.\n", dev->name); 661 671 } else { 662 ddf_msg(LVL_DEBUG2, "Character %c saved "663 "to the buffer of %s. ",664 val, ns->dev->name);672 printf(NAME ": the character %c saved " 673 "to the buffer of %s.\n", 674 val, dev->name); 665 675 } 666 676 } 667 677 } 668 678 669 fibril_mutex_unlock(& ns->mutex);679 fibril_mutex_unlock(&data->mutex); 670 680 fibril_yield(); 671 681 } … … 679 689 * @param dev The serial port device. 680 690 */ 681 static inline void ns8250_interrupt_handler(d df_dev_t *dev, ipc_callid_t iid,691 static inline void ns8250_interrupt_handler(device_t *dev, ipc_callid_t iid, 682 692 ipc_call_t *icall) 683 693 { 684 ns8250_read_from_device( NS8250_FROM_DEV(dev));694 ns8250_read_from_device(dev); 685 695 } 686 696 687 697 /** Register the interrupt handler for the device. 688 698 * 689 * @param ns Serial port device 690 */ 691 static inline int ns8250_register_interrupt_handler(ns8250_t *ns) 692 { 693 return register_interrupt_handler(ns->dev, ns->irq, 699 * @param dev The serial port device. 700 */ 701 static inline int ns8250_register_interrupt_handler(device_t *dev) 702 { 703 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data; 704 705 return register_interrupt_handler(dev, data->irq, 694 706 ns8250_interrupt_handler, NULL); 695 707 } … … 697 709 /** Unregister the interrupt handler for the device. 698 710 * 699 * @param ns Serial port device 700 */ 701 static inline int ns8250_unregister_interrupt_handler(ns8250_t *ns) 702 { 703 return unregister_interrupt_handler(ns->dev, ns->irq); 711 * @param dev The serial port device. 712 */ 713 static inline int ns8250_unregister_interrupt_handler(device_t *dev) 714 { 715 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data; 716 717 return unregister_interrupt_handler(dev, data->irq); 704 718 } 705 719 … … 710 724 * @param dev The serial port device. 711 725 */ 712 static int ns8250_add_device(ddf_dev_t *dev) 713 { 714 ns8250_t *ns = NULL; 715 ddf_fun_t *fun = NULL; 716 bool need_cleanup = false; 717 int rc; 718 719 ddf_msg(LVL_DEBUG, "ns8250_add_device %s (handle = %d)", 720 dev->name, (int) dev->handle); 721 722 /* Allocate soft-state for the device */ 723 ns = ns8250_new(); 724 if (ns == NULL) { 725 rc = ENOMEM; 726 goto fail; 727 } 728 729 ns->dev = dev; 730 dev->driver_data = ns; 731 732 rc = ns8250_dev_initialize(ns); 733 if (rc != EOK) 734 goto fail; 735 736 need_cleanup = true; 737 738 if (!ns8250_pio_enable(ns)) { 739 rc = EADDRNOTAVAIL; 740 goto fail; 726 static int ns8250_add_device(device_t *dev) 727 { 728 printf(NAME ": ns8250_add_device %s (handle = %d)\n", 729 dev->name, dev->handle); 730 731 int res = ns8250_dev_initialize(dev); 732 if (res != EOK) 733 return res; 734 735 if (!ns8250_pio_enable(dev)) { 736 ns8250_dev_cleanup(dev); 737 return EADDRNOTAVAIL; 741 738 } 742 739 743 740 /* Find out whether the device is present. */ 744 if (!ns8250_dev_probe( ns)) {745 rc = ENOENT;746 goto fail;741 if (!ns8250_dev_probe(dev)) { 742 ns8250_dev_cleanup(dev); 743 return ENOENT; 747 744 } 748 745 749 746 /* Serial port initialization (baud rate etc.). */ 750 ns8250_initialize_port( ns);747 ns8250_initialize_port(dev); 751 748 752 749 /* Register interrupt handler. */ 753 if (ns8250_register_interrupt_handler( ns) != EOK) {754 ddf_msg(LVL_ERROR, "Failed to register interrupt handler.");755 rc = EADDRNOTAVAIL;756 goto fail;750 if (ns8250_register_interrupt_handler(dev) != EOK) { 751 printf(NAME ": failed to register interrupt handler.\n"); 752 ns8250_dev_cleanup(dev); 753 return res; 757 754 } 758 755 759 756 /* Enable interrupt. */ 760 rc = ns8250_interrupt_enable(ns); 761 if (rc != EOK) { 762 ddf_msg(LVL_ERROR, "Failed to enable the interrupt. Error code = " 763 "%d.", rc); 764 goto fail; 765 } 766 767 fun = ddf_fun_create(dev, fun_exposed, "a"); 768 if (fun == NULL) { 769 ddf_msg(LVL_ERROR, "Failed creating function."); 770 goto fail; 757 res = ns8250_interrupt_enable(dev); 758 if (res != EOK) { 759 printf(NAME ": failed to enable the interrupt. Error code = " 760 "%d.\n", res); 761 ns8250_dev_cleanup(dev); 762 ns8250_unregister_interrupt_handler(dev); 763 return res; 771 764 } 772 765 773 766 /* Set device operations. */ 774 fun->ops = &ns8250_dev_ops; 775 rc = ddf_fun_bind(fun); 776 if (rc != EOK) { 777 ddf_msg(LVL_ERROR, "Failed binding function."); 778 goto fail; 779 } 780 781 ns->fun = fun; 782 783 ddf_fun_add_to_class(fun, "serial"); 784 785 ddf_msg(LVL_NOTE, "Device %s successfully initialized.", 767 dev->ops = &ns8250_dev_ops; 768 769 add_device_to_class(dev, "serial"); 770 771 printf(NAME ": the %s device has been successfully initialized.\n", 786 772 dev->name); 787 773 788 774 return EOK; 789 fail:790 if (fun != NULL)791 ddf_fun_destroy(fun);792 if (need_cleanup)793 ns8250_dev_cleanup(ns);794 if (ns != NULL)795 ns8250_delete(ns);796 return rc;797 775 } 798 776 … … 804 782 * @param dev The device. 805 783 */ 806 static int ns8250_open(d df_fun_t *fun)807 { 808 ns8250_ t *data = (ns8250_t *) fun->dev->driver_data;784 static int ns8250_open(device_t *dev) 785 { 786 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data; 809 787 int res; 810 788 … … 817 795 } 818 796 fibril_mutex_unlock(&data->mutex); 819 797 820 798 return res; 821 799 } … … 828 806 * @param dev The device. 829 807 */ 830 static void ns8250_close(d df_fun_t *fun)831 { 832 ns8250_ t *data = (ns8250_t *) fun->dev->driver_data;808 static void ns8250_close(device_t *dev) 809 { 810 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data; 833 811 834 812 fibril_mutex_lock(&data->mutex); … … 852 830 */ 853 831 static void 854 ns8250_get_props(d df_dev_t *dev, unsigned int *baud_rate, unsigned int *parity,832 ns8250_get_props(device_t *dev, unsigned int *baud_rate, unsigned int *parity, 855 833 unsigned int *word_length, unsigned int* stop_bits) 856 834 { 857 ns8250_ t *data = (ns8250_t *) dev->driver_data;835 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data; 858 836 ioport8_t *port = data->port; 859 837 … … 865 843 fibril_mutex_unlock(&data->mutex); 866 844 867 ddf_msg(LVL_DEBUG, "ns8250_get_props: baud rate %d, parity 0x%x, word "868 "length %d, stop bits %d ", *baud_rate, *parity, *word_length,845 printf(NAME ": ns8250_get_props: baud rate %d, parity 0x%x, word " 846 "length %d, stop bits %d\n", *baud_rate, *parity, *word_length, 869 847 *stop_bits); 870 848 } … … 879 857 * @param stop_bits The number of stop bits to be used. 880 858 */ 881 static int ns8250_set_props(d df_dev_t *dev, unsigned int baud_rate,859 static int ns8250_set_props(device_t *dev, unsigned int baud_rate, 882 860 unsigned int parity, unsigned int word_length, unsigned int stop_bits) 883 861 { 884 ddf_msg(LVL_DEBUG, "ns8250_set_props: baud rate %d, parity 0x%x, word "885 "length %d, stop bits %d ", baud_rate, parity, word_length,862 printf(NAME ": ns8250_set_props: baud rate %d, parity 0x%x, word " 863 "length %d, stop bits %d\n", baud_rate, parity, word_length, 886 864 stop_bits); 887 865 888 ns8250_ t *data = (ns8250_t *) dev->driver_data;866 ns8250_dev_data_t *data = (ns8250_dev_data_t *) dev->driver_data; 889 867 ioport8_t *port = data->port; 890 868 int ret; … … 906 884 * Configure the parameters of the serial communication. 907 885 */ 908 static void ns8250_default_handler(d df_fun_t *fun, ipc_callid_t callid,886 static void ns8250_default_handler(device_t *dev, ipc_callid_t callid, 909 887 ipc_call_t *call) 910 888 { 911 sysarg_t method = IPC_GET_IMETHOD(*call);889 ipcarg_t method = IPC_GET_METHOD(*call); 912 890 int ret; 913 891 unsigned int baud_rate, parity, word_length, stop_bits; … … 915 893 switch (method) { 916 894 case SERIAL_GET_COM_PROPS: 917 ns8250_get_props( fun->dev, &baud_rate, &parity, &word_length,895 ns8250_get_props(dev, &baud_rate, &parity, &word_length, 918 896 &stop_bits); 919 async_answer_4(callid, EOK, baud_rate, parity, word_length,897 ipc_answer_4(callid, EOK, baud_rate, parity, word_length, 920 898 stop_bits); 921 899 break; … … 926 904 word_length = IPC_GET_ARG3(*call); 927 905 stop_bits = IPC_GET_ARG4(*call); 928 ret = ns8250_set_props( fun->dev, baud_rate, parity, word_length,906 ret = ns8250_set_props(dev, baud_rate, parity, word_length, 929 907 stop_bits); 930 async_answer_0(callid, ret);908 ipc_answer_0(callid, ret); 931 909 break; 932 910 933 911 default: 934 async_answer_0(callid, ENOTSUP);912 ipc_answer_0(callid, ENOTSUP); 935 913 } 936 914 } … … 943 921 static void ns8250_init(void) 944 922 { 945 ddf_log_init(NAME, LVL_ERROR);946 947 923 ns8250_dev_ops.open = &ns8250_open; 948 924 ns8250_dev_ops.close = &ns8250_close; 949 925 950 ns8250_dev_ops.interfaces[CHAR_DEV_IFACE] = &ns8250_char_ dev_ops;926 ns8250_dev_ops.interfaces[CHAR_DEV_IFACE] = &ns8250_char_iface; 951 927 ns8250_dev_ops.default_handler = &ns8250_default_handler; 952 928 } … … 956 932 printf(NAME ": HelenOS serial port driver\n"); 957 933 ns8250_init(); 958 return d df_driver_main(&ns8250_driver);934 return driver_main(&ns8250_driver); 959 935 } 960 936
Note:
See TracChangeset
for help on using the changeset viewer.