Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

misc: amd-sbi: Use regmap subsystem

- regmap subsystem provides multiple benefits over direct smbus APIs
- subsystem adds another abstraction layer on top of struct i2c_client to
make it easy to read or write registers.
- The subsystem can be helpful in following cases
- Different types of bus (i2c/i3c), we have plans to support i3c.
- Different Register address size (1byte/2byte)

Reviewed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>
Signed-off-by: Akshay Gupta <akshay.gupta@amd.com>
Link: https://lore.kernel.org/r/20250428063034.2145566-5-akshay.gupta@amd.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Akshay Gupta and committed by
Greg Kroah-Hartman
013f7e71 f4dc6406

+30 -27
+12 -17
drivers/misc/amd-sbi/rmi-core.c
··· 9 9 #include <linux/err.h> 10 10 #include <linux/i2c.h> 11 11 #include <linux/mutex.h> 12 + #include <linux/regmap.h> 12 13 #include "rmi-core.h" 13 14 14 15 /* Mask for Status Register bit[1] */ ··· 22 21 int rmi_mailbox_xfer(struct sbrmi_data *data, 23 22 struct sbrmi_mailbox_msg *msg) 24 23 { 24 + unsigned int bytes; 25 25 int i, ret, retry = 10; 26 26 int sw_status; 27 27 u8 byte; ··· 30 28 mutex_lock(&data->lock); 31 29 32 30 /* Indicate firmware a command is to be serviced */ 33 - ret = i2c_smbus_write_byte_data(data->client, 34 - SBRMI_INBNDMSG7, START_CMD); 31 + ret = regmap_write(data->regmap, SBRMI_INBNDMSG7, START_CMD); 35 32 if (ret < 0) 36 33 goto exit_unlock; 37 34 38 35 /* Write the command to SBRMI::InBndMsg_inst0 */ 39 - ret = i2c_smbus_write_byte_data(data->client, 40 - SBRMI_INBNDMSG0, msg->cmd); 36 + ret = regmap_write(data->regmap, SBRMI_INBNDMSG0, msg->cmd); 41 37 if (ret < 0) 42 38 goto exit_unlock; 43 39 ··· 46 46 */ 47 47 for (i = 0; i < 4; i++) { 48 48 byte = (msg->data_in >> i * 8) & 0xff; 49 - ret = i2c_smbus_write_byte_data(data->client, 50 - SBRMI_INBNDMSG1 + i, byte); 49 + ret = regmap_write(data->regmap, SBRMI_INBNDMSG1 + i, byte); 51 50 if (ret < 0) 52 51 goto exit_unlock; 53 52 } ··· 55 56 * Write 0x01 to SBRMI::SoftwareInterrupt to notify firmware to 56 57 * perform the requested read or write command 57 58 */ 58 - ret = i2c_smbus_write_byte_data(data->client, 59 - SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); 59 + ret = regmap_write(data->regmap, SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX); 60 60 if (ret < 0) 61 61 goto exit_unlock; 62 62 ··· 65 67 * of the requested command 66 68 */ 67 69 do { 68 - sw_status = i2c_smbus_read_byte_data(data->client, 69 - SBRMI_STATUS); 70 + ret = regmap_read(data->regmap, SBRMI_STATUS, &sw_status); 70 71 if (sw_status < 0) { 71 72 ret = sw_status; 72 73 goto exit_unlock; ··· 76 79 } while (retry--); 77 80 78 81 if (retry < 0) { 79 - dev_err(&data->client->dev, 80 - "Firmware fail to indicate command completion\n"); 81 82 ret = -EIO; 82 83 goto exit_unlock; 83 84 } ··· 87 92 */ 88 93 if (msg->read) { 89 94 for (i = 0; i < 4; i++) { 90 - ret = i2c_smbus_read_byte_data(data->client, 91 - SBRMI_OUTBNDMSG1 + i); 95 + ret = regmap_read(data->regmap, 96 + SBRMI_OUTBNDMSG1 + i, &bytes); 92 97 if (ret < 0) 93 98 goto exit_unlock; 94 - msg->data_out |= ret << i * 8; 99 + msg->data_out |= bytes << i * 8; 95 100 } 96 101 } 97 102 ··· 99 104 * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the 100 105 * ALERT to initiator 101 106 */ 102 - ret = i2c_smbus_write_byte_data(data->client, SBRMI_STATUS, 103 - sw_status | SW_ALERT_MASK); 107 + ret = regmap_write(data->regmap, SBRMI_STATUS, 108 + sw_status | SW_ALERT_MASK); 104 109 105 110 exit_unlock: 106 111 mutex_unlock(&data->lock);
+2 -1
drivers/misc/amd-sbi/rmi-core.h
··· 9 9 #include <linux/mutex.h> 10 10 #include <linux/i2c.h> 11 11 #include <linux/platform_device.h> 12 + #include <linux/regmap.h> 12 13 13 14 /* SB-RMI registers */ 14 15 enum sbrmi_reg { ··· 48 47 49 48 /* Each client has this additional data */ 50 49 struct sbrmi_data { 51 - struct i2c_client *client; 50 + struct regmap *regmap; 52 51 struct mutex lock; 53 52 u32 pwr_limit_max; 54 53 };
+16 -9
drivers/misc/amd-sbi/rmi-i2c.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/mutex.h> 15 15 #include <linux/of.h> 16 + #include <linux/regmap.h> 16 17 #include "rmi-core.h" 17 18 18 - static int sbrmi_enable_alert(struct i2c_client *client) 19 + static int sbrmi_enable_alert(struct sbrmi_data *data) 19 20 { 20 - int ctrl; 21 + int ctrl, ret; 21 22 22 23 /* 23 24 * Enable the SB-RMI Software alert status 24 25 * by writing 0 to bit 4 of Control register(0x1) 25 26 */ 26 - ctrl = i2c_smbus_read_byte_data(client, SBRMI_CTRL); 27 - if (ctrl < 0) 28 - return ctrl; 27 + ret = regmap_read(data->regmap, SBRMI_CTRL, &ctrl); 28 + if (ret < 0) 29 + return ret; 29 30 30 31 if (ctrl & 0x10) { 31 32 ctrl &= ~0x10; 32 - return i2c_smbus_write_byte_data(client, 33 - SBRMI_CTRL, ctrl); 33 + return regmap_write(data->regmap, SBRMI_CTRL, ctrl); 34 34 } 35 35 36 36 return 0; ··· 55 55 { 56 56 struct device *dev = &client->dev; 57 57 struct sbrmi_data *data; 58 + struct regmap_config sbrmi_i2c_regmap_config = { 59 + .reg_bits = 8, 60 + .val_bits = 8, 61 + }; 58 62 int ret; 59 63 60 64 data = devm_kzalloc(dev, sizeof(struct sbrmi_data), GFP_KERNEL); 61 65 if (!data) 62 66 return -ENOMEM; 63 67 64 - data->client = client; 65 68 mutex_init(&data->lock); 66 69 70 + data->regmap = devm_regmap_init_i2c(client, &sbrmi_i2c_regmap_config); 71 + if (IS_ERR(data->regmap)) 72 + return PTR_ERR(data->regmap); 73 + 67 74 /* Enable alert for SB-RMI sequence */ 68 - ret = sbrmi_enable_alert(client); 75 + ret = sbrmi_enable_alert(data); 69 76 if (ret < 0) 70 77 return ret; 71 78