/* * GSC3280 GW-JZQ YX Driver * * Copyright (C) 2013 BLX IC Design Corp.,Ltd. * Author: Fei Lu, Lufei@china-cpu.com * * 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. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include enum { YX1 = 0, YX2, YX3, YX4, DOOR, MAX_PIN_NR, }; struct gpio yx_gpios[MAX_PIN_NR] = { {GSC3280_GPA(31), GPIOF_IN, "YX1"}, {GSC3280_GPA(14), GPIOF_IN, "YX2"}, {GSC3280_GPA(19), GPIOF_IN, "YX3"}, {GSC3280_GPA(20), GPIOF_IN, "YX4"}, {GSC3280_GPB(28), GPIOF_IN, "DOOR"}, }; struct jzq_yx { struct cdev cdev; struct class *yx_class; dev_t dev; }; struct jzq_yx jzq_yx_priv; static ssize_t yx_read ( struct file * pfile , char __user * pbuf , size_t size , loff_t * ppos ) { uint8_t buffer[5]; buffer[0] = gpio_get_value(yx_gpios[YX1].gpio); buffer[1] = gpio_get_value(yx_gpios[YX2].gpio); buffer[2] = gpio_get_value(yx_gpios[YX3].gpio); buffer[3] = gpio_get_value(yx_gpios[YX4].gpio); buffer[4] = gpio_get_value(yx_gpios[DOOR].gpio); copy_to_user(pbuf, buffer, 5); return 5; } static int yx_open(struct inode *inode, struct file *filp) { return 0; } static int yx_release(struct inode *inode, struct file *filp) { return 0; } struct file_operations yx_fops = { .owner = THIS_MODULE, .read = yx_read, .open = yx_open, .release = yx_release, }; static int __init jzq_yx_init(void) { int err,ret; int result; int major; result = alloc_chrdev_region(&jzq_yx_priv.dev, 0, 0, "yx"); major = MAJOR(jzq_yx_priv.dev); if (result < 0) { printk(KERN_WARNING "jzq_yx: can't get major %d\n", major); return result; } cdev_init(&jzq_yx_priv.cdev, &yx_fops); jzq_yx_priv.cdev.owner = THIS_MODULE; jzq_yx_priv.cdev.ops = &yx_fops; err = cdev_add(&jzq_yx_priv.cdev, jzq_yx_priv.dev, 1); if (err) { printk(KERN_NOTICE "Error[%d] cdev_add .\n", err); return -1; } jzq_yx_priv.yx_class = class_create(THIS_MODULE, "yx"); if (IS_ERR(jzq_yx_priv.yx_class)) { printk(KERN_ERR "Failed in create yx_cdev class\n"); return -1; } device_create(jzq_yx_priv.yx_class, NULL, jzq_yx_priv.dev, NULL, "yx"); ret = gpio_request_array(yx_gpios, MAX_PIN_NR); if (ret < 0) return ret; return 0; } static void __exit jzq_yx_exit(void) { gpio_free_array(yx_gpios, MAX_PIN_NR); cdev_del(&jzq_yx_priv.cdev); unregister_chrdev_region(jzq_yx_priv.dev, 1); device_destroy(jzq_yx_priv.yx_class, jzq_yx_priv.dev); class_destroy(jzq_yx_priv.yx_class); } module_init(jzq_yx_init); module_exit(jzq_yx_exit); MODULE_AUTHOR("lufei@china-cpu.com"); MODULE_DESCRIPTION("GSC3280 GW-JZQ YX Driver"); MODULE_LICENSE("GPL");