radeon_i2c.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include "drmP.h"
  27. #include "radeon_drm.h"
  28. #include "radeon.h"
  29. #include "atom.h"
  30. /**
  31. * radeon_ddc_probe
  32. *
  33. */
  34. bool radeon_ddc_probe(struct radeon_connector *radeon_connector, bool requires_extended_probe)
  35. {
  36. u8 out = 0x0;
  37. u8 buf[8];
  38. int ret;
  39. struct i2c_msg msgs[] = {
  40. {
  41. .addr = 0x50,
  42. .flags = 0,
  43. .len = 1,
  44. .buf = &out,
  45. },
  46. {
  47. .addr = 0x50,
  48. .flags = I2C_M_RD,
  49. .len = 1,
  50. .buf = buf,
  51. }
  52. };
  53. /* Read 8 bytes from i2c for extended probe of EDID header */
  54. if (requires_extended_probe)
  55. msgs[1].len = 8;
  56. /* on hw with routers, select right port */
  57. if (radeon_connector->router.ddc_valid)
  58. radeon_router_select_ddc_port(radeon_connector);
  59. ret = i2c_transfer(&radeon_connector->ddc_bus->adapter, msgs, 2);
  60. if (ret != 2)
  61. /* Couldn't find an accessible DDC on this connector */
  62. return false;
  63. if (requires_extended_probe) {
  64. /* Probe also for valid EDID header
  65. * EDID header starts with:
  66. * 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00.
  67. * Only the first 6 bytes must be valid as
  68. * drm_edid_block_valid() can fix the last 2 bytes */
  69. if (drm_edid_header_is_valid(buf) < 6) {
  70. /* Couldn't find an accessible EDID on this
  71. * connector */
  72. return false;
  73. }
  74. }
  75. return true;
  76. }
  77. /* bit banging i2c */
  78. static void radeon_i2c_do_lock(struct radeon_i2c_chan *i2c, int lock_state)
  79. {
  80. struct radeon_device *rdev = i2c->dev->dev_private;
  81. struct radeon_i2c_bus_rec *rec = &i2c->rec;
  82. uint32_t temp;
  83. /* RV410 appears to have a bug where the hw i2c in reset
  84. * holds the i2c port in a bad state - switch hw i2c away before
  85. * doing DDC - do this for all r200s/r300s/r400s for safety sake
  86. */
  87. if (rec->hw_capable) {
  88. if ((rdev->family >= CHIP_R200) && !ASIC_IS_AVIVO(rdev)) {
  89. u32 reg;
  90. if (rdev->family >= CHIP_RV350)
  91. reg = RADEON_GPIO_MONID;
  92. else if ((rdev->family == CHIP_R300) ||
  93. (rdev->family == CHIP_R350))
  94. reg = RADEON_GPIO_DVI_DDC;
  95. else
  96. reg = RADEON_GPIO_CRT2_DDC;
  97. mutex_lock(&rdev->dc_hw_i2c_mutex);
  98. if (rec->a_clk_reg == reg) {
  99. WREG32(RADEON_DVI_I2C_CNTL_0, (RADEON_I2C_SOFT_RST |
  100. R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1)));
  101. } else {
  102. WREG32(RADEON_DVI_I2C_CNTL_0, (RADEON_I2C_SOFT_RST |
  103. R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3)));
  104. }
  105. mutex_unlock(&rdev->dc_hw_i2c_mutex);
  106. }
  107. }
  108. /* switch the pads to ddc mode */
  109. if (ASIC_IS_DCE3(rdev) && rec->hw_capable) {
  110. temp = RREG32(rec->mask_clk_reg);
  111. temp &= ~(1 << 16);
  112. WREG32(rec->mask_clk_reg, temp);
  113. }
  114. /* clear the output pin values */
  115. temp = RREG32(rec->a_clk_reg) & ~rec->a_clk_mask;
  116. WREG32(rec->a_clk_reg, temp);
  117. temp = RREG32(rec->a_data_reg) & ~rec->a_data_mask;
  118. WREG32(rec->a_data_reg, temp);
  119. /* set the pins to input */
  120. temp = RREG32(rec->en_clk_reg) & ~rec->en_clk_mask;
  121. WREG32(rec->en_clk_reg, temp);
  122. temp = RREG32(rec->en_data_reg) & ~rec->en_data_mask;
  123. WREG32(rec->en_data_reg, temp);
  124. /* mask the gpio pins for software use */
  125. temp = RREG32(rec->mask_clk_reg);
  126. if (lock_state)
  127. temp |= rec->mask_clk_mask;
  128. else
  129. temp &= ~rec->mask_clk_mask;
  130. WREG32(rec->mask_clk_reg, temp);
  131. temp = RREG32(rec->mask_clk_reg);
  132. temp = RREG32(rec->mask_data_reg);
  133. if (lock_state)
  134. temp |= rec->mask_data_mask;
  135. else
  136. temp &= ~rec->mask_data_mask;
  137. WREG32(rec->mask_data_reg, temp);
  138. temp = RREG32(rec->mask_data_reg);
  139. }
  140. static int get_clock(void *i2c_priv)
  141. {
  142. struct radeon_i2c_chan *i2c = i2c_priv;
  143. struct radeon_device *rdev = i2c->dev->dev_private;
  144. struct radeon_i2c_bus_rec *rec = &i2c->rec;
  145. uint32_t val;
  146. /* read the value off the pin */
  147. val = RREG32(rec->y_clk_reg);
  148. val &= rec->y_clk_mask;
  149. return (val != 0);
  150. }
  151. static int get_data(void *i2c_priv)
  152. {
  153. struct radeon_i2c_chan *i2c = i2c_priv;
  154. struct radeon_device *rdev = i2c->dev->dev_private;
  155. struct radeon_i2c_bus_rec *rec = &i2c->rec;
  156. uint32_t val;
  157. /* read the value off the pin */
  158. val = RREG32(rec->y_data_reg);
  159. val &= rec->y_data_mask;
  160. return (val != 0);
  161. }
  162. static void set_clock(void *i2c_priv, int clock)
  163. {
  164. struct radeon_i2c_chan *i2c = i2c_priv;
  165. struct radeon_device *rdev = i2c->dev->dev_private;
  166. struct radeon_i2c_bus_rec *rec = &i2c->rec;
  167. uint32_t val;
  168. /* set pin direction */
  169. val = RREG32(rec->en_clk_reg) & ~rec->en_clk_mask;
  170. val |= clock ? 0 : rec->en_clk_mask;
  171. WREG32(rec->en_clk_reg, val);
  172. }
  173. static void set_data(void *i2c_priv, int data)
  174. {
  175. struct radeon_i2c_chan *i2c = i2c_priv;
  176. struct radeon_device *rdev = i2c->dev->dev_private;
  177. struct radeon_i2c_bus_rec *rec = &i2c->rec;
  178. uint32_t val;
  179. /* set pin direction */
  180. val = RREG32(rec->en_data_reg) & ~rec->en_data_mask;
  181. val |= data ? 0 : rec->en_data_mask;
  182. WREG32(rec->en_data_reg, val);
  183. }
  184. static int pre_xfer(struct i2c_adapter *i2c_adap)
  185. {
  186. struct radeon_i2c_chan *i2c = i2c_get_adapdata(i2c_adap);
  187. radeon_i2c_do_lock(i2c, 1);
  188. return 0;
  189. }
  190. static void post_xfer(struct i2c_adapter *i2c_adap)
  191. {
  192. struct radeon_i2c_chan *i2c = i2c_get_adapdata(i2c_adap);
  193. radeon_i2c_do_lock(i2c, 0);
  194. }
  195. /* hw i2c */
  196. static u32 radeon_get_i2c_prescale(struct radeon_device *rdev)
  197. {
  198. u32 sclk = rdev->pm.current_sclk;
  199. u32 prescale = 0;
  200. u32 nm;
  201. u8 n, m, loop;
  202. int i2c_clock;
  203. switch (rdev->family) {
  204. case CHIP_R100:
  205. case CHIP_RV100:
  206. case CHIP_RS100:
  207. case CHIP_RV200:
  208. case CHIP_RS200:
  209. case CHIP_R200:
  210. case CHIP_RV250:
  211. case CHIP_RS300:
  212. case CHIP_RV280:
  213. case CHIP_R300:
  214. case CHIP_R350:
  215. case CHIP_RV350:
  216. i2c_clock = 60;
  217. nm = (sclk * 10) / (i2c_clock * 4);
  218. for (loop = 1; loop < 255; loop++) {
  219. if ((nm / loop) < loop)
  220. break;
  221. }
  222. n = loop - 1;
  223. m = loop - 2;
  224. prescale = m | (n << 8);
  225. break;
  226. case CHIP_RV380:
  227. case CHIP_RS400:
  228. case CHIP_RS480:
  229. case CHIP_R420:
  230. case CHIP_R423:
  231. case CHIP_RV410:
  232. prescale = (((sclk * 10)/(4 * 128 * 100) + 1) << 8) + 128;
  233. break;
  234. case CHIP_RS600:
  235. case CHIP_RS690:
  236. case CHIP_RS740:
  237. /* todo */
  238. break;
  239. case CHIP_RV515:
  240. case CHIP_R520:
  241. case CHIP_RV530:
  242. case CHIP_RV560:
  243. case CHIP_RV570:
  244. case CHIP_R580:
  245. i2c_clock = 50;
  246. if (rdev->family == CHIP_R520)
  247. prescale = (127 << 8) + ((sclk * 10) / (4 * 127 * i2c_clock));
  248. else
  249. prescale = (((sclk * 10)/(4 * 128 * 100) + 1) << 8) + 128;
  250. break;
  251. case CHIP_R600:
  252. case CHIP_RV610:
  253. case CHIP_RV630:
  254. case CHIP_RV670:
  255. /* todo */
  256. break;
  257. case CHIP_RV620:
  258. case CHIP_RV635:
  259. case CHIP_RS780:
  260. case CHIP_RS880:
  261. case CHIP_RV770:
  262. case CHIP_RV730:
  263. case CHIP_RV710:
  264. case CHIP_RV740:
  265. /* todo */
  266. break;
  267. case CHIP_CEDAR:
  268. case CHIP_REDWOOD:
  269. case CHIP_JUNIPER:
  270. case CHIP_CYPRESS:
  271. case CHIP_HEMLOCK:
  272. /* todo */
  273. break;
  274. default:
  275. DRM_ERROR("i2c: unhandled radeon chip\n");
  276. break;
  277. }
  278. return prescale;
  279. }
  280. /* hw i2c engine for r1xx-4xx hardware
  281. * hw can buffer up to 15 bytes
  282. */
  283. static int r100_hw_i2c_xfer(struct i2c_adapter *i2c_adap,
  284. struct i2c_msg *msgs, int num)
  285. {
  286. struct radeon_i2c_chan *i2c = i2c_get_adapdata(i2c_adap);
  287. struct radeon_device *rdev = i2c->dev->dev_private;
  288. struct radeon_i2c_bus_rec *rec = &i2c->rec;
  289. struct i2c_msg *p;
  290. int i, j, k, ret = num;
  291. u32 prescale;
  292. u32 i2c_cntl_0, i2c_cntl_1, i2c_data;
  293. u32 tmp, reg;
  294. mutex_lock(&rdev->dc_hw_i2c_mutex);
  295. /* take the pm lock since we need a constant sclk */
  296. mutex_lock(&rdev->pm.mutex);
  297. prescale = radeon_get_i2c_prescale(rdev);
  298. reg = ((prescale << RADEON_I2C_PRESCALE_SHIFT) |
  299. RADEON_I2C_DRIVE_EN |
  300. RADEON_I2C_START |
  301. RADEON_I2C_STOP |
  302. RADEON_I2C_GO);
  303. if (rdev->is_atom_bios) {
  304. tmp = RREG32(RADEON_BIOS_6_SCRATCH);
  305. WREG32(RADEON_BIOS_6_SCRATCH, tmp | ATOM_S6_HW_I2C_BUSY_STATE);
  306. }
  307. if (rec->mm_i2c) {
  308. i2c_cntl_0 = RADEON_I2C_CNTL_0;
  309. i2c_cntl_1 = RADEON_I2C_CNTL_1;
  310. i2c_data = RADEON_I2C_DATA;
  311. } else {
  312. i2c_cntl_0 = RADEON_DVI_I2C_CNTL_0;
  313. i2c_cntl_1 = RADEON_DVI_I2C_CNTL_1;
  314. i2c_data = RADEON_DVI_I2C_DATA;
  315. switch (rdev->family) {
  316. case CHIP_R100:
  317. case CHIP_RV100:
  318. case CHIP_RS100:
  319. case CHIP_RV200:
  320. case CHIP_RS200:
  321. case CHIP_RS300:
  322. switch (rec->mask_clk_reg) {
  323. case RADEON_GPIO_DVI_DDC:
  324. /* no gpio select bit */
  325. break;
  326. default:
  327. DRM_ERROR("gpio not supported with hw i2c\n");
  328. ret = -EINVAL;
  329. goto done;
  330. }
  331. break;
  332. case CHIP_R200:
  333. /* only bit 4 on r200 */
  334. switch (rec->mask_clk_reg) {
  335. case RADEON_GPIO_DVI_DDC:
  336. reg |= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1);
  337. break;
  338. case RADEON_GPIO_MONID:
  339. reg |= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3);
  340. break;
  341. default:
  342. DRM_ERROR("gpio not supported with hw i2c\n");
  343. ret = -EINVAL;
  344. goto done;
  345. }
  346. break;
  347. case CHIP_RV250:
  348. case CHIP_RV280:
  349. /* bits 3 and 4 */
  350. switch (rec->mask_clk_reg) {
  351. case RADEON_GPIO_DVI_DDC:
  352. reg |= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1);
  353. break;
  354. case RADEON_GPIO_VGA_DDC:
  355. reg |= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC2);
  356. break;
  357. case RADEON_GPIO_CRT2_DDC:
  358. reg |= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3);
  359. break;
  360. default:
  361. DRM_ERROR("gpio not supported with hw i2c\n");
  362. ret = -EINVAL;
  363. goto done;
  364. }
  365. break;
  366. case CHIP_R300:
  367. case CHIP_R350:
  368. /* only bit 4 on r300/r350 */
  369. switch (rec->mask_clk_reg) {
  370. case RADEON_GPIO_VGA_DDC:
  371. reg |= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1);
  372. break;
  373. case RADEON_GPIO_DVI_DDC:
  374. reg |= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3);
  375. break;
  376. default:
  377. DRM_ERROR("gpio not supported with hw i2c\n");
  378. ret = -EINVAL;
  379. goto done;
  380. }
  381. break;
  382. case CHIP_RV350:
  383. case CHIP_RV380:
  384. case CHIP_R420:
  385. case CHIP_R423:
  386. case CHIP_RV410:
  387. case CHIP_RS400:
  388. case CHIP_RS480:
  389. /* bits 3 and 4 */
  390. switch (rec->mask_clk_reg) {
  391. case RADEON_GPIO_VGA_DDC:
  392. reg |= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC1);
  393. break;
  394. case RADEON_GPIO_DVI_DDC:
  395. reg |= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC2);
  396. break;
  397. case RADEON_GPIO_MONID:
  398. reg |= R200_DVI_I2C_PIN_SEL(R200_SEL_DDC3);
  399. break;
  400. default:
  401. DRM_ERROR("gpio not supported with hw i2c\n");
  402. ret = -EINVAL;
  403. goto done;
  404. }
  405. break;
  406. default:
  407. DRM_ERROR("unsupported asic\n");
  408. ret = -EINVAL;
  409. goto done;
  410. break;
  411. }
  412. }
  413. /* check for bus probe */
  414. p = &msgs[0];
  415. if ((num == 1) && (p->len == 0)) {
  416. WREG32(i2c_cntl_0, (RADEON_I2C_DONE |
  417. RADEON_I2C_NACK |
  418. RADEON_I2C_HALT |
  419. RADEON_I2C_SOFT_RST));
  420. WREG32(i2c_data, (p->addr << 1) & 0xff);
  421. WREG32(i2c_data, 0);
  422. WREG32(i2c_cntl_1, ((1 << RADEON_I2C_DATA_COUNT_SHIFT) |
  423. (1 << RADEON_I2C_ADDR_COUNT_SHIFT) |
  424. RADEON_I2C_EN |
  425. (48 << RADEON_I2C_TIME_LIMIT_SHIFT)));
  426. WREG32(i2c_cntl_0, reg);
  427. for (k = 0; k < 32; k++) {
  428. udelay(10);
  429. tmp = RREG32(i2c_cntl_0);
  430. if (tmp & RADEON_I2C_GO)
  431. continue;
  432. tmp = RREG32(i2c_cntl_0);
  433. if (tmp & RADEON_I2C_DONE)
  434. break;
  435. else {
  436. DRM_DEBUG("i2c write error 0x%08x\n", tmp);
  437. WREG32(i2c_cntl_0, tmp | RADEON_I2C_ABORT);
  438. ret = -EIO;
  439. goto done;
  440. }
  441. }
  442. goto done;
  443. }
  444. for (i = 0; i < num; i++) {
  445. p = &msgs[i];
  446. for (j = 0; j < p->len; j++) {
  447. if (p->flags & I2C_M_RD) {
  448. WREG32(i2c_cntl_0, (RADEON_I2C_DONE |
  449. RADEON_I2C_NACK |
  450. RADEON_I2C_HALT |
  451. RADEON_I2C_SOFT_RST));
  452. WREG32(i2c_data, ((p->addr << 1) & 0xff) | 0x1);
  453. WREG32(i2c_cntl_1, ((1 << RADEON_I2C_DATA_COUNT_SHIFT) |
  454. (1 << RADEON_I2C_ADDR_COUNT_SHIFT) |
  455. RADEON_I2C_EN |
  456. (48 << RADEON_I2C_TIME_LIMIT_SHIFT)));
  457. WREG32(i2c_cntl_0, reg | RADEON_I2C_RECEIVE);
  458. for (k = 0; k < 32; k++) {
  459. udelay(10);
  460. tmp = RREG32(i2c_cntl_0);
  461. if (tmp & RADEON_I2C_GO)
  462. continue;
  463. tmp = RREG32(i2c_cntl_0);
  464. if (tmp & RADEON_I2C_DONE)
  465. break;
  466. else {
  467. DRM_DEBUG("i2c read error 0x%08x\n", tmp);
  468. WREG32(i2c_cntl_0, tmp | RADEON_I2C_ABORT);
  469. ret = -EIO;
  470. goto done;
  471. }
  472. }
  473. p->buf[j] = RREG32(i2c_data) & 0xff;
  474. } else {
  475. WREG32(i2c_cntl_0, (RADEON_I2C_DONE |
  476. RADEON_I2C_NACK |
  477. RADEON_I2C_HALT |
  478. RADEON_I2C_SOFT_RST));
  479. WREG32(i2c_data, (p->addr << 1) & 0xff);
  480. WREG32(i2c_data, p->buf[j]);
  481. WREG32(i2c_cntl_1, ((1 << RADEON_I2C_DATA_COUNT_SHIFT) |
  482. (1 << RADEON_I2C_ADDR_COUNT_SHIFT) |
  483. RADEON_I2C_EN |
  484. (48 << RADEON_I2C_TIME_LIMIT_SHIFT)));
  485. WREG32(i2c_cntl_0, reg);
  486. for (k = 0; k < 32; k++) {
  487. udelay(10);
  488. tmp = RREG32(i2c_cntl_0);
  489. if (tmp & RADEON_I2C_GO)
  490. continue;
  491. tmp = RREG32(i2c_cntl_0);
  492. if (tmp & RADEON_I2C_DONE)
  493. break;
  494. else {
  495. DRM_DEBUG("i2c write error 0x%08x\n", tmp);
  496. WREG32(i2c_cntl_0, tmp | RADEON_I2C_ABORT);
  497. ret = -EIO;
  498. goto done;
  499. }
  500. }
  501. }
  502. }
  503. }
  504. done:
  505. WREG32(i2c_cntl_0, 0);
  506. WREG32(i2c_cntl_1, 0);
  507. WREG32(i2c_cntl_0, (RADEON_I2C_DONE |
  508. RADEON_I2C_NACK |
  509. RADEON_I2C_HALT |
  510. RADEON_I2C_SOFT_RST));
  511. if (rdev->is_atom_bios) {
  512. tmp = RREG32(RADEON_BIOS_6_SCRATCH);
  513. tmp &= ~ATOM_S6_HW_I2C_BUSY_STATE;
  514. WREG32(RADEON_BIOS_6_SCRATCH, tmp);
  515. }
  516. mutex_unlock(&rdev->pm.mutex);
  517. mutex_unlock(&rdev->dc_hw_i2c_mutex);
  518. return ret;
  519. }
  520. /* hw i2c engine for r5xx hardware
  521. * hw can buffer up to 15 bytes
  522. */
  523. static int r500_hw_i2c_xfer(struct i2c_adapter *i2c_adap,
  524. struct i2c_msg *msgs, int num)
  525. {
  526. struct radeon_i2c_chan *i2c = i2c_get_adapdata(i2c_adap);
  527. struct radeon_device *rdev = i2c->dev->dev_private;
  528. struct radeon_i2c_bus_rec *rec = &i2c->rec;
  529. struct i2c_msg *p;
  530. int i, j, remaining, current_count, buffer_offset, ret = num;
  531. u32 prescale;
  532. u32 tmp, reg;
  533. u32 saved1, saved2;
  534. mutex_lock(&rdev->dc_hw_i2c_mutex);
  535. /* take the pm lock since we need a constant sclk */
  536. mutex_lock(&rdev->pm.mutex);
  537. prescale = radeon_get_i2c_prescale(rdev);
  538. /* clear gpio mask bits */
  539. tmp = RREG32(rec->mask_clk_reg);
  540. tmp &= ~rec->mask_clk_mask;
  541. WREG32(rec->mask_clk_reg, tmp);
  542. tmp = RREG32(rec->mask_clk_reg);
  543. tmp = RREG32(rec->mask_data_reg);
  544. tmp &= ~rec->mask_data_mask;
  545. WREG32(rec->mask_data_reg, tmp);
  546. tmp = RREG32(rec->mask_data_reg);
  547. /* clear pin values */
  548. tmp = RREG32(rec->a_clk_reg);
  549. tmp &= ~rec->a_clk_mask;
  550. WREG32(rec->a_clk_reg, tmp);
  551. tmp = RREG32(rec->a_clk_reg);
  552. tmp = RREG32(rec->a_data_reg);
  553. tmp &= ~rec->a_data_mask;
  554. WREG32(rec->a_data_reg, tmp);
  555. tmp = RREG32(rec->a_data_reg);
  556. /* set the pins to input */
  557. tmp = RREG32(rec->en_clk_reg);
  558. tmp &= ~rec->en_clk_mask;
  559. WREG32(rec->en_clk_reg, tmp);
  560. tmp = RREG32(rec->en_clk_reg);
  561. tmp = RREG32(rec->en_data_reg);
  562. tmp &= ~rec->en_data_mask;
  563. WREG32(rec->en_data_reg, tmp);
  564. tmp = RREG32(rec->en_data_reg);
  565. /* */
  566. tmp = RREG32(RADEON_BIOS_6_SCRATCH);
  567. WREG32(RADEON_BIOS_6_SCRATCH, tmp | ATOM_S6_HW_I2C_BUSY_STATE);
  568. saved1 = RREG32(AVIVO_DC_I2C_CONTROL1);
  569. saved2 = RREG32(0x494);
  570. WREG32(0x494, saved2 | 0x1);
  571. WREG32(AVIVO_DC_I2C_ARBITRATION, AVIVO_DC_I2C_SW_WANTS_TO_USE_I2C);
  572. for (i = 0; i < 50; i++) {
  573. udelay(1);
  574. if (RREG32(AVIVO_DC_I2C_ARBITRATION) & AVIVO_DC_I2C_SW_CAN_USE_I2C)
  575. break;
  576. }
  577. if (i == 50) {
  578. DRM_ERROR("failed to get i2c bus\n");
  579. ret = -EBUSY;
  580. goto done;
  581. }
  582. reg = AVIVO_DC_I2C_START | AVIVO_DC_I2C_STOP | AVIVO_DC_I2C_EN;
  583. switch (rec->mask_clk_reg) {
  584. case AVIVO_DC_GPIO_DDC1_MASK:
  585. reg |= AVIVO_DC_I2C_PIN_SELECT(AVIVO_SEL_DDC1);
  586. break;
  587. case AVIVO_DC_GPIO_DDC2_MASK:
  588. reg |= AVIVO_DC_I2C_PIN_SELECT(AVIVO_SEL_DDC2);
  589. break;
  590. case AVIVO_DC_GPIO_DDC3_MASK:
  591. reg |= AVIVO_DC_I2C_PIN_SELECT(AVIVO_SEL_DDC3);
  592. break;
  593. default:
  594. DRM_ERROR("gpio not supported with hw i2c\n");
  595. ret = -EINVAL;
  596. goto done;
  597. }
  598. /* check for bus probe */
  599. p = &msgs[0];
  600. if ((num == 1) && (p->len == 0)) {
  601. WREG32(AVIVO_DC_I2C_STATUS1, (AVIVO_DC_I2C_DONE |
  602. AVIVO_DC_I2C_NACK |
  603. AVIVO_DC_I2C_HALT));
  604. WREG32(AVIVO_DC_I2C_RESET, AVIVO_DC_I2C_SOFT_RESET);
  605. udelay(1);
  606. WREG32(AVIVO_DC_I2C_RESET, 0);
  607. WREG32(AVIVO_DC_I2C_DATA, (p->addr << 1) & 0xff);
  608. WREG32(AVIVO_DC_I2C_DATA, 0);
  609. WREG32(AVIVO_DC_I2C_CONTROL3, AVIVO_DC_I2C_TIME_LIMIT(48));
  610. WREG32(AVIVO_DC_I2C_CONTROL2, (AVIVO_DC_I2C_ADDR_COUNT(1) |
  611. AVIVO_DC_I2C_DATA_COUNT(1) |
  612. (prescale << 16)));
  613. WREG32(AVIVO_DC_I2C_CONTROL1, reg);
  614. WREG32(AVIVO_DC_I2C_STATUS1, AVIVO_DC_I2C_GO);
  615. for (j = 0; j < 200; j++) {
  616. udelay(50);
  617. tmp = RREG32(AVIVO_DC_I2C_STATUS1);
  618. if (tmp & AVIVO_DC_I2C_GO)
  619. continue;
  620. tmp = RREG32(AVIVO_DC_I2C_STATUS1);
  621. if (tmp & AVIVO_DC_I2C_DONE)
  622. break;
  623. else {
  624. DRM_DEBUG("i2c write error 0x%08x\n", tmp);
  625. WREG32(AVIVO_DC_I2C_RESET, AVIVO_DC_I2C_ABORT);
  626. ret = -EIO;
  627. goto done;
  628. }
  629. }
  630. goto done;
  631. }
  632. for (i = 0; i < num; i++) {
  633. p = &msgs[i];
  634. remaining = p->len;
  635. buffer_offset = 0;
  636. if (p->flags & I2C_M_RD) {
  637. while (remaining) {
  638. if (remaining > 15)
  639. current_count = 15;
  640. else
  641. current_count = remaining;
  642. WREG32(AVIVO_DC_I2C_STATUS1, (AVIVO_DC_I2C_DONE |
  643. AVIVO_DC_I2C_NACK |
  644. AVIVO_DC_I2C_HALT));
  645. WREG32(AVIVO_DC_I2C_RESET, AVIVO_DC_I2C_SOFT_RESET);
  646. udelay(1);
  647. WREG32(AVIVO_DC_I2C_RESET, 0);
  648. WREG32(AVIVO_DC_I2C_DATA, ((p->addr << 1) & 0xff) | 0x1);
  649. WREG32(AVIVO_DC_I2C_CONTROL3, AVIVO_DC_I2C_TIME_LIMIT(48));
  650. WREG32(AVIVO_DC_I2C_CONTROL2, (AVIVO_DC_I2C_ADDR_COUNT(1) |
  651. AVIVO_DC_I2C_DATA_COUNT(current_count) |
  652. (prescale << 16)));
  653. WREG32(AVIVO_DC_I2C_CONTROL1, reg | AVIVO_DC_I2C_RECEIVE);
  654. WREG32(AVIVO_DC_I2C_STATUS1, AVIVO_DC_I2C_GO);
  655. for (j = 0; j < 200; j++) {
  656. udelay(50);
  657. tmp = RREG32(AVIVO_DC_I2C_STATUS1);
  658. if (tmp & AVIVO_DC_I2C_GO)
  659. continue;
  660. tmp = RREG32(AVIVO_DC_I2C_STATUS1);
  661. if (tmp & AVIVO_DC_I2C_DONE)
  662. break;
  663. else {
  664. DRM_DEBUG("i2c read error 0x%08x\n", tmp);
  665. WREG32(AVIVO_DC_I2C_RESET, AVIVO_DC_I2C_ABORT);
  666. ret = -EIO;
  667. goto done;
  668. }
  669. }
  670. for (j = 0; j < current_count; j++)
  671. p->buf[buffer_offset + j] = RREG32(AVIVO_DC_I2C_DATA) & 0xff;
  672. remaining -= current_count;
  673. buffer_offset += current_count;
  674. }
  675. } else {
  676. while (remaining) {
  677. if (remaining > 15)
  678. current_count = 15;
  679. else
  680. current_count = remaining;
  681. WREG32(AVIVO_DC_I2C_STATUS1, (AVIVO_DC_I2C_DONE |
  682. AVIVO_DC_I2C_NACK |
  683. AVIVO_DC_I2C_HALT));
  684. WREG32(AVIVO_DC_I2C_RESET, AVIVO_DC_I2C_SOFT_RESET);
  685. udelay(1);
  686. WREG32(AVIVO_DC_I2C_RESET, 0);
  687. WREG32(AVIVO_DC_I2C_DATA, (p->addr << 1) & 0xff);
  688. for (j = 0; j < current_count; j++)
  689. WREG32(AVIVO_DC_I2C_DATA, p->buf[buffer_offset + j]);
  690. WREG32(AVIVO_DC_I2C_CONTROL3, AVIVO_DC_I2C_TIME_LIMIT(48));
  691. WREG32(AVIVO_DC_I2C_CONTROL2, (AVIVO_DC_I2C_ADDR_COUNT(1) |
  692. AVIVO_DC_I2C_DATA_COUNT(current_count) |
  693. (prescale << 16)));
  694. WREG32(AVIVO_DC_I2C_CONTROL1, reg);
  695. WREG32(AVIVO_DC_I2C_STATUS1, AVIVO_DC_I2C_GO);
  696. for (j = 0; j < 200; j++) {
  697. udelay(50);
  698. tmp = RREG32(AVIVO_DC_I2C_STATUS1);
  699. if (tmp & AVIVO_DC_I2C_GO)
  700. continue;
  701. tmp = RREG32(AVIVO_DC_I2C_STATUS1);
  702. if (tmp & AVIVO_DC_I2C_DONE)
  703. break;
  704. else {
  705. DRM_DEBUG("i2c write error 0x%08x\n", tmp);
  706. WREG32(AVIVO_DC_I2C_RESET, AVIVO_DC_I2C_ABORT);
  707. ret = -EIO;
  708. goto done;
  709. }
  710. }
  711. remaining -= current_count;
  712. buffer_offset += current_count;
  713. }
  714. }
  715. }
  716. done:
  717. WREG32(AVIVO_DC_I2C_STATUS1, (AVIVO_DC_I2C_DONE |
  718. AVIVO_DC_I2C_NACK |
  719. AVIVO_DC_I2C_HALT));
  720. WREG32(AVIVO_DC_I2C_RESET, AVIVO_DC_I2C_SOFT_RESET);
  721. udelay(1);
  722. WREG32(AVIVO_DC_I2C_RESET, 0);
  723. WREG32(AVIVO_DC_I2C_ARBITRATION, AVIVO_DC_I2C_SW_DONE_USING_I2C);
  724. WREG32(AVIVO_DC_I2C_CONTROL1, saved1);
  725. WREG32(0x494, saved2);
  726. tmp = RREG32(RADEON_BIOS_6_SCRATCH);
  727. tmp &= ~ATOM_S6_HW_I2C_BUSY_STATE;
  728. WREG32(RADEON_BIOS_6_SCRATCH, tmp);
  729. mutex_unlock(&rdev->pm.mutex);
  730. mutex_unlock(&rdev->dc_hw_i2c_mutex);
  731. return ret;
  732. }
  733. static int radeon_hw_i2c_xfer(struct i2c_adapter *i2c_adap,
  734. struct i2c_msg *msgs, int num)
  735. {
  736. struct radeon_i2c_chan *i2c = i2c_get_adapdata(i2c_adap);
  737. struct radeon_device *rdev = i2c->dev->dev_private;
  738. struct radeon_i2c_bus_rec *rec = &i2c->rec;
  739. int ret = 0;
  740. switch (rdev->family) {
  741. case CHIP_R100:
  742. case CHIP_RV100:
  743. case CHIP_RS100:
  744. case CHIP_RV200:
  745. case CHIP_RS200:
  746. case CHIP_R200:
  747. case CHIP_RV250:
  748. case CHIP_RS300:
  749. case CHIP_RV280:
  750. case CHIP_R300:
  751. case CHIP_R350:
  752. case CHIP_RV350:
  753. case CHIP_RV380:
  754. case CHIP_R420:
  755. case CHIP_R423:
  756. case CHIP_RV410:
  757. case CHIP_RS400:
  758. case CHIP_RS480:
  759. ret = r100_hw_i2c_xfer(i2c_adap, msgs, num);
  760. break;
  761. case CHIP_RS600:
  762. case CHIP_RS690:
  763. case CHIP_RS740:
  764. /* XXX fill in hw i2c implementation */
  765. break;
  766. case CHIP_RV515:
  767. case CHIP_R520:
  768. case CHIP_RV530:
  769. case CHIP_RV560:
  770. case CHIP_RV570:
  771. case CHIP_R580:
  772. if (rec->mm_i2c)
  773. ret = r100_hw_i2c_xfer(i2c_adap, msgs, num);
  774. else
  775. ret = r500_hw_i2c_xfer(i2c_adap, msgs, num);
  776. break;
  777. case CHIP_R600:
  778. case CHIP_RV610:
  779. case CHIP_RV630:
  780. case CHIP_RV670:
  781. /* XXX fill in hw i2c implementation */
  782. break;
  783. case CHIP_RV620:
  784. case CHIP_RV635:
  785. case CHIP_RS780:
  786. case CHIP_RS880:
  787. case CHIP_RV770:
  788. case CHIP_RV730:
  789. case CHIP_RV710:
  790. case CHIP_RV740:
  791. /* XXX fill in hw i2c implementation */
  792. break;
  793. case CHIP_CEDAR:
  794. case CHIP_REDWOOD:
  795. case CHIP_JUNIPER:
  796. case CHIP_CYPRESS:
  797. case CHIP_HEMLOCK:
  798. /* XXX fill in hw i2c implementation */
  799. break;
  800. default:
  801. DRM_ERROR("i2c: unhandled radeon chip\n");
  802. ret = -EIO;
  803. break;
  804. }
  805. return ret;
  806. }
  807. static u32 radeon_hw_i2c_func(struct i2c_adapter *adap)
  808. {
  809. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
  810. }
  811. static const struct i2c_algorithm radeon_i2c_algo = {
  812. .master_xfer = radeon_hw_i2c_xfer,
  813. .functionality = radeon_hw_i2c_func,
  814. };
  815. struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
  816. struct radeon_i2c_bus_rec *rec,
  817. const char *name)
  818. {
  819. struct radeon_device *rdev = dev->dev_private;
  820. struct radeon_i2c_chan *i2c;
  821. int ret;
  822. /* don't add the mm_i2c bus unless hw_i2c is enabled */
  823. if (rec->mm_i2c && (radeon_hw_i2c == 0))
  824. return NULL;
  825. i2c = kzalloc(sizeof(struct radeon_i2c_chan), GFP_KERNEL);
  826. if (i2c == NULL)
  827. return NULL;
  828. i2c->rec = *rec;
  829. i2c->adapter.owner = THIS_MODULE;
  830. i2c->adapter.class = I2C_CLASS_DDC;
  831. i2c->dev = dev;
  832. i2c_set_adapdata(&i2c->adapter, i2c);
  833. if (rec->mm_i2c ||
  834. (rec->hw_capable &&
  835. radeon_hw_i2c &&
  836. ((rdev->family <= CHIP_RS480) ||
  837. ((rdev->family >= CHIP_RV515) && (rdev->family <= CHIP_R580))))) {
  838. /* set the radeon hw i2c adapter */
  839. snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
  840. "Radeon i2c hw bus %s", name);
  841. i2c->adapter.algo = &radeon_i2c_algo;
  842. ret = i2c_add_adapter(&i2c->adapter);
  843. if (ret) {
  844. DRM_ERROR("Failed to register hw i2c %s\n", name);
  845. goto out_free;
  846. }
  847. } else {
  848. /* set the radeon bit adapter */
  849. snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
  850. "Radeon i2c bit bus %s", name);
  851. i2c->adapter.algo_data = &i2c->algo.bit;
  852. i2c->algo.bit.pre_xfer = pre_xfer;
  853. i2c->algo.bit.post_xfer = post_xfer;
  854. i2c->algo.bit.setsda = set_data;
  855. i2c->algo.bit.setscl = set_clock;
  856. i2c->algo.bit.getsda = get_data;
  857. i2c->algo.bit.getscl = get_clock;
  858. i2c->algo.bit.udelay = 20;
  859. /* vesa says 2.2 ms is enough, 1 jiffy doesn't seem to always
  860. * make this, 2 jiffies is a lot more reliable */
  861. i2c->algo.bit.timeout = 2;
  862. i2c->algo.bit.data = i2c;
  863. ret = i2c_bit_add_bus(&i2c->adapter);
  864. if (ret) {
  865. DRM_ERROR("Failed to register bit i2c %s\n", name);
  866. goto out_free;
  867. }
  868. }
  869. return i2c;
  870. out_free:
  871. kfree(i2c);
  872. return NULL;
  873. }
  874. struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev,
  875. struct radeon_i2c_bus_rec *rec,
  876. const char *name)
  877. {
  878. struct radeon_i2c_chan *i2c;
  879. int ret;
  880. i2c = kzalloc(sizeof(struct radeon_i2c_chan), GFP_KERNEL);
  881. if (i2c == NULL)
  882. return NULL;
  883. i2c->rec = *rec;
  884. i2c->adapter.owner = THIS_MODULE;
  885. i2c->adapter.class = I2C_CLASS_DDC;
  886. i2c->dev = dev;
  887. snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
  888. "Radeon aux bus %s", name);
  889. i2c_set_adapdata(&i2c->adapter, i2c);
  890. i2c->adapter.algo_data = &i2c->algo.dp;
  891. i2c->algo.dp.aux_ch = radeon_dp_i2c_aux_ch;
  892. i2c->algo.dp.address = 0;
  893. ret = i2c_dp_aux_add_bus(&i2c->adapter);
  894. if (ret) {
  895. DRM_INFO("Failed to register i2c %s\n", name);
  896. goto out_free;
  897. }
  898. return i2c;
  899. out_free:
  900. kfree(i2c);
  901. return NULL;
  902. }
  903. void radeon_i2c_destroy(struct radeon_i2c_chan *i2c)
  904. {
  905. if (!i2c)
  906. return;
  907. i2c_del_adapter(&i2c->adapter);
  908. kfree(i2c);
  909. }
  910. /* Add the default buses */
  911. void radeon_i2c_init(struct radeon_device *rdev)
  912. {
  913. if (rdev->is_atom_bios)
  914. radeon_atombios_i2c_init(rdev);
  915. else
  916. radeon_combios_i2c_init(rdev);
  917. }
  918. /* remove all the buses */
  919. void radeon_i2c_fini(struct radeon_device *rdev)
  920. {
  921. int i;
  922. for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
  923. if (rdev->i2c_bus[i]) {
  924. radeon_i2c_destroy(rdev->i2c_bus[i]);
  925. rdev->i2c_bus[i] = NULL;
  926. }
  927. }
  928. }
  929. /* Add additional buses */
  930. void radeon_i2c_add(struct radeon_device *rdev,
  931. struct radeon_i2c_bus_rec *rec,
  932. const char *name)
  933. {
  934. struct drm_device *dev = rdev->ddev;
  935. int i;
  936. for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
  937. if (!rdev->i2c_bus[i]) {
  938. rdev->i2c_bus[i] = radeon_i2c_create(dev, rec, name);
  939. return;
  940. }
  941. }
  942. }
  943. /* looks up bus based on id */
  944. struct radeon_i2c_chan *radeon_i2c_lookup(struct radeon_device *rdev,
  945. struct radeon_i2c_bus_rec *i2c_bus)
  946. {
  947. int i;
  948. for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
  949. if (rdev->i2c_bus[i] &&
  950. (rdev->i2c_bus[i]->rec.i2c_id == i2c_bus->i2c_id)) {
  951. return rdev->i2c_bus[i];
  952. }
  953. }
  954. return NULL;
  955. }
  956. struct drm_encoder *radeon_best_encoder(struct drm_connector *connector)
  957. {
  958. return NULL;
  959. }
  960. void radeon_i2c_get_byte(struct radeon_i2c_chan *i2c_bus,
  961. u8 slave_addr,
  962. u8 addr,
  963. u8 *val)
  964. {
  965. u8 out_buf[2];
  966. u8 in_buf[2];
  967. struct i2c_msg msgs[] = {
  968. {
  969. .addr = slave_addr,
  970. .flags = 0,
  971. .len = 1,
  972. .buf = out_buf,
  973. },
  974. {
  975. .addr = slave_addr,
  976. .flags = I2C_M_RD,
  977. .len = 1,
  978. .buf = in_buf,
  979. }
  980. };
  981. out_buf[0] = addr;
  982. out_buf[1] = 0;
  983. if (i2c_transfer(&i2c_bus->adapter, msgs, 2) == 2) {
  984. *val = in_buf[0];
  985. DRM_DEBUG("val = 0x%02x\n", *val);
  986. } else {
  987. DRM_DEBUG("i2c 0x%02x 0x%02x read failed\n",
  988. addr, *val);
  989. }
  990. }
  991. void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c_bus,
  992. u8 slave_addr,
  993. u8 addr,
  994. u8 val)
  995. {
  996. uint8_t out_buf[2];
  997. struct i2c_msg msg = {
  998. .addr = slave_addr,
  999. .flags = 0,
  1000. .len = 2,
  1001. .buf = out_buf,
  1002. };
  1003. out_buf[0] = addr;
  1004. out_buf[1] = val;
  1005. if (i2c_transfer(&i2c_bus->adapter, &msg, 1) != 1)
  1006. DRM_DEBUG("i2c 0x%02x 0x%02x write failed\n",
  1007. addr, val);
  1008. }
  1009. /* ddc router switching */
  1010. void radeon_router_select_ddc_port(struct radeon_connector *radeon_connector)
  1011. {
  1012. u8 val;
  1013. if (!radeon_connector->router.ddc_valid)
  1014. return;
  1015. if (!radeon_connector->router_bus)
  1016. return;
  1017. radeon_i2c_get_byte(radeon_connector->router_bus,
  1018. radeon_connector->router.i2c_addr,
  1019. 0x3, &val);
  1020. val &= ~radeon_connector->router.ddc_mux_control_pin;
  1021. radeon_i2c_put_byte(radeon_connector->router_bus,
  1022. radeon_connector->router.i2c_addr,
  1023. 0x3, val);
  1024. radeon_i2c_get_byte(radeon_connector->router_bus,
  1025. radeon_connector->router.i2c_addr,
  1026. 0x1, &val);
  1027. val &= ~radeon_connector->router.ddc_mux_control_pin;
  1028. val |= radeon_connector->router.ddc_mux_state;
  1029. radeon_i2c_put_byte(radeon_connector->router_bus,
  1030. radeon_connector->router.i2c_addr,
  1031. 0x1, val);
  1032. }
  1033. /* clock/data router switching */
  1034. void radeon_router_select_cd_port(struct radeon_connector *radeon_connector)
  1035. {
  1036. u8 val;
  1037. if (!radeon_connector->router.cd_valid)
  1038. return;
  1039. if (!radeon_connector->router_bus)
  1040. return;
  1041. radeon_i2c_get_byte(radeon_connector->router_bus,
  1042. radeon_connector->router.i2c_addr,
  1043. 0x3, &val);
  1044. val &= ~radeon_connector->router.cd_mux_control_pin;
  1045. radeon_i2c_put_byte(radeon_connector->router_bus,
  1046. radeon_connector->router.i2c_addr,
  1047. 0x3, val);
  1048. radeon_i2c_get_byte(radeon_connector->router_bus,
  1049. radeon_connector->router.i2c_addr,
  1050. 0x1, &val);
  1051. val &= ~radeon_connector->router.cd_mux_control_pin;
  1052. val |= radeon_connector->router.cd_mux_state;
  1053. radeon_i2c_put_byte(radeon_connector->router_bus,
  1054. radeon_connector->router.i2c_addr,
  1055. 0x1, val);
  1056. }