This source file includes following definitions.
- get_clock
- get_data
- set_clock
- set_data
- psb_intel_i2c_create
- psb_intel_i2c_destroy
1
2
3
4
5
6
7
8
9 #include <linux/delay.h>
10 #include <linux/export.h>
11 #include <linux/i2c-algo-bit.h>
12 #include <linux/i2c.h>
13
14 #include "psb_drv.h"
15 #include "psb_intel_reg.h"
16
17
18
19
20
21 #define I2C_RISEFALL_TIME 20
22
23 static int get_clock(void *data)
24 {
25 struct psb_intel_i2c_chan *chan = data;
26 struct drm_device *dev = chan->drm_dev;
27 u32 val;
28
29 val = REG_READ(chan->reg);
30 return (val & GPIO_CLOCK_VAL_IN) != 0;
31 }
32
33 static int get_data(void *data)
34 {
35 struct psb_intel_i2c_chan *chan = data;
36 struct drm_device *dev = chan->drm_dev;
37 u32 val;
38
39 val = REG_READ(chan->reg);
40 return (val & GPIO_DATA_VAL_IN) != 0;
41 }
42
43 static void set_clock(void *data, int state_high)
44 {
45 struct psb_intel_i2c_chan *chan = data;
46 struct drm_device *dev = chan->drm_dev;
47 u32 reserved = 0, clock_bits;
48
49
50 reserved =
51 REG_READ(chan->reg) & (GPIO_DATA_PULLUP_DISABLE |
52 GPIO_CLOCK_PULLUP_DISABLE);
53
54 if (state_high)
55 clock_bits = GPIO_CLOCK_DIR_IN | GPIO_CLOCK_DIR_MASK;
56 else
57 clock_bits = GPIO_CLOCK_DIR_OUT | GPIO_CLOCK_DIR_MASK |
58 GPIO_CLOCK_VAL_MASK;
59 REG_WRITE(chan->reg, reserved | clock_bits);
60 udelay(I2C_RISEFALL_TIME);
61 }
62
63 static void set_data(void *data, int state_high)
64 {
65 struct psb_intel_i2c_chan *chan = data;
66 struct drm_device *dev = chan->drm_dev;
67 u32 reserved = 0, data_bits;
68
69
70 reserved =
71 REG_READ(chan->reg) & (GPIO_DATA_PULLUP_DISABLE |
72 GPIO_CLOCK_PULLUP_DISABLE);
73
74 if (state_high)
75 data_bits = GPIO_DATA_DIR_IN | GPIO_DATA_DIR_MASK;
76 else
77 data_bits =
78 GPIO_DATA_DIR_OUT | GPIO_DATA_DIR_MASK |
79 GPIO_DATA_VAL_MASK;
80
81 REG_WRITE(chan->reg, reserved | data_bits);
82 udelay(I2C_RISEFALL_TIME);
83 }
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 struct psb_intel_i2c_chan *psb_intel_i2c_create(struct drm_device *dev,
107 const u32 reg, const char *name)
108 {
109 struct psb_intel_i2c_chan *chan;
110
111 chan = kzalloc(sizeof(struct psb_intel_i2c_chan), GFP_KERNEL);
112 if (!chan)
113 goto out_free;
114
115 chan->drm_dev = dev;
116 chan->reg = reg;
117 snprintf(chan->adapter.name, I2C_NAME_SIZE, "intel drm %s", name);
118 chan->adapter.owner = THIS_MODULE;
119 chan->adapter.algo_data = &chan->algo;
120 chan->adapter.dev.parent = &dev->pdev->dev;
121 chan->algo.setsda = set_data;
122 chan->algo.setscl = set_clock;
123 chan->algo.getsda = get_data;
124 chan->algo.getscl = get_clock;
125 chan->algo.udelay = 20;
126 chan->algo.timeout = usecs_to_jiffies(2200);
127 chan->algo.data = chan;
128
129 i2c_set_adapdata(&chan->adapter, chan);
130
131 if (i2c_bit_add_bus(&chan->adapter))
132 goto out_free;
133
134
135 set_data(chan, 1);
136 set_clock(chan, 1);
137 udelay(20);
138
139 return chan;
140
141 out_free:
142 kfree(chan);
143 return NULL;
144 }
145
146
147
148
149
150
151
152 void psb_intel_i2c_destroy(struct psb_intel_i2c_chan *chan)
153 {
154 if (!chan)
155 return;
156
157 i2c_del_adapter(&chan->adapter);
158 kfree(chan);
159 }