Esempio n. 1
0
File: kbd.c Progetto: PyroOS/Pyro
status_t device_init( int nDeviceID )
{
    int nError;
    int nHandle;
    printk( "Keyboard device: device_init() called\n" );

    g_sVolume.hWaitThread    = -1;
    atomic_set( &g_sVolume.nInPos, 0 );
    atomic_set( &g_sVolume.nOutPos, 0 );
    atomic_set( &g_sVolume.nBytesReceived, 0 );
    atomic_set( &g_sVolume.nOpenCount, 0 );
    g_sVolume.nIrqHandle	   = request_irq( 1, kbd_irq, NULL, 0, "keyboard_device", NULL );

    g_nKbdLedStatus = 0;
  
    if ( g_sVolume.nIrqHandle < 0 ) {
	printk( "ERROR : Failed to initiate keyboard interrupt handler\n" );
	return( g_sVolume.nIrqHandle );
    }
    
	nHandle = register_device( "", "system" );
	claim_device( nDeviceID, nHandle , "Keyboard", DEVICE_INPUT );
    nError = create_device_node( nDeviceID, nHandle, "keybd", &g_sOperations, NULL );
    
    return( nError );
}
Esempio n. 2
0
int slogic_open(struct slogic_ctx *handle, int logic_index){
int err,i;	
size_t cnt;
libusb_device **list;
libusb_device *found = NULL;
struct libusb_device_descriptor descriptor;	
	
	cnt = libusb_get_device_list(handle->usb_context, &list);
	i = 0;
	if (cnt < 0) {
		log_printf( DEBUG,  "Failed to get a list of devices\n");
		return 0;
	}
	
	for (i = 0; i < cnt; i++) {
		libusb_device *device = list[i];
		err = libusb_get_device_descriptor(device, &descriptor);
		if (err) {
			log_printf( DEBUG,  "libusb_get_device_descriptor: %s\n", usbutil_error_to_string(err));
			libusb_free_device_list(list, 1);
			return 0;
		}
		if ((descriptor.idVendor == USB_VENDOR_ID) && (descriptor.idProduct == USB_PRODUCT_ID)) {
			found = device;
			usbutil_dump_device_descriptor(&descriptor);
			break;
		}
	}
	
	if (!found) {
		log_printf( DEBUG,  "Device not found\n");
		libusb_free_device_list(list, 1);
		return 0;
	}
	
	if ((err = libusb_open(found, &handle->device_handle))) {
		log_printf( DEBUG,  "Failed OPEN the device: %s\n", usbutil_error_to_string(err));
		libusb_free_device_list(list, 1);
		return 0;
	}
	log_printf( DEBUG,  "libusb_open: %s\n", usbutil_error_to_string(err));	
	
	if ((err = claim_device(handle->device_handle, 0)) != 0) {
		log_printf( DEBUG, "Failed to claim the usb interface: %s\n", usbutil_error_to_string(err));
		libusb_free_device_list(list, 1);
		return 0;
	}	
	
	
	if (!handle->device_handle) {
		log_printf( ERR, "Failed to open the device\n");
		libusb_free_device_list(list, 1);
		return -1;
	}
	libusb_free_device_list(list, 1);
	handle->dev = libusb_get_device(handle->device_handle);
	handle->transfers = calloc(1,sizeof(struct logic_transfers) * handle->n_transfer_buffers);

	return 0;
}
Esempio n. 3
0
File: ps2.c Progetto: PyroOS/Pyro
/* Initializes the controller and the keyboard part */
static status_t ps2_keyboard_init()
{
	int nError = 0;
	g_nKbdLedStatus = 0;
	
	memset( &g_sKbdPort, 0, sizeof( g_sKbdPort ) );
	
	/* Flush buffer */
	ps2_flush();
	
	/* Read control register */
	uint8 nControl = 0;
	nError = ps2_read_command( PS2_CMD_RCTR, &nControl );
	
	if( nError < 0 ) {
		printk( "PS2 I/O error\n" );
		return( -EIO );
	}
	
	/* TODO: Disable keyboard */
	nControl |= PS2_CTR_KBDDIS;
	nControl &= ~PS2_CTR_KBDINT;
	
	/* Check if translated mode is enabled */
	if( !( nControl & PS2_CTR_XLATE ) )
	{
		printk( "Keyboard is in non-translated mode. This is not supported\n" );
		return( -ENOENT );
	}
	
	/* Write control register */
	nError = ps2_write_command( PS2_CMD_WCTR, nControl );
	if( nError < 0 ) {
		printk( "PS2 I/O error\n" );
		return( -EIO );
	}
	
	g_sKbdPort.bPresent = true;
	g_sKbdPort.hWait = create_semaphore( "ps2_wait", 0, 0 );
	g_sKbdPort.nIrq = 1;
	g_sKbdPort.nDevHandle = register_device( "", "isa" );
	claim_device( g_nDevNum, g_sKbdPort.nDevHandle, "PS/2 or AT keyboard", DEVICE_INPUT );
	set_device_data( g_sKbdPort.nDevHandle, &g_sKbdPort );
	nError = create_device_node( g_nDevNum, g_sKbdPort.nDevHandle, "keybd", &g_sOperations, &g_sKbdPort );
	
	printk( "PS2 or AT Keyboard detected\n" );
	return( 0 );
}
Esempio n. 4
0
struct bbc_i2c_client *bbc_i2c_attach(struct linux_ebus_child *echild)
{
	struct bbc_i2c_bus *bp = find_bus_for_device(echild);
	struct bbc_i2c_client *client;

	if (!bp)
		return NULL;
	client = kmalloc(sizeof(*client), GFP_KERNEL);
	if (!client)
		return NULL;
	memset(client, 0, sizeof(*client));
	client->bp = bp;
	client->echild = echild;
	client->bus = echild->resource[0].start;
	client->address = echild->resource[1].start;

	claim_device(bp, echild);

	return client;
}
Esempio n. 5
0
struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct of_device *op)
{
	struct bbc_i2c_client *client;
	const u32 *reg;

	client = kzalloc(sizeof(*client), GFP_KERNEL);
	if (!client)
		return NULL;
	client->bp = bp;
	client->op = op;

	reg = of_get_property(op->node, "reg", NULL);
	if (!reg) {
		kfree(client);
		return NULL;
	}

	client->bus = reg[0];
	client->address = reg[1];

	claim_device(bp, op);

	return client;
}
Esempio n. 6
0
File: driver.c Progetto: PyroOS/Pyro
status_t device_init( int nDeviceID )
{
	PCI_bus_s *psBus;
	int nNumDevices = sizeof( g_sDevices ) / sizeof( struct gfx_device );
	int nDeviceNum;
	PCI_Info_s sInfo;
	int nPCINum;
	char zTemp[255];
	char zNodePath[255];
	struct gfx_node *psNode;
	bool bDevFound = false;

	/* Get PCI busmanager */
	psBus = get_busmanager( PCI_BUS_NAME, PCI_BUS_VERSION );
	if( psBus == NULL )
		return ( -ENODEV );

	/* Look for the device */
	for( nPCINum = 0; psBus->get_pci_info( &sInfo, nPCINum ) == 0; ++nPCINum )
	{
		for( nDeviceNum = 0; nDeviceNum < nNumDevices; ++nDeviceNum )
		{
			/* Compare vendor and device id */
			if( sInfo.nVendorID == g_sDevices[nDeviceNum].nVendorID && sInfo.nDeviceID == g_sDevices[nDeviceNum].nDeviceID )
			{
				sprintf( zTemp, "%s %s", g_sDevices[nDeviceNum].zVendorName, g_sDevices[nDeviceNum].zDeviceName );
				if( claim_device( nDeviceID, sInfo.nHandle, zTemp, DEVICE_VIDEO ) != 0 )
				{
					continue;
				}

				printk( "%s found\n", zTemp );

				/* Create private node */
				psNode = kmalloc( sizeof( struct gfx_node ), MEMF_KERNEL | MEMF_CLEAR | MEMF_NOBLOCK );
				if( psNode == NULL )
				{
					printk( "Error: Out of memory\n" );
					continue;
				}
				memcpy( &psNode->sInfo, &sInfo, sizeof( PCI_Info_s ) );
				strcpy( psNode->zName, zTemp );

				/* Create node path */
				sprintf( zNodePath, "graphics/tdfx_%i_0x%x_0x%x", nPCINum, ( uint )sInfo.nVendorID, ( uint )sInfo.nDeviceID );

				if( create_device_node( nDeviceID, sInfo.nHandle, zNodePath, &g_sOperations, psNode ) < 0 )
				{
					printk( "Error: Failed to create device node %s\n", zNodePath );
					continue;
				}

				bDevFound = true;
			}
		}
	}

	if( !bDevFound )
	{
		disable_device( nDeviceID );
		return ( -ENODEV );
	}

	return ( 0 );
}
Esempio n. 7
0
/*
 * Iterates over the usb devices on the usb busses and returns a handle to the
 * first device found that matches the predefined vendor and product id
 */
libusb_device_handle *open_device(libusb_context * ctx, int vendor_id, int product_id)
{
	// discover devices
	libusb_device **list;
	libusb_device *found = NULL;
	libusb_device_handle *device_handle = NULL;
	struct libusb_device_descriptor descriptor;

	size_t cnt = libusb_get_device_list(ctx, &list);
	size_t i = 0;
	int err = 0;
	if (cnt < 0) {
		fprintf(stderr, "Failed to get a list of devices\n");
		return NULL;
	}

	for (i = 0; i < cnt; i++) {
		libusb_device *device = list[i];
		err = libusb_get_device_descriptor(device, &descriptor);
		if (err) {
			fprintf(stderr, "libusb_get_device_descriptor: %s\n", usbutil_error_to_string(err));
			libusb_free_device_list(list, 1);
			return NULL;
		}
		if ((descriptor.idVendor == vendor_id) && (descriptor.idProduct == product_id)) {
			found = device;
			usbutil_dump_device_descriptor(stderr, &descriptor);
			break;
		}
	}

	if (!found) {
		fprintf(stderr, "Device not found\n");
		libusb_free_device_list(list, 1);
		return NULL;
	}

	if ((err = libusb_open(found, &device_handle))) {
		fprintf(stderr, "Failed OPEN the device: %s\n", usbutil_error_to_string(err));
		libusb_free_device_list(list, 1);
		return NULL;
	}
	fprintf(stderr, "libusb_open: %s\n", usbutil_error_to_string(err));

	libusb_free_device_list(list, 1);

	if ((err = claim_device(device_handle, 0)) != 0) {
		fprintf(stderr, "Failed to claim the usb interface: %s\n", usbutil_error_to_string(err));
		return NULL;
	}

	struct libusb_config_descriptor *config_descriptor;
	err = libusb_get_active_config_descriptor(found, &config_descriptor);
	if (err) {
		fprintf(stderr, "libusb_get_active_config_descriptor: %s\n", usbutil_error_to_string(err));
		return NULL;
	}
	fprintf(stderr, "Active configuration:%d\n", config_descriptor->bConfigurationValue);
	libusb_free_config_descriptor(config_descriptor);

	fprintf(stderr, "Available configurations (%d):\n", descriptor.bNumConfigurations);
	for (i = 0; i < descriptor.bNumConfigurations; i++) {
		err = libusb_get_config_descriptor(found, i, &config_descriptor);
		if (err) {
			fprintf(stderr, "libusb_get_config_descriptor: %s\n", usbutil_error_to_string(err));
			return NULL;
		}

		usbutil_dump_config_descriptor(stderr, config_descriptor);
		libusb_free_config_descriptor(config_descriptor);
	}

	return device_handle;
}
Esempio n. 8
0
File: ps2.c Progetto: PyroOS/Pyro
static status_t ps2_aux_init()
{
	int nError = 0;
	struct RMREGS rm;

	/* TODO: Do this without calling the bios */
	memset( &rm, 0, sizeof( struct RMREGS ) );
	realint( 0x11, &rm );

	if( ( rm.EAX & 0x04 ) == 0 ) {
		printk( "No PS2 mouse present\n" );
		return( -EIO );
    }
	
	memset( &g_sAuxPort, 0, sizeof( g_sAuxPort ) );
	g_sAuxPort.bIsAux = true;
	
	/* Flush buffer */
	ps2_flush();
	
	/* Test loop command */
	uint8 nData = 0x5a;
	
	nError = ps2_write_read_command( PS2_CMD_AUX_LOOP, &nData );
	
	if( nError < 0 || nData != 0x5a )
	{
		/* According to linux driver the loop test fails on some chipsets */
		printk( "PS2 Aux loop test failed (error = %i, data = %x)! Trying test command...\n", nError, (uint)nData );
		if( ps2_read_command( PS2_CMD_AUX_TEST, &nData ) < 0 )
		{
			printk( "Failed -> Aux port not present!\n" );
			return( -ENOENT );
		}
		printk( "Test command returned %x\n", (uint)nData );
		if( nData && nData != 0xfa && nData != 0xff )
		{
			printk( "Invalid return code!\n" );
			return( -ENOENT );
		}
	}
	
	/* Disable and then enable the auxport */
	if( ps2_command( PS2_CMD_AUX_DISABLE ) < 0 )
		return( -ENOENT );
	if( ps2_command( PS2_CMD_AUX_ENABLE ) < 0 )
		return( -ENOENT );
	if( ps2_read_command( PS2_CMD_RCTR, &nData ) < 0 || ( nData & PS2_CTR_AUXDIS ) )
		return( -EIO );
		
	/* Disable aux port */
	nData |= PS2_CTR_AUXDIS;
	nData &= ~PS2_CTR_AUXINT;
	
	/* Write control register */
	nError = ps2_write_command( PS2_CMD_WCTR, nData );
	if( nError < 0 ) {
		printk( "PS2 I/O error\n" );
		return( -EIO );
	}

	printk( "PS2 AUX port detected\n" );
	
	/* Register device */
	
	g_sAuxPort.bPresent = true;
	g_sAuxPort.hWait = create_semaphore( "ps2_wait", 0, 0 );
	g_sAuxPort.nDevHandle = register_device( "", "isa" );
	g_sAuxPort.nIrq = 12;
	claim_device( g_nDevNum, g_sAuxPort.nDevHandle, "PS/2 Aux port", DEVICE_PORT );
	set_device_data( g_sAuxPort.nDevHandle, &g_sAuxPort );
	nError = create_device_node( g_nDevNum, g_sAuxPort.nDevHandle, "misc/ps2aux", &g_sOperations, &g_sAuxPort );
	
	if( nError < 0 )
		return( -EIO );
	
	return( 0 );
}