Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * i2c-nforce2-s4985.c - i2c-nforce2 extras for the Tyan S4985 motherboard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2008 Jean Delvare <jdelvare@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * We select the channels by sending commands to the Philips
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * PCA9556 chip at I2C address 0x18. The main adapter is used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * the non-multiplexed part of the bus, and 4 virtual adapters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * are defined for the multiplexed addresses: 0x50-0x53 (memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * module EEPROM) located on channels 1-4. We define one virtual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * adapter per CPU, which corresponds to one multiplexed channel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *   CPU0: virtual adapter 1, channel 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *   CPU1: virtual adapter 2, channel 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *   CPU2: virtual adapter 3, channel 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *   CPU3: virtual adapter 4, channel 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) extern struct i2c_adapter *nforce2_smbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static struct i2c_adapter *s4985_adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static struct i2c_algorithm *s4985_algo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /* Wrapper access functions for multiplexed SMBus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static DEFINE_MUTEX(nforce2_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static s32 nforce2_access_virt0(struct i2c_adapter *adap, u16 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 				unsigned short flags, char read_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 				u8 command, int size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 				union i2c_smbus_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	/* We exclude the multiplexed addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if ((addr & 0xfc) == 0x50 || (addr & 0xfc) == 0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	 || addr == 0x18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	mutex_lock(&nforce2_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	error = nforce2_smbus->algo->smbus_xfer(adap, addr, flags, read_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 						command, size, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	mutex_unlock(&nforce2_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) /* We remember the last used channels combination so as to only switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)    channels when it is really needed. This greatly reduces the SMBus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)    overhead, but also assumes that nobody will be writing to the PCA9556
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)    in our back. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static u8 last_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static inline s32 nforce2_access_channel(struct i2c_adapter *adap, u16 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 					 unsigned short flags, char read_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 					 u8 command, int size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 					 union i2c_smbus_data *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 					 u8 channels)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	/* We exclude the non-multiplexed addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if ((addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	mutex_lock(&nforce2_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (last_channels != channels) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		union i2c_smbus_data mplxdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		mplxdata.byte = channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		error = nforce2_smbus->algo->smbus_xfer(adap, 0x18, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 							I2C_SMBUS_WRITE, 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 							I2C_SMBUS_BYTE_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 							&mplxdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			goto UNLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		last_channels = channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	error = nforce2_smbus->algo->smbus_xfer(adap, addr, flags, read_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 						command, size, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) UNLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	mutex_unlock(&nforce2_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static s32 nforce2_access_virt1(struct i2c_adapter *adap, u16 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 				unsigned short flags, char read_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				u8 command, int size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 				union i2c_smbus_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	/* CPU0: channel 1 enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return nforce2_access_channel(adap, addr, flags, read_write, command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 				      size, data, 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static s32 nforce2_access_virt2(struct i2c_adapter *adap, u16 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				unsigned short flags, char read_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 				u8 command, int size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				union i2c_smbus_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	/* CPU1: channel 2 enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return nforce2_access_channel(adap, addr, flags, read_write, command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 				      size, data, 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static s32 nforce2_access_virt3(struct i2c_adapter *adap, u16 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 				unsigned short flags, char read_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				u8 command, int size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 				union i2c_smbus_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/* CPU2: channel 3 enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return nforce2_access_channel(adap, addr, flags, read_write, command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				      size, data, 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static s32 nforce2_access_virt4(struct i2c_adapter *adap, u16 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				unsigned short flags, char read_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 				u8 command, int size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 				union i2c_smbus_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/* CPU3: channel 4 enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return nforce2_access_channel(adap, addr, flags, read_write, command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 				      size, data, 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static int __init nforce2_s4985_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	int i, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	union i2c_smbus_data ioconfig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (!nforce2_smbus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* Configure the PCA9556 multiplexer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	ioconfig.byte = 0x00; /* All I/O to output mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			       I2C_SMBUS_BYTE_DATA, &ioconfig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		dev_err(&nforce2_smbus->dev, "PCA9556 configuration failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		goto ERROR0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/* Unregister physical bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	i2c_del_adapter(nforce2_smbus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	printk(KERN_INFO "Enabling SMBus multiplexing for Tyan S4985\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/* Define the 5 virtual adapters and algorithms structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	s4985_adapter = kcalloc(5, sizeof(struct i2c_adapter), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (!s4985_adapter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		goto ERROR1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	s4985_algo = kcalloc(5, sizeof(struct i2c_algorithm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (!s4985_algo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		goto ERROR2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* Fill in the new structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	s4985_algo[0] = *(nforce2_smbus->algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	s4985_algo[0].smbus_xfer = nforce2_access_virt0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	s4985_adapter[0] = *nforce2_smbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	s4985_adapter[0].algo = s4985_algo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	s4985_adapter[0].dev.parent = nforce2_smbus->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	for (i = 1; i < 5; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		s4985_algo[i] = *(nforce2_smbus->algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		s4985_adapter[i] = *nforce2_smbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		snprintf(s4985_adapter[i].name, sizeof(s4985_adapter[i].name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			 "SMBus nForce2 adapter (CPU%d)", i - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		s4985_adapter[i].algo = s4985_algo + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		s4985_adapter[i].dev.parent = nforce2_smbus->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	s4985_algo[1].smbus_xfer = nforce2_access_virt1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	s4985_algo[2].smbus_xfer = nforce2_access_virt2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	s4985_algo[3].smbus_xfer = nforce2_access_virt3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	s4985_algo[4].smbus_xfer = nforce2_access_virt4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	/* Register virtual adapters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	for (i = 0; i < 5; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		error = i2c_add_adapter(s4985_adapter + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			printk(KERN_ERR "i2c-nforce2-s4985: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			       "Virtual adapter %d registration "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			       "failed, module not inserted\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			for (i--; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 				i2c_del_adapter(s4985_adapter + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			goto ERROR3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ERROR3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	kfree(s4985_algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	s4985_algo = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ERROR2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	kfree(s4985_adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	s4985_adapter = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) ERROR1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	/* Restore physical bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	i2c_add_adapter(nforce2_smbus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ERROR0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static void __exit nforce2_s4985_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (s4985_adapter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		for (i = 0; i < 5; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			i2c_del_adapter(s4985_adapter+i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		kfree(s4985_adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		s4985_adapter = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	kfree(s4985_algo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	s4985_algo = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	/* Restore physical bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (i2c_add_adapter(nforce2_smbus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		printk(KERN_ERR "i2c-nforce2-s4985: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		       "Physical bus restoration failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) MODULE_DESCRIPTION("S4985 SMBus multiplexing");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) module_init(nforce2_s4985_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) module_exit(nforce2_s4985_exit);