xref: /OK3568_Linux_fs/kernel/drivers/i2c/i2c-smbus.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * i2c-smbus.c - SMBus extensions to the I2C protocol
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2008 David Brownell
6*4882a593Smuzhiyun  * Copyright (C) 2010-2019 Jean Delvare <jdelvare@suse.de>
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/device.h>
10*4882a593Smuzhiyun #include <linux/dmi.h>
11*4882a593Smuzhiyun #include <linux/i2c.h>
12*4882a593Smuzhiyun #include <linux/i2c-smbus.h>
13*4882a593Smuzhiyun #include <linux/interrupt.h>
14*4882a593Smuzhiyun #include <linux/kernel.h>
15*4882a593Smuzhiyun #include <linux/module.h>
16*4882a593Smuzhiyun #include <linux/of_irq.h>
17*4882a593Smuzhiyun #include <linux/slab.h>
18*4882a593Smuzhiyun #include <linux/workqueue.h>
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun struct i2c_smbus_alert {
21*4882a593Smuzhiyun 	struct work_struct	alert;
22*4882a593Smuzhiyun 	struct i2c_client	*ara;		/* Alert response address */
23*4882a593Smuzhiyun };
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun struct alert_data {
26*4882a593Smuzhiyun 	unsigned short		addr;
27*4882a593Smuzhiyun 	enum i2c_alert_protocol	type;
28*4882a593Smuzhiyun 	unsigned int		data;
29*4882a593Smuzhiyun };
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /* If this is the alerting device, notify its driver */
smbus_do_alert(struct device * dev,void * addrp)32*4882a593Smuzhiyun static int smbus_do_alert(struct device *dev, void *addrp)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun 	struct i2c_client *client = i2c_verify_client(dev);
35*4882a593Smuzhiyun 	struct alert_data *data = addrp;
36*4882a593Smuzhiyun 	struct i2c_driver *driver;
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun 	if (!client || client->addr != data->addr)
39*4882a593Smuzhiyun 		return 0;
40*4882a593Smuzhiyun 	if (client->flags & I2C_CLIENT_TEN)
41*4882a593Smuzhiyun 		return 0;
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun 	/*
44*4882a593Smuzhiyun 	 * Drivers should either disable alerts, or provide at least
45*4882a593Smuzhiyun 	 * a minimal handler.  Lock so the driver won't change.
46*4882a593Smuzhiyun 	 */
47*4882a593Smuzhiyun 	device_lock(dev);
48*4882a593Smuzhiyun 	if (client->dev.driver) {
49*4882a593Smuzhiyun 		driver = to_i2c_driver(client->dev.driver);
50*4882a593Smuzhiyun 		if (driver->alert)
51*4882a593Smuzhiyun 			driver->alert(client, data->type, data->data);
52*4882a593Smuzhiyun 		else
53*4882a593Smuzhiyun 			dev_warn(&client->dev, "no driver alert()!\n");
54*4882a593Smuzhiyun 	} else
55*4882a593Smuzhiyun 		dev_dbg(&client->dev, "alert with no driver\n");
56*4882a593Smuzhiyun 	device_unlock(dev);
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun 	/* Stop iterating after we find the device */
59*4882a593Smuzhiyun 	return -EBUSY;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun /*
63*4882a593Smuzhiyun  * The alert IRQ handler needs to hand work off to a task which can issue
64*4882a593Smuzhiyun  * SMBus calls, because those sleeping calls can't be made in IRQ context.
65*4882a593Smuzhiyun  */
smbus_alert(int irq,void * d)66*4882a593Smuzhiyun static irqreturn_t smbus_alert(int irq, void *d)
67*4882a593Smuzhiyun {
68*4882a593Smuzhiyun 	struct i2c_smbus_alert *alert = d;
69*4882a593Smuzhiyun 	struct i2c_client *ara;
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 	ara = alert->ara;
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun 	for (;;) {
74*4882a593Smuzhiyun 		s32 status;
75*4882a593Smuzhiyun 		struct alert_data data;
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 		/*
78*4882a593Smuzhiyun 		 * Devices with pending alerts reply in address order, low
79*4882a593Smuzhiyun 		 * to high, because of slave transmit arbitration.  After
80*4882a593Smuzhiyun 		 * responding, an SMBus device stops asserting SMBALERT#.
81*4882a593Smuzhiyun 		 *
82*4882a593Smuzhiyun 		 * Note that SMBus 2.0 reserves 10-bit addresses for future
83*4882a593Smuzhiyun 		 * use.  We neither handle them, nor try to use PEC here.
84*4882a593Smuzhiyun 		 */
85*4882a593Smuzhiyun 		status = i2c_smbus_read_byte(ara);
86*4882a593Smuzhiyun 		if (status < 0)
87*4882a593Smuzhiyun 			break;
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun 		data.data = status & 1;
90*4882a593Smuzhiyun 		data.addr = status >> 1;
91*4882a593Smuzhiyun 		data.type = I2C_PROTOCOL_SMBUS_ALERT;
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun 		dev_dbg(&ara->dev, "SMBALERT# from dev 0x%02x, flag %d\n",
94*4882a593Smuzhiyun 			data.addr, data.data);
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 		/* Notify driver for the device which issued the alert */
97*4882a593Smuzhiyun 		device_for_each_child(&ara->adapter->dev, &data,
98*4882a593Smuzhiyun 				      smbus_do_alert);
99*4882a593Smuzhiyun 	}
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun 	return IRQ_HANDLED;
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun 
smbalert_work(struct work_struct * work)104*4882a593Smuzhiyun static void smbalert_work(struct work_struct *work)
105*4882a593Smuzhiyun {
106*4882a593Smuzhiyun 	struct i2c_smbus_alert *alert;
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun 	alert = container_of(work, struct i2c_smbus_alert, alert);
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun 	smbus_alert(0, alert);
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun /* Setup SMBALERT# infrastructure */
smbalert_probe(struct i2c_client * ara,const struct i2c_device_id * id)115*4882a593Smuzhiyun static int smbalert_probe(struct i2c_client *ara,
116*4882a593Smuzhiyun 			  const struct i2c_device_id *id)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun 	struct i2c_smbus_alert_setup *setup = dev_get_platdata(&ara->dev);
119*4882a593Smuzhiyun 	struct i2c_smbus_alert *alert;
120*4882a593Smuzhiyun 	struct i2c_adapter *adapter = ara->adapter;
121*4882a593Smuzhiyun 	int res, irq;
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun 	alert = devm_kzalloc(&ara->dev, sizeof(struct i2c_smbus_alert),
124*4882a593Smuzhiyun 			     GFP_KERNEL);
125*4882a593Smuzhiyun 	if (!alert)
126*4882a593Smuzhiyun 		return -ENOMEM;
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	if (setup) {
129*4882a593Smuzhiyun 		irq = setup->irq;
130*4882a593Smuzhiyun 	} else {
131*4882a593Smuzhiyun 		irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert");
132*4882a593Smuzhiyun 		if (irq <= 0)
133*4882a593Smuzhiyun 			return irq;
134*4882a593Smuzhiyun 	}
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 	INIT_WORK(&alert->alert, smbalert_work);
137*4882a593Smuzhiyun 	alert->ara = ara;
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun 	if (irq > 0) {
140*4882a593Smuzhiyun 		res = devm_request_threaded_irq(&ara->dev, irq,
141*4882a593Smuzhiyun 						NULL, smbus_alert,
142*4882a593Smuzhiyun 						IRQF_SHARED | IRQF_ONESHOT,
143*4882a593Smuzhiyun 						"smbus_alert", alert);
144*4882a593Smuzhiyun 		if (res)
145*4882a593Smuzhiyun 			return res;
146*4882a593Smuzhiyun 	}
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 	i2c_set_clientdata(ara, alert);
149*4882a593Smuzhiyun 	dev_info(&adapter->dev, "supports SMBALERT#\n");
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun 	return 0;
152*4882a593Smuzhiyun }
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun /* IRQ and memory resources are managed so they are freed automatically */
smbalert_remove(struct i2c_client * ara)155*4882a593Smuzhiyun static int smbalert_remove(struct i2c_client *ara)
156*4882a593Smuzhiyun {
157*4882a593Smuzhiyun 	struct i2c_smbus_alert *alert = i2c_get_clientdata(ara);
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	cancel_work_sync(&alert->alert);
160*4882a593Smuzhiyun 	return 0;
161*4882a593Smuzhiyun }
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun static const struct i2c_device_id smbalert_ids[] = {
164*4882a593Smuzhiyun 	{ "smbus_alert", 0 },
165*4882a593Smuzhiyun 	{ /* LIST END */ }
166*4882a593Smuzhiyun };
167*4882a593Smuzhiyun MODULE_DEVICE_TABLE(i2c, smbalert_ids);
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun static struct i2c_driver smbalert_driver = {
170*4882a593Smuzhiyun 	.driver = {
171*4882a593Smuzhiyun 		.name	= "smbus_alert",
172*4882a593Smuzhiyun 	},
173*4882a593Smuzhiyun 	.probe		= smbalert_probe,
174*4882a593Smuzhiyun 	.remove		= smbalert_remove,
175*4882a593Smuzhiyun 	.id_table	= smbalert_ids,
176*4882a593Smuzhiyun };
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun /**
179*4882a593Smuzhiyun  * i2c_handle_smbus_alert - Handle an SMBus alert
180*4882a593Smuzhiyun  * @ara: the ARA client on the relevant adapter
181*4882a593Smuzhiyun  * Context: can't sleep
182*4882a593Smuzhiyun  *
183*4882a593Smuzhiyun  * Helper function to be called from an I2C bus driver's interrupt
184*4882a593Smuzhiyun  * handler. It will schedule the alert work, in turn calling the
185*4882a593Smuzhiyun  * corresponding I2C device driver's alert function.
186*4882a593Smuzhiyun  *
187*4882a593Smuzhiyun  * It is assumed that ara is a valid i2c client previously returned by
188*4882a593Smuzhiyun  * i2c_new_smbus_alert_device().
189*4882a593Smuzhiyun  */
i2c_handle_smbus_alert(struct i2c_client * ara)190*4882a593Smuzhiyun int i2c_handle_smbus_alert(struct i2c_client *ara)
191*4882a593Smuzhiyun {
192*4882a593Smuzhiyun 	struct i2c_smbus_alert *alert = i2c_get_clientdata(ara);
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun 	return schedule_work(&alert->alert);
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(i2c_handle_smbus_alert);
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun module_i2c_driver(smbalert_driver);
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_I2C_SLAVE)
201*4882a593Smuzhiyun #define SMBUS_HOST_NOTIFY_LEN	3
202*4882a593Smuzhiyun struct i2c_slave_host_notify_status {
203*4882a593Smuzhiyun 	u8 index;
204*4882a593Smuzhiyun 	u8 addr;
205*4882a593Smuzhiyun };
206*4882a593Smuzhiyun 
i2c_slave_host_notify_cb(struct i2c_client * client,enum i2c_slave_event event,u8 * val)207*4882a593Smuzhiyun static int i2c_slave_host_notify_cb(struct i2c_client *client,
208*4882a593Smuzhiyun 				    enum i2c_slave_event event, u8 *val)
209*4882a593Smuzhiyun {
210*4882a593Smuzhiyun 	struct i2c_slave_host_notify_status *status = client->dev.platform_data;
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun 	switch (event) {
213*4882a593Smuzhiyun 	case I2C_SLAVE_WRITE_RECEIVED:
214*4882a593Smuzhiyun 		/* We only retrieve the first byte received (addr)
215*4882a593Smuzhiyun 		 * since there is currently no support to retrieve the data
216*4882a593Smuzhiyun 		 * parameter from the client.
217*4882a593Smuzhiyun 		 */
218*4882a593Smuzhiyun 		if (status->index == 0)
219*4882a593Smuzhiyun 			status->addr = *val;
220*4882a593Smuzhiyun 		if (status->index < U8_MAX)
221*4882a593Smuzhiyun 			status->index++;
222*4882a593Smuzhiyun 		break;
223*4882a593Smuzhiyun 	case I2C_SLAVE_STOP:
224*4882a593Smuzhiyun 		if (status->index == SMBUS_HOST_NOTIFY_LEN)
225*4882a593Smuzhiyun 			i2c_handle_smbus_host_notify(client->adapter,
226*4882a593Smuzhiyun 						     status->addr);
227*4882a593Smuzhiyun 		fallthrough;
228*4882a593Smuzhiyun 	case I2C_SLAVE_WRITE_REQUESTED:
229*4882a593Smuzhiyun 		status->index = 0;
230*4882a593Smuzhiyun 		break;
231*4882a593Smuzhiyun 	case I2C_SLAVE_READ_REQUESTED:
232*4882a593Smuzhiyun 	case I2C_SLAVE_READ_PROCESSED:
233*4882a593Smuzhiyun 		*val = 0xff;
234*4882a593Smuzhiyun 		break;
235*4882a593Smuzhiyun 	}
236*4882a593Smuzhiyun 
237*4882a593Smuzhiyun 	return 0;
238*4882a593Smuzhiyun }
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun /**
241*4882a593Smuzhiyun  * i2c_new_slave_host_notify_device - get a client for SMBus host-notify support
242*4882a593Smuzhiyun  * @adapter: the target adapter
243*4882a593Smuzhiyun  * Context: can sleep
244*4882a593Smuzhiyun  *
245*4882a593Smuzhiyun  * Setup handling of the SMBus host-notify protocol on a given I2C bus segment.
246*4882a593Smuzhiyun  *
247*4882a593Smuzhiyun  * Handling is done by creating a device and its callback and handling data
248*4882a593Smuzhiyun  * received via the SMBus host-notify address (0x8)
249*4882a593Smuzhiyun  *
250*4882a593Smuzhiyun  * This returns the client, which should be ultimately freed using
251*4882a593Smuzhiyun  * i2c_free_slave_host_notify_device(); or an ERRPTR to indicate an error.
252*4882a593Smuzhiyun  */
i2c_new_slave_host_notify_device(struct i2c_adapter * adapter)253*4882a593Smuzhiyun struct i2c_client *i2c_new_slave_host_notify_device(struct i2c_adapter *adapter)
254*4882a593Smuzhiyun {
255*4882a593Smuzhiyun 	struct i2c_board_info host_notify_board_info = {
256*4882a593Smuzhiyun 		I2C_BOARD_INFO("smbus_host_notify", 0x08),
257*4882a593Smuzhiyun 		.flags  = I2C_CLIENT_SLAVE,
258*4882a593Smuzhiyun 	};
259*4882a593Smuzhiyun 	struct i2c_slave_host_notify_status *status;
260*4882a593Smuzhiyun 	struct i2c_client *client;
261*4882a593Smuzhiyun 	int ret;
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun 	status = kzalloc(sizeof(struct i2c_slave_host_notify_status),
264*4882a593Smuzhiyun 			 GFP_KERNEL);
265*4882a593Smuzhiyun 	if (!status)
266*4882a593Smuzhiyun 		return ERR_PTR(-ENOMEM);
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun 	host_notify_board_info.platform_data = status;
269*4882a593Smuzhiyun 
270*4882a593Smuzhiyun 	client = i2c_new_client_device(adapter, &host_notify_board_info);
271*4882a593Smuzhiyun 	if (IS_ERR(client)) {
272*4882a593Smuzhiyun 		kfree(status);
273*4882a593Smuzhiyun 		return client;
274*4882a593Smuzhiyun 	}
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun 	ret = i2c_slave_register(client, i2c_slave_host_notify_cb);
277*4882a593Smuzhiyun 	if (ret) {
278*4882a593Smuzhiyun 		i2c_unregister_device(client);
279*4882a593Smuzhiyun 		kfree(status);
280*4882a593Smuzhiyun 		return ERR_PTR(ret);
281*4882a593Smuzhiyun 	}
282*4882a593Smuzhiyun 
283*4882a593Smuzhiyun 	return client;
284*4882a593Smuzhiyun }
285*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(i2c_new_slave_host_notify_device);
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun /**
288*4882a593Smuzhiyun  * i2c_free_slave_host_notify_device - free the client for SMBus host-notify
289*4882a593Smuzhiyun  * support
290*4882a593Smuzhiyun  * @client: the client to free
291*4882a593Smuzhiyun  * Context: can sleep
292*4882a593Smuzhiyun  *
293*4882a593Smuzhiyun  * Free the i2c_client allocated via i2c_new_slave_host_notify_device
294*4882a593Smuzhiyun  */
i2c_free_slave_host_notify_device(struct i2c_client * client)295*4882a593Smuzhiyun void i2c_free_slave_host_notify_device(struct i2c_client *client)
296*4882a593Smuzhiyun {
297*4882a593Smuzhiyun 	if (IS_ERR_OR_NULL(client))
298*4882a593Smuzhiyun 		return;
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun 	i2c_slave_unregister(client);
301*4882a593Smuzhiyun 	kfree(client->dev.platform_data);
302*4882a593Smuzhiyun 	i2c_unregister_device(client);
303*4882a593Smuzhiyun }
304*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(i2c_free_slave_host_notify_device);
305*4882a593Smuzhiyun #endif
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun /*
308*4882a593Smuzhiyun  * SPD is not part of SMBus but we include it here for convenience as the
309*4882a593Smuzhiyun  * target systems are the same.
310*4882a593Smuzhiyun  * Restrictions to automatic SPD instantiation:
311*4882a593Smuzhiyun  *  - Only works if all filled slots have the same memory type
312*4882a593Smuzhiyun  *  - Only works for DDR2, DDR3 and DDR4 for now
313*4882a593Smuzhiyun  *  - Only works on systems with 1 to 4 memory slots
314*4882a593Smuzhiyun  */
315*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_DMI)
i2c_register_spd(struct i2c_adapter * adap)316*4882a593Smuzhiyun void i2c_register_spd(struct i2c_adapter *adap)
317*4882a593Smuzhiyun {
318*4882a593Smuzhiyun 	int n, slot_count = 0, dimm_count = 0;
319*4882a593Smuzhiyun 	u16 handle;
320*4882a593Smuzhiyun 	u8 common_mem_type = 0x0, mem_type;
321*4882a593Smuzhiyun 	u64 mem_size;
322*4882a593Smuzhiyun 	const char *name;
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun 	while ((handle = dmi_memdev_handle(slot_count)) != 0xffff) {
325*4882a593Smuzhiyun 		slot_count++;
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 		/* Skip empty slots */
328*4882a593Smuzhiyun 		mem_size = dmi_memdev_size(handle);
329*4882a593Smuzhiyun 		if (!mem_size)
330*4882a593Smuzhiyun 			continue;
331*4882a593Smuzhiyun 
332*4882a593Smuzhiyun 		/* Skip undefined memory type */
333*4882a593Smuzhiyun 		mem_type = dmi_memdev_type(handle);
334*4882a593Smuzhiyun 		if (mem_type <= 0x02)		/* Invalid, Other, Unknown */
335*4882a593Smuzhiyun 			continue;
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun 		if (!common_mem_type) {
338*4882a593Smuzhiyun 			/* First filled slot */
339*4882a593Smuzhiyun 			common_mem_type = mem_type;
340*4882a593Smuzhiyun 		} else {
341*4882a593Smuzhiyun 			/* Check that all filled slots have the same type */
342*4882a593Smuzhiyun 			if (mem_type != common_mem_type) {
343*4882a593Smuzhiyun 				dev_warn(&adap->dev,
344*4882a593Smuzhiyun 					 "Different memory types mixed, not instantiating SPD\n");
345*4882a593Smuzhiyun 				return;
346*4882a593Smuzhiyun 			}
347*4882a593Smuzhiyun 		}
348*4882a593Smuzhiyun 		dimm_count++;
349*4882a593Smuzhiyun 	}
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun 	/* No useful DMI data, bail out */
352*4882a593Smuzhiyun 	if (!dimm_count)
353*4882a593Smuzhiyun 		return;
354*4882a593Smuzhiyun 
355*4882a593Smuzhiyun 	dev_info(&adap->dev, "%d/%d memory slots populated (from DMI)\n",
356*4882a593Smuzhiyun 		 dimm_count, slot_count);
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun 	if (slot_count > 4) {
359*4882a593Smuzhiyun 		dev_warn(&adap->dev,
360*4882a593Smuzhiyun 			 "Systems with more than 4 memory slots not supported yet, not instantiating SPD\n");
361*4882a593Smuzhiyun 		return;
362*4882a593Smuzhiyun 	}
363*4882a593Smuzhiyun 
364*4882a593Smuzhiyun 	switch (common_mem_type) {
365*4882a593Smuzhiyun 	case 0x13:	/* DDR2 */
366*4882a593Smuzhiyun 	case 0x18:	/* DDR3 */
367*4882a593Smuzhiyun 	case 0x1C:	/* LPDDR2 */
368*4882a593Smuzhiyun 	case 0x1D:	/* LPDDR3 */
369*4882a593Smuzhiyun 		name = "spd";
370*4882a593Smuzhiyun 		break;
371*4882a593Smuzhiyun 	case 0x1A:	/* DDR4 */
372*4882a593Smuzhiyun 	case 0x1E:	/* LPDDR4 */
373*4882a593Smuzhiyun 		name = "ee1004";
374*4882a593Smuzhiyun 		break;
375*4882a593Smuzhiyun 	default:
376*4882a593Smuzhiyun 		dev_info(&adap->dev,
377*4882a593Smuzhiyun 			 "Memory type 0x%02x not supported yet, not instantiating SPD\n",
378*4882a593Smuzhiyun 			 common_mem_type);
379*4882a593Smuzhiyun 		return;
380*4882a593Smuzhiyun 	}
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun 	/*
383*4882a593Smuzhiyun 	 * We don't know in which slots the memory modules are. We could
384*4882a593Smuzhiyun 	 * try to guess from the slot names, but that would be rather complex
385*4882a593Smuzhiyun 	 * and unreliable, so better probe all possible addresses until we
386*4882a593Smuzhiyun 	 * have found all memory modules.
387*4882a593Smuzhiyun 	 */
388*4882a593Smuzhiyun 	for (n = 0; n < slot_count && dimm_count; n++) {
389*4882a593Smuzhiyun 		struct i2c_board_info info;
390*4882a593Smuzhiyun 		unsigned short addr_list[2];
391*4882a593Smuzhiyun 
392*4882a593Smuzhiyun 		memset(&info, 0, sizeof(struct i2c_board_info));
393*4882a593Smuzhiyun 		strlcpy(info.type, name, I2C_NAME_SIZE);
394*4882a593Smuzhiyun 		addr_list[0] = 0x50 + n;
395*4882a593Smuzhiyun 		addr_list[1] = I2C_CLIENT_END;
396*4882a593Smuzhiyun 
397*4882a593Smuzhiyun 		if (!IS_ERR(i2c_new_scanned_device(adap, &info, addr_list, NULL))) {
398*4882a593Smuzhiyun 			dev_info(&adap->dev,
399*4882a593Smuzhiyun 				 "Successfully instantiated SPD at 0x%hx\n",
400*4882a593Smuzhiyun 				 addr_list[0]);
401*4882a593Smuzhiyun 			dimm_count--;
402*4882a593Smuzhiyun 		}
403*4882a593Smuzhiyun 	}
404*4882a593Smuzhiyun }
405*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(i2c_register_spd);
406*4882a593Smuzhiyun #endif
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>");
409*4882a593Smuzhiyun MODULE_DESCRIPTION("SMBus protocol extensions support");
410*4882a593Smuzhiyun MODULE_LICENSE("GPL");
411