Miguel Ojeda | 351f683b | 2018-02-17 20:33:13 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Filename: cfag12864bfb.c |
| 4 | * Version: 0.1.0 |
| 5 | * Description: cfag12864b LCD framebuffer driver |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 6 | * Depends: cfag12864b |
| 7 | * |
Miguel Ojeda | 450c622 | 2008-07-04 09:59:33 -0700 | [diff] [blame] | 8 | * Author: Copyright (C) Miguel Ojeda Sandonis |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 9 | * Date: 2006-10-31 |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/fb.h> |
| 18 | #include <linux/mm.h> |
| 19 | #include <linux/platform_device.h> |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 20 | #include <linux/string.h> |
| 21 | #include <linux/uaccess.h> |
| 22 | #include <linux/cfag12864b.h> |
| 23 | |
| 24 | #define CFAG12864BFB_NAME "cfag12864bfb" |
| 25 | |
Gustavo A. R. Silva | 7223310 | 2017-07-07 20:02:26 -0500 | [diff] [blame] | 26 | static const struct fb_fix_screeninfo cfag12864bfb_fix = { |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 27 | .id = "cfag12864b", |
| 28 | .type = FB_TYPE_PACKED_PIXELS, |
| 29 | .visual = FB_VISUAL_MONO10, |
| 30 | .xpanstep = 0, |
| 31 | .ypanstep = 0, |
| 32 | .ywrapstep = 0, |
| 33 | .line_length = CFAG12864B_WIDTH / 8, |
| 34 | .accel = FB_ACCEL_NONE, |
| 35 | }; |
| 36 | |
Gustavo A. R. Silva | 7223310 | 2017-07-07 20:02:26 -0500 | [diff] [blame] | 37 | static const struct fb_var_screeninfo cfag12864bfb_var = { |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 38 | .xres = CFAG12864B_WIDTH, |
| 39 | .yres = CFAG12864B_HEIGHT, |
| 40 | .xres_virtual = CFAG12864B_WIDTH, |
| 41 | .yres_virtual = CFAG12864B_HEIGHT, |
| 42 | .bits_per_pixel = 1, |
| 43 | .red = { 0, 1, 0 }, |
| 44 | .green = { 0, 1, 0 }, |
| 45 | .blue = { 0, 1, 0 }, |
| 46 | .left_margin = 0, |
| 47 | .right_margin = 0, |
| 48 | .upper_margin = 0, |
| 49 | .lower_margin = 0, |
| 50 | .vmode = FB_VMODE_NONINTERLACED, |
| 51 | }; |
| 52 | |
| 53 | static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma) |
| 54 | { |
Souptick Joarder | 461e274 | 2019-05-26 21:40:27 +0530 | [diff] [blame] | 55 | struct page *pages = virt_to_page(cfag12864b_buffer); |
| 56 | |
| 57 | return vm_map_pages_zero(vma, &pages, 1); |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Jani Nikula | bd223ac | 2019-12-03 18:38:54 +0200 | [diff] [blame] | 60 | static const struct fb_ops cfag12864bfb_ops = { |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 61 | .owner = THIS_MODULE, |
Avuton Olrich | bfeeffb | 2007-06-01 00:46:45 -0700 | [diff] [blame] | 62 | .fb_read = fb_sys_read, |
| 63 | .fb_write = fb_sys_write, |
| 64 | .fb_fillrect = sys_fillrect, |
| 65 | .fb_copyarea = sys_copyarea, |
| 66 | .fb_imageblit = sys_imageblit, |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 67 | .fb_mmap = cfag12864bfb_mmap, |
| 68 | }; |
| 69 | |
Greg Kroah-Hartman | 0fe763c | 2012-12-21 15:14:44 -0800 | [diff] [blame] | 70 | static int cfag12864bfb_probe(struct platform_device *device) |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 71 | { |
| 72 | int ret = -EINVAL; |
| 73 | struct fb_info *info = framebuffer_alloc(0, &device->dev); |
| 74 | |
| 75 | if (!info) |
| 76 | goto none; |
| 77 | |
| 78 | info->screen_base = (char __iomem *) cfag12864b_buffer; |
| 79 | info->screen_size = CFAG12864B_SIZE; |
| 80 | info->fbops = &cfag12864bfb_ops; |
| 81 | info->fix = cfag12864bfb_fix; |
| 82 | info->var = cfag12864bfb_var; |
| 83 | info->pseudo_palette = NULL; |
| 84 | info->par = NULL; |
| 85 | info->flags = FBINFO_FLAG_DEFAULT; |
| 86 | |
| 87 | if (register_framebuffer(info) < 0) |
| 88 | goto fballoced; |
| 89 | |
| 90 | platform_set_drvdata(device, info); |
| 91 | |
Joe Perches | 31b6780 | 2013-09-19 18:35:55 -0700 | [diff] [blame] | 92 | fb_info(info, "%s frame buffer device\n", info->fix.id); |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 93 | |
| 94 | return 0; |
| 95 | |
| 96 | fballoced: |
| 97 | framebuffer_release(info); |
| 98 | |
| 99 | none: |
| 100 | return ret; |
| 101 | } |
| 102 | |
Greg Kroah-Hartman | 0fe763c | 2012-12-21 15:14:44 -0800 | [diff] [blame] | 103 | static int cfag12864bfb_remove(struct platform_device *device) |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 104 | { |
| 105 | struct fb_info *info = platform_get_drvdata(device); |
| 106 | |
| 107 | if (info) { |
| 108 | unregister_framebuffer(info); |
| 109 | framebuffer_release(info); |
| 110 | } |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static struct platform_driver cfag12864bfb_driver = { |
| 116 | .probe = cfag12864bfb_probe, |
Greg Kroah-Hartman | 0fe763c | 2012-12-21 15:14:44 -0800 | [diff] [blame] | 117 | .remove = cfag12864bfb_remove, |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 118 | .driver = { |
| 119 | .name = CFAG12864BFB_NAME, |
| 120 | }, |
| 121 | }; |
| 122 | |
| 123 | static struct platform_device *cfag12864bfb_device; |
| 124 | |
| 125 | static int __init cfag12864bfb_init(void) |
| 126 | { |
Miguel Ojeda | 34173a4 | 2007-02-20 13:58:00 -0800 | [diff] [blame] | 127 | int ret = -EINVAL; |
| 128 | |
| 129 | /* cfag12864b_init() must be called first */ |
| 130 | if (!cfag12864b_isinited()) { |
| 131 | printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: " |
| 132 | "cfag12864b is not initialized\n"); |
| 133 | goto none; |
| 134 | } |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 135 | |
| 136 | if (cfag12864b_enable()) { |
| 137 | printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: " |
| 138 | "can't enable cfag12864b refreshing (being used)\n"); |
| 139 | return -ENODEV; |
| 140 | } |
| 141 | |
| 142 | ret = platform_driver_register(&cfag12864bfb_driver); |
| 143 | |
| 144 | if (!ret) { |
| 145 | cfag12864bfb_device = |
| 146 | platform_device_alloc(CFAG12864BFB_NAME, 0); |
| 147 | |
| 148 | if (cfag12864bfb_device) |
| 149 | ret = platform_device_add(cfag12864bfb_device); |
| 150 | else |
| 151 | ret = -ENOMEM; |
| 152 | |
| 153 | if (ret) { |
| 154 | platform_device_put(cfag12864bfb_device); |
| 155 | platform_driver_unregister(&cfag12864bfb_driver); |
| 156 | } |
| 157 | } |
| 158 | |
Miguel Ojeda | 34173a4 | 2007-02-20 13:58:00 -0800 | [diff] [blame] | 159 | none: |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 160 | return ret; |
| 161 | } |
| 162 | |
| 163 | static void __exit cfag12864bfb_exit(void) |
| 164 | { |
| 165 | platform_device_unregister(cfag12864bfb_device); |
| 166 | platform_driver_unregister(&cfag12864bfb_driver); |
| 167 | cfag12864b_disable(); |
| 168 | } |
| 169 | |
| 170 | module_init(cfag12864bfb_init); |
| 171 | module_exit(cfag12864bfb_exit); |
| 172 | |
| 173 | MODULE_LICENSE("GPL v2"); |
Miguel Ojeda | 450c622 | 2008-07-04 09:59:33 -0700 | [diff] [blame] | 174 | MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>"); |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 175 | MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver"); |