radeon_i2c.c 28 KB

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