Changeset bd87ae0 in mainline
- Timestamp:
- 2012-01-04T00:50:07Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 41c9a22
- Parents:
- 2f79a38
- Location:
- uspace/drv/char
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/i8042/i8042.c
r2f79a38 rbd87ae0 47 47 #include <ddf/log.h> 48 48 #include <ddf/interrupt.h> 49 #include <ops/char_dev.h>50 49 51 50 #include "i8042.h" … … 53 52 #define NAME "i8042" 54 53 55 static int i8042_write_kbd(ddf_fun_t *, char *, size_t);56 static int i8042_read_kbd(ddf_fun_t *, char *, size_t);57 58 /** Primary port interface structure. */59 static char_dev_ops_t kbd_iface = {60 .read = i8042_read_kbd,61 .write = i8042_write_kbd,62 };63 64 54 void default_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); 65 55 66 /** Primary port function operations. */ 67 static ddf_dev_ops_t kbd_ops = { 68 .interfaces[CHAR_DEV_IFACE] = &kbd_iface, 69 .default_handler = default_handler, 70 }; 71 72 /** Auxiliary port function operations. */ 56 /** Port function operations. */ 73 57 static ddf_dev_ops_t ops = { 74 58 .default_handler = default_handler, … … 189 173 } 190 174 191 dev->kbd_fun->ops = & kbd_ops;175 dev->kbd_fun->ops = &ops; 192 176 dev->aux_fun->ops = &ops; 193 177 dev->kbd_fun->driver_data = dev; … … 283 267 } 284 268 285 /** Write data to i8042 primary port. 286 * @param fun DDF function. 287 * @param buffer Data source. 288 * @param size Data size. 289 * @return Bytes written. 290 */ 291 static int i8042_write_kbd(ddf_fun_t *fun, char *buffer, size_t size) 292 { 293 assert(fun); 294 assert(fun->driver_data); 295 i8042_t *controller = fun->driver_data; 296 fibril_mutex_lock(&controller->write_guard); 297 for (size_t i = 0; i < size; ++i) { 298 wait_ready(controller); 299 pio_write_8(&controller->regs->data, buffer[i]); 300 } 301 fibril_mutex_unlock(&controller->write_guard); 302 return size; 303 } 304 305 /** Read data from i8042 primary port. 306 * @param fun DDF function. 307 * @param buffer Data place. 308 * @param size Data place size. 309 * @return Bytes read. 310 */ 311 static int i8042_read_kbd(ddf_fun_t *fun, char *buffer, size_t size) 312 { 313 assert(fun); 314 assert(fun->driver_data); 315 bzero(buffer, size); 316 317 i8042_t *controller = fun->driver_data; 318 319 for (size_t i = 0; i < size; ++i) { 320 *buffer++ = buffer_read(&controller->kbd_buffer); 321 } 322 return size; 323 } 324 325 // TODO use shared instead of own copy 269 // TODO use shared instead this 326 270 enum { 327 271 IPC_CHAR_READ = DEV_FIRST_CUSTOM_METHOD, … … 372 316 } 373 317 318 /** Handle data requests. 319 * @param fun ddf_fun_t function. 320 * @param id callid 321 * @param call IPC request. 322 */ 374 323 void default_handler(ddf_fun_t *fun, ipc_callid_t id, ipc_call_t *call) 375 324 { -
uspace/drv/char/xtkbd/Makefile
r2f79a38 rbd87ae0 33 33 34 34 SOURCES = \ 35 chardev.c \ 35 36 main.c \ 36 37 xtkbd.c -
uspace/drv/char/xtkbd/xtkbd.c
r2f79a38 rbd87ae0 35 35 #include <errno.h> 36 36 #include <devman.h> 37 #include <device/char_dev.h>38 37 #include <ddf/log.h> 39 38 #include <io/keycode.h> … … 42 41 #include <abi/ipc/methods.h> 43 42 43 #include "chardev.h" 44 44 #include "xtkbd.h" 45 45 … … 259 259 260 260 assert(kbd->parent_sess); 261 async_exch_t *parent_exch = async_exchange_begin(kbd->parent_sess); 261 262 while (1) { 263 if (!parent_exch) 264 parent_exch = async_exchange_begin(kbd->parent_sess); 265 262 266 const int *map = scanmap_simple; 263 267 size_t map_size = sizeof(scanmap_simple) / sizeof(int); 264 268 265 269 uint8_t code = 0; 266 ssize_t size = char _dev_read(kbd->parent_sess, &code, 1);270 ssize_t size = chardev_read(parent_exch, &code, 1); 267 271 268 272 /** Ignore AT command reply */ … … 274 278 map = scanmap_e0; 275 279 map_size = sizeof(scanmap_e0) / sizeof(int); 276 size = char _dev_read(kbd->parent_sess, &code, 1);280 size = chardev_read(parent_exch, &code, 1); 277 281 // TODO handle print screen 278 282 } … … 334 338 ((mods & KM_SCROLL_LOCK) ? LI_SCROLL : 0); 335 339 uint8_t cmds[] = { KBD_CMD_SET_LEDS, status }; 336 const ssize_t size = 337 char_dev_write(kbd->parent_sess, cmds, sizeof(cmds)); 340 async_exch_t *exch = async_exchange_begin(kbd->parent_sess); 341 const ssize_t size = chardev_write(exch, cmds, sizeof(cmds)); 342 async_exchange_end(exch); 338 343 async_answer_0(icallid, size < 0 ? size : EOK); 339 344 break;
Note:
See TracChangeset
for help on using the changeset viewer.