Rev 1125 | Rev 1404 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1125 | Rev 1321 | ||
---|---|---|---|
Line 57... | Line 57... | ||
57 | 57 | ||
58 | return false; |
58 | return false; |
Line 59... | Line 59... | ||
59 | } |
59 | } |
60 | 60 | ||
61 | 61 | ||
- | 62 | void radeon_i2c_do_lock(struct radeon_i2c_chan *i2c, int lock_state) |
|
62 | void radeon_i2c_do_lock(struct radeon_connector *radeon_connector, int lock_state) |
63 | { |
63 | { |
- | |
Line 64... | Line 64... | ||
64 | struct radeon_device *rdev = radeon_connector->base.dev->dev_private; |
64 | struct radeon_device *rdev = i2c->dev->dev_private; |
65 | uint32_t temp; |
65 | struct radeon_i2c_bus_rec *rec = &i2c->rec; |
66 | struct radeon_i2c_bus_rec *rec = &radeon_connector->ddc_bus->rec; |
66 | uint32_t temp; |
67 | 67 | ||
- | 68 | /* RV410 appears to have a bug where the hw i2c in reset |
|
68 | /* RV410 appears to have a bug where the hw i2c in reset |
69 | * holds the i2c port in a bad state - switch hw i2c away before |
69 | * holds the i2c port in a bad state - switch hw i2c away before |
70 | * doing DDC - do this for all r200s/r300s/r400s for safety sake |
70 | * doing DDC - do this for all r200s/r300s/r400s for safety sake |
71 | */ |
71 | */ |
72 | if (rec->hw_capable) { |
72 | if ((rdev->family >= CHIP_R200) && !ASIC_IS_AVIVO(rdev)) { |
73 | if ((rdev->family >= CHIP_R200) && !ASIC_IS_AVIVO(rdev)) { |
73 | if (rec->a_clk_reg == RADEON_GPIO_MONID) { |
74 | if (rec->a_clk_reg == RADEON_GPIO_MONID) { |
74 | WREG32(RADEON_DVI_I2C_CNTL_0, (RADEON_I2C_SOFT_RST | |
75 | WREG32(RADEON_DVI_I2C_CNTL_0, (RADEON_I2C_SOFT_RST | |
75 | R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1))); |
76 | R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1))); |
76 | } else { |
77 | } else { |
77 | WREG32(RADEON_DVI_I2C_CNTL_0, (RADEON_I2C_SOFT_RST | |
78 | WREG32(RADEON_DVI_I2C_CNTL_0, (RADEON_I2C_SOFT_RST | |
- | 79 | R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3))); |
|
78 | R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3))); |
80 | } |
79 | } |
81 | } |
80 | } |
82 | } |
Line 81... | Line 83... | ||
81 | if (lock_state) { |
83 | |
82 | temp = RREG32(rec->a_clk_reg); |
- | |
83 | temp &= ~(rec->a_clk_mask); |
84 | /* clear the output pin values */ |
84 | WREG32(rec->a_clk_reg, temp); |
- | |
Line -... | Line 85... | ||
- | 85 | temp = RREG32(rec->a_clk_reg) & ~rec->a_clk_mask; |
|
- | 86 | WREG32(rec->a_clk_reg, temp); |
|
- | 87 | ||
- | 88 | temp = RREG32(rec->a_data_reg) & ~rec->a_data_mask; |
|
- | 89 | WREG32(rec->a_data_reg, temp); |
|
- | 90 | ||
- | 91 | /* set the pins to input */ |
|
- | 92 | temp = RREG32(rec->en_clk_reg) & ~rec->en_clk_mask; |
|
85 | 93 | WREG32(rec->en_clk_reg, temp); |
|
86 | temp = RREG32(rec->a_data_reg); |
94 | |
87 | temp &= ~(rec->a_data_mask); |
95 | temp = RREG32(rec->en_data_reg) & ~rec->en_data_mask; |
88 | WREG32(rec->a_data_reg, temp); |
96 | WREG32(rec->en_data_reg, temp); |
89 | } |
97 | |
Line 110... | Line 118... | ||
110 | struct radeon_i2c_chan *i2c = i2c_priv; |
118 | struct radeon_i2c_chan *i2c = i2c_priv; |
111 | struct radeon_device *rdev = i2c->dev->dev_private; |
119 | struct radeon_device *rdev = i2c->dev->dev_private; |
112 | struct radeon_i2c_bus_rec *rec = &i2c->rec; |
120 | struct radeon_i2c_bus_rec *rec = &i2c->rec; |
113 | uint32_t val; |
121 | uint32_t val; |
Line -... | Line 122... | ||
- | 122 | ||
114 | 123 | /* read the value off the pin */ |
|
115 | val = RREG32(rec->get_clk_reg); |
124 | val = RREG32(rec->y_clk_reg); |
Line 116... | Line 125... | ||
116 | val &= rec->get_clk_mask; |
125 | val &= rec->y_clk_mask; |
117 | 126 | ||
Line 124... | Line 133... | ||
124 | struct radeon_i2c_chan *i2c = i2c_priv; |
133 | struct radeon_i2c_chan *i2c = i2c_priv; |
125 | struct radeon_device *rdev = i2c->dev->dev_private; |
134 | struct radeon_device *rdev = i2c->dev->dev_private; |
126 | struct radeon_i2c_bus_rec *rec = &i2c->rec; |
135 | struct radeon_i2c_bus_rec *rec = &i2c->rec; |
127 | uint32_t val; |
136 | uint32_t val; |
Line -... | Line 137... | ||
- | 137 | ||
128 | 138 | /* read the value off the pin */ |
|
129 | val = RREG32(rec->get_data_reg); |
139 | val = RREG32(rec->y_data_reg); |
- | 140 | val &= rec->y_data_mask; |
|
130 | val &= rec->get_data_mask; |
141 | |
131 | return (val != 0); |
142 | return (val != 0); |
Line 132... | Line 143... | ||
132 | } |
143 | } |
133 | 144 | ||
134 | static void set_clock(void *i2c_priv, int clock) |
145 | static void set_clock(void *i2c_priv, int clock) |
135 | { |
146 | { |
136 | struct radeon_i2c_chan *i2c = i2c_priv; |
147 | struct radeon_i2c_chan *i2c = i2c_priv; |
137 | struct radeon_device *rdev = i2c->dev->dev_private; |
148 | struct radeon_device *rdev = i2c->dev->dev_private; |
Line -... | Line 149... | ||
- | 149 | struct radeon_i2c_bus_rec *rec = &i2c->rec; |
|
138 | struct radeon_i2c_bus_rec *rec = &i2c->rec; |
150 | uint32_t val; |
139 | uint32_t val; |
151 | |
140 | 152 | /* set pin direction */ |
|
141 | val = RREG32(rec->put_clk_reg) & (uint32_t)~(rec->put_clk_mask); |
153 | val = RREG32(rec->en_clk_reg) & ~rec->en_clk_mask; |
Line 142... | Line 154... | ||
142 | val |= clock ? 0 : rec->put_clk_mask; |
154 | val |= clock ? 0 : rec->en_clk_mask; |
143 | WREG32(rec->put_clk_reg, val); |
155 | WREG32(rec->en_clk_reg, val); |
144 | } |
156 | } |
145 | 157 | ||
146 | static void set_data(void *i2c_priv, int data) |
158 | static void set_data(void *i2c_priv, int data) |
147 | { |
159 | { |
Line -... | Line 160... | ||
- | 160 | struct radeon_i2c_chan *i2c = i2c_priv; |
|
148 | struct radeon_i2c_chan *i2c = i2c_priv; |
161 | struct radeon_device *rdev = i2c->dev->dev_private; |
149 | struct radeon_device *rdev = i2c->dev->dev_private; |
162 | struct radeon_i2c_bus_rec *rec = &i2c->rec; |
150 | struct radeon_i2c_bus_rec *rec = &i2c->rec; |
163 | uint32_t val; |
151 | uint32_t val; |
164 | |
Line 152... | Line 165... | ||
152 | 165 | /* set pin direction */ |
|
153 | val = RREG32(rec->put_data_reg) & (uint32_t)~(rec->put_data_mask); |
166 | val = RREG32(rec->en_data_reg) & ~rec->en_data_mask; |
154 | val |= data ? 0 : rec->put_data_mask; |
167 | val |= data ? 0 : rec->en_data_mask; |
Line 164... | Line 177... | ||
164 | 177 | ||
165 | i2c = kzalloc(sizeof(struct radeon_i2c_chan), GFP_KERNEL); |
178 | i2c = kzalloc(sizeof(struct radeon_i2c_chan), GFP_KERNEL); |
166 | if (i2c == NULL) |
179 | if (i2c == NULL) |
Line 167... | Line -... | ||
167 | return NULL; |
- | |
168 | - | ||
169 | // i2c->adapter.owner = THIS_MODULE; |
180 | return NULL; |
- | 181 | ||
170 | i2c->adapter.algo_data = &i2c->algo; |
182 | i2c->dev = dev; |
171 | i2c->dev = dev; |
183 | i2c->adapter.algo_data = &i2c->algo.bit; |
172 | i2c->algo.setsda = set_data; |
184 | i2c->algo.bit.setsda = set_data; |
173 | i2c->algo.setscl = set_clock; |
185 | i2c->algo.bit.setscl = set_clock; |
174 | i2c->algo.getsda = get_data; |
186 | i2c->algo.bit.getsda = get_data; |
175 | i2c->algo.getscl = get_clock; |
187 | i2c->algo.bit.getscl = get_clock; |
176 | i2c->algo.udelay = 20; |
188 | i2c->algo.bit.udelay = 20; |
177 | /* vesa says 2.2 ms is enough, 1 jiffy doesn't seem to always |
189 | /* vesa says 2.2 ms is enough, 1 jiffy doesn't seem to always |
178 | * make this, 2 jiffies is a lot more reliable */ |
190 | * make this, 2 jiffies is a lot more reliable */ |
179 | i2c->algo.timeout = 2; |
191 | i2c->algo.bit.timeout = 2; |
180 | i2c->algo.data = i2c; |
- | |
181 | i2c->rec = *rec; |
- | |
182 | // i2c_set_adapdata(&i2c->adapter, i2c); |
192 | i2c->algo.bit.data = i2c; |
183 | 193 | i2c->rec = *rec; |
|
184 | ret = i2c_bit_add_bus(&i2c->adapter); |
194 | ret = i2c_bit_add_bus(&i2c->adapter); |
185 | if (ret) { |
195 | if (ret) { |
186 | DRM_INFO("Failed to register i2c %s\n", name); |
196 | DRM_INFO("Failed to register i2c %s\n", name); |
Line 192... | Line 202... | ||
192 | kfree(i2c); |
202 | kfree(i2c); |
193 | return NULL; |
203 | return NULL; |
Line 194... | Line 204... | ||
194 | 204 | ||
Line -... | Line 205... | ||
- | 205 | } |
|
- | 206 | ||
- | 207 | struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev, |
|
- | 208 | struct radeon_i2c_bus_rec *rec, |
|
- | 209 | const char *name) |
|
- | 210 | { |
|
- | 211 | struct radeon_i2c_chan *i2c; |
|
- | 212 | int ret; |
|
- | 213 | ||
- | 214 | i2c = kzalloc(sizeof(struct radeon_i2c_chan), GFP_KERNEL); |
|
- | 215 | if (i2c == NULL) |
|
- | 216 | return NULL; |
|
- | 217 | ||
- | 218 | i2c->rec = *rec; |
|
- | 219 | i2c->adapter.owner = THIS_MODULE; |
|
- | 220 | i2c->dev = dev; |
|
- | 221 | i2c->adapter.algo_data = &i2c->algo.dp; |
|
- | 222 | i2c->algo.dp.aux_ch = radeon_dp_i2c_aux_ch; |
|
- | 223 | i2c->algo.dp.address = 0; |
|
- | 224 | ret = i2c_dp_aux_add_bus(&i2c->adapter); |
|
- | 225 | if (ret) { |
|
- | 226 | DRM_INFO("Failed to register i2c %s\n", name); |
|
- | 227 | goto out_free; |
|
- | 228 | } |
|
- | 229 | ||
- | 230 | return i2c; |
|
- | 231 | out_free: |
|
- | 232 | kfree(i2c); |
|
- | 233 | return NULL; |
|
- | 234 | ||
- | 235 | } |
|
195 | } |
236 | |
196 | 237 | ||
197 | void radeon_i2c_destroy(struct radeon_i2c_chan *i2c) |
238 | void radeon_i2c_destroy(struct radeon_i2c_chan *i2c) |
198 | { |
239 | { |
Line 199... | Line -... | ||
199 | if (!i2c) |
- | |
200 | return; |
240 | if (!i2c) |
201 | 241 | return; |
|
Line 202... | Line 242... | ||
202 | // i2c_del_adapter(&i2c->adapter); |
242 | |
203 | kfree(i2c); |
243 | kfree(i2c); |
204 | } |
244 | } |
205 | 245 | ||
- | 246 | struct drm_encoder *radeon_best_encoder(struct drm_connector *connector) |
|
- | 247 | { |
|
- | 248 | return NULL; |
|
- | 249 | } |
|
- | 250 | ||
- | 251 | void radeon_i2c_sw_get_byte(struct radeon_i2c_chan *i2c_bus, |
|
- | 252 | u8 slave_addr, |
|
- | 253 | u8 addr, |
|
- | 254 | u8 *val) |
|
- | 255 | { |
|
- | 256 | u8 out_buf[2]; |
|
- | 257 | u8 in_buf[2]; |
|
- | 258 | struct i2c_msg msgs[] = { |
|
- | 259 | { |
|
- | 260 | .addr = slave_addr, |
|
- | 261 | .flags = 0, |
|
- | 262 | .len = 1, |
|
- | 263 | .buf = out_buf, |
|
- | 264 | }, |
|
- | 265 | { |
|
- | 266 | .addr = slave_addr, |
|
- | 267 | .flags = I2C_M_RD, |
|
- | 268 | .len = 1, |
|
- | 269 | .buf = in_buf, |
|
- | 270 | } |
|
- | 271 | }; |
|
- | 272 | ||
- | 273 | out_buf[0] = addr; |
|
- | 274 | out_buf[1] = 0; |
|
- | 275 | ||
- | 276 | if (i2c_transfer(&i2c_bus->adapter, msgs, 2) == 2) { |
|
- | 277 | *val = in_buf[0]; |
|
- | 278 | DRM_DEBUG("val = 0x%02x\n", *val); |
|
- | 279 | } else { |
|
- | 280 | DRM_ERROR("i2c 0x%02x 0x%02x read failed\n", |
|
- | 281 | addr, *val); |
|
- | 282 | } |
|
- | 283 | } |
|
- | 284 | ||
- | 285 | void radeon_i2c_sw_put_byte(struct radeon_i2c_chan *i2c_bus, |
|
- | 286 | u8 slave_addr, |
|
- | 287 | u8 addr, |
|
- | 288 | u8 val) |
|
- | 289 | { |
|
- | 290 | uint8_t out_buf[2]; |
|
- | 291 | struct i2c_msg msg = { |
|
- | 292 | .addr = slave_addr, |
|
- | 293 | .flags = 0, |
|
- | 294 | .len = 2, |
|
- | 295 | .buf = out_buf, |
|
- | 296 | }; |
|
- | 297 | ||
- | 298 | out_buf[0] = addr; |
|
- | 299 | out_buf[1] = val; |
|
- | 300 | ||
- | 301 | if (i2c_transfer(&i2c_bus->adapter, &msg, 1) != 1) |