Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 1 | /*-*- linux-c -*- |
| 2 | * linux/drivers/video/i810-i2c.c -- Intel 810/815 I2C support |
| 3 | * |
| 4 | * Copyright (C) 2004 Antonino Daplas<adaplas@pol.net> |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This file is subject to the terms and conditions of the GNU General Public |
| 8 | * License. See the file COPYING in the main directory of this archive for |
| 9 | * more details. |
| 10 | */ |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/kernel.h> |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 13 | #include <linux/delay.h> |
| 14 | #include <linux/pci.h> |
| 15 | #include <linux/fb.h> |
| 16 | #include "i810.h" |
| 17 | #include "i810_regs.h" |
Adrian Bunk | a0aa7d0 | 2006-01-09 20:54:04 -0800 | [diff] [blame] | 18 | #include "i810_main.h" |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 19 | #include "../edid.h" |
| 20 | |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 21 | /* bit locations in the registers */ |
| 22 | #define SCL_DIR_MASK 0x0001 |
| 23 | #define SCL_DIR 0x0002 |
| 24 | #define SCL_VAL_MASK 0x0004 |
| 25 | #define SCL_VAL_OUT 0x0008 |
| 26 | #define SCL_VAL_IN 0x0010 |
| 27 | #define SDA_DIR_MASK 0x0100 |
| 28 | #define SDA_DIR 0x0200 |
| 29 | #define SDA_VAL_MASK 0x0400 |
| 30 | #define SDA_VAL_OUT 0x0800 |
| 31 | #define SDA_VAL_IN 0x1000 |
| 32 | |
| 33 | #define DEBUG /* define this for verbose EDID parsing output */ |
| 34 | |
| 35 | #ifdef DEBUG |
| 36 | #define DPRINTK(fmt, args...) printk(fmt,## args) |
| 37 | #else |
| 38 | #define DPRINTK(fmt, args...) |
| 39 | #endif |
| 40 | |
| 41 | static void i810i2c_setscl(void *data, int state) |
| 42 | { |
Antonino A. Daplas | c019c0e | 2006-01-09 20:53:03 -0800 | [diff] [blame] | 43 | struct i810fb_i2c_chan *chan = data; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 44 | struct i810fb_par *par = chan->par; |
Al Viro | be88ec7 | 2005-09-29 00:36:10 +0100 | [diff] [blame] | 45 | u8 __iomem *mmio = par->mmio_start_virtual; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 46 | |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 47 | i810_writel(mmio, chan->ddc_base, (state ? SCL_VAL_OUT : 0) | SCL_DIR | |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 48 | SCL_DIR_MASK | SCL_VAL_MASK); |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 49 | i810_readl(mmio, chan->ddc_base); /* flush posted write */ |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | static void i810i2c_setsda(void *data, int state) |
| 53 | { |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 54 | struct i810fb_i2c_chan *chan = data; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 55 | struct i810fb_par *par = chan->par; |
Al Viro | be88ec7 | 2005-09-29 00:36:10 +0100 | [diff] [blame] | 56 | u8 __iomem *mmio = par->mmio_start_virtual; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 57 | |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 58 | i810_writel(mmio, chan->ddc_base, (state ? SDA_VAL_OUT : 0) | SDA_DIR | |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 59 | SDA_DIR_MASK | SDA_VAL_MASK); |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 60 | i810_readl(mmio, chan->ddc_base); /* flush posted write */ |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static int i810i2c_getscl(void *data) |
| 64 | { |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 65 | struct i810fb_i2c_chan *chan = data; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 66 | struct i810fb_par *par = chan->par; |
Al Viro | be88ec7 | 2005-09-29 00:36:10 +0100 | [diff] [blame] | 67 | u8 __iomem *mmio = par->mmio_start_virtual; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 68 | |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 69 | i810_writel(mmio, chan->ddc_base, SCL_DIR_MASK); |
| 70 | i810_writel(mmio, chan->ddc_base, 0); |
| 71 | return ((i810_readl(mmio, chan->ddc_base) & SCL_VAL_IN) != 0); |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static int i810i2c_getsda(void *data) |
| 75 | { |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 76 | struct i810fb_i2c_chan *chan = data; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 77 | struct i810fb_par *par = chan->par; |
Al Viro | be88ec7 | 2005-09-29 00:36:10 +0100 | [diff] [blame] | 78 | u8 __iomem *mmio = par->mmio_start_virtual; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 79 | |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 80 | i810_writel(mmio, chan->ddc_base, SDA_DIR_MASK); |
| 81 | i810_writel(mmio, chan->ddc_base, 0); |
| 82 | return ((i810_readl(mmio, chan->ddc_base) & SDA_VAL_IN) != 0); |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 85 | static int i810_setup_i2c_bus(struct i810fb_i2c_chan *chan, const char *name) |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 86 | { |
| 87 | int rc; |
| 88 | |
| 89 | strcpy(chan->adapter.name, name); |
| 90 | chan->adapter.owner = THIS_MODULE; |
| 91 | chan->adapter.algo_data = &chan->algo; |
| 92 | chan->adapter.dev.parent = &chan->par->dev->dev; |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 93 | chan->adapter.id = I2C_HW_B_I810; |
| 94 | chan->algo.setsda = i810i2c_setsda; |
| 95 | chan->algo.setscl = i810i2c_setscl; |
| 96 | chan->algo.getsda = i810i2c_getsda; |
| 97 | chan->algo.getscl = i810i2c_getscl; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 98 | chan->algo.udelay = 10; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 99 | chan->algo.timeout = (HZ/2); |
| 100 | chan->algo.data = chan; |
| 101 | |
| 102 | i2c_set_adapdata(&chan->adapter, chan); |
| 103 | |
| 104 | /* Raise SCL and SDA */ |
| 105 | chan->algo.setsda(chan, 1); |
| 106 | chan->algo.setscl(chan, 1); |
| 107 | udelay(20); |
| 108 | |
| 109 | rc = i2c_bit_add_bus(&chan->adapter); |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 110 | |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 111 | if (rc == 0) |
| 112 | dev_dbg(&chan->par->dev->dev, "I2C bus %s registered.\n",name); |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 113 | else { |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 114 | dev_warn(&chan->par->dev->dev, "Failed to register I2C bus " |
| 115 | "%s.\n", name); |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 116 | chan->par = NULL; |
| 117 | } |
| 118 | |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 119 | return rc; |
| 120 | } |
| 121 | |
| 122 | void i810_create_i2c_busses(struct i810fb_par *par) |
| 123 | { |
| 124 | par->chan[0].par = par; |
| 125 | par->chan[1].par = par; |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 126 | par->chan[2].par = par; |
| 127 | |
| 128 | par->chan[0].ddc_base = GPIOA; |
| 129 | i810_setup_i2c_bus(&par->chan[0], "I810-DDC"); |
| 130 | par->chan[1].ddc_base = GPIOB; |
| 131 | i810_setup_i2c_bus(&par->chan[1], "I810-I2C"); |
| 132 | par->chan[2].ddc_base = GPIOC; |
| 133 | i810_setup_i2c_bus(&par->chan[2], "I810-GPIOC"); |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void i810_delete_i2c_busses(struct i810fb_par *par) |
| 137 | { |
| 138 | if (par->chan[0].par) |
Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 139 | i2c_del_adapter(&par->chan[0].adapter); |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 140 | par->chan[0].par = NULL; |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 141 | |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 142 | if (par->chan[1].par) |
Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 143 | i2c_del_adapter(&par->chan[1].adapter); |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 144 | par->chan[1].par = NULL; |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 145 | |
| 146 | if (par->chan[2].par) |
Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 147 | i2c_del_adapter(&par->chan[2].adapter); |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 148 | par->chan[2].par = NULL; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 151 | int i810_probe_i2c_connector(struct fb_info *info, u8 **out_edid, int conn) |
| 152 | { |
| 153 | struct i810fb_par *par = info->par; |
| 154 | u8 *edid = NULL; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 155 | |
Manuel Lauss | 00d340b9 | 2006-02-01 03:06:54 -0800 | [diff] [blame] | 156 | DPRINTK("i810-i2c: Probe DDC%i Bus\n", conn+1); |
| 157 | if (conn < par->ddc_num) { |
Antonino A. Daplas | e80987f | 2006-10-03 01:14:44 -0700 | [diff] [blame] | 158 | edid = fb_ddc_read(&par->chan[conn].adapter); |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 159 | } else { |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 160 | const u8 *e = fb_firmware_edid(info->device); |
| 161 | |
| 162 | if (e != NULL) { |
| 163 | DPRINTK("i810-i2c: Getting EDID from BIOS\n"); |
Alexey Dobriyan | bfba7b3 | 2006-12-08 02:40:46 -0800 | [diff] [blame] | 164 | edid = kmemdup(e, EDID_LENGTH, GFP_KERNEL); |
Antonino A. Daplas | 5fab851 | 2005-11-07 01:00:50 -0800 | [diff] [blame] | 165 | } |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Antonino A. Daplas | 7c518eb | 2006-03-27 01:17:33 -0800 | [diff] [blame] | 168 | *out_edid = edid; |
Antonino A. Daplas | 74f6ae8 | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 169 | |
| 170 | return (edid) ? 0 : 1; |
| 171 | } |