]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/core/subdev/therm/ic.c
Merge remote-tracking branch 'net-next/master'
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / core / subdev / therm / ic.c
1 /*
2  * Copyright 2012 Nouveau community
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Martin Peres
23  */
24
25 #include "priv.h"
26
27 #include <subdev/i2c.h>
28 #include <subdev/bios/extdev.h>
29
30 static bool
31 probe_monitoring_device(struct nouveau_i2c_port *i2c,
32                         struct i2c_board_info *info)
33 {
34         struct nouveau_therm_priv *priv = (void *)nouveau_therm(i2c);
35         struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
36         struct i2c_client *client;
37
38         request_module("%s%s", I2C_MODULE_PREFIX, info->type);
39
40         client = i2c_new_device(&i2c->adapter, info);
41         if (!client)
42                 return false;
43
44         if (!client->dev.driver ||
45             to_i2c_driver(client->dev.driver)->detect(client, info)) {
46                 i2c_unregister_device(client);
47                 return false;
48         }
49
50         nv_info(priv,
51                 "Found an %s at address 0x%x (controlled by lm_sensors, "
52                 "temp offset %+i C)\n",
53                 info->type, info->addr, sensor->offset_constant);
54         priv->ic = client;
55
56         return true;
57 }
58
59 static struct i2c_board_info
60 nv_board_infos[] = {
61         { I2C_BOARD_INFO("w83l785ts", 0x2d) },
62         { I2C_BOARD_INFO("w83781d", 0x2d) },
63         { I2C_BOARD_INFO("adt7473", 0x2e) },
64         { I2C_BOARD_INFO("adt7473", 0x2d) },
65         { I2C_BOARD_INFO("adt7473", 0x2c) },
66         { I2C_BOARD_INFO("f75375", 0x2e) },
67         { I2C_BOARD_INFO("lm99", 0x4c) },
68         { I2C_BOARD_INFO("lm90", 0x4c) },
69         { I2C_BOARD_INFO("lm90", 0x4d) },
70         { I2C_BOARD_INFO("adm1021", 0x18) },
71         { I2C_BOARD_INFO("adm1021", 0x19) },
72         { I2C_BOARD_INFO("adm1021", 0x1a) },
73         { I2C_BOARD_INFO("adm1021", 0x29) },
74         { I2C_BOARD_INFO("adm1021", 0x2a) },
75         { I2C_BOARD_INFO("adm1021", 0x2b) },
76         { I2C_BOARD_INFO("adm1021", 0x4c) },
77         { I2C_BOARD_INFO("adm1021", 0x4d) },
78         { I2C_BOARD_INFO("adm1021", 0x4e) },
79         { I2C_BOARD_INFO("lm63", 0x18) },
80         { I2C_BOARD_INFO("lm63", 0x4e) },
81         { }
82 };
83
84 void
85 nouveau_therm_ic_ctor(struct nouveau_therm *therm)
86 {
87         struct nouveau_therm_priv *priv = (void *)therm;
88         struct nouveau_bios *bios = nouveau_bios(therm);
89         struct nouveau_i2c *i2c = nouveau_i2c(therm);
90         struct nvbios_extdev_func extdev_entry;
91
92         if (!nvbios_extdev_find(bios, NVBIOS_EXTDEV_LM89, &extdev_entry)) {
93                 struct i2c_board_info board[] = {
94                         { I2C_BOARD_INFO("lm90", extdev_entry.addr >> 1) },
95                         { }
96                 };
97
98                 i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device",
99                                   board, probe_monitoring_device);
100                 if (priv->ic)
101                         return;
102         }
103
104         if (!nvbios_extdev_find(bios, NVBIOS_EXTDEV_ADT7473, &extdev_entry)) {
105                 struct i2c_board_info board[] = {
106                         { I2C_BOARD_INFO("adt7473", extdev_entry.addr >> 1) },
107                         { }
108                 };
109
110                 i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device",
111                                   board, probe_monitoring_device);
112                 if (priv->ic)
113                         return;
114         }
115
116         /* The vbios doesn't provide the address of an exisiting monitoring
117            device. Let's try our static list.
118          */
119         i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device",
120                       nv_board_infos, probe_monitoring_device);
121 }