OSDN Git Service

radeon: make buffer swap for older drivers work again on GEM
[android-x86/external-libdrm.git] / linux-core / radeon_i2c.c
1 /*
2  * Copyright 2007-8 Advanced Micro Devices, Inc.
3  * Copyright 2008 Red Hat Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  * Authors: Dave Airlie
24  *          Alex Deucher
25  */
26 #include "drmP.h"
27 #include "radeon_drm.h"
28 #include "radeon_drv.h"
29
30
31 static int get_clock(void *i2c_priv)
32 {
33         struct radeon_i2c_chan *i2c = i2c_priv;
34         struct drm_radeon_private *dev_priv = i2c->dev->dev_private;
35         struct radeon_i2c_bus_rec *rec = &i2c->rec;
36         uint32_t val;
37
38         val = RADEON_READ(rec->get_clk_reg);
39         val &= rec->get_clk_mask;
40
41         return (val != 0);
42 }
43
44
45 static int get_data(void *i2c_priv)
46 {
47         struct radeon_i2c_chan *i2c = i2c_priv;
48         struct drm_radeon_private *dev_priv = i2c->dev->dev_private;
49         struct radeon_i2c_bus_rec *rec = &i2c->rec;
50         uint32_t val;
51
52         val = RADEON_READ(rec->get_data_reg);
53         val &= rec->get_data_mask;
54         return (val != 0);
55 }
56
57 static void set_clock(void *i2c_priv, int clock)
58 {
59         struct radeon_i2c_chan *i2c = i2c_priv;
60         struct drm_radeon_private *dev_priv = i2c->dev->dev_private;
61         struct radeon_i2c_bus_rec *rec = &i2c->rec;
62         uint32_t val;
63
64         val = RADEON_READ(rec->put_clk_reg) & (uint32_t)~(rec->put_clk_mask);
65         val |= clock ? 0 : rec->put_clk_mask;
66         RADEON_WRITE(rec->put_clk_reg, val);
67 }
68
69 static void set_data(void *i2c_priv, int data)
70 {
71         struct radeon_i2c_chan *i2c = i2c_priv;
72         struct drm_radeon_private *dev_priv = i2c->dev->dev_private;
73         struct radeon_i2c_bus_rec *rec = &i2c->rec;
74         uint32_t val;
75
76         val = RADEON_READ(rec->put_data_reg) & (uint32_t)~(rec->put_data_mask);
77         val |= data ? 0 : rec->put_data_mask;
78         RADEON_WRITE(rec->put_data_reg, val);
79 }
80
81 struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
82                                           struct radeon_i2c_bus_rec *rec,
83                                           const char *name)
84 {
85         struct radeon_i2c_chan *i2c;
86         int ret;
87
88         i2c = drm_calloc(1, sizeof(struct radeon_i2c_chan), DRM_MEM_DRIVER);
89         if (i2c == NULL)
90                 return NULL;
91         
92         i2c->adapter.owner = THIS_MODULE;
93         i2c->adapter.id = I2C_HW_B_RADEON;
94         i2c->adapter.algo_data = &i2c->algo;
95         i2c->dev = dev;
96         i2c->algo.setsda = set_data;
97         i2c->algo.setscl = set_clock;
98         i2c->algo.getsda = get_data;
99         i2c->algo.getscl = get_clock;
100         i2c->algo.udelay = 20;
101         i2c->algo.timeout = usecs_to_jiffies(2200);
102         i2c->algo.data = i2c;
103         i2c->rec = *rec;
104         i2c_set_adapdata(&i2c->adapter, i2c);
105
106         ret = i2c_bit_add_bus(&i2c->adapter);
107         if (ret) {
108                 DRM_INFO("Failed to register i2c %s\n", name);
109                 goto out_free;
110         }
111
112         return i2c;
113 out_free:
114         drm_free(i2c, sizeof(struct radeon_i2c_chan), DRM_MEM_DRIVER);
115         return NULL;
116         
117 }
118
119 void radeon_i2c_destroy(struct radeon_i2c_chan *i2c)
120 {
121         if (!i2c)
122                 return;
123
124         i2c_del_adapter(&i2c->adapter);
125         drm_free(i2c, sizeof(struct radeon_i2c_chan), DRM_MEM_DRIVER);
126 }
127
128 struct drm_encoder *radeon_best_encoder(struct drm_connector *connector)
129 {
130         return NULL;
131 }