Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/gma500: add support for atom e6xx lpc lvds i2c

add gpio bitbanging i2c adapter on LPC device of atom e6xx
gpu chipset to access lvds EDID
tested on SECO QuadMo747-E6xx-EXTREME Qseven platform

Reviewed-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Signed-off-by: Jan Safrata <jan.nikitenko@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>

authored by

Jan Safrata and committed by
Dave Airlie
5a52b1f2 e8115e79

+214 -12
+1
drivers/gpu/drm/gma500/Makefile
··· 39 39 gma500_gfx-$(CONFIG_DRM_GMA600) += oaktrail_device.o \ 40 40 oaktrail_crtc.o \ 41 41 oaktrail_lvds.o \ 42 + oaktrail_lvds_i2c.o \ 42 43 oaktrail_hdmi.o \ 43 44 oaktrail_hdmi_i2c.o 44 45
+19 -12
drivers/gpu/drm/gma500/oaktrail_lvds.c
··· 359 359 * if closed, act like it's not there for now 360 360 */ 361 361 362 + edid = NULL; 362 363 mutex_lock(&dev->mode_config.mutex); 363 364 i2c_adap = i2c_get_adapter(dev_priv->ops->i2c_bus); 364 - if (i2c_adap == NULL) 365 - dev_err(dev->dev, "No ddc adapter available!\n"); 365 + if (i2c_adap) 366 + edid = drm_get_edid(connector, i2c_adap); 367 + if (edid == NULL && dev_priv->lpc_gpio_base) { 368 + oaktrail_lvds_i2c_init(encoder); 369 + if (gma_encoder->ddc_bus != NULL) { 370 + i2c_adap = &gma_encoder->ddc_bus->adapter; 371 + edid = drm_get_edid(connector, i2c_adap); 372 + } 373 + } 366 374 /* 367 375 * Attempt to get the fixed panel mode from DDC. Assume that the 368 376 * preferred mode is the right one. 369 377 */ 370 - if (i2c_adap) { 371 - edid = drm_get_edid(connector, i2c_adap); 372 - if (edid) { 373 - drm_mode_connector_update_edid_property(connector, 374 - edid); 375 - drm_add_edid_modes(connector, edid); 376 - kfree(edid); 377 - } 378 + if (edid) { 379 + drm_mode_connector_update_edid_property(connector, edid); 380 + drm_add_edid_modes(connector, edid); 381 + kfree(edid); 378 382 379 383 list_for_each_entry(scan, &connector->probed_modes, head) { 380 384 if (scan->type & DRM_MODE_TYPE_PREFERRED) { ··· 387 383 goto out; /* FIXME: check for quirks */ 388 384 } 389 385 } 390 - } 386 + } else 387 + dev_err(dev->dev, "No ddc adapter available!\n"); 391 388 /* 392 389 * If we didn't get EDID, try geting panel timing 393 390 * from configuration data ··· 416 411 mutex_unlock(&dev->mode_config.mutex); 417 412 418 413 dev_dbg(dev->dev, "No LVDS modes found, disabling.\n"); 419 - if (gma_encoder->ddc_bus) 414 + if (gma_encoder->ddc_bus) { 420 415 psb_intel_i2c_destroy(gma_encoder->ddc_bus); 416 + gma_encoder->ddc_bus = NULL; 417 + } 421 418 422 419 /* failed_ddc: */ 423 420
+170
drivers/gpu/drm/gma500/oaktrail_lvds_i2c.c
··· 1 + /* 2 + * Copyright (c) 2002-2010, Intel Corporation. 3 + * Copyright (c) 2014 ATRON electronic GmbH 4 + * Author: Jan Safrata <jan.nikitenko@gmail.com> 5 + * 6 + * Permission is hereby granted, free of charge, to any person obtaining a copy 7 + * of this software and associated documentation files (the "Software"), to deal 8 + * in the Software without restriction, including without limitation the rights 9 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 + * copies of the Software, and to permit persons to whom the Software is 11 + * furnished to do so, subject to the following conditions: 12 + * 13 + * The above copyright notice and this permission notice shall be included in 14 + * all copies or substantial portions of the Software. 15 + * 16 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 + * THE SOFTWARE. 23 + * 24 + */ 25 + 26 + #include <linux/kernel.h> 27 + #include <linux/module.h> 28 + #include <linux/pci.h> 29 + #include <linux/types.h> 30 + #include <linux/i2c.h> 31 + #include <linux/i2c-algo-bit.h> 32 + #include <linux/init.h> 33 + #include <linux/io.h> 34 + #include <linux/delay.h> 35 + 36 + #include <drm/drmP.h> 37 + #include "psb_drv.h" 38 + #include "psb_intel_reg.h" 39 + 40 + 41 + /* 42 + * LPC GPIO based I2C bus for LVDS of Atom E6xx 43 + */ 44 + 45 + /*----------------------------------------------------------------------------- 46 + * LPC Register Offsets. Used for LVDS GPIO Bit Bashing. Registers are part 47 + * Atom E6xx [D31:F0] 48 + ----------------------------------------------------------------------------*/ 49 + #define RGEN 0x20 50 + #define RGIO 0x24 51 + #define RGLVL 0x28 52 + #define RGTPE 0x2C 53 + #define RGTNE 0x30 54 + #define RGGPE 0x34 55 + #define RGSMI 0x38 56 + #define RGTS 0x3C 57 + 58 + /* The LVDS GPIO clock lines are GPIOSUS[3] 59 + * The LVDS GPIO data lines are GPIOSUS[4] 60 + */ 61 + #define GPIO_CLOCK 0x08 62 + #define GPIO_DATA 0x10 63 + 64 + #define LPC_READ_REG(chan, r) inl((chan)->reg + (r)) 65 + #define LPC_WRITE_REG(chan, r, val) outl((val), (chan)->reg + (r)) 66 + 67 + static int get_clock(void *data) 68 + { 69 + struct psb_intel_i2c_chan *chan = data; 70 + u32 val, tmp; 71 + 72 + val = LPC_READ_REG(chan, RGIO); 73 + val |= GPIO_CLOCK; 74 + LPC_WRITE_REG(chan, RGIO, val); 75 + tmp = LPC_READ_REG(chan, RGLVL); 76 + val = (LPC_READ_REG(chan, RGLVL) & GPIO_CLOCK) ? 1 : 0; 77 + 78 + return val; 79 + } 80 + 81 + static int get_data(void *data) 82 + { 83 + struct psb_intel_i2c_chan *chan = data; 84 + u32 val, tmp; 85 + 86 + val = LPC_READ_REG(chan, RGIO); 87 + val |= GPIO_DATA; 88 + LPC_WRITE_REG(chan, RGIO, val); 89 + tmp = LPC_READ_REG(chan, RGLVL); 90 + val = (LPC_READ_REG(chan, RGLVL) & GPIO_DATA) ? 1 : 0; 91 + 92 + return val; 93 + } 94 + 95 + static void set_clock(void *data, int state_high) 96 + { 97 + struct psb_intel_i2c_chan *chan = data; 98 + u32 val; 99 + 100 + if (state_high) { 101 + val = LPC_READ_REG(chan, RGIO); 102 + val |= GPIO_CLOCK; 103 + LPC_WRITE_REG(chan, RGIO, val); 104 + } else { 105 + val = LPC_READ_REG(chan, RGIO); 106 + val &= ~GPIO_CLOCK; 107 + LPC_WRITE_REG(chan, RGIO, val); 108 + val = LPC_READ_REG(chan, RGLVL); 109 + val &= ~GPIO_CLOCK; 110 + LPC_WRITE_REG(chan, RGLVL, val); 111 + } 112 + } 113 + 114 + static void set_data(void *data, int state_high) 115 + { 116 + struct psb_intel_i2c_chan *chan = data; 117 + u32 val; 118 + 119 + if (state_high) { 120 + val = LPC_READ_REG(chan, RGIO); 121 + val |= GPIO_DATA; 122 + LPC_WRITE_REG(chan, RGIO, val); 123 + } else { 124 + val = LPC_READ_REG(chan, RGIO); 125 + val &= ~GPIO_DATA; 126 + LPC_WRITE_REG(chan, RGIO, val); 127 + val = LPC_READ_REG(chan, RGLVL); 128 + val &= ~GPIO_DATA; 129 + LPC_WRITE_REG(chan, RGLVL, val); 130 + } 131 + } 132 + 133 + void oaktrail_lvds_i2c_init(struct drm_encoder *encoder) 134 + { 135 + struct drm_device *dev = encoder->dev; 136 + struct gma_encoder *gma_encoder = to_gma_encoder(encoder); 137 + struct drm_psb_private *dev_priv = dev->dev_private; 138 + struct psb_intel_i2c_chan *chan; 139 + 140 + chan = kzalloc(sizeof(struct psb_intel_i2c_chan), GFP_KERNEL); 141 + if (!chan) 142 + return; 143 + 144 + chan->drm_dev = dev; 145 + chan->reg = dev_priv->lpc_gpio_base; 146 + strncpy(chan->adapter.name, "gma500 LPC", I2C_NAME_SIZE - 1); 147 + chan->adapter.owner = THIS_MODULE; 148 + chan->adapter.algo_data = &chan->algo; 149 + chan->adapter.dev.parent = &dev->pdev->dev; 150 + chan->algo.setsda = set_data; 151 + chan->algo.setscl = set_clock; 152 + chan->algo.getsda = get_data; 153 + chan->algo.getscl = get_clock; 154 + chan->algo.udelay = 100; 155 + chan->algo.timeout = usecs_to_jiffies(2200); 156 + chan->algo.data = chan; 157 + 158 + i2c_set_adapdata(&chan->adapter, chan); 159 + 160 + set_data(chan, 1); 161 + set_clock(chan, 1); 162 + udelay(50); 163 + 164 + if (i2c_bit_add_bus(&chan->adapter)) { 165 + kfree(chan); 166 + return; 167 + } 168 + 169 + gma_encoder->ddc_bus = chan; 170 + }
+20
drivers/gpu/drm/gma500/psb_drv.c
··· 212 212 } 213 213 if (dev_priv->aux_pdev) 214 214 pci_dev_put(dev_priv->aux_pdev); 215 + if (dev_priv->lpc_pdev) 216 + pci_dev_put(dev_priv->lpc_pdev); 215 217 216 218 /* Destroy VBT data */ 217 219 psb_intel_destroy_bios(dev); ··· 282 280 DRM_DEBUG_KMS("Couldn't find aux pci device"); 283 281 } 284 282 dev_priv->gmbus_reg = dev_priv->aux_reg; 283 + 284 + dev_priv->lpc_pdev = pci_get_bus_and_slot(0, PCI_DEVFN(31, 0)); 285 + if (dev_priv->lpc_pdev) { 286 + pci_read_config_word(dev_priv->lpc_pdev, PSB_LPC_GBA, 287 + &dev_priv->lpc_gpio_base); 288 + pci_write_config_dword(dev_priv->lpc_pdev, PSB_LPC_GBA, 289 + (u32)dev_priv->lpc_gpio_base | (1L<<31)); 290 + pci_read_config_word(dev_priv->lpc_pdev, PSB_LPC_GBA, 291 + &dev_priv->lpc_gpio_base); 292 + dev_priv->lpc_gpio_base &= 0xffc0; 293 + if (dev_priv->lpc_gpio_base) 294 + DRM_DEBUG_KMS("Found LPC GPIO at 0x%04x\n", 295 + dev_priv->lpc_gpio_base); 296 + else { 297 + pci_dev_put(dev_priv->lpc_pdev); 298 + dev_priv->lpc_pdev = NULL; 299 + } 300 + } 285 301 } else { 286 302 dev_priv->gmbus_reg = dev_priv->vdc_reg; 287 303 }
+3
drivers/gpu/drm/gma500/psb_drv.h
··· 83 83 #define PSB_PGETBL_CTL 0x2020 84 84 #define _PSB_PGETBL_ENABLED 0x00000001 85 85 #define PSB_SGX_2D_SLAVE_PORT 0x4000 86 + #define PSB_LPC_GBA 0x44 86 87 87 88 /* TODO: To get rid of */ 88 89 #define PSB_TT_PRIV0_LIMIT (256*1024*1024) ··· 442 441 struct drm_psb_private { 443 442 struct drm_device *dev; 444 443 struct pci_dev *aux_pdev; /* Currently only used by mrst */ 444 + struct pci_dev *lpc_pdev; /* Currently only used by mrst */ 445 445 const struct psb_ops *ops; 446 446 const struct psb_offset *regmap; 447 447 ··· 472 470 uint8_t __iomem *sgx_reg; 473 471 uint8_t __iomem *vdc_reg; 474 472 uint8_t __iomem *aux_reg; /* Auxillary vdc pipe regs */ 473 + uint16_t lpc_gpio_base; 475 474 uint32_t gatt_free_offset; 476 475 477 476 /* Fencing / irq */
+1
drivers/gpu/drm/gma500/psb_intel_drv.h
··· 223 223 extern void oaktrail_wait_for_INTR_PKT_SENT(struct drm_device *dev); 224 224 extern void oaktrail_dsi_init(struct drm_device *dev, 225 225 struct psb_intel_mode_device *mode_dev); 226 + extern void oaktrail_lvds_i2c_init(struct drm_encoder *encoder); 226 227 extern void mid_dsi_init(struct drm_device *dev, 227 228 struct psb_intel_mode_device *mode_dev, int dsi_num); 228 229