Commit 16426c0dcc228aa6623cd04623304be655bdd08f
Committed by
Afzal Mohammed
1 parent
be0ad06976
Exists in
master
mfd: TPS65910: Handle non-existent devices
Attempt to read the first register of the device, if there is no device return -ENODEV Signed-off-by: Kyle Manna <kyle.manna@fuel7.com> Signed-off-by: Afzal Mohammed <afzal@ti.com>
Showing 1 changed file with 22 additions and 5 deletions Side-by-side Diff
drivers/mfd/tps65910.c
... | ... | @@ -138,6 +138,7 @@ |
138 | 138 | struct tps65910_board *pmic_plat_data; |
139 | 139 | struct tps65910_platform_data *init_data; |
140 | 140 | int ret = 0; |
141 | + unsigned char buff; | |
141 | 142 | |
142 | 143 | pmic_plat_data = dev_get_platdata(&i2c->dev); |
143 | 144 | if (!pmic_plat_data) |
... | ... | @@ -161,9 +162,24 @@ |
161 | 162 | tps65910->write = tps65910_i2c_write; |
162 | 163 | mutex_init(&tps65910->io_mutex); |
163 | 164 | |
164 | - ret = mfd_add_devices(tps65910->dev, -1, | |
165 | - tps65910s, ARRAY_SIZE(tps65910s), | |
166 | - NULL, 0); | |
165 | + /* Check that the device is actually there */ | |
166 | + ret = tps65910_i2c_read(tps65910, 0x0, 1, &buff); | |
167 | + if (ret < 0) { | |
168 | + dev_err(tps65910->dev, "could not be detected\n"); | |
169 | + ret = -ENODEV; | |
170 | + goto err; | |
171 | + } | |
172 | + | |
173 | + dev_info(tps65910->dev, "JTAGREVNUM 0x%x\n", buff); | |
174 | + | |
175 | + if (buff & ~JTAGVERNUM_VERNUM_MASK) { | |
176 | + dev_err(tps65910->dev, "unknown version\n"); | |
177 | + ret = -ENODEV; | |
178 | + goto err; | |
179 | + } | |
180 | + | |
181 | + ret = mfd_add_devices(tps65910->dev, -1, tps65910s, | |
182 | + ARRAY_SIZE(tps65910s), NULL, 0); | |
167 | 183 | if (ret < 0) |
168 | 184 | goto err; |
169 | 185 | |
170 | 186 | |
171 | 187 | |
... | ... | @@ -174,13 +190,14 @@ |
174 | 190 | |
175 | 191 | ret = tps65910_irq_init(tps65910, init_data->irq, init_data); |
176 | 192 | if (ret < 0) |
177 | - goto err; | |
193 | + goto err2; | |
178 | 194 | |
179 | 195 | kfree(init_data); |
180 | 196 | return ret; |
181 | 197 | |
182 | -err: | |
198 | +err2: | |
183 | 199 | mfd_remove_devices(tps65910->dev); |
200 | +err: | |
184 | 201 | kfree(tps65910); |
185 | 202 | kfree(init_data); |
186 | 203 | return ret; |