// SPDX-License-Identifier: GPL-2.0-or-later /* * i2c-smbus.c - SMBus extensions to the I2C protocol * * Copyright (C) 2008 David Brownell * Copyright (C) 2010-2019 Jean Delvare <[email protected]> */ #include <linux/device.h> #include <linux/dmi.h> #include <linux/i2c.h> #include <linux/i2c-smbus.h> #include <linux/interrupt.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/property.h> #include <linux/slab.h> #include <linux/workqueue.h> struct i2c_smbus_alert { … }; struct alert_data { … }; /* If this is the alerting device, notify its driver */ static int smbus_do_alert(struct device *dev, void *addrp) { … } /* * The alert IRQ handler needs to hand work off to a task which can issue * SMBus calls, because those sleeping calls can't be made in IRQ context. */ static irqreturn_t smbus_alert(int irq, void *d) { … } static void smbalert_work(struct work_struct *work) { … } /* Setup SMBALERT# infrastructure */ static int smbalert_probe(struct i2c_client *ara) { … } /* IRQ and memory resources are managed so they are freed automatically */ static void smbalert_remove(struct i2c_client *ara) { … } static const struct i2c_device_id smbalert_ids[] = …; MODULE_DEVICE_TABLE(i2c, smbalert_ids); static struct i2c_driver smbalert_driver = …; /** * i2c_handle_smbus_alert - Handle an SMBus alert * @ara: the ARA client on the relevant adapter * Context: can't sleep * * Helper function to be called from an I2C bus driver's interrupt * handler. It will schedule the alert work, in turn calling the * corresponding I2C device driver's alert function. * * It is assumed that ara is a valid i2c client previously returned by * i2c_new_smbus_alert_device(). */ int i2c_handle_smbus_alert(struct i2c_client *ara) { … } EXPORT_SYMBOL_GPL(…); module_i2c_driver(…) …; #if IS_ENABLED(CONFIG_I2C_SLAVE) #define SMBUS_HOST_NOTIFY_LEN … struct i2c_slave_host_notify_status { … }; static int i2c_slave_host_notify_cb(struct i2c_client *client, enum i2c_slave_event event, u8 *val) { … } /** * i2c_new_slave_host_notify_device - get a client for SMBus host-notify support * @adapter: the target adapter * Context: can sleep * * Setup handling of the SMBus host-notify protocol on a given I2C bus segment. * * Handling is done by creating a device and its callback and handling data * received via the SMBus host-notify address (0x8) * * This returns the client, which should be ultimately freed using * i2c_free_slave_host_notify_device(); or an ERRPTR to indicate an error. */ struct i2c_client *i2c_new_slave_host_notify_device(struct i2c_adapter *adapter) { … } EXPORT_SYMBOL_GPL(…); /** * i2c_free_slave_host_notify_device - free the client for SMBus host-notify * support * @client: the client to free * Context: can sleep * * Free the i2c_client allocated via i2c_new_slave_host_notify_device */ void i2c_free_slave_host_notify_device(struct i2c_client *client) { … } EXPORT_SYMBOL_GPL(…); #endif /* * SPD is not part of SMBus but we include it here for convenience as the * target systems are the same. * Restrictions to automatic SPD instantiation: * - Only works if all filled slots have the same memory type * - Only works for (LP)DDR memory types up to DDR5 * - Only works on systems with 1 to 8 memory slots */ #if IS_ENABLED(CONFIG_DMI) void i2c_register_spd(struct i2c_adapter *adap) { … } EXPORT_SYMBOL_GPL(…); #endif MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;