Jean Delvare | b0313f8 | 2008-04-28 02:15:12 -0700 | [diff] [blame] | 1 | #include "radeonfb.h" |
| 2 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | #include <linux/module.h> |
| 4 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/fb.h> |
| 7 | |
| 8 | |
| 9 | #include <linux/i2c.h> |
| 10 | #include <linux/i2c-id.h> |
| 11 | #include <linux/i2c-algo-bit.h> |
| 12 | |
| 13 | #include <asm/io.h> |
| 14 | |
| 15 | #include <video/radeon.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "../edid.h" |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | static void radeon_gpio_setscl(void* data, int state) |
| 19 | { |
| 20 | struct radeon_i2c_chan *chan = data; |
| 21 | struct radeonfb_info *rinfo = chan->rinfo; |
| 22 | u32 val; |
| 23 | |
| 24 | val = INREG(chan->ddc_reg) & ~(VGA_DDC_CLK_OUT_EN); |
| 25 | if (!state) |
| 26 | val |= VGA_DDC_CLK_OUT_EN; |
| 27 | |
| 28 | OUTREG(chan->ddc_reg, val); |
| 29 | (void)INREG(chan->ddc_reg); |
| 30 | } |
| 31 | |
| 32 | static void radeon_gpio_setsda(void* data, int state) |
| 33 | { |
| 34 | struct radeon_i2c_chan *chan = data; |
| 35 | struct radeonfb_info *rinfo = chan->rinfo; |
| 36 | u32 val; |
| 37 | |
| 38 | val = INREG(chan->ddc_reg) & ~(VGA_DDC_DATA_OUT_EN); |
| 39 | if (!state) |
| 40 | val |= VGA_DDC_DATA_OUT_EN; |
| 41 | |
| 42 | OUTREG(chan->ddc_reg, val); |
| 43 | (void)INREG(chan->ddc_reg); |
| 44 | } |
| 45 | |
| 46 | static int radeon_gpio_getscl(void* data) |
| 47 | { |
| 48 | struct radeon_i2c_chan *chan = data; |
| 49 | struct radeonfb_info *rinfo = chan->rinfo; |
| 50 | u32 val; |
| 51 | |
| 52 | val = INREG(chan->ddc_reg); |
| 53 | |
| 54 | return (val & VGA_DDC_CLK_INPUT) ? 1 : 0; |
| 55 | } |
| 56 | |
| 57 | static int radeon_gpio_getsda(void* data) |
| 58 | { |
| 59 | struct radeon_i2c_chan *chan = data; |
| 60 | struct radeonfb_info *rinfo = chan->rinfo; |
| 61 | u32 val; |
| 62 | |
| 63 | val = INREG(chan->ddc_reg); |
| 64 | |
| 65 | return (val & VGA_DDC_DATA_INPUT) ? 1 : 0; |
| 66 | } |
| 67 | |
| 68 | static int radeon_setup_i2c_bus(struct radeon_i2c_chan *chan, const char *name) |
| 69 | { |
| 70 | int rc; |
| 71 | |
Jean Delvare | 9bd6ceb | 2008-08-05 13:01:27 -0700 | [diff] [blame] | 72 | snprintf(chan->adapter.name, sizeof(chan->adapter.name), |
| 73 | "radeonfb %s", name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | chan->adapter.owner = THIS_MODULE; |
Jean Delvare | 1684a984 | 2005-08-11 23:51:10 +0200 | [diff] [blame] | 75 | chan->adapter.id = I2C_HW_B_RADEON; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | chan->adapter.algo_data = &chan->algo; |
| 77 | chan->adapter.dev.parent = &chan->rinfo->pdev->dev; |
| 78 | chan->algo.setsda = radeon_gpio_setsda; |
| 79 | chan->algo.setscl = radeon_gpio_setscl; |
| 80 | chan->algo.getsda = radeon_gpio_getsda; |
| 81 | chan->algo.getscl = radeon_gpio_getscl; |
Jean Delvare | e0745ae | 2008-04-28 02:15:14 -0700 | [diff] [blame] | 82 | chan->algo.udelay = 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | chan->algo.timeout = 20; |
| 84 | chan->algo.data = chan; |
| 85 | |
| 86 | i2c_set_adapdata(&chan->adapter, chan); |
| 87 | |
| 88 | /* Raise SCL and SDA */ |
| 89 | radeon_gpio_setsda(chan, 1); |
| 90 | radeon_gpio_setscl(chan, 1); |
| 91 | udelay(20); |
| 92 | |
| 93 | rc = i2c_bit_add_bus(&chan->adapter); |
| 94 | if (rc == 0) |
| 95 | dev_dbg(&chan->rinfo->pdev->dev, "I2C bus %s registered.\n", name); |
| 96 | else |
| 97 | dev_warn(&chan->rinfo->pdev->dev, "Failed to register I2C bus %s.\n", name); |
| 98 | return rc; |
| 99 | } |
| 100 | |
| 101 | void radeon_create_i2c_busses(struct radeonfb_info *rinfo) |
| 102 | { |
| 103 | rinfo->i2c[0].rinfo = rinfo; |
| 104 | rinfo->i2c[0].ddc_reg = GPIO_MONID; |
| 105 | radeon_setup_i2c_bus(&rinfo->i2c[0], "monid"); |
| 106 | |
| 107 | rinfo->i2c[1].rinfo = rinfo; |
| 108 | rinfo->i2c[1].ddc_reg = GPIO_DVI_DDC; |
| 109 | radeon_setup_i2c_bus(&rinfo->i2c[1], "dvi"); |
| 110 | |
| 111 | rinfo->i2c[2].rinfo = rinfo; |
| 112 | rinfo->i2c[2].ddc_reg = GPIO_VGA_DDC; |
| 113 | radeon_setup_i2c_bus(&rinfo->i2c[2], "vga"); |
| 114 | |
| 115 | rinfo->i2c[3].rinfo = rinfo; |
| 116 | rinfo->i2c[3].ddc_reg = GPIO_CRT2_DDC; |
| 117 | radeon_setup_i2c_bus(&rinfo->i2c[3], "crt2"); |
| 118 | } |
| 119 | |
| 120 | void radeon_delete_i2c_busses(struct radeonfb_info *rinfo) |
| 121 | { |
| 122 | if (rinfo->i2c[0].rinfo) |
Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 123 | i2c_del_adapter(&rinfo->i2c[0].adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | rinfo->i2c[0].rinfo = NULL; |
| 125 | |
| 126 | if (rinfo->i2c[1].rinfo) |
Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 127 | i2c_del_adapter(&rinfo->i2c[1].adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | rinfo->i2c[1].rinfo = NULL; |
| 129 | |
| 130 | if (rinfo->i2c[2].rinfo) |
Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 131 | i2c_del_adapter(&rinfo->i2c[2].adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | rinfo->i2c[2].rinfo = NULL; |
| 133 | |
| 134 | if (rinfo->i2c[3].rinfo) |
Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 135 | i2c_del_adapter(&rinfo->i2c[3].adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | rinfo->i2c[3].rinfo = NULL; |
| 137 | } |
| 138 | |
Dennis Munsie | 7a45093 | 2006-10-03 01:14:46 -0700 | [diff] [blame] | 139 | int radeon_probe_i2c_connector(struct radeonfb_info *rinfo, int conn, |
| 140 | u8 **out_edid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
Benjamin Herrenschmidt | 4f71c5d | 2006-11-17 15:35:00 +1100 | [diff] [blame] | 142 | u8 *edid; |
| 143 | |
Benjamin Herrenschmidt | 4f71c5d | 2006-11-17 15:35:00 +1100 | [diff] [blame] | 144 | edid = fb_ddc_read(&rinfo->i2c[conn-1].adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | if (out_edid) |
| 147 | *out_edid = edid; |
| 148 | if (!edid) { |
Jean Delvare | bc3bf46 | 2008-04-28 02:15:13 -0700 | [diff] [blame] | 149 | pr_debug("radeonfb: I2C (port %d) ... not found\n", conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | return MT_NONE; |
| 151 | } |
| 152 | if (edid[0x14] & 0x80) { |
| 153 | /* Fix detection using BIOS tables */ |
| 154 | if (rinfo->is_mobility /*&& conn == ddc_dvi*/ && |
| 155 | (INREG(LVDS_GEN_CNTL) & LVDS_ON)) { |
Jean Delvare | bc3bf46 | 2008-04-28 02:15:13 -0700 | [diff] [blame] | 156 | pr_debug("radeonfb: I2C (port %d) ... found LVDS panel\n", conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return MT_LCD; |
| 158 | } else { |
Jean Delvare | bc3bf46 | 2008-04-28 02:15:13 -0700 | [diff] [blame] | 159 | pr_debug("radeonfb: I2C (port %d) ... found TMDS panel\n", conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | return MT_DFP; |
| 161 | } |
| 162 | } |
Jean Delvare | bc3bf46 | 2008-04-28 02:15:13 -0700 | [diff] [blame] | 163 | pr_debug("radeonfb: I2C (port %d) ... found CRT display\n", conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | return MT_CRT; |
| 165 | } |
| 166 | |