aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/am200epd.c
blob: 51e26c1f5e8b747310cc5b6e2aff47c5661336a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
 * linux/drivers/video/am200epd.c -- Platform device for AM200 EPD kit
 *
 * Copyright (C) 2008, Jaya Kumar
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License. See the file COPYING in the main directory of this archive for
 * more details.
 *
 * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
 *
 * This work was made possible by help and equipment support from E-Ink
 * Corporation. http://support.eink.com/community
 *
 * This driver is written to be used with the Metronome display controller.
 * on the AM200 EPD prototype kit/development kit with an E-Ink 800x600
 * Vizplex EPD on a Gumstix board using the Lyre interface board.
 *
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/fb.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/list.h>
#include <linux/uaccess.h>
#include <linux/irq.h>

#include <video/metronomefb.h>

#include <asm/arch/pxa-regs.h>

/* register offsets for gpio control */
#define LED_GPIO_PIN 51
#define STDBY_GPIO_PIN 48
#define RST_GPIO_PIN 49
#define RDY_GPIO_PIN 32
#define ERR_GPIO_PIN 17
#define PCBPWR_GPIO_PIN 16

#define AF_SEL_GPIO_N 0x3
#define GAFR0_U_OFFSET(pin) ((pin - 16) * 2)
#define GAFR1_L_OFFSET(pin) ((pin - 32) * 2)
#define GAFR1_U_OFFSET(pin) ((pin - 48) * 2)
#define GPDR1_OFFSET(pin) (pin - 32)
#define GPCR1_OFFSET(pin) (pin - 32)
#define GPSR1_OFFSET(pin) (pin - 32)
#define GPCR0_OFFSET(pin) (pin)
#define GPSR0_OFFSET(pin) (pin)

static void am200_set_gpio_output(int pin, int val)
{
	u8 index;

	index = pin >> 4;

	switch (index) {
	case 1:
		if (val)
			GPSR0 |= (1 << GPSR0_OFFSET(pin));
		else
			GPCR0 |= (1 << GPCR0_OFFSET(pin));
		break;
	case 2:
		break;
	case 3:
		if (val)
			GPSR1 |= (1 << GPSR1_OFFSET(pin));
		else
			GPCR1 |= (1 << GPCR1_OFFSET(pin));
		break;
	default:
		printk(KERN_ERR "unimplemented\n");
	}
}

static void __devinit am200_init_gpio_pin(int pin, int dir)
{
	u8 index;
	/* dir 0 is output, 1 is input
	- do 2 things here:
	- set gpio alternate function to standard gpio
	- set gpio direction to input or output  */

	index = pin >> 4;
	switch (index) {
	case 1:
		GAFR0_U &= ~(AF_SEL_GPIO_N << GAFR0_U_OFFSET(pin));

		if (dir)
			GPDR0 &= ~(1 << pin);
		else
			GPDR0 |= (1 << pin);
		break;
	case 2:
		GAFR1_L &= ~(AF_SEL_GPIO_N << GAFR1_L_OFFSET(pin));

		if (dir)
			GPDR1 &= ~(1 << GPDR1_OFFSET(pin));
		else
			GPDR1 |= (1 << GPDR1_OFFSET(pin));
		break;
	case 3:
		GAFR1_U &= ~(AF_SEL_GPIO_N << GAFR1_U_OFFSET(pin));

		if (dir)
			GPDR1 &= ~(1 << GPDR1_OFFSET(pin));
		else
			GPDR1 |= (1 << GPDR1_OFFSET(pin));
		break;
	default:
		printk(KERN_ERR "unimplemented\n");
	}
}

static void am200_init_gpio_regs(struct metronomefb_par *par)
{
	am200_init_gpio_pin(LED_GPIO_PIN, 0);
	am200_set_gpio_output(LED_GPIO_PIN, 0);

	am200_init_gpio_pin(STDBY_GPIO_PIN, 0);
	am200_set_gpio_output(STDBY_GPIO_PIN, 0);

	am200_init_gpio_pin(RST_GPIO_PIN, 0);
	am200_set_gpio_output(RST_GPIO_PIN, 0);

	am200_init_gpio_pin(RDY_GPIO_PIN, 1);

	am200_init_gpio_pin(ERR_GPIO_PIN, 1);

	am200_init_gpio_pin(PCBPWR_GPIO_PIN, 0);
	am200_set_gpio_output(PCBPWR_GPIO_PIN, 0);
}

static void am200_disable_lcd_controller(struct metronomefb_par *par)
{
	LCSR = 0xffffffff;	/* Clear LCD Status Register */
	LCCR0 |= LCCR0_DIS;	/* Disable LCD Controller */

	/* we reset and just wait for things to settle */
	msleep(200);
}

static void am200_enable_lcd_controller(struct metronomefb_par *par)
{
	LCSR = 0xffffffff;
	FDADR0 = par->metromem_desc_dma;
	LCCR0 |= LCCR0_ENB;
}

static void am200_init_lcdc_regs(struct metronomefb_par *par)
{
	/* here we do:
	- disable the lcd controller
	- setup lcd control registers
	- setup dma descriptor
	- reenable lcd controller
	*/

	/* disable the lcd controller */
	am200_disable_lcd_controller(par);

	/* setup lcd control registers */
	LCCR0 = LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM | LCCR0_PAS
		| LCCR0_QDM | LCCR0_BM | LCCR0_OUM;

	LCCR1 = (par->info->var.xres/2 - 1) /* pixels per line */
		| (27 << 10) /* hsync pulse width - 1 */
		| (33 << 16) /* eol pixel count */
		| (33 << 24); /* bol pixel count */

	LCCR2 = (par->info->var.yres - 1) /* lines per panel */
		| (24 << 10) /* vsync pulse width - 1 */
		| (2 << 16) /* eof pixel count */
		| (0 << 24); /* bof pixel count */

	LCCR3 = 2 /* pixel clock divisor */
		| (24 << 8) /* AC Bias pin freq */
		| LCCR3_16BPP /* BPP */
		| LCCR3_PCP;  /* PCP falling edge */

}

static void am200_post_dma_setup(struct metronomefb_par *par)
{
	par->metromem_desc->mFDADR0 = par->metromem_desc_dma;
	par->metromem_desc->mFSADR0 = par->metromem_dma;
	par->metromem_desc->mFIDR0 = 0;
	par->metromem_desc->mLDCMD0 = par->info->var.xres
					* par->info->var.yres;
	am200_enable_lcd_controller(par);
}

static void am200_free_irq(struct fb_info *info)
{
	free_irq(IRQ_GPIO(RDY_GPIO_PIN), info);
}

static irqreturn_t am200_handle_irq(int irq, void *dev_id)
{
	struct fb_info *info = dev_id;
	struct metronomefb_par *par = info->par;

	wake_up_interruptible(&par->waitq);
	return IRQ_HANDLED;
}

static int am200_setup_irq(struct fb_info *info)
{
	int retval;

	retval = request_irq(IRQ_GPIO(RDY_GPIO_PIN), am200_handle_irq,
				IRQF_DISABLED, "AM200", info);
	if (retval) {
		printk(KERN_ERR "am200epd: request_irq failed: %d\n", retval);
		return retval;
	}

	return set_irq_type(IRQ_GPIO(RDY_GPIO_PIN), IRQT_FALLING);
}

static void am200_set_rst(struct metronomefb_par *par, int state)
{
	am200_set_gpio_output(RST_GPIO_PIN, state);
}

static void am200_set_stdby(struct metronomefb_par *par, int state)
{
	am200_set_gpio_output(STDBY_GPIO_PIN, state);
}

static int am200_wait_event(struct metronomefb_par *par)
{
	return wait_event_timeout(par->waitq, (GPLR1 & 0x01), HZ);
}

static int am200_wait_event_intr(struct metronomefb_par *par)
{
	return wait_event_interruptible_timeout(par->waitq, (GPLR1 & 0x01), HZ);
}

static struct metronome_board am200_board = {
	.owner			= THIS_MODULE,
	.free_irq		= am200_free_irq,
	.setup_irq		= am200_setup_irq,
	.init_gpio_regs		= am200_init_gpio_regs,
	.init_lcdc_regs		= am200_init_lcdc_regs,
	.post_dma_setup		= am200_post_dma_setup,
	.set_rst		= am200_set_rst,
	.set_stdby		= am200_set_stdby,
	.met_wait_event		= am200_wait_event,
	.met_wait_event_intr	= am200_wait_event_intr,
};

static struct platform_device *am200_device;

static int __init am200_init(void)
{
	int ret;

	/* request our platform independent driver */
	request_module("metronomefb");

	am200_device = platform_device_alloc("metronomefb", -1);
	if (!am200_device)
		return -ENOMEM;

	platform_device_add_data(am200_device, &am200_board,
					sizeof(am200_board));

	/* this _add binds metronomefb to am200. metronomefb refcounts am200 */
	ret = platform_device_add(am200_device);

	if (ret)
		platform_device_put(am200_device);

	return ret;
}

static void __exit am200_exit(void)
{
	platform_device_unregister(am200_device);
}

module_init(am200_init);
module_exit(am200_exit);

MODULE_DESCRIPTION("board driver for am200 metronome epd kit");
MODULE_AUTHOR("Jaya Kumar");
MODULE_LICENSE("GPL");