LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-12-2008, 10:32 AM   #1
avinashkharbanda
LQ Newbie
 
Registered: Aug 2008
Posts: 6

Rep: Reputation: 0
Question outb() unable to write on the registered port.


Hi All,
I wrote a simple character linux device driver (2.6 kernel) for paralel port and tried to glow the led's by connecting them to paralel port pins.But before requesting for io port 0x378 , I rmmod parportpc.ko and parport.ko and then insmod my own module,, it works fine i.e no error was given but outb() unable to glow the led's.Can anybody tell me What's the problem?

Thanks
Avinash Kharbanda
 
Old 08-12-2008, 11:56 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,749

Rep: Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928
Welcome to LinuxQuestions.
Not really... Without details it is difficult to provide help.
Even though your module loaded without errors does not mean it works.
Your LEDs may not be wired correctly or you did not use the proper resister for current limiting and have burned out the parallel port.
 
Old 08-13-2008, 10:50 AM   #3
avinashkharbanda
LQ Newbie
 
Registered: Aug 2008
Posts: 6

Original Poster
Rep: Reputation: 0
outb unable to glow leds.

Hi,
This is the code for the driver which i wrote :

//-----------------------------------------------------------/

#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/init.h>
#include<linux/fs.h>
#include<linux/types.h>
#include<linux/kdev_t.h>
#include<linux/cdev.h>
#include<asm/uaccess.h>
#include<linux/sched.h>
#include<linux/ioport.h>
#include<linux/interrupt.h>
#include<asm/io.h>

#define PORT 0x378
unsigned int SHORT_IRQ = 7;
unsigned int check_reg = 0;

MODULE_LICENSE("GPL");

dev_t dev;//DEVICE_NUMBER
unsigned char *short_buffer = 0;


// Short's interrupt handler

irqreturn_t short_interrupt_handler (int irq, void *dev_id)
{
printk (KERN_ALERT "Short recieved an interrupt");
return 0;
}

/////////////////////////////


int short_open(struct inode *inode , struct file *filp)
{
short_buffer = kmalloc(1,GFP_KERNEL);

if(short_buffer == 0)
{
printk(KERN_ALERT "Unable to allocate memory");
return -1;
}

// Requesting Port

if(!request_region(PORT,1,"short"))
{
printk(KERN_INFO "short unable to use 0x378 Port");
return -1;
}
else
{
printk(KERN_INFO "short can now use 0x378 Port");
check_reg = 1;
}
////////////////////////////////////////


// Requesting the IRQ Number


if(request_irq(SHORT_IRQ , short_interrupt_handler , SA_INTERRUPT , "short" , NULL))
{
printk(KERN_INFO "short can't get assigned IRQ\n");
SHORT_IRQ = 0;
kfree(short_buffer);
release_region(PORT,1);
return -1;
}
else
{
printk("short is now enabling pnp: 0:7 device");
outb(0x10 , PORT+2);
}

////////////////////////////


return 0;
}

int short_release(struct inode * inode , struct file *filp)
{
if(short_buffer)
{
kfree(short_buffer);
}

if(check_reg)
release_region(PORT,1);

if(SHORT_IRQ == 7)
free_irq(SHORT_IRQ , NULL);

return 0;
}


ssize_t short_read(struct file *filp , char __user *user_buffer , size_t count , loff_t *f_pos)
{
int result = -1;

if(count != 1)
{
printk(KERN_ALERT "Read request failed due to improper count parameter passed");
return result;
}





if(short_buffer)
{
result = copy_to_user(user_buffer , short_buffer , count);
if(result)
{
return -1;
}
else
{
printk(KERN_INFO "\nProcess issued Read :%s\n",current->comm);
}

}

return count;
}



ssize_t short_write(struct file *filp , const char __user *user_buffer , size_t count , loff_t *f_pos)
{
int result = -1;

if(count != 1)
{
printk(KERN_ALERT "Write request failed due to improper count parameter passed");
return result;
}
else
{
printk(KERN_ALERT "Write request passed count parameter");
}

if(short_buffer)
{
result = copy_from_user(short_buffer, user_buffer , count);
if(result)
{
printk(KERN_ALERT "Write request failed due to copy_from_user");

return -1;
}
else
{
printk(KERN_INFO "\nProcess issued Write:%s\n",current->comm);
}

//Writing to port

outb(*short_buffer,PORT);

//////////////////
}

return count;
}



// Registering the file operations with VFS

struct file_operations short_fops = {
.owner = THIS_MODULE,
.read = short_read,
.write= short_write,
.open= short_open,
.release=short_release,
};


static int __init short_init(void)
{

int result;
struct cdev *short_cdev;//For registering the device

// Getting a Major Number Dynamically .....

result = alloc_chrdev_region(&dev,0,1,"short");

if(result < 0)
{
printk(KERN_WARNING "short did'nt got any Major number");
return result;
}
else
{
printk(KERN_INFO "short got Major Number as %d",MAJOR(dev));
}

/////////////////////////////////////////

// Registering the short

short_cdev = cdev_alloc();

short_cdev->owner = THIS_MODULE;
short_cdev->ops = &short_fops;

result = cdev_add(short_cdev,dev,1);

if(result)
{
printk(KERN_NOTICE "short unable to add");
return -1;
}

////////////////////////////////////////

return 0;
}

static void __exit short_exit(void)
{
unregister_chrdev_region(dev,1);
}

module_init(short_init);
module_exit(short_exit);


//----------------------------------------------------------/

1)Initially I loaded the module short.ko using insmod
2)made the file with Major Number received dynamically.
3)rmmoded the parport & parportpc.
4)then I wrote an application program that wud write on this file.
5)the printk(KERN_INFO "\nProcess issued Write:%s\n",current->comm); line
in short_write got executed but Led's did'nt glow.

Can u plz help me out.
 
Old 08-15-2008, 04:56 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,749

Rep: Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928
Sorry, I am unable to take to time to look at your driver. Hopefully someone else might.
 
Old 08-27-2008, 05:30 AM   #5
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
neither can I, but are you sure that the x86 chip has an IOPL which will allow you to output you byte or whatever>?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
root unable to write on drive mounted with read/write perrmission aquash2000 Linux - Server 5 07-19-2008 12:20 PM
Unable to allocate port with port forwarding software djeepp Linux - Networking 3 01-29-2008 07:28 AM
unable to install mplayer on RHEl 5.0 its throwing an error not registered with RHN sangayya.a Linux - Enterprise 7 10-29-2007 04:57 AM
registered verion software wants to write to widows registry phoneguy Linux - Desktop 4 11-21-2006 08:46 PM
Help please: outb() linyiji Linux - Hardware 1 05-27-2005 10:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration