From c164cdc151902a4be76057d64b6f21ce703dbc29 Mon Sep 17 00:00:00 2001 From: Zheng Yang Date: Wed, 28 Jan 2015 18:13:37 +0800 Subject: [PATCH] modify display-sys.c and display-sys.h code style. Signed-off-by: Zheng Yang --- drivers/video/rockchip/display-sys.c | 303 ++++++++++++++------------- include/linux/display-sys.h | 44 ++-- 2 files changed, 179 insertions(+), 168 deletions(-) diff --git a/drivers/video/rockchip/display-sys.c b/drivers/video/rockchip/display-sys.c index 3097ace6ea75..dd1f9da3987e 100755 --- a/drivers/video/rockchip/display-sys.c +++ b/drivers/video/rockchip/display-sys.c @@ -8,50 +8,55 @@ static struct list_head display_device_list; static ssize_t display_show_name(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct rk_display_device *dsp = dev_get_drvdata(dev); + return snprintf(buf, PAGE_SIZE, "%s\n", dsp->name); } static ssize_t display_show_type(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct rk_display_device *dsp = dev_get_drvdata(dev); + return snprintf(buf, PAGE_SIZE, "%s\n", dsp->type); } static ssize_t display_show_enable(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct rk_display_device *dsp = dev_get_drvdata(dev); int enable; - if(dsp->ops && dsp->ops->getenable) + + if (dsp->ops && dsp->ops->getenable) enable = dsp->ops->getenable(dsp); else return 0; return snprintf(buf, PAGE_SIZE, "%d\n", enable); } -static ssize_t display_store_enable(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) +static ssize_t display_store_enable(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) { struct rk_display_device *dsp = dev_get_drvdata(dev); int enable; - - sscanf(buf, "%d", &enable); - if(dsp->ops && dsp->ops->setenable) + + if (kstrtoint(buf, 0, &enable)) + return size; + if (dsp->ops && dsp->ops->setenable) dsp->ops->setenable(dsp, enable); return size; } static ssize_t display_show_connect(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct rk_display_device *dsp = dev_get_drvdata(dev); int connect; - if(dsp->ops && dsp->ops->getstatus) + + if (dsp->ops && dsp->ops->getstatus) connect = dsp->ops->getstatus(dsp); else return 0; @@ -61,40 +66,39 @@ static ssize_t display_show_connect(struct device *dev, static int mode_string(char *buf, unsigned int offset, const struct fb_videomode *mode) { -// char m = 'U'; char v = 'p'; -// if (mode->flag & FB_MODE_IS_DETAILED) -// m = 'D'; -// if (mode->flag & FB_MODE_IS_VESA) -// m = 'V'; -// if (mode->flag & FB_MODE_IS_STANDARD) -// m = 'S'; - +/* + if (mode->flag & FB_MODE_IS_DETAILED) + m = 'D'; + if (mode->flag & FB_MODE_IS_VESA) + m = 'V'; + if (mode->flag & FB_MODE_IS_STANDARD) + m = 'S'; +*/ if (mode->vmode & FB_VMODE_INTERLACED) v = 'i'; if (mode->vmode & FB_VMODE_DOUBLE) v = 'd'; return snprintf(&buf[offset], PAGE_SIZE - offset, "%dx%d%c-%d\n", - mode->xres, mode->yres, v, mode->refresh); + mode->xres, mode->yres, v, mode->refresh); } static ssize_t display_show_modes(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct rk_display_device *dsp = dev_get_drvdata(dev); struct list_head *modelist, *pos; struct fb_modelist *fb_modelist; const struct fb_videomode *mode; int i; - if(dsp->ops && dsp->ops->getmodelist) - { - if(dsp->ops->getmodelist(dsp, &modelist)) + + if (dsp->ops && dsp->ops->getmodelist) { + if (dsp->ops->getmodelist(dsp, &modelist)) return -EINVAL; - } - else + } else { return 0; - + } i = 0; list_for_each(pos, modelist) { fb_modelist = list_entry(pos, struct fb_modelist, list); @@ -105,41 +109,40 @@ static ssize_t display_show_modes(struct device *dev, } static ssize_t display_show_mode(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct rk_display_device *dsp = dev_get_drvdata(dev); struct fb_videomode mode; - - if(dsp->ops && dsp->ops->getmode) - if(dsp->ops->getmode(dsp, &mode) == 0) + + if (dsp->ops && dsp->ops->getmode) + if (dsp->ops->getmode(dsp, &mode) == 0) return mode_string(buf, 0, &mode); return 0; } -static ssize_t display_store_mode(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t display_store_mode(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { struct rk_display_device *dsp = dev_get_drvdata(dev); char mstr[100]; struct list_head *modelist, *pos; struct fb_modelist *fb_modelist; - struct fb_videomode *mode; - size_t i; - - if(dsp->ops && dsp->ops->getmodelist) - { - if(dsp->ops && dsp->ops->getmodelist) - { - if(dsp->ops->getmodelist(dsp, &modelist)) + struct fb_videomode *mode; + size_t i; + + if (dsp->ops && dsp->ops->getmodelist) { + if (dsp->ops && dsp->ops->getmodelist) { + if (dsp->ops->getmodelist(dsp, &modelist)) return -EINVAL; } list_for_each(pos, modelist) { - fb_modelist = list_entry(pos, struct fb_modelist, list); + fb_modelist = list_entry(pos, + struct fb_modelist, list); mode = &fb_modelist->mode; i = mode_string(mstr, 0, mode); if (strncmp(mstr, buf, max(count, i)) == 0) { - if(dsp->ops && dsp->ops->setmode) + if (dsp->ops && dsp->ops->setmode) dsp->ops->setmode(dsp, mode); return count; } @@ -149,40 +152,50 @@ static ssize_t display_store_mode(struct device *dev, } static ssize_t display_show_scale(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, + char *buf) { struct rk_display_device *dsp = dev_get_drvdata(dev); int xscale, yscale; - - if(dsp->ops && dsp->ops->getscale) { + + if (dsp->ops && dsp->ops->getscale) { xscale = dsp->ops->getscale(dsp, DISPLAY_SCALE_X); yscale = dsp->ops->getscale(dsp, DISPLAY_SCALE_Y); - if(xscale && yscale) - return snprintf(buf, PAGE_SIZE, "xscale=%d yscale=%d\n", xscale, yscale); + if (xscale && yscale) + return snprintf(buf, PAGE_SIZE, + "xscale=%d yscale=%d\n", + xscale, yscale); } return -EINVAL; } -static ssize_t display_store_scale(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t display_store_scale(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { struct rk_display_device *dsp = dev_get_drvdata(dev); int scale = 100; - - if(dsp->ops && dsp->ops->setscale) { - if(!strncmp(buf, "xscale", 6)) { - sscanf(buf, "xscale=%d", &scale); - dsp->ops->setscale(dsp, DISPLAY_SCALE_X, scale); - } - else if(!strncmp(buf, "yscale", 6)) { - sscanf(buf, "yscale=%d", &scale); - dsp->ops->setscale(dsp, DISPLAY_SCALE_Y, scale); - } - else { - sscanf(buf, "%d", &scale); - dsp->ops->setscale(dsp, DISPLAY_SCALE_X, scale); - dsp->ops->setscale(dsp, DISPLAY_SCALE_Y, scale); + + if (dsp->ops && dsp->ops->setscale) { + if (!strncmp(buf, "xscale", 6)) { + if (!kstrtoint(buf, 0, &scale)) + dsp->ops->setscale(dsp, + DISPLAY_SCALE_X, + scale); + } else if (!strncmp(buf, "yscale", 6)) { + if (!kstrtoint(buf, 0, &scale)) + dsp->ops->setscale(dsp, + DISPLAY_SCALE_Y, + scale); + } else { + if (!kstrtoint(buf, 0, &scale)) { + dsp->ops->setscale(dsp, + DISPLAY_SCALE_X, + scale); + dsp->ops->setscale(dsp, + DISPLAY_SCALE_Y, + scale); + } } return count; } @@ -190,38 +203,38 @@ static ssize_t display_store_scale(struct device *dev, } static ssize_t display_show_debug(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { return -EINVAL; } static ssize_t display_store_debug(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) + struct device_attribute *attr, + const char *buf, size_t count) { int cmd; struct rk_display_device *dsp = dev_get_drvdata(dev); - if(dsp->ops && dsp->ops->setdebug) { - sscanf(buf, "%d", &cmd); - dsp->ops->setdebug(dsp, cmd); + if (dsp->ops && dsp->ops->setdebug) { + if (kstrtoint(buf, 0, &cmd) != -1) + dsp->ops->setdebug(dsp, cmd); return count; } return -EINVAL; } static ssize_t display_show_sinkaudioinfo(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, + char *buf) { struct rk_display_device *dsp = dev_get_drvdata(dev); char audioinfo[200]; - int ret=0; + int ret = 0; - if(dsp->ops && dsp->ops->getedidaudioinfo) { + if (dsp->ops && dsp->ops->getedidaudioinfo) { ret = dsp->ops->getedidaudioinfo(dsp, audioinfo, 200); - if(!ret){ + if (!ret) return snprintf(buf, PAGE_SIZE, "%s\n", audioinfo); - } } return -EINVAL; } @@ -229,16 +242,17 @@ static ssize_t display_show_sinkaudioinfo(struct device *dev, static ssize_t display_show_monspecs(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct rk_display_device *dsp = dev_get_drvdata(dev); struct fb_monspecs monspecs; int ret = 0; - if(dsp->ops && dsp->ops->getmonspecs) { - ret = dsp->ops->getmonspecs(dsp,&monspecs); - if(!ret) { + + if (dsp->ops && dsp->ops->getmonspecs) { + ret = dsp->ops->getmonspecs(dsp, &monspecs); + if (!ret) { memcpy(buf, &monspecs, sizeof(struct fb_monspecs)); - return sizeof(struct fb_monspecs);//snprintf(buf, PAGE_SIZE, "%s\n", monspecs.monitor); + return sizeof(struct fb_monspecs); } } return -EINVAL; @@ -283,59 +297,52 @@ static int display_resume(struct device *dev) void rk_display_device_enable(struct rk_display_device *ddev) { -//#ifndef CONFIG_DISPLAY_AUTO_SWITCH -// return; -//#else - struct list_head *pos, *head = &display_device_list; - struct rk_display_device *dev = NULL, *dev_enabled = NULL, *dev_enable = NULL; - int enable = 0,connect; - + struct list_head *pos, *head; + struct rk_display_device *dev = NULL, *dev_enabled = NULL; + struct rk_display_device *dev_enable = NULL; + int enable = 0, connect; + + head = &display_device_list; list_for_each(pos, head) { dev = list_entry(pos, struct rk_display_device, list); enable = dev->ops->getenable(dev); connect = dev->ops->getstatus(dev); - if(connect) + if (connect) dev_enable = dev; - if(enable == 1) + if (enable == 1) dev_enabled = dev; } - // If no device is connected, enable highest priority device. - if(dev_enable == NULL) { + /* If no device is connected, enable highest priority device. */ + if (dev_enable == NULL) { dev->ops->setenable(dev, 1); return; } - - if(dev_enable == dev_enabled) { - if(dev_enable != ddev) + + if (dev_enable == dev_enabled) { + if (dev_enable != ddev) ddev->ops->setenable(ddev, 0); - } - else { - if(dev_enabled) + } else { + if (dev_enabled) dev_enabled->ops->setenable(dev_enabled, 0); dev_enable->ops->setenable(dev_enable, 1); } - - -//#endif } EXPORT_SYMBOL(rk_display_device_enable); void rk_display_device_enable_other(struct rk_display_device *ddev) { -#ifndef CONFIG_DISPLAY_AUTO_SWITCH +#ifndef CONFIG_DISPLAY_AUTO_SWITCH return; #else struct list_head *pos, *head = &display_device_list; - struct rk_display_device *dev; + struct rk_display_device *dev; int connect = 0; - + list_for_each_prev(pos, head) { dev = list_entry(pos, struct rk_display_device, list); - if(dev != ddev) - { + if (dev != ddev) { connect = dev->ops->getstatus(dev); - if(connect) - { + if (connect) { dev->ops->setenable(dev, 1); return; } @@ -351,15 +358,14 @@ void rk_display_device_disable_other(struct rk_display_device *ddev) return; #else struct list_head *pos, *head = &display_device_list; - struct rk_display_device *dev; + struct rk_display_device *dev; int enable = 0; - + list_for_each(pos, head) { dev = list_entry(pos, struct rk_display_device, list); - if(dev != ddev) - { + if (dev != ddev) { enable = dev->ops->getenable(dev); - if(enable) + if (enable) dev->ops->setenable(dev, 0); } } @@ -373,29 +379,28 @@ void rk_display_device_select(int priority) struct list_head *pos, *head = &display_device_list; struct rk_display_device *dev; int enable, found = 0; - + list_for_each(pos, head) { dev = list_entry(pos, struct rk_display_device, list); - if(dev->priority == priority) + if (dev->priority == priority) found = 1; } - - if(!found) - { - printk("[%s] select display interface %d not exist\n", __FUNCTION__, priority); + + if (!found) { + pr_err("[%s] select display interface %d not exist\n", + __func__, priority); return; } - + list_for_each(pos, head) { dev = list_entry(pos, struct rk_display_device, list); enable = dev->ops->getenable(dev); - if(dev->priority == priority) - { - if(!enable) + if (dev->priority == priority) { + if (!enable) dev->ops->setenable(dev, 1); - } - else if(enable) + } else if (enable) { dev->ops->setenable(dev, 0); + } } } EXPORT_SYMBOL(rk_display_device_select); @@ -403,8 +408,9 @@ static struct mutex allocated_dsp_lock; static DEFINE_IDR(allocated_dsp); static struct class *display_class; -struct rk_display_device *rk_display_device_register(struct rk_display_driver *driver, - struct device *parent, void *devdata) +struct rk_display_device + *rk_display_device_register(struct rk_display_driver *driver, + struct device *parent, void *devdata) { struct rk_display_device *new_dev = NULL; int ret = -EINVAL; @@ -412,11 +418,12 @@ struct rk_display_device *rk_display_device_register(struct rk_display_driver *d if (unlikely(!driver)) return ERR_PTR(ret); - new_dev = kzalloc(sizeof(struct rk_display_device), GFP_KERNEL); + new_dev = kzalloc(sizeof(*new_dev), GFP_KERNEL); if (likely(new_dev) && unlikely(driver->probe(new_dev, devdata))) { - // Reserve the index for this display + /* Reserve the index for this display */ mutex_lock(&allocated_dsp_lock); - new_dev->idx = idr_alloc(&allocated_dsp, new_dev, 0, 0, GFP_KERNEL); + new_dev->idx = idr_alloc(&allocated_dsp, new_dev, + 0, 0, GFP_KERNEL); mutex_unlock(&allocated_dsp_lock); if (new_dev->idx >= 0) { @@ -426,22 +433,26 @@ struct rk_display_device *rk_display_device_register(struct rk_display_driver *d if (!IS_ERR(new_dev->dev)) { new_dev->parent = parent; new_dev->driver = driver; - if(parent) + if (parent) new_dev->dev->driver = parent->driver; mutex_init(&new_dev->lock); - // Add new device to display device list. + /* Add new device to display device list. */ { - struct list_head *pos, *head = &display_device_list; - struct rk_display_device *dev; - - list_for_each(pos, head) { - dev = list_entry(pos, struct rk_display_device, list); - if(dev->priority > new_dev->priority) - break; - } - list_add_tail(&new_dev->list, pos); + struct list_head *pos, *head; + struct rk_display_device *dev; + + head = &display_device_list; + list_for_each(pos, head) { + dev = + list_entry(pos, + struct rk_display_device, + list); + if (dev->priority > new_dev->priority) + break; } + list_add_tail(&new_dev->list, pos); return new_dev; + } } mutex_lock(&allocated_dsp_lock); idr_remove(&allocated_dsp, new_dev->idx); @@ -458,11 +469,11 @@ void rk_display_device_unregister(struct rk_display_device *ddev) { if (!ddev) return; - // Free device + /* Free device */ mutex_lock(&ddev->lock); device_unregister(ddev->dev); mutex_unlock(&ddev->lock); - // Mark device index as avaliable + /* Mark device index as avaliable */ mutex_lock(&allocated_dsp_lock); idr_remove(&allocated_dsp, ddev->idx); mutex_unlock(&allocated_dsp_lock); @@ -475,7 +486,7 @@ static int __init rk_display_class_init(void) { display_class = class_create(THIS_MODULE, "display"); if (IS_ERR(display_class)) { - printk(KERN_ERR "Failed to create display class\n"); + pr_err("Failed to create display class\n"); display_class = NULL; return -EINVAL; } diff --git a/include/linux/display-sys.h b/include/linux/display-sys.h index ce89ff7adedc..28a14aac7ff0 100755 --- a/include/linux/display-sys.h +++ b/include/linux/display-sys.h @@ -9,7 +9,7 @@ struct rk_display_device; enum rk_display_priority { DISPLAY_PRIORITY_TV = 0, - DISPLAY_PRIORITY_YPbPr, + DISPLAY_PRIORITY_YPBPR, DISPLAY_PRIORITY_VGA, DISPLAY_PRIORITY_HDMI, DISPLAY_PRIORITY_LCD, @@ -32,21 +32,26 @@ struct rk_display_ops { int (*setenable)(struct rk_display_device *, int enable); int (*getenable)(struct rk_display_device *); int (*getstatus)(struct rk_display_device *); - int (*getmodelist)(struct rk_display_device *, struct list_head **modelist); - int (*setmode)(struct rk_display_device *, struct fb_videomode *mode); - int (*getmode)(struct rk_display_device *, struct fb_videomode *mode); + int (*getmodelist)(struct rk_display_device *, + struct list_head **modelist); + int (*setmode)(struct rk_display_device *, + struct fb_videomode *mode); + int (*getmode)(struct rk_display_device *, + struct fb_videomode *mode); int (*setscale)(struct rk_display_device *, int, int); int (*getscale)(struct rk_display_device *, int); int (*setdebug)(struct rk_display_device *, int); - int (*getedidaudioinfo)(struct rk_display_device *, char *audioinfo, int len); - int (*getmonspecs)(struct rk_display_device *, struct fb_monspecs *monspecs); + int (*getedidaudioinfo)(struct rk_display_device *, + char *audioinfo, int len); + int (*getmonspecs)(struct rk_display_device *, + struct fb_monspecs *monspecs); }; struct rk_display_device { - struct module *owner; /* Owner module */ + struct module *owner; /* Owner module */ struct rk_display_driver *driver; - struct device *parent; /* This is the parent */ - struct device *dev; /* This is this display device */ + struct device *parent; /* This is the parent */ + struct device *dev; /* This is this display device */ struct mutex lock; void *priv_data; char type[16]; @@ -62,18 +67,13 @@ struct rk_display_devicelist { struct rk_display_device *dev; }; -extern struct rk_display_device *rk_display_device_register(struct rk_display_driver *driver, - struct device *dev, void *devdata); -extern void rk_display_device_unregister(struct rk_display_device *dev); - -extern void rk_display_device_enable(struct rk_display_device *ddev); - -extern void rk_display_device_enable_other(struct rk_display_device *ddev); -extern void rk_display_device_disable_other(struct rk_display_device *ddev); - - -extern void rk_display_device_select(int priority); - -#define to_rk_display_device(obj) container_of(obj, struct rk_display_device, class_dev) +struct rk_display_device + *rk_display_device_register(struct rk_display_driver *driver, + struct device *parent, void *devdata); +void rk_display_device_unregister(struct rk_display_device *dev); +void rk_display_device_enable(struct rk_display_device *ddev); +void rk_display_device_enable_other(struct rk_display_device *ddev); +void rk_display_device_disable_other(struct rk_display_device *ddev); +void rk_display_device_select(int priority); #endif -- 2.34.1