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