Lines Matching refs:drvdata
232 static int hwicap_command_desync(struct hwicap_drvdata *drvdata) in hwicap_command_desync() argument
240 buffer[index++] = hwicap_type_1_write(drvdata->config_regs->CMD) | 1; in hwicap_command_desync()
249 return drvdata->config->set_configuration(drvdata, in hwicap_command_desync()
266 static int hwicap_get_configuration_register(struct hwicap_drvdata *drvdata, in hwicap_get_configuration_register() argument
286 status = drvdata->config->set_configuration(drvdata, in hwicap_get_configuration_register()
292 status = drvdata->config->get_status(drvdata); in hwicap_get_configuration_register()
305 status = drvdata->config->set_configuration(drvdata, in hwicap_get_configuration_register()
313 status = drvdata->config->get_configuration(drvdata, reg_data, 1); in hwicap_get_configuration_register()
320 static int hwicap_initialize_hwicap(struct hwicap_drvdata *drvdata) in hwicap_initialize_hwicap() argument
325 dev_dbg(drvdata->dev, "initializing\n"); in hwicap_initialize_hwicap()
330 dev_dbg(drvdata->dev, "Reset...\n"); in hwicap_initialize_hwicap()
331 drvdata->config->reset(drvdata); in hwicap_initialize_hwicap()
333 dev_dbg(drvdata->dev, "Desync...\n"); in hwicap_initialize_hwicap()
334 status = hwicap_command_desync(drvdata); in hwicap_initialize_hwicap()
342 dev_dbg(drvdata->dev, "Reading IDCODE...\n"); in hwicap_initialize_hwicap()
344 drvdata, drvdata->config_regs->IDCODE, &idcode); in hwicap_initialize_hwicap()
345 dev_dbg(drvdata->dev, "IDCODE = %x\n", idcode); in hwicap_initialize_hwicap()
349 dev_dbg(drvdata->dev, "Desync...\n"); in hwicap_initialize_hwicap()
350 status = hwicap_command_desync(drvdata); in hwicap_initialize_hwicap()
360 struct hwicap_drvdata *drvdata = file->private_data; in hwicap_read() local
367 status = mutex_lock_interruptible(&drvdata->sem); in hwicap_read()
371 if (drvdata->read_buffer_in_use) { in hwicap_read()
376 (count < drvdata->read_buffer_in_use) ? count : in hwicap_read()
377 drvdata->read_buffer_in_use; in hwicap_read()
380 if (copy_to_user(buf, drvdata->read_buffer, bytes_to_read)) { in hwicap_read()
384 drvdata->read_buffer_in_use -= bytes_to_read; in hwicap_read()
385 memmove(drvdata->read_buffer, in hwicap_read()
386 drvdata->read_buffer + bytes_to_read, in hwicap_read()
415 status = drvdata->config->get_configuration(drvdata, in hwicap_read()
430 memcpy(drvdata->read_buffer, in hwicap_read()
433 drvdata->read_buffer_in_use = bytes_remaining; in hwicap_read()
438 mutex_unlock(&drvdata->sem); in hwicap_read()
446 struct hwicap_drvdata *drvdata = file->private_data; in hwicap_write() local
453 status = mutex_lock_interruptible(&drvdata->sem); in hwicap_write()
457 left += drvdata->write_buffer_in_use; in hwicap_write()
480 if (drvdata->write_buffer_in_use) { in hwicap_write()
481 memcpy(kbuf, drvdata->write_buffer, in hwicap_write()
482 drvdata->write_buffer_in_use); in hwicap_write()
484 (((char *)kbuf) + drvdata->write_buffer_in_use), in hwicap_write()
486 len - (drvdata->write_buffer_in_use))) { in hwicap_write()
499 status = drvdata->config->set_configuration(drvdata, in hwicap_write()
507 if (drvdata->write_buffer_in_use) { in hwicap_write()
508 len -= drvdata->write_buffer_in_use; in hwicap_write()
509 left -= drvdata->write_buffer_in_use; in hwicap_write()
510 drvdata->write_buffer_in_use = 0; in hwicap_write()
516 if (!copy_from_user(drvdata->write_buffer, in hwicap_write()
518 drvdata->write_buffer_in_use = left; in hwicap_write()
527 mutex_unlock(&drvdata->sem); in hwicap_write()
533 struct hwicap_drvdata *drvdata; in hwicap_open() local
537 drvdata = container_of(inode->i_cdev, struct hwicap_drvdata, cdev); in hwicap_open()
539 status = mutex_lock_interruptible(&drvdata->sem); in hwicap_open()
543 if (drvdata->is_open) { in hwicap_open()
548 status = hwicap_initialize_hwicap(drvdata); in hwicap_open()
550 dev_err(drvdata->dev, "Failed to open file"); in hwicap_open()
554 file->private_data = drvdata; in hwicap_open()
555 drvdata->write_buffer_in_use = 0; in hwicap_open()
556 drvdata->read_buffer_in_use = 0; in hwicap_open()
557 drvdata->is_open = 1; in hwicap_open()
560 mutex_unlock(&drvdata->sem); in hwicap_open()
568 struct hwicap_drvdata *drvdata = file->private_data; in hwicap_release() local
572 mutex_lock(&drvdata->sem); in hwicap_release()
574 if (drvdata->write_buffer_in_use) { in hwicap_release()
576 for (i = drvdata->write_buffer_in_use; i < 4; i++) in hwicap_release()
577 drvdata->write_buffer[i] = 0; in hwicap_release()
579 status = drvdata->config->set_configuration(drvdata, in hwicap_release()
580 (u32 *) drvdata->write_buffer, 1); in hwicap_release()
585 status = hwicap_command_desync(drvdata); in hwicap_release()
590 drvdata->is_open = 0; in hwicap_release()
591 mutex_unlock(&drvdata->sem); in hwicap_release()
610 struct hwicap_drvdata *drvdata = NULL; in hwicap_setup() local
639 drvdata = kzalloc(sizeof(struct hwicap_drvdata), GFP_KERNEL); in hwicap_setup()
640 if (!drvdata) { in hwicap_setup()
644 dev_set_drvdata(dev, (void *)drvdata); in hwicap_setup()
652 drvdata->mem_start = regs_res->start; in hwicap_setup()
653 drvdata->mem_end = regs_res->end; in hwicap_setup()
654 drvdata->mem_size = resource_size(regs_res); in hwicap_setup()
656 if (!request_mem_region(drvdata->mem_start, in hwicap_setup()
657 drvdata->mem_size, DRIVER_NAME)) { in hwicap_setup()
664 drvdata->devt = devt; in hwicap_setup()
665 drvdata->dev = dev; in hwicap_setup()
666 drvdata->base_address = ioremap(drvdata->mem_start, drvdata->mem_size); in hwicap_setup()
667 if (!drvdata->base_address) { in hwicap_setup()
673 drvdata->config = config; in hwicap_setup()
674 drvdata->config_regs = config_regs; in hwicap_setup()
676 mutex_init(&drvdata->sem); in hwicap_setup()
677 drvdata->is_open = 0; in hwicap_setup()
680 (unsigned long long) drvdata->mem_start, in hwicap_setup()
681 drvdata->base_address, in hwicap_setup()
682 (unsigned long long) drvdata->mem_size); in hwicap_setup()
684 cdev_init(&drvdata->cdev, &hwicap_fops); in hwicap_setup()
685 drvdata->cdev.owner = THIS_MODULE; in hwicap_setup()
686 retval = cdev_add(&drvdata->cdev, devt, 1); in hwicap_setup()
696 iounmap(drvdata->base_address); in hwicap_setup()
699 release_mem_region(regs_res->start, drvdata->mem_size); in hwicap_setup()
702 kfree(drvdata); in hwicap_setup()
812 struct hwicap_drvdata *drvdata; in hwicap_drv_remove() local
814 drvdata = dev_get_drvdata(dev); in hwicap_drv_remove()
816 device_destroy(&icap_class, drvdata->devt); in hwicap_drv_remove()
817 cdev_del(&drvdata->cdev); in hwicap_drv_remove()
818 iounmap(drvdata->base_address); in hwicap_drv_remove()
819 release_mem_region(drvdata->mem_start, drvdata->mem_size); in hwicap_drv_remove()
820 kfree(drvdata); in hwicap_drv_remove()