radeon_i2c.c 29 KB

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