radeon_i2c.c 29 KB

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