Changeset 78aa0ab in mainline for uspace/drv/char/i8042/i8042.c


Ignore:
Timestamp:
2011-12-09T16:56:17Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dd28c1a
Parents:
7f1669f
Message:

i8042: Use one device structure instead of multiple separate variables.

File:
1 edited

Legend:

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

    r7f1669f r78aa0ab  
    6868
    6969
    70 enum {
    71         DEVID_PRI = 0, /**< primary device */
    72         DEVID_AUX = 1, /**< AUX device */
    73         MAX_DEVS  = 2
    74 };
    75 
    7670static irq_cmd_t i8042_cmds[] = {
    7771        {
     
    106100};
    107101
    108 static uintptr_t i8042_physical;
    109 static uintptr_t i8042_kernel;
    110 static i8042_regs_t * i8042;
    111 
    112 static i8042_port_t i8042_port[MAX_DEVS];
     102static i8042_dev_t device;
    113103
    114104static void wait_ready(void)
    115105{
    116         while (pio_read_8(&i8042->status) & i8042_INPUT_FULL);
     106        while (pio_read_8(&device.regs->status) & i8042_INPUT_FULL);
    117107}
    118108
    119109static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call);
    120110static void i8042_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg);
    121 static int i8042_init(void);
     111static int i8042_init(i8042_dev_t *dev);
    122112static void i8042_port_write(int devid, uint8_t data);
    123113
     
    127117        char name[16];
    128118        int i, rc;
    129         char dchar[MAX_DEVS] = { 'a', 'b' };
     119        const char dchar[MAX_DEVS] = { 'a', 'b' };
    130120
    131121        printf(NAME ": i8042 PS/2 port driver\n");
     
    137127        }
    138128
    139         if (i8042_init() != EOK)
     129        if (i8042_init(&device) != EOK)
    140130                return -1;
    141131
    142132        for (i = 0; i < MAX_DEVS; i++) {
    143                 i8042_port[i].client_sess = NULL;
     133                device.port[i].client_sess = NULL;
    144134
    145135                snprintf(name, 16, "%s/ps2%c", NAMESPACE, dchar[i]);
    146                 rc = loc_service_register(name, &i8042_port[i].service_id);
     136                rc = loc_service_register(name, &device.port[i].service_id);
    147137                if (rc != EOK) {
    148138                        printf(NAME ": Unable to register device %s.\n", name);
     
    160150}
    161151
    162 static int i8042_init(void)
    163 {
     152static int i8042_init(i8042_dev_t *dev)
     153{
     154        static uintptr_t i8042_physical;
     155        static uintptr_t i8042_kernel;
     156        assert(dev);
    164157        if (sysinfo_get_value("i8042.address.physical", &i8042_physical) != EOK)
    165158                return -1;
     
    172165                return -1;
    173166       
    174         i8042 = vaddr;
     167        dev->regs = vaddr;
    175168       
    176169        sysarg_t inr_a;
     
    187180        /* Disable kbd and aux */
    188181        wait_ready();
    189         pio_write_8(&i8042->status, i8042_CMD_WRITE_CMDB);
    190         wait_ready();
    191         pio_write_8(&i8042->data, i8042_KBD_DISABLE | i8042_AUX_DISABLE);
     182        pio_write_8(&dev->regs->status, i8042_CMD_WRITE_CMDB);
     183        wait_ready();
     184        pio_write_8(&dev->regs->data, i8042_KBD_DISABLE | i8042_AUX_DISABLE);
    192185
    193186        /* Flush all current IO */
    194         while (pio_read_8(&i8042->status) & i8042_OUTPUT_FULL)
    195                 (void) pio_read_8(&i8042->data);
     187        while (pio_read_8(&dev->regs->status) & i8042_OUTPUT_FULL)
     188                (void) pio_read_8(&dev->regs->data);
    196189
    197190        i8042_kbd.cmds[0].addr = (void *) &((i8042_regs_t *) i8042_kernel)->status;
     
    203196
    204197        wait_ready();
    205         pio_write_8(&i8042->status, i8042_CMD_WRITE_CMDB);
    206         wait_ready();
    207         pio_write_8(&i8042->data, i8042_KBD_IE | i8042_KBD_TRANSLATE |
     198        pio_write_8(&dev->regs->status, i8042_CMD_WRITE_CMDB);
     199        wait_ready();
     200        pio_write_8(&dev->regs->data, i8042_KBD_IE | i8042_KBD_TRANSLATE |
    208201            i8042_AUX_IE);
    209202
     
    229222        dev_id = -1;
    230223        for (i = 0; i < MAX_DEVS; i++) {
    231                 if (i8042_port[i].service_id == dsid)
     224                if (device.port[i].service_id == dsid)
    232225                        dev_id = i;
    233226        }
     
    256249                    async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
    257250                if (sess != NULL) {
    258                         if (i8042_port[dev_id].client_sess == NULL) {
    259                                 i8042_port[dev_id].client_sess = sess;
     251                        if (device.port[dev_id].client_sess == NULL) {
     252                                device.port[dev_id].client_sess = sess;
    260253                                retval = EOK;
    261254                        } else
     
    283276        if (devid == DEVID_AUX) {
    284277                wait_ready();
    285                 pio_write_8(&i8042->status, i8042_CMD_WRITE_AUX);
    286         }
    287         wait_ready();
    288         pio_write_8(&i8042->data, data);
     278                pio_write_8(&device.regs->status, i8042_CMD_WRITE_AUX);
     279        }
     280        wait_ready();
     281        pio_write_8(&device.regs->data, data);
    289282}
    290283
     
    303296        }
    304297
    305         if (i8042_port[devid].client_sess != NULL) {
     298        if (device.port[devid].client_sess != NULL) {
    306299                async_exch_t *exch =
    307                     async_exchange_begin(i8042_port[devid].client_sess);
     300                    async_exchange_begin(device.port[devid].client_sess);
    308301                async_msg_1(exch, IPC_FIRST_USER_METHOD, data);
    309302                async_exchange_end(exch);
Note: See TracChangeset for help on using the changeset viewer.