~ubuntu-branches/ubuntu/trusty/linux-armadaxp/trusty

« back to all changes in this revision

Viewing changes to drivers/staging/gma500/psb_intel_i2c.c

  • Committer: Package Import Robot
  • Author(s): Michael Casadevall, Bryan Wu, Dann Frazier, Michael Casadeall
  • Date: 2012-03-10 15:00:54 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120310150054-flugb39zon8vvgwe
Tags: 3.2.0-1600.1
[ Bryan Wu ]
* UBUNTU: import debian/debian.env and debian.armadaxp

[ Dann Frazier ]
* ARM: Armada XP: remove trailing '/' in dirnames in mvRules.mk

[ Michael Casadeall ]
* tools: add some tools for Marvell Armada XP processor
* kernel: timer tick hacking from Marvell
* kernel: Sheeva Errata: add delay on Sheeva when powering down
* net: add Marvell NFP netfilter
* net: socket and skb modifications made by Marvell
* miscdevice: add minor IDs for some Marvell Armada drivers
* fs: introduce memory pool for splice()
* video: EDID detection updates from Marvell Armada XP patchset
* video: backlight: add Marvell Dove LCD backlight driver
* video: display: add THS8200 display driver
* video: framebuffer: add Marvell Dove and Armada XP processor onchip LCD controller driver
* usbtest: add Interrupt transfer testing by Marvell Armada XP code
* usb: ehci: add support for Marvell EHCI controler
* tty/serial: 8250: add support for Marvell Armada XP processor and DeviceTree work
* rtc: add support for Marvell Armada XP onchip RTC controller
* net: pppoe: add Marvell ethernet NFP hook in PPPoE networking driver
* mtd: nand: add support for Marvell Armada XP Nand Flash Controller
* mtd: maps: add Marvell Armada XP specific map driver
* mmc: add support for Marvell Armada XP MMC/SD host controller
* i2c: add support for Marvell Armada XP onchip i2c bus controller
* hwmon: add Kconfig option for Armada XP onchip thermal sensor driver
* dmaengine: add Net DMA support for splice and update Marvell XOR DMA engine driver
* ata: add support for Marvell Armada XP SATA controller and update some quirks
* ARM: add Marvell Armada XP machine to mach-types
* ARM: oprofile: add support for Marvell PJ4B core
* ARM: mm: more ARMv6 switches for Marvell Armada XP
* ARM: remove static declaration to allow compilation
* ARM: alignment access fault trick
* ARM: mm: skip some fault fixing when run on NONE SMP ARMv6 mode during early abort event
* ARM: mm: add Marvell Sheeva CPU Architecture for PJ4B
* ARM: introduce optimized copy operation for Marvell Armada XP
* ARM: SAUCE: hardware breakpoint trick for Marvell Armada XP
* ARM: big endian and little endian tricks for Marvell Armada XP
* ARM: SAUCE: Add Marvell Armada XP build rules to arch/arm/kernel/Makefile
* ARM: vfp: add special handling for Marvell Armada XP
* ARM: add support for Marvell U-Boot
* ARM: add mv_controller_num for ARM PCI drivers
* ARM: add support for local PMUs, general SMP tweaks and cache flushing
* ARM: add Marvell device identifies in glue-proc.h
* ARM: add IPC driver support for Marvell platforms
* ARM: add DMA mapping for Marvell platforms
* ARM: add Sheeva errata and PJ4B code for booting
* ARM: update Kconfig and Makefile to include Marvell Armada XP platforms
* ARM: Armada XP: import LSP from Marvell for Armada XP 3.2 kernel enablement

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2006-2007 Intel Corporation
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify it
5
 
 * under the terms and conditions of the GNU General Public License,
6
 
 * version 2, as published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope it will be useful, but WITHOUT
9
 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11
 
 * more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License along with
14
 
 * this program; if not, write to the Free Software Foundation, Inc.,
15
 
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16
 
 *
17
 
 * Authors:
18
 
 *      Eric Anholt <eric@anholt.net>
19
 
 */
20
 
 
21
 
#include <linux/i2c.h>
22
 
#include <linux/i2c-algo-bit.h>
23
 
 
24
 
#include "psb_drv.h"
25
 
#include "psb_intel_reg.h"
26
 
 
27
 
/*
28
 
 * Intel GPIO access functions
29
 
 */
30
 
 
31
 
#define I2C_RISEFALL_TIME 20
32
 
 
33
 
static int get_clock(void *data)
34
 
{
35
 
        struct psb_intel_i2c_chan *chan = data;
36
 
        struct drm_device *dev = chan->drm_dev;
37
 
        u32 val;
38
 
 
39
 
        val = REG_READ(chan->reg);
40
 
        return (val & GPIO_CLOCK_VAL_IN) != 0;
41
 
}
42
 
 
43
 
static int get_data(void *data)
44
 
{
45
 
        struct psb_intel_i2c_chan *chan = data;
46
 
        struct drm_device *dev = chan->drm_dev;
47
 
        u32 val;
48
 
 
49
 
        val = REG_READ(chan->reg);
50
 
        return (val & GPIO_DATA_VAL_IN) != 0;
51
 
}
52
 
 
53
 
static void set_clock(void *data, int state_high)
54
 
{
55
 
        struct psb_intel_i2c_chan *chan = data;
56
 
        struct drm_device *dev = chan->drm_dev;
57
 
        u32 reserved = 0, clock_bits;
58
 
 
59
 
        /* On most chips, these bits must be preserved in software. */
60
 
        reserved =
61
 
                    REG_READ(chan->reg) & (GPIO_DATA_PULLUP_DISABLE |
62
 
                                           GPIO_CLOCK_PULLUP_DISABLE);
63
 
 
64
 
        if (state_high)
65
 
                clock_bits = GPIO_CLOCK_DIR_IN | GPIO_CLOCK_DIR_MASK;
66
 
        else
67
 
                clock_bits = GPIO_CLOCK_DIR_OUT | GPIO_CLOCK_DIR_MASK |
68
 
                    GPIO_CLOCK_VAL_MASK;
69
 
        REG_WRITE(chan->reg, reserved | clock_bits);
70
 
        udelay(I2C_RISEFALL_TIME);      /* wait for the line to change state */
71
 
}
72
 
 
73
 
static void set_data(void *data, int state_high)
74
 
{
75
 
        struct psb_intel_i2c_chan *chan = data;
76
 
        struct drm_device *dev = chan->drm_dev;
77
 
        u32 reserved = 0, data_bits;
78
 
 
79
 
        /* On most chips, these bits must be preserved in software. */
80
 
        reserved =
81
 
                    REG_READ(chan->reg) & (GPIO_DATA_PULLUP_DISABLE |
82
 
                                           GPIO_CLOCK_PULLUP_DISABLE);
83
 
 
84
 
        if (state_high)
85
 
                data_bits = GPIO_DATA_DIR_IN | GPIO_DATA_DIR_MASK;
86
 
        else
87
 
                data_bits =
88
 
                    GPIO_DATA_DIR_OUT | GPIO_DATA_DIR_MASK |
89
 
                    GPIO_DATA_VAL_MASK;
90
 
 
91
 
        REG_WRITE(chan->reg, reserved | data_bits);
92
 
        udelay(I2C_RISEFALL_TIME);      /* wait for the line to change state */
93
 
}
94
 
 
95
 
/**
96
 
 * psb_intel_i2c_create - instantiate an Intel i2c bus using the specified GPIO reg
97
 
 * @dev: DRM device
98
 
 * @output: driver specific output device
99
 
 * @reg: GPIO reg to use
100
 
 * @name: name for this bus
101
 
 *
102
 
 * Creates and registers a new i2c bus with the Linux i2c layer, for use
103
 
 * in output probing and control (e.g. DDC or SDVO control functions).
104
 
 *
105
 
 * Possible values for @reg include:
106
 
 *   %GPIOA
107
 
 *   %GPIOB
108
 
 *   %GPIOC
109
 
 *   %GPIOD
110
 
 *   %GPIOE
111
 
 *   %GPIOF
112
 
 *   %GPIOG
113
 
 *   %GPIOH
114
 
 * see PRM for details on how these different busses are used.
115
 
 */
116
 
struct psb_intel_i2c_chan *psb_intel_i2c_create(struct drm_device *dev,
117
 
                                        const u32 reg, const char *name)
118
 
{
119
 
        struct psb_intel_i2c_chan *chan;
120
 
 
121
 
        chan = kzalloc(sizeof(struct psb_intel_i2c_chan), GFP_KERNEL);
122
 
        if (!chan)
123
 
                goto out_free;
124
 
 
125
 
        chan->drm_dev = dev;
126
 
        chan->reg = reg;
127
 
        snprintf(chan->adapter.name, I2C_NAME_SIZE, "intel drm %s", name);
128
 
        chan->adapter.owner = THIS_MODULE;
129
 
        chan->adapter.algo_data = &chan->algo;
130
 
        chan->adapter.dev.parent = &dev->pdev->dev;
131
 
        chan->algo.setsda = set_data;
132
 
        chan->algo.setscl = set_clock;
133
 
        chan->algo.getsda = get_data;
134
 
        chan->algo.getscl = get_clock;
135
 
        chan->algo.udelay = 20;
136
 
        chan->algo.timeout = usecs_to_jiffies(2200);
137
 
        chan->algo.data = chan;
138
 
 
139
 
        i2c_set_adapdata(&chan->adapter, chan);
140
 
 
141
 
        if (i2c_bit_add_bus(&chan->adapter))
142
 
                goto out_free;
143
 
 
144
 
        /* JJJ:  raise SCL and SDA? */
145
 
        set_data(chan, 1);
146
 
        set_clock(chan, 1);
147
 
        udelay(20);
148
 
 
149
 
        return chan;
150
 
 
151
 
out_free:
152
 
        kfree(chan);
153
 
        return NULL;
154
 
}
155
 
 
156
 
/**
157
 
 * psb_intel_i2c_destroy - unregister and free i2c bus resources
158
 
 * @output: channel to free
159
 
 *
160
 
 * Unregister the adapter from the i2c layer, then free the structure.
161
 
 */
162
 
void psb_intel_i2c_destroy(struct psb_intel_i2c_chan *chan)
163
 
{
164
 
        if (!chan)
165
 
                return;
166
 
 
167
 
        i2c_del_adapter(&chan->adapter);
168
 
        kfree(chan);
169
 
}