Changeset 336f03b in mainline
- Timestamp:
- 2011-12-27T10:53:46Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a84ddf0
- Parents:
- 9ff60d1
- Location:
- uspace/drv/char/i8042
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/i8042/i8042.c
r9ff60d1 r336f03b 57 57 static int i8042_write_aux(ddf_fun_t *, char *, size_t); 58 58 static int i8042_read_aux(ddf_fun_t *, char *, size_t); 59 59 /*----------------------------------------------------------------------------*/ 60 /** Primary port interface structure. */ 60 61 static char_dev_ops_t kbd_iface = { 61 62 .read = i8042_read_kbd, 62 63 .write = i8042_write_kbd, 63 64 }; 64 65 /*----------------------------------------------------------------------------*/ 66 /** Auxiliary port interface structure. */ 65 67 static char_dev_ops_t aux_iface = { 66 68 .read = i8042_read_aux, 67 69 .write = i8042_write_aux, 68 70 }; 69 71 /*----------------------------------------------------------------------------*/ 72 /** Primary port function operations. */ 70 73 static ddf_dev_ops_t kbd_ops = { 71 74 .interfaces[CHAR_DEV_IFACE] = &kbd_iface 72 75 }; 73 76 /*----------------------------------------------------------------------------*/ 77 /** Auxiliary port function operations. */ 74 78 static ddf_dev_ops_t aux_ops = { 75 79 .interfaces[CHAR_DEV_IFACE] = &aux_iface … … 92 96 #define i8042_KBD_TRANSLATE 0x40 /* Use this to switch to XT scancodes */ 93 97 98 /** i8042 Interrupt pseudo-code. */ 94 99 static const irq_cmd_t i8042_cmds[] = { 95 100 { … … 119 124 }; 120 125 /*----------------------------------------------------------------------------*/ 126 /** Wait until it is safe to write to the device. */ 121 127 static void wait_ready(i8042_t *dev) 122 128 { … … 125 131 } 126 132 /*----------------------------------------------------------------------------*/ 127 static void wait_ready_write(i8042_t *dev) 128 { 129 assert(dev); 130 while (pio_read_8(&dev->regs->status) & i8042_OUTPUT_FULL); 131 } 132 /*----------------------------------------------------------------------------*/133 /** Interrupt handler routine. 134 * Writes new data to the corresponding buffer. 135 * @param dev Device that caued the interrupt. 136 * @param iid Call id. 137 * @param call pointerr to call data. 138 */ 133 139 static void i8042_irq_handler( 134 140 ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call) … … 145 151 } 146 152 /*----------------------------------------------------------------------------*/ 153 /** Initialize i8042 driver structure. 154 * @param dev Driver structure to initialize. 155 * @param regs I/O address of registers. 156 * @param reg_size size of the reserved I/O address space. 157 * @param irq_kbd IRQ for primary port. 158 * @param irq_mouse IRQ for aux port. 159 * @param ddf_dev DDF device structure of the device. 160 * @return Error code. 161 */ 147 162 int i8042_init(i8042_t *dev, void *regs, size_t reg_size, int irq_kbd, 148 163 int irq_mouse, ddf_dev_t *ddf_dev) … … 273 288 } 274 289 /*----------------------------------------------------------------------------*/ 290 /** Write data to i8042 primary port. 291 * @param fun DDF function. 292 * @param buffer Data source. 293 * @param size Data size. 294 * @return Bytes written. 295 */ 275 296 static int i8042_write_kbd(ddf_fun_t *fun, char *buffer, size_t size) 276 297 { … … 280 301 fibril_mutex_lock(&controller->write_guard); 281 302 for (size_t i = 0; i < size; ++i) { 282 wait_ready _write(controller);303 wait_ready(controller); 283 304 pio_write_8(&controller->regs->data, buffer[i]); 284 305 } … … 287 308 } 288 309 /*----------------------------------------------------------------------------*/ 310 /** Read data from i8042 primary port. 311 * @param fun DDF function. 312 * @param buffer Data place. 313 * @param size Data place size. 314 * @return Bytes read. 315 */ 289 316 static int i8042_read_kbd(ddf_fun_t *fun, char *buffer, size_t size) 290 317 { … … 301 328 } 302 329 /*----------------------------------------------------------------------------*/ 330 /** Write data to i8042 auxiliary port. 331 * @param fun DDF function. 332 * @param buffer Data source. 333 * @param size Data size. 334 * @return Bytes written. 335 */ 303 336 static int i8042_write_aux(ddf_fun_t *fun, char *buffer, size_t size) 304 337 { … … 308 341 fibril_mutex_lock(&controller->write_guard); 309 342 for (size_t i = 0; i < size; ++i) { 310 wait_ready _write(controller);343 wait_ready(controller); 311 344 pio_write_8(&controller->regs->status, i8042_CMD_WRITE_AUX); 312 345 pio_write_8(&controller->regs->data, buffer[i]); … … 316 349 } 317 350 /*----------------------------------------------------------------------------*/ 351 /** Read data from i8042 auxiliary port. 352 * @param fun DDF function. 353 * @param buffer Data place. 354 * @param size Data place size. 355 * @return Bytes read. 356 */ 318 357 static int i8042_read_aux(ddf_fun_t *fun, char *buffer, size_t size) 319 358 { -
uspace/drv/char/i8042/i8042.h
r9ff60d1 r336f03b 53 53 } __attribute__ ((packed)) i8042_regs_t; 54 54 55 typedef struct i8042 i8042_t; 56 57 struct i8042 { 58 i8042_regs_t *regs; 59 ddf_fun_t *kbd_fun; 60 ddf_fun_t *mouse_fun; 61 buffer_t aux_buffer; 62 buffer_t kbd_buffer; 63 uint8_t aux_data[BUFFER_SIZE]; 64 uint8_t kbd_data[BUFFER_SIZE]; 65 fibril_mutex_t write_guard; 66 }; 55 /** i8042 driver structure. */ 56 typedef struct i8042 { 57 i8042_regs_t *regs; /**< I/O registers. */ 58 ddf_fun_t *kbd_fun; /**< Pirmary port device function. */ 59 ddf_fun_t *mouse_fun; /**< Auxiliary port device function. */ 60 buffer_t kbd_buffer; /**< Primary port buffer. */ 61 buffer_t aux_buffer; /**< Aux. port buffer. */ 62 uint8_t aux_data[BUFFER_SIZE]; /**< Primary port buffer space. */ 63 uint8_t kbd_data[BUFFER_SIZE]; /**< Aux. port buffer space. */ 64 fibril_mutex_t write_guard; /**< Prevents simultanous port writes.*/ 65 } i8042_t; 67 66 68 67 int i8042_init(i8042_t *, void *, size_t, int, int, ddf_dev_t *); -
uspace/drv/char/i8042/main.c
r9ff60d1 r336f03b 48 48 static int get_my_registers(const ddf_dev_t *dev, 49 49 uintptr_t *io_reg_address, size_t *io_reg_size, int *kbd, int *mouse); 50 51 50 static int i8042_dev_add(ddf_dev_t *device); 52 51 /*----------------------------------------------------------------------------*/ 52 /** DDF driver operations. */ 53 53 static driver_ops_t i8042_driver_ops = { 54 54 .dev_add = i8042_dev_add, 55 55 }; 56 56 /*----------------------------------------------------------------------------*/ 57 /** DDF driver. */ 57 58 static driver_t i8042_driver = { 58 59 .name = NAME, 59 60 .driver_ops = &i8042_driver_ops 60 61 }; 61 62 /*----------------------------------------------------------------------------*/ 62 63 /** Initialize global driver structures (NONE). 63 64 * … … 71 72 { 72 73 printf(NAME ": HelenOS ps/2 driver.\n"); 73 ddf_log_init(NAME, LVL_ DEBUG2);74 ddf_log_init(NAME, LVL_NOTE); 74 75 return ddf_driver_main(&i8042_driver); 75 76 } 76 77 /*----------------------------------------------------------------------------*/ 77 78 /** Initialize a new ddf driver instance of i8042 driver 78 79 * … … 120 121 * @param[out] io_reg_address Base address of the memory range. 121 122 * @param[out] io_reg_size Size of the memory range. 123 * @param[out] kbd_irq Primary port IRQ. 124 * @param[out] mouse_irq Auxiliary port IRQ. 122 125 * @return Error code. 123 126 */
Note:
See TracChangeset
for help on using the changeset viewer.