* [PATCH] This is my first commit
@ 2014-05-27 5:31 hnnnet48
0 siblings, 0 replies; 4+ messages in thread
From: hnnnet48 @ 2014-05-27 5:31 UTC (permalink / raw)
To: gregkh, devel, linux-kernel; +Cc: kevin
From: kevin <hnnnet48@gmail.com>
---
gtserio.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 188 insertions(+)
create mode 100755 gtserio.c
diff --git a/gtserio.c b/gtserio.c
new file mode 100755
index 0000000..24f1e00
--- /dev/null
+++ b/gtserio.c
@@ -0,0 +1,188 @@
+/*
+ * gtserio.c - Create an input/output character device for GeneralTouch serial screen
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <asm/uaccess.h>
+#include <linux/device.h>
+#include <linux/input.h>
+#include <linux/kd.h>
+//#include <linux/ioctl.h>
+
+#define MAJOR_NUM 100
+#define MAJOR_MIN 0
+#define SUCCESS 0
+#define DEVICE_NAME "general_touch_serial"
+#define BUF_LEN 80
+MODULE_AUTHOR("GeneralTouch <support@generaltouch.com>");
+MODULE_DESCRIPTION(DEVICE_NAME);
+MODULE_LICENSE("GPL");
+static int Device_Open = 0;
+struct input_dev *devq;
+char Message[BUF_LEN];
+dev_t gts_t;
+unsigned char val[10];
+int gtsdata[4];
+unsigned long min_x = 0;
+unsigned long max_x = 32767;
+unsigned long min_y = 0;
+unsigned long max_y = 32767;
+
+char *Message_Ptr;
+struct class *gts_class;
+
+static int device_open(struct inode *inode, struct file *file)
+{
+ printk("GTS device_open(%p)\n", file);
+
+#ifdef DEBUG
+ printk("device_open(%p)\n", file);
+#endif
+
+ /*
+ * We don't want to talk to two processes at the same time
+ */
+ if (Device_Open)
+ return -EBUSY;
+
+ Device_Open++;
+ /*
+ * Initialize the message
+ */
+ Message_Ptr = Message;
+ return SUCCESS;
+}
+
+static int device_release(struct inode *inode, struct file *file)
+{
+#ifdef DEBUG
+ printk("device_release(%p,%p)\n", inode, file);
+#endif
+
+ /*
+ * We're now ready for our next caller
+ */
+ Device_Open--;
+
+ module_put(THIS_MODULE);
+ return SUCCESS;
+}
+
+/*
+ * This function is called whenever a process which has already opened the
+ * device file attempts to read from it.
+ */
+static ssize_t device_read(struct file *file,
+ char __user * buffer, size_t length, loff_t * offset)
+{
+
+ return 0;
+}
+
+static ssize_t
+device_write(struct file *file,
+ const char __user * buffer, size_t length, loff_t * offset)
+{
+#ifdef DEBUG
+ printk("device_write(%p,%s,%d)", file, buffer, length);
+#endif
+
+ if (copy_from_user(&val, buffer, length)) {
+ length = -EFAULT;
+ }
+
+ printk("val[3] = %x,val[4] = %x\nval[5] = %x,val[6] = %x\n", val[3],
+ val[4], val[5], val[6]);
+ gtsdata[0] = val[2];
+ gtsdata[1] = (val[4] << 8) | (val[3]);
+ gtsdata[2] = (val[6] << 8) | (val[5]);
+ gtsdata[3] = val[9];
+ printk("gtsdata[1] = %x\ngtsdata[2] = %x\n", gtsdata[1], gtsdata[2]);
+ input_report_abs(devq, ABS_X, gtsdata[1]);
+ input_report_abs(devq, ABS_Y, gtsdata[2]);
+ if (gtsdata[0] == 0x81) {
+
+ input_report_key(devq, BTN_TOUCH, 1);
+ input_report_abs(devq, ABS_PRESSURE, 1);
+ input_sync(devq);
+ }
+ if (gtsdata[0] == 0x84) {
+ input_report_key(devq, BTN_TOUCH, 0);
+ input_report_abs(devq, ABS_PRESSURE, 0);
+ input_sync(devq);
+ }
+ input_sync(devq);
+
+ return length;
+}
+
+struct file_operations Fops = {
+ .read = device_read,
+ .write = device_write,
+ .open = device_open,
+ .release = device_release, /* a.k.a. close */
+};
+
+/*
+ * Initialize the module - Register the character device
+ */
+static int __init gts_init(void)
+{
+ int ret_val;
+ struct input_dev *gts_dev;
+ int err1;
+ gts_t = MKDEV(MAJOR_NUM, MAJOR_MIN);
+
+ gts_class = class_create(THIS_MODULE, "gts_class");
+ device_create(gts_class, NULL, gts_t, NULL, DEVICE_NAME);
+ ret_val = register_chrdev(MAJOR_NUM, DEVICE_NAME, &Fops);
+
+ if (ret_val < 0) {
+ printk("%s failed with %d\n",
+ "Sorry, registering the character device ", ret_val);
+ return ret_val;
+ }
+
+ gts_dev = input_allocate_device();
+ if (!gts_dev) {
+ err1 = -ENOMEM;
+ goto fail1;
+ }
+ gts_dev->name = "GeneralTouch Serial TouchScreen";
+ gts_dev->phys = "generaltouch/input0";
+ gts_dev->id.bustype = BUS_RS232;
+ gts_dev->id.vendor = (int)("GT_SERIAL");
+ gts_dev->id.product = (int)("GT_SERIAL");
+ gts_dev->id.version = 0x0100;
+ gts_dev->evbit[0] =
+ BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
+ gts_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
+
+ input_set_abs_params(gts_dev, ABS_X, min_x, max_x, 0, 0);
+ input_set_abs_params(gts_dev, ABS_Y, min_y, max_y, 0, 0);
+
+ err1 = input_register_device(gts_dev);
+ devq = gts_dev;
+fail1: input_free_device(gts_dev);
+ return err1;
+}
+
+static void __exit gts_exit(void)
+{
+ int ret;
+
+ /*
+ * Unregister the device
+ */
+ unregister_chrdev(MAJOR_NUM, DEVICE_NAME);
+
+ /*
+ * If there's an error, report it
+ */
+ if (ret < 0)
+ printk("Error in module_unregister_chrdev: %d\n", ret);
+}
+
+module_init(gts_init);
+module_exit(gts_exit);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] This is my first commit
@ 2014-05-27 6:44 hnnnet48
2014-05-27 7:03 ` Joe Perches
2014-05-27 7:11 ` H. Peter Anvin
0 siblings, 2 replies; 4+ messages in thread
From: hnnnet48 @ 2014-05-27 6:44 UTC (permalink / raw)
To: gregkh, devel, linux-kernel; +Cc: kevin
From: kevin <hnnnet48@gmail.com>
---
gtserio.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 188 insertions(+)
create mode 100755 gtserio.c
diff --git a/gtserio.c b/gtserio.c
new file mode 100755
index 0000000..24f1e00
--- /dev/null
+++ b/gtserio.c
@@ -0,0 +1,188 @@
+/*
+ * gtserio.c - Create an input/output character device for GeneralTouch serial screen
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <asm/uaccess.h>
+#include <linux/device.h>
+#include <linux/input.h>
+#include <linux/kd.h>
+//#include <linux/ioctl.h>
+
+#define MAJOR_NUM 100
+#define MAJOR_MIN 0
+#define SUCCESS 0
+#define DEVICE_NAME "general_touch_serial"
+#define BUF_LEN 80
+MODULE_AUTHOR("GeneralTouch <support@generaltouch.com>");
+MODULE_DESCRIPTION(DEVICE_NAME);
+MODULE_LICENSE("GPL");
+static int Device_Open = 0;
+struct input_dev *devq;
+char Message[BUF_LEN];
+dev_t gts_t;
+unsigned char val[10];
+int gtsdata[4];
+unsigned long min_x = 0;
+unsigned long max_x = 32767;
+unsigned long min_y = 0;
+unsigned long max_y = 32767;
+
+char *Message_Ptr;
+struct class *gts_class;
+
+static int device_open(struct inode *inode, struct file *file)
+{
+ printk("GTS device_open(%p)\n", file);
+
+#ifdef DEBUG
+ printk("device_open(%p)\n", file);
+#endif
+
+ /*
+ * We don't want to talk to two processes at the same time
+ */
+ if (Device_Open)
+ return -EBUSY;
+
+ Device_Open++;
+ /*
+ * Initialize the message
+ */
+ Message_Ptr = Message;
+ return SUCCESS;
+}
+
+static int device_release(struct inode *inode, struct file *file)
+{
+#ifdef DEBUG
+ printk("device_release(%p,%p)\n", inode, file);
+#endif
+
+ /*
+ * We're now ready for our next caller
+ */
+ Device_Open--;
+
+ module_put(THIS_MODULE);
+ return SUCCESS;
+}
+
+/*
+ * This function is called whenever a process which has already opened the
+ * device file attempts to read from it.
+ */
+static ssize_t device_read(struct file *file,
+ char __user * buffer, size_t length, loff_t * offset)
+{
+
+ return 0;
+}
+
+static ssize_t
+device_write(struct file *file,
+ const char __user * buffer, size_t length, loff_t * offset)
+{
+#ifdef DEBUG
+ printk("device_write(%p,%s,%d)", file, buffer, length);
+#endif
+
+ if (copy_from_user(&val, buffer, length)) {
+ length = -EFAULT;
+ }
+
+ printk("val[3] = %x,val[4] = %x\nval[5] = %x,val[6] = %x\n", val[3],
+ val[4], val[5], val[6]);
+ gtsdata[0] = val[2];
+ gtsdata[1] = (val[4] << 8) | (val[3]);
+ gtsdata[2] = (val[6] << 8) | (val[5]);
+ gtsdata[3] = val[9];
+ printk("gtsdata[1] = %x\ngtsdata[2] = %x\n", gtsdata[1], gtsdata[2]);
+ input_report_abs(devq, ABS_X, gtsdata[1]);
+ input_report_abs(devq, ABS_Y, gtsdata[2]);
+ if (gtsdata[0] == 0x81) {
+
+ input_report_key(devq, BTN_TOUCH, 1);
+ input_report_abs(devq, ABS_PRESSURE, 1);
+ input_sync(devq);
+ }
+ if (gtsdata[0] == 0x84) {
+ input_report_key(devq, BTN_TOUCH, 0);
+ input_report_abs(devq, ABS_PRESSURE, 0);
+ input_sync(devq);
+ }
+ input_sync(devq);
+
+ return length;
+}
+
+struct file_operations Fops = {
+ .read = device_read,
+ .write = device_write,
+ .open = device_open,
+ .release = device_release, /* a.k.a. close */
+};
+
+/*
+ * Initialize the module - Register the character device
+ */
+static int __init gts_init(void)
+{
+ int ret_val;
+ struct input_dev *gts_dev;
+ int err1;
+ gts_t = MKDEV(MAJOR_NUM, MAJOR_MIN);
+
+ gts_class = class_create(THIS_MODULE, "gts_class");
+ device_create(gts_class, NULL, gts_t, NULL, DEVICE_NAME);
+ ret_val = register_chrdev(MAJOR_NUM, DEVICE_NAME, &Fops);
+
+ if (ret_val < 0) {
+ printk("%s failed with %d\n",
+ "Sorry, registering the character device ", ret_val);
+ return ret_val;
+ }
+
+ gts_dev = input_allocate_device();
+ if (!gts_dev) {
+ err1 = -ENOMEM;
+ goto fail1;
+ }
+ gts_dev->name = "GeneralTouch Serial TouchScreen";
+ gts_dev->phys = "generaltouch/input0";
+ gts_dev->id.bustype = BUS_RS232;
+ gts_dev->id.vendor = (int)("GT_SERIAL");
+ gts_dev->id.product = (int)("GT_SERIAL");
+ gts_dev->id.version = 0x0100;
+ gts_dev->evbit[0] =
+ BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
+ gts_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
+
+ input_set_abs_params(gts_dev, ABS_X, min_x, max_x, 0, 0);
+ input_set_abs_params(gts_dev, ABS_Y, min_y, max_y, 0, 0);
+
+ err1 = input_register_device(gts_dev);
+ devq = gts_dev;
+fail1: input_free_device(gts_dev);
+ return err1;
+}
+
+static void __exit gts_exit(void)
+{
+ int ret;
+
+ /*
+ * Unregister the device
+ */
+ unregister_chrdev(MAJOR_NUM, DEVICE_NAME);
+
+ /*
+ * If there's an error, report it
+ */
+ if (ret < 0)
+ printk("Error in module_unregister_chrdev: %d\n", ret);
+}
+
+module_init(gts_init);
+module_exit(gts_exit);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] This is my first commit
2014-05-27 6:44 [PATCH] This is my first commit hnnnet48
@ 2014-05-27 7:03 ` Joe Perches
2014-05-27 7:11 ` H. Peter Anvin
1 sibling, 0 replies; 4+ messages in thread
From: Joe Perches @ 2014-05-27 7:03 UTC (permalink / raw)
To: hnnnet48; +Cc: gregkh, devel, linux-kernel
On Tue, 2014-05-27 at 14:44 +0800, hnnnet48@gmail.com wrote:
> From: kevin <hnnnet48@gmail.com>
Hi Kevin.
You subject line should be something like:
[PATCH] Add support for GeneralTouch serial screen
There should be a commit message too.
> ---
> gtserio.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
In what directory should this file be placed?
Will you submit a Makefile/Kconfig mechanism to make it?
You should run your patch through scripts/checkpatch.pl
It will flag a number of things you should consider fixing.
> create mode 100755 gtserio.c
755 is not correct. 644 please.
> diff --git a/gtserio.c b/gtserio.c
[]
> + * gtserio.c - Create an input/output character device for GeneralTouch serial screen
[]
> +MODULE_AUTHOR("GeneralTouch <support@generaltouch.com>");
Kevin, do you work for generaltouch
or did you get this file from somewhere?
> +static int Device_Open = 0;
> +struct input_dev *devq;
> +char Message[BUF_LEN];
> +dev_t gts_t;
> +unsigned char val[10];
> +int gtsdata[4];
> +unsigned long min_x = 0;
> +unsigned long max_x = 32767;
> +unsigned long min_y = 0;
> +unsigned long max_y = 32767;
All of these should probably be static.
> +char *Message_Ptr;
CamelCase is not generally used in linux-kernel.
> +static int device_open(struct inode *inode, struct file *file)
> +{
> + printk("GTS device_open(%p)\n", file);
printk should use a KERN_<LEVEL>
> +
> +#ifdef DEBUG
> + printk("device_open(%p)\n", file);
> +#endif
Unnecessary duplication, this DEBUG should be removed.
> +static int device_release(struct inode *inode, struct file *file)
> +{
> +#ifdef DEBUG
> + printk("device_release(%p,%p)\n", inode, file);
> +#endif
pr_debug is used instead of
#ifdef DEBUG
printk(foo...)
#endif
> + return SUCCESS;
return 0;
instead of a somewhat unnecessary #define
> + printk("val[3] = %x,val[4] = %x\nval[5] = %x,val[6] = %x\n", val[3],
> + val[4], val[5], val[6]);
I suspect this should be pr_debug too.
> + gtsdata[0] = val[2];
> + gtsdata[1] = (val[4] << 8) | (val[3]);
> + gtsdata[2] = (val[6] << 8) | (val[5]);
> + gtsdata[3] = val[9];
> + printk("gtsdata[1] = %x\ngtsdata[2] = %x\n", gtsdata[1], gtsdata[2]);
and this
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] This is my first commit
2014-05-27 6:44 [PATCH] This is my first commit hnnnet48
2014-05-27 7:03 ` Joe Perches
@ 2014-05-27 7:11 ` H. Peter Anvin
1 sibling, 0 replies; 4+ messages in thread
From: H. Peter Anvin @ 2014-05-27 7:11 UTC (permalink / raw)
To: hnnnet48, gregkh, devel, linux-kernel
Hi Kevin,
I suggest reading the file Documentation/SubmittingPatches for general
guidance as how to submit patches.
> +#define MAJOR_NUM 100
> +#define MAJOR_MIN 0
Fixed device numbers need to be allocated from <device@lanana.org>
(currently managed by Alan Cox). However, this should probably be a
misc device, or better yet, an input device.
-hpa
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-05-27 7:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-27 6:44 [PATCH] This is my first commit hnnnet48
2014-05-27 7:03 ` Joe Perches
2014-05-27 7:11 ` H. Peter Anvin
-- strict thread matches above, loose matches on Subject: below --
2014-05-27 5:31 hnnnet48
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox