0

I am trying short.c in examples of Linux Device Driver 3

My PC has Parallel Port and after the Ubuntu boots up, I can see these:

cat /proc/ioports
0378-037a : parport0
037b-037f : parport0

outp 0x378 1 
(outp is another example in LDD3 which write data to ports)
the LED on the port is ON.

Then I run these commands to remove modules

rmmod lp
rmmod parport_pc
cat /proc/ioports
(There is no module on 0378-037f any more.)

I run this again but the LED is not ON this time.

outp 0x378 1

Then I install short.ko and request_region() succeeds.

cat /proc/ioports
0378-037f : short

cat /proc/devices
249 short

outp 0x378 1
the LED is not ON this time either.

I tried these too, but same result (LED is not ON)

mknod /dev/short0 c 249 0
echo -n "a" > /dev/short0

"a" is 0x61 so that the last bit is 1.

Why can I not write data out though I have got the I/O region?

Thanks for your answer.

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
user1443721
  • 1,110
  • 2
  • 14
  • 33
  • What have you done to verify that you have wired up the LED correctly? – sawdust May 20 '14 at 23:27
  • yes, the LED is wired correctly. I can make it ON before module parport_pc is moved. – user1443721 May 21 '14 at 03:03
  • New findings. I can make code read and write (light the LED too) if I remove request_region() function call and don't unload parport module. Because the parport module is there, the irq 7 is used by it. I have to assign irq 5 to "short" module. Though I enable irq 5 successfully, the interrupt never comes in [by wired pin 9 and pin 10, and outb(0xff, 0x378)]. Checking /proc/interrupts, I notice counter of irq 7 is increased when outb(0xff, 0x378) is called, but irq 5 is always 0. Any suggestion to fix it? – user1443721 May 21 '14 at 07:51

1 Answers1

0

Finally, I found the solution.

Make sure the “parport” module is not loaded or compiled into your kernel. It is not enough to simply unload the parport module, as it leaves the ports in an inconsistent state. You must reboot the machine and keep the parport and all related modules/code from loading in the first place.

One way to do this is to edit the /etc/modprobe.d/blacklist.conf file and add the following lines:

blacklist ppdev
blacklist lp
blacklist parport_pc
blacklist parport

It seems that partport has modify the mode of parallel port.

And if cups is installed, you should modify /etc/modules-load.d/cups-filters.conf:

#lp
#ppdev
#parport_pc
zmzxlw
  • 34
  • 4