Changes in uspace/drv/char/i8042/i8042.c [8820544:75751db6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/i8042/i8042.c
r8820544 r75751db6 2 2 * Copyright (c) 2001-2004 Jakub Jermar 3 3 * Copyright (c) 2006 Josef Cejka 4 * Copyright (c) 20 09Jiri Svoboda4 * Copyright (c) 2014 Jiri Svoboda 5 5 * Copyright (c) 2011 Jan Vesely 6 6 * All rights reserved. … … 39 39 */ 40 40 41 #include <ddf/log.h> 42 #include <ddf/interrupt.h> 43 #include <ddi.h> 41 44 #include <device/hw_res.h> 42 #include <ddi.h>43 45 #include <errno.h> 44 46 #include <str_error.h> 45 47 #include <inttypes.h> 46 #include < ddf/log.h>47 #include <ddf/interrupt.h> 48 #include <io/chardev_srv.h> 49 48 50 #include "i8042.h" 49 51 … … 64 66 #define i8042_KBD_TRANSLATE 0x40 /* Use this to switch to XT scancodes */ 65 67 66 static void default_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); 67 68 /** Port function operations. */ 69 static ddf_dev_ops_t ops = { 70 .default_handler = default_handler 68 static void i8042_char_conn(ipc_callid_t, ipc_call_t *, void *); 69 static int i8042_read(chardev_srv_t *, void *, size_t); 70 static int i8042_write(chardev_srv_t *, const void *, size_t); 71 72 static chardev_ops_t i8042_chardev_ops = { 73 .read = i8042_read, 74 .write = i8042_write 71 75 }; 72 76 … … 106 110 }; 107 111 108 /** Get i8042 soft state from device node. */109 static i8042_t *dev_i8042(ddf_dev_t *dev)110 {111 return ddf_dev_data_get(dev);112 }113 114 112 /** Wait until it is safe to write to the device. */ 115 113 static void wait_ready(i8042_t *dev) … … 131 129 ddf_dev_t *dev) 132 130 { 133 i8042_t *controller = d ev_i8042(dev);131 i8042_t *controller = ddf_dev_data_get(dev); 134 132 135 133 const uint8_t status = IPC_GET_ARG1(*call); … … 186 184 }; 187 185 186 dev->kbd = ddf_fun_data_alloc(dev->kbd_fun, sizeof(i8042_port_t)); 187 if (dev->kbd == NULL) { 188 rc = ENOMEM; 189 goto error; 190 } 191 192 dev->kbd->ctl = dev; 193 chardev_srvs_init(&dev->kbd->cds); 194 dev->kbd->cds.ops = &i8042_chardev_ops; 195 dev->kbd->cds.sarg = dev->kbd; 196 188 197 rc = ddf_fun_add_match_id(dev->kbd_fun, "char/xtkbd", 90); 189 198 if (rc != EOK) … … 196 205 } 197 206 207 dev->aux = ddf_fun_data_alloc(dev->aux_fun, sizeof(i8042_port_t)); 208 if (dev->aux == NULL) { 209 rc = ENOMEM; 210 goto error; 211 } 212 213 dev->aux->ctl = dev; 214 chardev_srvs_init(&dev->aux->cds); 215 dev->aux->cds.ops = &i8042_chardev_ops; 216 dev->aux->cds.sarg = dev->aux; 217 198 218 rc = ddf_fun_add_match_id(dev->aux_fun, "char/ps2mouse", 90); 199 219 if (rc != EOK) 200 220 goto error; 201 221 202 ddf_fun_set_ ops(dev->kbd_fun, &ops);203 ddf_fun_set_ ops(dev->aux_fun, &ops);222 ddf_fun_set_conn_handler(dev->kbd_fun, i8042_char_conn); 223 ddf_fun_set_conn_handler(dev->aux_fun, i8042_char_conn); 204 224 205 225 buffer_init(&dev->kbd_buffer, dev->kbd_data, BUFFER_SIZE); … … 298 318 } 299 319 300 // FIXME TODO use shared instead this301 enum {302 IPC_CHAR_READ = DEV_FIRST_CUSTOM_METHOD,303 IPC_CHAR_WRITE,304 };305 306 320 /** Write data to i8042 port. 307 321 * 308 * @param fun DDF function.309 * @param buffer Data source .310 * @param size Data size .322 * @param srv Connection-specific data 323 * @param buffer Data source 324 * @param size Data size 311 325 * 312 326 * @return Bytes written. 313 327 * 314 328 */ 315 static int i8042_write(ddf_fun_t *fun, char *buffer, size_t size) 316 { 317 i8042_t *controller = dev_i8042(ddf_fun_get_dev(fun)); 318 fibril_mutex_lock(&controller->write_guard); 329 static int i8042_write(chardev_srv_t *srv, const void *data, size_t size) 330 { 331 i8042_port_t *port = (i8042_port_t *)srv->srvs->sarg; 332 i8042_t *i8042 = port->ctl; 333 const char *dp = (const char *)data; 334 335 fibril_mutex_lock(&i8042->write_guard); 319 336 320 337 for (size_t i = 0; i < size; ++i) { 321 if ( controller->aux_fun == fun) {322 wait_ready( controller);323 pio_write_8(& controller->regs->status,338 if (port == i8042->aux) { 339 wait_ready(i8042); 340 pio_write_8(&i8042->regs->status, 324 341 i8042_CMD_WRITE_AUX); 325 342 } 326 343 327 wait_ready( controller);328 pio_write_8(& controller->regs->data, buffer[i]);329 } 330 331 fibril_mutex_unlock(& controller->write_guard);344 wait_ready(i8042); 345 pio_write_8(&i8042->regs->data, dp[i]); 346 } 347 348 fibril_mutex_unlock(&i8042->write_guard); 332 349 return size; 333 350 } … … 335 352 /** Read data from i8042 port. 336 353 * 337 * @param fun DDF function.338 * @param buffer Data place .339 * @param size Data place size .354 * @param srv Connection-specific data 355 * @param buffer Data place 356 * @param size Data place size 340 357 * 341 358 * @return Bytes read. 342 359 * 343 360 */ 344 static int i8042_read(ddf_fun_t *fun, char *data, size_t size) 345 { 346 i8042_t *controller = dev_i8042(ddf_fun_get_dev(fun)); 347 buffer_t *buffer = (fun == controller->aux_fun) ? 348 &controller->aux_buffer : &controller->kbd_buffer; 361 static int i8042_read(chardev_srv_t *srv, void *dest, size_t size) 362 { 363 i8042_port_t *port = (i8042_port_t *)srv->srvs->sarg; 364 i8042_t *i8042 = port->ctl; 365 uint8_t *destp = (uint8_t *)dest; 366 367 buffer_t *buffer = (port == i8042->aux) ? 368 &i8042->aux_buffer : &i8042->kbd_buffer; 349 369 350 370 for (size_t i = 0; i < size; ++i) 351 *d ata++ = buffer_read(buffer);371 *destp++ = buffer_read(buffer); 352 372 353 373 return size; … … 356 376 /** Handle data requests. 357 377 * 358 * @param fun ddf_fun_t function.359 378 * @param id callid 360 379 * @param call IPC request. 361 * 362 */ 363 static void default_handler(ddf_fun_t *fun, ipc_callid_t id, ipc_call_t *call) 364 { 365 const sysarg_t method = IPC_GET_IMETHOD(*call); 366 const size_t size = IPC_GET_ARG1(*call); 367 368 switch (method) { 369 case IPC_CHAR_READ: 370 if (size <= 4 * sizeof(sysarg_t)) { 371 sysarg_t message[4] = {}; 372 373 i8042_read(fun, (char *) message, size); 374 async_answer_4(id, size, message[0], message[1], 375 message[2], message[3]); 376 } else 377 async_answer_0(id, ELIMIT); 378 break; 379 380 case IPC_CHAR_WRITE: 381 if (size <= 3 * sizeof(sysarg_t)) { 382 const sysarg_t message[3] = { 383 IPC_GET_ARG2(*call), 384 IPC_GET_ARG3(*call), 385 IPC_GET_ARG4(*call) 386 }; 387 388 i8042_write(fun, (char *) message, size); 389 async_answer_0(id, size); 390 } else 391 async_answer_0(id, ELIMIT); 392 393 default: 394 async_answer_0(id, EINVAL); 395 } 380 * @param arg ddf_fun_t function. 381 */ 382 void i8042_char_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 383 { 384 i8042_port_t *port = ddf_fun_data_get((ddf_fun_t *)arg); 385 386 chardev_conn(iid, icall, &port->cds); 396 387 } 397 388
Note:
See TracChangeset
for help on using the changeset viewer.