Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 *    Filename: cfag12864bfb.c
  4 *     Version: 0.1.0
  5 * Description: cfag12864b LCD framebuffer driver
 
  6 *     Depends: cfag12864b
  7 *
  8 *      Author: Copyright (C) Miguel Ojeda <ojeda@kernel.org>
  9 *        Date: 2006-10-31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 10 */
 11
 12#include <linux/init.h>
 13#include <linux/module.h>
 14#include <linux/kernel.h>
 
 15#include <linux/errno.h>
 16#include <linux/fb.h>
 17#include <linux/mm.h>
 18#include <linux/platform_device.h>
 
 
 19#include <linux/cfag12864b.h>
 20
 21#define CFAG12864BFB_NAME "cfag12864bfb"
 22
 23static const struct fb_fix_screeninfo cfag12864bfb_fix = {
 24	.id = "cfag12864b",
 25	.type = FB_TYPE_PACKED_PIXELS,
 26	.visual = FB_VISUAL_MONO10,
 27	.xpanstep = 0,
 28	.ypanstep = 0,
 29	.ywrapstep = 0,
 30	.line_length = CFAG12864B_WIDTH / 8,
 31	.accel = FB_ACCEL_NONE,
 32};
 33
 34static const struct fb_var_screeninfo cfag12864bfb_var = {
 35	.xres = CFAG12864B_WIDTH,
 36	.yres = CFAG12864B_HEIGHT,
 37	.xres_virtual = CFAG12864B_WIDTH,
 38	.yres_virtual = CFAG12864B_HEIGHT,
 39	.bits_per_pixel = 1,
 40	.red = { 0, 1, 0 },
 41	.green = { 0, 1, 0 },
 42	.blue = { 0, 1, 0 },
 43	.left_margin = 0,
 44	.right_margin = 0,
 45	.upper_margin = 0,
 46	.lower_margin = 0,
 47	.vmode = FB_VMODE_NONINTERLACED,
 48};
 49
 50static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 51{
 52	struct page *pages = virt_to_page(cfag12864b_buffer);
 53
 54	vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
 55
 56	return vm_map_pages_zero(vma, &pages, 1);
 57}
 58
 59static const struct fb_ops cfag12864bfb_ops = {
 60	.owner = THIS_MODULE,
 61	__FB_DEFAULT_SYSMEM_OPS_RDWR,
 62	__FB_DEFAULT_SYSMEM_OPS_DRAW,
 
 
 
 63	.fb_mmap = cfag12864bfb_mmap,
 64};
 65
 66static int cfag12864bfb_probe(struct platform_device *device)
 67{
 68	int ret = -EINVAL;
 69	struct fb_info *info = framebuffer_alloc(0, &device->dev);
 70
 71	if (!info)
 72		goto none;
 73
 74	info->flags = FBINFO_VIRTFB;
 75	info->screen_buffer = cfag12864b_buffer;
 76	info->screen_size = CFAG12864B_SIZE;
 77	info->fbops = &cfag12864bfb_ops;
 78	info->fix = cfag12864bfb_fix;
 79	info->var = cfag12864bfb_var;
 80	info->pseudo_palette = NULL;
 81	info->par = NULL;
 
 82
 83	if (register_framebuffer(info) < 0)
 84		goto fballoced;
 85
 86	platform_set_drvdata(device, info);
 87
 88	fb_info(info, "%s frame buffer device\n", info->fix.id);
 89
 90	return 0;
 91
 92fballoced:
 93	framebuffer_release(info);
 94
 95none:
 96	return ret;
 97}
 98
 99static int cfag12864bfb_remove(struct platform_device *device)
100{
101	struct fb_info *info = platform_get_drvdata(device);
102
103	if (info) {
104		unregister_framebuffer(info);
105		framebuffer_release(info);
106	}
107
108	return 0;
109}
110
111static struct platform_driver cfag12864bfb_driver = {
112	.probe	= cfag12864bfb_probe,
113	.remove = cfag12864bfb_remove,
114	.driver = {
115		.name	= CFAG12864BFB_NAME,
116	},
117};
118
119static struct platform_device *cfag12864bfb_device;
120
121static int __init cfag12864bfb_init(void)
122{
123	int ret = -EINVAL;
124
125	/* cfag12864b_init() must be called first */
126	if (!cfag12864b_isinited()) {
127		printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
128			"cfag12864b is not initialized\n");
129		goto none;
130	}
131
132	if (cfag12864b_enable()) {
133		printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
134			"can't enable cfag12864b refreshing (being used)\n");
135		return -ENODEV;
136	}
137
138	ret = platform_driver_register(&cfag12864bfb_driver);
139
140	if (!ret) {
141		cfag12864bfb_device =
142			platform_device_alloc(CFAG12864BFB_NAME, 0);
143
144		if (cfag12864bfb_device)
145			ret = platform_device_add(cfag12864bfb_device);
146		else
147			ret = -ENOMEM;
148
149		if (ret) {
150			platform_device_put(cfag12864bfb_device);
151			platform_driver_unregister(&cfag12864bfb_driver);
152		}
153	}
154
155none:
156	return ret;
157}
158
159static void __exit cfag12864bfb_exit(void)
160{
161	platform_device_unregister(cfag12864bfb_device);
162	platform_driver_unregister(&cfag12864bfb_driver);
163	cfag12864b_disable();
164}
165
166module_init(cfag12864bfb_init);
167module_exit(cfag12864bfb_exit);
168
169MODULE_LICENSE("GPL v2");
170MODULE_AUTHOR("Miguel Ojeda <ojeda@kernel.org>");
171MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");
v3.15
 
  1/*
  2 *    Filename: cfag12864bfb.c
  3 *     Version: 0.1.0
  4 * Description: cfag12864b LCD framebuffer driver
  5 *     License: GPLv2
  6 *     Depends: cfag12864b
  7 *
  8 *      Author: Copyright (C) Miguel Ojeda Sandonis
  9 *        Date: 2006-10-31
 10 *
 11 *  This program is free software; you can redistribute it and/or modify
 12 *  it under the terms of the GNU General Public License version 2 as
 13 *  published by the Free Software Foundation.
 14 *
 15 *  This program is distributed in the hope that it will be useful,
 16 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 *  GNU General Public License for more details.
 19 *
 20 *  You should have received a copy of the GNU General Public License
 21 *  along with this program; if not, write to the Free Software
 22 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 23 *
 24 */
 25
 26#include <linux/init.h>
 27#include <linux/module.h>
 28#include <linux/kernel.h>
 29#include <linux/delay.h>
 30#include <linux/errno.h>
 31#include <linux/fb.h>
 32#include <linux/mm.h>
 33#include <linux/platform_device.h>
 34#include <linux/string.h>
 35#include <linux/uaccess.h>
 36#include <linux/cfag12864b.h>
 37
 38#define CFAG12864BFB_NAME "cfag12864bfb"
 39
 40static struct fb_fix_screeninfo cfag12864bfb_fix = {
 41	.id = "cfag12864b",
 42	.type = FB_TYPE_PACKED_PIXELS,
 43	.visual = FB_VISUAL_MONO10,
 44	.xpanstep = 0,
 45	.ypanstep = 0,
 46	.ywrapstep = 0,
 47	.line_length = CFAG12864B_WIDTH / 8,
 48	.accel = FB_ACCEL_NONE,
 49};
 50
 51static struct fb_var_screeninfo cfag12864bfb_var = {
 52	.xres = CFAG12864B_WIDTH,
 53	.yres = CFAG12864B_HEIGHT,
 54	.xres_virtual = CFAG12864B_WIDTH,
 55	.yres_virtual = CFAG12864B_HEIGHT,
 56	.bits_per_pixel = 1,
 57	.red = { 0, 1, 0 },
 58      	.green = { 0, 1, 0 },
 59      	.blue = { 0, 1, 0 },
 60	.left_margin = 0,
 61	.right_margin = 0,
 62	.upper_margin = 0,
 63	.lower_margin = 0,
 64	.vmode = FB_VMODE_NONINTERLACED,
 65};
 66
 67static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 68{
 69	return vm_insert_page(vma, vma->vm_start,
 70		virt_to_page(cfag12864b_buffer));
 
 
 
 71}
 72
 73static struct fb_ops cfag12864bfb_ops = {
 74	.owner = THIS_MODULE,
 75	.fb_read = fb_sys_read,
 76	.fb_write = fb_sys_write,
 77	.fb_fillrect = sys_fillrect,
 78	.fb_copyarea = sys_copyarea,
 79	.fb_imageblit = sys_imageblit,
 80	.fb_mmap = cfag12864bfb_mmap,
 81};
 82
 83static int cfag12864bfb_probe(struct platform_device *device)
 84{
 85	int ret = -EINVAL;
 86 	struct fb_info *info = framebuffer_alloc(0, &device->dev);
 87
 88	if (!info)
 89		goto none;
 90
 91	info->screen_base = (char __iomem *) cfag12864b_buffer;
 
 92	info->screen_size = CFAG12864B_SIZE;
 93	info->fbops = &cfag12864bfb_ops;
 94	info->fix = cfag12864bfb_fix;
 95	info->var = cfag12864bfb_var;
 96	info->pseudo_palette = NULL;
 97	info->par = NULL;
 98	info->flags = FBINFO_FLAG_DEFAULT;
 99
100	if (register_framebuffer(info) < 0)
101		goto fballoced;
102
103	platform_set_drvdata(device, info);
104
105	fb_info(info, "%s frame buffer device\n", info->fix.id);
106
107	return 0;
108
109fballoced:
110	framebuffer_release(info);
111
112none:
113	return ret;
114}
115
116static int cfag12864bfb_remove(struct platform_device *device)
117{
118	struct fb_info *info = platform_get_drvdata(device);
119
120	if (info) {
121		unregister_framebuffer(info);
122		framebuffer_release(info);
123	}
124
125	return 0;
126}
127
128static struct platform_driver cfag12864bfb_driver = {
129	.probe	= cfag12864bfb_probe,
130	.remove = cfag12864bfb_remove,
131	.driver = {
132		.name	= CFAG12864BFB_NAME,
133	},
134};
135
136static struct platform_device *cfag12864bfb_device;
137
138static int __init cfag12864bfb_init(void)
139{
140	int ret = -EINVAL;
141
142	/* cfag12864b_init() must be called first */
143	if (!cfag12864b_isinited()) {
144		printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
145			"cfag12864b is not initialized\n");
146		goto none;
147	}
148
149	if (cfag12864b_enable()) {
150		printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
151			"can't enable cfag12864b refreshing (being used)\n");
152		return -ENODEV;
153	}
154
155	ret = platform_driver_register(&cfag12864bfb_driver);
156
157	if (!ret) {
158		cfag12864bfb_device =
159			platform_device_alloc(CFAG12864BFB_NAME, 0);
160
161		if (cfag12864bfb_device)
162			ret = platform_device_add(cfag12864bfb_device);
163		else
164			ret = -ENOMEM;
165
166		if (ret) {
167			platform_device_put(cfag12864bfb_device);
168			platform_driver_unregister(&cfag12864bfb_driver);
169		}
170	}
171
172none:
173	return ret;
174}
175
176static void __exit cfag12864bfb_exit(void)
177{
178	platform_device_unregister(cfag12864bfb_device);
179	platform_driver_unregister(&cfag12864bfb_driver);
180	cfag12864b_disable();
181}
182
183module_init(cfag12864bfb_init);
184module_exit(cfag12864bfb_exit);
185
186MODULE_LICENSE("GPL v2");
187MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
188MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");