radeon_i2c.c 28 KB

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