drivers: add lcd display support
Subsystems (6)
PATCH 1/1 drivers: add lcd display support
(This is the real V5 patch. The other V5-mail was the V4, sorry)
miguelojeda-2.6.18-add-lcd-display-support.patch
Changelog (newer first):
V5 - Fixed mistakes found by Joe Perches
- coding style
- const, spelling mistake
V4 - Fixed mistakes found by Pavel Machek
- no zero initialization
- GPL version
- use bitop generic functions
V3 - Apply for 2.6.18
- added const to class_create (2.6.18 hasn't add-const-to-class_create.patch)
V2 - Fixed mistakes found by Greg KH
- coding style
V1 - Fixed mistakes found by Alexey Dobriyan
- coding style
- init() and exit() error management
V0 - Original patch
Brief:
- Adds const to class_create (2.6.18 hasn't add-const-to-class_create.patch)
- Adds a "lcddisplay" class for registering LCD devices.
- Adds support for the ks0108 LCD Controller as a device driver.
(uses lcddisplay class and parport interface)
- Adds support for the cfag12864b LCD Display as a device driver.
(uses ks0108 device driver)
- Adds a new ioctl() magic number/range (0xFF) in the list for the cfag12864b device.
- Adds the usual Documentation, includes, Makefiles, Kconfigs, MAINTAINERS, CREDITS...
Patched files Index:
patching file drivers/base/class.c
patching file include/linux/device.h
patching file drivers/Kconfig
patching file drivers/lcddisplay/cfag12864b.c patching file drivers/lcddisplay/cfag12864b_image.h patching file drivers/lcddisplay/Kconfig patching file drivers/lcddisplay/ks0108.c patching file drivers/lcddisplay/lcddisplay.c patching file drivers/lcddisplay/Makefile patching file drivers/Makefile
patching file include/linux/cfag12864b.h patching file include/linux/ks0108.h
patching file include/linux/lcddisplay.h patching file Documentation/drivers/lcddisplay/cfag12864b patching file Documentation/drivers/lcddisplay/lcddisplay patching file Documentation/ioctl-number.txt patching file CREDITS
patching file MAINTAINERS
Please review.
miguelojeda-2.6.18-add-lcd-display-support.patch
---
drivers/base/class.c +1 -1
@@ -197,7 +197,7 @@ static int class_device_create_uevent(st* Note, the pointer created here is to be destroyed when finished by * making a call to class_destroy(). */ -struct class *class_create (struct module *owner,char *name) +struct class *class_create (struct module *owner,const char *name) {struct class *cls;int retval;
include/linux/device.h +1 -1
@@ -271,7 +271,7 @@ struct class_interface {extern int class_interface_register (struct class_interface *);extern void class_interface_unregister (struct class_interface *); -extern struct class *class_create (struct module *owner,char *name); +extern struct class *class_create (struct module *owner,const char *name);extern void class_destroy (struct class *cls); extern struct class_device *class_device_create(struct class *cls, struct class_device *parent,
drivers/Kconfig +2 -0
@@ -74,4 +74,6 @@ source "drivers/rtc/Kconfig" source "drivers/dma/Kconfig" +source "drivers/lcddisplay/Kconfig" + endmenu
drivers/lcddisplay/cfag12864b.c +529 -0
529 lines not on this page · raw message
drivers/lcddisplay/cfag12864b_image.h +80 -0
80 lines not on this page · raw message
drivers/lcddisplay/Kconfig +61 -0
61 lines not on this page · raw message
drivers/lcddisplay/ks0108.c +175 -0
175 lines not on this page · raw message
drivers/lcddisplay/lcddisplay.c +71 -0
71 lines not on this page · raw message
drivers/lcddisplay/Makefile +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for the kernel LCD Display device drivers. +# + +obj-$(CONFIG_LCDDISPLAY) += lcddisplay.o +obj-$(CONFIG_KS0108) += ks0108.o +obj-$(CONFIG_CFAG12864B) += cfag12864b.o
drivers/Makefile +1 -0
@@ -76,3 +76,4 @@ obj-$(CONFIG_CRYPTO) += crypto/ obj-$(CONFIG_SUPERH) += sh/ obj-$(CONFIG_GENERIC_TIME) += clocksource/ obj-$(CONFIG_DMA_ENGINE) += dma/ +obj-$(CONFIG_LCDDISPLAY) += lcddisplay/
include/linux/cfag12864b.h +45 -0
45 lines not on this page · raw message
include/linux/ks0108.h +21 -0
@@ -0,0 +1,21 @@ +/* +* Filename: ks0108.h +* Version: 0.1.0 +* Description: ks0108 LCD Display Controller Driver Header +* License: GPLv2 +* +* Author: Miguel Ojeda Sandonis <[email protected]> +* Date: 2006-09-12 +*/ + +#ifndef _KS0108_H_ +#define _KS0108_H_ + +extern void ks0108_writedata (unsigned char byte); +extern void ks0108_writecontrol (unsigned char byte); +extern void ks0108_displaystate (unsigned char state); +extern void ks0108_startline (unsigned char startline); +extern void ks0108_address (unsigned char address); +extern void ks0108_page (unsigned char page); + +#endif /* _KS0108_H_ */
include/linux/lcddisplay.h +19 -0
@@ -0,0 +1,19 @@ +/* +* Filename: lcddisplay.h +* Version: 0.1.0 +* Description: Display Class Header +* License: GPLv2 +* +* Author: Miguel Ojeda Sandonis <[email protected]> +* Date: 2006-09-12 +*/ + +#ifndef _LCDDISPLAY_H_ +#define _LCDDISPLAY_H_ + +#include <linux/device.h> + +extern struct class * lcddisplay_class; + +#endif /* _LCDDISPLAY_H_ */ +
Documentation/drivers/lcddisplay/cfag12864b +367 -0
367 lines not on this page · raw message
Documentation/drivers/lcddisplay/lcddisplay +37 -0
@@ -0,0 +1,37 @@ + ================================= + LCD Display Drivers Documentation + ================================= + +License: GPL +Author & Maintainer: Miguel Ojeda Sandonis <[email protected]> +Date: 2006-09-12 + +-------- +0. INDEX +-------- + + 1. NEW DISPLAY DRIVERS + 2. GENERAL TIPS + + + +---------------------- +1. NEW DISPLAY DRIVERS +---------------------- + +Feel free to send me new display drivers. I will try to do my best. + +If you don't get any answer, send your patch directly to the linux-kernel ml. + + + +--------------- +2. GENERAL TIPS +--------------- + +- Divide your driver into the controller driver, like ks0108, + and the specific LCD display series driver, like cfag12864b. + +- Claim for your IO ports in the controller driver. + +EOF
Documentation/ioctl-number.txt +2 -0
@@ -191,3 +191,5 @@ Code Seq# Include File Comments <mailto:[email protected]> 0xF3 00-3F video/sisfb.h sisfb (in development) <mailto:[email protected]> +0xFF 00-1F linux/cfag12864b.h cfag12864b LCD Display Driver + <mailto:[email protected]>
CREDITS +8 -0
@@ -2535,6 +2535,14 @@ S: Subiaco, 6008 S: Perth, Western Australia S: Australia +N: Miguel Ojeda Sandonis +E: [email protected] +D: Author: LCD Display Drivers (ks0108, cfag12864b) +D: Maintainer: LCD Display Drivers Tree (drivers/lcddisplay/*) +S: C/ Mieses 20, 9-B +S: Valladolid 47009 +S: Spain + N: Greg Page E: [email protected] D: IPX development and support
MAINTAINERS +5 -0
@@ -1707,6 +1707,11 @@ M: [email protected] L: [email protected] S: Maintained +LCD DISPLAY DRIVERS +P: Miguel Ojeda Sandonis +M: [email protected] +S: Maintained + LED SUBSYSTEM P: Richard Purdie M: [email protected]
include/linux/device.h struct class_interface { · line 274
Quoted 13 lines · On Fri, 22 Sep 2006 22:03:46 +0200 Miguel Ojeda Sandonis…
miguelojeda-2.6.18-add-lcd-display-support.patch
...
diff -uprN -X dontdiff
linux-2.6.18-vanilla/include/linux/device.hlinux-2.6.18/include/linux/device.hinclude/linux/device.h +1
-1@@ -271,7 +271,7 @@ struct class_interface {extern int class_interface_register (struct class_interface *);extern void class_interface_unregister (struct class_interface *); -extern struct class *class_create (struct module *owner,char *name); +extern struct class *class_create (struct module *owner,const char *name);
Please prepare a separate patch for this, send to Greg.
Quoted 18 lines
drivers/lcddisplay/cfag12864b.c +15
-0@@ -0,0 +1,529 @@ +/* +* Filename: cfag12864b.c +* Version: 0.1.0 +* Description: cfag12864b LCD Display Driver +* License: GPLv2 +* Depends: lcddisplay ks0108 +* +* Author: Miguel Ojeda Sandonis <[email protected]> +* Date: 2006-09-21 +*/ + + +#include <linux/init.h> +#include <linux/module.h> +#include <linux/kernel.h>
drivers/lcddisplay/cfag12864b.c line 25
Quoted 10 lines
drivers/lcddisplay/cfag12864b.c +10
-0+#include <linux/fs.h> +#include <linux/cdev.h> +#include <linux/device.h> +#include <linux/lcddisplay.h> +#include <linux/ks0108.h> +#include <linux/cfag12864b.h> +#include <asm/uaccess.h> + +#define NAME "cfag12864b" +#define PRINTK_PREFIX KERN_INFO NAME ": "
In numerous places the driver uses PRINTK_PREFIX for reporting errors. It should use KERN_ERR. I suggest that PRINTK_PREFIX be removed and that you open-code all the printk facility levels, make sure that the appropriate level is being used at each site.
drivers/lcddisplay/cfag12864b.c line 35
Quoted 9 lines
drivers/lcddisplay/cfag12864b.c +9
-0+ + +/* +* Device +*/ + +static const unsigned int cfag12864b_firstminor; +static const unsigned int cfag12864b_ndevices =1 ; +static const char * cfag12864b_name =NAME ;
The more usual kernel style is to not put a space after the `*':
static const char *cfag12864b_name = NAME;
(this affects the entire patch).
Suggest that cfag12864b_name be removed - just use NAME at the single place where this variable is used.
drivers/lcddisplay/cfag12864b.c line 43
Quoted 8 lines
drivers/lcddisplay/cfag12864b.c +8
-0+static int cfag12864b_major; +static int cfag12864b_minor; +static dev_t cfag12864b_device; +struct cdev cfag12864b_chardevice; + + + +
One blank line is sufficient (there are many instances of this)
Quoted 17 lines
drivers/lcddisplay/cfag12864b.c +17
-0+/* +* cfag12864b Commands +*/ + +static const unsigned int cfag12864b_bits =8 ; +static const unsigned int cfag12864b_width =CFAG12864B_WIDTH ; +static const unsigned int cfag12864b_height =CFAG12864B_HEIGHT ; +static const unsigned int cfag12864b_matrixsize =CFAG12864B_MATRIXSIZE ; +static const unsigned int cfag12864b_controllers =CFAG12864B_CONTROLLERS ; +static const unsigned int cfag12864b_pages =CFAG12864B_PAGES ; +static const unsigned int cfag12864b_addresses =CFAG12864B_ADDRESSES ; +static const unsigned int cfag12864b_size =CFAG12864B_SIZE ; +static unsigned char cfag12864b_state; + +static void cfag12864b_set (void ) +{ +ks0108_writecontrol (cfag12864b_state);
drivers/lcddisplay/cfag12864b.c line 70
Quoted 10 lines
drivers/lcddisplay/cfag12864b.c +10
-0+} + +static void cfag12864b_setbit (unsigned char state,unsigned char bit) +{ +if (state) +set_bit (bit, (void *)&cfag12864b_state); +else +clear_bit (bit, (void *)&cfag12864b_state); +cfag12864b_set (); +}
bitops are defined on an unsigned long only. This trick is as ugly as sin and is buggy on big-endian CPUs. Suggest that cfag12864b_state be converted to unsigned long.
drivers/lcddisplay/cfag12864b.c line 159
Quoted 6 lines
drivers/lcddisplay/cfag12864b.c +6
-0+{ +cfag12864b_startline (0 ); +} + + +
blank lines
drivers/lcddisplay/cfag12864b.c line 164
Quoted 5 lines
drivers/lcddisplay/cfag12864b.c +5
-0+/* +* Auxiliary +*/ + +static void normalizeoffset (unsigned int * offset)
coding style.
drivers/lcddisplay/cfag12864b.c line 168
Quoted 4 lines
drivers/lcddisplay/cfag12864b.c +4
-0+{ +if (*offset >= cfag12864b_pages*cfag12864b_addresses) + *offset -= cfag12864b_pages*cfag12864b_addresses; +}
Ths usual kernel style is to put a single space around arithmetic operators and around comparison operators. This affects the entire patch, please.
drivers/lcddisplay/cfag12864b.c line 212
Quoted 6 lines
drivers/lcddisplay/cfag12864b.c +6
-0+void cfag12864b_clear (void ) +{ +unsigned char page,address; + +cfag12864b_setcontrollers (1 ,1 ); +for (page=0 ; page<cfag12864b_pages; ++page) {
For example,
for (page = 0; page < cfag12864b_pages; page++) {would be more kernelish.
The use of the identifier page' here is unfortunate. We usually expect such a thing to have type struct page *'. I understand that "Each controller is divided into 8 pages", but it'd be nice if some different nomenclature could be used here. If nothing else comes to mind, we can live with it as-is.
drivers/lcddisplay/cfag12864b.c line 224
Quoted 5 lines
drivers/lcddisplay/cfag12864b.c +5
-0+void cfag12864b_write ( +unsigned short offset, +const unsigned char * buffer, +unsigned short count) +{
It is more usual to do
void cfag12864b_write(unsigned short offset, const unsigned char *buffer,
unsigned short count)
{
drivers/lcddisplay/cfag12864b.c line 286
Quoted 8 lines
drivers/lcddisplay/cfag12864b.c +8
-0+for (controller=0 ; controller < cfag12864b_controllers; ++controller) +for (page=0 ; page < cfag12864b_pages; ++page) +for (address=0 ; address < cfag12864b_addresses; ++address) { + dest[(controller*cfag12864b_pages+page)*cfag12864b_addresses+address]=0 ; +for (bit=0 ; bit < cfag12864b_bits; ++bit) +if (src[controller*cfag12864b_addresses+address+(page*cfag12864b_bits+bit)*cfag12864b_width]) +set_bit (bit, (void *)(dest+(controller*cfag12864b_pages+page)*cfag12864b_addresses+address)); + }
That's rather ugly-looking.
It's also probably-incorrect on big-endian CPUs. Perhaps you should not use bitops at all for this driver, use open-coded | and &/~ instead?
The driver doesn't have any locking. Is it racy on SMP and/or CONFIG_PREEMPT?
Quoted 10 lines
drivers/lcddisplay/cfag12864b.c +10
-0+static int cfag12864b_fopioctlformat (void __user * arg) +{ +int result; +int ret = -ENOTTY ; + +unsigned char * tmpbuffer; + + tmpbuffer =kmalloc ( +sizeof (unsigned char )*cfag12864b_matrixsize,GFP_KERNEL ); +if (tmpbuffer ==NULL ) {
drivers/lcddisplay/cfag12864b.c line 394
Quoted 10 lines
drivers/lcddisplay/cfag12864b.c +10
-0+printk (PRINTK_PREFIX "FOP ioctl: ERROR: " +"can't alloc memory %i bytes\n" , +sizeof (unsigned char )*cfag12864b_matrixsize); + goto none; + } + + result =copy_from_user ( + tmpbuffer, + arg, +sizeof (unsigned char )*cfag12864b_matrixsize);
result = copy_from_user(tmpbuffer, arg, cfag12864b_matrixsize);
Quoted 12 lines
drivers/lcddisplay/cfag12864b.c +12
-0+if (result !=0 ) { +printk (PRINTK_PREFIX "FOP ioctl: ERROR: " +"can't copy memory from user\n" ); + goto bufferalloced; + } + +cfag12864b_format (tmpbuffer); + + ret =0 ; + +bufferalloced: +kfree (tmpbuffer);
drivers/lcddisplay/cfag12864b.c line 443
Quoted 10 lines
drivers/lcddisplay/cfag12864b.c +7
-0+ +none: +return ret; +} + + +static struct file_operations cfag12864b_fops =
`static const struct'
drivers/lcddisplay/cfag12864b.c line 498
Quoted 5 lines
drivers/lcddisplay/cfag12864b.c +5
-0+ +class_device_create ( + lcddisplay_class,NULL , + cfag12864b_device, +NULL ,"cfag12864b%d" , cfag12864b_minor);
class_device_create() can fail.
drivers/lcddisplay/cfag12864b.c
Quoted 6 lines
drivers/lcddisplay/cfag12864b.c +6
-0+void ks0108_writecontrol (unsigned char byte) +{ +const unsigned int ecycledelay =2 ; +udelay (ecycledelay); +parport_write_control (ks0108_parport, byte^(bit (3 )|bit (1 )|bit (0 ))); +}
udelay(2) would be clearer.
drivers/lcddisplay/cfag12864b.c
Quoted 5 lines
drivers/lcddisplay/cfag12864b.c +5
-0+void ks0108_displaystate (unsigned char state) +{ +unsigned char cmd =bit (1 ) |bit (2 ) |bit (3 ) |bit (4 ) |bit (5 ); +if (state) +set_bit (0 , (void *)&cmd);
argh. Even if this driver will only ever run on big-endian hardware, please don't do this.
drivers/lcddisplay/cfag12864b.c
Quoted 6 lines
drivers/lcddisplay/cfag12864b.c +6
-0+void ks0108_startline (unsigned char startline) +{ +const unsigned char maxstartline =63 ; +unsigned char cmd =bit (6 ) |bit (7 ); +if (startline > maxstartline) + startline = maxstartline;
There are a lot of open-coded min() and max() operations in this driver. Suggest it be changed to use min() and max().
Quoted 4 lines · Andrew Morton
It's also probably-incorrect on big-endian CPUs. Perhaps you should not
use bitops at all for this driver, use open-coded | and &/~ instead?
Uhm, someone told me that they shouldn't be used because the kernel has generic functions for that.
I researched the kernel sources, and looking at bitops.h I found setbit(), so I tried to use it in the driver, althought I prefer standard |= and &=.
Are there more generic bitops kernel functions I may didn't find and I should use in the future?
Anyway, it's just a question: I will turn back the driver to use |= and &=, they look better to me too.
Quoted 8 lines · On Wed, 27 Sep 2006 20:58:24 +0000 "Miguel Ojeda" <[email protected]> wrote:
Quoted 4 lines · Andrew Morton
It's also probably-incorrect on big-endian CPUs. Perhaps you should not
use bitops at all for this driver, use open-coded | and &/~ instead?Uhm, someone told me that they shouldn't be used because the kernel has generic functions for that.
You can't believe everything you read on the internet ;)
set_bit() and friends are a) atomic wrt other CPUs on SMP and b) only to be performed on unsigned longs.
Quoted 3 lines
I researched the kernel sources, and looking at
bitops.hI foundsetbit(), so I tried to use it in the driver, althought I prefer standard |= and &=.
Those are the appropriate operations to use in this driver.
Quoted 14 lines · Andrew Morton
Quoted 8 lines · On Wed, 27 Sep 2006 20:58:24 +0000 "Miguel Ojeda" <[email protected]> wrote:
Quoted 4 lines · Andrew Morton
It's also probably-incorrect on big-endian CPUs. Perhaps you should not
use bitops at all for this driver, use open-coded | and &/~ instead?Uhm, someone told me that they shouldn't be used because the kernel has generic functions for that.
You can't believe everything you read on the internet ;)
Quoted 10 lines
set_bit()and friends are a) atomic wrt other CPUs on SMP and b) only to be performed on unsigned longs.Quoted 3 lines
I researched the kernel sources, and looking at
bitops.hI foundsetbit(), so I tried to use it in the driver, althought I prefer standard |= and &=.Those are the appropriate operations to use in this driver.
Ok, I have fixed all the mistakes you found. However, I have a question about locking.
I have used 1 global mutex for all the fops: seek, write and ioctl. They call down_interruptable() at the very beggining and up() just before returning. I think that it's right.
However, what about the exported symbols? I have exported functions at the ks0108 driver like EXPORT_SYMBOL_GPL(ks0108_writedata); The cfag12864b drivers exports more symbols also, like:EXPORT_SYMBOL_GPL(cfag12864b_write);
Should use the mutex all this functions too?
For example: Another driver can have a fops which isn't perform any kind of locking. Such function is being executed twice at the same time. And it calls some of my exported symbols. Then, I will have a race condition in my driver.
(I couldn't find anything specific about that at LDD3, just for fops).
Thanks,
Miguel Ojeda