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.

mfd: rk8xx-i2c: Use device_get_match_data

Simplify the device identification logic by supplying the relevant
information via of_match_data. This also removes the dev_info()
printing the chip version, since that's supplied by the match data
now.

Due to lack of hardware this change is compile-tested only.

Tested-by: Diederik de Haas <didi.debian@cknow.org> # Rock64, Quartz64 Model A + B
Tested-by: Vincent Legoll <vincent.legoll@gmail.com> # Pine64 QuartzPro64
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Link: https://lore.kernel.org/r/20230504173618.142075-7-sebastian.reichel@collabora.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Sebastian Reichel and committed by
Lee Jones
74413bd6 c20e8c5b

+36 -53
-2
drivers/mfd/rk8xx-core.c
··· 597 597 return -EINVAL; 598 598 } 599 599 600 - dev_info(dev, "chip id: 0x%x\n", (unsigned int)rk808->variant); 601 - 602 600 if (!irq) 603 601 return dev_err_probe(dev, -EINVAL, "No interrupt support, no core IRQ\n"); 604 602
+36 -51
drivers/mfd/rk8xx-i2c.c
··· 16 16 #include <linux/of.h> 17 17 #include <linux/regmap.h> 18 18 19 + struct rk8xx_i2c_platform_data { 20 + const struct regmap_config *regmap_cfg; 21 + int variant; 22 + }; 23 + 19 24 static bool rk808_is_volatile_reg(struct device *dev, unsigned int reg) 20 25 { 21 26 /* ··· 108 103 .volatile_reg = rk817_is_volatile_reg, 109 104 }; 110 105 111 - static int rk8xx_i2c_get_variant(struct i2c_client *client) 112 - { 113 - u8 pmic_id_msb, pmic_id_lsb; 114 - int msb, lsb; 106 + static const struct rk8xx_i2c_platform_data rk805_data = { 107 + .regmap_cfg = &rk805_regmap_config, 108 + .variant = RK805_ID, 109 + }; 115 110 116 - if (of_device_is_compatible(client->dev.of_node, "rockchip,rk817") || 117 - of_device_is_compatible(client->dev.of_node, "rockchip,rk809")) { 118 - pmic_id_msb = RK817_ID_MSB; 119 - pmic_id_lsb = RK817_ID_LSB; 120 - } else { 121 - pmic_id_msb = RK808_ID_MSB; 122 - pmic_id_lsb = RK808_ID_LSB; 123 - } 111 + static const struct rk8xx_i2c_platform_data rk808_data = { 112 + .regmap_cfg = &rk808_regmap_config, 113 + .variant = RK808_ID, 114 + }; 124 115 125 - /* Read chip variant */ 126 - msb = i2c_smbus_read_byte_data(client, pmic_id_msb); 127 - if (msb < 0) 128 - return dev_err_probe(&client->dev, msb, "failed to read the chip id MSB\n"); 116 + static const struct rk8xx_i2c_platform_data rk809_data = { 117 + .regmap_cfg = &rk817_regmap_config, 118 + .variant = RK809_ID, 119 + }; 129 120 130 - lsb = i2c_smbus_read_byte_data(client, pmic_id_lsb); 131 - if (lsb < 0) 132 - return dev_err_probe(&client->dev, lsb, "failed to read the chip id LSB\n"); 121 + static const struct rk8xx_i2c_platform_data rk817_data = { 122 + .regmap_cfg = &rk817_regmap_config, 123 + .variant = RK817_ID, 124 + }; 133 125 134 - return ((msb << 8) | lsb) & RK8XX_ID_MSK; 135 - } 126 + static const struct rk8xx_i2c_platform_data rk818_data = { 127 + .regmap_cfg = &rk818_regmap_config, 128 + .variant = RK818_ID, 129 + }; 136 130 137 131 static int rk8xx_i2c_probe(struct i2c_client *client) 138 132 { 139 - const struct regmap_config *regmap_cfg; 133 + const struct rk8xx_i2c_platform_data *data; 140 134 struct regmap *regmap; 141 - int variant; 142 135 143 - variant = rk8xx_i2c_get_variant(client); 144 - if (variant < 0) 145 - return variant; 136 + data = device_get_match_data(&client->dev); 137 + if (!data) 138 + return -ENODEV; 146 139 147 - switch (variant) { 148 - case RK805_ID: 149 - regmap_cfg = &rk805_regmap_config; 150 - break; 151 - case RK808_ID: 152 - regmap_cfg = &rk808_regmap_config; 153 - break; 154 - case RK818_ID: 155 - regmap_cfg = &rk818_regmap_config; 156 - break; 157 - case RK809_ID: 158 - case RK817_ID: 159 - regmap_cfg = &rk817_regmap_config; 160 - break; 161 - default: 162 - return dev_err_probe(&client->dev, -EINVAL, "Unsupported RK8XX ID %x\n", variant); 163 - } 164 - 165 - regmap = devm_regmap_init_i2c(client, regmap_cfg); 140 + regmap = devm_regmap_init_i2c(client, data->regmap_cfg); 166 141 if (IS_ERR(regmap)) 167 142 return dev_err_probe(&client->dev, PTR_ERR(regmap), 168 143 "regmap initialization failed\n"); 169 144 170 - return rk8xx_probe(&client->dev, variant, client->irq, regmap); 145 + return rk8xx_probe(&client->dev, data->variant, client->irq, regmap); 171 146 } 172 147 173 148 static void rk8xx_i2c_shutdown(struct i2c_client *client) ··· 158 173 static SIMPLE_DEV_PM_OPS(rk8xx_i2c_pm_ops, rk8xx_suspend, rk8xx_resume); 159 174 160 175 static const struct of_device_id rk8xx_i2c_of_match[] = { 161 - { .compatible = "rockchip,rk805" }, 162 - { .compatible = "rockchip,rk808" }, 163 - { .compatible = "rockchip,rk809" }, 164 - { .compatible = "rockchip,rk817" }, 165 - { .compatible = "rockchip,rk818" }, 176 + { .compatible = "rockchip,rk805", .data = &rk805_data }, 177 + { .compatible = "rockchip,rk808", .data = &rk808_data }, 178 + { .compatible = "rockchip,rk809", .data = &rk809_data }, 179 + { .compatible = "rockchip,rk817", .data = &rk817_data }, 180 + { .compatible = "rockchip,rk818", .data = &rk818_data }, 166 181 { }, 167 182 }; 168 183 MODULE_DEVICE_TABLE(of, rk8xx_i2c_of_match);