staging: fbtft: fix Macros with complex values should be enclosed in parentheses
[deliverable/linux.git] / drivers / staging / fbtft / fb_pcd8544.c
1 /*
2 * FB driver for the PCD8544 LCD Controller
3 *
4 * The display is monochrome and the video memory is RGB565.
5 * Any pixel value except 0 turns the pixel on.
6 *
7 * Copyright (C) 2013 Noralf Tronnes
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/gpio.h>
28 #include <linux/spi/spi.h>
29 #include <linux/delay.h>
30
31 #include "fbtft.h"
32
33 #define DRVNAME "fb_pcd8544"
34 #define WIDTH 84
35 #define HEIGHT 48
36 #define TXBUFLEN (84*6)
37 #define DEFAULT_GAMMA "40" /* gamma is used to control contrast in this driver */
38
39 static unsigned tc = 0;
40 module_param(tc, uint, 0);
41 MODULE_PARM_DESC(tc, "TC[1:0] Temperature coefficient: 0-3 (default: 0)");
42
43 static unsigned bs = 4;
44 module_param(bs, uint, 0);
45 MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)");
46
47
48 static int init_display(struct fbtft_par *par)
49 {
50 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
51
52 par->fbtftops.reset(par);
53
54 /* Function set */
55 write_reg(par, 0x21); /* 5:1 1
56 2:0 PD - Powerdown control: chip is active
57 1:0 V - Entry mode: horizontal addressing
58 0:1 H - Extended instruction set control: extended
59 */
60
61 /* H=1 Temperature control */
62 write_reg(par, 0x04 | (tc & 0x3)); /*
63 2:1 1
64 1:x TC1 - Temperature Coefficient: 0x10
65 0:x TC0
66 */
67
68 /* H=1 Bias system */
69 write_reg(par, 0x10 | (bs & 0x7)); /*
70 4:1 1
71 3:0 0
72 2:x BS2 - Bias System
73 1:x BS1
74 0:x BS0
75 */
76
77 /* Function set */
78 write_reg(par, 0x22); /* 5:1 1
79 2:0 PD - Powerdown control: chip is active
80 1:1 V - Entry mode: vertical addressing
81 0:0 H - Extended instruction set control: basic
82 */
83
84 /* H=0 Display control */
85 write_reg(par, 0x08 | 4); /*
86 3:1 1
87 2:1 D - DE: 10=normal mode
88 1:0 0
89 0:0 E
90 */
91
92 return 0;
93 }
94
95 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
96 {
97 fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
98
99 /* H=0 Set X address of RAM */
100 write_reg(par, 0x80); /* 7:1 1
101 6-0: X[6:0] - 0x00
102 */
103
104 /* H=0 Set Y address of RAM */
105 write_reg(par, 0x40); /* 7:0 0
106 6:1 1
107 2-0: Y[2:0] - 0x0
108 */
109 }
110
111 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
112 {
113 u16 *vmem16 = (u16 *)par->info->screen_base;
114 u8 *buf = par->txbuf.buf;
115 int x, y, i;
116 int ret = 0;
117
118 fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
119
120 for (x = 0; x < 84; x++) {
121 for (y = 0; y < 6; y++) {
122 *buf = 0x00;
123 for (i = 0; i < 8; i++) {
124 *buf |= (vmem16[(y*8+i)*84+x] ? 1 : 0) << i;
125 }
126 buf++;
127 }
128 }
129
130 /* Write data */
131 gpio_set_value(par->gpio.dc, 1);
132 ret = par->fbtftops.write(par, par->txbuf.buf, 6*84);
133 if (ret < 0)
134 dev_err(par->info->device, "%s: write failed and returned: %d\n", __func__, ret);
135
136 return ret;
137 }
138
139 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
140 {
141 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
142
143 /* apply mask */
144 curves[0] &= 0x7F;
145
146 write_reg(par, 0x23); /* turn on extended instruction set */
147 write_reg(par, 0x80 | curves[0]);
148 write_reg(par, 0x22); /* turn off extended instruction set */
149
150 return 0;
151 }
152
153
154 static struct fbtft_display display = {
155 .regwidth = 8,
156 .width = WIDTH,
157 .height = HEIGHT,
158 .txbuflen = TXBUFLEN,
159 .gamma_num = 1,
160 .gamma_len = 1,
161 .gamma = DEFAULT_GAMMA,
162 .fbtftops = {
163 .init_display = init_display,
164 .set_addr_win = set_addr_win,
165 .write_vmem = write_vmem,
166 .set_gamma = set_gamma,
167 },
168 .backlight = 1,
169 };
170 FBTFT_REGISTER_DRIVER(DRVNAME, "philips,pdc8544", &display);
171
172 MODULE_ALIAS("spi:" DRVNAME);
173 MODULE_ALIAS("spi:pdc8544");
174
175 MODULE_DESCRIPTION("FB driver for the PCD8544 LCD Controller");
176 MODULE_AUTHOR("Noralf Tronnes");
177 MODULE_LICENSE("GPL");
This page took 0.035392 seconds and 5 git commands to generate.