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
17#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/delay.h>
21
22#include "fbtft.h"
23
24#define DRVNAME		"fb_tinylcd"
25#define WIDTH		320
26#define HEIGHT		480
27
28static int init_display(struct fbtft_par *par)
29{
30	par->fbtftops.reset(par);
31
32	write_reg(par, 0xB0, 0x80);
33	write_reg(par, 0xC0, 0x0A, 0x0A);
34	write_reg(par, 0xC1, 0x45, 0x07);
35	write_reg(par, 0xC2, 0x33);
36	write_reg(par, 0xC5, 0x00, 0x42, 0x80);
37	write_reg(par, 0xB1, 0xD0, 0x11);
38	write_reg(par, 0xB4, 0x02);
39	write_reg(par, 0xB6, 0x00, 0x22, 0x3B);
40	write_reg(par, 0xB7, 0x07);
41	write_reg(par, 0x36, 0x58);
42	write_reg(par, 0xF0, 0x36, 0xA5, 0xD3);
43	write_reg(par, 0xE5, 0x80);
44	write_reg(par, 0xE5, 0x01);
45	write_reg(par, 0xB3, 0x00);
46	write_reg(par, 0xE5, 0x00);
47	write_reg(par, 0xF0, 0x36, 0xA5, 0x53);
48	write_reg(par, 0xE0, 0x00, 0x35, 0x33, 0x00, 0x00, 0x00,
49			     0x00, 0x35, 0x33, 0x00, 0x00, 0x00);
50	write_reg(par, 0x3A, 0x55);
51	write_reg(par, 0x11);
52	udelay(250);
53	write_reg(par, 0x29);
54
55	return 0;
56}
57
58static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
59{
60	/* Column address */
61	write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
62
63	/* Row address */
64	write_reg(par, 0x2B, ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
65
66	/* Memory write */
67	write_reg(par, 0x2C);
68}
69
70static int set_var(struct fbtft_par *par)
71{
72	switch (par->info->var.rotate) {
73	case 270:
74		write_reg(par, 0xB6, 0x00, 0x02, 0x3B);
75		write_reg(par, 0x36, 0x28);
76		break;
77	case 180:
78		write_reg(par, 0xB6, 0x00, 0x22, 0x3B);
79		write_reg(par, 0x36, 0x58);
80		break;
81	case 90:
82		write_reg(par, 0xB6, 0x00, 0x22, 0x3B);
83		write_reg(par, 0x36, 0x38);
84		break;
85	default:
86		write_reg(par, 0xB6, 0x00, 0x22, 0x3B);
87		write_reg(par, 0x36, 0x08);
88		break;
89	}
90
91	return 0;
92}
93
94static struct fbtft_display display = {
95	.regwidth = 8,
96	.width = WIDTH,
97	.height = HEIGHT,
98	.fbtftops = {
99		.init_display = init_display,
100		.set_addr_win = set_addr_win,
101		.set_var = set_var,
102	},
103};
104
105FBTFT_REGISTER_DRIVER(DRVNAME, "neosec,tinylcd", &display);
106
107MODULE_ALIAS("spi:" DRVNAME);
108MODULE_ALIAS("spi:tinylcd");
109
110MODULE_DESCRIPTION("Custom FB driver for tinylcd.com display");
111MODULE_AUTHOR("Noralf Tronnes");
112MODULE_LICENSE("GPL");
113