2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
23 * Authors: Dave Airlie
27 #include "radeon_drm.h"
28 #include "radeon_drv.h"
31 static int get_clock(void *i2c_priv)
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;
38 val = RADEON_READ(rec->get_clk_reg);
39 val &= rec->get_clk_mask;
45 static int get_data(void *i2c_priv)
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;
52 val = RADEON_READ(rec->get_data_reg);
53 val &= rec->get_data_mask;
57 static void set_clock(void *i2c_priv, int clock)
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;
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);
69 static void set_data(void *i2c_priv, int data)
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;
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);
81 struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
82 struct radeon_i2c_bus_rec *rec,
85 struct radeon_i2c_chan *i2c;
88 i2c = drm_calloc(1, sizeof(struct radeon_i2c_chan), DRM_MEM_DRIVER);
92 i2c->adapter.owner = THIS_MODULE;
93 i2c->adapter.id = I2C_HW_B_RADEON;
94 i2c->adapter.algo_data = &i2c->algo;
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;
104 i2c_set_adapdata(&i2c->adapter, i2c);
106 ret = i2c_bit_add_bus(&i2c->adapter);
108 DRM_INFO("Failed to register i2c %s\n", name);
114 drm_free(i2c, sizeof(struct radeon_i2c_chan), DRM_MEM_DRIVER);
119 void radeon_i2c_destroy(struct radeon_i2c_chan *i2c)
124 i2c_del_adapter(&i2c->adapter);
125 drm_free(i2c, sizeof(struct radeon_i2c_chan), DRM_MEM_DRIVER);
128 struct drm_encoder *radeon_best_encoder(struct drm_connector *connector)