Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | |
| 3 | Copyright 2006 Dave Airlie <airlied@linux.ie> |
| 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 "Software"), |
| 9 | to deal in the Software without restriction, including without limitation |
| 10 | on the rights to use, copy, modify, merge, publish, distribute, sub |
| 11 | license, and/or sell copies of the Software, and to permit persons to whom |
| 12 | the Software is furnished to do so, subject to the following conditions: |
| 13 | |
| 14 | The above copyright notice and this permission notice (including the next |
| 15 | paragraph) shall be included in all copies or substantial portions of the |
| 16 | Software. |
| 17 | |
| 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 21 | THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 22 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 23 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 24 | USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | |
| 26 | **************************************************************************/ |
| 27 | |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/kernel.h> |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 30 | #include <linux/delay.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/fb.h> |
| 33 | |
| 34 | #include <linux/i2c.h> |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 35 | #include <linux/i2c-algo-bit.h> |
| 36 | |
| 37 | #include <asm/io.h> |
| 38 | |
| 39 | #include "intelfb.h" |
| 40 | #include "intelfbhw.h" |
| 41 | |
| 42 | /* bit locations in the registers */ |
| 43 | #define SCL_DIR_MASK 0x0001 |
| 44 | #define SCL_DIR 0x0002 |
| 45 | #define SCL_VAL_MASK 0x0004 |
| 46 | #define SCL_VAL_OUT 0x0008 |
| 47 | #define SCL_VAL_IN 0x0010 |
| 48 | #define SDA_DIR_MASK 0x0100 |
| 49 | #define SDA_DIR 0x0200 |
| 50 | #define SDA_VAL_MASK 0x0400 |
| 51 | #define SDA_VAL_OUT 0x0800 |
| 52 | #define SDA_VAL_IN 0x1000 |
| 53 | |
| 54 | static void intelfb_gpio_setscl(void *data, int state) |
| 55 | { |
| 56 | struct intelfb_i2c_chan *chan = data; |
| 57 | struct intelfb_info *dinfo = chan->dinfo; |
| 58 | u32 val; |
| 59 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 60 | OUTREG(chan->reg, (state ? SCL_VAL_OUT : 0) | |
| 61 | SCL_DIR | SCL_DIR_MASK | SCL_VAL_MASK); |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 62 | val = INREG(chan->reg); |
| 63 | } |
| 64 | |
| 65 | static void intelfb_gpio_setsda(void *data, int state) |
| 66 | { |
| 67 | struct intelfb_i2c_chan *chan = data; |
| 68 | struct intelfb_info *dinfo = chan->dinfo; |
| 69 | u32 val; |
| 70 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 71 | OUTREG(chan->reg, (state ? SDA_VAL_OUT : 0) | |
| 72 | SDA_DIR | SDA_DIR_MASK | SDA_VAL_MASK); |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 73 | val = INREG(chan->reg); |
| 74 | } |
| 75 | |
| 76 | static int intelfb_gpio_getscl(void *data) |
| 77 | { |
| 78 | struct intelfb_i2c_chan *chan = data; |
| 79 | struct intelfb_info *dinfo = chan->dinfo; |
| 80 | u32 val; |
| 81 | |
| 82 | OUTREG(chan->reg, SCL_DIR_MASK); |
| 83 | OUTREG(chan->reg, 0); |
| 84 | val = INREG(chan->reg); |
| 85 | return ((val & SCL_VAL_IN) != 0); |
| 86 | } |
| 87 | |
| 88 | static int intelfb_gpio_getsda(void *data) |
| 89 | { |
| 90 | struct intelfb_i2c_chan *chan = data; |
| 91 | struct intelfb_info *dinfo = chan->dinfo; |
| 92 | u32 val; |
| 93 | |
| 94 | OUTREG(chan->reg, SDA_DIR_MASK); |
| 95 | OUTREG(chan->reg, 0); |
| 96 | val = INREG(chan->reg); |
| 97 | return ((val & SDA_VAL_IN) != 0); |
| 98 | } |
| 99 | |
| 100 | static int intelfb_setup_i2c_bus(struct intelfb_info *dinfo, |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 101 | struct intelfb_i2c_chan *chan, |
Jean Delvare | c1b6b4f | 2008-07-14 22:38:28 +0200 | [diff] [blame] | 102 | const u32 reg, const char *name, |
| 103 | int class) |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 104 | { |
| 105 | int rc; |
| 106 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 107 | chan->dinfo = dinfo; |
| 108 | chan->reg = reg; |
David Brownell | 2096b95 | 2007-05-01 23:26:28 +0200 | [diff] [blame] | 109 | snprintf(chan->adapter.name, sizeof(chan->adapter.name), |
| 110 | "intelfb %s", name); |
Jean Delvare | c1b6b4f | 2008-07-14 22:38:28 +0200 | [diff] [blame] | 111 | chan->adapter.class = class; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 112 | chan->adapter.owner = THIS_MODULE; |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 113 | chan->adapter.algo_data = &chan->algo; |
| 114 | chan->adapter.dev.parent = &chan->dinfo->pdev->dev; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 115 | chan->algo.setsda = intelfb_gpio_setsda; |
| 116 | chan->algo.setscl = intelfb_gpio_setscl; |
| 117 | chan->algo.getsda = intelfb_gpio_getsda; |
| 118 | chan->algo.getscl = intelfb_gpio_getscl; |
| 119 | chan->algo.udelay = 40; |
| 120 | chan->algo.timeout = 20; |
| 121 | chan->algo.data = chan; |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 122 | |
| 123 | i2c_set_adapdata(&chan->adapter, chan); |
| 124 | |
| 125 | /* Raise SCL and SDA */ |
| 126 | intelfb_gpio_setsda(chan, 1); |
| 127 | intelfb_gpio_setscl(chan, 1); |
| 128 | udelay(20); |
| 129 | |
| 130 | rc = i2c_bit_add_bus(&chan->adapter); |
| 131 | if (rc == 0) |
| 132 | DBG_MSG("I2C bus %s registered.\n", name); |
| 133 | else |
| 134 | WRN_MSG("Failed to register I2C bus %s.\n", name); |
| 135 | return rc; |
| 136 | } |
| 137 | |
| 138 | void intelfb_create_i2c_busses(struct intelfb_info *dinfo) |
| 139 | { |
| 140 | int i = 0; |
| 141 | |
| 142 | /* everyone has at least a single analog output */ |
| 143 | dinfo->num_outputs = 1; |
| 144 | dinfo->output[i].type = INTELFB_OUTPUT_ANALOG; |
| 145 | |
| 146 | /* setup the DDC bus for analog output */ |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 147 | intelfb_setup_i2c_bus(dinfo, &dinfo->output[i].ddc_bus, GPIOA, |
Jean Delvare | c1b6b4f | 2008-07-14 22:38:28 +0200 | [diff] [blame] | 148 | "CRTDDC_A", I2C_CLASS_DDC); |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 149 | i++; |
| 150 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 151 | /* need to add the output busses for each device |
| 152 | - this function is very incomplete |
| 153 | - i915GM has LVDS and TVOUT for example |
| 154 | */ |
| 155 | switch(dinfo->chipset) { |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 156 | case INTEL_830M: |
| 157 | case INTEL_845G: |
Stefan Husemann | 347486b | 2009-04-13 14:40:10 -0700 | [diff] [blame] | 158 | case INTEL_854: |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 159 | case INTEL_855GM: |
| 160 | case INTEL_865G: |
| 161 | dinfo->output[i].type = INTELFB_OUTPUT_DVO; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 162 | intelfb_setup_i2c_bus(dinfo, &dinfo->output[i].ddc_bus, |
Jean Delvare | c1b6b4f | 2008-07-14 22:38:28 +0200 | [diff] [blame] | 163 | GPIOD, "DVODDC_D", I2C_CLASS_DDC); |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 164 | intelfb_setup_i2c_bus(dinfo, &dinfo->output[i].i2c_bus, |
Jean Delvare | c1b6b4f | 2008-07-14 22:38:28 +0200 | [diff] [blame] | 165 | GPIOE, "DVOI2C_E", 0); |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 166 | i++; |
| 167 | break; |
| 168 | case INTEL_915G: |
| 169 | case INTEL_915GM: |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 170 | /* has some LVDS + tv-out */ |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 171 | case INTEL_945G: |
| 172 | case INTEL_945GM: |
Phil Endecott | 3f7a26b | 2008-10-15 22:03:35 -0700 | [diff] [blame] | 173 | case INTEL_945GME: |
Maik Broemme | 0e170c7 | 2008-04-28 02:15:43 -0700 | [diff] [blame] | 174 | case INTEL_965G: |
| 175 | case INTEL_965GM: |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 176 | /* SDVO ports have a single control bus - 2 devices */ |
| 177 | dinfo->output[i].type = INTELFB_OUTPUT_SDVO; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 178 | intelfb_setup_i2c_bus(dinfo, &dinfo->output[i].i2c_bus, |
Jean Delvare | c1b6b4f | 2008-07-14 22:38:28 +0200 | [diff] [blame] | 179 | GPIOE, "SDVOCTRL_E", 0); |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 180 | /* TODO: initialize the SDVO */ |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 181 | /* I830SDVOInit(pScrn, i, DVOB); */ |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 182 | i++; |
| 183 | |
| 184 | /* set up SDVOC */ |
| 185 | dinfo->output[i].type = INTELFB_OUTPUT_SDVO; |
| 186 | dinfo->output[i].i2c_bus = dinfo->output[i - 1].i2c_bus; |
| 187 | /* TODO: initialize the SDVO */ |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 188 | /* I830SDVOInit(pScrn, i, DVOC); */ |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 189 | i++; |
| 190 | break; |
| 191 | } |
| 192 | dinfo->num_outputs = i; |
| 193 | } |
Dennis Munsie | 7627899 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 194 | |
| 195 | void intelfb_delete_i2c_busses(struct intelfb_info *dinfo) |
| 196 | { |
| 197 | int i; |
| 198 | |
| 199 | for (i = 0; i < MAX_OUTPUTS; i++) { |
| 200 | if (dinfo->output[i].i2c_bus.dinfo) { |
Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 201 | i2c_del_adapter(&dinfo->output[i].i2c_bus.adapter); |
Dennis Munsie | 7627899 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 202 | dinfo->output[i].i2c_bus.dinfo = NULL; |
| 203 | } |
| 204 | if (dinfo->output[i].ddc_bus.dinfo) { |
Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 205 | i2c_del_adapter(&dinfo->output[i].ddc_bus.adapter); |
Dennis Munsie | 7627899 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 206 | dinfo->output[i].ddc_bus.dinfo = NULL; |
| 207 | } |
| 208 | } |
| 209 | } |