Skip to contentSkip to conversation

drivers: add LCD support

PATCH In review Miguel Ojeda Sandonis 2 participants 3 messages Oct 31, 2006 – Nov 1, 2006

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: add LCD support

Andrew, here it is the fifth update for the drivers-add-lcd-support. This is a general improvement. The main point is the four new exported functions that help reducing conflicts, provide more information, may reduce some CPU time wasting, etc.

Please review mutex-locking of cfag12864b_enable() and cfag12864b_disable() added exported functions before applying. Thanks you.

Thanks Paulo Marques and Franck Bui-Huu for their time & ideas. Also, please review the patch. There are many small changes, maybe I missed something in all the mess.
---

- New exported functions for cfag12864b useful for future modules, feature adding and avoiding conflicts.
· cfag12864b_getrate() - Returns the refreshing rate (hertzs).
· cfag12864b_enable() - Enable refreshing.
Return 0 if successful. Anyone was using the LCD. Return != 0 if failed. Someone is using the LCD.
· cfag12864b_disable() - Disable refreshing.
· cfag12864b_isenabled() - Returns 0 if refreshing is not enabled.
Return 0 if refreshing is not enabled. Anyone is using the LCD. Return != 0 if refresing is enabled. Someone is using the LCD.

This way, cfag12864b doesn't waste CPU time until some module request refreshing.
Also, when a module is over working with the LCD, it should disable it, so other modules can take the control, and CPU time isn't waste.

In addition, a module which wants to uses the LCD should check if there
is anyone using it (enable will return !=0 if so).

Modules which only want to read it the buffer can use isenabled() to check if
there is any module using it so they can take useful information, for example.

Finally, now a nodule has a way to know what the refreshing rate is
by calling getrate();

- Improved headers (cfag12864b.h and ks0108.h) · Now every exported function is briefly explained.

- Fixed code related to destroying the workqueue:
· Now the workqueue is destroyed safely without any sleeping.

- Adds an userspace example program at Documentation/auxdisplay/cfag12864b-example

- Fixed GPL headers to be only v2 as "License: GPLv2" header line and "MODULE_LICENSE" states.

- Cleaned #includes to be alphabetically ordered.

 Documentation/auxdisplay/cfag12864b           |   28 -
 Documentation/auxdisplay/cfag12864b-example.c |  282 ++++++++++++++++
 Documentation/auxdisplay/ks0108               |    2
 drivers/auxdisplay/cfag12864b.c               |  100 ++++-
 drivers/auxdisplay/cfag12864bfb.c             |   30 +
 drivers/auxdisplay/ks0108.c                   |   17
 include/linux/cfag12864b.h                    |   42 ++
 include/linux/ks0108.h                        |   18 -
 8 files changed, 441 insertions(+), 78 deletions(-)

miguelojeda-2.6.19-rc1-drivers-add-LCD-support-5-general-improvement.patch

---

Documentation/auxdisplay/cfag12864b +4 -24
diff -uprN -X dontdiff linux-2.6.19-rc1-mod2/Documentation/auxdisplay/cfag12864b linux/Documentation/auxdisplay/cfag12864b
@@ -96,30 +96,10 @@ Each bit represents one pixel. If the bi
 turn on. If the pixel is low, the pixel will turn off.
 
 You can use the framebuffer as a file: fopen, fwrite, fclose...
+Although the LCD won't get updated until the next refresh time arrives.
 
 Also, you can mmap the framebuffer: open & mmap, munmap & close...
-which is the best option.
+which is the best option for most uses.
 
-You can use a copy of this header in your userspace programs.
-
----8<---
-/*
- *    Filename: cfag12864b.h
- * Description: cfag12864b LCD Display Driver Header for user-space apps
- *
- *      Author: Miguel Ojeda Sandonis <[email protected]>
- *        Date: 2006-10-27
- */
-
-#ifndef _CFAG12864B_H_
-#define _CFAG12864B_H_
-
-#define CFAG12864B_WIDTH	(128)
-#define CFAG12864B_HEIGHT	(64)
-#define CFAG12864B_SIZE		(1024)
-
-#endif // _CFAG12864B_H_
----8<---
-
-
-EOF
+Check Documentation/auxdisplay/cfag12864b-example.c
+for a real working userspace complete program with usage examples.
Documentation/auxdisplay/cfag12864b-example.c +282 -0

282 lines not on this page · raw message

Documentation/auxdisplay/ks0108 +0 -2
diff -uprN -X dontdiff linux-2.6.19-rc1-mod2/Documentation/auxdisplay/ks0108 linux/Documentation/auxdisplay/ks0108
@@ -53,5 +53,3 @@ If you aren't building LCD related hardw
 your LCD specific wiring information in the same folder.
 
 For example, check Documentation/auxdisplay/cfag12864b.
-
-EOF
drivers/auxdisplay/cfag12864b.c +75 -25

165 lines not on this page · raw message

drivers/auxdisplay/cfag12864bfb.c +19 -11
diff -uprN -X dontdiff linux-2.6.19-rc1-mod2/drivers/auxdisplay/cfag12864bfb.c linux/drivers/auxdisplay/cfag12864bfb.c
@@ -6,12 +6,11 @@
  *     Depends: cfag12864b
  *
  *      Author: Copyright (C) Miguel Ojeda Sandonis <[email protected]>
- *        Date: 2006-10-26
+ *        Date: 2006-10-31
  *
  *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -24,18 +23,18 @@
  *
  */
 
+#include <linux/init.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/string.h>
-#include <linux/mm.h>
-#include <linux/slab.h>
 #include <linux/delay.h>
+#include <linux/errno.h>
 #include <linux/fb.h>
+#include <linux/mm.h>
 #include <linux/platform_device.h>
-#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/uaccess.h>
 #include <linux/cfag12864b.h>
-#include <asm/uaccess.h>
 
 #define CFAG12864BFB_NAME "cfag12864bfb"
 
@@ -155,7 +154,15 @@ static struct platform_device *cfag12864
 
 static int __init cfag12864bfb_init(void)
 {
-	int ret = platform_driver_register(&cfag12864bfb_driver);
+	int ret;
+
+	if(cfag12864b_enable()) {
+		printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
+			"can't enable cfag12864b refreshing (being used)\n");
+		return -ENODEV;
+	}
+
+	ret = platform_driver_register(&cfag12864bfb_driver);
 
 	if (!ret) {
 		cfag12864bfb_device =
@@ -179,6 +186,7 @@ static void __exit cfag12864bfb_exit(voi
 {
 	platform_device_unregister(cfag12864bfb_device);
 	platform_driver_unregister(&cfag12864bfb_driver);
+	cfag12864b_disable();
 }
 
 module_init(cfag12864bfb_init);
drivers/auxdisplay/ks0108.c +8 -9
diff -uprN -X dontdiff linux-2.6.19-rc1-mod2/drivers/auxdisplay/ks0108.c linux/drivers/auxdisplay/ks0108.c
@@ -6,12 +6,11 @@
  *     Depends: parport
  *
  *      Author: Copyright (C) Miguel Ojeda Sandonis <[email protected]>
- *        Date: 2006-10-04
+ *        Date: 2006-10-31
  *
  *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,12 +26,12 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/fs.h>
 #include <linux/delay.h>
+#include <linux/fs.h>
+#include <linux/io.h>
 #include <linux/parport.h>
+#include <linux/uaccess.h>
 #include <linux/ks0108.h>
-#include <asm/io.h>
-#include <asm/uaccess.h>
 
 #define KS0108_NAME "ks0108"
 
@@ -56,7 +55,7 @@ static struct parport *ks0108_parport;
 static struct pardevice *ks0108_pardevice;
 
 /*
- * ks0108 Exported cmds (don't lock)
+ * ks0108 Exported Commands (don't lock)
  *
  *   You _should_ lock in the top driver: This functions _should not_
  *   get race conditions in any way. Locking for each byte here would be
@@ -68,7 +67,7 @@ static struct pardevice *ks0108_pardevic
  *   a specific combination, look at the function's name.
  *
  *   The ks0108_writecontrol bits need to be reverted ^(0,1,3) because
- *   the parallel port also revert them with a "not" logic gate.
+ *   the parallel port also revert them using a "not" logic gate.
  */
 
 #define bit(n) (((unsigned char)1)<<(n))
include/linux/cfag12864b.h +39 -3

55 lines not on this page · raw message

include/linux/ks0108.h +14 -4
diff -uprN -X dontdiff linux-2.6.19-rc1-mod2/include/linux/ks0108.h linux/include/linux/ks0108.h
@@ -5,12 +5,11 @@
  *     License: GPLv2
  *
  *      Author: Copyright (C) Miguel Ojeda Sandonis <[email protected]>
- *        Date: 2006-10-04
+ *        Date: 2006-10-31
  *
  *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -26,11 +25,22 @@
 #ifndef _KS0108_H_
 #define _KS0108_H_
 
+/* Write a byte to the data port */
 extern void ks0108_writedata(unsigned char byte);
+
+/* Write a byte to the control port */
 extern void ks0108_writecontrol(unsigned char byte);
+
+/* Set the controller's current display state (0..1) */
 extern void ks0108_displaystate(unsigned char state);
+
+/* Set the controller's current startline (0..63) */
 extern void ks0108_startline(unsigned char startline);
+
+/* Set the controller's current address (0..63) */
 extern void ks0108_address(unsigned char address);
+
+/* Set the controller's current page (0..7) */
 extern void ks0108_page(unsigned char page);
 
 #endif /* _KS0108_H_ */
#1 lore raw
Quoted 1 line · On Wed, 1 Nov 2006 00:37:48 +0000 Miguel Ojeda Sandonis <[email protected]>…

Andrew, here it is the fifth update for the drivers-add-lcd-support.

It does queue_delayed_work(), but forgot to do cancel_delayed_work(). If the timer is still pending after module unload, deadly things will happen.

There's a lot of "if(" in there. Usual kernel style is "if (".

#2 lore raw
Quoted 8 lines · Andrew Morton
Quoted 1 line · On Wed, 1 Nov 2006 00:37:48 +0000 Miguel Ojeda Sandonis <[email protected]>…

Andrew, here it is the fifth update for the drivers-add-lcd-support.

It does queue_delayed_work(), but forgot to do cancel_delayed_work(). If the timer is still pending after module unload, deadly things will happen.

Hum, I call cancel_delayed_work() as well as flush_workqueue() at module exit:

static void __exit cfag12864b_exit(void)
{
...
+ cfag12864b_disable();
...
}

And cfag12864b_disable() will call them, as fast as the mutex is unlocked (in fact, modules must call cfag12864b_disable() when they finish working with the LCD, as cfag12864bfb, for example, does, but just for be safe, I called it at module unload in cfag12864b. If it is already disabled, it won't hurt in any way.)

Is that right?

Quoted 2 lines

There's a lot of "if(" in there. Usual kernel style is "if (".

Excuse me, will fix in a few moments.