0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/init.h>
0013 #include <linux/module.h>
0014 #include <linux/kernel.h>
0015 #include <linux/errno.h>
0016 #include <linux/fb.h>
0017 #include <linux/mm.h>
0018 #include <linux/platform_device.h>
0019 #include <linux/cfag12864b.h>
0020
0021 #define CFAG12864BFB_NAME "cfag12864bfb"
0022
0023 static const struct fb_fix_screeninfo cfag12864bfb_fix = {
0024 .id = "cfag12864b",
0025 .type = FB_TYPE_PACKED_PIXELS,
0026 .visual = FB_VISUAL_MONO10,
0027 .xpanstep = 0,
0028 .ypanstep = 0,
0029 .ywrapstep = 0,
0030 .line_length = CFAG12864B_WIDTH / 8,
0031 .accel = FB_ACCEL_NONE,
0032 };
0033
0034 static const struct fb_var_screeninfo cfag12864bfb_var = {
0035 .xres = CFAG12864B_WIDTH,
0036 .yres = CFAG12864B_HEIGHT,
0037 .xres_virtual = CFAG12864B_WIDTH,
0038 .yres_virtual = CFAG12864B_HEIGHT,
0039 .bits_per_pixel = 1,
0040 .red = { 0, 1, 0 },
0041 .green = { 0, 1, 0 },
0042 .blue = { 0, 1, 0 },
0043 .left_margin = 0,
0044 .right_margin = 0,
0045 .upper_margin = 0,
0046 .lower_margin = 0,
0047 .vmode = FB_VMODE_NONINTERLACED,
0048 };
0049
0050 static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
0051 {
0052 struct page *pages = virt_to_page(cfag12864b_buffer);
0053
0054 return vm_map_pages_zero(vma, &pages, 1);
0055 }
0056
0057 static const struct fb_ops cfag12864bfb_ops = {
0058 .owner = THIS_MODULE,
0059 .fb_read = fb_sys_read,
0060 .fb_write = fb_sys_write,
0061 .fb_fillrect = sys_fillrect,
0062 .fb_copyarea = sys_copyarea,
0063 .fb_imageblit = sys_imageblit,
0064 .fb_mmap = cfag12864bfb_mmap,
0065 };
0066
0067 static int cfag12864bfb_probe(struct platform_device *device)
0068 {
0069 int ret = -EINVAL;
0070 struct fb_info *info = framebuffer_alloc(0, &device->dev);
0071
0072 if (!info)
0073 goto none;
0074
0075 info->screen_base = (char __iomem *) cfag12864b_buffer;
0076 info->screen_size = CFAG12864B_SIZE;
0077 info->fbops = &cfag12864bfb_ops;
0078 info->fix = cfag12864bfb_fix;
0079 info->var = cfag12864bfb_var;
0080 info->pseudo_palette = NULL;
0081 info->par = NULL;
0082 info->flags = FBINFO_FLAG_DEFAULT;
0083
0084 if (register_framebuffer(info) < 0)
0085 goto fballoced;
0086
0087 platform_set_drvdata(device, info);
0088
0089 fb_info(info, "%s frame buffer device\n", info->fix.id);
0090
0091 return 0;
0092
0093 fballoced:
0094 framebuffer_release(info);
0095
0096 none:
0097 return ret;
0098 }
0099
0100 static int cfag12864bfb_remove(struct platform_device *device)
0101 {
0102 struct fb_info *info = platform_get_drvdata(device);
0103
0104 if (info) {
0105 unregister_framebuffer(info);
0106 framebuffer_release(info);
0107 }
0108
0109 return 0;
0110 }
0111
0112 static struct platform_driver cfag12864bfb_driver = {
0113 .probe = cfag12864bfb_probe,
0114 .remove = cfag12864bfb_remove,
0115 .driver = {
0116 .name = CFAG12864BFB_NAME,
0117 },
0118 };
0119
0120 static struct platform_device *cfag12864bfb_device;
0121
0122 static int __init cfag12864bfb_init(void)
0123 {
0124 int ret = -EINVAL;
0125
0126
0127 if (!cfag12864b_isinited()) {
0128 printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
0129 "cfag12864b is not initialized\n");
0130 goto none;
0131 }
0132
0133 if (cfag12864b_enable()) {
0134 printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
0135 "can't enable cfag12864b refreshing (being used)\n");
0136 return -ENODEV;
0137 }
0138
0139 ret = platform_driver_register(&cfag12864bfb_driver);
0140
0141 if (!ret) {
0142 cfag12864bfb_device =
0143 platform_device_alloc(CFAG12864BFB_NAME, 0);
0144
0145 if (cfag12864bfb_device)
0146 ret = platform_device_add(cfag12864bfb_device);
0147 else
0148 ret = -ENOMEM;
0149
0150 if (ret) {
0151 platform_device_put(cfag12864bfb_device);
0152 platform_driver_unregister(&cfag12864bfb_driver);
0153 }
0154 }
0155
0156 none:
0157 return ret;
0158 }
0159
0160 static void __exit cfag12864bfb_exit(void)
0161 {
0162 platform_device_unregister(cfag12864bfb_device);
0163 platform_driver_unregister(&cfag12864bfb_driver);
0164 cfag12864b_disable();
0165 }
0166
0167 module_init(cfag12864bfb_init);
0168 module_exit(cfag12864bfb_exit);
0169
0170 MODULE_LICENSE("GPL v2");
0171 MODULE_AUTHOR("Miguel Ojeda <ojeda@kernel.org>");
0172 MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");