aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnatolij Gustschin <agust@denx.de>2011-05-24 09:19:48 -0400
committerAnatolij Gustschin <agust@denx.de>2011-05-24 10:28:52 -0400
commitf8a6b1f44833a4eb4c323b8b71fc592646212090 (patch)
tree99b10399dbdc7f817c51bedd55efed943aeb555b
parent12ed0c4baa4144ab3560ae793b5120316d74c0fe (diff)
video: mb862xx: add support for controller's I2C bus adapter
Add adapter driver for I2C adapter in Coral-P(A)/Lime GDCs. So we can easily access devices on controller's I2C bus using i2c-dev interface. Signed-off-by: Anatolij Gustschin <agust@denx.de>
-rw-r--r--drivers/video/Kconfig9
-rw-r--r--drivers/video/mb862xx/Makefile5
-rw-r--r--drivers/video/mb862xx/mb862xx-i2c.c177
-rw-r--r--drivers/video/mb862xx/mb862xx_reg.h21
-rw-r--r--drivers/video/mb862xx/mb862xxfb.h9
-rw-r--r--drivers/video/mb862xx/mb862xxfbdrv.c (renamed from drivers/video/mb862xx/mb862xxfb.c)4
6 files changed, 224 insertions, 1 deletions
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 7326962565ce..549b960667c8 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -2294,6 +2294,15 @@ config FB_MB862XX_LIME
2294 2294
2295endchoice 2295endchoice
2296 2296
2297config FB_MB862XX_I2C
2298 bool "Support I2C bus on MB862XX GDC"
2299 depends on FB_MB862XX && I2C
2300 default y
2301 help
2302 Selecting this option adds Coral-P(A)/Lime GDC I2C bus adapter
2303 driver to support accessing I2C devices on controller's I2C bus.
2304 These are usually some video decoder chips.
2305
2297config FB_EP93XX 2306config FB_EP93XX
2298 tristate "EP93XX frame buffer support" 2307 tristate "EP93XX frame buffer support"
2299 depends on FB && ARCH_EP93XX 2308 depends on FB && ARCH_EP93XX
diff --git a/drivers/video/mb862xx/Makefile b/drivers/video/mb862xx/Makefile
index d7777714166b..5707ed0e31a7 100644
--- a/drivers/video/mb862xx/Makefile
+++ b/drivers/video/mb862xx/Makefile
@@ -2,4 +2,7 @@
2# Makefile for the MB862xx framebuffer driver 2# Makefile for the MB862xx framebuffer driver
3# 3#
4 4
5obj-$(CONFIG_FB_MB862XX) := mb862xxfb.o mb862xxfb_accel.o 5obj-$(CONFIG_FB_MB862XX) += mb862xxfb.o
6
7mb862xxfb-y := mb862xxfbdrv.o mb862xxfb_accel.o
8mb862xxfb-$(CONFIG_FB_MB862XX_I2C) += mb862xx-i2c.o
diff --git a/drivers/video/mb862xx/mb862xx-i2c.c b/drivers/video/mb862xx/mb862xx-i2c.c
new file mode 100644
index 000000000000..cb77d3b4657d
--- /dev/null
+++ b/drivers/video/mb862xx/mb862xx-i2c.c
@@ -0,0 +1,177 @@
1/*
2 * Coral-P(A)/Lime I2C adapter driver
3 *
4 * (C) 2011 DENX Software Engineering, Anatolij Gustschin <agust@denx.de>
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 version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/fb.h>
13#include <linux/i2c.h>
14#include <linux/io.h>
15
16#include "mb862xxfb.h"
17#include "mb862xx_reg.h"
18
19static int mb862xx_i2c_wait_event(struct i2c_adapter *adap)
20{
21 struct mb862xxfb_par *par = adap->algo_data;
22 u32 reg;
23
24 do {
25 udelay(1);
26 reg = inreg(i2c, GC_I2C_BCR);
27 if (reg & (I2C_INT | I2C_BER))
28 break;
29 } while (1);
30
31 return (reg & I2C_BER) ? 0 : 1;
32}
33
34static int mb862xx_i2c_do_address(struct i2c_adapter *adap, int addr)
35{
36 struct mb862xxfb_par *par = adap->algo_data;
37
38 outreg(i2c, GC_I2C_DAR, addr);
39 outreg(i2c, GC_I2C_CCR, I2C_CLOCK_AND_ENABLE);
40 outreg(i2c, GC_I2C_BCR, par->i2c_rs ? I2C_REPEATED_START : I2C_START);
41 if (!mb862xx_i2c_wait_event(adap))
42 return -EIO;
43 par->i2c_rs = !(inreg(i2c, GC_I2C_BSR) & I2C_LRB);
44 return par->i2c_rs;
45}
46
47static int mb862xx_i2c_write_byte(struct i2c_adapter *adap, u8 byte)
48{
49 struct mb862xxfb_par *par = adap->algo_data;
50
51 outreg(i2c, GC_I2C_DAR, byte);
52 outreg(i2c, GC_I2C_BCR, I2C_START);
53 if (!mb862xx_i2c_wait_event(adap))
54 return -EIO;
55 return !(inreg(i2c, GC_I2C_BSR) & I2C_LRB);
56}
57
58static int mb862xx_i2c_read_byte(struct i2c_adapter *adap, u8 *byte, int last)
59{
60 struct mb862xxfb_par *par = adap->algo_data;
61
62 outreg(i2c, GC_I2C_BCR, I2C_START | (last ? 0 : I2C_ACK));
63 if (!mb862xx_i2c_wait_event(adap))
64 return 0;
65 *byte = inreg(i2c, GC_I2C_DAR);
66 return 1;
67}
68
69void mb862xx_i2c_stop(struct i2c_adapter *adap)
70{
71 struct mb862xxfb_par *par = adap->algo_data;
72
73 outreg(i2c, GC_I2C_BCR, I2C_STOP);
74 outreg(i2c, GC_I2C_CCR, I2C_DISABLE);
75 par->i2c_rs = 0;
76}
77
78static int mb862xx_i2c_read(struct i2c_adapter *adap, struct i2c_msg *m)
79{
80 int i, ret = 0;
81 int last = m->len - 1;
82
83 for (i = 0; i < m->len; i++) {
84 if (!mb862xx_i2c_read_byte(adap, &m->buf[i], i == last)) {
85 ret = -EIO;
86 break;
87 }
88 }
89 return ret;
90}
91
92static int mb862xx_i2c_write(struct i2c_adapter *adap, struct i2c_msg *m)
93{
94 int i, ret = 0;
95
96 for (i = 0; i < m->len; i++) {
97 if (!mb862xx_i2c_write_byte(adap, m->buf[i])) {
98 ret = -EIO;
99 break;
100 }
101 }
102 return ret;
103}
104
105static int mb862xx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
106 int num)
107{
108 struct mb862xxfb_par *par = adap->algo_data;
109 struct i2c_msg *m;
110 int addr;
111 int i = 0, err = 0;
112
113 dev_dbg(par->dev, "%s: %d msgs\n", __func__, num);
114
115 for (i = 0; i < num; i++) {
116 m = &msgs[i];
117 if (!m->len) {
118 dev_dbg(par->dev, "%s: null msgs\n", __func__);
119 continue;
120 }
121 addr = m->addr;
122 if (m->flags & I2C_M_RD)
123 addr |= 1;
124
125 err = mb862xx_i2c_do_address(adap, addr);
126 if (err < 0)
127 break;
128 if (m->flags & I2C_M_RD)
129 err = mb862xx_i2c_read(adap, m);
130 else
131 err = mb862xx_i2c_write(adap, m);
132 }
133
134 if (i)
135 mb862xx_i2c_stop(adap);
136
137 return (err < 0) ? err : i;
138}
139
140static u32 mb862xx_func(struct i2c_adapter *adap)
141{
142 return I2C_FUNC_SMBUS_BYTE_DATA;
143}
144
145static const struct i2c_algorithm mb862xx_algo = {
146 .master_xfer = mb862xx_xfer,
147 .functionality = mb862xx_func,
148};
149
150static struct i2c_adapter mb862xx_i2c_adapter = {
151 .name = "MB862xx I2C adapter",
152 .algo = &mb862xx_algo,
153 .owner = THIS_MODULE,
154};
155
156int mb862xx_i2c_init(struct mb862xxfb_par *par)
157{
158 int ret;
159
160 mb862xx_i2c_adapter.algo_data = par;
161 par->adap = &mb862xx_i2c_adapter;
162
163 ret = i2c_add_adapter(par->adap);
164 if (ret < 0) {
165 dev_err(par->dev, "failed to add %s\n",
166 mb862xx_i2c_adapter.name);
167 }
168 return ret;
169}
170
171void mb862xx_i2c_exit(struct mb862xxfb_par *par)
172{
173 if (par->adap) {
174 i2c_del_adapter(par->adap);
175 par->adap = NULL;
176 }
177}
diff --git a/drivers/video/mb862xx/mb862xx_reg.h b/drivers/video/mb862xx/mb862xx_reg.h
index 737fc011caff..5784b018f15d 100644
--- a/drivers/video/mb862xx/mb862xx_reg.h
+++ b/drivers/video/mb862xx/mb862xx_reg.h
@@ -80,6 +80,27 @@
80 80
81#define GC_DISP_REFCLK_400 400 81#define GC_DISP_REFCLK_400 400
82 82
83/* I2C */
84#define GC_I2C_BSR 0x00000000 /* BSR */
85#define GC_I2C_BCR 0x00000004 /* BCR */
86#define GC_I2C_CCR 0x00000008 /* CCR */
87#define GC_I2C_ADR 0x0000000C /* ADR */
88#define GC_I2C_DAR 0x00000010 /* DAR */
89
90#define I2C_DISABLE 0x00000000
91#define I2C_STOP 0x00000000
92#define I2C_START 0x00000010
93#define I2C_REPEATED_START 0x00000030
94#define I2C_CLOCK_AND_ENABLE 0x0000003f
95#define I2C_READY 0x01
96#define I2C_INT 0x01
97#define I2C_INTE 0x02
98#define I2C_ACK 0x08
99#define I2C_BER 0x80
100#define I2C_BEIE 0x40
101#define I2C_TRX 0x80
102#define I2C_LRB 0x10
103
83/* Carmine specific */ 104/* Carmine specific */
84#define MB86297_DRAW_BASE 0x00020000 105#define MB86297_DRAW_BASE 0x00020000
85#define MB86297_DISP0_BASE 0x00100000 106#define MB86297_DISP0_BASE 0x00100000
diff --git a/drivers/video/mb862xx/mb862xxfb.h b/drivers/video/mb862xx/mb862xxfb.h
index d7e7cb76bbf2..d5dd7d9ec0cd 100644
--- a/drivers/video/mb862xx/mb862xxfb.h
+++ b/drivers/video/mb862xx/mb862xxfb.h
@@ -57,11 +57,20 @@ struct mb862xxfb_par {
57 unsigned int refclk; /* disp. reference clock */ 57 unsigned int refclk; /* disp. reference clock */
58 struct mb862xx_gc_mode *gc_mode; /* GDC mode init data */ 58 struct mb862xx_gc_mode *gc_mode; /* GDC mode init data */
59 int pre_init; /* don't init display if 1 */ 59 int pre_init; /* don't init display if 1 */
60 struct i2c_adapter *adap; /* GDC I2C bus adapter */
61 int i2c_rs;
60 62
61 u32 pseudo_palette[16]; 63 u32 pseudo_palette[16];
62}; 64};
63 65
64extern void mb862xxfb_init_accel(struct fb_info *info, int xres); 66extern void mb862xxfb_init_accel(struct fb_info *info, int xres);
67#ifdef CONFIG_FB_MB862XX_I2C
68extern int mb862xx_i2c_init(struct mb862xxfb_par *par);
69extern void mb862xx_i2c_exit(struct mb862xxfb_par *par);
70#else
71static inline int mb862xx_i2c_init(struct mb862xxfb_par *par) { return 0; }
72static inline void mb862xx_i2c_exit(struct mb862xxfb_par *par) { }
73#endif
65 74
66#if defined(CONFIG_FB_MB862XX_LIME) && defined(CONFIG_FB_MB862XX_PCI_GDC) 75#if defined(CONFIG_FB_MB862XX_LIME) && defined(CONFIG_FB_MB862XX_PCI_GDC)
67#error "Select Lime GDC or CoralP/Carmine support, but not both together" 76#error "Select Lime GDC or CoralP/Carmine support, but not both together"
diff --git a/drivers/video/mb862xx/mb862xxfb.c b/drivers/video/mb862xx/mb862xxfbdrv.c
index ffb6a2c36d3c..0cc20b4fbcb5 100644
--- a/drivers/video/mb862xx/mb862xxfb.c
+++ b/drivers/video/mb862xx/mb862xxfbdrv.c
@@ -772,6 +772,8 @@ static int coralp_init(struct mb862xxfb_par *par)
772 } else { 772 } else {
773 return -ENODEV; 773 return -ENODEV;
774 } 774 }
775
776 mb862xx_i2c_init(par);
775 return 0; 777 return 0;
776} 778}
777 779
@@ -1029,6 +1031,8 @@ static void __devexit mb862xx_pci_remove(struct pci_dev *pdev)
1029 outreg(host, GC_IMASK, 0); 1031 outreg(host, GC_IMASK, 0);
1030 } 1032 }
1031 1033
1034 mb862xx_i2c_exit(par);
1035
1032 device_remove_file(&pdev->dev, &dev_attr_dispregs); 1036 device_remove_file(&pdev->dev, &dev_attr_dispregs);
1033 1037
1034 pci_set_drvdata(pdev, NULL); 1038 pci_set_drvdata(pdev, NULL);