Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | |
| 3 | Copyright © 2006 Dave Airlie |
| 4 | |
| 5 | All Rights Reserved. |
| 6 | |
| 7 | Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | copy of this software and associated documentation files (the |
| 9 | "Software"), to deal in the Software without restriction, including |
| 10 | without limitation the rights to use, copy, modify, merge, publish, |
| 11 | distribute, sub license, and/or sell copies of the Software, and to |
| 12 | permit persons to whom the Software is furnished to do so, subject to |
| 13 | the following conditions: |
| 14 | |
| 15 | The above copyright notice and this permission notice (including the |
| 16 | next paragraph) shall be included in all copies or substantial portions |
| 17 | of the Software. |
| 18 | |
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 22 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 23 | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 24 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 25 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 26 | |
| 27 | **************************************************************************/ |
| 28 | |
| 29 | #include "dvo.h" |
| 30 | |
| 31 | #define SIL164_VID 0x0001 |
| 32 | #define SIL164_DID 0x0006 |
| 33 | |
| 34 | #define SIL164_VID_LO 0x00 |
| 35 | #define SIL164_VID_HI 0x01 |
| 36 | #define SIL164_DID_LO 0x02 |
| 37 | #define SIL164_DID_HI 0x03 |
| 38 | #define SIL164_REV 0x04 |
| 39 | #define SIL164_RSVD 0x05 |
| 40 | #define SIL164_FREQ_LO 0x06 |
| 41 | #define SIL164_FREQ_HI 0x07 |
| 42 | |
| 43 | #define SIL164_REG8 0x08 |
| 44 | #define SIL164_8_VEN (1<<5) |
| 45 | #define SIL164_8_HEN (1<<4) |
| 46 | #define SIL164_8_DSEL (1<<3) |
| 47 | #define SIL164_8_BSEL (1<<2) |
| 48 | #define SIL164_8_EDGE (1<<1) |
| 49 | #define SIL164_8_PD (1<<0) |
| 50 | |
| 51 | #define SIL164_REG9 0x09 |
| 52 | #define SIL164_9_VLOW (1<<7) |
| 53 | #define SIL164_9_MSEL_MASK (0x7<<4) |
| 54 | #define SIL164_9_TSEL (1<<3) |
| 55 | #define SIL164_9_RSEN (1<<2) |
| 56 | #define SIL164_9_HTPLG (1<<1) |
| 57 | #define SIL164_9_MDI (1<<0) |
| 58 | |
| 59 | #define SIL164_REGC 0x0c |
| 60 | |
| 61 | struct sil164_save_rec { |
| 62 | uint8_t reg8; |
| 63 | uint8_t reg9; |
| 64 | uint8_t regc; |
| 65 | }; |
| 66 | |
| 67 | struct sil164_priv { |
| 68 | //I2CDevRec d; |
| 69 | bool quiet; |
| 70 | struct sil164_save_rec save_regs; |
| 71 | struct sil164_save_rec mode_regs; |
| 72 | }; |
| 73 | |
| 74 | #define SILPTR(d) ((SIL164Ptr)(d->DriverPrivate.ptr)) |
| 75 | |
| 76 | static bool sil164_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch) |
| 77 | { |
| 78 | struct sil164_priv *sil = dvo->dev_priv; |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 79 | struct i2c_adapter *adapter = dvo->i2c_bus; |
| 80 | struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 81 | u8 out_buf[2]; |
| 82 | u8 in_buf[2]; |
| 83 | |
| 84 | struct i2c_msg msgs[] = { |
| 85 | { |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 86 | .addr = dvo->slave_addr, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 87 | .flags = 0, |
| 88 | .len = 1, |
| 89 | .buf = out_buf, |
| 90 | }, |
| 91 | { |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 92 | .addr = dvo->slave_addr, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 93 | .flags = I2C_M_RD, |
| 94 | .len = 1, |
| 95 | .buf = in_buf, |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | out_buf[0] = addr; |
| 100 | out_buf[1] = 0; |
| 101 | |
| 102 | if (i2c_transfer(&i2cbus->adapter, msgs, 2) == 2) { |
| 103 | *ch = in_buf[0]; |
| 104 | return true; |
| 105 | }; |
| 106 | |
| 107 | if (!sil->quiet) { |
Zhao Yakui | d0c3b04 | 2009-10-09 11:39:43 +0800 | [diff] [blame^] | 108 | DRM_DEBUG_KMS("Unable to read register 0x%02x from %s:%02x.\n", |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 109 | addr, i2cbus->adapter.name, dvo->slave_addr); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 110 | } |
| 111 | return false; |
| 112 | } |
| 113 | |
| 114 | static bool sil164_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch) |
| 115 | { |
| 116 | struct sil164_priv *sil= dvo->dev_priv; |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 117 | struct i2c_adapter *adapter = dvo->i2c_bus; |
| 118 | struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 119 | uint8_t out_buf[2]; |
| 120 | struct i2c_msg msg = { |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 121 | .addr = dvo->slave_addr, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 122 | .flags = 0, |
| 123 | .len = 2, |
| 124 | .buf = out_buf, |
| 125 | }; |
| 126 | |
| 127 | out_buf[0] = addr; |
| 128 | out_buf[1] = ch; |
| 129 | |
| 130 | if (i2c_transfer(&i2cbus->adapter, &msg, 1) == 1) |
| 131 | return true; |
| 132 | |
| 133 | if (!sil->quiet) { |
Zhao Yakui | d0c3b04 | 2009-10-09 11:39:43 +0800 | [diff] [blame^] | 134 | DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d.\n", |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 135 | addr, i2cbus->adapter.name, dvo->slave_addr); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | /* Silicon Image 164 driver for chip on i2c bus */ |
| 142 | static bool sil164_init(struct intel_dvo_device *dvo, |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 143 | struct i2c_adapter *adapter) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 144 | { |
| 145 | /* this will detect the SIL164 chip on the specified i2c bus */ |
| 146 | struct sil164_priv *sil; |
| 147 | unsigned char ch; |
| 148 | |
| 149 | sil = kzalloc(sizeof(struct sil164_priv), GFP_KERNEL); |
| 150 | if (sil == NULL) |
| 151 | return false; |
| 152 | |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 153 | dvo->i2c_bus = adapter; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 154 | dvo->dev_priv = sil; |
| 155 | sil->quiet = true; |
| 156 | |
| 157 | if (!sil164_readb(dvo, SIL164_VID_LO, &ch)) |
| 158 | goto out; |
| 159 | |
| 160 | if (ch != (SIL164_VID & 0xff)) { |
Zhao Yakui | d0c3b04 | 2009-10-09 11:39:43 +0800 | [diff] [blame^] | 161 | DRM_DEBUG_KMS("sil164 not detected got %d: from %s Slave %d.\n", |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 162 | ch, adapter->name, dvo->slave_addr); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 163 | goto out; |
| 164 | } |
| 165 | |
| 166 | if (!sil164_readb(dvo, SIL164_DID_LO, &ch)) |
| 167 | goto out; |
| 168 | |
| 169 | if (ch != (SIL164_DID & 0xff)) { |
Zhao Yakui | d0c3b04 | 2009-10-09 11:39:43 +0800 | [diff] [blame^] | 170 | DRM_DEBUG_KMS("sil164 not detected got %d: from %s Slave %d.\n", |
Keith Packard | f9c10a9 | 2009-05-30 12:16:25 -0700 | [diff] [blame] | 171 | ch, adapter->name, dvo->slave_addr); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 172 | goto out; |
| 173 | } |
| 174 | sil->quiet = false; |
| 175 | |
Zhao Yakui | d0c3b04 | 2009-10-09 11:39:43 +0800 | [diff] [blame^] | 176 | DRM_DEBUG_KMS("init sil164 dvo controller successfully!\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 177 | return true; |
| 178 | |
| 179 | out: |
| 180 | kfree(sil); |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | static enum drm_connector_status sil164_detect(struct intel_dvo_device *dvo) |
| 185 | { |
| 186 | uint8_t reg9; |
| 187 | |
| 188 | sil164_readb(dvo, SIL164_REG9, ®9); |
| 189 | |
| 190 | if (reg9 & SIL164_9_HTPLG) |
| 191 | return connector_status_connected; |
| 192 | else |
| 193 | return connector_status_disconnected; |
| 194 | } |
| 195 | |
| 196 | static enum drm_mode_status sil164_mode_valid(struct intel_dvo_device *dvo, |
| 197 | struct drm_display_mode *mode) |
| 198 | { |
| 199 | return MODE_OK; |
| 200 | } |
| 201 | |
| 202 | static void sil164_mode_set(struct intel_dvo_device *dvo, |
| 203 | struct drm_display_mode *mode, |
| 204 | struct drm_display_mode *adjusted_mode) |
| 205 | { |
| 206 | /* As long as the basics are set up, since we don't have clock |
| 207 | * dependencies in the mode setup, we can just leave the |
| 208 | * registers alone and everything will work fine. |
| 209 | */ |
| 210 | /* recommended programming sequence from doc */ |
| 211 | /*sil164_writeb(sil, 0x08, 0x30); |
| 212 | sil164_writeb(sil, 0x09, 0x00); |
| 213 | sil164_writeb(sil, 0x0a, 0x90); |
| 214 | sil164_writeb(sil, 0x0c, 0x89); |
| 215 | sil164_writeb(sil, 0x08, 0x31);*/ |
| 216 | /* don't do much */ |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | /* set the SIL164 power state */ |
| 221 | static void sil164_dpms(struct intel_dvo_device *dvo, int mode) |
| 222 | { |
| 223 | int ret; |
| 224 | unsigned char ch; |
| 225 | |
| 226 | ret = sil164_readb(dvo, SIL164_REG8, &ch); |
| 227 | if (ret == false) |
| 228 | return; |
| 229 | |
| 230 | if (mode == DRM_MODE_DPMS_ON) |
| 231 | ch |= SIL164_8_PD; |
| 232 | else |
| 233 | ch &= ~SIL164_8_PD; |
| 234 | |
| 235 | sil164_writeb(dvo, SIL164_REG8, ch); |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | static void sil164_dump_regs(struct intel_dvo_device *dvo) |
| 240 | { |
| 241 | uint8_t val; |
| 242 | |
| 243 | sil164_readb(dvo, SIL164_FREQ_LO, &val); |
Zhao Yakui | d0c3b04 | 2009-10-09 11:39:43 +0800 | [diff] [blame^] | 244 | DRM_LOG_KMS("SIL164_FREQ_LO: 0x%02x\n", val); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 245 | sil164_readb(dvo, SIL164_FREQ_HI, &val); |
Zhao Yakui | d0c3b04 | 2009-10-09 11:39:43 +0800 | [diff] [blame^] | 246 | DRM_LOG_KMS("SIL164_FREQ_HI: 0x%02x\n", val); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 247 | sil164_readb(dvo, SIL164_REG8, &val); |
Zhao Yakui | d0c3b04 | 2009-10-09 11:39:43 +0800 | [diff] [blame^] | 248 | DRM_LOG_KMS("SIL164_REG8: 0x%02x\n", val); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 249 | sil164_readb(dvo, SIL164_REG9, &val); |
Zhao Yakui | d0c3b04 | 2009-10-09 11:39:43 +0800 | [diff] [blame^] | 250 | DRM_LOG_KMS("SIL164_REG9: 0x%02x\n", val); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 251 | sil164_readb(dvo, SIL164_REGC, &val); |
Zhao Yakui | d0c3b04 | 2009-10-09 11:39:43 +0800 | [diff] [blame^] | 252 | DRM_LOG_KMS("SIL164_REGC: 0x%02x\n", val); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | static void sil164_save(struct intel_dvo_device *dvo) |
| 256 | { |
| 257 | struct sil164_priv *sil= dvo->dev_priv; |
| 258 | |
| 259 | if (!sil164_readb(dvo, SIL164_REG8, &sil->save_regs.reg8)) |
| 260 | return; |
| 261 | |
| 262 | if (!sil164_readb(dvo, SIL164_REG9, &sil->save_regs.reg9)) |
| 263 | return; |
| 264 | |
| 265 | if (!sil164_readb(dvo, SIL164_REGC, &sil->save_regs.regc)) |
| 266 | return; |
| 267 | |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | static void sil164_restore(struct intel_dvo_device *dvo) |
| 272 | { |
| 273 | struct sil164_priv *sil = dvo->dev_priv; |
| 274 | |
| 275 | /* Restore it powered down initially */ |
| 276 | sil164_writeb(dvo, SIL164_REG8, sil->save_regs.reg8 & ~0x1); |
| 277 | |
| 278 | sil164_writeb(dvo, SIL164_REG9, sil->save_regs.reg9); |
| 279 | sil164_writeb(dvo, SIL164_REGC, sil->save_regs.regc); |
| 280 | sil164_writeb(dvo, SIL164_REG8, sil->save_regs.reg8); |
| 281 | } |
| 282 | |
| 283 | static void sil164_destroy(struct intel_dvo_device *dvo) |
| 284 | { |
| 285 | struct sil164_priv *sil = dvo->dev_priv; |
| 286 | |
| 287 | if (sil) { |
| 288 | kfree(sil); |
| 289 | dvo->dev_priv = NULL; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | struct intel_dvo_dev_ops sil164_ops = { |
| 294 | .init = sil164_init, |
| 295 | .detect = sil164_detect, |
| 296 | .mode_valid = sil164_mode_valid, |
| 297 | .mode_set = sil164_mode_set, |
| 298 | .dpms = sil164_dpms, |
| 299 | .dump_regs = sil164_dump_regs, |
| 300 | .save = sil164_save, |
| 301 | .restore = sil164_restore, |
| 302 | .destroy = sil164_destroy, |
| 303 | }; |