1/*
2 * Custom FB driver for tinylcd.com display
3 *
4 * Copyright (C) 2013 Noralf Tronnes
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25
26#include "fbtft.h"
27
28#define DRVNAME		"fb_tinylcd"
29#define WIDTH		320
30#define HEIGHT		480
31
32
33static int init_display(struct fbtft_par *par)
34{
35	fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
36
37	par->fbtftops.reset(par);
38
39	write_reg(par, 0xB0, 0x80);
40	write_reg(par, 0xC0, 0x0A, 0x0A);
41	write_reg(par, 0xC1, 0x45, 0x07);
42	write_reg(par, 0xC2, 0x33);
43	write_reg(par, 0xC5, 0x00, 0x42, 0x80);
44	write_reg(par, 0xB1, 0xD0, 0x11);
45	write_reg(par, 0xB4, 0x02);
46	write_reg(par, 0xB6, 0x00, 0x22, 0x3B);
47	write_reg(par, 0xB7, 0x07);
48	write_reg(par, 0x36, 0x58);
49	write_reg(par, 0xF0, 0x36, 0xA5, 0xD3);
50	write_reg(par, 0xE5, 0x80);
51	write_reg(par, 0xE5, 0x01);
52	write_reg(par, 0xB3, 0x00);
53	write_reg(par, 0xE5, 0x00);
54	write_reg(par, 0xF0, 0x36, 0xA5, 0x53);
55	write_reg(par, 0xE0, 0x00, 0x35, 0x33, 0x00, 0x00, 0x00,
56	                     0x00, 0x35, 0x33, 0x00, 0x00, 0x00);
57	write_reg(par, 0x3A, 0x55);
58	write_reg(par, 0x11);
59	udelay(250);
60	write_reg(par, 0x29);
61
62	return 0;
63}
64
65static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
66{
67	fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
68		"%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
69
70	/* Column address */
71	write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
72
73	/* Row address */
74	write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
75
76	/* Memory write */
77	write_reg(par, 0x2C);
78}
79
80static int set_var(struct fbtft_par *par)
81{
82	fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
83
84	switch (par->info->var.rotate) {
85	case 270:
86		write_reg(par, 0xB6, 0x00, 0x02, 0x3B);
87		write_reg(par, 0x36, 0x28);
88		break;
89	case 180:
90		write_reg(par, 0xB6, 0x00, 0x22, 0x3B);
91		write_reg(par, 0x36, 0x58);
92		break;
93	case 90:
94		write_reg(par, 0xB6, 0x00, 0x22, 0x3B);
95		write_reg(par, 0x36, 0x38);
96		break;
97	default:
98		write_reg(par, 0xB6, 0x00, 0x22, 0x3B);
99		write_reg(par, 0x36, 0x08);
100		break;
101	}
102
103	return 0;
104}
105
106
107static struct fbtft_display display = {
108	.regwidth = 8,
109	.width = WIDTH,
110	.height = HEIGHT,
111	.fbtftops = {
112		.init_display = init_display,
113		.set_addr_win = set_addr_win,
114		.set_var = set_var,
115	},
116};
117FBTFT_REGISTER_DRIVER(DRVNAME, "neosec,tinylcd", &display);
118
119MODULE_ALIAS("spi:" DRVNAME);
120MODULE_ALIAS("spi:tinylcd");
121
122MODULE_DESCRIPTION("Custom FB driver for tinylcd.com display");
123MODULE_AUTHOR("Noralf Tronnes");
124MODULE_LICENSE("GPL");
125