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

misc: hisi_hikey_usb: change the DT schema

As there's no upstream DT bindings for this driver, let's
update its DT schema, while it is not too late.

While here, add error messages, in order to help discovering
problems during probing time.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/746237a6bdbb84d4271a77994c82bccf524680c7.1630659949.git.mchehab+huawei@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Mauro Carvalho Chehab and committed by
Greg Kroah-Hartman
a34993a2 83c51056

+63 -56
+63 -56
drivers/misc/hisi_hikey_usb.c
··· 34 34 struct device *dev; 35 35 struct gpio_desc *otg_switch; 36 36 struct gpio_desc *typec_vbus; 37 - struct gpio_desc *hub_vbus; 38 37 struct gpio_desc *reset; 39 38 40 39 struct regulator *regulator; ··· 52 53 static void hub_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, int value) 53 54 { 54 55 int ret, status; 55 - 56 - if (hisi_hikey_usb->hub_vbus) 57 - gpiod_set_value_cansleep(hisi_hikey_usb->hub_vbus, value); 58 56 59 57 if (!hisi_hikey_usb->regulator) 60 58 return; ··· 143 147 return 0; 144 148 } 145 149 146 - static int hisi_hikey_usb_parse_kirin970(struct platform_device *pdev, 150 + static int hisi_hikey_usb_of_role_switch(struct platform_device *pdev, 147 151 struct hisi_hikey_usb *hisi_hikey_usb) 148 152 { 149 - struct regulator *regulator; 150 - 151 - regulator = devm_regulator_get(&pdev->dev, "hub-vdd"); 152 - if (IS_ERR(regulator)) { 153 - if (PTR_ERR(regulator) == -EPROBE_DEFER) { 154 - dev_info(&pdev->dev, 155 - "waiting for hub-vdd-supply to be probed\n"); 156 - return PTR_ERR(regulator); 157 - } 158 - dev_err(&pdev->dev, 159 - "get hub-vdd-supply failed with error %ld\n", 160 - PTR_ERR(regulator)); 161 - return PTR_ERR(regulator); 162 - } 163 - hisi_hikey_usb->regulator = regulator; 164 - 165 - hisi_hikey_usb->reset = devm_gpiod_get(&pdev->dev, "hub_reset_en_gpio", 166 - GPIOD_OUT_HIGH); 167 - return PTR_ERR_OR_ZERO(hisi_hikey_usb->reset); 168 - } 169 - 170 - static int hisi_hikey_usb_probe(struct platform_device *pdev) 171 - { 172 153 struct device *dev = &pdev->dev; 173 - struct hisi_hikey_usb *hisi_hikey_usb; 174 154 struct usb_role_switch_desc hub_role_switch = {NULL}; 175 - int ret; 176 155 177 - hisi_hikey_usb = devm_kzalloc(dev, sizeof(*hisi_hikey_usb), GFP_KERNEL); 178 - if (!hisi_hikey_usb) 179 - return -ENOMEM; 180 - 181 - hisi_hikey_usb->dev = &pdev->dev; 156 + if (!device_property_read_bool(dev, "usb-role-switch")) 157 + return 0; 182 158 183 159 hisi_hikey_usb->otg_switch = devm_gpiod_get(dev, "otg-switch", 184 160 GPIOD_OUT_HIGH); 185 - if (IS_ERR(hisi_hikey_usb->otg_switch)) 161 + if (IS_ERR(hisi_hikey_usb->otg_switch)) { 162 + dev_err(dev, "get otg-switch failed with error %ld\n", 163 + PTR_ERR(hisi_hikey_usb->otg_switch)); 186 164 return PTR_ERR(hisi_hikey_usb->otg_switch); 165 + } 187 166 188 167 hisi_hikey_usb->typec_vbus = devm_gpiod_get(dev, "typec-vbus", 189 168 GPIOD_OUT_LOW); 190 - if (IS_ERR(hisi_hikey_usb->typec_vbus)) 169 + if (IS_ERR(hisi_hikey_usb->typec_vbus)) { 170 + dev_err(dev, "get typec-vbus failed with error %ld\n", 171 + PTR_ERR(hisi_hikey_usb->typec_vbus)); 191 172 return PTR_ERR(hisi_hikey_usb->typec_vbus); 173 + } 192 174 193 - /* Parse Kirin 970-specific OF data */ 194 - if (of_device_is_compatible(pdev->dev.of_node, 195 - "hisilicon,kirin970_hikey_usbhub")) { 196 - ret = hisi_hikey_usb_parse_kirin970(pdev, hisi_hikey_usb); 197 - if (ret) 198 - return ret; 199 - } else { 200 - /* hub-vdd33-en is optional */ 201 - hisi_hikey_usb->hub_vbus = devm_gpiod_get_optional(dev, "hub-vdd33-en", 202 - GPIOD_OUT_HIGH); 203 - if (IS_ERR(hisi_hikey_usb->hub_vbus)) 204 - return PTR_ERR(hisi_hikey_usb->hub_vbus); 175 + hisi_hikey_usb->reset = devm_gpiod_get_optional(dev, 176 + "hub-reset-en", 177 + GPIOD_OUT_HIGH); 178 + if (IS_ERR(hisi_hikey_usb->reset)) { 179 + dev_err(dev, "get hub-reset-en failed with error %ld\n", 180 + PTR_ERR(hisi_hikey_usb->reset)); 181 + return PTR_ERR(hisi_hikey_usb->reset); 205 182 } 206 183 207 184 hisi_hikey_usb->dev_role_sw = usb_role_switch_get(dev); 208 185 if (!hisi_hikey_usb->dev_role_sw) 209 186 return -EPROBE_DEFER; 210 - if (IS_ERR(hisi_hikey_usb->dev_role_sw)) 187 + if (IS_ERR(hisi_hikey_usb->dev_role_sw)) { 188 + dev_err(dev, "get device role switch failed with error %ld\n", 189 + PTR_ERR(hisi_hikey_usb->dev_role_sw)); 211 190 return PTR_ERR(hisi_hikey_usb->dev_role_sw); 191 + } 212 192 213 193 INIT_WORK(&hisi_hikey_usb->work, relay_set_role_switch); 214 - mutex_init(&hisi_hikey_usb->lock); 215 194 216 195 hub_role_switch.fwnode = dev_fwnode(dev); 217 196 hub_role_switch.set = hub_usb_role_switch_set; ··· 196 225 &hub_role_switch); 197 226 198 227 if (IS_ERR(hisi_hikey_usb->hub_role_sw)) { 228 + dev_err(dev, 229 + "failed to register hub role with error %ld\n", 230 + PTR_ERR(hisi_hikey_usb->hub_role_sw)); 199 231 usb_role_switch_put(hisi_hikey_usb->dev_role_sw); 200 232 return PTR_ERR(hisi_hikey_usb->hub_role_sw); 201 233 } 234 + 235 + return 0; 236 + } 237 + 238 + static int hisi_hikey_usb_probe(struct platform_device *pdev) 239 + { 240 + struct device *dev = &pdev->dev; 241 + struct hisi_hikey_usb *hisi_hikey_usb; 242 + int ret; 243 + 244 + hisi_hikey_usb = devm_kzalloc(dev, sizeof(*hisi_hikey_usb), GFP_KERNEL); 245 + if (!hisi_hikey_usb) 246 + return -ENOMEM; 247 + 248 + hisi_hikey_usb->dev = &pdev->dev; 249 + mutex_init(&hisi_hikey_usb->lock); 250 + 251 + hisi_hikey_usb->regulator = devm_regulator_get(dev, "hub-vdd"); 252 + if (IS_ERR(hisi_hikey_usb->regulator)) { 253 + if (PTR_ERR(hisi_hikey_usb->regulator) == -EPROBE_DEFER) { 254 + dev_info(dev, "waiting for hub-vdd-supply\n"); 255 + return PTR_ERR(hisi_hikey_usb->regulator); 256 + } 257 + dev_err(dev, "get hub-vdd-supply failed with error %ld\n", 258 + PTR_ERR(hisi_hikey_usb->regulator)); 259 + return PTR_ERR(hisi_hikey_usb->regulator); 260 + } 261 + 262 + ret = hisi_hikey_usb_of_role_switch(pdev, hisi_hikey_usb); 263 + if (ret) 264 + return ret; 202 265 203 266 platform_set_drvdata(pdev, hisi_hikey_usb); 204 267 ··· 243 238 { 244 239 struct hisi_hikey_usb *hisi_hikey_usb = platform_get_drvdata(pdev); 245 240 246 - if (hisi_hikey_usb->hub_role_sw) 241 + if (hisi_hikey_usb->hub_role_sw) { 247 242 usb_role_switch_unregister(hisi_hikey_usb->hub_role_sw); 248 243 249 - if (hisi_hikey_usb->dev_role_sw) 250 - usb_role_switch_put(hisi_hikey_usb->dev_role_sw); 244 + if (hisi_hikey_usb->dev_role_sw) 245 + usb_role_switch_put(hisi_hikey_usb->dev_role_sw); 246 + } else { 247 + hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_OFF); 248 + } 251 249 252 250 return 0; 253 251 } 254 252 255 253 static const struct of_device_id id_table_hisi_hikey_usb[] = { 256 - { .compatible = "hisilicon,gpio_hubv1" }, 257 - { .compatible = "hisilicon,kirin970_hikey_usbhub" }, 254 + { .compatible = "hisilicon,usbhub" }, 258 255 {} 259 256 }; 260 257 MODULE_DEVICE_TABLE(of, id_table_hisi_hikey_usb);