Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 04c7003f in mainline


Ignore:
Timestamp:
2010-05-14T08:11:15Z (11 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master
Children:
cf8cc36
Parents:
f619943a
Message:

renamed serial port driver to ns8250, fixed a little bug

Files:
1 added
1 deleted
4 edited
3 moved

Legend:

Unmodified
Added
Removed
  • boot/arch/amd64/Makefile.inc

    rf619943a r04c7003f  
    4141        pciintel \
    4242        isa \
    43         serial
     43        ns8250
    4444
    4545RD_DRV_CONF = \
  • uspace/Makefile

    rf619943a r04c7003f  
    8080        DIRS += srv/drivers/pciintel
    8181        DIRS += srv/drivers/isa
    82         DIRS += srv/drivers/serial
     82        DIRS += srv/drivers/ns8250
    8383#       DIRS += srv/hw/bus/pci
    8484endif
  • uspace/srv/devman/main.c

    rf619943a r04c7003f  
    9090        driver = find_driver(&drivers_list, drv_name);
    9191       
     92        if (NULL == driver) {
     93                printf(NAME ": no driver named %s was found.\n", drv_name);
     94                free(drv_name);
     95                drv_name = NULL;
     96                ipc_answer_0(iid, ENOENT);
     97                return NULL;
     98        }
     99       
    92100        free(drv_name);
    93101        drv_name = NULL;
    94        
    95         if (NULL == driver) {
    96                 printf(NAME ": no driver named %s was found.\n", drv_name);
    97                 ipc_answer_0(iid, ENOENT);
    98                 return NULL;
    99         }
    100102       
    101103        // Create connection to the driver
  • uspace/srv/drivers/isa/isa.dev

    rf619943a r04c7003f  
    11com1:
    2         match 100 isa/serial
     2        match 100 isa/ns8250
    33        irq 4
    44        io_range 3f8 8
    55
    66com2:
    7         match 100 isa/serial
     7        match 100 isa/ns8250
    88        irq 3
    99        io_range 2f8 8
  • uspace/srv/drivers/ns8250/Makefile

    rf619943a r04c7003f  
    2929LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBC_PREFIX)/libc.a
    3030
    31 OUTPUT = serial
     31OUTPUT = ns8250
    3232
    3333SOURCES = \
    34         serial.c
     34        ns8250.c
    3535
    3636include ../../Makefile.common
  • uspace/srv/drivers/ns8250/cyclic_buffer.h

    rf619943a r04c7003f  
    2727 */
    2828
    29 /** @addtogroup serial
     29/** @addtogroup ns8250
    3030 * @{
    3131 */
  • uspace/srv/drivers/ns8250/ns8250.c

    rf619943a r04c7003f  
    2828
    2929/**
    30  * @defgroup serial Serial port driver.
     30 * @defgroup ns8250 Serial port driver.
    3131 * @brief HelenOS serial port driver.
    3232 * @{
     
    6363#include "cyclic_buffer.h"
    6464
    65 #define NAME "serial"
     65#define NAME "ns8250"
    6666
    6767#define REG_COUNT 7
    6868#define MAX_BAUD_RATE 115200
    6969
    70 typedef struct serial_dev_data {
     70typedef struct ns8250_dev_data {
    7171        bool client_connected;
    7272        int irq;
     
    7575        cyclic_buffer_t input_buffer;
    7676        fibril_mutex_t mutex;           
    77 } serial_dev_data_t;
    78 
    79 static serial_dev_data_t * create_serial_dev_data()
    80 {
    81         serial_dev_data_t *data = (serial_dev_data_t *)malloc(sizeof(serial_dev_data_t));
     77} ns8250_dev_data_t;
     78
     79static ns8250_dev_data_t * create_ns8250_dev_data()
     80{
     81        ns8250_dev_data_t *data = (ns8250_dev_data_t *)malloc(sizeof(ns8250_dev_data_t));
    8282        if (NULL != data) {
    83                 memset(data, 0, sizeof(serial_dev_data_t));
     83                memset(data, 0, sizeof(ns8250_dev_data_t));
    8484                fibril_mutex_initialize(&data->mutex);
    8585        }
     
    8787}
    8888
    89 static void delete_serial_dev_data(serial_dev_data_t *data)
     89static void delete_ns8250_dev_data(ns8250_dev_data_t *data)
    9090{
    9191        if (NULL != data) {
     
    9494}
    9595
    96 static bool serial_received(ioport8_t *port)
     96static bool ns8250_received(ioport8_t *port)
    9797{
    9898   return (pio_read_8(port + 5) & 1) != 0;
    9999}
    100100
    101 static uint8_t serial_read_8(ioport8_t *port)
     101static uint8_t ns8250_read_8(ioport8_t *port)
    102102{
    103103        return pio_read_8(port);
     
    109109}
    110110
    111 static void serial_write_8(ioport8_t *port, uint8_t c)
     111static void ns8250_write_8(ioport8_t *port, uint8_t c)
    112112{
    113113        while (!is_transmit_empty(port))
     
    117117}
    118118
    119 static int serial_read(device_t *dev, char *buf, size_t count)
    120 {
    121         // printf(NAME ": serial_read %s\n", dev->name);
     119static int ns8250_read(device_t *dev, char *buf, size_t count)
     120{
     121        // printf(NAME ": ns8250_read %s\n", dev->name);
    122122       
    123123        int ret = 0;
    124124       
    125         serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     125        ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
    126126        fibril_mutex_lock(&data->mutex);
    127127       
     
    136136}
    137137
    138 static inline void serial_putchar(serial_dev_data_t *data, uint8_t c)
     138static inline void ns8250_putchar(ns8250_dev_data_t *data, uint8_t c)
    139139{       
    140140        fibril_mutex_lock(&data->mutex);
    141         serial_write_8(data->port, c); 
     141        ns8250_write_8(data->port, c); 
    142142        fibril_mutex_unlock(&data->mutex);
    143143}
    144144
    145 static int serial_write(device_t *dev, char *buf, size_t count)
    146 {
    147         serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     145static int ns8250_write(device_t *dev, char *buf, size_t count)
     146{
     147        ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
    148148       
    149149        size_t idx;
    150150        for (idx = 0; idx < count; idx++) {
    151                 serial_putchar(data, (uint8_t)buf[idx]);
     151                ns8250_putchar(data, (uint8_t)buf[idx]);
    152152        }
    153153       
     
    155155}
    156156
    157 static device_class_t serial_dev_class;
    158 
    159 static char_iface_t serial_char_iface = {
    160         .read = &serial_read,
    161         .write = &serial_write
     157static device_class_t ns8250_dev_class;
     158
     159static char_iface_t ns8250_char_iface = {
     160        .read = &ns8250_read,
     161        .write = &ns8250_write
    162162};
    163163
    164 static int serial_add_device(device_t *dev);
     164static int ns8250_add_device(device_t *dev);
    165165
    166166/** The serial port device driver's standard operations.
    167167 */
    168 static driver_ops_t serial_ops = {
    169         .add_device = &serial_add_device
     168static driver_ops_t ns8250_ops = {
     169        .add_device = &ns8250_add_device
    170170};
    171171
    172172/** The serial port device driver structure.
    173173 */
    174 static driver_t serial_driver = {
     174static driver_t ns8250_driver = {
    175175        .name = NAME,
    176         .driver_ops = &serial_ops
     176        .driver_ops = &ns8250_ops
    177177};
    178178
    179 static void serial_dev_cleanup(device_t *dev)
     179static void ns8250_dev_cleanup(device_t *dev)
    180180{
    181181        if (NULL != dev->driver_data) {
    182                 delete_serial_dev_data((serial_dev_data_t*)dev->driver_data);   
     182                delete_ns8250_dev_data((ns8250_dev_data_t*)dev->driver_data);   
    183183                dev->driver_data = NULL;
    184184        }
     
    190190}
    191191
    192 static bool serial_pio_enable(device_t *dev)
    193 {
    194         printf(NAME ": serial_pio_enable %s\n", dev->name);
    195        
    196         serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     192static bool ns8250_pio_enable(device_t *dev)
     193{
     194        printf(NAME ": ns8250_pio_enable %s\n", dev->name);
     195       
     196        ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
    197197       
    198198        // Gain control over port's registers.
     
    205205}
    206206
    207 static bool serial_dev_probe(device_t *dev)
    208 {
    209         printf(NAME ": serial_dev_probe %s\n", dev->name);
    210        
    211         serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     207static bool ns8250_dev_probe(device_t *dev)
     208{
     209        printf(NAME ": ns8250_dev_probe %s\n", dev->name);
     210       
     211        ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
    212212        ioport8_t *port_addr = data->port;     
    213213        bool res = true;
     
    235235}
    236236
    237 static int serial_dev_initialize(device_t *dev)
    238 {
    239         printf(NAME ": serial_dev_initialize %s\n", dev->name);
     237static int ns8250_dev_initialize(device_t *dev)
     238{
     239        printf(NAME ": ns8250_dev_initialize %s\n", dev->name);
    240240       
    241241        int ret = EOK;
     
    244244       
    245245        // allocate driver data for the device
    246         serial_dev_data_t *data = create_serial_dev_data();     
     246        ns8250_dev_data_t *data = create_ns8250_dev_data();     
    247247        if (NULL == data) {
    248248                return ENOMEM;
     
    304304       
    305305failed:
    306         serial_dev_cleanup(dev);       
     306        ns8250_dev_cleanup(dev);       
    307307        clean_hw_resource_list(&hw_resources); 
    308308        return ret;     
    309309}
    310310
    311 static inline void serial_port_interrupts_enable(ioport8_t *port)
     311static inline void ns8250_port_interrupts_enable(ioport8_t *port)
    312312{       
    313313        pio_write_8(port + 1 , 0x01);   // Interrupt when data received
     
    315315}
    316316
    317 static inline void serial_port_interrupts_disable(ioport8_t *port)
     317static inline void ns8250_port_interrupts_disable(ioport8_t *port)
    318318{
    319319        pio_write_8(port + 1, 0x00);    // Disable all interrupts
    320320}
    321321
    322 static int serial_interrupt_enable(device_t *dev)
    323 {
    324         serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     322static int ns8250_interrupt_enable(device_t *dev)
     323{
     324        ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
    325325       
    326326        int res;
     
    331331       
    332332        // enable interrupt on the serial port
    333         serial_port_interrupts_enable(data->port);
     333        ns8250_port_interrupts_enable(data->port);
    334334       
    335335        return EOK;
    336336}
    337337
    338 static int serial_port_set_baud_rate(ioport8_t *port, unsigned int baud_rate)
     338static int ns8250_port_set_baud_rate(ioport8_t *port, unsigned int baud_rate)
    339339{
    340340        uint16_t divisor;
     
    360360}
    361361
    362 static int serial_set_baud_rate(device_t *dev, unsigned int baud_rate)
    363 {
    364         serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     362static int ns8250_set_baud_rate(device_t *dev, unsigned int baud_rate)
     363{
     364        ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
    365365        ioport8_t *port = data->port;
    366366        int ret;
     
    369369       
    370370        fibril_mutex_lock(&data->mutex);       
    371         serial_port_interrupts_disable(port);    // Disable all interrupts
    372         ret = serial_port_set_baud_rate(port, baud_rate);
    373         serial_port_interrupts_enable(port);
     371        ns8250_port_interrupts_disable(port);    // Disable all interrupts
     372        ret = ns8250_port_set_baud_rate(port, baud_rate);
     373        ns8250_port_interrupts_enable(port);
    374374        fibril_mutex_unlock(&data->mutex);     
    375375       
     
    377377}
    378378
    379 static void serial_initialize_port(device_t *dev)
    380 {
    381         serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     379static void ns8250_initialize_port(device_t *dev)
     380{
     381        ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
    382382        ioport8_t *port = data->port;
    383383       
    384         serial_port_interrupts_disable(port);     // Disable all interrupts
    385         serial_port_set_baud_rate(port, 38400);
     384        ns8250_port_interrupts_disable(port);     // Disable all interrupts
     385        ns8250_port_set_baud_rate(port, 38400);
    386386        pio_write_8(port + 3, 0x07);    // 8 bits, no parity, two stop bits
    387387        pio_write_8(port + 2, 0xC7);    // Enable FIFO, clear them, with 14-byte threshold
     
    390390}
    391391
    392 static void serial_read_from_device(device_t *dev)
    393 {
    394         serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     392static void ns8250_read_from_device(device_t *dev)
     393{
     394        ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
    395395        ioport8_t *port = data->port;
    396396        bool cont = true;
     
    399399                fibril_mutex_lock(&data->mutex);
    400400               
    401                 if (cont = serial_received(port)) {
    402                         uint8_t val = serial_read_8(port);
     401                if (cont = ns8250_received(port)) {
     402                        uint8_t val = ns8250_read_8(port);
    403403                        // printf(NAME ": character %c read from %s.\n", val, dev->name);                       
    404404                       
     
    420420}
    421421
    422 static inline void serial_interrupt_handler(device_t *dev, ipc_callid_t iid, ipc_call_t *icall)
    423 {
    424         serial_read_from_device(dev);
    425 }
    426 
    427 static inline int serial_register_interrupt_handler(device_t *dev)
    428 {
    429         serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
    430        
    431         return register_interrupt_handler(dev, data->irq, serial_interrupt_handler, NULL);     
    432 }
    433 
    434 static inline int serial_unregister_interrupt_handler(device_t *dev)
    435 {
    436         serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     422static inline void ns8250_interrupt_handler(device_t *dev, ipc_callid_t iid, ipc_call_t *icall)
     423{
     424        ns8250_read_from_device(dev);
     425}
     426
     427static inline int ns8250_register_interrupt_handler(device_t *dev)
     428{
     429        ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
     430       
     431        return register_interrupt_handler(dev, data->irq, ns8250_interrupt_handler, NULL);     
     432}
     433
     434static inline int ns8250_unregister_interrupt_handler(device_t *dev)
     435{
     436        ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
    437437       
    438438        return unregister_interrupt_handler(dev, data->irq);   
    439439}
    440440
    441 static int serial_add_device(device_t *dev)
    442 {
    443         printf(NAME ": serial_add_device %s (handle = %d)\n", dev->name, dev->handle);
    444        
    445         int res = serial_dev_initialize(dev);
     441static int ns8250_add_device(device_t *dev)
     442{
     443        printf(NAME ": ns8250_add_device %s (handle = %d)\n", dev->name, dev->handle);
     444       
     445        int res = ns8250_dev_initialize(dev);
    446446        if (EOK != res) {
    447447                return res;
    448448        }
    449449       
    450         if (!serial_pio_enable(dev)) {
    451                 serial_dev_cleanup(dev);
     450        if (!ns8250_pio_enable(dev)) {
     451                ns8250_dev_cleanup(dev);
    452452                return EADDRNOTAVAIL;
    453453        }       
    454454       
    455455        // find out whether the device is present
    456         if (!serial_dev_probe(dev)) {
    457                 serial_dev_cleanup(dev);
     456        if (!ns8250_dev_probe(dev)) {
     457                ns8250_dev_cleanup(dev);
    458458                return ENOENT;
    459459        }       
    460460       
    461461        // serial port initialization (baud rate etc.)
    462         serial_initialize_port(dev);
     462        ns8250_initialize_port(dev);
    463463       
    464464        // register interrupt handler
    465         if (EOK != serial_register_interrupt_handler(dev)) {
     465        if (EOK != ns8250_register_interrupt_handler(dev)) {
    466466                printf(NAME ": failed to register interrupt handler.\n");
    467                 serial_dev_cleanup(dev);
     467                ns8250_dev_cleanup(dev);
    468468                return res;
    469469        }
    470470       
    471471        // enable interrupt
    472         if (EOK != (res = serial_interrupt_enable(dev))) {
     472        if (EOK != (res = ns8250_interrupt_enable(dev))) {
    473473                printf(NAME ": failed to enable the interrupt. Error code = %d.\n", res);
    474                 serial_dev_cleanup(dev);
    475                 serial_unregister_interrupt_handler(dev);
     474                ns8250_dev_cleanup(dev);
     475                ns8250_unregister_interrupt_handler(dev);
    476476                return res;
    477477        }       
    478478       
    479         dev->class = &serial_dev_class;
     479        dev->class = &ns8250_dev_class;
    480480       
    481481        printf(NAME ": the %s device has been successfully initialized.\n", dev->name);
     
    490490 * @param dev the device.
    491491 */
    492 static int serial_open(device_t *dev)
    493 {
    494         serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     492static int ns8250_open(device_t *dev)
     493{
     494        ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
    495495        int res;
    496496       
     
    515515 * @param dev the device.
    516516 */
    517 static void serial_close(device_t *dev)
    518 {
    519         serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data;
     517static void ns8250_close(device_t *dev)
     518{
     519        ns8250_dev_data_t *data = (ns8250_dev_data_t *)dev->driver_data;
    520520       
    521521        fibril_mutex_lock(&data->mutex);
     
    533533 * Configure the parameters of the serial communication.
    534534 */
    535 static void serial_default_handler(device_t *dev, ipc_callid_t callid, ipc_call_t *call)
     535static void ns8250_default_handler(device_t *dev, ipc_callid_t callid, ipc_call_t *call)
    536536{
    537537        ipcarg_t method = IPC_GET_METHOD(*call);
     
    540540        switch(method) {
    541541                case SERIAL_SET_BAUD_RATE:
    542                         ret = serial_set_baud_rate(dev, IPC_GET_ARG1(*call));
     542                        ret = ns8250_set_baud_rate(dev, IPC_GET_ARG1(*call));
    543543                        ipc_answer_0(callid, ret);
    544544                        break;
     
    559559 * client requests to the serial port devices.
    560560 */
    561 static void serial_init()
     561static void ns8250_init()
    562562{
    563563        // TODO
    564         serial_dev_class.id = 0;
    565         serial_dev_class.open = &serial_open;
    566         serial_dev_class.close = &serial_close;
    567        
    568         serial_dev_class.interfaces[CHAR_DEV_IFACE] = &serial_char_iface;
    569         serial_dev_class.default_handler = &serial_default_handler;
     564        ns8250_dev_class.id = 0;
     565        ns8250_dev_class.open = &ns8250_open;
     566        ns8250_dev_class.close = &ns8250_close;
     567       
     568        ns8250_dev_class.interfaces[CHAR_DEV_IFACE] = &ns8250_char_iface;
     569        ns8250_dev_class.default_handler = &ns8250_default_handler;
    570570}
    571571
     
    573573{
    574574        printf(NAME ": HelenOS serial port driver\n"); 
    575         serial_init();
    576         return driver_main(&serial_driver);
     575        ns8250_init();
     576        return driver_main(&ns8250_driver);
    577577}
    578578
Note: See TracChangeset for help on using the changeset viewer.