radeon_i2c.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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. i2c = kzalloc(sizeof(struct radeon_i2c_chan), GFP_KERNEL);
  823. if (i2c == NULL)
  824. return NULL;
  825. i2c->rec = *rec;
  826. i2c->adapter.owner = THIS_MODULE;
  827. i2c->adapter.class = I2C_CLASS_DDC;
  828. i2c->dev = dev;
  829. i2c_set_adapdata(&i2c->adapter, i2c);
  830. if (rec->mm_i2c ||
  831. (rec->hw_capable &&
  832. radeon_hw_i2c &&
  833. ((rdev->family <= CHIP_RS480) ||
  834. ((rdev->family >= CHIP_RV515) && (rdev->family <= CHIP_R580))))) {
  835. /* set the radeon hw i2c adapter */
  836. snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
  837. "Radeon i2c hw bus %s", name);
  838. i2c->adapter.algo = &radeon_i2c_algo;
  839. ret = i2c_add_adapter(&i2c->adapter);
  840. if (ret) {
  841. DRM_ERROR("Failed to register hw i2c %s\n", name);
  842. goto out_free;
  843. }
  844. } else {
  845. /* set the radeon bit adapter */
  846. snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
  847. "Radeon i2c bit bus %s", name);
  848. i2c->adapter.algo_data = &i2c->algo.bit;
  849. i2c->algo.bit.pre_xfer = pre_xfer;
  850. i2c->algo.bit.post_xfer = post_xfer;
  851. i2c->algo.bit.setsda = set_data;
  852. i2c->algo.bit.setscl = set_clock;
  853. i2c->algo.bit.getsda = get_data;
  854. i2c->algo.bit.getscl = get_clock;
  855. i2c->algo.bit.udelay = 20;
  856. /* vesa says 2.2 ms is enough, 1 jiffy doesn't seem to always
  857. * make this, 2 jiffies is a lot more reliable */
  858. i2c->algo.bit.timeout = 2;
  859. i2c->algo.bit.data = i2c;
  860. ret = i2c_bit_add_bus(&i2c->adapter);
  861. if (ret) {
  862. DRM_ERROR("Failed to register bit i2c %s\n", name);
  863. goto out_free;
  864. }
  865. }
  866. return i2c;
  867. out_free:
  868. kfree(i2c);
  869. return NULL;
  870. }
  871. struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev,
  872. struct radeon_i2c_bus_rec *rec,
  873. const char *name)
  874. {
  875. struct radeon_i2c_chan *i2c;
  876. int ret;
  877. i2c = kzalloc(sizeof(struct radeon_i2c_chan), GFP_KERNEL);
  878. if (i2c == NULL)
  879. return NULL;
  880. i2c->rec = *rec;
  881. i2c->adapter.owner = THIS_MODULE;
  882. i2c->adapter.class = I2C_CLASS_DDC;
  883. i2c->dev = dev;
  884. snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
  885. "Radeon aux bus %s", name);
  886. i2c_set_adapdata(&i2c->adapter, i2c);
  887. i2c->adapter.algo_data = &i2c->algo.dp;
  888. i2c->algo.dp.aux_ch = radeon_dp_i2c_aux_ch;
  889. i2c->algo.dp.address = 0;
  890. ret = i2c_dp_aux_add_bus(&i2c->adapter);
  891. if (ret) {
  892. DRM_INFO("Failed to register i2c %s\n", name);
  893. goto out_free;
  894. }
  895. return i2c;
  896. out_free:
  897. kfree(i2c);
  898. return NULL;
  899. }
  900. void radeon_i2c_destroy(struct radeon_i2c_chan *i2c)
  901. {
  902. if (!i2c)
  903. return;
  904. i2c_del_adapter(&i2c->adapter);
  905. kfree(i2c);
  906. }
  907. /* Add the default buses */
  908. void radeon_i2c_init(struct radeon_device *rdev)
  909. {
  910. if (rdev->is_atom_bios)
  911. radeon_atombios_i2c_init(rdev);
  912. else
  913. radeon_combios_i2c_init(rdev);
  914. }
  915. /* remove all the buses */
  916. void radeon_i2c_fini(struct radeon_device *rdev)
  917. {
  918. int i;
  919. for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
  920. if (rdev->i2c_bus[i]) {
  921. radeon_i2c_destroy(rdev->i2c_bus[i]);
  922. rdev->i2c_bus[i] = NULL;
  923. }
  924. }
  925. }
  926. /* Add additional buses */
  927. void radeon_i2c_add(struct radeon_device *rdev,
  928. struct radeon_i2c_bus_rec *rec,
  929. const char *name)
  930. {
  931. struct drm_device *dev = rdev->ddev;
  932. int i;
  933. for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
  934. if (!rdev->i2c_bus[i]) {
  935. rdev->i2c_bus[i] = radeon_i2c_create(dev, rec, name);
  936. return;
  937. }
  938. }
  939. }
  940. /* looks up bus based on id */
  941. struct radeon_i2c_chan *radeon_i2c_lookup(struct radeon_device *rdev,
  942. struct radeon_i2c_bus_rec *i2c_bus)
  943. {
  944. int i;
  945. for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
  946. if (rdev->i2c_bus[i] &&
  947. (rdev->i2c_bus[i]->rec.i2c_id == i2c_bus->i2c_id)) {
  948. return rdev->i2c_bus[i];
  949. }
  950. }
  951. return NULL;
  952. }
  953. struct drm_encoder *radeon_best_encoder(struct drm_connector *connector)
  954. {
  955. return NULL;
  956. }
  957. void radeon_i2c_get_byte(struct radeon_i2c_chan *i2c_bus,
  958. u8 slave_addr,
  959. u8 addr,
  960. u8 *val)
  961. {
  962. u8 out_buf[2];
  963. u8 in_buf[2];
  964. struct i2c_msg msgs[] = {
  965. {
  966. .addr = slave_addr,
  967. .flags = 0,
  968. .len = 1,
  969. .buf = out_buf,
  970. },
  971. {
  972. .addr = slave_addr,
  973. .flags = I2C_M_RD,
  974. .len = 1,
  975. .buf = in_buf,
  976. }
  977. };
  978. out_buf[0] = addr;
  979. out_buf[1] = 0;
  980. if (i2c_transfer(&i2c_bus->adapter, msgs, 2) == 2) {
  981. *val = in_buf[0];
  982. DRM_DEBUG("val = 0x%02x\n", *val);
  983. } else {
  984. DRM_DEBUG("i2c 0x%02x 0x%02x read failed\n",
  985. addr, *val);
  986. }
  987. }
  988. void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c_bus,
  989. u8 slave_addr,
  990. u8 addr,
  991. u8 val)
  992. {
  993. uint8_t out_buf[2];
  994. struct i2c_msg msg = {
  995. .addr = slave_addr,
  996. .flags = 0,
  997. .len = 2,
  998. .buf = out_buf,
  999. };
  1000. out_buf[0] = addr;
  1001. out_buf[1] = val;
  1002. if (i2c_transfer(&i2c_bus->adapter, &msg, 1) != 1)
  1003. DRM_DEBUG("i2c 0x%02x 0x%02x write failed\n",
  1004. addr, val);
  1005. }
  1006. /* ddc router switching */
  1007. void radeon_router_select_ddc_port(struct radeon_connector *radeon_connector)
  1008. {
  1009. u8 val;
  1010. if (!radeon_connector->router.ddc_valid)
  1011. return;
  1012. if (!radeon_connector->router_bus)
  1013. return;
  1014. radeon_i2c_get_byte(radeon_connector->router_bus,
  1015. radeon_connector->router.i2c_addr,
  1016. 0x3, &val);
  1017. val &= ~radeon_connector->router.ddc_mux_control_pin;
  1018. radeon_i2c_put_byte(radeon_connector->router_bus,
  1019. radeon_connector->router.i2c_addr,
  1020. 0x3, val);
  1021. radeon_i2c_get_byte(radeon_connector->router_bus,
  1022. radeon_connector->router.i2c_addr,
  1023. 0x1, &val);
  1024. val &= ~radeon_connector->router.ddc_mux_control_pin;
  1025. val |= radeon_connector->router.ddc_mux_state;
  1026. radeon_i2c_put_byte(radeon_connector->router_bus,
  1027. radeon_connector->router.i2c_addr,
  1028. 0x1, val);
  1029. }
  1030. /* clock/data router switching */
  1031. void radeon_router_select_cd_port(struct radeon_connector *radeon_connector)
  1032. {
  1033. u8 val;
  1034. if (!radeon_connector->router.cd_valid)
  1035. return;
  1036. if (!radeon_connector->router_bus)
  1037. return;
  1038. radeon_i2c_get_byte(radeon_connector->router_bus,
  1039. radeon_connector->router.i2c_addr,
  1040. 0x3, &val);
  1041. val &= ~radeon_connector->router.cd_mux_control_pin;
  1042. radeon_i2c_put_byte(radeon_connector->router_bus,
  1043. radeon_connector->router.i2c_addr,
  1044. 0x3, val);
  1045. radeon_i2c_get_byte(radeon_connector->router_bus,
  1046. radeon_connector->router.i2c_addr,
  1047. 0x1, &val);
  1048. val &= ~radeon_connector->router.cd_mux_control_pin;
  1049. val |= radeon_connector->router.cd_mux_state;
  1050. radeon_i2c_put_byte(radeon_connector->router_bus,
  1051. radeon_connector->router.i2c_addr,
  1052. 0x1, val);
  1053. }