xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvkm/subdev/therm/ic.c (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs  * Copyright 2012 Nouveau community
3c39f472eSBen Skeggs  *
4c39f472eSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
5c39f472eSBen Skeggs  * copy of this software and associated documentation files (the "Software"),
6c39f472eSBen Skeggs  * to deal in the Software without restriction, including without limitation
7c39f472eSBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c39f472eSBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
9c39f472eSBen Skeggs  * Software is furnished to do so, subject to the following conditions:
10c39f472eSBen Skeggs  *
11c39f472eSBen Skeggs  * The above copyright notice and this permission notice shall be included in
12c39f472eSBen Skeggs  * all copies or substantial portions of the Software.
13c39f472eSBen Skeggs  *
14c39f472eSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c39f472eSBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c39f472eSBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17c39f472eSBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c39f472eSBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c39f472eSBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c39f472eSBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
21c39f472eSBen Skeggs  *
22c39f472eSBen Skeggs  * Authors: Martin Peres
23c39f472eSBen Skeggs  */
24c39f472eSBen Skeggs #include "priv.h"
25c39f472eSBen Skeggs 
26c39f472eSBen Skeggs #include <subdev/bios/extdev.h>
27e1404611SBen Skeggs #include <subdev/i2c.h>
28c39f472eSBen Skeggs 
29c39f472eSBen Skeggs static bool
probe_monitoring_device(struct nvkm_i2c_bus * bus,struct i2c_board_info * info,void * data)302aa5eac5SBen Skeggs probe_monitoring_device(struct nvkm_i2c_bus *bus,
31c39f472eSBen Skeggs 			struct i2c_board_info *info, void *data)
32c39f472eSBen Skeggs {
3357113c01SBen Skeggs 	struct nvkm_therm *therm = data;
34da06b46bSBen Skeggs 	struct nvbios_therm_sensor *sensor = &therm->bios_sensor;
35c39f472eSBen Skeggs 	struct i2c_client *client;
36c39f472eSBen Skeggs 
37c39f472eSBen Skeggs 	request_module("%s%s", I2C_MODULE_PREFIX, info->type);
38c39f472eSBen Skeggs 
39*3f9becf9SWolfram Sang 	client = i2c_new_client_device(&bus->i2c, info);
40*3f9becf9SWolfram Sang 	if (IS_ERR(client))
41c39f472eSBen Skeggs 		return false;
42c39f472eSBen Skeggs 
43c39f472eSBen Skeggs 	if (!client->dev.driver ||
44c39f472eSBen Skeggs 	    to_i2c_driver(client->dev.driver)->detect(client, info)) {
45c39f472eSBen Skeggs 		i2c_unregister_device(client);
46c39f472eSBen Skeggs 		return false;
47c39f472eSBen Skeggs 	}
48c39f472eSBen Skeggs 
4957113c01SBen Skeggs 	nvkm_debug(&therm->subdev,
50c39f472eSBen Skeggs 		   "Found an %s at address 0x%x (controlled by lm_sensors, "
51c39f472eSBen Skeggs 		   "temp offset %+i C)\n",
52c39f472eSBen Skeggs 		   info->type, info->addr, sensor->offset_constant);
53da06b46bSBen Skeggs 	therm->ic = client;
54c39f472eSBen Skeggs 	return true;
55c39f472eSBen Skeggs }
56c39f472eSBen Skeggs 
572aa5eac5SBen Skeggs static struct nvkm_i2c_bus_probe
58c39f472eSBen Skeggs nv_board_infos[] = {
59c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("w83l785ts", 0x2d) }, 0 },
60c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("w83781d", 0x2d) }, 0  },
61c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("adt7473", 0x2e) }, 40  },
62c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("adt7473", 0x2d) }, 40  },
63c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("adt7473", 0x2c) }, 40  },
64c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("f75375", 0x2e) }, 0  },
65c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("lm99", 0x4c) }, 0  },
66c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("lm90", 0x4c) }, 0  },
67c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("lm90", 0x4d) }, 0  },
68c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("adm1021", 0x18) }, 0  },
69c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("adm1021", 0x19) }, 0  },
70c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("adm1021", 0x1a) }, 0  },
71c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("adm1021", 0x29) }, 0  },
72c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("adm1021", 0x2a) }, 0  },
73c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("adm1021", 0x2b) }, 0  },
74c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("adm1021", 0x4c) }, 0  },
75c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("adm1021", 0x4d) }, 0  },
76c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("adm1021", 0x4e) }, 0  },
77c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("lm63", 0x18) }, 0  },
78c39f472eSBen Skeggs 	{ { I2C_BOARD_INFO("lm63", 0x4e) }, 0  },
79c39f472eSBen Skeggs 	{ }
80c39f472eSBen Skeggs };
81c39f472eSBen Skeggs 
82c39f472eSBen Skeggs void
nvkm_therm_ic_ctor(struct nvkm_therm * therm)8357113c01SBen Skeggs nvkm_therm_ic_ctor(struct nvkm_therm *therm)
84c39f472eSBen Skeggs {
8557113c01SBen Skeggs 	struct nvkm_device *device = therm->subdev.device;
862aa5eac5SBen Skeggs 	struct nvkm_bios *bios = device->bios;
872aa5eac5SBen Skeggs 	struct nvkm_i2c *i2c = device->i2c;
882aa5eac5SBen Skeggs 	struct nvkm_i2c_bus *bus;
89c39f472eSBen Skeggs 	struct nvbios_extdev_func extdev_entry;
90c39f472eSBen Skeggs 
912aa5eac5SBen Skeggs 	bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_PRI);
922aa5eac5SBen Skeggs 	if (!bus)
932aa5eac5SBen Skeggs 		return;
942aa5eac5SBen Skeggs 
95c39f472eSBen Skeggs 	if (!nvbios_extdev_find(bios, NVBIOS_EXTDEV_LM89, &extdev_entry)) {
962aa5eac5SBen Skeggs 		struct nvkm_i2c_bus_probe board[] = {
97c39f472eSBen Skeggs 		  { { I2C_BOARD_INFO("lm90", extdev_entry.addr >> 1) }, 0},
98c39f472eSBen Skeggs 		  { }
99c39f472eSBen Skeggs 		};
100c39f472eSBen Skeggs 
1012aa5eac5SBen Skeggs 		nvkm_i2c_bus_probe(bus, "monitoring device", board,
1022aa5eac5SBen Skeggs 				   probe_monitoring_device, therm);
103da06b46bSBen Skeggs 		if (therm->ic)
104c39f472eSBen Skeggs 			return;
105c39f472eSBen Skeggs 	}
106c39f472eSBen Skeggs 
107c39f472eSBen Skeggs 	if (!nvbios_extdev_find(bios, NVBIOS_EXTDEV_ADT7473, &extdev_entry)) {
1082aa5eac5SBen Skeggs 		struct nvkm_i2c_bus_probe board[] = {
109c39f472eSBen Skeggs 		  { { I2C_BOARD_INFO("adt7473", extdev_entry.addr >> 1) }, 20 },
110c39f472eSBen Skeggs 		  { }
111c39f472eSBen Skeggs 		};
112c39f472eSBen Skeggs 
1132aa5eac5SBen Skeggs 		nvkm_i2c_bus_probe(bus, "monitoring device", board,
1142aa5eac5SBen Skeggs 				   probe_monitoring_device, therm);
115da06b46bSBen Skeggs 		if (therm->ic)
116c39f472eSBen Skeggs 			return;
117c39f472eSBen Skeggs 	}
118c39f472eSBen Skeggs 
119f0790cdaSBen Skeggs 	if (nvbios_extdev_skip_probe(bios))
120f0790cdaSBen Skeggs 		return;
121f0790cdaSBen Skeggs 
122c39f472eSBen Skeggs 	/* The vbios doesn't provide the address of an exisiting monitoring
123c39f472eSBen Skeggs 	   device. Let's try our static list.
124c39f472eSBen Skeggs 	 */
1252aa5eac5SBen Skeggs 	nvkm_i2c_bus_probe(bus, "monitoring device", nv_board_infos,
1262aa5eac5SBen Skeggs 			   probe_monitoring_device, therm);
127c39f472eSBen Skeggs }
128