diff options
Diffstat (limited to 'drivers/staging/greybus')
-rw-r--r-- | drivers/staging/greybus/Kconfig | 2 | ||||
-rw-r--r-- | drivers/staging/greybus/audio_apbridgea.h | 1 | ||||
-rw-r--r-- | drivers/staging/greybus/audio_manager.c | 8 | ||||
-rw-r--r-- | drivers/staging/greybus/audio_topology.c | 3 | ||||
-rw-r--r-- | drivers/staging/greybus/authentication.c | 6 | ||||
-rw-r--r-- | drivers/staging/greybus/bootrom.c | 8 | ||||
-rw-r--r-- | drivers/staging/greybus/fw-download.c | 15 | ||||
-rw-r--r-- | drivers/staging/greybus/fw-management.c | 20 | ||||
-rw-r--r-- | drivers/staging/greybus/gbphy.c | 8 | ||||
-rw-r--r-- | drivers/staging/greybus/greybus_authentication.h | 6 | ||||
-rw-r--r-- | drivers/staging/greybus/greybus_firmware.h | 8 | ||||
-rw-r--r-- | drivers/staging/greybus/light.c | 21 | ||||
-rw-r--r-- | drivers/staging/greybus/loopback.c | 6 | ||||
-rw-r--r-- | drivers/staging/greybus/pwm.c | 133 | ||||
-rw-r--r-- | drivers/staging/greybus/raw.c | 6 | ||||
-rw-r--r-- | drivers/staging/greybus/spilib.c | 66 | ||||
-rw-r--r-- | drivers/staging/greybus/vibrator.c | 6 |
17 files changed, 137 insertions, 186 deletions
diff --git a/drivers/staging/greybus/Kconfig b/drivers/staging/greybus/Kconfig index 927cfa4bc9..1e745a8d43 100644 --- a/drivers/staging/greybus/Kconfig +++ b/drivers/staging/greybus/Kconfig @@ -64,7 +64,7 @@ config GREYBUS_HID config GREYBUS_LIGHT tristate "Greybus LED Class driver" - depends on LEDS_CLASS + depends on LEDS_CLASS_FLASH help Select this option if you have a device that follows the Greybus LED Class specification. diff --git a/drivers/staging/greybus/audio_apbridgea.h b/drivers/staging/greybus/audio_apbridgea.h index efec0f815e..ab707d3101 100644 --- a/drivers/staging/greybus/audio_apbridgea.h +++ b/drivers/staging/greybus/audio_apbridgea.h @@ -65,7 +65,6 @@ struct audio_apbridgea_hdr { __u8 type; __le16 i2s_port; - __u8 data[]; } __packed; struct audio_apbridgea_set_config_request { diff --git a/drivers/staging/greybus/audio_manager.c b/drivers/staging/greybus/audio_manager.c index 9a3f7c034a..fa43d35bbc 100644 --- a/drivers/staging/greybus/audio_manager.c +++ b/drivers/staging/greybus/audio_manager.c @@ -44,14 +44,14 @@ int gb_audio_manager_add(struct gb_audio_manager_module_descriptor *desc) int id; int err; - id = ida_simple_get(&module_id, 0, 0, GFP_KERNEL); + id = ida_alloc(&module_id, GFP_KERNEL); if (id < 0) return id; err = gb_audio_manager_module_create(&module, manager_kset, id, desc); if (err) { - ida_simple_remove(&module_id, id); + ida_free(&module_id, id); return err; } @@ -78,7 +78,7 @@ int gb_audio_manager_remove(int id) list_del(&module->list); kobject_put(&module->kobj); up_write(&modules_rwsem); - ida_simple_remove(&module_id, id); + ida_free(&module_id, id); return 0; } EXPORT_SYMBOL_GPL(gb_audio_manager_remove); @@ -92,7 +92,7 @@ void gb_audio_manager_remove_all(void) list_for_each_entry_safe(module, next, &modules_list, list) { list_del(&module->list); - ida_simple_remove(&module_id, module->id); + ida_free(&module_id, module->id); kobject_put(&module->kobj); } diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c index 08e6a807c1..5dc4721105 100644 --- a/drivers/staging/greybus/audio_topology.c +++ b/drivers/staging/greybus/audio_topology.c @@ -761,7 +761,6 @@ static int gbcodec_enum_dapm_ctl_put(struct snd_kcontrol *kcontrol, { int ret, wi, ctl_id; unsigned int val, mux, change; - unsigned int mask; struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); struct snd_soc_dapm_widget *widget = wlist->widgets[0]; struct gb_audio_ctl_elem_value gbvalue; @@ -802,7 +801,6 @@ static int gbcodec_enum_dapm_ctl_put(struct snd_kcontrol *kcontrol, mux = ucontrol->value.enumerated.item[0]; val = mux << e->shift_l; - mask = e->mask << e->shift_l; if (le32_to_cpu(gbvalue.value.enumerated_item[0]) != ucontrol->value.enumerated.item[0]) { @@ -815,7 +813,6 @@ static int gbcodec_enum_dapm_ctl_put(struct snd_kcontrol *kcontrol, if (ucontrol->value.enumerated.item[1] > e->items - 1) return -EINVAL; val |= ucontrol->value.enumerated.item[1] << e->shift_r; - mask |= e->mask << e->shift_r; if (le32_to_cpu(gbvalue.value.enumerated_item[1]) != ucontrol->value.enumerated.item[1]) { change = 1; diff --git a/drivers/staging/greybus/authentication.c b/drivers/staging/greybus/authentication.c index b67315641d..d53e58f92e 100644 --- a/drivers/staging/greybus/authentication.c +++ b/drivers/staging/greybus/authentication.c @@ -324,7 +324,7 @@ int gb_cap_connection_init(struct gb_connection *connection) if (ret) goto err_list_del; - minor = ida_simple_get(&cap_minors_map, 0, NUM_MINORS, GFP_KERNEL); + minor = ida_alloc_max(&cap_minors_map, NUM_MINORS - 1, GFP_KERNEL); if (minor < 0) { ret = minor; goto err_connection_disable; @@ -351,7 +351,7 @@ int gb_cap_connection_init(struct gb_connection *connection) err_del_cdev: cdev_del(&cap->cdev); err_remove_ida: - ida_simple_remove(&cap_minors_map, minor); + ida_free(&cap_minors_map, minor); err_connection_disable: gb_connection_disable(connection); err_list_del: @@ -375,7 +375,7 @@ void gb_cap_connection_exit(struct gb_connection *connection) device_destroy(&cap_class, cap->dev_num); cdev_del(&cap->cdev); - ida_simple_remove(&cap_minors_map, MINOR(cap->dev_num)); + ida_free(&cap_minors_map, MINOR(cap->dev_num)); /* * Disallow any new ioctl operations on the char device and wait for diff --git a/drivers/staging/greybus/bootrom.c b/drivers/staging/greybus/bootrom.c index 79581457c4..c0d338db6b 100644 --- a/drivers/staging/greybus/bootrom.c +++ b/drivers/staging/greybus/bootrom.c @@ -243,10 +243,10 @@ static int gb_bootrom_get_firmware(struct gb_operation *op) struct gb_bootrom *bootrom = gb_connection_get_data(op->connection); const struct firmware *fw; struct gb_bootrom_get_firmware_request *firmware_request; - struct gb_bootrom_get_firmware_response *firmware_response; struct device *dev = &op->connection->bundle->dev; unsigned int offset, size; enum next_request_type next_request; + u8 *firmware_response; int ret = 0; /* Disable timeouts */ @@ -280,15 +280,15 @@ static int gb_bootrom_get_firmware(struct gb_operation *op) goto unlock; } - if (!gb_operation_response_alloc(op, sizeof(*firmware_response) + size, - GFP_KERNEL)) { + /* gb_bootrom_get_firmware_response contains only a byte array */ + if (!gb_operation_response_alloc(op, size, GFP_KERNEL)) { dev_err(dev, "%s: error allocating response\n", __func__); ret = -ENOMEM; goto unlock; } firmware_response = op->response->payload; - memcpy(firmware_response->data, fw->data + offset, size); + memcpy(firmware_response, fw->data + offset, size); dev_dbg(dev, "responding with firmware (offs = %u, size = %u)\n", offset, size); diff --git a/drivers/staging/greybus/fw-download.c b/drivers/staging/greybus/fw-download.c index 543692c567..9a09bd3af7 100644 --- a/drivers/staging/greybus/fw-download.c +++ b/drivers/staging/greybus/fw-download.c @@ -63,8 +63,7 @@ static void fw_req_release(struct kref *kref) * just hope that it never happens. */ if (!fw_req->timedout) - ida_simple_remove(&fw_req->fw_download->id_map, - fw_req->firmware_id); + ida_free(&fw_req->fw_download->id_map, fw_req->firmware_id); kfree(fw_req); } @@ -171,7 +170,7 @@ static struct fw_request *find_firmware(struct fw_download *fw_download, return ERR_PTR(-ENOMEM); /* Allocate ids from 1 to 255 (u8-max), 0 is an invalid id */ - ret = ida_simple_get(&fw_download->id_map, 1, 256, GFP_KERNEL); + ret = ida_alloc_range(&fw_download->id_map, 1, 255, GFP_KERNEL); if (ret < 0) { dev_err(fw_download->parent, "failed to allocate firmware id (%d)\n", ret); @@ -212,7 +211,7 @@ static struct fw_request *find_firmware(struct fw_download *fw_download, return fw_req; err_free_id: - ida_simple_remove(&fw_download->id_map, fw_req->firmware_id); + ida_free(&fw_download->id_map, fw_req->firmware_id); err_free_req: kfree(fw_req); @@ -271,11 +270,11 @@ static int fw_download_fetch_firmware(struct gb_operation *op) struct gb_connection *connection = op->connection; struct fw_download *fw_download = gb_connection_get_data(connection); struct gb_fw_download_fetch_firmware_request *request; - struct gb_fw_download_fetch_firmware_response *response; struct fw_request *fw_req; const struct firmware *fw; unsigned int offset, size; u8 firmware_id; + u8 *response; int ret = 0; if (op->request->payload_size != sizeof(*request)) { @@ -325,8 +324,8 @@ static int fw_download_fetch_firmware(struct gb_operation *op) goto put_fw; } - if (!gb_operation_response_alloc(op, sizeof(*response) + size, - GFP_KERNEL)) { + /* gb_fw_download_fetch_firmware_response contains only a byte array */ + if (!gb_operation_response_alloc(op, size, GFP_KERNEL)) { dev_err(fw_download->parent, "error allocating fetch firmware response\n"); ret = -ENOMEM; @@ -334,7 +333,7 @@ static int fw_download_fetch_firmware(struct gb_operation *op) } response = op->response->payload; - memcpy(response->data, fw->data + offset, size); + memcpy(response, fw->data + offset, size); dev_dbg(fw_download->parent, "responding with firmware (offs = %u, size = %u)\n", offset, diff --git a/drivers/staging/greybus/fw-management.c b/drivers/staging/greybus/fw-management.c index 93137a3c49..3054f084d7 100644 --- a/drivers/staging/greybus/fw-management.c +++ b/drivers/staging/greybus/fw-management.c @@ -165,7 +165,7 @@ static int fw_mgmt_load_and_validate_operation(struct fw_mgmt *fw_mgmt, } /* Allocate ids from 1 to 255 (u8-max), 0 is an invalid id */ - ret = ida_simple_get(&fw_mgmt->id_map, 1, 256, GFP_KERNEL); + ret = ida_alloc_range(&fw_mgmt->id_map, 1, 255, GFP_KERNEL); if (ret < 0) { dev_err(fw_mgmt->parent, "failed to allocate request id (%d)\n", ret); @@ -180,8 +180,7 @@ static int fw_mgmt_load_and_validate_operation(struct fw_mgmt *fw_mgmt, GB_FW_MGMT_TYPE_LOAD_AND_VALIDATE_FW, &request, sizeof(request), NULL, 0); if (ret) { - ida_simple_remove(&fw_mgmt->id_map, - fw_mgmt->intf_fw_request_id); + ida_free(&fw_mgmt->id_map, fw_mgmt->intf_fw_request_id); fw_mgmt->intf_fw_request_id = 0; dev_err(fw_mgmt->parent, "load and validate firmware request failed (%d)\n", @@ -220,7 +219,7 @@ static int fw_mgmt_interface_fw_loaded_operation(struct gb_operation *op) return -ENODEV; } - ida_simple_remove(&fw_mgmt->id_map, fw_mgmt->intf_fw_request_id); + ida_free(&fw_mgmt->id_map, fw_mgmt->intf_fw_request_id); fw_mgmt->intf_fw_request_id = 0; fw_mgmt->intf_fw_status = request->status; fw_mgmt->intf_fw_major = le16_to_cpu(request->major); @@ -316,7 +315,7 @@ static int fw_mgmt_backend_fw_update_operation(struct fw_mgmt *fw_mgmt, } /* Allocate ids from 1 to 255 (u8-max), 0 is an invalid id */ - ret = ida_simple_get(&fw_mgmt->id_map, 1, 256, GFP_KERNEL); + ret = ida_alloc_range(&fw_mgmt->id_map, 1, 255, GFP_KERNEL); if (ret < 0) { dev_err(fw_mgmt->parent, "failed to allocate request id (%d)\n", ret); @@ -330,8 +329,7 @@ static int fw_mgmt_backend_fw_update_operation(struct fw_mgmt *fw_mgmt, GB_FW_MGMT_TYPE_BACKEND_FW_UPDATE, &request, sizeof(request), NULL, 0); if (ret) { - ida_simple_remove(&fw_mgmt->id_map, - fw_mgmt->backend_fw_request_id); + ida_free(&fw_mgmt->id_map, fw_mgmt->backend_fw_request_id); fw_mgmt->backend_fw_request_id = 0; dev_err(fw_mgmt->parent, "backend %s firmware update request failed (%d)\n", tag, @@ -369,7 +367,7 @@ static int fw_mgmt_backend_fw_updated_operation(struct gb_operation *op) return -ENODEV; } - ida_simple_remove(&fw_mgmt->id_map, fw_mgmt->backend_fw_request_id); + ida_free(&fw_mgmt->id_map, fw_mgmt->backend_fw_request_id); fw_mgmt->backend_fw_request_id = 0; fw_mgmt->backend_fw_status = request->status; @@ -617,7 +615,7 @@ int gb_fw_mgmt_connection_init(struct gb_connection *connection) if (ret) goto err_list_del; - minor = ida_simple_get(&fw_mgmt_minors_map, 0, NUM_MINORS, GFP_KERNEL); + minor = ida_alloc_max(&fw_mgmt_minors_map, NUM_MINORS - 1, GFP_KERNEL); if (minor < 0) { ret = minor; goto err_connection_disable; @@ -645,7 +643,7 @@ int gb_fw_mgmt_connection_init(struct gb_connection *connection) err_del_cdev: cdev_del(&fw_mgmt->cdev); err_remove_ida: - ida_simple_remove(&fw_mgmt_minors_map, minor); + ida_free(&fw_mgmt_minors_map, minor); err_connection_disable: gb_connection_disable(connection); err_list_del: @@ -669,7 +667,7 @@ void gb_fw_mgmt_connection_exit(struct gb_connection *connection) device_destroy(&fw_mgmt_class, fw_mgmt->dev_num); cdev_del(&fw_mgmt->cdev); - ida_simple_remove(&fw_mgmt_minors_map, MINOR(fw_mgmt->dev_num)); + ida_free(&fw_mgmt_minors_map, MINOR(fw_mgmt->dev_num)); /* * Disallow any new ioctl operations on the char device and wait for diff --git a/drivers/staging/greybus/gbphy.c b/drivers/staging/greybus/gbphy.c index 6a7d8cf2a1..d827f03f52 100644 --- a/drivers/staging/greybus/gbphy.c +++ b/drivers/staging/greybus/gbphy.c @@ -46,7 +46,7 @@ static void gbphy_dev_release(struct device *dev) { struct gbphy_device *gbphy_dev = to_gbphy_dev(dev); - ida_simple_remove(&gbphy_id, gbphy_dev->id); + ida_free(&gbphy_id, gbphy_dev->id); kfree(gbphy_dev); } @@ -182,7 +182,7 @@ static void gbphy_dev_remove(struct device *dev) pm_runtime_dont_use_autosuspend(dev); } -static struct bus_type gbphy_bus_type = { +static const struct bus_type gbphy_bus_type = { .name = "gbphy", .match = gbphy_dev_match, .probe = gbphy_dev_probe, @@ -225,13 +225,13 @@ static struct gbphy_device *gb_gbphy_create_dev(struct gb_bundle *bundle, int retval; int id; - id = ida_simple_get(&gbphy_id, 1, 0, GFP_KERNEL); + id = ida_alloc_min(&gbphy_id, 1, GFP_KERNEL); if (id < 0) return ERR_PTR(id); gbphy_dev = kzalloc(sizeof(*gbphy_dev), GFP_KERNEL); if (!gbphy_dev) { - ida_simple_remove(&gbphy_id, id); + ida_free(&gbphy_id, id); return ERR_PTR(-ENOMEM); } diff --git a/drivers/staging/greybus/greybus_authentication.h b/drivers/staging/greybus/greybus_authentication.h index 48b4a9794d..ee88f880cf 100644 --- a/drivers/staging/greybus/greybus_authentication.h +++ b/drivers/staging/greybus/greybus_authentication.h @@ -44,7 +44,7 @@ /* IOCTL support */ struct cap_ioc_get_endpoint_uid { __u8 uid[8]; -} __attribute__ ((__packed__)); +} __packed; struct cap_ioc_get_ims_certificate { __u32 certificate_class; @@ -53,7 +53,7 @@ struct cap_ioc_get_ims_certificate { __u8 result_code; __u32 cert_size; __u8 certificate[CAP_CERTIFICATE_MAX_SIZE]; -} __attribute__ ((__packed__)); +} __packed; struct cap_ioc_authenticate { __u32 auth_type; @@ -64,7 +64,7 @@ struct cap_ioc_authenticate { __u8 response[64]; __u32 signature_size; __u8 signature[CAP_SIGNATURE_MAX_SIZE]; -} __attribute__ ((__packed__)); +} __packed; #define CAP_IOCTL_BASE 'C' #define CAP_IOC_GET_ENDPOINT_UID _IOR(CAP_IOCTL_BASE, 0, struct cap_ioc_get_endpoint_uid) diff --git a/drivers/staging/greybus/greybus_firmware.h b/drivers/staging/greybus/greybus_firmware.h index f68fd5e253..b6042a82ad 100644 --- a/drivers/staging/greybus/greybus_firmware.h +++ b/drivers/staging/greybus/greybus_firmware.h @@ -41,14 +41,14 @@ struct fw_mgmt_ioc_get_intf_version { __u8 firmware_tag[GB_FIRMWARE_U_TAG_MAX_SIZE]; __u16 major; __u16 minor; -} __attribute__ ((__packed__)); +} __packed; struct fw_mgmt_ioc_get_backend_version { __u8 firmware_tag[GB_FIRMWARE_U_TAG_MAX_SIZE]; __u16 major; __u16 minor; __u8 status; -} __attribute__ ((__packed__)); +} __packed; struct fw_mgmt_ioc_intf_load_and_validate { __u8 firmware_tag[GB_FIRMWARE_U_TAG_MAX_SIZE]; @@ -56,12 +56,12 @@ struct fw_mgmt_ioc_intf_load_and_validate { __u8 status; __u16 major; __u16 minor; -} __attribute__ ((__packed__)); +} __packed; struct fw_mgmt_ioc_backend_fw_update { __u8 firmware_tag[GB_FIRMWARE_U_TAG_MAX_SIZE]; __u8 status; -} __attribute__ ((__packed__)); +} __packed; #define FW_MGMT_IOCTL_BASE 'F' #define FW_MGMT_IOC_GET_INTF_FW _IOR(FW_MGMT_IOCTL_BASE, 0, struct fw_mgmt_ioc_get_intf_version) diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c index c6bd86a533..a5c2fe9638 100644 --- a/drivers/staging/greybus/light.c +++ b/drivers/staging/greybus/light.c @@ -29,13 +29,9 @@ struct gb_channel { struct attribute_group *attr_group; const struct attribute_group **attr_groups; struct led_classdev *led; -#if IS_REACHABLE(CONFIG_LEDS_CLASS_FLASH) struct led_classdev_flash fled; struct led_flash_setting intensity_uA; struct led_flash_setting timeout_us; -#else - struct led_classdev cled; -#endif struct gb_light *light; bool is_registered; bool releasing; @@ -84,7 +80,6 @@ static bool is_channel_flash(struct gb_channel *channel) | GB_CHANNEL_MODE_INDICATOR)); } -#if IS_REACHABLE(CONFIG_LEDS_CLASS_FLASH) static struct gb_channel *get_channel_from_cdev(struct led_classdev *cdev) { struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(cdev); @@ -153,22 +148,6 @@ static int __gb_lights_flash_brightness_set(struct gb_channel *channel) return __gb_lights_flash_intensity_set(channel, intensity); } -#else -static struct gb_channel *get_channel_from_cdev(struct led_classdev *cdev) -{ - return container_of(cdev, struct gb_channel, cled); -} - -static struct led_classdev *get_channel_cdev(struct gb_channel *channel) -{ - return &channel->cled; -} - -static int __gb_lights_flash_brightness_set(struct gb_channel *channel) -{ - return 0; -} -#endif static int gb_lights_color_set(struct gb_channel *channel, u32 color); static int gb_lights_fade_set(struct gb_channel *channel); diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c index d7b39f3bb6..bb33379b52 100644 --- a/drivers/staging/greybus/loopback.c +++ b/drivers/staging/greybus/loopback.c @@ -1028,7 +1028,7 @@ static int gb_loopback_probe(struct gb_bundle *bundle, gb->file = debugfs_create_file(name, S_IFREG | 0444, gb_dev.root, gb, &gb_loopback_dbgfs_latency_fops); - gb->id = ida_simple_get(&loopback_ida, 0, 0, GFP_KERNEL); + gb->id = ida_alloc(&loopback_ida, GFP_KERNEL); if (gb->id < 0) { retval = gb->id; goto out_debugfs_remove; @@ -1079,7 +1079,7 @@ out_conn: out_connection_disable: gb_connection_disable(connection); out_ida_remove: - ida_simple_remove(&loopback_ida, gb->id); + ida_free(&loopback_ida, gb->id); out_debugfs_remove: debugfs_remove(gb->file); out_connection_destroy: @@ -1121,7 +1121,7 @@ static void gb_loopback_disconnect(struct gb_bundle *bundle) spin_unlock_irqrestore(&gb_dev.lock, flags); device_unregister(gb->dev); - ida_simple_remove(&loopback_ida, gb->id); + ida_free(&loopback_ida, gb->id); gb_connection_destroy(gb->connection); kfree(gb); diff --git a/drivers/staging/greybus/pwm.c b/drivers/staging/greybus/pwm.c index a3cb68cfa0..01883fbcd7 100644 --- a/drivers/staging/greybus/pwm.c +++ b/drivers/staging/greybus/pwm.c @@ -16,8 +16,6 @@ struct gb_pwm_chip { struct gb_connection *connection; - u8 pwm_max; /* max pwm number */ - struct pwm_chip chip; }; @@ -26,32 +24,33 @@ static inline struct gb_pwm_chip *pwm_chip_to_gb_pwm_chip(struct pwm_chip *chip) return container_of(chip, struct gb_pwm_chip, chip); } -static int gb_pwm_count_operation(struct gb_pwm_chip *pwmc) +static int gb_pwm_get_npwm(struct gb_connection *connection) { struct gb_pwm_count_response response; int ret; - ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_PWM_COUNT, + ret = gb_operation_sync(connection, GB_PWM_TYPE_PWM_COUNT, NULL, 0, &response, sizeof(response)); if (ret) return ret; - pwmc->pwm_max = response.count; - return 0; + + /* + * The request returns the highest allowed PWM id parameter. So add one + * to get the number of PWMs. + */ + return response.count + 1; } -static int gb_pwm_activate_operation(struct gb_pwm_chip *pwmc, - u8 which) +static int gb_pwm_activate_operation(struct pwm_chip *chip, u8 which) { + struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); struct gb_pwm_activate_request request; struct gbphy_device *gbphy_dev; int ret; - if (which > pwmc->pwm_max) - return -EINVAL; - request.which = which; - gbphy_dev = to_gbphy_dev(pwmc->chip.dev); + gbphy_dev = to_gbphy_dev(pwmchip_parent(chip)); ret = gbphy_runtime_get_sync(gbphy_dev); if (ret) return ret; @@ -64,19 +63,16 @@ static int gb_pwm_activate_operation(struct gb_pwm_chip *pwmc, return ret; } -static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc, - u8 which) +static int gb_pwm_deactivate_operation(struct pwm_chip *chip, u8 which) { + struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); struct gb_pwm_deactivate_request request; struct gbphy_device *gbphy_dev; int ret; - if (which > pwmc->pwm_max) - return -EINVAL; - request.which = which; - gbphy_dev = to_gbphy_dev(pwmc->chip.dev); + gbphy_dev = to_gbphy_dev(pwmchip_parent(chip)); ret = gbphy_runtime_get_sync(gbphy_dev); if (ret) return ret; @@ -89,21 +85,19 @@ static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc, return ret; } -static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc, +static int gb_pwm_config_operation(struct pwm_chip *chip, u8 which, u32 duty, u32 period) { + struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); struct gb_pwm_config_request request; struct gbphy_device *gbphy_dev; int ret; - if (which > pwmc->pwm_max) - return -EINVAL; - request.which = which; request.duty = cpu_to_le32(duty); request.period = cpu_to_le32(period); - gbphy_dev = to_gbphy_dev(pwmc->chip.dev); + gbphy_dev = to_gbphy_dev(pwmchip_parent(chip)); ret = gbphy_runtime_get_sync(gbphy_dev); if (ret) return ret; @@ -116,20 +110,18 @@ static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc, return ret; } -static int gb_pwm_set_polarity_operation(struct gb_pwm_chip *pwmc, +static int gb_pwm_set_polarity_operation(struct pwm_chip *chip, u8 which, u8 polarity) { + struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); struct gb_pwm_polarity_request request; struct gbphy_device *gbphy_dev; int ret; - if (which > pwmc->pwm_max) - return -EINVAL; - request.which = which; request.polarity = polarity; - gbphy_dev = to_gbphy_dev(pwmc->chip.dev); + gbphy_dev = to_gbphy_dev(pwmchip_parent(chip)); ret = gbphy_runtime_get_sync(gbphy_dev); if (ret) return ret; @@ -142,19 +134,16 @@ static int gb_pwm_set_polarity_operation(struct gb_pwm_chip *pwmc, return ret; } -static int gb_pwm_enable_operation(struct gb_pwm_chip *pwmc, - u8 which) +static int gb_pwm_enable_operation(struct pwm_chip *chip, u8 which) { + struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); struct gb_pwm_enable_request request; struct gbphy_device *gbphy_dev; int ret; - if (which > pwmc->pwm_max) - return -EINVAL; - request.which = which; - gbphy_dev = to_gbphy_dev(pwmc->chip.dev); + gbphy_dev = to_gbphy_dev(pwmchip_parent(chip)); ret = gbphy_runtime_get_sync(gbphy_dev); if (ret) return ret; @@ -167,22 +156,19 @@ static int gb_pwm_enable_operation(struct gb_pwm_chip *pwmc, return ret; } -static int gb_pwm_disable_operation(struct gb_pwm_chip *pwmc, - u8 which) +static int gb_pwm_disable_operation(struct pwm_chip *chip, u8 which) { + struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); struct gb_pwm_disable_request request; struct gbphy_device *gbphy_dev; int ret; - if (which > pwmc->pwm_max) - return -EINVAL; - request.which = which; ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_DISABLE, &request, sizeof(request), NULL, 0); - gbphy_dev = to_gbphy_dev(pwmc->chip.dev); + gbphy_dev = to_gbphy_dev(pwmchip_parent(chip)); gbphy_runtime_put_autosuspend(gbphy_dev); return ret; @@ -190,19 +176,15 @@ static int gb_pwm_disable_operation(struct gb_pwm_chip *pwmc, static int gb_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) { - struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); - - return gb_pwm_activate_operation(pwmc, pwm->hwpwm); + return gb_pwm_activate_operation(chip, pwm->hwpwm); }; static void gb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) { - struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); - if (pwm_is_enabled(pwm)) - dev_warn(chip->dev, "freeing PWM device without disabling\n"); + dev_warn(pwmchip_parent(chip), "freeing PWM device without disabling\n"); - gb_pwm_deactivate_operation(pwmc, pwm->hwpwm); + gb_pwm_deactivate_operation(chip, pwm->hwpwm); } static int gb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, @@ -212,22 +194,21 @@ static int gb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, bool enabled = pwm->state.enabled; u64 period = state->period; u64 duty_cycle = state->duty_cycle; - struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); /* Set polarity */ if (state->polarity != pwm->state.polarity) { if (enabled) { - gb_pwm_disable_operation(pwmc, pwm->hwpwm); + gb_pwm_disable_operation(chip, pwm->hwpwm); enabled = false; } - err = gb_pwm_set_polarity_operation(pwmc, pwm->hwpwm, state->polarity); + err = gb_pwm_set_polarity_operation(chip, pwm->hwpwm, state->polarity); if (err) return err; } if (!state->enabled) { if (enabled) - gb_pwm_disable_operation(pwmc, pwm->hwpwm); + gb_pwm_disable_operation(chip, pwm->hwpwm); return 0; } @@ -243,13 +224,13 @@ static int gb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (duty_cycle > period) duty_cycle = period; - err = gb_pwm_config_operation(pwmc, pwm->hwpwm, duty_cycle, period); + err = gb_pwm_config_operation(chip, pwm->hwpwm, duty_cycle, period); if (err) return err; /* enable/disable */ if (!enabled) - return gb_pwm_enable_operation(pwmc, pwm->hwpwm); + return gb_pwm_enable_operation(chip, pwm->hwpwm); return 0; } @@ -266,61 +247,59 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev, struct gb_connection *connection; struct gb_pwm_chip *pwmc; struct pwm_chip *chip; - int ret; - - pwmc = kzalloc(sizeof(*pwmc), GFP_KERNEL); - if (!pwmc) - return -ENOMEM; + int ret, npwm; connection = gb_connection_create(gbphy_dev->bundle, le16_to_cpu(gbphy_dev->cport_desc->id), NULL); - if (IS_ERR(connection)) { - ret = PTR_ERR(connection); - goto exit_pwmc_free; - } - - pwmc->connection = connection; - gb_connection_set_data(connection, pwmc); - gb_gbphy_set_data(gbphy_dev, pwmc); + if (IS_ERR(connection)) + return PTR_ERR(connection); ret = gb_connection_enable(connection); if (ret) goto exit_connection_destroy; /* Query number of pwms present */ - ret = gb_pwm_count_operation(pwmc); - if (ret) + ret = gb_pwm_get_npwm(connection); + if (ret < 0) + goto exit_connection_disable; + npwm = ret; + + chip = pwmchip_alloc(&gbphy_dev->dev, npwm, sizeof(*pwmc)); + if (IS_ERR(chip)) { + ret = PTR_ERR(chip); goto exit_connection_disable; + } + gb_gbphy_set_data(gbphy_dev, chip); - chip = &pwmc->chip; + pwmc = pwm_chip_to_gb_pwm_chip(chip); + pwmc->connection = connection; - chip->dev = &gbphy_dev->dev; chip->ops = &gb_pwm_ops; - chip->npwm = pwmc->pwm_max + 1; ret = pwmchip_add(chip); if (ret) { dev_err(&gbphy_dev->dev, "failed to register PWM: %d\n", ret); - goto exit_connection_disable; + goto exit_pwmchip_put; } gbphy_runtime_put_autosuspend(gbphy_dev); return 0; +exit_pwmchip_put: + pwmchip_put(chip); exit_connection_disable: gb_connection_disable(connection); exit_connection_destroy: gb_connection_destroy(connection); -exit_pwmc_free: - kfree(pwmc); return ret; } static void gb_pwm_remove(struct gbphy_device *gbphy_dev) { - struct gb_pwm_chip *pwmc = gb_gbphy_get_data(gbphy_dev); + struct pwm_chip *chip = gb_gbphy_get_data(gbphy_dev); + struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); struct gb_connection *connection = pwmc->connection; int ret; @@ -328,10 +307,10 @@ static void gb_pwm_remove(struct gbphy_device *gbphy_dev) if (ret) gbphy_runtime_get_noresume(gbphy_dev); - pwmchip_remove(&pwmc->chip); + pwmchip_remove(chip); + pwmchip_put(chip); gb_connection_disable(connection); gb_connection_destroy(connection); - kfree(pwmc); } static const struct gbphy_device_id gb_pwm_id_table[] = { diff --git a/drivers/staging/greybus/raw.c b/drivers/staging/greybus/raw.c index b9c6eff7cd..836d35e5fa 100644 --- a/drivers/staging/greybus/raw.c +++ b/drivers/staging/greybus/raw.c @@ -181,7 +181,7 @@ static int gb_raw_probe(struct gb_bundle *bundle, raw->connection = connection; greybus_set_drvdata(bundle, raw); - minor = ida_simple_get(&minors, 0, 0, GFP_KERNEL); + minor = ida_alloc(&minors, GFP_KERNEL); if (minor < 0) { retval = minor; goto error_connection_destroy; @@ -214,7 +214,7 @@ error_connection_disable: gb_connection_disable(connection); error_remove_ida: - ida_simple_remove(&minors, minor); + ida_free(&minors, minor); error_connection_destroy: gb_connection_destroy(connection); @@ -235,7 +235,7 @@ static void gb_raw_disconnect(struct gb_bundle *bundle) device_destroy(&raw_class, raw->dev); cdev_del(&raw->cdev); gb_connection_disable(connection); - ida_simple_remove(&minors, MINOR(raw->dev)); + ida_free(&minors, MINOR(raw->dev)); gb_connection_destroy(connection); mutex_lock(&raw->list_lock); diff --git a/drivers/staging/greybus/spilib.c b/drivers/staging/greybus/spilib.c index efb3bec58e..34f1068513 100644 --- a/drivers/staging/greybus/spilib.c +++ b/drivers/staging/greybus/spilib.c @@ -42,7 +42,7 @@ struct gb_spilib { #define XFER_TIMEOUT_TOLERANCE 200 -static struct spi_master *get_master_from_spi(struct gb_spilib *spi) +static struct spi_controller *get_controller_from_spi(struct gb_spilib *spi) { return gb_connection_get_data(spi->connection); } @@ -324,10 +324,10 @@ static void gb_spi_decode_response(struct gb_spilib *spi, } } -static int gb_spi_transfer_one_message(struct spi_master *master, +static int gb_spi_transfer_one_message(struct spi_controller *ctlr, struct spi_message *msg) { - struct gb_spilib *spi = spi_master_get_devdata(master); + struct gb_spilib *spi = spi_controller_get_devdata(ctlr); struct gb_connection *connection = spi->connection; struct gb_spi_transfer_response *response; struct gb_operation *operation; @@ -371,21 +371,21 @@ static int gb_spi_transfer_one_message(struct spi_master *master, out: msg->status = ret; clean_xfer_state(spi); - spi_finalize_current_message(master); + spi_finalize_current_message(ctlr); return ret; } -static int gb_spi_prepare_transfer_hardware(struct spi_master *master) +static int gb_spi_prepare_transfer_hardware(struct spi_controller *ctlr) { - struct gb_spilib *spi = spi_master_get_devdata(master); + struct gb_spilib *spi = spi_controller_get_devdata(ctlr); return spi->ops->prepare_transfer_hardware(spi->parent); } -static int gb_spi_unprepare_transfer_hardware(struct spi_master *master) +static int gb_spi_unprepare_transfer_hardware(struct spi_controller *ctlr) { - struct gb_spilib *spi = spi_master_get_devdata(master); + struct gb_spilib *spi = spi_controller_get_devdata(ctlr); spi->ops->unprepare_transfer_hardware(spi->parent); @@ -440,7 +440,7 @@ static int gb_spi_get_master_config(struct gb_spilib *spi) static int gb_spi_setup_device(struct gb_spilib *spi, u8 cs) { - struct spi_master *master = get_master_from_spi(spi); + struct spi_controller *ctlr = get_controller_from_spi(spi); struct gb_spi_device_config_request request; struct gb_spi_device_config_response response; struct spi_board_info spi_board = { {0} }; @@ -471,11 +471,11 @@ static int gb_spi_setup_device(struct gb_spilib *spi, u8 cs) return -EINVAL; spi_board.mode = le16_to_cpu(response.mode); - spi_board.bus_num = master->bus_num; + spi_board.bus_num = ctlr->bus_num; spi_board.chip_select = cs; spi_board.max_speed_hz = le32_to_cpu(response.max_speed_hz); - spidev = spi_new_device(master, &spi_board); + spidev = spi_new_device(ctlr, &spi_board); if (!spidev) return -EINVAL; @@ -486,52 +486,52 @@ int gb_spilib_master_init(struct gb_connection *connection, struct device *dev, struct spilib_ops *ops) { struct gb_spilib *spi; - struct spi_master *master; + struct spi_controller *ctlr; int ret; u8 i; /* Allocate master with space for data */ - master = spi_alloc_master(dev, sizeof(*spi)); - if (!master) { + ctlr = spi_alloc_master(dev, sizeof(*spi)); + if (!ctlr) { dev_err(dev, "cannot alloc SPI master\n"); return -ENOMEM; } - spi = spi_master_get_devdata(master); + spi = spi_controller_get_devdata(ctlr); spi->connection = connection; - gb_connection_set_data(connection, master); + gb_connection_set_data(connection, ctlr); spi->parent = dev; spi->ops = ops; - /* get master configuration */ + /* get controller configuration */ ret = gb_spi_get_master_config(spi); if (ret) goto exit_spi_put; - master->bus_num = -1; /* Allow spi-core to allocate it dynamically */ - master->num_chipselect = spi->num_chipselect; - master->mode_bits = spi->mode; - master->flags = spi->flags; - master->bits_per_word_mask = spi->bits_per_word_mask; + ctlr->bus_num = -1; /* Allow spi-core to allocate it dynamically */ + ctlr->num_chipselect = spi->num_chipselect; + ctlr->mode_bits = spi->mode; + ctlr->flags = spi->flags; + ctlr->bits_per_word_mask = spi->bits_per_word_mask; /* Attach methods */ - master->cleanup = gb_spi_cleanup; - master->setup = gb_spi_setup; - master->transfer_one_message = gb_spi_transfer_one_message; + ctlr->cleanup = gb_spi_cleanup; + ctlr->setup = gb_spi_setup; + ctlr->transfer_one_message = gb_spi_transfer_one_message; if (ops && ops->prepare_transfer_hardware) { - master->prepare_transfer_hardware = + ctlr->prepare_transfer_hardware = gb_spi_prepare_transfer_hardware; } if (ops && ops->unprepare_transfer_hardware) { - master->unprepare_transfer_hardware = + ctlr->unprepare_transfer_hardware = gb_spi_unprepare_transfer_hardware; } - master->auto_runtime_pm = true; + ctlr->auto_runtime_pm = true; - ret = spi_register_master(master); + ret = spi_register_controller(ctlr); if (ret < 0) goto exit_spi_put; @@ -548,12 +548,12 @@ int gb_spilib_master_init(struct gb_connection *connection, struct device *dev, return 0; exit_spi_put: - spi_master_put(master); + spi_controller_put(ctlr); return ret; exit_spi_unregister: - spi_unregister_master(master); + spi_unregister_controller(ctlr); return ret; } @@ -561,9 +561,9 @@ EXPORT_SYMBOL_GPL(gb_spilib_master_init); void gb_spilib_master_exit(struct gb_connection *connection) { - struct spi_master *master = gb_connection_get_data(connection); + struct spi_controller *ctlr = gb_connection_get_data(connection); - spi_unregister_master(master); + spi_unregister_controller(ctlr); } EXPORT_SYMBOL_GPL(gb_spilib_master_exit); diff --git a/drivers/staging/greybus/vibrator.c b/drivers/staging/greybus/vibrator.c index 227e18d92a..89bef80455 100644 --- a/drivers/staging/greybus/vibrator.c +++ b/drivers/staging/greybus/vibrator.c @@ -153,7 +153,7 @@ static int gb_vibrator_probe(struct gb_bundle *bundle, * there is a "real" device somewhere in the kernel for this, but I * can't find it at the moment... */ - vib->minor = ida_simple_get(&minors, 0, 0, GFP_KERNEL); + vib->minor = ida_alloc(&minors, GFP_KERNEL); if (vib->minor < 0) { retval = vib->minor; goto err_connection_disable; @@ -173,7 +173,7 @@ static int gb_vibrator_probe(struct gb_bundle *bundle, return 0; err_ida_remove: - ida_simple_remove(&minors, vib->minor); + ida_free(&minors, vib->minor); err_connection_disable: gb_connection_disable(connection); err_connection_destroy: @@ -197,7 +197,7 @@ static void gb_vibrator_disconnect(struct gb_bundle *bundle) turn_off(vib); device_unregister(vib->dev); - ida_simple_remove(&minors, vib->minor); + ida_free(&minors, vib->minor); gb_connection_disable(vib->connection); gb_connection_destroy(vib->connection); kfree(vib); |