Lines Matching refs:dev

117 	struct device		*dev;  member
159 struct bcm_device *dev; member
185 if (speed > 3000000 && !bcm->dev->no_uart_clock_set) { in bcm_set_baudrate()
240 struct bcm_device *dev = list_entry(p, struct bcm_device, list); in bcm_device_exists() local
242 if (device == dev) in bcm_device_exists()
249 static int bcm_gpio_set_power(struct bcm_device *dev, bool powered) in bcm_gpio_set_power() argument
253 if (powered && !dev->res_enabled) { in bcm_gpio_set_power()
257 if (dev->supplies[0].supply) { in bcm_gpio_set_power()
259 dev->supplies); in bcm_gpio_set_power()
265 err = clk_set_rate(dev->lpo_clk, 32768); in bcm_gpio_set_power()
267 dev_err(dev->dev, "Could not set LPO clock rate\n"); in bcm_gpio_set_power()
271 err = clk_prepare_enable(dev->lpo_clk); in bcm_gpio_set_power()
275 err = clk_prepare_enable(dev->txco_clk); in bcm_gpio_set_power()
280 err = dev->set_shutdown(dev, powered); in bcm_gpio_set_power()
284 err = dev->set_device_wakeup(dev, powered); in bcm_gpio_set_power()
288 if (!powered && dev->res_enabled) { in bcm_gpio_set_power()
289 clk_disable_unprepare(dev->txco_clk); in bcm_gpio_set_power()
290 clk_disable_unprepare(dev->lpo_clk); in bcm_gpio_set_power()
295 if (dev->supplies[0].supply) in bcm_gpio_set_power()
297 dev->supplies); in bcm_gpio_set_power()
303 dev->res_enabled = powered; in bcm_gpio_set_power()
308 dev->set_shutdown(dev, !powered); in bcm_gpio_set_power()
310 if (powered && !dev->res_enabled) in bcm_gpio_set_power()
311 clk_disable_unprepare(dev->txco_clk); in bcm_gpio_set_power()
313 if (powered && !dev->res_enabled) in bcm_gpio_set_power()
314 clk_disable_unprepare(dev->lpo_clk); in bcm_gpio_set_power()
316 if (powered && !dev->res_enabled) in bcm_gpio_set_power()
317 regulator_bulk_disable(BCM_NUM_SUPPLIES, dev->supplies); in bcm_gpio_set_power()
328 pm_runtime_get(bdev->dev); in bcm_host_wake()
329 pm_runtime_mark_last_busy(bdev->dev); in bcm_host_wake()
330 pm_runtime_put_autosuspend(bdev->dev); in bcm_host_wake()
337 struct bcm_device *bdev = bcm->dev; in bcm_request_irq()
351 err = devm_request_irq(bdev->dev, bdev->irq, bcm_host_wake, in bcm_request_irq()
362 device_init_wakeup(bdev->dev, true); in bcm_request_irq()
364 pm_runtime_set_autosuspend_delay(bdev->dev, in bcm_request_irq()
366 pm_runtime_use_autosuspend(bdev->dev); in bcm_request_irq()
367 pm_runtime_set_active(bdev->dev); in bcm_request_irq()
368 pm_runtime_enable(bdev->dev); in bcm_request_irq()
398 sleep_params.host_wake_active = !bcm->dev->irq_active_low; in bcm_setup_sleep()
463 bcm->dev = serdev_device_get_drvdata(hu->serdev); in bcm_open()
467 if (!hu->tty->dev) in bcm_open()
471 struct bcm_device *dev = list_entry(p, struct bcm_device, list); in bcm_open() local
477 if (hu->tty->dev->parent == dev->dev->parent) { in bcm_open()
478 bcm->dev = dev; in bcm_open()
480 dev->hu = hu; in bcm_open()
487 if (bcm->dev) { in bcm_open()
488 if (bcm->dev->use_autobaud_mode) in bcm_open()
490 else if (bcm->dev->drive_rts_on_open) in bcm_open()
493 if (bcm->dev->use_autobaud_mode && bcm->dev->max_autobaud_speed) in bcm_open()
494 hu->init_speed = min(bcm->dev->oper_speed, bcm->dev->max_autobaud_speed); in bcm_open()
496 hu->init_speed = bcm->dev->init_speed; in bcm_open()
501 if (!bcm->dev->no_early_set_baudrate && !bcm->dev->use_autobaud_mode) in bcm_open()
502 hu->oper_speed = bcm->dev->oper_speed; in bcm_open()
504 err = bcm_gpio_set_power(bcm->dev, true); in bcm_open()
506 if (bcm->dev->drive_rts_on_open) in bcm_open()
519 bcm->dev->hu = NULL; in bcm_open()
540 } else if (bcm_device_exists(bcm->dev)) { in bcm_close()
541 bdev = bcm->dev; in bcm_close()
549 devm_free_irq(bdev->dev, bdev->irq, bdev); in bcm_close()
550 device_init_wakeup(bdev->dev, false); in bcm_close()
551 pm_runtime_disable(bdev->dev); in bcm_close()
558 pm_runtime_set_suspended(bdev->dev); in bcm_close()
585 bool use_autobaud_mode = (bcm->dev ? bcm->dev->use_autobaud_mode : 0); in bcm_setup()
602 if (bcm->dev && bcm->dev->init_speed) in bcm_setup()
603 speed = bcm->dev->init_speed; in bcm_setup()
615 else if (bcm->dev && bcm->dev->oper_speed) in bcm_setup()
616 speed = bcm->dev->oper_speed; in bcm_setup()
629 if (bcm->dev && bcm->dev->pcm_int_params[0] != 0xff) { in bcm_setup()
634 memcpy(&params, bcm->dev->pcm_int_params, 5); in bcm_setup()
711 if (bcm->dev && bcm_device_exists(bcm->dev)) { in bcm_recv()
712 pm_runtime_get(bcm->dev->dev); in bcm_recv()
713 pm_runtime_mark_last_busy(bcm->dev->dev); in bcm_recv()
714 pm_runtime_put_autosuspend(bcm->dev->dev); in bcm_recv()
743 if (bcm_device_exists(bcm->dev)) { in bcm_dequeue()
744 bdev = bcm->dev; in bcm_dequeue()
745 pm_runtime_get_sync(bdev->dev); in bcm_dequeue()
752 pm_runtime_mark_last_busy(bdev->dev); in bcm_dequeue()
753 pm_runtime_put_autosuspend(bdev->dev); in bcm_dequeue()
762 static int bcm_suspend_device(struct device *dev) in bcm_suspend_device() argument
764 struct bcm_device *bdev = dev_get_drvdata(dev); in bcm_suspend_device()
792 static int bcm_resume_device(struct device *dev) in bcm_resume_device() argument
794 struct bcm_device *bdev = dev_get_drvdata(dev); in bcm_resume_device()
801 dev_err(dev, "Failed to power up\n"); in bcm_resume_device()
821 static int bcm_suspend(struct device *dev) in bcm_suspend() argument
823 struct bcm_device *bdev = dev_get_drvdata(dev); in bcm_suspend()
839 if (pm_runtime_active(dev)) in bcm_suspend()
840 bcm_suspend_device(dev); in bcm_suspend()
842 if (device_may_wakeup(dev) && bdev->irq > 0) { in bcm_suspend()
855 static int bcm_resume(struct device *dev) in bcm_resume() argument
857 struct bcm_device *bdev = dev_get_drvdata(dev); in bcm_resume()
873 if (device_may_wakeup(dev) && bdev->irq > 0) { in bcm_resume()
878 err = bcm_resume_device(dev); in bcm_resume()
884 pm_runtime_disable(dev); in bcm_resume()
885 pm_runtime_set_active(dev); in bcm_resume()
886 pm_runtime_enable(dev); in bcm_resume()
963 struct bcm_device *dev = data; in bcm_resource() local
972 …dev_info(dev->dev, "ACPI Interrupt resource is active-high, this is usually wrong, treating the IR… in bcm_resource()
973 dev->irq_active_low = true; in bcm_resource()
979 dev->gpio_int_idx = dev->gpio_count; in bcm_resource()
980 dev->irq_active_low = gpio->polarity == ACPI_ACTIVE_LOW; in bcm_resource()
982 dev->gpio_count++; in bcm_resource()
988 dev->init_speed = sb->default_baud_rate; in bcm_resource()
989 dev->oper_speed = 4000000; in bcm_resource()
1000 static int bcm_apple_set_device_wakeup(struct bcm_device *dev, bool awake) in bcm_apple_set_device_wakeup() argument
1002 if (ACPI_FAILURE(acpi_execute_simple_method(dev->btlp, NULL, !awake))) in bcm_apple_set_device_wakeup()
1008 static int bcm_apple_set_shutdown(struct bcm_device *dev, bool powered) in bcm_apple_set_shutdown() argument
1010 if (ACPI_FAILURE(acpi_evaluate_object(powered ? dev->btpu : dev->btpd, in bcm_apple_set_shutdown()
1017 static int bcm_apple_get_resources(struct bcm_device *dev) in bcm_apple_get_resources() argument
1019 struct acpi_device *adev = ACPI_COMPANION(dev->dev); in bcm_apple_get_resources()
1023 ACPI_FAILURE(acpi_get_handle(adev->handle, "BTLP", &dev->btlp)) || in bcm_apple_get_resources()
1024 ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPU", &dev->btpu)) || in bcm_apple_get_resources()
1025 ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPD", &dev->btpd))) in bcm_apple_get_resources()
1030 dev->init_speed = *(u64 *)obj->buffer.pointer; in bcm_apple_get_resources()
1032 dev->set_device_wakeup = bcm_apple_set_device_wakeup; in bcm_apple_get_resources()
1033 dev->set_shutdown = bcm_apple_set_shutdown; in bcm_apple_get_resources()
1038 static inline int bcm_apple_get_resources(struct bcm_device *dev) in bcm_apple_get_resources() argument
1044 static int bcm_gpio_set_device_wakeup(struct bcm_device *dev, bool awake) in bcm_gpio_set_device_wakeup() argument
1046 gpiod_set_value_cansleep(dev->device_wakeup, awake); in bcm_gpio_set_device_wakeup()
1050 static int bcm_gpio_set_shutdown(struct bcm_device *dev, bool powered) in bcm_gpio_set_shutdown() argument
1052 gpiod_set_value_cansleep(dev->shutdown, powered); in bcm_gpio_set_shutdown()
1053 if (dev->reset) in bcm_gpio_set_shutdown()
1061 gpiod_set_value_cansleep(dev->reset, !powered); in bcm_gpio_set_shutdown()
1066 static struct clk *bcm_get_txco(struct device *dev) in bcm_get_txco() argument
1071 clk = devm_clk_get(dev, "txco"); in bcm_get_txco()
1076 clk = devm_clk_get(dev, "extclk"); in bcm_get_txco()
1081 return devm_clk_get(dev, NULL); in bcm_get_txco()
1084 static int bcm_get_resources(struct bcm_device *dev) in bcm_get_resources() argument
1090 dev->name = dev_name(dev->dev); in bcm_get_resources()
1092 if (x86_apple_machine && !bcm_apple_get_resources(dev)) in bcm_get_resources()
1095 dev->txco_clk = bcm_get_txco(dev->dev); in bcm_get_resources()
1098 if (dev->txco_clk == ERR_PTR(-EPROBE_DEFER)) in bcm_get_resources()
1099 return PTR_ERR(dev->txco_clk); in bcm_get_resources()
1102 if (IS_ERR(dev->txco_clk)) in bcm_get_resources()
1103 dev->txco_clk = NULL; in bcm_get_resources()
1105 dev->lpo_clk = devm_clk_get(dev->dev, "lpo"); in bcm_get_resources()
1106 if (dev->lpo_clk == ERR_PTR(-EPROBE_DEFER)) in bcm_get_resources()
1107 return PTR_ERR(dev->lpo_clk); in bcm_get_resources()
1109 if (IS_ERR(dev->lpo_clk)) in bcm_get_resources()
1110 dev->lpo_clk = NULL; in bcm_get_resources()
1113 if (dev->lpo_clk && clk_is_match(dev->lpo_clk, dev->txco_clk)) { in bcm_get_resources()
1114 devm_clk_put(dev->dev, dev->txco_clk); in bcm_get_resources()
1115 dev->txco_clk = NULL; in bcm_get_resources()
1118 dev->device_wakeup = devm_gpiod_get_optional(dev->dev, "device-wakeup", in bcm_get_resources()
1120 if (IS_ERR(dev->device_wakeup)) in bcm_get_resources()
1121 return PTR_ERR(dev->device_wakeup); in bcm_get_resources()
1123 dev->shutdown = devm_gpiod_get_optional(dev->dev, "shutdown", in bcm_get_resources()
1125 if (IS_ERR(dev->shutdown)) in bcm_get_resources()
1126 return PTR_ERR(dev->shutdown); in bcm_get_resources()
1128 dev->reset = devm_gpiod_get_optional(dev->dev, "reset", in bcm_get_resources()
1130 if (IS_ERR(dev->reset)) in bcm_get_resources()
1131 return PTR_ERR(dev->reset); in bcm_get_resources()
1133 dev->set_device_wakeup = bcm_gpio_set_device_wakeup; in bcm_get_resources()
1134 dev->set_shutdown = bcm_gpio_set_shutdown; in bcm_get_resources()
1136 dev->supplies[0].supply = "vbat"; in bcm_get_resources()
1137 dev->supplies[1].supply = "vddio"; in bcm_get_resources()
1138 err = devm_regulator_bulk_get(dev->dev, BCM_NUM_SUPPLIES, in bcm_get_resources()
1139 dev->supplies); in bcm_get_resources()
1147 dev->irq_active_low = false; in bcm_get_resources()
1148 dev->irq = 0; in bcm_get_resources()
1152 if (dev->irq <= 0) { in bcm_get_resources()
1155 gpio = devm_gpiod_get_optional(dev->dev, irq_con_id, GPIOD_IN); in bcm_get_resources()
1159 dev->irq = gpiod_to_irq(gpio); in bcm_get_resources()
1166 dev_info(dev->dev, "%s: Has a broken IRQ config, disabling IRQ support / runtime-pm\n", in bcm_get_resources()
1168 dev->irq = 0; in bcm_get_resources()
1172 dev_dbg(dev->dev, "BCM irq: %d\n", dev->irq); in bcm_get_resources()
1177 static int bcm_acpi_probe(struct bcm_device *dev) in bcm_acpi_probe() argument
1185 dev->gpio_int_idx = -1; in bcm_acpi_probe()
1186 ret = acpi_dev_get_resources(ACPI_COMPANION(dev->dev), in bcm_acpi_probe()
1187 &resources, bcm_resource, dev); in bcm_acpi_probe()
1193 dev->irq = entry->res->start; in bcm_acpi_probe()
1203 if (dev->irq) in bcm_acpi_probe()
1205 else if (dev->gpio_int_idx == 0) in bcm_acpi_probe()
1207 else if (dev->gpio_int_idx == 2) in bcm_acpi_probe()
1210 dev_warn(dev->dev, "Unexpected ACPI gpio_int_idx: %d\n", in bcm_acpi_probe()
1211 dev->gpio_int_idx); in bcm_acpi_probe()
1214 if (dev->gpio_count != (dev->irq ? 2 : 3)) in bcm_acpi_probe()
1215 dev_warn(dev->dev, "Unexpected number of ACPI GPIOs: %d\n", in bcm_acpi_probe()
1216 dev->gpio_count); in bcm_acpi_probe()
1218 ret = devm_acpi_dev_add_driver_gpios(dev->dev, gpio_mapping); in bcm_acpi_probe()
1223 dev->irq_active_low = irq_polarity; in bcm_acpi_probe()
1224 dev_warn(dev->dev, "Overwriting IRQ polarity to active %s by module-param\n", in bcm_acpi_probe()
1225 dev->irq_active_low ? "low" : "high"); in bcm_acpi_probe()
1231 static int bcm_acpi_probe(struct bcm_device *dev) in bcm_acpi_probe() argument
1239 bdev->use_autobaud_mode = device_property_read_bool(bdev->dev, in bcm_of_probe()
1241 device_property_read_u32(bdev->dev, "max-speed", &bdev->oper_speed); in bcm_of_probe()
1242 device_property_read_u8_array(bdev->dev, "brcm,bt-pcm-int-params", in bcm_of_probe()
1244 bdev->irq = of_irq_get_byname(bdev->dev->of_node, "host-wakeup"); in bcm_of_probe()
1252 struct bcm_device *dev; in bcm_probe() local
1255 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); in bcm_probe()
1256 if (!dev) in bcm_probe()
1259 dev->dev = &pdev->dev; in bcm_probe()
1265 dev->irq = ret; in bcm_probe()
1268 dev->pcm_int_params[0] = 0xff; in bcm_probe()
1270 if (has_acpi_companion(&pdev->dev)) { in bcm_probe()
1271 ret = bcm_acpi_probe(dev); in bcm_probe()
1276 ret = bcm_get_resources(dev); in bcm_probe()
1280 platform_set_drvdata(pdev, dev); in bcm_probe()
1282 dev_info(&pdev->dev, "%s device registered.\n", dev->name); in bcm_probe()
1286 list_add_tail(&dev->list, &bcm_device_list); in bcm_probe()
1289 ret = bcm_gpio_set_power(dev, false); in bcm_probe()
1291 dev_err(&pdev->dev, "Failed to power down\n"); in bcm_probe()
1298 struct bcm_device *dev = platform_get_drvdata(pdev); in bcm_remove() local
1301 list_del(&dev->list); in bcm_remove()
1304 dev_info(&pdev->dev, "%s device unregistered.\n", dev->name); in bcm_remove()
1526 bcmdev = devm_kzalloc(&serdev->dev, sizeof(*bcmdev), GFP_KERNEL); in bcm_serdev_probe()
1530 bcmdev->dev = &serdev->dev; in bcm_serdev_probe()
1540 if (has_acpi_companion(&serdev->dev)) in bcm_serdev_probe()
1552 dev_warn(&serdev->dev, in bcm_serdev_probe()
1559 dev_err(&serdev->dev, "Failed to power down\n"); in bcm_serdev_probe()
1561 data = device_get_match_data(bcmdev->dev); in bcm_serdev_probe()