blob: f5b668e77af32e8b4c7306f64032938da453dd33 [file] [log] [blame]
Heiko Stübner96b1d502012-04-28 12:21:12 +02001/*
2 * auok190xfb.c -- FB driver for AUO-K1900 controllers
3 *
4 * Copyright (C) 2011, 2012 Heiko Stuebner <heiko@sntech.de>
5 *
6 * based on broadsheetfb.c
7 *
8 * Copyright (C) 2008, Jaya Kumar
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
15 *
16 * This driver is written to be used with the AUO-K1900 display controller.
17 *
18 * It is intended to be architecture independent. A board specific driver
19 * must be used to perform all the physical IO interactions.
20 *
21 * The controller supports different update modes:
22 * mode0+1 16 step gray (4bit)
23 * mode2 4 step gray (2bit) - FIXME: add strange refresh
24 * mode3 2 step gray (1bit) - FIXME: add strange refresh
25 * mode4 handwriting mode (strange behaviour)
26 * mode5 automatic selection of update mode
27 */
28
29#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/errno.h>
32#include <linux/string.h>
33#include <linux/mm.h>
34#include <linux/slab.h>
35#include <linux/delay.h>
36#include <linux/interrupt.h>
37#include <linux/fb.h>
38#include <linux/init.h>
39#include <linux/platform_device.h>
40#include <linux/list.h>
41#include <linux/firmware.h>
42#include <linux/gpio.h>
43#include <linux/pm_runtime.h>
44
45#include <video/auo_k190xfb.h>
46
47#include "auo_k190x.h"
48
49/*
50 * AUO-K1900 specific commands
51 */
52
53#define AUOK1900_CMD_PARTIALDISP 0x1001
54#define AUOK1900_CMD_ROTATION 0x1006
55#define AUOK1900_CMD_LUT_STOP 0x1009
56
57#define AUOK1900_INIT_TEMP_AVERAGE (1 << 13)
58#define AUOK1900_INIT_ROTATE(_x) ((_x & 0x3) << 10)
59#define AUOK1900_INIT_RESOLUTION(_res) ((_res & 0x7) << 2)
60
61static void auok1900_init(struct auok190xfb_par *par)
62{
Heiko Stübner70f1e282013-03-22 15:13:37 +010063 struct device *dev = par->info->device;
Heiko Stübner96b1d502012-04-28 12:21:12 +020064 struct auok190x_board *board = par->board;
65 u16 init_param = 0;
66
Heiko Stübner70f1e282013-03-22 15:13:37 +010067 pm_runtime_get_sync(dev);
68
Heiko Stübner96b1d502012-04-28 12:21:12 +020069 init_param |= AUOK1900_INIT_TEMP_AVERAGE;
70 init_param |= AUOK1900_INIT_ROTATE(par->rotation);
71 init_param |= AUOK190X_INIT_INVERSE_WHITE;
72 init_param |= AUOK190X_INIT_FORMAT0;
73 init_param |= AUOK1900_INIT_RESOLUTION(par->resolution);
74 init_param |= AUOK190X_INIT_SHIFT_RIGHT;
75
76 auok190x_send_cmdargs(par, AUOK190X_CMD_INIT, 1, &init_param);
77
78 /* let the controller finish */
79 board->wait_for_rdy(par);
Heiko Stübner70f1e282013-03-22 15:13:37 +010080
81 pm_runtime_mark_last_busy(dev);
82 pm_runtime_put_autosuspend(dev);
Heiko Stübner96b1d502012-04-28 12:21:12 +020083}
84
85static void auok1900_update_region(struct auok190xfb_par *par, int mode,
86 u16 y1, u16 y2)
87{
88 struct device *dev = par->info->device;
89 unsigned char *buf = (unsigned char *)par->info->screen_base;
90 int xres = par->info->var.xres;
Heiko Stübnera1655102013-03-22 15:13:02 +010091 int line_length = par->info->fix.line_length;
Heiko Stübner96b1d502012-04-28 12:21:12 +020092 u16 args[4];
93
94 pm_runtime_get_sync(dev);
95
96 mutex_lock(&(par->io_lock));
97
98 /* y1 and y2 must be a multiple of 2 so drop the lowest bit */
99 y1 &= 0xfffe;
100 y2 &= 0xfffe;
101
102 dev_dbg(dev, "update (x,y,w,h,mode)=(%d,%d,%d,%d,%d)\n",
103 1, y1+1, xres, y2-y1, mode);
104
105 /* to FIX handle different partial update modes */
106 args[0] = mode | 1;
107 args[1] = y1 + 1;
108 args[2] = xres;
109 args[3] = y2 - y1;
Heiko Stübnera1655102013-03-22 15:13:02 +0100110 buf += y1 * line_length;
Heiko Stübner96b1d502012-04-28 12:21:12 +0200111 auok190x_send_cmdargs_pixels(par, AUOK1900_CMD_PARTIALDISP, 4, args,
Heiko Stübnera1655102013-03-22 15:13:02 +0100112 ((y2 - y1) * line_length)/2, (u16 *) buf);
Heiko Stübner96b1d502012-04-28 12:21:12 +0200113 auok190x_send_command(par, AUOK190X_CMD_DATA_STOP);
114
115 par->update_cnt++;
116
117 mutex_unlock(&(par->io_lock));
118
119 pm_runtime_mark_last_busy(dev);
120 pm_runtime_put_autosuspend(dev);
121}
122
123static void auok1900fb_dpy_update_pages(struct auok190xfb_par *par,
124 u16 y1, u16 y2)
125{
126 int mode;
127
128 if (par->update_mode < 0) {
129 mode = AUOK190X_UPDATE_MODE(1);
130 par->last_mode = -1;
131 } else {
132 mode = AUOK190X_UPDATE_MODE(par->update_mode);
133 par->last_mode = par->update_mode;
134 }
135
136 if (par->flash)
137 mode |= AUOK190X_UPDATE_NONFLASH;
138
139 auok1900_update_region(par, mode, y1, y2);
140}
141
142static void auok1900fb_dpy_update(struct auok190xfb_par *par)
143{
144 int mode;
145
146 if (par->update_mode < 0) {
147 mode = AUOK190X_UPDATE_MODE(0);
148 par->last_mode = -1;
149 } else {
150 mode = AUOK190X_UPDATE_MODE(par->update_mode);
151 par->last_mode = par->update_mode;
152 }
153
154 if (par->flash)
155 mode |= AUOK190X_UPDATE_NONFLASH;
156
157 auok1900_update_region(par, mode, 0, par->info->var.yres);
158 par->update_cnt = 0;
159}
160
161static bool auok1900fb_need_refresh(struct auok190xfb_par *par)
162{
163 return (par->update_cnt > 10);
164}
165
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800166static int auok1900fb_probe(struct platform_device *pdev)
Heiko Stübner96b1d502012-04-28 12:21:12 +0200167{
168 struct auok190x_init_data init;
169 struct auok190x_board *board;
170
171 /* pick up board specific routines */
172 board = pdev->dev.platform_data;
173 if (!board)
174 return -EINVAL;
175
176 /* fill temporary init struct for common init */
177 init.id = "auo_k1900fb";
178 init.board = board;
179 init.update_partial = auok1900fb_dpy_update_pages;
180 init.update_all = auok1900fb_dpy_update;
181 init.need_refresh = auok1900fb_need_refresh;
182 init.init = auok1900_init;
183
184 return auok190x_common_probe(pdev, &init);
185}
186
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800187static int auok1900fb_remove(struct platform_device *pdev)
Heiko Stübner96b1d502012-04-28 12:21:12 +0200188{
189 return auok190x_common_remove(pdev);
190}
191
192static struct platform_driver auok1900fb_driver = {
193 .probe = auok1900fb_probe,
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800194 .remove = auok1900fb_remove,
Heiko Stübner96b1d502012-04-28 12:21:12 +0200195 .driver = {
196 .owner = THIS_MODULE,
197 .name = "auo_k1900fb",
198 .pm = &auok190x_pm,
199 },
200};
201module_platform_driver(auok1900fb_driver);
202
203MODULE_DESCRIPTION("framebuffer driver for the AUO-K1900 EPD controller");
204MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
205MODULE_LICENSE("GPL");