commit_title
stringlengths
13
124
commit_body
stringlengths
0
1.9k
release_summary
stringclasses
52 values
changes_summary
stringlengths
1
758
release_affected_domains
stringclasses
33 values
release_affected_drivers
stringclasses
51 values
domain_of_changes
stringlengths
2
571
language_set
stringclasses
983 values
diffstat_files
int64
1
300
diffstat_insertions
int64
0
309k
diffstat_deletions
int64
0
168k
commit_diff
stringlengths
92
23.4M
category
stringclasses
108 values
commit_hash
stringlengths
34
40
related_people
stringlengths
0
370
domain
stringclasses
21 values
subdomain
stringclasses
241 values
leaf_module
stringlengths
0
912
media: ov5647: support v4l2_cid_hblank control
add support for the v4l2_cid_hblank read-only control.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support raspberrypi camera module
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['ov5647']
['c']
1
26
1
--- diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c + int hts; + struct v4l2_ctrl *hblank; + .hts = 1896, + .hts = 2844, + .hts = 2416, + .hts = 1896, + .hts = 1852, + int hblank; + + + hblank = mode->hts - mode->format.width; + __v4l2_ctrl_modify_range(sensor->hblank, hblank, hblank, 1, + hblank); + case v4l2_cid_hblank: + /* read-only, but we adjust it based on mode. */ + return 0; + int hblank; - v4l2_ctrl_handler_init(&sensor->ctrls, 6); + v4l2_ctrl_handler_init(&sensor->ctrls, 7); + + /* by default, hblank is read only, but it does change per mode. */ + hblank = sensor->mode->hts - sensor->mode->format.width; + sensor->hblank = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops, + v4l2_cid_hblank, hblank, hblank, 1, + hblank); + + sensor->hblank->flags |= v4l2_ctrl_flag_read_only;
TV tuners, webcams, video capturers
c6da1ae49edd02704ce4589189d7895eae55f658
jacopo mondi
drivers
media
i2c
media: ov5647: support v4l2_cid_vblank control
adds vblank control to allow for frame rate control.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support raspberrypi camera module
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['ov5647']
['c']
1
46
4
--- diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c +#define ov5647_reg_vts_hi 0x380e +#define ov5647_reg_vts_lo 0x380f +#define ov5647_vblank_min 4 +#define ov5647_vts_max 32767 + + int vts; + struct v4l2_ctrl *vblank; - {0x380e, 0x03}, - {0x380f, 0xd8}, + .vts = 0x3d8, + .vts = 0x7b0, + .vts = 0x450, + .vts = 0x59b, + .vts = 0x1f8, +static int ov5647_write16(struct v4l2_subdev *sd, u16 reg, u16 val) +{ + unsigned char data[4] = { reg >> 8, reg & 0xff, val >> 8, val & 0xff}; + struct i2c_client *client = v4l2_get_subdevdata(sd); + int ret; + + ret = i2c_master_send(client, data, 4); + if (ret < 0) { + dev_dbg(&client->dev, "%s: i2c write error, reg: %x ", + __func__, reg); + return ret; + } + + return 0; +} + - int hblank; + int hblank, vblank; + + vblank = mode->vts - mode->format.height; + __v4l2_ctrl_modify_range(sensor->vblank, ov5647_vblank_min, + ov5647_vts_max - mode->format.height, + 1, vblank); + __v4l2_ctrl_s_ctrl(sensor->vblank, vblank); + case v4l2_cid_vblank: + return ov5647_write16(sd, ov5647_reg_vts_hi, + sensor->mode->format.height + ctrl->val); - v4l2_ctrl_handler_init(&sensor->ctrls, 7); + v4l2_ctrl_handler_init(&sensor->ctrls, 8); + sensor->vblank = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops, + v4l2_cid_vblank, ov5647_vblank_min, + ov5647_vts_max - + sensor->mode->format.height, 1, + sensor->mode->vts - + sensor->mode->format.height); +
TV tuners, webcams, video capturers
2512c06441e3f0dd505c3f00274fff892c111c8f
dave stevenson
drivers
media
i2c
media: ov5647: advertise the correct exposure range
exposure is clipped by the vts of the mode, so it needs to be updated when this is changed.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support raspberrypi camera module
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['ov5647']
['c']
1
35
4
--- diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c +#define ov5647_exposure_min 4 +#define ov5647_exposure_step 1 +#define ov5647_exposure_default 1000 +#define ov5647_exposure_max 65535 + + struct v4l2_ctrl *exposure; + + int exposure_max, exposure_def; + + exposure_max = mode->vts - 4; + exposure_def = min(exposure_max, ov5647_exposure_default); + __v4l2_ctrl_modify_range(sensor->exposure, + sensor->exposure->minimum, + exposure_max, sensor->exposure->step, + exposure_def); + if (ctrl->id == v4l2_cid_vblank) { + int exposure_max, exposure_def; + + /* update max exposure while meeting expected vblanking */ + exposure_max = sensor->mode->format.height + ctrl->val - 4; + exposure_def = min(exposure_max, ov5647_exposure_default); + __v4l2_ctrl_modify_range(sensor->exposure, + sensor->exposure->minimum, + exposure_max, sensor->exposure->step, + exposure_def); + } + - int hblank; + int hblank, exposure_max, exposure_def; - /* min: 4 lines; max: 0xffff lines; default: 1000 lines. */ - v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops, - v4l2_cid_exposure, 4, 65535, 1, 1000); + exposure_max = sensor->mode->vts - 4; + exposure_def = min(exposure_max, ov5647_exposure_default); + sensor->exposure = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops, + v4l2_cid_exposure, + ov5647_exposure_min, + exposure_max, ov5647_exposure_step, + exposure_def);
TV tuners, webcams, video capturers
646a0249ffd0d8334ec291e3380845b8ade2f1a0
dave stevenson
drivers
media
i2c
media: ov5647: use pm_runtime infrastructure
use the pm_runtime framework to replace the legacy s_power() operation.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support raspberrypi camera module
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['ov5647']
['c']
1
71
71
--- diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c +#include <linux/pm_runtime.h> -static int set_sw_standby(struct v4l2_subdev *sd, bool standby) +static int ov5647_power_on(struct device *dev) + struct ov5647 *sensor = dev_get_drvdata(dev); - u8 rdval; - ret = ov5647_read(sd, ov5647_sw_standby, &rdval); - if (ret < 0) - return ret; + dev_dbg(dev, "ov5647 power on "); - if (standby) - rdval &= ~0x01; - else - rdval |= 0x01; - - return ov5647_write(sd, ov5647_sw_standby, rdval); -} + if (sensor->pwdn) { + gpiod_set_value_cansleep(sensor->pwdn, 0); + msleep(pwdn_active_delay_ms); + } -static int ov5647_sensor_power(struct v4l2_subdev *sd, int on) -{ - struct i2c_client *client = v4l2_get_subdevdata(sd); - struct ov5647 *sensor = to_sensor(sd); - int ret = 0; + ret = clk_prepare_enable(sensor->xclk); + if (ret < 0) { + dev_err(dev, "clk prepare enable failed "); + goto error_pwdn; + } - mutex_lock(&sensor->lock); + ret = ov5647_write_array(&sensor->sd, sensor_oe_enable_regs, + array_size(sensor_oe_enable_regs)); + if (ret < 0) { + dev_err(dev, "write sensor_oe_enable_regs error "); + goto error_clk_disable; + } - if (on && !sensor->power_count) { - dev_dbg(&client->dev, "ov5647 power on "); + /* stream off to coax lanes into lp-11 state. */ + ret = ov5647_stream_off(&sensor->sd); + if (ret < 0) { + dev_err(dev, "camera not available, check power "); + goto error_clk_disable; + } - if (sensor->pwdn) { - gpiod_set_value_cansleep(sensor->pwdn, 0); - msleep(pwdn_active_delay_ms); - } + return 0; - ret = clk_prepare_enable(sensor->xclk); - if (ret < 0) { - dev_err(&client->dev, "clk prepare enable failed "); - goto out; - } +error_clk_disable: + clk_disable_unprepare(sensor->xclk); +error_pwdn: + gpiod_set_value_cansleep(sensor->pwdn, 1); - ret = ov5647_write_array(sd, sensor_oe_enable_regs, - array_size(sensor_oe_enable_regs)); - if (ret < 0) { - clk_disable_unprepare(sensor->xclk); - dev_err(&client->dev, - "write sensor_oe_enable_regs error "); - goto out; - } + return ret; +} - /* stream off to coax lanes into lp-11 state. */ - ret = ov5647_stream_off(sd); - if (ret < 0) { - clk_disable_unprepare(sensor->xclk); - dev_err(&client->dev, - "camera not available, check power "); - goto out; - } - } else if (!on && sensor->power_count == 1) { - dev_dbg(&client->dev, "ov5647 power off "); +static int ov5647_power_off(struct device *dev) +{ + struct ov5647 *sensor = dev_get_drvdata(dev); + u8 rdval; + int ret; - ret = ov5647_write_array(sd, sensor_oe_disable_regs, - array_size(sensor_oe_disable_regs)); - if (ret < 0) - dev_dbg(&client->dev, "disable oe failed "); + dev_dbg(dev, "ov5647 power off "); - ret = set_sw_standby(sd, true); - if (ret < 0) - dev_dbg(&client->dev, "soft stby failed "); + ret = ov5647_write_array(&sensor->sd, sensor_oe_disable_regs, + array_size(sensor_oe_disable_regs)); + if (ret < 0) + dev_dbg(dev, "disable oe failed "); - clk_disable_unprepare(sensor->xclk); - gpiod_set_value_cansleep(sensor->pwdn, 1); - } + /* enter software standby */ + ret = ov5647_read(&sensor->sd, ov5647_sw_standby, &rdval); + if (ret < 0) + dev_dbg(dev, "software standby failed "); - /* update the power count. */ - sensor->power_count += on ? 1 : -1; - warn_on(sensor->power_count < 0); + rdval &= ~0x01; + ret = ov5647_write(&sensor->sd, ov5647_sw_standby, rdval); + if (ret < 0) + dev_dbg(dev, "software standby failed "); -out: - mutex_unlock(&sensor->lock); + clk_disable_unprepare(sensor->xclk); + gpiod_set_value_cansleep(sensor->pwdn, 1); - return ret; + return 0; - .s_power = ov5647_sensor_power, - if (sensor->pwdn) { - gpiod_set_value_cansleep(sensor->pwdn, 0); - msleep(pwdn_active_delay_ms); - } + ret = ov5647_power_on(dev); + if (ret) + goto entity_cleanup; - gpiod_set_value_cansleep(sensor->pwdn, 1); - goto entity_cleanup; + goto power_off; - goto entity_cleanup; + goto power_off; + + /* enable runtime pm and turn off the device */ + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + pm_runtime_idle(dev); +power_off: + ov5647_power_off(dev); + pm_runtime_disable(&client->dev); +static const struct dev_pm_ops ov5647_pm_ops = { + set_runtime_pm_ops(ov5647_power_off, ov5647_power_on, null) +}; + + .pm = &ov5647_pm_ops,
TV tuners, webcams, video capturers
089b7c70f0d80f5169cc87f65b065fc80668a0eb
jacopo mondi
drivers
media
i2c
media: ov5647: rework s_stream() operation
rework the s_stream() operation to turn the sensor on and off at stream enable/disable time using the pm_runtime infrastructure.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support raspberrypi camera module
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['ov5647']
['c']
1
31
2
--- diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c + bool streaming; + struct i2c_client *client = v4l2_get_subdevdata(sd); - if (enable) + if (sensor->streaming == enable) { + mutex_unlock(&sensor->lock); + return 0; + } + + if (enable) { + ret = pm_runtime_get_sync(&client->dev); + if (ret < 0) + goto error_unlock; + - else + if (ret < 0) { + dev_err(&client->dev, "stream start failed: %d ", ret); + goto error_unlock; + } + } else { + if (ret < 0) { + dev_err(&client->dev, "stream stop failed: %d ", ret); + goto error_unlock; + } + pm_runtime_put(&client->dev); + } + + sensor->streaming = enable; + mutex_unlock(&sensor->lock); + + return 0; + +error_unlock: + pm_runtime_put(&client->dev);
TV tuners, webcams, video capturers
2f038c97fd7baaf9508cf32998a5f8f1ddc09a5e
jacopo mondi
drivers
media
i2c
media: ov5647: apply controls only when powered
use pm_runtime_get_if_in_use() in s_ctrl to apply controls only when the device is powered on.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support raspberrypi camera module
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['ov5647']
['c']
1
27
17
--- diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c - int power_count; + int ret = 0; + - * if the device is not powered up by the host driver do - * not apply any controls to h/w at this time. instead - * the controls will be restored at s_stream(1) time. + * if the device is not powered up do not apply any controls + * to h/w at this time. instead the controls will be restored + * at s_stream(1) time. - if (!sensor->power_count) + if (pm_runtime_get_if_in_use(&client->dev) == 0) - return ov5647_s_auto_white_balance(sd, ctrl->val); + ret = ov5647_s_auto_white_balance(sd, ctrl->val); + break; - return ov5647_s_autogain(sd, ctrl->val); + ret = ov5647_s_autogain(sd, ctrl->val); + break; - return ov5647_s_exposure_auto(sd, ctrl->val); + ret = ov5647_s_exposure_auto(sd, ctrl->val); + break; - return ov5647_s_analogue_gain(sd, ctrl->val); + ret = ov5647_s_analogue_gain(sd, ctrl->val); + break; - return ov5647_s_exposure(sd, ctrl->val); + ret = ov5647_s_exposure(sd, ctrl->val); + break; + case v4l2_cid_vblank: + ret = ov5647_write16(sd, ov5647_reg_vts_hi, + sensor->mode->format.height + ctrl->val); + break; + + /* read-only, but we adjust it based on mode. */ - /* read-only, but we adjust it based on mode. */ - return 0; - return 0; - case v4l2_cid_vblank: - return ov5647_write16(sd, ov5647_reg_vts_hi, - sensor->mode->format.height + ctrl->val); + break; + - return 0; + pm_runtime_put(&client->dev); + + return ret;
TV tuners, webcams, video capturers
4eec1919c9585d12526dced3de64c1d95c7fc451
jacopo mondi
drivers
media
i2c
media: ov5647: constify oe_enable/disable reglist
make the two register-value lists const.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support raspberrypi camera module
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['ov5647']
['c']
1
2
2
--- diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c -static struct regval_list sensor_oe_disable_regs[] = { +static const struct regval_list sensor_oe_disable_regs[] = { -static struct regval_list sensor_oe_enable_regs[] = { +static const struct regval_list sensor_oe_enable_regs[] = {
TV tuners, webcams, video capturers
d07440702da0ff084f2bb97b1396d75fd7acc53f
jacopo mondi
drivers
media
i2c
media: em28xx: add support for hauppauge usb quadhd
hauppauge usb quadhd contains two two-tuner em28xx devices behind a usb hub. each of the four dvb adapters contains a maxlinear 692 combo atsc demod/tuner.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add support for hauppauge usb quadhd
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['em28xx']
['h', 'kconfig', 'c']
4
74
0
--- diff --git a/drivers/media/usb/em28xx/kconfig b/drivers/media/usb/em28xx/kconfig --- a/drivers/media/usb/em28xx/kconfig +++ b/drivers/media/usb/em28xx/kconfig + select dvb_mxl692 if media_subdrv_autoselect diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c --- a/drivers/media/usb/em28xx/em28xx-cards.c +++ b/drivers/media/usb/em28xx/em28xx-cards.c +/* hauppauge usb quadhd */ +static struct em28xx_reg_seq hauppauge_usb_quadhd_atsc_reg_seq[] = { + {em2874_r80_gpio_p0_ctrl, 0xff, 0xff, 0}, + {0x0d, 0xff, 0xff, 200}, + {0x50, 0x04, 0xff, 300}, + {em2874_r80_gpio_p0_ctrl, 0xb0, 0xf0, 100}, /* demod 1 reset */ + {em2874_r80_gpio_p0_ctrl, 0xf0, 0xf0, 100}, + {em2874_r80_gpio_p0_ctrl, 0xd0, 0xf0, 100}, /* demod 2 reset */ + {em2874_r80_gpio_p0_ctrl, 0xf0, 0xf0, 100}, + {em2874_r5f_ts_enable, 0x44, 0xff, 50}, + {em2874_r5d_ts1_pkt_size, 0x05, 0xff, 50}, + {em2874_r5e_ts2_pkt_size, 0x05, 0xff, 50}, + {-1, -1, -1, -1}, +}; + +static struct em28xx_led hauppauge_usb_quadhd_leds[] = { + { + .role = em28xx_led_digital_capturing, + .gpio_reg = em2874_r80_gpio_p0_ctrl, + .gpio_mask = em_gpio_2, + .inverted = 1, + }, + { + .role = em28xx_led_digital_capturing_ts2, + .gpio_reg = em2874_r80_gpio_p0_ctrl, + .gpio_mask = em_gpio_0, + .inverted = 1, + }, + {-1, 0, 0, 0}, +}; + + /* 2040:826d hauppauge usb quadhd + * empia 28274, max linear 692 atsc combo demod/tuner + */ + [em2874_board_hauppauge_usb_quadhd] = { + .name = "hauppauge usb quadhd atsc", + .def_i2c_bus = 1, + .has_dual_ts = 1, + .has_dvb = 1, + .i2c_speed = em28xx_i2c_clk_wait_enable | em28xx_i2c_freq_100_khz, + .tuner_type = tuner_absent, + .tuner_gpio = hauppauge_usb_quadhd_atsc_reg_seq, + .leds = hauppauge_usb_quadhd_leds, + }, + { usb_device(0x2040, 0x846d), + .driver_info = em2874_board_hauppauge_usb_quadhd }, diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c b/drivers/media/usb/em28xx/em28xx-dvb.c --- a/drivers/media/usb/em28xx/em28xx-dvb.c +++ b/drivers/media/usb/em28xx/em28xx-dvb.c +#include "mxl692.h" +static int em2874_dvb_init_hauppauge_usb_quadhd(struct em28xx *dev) +{ + struct em28xx_dvb *dvb = dev->dvb; + struct mxl692_config mxl692_config = {}; + unsigned char addr; + + /* attach demod/tuner combo */ + mxl692_config.id = (dev->ts == primary_ts) ? 0 : 1; + mxl692_config.fe = &dvb->fe[0]; + addr = (dev->ts == primary_ts) ? 0x60 : 0x63; + + dvb->i2c_client_demod = dvb_module_probe("mxl692", null, + &dev->i2c_adap[dev->def_i2c_bus], + addr, &mxl692_config); + if (!dvb->i2c_client_demod) + return -enodev; + + return 0; +} + + case em2874_board_hauppauge_usb_quadhd: + result = em2874_dvb_init_hauppauge_usb_quadhd(dev); + if (result) + goto out_free; + break; diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h --- a/drivers/media/usb/em28xx/em28xx.h +++ b/drivers/media/usb/em28xx/em28xx.h +#define em2874_board_hauppauge_usb_quadhd 106
TV tuners, webcams, video capturers
2e74a01fb073900c8cc5df6b5e4bcbf575ac6c26
brad love
drivers
media
em28xx, usb
media: i2c: add driver for rdacm21 camera module
the rdacm21 is a gmsl camera supporting 1280x1080 resolution images developed by imi based on an omnivision ov10640 sensor, an omnivision ov490 isp and a maxim max9271 gmsl serializer.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add driver for rdacm21 camera module
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['i2c']
['kconfig', 'maintainers', 'c', 'makefile']
4
650
0
--- diff --git a/maintainers b/maintainers --- a/maintainers +++ b/maintainers +rdacm21 camera sensor +m: jacopo mondi <jacopo+renesas@jmondi.org> +m: kieran bingham <kieran.bingham+renesas@ideasonboard.com> +m: laurent pinchart <laurent.pinchart+renesas@ideasonboard.com> +m: niklas soderlund <niklas.soderlund+renesas@ragnatech.se> +l: linux-media@vger.kernel.org +s: maintained +f: documentation/devicetree/bindings/media/i2c/rdacm2x-gmsl.yaml +f: drivers/media/i2c/max9271.c +f: drivers/media/i2c/max9271.h +f: drivers/media/i2c/rdacm21.c + diff --git a/drivers/media/i2c/kconfig b/drivers/media/i2c/kconfig --- a/drivers/media/i2c/kconfig +++ b/drivers/media/i2c/kconfig +config video_rdacm21 + tristate "imi rdacm21 camera support" + depends on i2c + select v4l2_fwnode + select video_v4l2_subdev_api + select media_controller + help + this driver supports the imi rdacm21 gmsl camera, used in + adas systems. + + this camera should be used in conjunction with a gmsl + deserialiser such as the max9286. + diff --git a/drivers/media/i2c/makefile b/drivers/media/i2c/makefile --- a/drivers/media/i2c/makefile +++ b/drivers/media/i2c/makefile +rdacm21-camera_module-objs := rdacm21.o max9271.o +obj-$(config_video_rdacm21) += rdacm21-camera_module.o diff --git a/drivers/media/i2c/rdacm21.c b/drivers/media/i2c/rdacm21.c --- /dev/null +++ b/drivers/media/i2c/rdacm21.c +// spdx-license-identifier: gpl-2.0+ +/* + * imi rdacm21 gmsl camera driver + * + * copyright (c) 2017-2020 jacopo mondi + * copyright (c) 2017-2019 kieran bingham + * copyright (c) 2017-2019 laurent pinchart + * copyright (c) 2017-2019 niklas soderlund + * copyright (c) 2016 renesas electronics corporation + * copyright (c) 2015 cogent embedded, inc. + */ + +#include <linux/delay.h> +#include <linux/fwnode.h> +#include <linux/init.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/videodev2.h> + +#include <media/v4l2-async.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-subdev.h> +#include "max9271.h" + +#define max9271_reset_cycles 10 + +#define ov490_i2c_address 0x24 + +#define ov490_page_high_reg 0xfffd +#define ov490_page_low_reg 0xfffe + +/* + * the sccb slave handling is undocumented; the registers naming scheme is + * totally arbitrary. + */ +#define ov490_sccb_slave_write 0x00 +#define ov490_sccb_slave_read 0x01 +#define ov490_sccb_slave0_dir 0x80195000 +#define ov490_sccb_slave0_addr_high 0x80195001 +#define ov490_sccb_slave0_addr_low 0x80195002 + +#define ov490_dvp_ctrl3 0x80286009 + +#define ov490_ods_ctrl_frame_output_en 0x0c +#define ov490_ods_ctrl 0x8029d000 + +#define ov490_host_cmd 0x808000c0 +#define ov490_host_cmd_trigger 0xc1 + +#define ov490_id_val 0x0490 +#define ov490_id(_p, _v) ((((_p) & 0xff) << 8) | ((_v) & 0xff)) +#define ov490_pid 0x8080300a +#define ov490_ver 0x8080300b +#define ov490_pid_timeout 20 +#define ov490_output_en_timeout 300 + +#define ov490_gpio0 bit(0) +#define ov490_spwdn0 bit(0) +#define ov490_gpio_sel0 0x80800050 +#define ov490_gpio_sel1 0x80800051 +#define ov490_gpio_direction0 0x80800054 +#define ov490_gpio_direction1 0x80800055 +#define ov490_gpio_output_value0 0x80800058 +#define ov490_gpio_output_value1 0x80800059 + +#define ov490_isp_hsize_low 0x80820060 +#define ov490_isp_hsize_high 0x80820061 +#define ov490_isp_vsize_low 0x80820062 +#define ov490_isp_vsize_high 0x80820063 + +#define ov10640_id_high 0xa6 +#define ov10640_chip_id 0x300a +#define ov10640_pixel_rate 55000000 + +struct rdacm21_device { + struct device *dev; + struct max9271_device serializer; + struct i2c_client *isp; + struct v4l2_subdev sd; + struct media_pad pad; + struct v4l2_mbus_framefmt fmt; + struct v4l2_ctrl_handler ctrls; + u32 addrs[2]; + u16 last_page; +}; + +static inline struct rdacm21_device *sd_to_rdacm21(struct v4l2_subdev *sd) +{ + return container_of(sd, struct rdacm21_device, sd); +} + +static const struct ov490_reg { + u16 reg; + u8 val; +} ov490_regs_wizard[] = { + {0xfffd, 0x80}, + {0xfffe, 0x82}, + {0x0071, 0x11}, + {0x0075, 0x11}, + {0xfffe, 0x29}, + {0x6010, 0x01}, + /* + * ov490 emb line disable in yuv and raw data, + * note: emb line is still used in isp and sensor + */ + {0xe000, 0x14}, + {0xfffe, 0x28}, + {0x6000, 0x04}, + {0x6004, 0x00}, + /* + * pclk polarity - useless due to silicon bug. + * use 0x808000bb register instead. + */ + {0x6008, 0x00}, + {0xfffe, 0x80}, + {0x0091, 0x00}, + /* bit[3]=0 - pclk polarity workaround. */ + {0x00bb, 0x1d}, + /* ov490 fsin: app_fsin_from_fsync */ + {0xfffe, 0x85}, + {0x0008, 0x00}, + {0x0009, 0x01}, + /* fsin0 source. */ + {0x000a, 0x05}, + {0x000b, 0x00}, + /* fsin0 delay. */ + {0x0030, 0x02}, + {0x0031, 0x00}, + {0x0032, 0x00}, + {0x0033, 0x00}, + /* fsin1 delay. */ + {0x0038, 0x02}, + {0x0039, 0x00}, + {0x003a, 0x00}, + {0x003b, 0x00}, + /* fsin0 length. */ + {0x0070, 0x2c}, + {0x0071, 0x01}, + {0x0072, 0x00}, + {0x0073, 0x00}, + /* fsin1 length. */ + {0x0074, 0x64}, + {0x0075, 0x00}, + {0x0076, 0x00}, + {0x0077, 0x00}, + {0x0000, 0x14}, + {0x0001, 0x00}, + {0x0002, 0x00}, + {0x0003, 0x00}, + /* + * load fsin0,load fsin1,load other, + * it will be cleared automatically. + */ + {0x0004, 0x32}, + {0x0005, 0x00}, + {0x0006, 0x00}, + {0x0007, 0x00}, + {0xfffe, 0x80}, + /* sensor fsin. */ + {0x0081, 0x00}, + /* ov10640 fsin enable */ + {0xfffe, 0x19}, + {0x5000, 0x00}, + {0x5001, 0x30}, + {0x5002, 0x8c}, + {0x5003, 0xb2}, + {0xfffe, 0x80}, + {0x00c0, 0xc1}, + /* ov10640 hflip=1 by default */ + {0xfffe, 0x19}, + {0x5000, 0x01}, + {0x5001, 0x00}, + {0xfffe, 0x80}, + {0x00c0, 0xdc}, +}; + +static int ov490_read(struct rdacm21_device *dev, u16 reg, u8 *val) +{ + u8 buf[2] = { reg >> 8, reg }; + int ret; + + ret = i2c_master_send(dev->isp, buf, 2); + if (ret == 2) + ret = i2c_master_recv(dev->isp, val, 1); + + if (ret < 0) { + dev_dbg(dev->dev, "%s: register 0x%04x read failed (%d) ", + __func__, reg, ret); + return ret; + } + + return 0; +} + +static int ov490_write(struct rdacm21_device *dev, u16 reg, u8 val) +{ + u8 buf[3] = { reg >> 8, reg, val }; + int ret; + + ret = i2c_master_send(dev->isp, buf, 3); + if (ret < 0) { + dev_err(dev->dev, "%s: register 0x%04x write failed (%d) ", + __func__, reg, ret); + return ret; + } + + return 0; +} + +static int ov490_set_page(struct rdacm21_device *dev, u16 page) +{ + u8 page_high = page >> 8; + u8 page_low = page; + int ret; + + if (page == dev->last_page) + return 0; + + if (page_high != (dev->last_page >> 8)) { + ret = ov490_write(dev, ov490_page_high_reg, page_high); + if (ret) + return ret; + } + + if (page_low != (u8)dev->last_page) { + ret = ov490_write(dev, ov490_page_low_reg, page_low); + if (ret) + return ret; + } + + dev->last_page = page; + usleep_range(100, 150); + + return 0; +} + +static int ov490_read_reg(struct rdacm21_device *dev, u32 reg, u8 *val) +{ + int ret; + + ret = ov490_set_page(dev, reg >> 16); + if (ret) + return ret; + + ret = ov490_read(dev, (u16)reg, val); + if (ret) + return ret; + + dev_dbg(dev->dev, "%s: 0x%08x = 0x%02x ", __func__, reg, *val); + + return 0; +} + +static int ov490_write_reg(struct rdacm21_device *dev, u32 reg, u8 val) +{ + int ret; + + ret = ov490_set_page(dev, reg >> 16); + if (ret) + return ret; + + ret = ov490_write(dev, (u16)reg, val); + if (ret) + return ret; + + dev_dbg(dev->dev, "%s: 0x%08x = 0x%02x ", __func__, reg, val); + + return 0; +} + +static int rdacm21_s_stream(struct v4l2_subdev *sd, int enable) +{ + struct rdacm21_device *dev = sd_to_rdacm21(sd); + + /* + * enable serial link now that the isp provides a valid pixel clock + * to start serializing video data on the gmsl link. + */ + return max9271_set_serial_link(&dev->serializer, enable); +} + +static int rdacm21_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_mbus_code_enum *code) +{ + if (code->pad || code->index > 0) + return -einval; + + code->code = media_bus_fmt_yuyv8_1x16; + + return 0; +} + +static int rdacm21_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *format) +{ + struct v4l2_mbus_framefmt *mf = &format->format; + struct rdacm21_device *dev = sd_to_rdacm21(sd); + + if (format->pad) + return -einval; + + mf->width = dev->fmt.width; + mf->height = dev->fmt.height; + mf->code = media_bus_fmt_yuyv8_1x16; + mf->colorspace = v4l2_colorspace_srgb; + mf->field = v4l2_field_none; + mf->ycbcr_enc = v4l2_ycbcr_enc_601; + mf->quantization = v4l2_quantization_full_range; + mf->xfer_func = v4l2_xfer_func_none; + + return 0; +} + +static const struct v4l2_subdev_video_ops rdacm21_video_ops = { + .s_stream = rdacm21_s_stream, +}; + +static const struct v4l2_subdev_pad_ops rdacm21_subdev_pad_ops = { + .enum_mbus_code = rdacm21_enum_mbus_code, + .get_fmt = rdacm21_get_fmt, + .set_fmt = rdacm21_get_fmt, +}; + +static const struct v4l2_subdev_ops rdacm21_subdev_ops = { + .video = &rdacm21_video_ops, + .pad = &rdacm21_subdev_pad_ops, +}; + +static int ov10640_initialize(struct rdacm21_device *dev) +{ + u8 val; + + /* power-up ov10640 by setting resetb and pwdnb pins high. */ + ov490_write_reg(dev, ov490_gpio_sel0, ov490_gpio0); + ov490_write_reg(dev, ov490_gpio_sel1, ov490_spwdn0); + ov490_write_reg(dev, ov490_gpio_direction0, ov490_gpio0); + ov490_write_reg(dev, ov490_gpio_direction1, ov490_spwdn0); + ov490_write_reg(dev, ov490_gpio_output_value0, ov490_gpio0); + ov490_write_reg(dev, ov490_gpio_output_value0, ov490_spwdn0); + usleep_range(3000, 5000); + + /* read ov10640 id to test communications. */ + ov490_write_reg(dev, ov490_sccb_slave0_dir, ov490_sccb_slave_read); + ov490_write_reg(dev, ov490_sccb_slave0_addr_high, ov10640_chip_id >> 8); + ov490_write_reg(dev, ov490_sccb_slave0_addr_low, (u8)ov10640_chip_id); + + /* trigger sccb slave transaction and give it some time to complete. */ + ov490_write_reg(dev, ov490_host_cmd, ov490_host_cmd_trigger); + usleep_range(1000, 1500); + + ov490_read_reg(dev, ov490_sccb_slave0_dir, &val); + if (val != ov10640_id_high) { + dev_err(dev->dev, "ov10640 id mismatch: (0x%02x) ", val); + return -enodev; + } + + dev_dbg(dev->dev, "ov10640 id = 0x%2x ", val); + + return 0; +} + +static int ov490_initialize(struct rdacm21_device *dev) +{ + u8 pid, ver, val; + unsigned int i; + int ret; + + /* + * read ov490 id to test communications. give it up to 40msec to + * exit from reset. + */ + for (i = 0; i < ov490_pid_timeout; ++i) { + ret = ov490_read_reg(dev, ov490_pid, &pid); + if (ret == 0) + break; + usleep_range(1000, 2000); + } + if (i == ov490_pid_timeout) { + dev_err(dev->dev, "ov490 pid read failed (%d) ", ret); + return ret; + } + + ret = ov490_read_reg(dev, ov490_ver, &ver); + if (ret < 0) + return ret; + + if (ov490_id(pid, ver) != ov490_id_val) { + dev_err(dev->dev, "ov490 id mismatch (0x%04x) ", + ov490_id(pid, ver)); + return -enodev; + } + + /* wait for firmware boot by reading streamon status. */ + for (i = 0; i < ov490_output_en_timeout; ++i) { + ov490_read_reg(dev, ov490_ods_ctrl, &val); + if (val == ov490_ods_ctrl_frame_output_en) + break; + usleep_range(1000, 2000); + } + if (i == ov490_output_en_timeout) { + dev_err(dev->dev, "timeout waiting for firmware boot "); + return -enodev; + } + + ret = ov10640_initialize(dev); + if (ret) + return ret; + + /* program ov490 with register-value table. */ + for (i = 0; i < array_size(ov490_regs_wizard); ++i) { + ret = ov490_write(dev, ov490_regs_wizard[i].reg, + ov490_regs_wizard[i].val); + if (ret < 0) { + dev_err(dev->dev, + "%s: register %u (0x%04x) write failed (%d) ", + __func__, i, ov490_regs_wizard[i].reg, ret); + + return -eio; + } + + usleep_range(100, 150); + } + + /* + * the isp is programmed with the content of a serial flash memory. + * read the firmware configuration to reflect it through the v4l2 apis. + */ + ov490_read_reg(dev, ov490_isp_hsize_high, &val); + dev->fmt.width = (val & 0xf) << 8; + ov490_read_reg(dev, ov490_isp_hsize_low, &val); + dev->fmt.width |= (val & 0xff); + + ov490_read_reg(dev, ov490_isp_vsize_high, &val); + dev->fmt.height = (val & 0xf) << 8; + ov490_read_reg(dev, ov490_isp_vsize_low, &val); + dev->fmt.height |= val & 0xff; + + /* set bus width to 12 bits with [0:11] ordering. */ + ov490_write_reg(dev, ov490_dvp_ctrl3, 0x10); + + dev_info(dev->dev, "identified rdacm21 camera module "); + + return 0; +} + +static int rdacm21_initialize(struct rdacm21_device *dev) +{ + int ret; + + /* verify communication with the max9271: ping to wakeup. */ + dev->serializer.client->addr = max9271_default_addr; + i2c_smbus_read_byte(dev->serializer.client); + usleep_range(3000, 5000); + + /* enable reverse channel and disable the serial link. */ + ret = max9271_set_serial_link(&dev->serializer, false); + if (ret) + return ret; + + /* configure i2c bus at 105kbps speed and configure gmsl. */ + ret = max9271_configure_i2c(&dev->serializer, + max9271_i2cslvsh_469ns_234ns | + max9271_i2cslvto_1024us | + max9271_i2cmstbt_105kbps); + if (ret) + return ret; + + ret = max9271_verify_id(&dev->serializer); + if (ret) + return ret; + + /* enable gpio1 and hold ov490 in reset during max9271 configuration. */ + ret = max9271_enable_gpios(&dev->serializer, max9271_gpio1out); + if (ret) + return ret; + + ret = max9271_clear_gpios(&dev->serializer, max9271_gpio1out); + if (ret) + return ret; + + ret = max9271_configure_gmsl_link(&dev->serializer); + if (ret) + return ret; + + ret = max9271_set_address(&dev->serializer, dev->addrs[0]); + if (ret) + return ret; + dev->serializer.client->addr = dev->addrs[0]; + + ret = max9271_set_translation(&dev->serializer, dev->addrs[1], + ov490_i2c_address); + if (ret) + return ret; + dev->isp->addr = dev->addrs[1]; + + /* release ov490 from reset and initialize it. */ + ret = max9271_set_gpios(&dev->serializer, max9271_gpio1out); + if (ret) + return ret; + usleep_range(3000, 5000); + + ret = ov490_initialize(dev); + if (ret) + return ret; + + /* + * set reverse channel high threshold to increase noise immunity. + * + * this should be compensated by increasing the reverse channel + * amplitude on the remote deserializer side. + */ + return max9271_set_high_threshold(&dev->serializer, true); +} + +static int rdacm21_probe(struct i2c_client *client) +{ + struct rdacm21_device *dev; + struct fwnode_handle *ep; + int ret; + + dev = devm_kzalloc(&client->dev, sizeof(*dev), gfp_kernel); + if (!dev) + return -enomem; + dev->dev = &client->dev; + dev->serializer.client = client; + + ret = of_property_read_u32_array(client->dev.of_node, "reg", + dev->addrs, 2); + if (ret < 0) { + dev_err(dev->dev, "invalid dt reg property: %d ", ret); + return -einval; + } + + /* create the dummy i2c client for the sensor. */ + dev->isp = i2c_new_dummy_device(client->adapter, ov490_i2c_address); + if (is_err(dev->isp)) + return ptr_err(dev->isp); + + ret = rdacm21_initialize(dev); + if (ret < 0) + goto error; + + /* initialize and register the subdevice. */ + v4l2_i2c_subdev_init(&dev->sd, client, &rdacm21_subdev_ops); + dev->sd.flags |= v4l2_subdev_fl_has_devnode; + + v4l2_ctrl_handler_init(&dev->ctrls, 1); + v4l2_ctrl_new_std(&dev->ctrls, null, v4l2_cid_pixel_rate, + ov10640_pixel_rate, ov10640_pixel_rate, 1, + ov10640_pixel_rate); + dev->sd.ctrl_handler = &dev->ctrls; + + ret = dev->ctrls.error; + if (ret) + goto error_free_ctrls; + + dev->pad.flags = media_pad_fl_source; + dev->sd.entity.flags |= media_ent_f_cam_sensor; + ret = media_entity_pads_init(&dev->sd.entity, 1, &dev->pad); + if (ret < 0) + goto error_free_ctrls; + + ep = fwnode_graph_get_next_endpoint(dev_fwnode(&client->dev), null); + if (!ep) { + dev_err(&client->dev, + "unable to get endpoint in node %pof ", + client->dev.of_node); + ret = -enoent; + goto error_free_ctrls; + } + dev->sd.fwnode = ep; + + ret = v4l2_async_register_subdev(&dev->sd); + if (ret) + goto error_put_node; + + return 0; + +error_put_node: + fwnode_handle_put(dev->sd.fwnode); +error_free_ctrls: + v4l2_ctrl_handler_free(&dev->ctrls); +error: + i2c_unregister_device(dev->isp); + + return ret; +} + +static int rdacm21_remove(struct i2c_client *client) +{ + struct rdacm21_device *dev = sd_to_rdacm21(i2c_get_clientdata(client)); + + v4l2_async_unregister_subdev(&dev->sd); + v4l2_ctrl_handler_free(&dev->ctrls); + i2c_unregister_device(dev->isp); + fwnode_handle_put(dev->sd.fwnode); + + return 0; +} + +static const struct of_device_id rdacm21_of_ids[] = { + { .compatible = "imi,rdacm21" }, + { } +}; +module_device_table(of, rdacm21_of_ids); + +static struct i2c_driver rdacm21_i2c_driver = { + .driver = { + .name = "rdacm21", + .of_match_table = rdacm21_of_ids, + }, + .probe_new = rdacm21_probe, + .remove = rdacm21_remove, +}; + +module_i2c_driver(rdacm21_i2c_driver); + +module_description("gmsl camera driver for rdacm21"); +module_author("jacopo mondi"); +module_license("gpl v2");
TV tuners, webcams, video capturers
a59f853b3b4bce1471ad164357c3f51bdd0e6ba9
jacopo mondi
drivers
media
i2c
media: i2c: add imx334 camera sensor driver
add a v4l2 sub-device driver for the sony imx334 image sensor. this is a camera sensor using the i2c bus for control and the csi-2 bus for data.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add imx334 camera sensor driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['i2c']
['kconfig', 'maintainers', 'c', 'makefile']
4
1,147
0
- manual exposure and analog gain control support - vblank/hblank/pixel rate/link freq control support - supported resolution: - 3840x2160 @ 60fps - supported bayer order output: - srggb12 --- diff --git a/maintainers b/maintainers --- a/maintainers +++ b/maintainers +f: drivers/media/i2c/imx334.c diff --git a/drivers/media/i2c/kconfig b/drivers/media/i2c/kconfig --- a/drivers/media/i2c/kconfig +++ b/drivers/media/i2c/kconfig +config video_imx334 + tristate "sony imx334 sensor support" + depends on of_gpio + depends on i2c && video_v4l2 + select video_v4l2_subdev_api + select media_controller + select v4l2_fwnode + help + this is a video4linux2 sensor driver for the sony + imx334 camera. + + to compile this driver as a module, choose m here: the + module will be called imx334. + diff --git a/drivers/media/i2c/makefile b/drivers/media/i2c/makefile --- a/drivers/media/i2c/makefile +++ b/drivers/media/i2c/makefile +obj-$(config_video_imx334) += imx334.o diff --git a/drivers/media/i2c/imx334.c b/drivers/media/i2c/imx334.c --- /dev/null +++ b/drivers/media/i2c/imx334.c +// spdx-license-identifier: gpl-2.0-only +/* + * sony imx334 sensor driver + * + * copyright (c) 2021 intel corporation + */ +#include <asm/unaligned.h> + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/pm_runtime.h> + +#include <media/v4l2-ctrls.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-subdev.h> + +/* streaming mode */ +#define imx334_reg_mode_select 0x3000 +#define imx334_mode_standby 0x01 +#define imx334_mode_streaming 0x00 + +/* lines per frame */ +#define imx334_reg_lpfr 0x3030 + +/* chip id */ +#define imx334_reg_id 0x3044 +#define imx334_id 0x1e + +/* exposure control */ +#define imx334_reg_shutter 0x3058 +#define imx334_exposure_min 1 +#define imx334_exposure_offset 5 +#define imx334_exposure_step 1 +#define imx334_exposure_default 0x0648 + +/* analog gain control */ +#define imx334_reg_again 0x30e8 +#define imx334_again_min 0 +#define imx334_again_max 240 +#define imx334_again_step 1 +#define imx334_again_default 0 + +/* group hold register */ +#define imx334_reg_hold 0x3001 + +/* input clock rate */ +#define imx334_inclk_rate 24000000 + +/* csi2 hw configuration */ +#define imx334_link_freq 891000000 +#define imx334_num_data_lanes 4 + +#define imx334_reg_min 0x00 +#define imx334_reg_max 0xfffff + +/** + * struct imx334_reg - imx334 sensor register + * @address: register address + * @val: register value + */ +struct imx334_reg { + u16 address; + u8 val; +}; + +/** + * struct imx334_reg_list - imx334 sensor register list + * @num_of_regs: number of registers in the list + * @regs: pointer to register list + */ +struct imx334_reg_list { + u32 num_of_regs; + const struct imx334_reg *regs; +}; + +/** + * struct imx334_mode - imx334 sensor mode structure + * @width: frame width + * @height: frame height + * @code: format code + * @hblank: horizontal blanking in lines + * @vblank: vertical blanking in lines + * @vblank_min: minimal vertical blanking in lines + * @vblank_max: maximum vertical blanking in lines + * @pclk: sensor pixel clock + * @link_freq_idx: link frequency index + * @reg_list: register list for sensor mode + */ +struct imx334_mode { + u32 width; + u32 height; + u32 code; + u32 hblank; + u32 vblank; + u32 vblank_min; + u32 vblank_max; + u64 pclk; + u32 link_freq_idx; + struct imx334_reg_list reg_list; +}; + +/** + * struct imx334 - imx334 sensor device structure + * @dev: pointer to generic device + * @client: pointer to i2c client + * @sd: v4l2 sub-device + * @pad: media pad. only one pad supported + * @reset_gpio: sensor reset gpio + * @inclk: sensor input clock + * @ctrl_handler: v4l2 control handler + * @link_freq_ctrl: pointer to link frequency control + * @pclk_ctrl: pointer to pixel clock control + * @hblank_ctrl: pointer to horizontal blanking control + * @vblank_ctrl: pointer to vertical blanking control + * @exp_ctrl: pointer to exposure control + * @again_ctrl: pointer to analog gain control + * @vblank: vertical blanking in lines + * @cur_mode: pointer to current selected sensor mode + * @mutex: mutex for serializing sensor controls + * @streaming: flag indicating streaming state + */ +struct imx334 { + struct device *dev; + struct i2c_client *client; + struct v4l2_subdev sd; + struct media_pad pad; + struct gpio_desc *reset_gpio; + struct clk *inclk; + struct v4l2_ctrl_handler ctrl_handler; + struct v4l2_ctrl *link_freq_ctrl; + struct v4l2_ctrl *pclk_ctrl; + struct v4l2_ctrl *hblank_ctrl; + struct v4l2_ctrl *vblank_ctrl; + struct { + struct v4l2_ctrl *exp_ctrl; + struct v4l2_ctrl *again_ctrl; + }; + u32 vblank; + const struct imx334_mode *cur_mode; + struct mutex mutex; + bool streaming; +}; + +static const s64 link_freq[] = { + imx334_link_freq, +}; + +/* sensor mode registers */ +static const struct imx334_reg mode_3840x2160_regs[] = { + {0x3000, 0x01}, + {0x3002, 0x00}, + {0x3018, 0x04}, + {0x37b0, 0x36}, + {0x304c, 0x00}, + {0x300c, 0x3b}, + {0x300d, 0x2a}, + {0x3034, 0x26}, + {0x3035, 0x02}, + {0x314c, 0x29}, + {0x314d, 0x01}, + {0x315a, 0x02}, + {0x3168, 0xa0}, + {0x316a, 0x7e}, + {0x3288, 0x21}, + {0x328a, 0x02}, + {0x302c, 0x3c}, + {0x302e, 0x00}, + {0x302f, 0x0f}, + {0x3076, 0x70}, + {0x3077, 0x08}, + {0x3090, 0x70}, + {0x3091, 0x08}, + {0x30d8, 0x20}, + {0x30d9, 0x12}, + {0x3308, 0x70}, + {0x3309, 0x08}, + {0x3414, 0x05}, + {0x3416, 0x18}, + {0x35ac, 0x0e}, + {0x3648, 0x01}, + {0x364a, 0x04}, + {0x364c, 0x04}, + {0x3678, 0x01}, + {0x367c, 0x31}, + {0x367e, 0x31}, + {0x3708, 0x02}, + {0x3714, 0x01}, + {0x3715, 0x02}, + {0x3716, 0x02}, + {0x3717, 0x02}, + {0x371c, 0x3d}, + {0x371d, 0x3f}, + {0x372c, 0x00}, + {0x372d, 0x00}, + {0x372e, 0x46}, + {0x372f, 0x00}, + {0x3730, 0x89}, + {0x3731, 0x00}, + {0x3732, 0x08}, + {0x3733, 0x01}, + {0x3734, 0xfe}, + {0x3735, 0x05}, + {0x375d, 0x00}, + {0x375e, 0x00}, + {0x375f, 0x61}, + {0x3760, 0x06}, + {0x3768, 0x1b}, + {0x3769, 0x1b}, + {0x376a, 0x1a}, + {0x376b, 0x19}, + {0x376c, 0x18}, + {0x376d, 0x14}, + {0x376e, 0x0f}, + {0x3776, 0x00}, + {0x3777, 0x00}, + {0x3778, 0x46}, + {0x3779, 0x00}, + {0x377a, 0x08}, + {0x377b, 0x01}, + {0x377c, 0x45}, + {0x377d, 0x01}, + {0x377e, 0x23}, + {0x377f, 0x02}, + {0x3780, 0xd9}, + {0x3781, 0x03}, + {0x3782, 0xf5}, + {0x3783, 0x06}, + {0x3784, 0xa5}, + {0x3788, 0x0f}, + {0x378a, 0xd9}, + {0x378b, 0x03}, + {0x378c, 0xeb}, + {0x378d, 0x05}, + {0x378e, 0x87}, + {0x378f, 0x06}, + {0x3790, 0xf5}, + {0x3792, 0x43}, + {0x3794, 0x7a}, + {0x3796, 0xa1}, + {0x3e04, 0x0e}, + {0x3a00, 0x01}, +}; + +/* supported sensor mode configurations */ +static const struct imx334_mode supported_mode = { + .width = 3840, + .height = 2160, + .hblank = 560, + .vblank = 2340, + .vblank_min = 90, + .vblank_max = 132840, + .pclk = 594000000, + .link_freq_idx = 0, + .code = media_bus_fmt_srggb12_1x12, + .reg_list = { + .num_of_regs = array_size(mode_3840x2160_regs), + .regs = mode_3840x2160_regs, + }, +}; + +/** + * to_imx334() - imv334 v4l2 sub-device to imx334 device. + * @subdev: pointer to imx334 v4l2 sub-device + * + * return: pointer to imx334 device + */ +static inline struct imx334 *to_imx334(struct v4l2_subdev *subdev) +{ + return container_of(subdev, struct imx334, sd); +} + +/** + * imx334_read_reg() - read registers. + * @imx334: pointer to imx334 device + * @reg: register address + * @len: length of bytes to read. max supported bytes is 4 + * @val: pointer to register value to be filled. + * + * big endian register addresses with little endian values. + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_read_reg(struct imx334 *imx334, u16 reg, u32 len, u32 *val) +{ + struct i2c_client *client = v4l2_get_subdevdata(&imx334->sd); + struct i2c_msg msgs[2] = {0}; + u8 addr_buf[2] = {0}; + u8 data_buf[4] = {0}; + int ret; + + if (warn_on(len > 4)) + return -einval; + + put_unaligned_be16(reg, addr_buf); + + /* write register address */ + msgs[0].addr = client->addr; + msgs[0].flags = 0; + msgs[0].len = array_size(addr_buf); + msgs[0].buf = addr_buf; + + /* read data from register */ + msgs[1].addr = client->addr; + msgs[1].flags = i2c_m_rd; + msgs[1].len = len; + msgs[1].buf = data_buf; + + ret = i2c_transfer(client->adapter, msgs, array_size(msgs)); + if (ret != array_size(msgs)) + return -eio; + + *val = get_unaligned_le32(data_buf); + + return 0; +} + +/** + * imx334_write_reg() - write register + * @imx334: pointer to imx334 device + * @reg: register address + * @len: length of bytes. max supported bytes is 4 + * @val: register value + * + * big endian register addresses with little endian values. + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_write_reg(struct imx334 *imx334, u16 reg, u32 len, u32 val) +{ + struct i2c_client *client = v4l2_get_subdevdata(&imx334->sd); + u8 buf[6] = {0}; + + if (warn_on(len > 4)) + return -einval; + + put_unaligned_be16(reg, buf); + put_unaligned_le32(val, buf + 2); + if (i2c_master_send(client, buf, len + 2) != len + 2) + return -eio; + + return 0; +} + +/** + * imx334_write_regs() - write a list of registers + * @imx334: pointer to imx334 device + * @regs: list of registers to be written + * @len: length of registers array + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_write_regs(struct imx334 *imx334, + const struct imx334_reg *regs, u32 len) +{ + unsigned int i; + int ret; + + for (i = 0; i < len; i++) { + ret = imx334_write_reg(imx334, regs[i].address, 1, regs[i].val); + if (ret) + return ret; + } + + return 0; +} + +/** + * imx334_update_controls() - update control ranges based on streaming mode + * @imx334: pointer to imx334 device + * @mode: pointer to imx334_mode sensor mode + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_update_controls(struct imx334 *imx334, + const struct imx334_mode *mode) +{ + int ret; + + ret = __v4l2_ctrl_s_ctrl(imx334->link_freq_ctrl, mode->link_freq_idx); + if (ret) + return ret; + + ret = __v4l2_ctrl_s_ctrl(imx334->hblank_ctrl, mode->hblank); + if (ret) + return ret; + + return __v4l2_ctrl_modify_range(imx334->vblank_ctrl, mode->vblank_min, + mode->vblank_max, 1, mode->vblank); +} + +/** + * imx334_update_exp_gain() - set updated exposure and gain + * @imx334: pointer to imx334 device + * @exposure: updated exposure value + * @gain: updated analog gain value + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_update_exp_gain(struct imx334 *imx334, u32 exposure, u32 gain) +{ + u32 lpfr, shutter; + int ret; + + lpfr = imx334->vblank + imx334->cur_mode->height; + shutter = lpfr - exposure; + + dev_dbg(imx334->dev, "set long exp %u analog gain %u sh0 %u lpfr %u", + exposure, gain, shutter, lpfr); + + ret = imx334_write_reg(imx334, imx334_reg_hold, 1, 1); + if (ret) + return ret; + + ret = imx334_write_reg(imx334, imx334_reg_lpfr, 3, lpfr); + if (ret) + goto error_release_group_hold; + + ret = imx334_write_reg(imx334, imx334_reg_shutter, 3, shutter); + if (ret) + goto error_release_group_hold; + + ret = imx334_write_reg(imx334, imx334_reg_again, 1, gain); + +error_release_group_hold: + imx334_write_reg(imx334, imx334_reg_hold, 1, 0); + + return ret; +} + +/** + * imx334_set_ctrl() - set subdevice control + * @ctrl: pointer to v4l2_ctrl structure + * + * supported controls: + * - v4l2_cid_vblank + * - cluster controls: + * - v4l2_cid_analogue_gain + * - v4l2_cid_exposure + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct imx334 *imx334 = + container_of(ctrl->handler, struct imx334, ctrl_handler); + u32 analog_gain; + u32 exposure; + int ret; + + switch (ctrl->id) { + case v4l2_cid_vblank: + imx334->vblank = imx334->vblank_ctrl->val; + + dev_dbg(imx334->dev, "received vblank %u, new lpfr %u", + imx334->vblank, + imx334->vblank + imx334->cur_mode->height); + + ret = __v4l2_ctrl_modify_range(imx334->exp_ctrl, + imx334_exposure_min, + imx334->vblank + + imx334->cur_mode->height - + imx334_exposure_offset, + 1, imx334_exposure_default); + break; + case v4l2_cid_exposure: + + /* set controls only if sensor is in power on state */ + if (!pm_runtime_get_if_in_use(imx334->dev)) + return 0; + + exposure = ctrl->val; + analog_gain = imx334->again_ctrl->val; + + dev_dbg(imx334->dev, "received exp %u analog gain %u", + exposure, analog_gain); + + ret = imx334_update_exp_gain(imx334, exposure, analog_gain); + + pm_runtime_put(imx334->dev); + + break; + default: + dev_err(imx334->dev, "invalid control %d", ctrl->id); + ret = -einval; + } + + return ret; +} + +/* v4l2 subdevice control ops*/ +static const struct v4l2_ctrl_ops imx334_ctrl_ops = { + .s_ctrl = imx334_set_ctrl, +}; + +/** + * imx334_enum_mbus_code() - enumerate v4l2 sub-device mbus codes + * @sd: pointer to imx334 v4l2 sub-device structure + * @cfg: v4l2 sub-device pad configuration + * @code: v4l2 sub-device code enumeration need to be filled + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_mbus_code_enum *code) +{ + if (code->index > 0) + return -einval; + + code->code = supported_mode.code; + + return 0; +} + +/** + * imx334_enum_frame_size() - enumerate v4l2 sub-device frame sizes + * @sd: pointer to imx334 v4l2 sub-device structure + * @cfg: v4l2 sub-device pad configuration + * @fsize: v4l2 sub-device size enumeration need to be filled + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_enum_frame_size(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_frame_size_enum *fsize) +{ + if (fsize->index > 0) + return -einval; + + if (fsize->code != supported_mode.code) + return -einval; + + fsize->min_width = supported_mode.width; + fsize->max_width = fsize->min_width; + fsize->min_height = supported_mode.height; + fsize->max_height = fsize->min_height; + + return 0; +} + +/** + * imx334_fill_pad_format() - fill subdevice pad format + * from selected sensor mode + * @imx334: pointer to imx334 device + * @mode: pointer to imx334_mode sensor mode + * @fmt: v4l2 sub-device format need to be filled + */ +static void imx334_fill_pad_format(struct imx334 *imx334, + const struct imx334_mode *mode, + struct v4l2_subdev_format *fmt) +{ + fmt->format.width = mode->width; + fmt->format.height = mode->height; + fmt->format.code = mode->code; + fmt->format.field = v4l2_field_none; + fmt->format.colorspace = v4l2_colorspace_raw; + fmt->format.ycbcr_enc = v4l2_ycbcr_enc_default; + fmt->format.quantization = v4l2_quantization_default; + fmt->format.xfer_func = v4l2_xfer_func_none; +} + +/** + * imx334_get_pad_format() - get subdevice pad format + * @sd: pointer to imx334 v4l2 sub-device structure + * @cfg: v4l2 sub-device pad configuration + * @fmt: v4l2 sub-device format need to be set + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_get_pad_format(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) +{ + struct imx334 *imx334 = to_imx334(sd); + + mutex_lock(&imx334->mutex); + + if (fmt->which == v4l2_subdev_format_try) { + struct v4l2_mbus_framefmt *framefmt; + + framefmt = v4l2_subdev_get_try_format(sd, cfg, fmt->pad); + fmt->format = *framefmt; + } else { + imx334_fill_pad_format(imx334, imx334->cur_mode, fmt); + } + + mutex_unlock(&imx334->mutex); + + return 0; +} + +/** + * imx334_set_pad_format() - set subdevice pad format + * @sd: pointer to imx334 v4l2 sub-device structure + * @cfg: v4l2 sub-device pad configuration + * @fmt: v4l2 sub-device format need to be set + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_set_pad_format(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) +{ + struct imx334 *imx334 = to_imx334(sd); + const struct imx334_mode *mode; + int ret = 0; + + mutex_lock(&imx334->mutex); + + mode = &supported_mode; + imx334_fill_pad_format(imx334, mode, fmt); + + if (fmt->which == v4l2_subdev_format_try) { + struct v4l2_mbus_framefmt *framefmt; + + framefmt = v4l2_subdev_get_try_format(sd, cfg, fmt->pad); + *framefmt = fmt->format; + } else { + ret = imx334_update_controls(imx334, mode); + if (!ret) + imx334->cur_mode = mode; + } + + mutex_unlock(&imx334->mutex); + + return ret; +} + +/** + * imx334_init_pad_cfg() - initialize sub-device pad configuration + * @sd: pointer to imx334 v4l2 sub-device structure + * @cfg: v4l2 sub-device pad configuration + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_init_pad_cfg(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg) +{ + struct imx334 *imx334 = to_imx334(sd); + struct v4l2_subdev_format fmt = { 0 }; + + fmt.which = cfg ? v4l2_subdev_format_try : v4l2_subdev_format_active; + imx334_fill_pad_format(imx334, &supported_mode, &fmt); + + return imx334_set_pad_format(sd, cfg, &fmt); +} + +/** + * imx334_start_streaming() - start sensor stream + * @imx334: pointer to imx334 device + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_start_streaming(struct imx334 *imx334) +{ + const struct imx334_reg_list *reg_list; + int ret; + + /* write sensor mode registers */ + reg_list = &imx334->cur_mode->reg_list; + ret = imx334_write_regs(imx334, reg_list->regs, + reg_list->num_of_regs); + if (ret) { + dev_err(imx334->dev, "fail to write initial registers"); + return ret; + } + + /* setup handler will write actual exposure and gain */ + ret = __v4l2_ctrl_handler_setup(imx334->sd.ctrl_handler); + if (ret) { + dev_err(imx334->dev, "fail to setup handler"); + return ret; + } + + /* start streaming */ + ret = imx334_write_reg(imx334, imx334_reg_mode_select, + 1, imx334_mode_streaming); + if (ret) { + dev_err(imx334->dev, "fail to start streaming"); + return ret; + } + + return 0; +} + +/** + * imx334_stop_streaming() - stop sensor stream + * @imx334: pointer to imx334 device + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_stop_streaming(struct imx334 *imx334) +{ + return imx334_write_reg(imx334, imx334_reg_mode_select, + 1, imx334_mode_standby); +} + +/** + * imx334_set_stream() - enable sensor streaming + * @sd: pointer to imx334 subdevice + * @enable: set to enable sensor streaming + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_set_stream(struct v4l2_subdev *sd, int enable) +{ + struct imx334 *imx334 = to_imx334(sd); + int ret; + + mutex_lock(&imx334->mutex); + + if (imx334->streaming == enable) { + mutex_unlock(&imx334->mutex); + return 0; + } + + if (enable) { + ret = pm_runtime_get_sync(imx334->dev); + if (ret) + goto error_power_off; + + ret = imx334_start_streaming(imx334); + if (ret) + goto error_power_off; + } else { + imx334_stop_streaming(imx334); + pm_runtime_put(imx334->dev); + } + + imx334->streaming = enable; + + mutex_unlock(&imx334->mutex); + + return 0; + +error_power_off: + pm_runtime_put(imx334->dev); + mutex_unlock(&imx334->mutex); + + return ret; +} + +/** + * imx334_detect() - detect imx334 sensor + * @imx334: pointer to imx334 device + * + * return: 0 if successful, -eio if sensor id does not match + */ +static int imx334_detect(struct imx334 *imx334) +{ + int ret; + u32 val; + + ret = imx334_read_reg(imx334, imx334_reg_id, 2, &val); + if (ret) + return ret; + + if (val != imx334_id) { + dev_err(imx334->dev, "chip id mismatch: %x!=%x", + imx334_id, val); + return -enxio; + } + + return 0; +} + +/** + * imx334_parse_hw_config() - parse hw configuration and check if supported + * @imx334: pointer to imx334 device + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_parse_hw_config(struct imx334 *imx334) +{ + struct fwnode_handle *fwnode = dev_fwnode(imx334->dev); + struct v4l2_fwnode_endpoint bus_cfg = { + .bus_type = v4l2_mbus_csi2_dphy + }; + struct fwnode_handle *ep; + unsigned long rate; + int ret; + int i; + + if (!fwnode) + return -enxio; + + /* request optional reset pin */ + imx334->reset_gpio = devm_gpiod_get_optional(imx334->dev, "reset", + gpiod_out_low); + if (is_err(imx334->reset_gpio)) { + dev_err(imx334->dev, "failed to get reset gpio %d", ret); + return ptr_err(imx334->reset_gpio); + } + + /* get sensor input clock */ + imx334->inclk = devm_clk_get(imx334->dev, null); + if (is_err(imx334->inclk)) { + dev_err(imx334->dev, "could not get inclk"); + return ptr_err(imx334->inclk); + } + + rate = clk_get_rate(imx334->inclk); + if (rate != imx334_inclk_rate) { + dev_err(imx334->dev, "inclk frequency mismatch"); + return -einval; + } + + ep = fwnode_graph_get_next_endpoint(fwnode, null); + if (!ep) + return -enxio; + + ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg); + fwnode_handle_put(ep); + if (ret) + return ret; + + if (bus_cfg.bus.mipi_csi2.num_data_lanes != imx334_num_data_lanes) { + dev_err(imx334->dev, + "number of csi2 data lanes %d is not supported", + bus_cfg.bus.mipi_csi2.num_data_lanes); + ret = -einval; + goto done_endpoint_free; + } + + if (!bus_cfg.nr_of_link_frequencies) { + dev_err(imx334->dev, "no link frequencies defined"); + ret = -einval; + goto done_endpoint_free; + } + + for (i = 0; i < bus_cfg.nr_of_link_frequencies; i++) + if (bus_cfg.link_frequencies[i] == imx334_link_freq) + goto done_endpoint_free; + + ret = -einval; + +done_endpoint_free: + v4l2_fwnode_endpoint_free(&bus_cfg); + + return ret; +} + +/* v4l2 subdevice ops */ +static const struct v4l2_subdev_video_ops imx334_video_ops = { + .s_stream = imx334_set_stream, +}; + +static const struct v4l2_subdev_pad_ops imx334_pad_ops = { + .init_cfg = imx334_init_pad_cfg, + .enum_mbus_code = imx334_enum_mbus_code, + .enum_frame_size = imx334_enum_frame_size, + .get_fmt = imx334_get_pad_format, + .set_fmt = imx334_set_pad_format, +}; + +static const struct v4l2_subdev_ops imx334_subdev_ops = { + .video = &imx334_video_ops, + .pad = &imx334_pad_ops, +}; + +/** + * imx334_power_on() - sensor power on sequence + * @dev: pointer to i2c device + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_power_on(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct imx334 *imx334 = to_imx334(sd); + int ret; + + gpiod_set_value_cansleep(imx334->reset_gpio, 1); + + ret = clk_prepare_enable(imx334->inclk); + if (ret) { + dev_err(imx334->dev, "fail to enable inclk"); + goto error_reset; + } + + usleep_range(18000, 20000); + + return 0; + +error_reset: + gpiod_set_value_cansleep(imx334->reset_gpio, 0); + + return ret; +} + +/** + * imx334_power_off() - sensor power off sequence + * @dev: pointer to i2c device + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_power_off(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct imx334 *imx334 = to_imx334(sd); + + gpiod_set_value_cansleep(imx334->reset_gpio, 0); + + clk_disable_unprepare(imx334->inclk); + + return 0; +} + +/** + * imx334_init_controls() - initialize sensor subdevice controls + * @imx334: pointer to imx334 device + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_init_controls(struct imx334 *imx334) +{ + struct v4l2_ctrl_handler *ctrl_hdlr = &imx334->ctrl_handler; + const struct imx334_mode *mode = imx334->cur_mode; + u32 lpfr; + int ret; + + ret = v4l2_ctrl_handler_init(ctrl_hdlr, 6); + if (ret) + return ret; + + /* serialize controls with sensor device */ + ctrl_hdlr->lock = &imx334->mutex; + + /* initialize exposure and gain */ + lpfr = mode->vblank + mode->height; + imx334->exp_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, + &imx334_ctrl_ops, + v4l2_cid_exposure, + imx334_exposure_min, + lpfr - imx334_exposure_offset, + imx334_exposure_step, + imx334_exposure_default); + + imx334->again_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, + &imx334_ctrl_ops, + v4l2_cid_analogue_gain, + imx334_again_min, + imx334_again_max, + imx334_again_step, + imx334_again_default); + + v4l2_ctrl_cluster(2, &imx334->exp_ctrl); + + imx334->vblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, + &imx334_ctrl_ops, + v4l2_cid_vblank, + mode->vblank_min, + mode->vblank_max, + 1, mode->vblank); + + /* read only controls */ + imx334->pclk_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, + &imx334_ctrl_ops, + v4l2_cid_pixel_rate, + mode->pclk, mode->pclk, + 1, mode->pclk); + + imx334->link_freq_ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr, + &imx334_ctrl_ops, + v4l2_cid_link_freq, + array_size(link_freq) - + 1, + mode->link_freq_idx, + link_freq); + if (imx334->link_freq_ctrl) + imx334->link_freq_ctrl->flags |= v4l2_ctrl_flag_read_only; + + imx334->hblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, + &imx334_ctrl_ops, + v4l2_cid_hblank, + imx334_reg_min, + imx334_reg_max, + 1, mode->hblank); + if (imx334->hblank_ctrl) + imx334->hblank_ctrl->flags |= v4l2_ctrl_flag_read_only; + + if (ctrl_hdlr->error) { + dev_err(imx334->dev, "control init failed: %d", + ctrl_hdlr->error); + v4l2_ctrl_handler_free(ctrl_hdlr); + return ctrl_hdlr->error; + } + + imx334->sd.ctrl_handler = ctrl_hdlr; + + return 0; +} + +/** + * imx334_probe() - i2c client device binding + * @client: pointer to i2c client device + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_probe(struct i2c_client *client) +{ + struct imx334 *imx334; + int ret; + + imx334 = devm_kzalloc(&client->dev, sizeof(*imx334), gfp_kernel); + if (!imx334) + return -enomem; + + imx334->dev = &client->dev; + + /* initialize subdev */ + v4l2_i2c_subdev_init(&imx334->sd, client, &imx334_subdev_ops); + + ret = imx334_parse_hw_config(imx334); + if (ret) { + dev_err(imx334->dev, "hw configuration is not supported"); + return ret; + } + + mutex_init(&imx334->mutex); + + ret = imx334_power_on(imx334->dev); + if (ret) { + dev_err(imx334->dev, "failed to power-on the sensor"); + goto error_mutex_destroy; + } + + /* check module identity */ + ret = imx334_detect(imx334); + if (ret) { + dev_err(imx334->dev, "failed to find sensor: %d", ret); + goto error_power_off; + } + + /* set default mode to max resolution */ + imx334->cur_mode = &supported_mode; + imx334->vblank = imx334->cur_mode->vblank; + + ret = imx334_init_controls(imx334); + if (ret) { + dev_err(imx334->dev, "failed to init controls: %d", ret); + goto error_power_off; + } + + /* initialize subdev */ + imx334->sd.flags |= v4l2_subdev_fl_has_devnode; + imx334->sd.entity.function = media_ent_f_cam_sensor; + + /* initialize source pad */ + imx334->pad.flags = media_pad_fl_source; + ret = media_entity_pads_init(&imx334->sd.entity, 1, &imx334->pad); + if (ret) { + dev_err(imx334->dev, "failed to init entity pads: %d", ret); + goto error_handler_free; + } + + ret = v4l2_async_register_subdev_sensor_common(&imx334->sd); + if (ret < 0) { + dev_err(imx334->dev, + "failed to register async subdev: %d", ret); + goto error_media_entity; + } + + pm_runtime_set_active(imx334->dev); + pm_runtime_enable(imx334->dev); + pm_runtime_idle(imx334->dev); + + return 0; + +error_media_entity: + media_entity_cleanup(&imx334->sd.entity); +error_handler_free: + v4l2_ctrl_handler_free(imx334->sd.ctrl_handler); +error_power_off: + imx334_power_off(imx334->dev); +error_mutex_destroy: + mutex_destroy(&imx334->mutex); + + return ret; +} + +/** + * imx334_remove() - i2c client device unbinding + * @client: pointer to i2c client device + * + * return: 0 if successful, error code otherwise. + */ +static int imx334_remove(struct i2c_client *client) +{ + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct imx334 *imx334 = to_imx334(sd); + + v4l2_async_unregister_subdev(sd); + media_entity_cleanup(&sd->entity); + v4l2_ctrl_handler_free(sd->ctrl_handler); + + pm_runtime_disable(&client->dev); + pm_runtime_suspended(&client->dev); + + mutex_destroy(&imx334->mutex); + + return 0; +} + +static const struct dev_pm_ops imx334_pm_ops = { + set_runtime_pm_ops(imx334_power_off, imx334_power_on, null) +}; + +static const struct of_device_id imx334_of_match[] = { + { .compatible = "sony,imx334" }, + { } +}; + +module_device_table(of, imx334_of_match); + +static struct i2c_driver imx334_driver = { + .probe_new = imx334_probe, + .remove = imx334_remove, + .driver = { + .name = "imx334", + .pm = &imx334_pm_ops, + .of_match_table = imx334_of_match, + }, +}; + +module_i2c_driver(imx334_driver); + +module_description("sony imx334 sensor driver"); +module_license("gpl");
TV tuners, webcams, video capturers
9746b11715c3949241e2d88cb9057da4adab7e02
martina krasteva
drivers
media
i2c
media: i2c: add support for the ov5648 image sensor
the ov5648 is a 5 mpx cmos image sensor, connected via mipi csi-2 in a one or two lane configuration.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add support for the ov5648 image sensor
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['i2c']
['kconfig', 'c', 'makefile']
3
2,637
0
- auto and manual exposition/gain - auto and manual white balance - horizontal and vertical flip - test patterns - debanding, based on power source frequency; - exposition setting correlated to time units. --- diff --git a/drivers/media/i2c/kconfig b/drivers/media/i2c/kconfig --- a/drivers/media/i2c/kconfig +++ b/drivers/media/i2c/kconfig +config video_ov5648 + tristate "omnivision ov5648 sensor support" + depends on i2c && pm && video_v4l2 + select media_controller + select video_v4l2_subdev_api + select v4l2_fwnode + help + this is a video4linux2 sensor driver for the omnivision + ov5648 camera. + + to compile this driver as a module, choose m here: the + module will be called ov5648. + diff --git a/drivers/media/i2c/makefile b/drivers/media/i2c/makefile --- a/drivers/media/i2c/makefile +++ b/drivers/media/i2c/makefile +obj-$(config_video_ov5648) += ov5648.o diff --git a/drivers/media/i2c/ov5648.c b/drivers/media/i2c/ov5648.c --- /dev/null +++ b/drivers/media/i2c/ov5648.c +// spdx-license-identifier: gpl-2.0-or-later +/* + * copyright (c) 2020 bootlin + * author: paul kocialkowski <paul.kocialkowski@bootlin.com> + */ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/of_graph.h> +#include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> +#include <linux/videodev2.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-image-sizes.h> +#include <media/v4l2-mediabus.h> + +/* clock rate */ + +#define ov5648_xvclk_rate 24000000 + +/* register definitions */ + +/* system */ + +#define ov5648_sw_standby_reg 0x100 +#define ov5648_sw_standby_stream_on bit(0) + +#define ov5648_sw_reset_reg 0x103 +#define ov5648_sw_reset_reset bit(0) + +#define ov5648_pad_oen0_reg 0x3000 +#define ov5648_pad_oen1_reg 0x3001 +#define ov5648_pad_oen2_reg 0x3002 +#define ov5648_pad_out0_reg 0x3008 +#define ov5648_pad_out1_reg 0x3009 + +#define ov5648_chip_id_h_reg 0x300a +#define ov5648_chip_id_h_value 0x56 +#define ov5648_chip_id_l_reg 0x300b +#define ov5648_chip_id_l_value 0x48 + +#define ov5648_pad_out2_reg 0x300d +#define ov5648_pad_sel0_reg 0x300e +#define ov5648_pad_sel1_reg 0x300f +#define ov5648_pad_sel2_reg 0x3010 +#define ov5648_pad_pk_reg 0x3011 +#define ov5648_pad_pk_pd_dato_en bit(7) +#define ov5648_pad_pk_drive_strength_1x (0 << 5) +#define ov5648_pad_pk_drive_strength_2x (2 << 5) +#define ov5648_pad_pk_frex_n bit(1) + +#define ov5648_a_pwc_pk_o0_reg 0x3013 +#define ov5648_a_pwc_pk_o0_bp_regulator_n bit(3) +#define ov5648_a_pwc_pk_o1_reg 0x3014 + +#define ov5648_mipi_phy0_reg 0x3016 +#define ov5648_mipi_phy1_reg 0x3017 +#define ov5648_mipi_sc_ctrl0_reg 0x3018 +#define ov5648_mipi_sc_ctrl0_mipi_lanes(v) (((v) << 5) & genmask(7, 5)) +#define ov5648_mipi_sc_ctrl0_phy_hs_tx_pd bit(4) +#define ov5648_mipi_sc_ctrl0_phy_lp_rx_pd bit(3) +#define ov5648_mipi_sc_ctrl0_mipi_en bit(2) +#define ov5648_mipi_sc_ctrl0_mipi_susp bit(1) +#define ov5648_mipi_sc_ctrl0_lane_dis_op bit(0) +#define ov5648_mipi_sc_ctrl1_reg 0x3019 +#define ov5648_misc_ctrl0_reg 0x3021 +#define ov5648_mipi_sc_ctrl2_reg 0x3022 +#define ov5648_sub_id_reg 0x302a + +#define ov5648_pll_ctrl0_reg 0x3034 +#define ov5648_pll_ctrl0_pll_charge_pump(v) (((v) << 4) & genmask(6, 4)) +#define ov5648_pll_ctrl0_bits(v) ((v) & genmask(3, 0)) +#define ov5648_pll_ctrl1_reg 0x3035 +#define ov5648_pll_ctrl1_sys_div(v) (((v) << 4) & genmask(7, 4)) +#define ov5648_pll_ctrl1_mipi_div(v) ((v) & genmask(3, 0)) +#define ov5648_pll_mul_reg 0x3036 +#define ov5648_pll_mul(v) ((v) & genmask(7, 0)) +#define ov5648_pll_div_reg 0x3037 +#define ov5648_pll_div_root_div(v) ((((v) - 1) << 4) & bit(4)) +#define ov5648_pll_div_pll_pre_div(v) ((v) & genmask(3, 0)) +#define ov5648_pll_debug_reg 0x3038 +#define ov5648_pll_bypass_reg 0x3039 + +#define ov5648_plls_bypass_reg 0x303a +#define ov5648_plls_mul_reg 0x303b +#define ov5648_plls_mul(v) ((v) & genmask(4, 0)) +#define ov5648_plls_ctrl_reg 0x303c +#define ov5648_plls_ctrl_pll_charge_pump(v) (((v) << 4) & genmask(6, 4)) +#define ov5648_plls_ctrl_sys_div(v) ((v) & genmask(3, 0)) +#define ov5648_plls_div_reg 0x303d +#define ov5648_plls_div_plls_pre_div(v) (((v) << 4) & genmask(5, 4)) +#define ov5648_plls_div_plls_div_r(v) ((((v) - 1) << 2) & bit(2)) +#define ov5648_plls_div_plls_sel_div(v) ((v) & genmask(1, 0)) + +#define ov5648_srb_ctrl_reg 0x3106 +#define ov5648_srb_ctrl_sclk_div(v) (((v) << 2) & genmask(3, 2)) +#define ov5648_srb_ctrl_reset_arbiter_en bit(1) +#define ov5648_srb_ctrl_sclk_arbiter_en bit(0) + +/* group hold */ + +#define ov5648_group_adr0_reg 0x3200 +#define ov5648_group_adr1_reg 0x3201 +#define ov5648_group_adr2_reg 0x3202 +#define ov5648_group_adr3_reg 0x3203 +#define ov5648_group_len0_reg 0x3204 +#define ov5648_group_len1_reg 0x3205 +#define ov5648_group_len2_reg 0x3206 +#define ov5648_group_len3_reg 0x3207 +#define ov5648_group_access_reg 0x3208 + +/* exposure/gain/banding */ + +#define ov5648_exposure_ctrl_hh_reg 0x3500 +#define ov5648_exposure_ctrl_hh(v) (((v) & genmask(19, 16)) >> 16) +#define ov5648_exposure_ctrl_hh_value(v) (((v) << 16) & genmask(19, 16)) +#define ov5648_exposure_ctrl_h_reg 0x3501 +#define ov5648_exposure_ctrl_h(v) (((v) & genmask(15, 8)) >> 8) +#define ov5648_exposure_ctrl_h_value(v) (((v) << 8) & genmask(15, 8)) +#define ov5648_exposure_ctrl_l_reg 0x3502 +#define ov5648_exposure_ctrl_l(v) ((v) & genmask(7, 0)) +#define ov5648_exposure_ctrl_l_value(v) ((v) & genmask(7, 0)) +#define ov5648_manual_ctrl_reg 0x3503 +#define ov5648_manual_ctrl_frame_delay(v) (((v) << 4) & genmask(5, 4)) +#define ov5648_manual_ctrl_agc_manual_en bit(1) +#define ov5648_manual_ctrl_aec_manual_en bit(0) +#define ov5648_gain_ctrl_h_reg 0x350a +#define ov5648_gain_ctrl_h(v) (((v) & genmask(9, 8)) >> 8) +#define ov5648_gain_ctrl_h_value(v) (((v) << 8) & genmask(9, 8)) +#define ov5648_gain_ctrl_l_reg 0x350b +#define ov5648_gain_ctrl_l(v) ((v) & genmask(7, 0)) +#define ov5648_gain_ctrl_l_value(v) ((v) & genmask(7, 0)) + +#define ov5648_analog_ctrl0_reg_base 0x3600 +#define ov5648_analog_ctrl1_reg_base 0x3700 + +#define ov5648_aec_ctrl0_reg 0x3a00 +#define ov5648_aec_ctrl0_debug bit(6) +#define ov5648_aec_ctrl0_deband_en bit(5) +#define ov5648_aec_ctrl0_deband_low_limit_en bit(4) +#define ov5648_aec_ctrl0_start_sel_en bit(3) +#define ov5648_aec_ctrl0_night_mode_en bit(2) +#define ov5648_aec_ctrl0_freeze_en bit(0) +#define ov5648_exposure_min_reg 0x3a01 +#define ov5648_exposure_max_60_h_reg 0x3a02 +#define ov5648_exposure_max_60_l_reg 0x3a03 +#define ov5648_aec_ctrl5_reg 0x3a05 +#define ov5648_aec_ctrl6_reg 0x3a06 +#define ov5648_aec_ctrl7_reg 0x3a07 +#define ov5648_banding_step_50_h_reg 0x3a08 +#define ov5648_banding_step_50_l_reg 0x3a09 +#define ov5648_banding_step_60_h_reg 0x3a0a +#define ov5648_banding_step_60_l_reg 0x3a0b +#define ov5648_aec_ctrlc_reg 0x3a0c +#define ov5648_banding_max_60_reg 0x3a0d +#define ov5648_banding_max_50_reg 0x3a0e +#define ov5648_wpt_reg 0x3a0f +#define ov5648_bpt_reg 0x3a10 +#define ov5648_vpt_high_reg 0x3a11 +#define ov5648_avg_manual_reg 0x3a12 +#define ov5648_pre_gain_reg 0x3a13 +#define ov5648_exposure_max_50_h_reg 0x3a14 +#define ov5648_exposure_max_50_l_reg 0x3a15 +#define ov5648_gain_base_night_reg 0x3a17 +#define ov5648_aec_gain_ceiling_h_reg 0x3a18 +#define ov5648_aec_gain_ceiling_l_reg 0x3a19 +#define ov5648_diff_max_reg 0x3a1a +#define ov5648_wpt2_reg 0x3a1b +#define ov5648_led_add_row_h_reg 0x3a1c +#define ov5648_led_add_row_l_reg 0x3a1d +#define ov5648_bpt2_reg 0x3a1e +#define ov5648_vpt_low_reg 0x3a1f +#define ov5648_aec_ctrl20_reg 0x3a20 +#define ov5648_aec_ctrl21_reg 0x3a21 + +#define ov5648_avg_start_x_h_reg 0x5680 +#define ov5648_avg_start_x_l_reg 0x5681 +#define ov5648_avg_start_y_h_reg 0x5682 +#define ov5648_avg_start_y_l_reg 0x5683 +#define ov5648_avg_window_x_h_reg 0x5684 +#define ov5648_avg_window_x_l_reg 0x5685 +#define ov5648_avg_window_y_h_reg 0x5686 +#define ov5648_avg_window_y_l_reg 0x5687 +#define ov5648_avg_weight00_reg 0x5688 +#define ov5648_avg_weight01_reg 0x5689 +#define ov5648_avg_weight02_reg 0x568a +#define ov5648_avg_weight03_reg 0x568b +#define ov5648_avg_weight04_reg 0x568c +#define ov5648_avg_weight05_reg 0x568d +#define ov5648_avg_weight06_reg 0x568e +#define ov5648_avg_weight07_reg 0x568f +#define ov5648_avg_ctrl10_reg 0x5690 +#define ov5648_avg_weight_sum_reg 0x5691 +#define ov5648_avg_readout_reg 0x5693 + +#define ov5648_dig_ctrl0_reg 0x5a00 +#define ov5648_dig_comp_man_h_reg 0x5a02 +#define ov5648_dig_comp_man_l_reg 0x5a03 + +#define ov5648_gainc_man_h_reg 0x5a20 +#define ov5648_gainc_man_l_reg 0x5a21 +#define ov5648_gainc_dgc_man_h_reg 0x5a22 +#define ov5648_gainc_dgc_man_l_reg 0x5a23 +#define ov5648_gainc_ctrl0_reg 0x5a24 + +#define ov5648_gainf_ana_num_reg 0x5a40 +#define ov5648_gainf_dig_gain_reg 0x5a41 + +/* timing */ + +#define ov5648_crop_start_x_h_reg 0x3800 +#define ov5648_crop_start_x_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov5648_crop_start_x_l_reg 0x3801 +#define ov5648_crop_start_x_l(v) ((v) & genmask(7, 0)) +#define ov5648_crop_start_y_h_reg 0x3802 +#define ov5648_crop_start_y_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov5648_crop_start_y_l_reg 0x3803 +#define ov5648_crop_start_y_l(v) ((v) & genmask(7, 0)) +#define ov5648_crop_end_x_h_reg 0x3804 +#define ov5648_crop_end_x_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov5648_crop_end_x_l_reg 0x3805 +#define ov5648_crop_end_x_l(v) ((v) & genmask(7, 0)) +#define ov5648_crop_end_y_h_reg 0x3806 +#define ov5648_crop_end_y_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov5648_crop_end_y_l_reg 0x3807 +#define ov5648_crop_end_y_l(v) ((v) & genmask(7, 0)) +#define ov5648_output_size_x_h_reg 0x3808 +#define ov5648_output_size_x_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov5648_output_size_x_l_reg 0x3809 +#define ov5648_output_size_x_l(v) ((v) & genmask(7, 0)) +#define ov5648_output_size_y_h_reg 0x380a +#define ov5648_output_size_y_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov5648_output_size_y_l_reg 0x380b +#define ov5648_output_size_y_l(v) ((v) & genmask(7, 0)) +#define ov5648_hts_h_reg 0x380c +#define ov5648_hts_h(v) (((v) & genmask(12, 8)) >> 8) +#define ov5648_hts_l_reg 0x380d +#define ov5648_hts_l(v) ((v) & genmask(7, 0)) +#define ov5648_vts_h_reg 0x380e +#define ov5648_vts_h(v) (((v) & genmask(15, 8)) >> 8) +#define ov5648_vts_l_reg 0x380f +#define ov5648_vts_l(v) ((v) & genmask(7, 0)) +#define ov5648_offset_x_h_reg 0x3810 +#define ov5648_offset_x_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov5648_offset_x_l_reg 0x3811 +#define ov5648_offset_x_l(v) ((v) & genmask(7, 0)) +#define ov5648_offset_y_h_reg 0x3812 +#define ov5648_offset_y_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov5648_offset_y_l_reg 0x3813 +#define ov5648_offset_y_l(v) ((v) & genmask(7, 0)) +#define ov5648_sub_inc_x_reg 0x3814 +#define ov5648_sub_inc_x_odd(v) (((v) << 4) & genmask(7, 4)) +#define ov5648_sub_inc_x_even(v) ((v) & genmask(3, 0)) +#define ov5648_sub_inc_y_reg 0x3815 +#define ov5648_sub_inc_y_odd(v) (((v) << 4) & genmask(7, 4)) +#define ov5648_sub_inc_y_even(v) ((v) & genmask(3, 0)) +#define ov5648_hsyncst_h_reg 0x3816 +#define ov5648_hsyncst_h(v) (((v) >> 8) & 0xf) +#define ov5648_hsyncst_l_reg 0x3817 +#define ov5648_hsyncst_l(v) ((v) & genmask(7, 0)) +#define ov5648_hsyncw_h_reg 0x3818 +#define ov5648_hsyncw_h(v) (((v) >> 8) & 0xf) +#define ov5648_hsyncw_l_reg 0x3819 +#define ov5648_hsyncw_l(v) ((v) & genmask(7, 0)) + +#define ov5648_tc20_reg 0x3820 +#define ov5648_tc20_debug bit(6) +#define ov5648_tc20_flip_vert_isp_en bit(2) +#define ov5648_tc20_flip_vert_sensor_en bit(1) +#define ov5648_tc20_binning_vert_en bit(0) +#define ov5648_tc21_reg 0x3821 +#define ov5648_tc21_flip_horz_isp_en bit(2) +#define ov5648_tc21_flip_horz_sensor_en bit(1) +#define ov5648_tc21_binning_horz_en bit(0) + +/* strobe/exposure */ + +#define ov5648_strobe_reg 0x3b00 +#define ov5648_frex_exp_hh_reg 0x3b01 +#define ov5648_shutter_dly_h_reg 0x3b02 +#define ov5648_shutter_dly_l_reg 0x3b03 +#define ov5648_frex_exp_h_reg 0x3b04 +#define ov5648_frex_exp_l_reg 0x3b05 +#define ov5648_frex_ctrl_reg 0x3b06 +#define ov5648_frex_mode_sel_reg 0x3b07 +#define ov5648_frex_mode_sel_frex_sa1 bit(4) +#define ov5648_frex_mode_sel_fx1_fm_en bit(3) +#define ov5648_frex_mode_sel_frex_inv bit(2) +#define ov5648_frex_mode_sel_mode1 0x0 +#define ov5648_frex_mode_sel_mode2 0x1 +#define ov5648_frex_mode_sel_rolling 0x2 +#define ov5648_frex_exp_req_reg 0x3b08 +#define ov5648_frex_shutter_dly_reg 0x3b09 +#define ov5648_frex_rst_len_reg 0x3b0a +#define ov5648_strobe_width_hh_reg 0x3b0b +#define ov5648_strobe_width_h_reg 0x3b0c + +/* otp */ + +#define ov5648_otp_data_reg_base 0x3d00 +#define ov5648_otp_program_ctrl_reg 0x3d80 +#define ov5648_otp_load_ctrl_reg 0x3d81 + +/* psram */ + +#define ov5648_psram_ctrl1_reg 0x3f01 +#define ov5648_psram_ctrlf_reg 0x3f0f + +/* black level */ + +#define ov5648_blc_ctrl0_reg 0x4000 +#define ov5648_blc_ctrl1_reg 0x4001 +#define ov5648_blc_ctrl1_start_line(v) ((v) & genmask(5, 0)) +#define ov5648_blc_ctrl2_reg 0x4002 +#define ov5648_blc_ctrl2_auto_en bit(6) +#define ov5648_blc_ctrl2_reset_frame_num(v) ((v) & genmask(5, 0)) +#define ov5648_blc_ctrl3_reg 0x4003 +#define ov5648_blc_line_num_reg 0x4004 +#define ov5648_blc_line_num(v) ((v) & genmask(7, 0)) +#define ov5648_blc_ctrl5_reg 0x4005 +#define ov5648_blc_ctrl5_update_en bit(1) +#define ov5648_blc_level_reg 0x4009 + +/* frame */ + +#define ov5648_frame_ctrl_reg 0x4200 +#define ov5648_frame_on_num_reg 0x4201 +#define ov5648_frame_off_num_reg 0x4202 + +/* mipi csi-2 */ + +#define ov5648_mipi_ctrl0_reg 0x4800 +#define ov5648_mipi_ctrl0_clk_lane_autogate bit(5) +#define ov5648_mipi_ctrl0_lane_sync_en bit(4) +#define ov5648_mipi_ctrl0_lane_select_lane1 0 +#define ov5648_mipi_ctrl0_lane_select_lane2 bit(3) +#define ov5648_mipi_ctrl0_idle_lp00 0 +#define ov5648_mipi_ctrl0_idle_lp11 bit(2) + +#define ov5648_mipi_ctrl1_reg 0x4801 +#define ov5648_mipi_ctrl2_reg 0x4802 +#define ov5648_mipi_ctrl3_reg 0x4803 +#define ov5648_mipi_ctrl4_reg 0x4804 +#define ov5648_mipi_ctrl5_reg 0x4805 +#define ov5648_mipi_max_frame_count_h_reg 0x4810 +#define ov5648_mipi_max_frame_count_l_reg 0x4811 +#define ov5648_mipi_ctrl14_reg 0x4814 +#define ov5648_mipi_dt_spkt_reg 0x4815 +#define ov5648_mipi_hs_zero_min_h_reg 0x4818 +#define ov5648_mipi_hs_zero_min_l_reg 0x4819 +#define ov5648_mipi_hs_train_min_h_reg 0x481a +#define ov5648_mipi_hs_train_min_l_reg 0x481b +#define ov5648_mipi_clk_zero_min_h_reg 0x481c +#define ov5648_mipi_clk_zero_min_l_reg 0x481d +#define ov5648_mipi_clk_prepare_min_h_reg 0x481e +#define ov5648_mipi_clk_prepare_min_l_reg 0x481f +#define ov5648_mipi_clk_post_min_h_reg 0x4820 +#define ov5648_mipi_clk_post_min_l_reg 0x4821 +#define ov5648_mipi_clk_trail_min_h_reg 0x4822 +#define ov5648_mipi_clk_trail_min_l_reg 0x4823 +#define ov5648_mipi_lpx_p_min_h_reg 0x4824 +#define ov5648_mipi_lpx_p_min_l_reg 0x4825 +#define ov5648_mipi_hs_prepare_min_h_reg 0x4826 +#define ov5648_mipi_hs_prepare_min_l_reg 0x4827 +#define ov5648_mipi_hs_exit_min_h_reg 0x4828 +#define ov5648_mipi_hs_exit_min_l_reg 0x4829 +#define ov5648_mipi_hs_zero_min_ui_reg 0x482a +#define ov5648_mipi_hs_trail_min_ui_reg 0x482b +#define ov5648_mipi_clk_zero_min_ui_reg 0x482c +#define ov5648_mipi_clk_prepare_min_ui_reg 0x482d +#define ov5648_mipi_clk_post_min_ui_reg 0x482e +#define ov5648_mipi_clk_trail_min_ui_reg 0x482f +#define ov5648_mipi_lpx_p_min_ui_reg 0x4830 +#define ov5648_mipi_hs_prepare_min_ui_reg 0x4831 +#define ov5648_mipi_hs_exit_min_ui_reg 0x4832 +#define ov5648_mipi_reg_min_h_reg 0x4833 +#define ov5648_mipi_reg_min_l_reg 0x4834 +#define ov5648_mipi_reg_max_h_reg 0x4835 +#define ov5648_mipi_reg_max_l_reg 0x4836 +#define ov5648_mipi_pclk_period_reg 0x4837 +#define ov5648_mipi_wkup_dly_reg 0x4838 +#define ov5648_mipi_lp_gpio_reg 0x483b +#define ov5648_mipi_snr_pclk_div_reg 0x4843 + +/* isp */ + +#define ov5648_isp_ctrl0_reg 0x5000 +#define ov5648_isp_ctrl0_black_correct_en bit(2) +#define ov5648_isp_ctrl0_white_correct_en bit(1) +#define ov5648_isp_ctrl1_reg 0x5001 +#define ov5648_isp_ctrl1_awb_en bit(0) +#define ov5648_isp_ctrl2_reg 0x5002 +#define ov5648_isp_ctrl2_win_en bit(6) +#define ov5648_isp_ctrl2_otp_en bit(1) +#define ov5648_isp_ctrl2_awb_gain_en bit(0) +#define ov5648_isp_ctrl3_reg 0x5003 +#define ov5648_isp_ctrl3_buf_en bit(3) +#define ov5648_isp_ctrl3_bin_man_set bit(2) +#define ov5648_isp_ctrl3_bin_auto_en bit(1) +#define ov5648_isp_ctrl4_reg 0x5004 +#define ov5648_isp_ctrl5_reg 0x5005 +#define ov5648_isp_ctrl6_reg 0x5006 +#define ov5648_isp_ctrl7_reg 0x5007 +#define ov5648_isp_man_offset_x_h_reg 0x5008 +#define ov5648_isp_man_offset_x_l_reg 0x5009 +#define ov5648_isp_man_offset_y_h_reg 0x500a +#define ov5648_isp_man_offset_y_l_reg 0x500b +#define ov5648_isp_man_win_offset_x_h_reg 0x500c +#define ov5648_isp_man_win_offset_x_l_reg 0x500d +#define ov5648_isp_man_win_offset_y_h_reg 0x500e +#define ov5648_isp_man_win_offset_y_l_reg 0x500f +#define ov5648_isp_man_win_output_x_h_reg 0x5010 +#define ov5648_isp_man_win_output_x_l_reg 0x5011 +#define ov5648_isp_man_win_output_y_h_reg 0x5012 +#define ov5648_isp_man_win_output_y_l_reg 0x5013 +#define ov5648_isp_man_input_x_h_reg 0x5014 +#define ov5648_isp_man_input_x_l_reg 0x5015 +#define ov5648_isp_man_input_y_h_reg 0x5016 +#define ov5648_isp_man_input_y_l_reg 0x5017 +#define ov5648_isp_ctrl18_reg 0x5018 +#define ov5648_isp_ctrl19_reg 0x5019 +#define ov5648_isp_ctrl1a_reg 0x501a +#define ov5648_isp_ctrl1d_reg 0x501d +#define ov5648_isp_ctrl1f_reg 0x501f +#define ov5648_isp_ctrl1f_output_en 3 +#define ov5648_isp_ctrl25_reg 0x5025 + +#define ov5648_isp_ctrl3d_reg 0x503d +#define ov5648_isp_ctrl3d_pattern_en bit(7) +#define ov5648_isp_ctrl3d_rolling_bar_en bit(6) +#define ov5648_isp_ctrl3d_transparent_mode bit(5) +#define ov5648_isp_ctrl3d_squares_bw_mode bit(4) +#define ov5648_isp_ctrl3d_pattern_color_bars 0 +#define ov5648_isp_ctrl3d_pattern_random_data 1 +#define ov5648_isp_ctrl3d_pattern_color_squares 2 +#define ov5648_isp_ctrl3d_pattern_input 3 + +#define ov5648_isp_ctrl3e_reg 0x503e +#define ov5648_isp_ctrl4b_reg 0x504b +#define ov5648_isp_ctrl4b_post_bin_h_en bit(5) +#define ov5648_isp_ctrl4b_post_bin_v_en bit(4) +#define ov5648_isp_ctrl4c_reg 0x504c +#define ov5648_isp_ctrl57_reg 0x5057 +#define ov5648_isp_ctrl58_reg 0x5058 +#define ov5648_isp_ctrl59_reg 0x5059 + +#define ov5648_isp_window_start_x_h_reg 0x5980 +#define ov5648_isp_window_start_x_l_reg 0x5981 +#define ov5648_isp_window_start_y_h_reg 0x5982 +#define ov5648_isp_window_start_y_l_reg 0x5983 +#define ov5648_isp_window_win_x_h_reg 0x5984 +#define ov5648_isp_window_win_x_l_reg 0x5985 +#define ov5648_isp_window_win_y_h_reg 0x5986 +#define ov5648_isp_window_win_y_l_reg 0x5987 +#define ov5648_isp_window_man_reg 0x5988 + +/* white balance */ + +#define ov5648_awb_ctrl_reg 0x5180 +#define ov5648_awb_ctrl_fast_awb bit(6) +#define ov5648_awb_ctrl_gain_freeze_en bit(5) +#define ov5648_awb_ctrl_sum_freeze_en bit(4) +#define ov5648_awb_ctrl_gain_manual_en bit(3) + +#define ov5648_awb_delta_reg 0x5181 +#define ov5648_awb_stable_range_reg 0x5182 +#define ov5648_awb_stable_range_wide_reg 0x5183 +#define ov5648_hsize_man_reg 0x5185 + +#define ov5648_gain_red_man_h_reg 0x5186 +#define ov5648_gain_red_man_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov5648_gain_red_man_l_reg 0x5187 +#define ov5648_gain_red_man_l(v) ((v) & genmask(7, 0)) +#define ov5648_gain_green_man_h_reg 0x5188 +#define ov5648_gain_green_man_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov5648_gain_green_man_l_reg 0x5189 +#define ov5648_gain_green_man_l(v) ((v) & genmask(7, 0)) +#define ov5648_gain_blue_man_h_reg 0x518a +#define ov5648_gain_blue_man_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov5648_gain_blue_man_l_reg 0x518b +#define ov5648_gain_blue_man_l(v) ((v) & genmask(7, 0)) +#define ov5648_gain_red_limit_reg 0x518c +#define ov5648_gain_green_limit_reg 0x518d +#define ov5648_gain_blue_limit_reg 0x518e +#define ov5648_awb_frame_count_reg 0x518f +#define ov5648_awb_base_man_reg 0x51df + +/* macros */ + +#define ov5648_subdev_sensor(s) \ + container_of(s, struct ov5648_sensor, subdev) + +#define ov5648_ctrl_subdev(c) \ + (&container_of(c->handler, struct ov5648_sensor, ctrls.handler)->subdev) + +/* data structures */ + +struct ov5648_register_value { + u16 address; + u8 value; + unsigned int delay_ms; +}; + +/* + * pll1 clock tree: + * + * +-< xvclk + * | + * +-+ pll_pre_div (0x3037 [3:0], special values: 5: 1.5, 7: 2.5) + * | + * +-+ pll_mul (0x3036 [7:0]) + * | + * +-+ sys_div (0x3035 [7:4]) + * | + * +-+ mipi_div (0x3035 [3:0]) + * | | + * | +-> mipi_sclk + * | | + * | +-+ mipi_phy_div (2) + * | | + * | +-> mipi_clk + * | + * +-+ root_div (0x3037 [4]) + * | + * +-+ bit_div (0x3034 [3:0], 8 bits: 2, 10 bits: 2.5, other: 1) + * | + * +-+ sclk_div (0x3106 [3:2]) + * | + * +-> sclk + * | + * +-+ mipi_div (0x3035, 1: pclk = sclk) + * | + * +-> pclk + */ + +struct ov5648_pll1_config { + unsigned int pll_pre_div; + unsigned int pll_mul; + unsigned int sys_div; + unsigned int root_div; + unsigned int sclk_div; + unsigned int mipi_div; +}; + +/* + * pll2 clock tree: + * + * +-< xvclk + * | + * +-+ plls_pre_div (0x303d [5:4], special values: 0: 1, 1: 1.5) + * | + * +-+ plls_div_r (0x303d [2]) + * | + * +-+ plls_mul (0x303b [4:0]) + * | + * +-+ sys_div (0x303c [3:0]) + * | + * +-+ sel_div (0x303d [1:0], special values: 0: 1, 3: 2.5) + * | + * +-> adclk + */ + +struct ov5648_pll2_config { + unsigned int plls_pre_div; + unsigned int plls_div_r; + unsigned int plls_mul; + unsigned int sys_div; + unsigned int sel_div; +}; + +/* + * general formulas for (array-centered) mode calculation: + * - photo_array_width = 2624 + * - crop_start_x = (photo_array_width - output_size_x) / 2 + * - crop_end_x = crop_start_x + offset_x + output_size_x - 1 + * + * - photo_array_height = 1956 + * - crop_start_y = (photo_array_height - output_size_y) / 2 + * - crop_end_y = crop_start_y + offset_y + output_size_y - 1 + */ + +struct ov5648_mode { + unsigned int crop_start_x; + unsigned int offset_x; + unsigned int output_size_x; + unsigned int crop_end_x; + unsigned int hts; + + unsigned int crop_start_y; + unsigned int offset_y; + unsigned int output_size_y; + unsigned int crop_end_y; + unsigned int vts; + + bool binning_x; + bool binning_y; + + unsigned int inc_x_odd; + unsigned int inc_x_even; + unsigned int inc_y_odd; + unsigned int inc_y_even; + + /* 8-bit frame interval followed by 10-bit frame interval. */ + struct v4l2_fract frame_interval[2]; + + /* 8-bit config followed by 10-bit config. */ + const struct ov5648_pll1_config *pll1_config[2]; + const struct ov5648_pll2_config *pll2_config; + + const struct ov5648_register_value *register_values; + unsigned int register_values_count; +}; + +struct ov5648_state { + const struct ov5648_mode *mode; + u32 mbus_code; + + bool streaming; +}; + +struct ov5648_ctrls { + struct v4l2_ctrl *exposure_auto; + struct v4l2_ctrl *exposure; + + struct v4l2_ctrl *gain_auto; + struct v4l2_ctrl *gain; + + struct v4l2_ctrl *white_balance_auto; + struct v4l2_ctrl *red_balance; + struct v4l2_ctrl *blue_balance; + + struct v4l2_ctrl *link_freq; + struct v4l2_ctrl *pixel_rate; + + struct v4l2_ctrl_handler handler; +} __packed; + +struct ov5648_sensor { + struct device *dev; + struct i2c_client *i2c_client; + struct gpio_desc *reset; + struct gpio_desc *powerdown; + struct regulator *avdd; + struct regulator *dvdd; + struct regulator *dovdd; + struct clk *xvclk; + + struct v4l2_fwnode_endpoint endpoint; + struct v4l2_subdev subdev; + struct media_pad pad; + + struct mutex mutex; + + struct ov5648_state state; + struct ov5648_ctrls ctrls; +}; + +/* static definitions */ + +/* + * xvclk = 24 mhz + * sclk = 84 mhz + * pclk = 84 mhz + */ +static const struct ov5648_pll1_config ov5648_pll1_config_native_8_bits = { + .pll_pre_div = 3, + .pll_mul = 84, + .sys_div = 2, + .root_div = 1, + .sclk_div = 1, + .mipi_div = 1, +}; + +/* + * xvclk = 24 mhz + * sclk = 84 mhz + * pclk = 84 mhz + */ +static const struct ov5648_pll1_config ov5648_pll1_config_native_10_bits = { + .pll_pre_div = 3, + .pll_mul = 105, + .sys_div = 2, + .root_div = 1, + .sclk_div = 1, + .mipi_div = 1, +}; + +/* + * xvclk = 24 mhz + * adclk = 200 mhz + */ +static const struct ov5648_pll2_config ov5648_pll2_config_native = { + .plls_pre_div = 3, + .plls_div_r = 1, + .plls_mul = 25, + .sys_div = 1, + .sel_div = 1, +}; + +static const struct ov5648_mode ov5648_modes[] = { + /* 2592x1944 */ + { + /* horizontal */ + .crop_start_x = 16, + .offset_x = 0, + .output_size_x = 2592, + .crop_end_x = 2607, + .hts = 2816, + + /* vertical */ + .crop_start_y = 6, + .offset_y = 0, + .output_size_y = 1944, + .crop_end_y = 1949, + .vts = 1984, + + /* subsample increase */ + .inc_x_odd = 1, + .inc_x_even = 1, + .inc_y_odd = 1, + .inc_y_even = 1, + + /* frame interval */ + .frame_interval = { + { 1, 15 }, + { 1, 15 }, + }, + + /* pll */ + .pll1_config = { + &ov5648_pll1_config_native_8_bits, + &ov5648_pll1_config_native_10_bits, + }, + .pll2_config = &ov5648_pll2_config_native, + }, + /* 1600x1200 (uxga) */ + { + /* horizontal */ + .crop_start_x = 512, + .offset_x = 0, + .output_size_x = 1600, + .crop_end_x = 2111, + .hts = 2816, + + /* vertical */ + .crop_start_y = 378, + .offset_y = 0, + .output_size_y = 1200, + .crop_end_y = 1577, + .vts = 1984, + + /* subsample increase */ + .inc_x_odd = 1, + .inc_x_even = 1, + .inc_y_odd = 1, + .inc_y_even = 1, + + /* frame interval */ + .frame_interval = { + { 1, 15 }, + { 1, 15 }, + }, + + /* pll */ + .pll1_config = { + &ov5648_pll1_config_native_8_bits, + &ov5648_pll1_config_native_10_bits, + }, + .pll2_config = &ov5648_pll2_config_native, + }, + /* 1920x1080 (full hd) */ + { + /* horizontal */ + .crop_start_x = 352, + .offset_x = 0, + .output_size_x = 1920, + .crop_end_x = 2271, + .hts = 2816, + + /* vertical */ + .crop_start_y = 438, + .offset_y = 0, + .output_size_y = 1080, + .crop_end_y = 1517, + .vts = 1984, + + /* subsample increase */ + .inc_x_odd = 1, + .inc_x_even = 1, + .inc_y_odd = 1, + .inc_y_even = 1, + + /* frame interval */ + .frame_interval = { + { 1, 15 }, + { 1, 15 }, + }, + + /* pll */ + .pll1_config = { + &ov5648_pll1_config_native_8_bits, + &ov5648_pll1_config_native_10_bits, + }, + .pll2_config = &ov5648_pll2_config_native, + }, + /* 1280x960 */ + { + /* horizontal */ + .crop_start_x = 16, + .offset_x = 8, + .output_size_x = 1280, + .crop_end_x = 2607, + .hts = 1912, + + /* vertical */ + .crop_start_y = 6, + .offset_y = 6, + .output_size_y = 960, + .crop_end_y = 1949, + .vts = 1496, + + /* binning */ + .binning_x = true, + + /* subsample increase */ + .inc_x_odd = 3, + .inc_x_even = 1, + .inc_y_odd = 3, + .inc_y_even = 1, + + /* frame interval */ + .frame_interval = { + { 1, 30 }, + { 1, 30 }, + }, + + /* pll */ + .pll1_config = { + &ov5648_pll1_config_native_8_bits, + &ov5648_pll1_config_native_10_bits, + }, + .pll2_config = &ov5648_pll2_config_native, + }, + /* 1280x720 (hd) */ + { + /* horizontal */ + .crop_start_x = 16, + .offset_x = 8, + .output_size_x = 1280, + .crop_end_x = 2607, + .hts = 1912, + + /* vertical */ + .crop_start_y = 254, + .offset_y = 2, + .output_size_y = 720, + .crop_end_y = 1701, + .vts = 1496, + + /* binning */ + .binning_x = true, + + /* subsample increase */ + .inc_x_odd = 3, + .inc_x_even = 1, + .inc_y_odd = 3, + .inc_y_even = 1, + + /* frame interval */ + .frame_interval = { + { 1, 30 }, + { 1, 30 }, + }, + + /* pll */ + .pll1_config = { + &ov5648_pll1_config_native_8_bits, + &ov5648_pll1_config_native_10_bits, + }, + .pll2_config = &ov5648_pll2_config_native, + }, + /* 640x480 (vga) */ + { + /* horizontal */ + .crop_start_x = 0, + .offset_x = 8, + .output_size_x = 640, + .crop_end_x = 2623, + .hts = 1896, + + /* vertical */ + .crop_start_y = 0, + .offset_y = 2, + .output_size_y = 480, + .crop_end_y = 1953, + .vts = 984, + + /* binning */ + .binning_x = true, + + /* subsample increase */ + .inc_x_odd = 7, + .inc_x_even = 1, + .inc_y_odd = 7, + .inc_y_even = 1, + + /* frame interval */ + .frame_interval = { + { 1, 30 }, + { 1, 30 }, + }, + + /* pll */ + .pll1_config = { + &ov5648_pll1_config_native_8_bits, + &ov5648_pll1_config_native_10_bits, + }, + .pll2_config = &ov5648_pll2_config_native, + }, +}; + +static const u32 ov5648_mbus_codes[] = { + media_bus_fmt_sbggr8_1x8, + media_bus_fmt_sbggr10_1x10, +}; + +static const struct ov5648_register_value ov5648_init_sequence[] = { + /* psram */ + { ov5648_psram_ctrl1_reg, 0x0d }, + { ov5648_psram_ctrlf_reg, 0xf5 }, +}; + +static const s64 ov5648_link_freq_menu[] = { + 210000000, + 168000000, +}; + +static const char *const ov5648_test_pattern_menu[] = { + "disabled", + "random data", + "color bars", + "color bars with rolling bar", + "color squares", + "color squares with rolling bar" +}; + +static const u8 ov5648_test_pattern_bits[] = { + 0, + ov5648_isp_ctrl3d_pattern_en | ov5648_isp_ctrl3d_pattern_random_data, + ov5648_isp_ctrl3d_pattern_en | ov5648_isp_ctrl3d_pattern_color_bars, + ov5648_isp_ctrl3d_pattern_en | ov5648_isp_ctrl3d_rolling_bar_en | + ov5648_isp_ctrl3d_pattern_color_bars, + ov5648_isp_ctrl3d_pattern_en | ov5648_isp_ctrl3d_pattern_color_squares, + ov5648_isp_ctrl3d_pattern_en | ov5648_isp_ctrl3d_rolling_bar_en | + ov5648_isp_ctrl3d_pattern_color_squares, +}; + +/* input/output */ + +static int ov5648_read(struct ov5648_sensor *sensor, u16 address, u8 *value) +{ + unsigned char data[2] = { address >> 8, address & 0xff }; + struct i2c_client *client = sensor->i2c_client; + int ret; + + ret = i2c_master_send(client, data, sizeof(data)); + if (ret < 0) { + dev_dbg(&client->dev, "i2c send error at address %#04x ", + address); + return ret; + } + + ret = i2c_master_recv(client, value, 1); + if (ret < 0) { + dev_dbg(&client->dev, "i2c recv error at address %#04x ", + address); + return ret; + } + + return 0; +} + +static int ov5648_write(struct ov5648_sensor *sensor, u16 address, u8 value) +{ + unsigned char data[3] = { address >> 8, address & 0xff, value }; + struct i2c_client *client = sensor->i2c_client; + int ret; + + ret = i2c_master_send(client, data, sizeof(data)); + if (ret < 0) { + dev_dbg(&client->dev, "i2c send error at address %#04x ", + address); + return ret; + } + + return 0; +} + +static int ov5648_write_sequence(struct ov5648_sensor *sensor, + const struct ov5648_register_value *sequence, + unsigned int sequence_count) +{ + unsigned int i; + int ret = 0; + + for (i = 0; i < sequence_count; i++) { + ret = ov5648_write(sensor, sequence[i].address, + sequence[i].value); + if (ret) + break; + + if (sequence[i].delay_ms) + msleep(sequence[i].delay_ms); + } + + return ret; +} + +static int ov5648_update_bits(struct ov5648_sensor *sensor, u16 address, + u8 mask, u8 bits) +{ + u8 value = 0; + int ret; + + ret = ov5648_read(sensor, address, &value); + if (ret) + return ret; + + value &= ~mask; + value |= bits; + + ret = ov5648_write(sensor, address, value); + if (ret) + return ret; + + return 0; +} + +/* sensor */ + +static int ov5648_sw_reset(struct ov5648_sensor *sensor) +{ + return ov5648_write(sensor, ov5648_sw_reset_reg, ov5648_sw_reset_reset); +} + +static int ov5648_sw_standby(struct ov5648_sensor *sensor, int standby) +{ + u8 value = 0; + + if (!standby) + value = ov5648_sw_standby_stream_on; + + return ov5648_write(sensor, ov5648_sw_standby_reg, value); +} + +static int ov5648_chip_id_check(struct ov5648_sensor *sensor) +{ + u16 regs[] = { ov5648_chip_id_h_reg, ov5648_chip_id_l_reg }; + u8 values[] = { ov5648_chip_id_h_value, ov5648_chip_id_l_value }; + unsigned int i; + u8 value; + int ret; + + for (i = 0; i < array_size(regs); i++) { + ret = ov5648_read(sensor, regs[i], &value); + if (ret < 0) + return ret; + + if (value != values[i]) { + dev_err(sensor->dev, + "chip id value mismatch: %#x instead of %#x ", + value, values[i]); + return -einval; + } + } + + return 0; +} + +static int ov5648_avdd_internal_power(struct ov5648_sensor *sensor, int on) +{ + return ov5648_write(sensor, ov5648_a_pwc_pk_o0_reg, + on ? 0 : ov5648_a_pwc_pk_o0_bp_regulator_n); +} + +static int ov5648_pad_configure(struct ov5648_sensor *sensor) +{ + int ret; + + /* configure pads as input. */ + + ret = ov5648_write(sensor, ov5648_pad_oen1_reg, 0); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_pad_oen2_reg, 0); + if (ret) + return ret; + + /* disable frex pin. */ + + return ov5648_write(sensor, ov5648_pad_pk_reg, + ov5648_pad_pk_drive_strength_1x | + ov5648_pad_pk_frex_n); +} + +static int ov5648_mipi_configure(struct ov5648_sensor *sensor) +{ + struct v4l2_fwnode_bus_mipi_csi2 *bus_mipi_csi2 = + &sensor->endpoint.bus.mipi_csi2; + unsigned int lanes_count = bus_mipi_csi2->num_data_lanes; + int ret; + + ret = ov5648_write(sensor, ov5648_mipi_ctrl0_reg, + ov5648_mipi_ctrl0_clk_lane_autogate | + ov5648_mipi_ctrl0_lane_select_lane1 | + ov5648_mipi_ctrl0_idle_lp11); + if (ret) + return ret; + + return ov5648_write(sensor, ov5648_mipi_sc_ctrl0_reg, + ov5648_mipi_sc_ctrl0_mipi_lanes(lanes_count) | + ov5648_mipi_sc_ctrl0_phy_lp_rx_pd | + ov5648_mipi_sc_ctrl0_mipi_en); +} + +static int ov5648_black_level_configure(struct ov5648_sensor *sensor) +{ + int ret; + + /* up to 6 lines are available for black level calibration. */ + + ret = ov5648_write(sensor, ov5648_blc_ctrl1_reg, + ov5648_blc_ctrl1_start_line(2)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_blc_ctrl2_reg, + ov5648_blc_ctrl2_auto_en | + ov5648_blc_ctrl2_reset_frame_num(5)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_blc_line_num_reg, + ov5648_blc_line_num(4)); + if (ret) + return ret; + + return ov5648_update_bits(sensor, ov5648_blc_ctrl5_reg, + ov5648_blc_ctrl5_update_en, + ov5648_blc_ctrl5_update_en); +} + +static int ov5648_isp_configure(struct ov5648_sensor *sensor) +{ + u8 bits; + int ret; + + /* enable black and white level correction. */ + bits = ov5648_isp_ctrl0_black_correct_en | + ov5648_isp_ctrl0_white_correct_en; + + ret = ov5648_update_bits(sensor, ov5648_isp_ctrl0_reg, bits, bits); + if (ret) + return ret; + + /* enable awb. */ + ret = ov5648_write(sensor, ov5648_isp_ctrl1_reg, + ov5648_isp_ctrl1_awb_en); + if (ret) + return ret; + + /* enable awb gain and windowing. */ + ret = ov5648_write(sensor, ov5648_isp_ctrl2_reg, + ov5648_isp_ctrl2_win_en | + ov5648_isp_ctrl2_awb_gain_en); + if (ret) + return ret; + + /* enable buffering and auto-binning. */ + ret = ov5648_write(sensor, ov5648_isp_ctrl3_reg, + ov5648_isp_ctrl3_buf_en | + ov5648_isp_ctrl3_bin_auto_en); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_isp_ctrl4_reg, 0); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_isp_ctrl1f_reg, + ov5648_isp_ctrl1f_output_en); + if (ret) + return ret; + + /* enable post-binning filters. */ + ret = ov5648_write(sensor, ov5648_isp_ctrl4b_reg, + ov5648_isp_ctrl4b_post_bin_h_en | + ov5648_isp_ctrl4b_post_bin_v_en); + if (ret) + return ret; + + /* disable debanding and night mode. debug bit seems necessary. */ + ret = ov5648_write(sensor, ov5648_aec_ctrl0_reg, + ov5648_aec_ctrl0_debug | + ov5648_aec_ctrl0_start_sel_en); + if (ret) + return ret; + + return ov5648_write(sensor, ov5648_manual_ctrl_reg, + ov5648_manual_ctrl_frame_delay(1)); +} + +static unsigned long ov5648_mode_pll1_rate(struct ov5648_sensor *sensor, + const struct ov5648_pll1_config *config) +{ + unsigned long xvclk_rate; + unsigned long pll1_rate; + + xvclk_rate = clk_get_rate(sensor->xvclk); + pll1_rate = xvclk_rate * config->pll_mul; + + switch (config->pll_pre_div) { + case 5: + pll1_rate *= 3; + pll1_rate /= 2; + break; + case 7: + pll1_rate *= 5; + pll1_rate /= 2; + break; + default: + pll1_rate /= config->pll_pre_div; + break; + } + + return pll1_rate; +} + +static int ov5648_mode_pll1_configure(struct ov5648_sensor *sensor, + const struct ov5648_mode *mode, + u32 mbus_code) +{ + const struct ov5648_pll1_config *config; + u8 value; + int ret; + + value = ov5648_pll_ctrl0_pll_charge_pump(1); + + switch (mbus_code) { + case media_bus_fmt_sbggr8_1x8: + config = mode->pll1_config[0]; + value |= ov5648_pll_ctrl0_bits(8); + break; + case media_bus_fmt_sbggr10_1x10: + config = mode->pll1_config[1]; + value |= ov5648_pll_ctrl0_bits(10); + break; + default: + return -einval; + } + + ret = ov5648_write(sensor, ov5648_pll_ctrl0_reg, value); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_pll_div_reg, + ov5648_pll_div_root_div(config->root_div) | + ov5648_pll_div_pll_pre_div(config->pll_pre_div)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_pll_mul_reg, + ov5648_pll_mul(config->pll_mul)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_pll_ctrl1_reg, + ov5648_pll_ctrl1_sys_div(config->sys_div) | + ov5648_pll_ctrl1_mipi_div(config->mipi_div)); + if (ret) + return ret; + + return ov5648_write(sensor, ov5648_srb_ctrl_reg, + ov5648_srb_ctrl_sclk_div(config->sclk_div) | + ov5648_srb_ctrl_sclk_arbiter_en); +} + +static int ov5648_mode_pll2_configure(struct ov5648_sensor *sensor, + const struct ov5648_mode *mode) +{ + const struct ov5648_pll2_config *config = mode->pll2_config; + int ret; + + ret = ov5648_write(sensor, ov5648_plls_div_reg, + ov5648_plls_div_plls_pre_div(config->plls_pre_div) | + ov5648_plls_div_plls_div_r(config->plls_div_r) | + ov5648_plls_div_plls_sel_div(config->sel_div)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_plls_mul_reg, + ov5648_plls_mul(config->plls_mul)); + if (ret) + return ret; + + return ov5648_write(sensor, ov5648_plls_ctrl_reg, + ov5648_plls_ctrl_pll_charge_pump(1) | + ov5648_plls_ctrl_sys_div(config->sys_div)); +} + +static int ov5648_mode_configure(struct ov5648_sensor *sensor, + const struct ov5648_mode *mode, u32 mbus_code) +{ + int ret; + + /* crop start x */ + + ret = ov5648_write(sensor, ov5648_crop_start_x_h_reg, + ov5648_crop_start_x_h(mode->crop_start_x)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_crop_start_x_l_reg, + ov5648_crop_start_x_l(mode->crop_start_x)); + if (ret) + return ret; + + /* offset x */ + + ret = ov5648_write(sensor, ov5648_offset_x_h_reg, + ov5648_offset_x_h(mode->offset_x)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_offset_x_l_reg, + ov5648_offset_x_l(mode->offset_x)); + if (ret) + return ret; + + /* output size x */ + + ret = ov5648_write(sensor, ov5648_output_size_x_h_reg, + ov5648_output_size_x_h(mode->output_size_x)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_output_size_x_l_reg, + ov5648_output_size_x_l(mode->output_size_x)); + if (ret) + return ret; + + /* crop end x */ + + ret = ov5648_write(sensor, ov5648_crop_end_x_h_reg, + ov5648_crop_end_x_h(mode->crop_end_x)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_crop_end_x_l_reg, + ov5648_crop_end_x_l(mode->crop_end_x)); + if (ret) + return ret; + + /* horizontal total size */ + + ret = ov5648_write(sensor, ov5648_hts_h_reg, ov5648_hts_h(mode->hts)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_hts_l_reg, ov5648_hts_l(mode->hts)); + if (ret) + return ret; + + /* crop start y */ + + ret = ov5648_write(sensor, ov5648_crop_start_y_h_reg, + ov5648_crop_start_y_h(mode->crop_start_y)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_crop_start_y_l_reg, + ov5648_crop_start_y_l(mode->crop_start_y)); + if (ret) + return ret; + + /* offset y */ + + ret = ov5648_write(sensor, ov5648_offset_y_h_reg, + ov5648_offset_y_h(mode->offset_y)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_offset_y_l_reg, + ov5648_offset_y_l(mode->offset_y)); + if (ret) + return ret; + + /* output size y */ + + ret = ov5648_write(sensor, ov5648_output_size_y_h_reg, + ov5648_output_size_y_h(mode->output_size_y)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_output_size_y_l_reg, + ov5648_output_size_y_l(mode->output_size_y)); + if (ret) + return ret; + + /* crop end y */ + + ret = ov5648_write(sensor, ov5648_crop_end_y_h_reg, + ov5648_crop_end_y_h(mode->crop_end_y)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_crop_end_y_l_reg, + ov5648_crop_end_y_l(mode->crop_end_y)); + if (ret) + return ret; + + /* vertical total size */ + + ret = ov5648_write(sensor, ov5648_vts_h_reg, ov5648_vts_h(mode->vts)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_vts_l_reg, ov5648_vts_l(mode->vts)); + if (ret) + return ret; + + /* flip/mirror/binning */ + + /* + * a debug bit is enabled by default and needs to be cleared for + * subsampling to work. + */ + ret = ov5648_update_bits(sensor, ov5648_tc20_reg, + ov5648_tc20_debug | + ov5648_tc20_binning_vert_en, + mode->binning_y ? ov5648_tc20_binning_vert_en : + 0); + if (ret) + return ret; + + ret = ov5648_update_bits(sensor, ov5648_tc21_reg, + ov5648_tc21_binning_horz_en, + mode->binning_x ? ov5648_tc21_binning_horz_en : + 0); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_sub_inc_x_reg, + ov5648_sub_inc_x_odd(mode->inc_x_odd) | + ov5648_sub_inc_x_even(mode->inc_x_even)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_sub_inc_y_reg, + ov5648_sub_inc_y_odd(mode->inc_y_odd) | + ov5648_sub_inc_y_even(mode->inc_y_even)); + if (ret) + return ret; + + /* plls */ + + ret = ov5648_mode_pll1_configure(sensor, mode, mbus_code); + if (ret) + return ret; + + ret = ov5648_mode_pll2_configure(sensor, mode); + if (ret) + return ret; + + /* extra registers */ + + if (mode->register_values) { + ret = ov5648_write_sequence(sensor, mode->register_values, + mode->register_values_count); + if (ret) + return ret; + } + + return 0; +} + +static unsigned long ov5648_mode_mipi_clk_rate(struct ov5648_sensor *sensor, + const struct ov5648_mode *mode, + u32 mbus_code) +{ + const struct ov5648_pll1_config *config; + unsigned long pll1_rate; + + switch (mbus_code) { + case media_bus_fmt_sbggr8_1x8: + config = mode->pll1_config[0]; + break; + case media_bus_fmt_sbggr10_1x10: + config = mode->pll1_config[1]; + break; + default: + return 0; + } + + pll1_rate = ov5648_mode_pll1_rate(sensor, config); + + return pll1_rate / config->sys_div / config->mipi_div / 2; +} + +/* exposure */ + +static int ov5648_exposure_auto_configure(struct ov5648_sensor *sensor, + bool enable) +{ + return ov5648_update_bits(sensor, ov5648_manual_ctrl_reg, + ov5648_manual_ctrl_aec_manual_en, + enable ? 0 : ov5648_manual_ctrl_aec_manual_en); +} + +static int ov5648_exposure_configure(struct ov5648_sensor *sensor, u32 exposure) +{ + struct ov5648_ctrls *ctrls = &sensor->ctrls; + int ret; + + if (ctrls->exposure_auto->val != v4l2_exposure_manual) + return -einval; + + ret = ov5648_write(sensor, ov5648_exposure_ctrl_hh_reg, + ov5648_exposure_ctrl_hh(exposure)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_exposure_ctrl_h_reg, + ov5648_exposure_ctrl_h(exposure)); + if (ret) + return ret; + + return ov5648_write(sensor, ov5648_exposure_ctrl_l_reg, + ov5648_exposure_ctrl_l(exposure)); +} + +static int ov5648_exposure_value(struct ov5648_sensor *sensor, + u32 *exposure) +{ + u8 exposure_hh = 0, exposure_h = 0, exposure_l = 0; + int ret; + + ret = ov5648_read(sensor, ov5648_exposure_ctrl_hh_reg, &exposure_hh); + if (ret) + return ret; + + ret = ov5648_read(sensor, ov5648_exposure_ctrl_h_reg, &exposure_h); + if (ret) + return ret; + + ret = ov5648_read(sensor, ov5648_exposure_ctrl_l_reg, &exposure_l); + if (ret) + return ret; + + *exposure = ov5648_exposure_ctrl_hh_value((u32)exposure_hh) | + ov5648_exposure_ctrl_h_value((u32)exposure_h) | + ov5648_exposure_ctrl_l_value((u32)exposure_l); + + return 0; +} + +/* gain */ + +static int ov5648_gain_auto_configure(struct ov5648_sensor *sensor, bool enable) +{ + return ov5648_update_bits(sensor, ov5648_manual_ctrl_reg, + ov5648_manual_ctrl_agc_manual_en, + enable ? 0 : ov5648_manual_ctrl_agc_manual_en); +} + +static int ov5648_gain_configure(struct ov5648_sensor *sensor, u32 gain) +{ + struct ov5648_ctrls *ctrls = &sensor->ctrls; + int ret; + + if (ctrls->gain_auto->val) + return -einval; + + ret = ov5648_write(sensor, ov5648_gain_ctrl_h_reg, + ov5648_gain_ctrl_h(gain)); + if (ret) + return ret; + + return ov5648_write(sensor, ov5648_gain_ctrl_l_reg, + ov5648_gain_ctrl_l(gain)); +} + +static int ov5648_gain_value(struct ov5648_sensor *sensor, u32 *gain) +{ + u8 gain_h = 0, gain_l = 0; + int ret; + + ret = ov5648_read(sensor, ov5648_gain_ctrl_h_reg, &gain_h); + if (ret) + return ret; + + ret = ov5648_read(sensor, ov5648_gain_ctrl_l_reg, &gain_l); + if (ret) + return ret; + + *gain = ov5648_gain_ctrl_h_value((u32)gain_h) | + ov5648_gain_ctrl_l_value((u32)gain_l); + + return 0; +} + +/* white balance */ + +static int ov5648_white_balance_auto_configure(struct ov5648_sensor *sensor, + bool enable) +{ + return ov5648_write(sensor, ov5648_awb_ctrl_reg, + enable ? 0 : ov5648_awb_ctrl_gain_manual_en); +} + +static int ov5648_white_balance_configure(struct ov5648_sensor *sensor, + u32 red_balance, u32 blue_balance) +{ + struct ov5648_ctrls *ctrls = &sensor->ctrls; + int ret; + + if (ctrls->white_balance_auto->val) + return -einval; + + ret = ov5648_write(sensor, ov5648_gain_red_man_h_reg, + ov5648_gain_red_man_h(red_balance)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_gain_red_man_l_reg, + ov5648_gain_red_man_l(red_balance)); + if (ret) + return ret; + + ret = ov5648_write(sensor, ov5648_gain_blue_man_h_reg, + ov5648_gain_blue_man_h(blue_balance)); + if (ret) + return ret; + + return ov5648_write(sensor, ov5648_gain_blue_man_l_reg, + ov5648_gain_blue_man_l(blue_balance)); +} + +/* flip */ + +static int ov5648_flip_vert_configure(struct ov5648_sensor *sensor, bool enable) +{ + u8 bits = ov5648_tc20_flip_vert_isp_en | + ov5648_tc20_flip_vert_sensor_en; + + return ov5648_update_bits(sensor, ov5648_tc20_reg, bits, + enable ? bits : 0); +} + +static int ov5648_flip_horz_configure(struct ov5648_sensor *sensor, bool enable) +{ + u8 bits = ov5648_tc21_flip_horz_isp_en | + ov5648_tc21_flip_horz_sensor_en; + + return ov5648_update_bits(sensor, ov5648_tc21_reg, bits, + enable ? bits : 0); +} + +/* test pattern */ + +static int ov5648_test_pattern_configure(struct ov5648_sensor *sensor, + unsigned int index) +{ + if (index >= array_size(ov5648_test_pattern_bits)) + return -einval; + + return ov5648_write(sensor, ov5648_isp_ctrl3d_reg, + ov5648_test_pattern_bits[index]); +} + +/* state */ + +static int ov5648_state_mipi_configure(struct ov5648_sensor *sensor, + const struct ov5648_mode *mode, + u32 mbus_code) +{ + struct ov5648_ctrls *ctrls = &sensor->ctrls; + struct v4l2_fwnode_bus_mipi_csi2 *bus_mipi_csi2 = + &sensor->endpoint.bus.mipi_csi2; + unsigned long mipi_clk_rate; + unsigned int bits_per_sample; + unsigned int lanes_count; + unsigned int i, j; + s64 mipi_pixel_rate; + + mipi_clk_rate = ov5648_mode_mipi_clk_rate(sensor, mode, mbus_code); + if (!mipi_clk_rate) + return -einval; + + for (i = 0; i < array_size(ov5648_link_freq_menu); i++) { + s64 freq = ov5648_link_freq_menu[i]; + + if (freq == mipi_clk_rate) + break; + } + + for (j = 0; j < sensor->endpoint.nr_of_link_frequencies; j++) { + u64 freq = sensor->endpoint.link_frequencies[j]; + + if (freq == mipi_clk_rate) + break; + } + + if (i == array_size(ov5648_link_freq_menu)) { + dev_err(sensor->dev, + "failed to find %lu clk rate in link freq ", + mipi_clk_rate); + } else if (j == sensor->endpoint.nr_of_link_frequencies) { + dev_err(sensor->dev, + "failed to find %lu clk rate in endpoint link-frequencies ", + mipi_clk_rate); + } else { + __v4l2_ctrl_s_ctrl(ctrls->link_freq, i); + } + + switch (mbus_code) { + case media_bus_fmt_sbggr8_1x8: + bits_per_sample = 8; + break; + case media_bus_fmt_sbggr10_1x10: + bits_per_sample = 10; + break; + default: + return -einval; + } + + lanes_count = bus_mipi_csi2->num_data_lanes; + mipi_pixel_rate = mipi_clk_rate * 2 * lanes_count / bits_per_sample; + + __v4l2_ctrl_s_ctrl_int64(ctrls->pixel_rate, mipi_pixel_rate); + + return 0; +} + +static int ov5648_state_configure(struct ov5648_sensor *sensor, + const struct ov5648_mode *mode, + u32 mbus_code) +{ + int ret; + + if (sensor->state.streaming) + return -ebusy; + + /* state will be configured at first power on otherwise. */ + if (pm_runtime_enabled(sensor->dev) && + !pm_runtime_suspended(sensor->dev)) { + ret = ov5648_mode_configure(sensor, mode, mbus_code); + if (ret) + return ret; + } + + ret = ov5648_state_mipi_configure(sensor, mode, mbus_code); + if (ret) + return ret; + + sensor->state.mode = mode; + sensor->state.mbus_code = mbus_code; + + return 0; +} + +static int ov5648_state_init(struct ov5648_sensor *sensor) +{ + return ov5648_state_configure(sensor, &ov5648_modes[0], + ov5648_mbus_codes[0]); +} + +/* sensor base */ + +static int ov5648_sensor_init(struct ov5648_sensor *sensor) +{ + int ret; + + ret = ov5648_sw_reset(sensor); + if (ret) { + dev_err(sensor->dev, "failed to perform sw reset "); + return ret; + } + + ret = ov5648_sw_standby(sensor, 1); + if (ret) { + dev_err(sensor->dev, "failed to set sensor standby "); + return ret; + } + + ret = ov5648_chip_id_check(sensor); + if (ret) { + dev_err(sensor->dev, "failed to check sensor chip id "); + return ret; + } + + ret = ov5648_avdd_internal_power(sensor, !sensor->avdd); + if (ret) { + dev_err(sensor->dev, "failed to set internal avdd power "); + return ret; + } + + ret = ov5648_write_sequence(sensor, ov5648_init_sequence, + array_size(ov5648_init_sequence)); + if (ret) { + dev_err(sensor->dev, "failed to write init sequence "); + return ret; + } + + ret = ov5648_pad_configure(sensor); + if (ret) { + dev_err(sensor->dev, "failed to configure pad "); + return ret; + } + + ret = ov5648_mipi_configure(sensor); + if (ret) { + dev_err(sensor->dev, "failed to configure mipi "); + return ret; + } + + ret = ov5648_isp_configure(sensor); + if (ret) { + dev_err(sensor->dev, "failed to configure isp "); + return ret; + } + + ret = ov5648_black_level_configure(sensor); + if (ret) { + dev_err(sensor->dev, "failed to configure black level "); + return ret; + } + + /* configure current mode. */ + ret = ov5648_state_configure(sensor, sensor->state.mode, + sensor->state.mbus_code); + if (ret) { + dev_err(sensor->dev, "failed to configure state "); + return ret; + } + + return 0; +} + +static int ov5648_sensor_power(struct ov5648_sensor *sensor, bool on) +{ + /* keep initialized to zero for disable label. */ + int ret = 0; + + /* + * general notes about the power sequence: + * - power-down gpio must be active (low) during power-on; + * - reset gpio state does not matter during power-on; + * - xvclk must be provided 1 ms before register access; + * - 10 ms are needed between power-down deassert and register access. + */ + + /* note that regulator-and-gpio-based power is untested. */ + if (on) { + gpiod_set_value_cansleep(sensor->reset, 1); + gpiod_set_value_cansleep(sensor->powerdown, 1); + + ret = regulator_enable(sensor->dovdd); + if (ret) { + dev_err(sensor->dev, + "failed to enable dovdd regulator "); + goto disable; + } + + if (sensor->avdd) { + ret = regulator_enable(sensor->avdd); + if (ret) { + dev_err(sensor->dev, + "failed to enable avdd regulator "); + goto disable; + } + } + + ret = regulator_enable(sensor->dvdd); + if (ret) { + dev_err(sensor->dev, + "failed to enable dvdd regulator "); + goto disable; + } + + /* according to ov5648 power up diagram. */ + usleep_range(5000, 10000); + + ret = clk_prepare_enable(sensor->xvclk); + if (ret) { + dev_err(sensor->dev, "failed to enable xvclk clock "); + goto disable; + } + + gpiod_set_value_cansleep(sensor->reset, 0); + gpiod_set_value_cansleep(sensor->powerdown, 0); + + usleep_range(20000, 25000); + } else { +disable: + gpiod_set_value_cansleep(sensor->powerdown, 1); + gpiod_set_value_cansleep(sensor->reset, 1); + + clk_disable_unprepare(sensor->xvclk); + + regulator_disable(sensor->dvdd); + + if (sensor->avdd) + regulator_disable(sensor->avdd); + + regulator_disable(sensor->dovdd); + } + + return ret; +} + +/* controls */ + +static int ov5648_g_volatile_ctrl(struct v4l2_ctrl *ctrl) +{ + struct v4l2_subdev *subdev = ov5648_ctrl_subdev(ctrl); + struct ov5648_sensor *sensor = ov5648_subdev_sensor(subdev); + struct ov5648_ctrls *ctrls = &sensor->ctrls; + int ret; + + switch (ctrl->id) { + case v4l2_cid_exposure_auto: + ret = ov5648_exposure_value(sensor, &ctrls->exposure->val); + if (ret) + return ret; + break; + case v4l2_cid_autogain: + ret = ov5648_gain_value(sensor, &ctrls->gain->val); + if (ret) + return ret; + break; + default: + return -einval; + } + + return 0; +} + +static int ov5648_s_ctrl(struct v4l2_ctrl *ctrl) +{ + struct v4l2_subdev *subdev = ov5648_ctrl_subdev(ctrl); + struct ov5648_sensor *sensor = ov5648_subdev_sensor(subdev); + struct ov5648_ctrls *ctrls = &sensor->ctrls; + unsigned int index; + bool enable; + int ret; + + /* wait for the sensor to be on before setting controls. */ + if (pm_runtime_suspended(sensor->dev)) + return 0; + + switch (ctrl->id) { + case v4l2_cid_exposure_auto: + enable = ctrl->val == v4l2_exposure_auto; + + ret = ov5648_exposure_auto_configure(sensor, enable); + if (ret) + return ret; + + if (!enable && ctrls->exposure->is_new) { + ret = ov5648_exposure_configure(sensor, + ctrls->exposure->val); + if (ret) + return ret; + } + break; + case v4l2_cid_autogain: + enable = !!ctrl->val; + + ret = ov5648_gain_auto_configure(sensor, enable); + if (ret) + return ret; + + if (!enable) { + ret = ov5648_gain_configure(sensor, ctrls->gain->val); + if (ret) + return ret; + } + break; + case v4l2_cid_auto_white_balance: + enable = !!ctrl->val; + + ret = ov5648_white_balance_auto_configure(sensor, enable); + if (ret) + return ret; + + if (!enable) { + ret = ov5648_white_balance_configure(sensor, + ctrls->red_balance->val, + ctrls->blue_balance->val); + if (ret) + return ret; + } + break; + case v4l2_cid_hflip: + enable = !!ctrl->val; + return ov5648_flip_horz_configure(sensor, enable); + case v4l2_cid_vflip: + enable = !!ctrl->val; + return ov5648_flip_vert_configure(sensor, enable); + case v4l2_cid_test_pattern: + index = (unsigned int)ctrl->val; + return ov5648_test_pattern_configure(sensor, index); + default: + return -einval; + } + + return 0; +} + +static const struct v4l2_ctrl_ops ov5648_ctrl_ops = { + .g_volatile_ctrl = ov5648_g_volatile_ctrl, + .s_ctrl = ov5648_s_ctrl, +}; + +static int ov5648_ctrls_init(struct ov5648_sensor *sensor) +{ + struct ov5648_ctrls *ctrls = &sensor->ctrls; + struct v4l2_ctrl_handler *handler = &ctrls->handler; + const struct v4l2_ctrl_ops *ops = &ov5648_ctrl_ops; + int ret; + + v4l2_ctrl_handler_init(handler, 32); + + /* use our mutex for ctrl locking. */ + handler->lock = &sensor->mutex; + + /* exposure */ + + ctrls->exposure_auto = v4l2_ctrl_new_std_menu(handler, ops, + v4l2_cid_exposure_auto, + v4l2_exposure_manual, 0, + v4l2_exposure_auto); + + ctrls->exposure = v4l2_ctrl_new_std(handler, ops, v4l2_cid_exposure, + 16, 1048575, 16, 512); + + v4l2_ctrl_auto_cluster(2, &ctrls->exposure_auto, 1, true); + + /* gain */ + + ctrls->gain_auto = + v4l2_ctrl_new_std(handler, ops, v4l2_cid_autogain, 0, 1, 1, 1); + + ctrls->gain = v4l2_ctrl_new_std(handler, ops, v4l2_cid_gain, 16, 1023, + 16, 16); + + v4l2_ctrl_auto_cluster(2, &ctrls->gain_auto, 0, true); + + /* white balance */ + + ctrls->white_balance_auto = + v4l2_ctrl_new_std(handler, ops, v4l2_cid_auto_white_balance, 0, + 1, 1, 1); + + ctrls->red_balance = v4l2_ctrl_new_std(handler, ops, + v4l2_cid_red_balance, 0, 4095, + 1, 1024); + + ctrls->blue_balance = v4l2_ctrl_new_std(handler, ops, + v4l2_cid_blue_balance, 0, 4095, + 1, 1024); + + v4l2_ctrl_auto_cluster(3, &ctrls->white_balance_auto, 0, false); + + /* flip */ + + v4l2_ctrl_new_std(handler, ops, v4l2_cid_hflip, 0, 1, 1, 0); + v4l2_ctrl_new_std(handler, ops, v4l2_cid_vflip, 0, 1, 1, 0); + + /* test pattern */ + + v4l2_ctrl_new_std_menu_items(handler, ops, v4l2_cid_test_pattern, + array_size(ov5648_test_pattern_menu) - 1, + 0, 0, ov5648_test_pattern_menu); + + /* mipi csi-2 */ + + ctrls->link_freq = + v4l2_ctrl_new_int_menu(handler, null, v4l2_cid_link_freq, + array_size(ov5648_link_freq_menu) - 1, + 0, ov5648_link_freq_menu); + + ctrls->pixel_rate = + v4l2_ctrl_new_std(handler, null, v4l2_cid_pixel_rate, 1, + int_max, 1, 1); + + if (handler->error) { + ret = handler->error; + goto error_ctrls; + } + + ctrls->exposure->flags |= v4l2_ctrl_flag_volatile; + ctrls->gain->flags |= v4l2_ctrl_flag_volatile; + + ctrls->link_freq->flags |= v4l2_ctrl_flag_read_only; + ctrls->pixel_rate->flags |= v4l2_ctrl_flag_read_only; + + sensor->subdev.ctrl_handler = handler; + + return 0; + +error_ctrls: + v4l2_ctrl_handler_free(handler); + + return ret; +} + +/* subdev video operations */ + +static int ov5648_s_stream(struct v4l2_subdev *subdev, int enable) +{ + struct ov5648_sensor *sensor = ov5648_subdev_sensor(subdev); + struct ov5648_state *state = &sensor->state; + int ret; + + if (enable) { + ret = pm_runtime_get_sync(sensor->dev); + if (ret < 0) { + pm_runtime_put_noidle(sensor->dev); + return ret; + } + } + + mutex_lock(&sensor->mutex); + ret = ov5648_sw_standby(sensor, !enable); + mutex_unlock(&sensor->mutex); + + if (ret) + return ret; + + state->streaming = !!enable; + + if (!enable) + pm_runtime_put(sensor->dev); + + return 0; +} + +static int ov5648_g_frame_interval(struct v4l2_subdev *subdev, + struct v4l2_subdev_frame_interval *interval) +{ + struct ov5648_sensor *sensor = ov5648_subdev_sensor(subdev); + const struct ov5648_mode *mode; + int ret = 0; + + mutex_lock(&sensor->mutex); + + mode = sensor->state.mode; + + switch (sensor->state.mbus_code) { + case media_bus_fmt_sbggr8_1x8: + interval->interval = mode->frame_interval[0]; + break; + case media_bus_fmt_sbggr10_1x10: + interval->interval = mode->frame_interval[1]; + break; + default: + ret = -einval; + } + + mutex_unlock(&sensor->mutex); + + return ret; +} + +static const struct v4l2_subdev_video_ops ov5648_subdev_video_ops = { + .s_stream = ov5648_s_stream, + .g_frame_interval = ov5648_g_frame_interval, + .s_frame_interval = ov5648_g_frame_interval, +}; + +/* subdev pad operations */ + +static int ov5648_enum_mbus_code(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *config, + struct v4l2_subdev_mbus_code_enum *code_enum) +{ + if (code_enum->index >= array_size(ov5648_mbus_codes)) + return -einval; + + code_enum->code = ov5648_mbus_codes[code_enum->index]; + + return 0; +} + +static void ov5648_mbus_format_fill(struct v4l2_mbus_framefmt *mbus_format, + u32 mbus_code, + const struct ov5648_mode *mode) +{ + mbus_format->width = mode->output_size_x; + mbus_format->height = mode->output_size_y; + mbus_format->code = mbus_code; + + mbus_format->field = v4l2_field_none; + mbus_format->colorspace = v4l2_colorspace_raw; + mbus_format->ycbcr_enc = + v4l2_map_ycbcr_enc_default(mbus_format->colorspace); + mbus_format->quantization = v4l2_quantization_full_range; + mbus_format->xfer_func = + v4l2_map_xfer_func_default(mbus_format->colorspace); +} + +static int ov5648_get_fmt(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *config, + struct v4l2_subdev_format *format) +{ + struct ov5648_sensor *sensor = ov5648_subdev_sensor(subdev); + struct v4l2_mbus_framefmt *mbus_format = &format->format; + + mutex_lock(&sensor->mutex); + + if (format->which == v4l2_subdev_format_try) + *mbus_format = *v4l2_subdev_get_try_format(subdev, config, + format->pad); + else + ov5648_mbus_format_fill(mbus_format, sensor->state.mbus_code, + sensor->state.mode); + + mutex_unlock(&sensor->mutex); + + return 0; +} + +static int ov5648_set_fmt(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *config, + struct v4l2_subdev_format *format) +{ + struct ov5648_sensor *sensor = ov5648_subdev_sensor(subdev); + struct v4l2_mbus_framefmt *mbus_format = &format->format; + const struct ov5648_mode *mode; + u32 mbus_code = 0; + unsigned int index; + int ret = 0; + + mutex_lock(&sensor->mutex); + + if (sensor->state.streaming) { + ret = -ebusy; + goto complete; + } + + /* try to find requested mbus code. */ + for (index = 0; index < array_size(ov5648_mbus_codes); index++) { + if (ov5648_mbus_codes[index] == mbus_format->code) { + mbus_code = mbus_format->code; + break; + } + } + + /* fallback to default. */ + if (!mbus_code) + mbus_code = ov5648_mbus_codes[0]; + + /* find the mode with nearest dimensions. */ + mode = v4l2_find_nearest_size(ov5648_modes, array_size(ov5648_modes), + output_size_x, output_size_y, + mbus_format->width, mbus_format->height); + if (!mode) { + ret = -einval; + goto complete; + } + + ov5648_mbus_format_fill(mbus_format, mbus_code, mode); + + if (format->which == v4l2_subdev_format_try) + *v4l2_subdev_get_try_format(subdev, config, format->pad) = + *mbus_format; + else if (sensor->state.mode != mode || + sensor->state.mbus_code != mbus_code) + ret = ov5648_state_configure(sensor, mode, mbus_code); + +complete: + mutex_unlock(&sensor->mutex); + + return ret; +} + +static int ov5648_enum_frame_size(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *config, + struct v4l2_subdev_frame_size_enum *size_enum) +{ + const struct ov5648_mode *mode; + + if (size_enum->index >= array_size(ov5648_modes)) + return -einval; + + mode = &ov5648_modes[size_enum->index]; + + size_enum->min_width = size_enum->max_width = mode->output_size_x; + size_enum->min_height = size_enum->max_height = mode->output_size_y; + + return 0; +} + +static int ov5648_enum_frame_interval(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *config, + struct v4l2_subdev_frame_interval_enum *interval_enum) +{ + const struct ov5648_mode *mode = null; + unsigned int mode_index; + unsigned int interval_index; + + if (interval_enum->index > 0) + return -einval; + + /* + * multiple modes with the same dimensions may have different frame + * intervals, so look up each relevant mode. + */ + for (mode_index = 0, interval_index = 0; + mode_index < array_size(ov5648_modes); mode_index++) { + mode = &ov5648_modes[mode_index]; + + if (mode->output_size_x == interval_enum->width && + mode->output_size_y == interval_enum->height) { + if (interval_index == interval_enum->index) + break; + + interval_index++; + } + } + + if (mode_index == array_size(ov5648_modes) || !mode) + return -einval; + + switch (interval_enum->code) { + case media_bus_fmt_sbggr8_1x8: + interval_enum->interval = mode->frame_interval[0]; + break; + case media_bus_fmt_sbggr10_1x10: + interval_enum->interval = mode->frame_interval[1]; + break; + default: + return -einval; + } + + return 0; +} + +static const struct v4l2_subdev_pad_ops ov5648_subdev_pad_ops = { + .enum_mbus_code = ov5648_enum_mbus_code, + .get_fmt = ov5648_get_fmt, + .set_fmt = ov5648_set_fmt, + .enum_frame_size = ov5648_enum_frame_size, + .enum_frame_interval = ov5648_enum_frame_interval, +}; + +static const struct v4l2_subdev_ops ov5648_subdev_ops = { + .video = &ov5648_subdev_video_ops, + .pad = &ov5648_subdev_pad_ops, +}; + +static int ov5648_suspend(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ov5648_sensor *sensor = ov5648_subdev_sensor(subdev); + struct ov5648_state *state = &sensor->state; + int ret = 0; + + mutex_lock(&sensor->mutex); + + if (state->streaming) { + ret = ov5648_sw_standby(sensor, true); + if (ret) + goto complete; + } + + ret = ov5648_sensor_power(sensor, false); + if (ret) + ov5648_sw_standby(sensor, false); + +complete: + mutex_unlock(&sensor->mutex); + + return ret; +} + +static int ov5648_resume(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ov5648_sensor *sensor = ov5648_subdev_sensor(subdev); + struct ov5648_state *state = &sensor->state; + int ret = 0; + + mutex_lock(&sensor->mutex); + + ret = ov5648_sensor_power(sensor, true); + if (ret) + goto complete; + + ret = ov5648_sensor_init(sensor); + if (ret) + goto error_power; + + ret = __v4l2_ctrl_handler_setup(&sensor->ctrls.handler); + if (ret) + goto error_power; + + if (state->streaming) { + ret = ov5648_sw_standby(sensor, false); + if (ret) + goto error_power; + } + + goto complete; + +error_power: + ov5648_sensor_power(sensor, false); + +complete: + mutex_unlock(&sensor->mutex); + + return ret; +} + +static int ov5648_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct fwnode_handle *handle; + struct ov5648_sensor *sensor; + struct v4l2_subdev *subdev; + struct media_pad *pad; + unsigned long rate; + int ret; + + sensor = devm_kzalloc(dev, sizeof(*sensor), gfp_kernel); + if (!sensor) + return -enomem; + + sensor->dev = dev; + sensor->i2c_client = client; + + /* graph endpoint */ + + handle = fwnode_graph_get_next_endpoint(dev_fwnode(dev), null); + if (!handle) { + dev_err(dev, "unable to find enpoint node "); + return -einval; + } + + sensor->endpoint.bus_type = v4l2_mbus_csi2_dphy; + + ret = v4l2_fwnode_endpoint_alloc_parse(handle, &sensor->endpoint); + fwnode_handle_put(handle); + if (ret) { + dev_err(dev, "failed to parse endpoint node "); + return ret; + } + + /* gpios */ + + sensor->powerdown = devm_gpiod_get_optional(dev, "powerdown", + gpiod_out_high); + if (is_err(sensor->powerdown)) { + ret = ptr_err(sensor->powerdown); + goto error_endpoint; + } + + sensor->reset = devm_gpiod_get_optional(dev, "reset", gpiod_out_high); + if (is_err(sensor->reset)) { + ret = ptr_err(sensor->reset); + goto error_endpoint; + } + + /* regulators */ + + /* dvdd: digital core */ + sensor->dvdd = devm_regulator_get(dev, "dvdd"); + if (is_err(sensor->dvdd)) { + dev_err(dev, "cannot get dvdd (digital core) regulator "); + ret = ptr_err(sensor->dvdd); + goto error_endpoint; + } + + /* dovdd: digital i/o */ + sensor->dovdd = devm_regulator_get(dev, "dovdd"); + if (is_err(sensor->dvdd)) { + dev_err(dev, "cannot get dovdd (digital i/o) regulator "); + ret = ptr_err(sensor->dvdd); + goto error_endpoint; + } + + /* avdd: analog */ + sensor->avdd = devm_regulator_get_optional(dev, "avdd"); + if (is_err(sensor->avdd)) { + dev_info(dev, "no avdd regulator provided, using internal "); + sensor->avdd = null; + } + + /* external clock */ + + sensor->xvclk = devm_clk_get(dev, null); + if (is_err(sensor->xvclk)) { + dev_err(dev, "failed to get external clock "); + ret = ptr_err(sensor->xvclk); + goto error_endpoint; + } + + rate = clk_get_rate(sensor->xvclk); + if (rate != ov5648_xvclk_rate) { + dev_err(dev, "clock rate %lu hz is unsupported ", rate); + ret = -einval; + goto error_endpoint; + } + + /* subdev, entity and pad */ + + subdev = &sensor->subdev; + v4l2_i2c_subdev_init(subdev, client, &ov5648_subdev_ops); + + subdev->flags |= v4l2_subdev_fl_has_devnode; + subdev->entity.function = media_ent_f_cam_sensor; + + pad = &sensor->pad; + pad->flags = media_pad_fl_source; + + ret = media_entity_pads_init(&subdev->entity, 1, pad); + if (ret) + goto error_entity; + + /* mutex */ + + mutex_init(&sensor->mutex); + + /* sensor */ + + ret = ov5648_ctrls_init(sensor); + if (ret) + goto error_mutex; + + ret = ov5648_state_init(sensor); + if (ret) + goto error_ctrls; + + /* runtime pm */ + + pm_runtime_enable(sensor->dev); + pm_runtime_set_suspended(sensor->dev); + + /* v4l2 subdev register */ + + ret = v4l2_async_register_subdev_sensor_common(subdev); + if (ret) + goto error_pm; + + return 0; + +error_pm: + pm_runtime_disable(sensor->dev); + +error_ctrls: + v4l2_ctrl_handler_free(&sensor->ctrls.handler); + +error_mutex: + mutex_destroy(&sensor->mutex); + +error_entity: + media_entity_cleanup(&sensor->subdev.entity); + +error_endpoint: + v4l2_fwnode_endpoint_free(&sensor->endpoint); + + return ret; +} + +static int ov5648_remove(struct i2c_client *client) +{ + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ov5648_sensor *sensor = ov5648_subdev_sensor(subdev); + + v4l2_async_unregister_subdev(subdev); + pm_runtime_disable(sensor->dev); + v4l2_ctrl_handler_free(&sensor->ctrls.handler); + mutex_destroy(&sensor->mutex); + media_entity_cleanup(&subdev->entity); + + return 0; +} + +static const struct dev_pm_ops ov5648_pm_ops = { + set_runtime_pm_ops(ov5648_suspend, ov5648_resume, null) +}; + +static const struct of_device_id ov5648_of_match[] = { + { .compatible = "ovti,ov5648" }, + { } +}; +module_device_table(of, ov5648_of_match); + +static struct i2c_driver ov5648_driver = { + .driver = { + .name = "ov5648", + .of_match_table = ov5648_of_match, + .pm = &ov5648_pm_ops, + }, + .probe_new = ov5648_probe, + .remove = ov5648_remove, +}; + +module_i2c_driver(ov5648_driver); + +module_author("paul kocialkowski <paul.kocialkowski@bootlin.com>"); +module_description("v4l2 driver for the omnivision ov5648 image sensor"); +module_license("gpl v2");
TV tuners, webcams, video capturers
e43ccb0a045f34838b786e8021dc4838b4af5c38
paul kocialkowski
drivers
media
i2c
media: i2c: add support for the ov8865 image sensor
the ov8865 is a 8 mpx cmos image sensor producing 3264x2448 at 30 fps. other modes (including some with sub-sampling) are available too. it outputs 10-bit bayer cfa data through a mipi csi-2 interface with up to 4 lanes supported.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add support for the ov8865 image sensor
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['i2c']
['kconfig', 'c', 'makefile']
3
2,986
0
--- diff --git a/drivers/media/i2c/kconfig b/drivers/media/i2c/kconfig --- a/drivers/media/i2c/kconfig +++ b/drivers/media/i2c/kconfig +config video_ov8865 + tristate "omnivision ov8865 sensor support" + depends on i2c && pm && video_v4l2 + select media_controller + select video_v4l2_subdev_api + select v4l2_fwnode + help + this is a video4linux2 sensor driver for omnivision + ov8865 camera sensor. + + to compile this driver as a module, choose m here: the + module will be called ov8865. + diff --git a/drivers/media/i2c/makefile b/drivers/media/i2c/makefile --- a/drivers/media/i2c/makefile +++ b/drivers/media/i2c/makefile +obj-$(config_video_ov8865) += ov8865.o diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c --- /dev/null +++ b/drivers/media/i2c/ov8865.c +// spdx-license-identifier: gpl-2.0-or-later +/* + * copyright 2020 kevin l'hopital <kevin.lhopital@bootlin.com> + * copyright 2020 bootlin + * author: paul kocialkowski <paul.kocialkowski@bootlin.com> + */ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/i2c.h> +#include <linux/module.h> +#include <linux/of_graph.h> +#include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> +#include <linux/videodev2.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-image-sizes.h> +#include <media/v4l2-mediabus.h> + +/* clock rate */ + +#define ov8865_extclk_rate 24000000 + +/* register definitions */ + +/* system */ + +#define ov8865_sw_standby_reg 0x100 +#define ov8865_sw_standby_stream_on bit(0) + +#define ov8865_sw_reset_reg 0x103 +#define ov8865_sw_reset_reset bit(0) + +#define ov8865_pll_ctrl0_reg 0x300 +#define ov8865_pll_ctrl0_pre_div(v) ((v) & genmask(2, 0)) +#define ov8865_pll_ctrl1_reg 0x301 +#define ov8865_pll_ctrl1_mul_h(v) (((v) & genmask(9, 8)) >> 8) +#define ov8865_pll_ctrl2_reg 0x302 +#define ov8865_pll_ctrl2_mul_l(v) ((v) & genmask(7, 0)) +#define ov8865_pll_ctrl3_reg 0x303 +#define ov8865_pll_ctrl3_m_div(v) (((v) - 1) & genmask(3, 0)) +#define ov8865_pll_ctrl4_reg 0x304 +#define ov8865_pll_ctrl4_mipi_div(v) ((v) & genmask(1, 0)) +#define ov8865_pll_ctrl5_reg 0x305 +#define ov8865_pll_ctrl5_sys_pre_div(v) ((v) & genmask(1, 0)) +#define ov8865_pll_ctrl6_reg 0x306 +#define ov8865_pll_ctrl6_sys_div(v) (((v) - 1) & bit(0)) + +#define ov8865_pll_ctrl8_reg 0x308 +#define ov8865_pll_ctrl9_reg 0x309 +#define ov8865_pll_ctrla_reg 0x30a +#define ov8865_pll_ctrla_pre_div_half(v) (((v) - 1) & bit(0)) +#define ov8865_pll_ctrlb_reg 0x30b +#define ov8865_pll_ctrlb_pre_div(v) ((v) & genmask(2, 0)) +#define ov8865_pll_ctrlc_reg 0x30c +#define ov8865_pll_ctrlc_mul_h(v) (((v) & genmask(9, 8)) >> 8) +#define ov8865_pll_ctrld_reg 0x30d +#define ov8865_pll_ctrld_mul_l(v) ((v) & genmask(7, 0)) +#define ov8865_pll_ctrle_reg 0x30e +#define ov8865_pll_ctrle_sys_div(v) ((v) & genmask(2, 0)) +#define ov8865_pll_ctrlf_reg 0x30f +#define ov8865_pll_ctrlf_sys_pre_div(v) (((v) - 1) & genmask(3, 0)) +#define ov8865_pll_ctrl10_reg 0x310 +#define ov8865_pll_ctrl11_reg 0x311 +#define ov8865_pll_ctrl12_reg 0x312 +#define ov8865_pll_ctrl12_pre_div_half(v) ((((v) - 1) << 4) & bit(4)) +#define ov8865_pll_ctrl12_dac_div(v) (((v) - 1) & genmask(3, 0)) + +#define ov8865_pll_ctrl1b_reg 0x31b +#define ov8865_pll_ctrl1c_reg 0x31c + +#define ov8865_pll_ctrl1e_reg 0x31e +#define ov8865_pll_ctrl1e_pll1_no_lat bit(3) + +#define ov8865_pad_oen0_reg 0x3000 + +#define ov8865_pad_oen2_reg 0x3002 + +#define ov8865_clk_rst5_reg 0x3005 + +#define ov8865_chip_id_hh_reg 0x300a +#define ov8865_chip_id_hh_value 0x00 +#define ov8865_chip_id_h_reg 0x300b +#define ov8865_chip_id_h_value 0x88 +#define ov8865_chip_id_l_reg 0x300c +#define ov8865_chip_id_l_value 0x65 +#define ov8865_pad_out2_reg 0x300d + +#define ov8865_pad_sel2_reg 0x3010 +#define ov8865_pad_pk_reg 0x3011 +#define ov8865_pad_pk_drive_strength_1x (0 << 5) +#define ov8865_pad_pk_drive_strength_2x (1 << 5) +#define ov8865_pad_pk_drive_strength_3x (2 << 5) +#define ov8865_pad_pk_drive_strength_4x (3 << 5) + +#define ov8865_pump_clk_div_reg 0x3015 +#define ov8865_pump_clk_div_pump_n(v) (((v) << 4) & genmask(6, 4)) +#define ov8865_pump_clk_div_pump_p(v) ((v) & genmask(2, 0)) + +#define ov8865_mipi_sc_ctrl0_reg 0x3018 +#define ov8865_mipi_sc_ctrl0_lanes(v) ((((v) - 1) << 5) & \ + genmask(7, 5)) +#define ov8865_mipi_sc_ctrl0_mipi_en bit(4) +#define ov8865_mipi_sc_ctrl0_unknown bit(1) +#define ov8865_mipi_sc_ctrl0_lanes_pd_mipi bit(0) +#define ov8865_mipi_sc_ctrl1_reg 0x3019 +#define ov8865_clk_rst0_reg 0x301a +#define ov8865_clk_rst1_reg 0x301b +#define ov8865_clk_rst2_reg 0x301c +#define ov8865_clk_rst3_reg 0x301d +#define ov8865_clk_rst4_reg 0x301e + +#define ov8865_pclk_sel_reg 0x3020 +#define ov8865_pclk_sel_pclk_div_mask bit(3) +#define ov8865_pclk_sel_pclk_div(v) ((((v) - 1) << 3) & bit(3)) + +#define ov8865_misc_ctrl_reg 0x3021 +#define ov8865_mipi_sc_ctrl2_reg 0x3022 +#define ov8865_mipi_sc_ctrl2_clk_lanes_pd_mipi bit(1) +#define ov8865_mipi_sc_ctrl2_pd_mipi_rst_sync bit(0) + +#define ov8865_mipi_bit_sel_reg 0x3031 +#define ov8865_mipi_bit_sel(v) (((v) << 0) & genmask(4, 0)) +#define ov8865_clk_sel0_reg 0x3032 +#define ov8865_clk_sel0_pll1_sys_sel(v) (((v) << 7) & bit(7)) +#define ov8865_clk_sel1_reg 0x3033 +#define ov8865_clk_sel1_mipi_eof bit(5) +#define ov8865_clk_sel1_unknown bit(2) +#define ov8865_clk_sel1_pll_sclk_sel_mask bit(1) +#define ov8865_clk_sel1_pll_sclk_sel(v) (((v) << 1) & bit(1)) + +#define ov8865_sclk_ctrl_reg 0x3106 +#define ov8865_sclk_ctrl_sclk_div(v) (((v) << 4) & genmask(7, 4)) +#define ov8865_sclk_ctrl_sclk_pre_div(v) (((v) << 2) & genmask(3, 2)) +#define ov8865_sclk_ctrl_unknown bit(0) + +/* exposure/gain */ + +#define ov8865_exposure_ctrl_hh_reg 0x3500 +#define ov8865_exposure_ctrl_hh(v) (((v) & genmask(19, 16)) >> 16) +#define ov8865_exposure_ctrl_h_reg 0x3501 +#define ov8865_exposure_ctrl_h(v) (((v) & genmask(15, 8)) >> 8) +#define ov8865_exposure_ctrl_l_reg 0x3502 +#define ov8865_exposure_ctrl_l(v) ((v) & genmask(7, 0)) +#define ov8865_exposure_gain_manual_reg 0x3503 + +#define ov8865_gain_ctrl_h_reg 0x3508 +#define ov8865_gain_ctrl_h(v) (((v) & genmask(12, 8)) >> 8) +#define ov8865_gain_ctrl_l_reg 0x3509 +#define ov8865_gain_ctrl_l(v) ((v) & genmask(7, 0)) + +/* timing */ + +#define ov8865_crop_start_x_h_reg 0x3800 +#define ov8865_crop_start_x_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov8865_crop_start_x_l_reg 0x3801 +#define ov8865_crop_start_x_l(v) ((v) & genmask(7, 0)) +#define ov8865_crop_start_y_h_reg 0x3802 +#define ov8865_crop_start_y_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov8865_crop_start_y_l_reg 0x3803 +#define ov8865_crop_start_y_l(v) ((v) & genmask(7, 0)) +#define ov8865_crop_end_x_h_reg 0x3804 +#define ov8865_crop_end_x_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov8865_crop_end_x_l_reg 0x3805 +#define ov8865_crop_end_x_l(v) ((v) & genmask(7, 0)) +#define ov8865_crop_end_y_h_reg 0x3806 +#define ov8865_crop_end_y_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov8865_crop_end_y_l_reg 0x3807 +#define ov8865_crop_end_y_l(v) ((v) & genmask(7, 0)) +#define ov8865_output_size_x_h_reg 0x3808 +#define ov8865_output_size_x_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov8865_output_size_x_l_reg 0x3809 +#define ov8865_output_size_x_l(v) ((v) & genmask(7, 0)) +#define ov8865_output_size_y_h_reg 0x380a +#define ov8865_output_size_y_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov8865_output_size_y_l_reg 0x380b +#define ov8865_output_size_y_l(v) ((v) & genmask(7, 0)) +#define ov8865_hts_h_reg 0x380c +#define ov8865_hts_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov8865_hts_l_reg 0x380d +#define ov8865_hts_l(v) ((v) & genmask(7, 0)) +#define ov8865_vts_h_reg 0x380e +#define ov8865_vts_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov8865_vts_l_reg 0x380f +#define ov8865_vts_l(v) ((v) & genmask(7, 0)) +#define ov8865_offset_x_h_reg 0x3810 +#define ov8865_offset_x_h(v) (((v) & genmask(15, 8)) >> 8) +#define ov8865_offset_x_l_reg 0x3811 +#define ov8865_offset_x_l(v) ((v) & genmask(7, 0)) +#define ov8865_offset_y_h_reg 0x3812 +#define ov8865_offset_y_h(v) (((v) & genmask(14, 8)) >> 8) +#define ov8865_offset_y_l_reg 0x3813 +#define ov8865_offset_y_l(v) ((v) & genmask(7, 0)) +#define ov8865_inc_x_odd_reg 0x3814 +#define ov8865_inc_x_odd(v) ((v) & genmask(4, 0)) +#define ov8865_inc_x_even_reg 0x3815 +#define ov8865_inc_x_even(v) ((v) & genmask(4, 0)) +#define ov8865_vsync_start_h_reg 0x3816 +#define ov8865_vsync_start_h(v) (((v) & genmask(15, 8)) >> 8) +#define ov8865_vsync_start_l_reg 0x3817 +#define ov8865_vsync_start_l(v) ((v) & genmask(7, 0)) +#define ov8865_vsync_end_h_reg 0x3818 +#define ov8865_vsync_end_h(v) (((v) & genmask(15, 8)) >> 8) +#define ov8865_vsync_end_l_reg 0x3819 +#define ov8865_vsync_end_l(v) ((v) & genmask(7, 0)) +#define ov8865_hsync_first_h_reg 0x381a +#define ov8865_hsync_first_h(v) (((v) & genmask(15, 8)) >> 8) +#define ov8865_hsync_first_l_reg 0x381b +#define ov8865_hsync_first_l(v) ((v) & genmask(7, 0)) + +#define ov8865_format1_reg 0x3820 +#define ov8865_format1_flip_vert_isp_en bit(2) +#define ov8865_format1_flip_vert_sensor_en bit(1) +#define ov8865_format2_reg 0x3821 +#define ov8865_format2_hsync_en bit(6) +#define ov8865_format2_fst_vbin_en bit(5) +#define ov8865_format2_fst_hbin_en bit(4) +#define ov8865_format2_isp_horz_var2_en bit(3) +#define ov8865_format2_flip_horz_isp_en bit(2) +#define ov8865_format2_flip_horz_sensor_en bit(1) +#define ov8865_format2_sync_hbin_en bit(0) + + +#define ov8865_inc_y_odd_reg 0x382a +#define ov8865_inc_y_odd(v) ((v) & genmask(4, 0)) +#define ov8865_inc_y_even_reg 0x382b +#define ov8865_inc_y_even(v) ((v) & genmask(4, 0)) + +#define ov8865_ablc_num_reg 0x3830 +#define ov8865_ablc_num(v) ((v) & genmask(4, 0)) + +#define ov8865_zline_num_reg 0x3836 +#define ov8865_zline_num(v) ((v) & genmask(4, 0)) + +#define ov8865_auto_size_ctrl_reg 0x3841 +#define ov8865_auto_size_ctrl_offset_y_reg bit(5) +#define ov8865_auto_size_ctrl_offset_x_reg bit(4) +#define ov8865_auto_size_ctrl_crop_end_y_reg bit(3) +#define ov8865_auto_size_ctrl_crop_end_x_reg bit(2) +#define ov8865_auto_size_ctrl_crop_start_y_reg bit(1) +#define ov8865_auto_size_ctrl_crop_start_x_reg bit(0) +#define ov8865_auto_size_x_offset_h_reg 0x3842 +#define ov8865_auto_size_x_offset_l_reg 0x3843 +#define ov8865_auto_size_y_offset_h_reg 0x3844 +#define ov8865_auto_size_y_offset_l_reg 0x3845 +#define ov8865_auto_size_boundaries_reg 0x3846 +#define ov8865_auto_size_boundaries_y(v) (((v) << 4) & genmask(7, 4)) +#define ov8865_auto_size_boundaries_x(v) ((v) & genmask(3, 0)) + +/* psram */ + +#define ov8865_psram_ctrl8_reg 0x3f08 + +/* black level */ + +#define ov8865_blc_ctrl0_reg 0x4000 +#define ov8865_blc_ctrl0_trig_range_en bit(7) +#define ov8865_blc_ctrl0_trig_format_en bit(6) +#define ov8865_blc_ctrl0_trig_gain_en bit(5) +#define ov8865_blc_ctrl0_trig_exposure_en bit(4) +#define ov8865_blc_ctrl0_trig_manual_en bit(3) +#define ov8865_blc_ctrl0_freeze_en bit(2) +#define ov8865_blc_ctrl0_always_en bit(1) +#define ov8865_blc_ctrl0_filter_en bit(0) +#define ov8865_blc_ctrl1_reg 0x4001 +#define ov8865_blc_ctrl1_dither_en bit(7) +#define ov8865_blc_ctrl1_zero_line_diff_en bit(6) +#define ov8865_blc_ctrl1_col_shift_256 (0 << 4) +#define ov8865_blc_ctrl1_col_shift_128 (1 << 4) +#define ov8865_blc_ctrl1_col_shift_64 (2 << 4) +#define ov8865_blc_ctrl1_col_shift_32 (3 << 4) +#define ov8865_blc_ctrl1_offset_limit_en bit(2) +#define ov8865_blc_ctrl1_column_cancel_en bit(1) +#define ov8865_blc_ctrl2_reg 0x4002 +#define ov8865_blc_ctrl3_reg 0x4003 +#define ov8865_blc_ctrl4_reg 0x4004 +#define ov8865_blc_ctrl5_reg 0x4005 +#define ov8865_blc_ctrl6_reg 0x4006 +#define ov8865_blc_ctrl7_reg 0x4007 +#define ov8865_blc_ctrl8_reg 0x4008 +#define ov8865_blc_ctrl9_reg 0x4009 +#define ov8865_blc_ctrla_reg 0x400a +#define ov8865_blc_ctrlb_reg 0x400b +#define ov8865_blc_ctrlc_reg 0x400c +#define ov8865_blc_ctrld_reg 0x400d +#define ov8865_blc_ctrld_offset_trigger(v) ((v) & genmask(7, 0)) + +#define ov8865_blc_ctrl1f_reg 0x401f +#define ov8865_blc_ctrl1f_rb_reverse bit(3) +#define ov8865_blc_ctrl1f_interpol_x_en bit(2) +#define ov8865_blc_ctrl1f_interpol_y_en bit(1) + +#define ov8865_blc_anchor_left_start_h_reg 0x4020 +#define ov8865_blc_anchor_left_start_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov8865_blc_anchor_left_start_l_reg 0x4021 +#define ov8865_blc_anchor_left_start_l(v) ((v) & genmask(7, 0)) +#define ov8865_blc_anchor_left_end_h_reg 0x4022 +#define ov8865_blc_anchor_left_end_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov8865_blc_anchor_left_end_l_reg 0x4023 +#define ov8865_blc_anchor_left_end_l(v) ((v) & genmask(7, 0)) +#define ov8865_blc_anchor_right_start_h_reg 0x4024 +#define ov8865_blc_anchor_right_start_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov8865_blc_anchor_right_start_l_reg 0x4025 +#define ov8865_blc_anchor_right_start_l(v) ((v) & genmask(7, 0)) +#define ov8865_blc_anchor_right_end_h_reg 0x4026 +#define ov8865_blc_anchor_right_end_h(v) (((v) & genmask(11, 8)) >> 8) +#define ov8865_blc_anchor_right_end_l_reg 0x4027 +#define ov8865_blc_anchor_right_end_l(v) ((v) & genmask(7, 0)) + +#define ov8865_blc_top_zline_start_reg 0x4028 +#define ov8865_blc_top_zline_start(v) ((v) & genmask(5, 0)) +#define ov8865_blc_top_zline_num_reg 0x4029 +#define ov8865_blc_top_zline_num(v) ((v) & genmask(4, 0)) +#define ov8865_blc_top_blkline_start_reg 0x402a +#define ov8865_blc_top_blkline_start(v) ((v) & genmask(5, 0)) +#define ov8865_blc_top_blkline_num_reg 0x402b +#define ov8865_blc_top_blkline_num(v) ((v) & genmask(4, 0)) +#define ov8865_blc_bot_zline_start_reg 0x402c +#define ov8865_blc_bot_zline_start(v) ((v) & genmask(5, 0)) +#define ov8865_blc_bot_zline_num_reg 0x402d +#define ov8865_blc_bot_zline_num(v) ((v) & genmask(4, 0)) +#define ov8865_blc_bot_blkline_start_reg 0x402e +#define ov8865_blc_bot_blkline_start(v) ((v) & genmask(5, 0)) +#define ov8865_blc_bot_blkline_num_reg 0x402f +#define ov8865_blc_bot_blkline_num(v) ((v) & genmask(4, 0)) + +#define ov8865_blc_offset_limit_reg 0x4034 +#define ov8865_blc_offset_limit(v) ((v) & genmask(7, 0)) + +/* vfifo */ + +#define ov8865_vfifo_read_start_h_reg 0x4600 +#define ov8865_vfifo_read_start_h(v) (((v) & genmask(15, 8)) >> 8) +#define ov8865_vfifo_read_start_l_reg 0x4601 +#define ov8865_vfifo_read_start_l(v) ((v) & genmask(7, 0)) + +/* mipi */ + +#define ov8865_mipi_ctrl0_reg 0x4800 +#define ov8865_mipi_ctrl1_reg 0x4801 +#define ov8865_mipi_ctrl2_reg 0x4802 +#define ov8865_mipi_ctrl3_reg 0x4803 +#define ov8865_mipi_ctrl4_reg 0x4804 +#define ov8865_mipi_ctrl5_reg 0x4805 +#define ov8865_mipi_ctrl6_reg 0x4806 +#define ov8865_mipi_ctrl7_reg 0x4807 +#define ov8865_mipi_ctrl8_reg 0x4808 + +#define ov8865_mipi_fcnt_max_h_reg 0x4810 +#define ov8865_mipi_fcnt_max_l_reg 0x4811 + +#define ov8865_mipi_ctrl13_reg 0x4813 +#define ov8865_mipi_ctrl14_reg 0x4814 +#define ov8865_mipi_ctrl15_reg 0x4815 +#define ov8865_mipi_embedded_dt_reg 0x4816 + +#define ov8865_mipi_hs_zero_min_h_reg 0x4818 +#define ov8865_mipi_hs_zero_min_l_reg 0x4819 +#define ov8865_mipi_hs_trail_min_h_reg 0x481a +#define ov8865_mipi_hs_trail_min_l_reg 0x481b +#define ov8865_mipi_clk_zero_min_h_reg 0x481c +#define ov8865_mipi_clk_zero_min_l_reg 0x481d +#define ov8865_mipi_clk_prepare_max_reg 0x481e +#define ov8865_mipi_clk_prepare_min_reg 0x481f +#define ov8865_mipi_clk_post_min_h_reg 0x4820 +#define ov8865_mipi_clk_post_min_l_reg 0x4821 +#define ov8865_mipi_clk_trail_min_h_reg 0x4822 +#define ov8865_mipi_clk_trail_min_l_reg 0x4823 +#define ov8865_mipi_lpx_p_min_h_reg 0x4824 +#define ov8865_mipi_lpx_p_min_l_reg 0x4825 +#define ov8865_mipi_hs_prepare_min_reg 0x4826 +#define ov8865_mipi_hs_prepare_max_reg 0x4827 +#define ov8865_mipi_hs_exit_min_h_reg 0x4828 +#define ov8865_mipi_hs_exit_min_l_reg 0x4829 +#define ov8865_mipi_ui_hs_zero_min_reg 0x482a +#define ov8865_mipi_ui_hs_trail_min_reg 0x482b +#define ov8865_mipi_ui_clk_zero_min_reg 0x482c +#define ov8865_mipi_ui_clk_prepare_reg 0x482d +#define ov8865_mipi_ui_clk_post_min_reg 0x482e +#define ov8865_mipi_ui_clk_trail_min_reg 0x482f +#define ov8865_mipi_ui_lpx_p_min_reg 0x4830 +#define ov8865_mipi_ui_hs_prepare_reg 0x4831 +#define ov8865_mipi_ui_hs_exit_min_reg 0x4832 +#define ov8865_mipi_pkt_start_size_reg 0x4833 + +#define ov8865_mipi_pclk_period_reg 0x4837 +#define ov8865_mipi_lp_gpio0_reg 0x4838 +#define ov8865_mipi_lp_gpio1_reg 0x4839 + +#define ov8865_mipi_ctrl3c_reg 0x483c +#define ov8865_mipi_lp_gpio4_reg 0x483d + +#define ov8865_mipi_ctrl4a_reg 0x484a +#define ov8865_mipi_ctrl4b_reg 0x484b +#define ov8865_mipi_ctrl4c_reg 0x484c +#define ov8865_mipi_lane_test_pattern_reg 0x484d +#define ov8865_mipi_frame_end_delay_reg 0x484e +#define ov8865_mipi_clock_test_pattern_reg 0x484f +#define ov8865_mipi_lane_sel01_reg 0x4850 +#define ov8865_mipi_lane_sel01_lane0(v) (((v) << 0) & genmask(2, 0)) +#define ov8865_mipi_lane_sel01_lane1(v) (((v) << 4) & genmask(6, 4)) +#define ov8865_mipi_lane_sel23_reg 0x4851 +#define ov8865_mipi_lane_sel23_lane2(v) (((v) << 0) & genmask(2, 0)) +#define ov8865_mipi_lane_sel23_lane3(v) (((v) << 4) & genmask(6, 4)) + +/* isp */ + +#define ov8865_isp_ctrl0_reg 0x5000 +#define ov8865_isp_ctrl0_lenc_en bit(7) +#define ov8865_isp_ctrl0_white_balance_en bit(4) +#define ov8865_isp_ctrl0_dpc_black_en bit(2) +#define ov8865_isp_ctrl0_dpc_white_en bit(1) +#define ov8865_isp_ctrl1_reg 0x5001 +#define ov8865_isp_ctrl1_blc_en bit(0) +#define ov8865_isp_ctrl2_reg 0x5002 +#define ov8865_isp_ctrl2_debug bit(3) +#define ov8865_isp_ctrl2_variopixel_en bit(2) +#define ov8865_isp_ctrl2_vsync_latch_en bit(0) +#define ov8865_isp_ctrl3_reg 0x5003 + +#define ov8865_isp_gain_red_h_reg 0x5018 +#define ov8865_isp_gain_red_h(v) (((v) & genmask(13, 6)) >> 6) +#define ov8865_isp_gain_red_l_reg 0x5019 +#define ov8865_isp_gain_red_l(v) ((v) & genmask(5, 0)) +#define ov8865_isp_gain_green_h_reg 0x501a +#define ov8865_isp_gain_green_h(v) (((v) & genmask(13, 6)) >> 6) +#define ov8865_isp_gain_green_l_reg 0x501b +#define ov8865_isp_gain_green_l(v) ((v) & genmask(5, 0)) +#define ov8865_isp_gain_blue_h_reg 0x501c +#define ov8865_isp_gain_blue_h(v) (((v) & genmask(13, 6)) >> 6) +#define ov8865_isp_gain_blue_l_reg 0x501d +#define ov8865_isp_gain_blue_l(v) ((v) & genmask(5, 0)) + +/* variopixel */ + +#define ov8865_vap_ctrl0_reg 0x5900 +#define ov8865_vap_ctrl1_reg 0x5901 +#define ov8865_vap_ctrl1_hsub_coef(v) ((((v) - 1) << 2) & \ + genmask(3, 2)) +#define ov8865_vap_ctrl1_vsub_coef(v) (((v) - 1) & genmask(1, 0)) + +/* pre-dsp */ + +#define ov8865_pre_ctrl0_reg 0x5e00 +#define ov8865_pre_ctrl0_pattern_en bit(7) +#define ov8865_pre_ctrl0_rolling_bar_en bit(6) +#define ov8865_pre_ctrl0_transparent_mode bit(5) +#define ov8865_pre_ctrl0_squares_bw_mode bit(4) +#define ov8865_pre_ctrl0_pattern_color_bars 0 +#define ov8865_pre_ctrl0_pattern_random_data 1 +#define ov8865_pre_ctrl0_pattern_color_squares 2 +#define ov8865_pre_ctrl0_pattern_black 3 + +/* macros */ + +#define ov8865_subdev_sensor(s) \ + container_of(s, struct ov8865_sensor, subdev) + +#define ov8865_ctrl_subdev(c) \ + (&container_of(c->handler, struct ov8865_sensor, ctrls.handler)->subdev) + +/* data structures */ + +struct ov8865_register_value { + u16 address; + u8 value; + unsigned int delay_ms; +}; + +/* + * pll1 clock tree: + * + * +-< extclk + * | + * +-+ pll_pre_div_half (0x30a [0]) + * | + * +-+ pll_pre_div (0x300 [2:0], special values: + * | 0: 1, 1: 1.5, 3: 2.5, 4: 3, 5: 4, 7: 8) + * +-+ pll_mul (0x301 [1:0], 0x302 [7:0]) + * | + * +-+ m_div (0x303 [3:0]) + * | | + * | +-> phy_sclk + * | | + * | +-+ mipi_div (0x304 [1:0], special values: 0: 4, 1: 5, 2: 6, 3: 8) + * | | + * | +-+ pclk_div (0x3020 [3]) + * | | + * | +-> pclk + * | + * +-+ sys_pre_div (0x305 [1:0], special values: 0: 3, 1: 4, 2: 5, 3: 6) + * | + * +-+ sys_div (0x306 [0]) + * | + * +-+ sys_sel (0x3032 [7], 0: pll1, 1: pll2) + * | + * +-+ sclk_sel (0x3033 [1], 0: sys_sel, 1: pll2 dac_clk) + * | + * +-+ sclk_pre_div (0x3106 [3:2], special values: + * | 0: 1, 1: 2, 2: 4, 3: 1) + * | + * +-+ sclk_div (0x3106 [7:4], special values: 0: 1) + * | + * +-> sclk + */ + +struct ov8865_pll1_config { + unsigned int pll_pre_div_half; + unsigned int pll_pre_div; + unsigned int pll_mul; + unsigned int m_div; + unsigned int mipi_div; + unsigned int pclk_div; + unsigned int sys_pre_div; + unsigned int sys_div; +}; + +/* + * pll2 clock tree: + * + * +-< extclk + * | + * +-+ pll_pre_div_half (0x312 [4]) + * | + * +-+ pll_pre_div (0x30b [2:0], special values: + * | 0: 1, 1: 1.5, 3: 2.5, 4: 3, 5: 4, 7: 8) + * +-+ pll_mul (0x30c [1:0], 0x30d [7:0]) + * | + * +-+ dac_div (0x312 [3:0]) + * | | + * | +-> dac_clk + * | + * +-+ sys_pre_div (0x30f [3:0]) + * | + * +-+ sys_div (0x30e [2:0], special values: + * | 0: 1, 1: 1.5, 3: 2.5, 4: 3, 5: 3.5, 6: 4, 7:5) + * | + * +-+ sys_sel (0x3032 [7], 0: pll1, 1: pll2) + * | + * +-+ sclk_sel (0x3033 [1], 0: sys_sel, 1: pll2 dac_clk) + * | + * +-+ sclk_pre_div (0x3106 [3:2], special values: + * | 0: 1, 1: 2, 2: 4, 3: 1) + * | + * +-+ sclk_div (0x3106 [7:4], special values: 0: 1) + * | + * +-> sclk + */ + +struct ov8865_pll2_config { + unsigned int pll_pre_div_half; + unsigned int pll_pre_div; + unsigned int pll_mul; + unsigned int dac_div; + unsigned int sys_pre_div; + unsigned int sys_div; +}; + +struct ov8865_sclk_config { + unsigned int sys_sel; + unsigned int sclk_sel; + unsigned int sclk_pre_div; + unsigned int sclk_div; +}; + +/* + * general formulas for (array-centered) mode calculation: + * - photo_array_width = 3296 + * - crop_start_x = (photo_array_width - output_size_x) / 2 + * - crop_end_x = crop_start_x + offset_x + output_size_x - 1 + * + * - photo_array_height = 2480 + * - crop_start_y = (photo_array_height - output_size_y) / 2 + * - crop_end_y = crop_start_y + offset_y + output_size_y - 1 + */ + +struct ov8865_mode { + unsigned int crop_start_x; + unsigned int offset_x; + unsigned int output_size_x; + unsigned int crop_end_x; + unsigned int hts; + + unsigned int crop_start_y; + unsigned int offset_y; + unsigned int output_size_y; + unsigned int crop_end_y; + unsigned int vts; + + /* with auto size, only output and total sizes need to be set. */ + bool size_auto; + unsigned int size_auto_boundary_x; + unsigned int size_auto_boundary_y; + + bool binning_x; + bool binning_y; + bool variopixel; + unsigned int variopixel_hsub_coef; + unsigned int variopixel_vsub_coef; + + /* bits for the format register, used for binning. */ + bool sync_hbin; + bool horz_var2; + + unsigned int inc_x_odd; + unsigned int inc_x_even; + unsigned int inc_y_odd; + unsigned int inc_y_even; + + unsigned int vfifo_read_start; + + unsigned int ablc_num; + unsigned int zline_num; + + unsigned int blc_top_zero_line_start; + unsigned int blc_top_zero_line_num; + unsigned int blc_top_black_line_start; + unsigned int blc_top_black_line_num; + + unsigned int blc_bottom_zero_line_start; + unsigned int blc_bottom_zero_line_num; + unsigned int blc_bottom_black_line_start; + unsigned int blc_bottom_black_line_num; + + u8 blc_col_shift_mask; + + unsigned int blc_anchor_left_start; + unsigned int blc_anchor_left_end; + unsigned int blc_anchor_right_start; + unsigned int blc_anchor_right_end; + + struct v4l2_fract frame_interval; + + const struct ov8865_pll1_config *pll1_config; + const struct ov8865_pll2_config *pll2_config; + const struct ov8865_sclk_config *sclk_config; + + const struct ov8865_register_value *register_values; + unsigned int register_values_count; +}; + +struct ov8865_state { + const struct ov8865_mode *mode; + u32 mbus_code; + + bool streaming; +}; + +struct ov8865_ctrls { + struct v4l2_ctrl *link_freq; + struct v4l2_ctrl *pixel_rate; + + struct v4l2_ctrl_handler handler; +}; + +struct ov8865_sensor { + struct device *dev; + struct i2c_client *i2c_client; + struct gpio_desc *reset; + struct gpio_desc *powerdown; + struct regulator *avdd; + struct regulator *dvdd; + struct regulator *dovdd; + struct clk *extclk; + + struct v4l2_fwnode_endpoint endpoint; + struct v4l2_subdev subdev; + struct media_pad pad; + + struct mutex mutex; + + struct ov8865_state state; + struct ov8865_ctrls ctrls; +}; + +/* static definitions */ + +/* + * extclk = 24 mhz + * phy_sclk = 720 mhz + * mipi_pclk = 90 mhz + */ +static const struct ov8865_pll1_config ov8865_pll1_config_native = { + .pll_pre_div_half = 1, + .pll_pre_div = 0, + .pll_mul = 30, + .m_div = 1, + .mipi_div = 3, + .pclk_div = 1, + .sys_pre_div = 1, + .sys_div = 2, +}; + +/* + * extclk = 24 mhz + * dac_clk = 360 mhz + * sclk = 144 mhz + */ + +static const struct ov8865_pll2_config ov8865_pll2_config_native = { + .pll_pre_div_half = 1, + .pll_pre_div = 0, + .pll_mul = 30, + .dac_div = 2, + .sys_pre_div = 5, + .sys_div = 0, +}; + +/* + * extclk = 24 mhz + * dac_clk = 360 mhz + * sclk = 80 mhz + */ + +static const struct ov8865_pll2_config ov8865_pll2_config_binning = { + .pll_pre_div_half = 1, + .pll_pre_div = 0, + .pll_mul = 30, + .dac_div = 2, + .sys_pre_div = 10, + .sys_div = 0, +}; + +static const struct ov8865_sclk_config ov8865_sclk_config_native = { + .sys_sel = 1, + .sclk_sel = 0, + .sclk_pre_div = 0, + .sclk_div = 0, +}; + +static const struct ov8865_register_value ov8865_register_values_native[] = { + /* sensor */ + + { 0x3700, 0x48 }, + { 0x3701, 0x18 }, + { 0x3702, 0x50 }, + { 0x3703, 0x32 }, + { 0x3704, 0x28 }, + { 0x3706, 0x70 }, + { 0x3707, 0x08 }, + { 0x3708, 0x48 }, + { 0x3709, 0x80 }, + { 0x370a, 0x01 }, + { 0x370b, 0x70 }, + { 0x370c, 0x07 }, + { 0x3718, 0x14 }, + { 0x3712, 0x44 }, + { 0x371e, 0x31 }, + { 0x371f, 0x7f }, + { 0x3720, 0x0a }, + { 0x3721, 0x0a }, + { 0x3724, 0x04 }, + { 0x3725, 0x04 }, + { 0x3726, 0x0c }, + { 0x3728, 0x0a }, + { 0x3729, 0x03 }, + { 0x372a, 0x06 }, + { 0x372b, 0xa6 }, + { 0x372c, 0xa6 }, + { 0x372d, 0xa6 }, + { 0x372e, 0x0c }, + { 0x372f, 0x20 }, + { 0x3730, 0x02 }, + { 0x3731, 0x0c }, + { 0x3732, 0x28 }, + { 0x3736, 0x30 }, + { 0x373a, 0x04 }, + { 0x373b, 0x18 }, + { 0x373c, 0x14 }, + { 0x373e, 0x06 }, + { 0x375a, 0x0c }, + { 0x375b, 0x26 }, + { 0x375d, 0x04 }, + { 0x375f, 0x28 }, + { 0x3767, 0x1e }, + { 0x3772, 0x46 }, + { 0x3773, 0x04 }, + { 0x3774, 0x2c }, + { 0x3775, 0x13 }, + { 0x3776, 0x10 }, + { 0x37a0, 0x88 }, + { 0x37a1, 0x7a }, + { 0x37a2, 0x7a }, + { 0x37a3, 0x02 }, + { 0x37a5, 0x09 }, + { 0x37a7, 0x88 }, + { 0x37a8, 0xb0 }, + { 0x37a9, 0xb0 }, + { 0x37aa, 0x88 }, + { 0x37ab, 0x5c }, + { 0x37ac, 0x5c }, + { 0x37ad, 0x55 }, + { 0x37ae, 0x19 }, + { 0x37af, 0x19 }, + { 0x37b3, 0x84 }, + { 0x37b4, 0x84 }, + { 0x37b5, 0x66 }, + + /* psram */ + + { ov8865_psram_ctrl8_reg, 0x16 }, + + /* adc sync */ + + { 0x4500, 0x68 }, +}; + +static const struct ov8865_register_value ov8865_register_values_binning[] = { + /* sensor */ + + { 0x3700, 0x24 }, + { 0x3701, 0x0c }, + { 0x3702, 0x28 }, + { 0x3703, 0x19 }, + { 0x3704, 0x14 }, + { 0x3706, 0x38 }, + { 0x3707, 0x04 }, + { 0x3708, 0x24 }, + { 0x3709, 0x40 }, + { 0x370a, 0x00 }, + { 0x370b, 0xb8 }, + { 0x370c, 0x04 }, + { 0x3718, 0x12 }, + { 0x3712, 0x42 }, + { 0x371e, 0x19 }, + { 0x371f, 0x40 }, + { 0x3720, 0x05 }, + { 0x3721, 0x05 }, + { 0x3724, 0x02 }, + { 0x3725, 0x02 }, + { 0x3726, 0x06 }, + { 0x3728, 0x05 }, + { 0x3729, 0x02 }, + { 0x372a, 0x03 }, + { 0x372b, 0x53 }, + { 0x372c, 0xa3 }, + { 0x372d, 0x53 }, + { 0x372e, 0x06 }, + { 0x372f, 0x10 }, + { 0x3730, 0x01 }, + { 0x3731, 0x06 }, + { 0x3732, 0x14 }, + { 0x3736, 0x20 }, + { 0x373a, 0x02 }, + { 0x373b, 0x0c }, + { 0x373c, 0x0a }, + { 0x373e, 0x03 }, + { 0x375a, 0x06 }, + { 0x375b, 0x13 }, + { 0x375d, 0x02 }, + { 0x375f, 0x14 }, + { 0x3767, 0x1c }, + { 0x3772, 0x23 }, + { 0x3773, 0x02 }, + { 0x3774, 0x16 }, + { 0x3775, 0x12 }, + { 0x3776, 0x08 }, + { 0x37a0, 0x44 }, + { 0x37a1, 0x3d }, + { 0x37a2, 0x3d }, + { 0x37a3, 0x01 }, + { 0x37a5, 0x08 }, + { 0x37a7, 0x44 }, + { 0x37a8, 0x58 }, + { 0x37a9, 0x58 }, + { 0x37aa, 0x44 }, + { 0x37ab, 0x2e }, + { 0x37ac, 0x2e }, + { 0x37ad, 0x33 }, + { 0x37ae, 0x0d }, + { 0x37af, 0x0d }, + { 0x37b3, 0x42 }, + { 0x37b4, 0x42 }, + { 0x37b5, 0x33 }, + + /* psram */ + + { ov8865_psram_ctrl8_reg, 0x0b }, + + /* adc sync */ + + { 0x4500, 0x40 }, +}; + +static const struct ov8865_mode ov8865_modes[] = { + /* 3264x2448 */ + { + /* horizontal */ + .output_size_x = 3264, + .hts = 1944, + + /* vertical */ + .output_size_y = 2448, + .vts = 2470, + + .size_auto = true, + .size_auto_boundary_x = 8, + .size_auto_boundary_y = 4, + + /* subsample increase */ + .inc_x_odd = 1, + .inc_x_even = 1, + .inc_y_odd = 1, + .inc_y_even = 1, + + /* vfifo */ + .vfifo_read_start = 16, + + .ablc_num = 4, + .zline_num = 1, + + /* black level */ + + .blc_top_zero_line_start = 0, + .blc_top_zero_line_num = 2, + .blc_top_black_line_start = 4, + .blc_top_black_line_num = 4, + + .blc_bottom_zero_line_start = 2, + .blc_bottom_zero_line_num = 2, + .blc_bottom_black_line_start = 8, + .blc_bottom_black_line_num = 2, + + .blc_anchor_left_start = 576, + .blc_anchor_left_end = 831, + .blc_anchor_right_start = 1984, + .blc_anchor_right_end = 2239, + + /* frame interval */ + .frame_interval = { 1, 30 }, + + /* pll */ + .pll1_config = &ov8865_pll1_config_native, + .pll2_config = &ov8865_pll2_config_native, + .sclk_config = &ov8865_sclk_config_native, + + /* registers */ + .register_values = ov8865_register_values_native, + .register_values_count = + array_size(ov8865_register_values_native), + }, + /* 3264x1836 */ + { + /* horizontal */ + .output_size_x = 3264, + .hts = 2582, + + /* vertical */ + .output_size_y = 1836, + .vts = 2002, + + .size_auto = true, + .size_auto_boundary_x = 8, + .size_auto_boundary_y = 4, + + /* subsample increase */ + .inc_x_odd = 1, + .inc_x_even = 1, + .inc_y_odd = 1, + .inc_y_even = 1, + + /* vfifo */ + .vfifo_read_start = 16, + + .ablc_num = 4, + .zline_num = 1, + + /* black level */ + + .blc_top_zero_line_start = 0, + .blc_top_zero_line_num = 2, + .blc_top_black_line_start = 4, + .blc_top_black_line_num = 4, + + .blc_bottom_zero_line_start = 2, + .blc_bottom_zero_line_num = 2, + .blc_bottom_black_line_start = 8, + .blc_bottom_black_line_num = 2, + + .blc_anchor_left_start = 576, + .blc_anchor_left_end = 831, + .blc_anchor_right_start = 1984, + .blc_anchor_right_end = 2239, + + /* frame interval */ + .frame_interval = { 1, 30 }, + + /* pll */ + .pll1_config = &ov8865_pll1_config_native, + .pll2_config = &ov8865_pll2_config_native, + .sclk_config = &ov8865_sclk_config_native, + + /* registers */ + .register_values = ov8865_register_values_native, + .register_values_count = + array_size(ov8865_register_values_native), + }, + /* 1632x1224 */ + { + /* horizontal */ + .output_size_x = 1632, + .hts = 1923, + + /* vertical */ + .output_size_y = 1224, + .vts = 1248, + + .size_auto = true, + .size_auto_boundary_x = 8, + .size_auto_boundary_y = 8, + + /* subsample increase */ + .inc_x_odd = 3, + .inc_x_even = 1, + .inc_y_odd = 3, + .inc_y_even = 1, + + /* binning */ + .binning_y = true, + .sync_hbin = true, + + /* vfifo */ + .vfifo_read_start = 116, + + .ablc_num = 8, + .zline_num = 2, + + /* black level */ + + .blc_top_zero_line_start = 0, + .blc_top_zero_line_num = 2, + .blc_top_black_line_start = 4, + .blc_top_black_line_num = 4, + + .blc_bottom_zero_line_start = 2, + .blc_bottom_zero_line_num = 2, + .blc_bottom_black_line_start = 8, + .blc_bottom_black_line_num = 2, + + .blc_anchor_left_start = 288, + .blc_anchor_left_end = 415, + .blc_anchor_right_start = 992, + .blc_anchor_right_end = 1119, + + /* frame interval */ + .frame_interval = { 1, 30 }, + + /* pll */ + .pll1_config = &ov8865_pll1_config_native, + .pll2_config = &ov8865_pll2_config_binning, + .sclk_config = &ov8865_sclk_config_native, + + /* registers */ + .register_values = ov8865_register_values_binning, + .register_values_count = + array_size(ov8865_register_values_binning), + }, + /* 800x600 (svga) */ + { + /* horizontal */ + .output_size_x = 800, + .hts = 1250, + + /* vertical */ + .output_size_y = 600, + .vts = 640, + + .size_auto = true, + .size_auto_boundary_x = 8, + .size_auto_boundary_y = 8, + + /* subsample increase */ + .inc_x_odd = 3, + .inc_x_even = 1, + .inc_y_odd = 5, + .inc_y_even = 3, + + /* binning */ + .binning_y = true, + .variopixel = true, + .variopixel_hsub_coef = 2, + .variopixel_vsub_coef = 1, + .sync_hbin = true, + .horz_var2 = true, + + /* vfifo */ + .vfifo_read_start = 80, + + .ablc_num = 8, + .zline_num = 2, + + /* black level */ + + .blc_top_zero_line_start = 0, + .blc_top_zero_line_num = 2, + .blc_top_black_line_start = 2, + .blc_top_black_line_num = 2, + + .blc_bottom_zero_line_start = 0, + .blc_bottom_zero_line_num = 0, + .blc_bottom_black_line_start = 4, + .blc_bottom_black_line_num = 2, + + .blc_col_shift_mask = ov8865_blc_ctrl1_col_shift_128, + + .blc_anchor_left_start = 288, + .blc_anchor_left_end = 415, + .blc_anchor_right_start = 992, + .blc_anchor_right_end = 1119, + + /* frame interval */ + .frame_interval = { 1, 90 }, + + /* pll */ + .pll1_config = &ov8865_pll1_config_native, + .pll2_config = &ov8865_pll2_config_binning, + .sclk_config = &ov8865_sclk_config_native, + + /* registers */ + .register_values = ov8865_register_values_binning, + .register_values_count = + array_size(ov8865_register_values_binning), + }, +}; + +static const u32 ov8865_mbus_codes[] = { + media_bus_fmt_sbggr10_1x10, +}; + +static const struct ov8865_register_value ov8865_init_sequence[] = { + /* analog */ + + { 0x3604, 0x04 }, + { 0x3602, 0x30 }, + { 0x3605, 0x00 }, + { 0x3607, 0x20 }, + { 0x3608, 0x11 }, + { 0x3609, 0x68 }, + { 0x360a, 0x40 }, + { 0x360c, 0xdd }, + { 0x360e, 0x0c }, + { 0x3610, 0x07 }, + { 0x3612, 0x86 }, + { 0x3613, 0x58 }, + { 0x3614, 0x28 }, + { 0x3617, 0x40 }, + { 0x3618, 0x5a }, + { 0x3619, 0x9b }, + { 0x361c, 0x00 }, + { 0x361d, 0x60 }, + { 0x3631, 0x60 }, + { 0x3633, 0x10 }, + { 0x3634, 0x10 }, + { 0x3635, 0x10 }, + { 0x3636, 0x10 }, + { 0x3638, 0xff }, + { 0x3641, 0x55 }, + { 0x3646, 0x86 }, + { 0x3647, 0x27 }, + { 0x364a, 0x1b }, + + /* sensor */ + + { 0x3700, 0x24 }, + { 0x3701, 0x0c }, + { 0x3702, 0x28 }, + { 0x3703, 0x19 }, + { 0x3704, 0x14 }, + { 0x3705, 0x00 }, + { 0x3706, 0x38 }, + { 0x3707, 0x04 }, + { 0x3708, 0x24 }, + { 0x3709, 0x40 }, + { 0x370a, 0x00 }, + { 0x370b, 0xb8 }, + { 0x370c, 0x04 }, + { 0x3718, 0x12 }, + { 0x3719, 0x31 }, + { 0x3712, 0x42 }, + { 0x3714, 0x12 }, + { 0x371e, 0x19 }, + { 0x371f, 0x40 }, + { 0x3720, 0x05 }, + { 0x3721, 0x05 }, + { 0x3724, 0x02 }, + { 0x3725, 0x02 }, + { 0x3726, 0x06 }, + { 0x3728, 0x05 }, + { 0x3729, 0x02 }, + { 0x372a, 0x03 }, + { 0x372b, 0x53 }, + { 0x372c, 0xa3 }, + { 0x372d, 0x53 }, + { 0x372e, 0x06 }, + { 0x372f, 0x10 }, + { 0x3730, 0x01 }, + { 0x3731, 0x06 }, + { 0x3732, 0x14 }, + { 0x3733, 0x10 }, + { 0x3734, 0x40 }, + { 0x3736, 0x20 }, + { 0x373a, 0x02 }, + { 0x373b, 0x0c }, + { 0x373c, 0x0a }, + { 0x373e, 0x03 }, + { 0x3755, 0x40 }, + { 0x3758, 0x00 }, + { 0x3759, 0x4c }, + { 0x375a, 0x06 }, + { 0x375b, 0x13 }, + { 0x375c, 0x40 }, + { 0x375d, 0x02 }, + { 0x375e, 0x00 }, + { 0x375f, 0x14 }, + { 0x3767, 0x1c }, + { 0x3768, 0x04 }, + { 0x3769, 0x20 }, + { 0x376c, 0xc0 }, + { 0x376d, 0xc0 }, + { 0x376a, 0x08 }, + { 0x3761, 0x00 }, + { 0x3762, 0x00 }, + { 0x3763, 0x00 }, + { 0x3766, 0xff }, + { 0x376b, 0x42 }, + { 0x3772, 0x23 }, + { 0x3773, 0x02 }, + { 0x3774, 0x16 }, + { 0x3775, 0x12 }, + { 0x3776, 0x08 }, + { 0x37a0, 0x44 }, + { 0x37a1, 0x3d }, + { 0x37a2, 0x3d }, + { 0x37a3, 0x01 }, + { 0x37a4, 0x00 }, + { 0x37a5, 0x08 }, + { 0x37a6, 0x00 }, + { 0x37a7, 0x44 }, + { 0x37a8, 0x58 }, + { 0x37a9, 0x58 }, + { 0x3760, 0x00 }, + { 0x376f, 0x01 }, + { 0x37aa, 0x44 }, + { 0x37ab, 0x2e }, + { 0x37ac, 0x2e }, + { 0x37ad, 0x33 }, + { 0x37ae, 0x0d }, + { 0x37af, 0x0d }, + { 0x37b0, 0x00 }, + { 0x37b1, 0x00 }, + { 0x37b2, 0x00 }, + { 0x37b3, 0x42 }, + { 0x37b4, 0x42 }, + { 0x37b5, 0x33 }, + { 0x37b6, 0x00 }, + { 0x37b7, 0x00 }, + { 0x37b8, 0x00 }, + { 0x37b9, 0xff }, + + /* adc sync */ + + { 0x4503, 0x10 }, +}; + +static const s64 ov8865_link_freq_menu[] = { + 360000000, +}; + +static const char *const ov8865_test_pattern_menu[] = { + "disabled", + "random data", + "color bars", + "color bars with rolling bar", + "color squares", + "color squares with rolling bar" +}; + +static const u8 ov8865_test_pattern_bits[] = { + 0, + ov8865_pre_ctrl0_pattern_en | ov8865_pre_ctrl0_pattern_random_data, + ov8865_pre_ctrl0_pattern_en | ov8865_pre_ctrl0_pattern_color_bars, + ov8865_pre_ctrl0_pattern_en | ov8865_pre_ctrl0_rolling_bar_en | + ov8865_pre_ctrl0_pattern_color_bars, + ov8865_pre_ctrl0_pattern_en | ov8865_pre_ctrl0_pattern_color_squares, + ov8865_pre_ctrl0_pattern_en | ov8865_pre_ctrl0_rolling_bar_en | + ov8865_pre_ctrl0_pattern_color_squares, +}; + +/* input/output */ + +static int ov8865_read(struct ov8865_sensor *sensor, u16 address, u8 *value) +{ + unsigned char data[2] = { address >> 8, address & 0xff }; + struct i2c_client *client = sensor->i2c_client; + int ret; + + ret = i2c_master_send(client, data, sizeof(data)); + if (ret < 0) { + dev_dbg(&client->dev, "i2c send error at address %#04x ", + address); + return ret; + } + + ret = i2c_master_recv(client, value, 1); + if (ret < 0) { + dev_dbg(&client->dev, "i2c recv error at address %#04x ", + address); + return ret; + } + + return 0; +} + +static int ov8865_write(struct ov8865_sensor *sensor, u16 address, u8 value) +{ + unsigned char data[3] = { address >> 8, address & 0xff, value }; + struct i2c_client *client = sensor->i2c_client; + int ret; + + ret = i2c_master_send(client, data, sizeof(data)); + if (ret < 0) { + dev_dbg(&client->dev, "i2c send error at address %#04x ", + address); + return ret; + } + + return 0; +} + +static int ov8865_write_sequence(struct ov8865_sensor *sensor, + const struct ov8865_register_value *sequence, + unsigned int sequence_count) +{ + unsigned int i; + int ret = 0; + + for (i = 0; i < sequence_count; i++) { + ret = ov8865_write(sensor, sequence[i].address, + sequence[i].value); + if (ret) + break; + + if (sequence[i].delay_ms) + msleep(sequence[i].delay_ms); + } + + return ret; +} + +static int ov8865_update_bits(struct ov8865_sensor *sensor, u16 address, + u8 mask, u8 bits) +{ + u8 value = 0; + int ret; + + ret = ov8865_read(sensor, address, &value); + if (ret) + return ret; + + value &= ~mask; + value |= bits; + + return ov8865_write(sensor, address, value); +} + +/* sensor */ + +static int ov8865_sw_reset(struct ov8865_sensor *sensor) +{ + return ov8865_write(sensor, ov8865_sw_reset_reg, ov8865_sw_reset_reset); +} + +static int ov8865_sw_standby(struct ov8865_sensor *sensor, int standby) +{ + u8 value = 0; + + if (!standby) + value = ov8865_sw_standby_stream_on; + + return ov8865_write(sensor, ov8865_sw_standby_reg, value); +} + +static int ov8865_chip_id_check(struct ov8865_sensor *sensor) +{ + u16 regs[] = { ov8865_chip_id_hh_reg, ov8865_chip_id_h_reg, + ov8865_chip_id_l_reg }; + u8 values[] = { ov8865_chip_id_hh_value, ov8865_chip_id_h_value, + ov8865_chip_id_l_value }; + unsigned int i; + u8 value; + int ret; + + for (i = 0; i < array_size(regs); i++) { + ret = ov8865_read(sensor, regs[i], &value); + if (ret < 0) + return ret; + + if (value != values[i]) { + dev_err(sensor->dev, + "chip id value mismatch: %#x instead of %#x ", + value, values[i]); + return -einval; + } + } + + return 0; +} + +static int ov8865_charge_pump_configure(struct ov8865_sensor *sensor) +{ + return ov8865_write(sensor, ov8865_pump_clk_div_reg, + ov8865_pump_clk_div_pump_p(1)); +} + +static int ov8865_mipi_configure(struct ov8865_sensor *sensor) +{ + struct v4l2_fwnode_bus_mipi_csi2 *bus_mipi_csi2 = + &sensor->endpoint.bus.mipi_csi2; + unsigned int lanes_count = bus_mipi_csi2->num_data_lanes; + int ret; + + ret = ov8865_write(sensor, ov8865_mipi_sc_ctrl0_reg, + ov8865_mipi_sc_ctrl0_lanes(lanes_count) | + ov8865_mipi_sc_ctrl0_mipi_en | + ov8865_mipi_sc_ctrl0_unknown); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_mipi_sc_ctrl2_reg, + ov8865_mipi_sc_ctrl2_pd_mipi_rst_sync); + if (ret) + return ret; + + if (lanes_count >= 2) { + ret = ov8865_write(sensor, ov8865_mipi_lane_sel01_reg, + ov8865_mipi_lane_sel01_lane0(0) | + ov8865_mipi_lane_sel01_lane1(1)); + if (ret) + return ret; + } + + if (lanes_count >= 4) { + ret = ov8865_write(sensor, ov8865_mipi_lane_sel23_reg, + ov8865_mipi_lane_sel23_lane2(2) | + ov8865_mipi_lane_sel23_lane3(3)); + if (ret) + return ret; + } + + ret = ov8865_update_bits(sensor, ov8865_clk_sel1_reg, + ov8865_clk_sel1_mipi_eof, + ov8865_clk_sel1_mipi_eof); + if (ret) + return ret; + + /* + * this value might need to change depending on pclk rate, + * but it's unclear how. this value seems to generally work + * while the default value was found to cause transmission errors. + */ + return ov8865_write(sensor, ov8865_mipi_pclk_period_reg, 0x16); +} + +static int ov8865_black_level_configure(struct ov8865_sensor *sensor) +{ + int ret; + + /* trigger blc on relevant events and enable filter. */ + ret = ov8865_write(sensor, ov8865_blc_ctrl0_reg, + ov8865_blc_ctrl0_trig_range_en | + ov8865_blc_ctrl0_trig_format_en | + ov8865_blc_ctrl0_trig_gain_en | + ov8865_blc_ctrl0_trig_exposure_en | + ov8865_blc_ctrl0_filter_en); + if (ret) + return ret; + + /* lower blc offset trigger threshold. */ + ret = ov8865_write(sensor, ov8865_blc_ctrld_reg, + ov8865_blc_ctrld_offset_trigger(16)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_blc_ctrl1f_reg, 0); + if (ret) + return ret; + + /* increase blc offset maximum limit. */ + return ov8865_write(sensor, ov8865_blc_offset_limit_reg, + ov8865_blc_offset_limit(63)); +} + +static int ov8865_isp_configure(struct ov8865_sensor *sensor) +{ + int ret; + + /* disable lens correction. */ + ret = ov8865_write(sensor, ov8865_isp_ctrl0_reg, + ov8865_isp_ctrl0_white_balance_en | + ov8865_isp_ctrl0_dpc_black_en | + ov8865_isp_ctrl0_dpc_white_en); + if (ret) + return ret; + + return ov8865_write(sensor, ov8865_isp_ctrl1_reg, + ov8865_isp_ctrl1_blc_en); +} + +static unsigned long ov8865_mode_pll1_rate(struct ov8865_sensor *sensor, + const struct ov8865_mode *mode) +{ + const struct ov8865_pll1_config *config = mode->pll1_config; + unsigned long extclk_rate; + unsigned long pll1_rate; + + extclk_rate = clk_get_rate(sensor->extclk); + pll1_rate = extclk_rate * config->pll_mul / config->pll_pre_div_half; + + switch (config->pll_pre_div) { + case 0: + break; + case 1: + pll1_rate *= 3; + pll1_rate /= 2; + break; + case 3: + pll1_rate *= 5; + pll1_rate /= 2; + break; + case 4: + pll1_rate /= 3; + break; + case 5: + pll1_rate /= 4; + break; + case 7: + pll1_rate /= 8; + break; + default: + pll1_rate /= config->pll_pre_div; + break; + } + + return pll1_rate; +} + +static int ov8865_mode_pll1_configure(struct ov8865_sensor *sensor, + const struct ov8865_mode *mode, + u32 mbus_code) +{ + const struct ov8865_pll1_config *config = mode->pll1_config; + u8 value; + int ret; + + switch (mbus_code) { + case media_bus_fmt_sbggr10_1x10: + value = ov8865_mipi_bit_sel(10); + break; + default: + return -einval; + } + + ret = ov8865_write(sensor, ov8865_mipi_bit_sel_reg, value); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrla_reg, + ov8865_pll_ctrla_pre_div_half(config->pll_pre_div_half)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrl0_reg, + ov8865_pll_ctrl0_pre_div(config->pll_pre_div)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrl1_reg, + ov8865_pll_ctrl1_mul_h(config->pll_mul)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrl2_reg, + ov8865_pll_ctrl2_mul_l(config->pll_mul)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrl3_reg, + ov8865_pll_ctrl3_m_div(config->m_div)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrl4_reg, + ov8865_pll_ctrl4_mipi_div(config->mipi_div)); + if (ret) + return ret; + + ret = ov8865_update_bits(sensor, ov8865_pclk_sel_reg, + ov8865_pclk_sel_pclk_div_mask, + ov8865_pclk_sel_pclk_div(config->pclk_div)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrl5_reg, + ov8865_pll_ctrl5_sys_pre_div(config->sys_pre_div)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrl6_reg, + ov8865_pll_ctrl6_sys_div(config->sys_div)); + if (ret) + return ret; + + return ov8865_update_bits(sensor, ov8865_pll_ctrl1e_reg, + ov8865_pll_ctrl1e_pll1_no_lat, + ov8865_pll_ctrl1e_pll1_no_lat); +} + +static int ov8865_mode_pll2_configure(struct ov8865_sensor *sensor, + const struct ov8865_mode *mode) +{ + const struct ov8865_pll2_config *config = mode->pll2_config; + int ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrl12_reg, + ov8865_pll_ctrl12_pre_div_half(config->pll_pre_div_half) | + ov8865_pll_ctrl12_dac_div(config->dac_div)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrlb_reg, + ov8865_pll_ctrlb_pre_div(config->pll_pre_div)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrlc_reg, + ov8865_pll_ctrlc_mul_h(config->pll_mul)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrld_reg, + ov8865_pll_ctrld_mul_l(config->pll_mul)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_pll_ctrlf_reg, + ov8865_pll_ctrlf_sys_pre_div(config->sys_pre_div)); + if (ret) + return ret; + + return ov8865_write(sensor, ov8865_pll_ctrle_reg, + ov8865_pll_ctrle_sys_div(config->sys_div)); +} + +static int ov8865_mode_sclk_configure(struct ov8865_sensor *sensor, + const struct ov8865_mode *mode) +{ + const struct ov8865_sclk_config *config = mode->sclk_config; + int ret; + + ret = ov8865_write(sensor, ov8865_clk_sel0_reg, + ov8865_clk_sel0_pll1_sys_sel(config->sys_sel)); + if (ret) + return ret; + + ret = ov8865_update_bits(sensor, ov8865_clk_sel1_reg, + ov8865_clk_sel1_pll_sclk_sel_mask, + ov8865_clk_sel1_pll_sclk_sel(config->sclk_sel)); + if (ret) + return ret; + + return ov8865_write(sensor, ov8865_sclk_ctrl_reg, + ov8865_sclk_ctrl_unknown | + ov8865_sclk_ctrl_sclk_div(config->sclk_div) | + ov8865_sclk_ctrl_sclk_pre_div(config->sclk_pre_div)); +} + +static int ov8865_mode_binning_configure(struct ov8865_sensor *sensor, + const struct ov8865_mode *mode) +{ + unsigned int variopixel_hsub_coef, variopixel_vsub_coef; + u8 value; + int ret; + + ret = ov8865_write(sensor, ov8865_format1_reg, 0); + if (ret) + return ret; + + value = ov8865_format2_hsync_en; + + if (mode->binning_x) + value |= ov8865_format2_fst_hbin_en; + + if (mode->binning_y) + value |= ov8865_format2_fst_vbin_en; + + if (mode->sync_hbin) + value |= ov8865_format2_sync_hbin_en; + + if (mode->horz_var2) + value |= ov8865_format2_isp_horz_var2_en; + + ret = ov8865_write(sensor, ov8865_format2_reg, value); + if (ret) + return ret; + + ret = ov8865_update_bits(sensor, ov8865_isp_ctrl2_reg, + ov8865_isp_ctrl2_variopixel_en, + mode->variopixel ? + ov8865_isp_ctrl2_variopixel_en : 0); + if (ret) + return ret; + + if (mode->variopixel) { + /* variopixel coefs needs to be > 1. */ + variopixel_hsub_coef = mode->variopixel_hsub_coef; + variopixel_vsub_coef = mode->variopixel_vsub_coef; + } else { + variopixel_hsub_coef = 1; + variopixel_vsub_coef = 1; + } + + ret = ov8865_write(sensor, ov8865_vap_ctrl1_reg, + ov8865_vap_ctrl1_hsub_coef(variopixel_hsub_coef) | + ov8865_vap_ctrl1_vsub_coef(variopixel_vsub_coef)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_inc_x_odd_reg, + ov8865_inc_x_odd(mode->inc_x_odd)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_inc_x_even_reg, + ov8865_inc_x_even(mode->inc_x_even)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_inc_y_odd_reg, + ov8865_inc_y_odd(mode->inc_y_odd)); + if (ret) + return ret; + + return ov8865_write(sensor, ov8865_inc_y_even_reg, + ov8865_inc_y_even(mode->inc_y_even)); +} + +static int ov8865_mode_black_level_configure(struct ov8865_sensor *sensor, + const struct ov8865_mode *mode) +{ + int ret; + + /* note that a zero value for blc_col_shift_mask is the default 256. */ + ret = ov8865_write(sensor, ov8865_blc_ctrl1_reg, + mode->blc_col_shift_mask | + ov8865_blc_ctrl1_offset_limit_en); + if (ret) + return ret; + + /* blc top zero line */ + + ret = ov8865_write(sensor, ov8865_blc_top_zline_start_reg, + ov8865_blc_top_zline_start(mode->blc_top_zero_line_start)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_blc_top_zline_num_reg, + ov8865_blc_top_zline_num(mode->blc_top_zero_line_num)); + if (ret) + return ret; + + /* blc top black line */ + + ret = ov8865_write(sensor, ov8865_blc_top_blkline_start_reg, + ov8865_blc_top_blkline_start(mode->blc_top_black_line_start)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_blc_top_blkline_num_reg, + ov8865_blc_top_blkline_num(mode->blc_top_black_line_num)); + if (ret) + return ret; + + /* blc bottom zero line */ + + ret = ov8865_write(sensor, ov8865_blc_bot_zline_start_reg, + ov8865_blc_bot_zline_start(mode->blc_bottom_zero_line_start)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_blc_bot_zline_num_reg, + ov8865_blc_bot_zline_num(mode->blc_bottom_zero_line_num)); + if (ret) + return ret; + + /* blc bottom black line */ + + ret = ov8865_write(sensor, ov8865_blc_bot_blkline_start_reg, + ov8865_blc_bot_blkline_start(mode->blc_bottom_black_line_start)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_blc_bot_blkline_num_reg, + ov8865_blc_bot_blkline_num(mode->blc_bottom_black_line_num)); + if (ret) + return ret; + + /* blc anchor */ + + ret = ov8865_write(sensor, ov8865_blc_anchor_left_start_h_reg, + ov8865_blc_anchor_left_start_h(mode->blc_anchor_left_start)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_blc_anchor_left_start_l_reg, + ov8865_blc_anchor_left_start_l(mode->blc_anchor_left_start)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_blc_anchor_left_end_h_reg, + ov8865_blc_anchor_left_end_h(mode->blc_anchor_left_end)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_blc_anchor_left_end_l_reg, + ov8865_blc_anchor_left_end_l(mode->blc_anchor_left_end)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_blc_anchor_right_start_h_reg, + ov8865_blc_anchor_right_start_h(mode->blc_anchor_right_start)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_blc_anchor_right_start_l_reg, + ov8865_blc_anchor_right_start_l(mode->blc_anchor_right_start)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_blc_anchor_right_end_h_reg, + ov8865_blc_anchor_right_end_h(mode->blc_anchor_right_end)); + if (ret) + return ret; + + return ov8865_write(sensor, ov8865_blc_anchor_right_end_l_reg, + ov8865_blc_anchor_right_end_l(mode->blc_anchor_right_end)); +} + +static int ov8865_mode_configure(struct ov8865_sensor *sensor, + const struct ov8865_mode *mode, u32 mbus_code) +{ + int ret; + + /* output size x */ + + ret = ov8865_write(sensor, ov8865_output_size_x_h_reg, + ov8865_output_size_x_h(mode->output_size_x)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_output_size_x_l_reg, + ov8865_output_size_x_l(mode->output_size_x)); + if (ret) + return ret; + + /* horizontal total size */ + + ret = ov8865_write(sensor, ov8865_hts_h_reg, ov8865_hts_h(mode->hts)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_hts_l_reg, ov8865_hts_l(mode->hts)); + if (ret) + return ret; + + /* output size y */ + + ret = ov8865_write(sensor, ov8865_output_size_y_h_reg, + ov8865_output_size_y_h(mode->output_size_y)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_output_size_y_l_reg, + ov8865_output_size_y_l(mode->output_size_y)); + if (ret) + return ret; + + /* vertical total size */ + + ret = ov8865_write(sensor, ov8865_vts_h_reg, ov8865_vts_h(mode->vts)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_vts_l_reg, ov8865_vts_l(mode->vts)); + if (ret) + return ret; + + if (mode->size_auto) { + /* auto size */ + + ret = ov8865_write(sensor, ov8865_auto_size_ctrl_reg, + ov8865_auto_size_ctrl_offset_y_reg | + ov8865_auto_size_ctrl_offset_x_reg | + ov8865_auto_size_ctrl_crop_end_y_reg | + ov8865_auto_size_ctrl_crop_end_x_reg | + ov8865_auto_size_ctrl_crop_start_y_reg | + ov8865_auto_size_ctrl_crop_start_x_reg); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_auto_size_boundaries_reg, + ov8865_auto_size_boundaries_y(mode->size_auto_boundary_y) | + ov8865_auto_size_boundaries_x(mode->size_auto_boundary_x)); + if (ret) + return ret; + } else { + /* crop start x */ + + ret = ov8865_write(sensor, ov8865_crop_start_x_h_reg, + ov8865_crop_start_x_h(mode->crop_start_x)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_crop_start_x_l_reg, + ov8865_crop_start_x_l(mode->crop_start_x)); + if (ret) + return ret; + + /* offset x */ + + ret = ov8865_write(sensor, ov8865_offset_x_h_reg, + ov8865_offset_x_h(mode->offset_x)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_offset_x_l_reg, + ov8865_offset_x_l(mode->offset_x)); + if (ret) + return ret; + + /* crop end x */ + + ret = ov8865_write(sensor, ov8865_crop_end_x_h_reg, + ov8865_crop_end_x_h(mode->crop_end_x)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_crop_end_x_l_reg, + ov8865_crop_end_x_l(mode->crop_end_x)); + if (ret) + return ret; + + /* crop start y */ + + ret = ov8865_write(sensor, ov8865_crop_start_y_h_reg, + ov8865_crop_start_y_h(mode->crop_start_y)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_crop_start_y_l_reg, + ov8865_crop_start_y_l(mode->crop_start_y)); + if (ret) + return ret; + + /* offset y */ + + ret = ov8865_write(sensor, ov8865_offset_y_h_reg, + ov8865_offset_y_h(mode->offset_y)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_offset_y_l_reg, + ov8865_offset_y_l(mode->offset_y)); + if (ret) + return ret; + + /* crop end y */ + + ret = ov8865_write(sensor, ov8865_crop_end_y_h_reg, + ov8865_crop_end_y_h(mode->crop_end_y)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_crop_end_y_l_reg, + ov8865_crop_end_y_l(mode->crop_end_y)); + if (ret) + return ret; + } + + /* vfifo */ + + ret = ov8865_write(sensor, ov8865_vfifo_read_start_h_reg, + ov8865_vfifo_read_start_h(mode->vfifo_read_start)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_vfifo_read_start_l_reg, + ov8865_vfifo_read_start_l(mode->vfifo_read_start)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_ablc_num_reg, + ov8865_ablc_num(mode->ablc_num)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_zline_num_reg, + ov8865_zline_num(mode->zline_num)); + if (ret) + return ret; + + /* binning */ + + ret = ov8865_mode_binning_configure(sensor, mode); + if (ret) + return ret; + + /* black level */ + + ret = ov8865_mode_black_level_configure(sensor, mode); + if (ret) + return ret; + + /* plls */ + + ret = ov8865_mode_pll1_configure(sensor, mode, mbus_code); + if (ret) + return ret; + + ret = ov8865_mode_pll2_configure(sensor, mode); + if (ret) + return ret; + + ret = ov8865_mode_sclk_configure(sensor, mode); + if (ret) + return ret; + + /* extra registers */ + + if (mode->register_values) { + ret = ov8865_write_sequence(sensor, mode->register_values, + mode->register_values_count); + if (ret) + return ret; + } + + return 0; +} + +static unsigned long ov8865_mode_mipi_clk_rate(struct ov8865_sensor *sensor, + const struct ov8865_mode *mode) +{ + const struct ov8865_pll1_config *config = mode->pll1_config; + unsigned long pll1_rate; + + pll1_rate = ov8865_mode_pll1_rate(sensor, mode); + + return pll1_rate / config->m_div / 2; +} + +/* exposure */ + +static int ov8865_exposure_configure(struct ov8865_sensor *sensor, u32 exposure) +{ + int ret; + + ret = ov8865_write(sensor, ov8865_exposure_ctrl_hh_reg, + ov8865_exposure_ctrl_hh(exposure)); + if (ret) + return ret; + + ret = ov8865_write(sensor, ov8865_exposure_ctrl_h_reg, + ov8865_exposure_ctrl_h(exposure)); + if (ret) + return ret; + + return ov8865_write(sensor, ov8865_exposure_ctrl_l_reg, + ov8865_exposure_ctrl_l(exposure)); +} + +/* gain */ + +static int ov8865_gain_configure(struct ov8865_sensor *sensor, u32 gain) +{ + int ret; + + ret = ov8865_write(sensor, ov8865_gain_ctrl_h_reg, + ov8865_gain_ctrl_h(gain)); + if (ret) + return ret; + + return ov8865_write(sensor, ov8865_gain_ctrl_l_reg, + ov8865_gain_ctrl_l(gain)); +} + +/* white balance */ + +static int ov8865_red_balance_configure(struct ov8865_sensor *sensor, + u32 red_balance) +{ + int ret; + + ret = ov8865_write(sensor, ov8865_isp_gain_red_h_reg, + ov8865_isp_gain_red_h(red_balance)); + if (ret) + return ret; + + return ov8865_write(sensor, ov8865_isp_gain_red_l_reg, + ov8865_isp_gain_red_l(red_balance)); +} + +static int ov8865_blue_balance_configure(struct ov8865_sensor *sensor, + u32 blue_balance) +{ + int ret; + + ret = ov8865_write(sensor, ov8865_isp_gain_blue_h_reg, + ov8865_isp_gain_blue_h(blue_balance)); + if (ret) + return ret; + + return ov8865_write(sensor, ov8865_isp_gain_blue_l_reg, + ov8865_isp_gain_blue_l(blue_balance)); +} + +/* flip */ + +static int ov8865_flip_vert_configure(struct ov8865_sensor *sensor, bool enable) +{ + u8 bits = ov8865_format1_flip_vert_isp_en | + ov8865_format1_flip_vert_sensor_en; + + return ov8865_update_bits(sensor, ov8865_format1_reg, bits, + enable ? bits : 0); +} + +static int ov8865_flip_horz_configure(struct ov8865_sensor *sensor, bool enable) +{ + u8 bits = ov8865_format2_flip_horz_isp_en | + ov8865_format2_flip_horz_sensor_en; + + return ov8865_update_bits(sensor, ov8865_format2_reg, bits, + enable ? bits : 0); +} + +/* test pattern */ + +static int ov8865_test_pattern_configure(struct ov8865_sensor *sensor, + unsigned int index) +{ + if (index >= array_size(ov8865_test_pattern_bits)) + return -einval; + + return ov8865_write(sensor, ov8865_pre_ctrl0_reg, + ov8865_test_pattern_bits[index]); +} + +/* state */ + +static int ov8865_state_mipi_configure(struct ov8865_sensor *sensor, + const struct ov8865_mode *mode, + u32 mbus_code) +{ + struct ov8865_ctrls *ctrls = &sensor->ctrls; + struct v4l2_fwnode_bus_mipi_csi2 *bus_mipi_csi2 = + &sensor->endpoint.bus.mipi_csi2; + unsigned long mipi_clk_rate; + unsigned int bits_per_sample; + unsigned int lanes_count; + unsigned int i, j; + s64 mipi_pixel_rate; + + mipi_clk_rate = ov8865_mode_mipi_clk_rate(sensor, mode); + if (!mipi_clk_rate) + return -einval; + + for (i = 0; i < array_size(ov8865_link_freq_menu); i++) { + s64 freq = ov8865_link_freq_menu[i]; + + if (freq == mipi_clk_rate) + break; + } + + for (j = 0; j < sensor->endpoint.nr_of_link_frequencies; j++) { + u64 freq = sensor->endpoint.link_frequencies[j]; + + if (freq == mipi_clk_rate) + break; + } + + if (i == array_size(ov8865_link_freq_menu)) { + dev_err(sensor->dev, + "failed to find %lu clk rate in link freq ", + mipi_clk_rate); + } else if (j == sensor->endpoint.nr_of_link_frequencies) { + dev_err(sensor->dev, + "failed to find %lu clk rate in endpoint link-frequencies ", + mipi_clk_rate); + } else { + __v4l2_ctrl_s_ctrl(ctrls->link_freq, i); + } + + switch (mbus_code) { + case media_bus_fmt_sbggr10_1x10: + bits_per_sample = 10; + break; + default: + return -einval; + } + + lanes_count = bus_mipi_csi2->num_data_lanes; + mipi_pixel_rate = mipi_clk_rate * 2 * lanes_count / bits_per_sample; + + __v4l2_ctrl_s_ctrl_int64(ctrls->pixel_rate, mipi_pixel_rate); + + return 0; +} + +static int ov8865_state_configure(struct ov8865_sensor *sensor, + const struct ov8865_mode *mode, + u32 mbus_code) +{ + int ret; + + if (sensor->state.streaming) + return -ebusy; + + /* state will be configured at first power on otherwise. */ + if (pm_runtime_enabled(sensor->dev) && + !pm_runtime_suspended(sensor->dev)) { + ret = ov8865_mode_configure(sensor, mode, mbus_code); + if (ret) + return ret; + } + + ret = ov8865_state_mipi_configure(sensor, mode, mbus_code); + if (ret) + return ret; + + sensor->state.mode = mode; + sensor->state.mbus_code = mbus_code; + + return 0; +} + +static int ov8865_state_init(struct ov8865_sensor *sensor) +{ + return ov8865_state_configure(sensor, &ov8865_modes[0], + ov8865_mbus_codes[0]); +} + +/* sensor base */ + +static int ov8865_sensor_init(struct ov8865_sensor *sensor) +{ + int ret; + + ret = ov8865_sw_reset(sensor); + if (ret) { + dev_err(sensor->dev, "failed to perform sw reset "); + return ret; + } + + ret = ov8865_sw_standby(sensor, 1); + if (ret) { + dev_err(sensor->dev, "failed to set sensor standby "); + return ret; + } + + ret = ov8865_chip_id_check(sensor); + if (ret) { + dev_err(sensor->dev, "failed to check sensor chip id "); + return ret; + } + + ret = ov8865_write_sequence(sensor, ov8865_init_sequence, + array_size(ov8865_init_sequence)); + if (ret) { + dev_err(sensor->dev, "failed to write init sequence "); + return ret; + } + + ret = ov8865_charge_pump_configure(sensor); + if (ret) { + dev_err(sensor->dev, "failed to configure pad "); + return ret; + } + + ret = ov8865_mipi_configure(sensor); + if (ret) { + dev_err(sensor->dev, "failed to configure mipi "); + return ret; + } + + ret = ov8865_isp_configure(sensor); + if (ret) { + dev_err(sensor->dev, "failed to configure isp "); + return ret; + } + + ret = ov8865_black_level_configure(sensor); + if (ret) { + dev_err(sensor->dev, "failed to configure black level "); + return ret; + } + + /* configure current mode. */ + ret = ov8865_state_configure(sensor, sensor->state.mode, + sensor->state.mbus_code); + if (ret) { + dev_err(sensor->dev, "failed to configure state "); + return ret; + } + + return 0; +} + +static int ov8865_sensor_power(struct ov8865_sensor *sensor, bool on) +{ + /* keep initialized to zero for disable label. */ + int ret = 0; + + if (on) { + gpiod_set_value_cansleep(sensor->reset, 1); + gpiod_set_value_cansleep(sensor->powerdown, 1); + + ret = regulator_enable(sensor->dovdd); + if (ret) { + dev_err(sensor->dev, + "failed to enable dovdd regulator "); + goto disable; + } + + ret = regulator_enable(sensor->avdd); + if (ret) { + dev_err(sensor->dev, + "failed to enable avdd regulator "); + goto disable; + } + + ret = regulator_enable(sensor->dvdd); + if (ret) { + dev_err(sensor->dev, + "failed to enable dvdd regulator "); + goto disable; + } + + ret = clk_prepare_enable(sensor->extclk); + if (ret) { + dev_err(sensor->dev, "failed to enable extclk clock "); + goto disable; + } + + gpiod_set_value_cansleep(sensor->reset, 0); + gpiod_set_value_cansleep(sensor->powerdown, 0); + + /* time to enter streaming mode according to power timings. */ + usleep_range(10000, 12000); + } else { +disable: + gpiod_set_value_cansleep(sensor->powerdown, 1); + gpiod_set_value_cansleep(sensor->reset, 1); + + clk_disable_unprepare(sensor->extclk); + + regulator_disable(sensor->dvdd); + regulator_disable(sensor->avdd); + regulator_disable(sensor->dovdd); + } + + return ret; +} + +/* controls */ + +static int ov8865_s_ctrl(struct v4l2_ctrl *ctrl) +{ + struct v4l2_subdev *subdev = ov8865_ctrl_subdev(ctrl); + struct ov8865_sensor *sensor = ov8865_subdev_sensor(subdev); + unsigned int index; + int ret; + + /* wait for the sensor to be on before setting controls. */ + if (pm_runtime_suspended(sensor->dev)) + return 0; + + switch (ctrl->id) { + case v4l2_cid_exposure: + ret = ov8865_exposure_configure(sensor, ctrl->val); + if (ret) + return ret; + break; + case v4l2_cid_gain: + ret = ov8865_gain_configure(sensor, ctrl->val); + if (ret) + return ret; + break; + case v4l2_cid_red_balance: + return ov8865_red_balance_configure(sensor, ctrl->val); + case v4l2_cid_blue_balance: + return ov8865_blue_balance_configure(sensor, ctrl->val); + case v4l2_cid_hflip: + return ov8865_flip_horz_configure(sensor, !!ctrl->val); + case v4l2_cid_vflip: + return ov8865_flip_vert_configure(sensor, !!ctrl->val); + case v4l2_cid_test_pattern: + index = (unsigned int)ctrl->val; + return ov8865_test_pattern_configure(sensor, index); + default: + return -einval; + } + + return 0; +} + +static const struct v4l2_ctrl_ops ov8865_ctrl_ops = { + .s_ctrl = ov8865_s_ctrl, +}; + +static int ov8865_ctrls_init(struct ov8865_sensor *sensor) +{ + struct ov8865_ctrls *ctrls = &sensor->ctrls; + struct v4l2_ctrl_handler *handler = &ctrls->handler; + const struct v4l2_ctrl_ops *ops = &ov8865_ctrl_ops; + int ret; + + v4l2_ctrl_handler_init(handler, 32); + + /* use our mutex for ctrl locking. */ + handler->lock = &sensor->mutex; + + /* exposure */ + + v4l2_ctrl_new_std(handler, ops, v4l2_cid_exposure, 16, 1048575, 16, + 512); + + /* gain */ + + v4l2_ctrl_new_std(handler, ops, v4l2_cid_gain, 128, 8191, 128, 128); + + /* white balance */ + + v4l2_ctrl_new_std(handler, ops, v4l2_cid_red_balance, 1, 32767, 1, + 1024); + + v4l2_ctrl_new_std(handler, ops, v4l2_cid_blue_balance, 1, 32767, 1, + 1024); + + /* flip */ + + v4l2_ctrl_new_std(handler, ops, v4l2_cid_hflip, 0, 1, 1, 0); + v4l2_ctrl_new_std(handler, ops, v4l2_cid_vflip, 0, 1, 1, 0); + + /* test pattern */ + + v4l2_ctrl_new_std_menu_items(handler, ops, v4l2_cid_test_pattern, + array_size(ov8865_test_pattern_menu) - 1, + 0, 0, ov8865_test_pattern_menu); + + /* mipi csi-2 */ + + ctrls->link_freq = + v4l2_ctrl_new_int_menu(handler, null, v4l2_cid_link_freq, + array_size(ov8865_link_freq_menu) - 1, + 0, ov8865_link_freq_menu); + + ctrls->pixel_rate = + v4l2_ctrl_new_std(handler, null, v4l2_cid_pixel_rate, 1, + int_max, 1, 1); + + if (handler->error) { + ret = handler->error; + goto error_ctrls; + } + + ctrls->link_freq->flags |= v4l2_ctrl_flag_read_only; + ctrls->pixel_rate->flags |= v4l2_ctrl_flag_read_only; + + sensor->subdev.ctrl_handler = handler; + + return 0; + +error_ctrls: + v4l2_ctrl_handler_free(handler); + + return ret; +} + +/* subdev video operations */ + +static int ov8865_s_stream(struct v4l2_subdev *subdev, int enable) +{ + struct ov8865_sensor *sensor = ov8865_subdev_sensor(subdev); + struct ov8865_state *state = &sensor->state; + int ret; + + if (enable) { + ret = pm_runtime_get_sync(sensor->dev); + if (ret < 0) { + pm_runtime_put_noidle(sensor->dev); + return ret; + } + } + + mutex_lock(&sensor->mutex); + ret = ov8865_sw_standby(sensor, !enable); + mutex_unlock(&sensor->mutex); + + if (ret) + return ret; + + state->streaming = !!enable; + + if (!enable) + pm_runtime_put(sensor->dev); + + return 0; +} + +static int ov8865_g_frame_interval(struct v4l2_subdev *subdev, + struct v4l2_subdev_frame_interval *interval) +{ + struct ov8865_sensor *sensor = ov8865_subdev_sensor(subdev); + const struct ov8865_mode *mode; + int ret = 0; + + mutex_lock(&sensor->mutex); + + mode = sensor->state.mode; + interval->interval = mode->frame_interval; + + mutex_unlock(&sensor->mutex); + + return ret; +} + +static const struct v4l2_subdev_video_ops ov8865_subdev_video_ops = { + .s_stream = ov8865_s_stream, + .g_frame_interval = ov8865_g_frame_interval, + .s_frame_interval = ov8865_g_frame_interval, +}; + +/* subdev pad operations */ + +static int ov8865_enum_mbus_code(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *config, + struct v4l2_subdev_mbus_code_enum *code_enum) +{ + if (code_enum->index >= array_size(ov8865_mbus_codes)) + return -einval; + + code_enum->code = ov8865_mbus_codes[code_enum->index]; + + return 0; +} + +static void ov8865_mbus_format_fill(struct v4l2_mbus_framefmt *mbus_format, + u32 mbus_code, + const struct ov8865_mode *mode) +{ + mbus_format->width = mode->output_size_x; + mbus_format->height = mode->output_size_y; + mbus_format->code = mbus_code; + + mbus_format->field = v4l2_field_none; + mbus_format->colorspace = v4l2_colorspace_raw; + mbus_format->ycbcr_enc = + v4l2_map_ycbcr_enc_default(mbus_format->colorspace); + mbus_format->quantization = v4l2_quantization_full_range; + mbus_format->xfer_func = + v4l2_map_xfer_func_default(mbus_format->colorspace); +} + +static int ov8865_get_fmt(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *config, + struct v4l2_subdev_format *format) +{ + struct ov8865_sensor *sensor = ov8865_subdev_sensor(subdev); + struct v4l2_mbus_framefmt *mbus_format = &format->format; + + mutex_lock(&sensor->mutex); + + if (format->which == v4l2_subdev_format_try) + *mbus_format = *v4l2_subdev_get_try_format(subdev, config, + format->pad); + else + ov8865_mbus_format_fill(mbus_format, sensor->state.mbus_code, + sensor->state.mode); + + mutex_unlock(&sensor->mutex); + + return 0; +} + +static int ov8865_set_fmt(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *config, + struct v4l2_subdev_format *format) +{ + struct ov8865_sensor *sensor = ov8865_subdev_sensor(subdev); + struct v4l2_mbus_framefmt *mbus_format = &format->format; + const struct ov8865_mode *mode; + u32 mbus_code = 0; + unsigned int index; + int ret = 0; + + mutex_lock(&sensor->mutex); + + if (sensor->state.streaming) { + ret = -ebusy; + goto complete; + } + + /* try to find requested mbus code. */ + for (index = 0; index < array_size(ov8865_mbus_codes); index++) { + if (ov8865_mbus_codes[index] == mbus_format->code) { + mbus_code = mbus_format->code; + break; + } + } + + /* fallback to default. */ + if (!mbus_code) + mbus_code = ov8865_mbus_codes[0]; + + /* find the mode with nearest dimensions. */ + mode = v4l2_find_nearest_size(ov8865_modes, array_size(ov8865_modes), + output_size_x, output_size_y, + mbus_format->width, mbus_format->height); + if (!mode) { + ret = -einval; + goto complete; + } + + ov8865_mbus_format_fill(mbus_format, mbus_code, mode); + + if (format->which == v4l2_subdev_format_try) + *v4l2_subdev_get_try_format(subdev, config, format->pad) = + *mbus_format; + else if (sensor->state.mode != mode || + sensor->state.mbus_code != mbus_code) + ret = ov8865_state_configure(sensor, mode, mbus_code); + +complete: + mutex_unlock(&sensor->mutex); + + return ret; +} + +static int ov8865_enum_frame_size(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *config, + struct v4l2_subdev_frame_size_enum *size_enum) +{ + const struct ov8865_mode *mode; + + if (size_enum->index >= array_size(ov8865_modes)) + return -einval; + + mode = &ov8865_modes[size_enum->index]; + + size_enum->min_width = size_enum->max_width = mode->output_size_x; + size_enum->min_height = size_enum->max_height = mode->output_size_y; + + return 0; +} + +static int ov8865_enum_frame_interval(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *config, + struct v4l2_subdev_frame_interval_enum *interval_enum) +{ + const struct ov8865_mode *mode = null; + unsigned int mode_index; + unsigned int interval_index; + + if (interval_enum->index > 0) + return -einval; + /* + * multiple modes with the same dimensions may have different frame + * intervals, so look up each relevant mode. + */ + for (mode_index = 0, interval_index = 0; + mode_index < array_size(ov8865_modes); mode_index++) { + mode = &ov8865_modes[mode_index]; + + if (mode->output_size_x == interval_enum->width && + mode->output_size_y == interval_enum->height) { + if (interval_index == interval_enum->index) + break; + + interval_index++; + } + } + + if (mode_index == array_size(ov8865_modes) || !mode) + return -einval; + + interval_enum->interval = mode->frame_interval; + + return 0; +} + +static const struct v4l2_subdev_pad_ops ov8865_subdev_pad_ops = { + .enum_mbus_code = ov8865_enum_mbus_code, + .get_fmt = ov8865_get_fmt, + .set_fmt = ov8865_set_fmt, + .enum_frame_size = ov8865_enum_frame_size, + .enum_frame_interval = ov8865_enum_frame_interval, +}; + +static const struct v4l2_subdev_ops ov8865_subdev_ops = { + .video = &ov8865_subdev_video_ops, + .pad = &ov8865_subdev_pad_ops, +}; + +static int ov8865_suspend(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ov8865_sensor *sensor = ov8865_subdev_sensor(subdev); + struct ov8865_state *state = &sensor->state; + int ret = 0; + + mutex_lock(&sensor->mutex); + + if (state->streaming) { + ret = ov8865_sw_standby(sensor, true); + if (ret) + goto complete; + } + + ret = ov8865_sensor_power(sensor, false); + if (ret) + ov8865_sw_standby(sensor, false); + +complete: + mutex_unlock(&sensor->mutex); + + return ret; +} + +static int ov8865_resume(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ov8865_sensor *sensor = ov8865_subdev_sensor(subdev); + struct ov8865_state *state = &sensor->state; + int ret = 0; + + mutex_lock(&sensor->mutex); + + ret = ov8865_sensor_power(sensor, true); + if (ret) + goto complete; + + ret = ov8865_sensor_init(sensor); + if (ret) + goto error_power; + + ret = __v4l2_ctrl_handler_setup(&sensor->ctrls.handler); + if (ret) + goto error_power; + + if (state->streaming) { + ret = ov8865_sw_standby(sensor, false); + if (ret) + goto error_power; + } + + goto complete; + +error_power: + ov8865_sensor_power(sensor, false); + +complete: + mutex_unlock(&sensor->mutex); + + return ret; +} + +static int ov8865_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct fwnode_handle *handle; + struct ov8865_sensor *sensor; + struct v4l2_subdev *subdev; + struct media_pad *pad; + unsigned long rate; + int ret; + + sensor = devm_kzalloc(dev, sizeof(*sensor), gfp_kernel); + if (!sensor) + return -enomem; + + sensor->dev = dev; + sensor->i2c_client = client; + + /* graph endpoint */ + + handle = fwnode_graph_get_next_endpoint(dev_fwnode(dev), null); + if (!handle) { + dev_err(dev, "unable to find enpoint node "); + return -einval; + } + + sensor->endpoint.bus_type = v4l2_mbus_csi2_dphy; + + ret = v4l2_fwnode_endpoint_alloc_parse(handle, &sensor->endpoint); + fwnode_handle_put(handle); + if (ret) { + dev_err(dev, "failed to parse endpoint node "); + return ret; + } + + /* gpios */ + + sensor->powerdown = devm_gpiod_get_optional(dev, "powerdown", + gpiod_out_high); + if (is_err(sensor->powerdown)) { + ret = ptr_err(sensor->powerdown); + goto error_endpoint; + } + + sensor->reset = devm_gpiod_get_optional(dev, "reset", gpiod_out_high); + if (is_err(sensor->reset)) { + ret = ptr_err(sensor->reset); + goto error_endpoint; + } + + /* regulators */ + + /* dvdd: digital core */ + sensor->dvdd = devm_regulator_get(dev, "dvdd"); + if (is_err(sensor->dvdd)) { + dev_err(dev, "cannot get dvdd (digital core) regulator "); + ret = ptr_err(sensor->dvdd); + goto error_endpoint; + } + + /* dovdd: digital i/o */ + sensor->dovdd = devm_regulator_get(dev, "dovdd"); + if (is_err(sensor->dvdd)) { + dev_err(dev, "cannot get dovdd (digital i/o) regulator "); + ret = ptr_err(sensor->dvdd); + goto error_endpoint; + } + + /* avdd: analog */ + sensor->avdd = devm_regulator_get(dev, "avdd"); + if (is_err(sensor->avdd)) { + dev_err(dev, "cannot get avdd (analog) regulator "); + ret = ptr_err(sensor->dvdd); + goto error_endpoint; + } + + /* external clock */ + + sensor->extclk = devm_clk_get(dev, null); + if (is_err(sensor->extclk)) { + dev_err(dev, "failed to get external clock "); + ret = ptr_err(sensor->extclk); + goto error_endpoint; + } + + rate = clk_get_rate(sensor->extclk); + if (rate != ov8865_extclk_rate) { + dev_err(dev, "clock rate %lu hz is unsupported ", rate); + ret = -einval; + goto error_endpoint; + } + + /* subdev, entity and pad */ + + subdev = &sensor->subdev; + v4l2_i2c_subdev_init(subdev, client, &ov8865_subdev_ops); + + subdev->flags |= v4l2_subdev_fl_has_devnode; + subdev->entity.function = media_ent_f_cam_sensor; + + pad = &sensor->pad; + pad->flags = media_pad_fl_source; + + ret = media_entity_pads_init(&subdev->entity, 1, pad); + if (ret) + goto error_entity; + + /* mutex */ + + mutex_init(&sensor->mutex); + + /* sensor */ + + ret = ov8865_ctrls_init(sensor); + if (ret) + goto error_mutex; + + ret = ov8865_state_init(sensor); + if (ret) + goto error_ctrls; + + /* runtime pm */ + + pm_runtime_enable(sensor->dev); + pm_runtime_set_suspended(sensor->dev); + + /* v4l2 subdev register */ + + ret = v4l2_async_register_subdev_sensor_common(subdev); + if (ret) + goto error_pm; + + return 0; + +error_pm: + pm_runtime_disable(sensor->dev); + +error_ctrls: + v4l2_ctrl_handler_free(&sensor->ctrls.handler); + +error_mutex: + mutex_destroy(&sensor->mutex); + +error_entity: + media_entity_cleanup(&sensor->subdev.entity); + +error_endpoint: + v4l2_fwnode_endpoint_free(&sensor->endpoint); + + return ret; +} + +static int ov8865_remove(struct i2c_client *client) +{ + struct v4l2_subdev *subdev = i2c_get_clientdata(client); + struct ov8865_sensor *sensor = ov8865_subdev_sensor(subdev); + + v4l2_async_unregister_subdev(subdev); + pm_runtime_disable(sensor->dev); + v4l2_ctrl_handler_free(&sensor->ctrls.handler); + mutex_destroy(&sensor->mutex); + media_entity_cleanup(&subdev->entity); + + v4l2_fwnode_endpoint_free(&sensor->endpoint); + + return 0; +} + +static const struct dev_pm_ops ov8865_pm_ops = { + set_runtime_pm_ops(ov8865_suspend, ov8865_resume, null) +}; + +static const struct of_device_id ov8865_of_match[] = { + { .compatible = "ovti,ov8865" }, + { } +}; +module_device_table(of, ov8865_of_match); + +static struct i2c_driver ov8865_driver = { + .driver = { + .name = "ov8865", + .of_match_table = ov8865_of_match, + .pm = &ov8865_pm_ops, + }, + .probe_new = ov8865_probe, + .remove = ov8865_remove, +}; + +module_i2c_driver(ov8865_driver); + +module_author("paul kocialkowski <paul.kocialkowski@bootlin.com>"); +module_description("v4l2 driver for the omnivision ov8865 image sensor"); +module_license("gpl v2");
TV tuners, webcams, video capturers
11c0d8fdccc56fa15cb15906480b4737c31dd085
paul kocialkowski
drivers
media
i2c
media: ir_toy: add another ir droid device
this device is also supported.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add another ir droid device
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['ir_toy']
['c']
1
1
0
--- diff --git a/drivers/media/rc/ir_toy.c b/drivers/media/rc/ir_toy.c --- a/drivers/media/rc/ir_toy.c +++ b/drivers/media/rc/ir_toy.c + { usb_device_interface_class(0x04d8, 0xf58b, usb_class_cdc_data) },
TV tuners, webcams, video capturers
4487e0215560392bd11c9de08d60824d72c89cd9
sean young greg kroah hartman gregkh linuxfoundation org georgi bakalski georgi bakalski gmail com
drivers
media
rc
media: mxl692: maxlinear 692 atsc demod/tuner driver
maxlinear 692 is a combo demod/tuner which has atsc and qam capabilities. only atsc is currently advertised via dvb properties. qam still has issues.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
maxlinear 692 atsc demod/tuner driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['mxl692']
['h', 'kconfig', 'c', 'makefile']
5
1,974
0
--- diff --git a/drivers/media/dvb-frontends/kconfig b/drivers/media/dvb-frontends/kconfig --- a/drivers/media/dvb-frontends/kconfig +++ b/drivers/media/dvb-frontends/kconfig +config dvb_mxl692 + tristate "maxlinear mxl692 based" + depends on dvb_core && i2c + default m if !media_subdrv_autoselect + help + maxlinear mxl692 is a combo tuner-demodulator that + supports atsc 8vsb and qam modes. say y when you want to + support this frontend. + diff --git a/drivers/media/dvb-frontends/makefile b/drivers/media/dvb-frontends/makefile --- a/drivers/media/dvb-frontends/makefile +++ b/drivers/media/dvb-frontends/makefile +obj-$(config_dvb_mxl692) += mxl692.o diff --git a/drivers/media/dvb-frontends/mxl692.c b/drivers/media/dvb-frontends/mxl692.c --- /dev/null +++ b/drivers/media/dvb-frontends/mxl692.c +// spdx-license-identifier: gpl-2.0 +/* + * driver for the maxlinear mxl69x family of combo tuners/demods + * + * copyright (c) 2020 brad love <brad@nextdimension.cc> + * + * based on code: + * copyright (c) 2016 maxlinear, inc. all rights reserved + * which was released under gpl v2 + * + * this program is free software; you can redistribute it and/or + * modify it under the terms of the gnu general public license + * version 2, as published by the free software foundation. + * + * this program is distributed in the hope that it will be useful, + * but without any warranty; without even the implied warranty of + * merchantability or fitness for a particular purpose. see the + * gnu general public license for more details. + */ + +#include <linux/mutex.h> +#include <linux/i2c-mux.h> +#include <linux/string.h> +#include <linux/firmware.h> + +#include "mxl692.h" +#include "mxl692_defs.h" + +static const struct dvb_frontend_ops mxl692_ops; + +struct mxl692_dev { + struct dvb_frontend fe; + struct i2c_client *i2c_client; + struct mutex i2c_lock; /* i2c command mutex */ + enum mxl_eagle_demod_type_e demod_type; + enum mxl_eagle_power_mode_e power_mode; + u32 current_frequency; + int device_type; + int seqnum; + int init_done; +}; + +static int mxl692_i2c_write(struct mxl692_dev *dev, u8 *buffer, u16 buf_len) +{ + int ret = 0; + struct i2c_msg msg = { + .addr = dev->i2c_client->addr, + .flags = 0, + .buf = buffer, + .len = buf_len + }; + + ret = i2c_transfer(dev->i2c_client->adapter, &msg, 1); + if (ret != 1) + dev_dbg(&dev->i2c_client->dev, "i2c write error! "); + + return ret; +} + +static int mxl692_i2c_read(struct mxl692_dev *dev, u8 *buffer, u16 buf_len) +{ + int ret = 0; + struct i2c_msg msg = { + .addr = dev->i2c_client->addr, + .flags = i2c_m_rd, + .buf = buffer, + .len = buf_len + }; + + ret = i2c_transfer(dev->i2c_client->adapter, &msg, 1); + if (ret != 1) + dev_dbg(&dev->i2c_client->dev, "i2c read error! "); + + return ret; +} + +static int convert_endian(u32 size, u8 *d) +{ + u32 i; + + for (i = 0; i < (size & ~3); i += 4) { + d[i + 0] ^= d[i + 3]; + d[i + 3] ^= d[i + 0]; + d[i + 0] ^= d[i + 3]; + + d[i + 1] ^= d[i + 2]; + d[i + 2] ^= d[i + 1]; + d[i + 1] ^= d[i + 2]; + } + + switch (size & 3) { + case 0: + case 1: + /* do nothing */ + break; + case 2: + d[i + 0] ^= d[i + 1]; + d[i + 1] ^= d[i + 0]; + d[i + 0] ^= d[i + 1]; + break; + + case 3: + d[i + 0] ^= d[i + 2]; + d[i + 2] ^= d[i + 0]; + d[i + 0] ^= d[i + 2]; + break; + } + return size; +} + +static int convert_endian_n(int n, u32 size, u8 *d) +{ + int i, count = 0; + + for (i = 0; i < n; i += size) + count += convert_endian(size, d + i); + return count; +} + +static void mxl692_tx_swap(enum mxl_eagle_opcode_e opcode, u8 *buffer) +{ +#ifdef __big_endian + return; +#endif + buffer += mxl_eagle_host_msg_header_size; /* skip api header */ + + switch (opcode) { + case mxl_eagle_opcode_device_intr_mask_set: + case mxl_eagle_opcode_tuner_channel_tune_set: + case mxl_eagle_opcode_sma_transmit_set: + buffer += convert_endian(sizeof(u32), buffer); + break; + case mxl_eagle_opcode_qam_params_set: + buffer += 5; + buffer += convert_endian(2 * sizeof(u32), buffer); + break; + default: + /* no swapping - all get opcodes */ + /* atsc/oob no swapping */ + break; + } +} + +static void mxl692_rx_swap(enum mxl_eagle_opcode_e opcode, u8 *buffer) +{ +#ifdef __big_endian + return; +#endif + buffer += mxl_eagle_host_msg_header_size; /* skip api header */ + + switch (opcode) { + case mxl_eagle_opcode_tuner_agc_status_get: + buffer++; + buffer += convert_endian(2 * sizeof(u16), buffer); + break; + case mxl_eagle_opcode_atsc_status_get: + buffer += convert_endian_n(2, sizeof(u16), buffer); + buffer += convert_endian(sizeof(u32), buffer); + break; + case mxl_eagle_opcode_atsc_error_counters_get: + buffer += convert_endian(3 * sizeof(u32), buffer); + break; + case mxl_eagle_opcode_atsc_equalizer_filter_ffe_taps_get: + buffer += convert_endian_n(24, sizeof(u16), buffer); + break; + case mxl_eagle_opcode_qam_status_get: + buffer += 8; + buffer += convert_endian_n(2, sizeof(u16), buffer); + buffer += convert_endian(sizeof(u32), buffer); + break; + case mxl_eagle_opcode_qam_error_counters_get: + buffer += convert_endian(7 * sizeof(u32), buffer); + break; + case mxl_eagle_opcode_qam_constellation_value_get: + case mxl_eagle_opcode_qam_equalizer_filter_dfe_start_get: + case mxl_eagle_opcode_qam_equalizer_filter_dfe_middle_get: + case mxl_eagle_opcode_qam_equalizer_filter_dfe_end_get: + case mxl_eagle_opcode_qam_equalizer_filter_spur_start_get: + buffer += convert_endian_n(24, sizeof(u16), buffer); + break; + case mxl_eagle_opcode_qam_equalizer_filter_spur_end_get: + buffer += convert_endian_n(8, sizeof(u16), buffer); + break; + case mxl_eagle_opcode_qam_equalizer_filter_ffe_get: + buffer += convert_endian_n(17, sizeof(u16), buffer); + break; + case mxl_eagle_opcode_oob_error_counters_get: + buffer += convert_endian(3 * sizeof(u32), buffer); + break; + case mxl_eagle_opcode_oob_status_get: + buffer += convert_endian_n(2, sizeof(u16), buffer); + buffer += convert_endian(sizeof(u32), buffer); + break; + case mxl_eagle_opcode_sma_receive_get: + buffer += convert_endian(sizeof(u32), buffer); + break; + default: + /* no swapping - all set opcodes */ + break; + } +} + +static u32 mxl692_checksum(u8 *buffer, u32 size) +{ + u32 ix, div_size; + u32 cur_cksum = 0; + __be32 *buf; + + div_size = div_round_up(size, 4); + + buf = (__be32 *)buffer; + for (ix = 0; ix < div_size; ix++) + cur_cksum += be32_to_cpu(buf[ix]); + + cur_cksum ^= 0xdeadbeef; + + return cur_cksum; +} + +static int mxl692_validate_fw_header(struct mxl692_dev *dev, + const u8 *buffer, u32 buf_len) +{ + int status = 0; + u32 ix, temp; + __be32 *local_buf = null; + u8 temp_cksum = 0; + const u8 fw_hdr[] = { 0x4d, 0x31, 0x10, 0x02, 0x40, 0x00, 0x00, 0x80 }; + + if (memcmp(buffer, fw_hdr, 8) != 0) { + status = -einval; + goto err_finish; + } + + local_buf = (__be32 *)(buffer + 8); + temp = be32_to_cpu(*local_buf); + + if ((buf_len - 16) != temp >> 8) { + status = -einval; + goto err_finish; + } + + for (ix = 16; ix < buf_len; ix++) + temp_cksum += buffer[ix]; + + if (temp_cksum != buffer[11]) + status = -einval; + +err_finish: + if (status) + dev_dbg(&dev->i2c_client->dev, "failed "); + return status; +} + +static int mxl692_write_fw_block(struct mxl692_dev *dev, const u8 *buffer, + u32 buf_len, u32 *index) +{ + int status = 0; + u32 ix = 0, total_len = 0, addr = 0, chunk_len = 0, prevchunk_len = 0; + u8 local_buf[mxl_eagle_max_i2c_packet_size] = {}, *plocal_buf = null; + int payload_max = mxl_eagle_max_i2c_packet_size - mxl_eagle_i2c_mheader_size; + + ix = *index; + + if (buffer[ix] == 0x53) { + total_len = buffer[ix + 1] << 16 | buffer[ix + 2] << 8 | buffer[ix + 3]; + total_len = (total_len + 3) & ~3; + addr = buffer[ix + 4] << 24 | buffer[ix + 5] << 16 | + buffer[ix + 6] << 8 | buffer[ix + 7]; + ix += mxl_eagle_fw_segment_header_size; + + while ((total_len > 0) && (status == 0)) { + plocal_buf = local_buf; + chunk_len = (total_len < payload_max) ? total_len : payload_max; + + *plocal_buf++ = 0xfc; + *plocal_buf++ = chunk_len + sizeof(u32); + + *(u32 *)plocal_buf = addr + prevchunk_len; +#ifdef __big_endian + convert_endian(sizeof(u32), plocal_buf); +#endif + plocal_buf += sizeof(u32); + + memcpy(plocal_buf, &buffer[ix], chunk_len); + convert_endian(chunk_len, plocal_buf); + if (mxl692_i2c_write(dev, local_buf, + (chunk_len + mxl_eagle_i2c_mheader_size)) < 0) { + status = -eremoteio; + break; + } + + prevchunk_len += chunk_len; + total_len -= chunk_len; + ix += chunk_len; + } + *index = ix; + } else { + status = -einval; + } + + if (status) + dev_dbg(&dev->i2c_client->dev, "err %d ", status); + + return status; +} + +static int mxl692_memwrite(struct mxl692_dev *dev, u32 addr, + u8 *buffer, u32 size) +{ + int status = 0, total_len = 0; + u8 local_buf[mxl_eagle_max_i2c_packet_size] = {}, *plocal_buf = null; + + total_len = size; + total_len = (total_len + 3) & ~3; /* 4 byte alignment */ + + if (total_len > (mxl_eagle_max_i2c_packet_size - mxl_eagle_i2c_mheader_size)) + dev_dbg(&dev->i2c_client->dev, "hrmph? "); + + plocal_buf = local_buf; + + *plocal_buf++ = 0xfc; + *plocal_buf++ = total_len + sizeof(u32); + + *(u32 *)plocal_buf = addr; + plocal_buf += sizeof(u32); + + memcpy(plocal_buf, buffer, total_len); +#ifdef __big_endian + convert_endian(sizeof(u32) + total_len, local_buf + 2); +#endif + if (mxl692_i2c_write(dev, local_buf, + (total_len + mxl_eagle_i2c_mheader_size)) < 0) { + status = -eremoteio; + goto err_finish; + } + + return status; +err_finish: + dev_dbg(&dev->i2c_client->dev, "err %d ", status); + return status; +} + +static int mxl692_memread(struct mxl692_dev *dev, u32 addr, + u8 *buffer, u32 size) +{ + int status = 0; + u8 local_buf[mxl_eagle_i2c_mheader_size] = {}, *plocal_buf = null; + + plocal_buf = local_buf; + + *plocal_buf++ = 0xfb; + *plocal_buf++ = sizeof(u32); + *(u32 *)plocal_buf = addr; +#ifdef __big_endian + convert_endian(sizeof(u32), plocal_buf); +#endif + mutex_lock(&dev->i2c_lock); + + if (mxl692_i2c_write(dev, local_buf, mxl_eagle_i2c_mheader_size) > 0) { + size = (size + 3) & ~3; /* 4 byte alignment */ + status = mxl692_i2c_read(dev, buffer, (u16)size) < 0 ? -eremoteio : 0; +#ifdef __big_endian + if (status == 0) + convert_endian(size, buffer); +#endif + } else { + status = -eremoteio; + } + + mutex_unlock(&dev->i2c_lock); + + if (status) + dev_dbg(&dev->i2c_client->dev, "err %d ", status); + + return status; +} + +static const char *mxl692_opcode_string(u8 opcode) +{ + if (opcode >= 0 && opcode <= mxl_eagle_opcode_internal) + return mxl_eagle_opcode_string[opcode]; + + return "invalid opcode"; +} + +static int mxl692_opwrite(struct mxl692_dev *dev, u8 *buffer, + u32 size) +{ + int status = 0, total_len = 0; + u8 local_buf[mxl_eagle_max_i2c_packet_size] = {}, *plocal_buf = null; + struct mxl_eagle_host_msg_header_t *tx_hdr = (struct mxl_eagle_host_msg_header_t *)buffer; + + total_len = size; + total_len = (total_len + 3) & ~3; /* 4 byte alignment */ + + if (total_len > (mxl_eagle_max_i2c_packet_size - mxl_eagle_i2c_pheader_size)) + dev_dbg(&dev->i2c_client->dev, "hrmph? "); + + plocal_buf = local_buf; + + *plocal_buf++ = 0xfe; + *plocal_buf++ = (u8)total_len; + + memcpy(plocal_buf, buffer, total_len); + convert_endian(total_len, plocal_buf); + + if (mxl692_i2c_write(dev, local_buf, + (total_len + mxl_eagle_i2c_pheader_size)) < 0) { + status = -eremoteio; + goto err_finish; + } +err_finish: + if (status) + dev_dbg(&dev->i2c_client->dev, "opcode %s err %d ", + mxl692_opcode_string(tx_hdr->opcode), status); + return status; +} + +static int mxl692_opread(struct mxl692_dev *dev, u8 *buffer, + u32 size) +{ + int status = 0; + u32 ix = 0; + u8 local_buf[mxl_eagle_i2c_pheader_size] = {}; + + local_buf[0] = 0xfd; + local_buf[1] = 0; + + if (mxl692_i2c_write(dev, local_buf, mxl_eagle_i2c_pheader_size) > 0) { + size = (size + 3) & ~3; /* 4 byte alignment */ + + /* read in 4 byte chunks */ + for (ix = 0; ix < size; ix += 4) { + if (mxl692_i2c_read(dev, buffer + ix, 4) < 0) { + dev_dbg(&dev->i2c_client->dev, "ix=%d size=%d ", ix, size); + status = -eremoteio; + goto err_finish; + } + } + convert_endian(size, buffer); + } else { + status = -eremoteio; + } +err_finish: + if (status) + dev_dbg(&dev->i2c_client->dev, "err %d ", status); + return status; +} + +static int mxl692_i2c_writeread(struct mxl692_dev *dev, + u8 opcode, + u8 *tx_payload, + u8 tx_payload_size, + u8 *rx_payload, + u8 rx_payload_expected) +{ + int status = 0, timeout = 40; + u8 tx_buf[mxl_eagle_max_i2c_packet_size] = {}; + u8 rx_buf[mxl_eagle_max_i2c_packet_size] = {}; + u32 resp_checksum = 0, resp_checksum_tmp = 0; + struct mxl_eagle_host_msg_header_t *tx_header; + struct mxl_eagle_host_msg_header_t *rx_header; + + mutex_lock(&dev->i2c_lock); + + if ((tx_payload_size + mxl_eagle_host_msg_header_size) > + (mxl_eagle_max_i2c_packet_size - mxl_eagle_i2c_pheader_size)) { + status = -einval; + goto err_finish; + } + + tx_header = (struct mxl_eagle_host_msg_header_t *)tx_buf; + tx_header->opcode = opcode; + tx_header->seqnum = dev->seqnum++; + tx_header->payload_size = tx_payload_size; + tx_header->checksum = 0; + + if (dev->seqnum == 0) + dev->seqnum = 1; + + if (tx_payload && tx_payload_size > 0) + memcpy(&tx_buf[mxl_eagle_host_msg_header_size], tx_payload, tx_payload_size); + + mxl692_tx_swap(opcode, tx_buf); + + tx_header->checksum = 0; + tx_header->checksum = mxl692_checksum(tx_buf, + mxl_eagle_host_msg_header_size + tx_payload_size); +#ifdef __little_endian + convert_endian(4, (u8 *)&tx_header->checksum); /* cksum is big endian */ +#endif + /* send tx message */ + status = mxl692_opwrite(dev, tx_buf, + tx_payload_size + mxl_eagle_host_msg_header_size); + if (status) { + status = -eremoteio; + goto err_finish; + } + + /* receive rx message (polling) */ + rx_header = (struct mxl_eagle_host_msg_header_t *)rx_buf; + + do { + status = mxl692_opread(dev, rx_buf, + rx_payload_expected + mxl_eagle_host_msg_header_size); + usleep_range(1000, 2000); + timeout--; + } while ((timeout > 0) && (status == 0) && + (rx_header->seqnum == 0) && + (rx_header->checksum == 0)); + + if (timeout == 0 || status) { + dev_dbg(&dev->i2c_client->dev, "timeout=%d status=%d ", + timeout, status); + status = -etimedout; + goto err_finish; + } + + if (rx_header->status) { + dev_dbg(&dev->i2c_client->dev, "rx header status code: %d ", rx_header->status); + status = -eremoteio; + goto err_finish; + } + + if (rx_header->seqnum != tx_header->seqnum || + rx_header->opcode != tx_header->opcode || + rx_header->payload_size != rx_payload_expected) { + dev_dbg(&dev->i2c_client->dev, "something failed seq=%s opcode=%s psize=%s ", + rx_header->seqnum != tx_header->seqnum ? "x" : "0", + rx_header->opcode != tx_header->opcode ? "x" : "0", + rx_header->payload_size != rx_payload_expected ? "x" : "0"); + if (rx_header->payload_size != rx_payload_expected) + dev_dbg(&dev->i2c_client->dev, + "rx_header->payloadsize=%d rx_payload_expected=%d ", + rx_header->payload_size, rx_payload_expected); + status = -eremoteio; + goto err_finish; + } + + resp_checksum = rx_header->checksum; + rx_header->checksum = 0; + + resp_checksum_tmp = mxl692_checksum(rx_buf, + mxl_eagle_host_msg_header_size + rx_header->payload_size); +#ifdef __little_endian + convert_endian(4, (u8 *)&resp_checksum_tmp); /* cksum is big endian */ +#endif + if (resp_checksum != resp_checksum_tmp) { + dev_dbg(&dev->i2c_client->dev, "rx checksum failure "); + status = -eremoteio; + goto err_finish; + } + + mxl692_rx_swap(rx_header->opcode, rx_buf); + + if (rx_header->payload_size > 0) { + if (!rx_payload) { + dev_dbg(&dev->i2c_client->dev, "no rx payload?!? "); + status = -eremoteio; + goto err_finish; + } + memcpy(rx_payload, rx_buf + mxl_eagle_host_msg_header_size, + rx_header->payload_size); + } +err_finish: + if (status) + dev_dbg(&dev->i2c_client->dev, "err %d ", status); + + mutex_unlock(&dev->i2c_lock); + return status; +} + +static int mxl692_fwdownload(struct mxl692_dev *dev, + const u8 *firmware_buf, u32 buf_len) +{ + int status = 0; + u32 ix, reg_val = 0x1; + u8 rx_buf[mxl_eagle_max_i2c_packet_size] = {}; + struct mxl_eagle_dev_status_t *dev_status; + + if (buf_len < mxl_eagle_fw_header_size || + buf_len > mxl_eagle_fw_max_size_in_kb * 1000) + return -einval; + + mutex_lock(&dev->i2c_lock); + + dev_dbg(&dev->i2c_client->dev, " "); + + status = mxl692_validate_fw_header(dev, firmware_buf, buf_len); + if (status) + goto err_finish; + + ix = 16; + status = mxl692_write_fw_block(dev, firmware_buf, buf_len, &ix); /* dram */ + if (status) + goto err_finish; + + status = mxl692_write_fw_block(dev, firmware_buf, buf_len, &ix); /* iram */ + if (status) + goto err_finish; + + /* release cpu from reset */ + status = mxl692_memwrite(dev, 0x70000018, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + mutex_unlock(&dev->i2c_lock); + + if (status == 0) { + /* verify fw is alive */ + usleep_range(mxl_eagle_fw_load_time * 1000, (mxl_eagle_fw_load_time + 5) * 1000); + dev_status = (struct mxl_eagle_dev_status_t *)&rx_buf; + status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_device_status_get, + null, + 0, + (u8 *)dev_status, + sizeof(struct mxl_eagle_dev_status_t)); + } + + return status; +err_finish: + mutex_unlock(&dev->i2c_lock); + if (status) + dev_dbg(&dev->i2c_client->dev, "err %d ", status); + return status; +} + +static int mxl692_get_versions(struct mxl692_dev *dev) +{ + int status = 0; + struct mxl_eagle_dev_ver_t dev_ver = {}; + static const char * const chip_id[] = {"n/a", "691", "248", "692"}; + + status = mxl692_i2c_writeread(dev, mxl_eagle_opcode_device_version_get, + null, + 0, + (u8 *)&dev_ver, + sizeof(struct mxl_eagle_dev_ver_t)); + if (status) + return status; + + dev_info(&dev->i2c_client->dev, "mxl692_demod chip id: %s ", + chip_id[dev_ver.chip_id]); + + dev_info(&dev->i2c_client->dev, + "mxl692_demod fw version: %d.%d.%d.%d_rc%d ", + dev_ver.firmware_ver[0], + dev_ver.firmware_ver[1], + dev_ver.firmware_ver[2], + dev_ver.firmware_ver[3], + dev_ver.firmware_ver[4]); + + return status; +} + +static int mxl692_reset(struct mxl692_dev *dev) +{ + int status = 0; + u32 dev_type = mxl_eagle_device_max, reg_val = 0x2; + + dev_dbg(&dev->i2c_client->dev, " "); + + /* legacy i2c override */ + status = mxl692_memwrite(dev, 0x80000100, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + /* verify sku */ + status = mxl692_memread(dev, 0x70000188, (u8 *)&dev_type, sizeof(u32)); + if (status) + goto err_finish; + + if (dev_type != dev->device_type) + goto err_finish; + +err_finish: + if (status) + dev_dbg(&dev->i2c_client->dev, "err %d ", status); + return status; +} + +static int mxl692_config_regulators(struct mxl692_dev *dev, + enum mxl_eagle_power_supply_source_e power_supply) +{ + int status = 0; + u32 reg_val; + + dev_dbg(&dev->i2c_client->dev, " "); + + /* configure main regulator according to the power supply source */ + status = mxl692_memread(dev, 0x90000000, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + reg_val &= 0x00ffffff; + reg_val |= (power_supply == mxl_eagle_power_supply_source_single) ? + 0x14000000 : 0x10000000; + + status = mxl692_memwrite(dev, 0x90000000, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + /* configure digital regulator to high current mode */ + status = mxl692_memread(dev, 0x90000018, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + reg_val |= 0x800; + + status = mxl692_memwrite(dev, 0x90000018, (u8 *)&reg_val, sizeof(u32)); + +err_finish: + if (status) + dev_dbg(&dev->i2c_client->dev, "err %d ", status); + return status; +} + +static int mxl692_config_xtal(struct mxl692_dev *dev, + struct mxl_eagle_dev_xtal_t *dev_xtal) +{ + int status = 0; + u32 reg_val, reg_val1; + + dev_dbg(&dev->i2c_client->dev, " "); + + status = mxl692_memread(dev, 0x90000000, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + /* set xtal capacitance */ + reg_val &= 0xffffffe0; + reg_val |= dev_xtal->xtal_cap; + + /* set clk out */ + reg_val = dev_xtal->clk_out_enable ? (reg_val | 0x0100) : (reg_val & 0xfffffeff); + + status = mxl692_memwrite(dev, 0x90000000, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + /* set clk out divider */ + reg_val = dev_xtal->clk_out_div_enable ? (reg_val | 0x0200) : (reg_val & 0xfffffdff); + + status = mxl692_memwrite(dev, 0x90000000, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + /* set xtal sharing */ + reg_val = dev_xtal->xtal_sharing_enable ? (reg_val | 0x010400) : (reg_val & 0xfffefbff); + + status = mxl692_memwrite(dev, 0x90000000, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + /* enable/disable xtal calibration, based on master/slave device */ + status = mxl692_memread(dev, 0x90000030, (u8 *)&reg_val1, sizeof(u32)); + if (status) + goto err_finish; + + if (dev_xtal->xtal_calibration_enable) { + /* enable xtal calibration and set xtal amplitude to a higher value */ + reg_val1 &= 0xfffffffd; + reg_val1 |= 0x30; + + status = mxl692_memwrite(dev, 0x90000030, (u8 *)&reg_val1, sizeof(u32)); + if (status) + goto err_finish; + } else { + /* disable xtal calibration */ + reg_val1 |= 0x2; + + status = mxl692_memwrite(dev, 0x90000030, (u8 *)&reg_val1, sizeof(u32)); + if (status) + goto err_finish; + + /* set xtal bias value */ + status = mxl692_memread(dev, 0x9000002c, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + reg_val &= 0xc0ffffff; + reg_val |= 0xa000000; + + status = mxl692_memwrite(dev, 0x9000002c, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + } + + /* start xtal calibration */ + status = mxl692_memread(dev, 0x70000010, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + reg_val |= 0x8; + + status = mxl692_memwrite(dev, 0x70000010, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + status = mxl692_memread(dev, 0x70000018, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + reg_val |= 0x10; + + status = mxl692_memwrite(dev, 0x70000018, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + status = mxl692_memread(dev, 0x9001014c, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + reg_val &= 0xffffefff; + + status = mxl692_memwrite(dev, 0x9001014c, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + reg_val |= 0x1000; + + status = mxl692_memwrite(dev, 0x9001014c, (u8 *)&reg_val, sizeof(u32)); + if (status) + goto err_finish; + + usleep_range(45000, 55000); + +err_finish: + if (status) + dev_dbg(&dev->i2c_client->dev, "err %d ", status); + return status; +} + +static int mxl692_powermode(struct mxl692_dev *dev, + enum mxl_eagle_power_mode_e power_mode) +{ + int status = 0; + u8 mode = power_mode; + + dev_dbg(&dev->i2c_client->dev, "%s ", + power_mode == mxl_eagle_power_mode_sleep ? "sleep" : "active"); + + status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_device_powermode_set, + &mode, + sizeof(u8), + null, + 0); + if (status) { + dev_dbg(&dev->i2c_client->dev, "err %d ", status); + return status; + } + + dev->power_mode = power_mode; + + return status; +} + +static int mxl692_init(struct dvb_frontend *fe) +{ + struct mxl692_dev *dev = fe->demodulator_priv; + struct i2c_client *client = dev->i2c_client; + struct dtv_frontend_properties *c = &fe->dtv_property_cache; + int status = 0; + const struct firmware *firmware; + struct mxl_eagle_dev_xtal_t xtal_config = {}; + + dev_dbg(&dev->i2c_client->dev, " "); + + if (dev->init_done) + goto warm; + + dev->seqnum = 1; + + status = mxl692_reset(dev); + if (status) + goto err; + + usleep_range(50 * 1000, 60 * 1000); /* was 1000! */ + + status = mxl692_config_regulators(dev, mxl_eagle_power_supply_source_dual); + if (status) + goto err; + + xtal_config.xtal_cap = 26; + xtal_config.clk_out_div_enable = 0; + xtal_config.clk_out_enable = 0; + xtal_config.xtal_calibration_enable = 0; + xtal_config.xtal_sharing_enable = 1; + status = mxl692_config_xtal(dev, &xtal_config); + if (status) + goto err; + + status = request_firmware(&firmware, mxl692_firmware, &client->dev); + if (status) { + dev_dbg(&dev->i2c_client->dev, "firmware missing? %s ", + mxl692_firmware); + goto err; + } + + status = mxl692_fwdownload(dev, firmware->data, firmware->size); + if (status) + goto err_release_firmware; + + release_firmware(firmware); + + status = mxl692_get_versions(dev); + if (status) + goto err; + + dev->power_mode = mxl_eagle_power_mode_sleep; +warm: + /* config device power mode */ + if (dev->power_mode != mxl_eagle_power_mode_active) { + status = mxl692_powermode(dev, mxl_eagle_power_mode_active); + if (status) + goto err; + + usleep_range(50 * 1000, 60 * 1000); /* was 500! */ + } + + /* init stats here to indicate which stats are supported */ + c->cnr.len = 1; + c->cnr.stat[0].scale = fe_scale_not_available; + c->post_bit_error.len = 1; + c->post_bit_error.stat[0].scale = fe_scale_not_available; + c->post_bit_count.len = 1; + c->post_bit_count.stat[0].scale = fe_scale_not_available; + c->block_error.len = 1; + c->block_error.stat[0].scale = fe_scale_not_available; + + dev->init_done = 1; + return 0; +err_release_firmware: + release_firmware(firmware); +err: + dev_dbg(&dev->i2c_client->dev, "err %d ", status); + return status; +} + +static int mxl692_sleep(struct dvb_frontend *fe) +{ + struct mxl692_dev *dev = fe->demodulator_priv; + + if (dev->power_mode != mxl_eagle_power_mode_sleep) + mxl692_powermode(dev, mxl_eagle_power_mode_sleep); + + return 0; +} + +static int mxl692_set_frontend(struct dvb_frontend *fe) +{ + struct dtv_frontend_properties *p = &fe->dtv_property_cache; + struct mxl692_dev *dev = fe->demodulator_priv; + + int status = 0; + enum mxl_eagle_demod_type_e demod_type; + struct mxl_eagle_mpegout_params_t mpeg_params = {}; + enum mxl_eagle_qam_demod_annex_type_e qam_annex = mxl_eagle_qam_demod_annex_b; + struct mxl_eagle_qam_demod_params_t qam_params = {}; + struct mxl_eagle_tuner_channel_params_t tuner_params = {}; + u8 op_param = 0; + + dev_dbg(&dev->i2c_client->dev, " "); + + switch (p->modulation) { + case vsb_8: + demod_type = mxl_eagle_demod_type_atsc; + break; + case qam_auto: + case qam_64: + case qam_128: + case qam_256: + demod_type = mxl_eagle_demod_type_qam; + break; + default: + return -einval; + } + + if (dev->current_frequency == p->frequency && dev->demod_type == demod_type) { + dev_dbg(&dev->i2c_client->dev, "already set up "); + return 0; + } + + dev->current_frequency = -1; + dev->demod_type = -1; + + op_param = demod_type; + status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_device_demodulator_type_set, + &op_param, + sizeof(u8), + null, + 0); + if (status) { + dev_dbg(&dev->i2c_client->dev, + "device_demodulator_type_set...fail err 0x%x ", status); + goto err; + } + + usleep_range(20 * 1000, 30 * 1000); /* was 500! */ + + mpeg_params.mpeg_parallel = 0; + mpeg_params.msb_first = mxl_eagle_data_serial_msb_1st; + mpeg_params.mpeg_sync_pulse_width = mxl_eagle_data_sync_width_bit; + mpeg_params.mpeg_valid_pol = mxl_eagle_clock_positive; + mpeg_params.mpeg_sync_pol = mxl_eagle_clock_positive; + mpeg_params.mpeg_clk_pol = mxl_eagle_clock_negative; + mpeg_params.mpeg3wire_mode_enable = 0; + mpeg_params.mpeg_clk_freq = mxl_eagle_mpeg_clock_27mhz; + + switch (demod_type) { + case mxl_eagle_demod_type_atsc: + status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_device_mpeg_out_params_set, + (u8 *)&mpeg_params, + sizeof(struct mxl_eagle_mpegout_params_t), + null, + 0); + if (status) + goto err; + break; + case mxl_eagle_demod_type_qam: + if (qam_annex == mxl_eagle_qam_demod_annex_a) + mpeg_params.msb_first = mxl_eagle_data_serial_lsb_1st; + status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_device_mpeg_out_params_set, + (u8 *)&mpeg_params, + sizeof(struct mxl_eagle_mpegout_params_t), + null, + 0); + if (status) + goto err; + + qam_params.annex_type = qam_annex; + qam_params.qam_type = mxl_eagle_qam_demod_auto; + qam_params.iq_flip = mxl_eagle_demod_iq_auto; + if (p->modulation == qam_64) + qam_params.symbol_rate_hz = 5057000; + else + qam_params.symbol_rate_hz = 5361000; + + qam_params.symbol_rate_256qam_hz = 5361000; + + status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_qam_params_set, + (u8 *)&qam_params, + sizeof(struct mxl_eagle_qam_demod_params_t), + null, 0); + if (status) + goto err; + + break; + default: + break; + } + + usleep_range(20 * 1000, 30 * 1000); /* was 500! */ + + tuner_params.freq_hz = p->frequency; + tuner_params.bandwidth = mxl_eagle_tuner_bw_6mhz; + tuner_params.tune_mode = mxl_eagle_tuner_channel_tune_mode_view; + + dev_dbg(&dev->i2c_client->dev, " tuning freq: %d %s ", tuner_params.freq_hz, + demod_type == mxl_eagle_demod_type_atsc ? "atsc" : "qam"); + + status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_tuner_channel_tune_set, + (u8 *)&tuner_params, + sizeof(struct mxl_eagle_tuner_channel_params_t), + null, + 0); + if (status) + goto err; + + usleep_range(20 * 1000, 30 * 1000); /* was 500! */ + + switch (demod_type) { + case mxl_eagle_demod_type_atsc: + status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_atsc_init_set, + null, 0, null, 0); + if (status) + goto err; + break; + case mxl_eagle_demod_type_qam: + status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_qam_restart_set, + null, 0, null, 0); + if (status) + goto err; + break; + default: + break; + } + + dev->demod_type = demod_type; + dev->current_frequency = p->frequency; + + return 0; +err: + dev_dbg(&dev->i2c_client->dev, "err %d ", status); + return status; +} + +static int mxl692_get_frontend(struct dvb_frontend *fe, + struct dtv_frontend_properties *p) +{ + struct dtv_frontend_properties *c = &fe->dtv_property_cache; + + p->modulation = c->modulation; + p->frequency = c->frequency; + + return 0; +} + +static int mxl692_read_snr(struct dvb_frontend *fe, u16 *snr) +{ + struct mxl692_dev *dev = fe->demodulator_priv; + struct dtv_frontend_properties *c = &fe->dtv_property_cache; + u8 rx_buf[mxl_eagle_max_i2c_packet_size] = {}; + struct mxl_eagle_atsc_demod_status_t *atsc_status; + struct mxl_eagle_qam_demod_status_t *qam_status; + enum mxl_eagle_demod_type_e demod_type = dev->demod_type; + int mxl_status = 0; + + *snr = 0; + + dev_dbg(&dev->i2c_client->dev, " "); + + atsc_status = (struct mxl_eagle_atsc_demod_status_t *)&rx_buf; + qam_status = (struct mxl_eagle_qam_demod_status_t *)&rx_buf; + + switch (demod_type) { + case mxl_eagle_demod_type_atsc: + mxl_status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_atsc_status_get, + null, + 0, + rx_buf, + sizeof(struct mxl_eagle_atsc_demod_status_t)); + if (!mxl_status) { + *snr = (u16)(atsc_status->snr_db_tenths / 10); + c->cnr.stat[0].scale = fe_scale_decibel; + c->cnr.stat[0].svalue = *snr; + } + break; + case mxl_eagle_demod_type_qam: + mxl_status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_qam_status_get, + null, + 0, + rx_buf, + sizeof(struct mxl_eagle_qam_demod_status_t)); + if (!mxl_status) + *snr = (u16)(qam_status->snr_db_tenths / 10); + break; + case mxl_eagle_demod_type_oob: + default: + break; + } + + if (mxl_status) + dev_dbg(&dev->i2c_client->dev, "err %d ", mxl_status); + return mxl_status; +} + +static int mxl692_read_ber_ucb(struct dvb_frontend *fe) +{ + struct mxl692_dev *dev = fe->demodulator_priv; + struct dtv_frontend_properties *c = &fe->dtv_property_cache; + u8 rx_buf[mxl_eagle_max_i2c_packet_size] = {}; + struct mxl_eagle_atsc_demod_error_counters_t *atsc_errors; + enum mxl_eagle_demod_type_e demod_type = dev->demod_type; + int mxl_status = 0; + u32 utmp; + + dev_dbg(&dev->i2c_client->dev, " "); + + atsc_errors = (struct mxl_eagle_atsc_demod_error_counters_t *)&rx_buf; + + switch (demod_type) { + case mxl_eagle_demod_type_atsc: + mxl_status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_atsc_error_counters_get, + null, + 0, + rx_buf, + sizeof(struct mxl_eagle_atsc_demod_error_counters_t)); + if (!mxl_status) { + if (atsc_errors->error_packets == 0) + utmp = 0; + else + utmp = ((atsc_errors->error_bytes / atsc_errors->error_packets) * + atsc_errors->total_packets); + /* ber */ + c->post_bit_error.stat[0].scale = fe_scale_counter; + c->post_bit_error.stat[0].uvalue += atsc_errors->error_bytes; + c->post_bit_count.stat[0].scale = fe_scale_counter; + c->post_bit_count.stat[0].uvalue += utmp; + /* ucb */ + c->block_error.stat[0].scale = fe_scale_counter; + c->block_error.stat[0].uvalue += atsc_errors->error_packets; + + dev_dbg(&dev->i2c_client->dev, "%llu %llu ", + c->post_bit_count.stat[0].uvalue, c->block_error.stat[0].uvalue); + } + break; + case mxl_eagle_demod_type_qam: + case mxl_eagle_demod_type_oob: + default: + break; + } + + if (mxl_status) + dev_dbg(&dev->i2c_client->dev, "err %d ", mxl_status); + + return mxl_status; +} + +static int mxl692_read_status(struct dvb_frontend *fe, + enum fe_status *status) +{ + struct mxl692_dev *dev = fe->demodulator_priv; + struct dtv_frontend_properties *c = &fe->dtv_property_cache; + u8 rx_buf[mxl_eagle_max_i2c_packet_size] = {}; + struct mxl_eagle_atsc_demod_status_t *atsc_status; + struct mxl_eagle_qam_demod_status_t *qam_status; + enum mxl_eagle_demod_type_e demod_type = dev->demod_type; + int mxl_status = 0; + *status = 0; + + dev_dbg(&dev->i2c_client->dev, " "); + + atsc_status = (struct mxl_eagle_atsc_demod_status_t *)&rx_buf; + qam_status = (struct mxl_eagle_qam_demod_status_t *)&rx_buf; + + switch (demod_type) { + case mxl_eagle_demod_type_atsc: + mxl_status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_atsc_status_get, + null, + 0, + rx_buf, + sizeof(struct mxl_eagle_atsc_demod_status_t)); + if (!mxl_status && atsc_status->atsc_lock) { + *status |= fe_has_signal; + *status |= fe_has_carrier; + *status |= fe_has_viterbi; + *status |= fe_has_sync; + *status |= fe_has_lock; + + c->cnr.stat[0].scale = fe_scale_decibel; + c->cnr.stat[0].svalue = atsc_status->snr_db_tenths / 10; + } + break; + case mxl_eagle_demod_type_qam: + mxl_status = mxl692_i2c_writeread(dev, + mxl_eagle_opcode_qam_status_get, + null, + 0, + rx_buf, + sizeof(struct mxl_eagle_qam_demod_status_t)); + if (!mxl_status && qam_status->qam_locked) { + *status |= fe_has_signal; + *status |= fe_has_carrier; + *status |= fe_has_viterbi; + *status |= fe_has_sync; + *status |= fe_has_lock; + + c->cnr.stat[0].scale = fe_scale_decibel; + c->cnr.stat[0].svalue = qam_status->snr_db_tenths / 10; + } + break; + case mxl_eagle_demod_type_oob: + default: + break; + } + + if ((*status & fe_has_lock) == 0) { + /* no lock, reset all statistics */ + c->cnr.len = 1; + c->cnr.stat[0].scale = fe_scale_not_available; + c->block_error.stat[0].scale = fe_scale_not_available; + c->post_bit_error.stat[0].scale = fe_scale_not_available; + c->post_bit_count.stat[0].scale = fe_scale_not_available; + return 0; + } + + if (mxl_status) + dev_dbg(&dev->i2c_client->dev, "err %d ", mxl_status); + else + mxl_status = mxl692_read_ber_ucb(fe); + + return mxl_status; +} + +static const struct dvb_frontend_ops mxl692_ops = { + .delsys = { sys_atsc }, + .info = { + .name = "maxlinear mxl692 vsb tuner-demodulator", + .frequency_min_hz = 54000000, + .frequency_max_hz = 858000000, + .frequency_stepsize_hz = 62500, + .caps = fe_can_8vsb + }, + + .init = mxl692_init, + .sleep = mxl692_sleep, + .set_frontend = mxl692_set_frontend, + .get_frontend = mxl692_get_frontend, + + .read_status = mxl692_read_status, + .read_snr = mxl692_read_snr, +}; + +static int mxl692_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct mxl692_config *config = client->dev.platform_data; + struct mxl692_dev *dev; + int ret = 0; + + dev = kzalloc(sizeof(*dev), gfp_kernel); + if (!dev) { + ret = -enomem; + dev_dbg(&client->dev, "kzalloc() failed "); + goto err; + } + + memcpy(&dev->fe.ops, &mxl692_ops, sizeof(struct dvb_frontend_ops)); + dev->fe.demodulator_priv = dev; + dev->i2c_client = client; + *config->fe = &dev->fe; + mutex_init(&dev->i2c_lock); + i2c_set_clientdata(client, dev); + + dev_info(&client->dev, "maxlinear mxl692 successfully attached "); + + return 0; +err: + dev_dbg(&client->dev, "failed %d ", ret); + return -enodev; +} + +static int mxl692_remove(struct i2c_client *client) +{ + struct mxl692_dev *dev = i2c_get_clientdata(client); + + dev->fe.demodulator_priv = null; + i2c_set_clientdata(client, null); + kfree(dev); + + return 0; +} + +static const struct i2c_device_id mxl692_id_table[] = { + {"mxl692", 0}, + {} +}; +module_device_table(i2c, mxl692_id_table); + +static struct i2c_driver mxl692_driver = { + .driver = { + .name = "mxl692", + }, + .probe = mxl692_probe, + .remove = mxl692_remove, + .id_table = mxl692_id_table, +}; + +module_i2c_driver(mxl692_driver); + +module_author("brad love <brad@nextdimension.cc>"); +module_description("maxlinear mxl692 demodulator/tuner driver"); +module_firmware(mxl692_firmware); +module_license("gpl"); diff --git a/drivers/media/dvb-frontends/mxl692.h b/drivers/media/dvb-frontends/mxl692.h --- /dev/null +++ b/drivers/media/dvb-frontends/mxl692.h +/* spdx-license-identifier: gpl-2.0 */ +/* + * driver for the maxlinear mxl69x family of tuners/demods + * + * copyright (c) 2020 brad love <brad@nextdimension.cc> + * + * based on code: + * copyright (c) 2016 maxlinear, inc. all rights reserved + * which was released under gpl v2 + * + * this program is free software; you can redistribute it and/or + * modify it under the terms of the gnu general public license + * version 2, as published by the free software foundation. + * + * this program is distributed in the hope that it will be useful, + * but without any warranty; without even the implied warranty of + * merchantability or fitness for a particular purpose. see the + * gnu general public license for more details. + */ + +#ifndef _mxl692_h_ +#define _mxl692_h_ + +#include <media/dvb_frontend.h> + +#define mxl692_firmware "dvb-demod-mxl692.fw" + +struct mxl692_config { + unsigned char id; + u8 i2c_addr; + /* + * frontend + * returned by driver + */ + struct dvb_frontend **fe; +}; + +#endif /* _mxl692_h_ */ diff --git a/drivers/media/dvb-frontends/mxl692_defs.h b/drivers/media/dvb-frontends/mxl692_defs.h --- /dev/null +++ b/drivers/media/dvb-frontends/mxl692_defs.h +/* spdx-license-identifier: gpl-2.0 */ +/* + * driver for the maxlinear mxl69x family of combo tuners/demods + * + * copyright (c) 2020 brad love <brad@nextdimension.cc> + * + * based on code: + * copyright (c) 2016 maxlinear, inc. all rights reserved + * which was released under gpl v2 + * + * this program is free software; you can redistribute it and/or + * modify it under the terms of the gnu general public license + * version 2, as published by the free software foundation. + * + * this program is distributed in the hope that it will be useful, + * but without any warranty; without even the implied warranty of + * merchantability or fitness for a particular purpose. see the + * gnu general public license for more details. + */ + +/***************************************************************************** + * defines + ***************************************************************************** + */ +#define mxl_eagle_host_msg_header_size 8 +#define mxl_eagle_fw_max_size_in_kb 76 +#define mxl_eagle_qam_ffe_taps_length 16 +#define mxl_eagle_qam_spur_taps_length 32 +#define mxl_eagle_qam_dfe_taps_length 72 +#define mxl_eagle_atsc_ffe_taps_length 4096 +#define mxl_eagle_atsc_dfe_taps_length 384 +#define mxl_eagle_version_size 5 /* a.b.c.d-rcx */ +#define mxl_eagle_fw_load_time 50 + +#define mxl_eagle_fw_max_size_in_kb 76 +#define mxl_eagle_fw_header_size 16 +#define mxl_eagle_fw_segment_header_size 8 +#define mxl_eagle_max_i2c_packet_size 58 +#define mxl_eagle_i2c_mheader_size 6 +#define mxl_eagle_i2c_pheader_size 2 + +/* enum of eagle family devices */ +enum mxl_eagle_device_e { + mxl_eagle_device_691 = 1, /* device mxl691 */ + mxl_eagle_device_248 = 2, /* device mxl248 */ + mxl_eagle_device_692 = 3, /* device mxl692 */ + mxl_eagle_device_max, /* no such device */ +}; + +#define ver_a 1 +#define ver_b 1 +#define ver_c 1 +#define ver_d 3 +#define ver_e 6 + +/* enum of host to eagle i2c protocol opcodes */ +enum mxl_eagle_opcode_e { + /* device */ + mxl_eagle_opcode_device_demodulator_type_set, + mxl_eagle_opcode_device_mpeg_out_params_set, + mxl_eagle_opcode_device_powermode_set, + mxl_eagle_opcode_device_gpio_direction_set, + mxl_eagle_opcode_device_gpo_level_set, + mxl_eagle_opcode_device_intr_mask_set, + mxl_eagle_opcode_device_io_mux_set, + mxl_eagle_opcode_device_version_get, + mxl_eagle_opcode_device_status_get, + mxl_eagle_opcode_device_gpi_level_get, + + /* tuner */ + mxl_eagle_opcode_tuner_channel_tune_set, + mxl_eagle_opcode_tuner_lock_status_get, + mxl_eagle_opcode_tuner_agc_status_get, + + /* atsc */ + mxl_eagle_opcode_atsc_init_set, + mxl_eagle_opcode_atsc_acquire_carrier_set, + mxl_eagle_opcode_atsc_status_get, + mxl_eagle_opcode_atsc_error_counters_get, + mxl_eagle_opcode_atsc_equalizer_filter_dfe_taps_get, + mxl_eagle_opcode_atsc_equalizer_filter_ffe_taps_get, + + /* qam */ + mxl_eagle_opcode_qam_params_set, + mxl_eagle_opcode_qam_restart_set, + mxl_eagle_opcode_qam_status_get, + mxl_eagle_opcode_qam_error_counters_get, + mxl_eagle_opcode_qam_constellation_value_get, + mxl_eagle_opcode_qam_equalizer_filter_ffe_get, + mxl_eagle_opcode_qam_equalizer_filter_spur_start_get, + mxl_eagle_opcode_qam_equalizer_filter_spur_end_get, + mxl_eagle_opcode_qam_equalizer_filter_dfe_taps_number_get, + mxl_eagle_opcode_qam_equalizer_filter_dfe_start_get, + mxl_eagle_opcode_qam_equalizer_filter_dfe_middle_get, + mxl_eagle_opcode_qam_equalizer_filter_dfe_end_get, + + /* oob */ + mxl_eagle_opcode_oob_params_set, + mxl_eagle_opcode_oob_restart_set, + mxl_eagle_opcode_oob_error_counters_get, + mxl_eagle_opcode_oob_status_get, + + /* sma */ + mxl_eagle_opcode_sma_init_set, + mxl_eagle_opcode_sma_params_set, + mxl_eagle_opcode_sma_transmit_set, + mxl_eagle_opcode_sma_receive_get, + + /* debug */ + mxl_eagle_opcode_internal, + + mxl_eagle_opcode_max = 70, +}; + +/* enum of host to eagle i2c protocol opcodes */ +static const char * const mxl_eagle_opcode_string[] = { + /* device */ + "device_demodulator_type_set", + "device_mpeg_out_params_set", + "device_powermode_set", + "device_gpio_direction_set", + "device_gpo_level_set", + "device_intr_mask_set", + "device_io_mux_set", + "device_version_get", + "device_status_get", + "device_gpi_level_get", + + /* tuner */ + "tuner_channel_tune_set", + "tuner_lock_status_get", + "tuner_agc_status_get", + + /* atsc */ + "atsc_init_set", + "atsc_acquire_carrier_set", + "atsc_status_get", + "atsc_error_counters_get", + "atsc_equalizer_filter_dfe_taps_get", + "atsc_equalizer_filter_ffe_taps_get", + + /* qam */ + "qam_params_set", + "qam_restart_set", + "qam_status_get", + "qam_error_counters_get", + "qam_constellation_value_get", + "qam_equalizer_filter_ffe_get", + "qam_equalizer_filter_spur_start_get", + "qam_equalizer_filter_spur_end_get", + "qam_equalizer_filter_dfe_taps_number_get", + "qam_equalizer_filter_dfe_start_get", + "qam_equalizer_filter_dfe_middle_get", + "qam_equalizer_filter_dfe_end_get", + + /* oob */ + "oob_params_set", + "oob_restart_set", + "oob_error_counters_get", + "oob_status_get", + + /* sma */ + "sma_init_set", + "sma_params_set", + "sma_transmit_set", + "sma_receive_get", + + /* debug */ + "internal", +}; + +/* enum of callabck function types */ +enum mxl_eagle_cb_type_e { + mxl_eagle_cb_fw_download = 0, +}; + +/* enum of power supply types */ +enum mxl_eagle_power_supply_source_e { + mxl_eagle_power_supply_source_single, /* single supply of 3.3v */ + mxl_eagle_power_supply_source_dual, /* dual supply, 1.8v & 3.3v */ +}; + +/* enum of i/o pad drive modes */ +enum mxl_eagle_io_mux_drive_mode_e { + mxl_eagle_io_mux_drive_mode_1x, + mxl_eagle_io_mux_drive_mode_2x, + mxl_eagle_io_mux_drive_mode_3x, + mxl_eagle_io_mux_drive_mode_4x, + mxl_eagle_io_mux_drive_mode_5x, + mxl_eagle_io_mux_drive_mode_6x, + mxl_eagle_io_mux_drive_mode_7x, + mxl_eagle_io_mux_drive_mode_8x, +}; + +/* enum of demodulator types. used for selection of demodulator + * type in relevant devices, e.g. atsc vs. qam in mxl691 + */ +enum mxl_eagle_demod_type_e { + mxl_eagle_demod_type_qam, /* mxl248 or mxl692 */ + mxl_eagle_demod_type_oob, /* mxl248 only */ + mxl_eagle_demod_type_atsc /* mxl691 or mxl692 */ +}; + +/* enum of power modes. used for initial + * activation, or for activating sleep mode + */ +enum mxl_eagle_power_mode_e { + mxl_eagle_power_mode_sleep, + mxl_eagle_power_mode_active +}; + +/* enum of gpios, used in device gpio apis */ +enum mxl_eagle_gpio_number_e { + mxl_eagle_gpio_number_0, + mxl_eagle_gpio_number_1, + mxl_eagle_gpio_number_2, + mxl_eagle_gpio_number_3, + mxl_eagle_gpio_number_4, + mxl_eagle_gpio_number_5, + mxl_eagle_gpio_number_6 +}; + +/* enum of gpio directions, used in gpio direction configuration api */ +enum mxl_eagle_gpio_direction_e { + mxl_eagle_gpio_direction_input, + mxl_eagle_gpio_direction_output +}; + +/* enum of gpio level, used in device gpio apis */ +enum mxl_eagle_gpio_level_e { + mxl_eagle_gpio_level_low, + mxl_eagle_gpio_level_high, +}; + +/* enum of i/o mux function, used in device i/o mux configuration api */ +enum mxl_eagle_iomux_function_e { + mxl_eagle_iomux_func_fec_lock, + mxl_eagle_iomux_func_merr, +}; + +/* enum of mpeg data format, used in mpeg and oob output configuration */ +enum mxl_eagle_mpeg_data_format_e { + mxl_eagle_data_serial_lsb_1st = 0, + mxl_eagle_data_serial_msb_1st, + + mxl_eagle_data_sync_width_bit = 0, + mxl_eagle_data_sync_width_byte +}; + +/* enum of mpeg clock format, used in mpeg and oob output configuration */ +enum mxl_eagle_mpeg_clock_format_e { + mxl_eagle_clock_active_high = 0, + mxl_eagle_clock_active_low, + + mxl_eagle_clock_positive = 0, + mxl_eagle_clock_negative, + + mxl_eagle_clock_in_phase = 0, + mxl_eagle_clock_inverted, +}; + +/* enum of mpeg clock speeds, used in mpeg output configuration */ +enum mxl_eagle_mpeg_clock_rate_e { + mxl_eagle_mpeg_clock_54mhz, + mxl_eagle_mpeg_clock_40_5mhz, + mxl_eagle_mpeg_clock_27mhz, + mxl_eagle_mpeg_clock_13_5mhz, +}; + +/* enum of interrupt mask bit, used in host interrupt configuration */ +enum mxl_eagle_intr_mask_bits_e { + mxl_eagle_intr_mask_demod = 0, + mxl_eagle_intr_mask_sma_rx = 1, + mxl_eagle_intr_mask_wdog = 31 +}; + +/* enum of qam demodulator type, used in qam configuration */ +enum mxl_eagle_qam_demod_annex_type_e { + mxl_eagle_qam_demod_annex_b, /* j.83b */ + mxl_eagle_qam_demod_annex_a, /* dvb-c */ +}; + +/* enum of qam demodulator modulation, used in qam configuration and status */ +enum mxl_eagle_qam_demod_qam_type_e { + mxl_eagle_qam_demod_qam16, + mxl_eagle_qam_demod_qam64, + mxl_eagle_qam_demod_qam256, + mxl_eagle_qam_demod_qam1024, + mxl_eagle_qam_demod_qam32, + mxl_eagle_qam_demod_qam128, + mxl_eagle_qam_demod_qpsk, + mxl_eagle_qam_demod_auto, +}; + +/* enum of demodulator iq setup, used in qam, oob configuration and status */ +enum mxl_eagle_iq_flip_e { + mxl_eagle_demod_iq_normal, + mxl_eagle_demod_iq_flipped, + mxl_eagle_demod_iq_auto, +}; + +/* enum of oob demodulator symbol rates, used in oob configuration */ +enum mxl_eagle_oob_demod_symb_rate_e { + mxl_eagle_oob_demod_symb_rate_0_772mhz, /* ansi/scte 55-2 0.772 mhz */ + mxl_eagle_oob_demod_symb_rate_1_024mhz, /* ansi/scte 55-1 1.024 mhz */ + mxl_eagle_oob_demod_symb_rate_1_544mhz, /* ansi/scte 55-2 1.544 mhz */ +}; + +/* enum of tuner channel tuning mode */ +enum mxl_eagle_tuner_channel_tune_mode_e { + mxl_eagle_tuner_channel_tune_mode_view, /* normal "view" mode */ + mxl_eagle_tuner_channel_tune_mode_scan, /* fast "scan" mode */ +}; + +/* enum of tuner bandwidth */ +enum mxl_eagle_tuner_bw_e { + mxl_eagle_tuner_bw_6mhz, + mxl_eagle_tuner_bw_7mhz, + mxl_eagle_tuner_bw_8mhz, +}; + +/* enum of tuner bandwidth */ +enum mxl_eagle_junction_temperature_e { + mxl_eagle_junction_temperature_below_0_celsius = 0, + mxl_eagle_junction_temperature_between_0_to_14_celsius = 1, + mxl_eagle_junction_temperature_between_14_to_28_celsius = 3, + mxl_eagle_junction_temperature_between_28_to_42_celsius = 2, + mxl_eagle_junction_temperature_between_42_to_57_celsius = 6, + mxl_eagle_junction_temperature_between_57_to_71_celsius = 7, + mxl_eagle_junction_temperature_between_71_to_85_celsius = 5, + mxl_eagle_junction_temperature_above_85_celsius = 4, +}; + +/* struct passed in optional callback used during fw download */ +struct mxl_eagle_fw_download_cb_payload_t { + u32 total_len; + u32 downloaded_len; +}; + +/* struct used of i2c protocol between host and eagle, internal use only */ +struct __packed mxl_eagle_host_msg_header_t { + u8 opcode; + u8 seqnum; + u8 payload_size; + u8 status; + u32 checksum; +}; + +/* device version information struct */ +struct __packed mxl_eagle_dev_ver_t { + u8 chip_id; + u8 firmware_ver[mxl_eagle_version_size]; + u8 mxlware_ver[mxl_eagle_version_size]; +}; + +/* xtal configuration struct */ +struct __packed mxl_eagle_dev_xtal_t { + u8 xtal_cap; /* accepted range is 1..31 pf. default is 26 */ + u8 clk_out_enable; + u8 clk_out_div_enable; /* clock out freq is xtal freq / 6 */ + u8 xtal_sharing_enable; /* if enabled set xtal_cap to 25 pf */ + u8 xtal_calibration_enable; /* enable for master, disable for slave */ +}; + +/* gpio direction struct, internally used in gpio configuration api */ +struct __packed mxl_eagle_dev_gpio_direction_t { + u8 gpio_number; + u8 gpio_direction; +}; + +/* gpo level struct, internally used in gpio configuration api */ +struct __packed mxl_eagle_dev_gpo_level_t { + u8 gpio_number; + u8 gpo_level; +}; + +/* device status struct */ +struct mxl_eagle_dev_status_t { + u8 temperature; + u8 demod_type; + u8 power_mode; + u8 cpu_utilization_percent; +}; + +/* device interrupt configuration struct */ +struct __packed mxl_eagle_dev_intr_cfg_t { + u32 intr_mask; + u8 edge_trigger; + u8 positive_trigger; + u8 global_enable_interrupt; +}; + +/* mpeg pad drive parameters, used on mpeg output configuration */ +/* see mxl_eagle_io_mux_drive_mode_e */ +struct mxl_eagle_mpeg_pad_drive_t { + u8 pad_drv_mpeg_syn; + u8 pad_drv_mpeg_dat; + u8 pad_drv_mpeg_val; + u8 pad_drv_mpeg_clk; +}; + +/* mpegout parameter struct, used in mpeg output configuration */ +struct mxl_eagle_mpegout_params_t { + u8 mpeg_parallel; + u8 msb_first; + u8 mpeg_sync_pulse_width; /* see mxl_eagle_mpeg_data_format_e */ + u8 mpeg_valid_pol; + u8 mpeg_sync_pol; + u8 mpeg_clk_pol; + u8 mpeg3wire_mode_enable; + u8 mpeg_clk_freq; + struct mxl_eagle_mpeg_pad_drive_t mpeg_pad_drv; +}; + +/* qam demodulator parameters struct, used in qam params configuration */ +struct __packed mxl_eagle_qam_demod_params_t { + u8 annex_type; + u8 qam_type; + u8 iq_flip; + u8 search_range_idx; + u8 spur_canceller_enable; + u32 symbol_rate_hz; + u32 symbol_rate_256qam_hz; +}; + +/* qam demodulator status */ +struct mxl_eagle_qam_demod_status_t { + u8 annex_type; + u8 qam_type; + u8 iq_flip; + u8 interleaver_depth_i; + u8 interleaver_depth_j; + u8 qam_locked; + u8 fec_locked; + u8 mpeg_locked; + u16 snr_db_tenths; + s16 timing_offset; + s32 carrier_offset_hz; +}; + +/* qam demodulator error counters */ +struct mxl_eagle_qam_demod_error_counters_t { + u32 corrected_code_words; + u32 uncorrected_code_words; + u32 total_code_words_received; + u32 corrected_bits; + u32 error_mpeg_frames; + u32 mpeg_frames_received; + u32 erasures; +}; + +/* qam demodulator constellation point */ +struct mxl_eagle_qam_demod_constellation_val_t { + s16 i_value[12]; + s16 q_value[12]; +}; + +/* qam demodulator equalizer filter taps */ +struct mxl_eagle_qam_demod_equ_filter_t { + s16 ffe_taps[mxl_eagle_qam_ffe_taps_length]; + s16 spur_taps[mxl_eagle_qam_spur_taps_length]; + s16 dfe_taps[mxl_eagle_qam_dfe_taps_length]; + u8 ffe_leading_tap_index; + u8 dfe_taps_number; +}; + +/* oob demodulator parameters struct, used in oob params configuration */ +struct __packed mxl_eagle_oob_demod_params_t { + u8 symbol_rate; + u8 iq_flip; + u8 clk_pol; +}; + +/* oob demodulator error counters */ +struct mxl_eagle_oob_demod_error_counters_t { + u32 corrected_packets; + u32 uncorrected_packets; + u32 total_packets_received; +}; + +/* oob status */ +struct __packed mxl_eagle_oob_demod_status_t { + u16 snr_db_tenths; + s16 timing_offset; + s32 carrier_offsethz; + u8 qam_locked; + u8 fec_locked; + u8 mpeg_locked; + u8 retune_required; + u8 iq_flip; +}; + +/* atsc demodulator status */ +struct __packed mxl_eagle_atsc_demod_status_t { + s16 snr_db_tenths; + s16 timing_offset; + s32 carrier_offset_hz; + u8 frame_lock; + u8 atsc_lock; + u8 fec_lock; +}; + +/* atsc demodulator error counters */ +struct mxl_eagle_atsc_demod_error_counters_t { + u32 error_packets; + u32 total_packets; + u32 error_bytes; +}; + +/* atsc demodulator equalizers filter taps */ +struct __packed mxl_eagle_atsc_demod_equ_filter_t { + s16 ffe_taps[mxl_eagle_atsc_ffe_taps_length]; + s8 dfe_taps[mxl_eagle_atsc_dfe_taps_length]; +}; + +/* tuner agc status */ +struct __packed mxl_eagle_tuner_agc_status_t { + u8 locked; + u16 raw_agc_gain; /* agc gain [db] = rawagcgain / 2^6 */ + s16 rx_power_db_hundredths; +}; + +/* tuner channel tune parameters */ +struct __packed mxl_eagle_tuner_channel_params_t { + u32 freq_hz; + u8 tune_mode; + u8 bandwidth; +}; + +/* tuner channel lock indications */ +struct __packed mxl_eagle_tuner_lock_status_t { + u8 rf_pll_locked; + u8 ref_pll_locked; +}; + +/* smart antenna parameters used in smart antenna params configuration */ +struct __packed mxl_eagle_sma_params_t { + u8 full_duplex_enable; + u8 rx_disable; + u8 idle_logic_high; +}; + +/* smart antenna message format */ +struct __packed mxl_eagle_sma_message_t { + u32 payload_bits; + u8 total_num_bits; +}; +
TV tuners, webcams, video capturers
b53f2fa136b1b20f03184f4a98fea75eb2705eac
brad love
drivers
media
dvb-frontends
media: ov5647: remove 640x480 sbggr8 mode
capturing in 640x480 sbggr8_1x8 hangs the system when capturing with the unicam driver on raspberrypi 4 platform.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
remove 640x480 sbggr8 mode
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['ov5647']
['c']
1
9
171
--- diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c -struct ov5647_format_list { - unsigned int mbus_code; - const struct ov5647_mode *modes; - unsigned int num_modes; -}; - -static const struct regval_list ov5647_640x480_8bpp[] = { - {0x0100, 0x00}, - {0x0103, 0x01}, - {0x3034, 0x08}, - {0x3035, 0x21}, - {0x3036, 0x46}, - {0x303c, 0x11}, - {0x3106, 0xf5}, - {0x3821, 0x07}, - {0x3820, 0x41}, - {0x3827, 0xec}, - {0x370c, 0x0f}, - {0x3612, 0x59}, - {0x3618, 0x00}, - {0x5000, 0x06}, - {0x5002, 0x41}, - {0x5003, 0x08}, - {0x5a00, 0x08}, - {0x3000, 0x00}, - {0x3001, 0x00}, - {0x3002, 0x00}, - {0x3016, 0x08}, - {0x3017, 0xe0}, - {0x3018, 0x44}, - {0x301c, 0xf8}, - {0x301d, 0xf0}, - {0x3a18, 0x00}, - {0x3a19, 0xf8}, - {0x3c01, 0x80}, - {0x3b07, 0x0c}, - {0x380c, 0x07}, - {0x380d, 0x68}, - {0x3814, 0x31}, - {0x3815, 0x31}, - {0x3708, 0x64}, - {0x3709, 0x52}, - {0x3808, 0x02}, - {0x3809, 0x80}, - {0x380a, 0x01}, - {0x380b, 0xe0}, - {0x3801, 0x00}, - {0x3802, 0x00}, - {0x3803, 0x00}, - {0x3804, 0x0a}, - {0x3805, 0x3f}, - {0x3806, 0x07}, - {0x3807, 0xa1}, - {0x3811, 0x08}, - {0x3813, 0x02}, - {0x3630, 0x2e}, - {0x3632, 0xe2}, - {0x3633, 0x23}, - {0x3634, 0x44}, - {0x3636, 0x06}, - {0x3620, 0x64}, - {0x3621, 0xe0}, - {0x3600, 0x37}, - {0x3704, 0xa0}, - {0x3703, 0x5a}, - {0x3715, 0x78}, - {0x3717, 0x01}, - {0x3731, 0x02}, - {0x370b, 0x60}, - {0x3705, 0x1a}, - {0x3f05, 0x02}, - {0x3f06, 0x10}, - {0x3f01, 0x0a}, - {0x3a08, 0x01}, - {0x3a09, 0x27}, - {0x3a0a, 0x00}, - {0x3a0b, 0xf6}, - {0x3a0d, 0x04}, - {0x3a0e, 0x03}, - {0x3a0f, 0x58}, - {0x3a10, 0x50}, - {0x3a1b, 0x58}, - {0x3a1e, 0x50}, - {0x3a11, 0x60}, - {0x3a1f, 0x28}, - {0x4001, 0x02}, - {0x4004, 0x02}, - {0x4000, 0x09}, - {0x4837, 0x24}, - {0x4050, 0x6e}, - {0x4051, 0x8f}, - {0x0100, 0x01}, -}; - -static const struct ov5647_mode ov5647_8bpp_modes[] = { - /* 8-bit vga mode: uncentred crop 2x2 binned 1296x972 image. */ - { - .format = { - .code = media_bus_fmt_sbggr8_1x8, - .colorspace = v4l2_colorspace_srgb, - .field = v4l2_field_none, - .width = 640, - .height = 480 - }, - .crop = { - .left = ov5647_pixel_array_left, - .top = ov5647_pixel_array_top, - .width = 1280, - .height = 960, - }, - .pixel_rate = 77291670, - .hts = 1896, - .vts = 0x3d8, - .reg_list = ov5647_640x480_8bpp, - .num_regs = array_size(ov5647_640x480_8bpp) - }, -}; - -static const struct ov5647_mode ov5647_10bpp_modes[] = { +static const struct ov5647_mode ov5647_modes[] = { -static const struct ov5647_format_list ov5647_formats[] = { - { - .mbus_code = media_bus_fmt_sbggr8_1x8, - .modes = ov5647_8bpp_modes, - .num_modes = array_size(ov5647_8bpp_modes), - }, - { - .mbus_code = media_bus_fmt_sbggr10_1x10, - .modes = ov5647_10bpp_modes, - .num_modes = array_size(ov5647_10bpp_modes), - }, -}; - -#define ov5647_num_formats (array_size(ov5647_formats)) - -#define ov5647_default_mode (&ov5647_formats[1].modes[3]) -#define ov5647_default_format (ov5647_formats[1].modes[3].format) +#define ov5647_default_mode (&ov5647_modes[3]) +#define ov5647_default_format (ov5647_modes[3].format) - if (code->index >= ov5647_num_formats) + if (code->index > 0) - code->code = ov5647_formats[code->index].mbus_code; + code->code = media_bus_fmt_sbggr10_1x10; - unsigned int i = 0; - for (; i < ov5647_num_formats; ++i) { - if (ov5647_formats[i].mbus_code == fse->code) - break; - } - if (i == ov5647_num_formats) + if (fse->code != media_bus_fmt_sbggr10_1x10 || + fse->index >= array_size(ov5647_modes)) - if (fse->index >= ov5647_formats[i].num_modes) - return -einval; - - fmt = &ov5647_formats[i].modes[fse->index].format; + fmt = &ov5647_modes[fse->index].format; - const struct ov5647_mode *ov5647_mode_list; - - unsigned int num_modes; - unsigned int i; - - for (i = 0; i < ov5647_num_formats; ++i) { - if (ov5647_formats[i].mbus_code != fmt->code) - continue; - - ov5647_mode_list = ov5647_formats[i].modes; - num_modes = ov5647_formats[i].num_modes; - break; - } - - /* - * default mbus code media_bus_fmt_sbggr10_1x10 if the requested one is - * not supported. - */ - if (i == ov5647_num_formats) { - ov5647_mode_list = ov5647_10bpp_modes; - num_modes = array_size(ov5647_10bpp_modes); - } - mode = v4l2_find_nearest_size(ov5647_mode_list, num_modes, + mode = v4l2_find_nearest_size(ov5647_modes, array_size(ov5647_modes),
TV tuners, webcams, video capturers
38c22308181562d52926b6701327c3fe209f6d84
jacopo mondi
drivers
media
i2c
media: ov5647: support vidioc_subscribe_event
the driver reports the v4l2_subdev_fl_has_events flag but does not support subscribing and unsubscribing to events.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['ov5647']
['c']
1
3
0
--- diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c --- a/drivers/media/i2c/ov5647.c +++ b/drivers/media/i2c/ov5647.c +#include <media/v4l2-event.h> + .subscribe_event = v4l2_ctrl_subdev_subscribe_event, + .unsubscribe_event = v4l2_event_subdev_unsubscribe,
TV tuners, webcams, video capturers
dc3373081396f5317f8f0b593a2cb644c4e1786e
jacopo mondi
drivers
media
i2c
media: ti-vpe: cal: implement subdev ops for camerarx
implement subdev operations for the camerarx. they will be used to replace calls to custom camerarx functions in the v4l2 video device code, and will be exposed to userspace.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
implement subdev ops for camerarx
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['ti-vpe', 'cal']
['h', 'c']
2
207
0
--- diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c --- a/drivers/media/platform/ti-vpe/cal-camerarx.c +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c +static inline struct cal_camerarx *to_cal_camerarx(struct v4l2_subdev *sd) +{ + return container_of(sd, struct cal_camerarx, subdev); +} + +static struct v4l2_mbus_framefmt * +cal_camerarx_get_pad_format(struct cal_camerarx *phy, + struct v4l2_subdev_pad_config *cfg, + unsigned int pad, u32 which) +{ + switch (which) { + case v4l2_subdev_format_try: + return v4l2_subdev_get_try_format(&phy->subdev, cfg, pad); + case v4l2_subdev_format_active: + return &phy->formats[pad]; + default: + return null; + } +} + +static int cal_camerarx_sd_s_stream(struct v4l2_subdev *sd, int enable) +{ + struct cal_camerarx *phy = to_cal_camerarx(sd); + + if (enable) + return cal_camerarx_start(phy, null); + + cal_camerarx_stop(phy); + return 0; +} + +static int cal_camerarx_sd_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_mbus_code_enum *code) +{ + struct cal_camerarx *phy = to_cal_camerarx(sd); + + /* no transcoding, source and sink codes must match. */ + if (code->pad == cal_camerarx_pad_source) { + struct v4l2_mbus_framefmt *fmt; + + if (code->index > 0) + return -einval; + + fmt = cal_camerarx_get_pad_format(phy, cfg, + cal_camerarx_pad_sink, + code->which); + code->code = fmt->code; + return 0; + } + + if (code->index >= cal_num_formats) + return -einval; + + code->code = cal_formats[code->index].code; + + return 0; +} + +static int cal_camerarx_sd_enum_frame_size(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_frame_size_enum *fse) +{ + struct cal_camerarx *phy = to_cal_camerarx(sd); + const struct cal_fmt *fmtinfo; + + if (fse->index > 0) + return -einval; + + /* no transcoding, source and sink formats must match. */ + if (fse->pad == cal_camerarx_pad_source) { + struct v4l2_mbus_framefmt *fmt; + + fmt = cal_camerarx_get_pad_format(phy, cfg, + cal_camerarx_pad_sink, + fse->which); + if (fse->code != fmt->code) + return -einval; + + fse->min_width = fmt->width; + fse->max_width = fmt->width; + fse->min_height = fmt->height; + fse->max_height = fmt->height; + + return 0; + } + + fmtinfo = cal_format_by_code(fse->code); + if (!fmtinfo) + return -einval; + + fse->min_width = cal_min_width_bytes * 8 / align(fmtinfo->bpp, 8); + fse->max_width = cal_max_width_bytes * 8 / align(fmtinfo->bpp, 8); + fse->min_height = cal_min_height_lines; + fse->max_height = cal_max_height_lines; + + return 0; +} + +static int cal_camerarx_sd_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *format) +{ + struct cal_camerarx *phy = to_cal_camerarx(sd); + struct v4l2_mbus_framefmt *fmt; + + fmt = cal_camerarx_get_pad_format(phy, cfg, format->pad, format->which); + format->format = *fmt; + + return 0; +} + +static int cal_camerarx_sd_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *format) +{ + struct cal_camerarx *phy = to_cal_camerarx(sd); + const struct cal_fmt *fmtinfo; + struct v4l2_mbus_framefmt *fmt; + unsigned int bpp; + + /* no transcoding, source and sink formats must match. */ + if (format->pad == cal_camerarx_pad_source) + return cal_camerarx_sd_get_fmt(sd, cfg, format); + + /* + * default to the first format is the requested media bus code isn't + * supported. + */ + fmtinfo = cal_format_by_code(format->format.code); + if (!fmtinfo) + fmtinfo = &cal_formats[0]; + + /* + * clamp the size, update the code. the field and colorspace are + * accepted as-is. + */ + bpp = align(fmtinfo->bpp, 8); + + format->format.width = clamp_t(unsigned int, format->format.width, + cal_min_width_bytes * 8 / bpp, + cal_max_width_bytes * 8 / bpp); + format->format.height = clamp_t(unsigned int, format->format.height, + cal_min_height_lines, + cal_max_height_lines); + format->format.code = fmtinfo->code; + + /* store the format and propagate it to the source pad. */ + fmt = cal_camerarx_get_pad_format(phy, cfg, cal_camerarx_pad_sink, + format->which); + *fmt = format->format; + + fmt = cal_camerarx_get_pad_format(phy, cfg, cal_camerarx_pad_source, + format->which); + *fmt = format->format; + + if (format->which == v4l2_subdev_format_active) + phy->fmtinfo = fmtinfo; + + return 0; +} + +static int cal_camerarx_sd_init_cfg(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg) +{ + struct v4l2_subdev_format format = { + .which = cfg ? v4l2_subdev_format_try + : v4l2_subdev_format_active, + .pad = cal_camerarx_pad_sink, + .format = { + .width = 640, + .height = 480, + .code = media_bus_fmt_uyvy8_2x8, + .field = v4l2_field_none, + .colorspace = v4l2_colorspace_srgb, + .ycbcr_enc = v4l2_ycbcr_enc_601, + .quantization = v4l2_quantization_lim_range, + .xfer_func = v4l2_xfer_func_srgb, + }, + }; + + return cal_camerarx_sd_set_fmt(sd, cfg, &format); +} + +static const struct v4l2_subdev_video_ops cal_camerarx_video_ops = { + .s_stream = cal_camerarx_sd_s_stream, +}; + +static const struct v4l2_subdev_pad_ops cal_camerarx_pad_ops = { + .init_cfg = cal_camerarx_sd_init_cfg, + .enum_mbus_code = cal_camerarx_sd_enum_mbus_code, + .enum_frame_size = cal_camerarx_sd_enum_frame_size, + .get_fmt = cal_camerarx_sd_get_fmt, + .set_fmt = cal_camerarx_sd_set_fmt, +}; + + .video = &cal_camerarx_video_ops, + .pad = &cal_camerarx_pad_ops, +}; + +struct media_entity_operations cal_camerarx_media_ops = { + .link_validate = v4l2_subdev_link_validate, + sd->entity.ops = &cal_camerarx_media_ops; + cal_camerarx_sd_init_cfg(sd, null); + diff --git a/drivers/media/platform/ti-vpe/cal.h b/drivers/media/platform/ti-vpe/cal.h --- a/drivers/media/platform/ti-vpe/cal.h +++ b/drivers/media/platform/ti-vpe/cal.h + struct v4l2_mbus_framefmt formats[2]; + const struct cal_fmt *fmtinfo;
TV tuners, webcams, video capturers
8d6637f1087611a1408ae1c183c93e18b7fd9534
laurent pinchart benoit parrot bparrot ti com
drivers
media
platform, ti-vpe
media: v4l2-async: add waiting subdevices debugfs
there is currently little to no information available about the reasons why a v4l2-async device hasn't probed completely.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add waiting subdevices debugfs
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['v4l2-async']
['h', 'c']
3
79
0
--- diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c +#include <linux/debugfs.h> +#include <linux/seq_file.h> + +static void print_waiting_subdev(struct seq_file *s, + struct v4l2_async_subdev *asd) +{ + switch (asd->match_type) { + case v4l2_async_match_devname: + seq_printf(s, " [devname] dev=%s ", asd->match.device_name); + break; + case v4l2_async_match_i2c: + seq_printf(s, " [i2c] dev=%d-%04x ", asd->match.i2c.adapter_id, + asd->match.i2c.address); + break; + case v4l2_async_match_fwnode: { + struct fwnode_handle *devnode, *fwnode = asd->match.fwnode; + + devnode = fwnode_graph_is_endpoint(fwnode) ? + fwnode_graph_get_port_parent(fwnode) : + fwnode_handle_get(fwnode); + + seq_printf(s, " [fwnode] dev=%s, node=%pfw ", + devnode->dev ? dev_name(devnode->dev) : "nil", + fwnode); + + fwnode_handle_put(devnode); + break; + } + } +} + +static const char * +v4l2_async_notifier_name(struct v4l2_async_notifier *notifier) +{ + if (notifier->v4l2_dev) + return notifier->v4l2_dev->name; + else if (notifier->sd) + return notifier->sd->name; + else + return "nil"; +} + +static int pending_subdevs_show(struct seq_file *s, void *data) +{ + struct v4l2_async_notifier *notif; + struct v4l2_async_subdev *asd; + + mutex_lock(&list_lock); + + list_for_each_entry(notif, &notifier_list, list) { + seq_printf(s, "%s: ", v4l2_async_notifier_name(notif)); + list_for_each_entry(asd, &notif->waiting, list) + print_waiting_subdev(s, asd); + } + + mutex_unlock(&list_lock); + + return 0; +} +define_show_attribute(pending_subdevs); + +void v4l2_async_debug_init(struct dentry *debugfs_dir) +{ + debugfs_create_file("pending_async_subdevices", 0444, debugfs_dir, null, + &pending_subdevs_fops); +} diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c +#include <linux/debugfs.h> +static struct dentry *v4l2_debugfs_dir; + v4l2_debugfs_dir = debugfs_create_dir("video4linux", null); + v4l2_async_debug_init(v4l2_debugfs_dir); + debugfs_remove_recursive(v4l2_debugfs_dir); diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h --- a/include/media/v4l2-async.h +++ b/include/media/v4l2-async.h +struct dentry; +/** + * v4l2_async_debug_init - initialize debugging tools. + * + * @debugfs_dir: pointer to the parent debugfs &struct dentry + */ +void v4l2_async_debug_init(struct dentry *debugfs_dir); +
TV tuners, webcams, video capturers
517fd2b6a058bc4f23735ab9a9e6b0d5c56876d1
ezequiel garcia
drivers
media
v4l2-core
media: v4l2-ctrl: add base layer priority id control.
this control indicates the priority id to be applied to base layer.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add control to indicate the priority id to be applied to base layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['v4l2-ctrl']
['h', 'c', 'rst']
3
11
0
--- diff --git a/documentation/userspace-api/media/v4l/ext-ctrls-codec.rst b/documentation/userspace-api/media/v4l/ext-ctrls-codec.rst --- a/documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +++ b/documentation/userspace-api/media/v4l/ext-ctrls-codec.rst - selecting this value specifies that hevc slices are expected + +''v4l2_cid_mpeg_video_baselayer_priority_id (integer)'' + specifies a priority identifier for the nal unit, which will be applied to + the base layer. by default this value is set to 0 for the base layer, + and the next layer will have the priority id assigned as 1, 2, 3 and so on. + the video encoder can't decide the priority id to be applied to a layer, + so this has to come from client. + this is applicable to h264 and valid range is from 0 to 63. + source rec. itu-t h.264 (06/2019); g.7.4.1.1, g.8.8.1. diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c + case v4l2_cid_mpeg_video_baselayer_priority_id: return "base layer priority id"; diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h +#define v4l2_cid_mpeg_video_baselayer_priority_id (v4l2_cid_codec_base+230)
TV tuners, webcams, video capturers
6bde70da98f6b5f5dbd61d2fa9c1e7efe83b0402
dikshita agarwal
documentation
userspace-api
linux, media, v4l, v4l2-core
media: v4l2-ctrl: add frame-specific min/max qp controls for hevc
- adds min/max qp controls for b frame for h264. - adds min/max qp controls for i/p/b frames for hevc similar to h264. - update valid range of min/max qp for hevc to accommodate 10 bit.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add new controls for qp and layer bitrate
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['v4l2-ctrl']
['h', 'c', 'rst']
3
67
2
- adds min/max qp controls for b frame for h264. - adds min/max qp controls for i/p/b frames for hevc similar to h264. - update valid range of min/max qp for hevc to accommodate 10 bit. --- diff --git a/documentation/userspace-api/media/v4l/ext-ctrls-codec.rst b/documentation/userspace-api/media/v4l/ext-ctrls-codec.rst --- a/documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +++ b/documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +''v4l2_cid_mpeg_video_h264_b_frame_min_qp (integer)'' + minimum quantization parameter for the h264 b frame to limit b frame + quality to a range. valid range: from 0 to 51. if + v4l2_cid_mpeg_video_h264_min_qp is also set, the quantization parameter + should be chosen to meet both requirements. + +''v4l2_cid_mpeg_video_h264_b_frame_max_qp (integer)'' + maximum quantization parameter for the h264 b frame to limit b frame + quality to a range. valid range: from 0 to 51. if + v4l2_cid_mpeg_video_h264_max_qp is also set, the quantization parameter + should be chosen to meet both requirements. + - valid range: from 0 to 51. + valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. - valid range: from 0 to 51. + valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. +''v4l2_cid_mpeg_video_hevc_i_frame_min_qp (integer)'' + minimum quantization parameter for the hevc i frame to limit i frame + quality to a range. valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. + if v4l2_cid_mpeg_video_hevc_min_qp is also set, the quantization parameter + should be chosen to meet both requirements. + +''v4l2_cid_mpeg_video_hevc_i_frame_max_qp (integer)'' + maximum quantization parameter for the hevc i frame to limit i frame + quality to a range. valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. + if v4l2_cid_mpeg_video_hevc_max_qp is also set, the quantization parameter + should be chosen to meet both requirements. + +''v4l2_cid_mpeg_video_hevc_p_frame_min_qp (integer)'' + minimum quantization parameter for the hevc p frame to limit p frame + quality to a range. valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. + if v4l2_cid_mpeg_video_hevc_min_qp is also set, the quantization parameter + should be chosen to meet both requirements. + +''v4l2_cid_mpeg_video_hevc_p_frame_max_qp (integer)'' + maximum quantization parameter for the hevc p frame to limit p frame + quality to a range. valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. + if v4l2_cid_mpeg_video_hevc_max_qp is also set, the quantization parameter + should be chosen to meet both requirements. + +''v4l2_cid_mpeg_video_hevc_b_frame_min_qp (integer)'' + minimum quantization parameter for the hevc b frame to limit b frame + quality to a range. valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. + if v4l2_cid_mpeg_video_hevc_min_qp is also set, the quantization parameter + should be chosen to meet both requirements. + +''v4l2_cid_mpeg_video_hevc_b_frame_max_qp (integer)'' + maximum quantization parameter for the hevc b frame to limit b frame + quality to a range. valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. + if v4l2_cid_mpeg_video_hevc_max_qp is also set, the quantization parameter + should be chosen to meet both requirements. + diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c + case v4l2_cid_mpeg_video_h264_b_frame_min_qp: return "h264 b-frame minimum qp value"; + case v4l2_cid_mpeg_video_h264_b_frame_max_qp: return "h264 b-frame maximum qp value"; + case v4l2_cid_mpeg_video_hevc_i_frame_min_qp: return "hevc i-frame minimum qp value"; + case v4l2_cid_mpeg_video_hevc_i_frame_max_qp: return "hevc i-frame maximum qp value"; + case v4l2_cid_mpeg_video_hevc_p_frame_min_qp: return "hevc p-frame minimum qp value"; + case v4l2_cid_mpeg_video_hevc_p_frame_max_qp: return "hevc p-frame maximum qp value"; + case v4l2_cid_mpeg_video_hevc_b_frame_min_qp: return "hevc b-frame minimum qp value"; + case v4l2_cid_mpeg_video_hevc_b_frame_max_qp: return "hevc b-frame maximum qp value"; diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h +#define v4l2_cid_mpeg_video_h264_b_frame_min_qp (v4l2_cid_codec_base+389) +#define v4l2_cid_mpeg_video_h264_b_frame_max_qp (v4l2_cid_codec_base+390) +#define v4l2_cid_mpeg_video_hevc_i_frame_min_qp (v4l2_cid_codec_base + 647) +#define v4l2_cid_mpeg_video_hevc_i_frame_max_qp (v4l2_cid_codec_base + 648) +#define v4l2_cid_mpeg_video_hevc_p_frame_min_qp (v4l2_cid_codec_base + 649) +#define v4l2_cid_mpeg_video_hevc_p_frame_max_qp (v4l2_cid_codec_base + 650) +#define v4l2_cid_mpeg_video_hevc_b_frame_min_qp (v4l2_cid_codec_base + 651) +#define v4l2_cid_mpeg_video_hevc_b_frame_max_qp (v4l2_cid_codec_base + 652) +
TV tuners, webcams, video capturers
99d0cbe4be78ca33f06089521a8a0d76a20cdbb7
dikshita agarwal
documentation
userspace-api
linux, media, v4l, v4l2-core
media: v4l2-ctrl: add layer wise bitrate controls for h264
adds bitrate control for all coding layers for h264 same as hevc.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add new controls for qp and layer bitrate
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['v4l2-ctrl']
['h', 'c', 'rst']
3
34
0
--- diff --git a/documentation/userspace-api/media/v4l/ext-ctrls-codec.rst b/documentation/userspace-api/media/v4l/ext-ctrls-codec.rst --- a/documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +++ b/documentation/userspace-api/media/v4l/ext-ctrls-codec.rst - layer number +''v4l2_cid_mpeg_video_h264_hier_coding_l0_br (integer)'' + indicates bit rate (bps) for hierarchical coding layer 0 for h264 encoder. + +''v4l2_cid_mpeg_video_h264_hier_coding_l1_br (integer)'' + indicates bit rate (bps) for hierarchical coding layer 1 for h264 encoder. + +''v4l2_cid_mpeg_video_h264_hier_coding_l2_br (integer)'' + indicates bit rate (bps) for hierarchical coding layer 2 for h264 encoder. + +''v4l2_cid_mpeg_video_h264_hier_coding_l3_br (integer)'' + indicates bit rate (bps) for hierarchical coding layer 3 for h264 encoder. + +''v4l2_cid_mpeg_video_h264_hier_coding_l4_br (integer)'' + indicates bit rate (bps) for hierarchical coding layer 4 for h264 encoder. + +''v4l2_cid_mpeg_video_h264_hier_coding_l5_br (integer)'' + indicates bit rate (bps) for hierarchical coding layer 5 for h264 encoder. + +''v4l2_cid_mpeg_video_h264_hier_coding_l6_br (integer)'' + indicates bit rate (bps) for hierarchical coding layer 6 for h264 encoder. diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c + case v4l2_cid_mpeg_video_h264_hier_coding_l0_br: return "h264 hierarchical lay 0 bitrate"; + case v4l2_cid_mpeg_video_h264_hier_coding_l1_br: return "h264 hierarchical lay 1 bitrate"; + case v4l2_cid_mpeg_video_h264_hier_coding_l2_br: return "h264 hierarchical lay 2 bitrate"; + case v4l2_cid_mpeg_video_h264_hier_coding_l3_br: return "h264 hierarchical lay 3 bitrate"; + case v4l2_cid_mpeg_video_h264_hier_coding_l4_br: return "h264 hierarchical lay 4 bitrate"; + case v4l2_cid_mpeg_video_h264_hier_coding_l5_br: return "h264 hierarchical lay 5 bitrate"; + case v4l2_cid_mpeg_video_h264_hier_coding_l6_br: return "h264 hierarchical lay 6 bitrate"; diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h +#define v4l2_cid_mpeg_video_h264_hier_coding_l0_br (v4l2_cid_codec_base+391) +#define v4l2_cid_mpeg_video_h264_hier_coding_l1_br (v4l2_cid_codec_base+392) +#define v4l2_cid_mpeg_video_h264_hier_coding_l2_br (v4l2_cid_codec_base+393) +#define v4l2_cid_mpeg_video_h264_hier_coding_l3_br (v4l2_cid_codec_base+394) +#define v4l2_cid_mpeg_video_h264_hier_coding_l4_br (v4l2_cid_codec_base+395) +#define v4l2_cid_mpeg_video_h264_hier_coding_l5_br (v4l2_cid_codec_base+396) +#define v4l2_cid_mpeg_video_h264_hier_coding_l6_br (v4l2_cid_codec_base+397)
TV tuners, webcams, video capturers
4ca134ee98238c3aaf0bb51094716373d8ae8720
dikshita agarwal
documentation
userspace-api
linux, media, v4l, v4l2-core
media: venus: venc: add support for frame-specific min/max qp controls
add support for frame type specific min and max qp controls for encoder. this is a preparation patch to support v6.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add new controls for qp and layer bitrate
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['v4l2-ctrl']
['h', 'c']
3
142
11
--- diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h + u32 h264_i_min_qp; + u32 h264_i_max_qp; + u32 h264_p_min_qp; + u32 h264_p_max_qp; + u32 h264_b_min_qp; + u32 h264_b_max_qp; + u32 hevc_i_qp; + u32 hevc_p_qp; + u32 hevc_b_qp; + u32 hevc_min_qp; + u32 hevc_max_qp; + u32 hevc_i_min_qp; + u32 hevc_i_max_qp; + u32 hevc_p_min_qp; + u32 hevc_p_max_qp; + u32 hevc_b_min_qp; + u32 hevc_b_max_qp; + diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c - quant.qp_i = ctr->h264_i_qp; - quant.qp_p = ctr->h264_p_qp; - quant.qp_b = ctr->h264_b_qp; + if (inst->fmt_cap->pixfmt == v4l2_pix_fmt_hevc) { + quant.qp_i = ctr->hevc_i_qp; + quant.qp_p = ctr->hevc_p_qp; + quant.qp_b = ctr->hevc_b_qp; + } else { + quant.qp_i = ctr->h264_i_qp; + quant.qp_p = ctr->h264_p_qp; + quant.qp_b = ctr->h264_b_qp; + } - quant_range.min_qp = ctr->h264_min_qp; - quant_range.max_qp = ctr->h264_max_qp; + if (inst->fmt_cap->pixfmt == v4l2_pix_fmt_hevc) { + quant_range.min_qp = ctr->hevc_min_qp; + quant_range.max_qp = ctr->hevc_max_qp; + } else { + quant_range.min_qp = ctr->h264_min_qp; + quant_range.max_qp = ctr->h264_max_qp; + } diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c b/drivers/media/platform/qcom/venus/venc_ctrls.c --- a/drivers/media/platform/qcom/venus/venc_ctrls.c +++ b/drivers/media/platform/qcom/venus/venc_ctrls.c + case v4l2_cid_mpeg_video_h264_i_frame_min_qp: + ctr->h264_i_min_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_h264_p_frame_min_qp: + ctr->h264_p_min_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_h264_b_frame_min_qp: + ctr->h264_b_min_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_h264_i_frame_max_qp: + ctr->h264_i_max_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_h264_p_frame_max_qp: + ctr->h264_p_max_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_h264_b_frame_max_qp: + ctr->h264_b_max_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_hevc_i_frame_qp: + ctr->hevc_i_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_hevc_p_frame_qp: + ctr->hevc_p_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_hevc_b_frame_qp: + ctr->hevc_b_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_hevc_min_qp: + ctr->hevc_min_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_hevc_i_frame_min_qp: + ctr->hevc_i_min_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_hevc_p_frame_min_qp: + ctr->hevc_p_min_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_hevc_b_frame_min_qp: + ctr->hevc_b_min_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_hevc_max_qp: + ctr->hevc_max_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_hevc_i_frame_max_qp: + ctr->hevc_i_max_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_hevc_p_frame_max_qp: + ctr->hevc_p_max_qp = ctrl->val; + break; + case v4l2_cid_mpeg_video_hevc_b_frame_max_qp: + ctr->hevc_b_max_qp = ctrl->val; + break; - ret = v4l2_ctrl_handler_init(&inst->ctrl_handler, 33); + ret = v4l2_ctrl_handler_init(&inst->ctrl_handler, 50); - v4l2_cid_mpeg_video_h264_i_frame_qp, 1, 51, 1, 26); + v4l2_cid_mpeg_video_h264_i_frame_qp, 1, 51, 1, 26); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_h264_p_frame_qp, 1, 51, 1, 28); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_h264_b_frame_qp, 1, 51, 1, 30); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_h264_min_qp, 1, 51, 1, 1); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_h264_i_frame_min_qp, 1, 51, 1, 1); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_h264_p_frame_min_qp, 1, 51, 1, 1); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_h264_b_frame_min_qp, 1, 51, 1, 1); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_h264_max_qp, 1, 51, 1, 51); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_h264_i_frame_max_qp, 1, 51, 1, 51); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_h264_p_frame_max_qp, 1, 51, 1, 51); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_h264_b_frame_max_qp, 1, 51, 1, 51); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_hevc_i_frame_qp, 1, 63, 1, 26); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_hevc_p_frame_qp, 1, 63, 1, 28); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_hevc_b_frame_qp, 1, 63, 1, 30); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_hevc_min_qp, 1, 63, 1, 1); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_hevc_i_frame_min_qp, 1, 63, 1, 1); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_hevc_p_frame_min_qp, 1, 63, 1, 1); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + v4l2_cid_mpeg_video_hevc_b_frame_min_qp, 1, 63, 1, 1); - v4l2_cid_mpeg_video_h264_p_frame_qp, 1, 51, 1, 28); + v4l2_cid_mpeg_video_hevc_max_qp, 1, 63, 1, 63); - v4l2_cid_mpeg_video_h264_b_frame_qp, 1, 51, 1, 30); + v4l2_cid_mpeg_video_hevc_i_frame_max_qp, 1, 63, 1, 63); - v4l2_cid_mpeg_video_h264_min_qp, 1, 51, 1, 1); + v4l2_cid_mpeg_video_hevc_p_frame_max_qp, 1, 63, 1, 63); - v4l2_cid_mpeg_video_h264_max_qp, 1, 51, 1, 51); + v4l2_cid_mpeg_video_hevc_b_frame_max_qp, 1, 63, 1, 63);
TV tuners, webcams, video capturers
74c895974fd3566806ea3ce42f9bb660eb54b696
dikshita agarwal stanimir varbanov stanimir varbanov linaro org
drivers
media
platform, qcom, venus
media: venus: delete not used core caps
the core caps are filled but not used, delete them. in case we need them we can re-introduce.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
2
0
9
--- diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h - * @core_caps: core capabilities -#define enc_rotation_capability 0x1 -#define enc_scaling_capability 0x2 -#define enc_deinterlace_capability 0x4 -#define dec_multi_stream_capability 0x8 - unsigned int core_caps; diff --git a/drivers/media/platform/qcom/venus/hfi_venus.c b/drivers/media/platform/qcom/venus/hfi_venus.c --- a/drivers/media/platform/qcom/venus/hfi_venus.c +++ b/drivers/media/platform/qcom/venus/hfi_venus.c - core->core_caps = enc_rotation_capability | enc_scaling_capability | - enc_deinterlace_capability | - dec_multi_stream_capability;
TV tuners, webcams, video capturers
d4bdba7b1cab5fce4d04bfc781b477aa6c535202
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: add more capabilities and vp9 profile/levels
add more caps and vp9 definitions for newer venus versions.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h']
1
18
0
--- diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h b/drivers/media/platform/qcom/venus/hfi_helper.h --- a/drivers/media/platform/qcom/venus/hfi_helper.h +++ b/drivers/media/platform/qcom/venus/hfi_helper.h +#define hfi_vpx_profile_main 0x00000001 + +#define hfi_vpx_level_version_0 0x00000001 +#define hfi_vpx_level_version_1 0x00000002 +#define hfi_vpx_level_version_2 0x00000004 +#define hfi_vpx_level_version_3 0x00000008 + +#define hfi_capability_i_frame_qp 0x20 +#define hfi_capability_p_frame_qp 0x21 +#define hfi_capability_b_frame_qp 0x22 +#define hfi_capability_rate_control_modes 0x23 +#define hfi_capability_blur_width 0x24 +#define hfi_capability_blur_height 0x25 +#define hfi_capability_slice_byte 0x27 +#define hfi_capability_slice_mb 0x28 +#define hfi_capability_max_workmodes 0x2c +#define hfi_capability_rotation 0x2f +#define hfi_capability_color_space_conversion 0x30
TV tuners, webcams, video capturers
c7f50ce507d54ff0518d2f55971a6a8dab6ae8a5
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: create hfi platform and move vpp/vsp there
introduce a new hfi platform to cover differences between hfi versions. as a start move vpp/vsp freq data in that hfi platform, more platform data will come later.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c', 'makefile']
11
179
73
--- diff --git a/drivers/media/platform/qcom/venus/makefile b/drivers/media/platform/qcom/venus/makefile --- a/drivers/media/platform/qcom/venus/makefile +++ b/drivers/media/platform/qcom/venus/makefile - hfi_parser.o pm_helpers.o dbgfs.o + hfi_parser.o pm_helpers.o dbgfs.o \ + hfi_platform.o hfi_platform_v4.o \ diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c -static const struct codec_freq_data sdm845_codec_freq_data[] = { - { v4l2_pix_fmt_h264, vidc_session_type_enc, 675, 10 }, - { v4l2_pix_fmt_hevc, vidc_session_type_enc, 675, 10 }, - { v4l2_pix_fmt_vp8, vidc_session_type_enc, 675, 10 }, - { v4l2_pix_fmt_mpeg2, vidc_session_type_dec, 200, 10 }, - { v4l2_pix_fmt_h264, vidc_session_type_dec, 200, 10 }, - { v4l2_pix_fmt_hevc, vidc_session_type_dec, 200, 10 }, - { v4l2_pix_fmt_vp8, vidc_session_type_dec, 200, 10 }, - { v4l2_pix_fmt_vp9, vidc_session_type_dec, 200, 10 }, -}; - - .codec_freq_data = sdm845_codec_freq_data, - .codec_freq_data_size = array_size(sdm845_codec_freq_data), - .codec_freq_data = sdm845_codec_freq_data, - .codec_freq_data_size = array_size(sdm845_codec_freq_data), - .codec_freq_data = sdm845_codec_freq_data, - .codec_freq_data_size = array_size(sdm845_codec_freq_data), diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h -struct codec_freq_data { - u32 pixfmt; - u32 session_type; - unsigned long vpp_freq; - unsigned long vsp_freq; -}; - - const struct codec_freq_data *codec_freq_data; - unsigned int codec_freq_data_size; - const struct codec_freq_data *codec_freq_data; + unsigned long vpp_freq; + unsigned long vsp_freq; diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c --- a/drivers/media/platform/qcom/venus/helpers.c +++ b/drivers/media/platform/qcom/venus/helpers.c +#include "hfi_platform.h" -int venus_helper_init_codec_freq_data(struct venus_inst *inst) -{ - const struct codec_freq_data *data; - unsigned int i, data_size; - u32 pixfmt; - int ret = 0; - - if (!is_v4(inst->core)) - return 0; - - data = inst->core->res->codec_freq_data; - data_size = inst->core->res->codec_freq_data_size; - pixfmt = inst->session_type == vidc_session_type_dec ? - inst->fmt_out->pixfmt : inst->fmt_cap->pixfmt; - - for (i = 0; i < data_size; i++) { - if (data[i].pixfmt == pixfmt && - data[i].session_type == inst->session_type) { - inst->clk_data.codec_freq_data = &data[i]; - break; - } - } - - if (!inst->clk_data.codec_freq_data) - ret = -einval; - - return ret; -} -export_symbol_gpl(venus_helper_init_codec_freq_data); - +int venus_helper_session_init(struct venus_inst *inst) +{ + enum hfi_version version = inst->core->res->hfi_version; + u32 session_type = inst->session_type; + u32 codec; + int ret; + + codec = inst->session_type == vidc_session_type_dec ? + inst->fmt_out->pixfmt : inst->fmt_cap->pixfmt; + + ret = hfi_session_init(inst, codec); + if (ret) + return ret; + + inst->clk_data.vpp_freq = hfi_platform_get_codec_vpp_freq(version, codec, + session_type); + inst->clk_data.vsp_freq = hfi_platform_get_codec_vsp_freq(version, codec, + session_type); + + return 0; +} +export_symbol_gpl(venus_helper_session_init); + diff --git a/drivers/media/platform/qcom/venus/helpers.h b/drivers/media/platform/qcom/venus/helpers.h --- a/drivers/media/platform/qcom/venus/helpers.h +++ b/drivers/media/platform/qcom/venus/helpers.h -int venus_helper_init_codec_freq_data(struct venus_inst *inst); +int venus_helper_session_init(struct venus_inst *inst); diff --git a/drivers/media/platform/qcom/venus/hfi_platform.c b/drivers/media/platform/qcom/venus/hfi_platform.c --- /dev/null +++ b/drivers/media/platform/qcom/venus/hfi_platform.c +// spdx-license-identifier: gpl-2.0-only +/* + * copyright (c) 2020, the linux foundation. all rights reserved. + */ +#include "hfi_platform.h" + +const struct hfi_platform *hfi_platform_get(enum hfi_version version) +{ + switch (version) { + case hfi_version_4xx: + return &hfi_plat_v4; + default: + break; + } + + return null; +} + +unsigned long +hfi_platform_get_codec_vpp_freq(enum hfi_version version, u32 codec, u32 session_type) +{ + const struct hfi_platform *plat; + unsigned long freq = 0; + + plat = hfi_platform_get(version); + if (!plat) + return 0; + + if (plat->codec_vpp_freq) + freq = plat->codec_vpp_freq(session_type, codec); + + return freq; +} + +unsigned long +hfi_platform_get_codec_vsp_freq(enum hfi_version version, u32 codec, u32 session_type) +{ + const struct hfi_platform *plat; + unsigned long freq = 0; + + plat = hfi_platform_get(version); + if (!plat) + return 0; + + if (plat->codec_vpp_freq) + freq = plat->codec_vsp_freq(session_type, codec); + + return freq; +} diff --git a/drivers/media/platform/qcom/venus/hfi_platform.h b/drivers/media/platform/qcom/venus/hfi_platform.h --- /dev/null +++ b/drivers/media/platform/qcom/venus/hfi_platform.h +/* spdx-license-identifier: gpl-2.0-only */ +/* + * copyright (c) 2020, the linux foundation. all rights reserved. + */ + +#ifndef __hfi_platform_h__ +#define __hfi_platform_h__ + +#include <linux/types.h> +#include <linux/videodev2.h> + +#include "hfi.h" +#include "hfi_helper.h" + +struct hfi_platform_codec_freq_data { + u32 pixfmt; + u32 session_type; + unsigned long vpp_freq; + unsigned long vsp_freq; +}; + +struct hfi_platform { + unsigned long (*codec_vpp_freq)(u32 session_type, u32 codec); + unsigned long (*codec_vsp_freq)(u32 session_type, u32 codec); +}; + +extern const struct hfi_platform hfi_plat_v4; + +const struct hfi_platform *hfi_platform_get(enum hfi_version version); +unsigned long hfi_platform_get_codec_vpp_freq(enum hfi_version version, u32 codec, + u32 session_type); +unsigned long hfi_platform_get_codec_vsp_freq(enum hfi_version version, u32 codec, + u32 session_type); +#endif diff --git a/drivers/media/platform/qcom/venus/hfi_platform_v4.c b/drivers/media/platform/qcom/venus/hfi_platform_v4.c --- /dev/null +++ b/drivers/media/platform/qcom/venus/hfi_platform_v4.c +// spdx-license-identifier: gpl-2.0-only +/* + * copyright (c) 2020, the linux foundation. all rights reserved. + */ +#include "hfi_platform.h" + +static const struct hfi_platform_codec_freq_data codec_freq_data[] = { + { v4l2_pix_fmt_h264, vidc_session_type_enc, 675, 10 }, + { v4l2_pix_fmt_hevc, vidc_session_type_enc, 675, 10 }, + { v4l2_pix_fmt_vp8, vidc_session_type_enc, 675, 10 }, + { v4l2_pix_fmt_mpeg2, vidc_session_type_dec, 200, 10 }, + { v4l2_pix_fmt_h264, vidc_session_type_dec, 200, 10 }, + { v4l2_pix_fmt_hevc, vidc_session_type_dec, 200, 10 }, + { v4l2_pix_fmt_vp8, vidc_session_type_dec, 200, 10 }, + { v4l2_pix_fmt_vp9, vidc_session_type_dec, 200, 10 }, +}; + +static const struct hfi_platform_codec_freq_data * +get_codec_freq_data(u32 session_type, u32 pixfmt) +{ + const struct hfi_platform_codec_freq_data *data = codec_freq_data; + unsigned int i, data_size = array_size(codec_freq_data); + const struct hfi_platform_codec_freq_data *found = null; + + for (i = 0; i < data_size; i++) { + if (data[i].pixfmt == pixfmt && data[i].session_type == session_type) { + found = &data[i]; + break; + } + } + + return found; +} + +static unsigned long codec_vpp_freq(u32 session_type, u32 codec) +{ + const struct hfi_platform_codec_freq_data *data; + + data = get_codec_freq_data(session_type, codec); + if (data) + return data->vpp_freq; + + return 0; +} + +static unsigned long codec_vsp_freq(u32 session_type, u32 codec) +{ + const struct hfi_platform_codec_freq_data *data; + + data = get_codec_freq_data(session_type, codec); + if (data) + return data->vsp_freq; + + return 0; +} + +const struct hfi_platform hfi_plat_v4 = { + .codec_vpp_freq = codec_vpp_freq, + .codec_vsp_freq = codec_vsp_freq, +}; diff --git a/drivers/media/platform/qcom/venus/pm_helpers.c b/drivers/media/platform/qcom/venus/pm_helpers.c --- a/drivers/media/platform/qcom/venus/pm_helpers.c +++ b/drivers/media/platform/qcom/venus/pm_helpers.c +#include "hfi_platform.h" - vpp_freq = inst_pos->clk_data.codec_freq_data->vpp_freq; + vpp_freq = inst_pos->clk_data.vpp_freq; - inst_load *= inst->clk_data.codec_freq_data->vpp_freq; + inst_load *= inst->clk_data.vpp_freq; - vpp_freq = mbs_per_sec * inst->clk_data.codec_freq_data->vpp_freq; + vpp_freq = mbs_per_sec * inst->clk_data.vpp_freq; - vsp_freq = mbs_per_sec * inst->clk_data.codec_freq_data->vsp_freq; + vsp_freq = mbs_per_sec * inst->clk_data.vsp_freq; diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c - ret = hfi_session_init(inst, inst->fmt_out->pixfmt); + ret = venus_helper_session_init(inst); - ret = venus_helper_init_codec_freq_data(inst); - if (ret) - goto deinit; - diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c - ret = hfi_session_init(inst, inst->fmt_cap->pixfmt); + ret = venus_helper_session_init(inst); - ret = venus_helper_init_codec_freq_data(inst); - if (ret) - goto deinit; -
TV tuners, webcams, video capturers
aa6033892b1d8ea956ce0358867806e171a620d1
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: rename venus_caps to hfi_plat_caps
now when we have hfi platform make venus capabilities an hfi platform capabilities.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
5
41
40
--- diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h +#include "hfi_platform.h" -#define max_planes 4 -#define max_fmt_entries 32 -#define max_cap_entries 32 -#define max_alloc_mode_entries 16 -#define max_codec_num 32 -#define max_sessions 16 - -struct raw_formats { - u32 buftype; - u32 fmt; -}; - -struct venus_caps { - u32 codec; - u32 domain; - bool cap_bufs_mode_dynamic; - unsigned int num_caps; - struct hfi_capability caps[max_cap_entries]; - unsigned int num_pl; - struct hfi_profile_level pl[hfi_max_profile_count]; - unsigned int num_fmts; - struct raw_formats fmts[max_fmt_entries]; - bool valid; /* used only for venus v1xx */ -}; - - struct venus_caps caps[max_codec_num]; + struct hfi_plat_caps caps[max_codec_num]; -static inline struct venus_caps * +static inline struct hfi_plat_caps * diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c --- a/drivers/media/platform/qcom/venus/helpers.c +++ b/drivers/media/platform/qcom/venus/helpers.c - struct venus_caps *caps; + struct hfi_plat_caps *caps; -static bool find_fmt_from_caps(struct venus_caps *caps, u32 buftype, u32 fmt) +static bool find_fmt_from_caps(struct hfi_plat_caps *caps, u32 buftype, u32 fmt) - struct venus_caps *caps; + struct hfi_plat_caps *caps; diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c b/drivers/media/platform/qcom/venus/hfi_parser.c --- a/drivers/media/platform/qcom/venus/hfi_parser.c +++ b/drivers/media/platform/qcom/venus/hfi_parser.c -typedef void (*func)(struct venus_caps *cap, const void *data, +typedef void (*func)(struct hfi_plat_caps *cap, const void *data, - struct venus_caps *caps = core->caps, *cap; + struct hfi_plat_caps *caps = core->caps, *cap; -static void for_each_codec(struct venus_caps *caps, unsigned int caps_num, +static void for_each_codec(struct hfi_plat_caps *caps, unsigned int caps_num, - struct venus_caps *cap; + struct hfi_plat_caps *cap; -fill_buf_mode(struct venus_caps *cap, const void *data, unsigned int num) +fill_buf_mode(struct hfi_plat_caps *cap, const void *data, unsigned int num) -static void fill_profile_level(struct venus_caps *cap, const void *data, +static void fill_profile_level(struct hfi_plat_caps *cap, const void *data, -fill_caps(struct venus_caps *cap, const void *data, unsigned int num) +fill_caps(struct hfi_plat_caps *cap, const void *data, unsigned int num) -static void fill_raw_fmts(struct venus_caps *cap, const void *fmts, +static void fill_raw_fmts(struct hfi_plat_caps *cap, const void *fmts, - struct venus_caps *caps, *cap; + struct hfi_plat_caps *caps, *cap; diff --git a/drivers/media/platform/qcom/venus/hfi_parser.h b/drivers/media/platform/qcom/venus/hfi_parser.h --- a/drivers/media/platform/qcom/venus/hfi_parser.h +++ b/drivers/media/platform/qcom/venus/hfi_parser.h - struct venus_caps *caps; + struct hfi_plat_caps *caps; diff --git a/drivers/media/platform/qcom/venus/hfi_platform.h b/drivers/media/platform/qcom/venus/hfi_platform.h --- a/drivers/media/platform/qcom/venus/hfi_platform.h +++ b/drivers/media/platform/qcom/venus/hfi_platform.h +#define max_planes 4 +#define max_fmt_entries 32 +#define max_cap_entries 32 +#define max_alloc_mode_entries 16 +#define max_codec_num 32 +#define max_sessions 16 + +struct raw_formats { + u32 buftype; + u32 fmt; +}; + +struct hfi_plat_caps { + u32 codec; + u32 domain; + bool cap_bufs_mode_dynamic; + unsigned int num_caps; + struct hfi_capability caps[max_cap_entries]; + unsigned int num_pl; + struct hfi_profile_level pl[hfi_max_profile_count]; + unsigned int num_fmts; + struct raw_formats fmts[max_fmt_entries]; + bool valid; /* used only for venus v1xx */ +}; +
TV tuners, webcams, video capturers
8f3b41dcfb9a0fa2d2ca0af51c3eebd670dc153b
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: hfi_plat: add codecs and capabilities ops
add ops to get the supported by the platform codecs and capabilities.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h']
1
2
0
--- diff --git a/drivers/media/platform/qcom/venus/hfi_platform.h b/drivers/media/platform/qcom/venus/hfi_platform.h --- a/drivers/media/platform/qcom/venus/hfi_platform.h +++ b/drivers/media/platform/qcom/venus/hfi_platform.h + void (*codecs)(u32 *enc_codecs, u32 *dec_codecs, u32 *count); + const struct hfi_plat_caps *(*capabilities)(unsigned int *entries);
TV tuners, webcams, video capturers
9822291e031f6d7149ae4f3fc00bd9c33ac2a084
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: hfi_plat_v4: populate codecs and capabilities for v4
add new file for venus hfi v4 with supported codecs and capabilities.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['c']
1
259
0
--- diff --git a/drivers/media/platform/qcom/venus/hfi_platform_v4.c b/drivers/media/platform/qcom/venus/hfi_platform_v4.c --- a/drivers/media/platform/qcom/venus/hfi_platform_v4.c +++ b/drivers/media/platform/qcom/venus/hfi_platform_v4.c +static const struct hfi_plat_caps caps[] = { +{ + .codec = hfi_video_codec_h264, + .domain = vidc_session_type_dec, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 1}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 1}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 4096, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 4096, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 2073600, 1}, + .caps[7] = {hfi_capability_framerate, 1, 480, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 2, 1}, + .caps[9] = {hfi_capability_max_workmodes, 1, 3, 1}, + .num_caps = 10, + .pl[0] = {hfi_h264_profile_baseline, hfi_h264_level_52}, + .pl[1] = {hfi_h264_profile_main, hfi_h264_level_52}, + .pl[2] = {hfi_h264_profile_high, hfi_h264_level_52}, + .pl[3] = {hfi_h264_profile_constrained_base, hfi_h264_level_52}, + .pl[4] = {hfi_h264_profile_constrained_high, hfi_h264_level_52}, + .num_pl = 5, + .fmts[0] = {hfi_buffer_output, hfi_color_format_nv12_ubwc}, + .fmts[1] = {hfi_buffer_output2, hfi_color_format_nv12_ubwc}, + .fmts[2] = {hfi_buffer_output2, hfi_color_format_nv12}, + .fmts[3] = {hfi_buffer_output2, hfi_color_format_nv21}, + .num_fmts = 4, +}, { + .codec = hfi_video_codec_hevc, + .domain = vidc_session_type_dec, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 1}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 1}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 4096, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 4096, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 2073600, 1}, + .caps[7] = {hfi_capability_framerate, 1, 480, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 2, 1}, + .caps[9] = {hfi_capability_max_workmodes, 1, 3, 1}, + .num_caps = 10, + .pl[0] = {hfi_hevc_profile_main, hfi_hevc_level_6 | hfi_hevc_tier_high0 << 28}, + .pl[1] = {hfi_hevc_profile_main10, hfi_hevc_level_6 | hfi_hevc_tier_high0 << 28}, + .num_pl = 2, + .fmts[0] = {hfi_buffer_output, hfi_color_format_nv12_ubwc}, + .fmts[1] = {hfi_buffer_output, hfi_color_format_yuv420_tp10_ubwc}, + .fmts[2] = {hfi_buffer_output2, hfi_color_format_nv12_ubwc}, + .fmts[3] = {hfi_buffer_output2, hfi_color_format_nv12}, + .fmts[4] = {hfi_buffer_output2, hfi_color_format_nv21}, + .fmts[5] = {hfi_buffer_output2, hfi_color_format_p010}, + .fmts[6] = {hfi_buffer_output2, hfi_color_format_yuv420_tp10}, + .num_fmts = 7, +}, { + .codec = hfi_video_codec_vp8, + .domain = vidc_session_type_dec, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 1}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 1}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 4096, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 4096, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 2073600, 1}, + .caps[7] = {hfi_capability_framerate, 1, 480, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 2, 1}, + .caps[9] = {hfi_capability_max_workmodes, 1, 3, 1}, + .num_caps = 10, + .pl[0] = {hfi_vpx_profile_main, hfi_vpx_level_version_0}, + .pl[1] = {hfi_vpx_profile_main, hfi_vpx_level_version_1}, + .pl[2] = {hfi_vpx_profile_main, hfi_vpx_level_version_2}, + .pl[3] = {hfi_vpx_profile_main, hfi_vpx_level_version_3}, + .num_pl = 4, + .fmts[0] = {hfi_buffer_output, hfi_color_format_nv12_ubwc}, + .fmts[1] = {hfi_buffer_output2, hfi_color_format_nv12_ubwc}, + .fmts[2] = {hfi_buffer_output2, hfi_color_format_nv12}, + .fmts[3] = {hfi_buffer_output2, hfi_color_format_nv21}, + .num_fmts = 4, +}, { + .codec = hfi_video_codec_vp9, + .domain = vidc_session_type_dec, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 1}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 1}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 4096, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 4096, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 2073600, 1}, + .caps[7] = {hfi_capability_framerate, 1, 480, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 2, 1}, + .caps[9] = {hfi_capability_max_workmodes, 1, 3, 1}, + .num_caps = 10, + .pl[0] = {hfi_vp9_profile_p0, 200}, + .pl[1] = {hfi_vp9_profile_p2_10b, 200}, + .num_pl = 2, + .fmts[0] = {hfi_buffer_output, hfi_color_format_nv12_ubwc}, + .fmts[1] = {hfi_buffer_output, hfi_color_format_yuv420_tp10_ubwc}, + .fmts[2] = {hfi_buffer_output2, hfi_color_format_nv12_ubwc}, + .fmts[3] = {hfi_buffer_output2, hfi_color_format_nv12}, + .fmts[4] = {hfi_buffer_output2, hfi_color_format_nv21}, + .fmts[5] = {hfi_buffer_output2, hfi_color_format_p010}, + .fmts[6] = {hfi_buffer_output2, hfi_color_format_yuv420_tp10}, + .num_fmts = 7, +}, { + .codec = hfi_video_codec_mpeg2, + .domain = vidc_session_type_dec, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 1920, 1}, + .caps[1] = {hfi_capability_frame_height, 96, 1920, 1}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 8160, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 40000000, 1}, + .caps[4] = {hfi_capability_scale_x, 4096, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 4096, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 244800, 1}, + .caps[7] = {hfi_capability_framerate, 1, 30, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 2, 1}, + .caps[9] = {hfi_capability_max_workmodes, 1, 1, 1}, + .num_caps = 10, + .pl[0] = {hfi_mpeg2_profile_simple, hfi_mpeg2_level_h14}, + .pl[1] = {hfi_mpeg2_profile_main, hfi_mpeg2_level_h14}, + .num_pl = 2, + .fmts[0] = {hfi_buffer_output, hfi_color_format_nv12_ubwc}, + .fmts[1] = {hfi_buffer_output2, hfi_color_format_nv12_ubwc}, + .fmts[2] = {hfi_buffer_output2, hfi_color_format_nv12}, + .fmts[3] = {hfi_buffer_output2, hfi_color_format_nv21}, + .num_fmts = 4, +}, { + .codec = hfi_video_codec_h264, + .domain = vidc_session_type_enc, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 16}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 16}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 8192, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 8192, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 1036800, 1}, + .caps[7] = {hfi_capability_framerate, 1, 480, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 3, 1}, + .caps[9] = {hfi_capability_peakbitrate, 32000, 160000000, 1}, + .caps[10] = {hfi_capability_hier_p_num_enh_layers, 0, 5, 1}, + .caps[11] = {hfi_capability_enc_ltr_count, 0, 4, 1}, + .caps[12] = {hfi_capability_lcu_size, 16, 16, 1}, + .caps[13] = {hfi_capability_bframe, 0, 1, 1}, + .caps[14] = {hfi_capability_hier_p_hybrid_num_enh_layers, 0, 5, 1}, + .caps[15] = {hfi_capability_i_frame_qp, 0, 51, 1}, + .caps[16] = {hfi_capability_p_frame_qp, 0, 51, 1}, + .caps[17] = {hfi_capability_b_frame_qp, 0, 51, 1}, + .caps[18] = {hfi_capability_max_workmodes, 1, 2, 1}, + .caps[19] = {hfi_capability_rate_control_modes, 0x1000001, 0x1000005, 1}, + .caps[20] = {hfi_capability_color_space_conversion, 0, 2, 1}, + .num_caps = 21, + .pl[0] = {hfi_h264_profile_baseline, hfi_h264_level_52}, + .pl[1] = {hfi_h264_profile_main, hfi_h264_level_52}, + .pl[2] = {hfi_h264_profile_high, hfi_h264_level_52}, + .pl[3] = {hfi_h264_profile_constrained_base, hfi_h264_level_52}, + .pl[4] = {hfi_h264_profile_constrained_high, hfi_h264_level_52}, + .num_pl = 5, + .fmts[0] = {hfi_buffer_input, hfi_color_format_nv12}, + .fmts[1] = {hfi_buffer_input, hfi_color_format_nv12_ubwc}, + .fmts[2] = {hfi_buffer_input, hfi_color_format_yuv420_tp10_ubwc}, + .fmts[3] = {hfi_buffer_input, hfi_color_format_p010}, + .num_fmts = 4, +}, { + .codec = hfi_video_codec_hevc, + .domain = vidc_session_type_enc, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 16}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 16}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 8192, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 8192, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 1036800, 1}, + .caps[7] = {hfi_capability_framerate, 1, 480, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 3, 1}, + .caps[9] = {hfi_capability_peakbitrate, 32000, 160000000, 1}, + .caps[10] = {hfi_capability_hier_p_num_enh_layers, 0, 5, 1}, + .caps[11] = {hfi_capability_enc_ltr_count, 0, 4, 1}, + .caps[12] = {hfi_capability_lcu_size, 32, 32, 1}, + .caps[13] = {hfi_capability_bframe, 0, 1, 1}, + .caps[14] = {hfi_capability_hier_p_hybrid_num_enh_layers, 0, 5, 1}, + .caps[15] = {hfi_capability_i_frame_qp, 0, 63, 1}, + .caps[16] = {hfi_capability_p_frame_qp, 0, 63, 1}, + .caps[17] = {hfi_capability_b_frame_qp, 0, 63, 1}, + .caps[18] = {hfi_capability_max_workmodes, 1, 2, 1}, + .caps[19] = {hfi_capability_rate_control_modes, 0x1000001, 0x1000005, 1}, + .caps[20] = {hfi_capability_color_space_conversion, 0, 2, 1}, + .caps[21] = {hfi_capability_rotation, 1, 4, 90}, + .caps[22] = {hfi_capability_blur_width, 96, 4096, 16}, + .caps[23] = {hfi_capability_blur_height, 96, 4096, 16}, + .num_caps = 24, + .pl[0] = {hfi_hevc_profile_main, hfi_hevc_level_6 | hfi_hevc_tier_high0}, + .pl[1] = {hfi_hevc_profile_main10, hfi_hevc_level_6 | hfi_hevc_tier_high0}, + .num_pl = 2, + .fmts[0] = {hfi_buffer_input, hfi_color_format_nv12}, + .fmts[1] = {hfi_buffer_input, hfi_color_format_nv12_ubwc}, + .fmts[2] = {hfi_buffer_input, hfi_color_format_yuv420_tp10_ubwc}, + .fmts[3] = {hfi_buffer_input, hfi_color_format_p010}, + .num_fmts = 4, +}, { + .codec = hfi_video_codec_vp8, + .domain = vidc_session_type_enc, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 16}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 16}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 8192, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 8192, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 1036800, 1}, + .caps[7] = {hfi_capability_framerate, 1, 240, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 3, 1}, + .caps[9] = {hfi_capability_peakbitrate, 32000, 160000000, 1}, + .caps[10] = {hfi_capability_hier_p_num_enh_layers, 0, 3, 1}, + .caps[11] = {hfi_capability_enc_ltr_count, 0, 2, 1}, + .caps[12] = {hfi_capability_lcu_size, 16, 16, 1}, + .caps[13] = {hfi_capability_bframe, 0, 1, 1}, + .caps[14] = {hfi_capability_hier_p_hybrid_num_enh_layers, 0, 5, 1}, + .caps[15] = {hfi_capability_i_frame_qp, 0, 127, 1}, + .caps[16] = {hfi_capability_p_frame_qp, 0, 127, 1}, + .caps[17] = {hfi_capability_max_workmodes, 1, 2, 1}, + .caps[18] = {hfi_capability_rate_control_modes, 0x1000001, 0x1000005, 1}, + .caps[19] = {hfi_capability_blur_width, 96, 4096, 16}, + .caps[20] = {hfi_capability_blur_height, 96, 4096, 16}, + .caps[21] = {hfi_capability_color_space_conversion, 0, 2, 1}, + .caps[22] = {hfi_capability_rotation, 1, 4, 90}, + .num_caps = 23, + .pl[0] = {hfi_vpx_profile_main, hfi_vpx_level_version_0}, + .pl[1] = {hfi_vpx_profile_main, hfi_vpx_level_version_1}, + .pl[2] = {hfi_vpx_profile_main, hfi_vpx_level_version_2}, + .pl[3] = {hfi_vpx_profile_main, hfi_vpx_level_version_3}, + .num_pl = 4, + .fmts[0] = {hfi_buffer_input, hfi_color_format_nv12}, + .fmts[1] = {hfi_buffer_input, hfi_color_format_nv12_ubwc}, + .fmts[2] = {hfi_buffer_input, hfi_color_format_yuv420_tp10_ubwc}, + .fmts[3] = {hfi_buffer_input, hfi_color_format_p010}, + .num_fmts = 4, +} }; + +static const struct hfi_plat_caps *get_capabilities(unsigned int *entries) +{ + *entries = array_size(caps); + return caps; +} + +static void get_codecs(u32 *enc_codecs, u32 *dec_codecs, u32 *count) +{ + *enc_codecs = hfi_video_codec_h264 | hfi_video_codec_hevc | + hfi_video_codec_vp8; + *dec_codecs = hfi_video_codec_h264 | hfi_video_codec_hevc | + hfi_video_codec_vp8 | hfi_video_codec_vp9 | + hfi_video_codec_mpeg2; + *count = 8; +} + + .codecs = get_codecs, + .capabilities = get_capabilities,
TV tuners, webcams, video capturers
8b88cabef404ef07440ce90730c47b0f10935c8e
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: hfi_plat: add platform ops for getting number of vpp pipes
starting from v6 we have one more hfi property which will be needed to calculate buffer sizes/count for particular codec and session type.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
2
16
0
--- diff --git a/drivers/media/platform/qcom/venus/hfi_platform.c b/drivers/media/platform/qcom/venus/hfi_platform.c --- a/drivers/media/platform/qcom/venus/hfi_platform.c +++ b/drivers/media/platform/qcom/venus/hfi_platform.c + +u8 hfi_platform_num_vpp_pipes(enum hfi_version version) +{ + const struct hfi_platform *plat; + + plat = hfi_platform_get(version); + if (!plat) + return 0; + + if (plat->num_vpp_pipes) + return plat->num_vpp_pipes(); + + return 0; +} diff --git a/drivers/media/platform/qcom/venus/hfi_platform.h b/drivers/media/platform/qcom/venus/hfi_platform.h --- a/drivers/media/platform/qcom/venus/hfi_platform.h +++ b/drivers/media/platform/qcom/venus/hfi_platform.h + u8 (*num_vpp_pipes)(void); +u8 hfi_platform_num_vpp_pipes(enum hfi_version version);
TV tuners, webcams, video capturers
367b619ae70d25a0ccbbb7cf97db80cf2660657a
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: hfi_plat_v6: populate capabilities for v6
add new hfi platform file with capabilities of hfi v6.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c', 'makefile']
4
329
0
--- diff --git a/drivers/media/platform/qcom/venus/makefile b/drivers/media/platform/qcom/venus/makefile --- a/drivers/media/platform/qcom/venus/makefile +++ b/drivers/media/platform/qcom/venus/makefile + hfi_platform_v6.o \ diff --git a/drivers/media/platform/qcom/venus/hfi_platform.c b/drivers/media/platform/qcom/venus/hfi_platform.c --- a/drivers/media/platform/qcom/venus/hfi_platform.c +++ b/drivers/media/platform/qcom/venus/hfi_platform.c + case hfi_version_6xx: + return &hfi_plat_v6; diff --git a/drivers/media/platform/qcom/venus/hfi_platform.h b/drivers/media/platform/qcom/venus/hfi_platform.h --- a/drivers/media/platform/qcom/venus/hfi_platform.h +++ b/drivers/media/platform/qcom/venus/hfi_platform.h +extern const struct hfi_platform hfi_plat_v6; diff --git a/drivers/media/platform/qcom/venus/hfi_platform_v6.c b/drivers/media/platform/qcom/venus/hfi_platform_v6.c --- /dev/null +++ b/drivers/media/platform/qcom/venus/hfi_platform_v6.c +// spdx-license-identifier: gpl-2.0-only +/* + * copyright (c) 2020, the linux foundation. all rights reserved. + */ +#include "hfi_platform.h" + +static const struct hfi_plat_caps caps[] = { +{ + .codec = hfi_video_codec_h264, + .domain = vidc_session_type_dec, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 5760, 1}, + .caps[1] = {hfi_capability_frame_height, 96, 5760, 1}, + /* ((5760 * 2880) / 256) */ + .caps[2] = {hfi_capability_mbs_per_frame, 36, 64800, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 200000000, 1}, + .caps[4] = {hfi_capability_scale_x, 65536, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 65536, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 36, 1958400, 1}, + .caps[7] = {hfi_capability_framerate, 1, 480, 1}, + .caps[8] = {hfi_capability_max_videocores, 0, 1, 1}, + .num_caps = 9, + .pl[0] = {hfi_h264_profile_baseline, hfi_h264_level_52}, + .pl[1] = {hfi_h264_profile_main, hfi_h264_level_52}, + .pl[2] = {hfi_h264_profile_high, hfi_h264_level_52}, + .pl[3] = {hfi_h264_profile_constrained_base, hfi_h264_level_52}, + .pl[4] = {hfi_h264_profile_constrained_high, hfi_h264_level_52}, + .num_pl = 5, + .fmts[0] = {hfi_buffer_output, hfi_color_format_nv12_ubwc}, + .fmts[1] = {hfi_buffer_output2, hfi_color_format_nv12_ubwc}, + .fmts[2] = {hfi_buffer_output2, hfi_color_format_nv12}, + .fmts[3] = {hfi_buffer_output2, hfi_color_format_nv21}, + .num_fmts = 4, +}, { + .codec = hfi_video_codec_hevc, + .domain = vidc_session_type_dec, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 1}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 1}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 4096, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 4096, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 2073600, 1}, + .caps[7] = {hfi_capability_framerate, 1, 480, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 2, 1}, + .caps[9] = {hfi_capability_max_workmodes, 1, 3, 1}, + .num_caps = 10, + .pl[0] = {hfi_hevc_profile_main, hfi_hevc_level_6 | hfi_hevc_tier_high0}, + .pl[1] = {hfi_hevc_profile_main10, hfi_hevc_level_6 | hfi_hevc_tier_high0}, + .num_pl = 2, + .fmts[0] = {hfi_buffer_output, hfi_color_format_nv12_ubwc}, + .fmts[1] = {hfi_buffer_output, hfi_color_format_yuv420_tp10_ubwc}, + .fmts[2] = {hfi_buffer_output2, hfi_color_format_nv12_ubwc}, + .fmts[3] = {hfi_buffer_output2, hfi_color_format_nv12}, + .fmts[4] = {hfi_buffer_output2, hfi_color_format_nv21}, + .fmts[5] = {hfi_buffer_output2, hfi_color_format_p010}, + .fmts[6] = {hfi_buffer_output2, hfi_color_format_yuv420_tp10}, + .num_fmts = 7, +}, { + .codec = hfi_video_codec_vp8, + .domain = vidc_session_type_dec, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 1}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 1}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 4096, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 4096, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 2073600, 1}, + .caps[7] = {hfi_capability_framerate, 1, 480, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 2, 1}, + .caps[9] = {hfi_capability_max_workmodes, 1, 3, 1}, + .num_caps = 10, + .pl[0] = {hfi_vpx_profile_main, hfi_vpx_level_version_0}, + .pl[1] = {hfi_vpx_profile_main, hfi_vpx_level_version_1}, + .pl[2] = {hfi_vpx_profile_main, hfi_vpx_level_version_2}, + .pl[3] = {hfi_vpx_profile_main, hfi_vpx_level_version_3}, + .num_pl = 4, + .fmts[0] = {hfi_buffer_output, hfi_color_format_nv12_ubwc}, + .fmts[1] = {hfi_buffer_output2, hfi_color_format_nv12_ubwc}, + .fmts[2] = {hfi_buffer_output2, hfi_color_format_nv12}, + .fmts[3] = {hfi_buffer_output2, hfi_color_format_nv21}, + .num_fmts = 4, +}, { + .codec = hfi_video_codec_vp9, + .domain = vidc_session_type_dec, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 1}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 1}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 4096, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 4096, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 2073600, 1}, + .caps[7] = {hfi_capability_framerate, 1, 480, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 2, 1}, + .caps[9] = {hfi_capability_max_workmodes, 1, 3, 1}, + .num_caps = 10, + .pl[0] = {hfi_vp9_profile_p0, 200}, + .pl[1] = {hfi_vp9_profile_p2_10b, 200}, + .num_pl = 2, + .fmts[0] = {hfi_buffer_output, hfi_color_format_nv12_ubwc}, + .fmts[1] = {hfi_buffer_output, hfi_color_format_yuv420_tp10_ubwc}, + .fmts[2] = {hfi_buffer_output2, hfi_color_format_nv12_ubwc}, + .fmts[3] = {hfi_buffer_output2, hfi_color_format_nv12}, + .fmts[4] = {hfi_buffer_output2, hfi_color_format_nv21}, + .fmts[5] = {hfi_buffer_output2, hfi_color_format_p010}, + .fmts[6] = {hfi_buffer_output2, hfi_color_format_yuv420_tp10}, + .num_fmts = 7, +}, { + .codec = hfi_video_codec_mpeg2, + .domain = vidc_session_type_dec, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 1920, 1}, + .caps[1] = {hfi_capability_frame_height, 96, 1920, 1}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 8160, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 40000000, 1}, + .caps[4] = {hfi_capability_scale_x, 4096, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 4096, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 244800, 1}, + .caps[7] = {hfi_capability_framerate, 1, 30, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 2, 1}, + .caps[9] = {hfi_capability_max_workmodes, 1, 1, 1}, + .num_caps = 10, + .pl[0] = {hfi_mpeg2_profile_simple, hfi_mpeg2_level_h14}, + .pl[1] = {hfi_mpeg2_profile_main, hfi_mpeg2_level_h14}, + .num_pl = 2, + .fmts[0] = {hfi_buffer_output, hfi_color_format_nv12_ubwc}, + .fmts[1] = {hfi_buffer_output2, hfi_color_format_nv12_ubwc}, + .fmts[2] = {hfi_buffer_output2, hfi_color_format_nv12}, + .fmts[3] = {hfi_buffer_output2, hfi_color_format_nv21}, + .num_fmts = 4, +}, { + .codec = hfi_video_codec_h264, + .domain = vidc_session_type_enc, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 16}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 16}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 8192, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 8192, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 1036800, 1}, + .caps[7] = {hfi_capability_framerate, 1, 480, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 3, 1}, + .caps[9] = {hfi_capability_peakbitrate, 32000, 160000000, 1}, + .caps[10] = {hfi_capability_hier_p_num_enh_layers, 0, 5, 1}, + .caps[11] = {hfi_capability_enc_ltr_count, 0, 4, 1}, + .caps[12] = {hfi_capability_lcu_size, 16, 16, 1}, + .caps[13] = {hfi_capability_bframe, 0, 1, 1}, + .caps[14] = {hfi_capability_hier_p_hybrid_num_enh_layers, 0, 5, 1}, + .caps[15] = {hfi_capability_i_frame_qp, 0, 51, 1}, + .caps[16] = {hfi_capability_p_frame_qp, 0, 51, 1}, + .caps[17] = {hfi_capability_b_frame_qp, 0, 51, 1}, + .caps[18] = {hfi_capability_max_workmodes, 1, 2, 1}, + .caps[19] = {hfi_capability_rate_control_modes, 0x1000001, 0x1000005, 1}, + .caps[20] = {hfi_capability_color_space_conversion, 0, 2, 1}, + .num_caps = 21, + .pl[0] = {hfi_h264_profile_baseline, hfi_h264_level_52}, + .pl[1] = {hfi_h264_profile_main, hfi_h264_level_52}, + .pl[2] = {hfi_h264_profile_high, hfi_h264_level_52}, + .pl[3] = {hfi_h264_profile_constrained_base, hfi_h264_level_52}, + .pl[4] = {hfi_h264_profile_constrained_high, hfi_h264_level_52}, + .num_pl = 5, + .fmts[0] = {hfi_buffer_input, hfi_color_format_nv12}, + .fmts[1] = {hfi_buffer_input, hfi_color_format_nv12_ubwc}, + .fmts[2] = {hfi_buffer_input, hfi_color_format_yuv420_tp10_ubwc}, + .fmts[3] = {hfi_buffer_input, hfi_color_format_p010}, + .num_fmts = 4, +}, { + .codec = hfi_video_codec_hevc, + .domain = vidc_session_type_enc, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 16}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 16}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 8192, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 8192, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 1036800, 1}, + .caps[7] = {hfi_capability_framerate, 1, 480, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 3, 1}, + .caps[9] = {hfi_capability_peakbitrate, 32000, 160000000, 1}, + .caps[10] = {hfi_capability_hier_p_num_enh_layers, 0, 5, 1}, + .caps[11] = {hfi_capability_enc_ltr_count, 0, 4, 1}, + .caps[12] = {hfi_capability_lcu_size, 32, 32, 1}, + .caps[13] = {hfi_capability_bframe, 0, 1, 1}, + .caps[14] = {hfi_capability_hier_p_hybrid_num_enh_layers, 0, 5, 1}, + .caps[15] = {hfi_capability_i_frame_qp, 0, 63, 1}, + .caps[16] = {hfi_capability_p_frame_qp, 0, 63, 1}, + .caps[17] = {hfi_capability_b_frame_qp, 0, 63, 1}, + .caps[18] = {hfi_capability_max_workmodes, 1, 2, 1}, + .caps[19] = {hfi_capability_rate_control_modes, 0x1000001, 0x1000005, 1}, + .caps[20] = {hfi_capability_color_space_conversion, 0, 2, 1}, + .caps[21] = {hfi_capability_rotation, 1, 4, 90}, + .caps[22] = {hfi_capability_blur_width, 96, 4096, 16}, + .caps[23] = {hfi_capability_blur_height, 96, 4096, 16}, + .num_caps = 24, + .pl[0] = {hfi_hevc_profile_main, hfi_hevc_level_6 | hfi_hevc_tier_high0}, + .pl[1] = {hfi_hevc_profile_main10, hfi_hevc_level_6 | hfi_hevc_tier_high0}, + .num_pl = 2, + .fmts[0] = {hfi_buffer_input, hfi_color_format_nv12}, + .fmts[1] = {hfi_buffer_input, hfi_color_format_nv12_ubwc}, + .fmts[2] = {hfi_buffer_input, hfi_color_format_yuv420_tp10_ubwc}, + .fmts[3] = {hfi_buffer_input, hfi_color_format_p010}, + .num_fmts = 4, +}, { + .codec = hfi_video_codec_vp8, + .domain = vidc_session_type_enc, + .cap_bufs_mode_dynamic = true, + .caps[0] = {hfi_capability_frame_width, 96, 4096, 16}, + .caps[1] = {hfi_capability_frame_height, 96, 4096, 16}, + .caps[2] = {hfi_capability_mbs_per_frame, 1, 36864, 1}, + .caps[3] = {hfi_capability_bitrate, 1, 120000000, 1}, + .caps[4] = {hfi_capability_scale_x, 8192, 65536, 1}, + .caps[5] = {hfi_capability_scale_y, 8192, 65536, 1}, + .caps[6] = {hfi_capability_mbs_per_second, 1, 1036800, 1}, + .caps[7] = {hfi_capability_framerate, 1, 240, 1}, + .caps[8] = {hfi_capability_max_videocores, 1, 3, 1}, + .caps[9] = {hfi_capability_peakbitrate, 32000, 160000000, 1}, + .caps[10] = {hfi_capability_hier_p_num_enh_layers, 0, 3, 1}, + .caps[11] = {hfi_capability_enc_ltr_count, 0, 2, 1}, + .caps[12] = {hfi_capability_lcu_size, 16, 16, 1}, + .caps[13] = {hfi_capability_bframe, 0, 1, 1}, + .caps[14] = {hfi_capability_hier_p_hybrid_num_enh_layers, 0, 5, 1}, + .caps[15] = {hfi_capability_i_frame_qp, 0, 127, 1}, + .caps[16] = {hfi_capability_p_frame_qp, 0, 127, 1}, + .caps[17] = {hfi_capability_max_workmodes, 1, 2, 1}, + .caps[18] = {hfi_capability_rate_control_modes, 0x1000001, 0x1000005, 1}, + .caps[19] = {hfi_capability_blur_width, 96, 4096, 16}, + .caps[20] = {hfi_capability_blur_height, 96, 4096, 16}, + .caps[21] = {hfi_capability_color_space_conversion, 0, 2, 1}, + .caps[22] = {hfi_capability_rotation, 1, 4, 90}, + .num_caps = 23, + .pl[0] = {hfi_vpx_profile_main, hfi_vpx_level_version_0}, + .pl[1] = {hfi_vpx_profile_main, hfi_vpx_level_version_1}, + .pl[2] = {hfi_vpx_profile_main, hfi_vpx_level_version_2}, + .pl[3] = {hfi_vpx_profile_main, hfi_vpx_level_version_3}, + .num_pl = 4, + .fmts[0] = {hfi_buffer_input, hfi_color_format_nv12}, + .fmts[1] = {hfi_buffer_input, hfi_color_format_nv12_ubwc}, + .fmts[2] = {hfi_buffer_input, hfi_color_format_yuv420_tp10_ubwc}, + .fmts[3] = {hfi_buffer_input, hfi_color_format_p010}, + .num_fmts = 4, +} }; + +static const struct hfi_plat_caps *get_capabilities(unsigned int *entries) +{ + *entries = array_size(caps); + return caps; +} + +static void get_codecs(u32 *enc_codecs, u32 *dec_codecs, u32 *count) +{ + *enc_codecs = hfi_video_codec_h264 | hfi_video_codec_hevc | + hfi_video_codec_vp8; + *dec_codecs = hfi_video_codec_h264 | hfi_video_codec_hevc | + hfi_video_codec_vp8 | hfi_video_codec_vp9 | + hfi_video_codec_mpeg2; + *count = 8; +} + +static const struct hfi_platform_codec_freq_data codec_freq_data[] = { + { v4l2_pix_fmt_h264, vidc_session_type_enc, 675, 25 }, + { v4l2_pix_fmt_hevc, vidc_session_type_enc, 675, 25 }, + { v4l2_pix_fmt_vp8, vidc_session_type_enc, 675, 60 }, + { v4l2_pix_fmt_mpeg2, vidc_session_type_dec, 200, 25 }, + { v4l2_pix_fmt_h264, vidc_session_type_dec, 200, 25 }, + { v4l2_pix_fmt_hevc, vidc_session_type_dec, 200, 25 }, + { v4l2_pix_fmt_vp8, vidc_session_type_dec, 200, 60 }, + { v4l2_pix_fmt_vp9, vidc_session_type_dec, 200, 60 }, +}; + +static const struct hfi_platform_codec_freq_data * +get_codec_freq_data(u32 session_type, u32 pixfmt) +{ + const struct hfi_platform_codec_freq_data *data = codec_freq_data; + unsigned int i, data_size = array_size(codec_freq_data); + const struct hfi_platform_codec_freq_data *found = null; + + for (i = 0; i < data_size; i++) { + if (data[i].pixfmt == pixfmt && data[i].session_type == session_type) { + found = &data[i]; + break; + } + } + + return found; +} + +static unsigned long codec_vpp_freq(u32 session_type, u32 codec) +{ + const struct hfi_platform_codec_freq_data *data; + + data = get_codec_freq_data(session_type, codec); + if (data) + return data->vpp_freq; + + return 0; +} + +static unsigned long codec_vsp_freq(u32 session_type, u32 codec) +{ + const struct hfi_platform_codec_freq_data *data; + + data = get_codec_freq_data(session_type, codec); + if (data) + return data->vsp_freq; + + return 0; +} + +static u8 num_vpp_pipes(void) +{ + return 4; +} + +const struct hfi_platform hfi_plat_v6 = { + .codec_vpp_freq = codec_vpp_freq, + .codec_vsp_freq = codec_vsp_freq, + .codecs = get_codecs, + .capabilities = get_capabilities, + .num_vpp_pipes = num_vpp_pipes, +};
TV tuners, webcams, video capturers
869d77e7062906a84c2726dfc2433755b36a57e3
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: hfi_plat: add hfi platform buffers ops
>from venus v6 and beyond the buffer size and count have to be calculated in the v4l2 driver instead of getting them from firmware.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h']
2
38
0
--- diff --git a/drivers/media/platform/qcom/venus/hfi_plat_bufs.h b/drivers/media/platform/qcom/venus/hfi_plat_bufs.h --- /dev/null +++ b/drivers/media/platform/qcom/venus/hfi_plat_bufs.h +/* spdx-license-identifier: gpl-2.0-only */ +/* + * copyright (c) 2020, the linux foundation. all rights reserved. + */ + +#ifndef __hfi_platform_buffers_h__ +#define __hfi_platform_buffers_h__ + +#include <linux/types.h> +#include "hfi_helper.h" + +struct hfi_plat_buffers_params { + u32 width; + u32 height; + u32 codec; + u32 hfi_color_fmt; + enum hfi_version version; + u32 num_vpp_pipes; + union { + struct { + u32 max_mbs_per_frame; + u32 buffer_size_limit; + bool is_secondary_output; + bool is_interlaced; + } dec; + struct { + u32 work_mode; + u32 rc_type; + u32 num_b_frames; + bool is_tenbit; + } enc; + }; +}; + +#endif diff --git a/drivers/media/platform/qcom/venus/hfi_platform.h b/drivers/media/platform/qcom/venus/hfi_platform.h --- a/drivers/media/platform/qcom/venus/hfi_platform.h +++ b/drivers/media/platform/qcom/venus/hfi_platform.h +#include "hfi_plat_bufs.h" + int (*bufreq)(struct hfi_plat_buffers_params *params, u32 session_type, + u32 buftype, struct hfi_buffer_requirements *bufreq);
TV tuners, webcams, video capturers
05ec881b218c9a9500ce6f0b1363034608708040
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: add platform buffers for v6
add a new file for hfi platform buffer size and count calculations for v6.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c', 'makefile']
4
1,322
1
--- diff --git a/drivers/media/platform/qcom/venus/makefile b/drivers/media/platform/qcom/venus/makefile --- a/drivers/media/platform/qcom/venus/makefile +++ b/drivers/media/platform/qcom/venus/makefile - hfi_platform_v6.o \ + hfi_platform_v6.o hfi_plat_bufs_v6.o \ diff --git a/drivers/media/platform/qcom/venus/hfi_plat_bufs.h b/drivers/media/platform/qcom/venus/hfi_plat_bufs.h --- a/drivers/media/platform/qcom/venus/hfi_plat_bufs.h +++ b/drivers/media/platform/qcom/venus/hfi_plat_bufs.h +int hfi_plat_bufreq_v6(struct hfi_plat_buffers_params *params, u32 session_type, + u32 buftype, struct hfi_buffer_requirements *bufreq); + diff --git a/drivers/media/platform/qcom/venus/hfi_plat_bufs_v6.c b/drivers/media/platform/qcom/venus/hfi_plat_bufs_v6.c --- /dev/null +++ b/drivers/media/platform/qcom/venus/hfi_plat_bufs_v6.c +// spdx-license-identifier: gpl-2.0-only +/* + * copyright (c) 2020, the linux foundation. all rights reserved. + */ +#include <linux/kernel.h> +#include <linux/sizes.h> +#include <linux/videodev2.h> + +#include "hfi.h" +#include "hfi_plat_bufs.h" +#include "helpers.h" + +#define min_input_buffers 4 +#define min_enc_output_buffers 4 + +#define nv12_ubwc_y_tile_width 32 +#define nv12_ubwc_y_tile_height 8 +#define nv12_ubwc_uv_tile_width 16 +#define nv12_ubwc_uv_tile_height 8 +#define tp10_ubwc_y_tile_width 48 +#define tp10_ubwc_y_tile_height 4 +#define metadata_stride_multiple 64 +#define metadata_height_multiple 16 +#define hfi_dma_alignment 256 + +#define max_fe_nbr_ctrl_lcu64_line_buffer_size 64 +#define max_fe_nbr_ctrl_lcu32_line_buffer_size 64 +#define max_fe_nbr_ctrl_lcu16_line_buffer_size 64 +#define max_fe_nbr_data_luma_line_buffer_size 640 +#define max_fe_nbr_data_cb_line_buffer_size 320 +#define max_fe_nbr_data_cr_line_buffer_size 320 + +#define max_se_nbr_ctrl_lcu64_line_buffer_size (128 / 8) +#define max_se_nbr_ctrl_lcu32_line_buffer_size (128 / 8) +#define max_se_nbr_ctrl_lcu16_line_buffer_size (128 / 8) + +#define max_pe_nbr_data_lcu64_line_buffer_size (64 * 2 * 3) +#define max_pe_nbr_data_lcu32_line_buffer_size (32 * 2 * 3) +#define max_pe_nbr_data_lcu16_line_buffer_size (16 * 2 * 3) + +#define max_tile_columns 32 /* 8k/256 */ + +#define num_hw_pic_buf 10 +#define bin_buffer_threshold (1280 * 736) +#define h264d_max_slice 1800 +/* sizeof(h264d_buftab_t) aligned to 256 */ +#define size_h264d_buftab_t 256 +/* sizeof(h264d_hw_pic_t) aligned to 32 */ +#define size_h264d_hw_pic_t bit(11) +#define size_h264d_bse_cmd_per_buf (32 * 4) +#define size_h264d_vpp_cmd_per_buf 512 + +/* line buffer definitions, one for luma and 1/2 for each chroma */ +#define size_h264d_lb_fe_top_data(width, height) \ + (max_fe_nbr_data_luma_line_buffer_size * align((width), 16) * 3) + +#define size_h264d_lb_fe_top_ctrl(width, height) \ + (max_fe_nbr_ctrl_lcu64_line_buffer_size * (((width) + 15) >> 4)) + +#define size_h264d_lb_fe_left_ctrl(width, height) \ + (max_fe_nbr_ctrl_lcu64_line_buffer_size * (((height) + 15) >> 4)) + +#define size_h264d_lb_se_top_ctrl(width, height) \ + (max_se_nbr_ctrl_lcu64_line_buffer_size * (((width) + 15) >> 4)) + +#define size_h264d_lb_se_left_ctrl(width, height) \ + (max_se_nbr_ctrl_lcu64_line_buffer_size * (((height) + 15) >> 4)) + +#define size_h264d_lb_pe_top_data(width, height) \ + (max_pe_nbr_data_lcu64_line_buffer_size * (((width) + 15) >> 4)) + +#define size_h264d_lb_vsp_top(width, height) (((((width) + 15) >> 4) << 7)) + +#define size_h264d_lb_recon_dma_metadata_wr(width, height) \ + (align((height), 16) * 32) + +#define size_h264d_qp(width, height) \ + ((((width) + 63) >> 6) * (((height) + 63) >> 6) * 128) + +#define size_hw_pic(size_per_buf) (num_hw_pic_buf * (size_per_buf)) + +#define h264_cabac_hdr_ratio_hd_tot 1 +#define h264_cabac_res_ratio_hd_tot 3 + +/* + * some content need more bin buffer, but limit buffer + * size for high resolution + */ +#define num_slist_buf_h264 (256 + 32) +#define size_slist_buf_h264 512 +#define lcu_max_size_pels 64 +#define lcu_min_size_pels 16 + +#define h265d_max_slice 600 +#define size_h265d_hw_pic_t size_h264d_hw_pic_t +#define size_h265d_bse_cmd_per_buf (16 * sizeof(u32)) +#define size_h265d_vpp_cmd_per_buf 256 + +#define size_h265d_lb_fe_top_data(width, height) \ + (max_fe_nbr_data_luma_line_buffer_size * (align(width, 64) + 8) * 2) + +#define size_h265d_lb_fe_top_ctrl(width, height) \ + (max_fe_nbr_ctrl_lcu64_line_buffer_size * \ + (align(width, lcu_max_size_pels) / lcu_min_size_pels)) + +#define size_h265d_lb_fe_left_ctrl(width, height) \ + (max_fe_nbr_ctrl_lcu64_line_buffer_size * \ + (align(height, lcu_max_size_pels) / lcu_min_size_pels)) + +#define size_h265d_lb_se_top_ctrl(width, height) \ + ((lcu_max_size_pels / 8 * (128 / 8)) * (((width) + 15) >> 4)) + +static inline u32 size_h265d_lb_se_left_ctrl(u32 width, u32 height) +{ + u32 x, y, z; + + x = ((height + 16 - 1) / 8) * max_se_nbr_ctrl_lcu16_line_buffer_size; + y = ((height + 32 - 1) / 8) * max_se_nbr_ctrl_lcu32_line_buffer_size; + z = ((height + 64 - 1) / 8) * max_se_nbr_ctrl_lcu64_line_buffer_size; + + return max3(x, y, z); +} + +#define size_h265d_lb_pe_top_data(width, height) \ + (max_pe_nbr_data_lcu64_line_buffer_size * \ + (align(width, lcu_min_size_pels) / lcu_min_size_pels)) + +#define size_h265d_lb_vsp_top(width, height) ((((width) + 63) >> 6) * 128) + +#define size_h265d_lb_vsp_left(width, height) ((((height) + 63) >> 6) * 128) + +#define size_h265d_lb_recon_dma_metadata_wr(width, height) \ + size_h264d_lb_recon_dma_metadata_wr(width, height) + +#define size_h265d_qp(width, height) size_h264d_qp(width, height) + +#define h265_cabac_hdr_ratio_hd_tot 2 +#define h265_cabac_res_ratio_hd_tot 2 + +/* + * some content need more bin buffer, but limit buffer size + * for high resolution + */ +#define size_slist_buf_h265 bit(10) +#define num_slist_buf_h265 (80 + 20) +#define h265_num_tile_col 32 +#define h265_num_tile_row 128 +#define h265_num_tile (h265_num_tile_row * h265_num_tile_col + 1) + +static inline u32 size_vpxd_lb_fe_left_ctrl(u32 width, u32 height) +{ + u32 x, y, z; + + x = ((height + 15) >> 4) * max_fe_nbr_ctrl_lcu16_line_buffer_size; + y = ((height + 31) >> 5) * max_fe_nbr_ctrl_lcu32_line_buffer_size; + z = ((height + 63) >> 6) * max_fe_nbr_ctrl_lcu64_line_buffer_size; + + return max3(x, y, z); +} + +#define size_vpxd_lb_fe_top_ctrl(width, height) \ + (((align(width, 64) + 8) * 10 * 2)) /* small line */ +#define size_vpxd_lb_se_top_ctrl(width, height) \ + ((((width) + 15) >> 4) * max_fe_nbr_ctrl_lcu16_line_buffer_size) + +static inline u32 size_vpxd_lb_se_left_ctrl(u32 width, u32 height) +{ + u32 x, y, z; + + x = ((height + 15) >> 4) * max_se_nbr_ctrl_lcu16_line_buffer_size; + y = ((height + 31) >> 5) * max_se_nbr_ctrl_lcu32_line_buffer_size; + z = ((height + 63) >> 6) * max_se_nbr_ctrl_lcu64_line_buffer_size; + + return max3(x, y, z); +} + +#define size_vpxd_lb_recon_dma_metadata_wr(width, height) \ + align((align(height, 16) / (4 / 2)) * 64, 32) +#define size_vp8d_lb_fe_top_data(width, height) \ + ((align(width, 16) + 8) * 10 * 2) +#define size_vp9d_lb_fe_top_data(width, height) \ + ((align(align(width, 16), 64) + 8) * 10 * 2) +#define size_vp8d_lb_pe_top_data(width, height) \ + ((align(width, 16) >> 4) * 64) +#define size_vp9d_lb_pe_top_data(width, height) \ + ((align(align(width, 16), 64) >> 6) * 176) +#define size_vp8d_lb_vsp_top(width, height) \ + (((align(width, 16) >> 4) * 64 / 2) + 256) +#define size_vp9d_lb_vsp_top(width, height) \ + (((align(align(width, 16), 64) >> 6) * 64 * 8) + 256) + +#define hfi_iris2_vp9d_comv_size \ + ((((8192 + 63) >> 6) * ((4320 + 63) >> 6) * 8 * 8 * 2 * 8)) + +#define vpx_decoder_frame_concurency_lvl 2 +#define vpx_decoder_frame_bin_hdr_budget_ratio_num 1 +#define vpx_decoder_frame_bin_hdr_budget_ratio_den 2 +#define vpx_decoder_frame_bin_res_budget_ratio_num 3 +#define vpx_decoder_frame_bin_res_budget_ratio_den 2 + +#define vp8_num_frame_info_buf (5 + 1) +#define vp9_num_frame_info_buf (8 + 2 + 1 + 8) +#define vp8_num_probability_table_buf vp8_num_frame_info_buf +#define vp9_num_probability_table_buf (vp9_num_frame_info_buf + 4) +#define vp8_prob_table_size 3840 +#define vp9_prob_table_size 3840 + +#define vp9_udc_header_buf_size (3 * 128) +#define max_superframe_header_len 34 +#define cce_tile_offset_size align(32 * 4 * 4, 32) + +#define qmatrix_size (sizeof(u32) * 128 + 256) +#define mp2d_qpdump_size 115200 +#define hfi_iris2_enc_persist_size 102400 +#define hfi_max_col_frame 6 +#define hfi_venus_venc_tre_wb_buff_size (65 << 4) /* in bytes */ +#define hfi_venus_venc_db_line_buff_per_mb 512 +#define hfi_venus_vppsg_max_registers 2048 +#define hfi_venus_width_alignment 128 +#define hfi_venus_width_ten_bit_alignment 192 +#define hfi_venus_height_alignment 32 + +#define system_lal_tile10 192 +#define num_mbs_720p (((1280 + 15) >> 4) * ((720 + 15) >> 4)) +#define num_mbs_4k (((4096 + 15) >> 4) * ((2304 + 15) >> 4)) +#define mb_size_in_pixel (16 * 16) +#define hdr10plus_payload_size 1024 +#define hdr10_hist_extradata_size 4096 + +static u32 size_vpss_lb(u32 width, u32 height, u32 num_vpp_pipes) +{ + u32 vpss_4tap_top_buffer_size, vpss_div2_top_buffer_size; + u32 vpss_4tap_left_buffer_size, vpss_div2_left_buffer_size; + u32 opb_wr_top_line_luma_buf_size, opb_wr_top_line_chroma_buf_size; + u32 opb_lb_wr_llb_y_buffer_size, opb_lb_wr_llb_uv_buffer_size; + u32 macrotiling_size; + u32 size = 0; + + vpss_4tap_top_buffer_size = 0; + vpss_div2_top_buffer_size = 0; + vpss_4tap_left_buffer_size = 0; + vpss_div2_left_buffer_size = 0; + + macrotiling_size = 32; + opb_wr_top_line_luma_buf_size = + align(width, macrotiling_size) / macrotiling_size * 256; + opb_wr_top_line_luma_buf_size = + align(opb_wr_top_line_luma_buf_size, hfi_dma_alignment) + + (max_tile_columns - 1) * 256; + opb_wr_top_line_luma_buf_size = + max(opb_wr_top_line_luma_buf_size, (32 * align(height, 16))); + opb_wr_top_line_chroma_buf_size = opb_wr_top_line_luma_buf_size; + opb_lb_wr_llb_y_buffer_size = align((align(height, 16) / 2) * 64, 32); + opb_lb_wr_llb_uv_buffer_size = opb_lb_wr_llb_y_buffer_size; + size = num_vpp_pipes * + 2 * (vpss_4tap_top_buffer_size + vpss_div2_top_buffer_size) + + 2 * (vpss_4tap_left_buffer_size + vpss_div2_left_buffer_size) + + opb_wr_top_line_luma_buf_size + + opb_wr_top_line_chroma_buf_size + + opb_lb_wr_llb_uv_buffer_size + + opb_lb_wr_llb_y_buffer_size; + + return size; +} + +static u32 size_h264d_hw_bin_buffer(u32 width, u32 height) +{ + u32 size_yuv, size_bin_hdr, size_bin_res; + u32 size = 0; + u32 product; + + product = width * height; + size_yuv = (product <= bin_buffer_threshold) ? + ((bin_buffer_threshold * 3) >> 1) : ((product * 3) >> 1); + + size_bin_hdr = size_yuv * h264_cabac_hdr_ratio_hd_tot; + size_bin_res = size_yuv * h264_cabac_res_ratio_hd_tot; + size_bin_hdr = align(size_bin_hdr, hfi_dma_alignment); + size_bin_res = align(size_bin_res, hfi_dma_alignment); + size = size_bin_hdr + size_bin_res; + + return size; +} + +static u32 h264d_scratch_size(u32 width, u32 height, bool is_interlaced) +{ + u32 aligned_width = align(width, 16); + u32 aligned_height = align(height, 16); + u32 size = 0; + + if (!is_interlaced) + size = size_h264d_hw_bin_buffer(aligned_width, aligned_height); + + return size; +} + +static u32 size_h265d_hw_bin_buffer(u32 width, u32 height) +{ + u32 size_yuv, size_bin_hdr, size_bin_res; + u32 size = 0; + u32 product; + + product = width * height; + size_yuv = (product <= bin_buffer_threshold) ? + ((bin_buffer_threshold * 3) >> 1) : ((product * 3) >> 1); + size_bin_hdr = size_yuv * h265_cabac_hdr_ratio_hd_tot; + size_bin_res = size_yuv * h265_cabac_res_ratio_hd_tot; + size_bin_hdr = align(size_bin_hdr, hfi_dma_alignment); + size_bin_res = align(size_bin_res, hfi_dma_alignment); + size = size_bin_hdr + size_bin_res; + + return size; +} + +static u32 h265d_scratch_size(u32 width, u32 height, bool is_interlaced) +{ + u32 aligned_width = align(width, 16); + u32 aligned_height = align(height, 16); + u32 size = 0; + + if (!is_interlaced) + size = size_h265d_hw_bin_buffer(aligned_width, aligned_height); + + return size; +} + +static u32 vpxd_scratch_size(u32 width, u32 height, bool is_interlaced) +{ + u32 aligned_width = align(width, 16); + u32 aligned_height = align(height, 16); + u32 size_yuv = aligned_width * aligned_height * 3 / 2; + u32 size = 0; + + if (!is_interlaced) { + u32 binbuffer1_size, binbufer2_size; + + binbuffer1_size = max_t(u32, size_yuv, + ((bin_buffer_threshold * 3) >> 1)); + binbuffer1_size *= vpx_decoder_frame_concurency_lvl * + vpx_decoder_frame_bin_hdr_budget_ratio_num / + vpx_decoder_frame_bin_hdr_budget_ratio_den; + binbufer2_size = max_t(u32, size_yuv, + ((bin_buffer_threshold * 3) >> 1)); + binbufer2_size *= vpx_decoder_frame_concurency_lvl * + vpx_decoder_frame_bin_res_budget_ratio_num / + vpx_decoder_frame_bin_res_budget_ratio_den; + size = align(binbuffer1_size + binbufer2_size, + hfi_dma_alignment); + } + + return size; +} + +static u32 mpeg2d_scratch_size(u32 width, u32 height, bool is_interlaced) +{ + return 0; +} + +static u32 calculate_enc_output_frame_size(u32 width, u32 height, u32 rc_type) +{ + u32 aligned_width, aligned_height; + u32 mbs_per_frame; + u32 frame_size; + + /* + * encoder output size calculation: 32 align width/height + * for resolution < 720p : yuvsize * 4 + * for resolution > 720p & <= 4k : yuvsize / 2 + * for resolution > 4k : yuvsize / 4 + * initially frame_size = yuvsize * 2; + */ + aligned_width = align(width, 32); + aligned_height = align(height, 32); + mbs_per_frame = (align(aligned_height, 16) * + align(aligned_width, 16)) / 256; + frame_size = width * height * 3; + + if (mbs_per_frame < num_mbs_720p) + frame_size = frame_size << 1; + else if (mbs_per_frame <= num_mbs_4k) + frame_size = frame_size >> 2; + else + frame_size = frame_size >> 3; + + if (rc_type == hfi_rate_control_off || rc_type == hfi_rate_control_cq) + frame_size = frame_size << 1; + + /* + * in case of opaque color format bitdepth will be known + * with first etb, buffers allocated already with 8 bit + * won't be sufficient for 10 bit + * calculate size considering 10-bit by default + * for 10-bit cases size = size * 1.25 + */ + frame_size *= 5; + frame_size /= 4; + + return align(frame_size, sz_4k); +} + +static u32 calculate_enc_scratch_size(u32 width, u32 height, u32 work_mode, + u32 lcu_size, u32 num_vpp_pipes, + u32 rc_type) +{ + u32 aligned_width, aligned_height, bitstream_size; + u32 total_bitbin_buffers, size_single_pipe, bitbin_size; + u32 sao_bin_buffer_size, padded_bin_size, size; + + aligned_width = align(width, lcu_size); + aligned_height = align(height, lcu_size); + bitstream_size = + calculate_enc_output_frame_size(width, height, rc_type); + + bitstream_size = align(bitstream_size, hfi_dma_alignment); + + if (work_mode == vidc_work_mode_2) { + total_bitbin_buffers = 3; + bitbin_size = bitstream_size * 17 / 10; + bitbin_size = align(bitbin_size, hfi_dma_alignment); + } else { + total_bitbin_buffers = 1; + bitstream_size = aligned_width * aligned_height * 3; + bitbin_size = align(bitstream_size, hfi_dma_alignment); + } + + if (num_vpp_pipes > 2) + size_single_pipe = bitbin_size / 2; + else + size_single_pipe = bitbin_size; + + size_single_pipe = align(size_single_pipe, hfi_dma_alignment); + sao_bin_buffer_size = + (64 * (((width + 32) * (height + 32)) >> 10)) + 384; + padded_bin_size = align(size_single_pipe, hfi_dma_alignment); + size_single_pipe = sao_bin_buffer_size + padded_bin_size; + size_single_pipe = align(size_single_pipe, hfi_dma_alignment); + bitbin_size = size_single_pipe * num_vpp_pipes; + size = align(bitbin_size, hfi_dma_alignment) * + total_bitbin_buffers + 512; + + return size; +} + +static u32 h264e_scratch_size(u32 width, u32 height, u32 work_mode, + u32 num_vpp_pipes, u32 rc_type) +{ + return calculate_enc_scratch_size(width, height, work_mode, 16, + num_vpp_pipes, rc_type); +} + +static u32 h265e_scratch_size(u32 width, u32 height, u32 work_mode, + u32 num_vpp_pipes, u32 rc_type) +{ + return calculate_enc_scratch_size(width, height, work_mode, 32, + num_vpp_pipes, rc_type); +} + +static u32 vp8e_scratch_size(u32 width, u32 height, u32 work_mode, + u32 num_vpp_pipes, u32 rc_type) +{ + return calculate_enc_scratch_size(width, height, work_mode, 16, + num_vpp_pipes, rc_type); +} + +static u32 hfi_iris2_h264d_comv_size(u32 width, u32 height, + u32 yuv_buf_min_count) +{ + u32 frame_width_in_mbs = ((width + 15) >> 4); + u32 frame_height_in_mbs = ((height + 15) >> 4); + u32 col_mv_aligned_width = (frame_width_in_mbs << 6); + u32 col_zero_aligned_width = (frame_width_in_mbs << 2); + u32 col_zero_size = 0, size_colloc = 0, comv_size = 0; + + col_mv_aligned_width = align(col_mv_aligned_width, 16); + col_zero_aligned_width = align(col_zero_aligned_width, 16); + col_zero_size = + col_zero_aligned_width * ((frame_height_in_mbs + 1) >> 1); + col_zero_size = align(col_zero_size, 64); + col_zero_size <<= 1; + col_zero_size = align(col_zero_size, 512); + size_colloc = col_mv_aligned_width * ((frame_height_in_mbs + 1) >> 1); + size_colloc = align(size_colloc, 64); + size_colloc <<= 1; + size_colloc = align(size_colloc, 512); + size_colloc += (col_zero_size + size_h264d_buftab_t * 2); + comv_size = size_colloc * yuv_buf_min_count; + comv_size += 512; + + return comv_size; +} + +static u32 size_h264d_bse_cmd_buf(u32 height) +{ + u32 aligned_height = align(height, 32); + + return min_t(u32, (((aligned_height + 15) >> 4) * 3 * 4), + h264d_max_slice) * size_h264d_bse_cmd_per_buf; +} + +static u32 size_h264d_vpp_cmd_buf(u32 height) +{ + u32 aligned_height = align(height, 32); + + return min_t(u32, (((aligned_height + 15) >> 4) * 3 * 4), + h264d_max_slice) * size_h264d_vpp_cmd_per_buf; +} + +static u32 hfi_iris2_h264d_non_comv_size(u32 width, u32 height, + u32 num_vpp_pipes) +{ + u32 size_bse, size_vpp, size; + + size_bse = size_h264d_bse_cmd_buf(height); + size_vpp = size_h264d_vpp_cmd_buf(height); + size = + align(size_bse, hfi_dma_alignment) + + align(size_vpp, hfi_dma_alignment) + + align(size_hw_pic(size_h264d_hw_pic_t), hfi_dma_alignment) + + align(size_h264d_lb_fe_top_data(width, height), + hfi_dma_alignment) + + align(size_h264d_lb_fe_top_ctrl(width, height), + hfi_dma_alignment) + + align(size_h264d_lb_fe_left_ctrl(width, height), + hfi_dma_alignment) * num_vpp_pipes + + align(size_h264d_lb_se_top_ctrl(width, height), + hfi_dma_alignment) + + align(size_h264d_lb_se_left_ctrl(width, height), + hfi_dma_alignment) * num_vpp_pipes + + align(size_h264d_lb_pe_top_data(width, height), + hfi_dma_alignment) + + align(size_h264d_lb_vsp_top(width, height), hfi_dma_alignment) + + align(size_h264d_lb_recon_dma_metadata_wr(width, height), + hfi_dma_alignment) * 2 + + align(size_h264d_qp(width, height), hfi_dma_alignment); + + return align(size, hfi_dma_alignment); +} + +static u32 size_h265d_bse_cmd_buf(u32 width, u32 height) +{ + u32 size; + + size = (align(width, lcu_max_size_pels) / lcu_min_size_pels) * + (align(height, lcu_max_size_pels) / lcu_min_size_pels) * + num_hw_pic_buf; + size = min_t(u32, size, h265d_max_slice + 1); + size = 2 * size * size_h265d_bse_cmd_per_buf; + + return align(size, hfi_dma_alignment); +} + +static u32 size_h265d_vpp_cmd_buf(u32 width, u32 height) +{ + u32 size; + + size = (align(width, lcu_max_size_pels) / lcu_min_size_pels) * + (align(height, lcu_max_size_pels) / lcu_min_size_pels) * + num_hw_pic_buf; + size = min_t(u32, size, h265d_max_slice + 1); + size = align(size, 4); + size = 2 * size * size_h265d_vpp_cmd_per_buf; + + return align(size, hfi_dma_alignment); +} + +static u32 hfi_iris2_h265d_comv_size(u32 width, u32 height, + u32 yuv_buf_count_min) +{ + u32 size; + + size = align(((((width + 15) >> 4) * ((height + 15) >> 4)) << 8), 512); + size *= yuv_buf_count_min; + size += 512; + + return size; +} + +static u32 hfi_iris2_h265d_non_comv_size(u32 width, u32 height, + u32 num_vpp_pipes) +{ + u32 size_bse, size_vpp, size; + + size_bse = size_h265d_bse_cmd_buf(width, height); + size_vpp = size_h265d_vpp_cmd_buf(width, height); + size = + align(size_bse, hfi_dma_alignment) + + align(size_vpp, hfi_dma_alignment) + + align(num_hw_pic_buf * 20 * 22 * 4, hfi_dma_alignment) + + align(2 * sizeof(u16) * + (align(width, lcu_max_size_pels) / lcu_min_size_pels) * + (align(height, lcu_max_size_pels) / lcu_min_size_pels), + hfi_dma_alignment) + + align(size_hw_pic(size_h265d_hw_pic_t), hfi_dma_alignment) + + align(size_h265d_lb_fe_top_data(width, height), + hfi_dma_alignment) + + align(size_h265d_lb_fe_top_ctrl(width, height), + hfi_dma_alignment) + + align(size_h265d_lb_fe_left_ctrl(width, height), + hfi_dma_alignment) * num_vpp_pipes + + align(size_h265d_lb_se_left_ctrl(width, height), + hfi_dma_alignment) * num_vpp_pipes + + align(size_h265d_lb_se_top_ctrl(width, height), + hfi_dma_alignment) + + align(size_h265d_lb_pe_top_data(width, height), + hfi_dma_alignment) + + align(size_h265d_lb_vsp_top(width, height), hfi_dma_alignment) + + align(size_h265d_lb_vsp_left(width, height), + hfi_dma_alignment) * num_vpp_pipes + + align(size_h265d_lb_recon_dma_metadata_wr(width, height), + hfi_dma_alignment) + * 4 + + align(size_h265d_qp(width, height), hfi_dma_alignment); + + return align(size, hfi_dma_alignment); +} + +static u32 hfi_iris2_vp8d_comv_size(u32 width, u32 height, + u32 yuv_min_buf_count) +{ + return (((width + 15) >> 4) * ((height + 15) >> 4) * 8 * 2); +} + +static u32 h264d_scratch1_size(u32 width, u32 height, u32 min_buf_count, + bool split_mode_enabled, u32 num_vpp_pipes) +{ + u32 co_mv_size, nonco_mv_size, vpss_lb_size = 0; + + co_mv_size = hfi_iris2_h264d_comv_size(width, height, min_buf_count); + nonco_mv_size = hfi_iris2_h264d_non_comv_size(width, height, + num_vpp_pipes); + if (split_mode_enabled) + vpss_lb_size = size_vpss_lb(width, height, num_vpp_pipes); + + return co_mv_size + nonco_mv_size + vpss_lb_size; +} + +static u32 h265d_scratch1_size(u32 width, u32 height, u32 min_buf_count, + bool split_mode_enabled, u32 num_vpp_pipes) +{ + u32 co_mv_size, nonco_mv_size, vpss_lb_size = 0; + + co_mv_size = hfi_iris2_h265d_comv_size(width, height, min_buf_count); + nonco_mv_size = hfi_iris2_h265d_non_comv_size(width, height, + num_vpp_pipes); + if (split_mode_enabled) + vpss_lb_size = size_vpss_lb(width, height, num_vpp_pipes); + + return co_mv_size + nonco_mv_size + vpss_lb_size + + hdr10_hist_extradata_size; +} + +static u32 vp8d_scratch1_size(u32 width, u32 height, u32 min_buf_count, + bool split_mode_enabled, u32 num_vpp_pipes) +{ + u32 vpss_lb_size = 0, size; + + size = hfi_iris2_vp8d_comv_size(width, height, 0); + size += align(size_vpxd_lb_fe_left_ctrl(width, height), + hfi_dma_alignment) * num_vpp_pipes + + align(size_vpxd_lb_se_left_ctrl(width, height), + hfi_dma_alignment) * num_vpp_pipes + + align(size_vp8d_lb_vsp_top(width, height), hfi_dma_alignment) + + align(size_vpxd_lb_fe_top_ctrl(width, height), + hfi_dma_alignment) + + 2 * align(size_vpxd_lb_recon_dma_metadata_wr(width, height), + hfi_dma_alignment) + + align(size_vpxd_lb_se_top_ctrl(width, height), + hfi_dma_alignment) + + align(size_vp8d_lb_pe_top_data(width, height), + hfi_dma_alignment) + + align(size_vp8d_lb_fe_top_data(width, height), + hfi_dma_alignment); + if (split_mode_enabled) + vpss_lb_size = size_vpss_lb(width, height, num_vpp_pipes); + + size += vpss_lb_size; + + return size; +} + +static u32 vp9d_scratch1_size(u32 width, u32 height, u32 min_buf_count, + bool split_mode_enabled, u32 num_vpp_pipes) +{ + u32 vpss_lb_size = 0; + u32 size; + + size = + align(size_vpxd_lb_fe_left_ctrl(width, height), + hfi_dma_alignment) * num_vpp_pipes + + align(size_vpxd_lb_se_left_ctrl(width, height), + hfi_dma_alignment) * num_vpp_pipes + + align(size_vp9d_lb_vsp_top(width, height), hfi_dma_alignment) + + align(size_vpxd_lb_fe_top_ctrl(width, height), + hfi_dma_alignment) + + 2 * align(size_vpxd_lb_recon_dma_metadata_wr(width, height), + hfi_dma_alignment) + + align(size_vpxd_lb_se_top_ctrl(width, height), + hfi_dma_alignment) + + align(size_vp9d_lb_pe_top_data(width, height), + hfi_dma_alignment) + + align(size_vp9d_lb_fe_top_data(width, height), + hfi_dma_alignment); + + if (split_mode_enabled) + vpss_lb_size = size_vpss_lb(width, height, num_vpp_pipes); + + size += vpss_lb_size + hdr10_hist_extradata_size; + + return size; +} + +static u32 mpeg2d_scratch1_size(u32 width, u32 height, u32 min_buf_count, + bool split_mode_enabled, u32 num_vpp_pipes) +{ + u32 vpss_lb_size = 0; + u32 size; + + size = + align(size_vpxd_lb_fe_left_ctrl(width, height), + hfi_dma_alignment) * num_vpp_pipes + + align(size_vpxd_lb_se_left_ctrl(width, height), + hfi_dma_alignment) * num_vpp_pipes + + align(size_vp8d_lb_vsp_top(width, height), hfi_dma_alignment) + + align(size_vpxd_lb_fe_top_ctrl(width, height), + hfi_dma_alignment) + + 2 * align(size_vpxd_lb_recon_dma_metadata_wr(width, height), + hfi_dma_alignment) + + align(size_vpxd_lb_se_top_ctrl(width, height), + hfi_dma_alignment) + + align(size_vp8d_lb_pe_top_data(width, height), + hfi_dma_alignment) + + align(size_vp8d_lb_fe_top_data(width, height), + hfi_dma_alignment); + + if (split_mode_enabled) + vpss_lb_size = size_vpss_lb(width, height, num_vpp_pipes); + + size += vpss_lb_size; + + return size; +} + +static u32 +calculate_enc_scratch1_size(u32 width, u32 height, u32 lcu_size, u32 num_ref, + bool ten_bit, u32 num_vpp_pipes, bool is_h265) +{ + u32 line_buf_ctrl_size, line_buf_data_size, leftline_buf_ctrl_size; + u32 line_buf_sde_size, sps_pps_slice_hdr, topline_buf_ctrl_size_fe; + u32 leftline_buf_ctrl_size_fe, line_buf_recon_pix_size; + u32 leftline_buf_recon_pix_size, lambda_lut_size, override_buffer_size; + u32 col_mv_buf_size, vpp_reg_buffer_size, ir_buffer_size; + u32 vpss_line_buf, leftline_buf_meta_recony, h265e_colrcbuf_size; + u32 h265e_framerc_bufsize, h265e_lcubitcnt_bufsize; + u32 h265e_lcubitmap_bufsize, se_stats_bufsize; + u32 bse_reg_buffer_size, bse_slice_cmd_buffer_size, slice_info_bufsize; + u32 line_buf_ctrl_size_buffid2, slice_cmd_buffer_size; + u32 width_lcu_num, height_lcu_num, width_coded, height_coded; + u32 frame_num_lcu, linebuf_meta_recon_uv, topline_bufsize_fe_1stg_sao; + u32 size, bit_depth, num_lcu_mb; + u32 vpss_line_buffer_size_1; + + width_lcu_num = (width + lcu_size - 1) / lcu_size; + height_lcu_num = (height + lcu_size - 1) / lcu_size; + frame_num_lcu = width_lcu_num * height_lcu_num; + width_coded = width_lcu_num * lcu_size; + height_coded = height_lcu_num * lcu_size; + num_lcu_mb = (height_coded / lcu_size) * + ((width_coded + lcu_size * 8) / lcu_size); + slice_info_bufsize = 256 + (frame_num_lcu << 4); + slice_info_bufsize = align(slice_info_bufsize, hfi_dma_alignment); + line_buf_ctrl_size = align(width_coded, hfi_dma_alignment); + line_buf_ctrl_size_buffid2 = align(width_coded, hfi_dma_alignment); + + bit_depth = ten_bit ? 10 : 8; + line_buf_data_size = + (((((bit_depth * width_coded + 1024) + + (hfi_dma_alignment - 1)) & (~(hfi_dma_alignment - 1))) * 1) + + (((((bit_depth * width_coded + 1024) >> 1) + + (hfi_dma_alignment - 1)) & (~(hfi_dma_alignment - 1))) * 2)); + + leftline_buf_ctrl_size = is_h265 ? + ((height_coded + 32) / 32 * 4 * 16) : + ((height_coded + 15) / 16 * 5 * 16); + + if (num_vpp_pipes > 1) { + leftline_buf_ctrl_size += 512; + leftline_buf_ctrl_size = + align(leftline_buf_ctrl_size, 512) * num_vpp_pipes; + } + + leftline_buf_ctrl_size = + align(leftline_buf_ctrl_size, hfi_dma_alignment); + leftline_buf_recon_pix_size = (((ten_bit + 1) * 2 * + (height_coded) + hfi_dma_alignment) + + (hfi_dma_alignment << (num_vpp_pipes - 1)) - 1) & + (~((hfi_dma_alignment << (num_vpp_pipes - 1)) - 1)) * 1; + + topline_buf_ctrl_size_fe = is_h265 ? (64 * (width_coded >> 5)) : + (hfi_dma_alignment + 16 * (width_coded >> 4)); + topline_buf_ctrl_size_fe = + align(topline_buf_ctrl_size_fe, hfi_dma_alignment); + leftline_buf_ctrl_size_fe = + (((hfi_dma_alignment + 64 * (height_coded >> 4)) + + (hfi_dma_alignment << (num_vpp_pipes - 1)) - 1) & + (~((hfi_dma_alignment << (num_vpp_pipes - 1)) - 1)) * 1) * + num_vpp_pipes; + leftline_buf_meta_recony = (hfi_dma_alignment + 64 * + ((height_coded) / (8 * (ten_bit ? 4 : 8)))); + leftline_buf_meta_recony = + align(leftline_buf_meta_recony, hfi_dma_alignment); + leftline_buf_meta_recony = leftline_buf_meta_recony * num_vpp_pipes; + linebuf_meta_recon_uv = (hfi_dma_alignment + 64 * + ((height_coded) / (4 * (ten_bit ? 4 : 8)))); + linebuf_meta_recon_uv = align(linebuf_meta_recon_uv, hfi_dma_alignment); + linebuf_meta_recon_uv = linebuf_meta_recon_uv * num_vpp_pipes; + line_buf_recon_pix_size = ((ten_bit ? 3 : 2) * width_coded); + line_buf_recon_pix_size = + align(line_buf_recon_pix_size, hfi_dma_alignment); + slice_cmd_buffer_size = align(20480, hfi_dma_alignment); + sps_pps_slice_hdr = 2048 + 4096; + col_mv_buf_size = is_h265 ? (16 * ((frame_num_lcu << 2) + 32)) : + (3 * 16 * (width_lcu_num * height_lcu_num + 32)); + col_mv_buf_size = + align(col_mv_buf_size, hfi_dma_alignment) * (num_ref + 1); + h265e_colrcbuf_size = + (((width_lcu_num + 7) >> 3) * 16 * 2 * height_lcu_num); + if (num_vpp_pipes > 1) + h265e_colrcbuf_size = + align(h265e_colrcbuf_size, hfi_dma_alignment) * + num_vpp_pipes; + + h265e_colrcbuf_size = align(h265e_colrcbuf_size, hfi_dma_alignment) * + hfi_max_col_frame; + h265e_framerc_bufsize = (is_h265) ? (256 + 16 * + (14 + (((height_coded >> 5) + 7) >> 3))) : + (256 + 16 * (14 + (((height_coded >> 4) + 7) >> 3))); + h265e_framerc_bufsize *= 6; /* multiply by max numtilescol */ + if (num_vpp_pipes > 1) + h265e_framerc_bufsize = + align(h265e_framerc_bufsize, hfi_dma_alignment) * + num_vpp_pipes; + + h265e_framerc_bufsize = align(h265e_framerc_bufsize, 512) * + hfi_max_col_frame; + h265e_lcubitcnt_bufsize = 256 + 4 * frame_num_lcu; + h265e_lcubitcnt_bufsize = + align(h265e_lcubitcnt_bufsize, hfi_dma_alignment); + h265e_lcubitmap_bufsize = 256 + (frame_num_lcu >> 3); + h265e_lcubitmap_bufsize = + align(h265e_lcubitmap_bufsize, hfi_dma_alignment); + line_buf_sde_size = 256 + 16 * (width_coded >> 4); + line_buf_sde_size = align(line_buf_sde_size, hfi_dma_alignment); + if ((width_coded * height_coded) > (4096 * 2160)) + se_stats_bufsize = 0; + else if ((width_coded * height_coded) > (1920 * 1088)) + se_stats_bufsize = (40 * 4 * frame_num_lcu + 256 + 256); + else + se_stats_bufsize = (1024 * frame_num_lcu + 256 + 256); + + se_stats_bufsize = align(se_stats_bufsize, hfi_dma_alignment) * 2; + bse_slice_cmd_buffer_size = (((8192 << 2) + 7) & (~7)) * 6; + bse_reg_buffer_size = (((512 << 3) + 7) & (~7)) * 4; + vpp_reg_buffer_size = + (((hfi_venus_vppsg_max_registers << 3) + 31) & (~31)) * 10; + lambda_lut_size = 256 * 11; + override_buffer_size = 16 * ((num_lcu_mb + 7) >> 3); + override_buffer_size = + align(override_buffer_size, hfi_dma_alignment) * 2; + ir_buffer_size = (((frame_num_lcu << 1) + 7) & (~7)) * 3; + vpss_line_buffer_size_1 = (((8192 >> 2) << 5) * num_vpp_pipes) + 64; + vpss_line_buf = + (((((max(width_coded, height_coded) + 3) >> 2) << 5) + 256) * + 16) + vpss_line_buffer_size_1; + topline_bufsize_fe_1stg_sao = 16 * (width_coded >> 5); + topline_bufsize_fe_1stg_sao = + align(topline_bufsize_fe_1stg_sao, hfi_dma_alignment); + + size = + line_buf_ctrl_size + line_buf_data_size + + line_buf_ctrl_size_buffid2 + leftline_buf_ctrl_size + + vpss_line_buf + col_mv_buf_size + topline_buf_ctrl_size_fe + + leftline_buf_ctrl_size_fe + line_buf_recon_pix_size + + leftline_buf_recon_pix_size + + leftline_buf_meta_recony + linebuf_meta_recon_uv + + h265e_colrcbuf_size + h265e_framerc_bufsize + + h265e_lcubitcnt_bufsize + h265e_lcubitmap_bufsize + + line_buf_sde_size + + topline_bufsize_fe_1stg_sao + override_buffer_size + + bse_reg_buffer_size + vpp_reg_buffer_size + sps_pps_slice_hdr + + slice_cmd_buffer_size + bse_slice_cmd_buffer_size + + ir_buffer_size + slice_info_bufsize + lambda_lut_size + + se_stats_bufsize + 1024; + + return size; +} + +static u32 h264e_scratch1_size(u32 width, u32 height, u32 num_ref, bool ten_bit, + u32 num_vpp_pipes) +{ + return calculate_enc_scratch1_size(width, height, 16, num_ref, ten_bit, + num_vpp_pipes, false); +} + +static u32 h265e_scratch1_size(u32 width, u32 height, u32 num_ref, bool ten_bit, + u32 num_vpp_pipes) +{ + return calculate_enc_scratch1_size(width, height, 32, num_ref, ten_bit, + num_vpp_pipes, true); +} + +static u32 vp8e_scratch1_size(u32 width, u32 height, u32 num_ref, bool ten_bit, + u32 num_vpp_pipes) +{ + return calculate_enc_scratch1_size(width, height, 16, num_ref, ten_bit, + 1, false); +} + +static u32 ubwc_metadata_plane_stride(u32 width, u32 metadata_stride_multi, + u32 tile_width_pels) +{ + return align(((width + (tile_width_pels - 1)) / tile_width_pels), + metadata_stride_multi); +} + +static u32 ubwc_metadata_plane_bufheight(u32 height, u32 metadata_height_multi, + u32 tile_height_pels) +{ + return align(((height + (tile_height_pels - 1)) / tile_height_pels), + metadata_height_multi); +} + +static u32 ubwc_metadata_plane_buffer_size(u32 metadata_stride, + u32 metadata_buf_height) +{ + return align(metadata_stride * metadata_buf_height, sz_4k); +} + +static u32 enc_scratch2_size(u32 width, u32 height, u32 num_ref, bool ten_bit) +{ + u32 aligned_width, aligned_height, chroma_height, ref_buf_height; + u32 luma_size, chroma_size; + u32 metadata_stride, meta_buf_height, meta_size_y, meta_size_c; + u32 ref_luma_stride_bytes, ref_chroma_height_bytes; + u32 ref_buf_size, ref_stride; + u32 size; + + if (!ten_bit) { + aligned_height = align(height, hfi_venus_height_alignment); + chroma_height = height >> 1; + chroma_height = align(chroma_height, + hfi_venus_height_alignment); + aligned_width = align(width, hfi_venus_width_alignment); + metadata_stride = + ubwc_metadata_plane_stride(width, 64, + nv12_ubwc_y_tile_width); + meta_buf_height = + ubwc_metadata_plane_bufheight(height, 16, + nv12_ubwc_y_tile_height); + meta_size_y = ubwc_metadata_plane_buffer_size(metadata_stride, + meta_buf_height); + meta_size_c = ubwc_metadata_plane_buffer_size(metadata_stride, + meta_buf_height); + size = (aligned_height + chroma_height) * aligned_width + + meta_size_y + meta_size_c; + size = (size * (num_ref + 3)) + 4096; + } else { + ref_buf_height = (height + (hfi_venus_height_alignment - 1)) + & (~(hfi_venus_height_alignment - 1)); + ref_luma_stride_bytes = + ((width + system_lal_tile10 - 1) / system_lal_tile10) * + system_lal_tile10; + ref_stride = 4 * (ref_luma_stride_bytes / 3); + ref_stride = (ref_stride + (128 - 1)) & (~(128 - 1)); + luma_size = ref_buf_height * ref_stride; + ref_chroma_height_bytes = (((height + 1) >> 1) + + (32 - 1)) & (~(32 - 1)); + chroma_size = ref_stride * ref_chroma_height_bytes; + luma_size = (luma_size + (sz_4k - 1)) & (~(sz_4k - 1)); + chroma_size = (chroma_size + (sz_4k - 1)) & (~(sz_4k - 1)); + ref_buf_size = luma_size + chroma_size; + metadata_stride = + ubwc_metadata_plane_stride(width, + metadata_stride_multiple, + tp10_ubwc_y_tile_width); + meta_buf_height = + ubwc_metadata_plane_bufheight(height, + metadata_height_multiple, + tp10_ubwc_y_tile_height); + meta_size_y = ubwc_metadata_plane_buffer_size(metadata_stride, + meta_buf_height); + meta_size_c = ubwc_metadata_plane_buffer_size(metadata_stride, + meta_buf_height); + size = ref_buf_size + meta_size_y + meta_size_c; + size = (size * (num_ref + 3)) + 4096; + } + + return size; +} + +static u32 enc_persist_size(void) +{ + return hfi_iris2_enc_persist_size; +} + +static u32 h264d_persist1_size(void) +{ + return align((size_slist_buf_h264 * num_slist_buf_h264), + hfi_dma_alignment); +} + +static u32 h265d_persist1_size(void) +{ + return align((size_slist_buf_h265 * num_slist_buf_h265 + h265_num_tile + * sizeof(u32)), hfi_dma_alignment); +} + +static u32 vp8d_persist1_size(void) +{ + return align(vp8_num_probability_table_buf * vp8_prob_table_size, + hfi_dma_alignment); +} + +static u32 vp9d_persist1_size(void) +{ + return + align(vp9_num_probability_table_buf * vp9_prob_table_size, + hfi_dma_alignment) + + align(hfi_iris2_vp9d_comv_size, hfi_dma_alignment) + + align(max_superframe_header_len, hfi_dma_alignment) + + align(vp9_udc_header_buf_size, hfi_dma_alignment) + + align(vp9_num_frame_info_buf * cce_tile_offset_size, + hfi_dma_alignment); +} + +static u32 mpeg2d_persist1_size(void) +{ + return qmatrix_size + mp2d_qpdump_size; +} + +struct dec_bufsize_ops { + u32 (*scratch)(u32 width, u32 height, bool is_interlaced); + u32 (*scratch1)(u32 width, u32 height, u32 min_buf_count, + bool split_mode_enabled, u32 num_vpp_pipes); + u32 (*persist1)(void); +}; + +struct enc_bufsize_ops { + u32 (*scratch)(u32 width, u32 height, u32 work_mode, u32 num_vpp_pipes, + u32 rc_type); + u32 (*scratch1)(u32 width, u32 height, u32 num_ref, bool ten_bit, + u32 num_vpp_pipes); + u32 (*scratch2)(u32 width, u32 height, u32 num_ref, bool ten_bit); + u32 (*persist)(void); +}; + +static struct dec_bufsize_ops dec_h264_ops = { + .scratch = h264d_scratch_size, + .scratch1 = h264d_scratch1_size, + .persist1 = h264d_persist1_size, +}; + +static struct dec_bufsize_ops dec_h265_ops = { + .scratch = h265d_scratch_size, + .scratch1 = h265d_scratch1_size, + .persist1 = h265d_persist1_size, +}; + +static struct dec_bufsize_ops dec_vp8_ops = { + .scratch = vpxd_scratch_size, + .scratch1 = vp8d_scratch1_size, + .persist1 = vp8d_persist1_size, +}; + +static struct dec_bufsize_ops dec_vp9_ops = { + .scratch = vpxd_scratch_size, + .scratch1 = vp9d_scratch1_size, + .persist1 = vp9d_persist1_size, +}; + +static struct dec_bufsize_ops dec_mpeg2_ops = { + .scratch = mpeg2d_scratch_size, + .scratch1 = mpeg2d_scratch1_size, + .persist1 = mpeg2d_persist1_size, +}; + +static struct enc_bufsize_ops enc_h264_ops = { + .scratch = h264e_scratch_size, + .scratch1 = h264e_scratch1_size, + .scratch2 = enc_scratch2_size, + .persist = enc_persist_size, +}; + +static struct enc_bufsize_ops enc_h265_ops = { + .scratch = h265e_scratch_size, + .scratch1 = h265e_scratch1_size, + .scratch2 = enc_scratch2_size, + .persist = enc_persist_size, +}; + +static struct enc_bufsize_ops enc_vp8_ops = { + .scratch = vp8e_scratch_size, + .scratch1 = vp8e_scratch1_size, + .scratch2 = enc_scratch2_size, + .persist = enc_persist_size, +}; + +static u32 +calculate_dec_input_frame_size(u32 width, u32 height, u32 codec, + u32 max_mbs_per_frame, u32 buffer_size_limit) +{ + u32 frame_size, num_mbs; + u32 div_factor = 1; + u32 base_res_mbs = num_mbs_4k; + + /* + * decoder input size calculation: + * if clip is 8k buffer size is calculated for 8k : 8k mbs/4 + * for 8k cases we expect width/height to be set always. + * in all other cases size is calculated for 4k: + * 4k mbs for vp8/vp9 and 4k/2 for remaining codecs + */ + num_mbs = (align(height, 16) * align(width, 16)) / 256; + if (num_mbs > num_mbs_4k) { + div_factor = 4; + base_res_mbs = max_mbs_per_frame; + } else { + base_res_mbs = num_mbs_4k; + if (codec == v4l2_pix_fmt_vp9) + div_factor = 1; + else + div_factor = 2; + } + + frame_size = base_res_mbs * mb_size_in_pixel * 3 / 2 / div_factor; + + /* multiply by 10/8 (1.25) to get size for 10 bit case */ + if (codec == v4l2_pix_fmt_vp9 || codec == v4l2_pix_fmt_hevc) + frame_size = frame_size + (frame_size >> 2); + + if (buffer_size_limit && buffer_size_limit < frame_size) + frame_size = buffer_size_limit; + + return align(frame_size, sz_4k); +} + +static int output_buffer_count(u32 session_type, u32 codec) +{ + u32 output_min_count; + + if (session_type == vidc_session_type_dec) { + switch (codec) { + case v4l2_pix_fmt_mpeg2: + case v4l2_pix_fmt_vp8: + output_min_count = 6; + break; + case v4l2_pix_fmt_vp9: + output_min_count = 9; + break; + case v4l2_pix_fmt_h264: + case v4l2_pix_fmt_hevc: + default: + output_min_count = 8; + break; + } + } else { + output_min_count = min_enc_output_buffers; + } + + return output_min_count; +} + +static int bufreq_dec(struct hfi_plat_buffers_params *params, u32 buftype, + struct hfi_buffer_requirements *bufreq) +{ + enum hfi_version version = params->version; + u32 codec = params->codec; + u32 width = params->width, height = params->height, out_min_count; + struct dec_bufsize_ops *dec_ops; + bool is_secondary_output = params->dec.is_secondary_output; + bool is_interlaced = params->dec.is_interlaced; + u32 max_mbs_per_frame = params->dec.max_mbs_per_frame; + u32 buffer_size_limit = params->dec.buffer_size_limit; + u32 num_vpp_pipes = params->num_vpp_pipes; + + switch (codec) { + case v4l2_pix_fmt_h264: + dec_ops = &dec_h264_ops; + break; + case v4l2_pix_fmt_hevc: + dec_ops = &dec_h265_ops; + break; + case v4l2_pix_fmt_vp8: + dec_ops = &dec_vp8_ops; + break; + case v4l2_pix_fmt_vp9: + dec_ops = &dec_vp9_ops; + break; + case v4l2_pix_fmt_mpeg2: + dec_ops = &dec_mpeg2_ops; + break; + default: + return -einval; + } + + out_min_count = output_buffer_count(vidc_session_type_dec, codec); + + bufreq->type = buftype; + bufreq->region_size = 0; + bufreq->count_min = 1; + bufreq->count_actual = 1; + bufreq->hold_count = 1; + bufreq->contiguous = 1; + bufreq->alignment = 256; + + if (buftype == hfi_buffer_input) { + bufreq->count_min = min_input_buffers; + bufreq->size = + calculate_dec_input_frame_size(width, height, codec, + max_mbs_per_frame, + buffer_size_limit); + } else if (buftype == hfi_buffer_output || + buftype == hfi_buffer_output2) { + bufreq->count_min = out_min_count; + bufreq->size = + venus_helper_get_framesz_raw(params->hfi_color_fmt, + width, height); + } else if (buftype == hfi_buffer_internal_scratch(version)) { + bufreq->size = dec_ops->scratch(width, height, is_interlaced); + } else if (buftype == hfi_buffer_internal_scratch_1(version)) { + bufreq->size = dec_ops->scratch1(width, height, out_min_count, + is_secondary_output, + num_vpp_pipes); + } else if (buftype == hfi_buffer_internal_persist_1) { + bufreq->size = dec_ops->persist1(); + } else { + return -einval; + } + + return 0; +} + +int bufreq_enc(struct hfi_plat_buffers_params *params, u32 buftype, + struct hfi_buffer_requirements *bufreq) +{ + enum hfi_version version = params->version; + struct enc_bufsize_ops *enc_ops; + u32 width = params->width; + u32 height = params->height; + bool is_tenbit = params->enc.is_tenbit; + u32 num_bframes = params->enc.num_b_frames; + u32 codec = params->codec; + u32 work_mode = params->enc.work_mode; + u32 rc_type = params->enc.rc_type; + u32 num_vpp_pipes = params->num_vpp_pipes; + u32 num_ref; + + switch (codec) { + case v4l2_pix_fmt_h264: + enc_ops = &enc_h264_ops; + break; + case v4l2_pix_fmt_hevc: + enc_ops = &enc_h265_ops; + break; + case v4l2_pix_fmt_vp8: + enc_ops = &enc_vp8_ops; + break; + default: + return -einval; + } + + num_ref = num_bframes > 0 ? num_bframes + 1 : 1; + + bufreq->type = buftype; + bufreq->region_size = 0; + bufreq->count_min = 1; + bufreq->count_actual = 1; + bufreq->hold_count = 1; + bufreq->contiguous = 1; + bufreq->alignment = 256; + + if (buftype == hfi_buffer_input) { + bufreq->count_min = min_input_buffers; + bufreq->size = + venus_helper_get_framesz_raw(params->hfi_color_fmt, + width, height); + } else if (buftype == hfi_buffer_output || + buftype == hfi_buffer_output2) { + bufreq->count_min = + output_buffer_count(vidc_session_type_enc, codec); + bufreq->size = calculate_enc_output_frame_size(width, height, + rc_type); + } else if (buftype == hfi_buffer_internal_scratch(version)) { + bufreq->size = enc_ops->scratch(width, height, work_mode, + num_vpp_pipes, rc_type); + } else if (buftype == hfi_buffer_internal_scratch_1(version)) { + bufreq->size = enc_ops->scratch1(width, height, num_ref, + is_tenbit, num_vpp_pipes); + } else if (buftype == hfi_buffer_internal_scratch_2(version)) { + bufreq->size = enc_ops->scratch2(width, height, num_ref, + is_tenbit); + } else if (buftype == hfi_buffer_internal_persist) { + bufreq->size = enc_ops->persist(); + } else { + return -einval; + } + + return 0; +} + +int hfi_plat_bufreq_v6(struct hfi_plat_buffers_params *params, u32 session_type, + u32 buftype, struct hfi_buffer_requirements *bufreq) +{ + if (session_type == vidc_session_type_dec) + return bufreq_dec(params, buftype, bufreq); + else + return bufreq_enc(params, buftype, bufreq); +} diff --git a/drivers/media/platform/qcom/venus/hfi_platform_v6.c b/drivers/media/platform/qcom/venus/hfi_platform_v6.c --- a/drivers/media/platform/qcom/venus/hfi_platform_v6.c +++ b/drivers/media/platform/qcom/venus/hfi_platform_v6.c + .bufreq = hfi_plat_bufreq_v6,
TV tuners, webcams, video capturers
3a75bf4e792587d7fd82242aa6c61ec6df4c0fcc
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: get codecs and capabilities from hfi platform
wire up hfi platform codec and capabilities instead of getting them from firmware.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['c']
1
38
0
--- diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c b/drivers/media/platform/qcom/venus/hfi_parser.c --- a/drivers/media/platform/qcom/venus/hfi_parser.c +++ b/drivers/media/platform/qcom/venus/hfi_parser.c +static int hfi_platform_parser(struct venus_core *core, struct venus_inst *inst) +{ + const struct hfi_platform *plat; + const struct hfi_plat_caps *caps = null; + u32 enc_codecs, dec_codecs, count; + unsigned int entries; + + if (inst) + return 0; + + plat = hfi_platform_get(core->res->hfi_version); + if (!plat) + return -einval; + + if (plat->codecs) + plat->codecs(&enc_codecs, &dec_codecs, &count); + + if (plat->capabilities) + caps = plat->capabilities(&entries); + + if (!caps || !entries || !count) + return -einval; + + core->enc_codecs = enc_codecs; + core->dec_codecs = dec_codecs; + core->codecs_count = count; + core->max_sessions_supported = max_sessions; + memset(core->caps, 0, sizeof(*caps) * max_codec_num); + memcpy(core->caps, caps, sizeof(*caps) * entries); + + return 0; +} + + int ret; + + ret = hfi_platform_parser(core, inst); + if (!ret) + return hfi_err_none;
TV tuners, webcams, video capturers
e29929266be1ac0e40121f56b5c13b52c281db06
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: vdec,core: handle picture structure event
handle progressive/interlaced bitstream event by similar way as bit depth.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
2
5
0
--- diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h + unsigned int pic_struct; diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c + if (inst->pic_struct != ev_data->pic_struct) + inst->pic_struct = ev_data->pic_struct; + + inst->pic_struct = hfi_interlace_frame_progressive;
TV tuners, webcams, video capturers
b8201f3ebc4cbfd949a3bcf583b25a484e21f2f0
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: helpers: wire up hfi platform buffer requirements
now when everything is in place wire up buffer requirements from hfi platform buffers to the buffer requirements helper.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduce new hfi platform layer
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
2
55
0
--- diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c --- a/drivers/media/platform/qcom/venus/helpers.c +++ b/drivers/media/platform/qcom/venus/helpers.c +#include "hfi_parser.h" +static int platform_get_bufreq(struct venus_inst *inst, u32 buftype, + struct hfi_buffer_requirements *req) +{ + enum hfi_version version = inst->core->res->hfi_version; + const struct hfi_platform *hfi_plat; + struct hfi_plat_buffers_params params; + bool is_dec = inst->session_type == vidc_session_type_dec; + struct venc_controls *enc_ctr = &inst->controls.enc; + + hfi_plat = hfi_platform_get(version); + + if (!hfi_plat || !hfi_plat->bufreq) + return -einval; + + params.version = version; + params.num_vpp_pipes = hfi_platform_num_vpp_pipes(version); + + if (is_dec) { + params.width = inst->width; + params.height = inst->height; + params.codec = inst->fmt_out->pixfmt; + params.hfi_color_fmt = to_hfi_raw_fmt(inst->fmt_cap->pixfmt); + params.dec.max_mbs_per_frame = mbs_per_frame_max(inst); + params.dec.buffer_size_limit = 0; + params.dec.is_secondary_output = + inst->opb_buftype == hfi_buffer_output2; + params.dec.is_interlaced = + inst->pic_struct != hfi_interlace_frame_progressive ? + true : false; + } else { + params.width = inst->out_width; + params.height = inst->out_height; + params.codec = inst->fmt_cap->pixfmt; + params.hfi_color_fmt = to_hfi_raw_fmt(inst->fmt_out->pixfmt); + params.enc.work_mode = vidc_work_mode_2; + params.enc.rc_type = hfi_rate_control_off; + if (enc_ctr->bitrate_mode == v4l2_mpeg_video_bitrate_mode_cq) + params.enc.rc_type = hfi_rate_control_cq; + params.enc.num_b_frames = enc_ctr->num_b_frames; + params.enc.is_tenbit = inst->bit_depth == vidc_bitdepth_10; + } + + return hfi_plat->bufreq(&params, inst->session_type, buftype, req); +} + + ret = platform_get_bufreq(inst, type, req); + if (!ret) + return 0; + diff --git a/drivers/media/platform/qcom/venus/hfi_parser.h b/drivers/media/platform/qcom/venus/hfi_parser.h --- a/drivers/media/platform/qcom/venus/hfi_parser.h +++ b/drivers/media/platform/qcom/venus/hfi_parser.h +static inline u32 mbs_per_frame_max(struct venus_inst *inst) +{ + return cap_max(inst, hfi_capability_mbs_per_frame); +} +
TV tuners, webcams, video capturers
7371093f983d35d60a7fac3a6f082de7fefe3648
stanimir varbanov
drivers
media
platform, qcom, venus
media: venus: core: add support to dump fw region
add support to dump video fw region during fw crash using devcoredump helpers.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add support to dump fw region
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['venus']
['h', 'c']
3
35
0
--- diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c +#include <linux/devcoredump.h> +static void venus_coredump(struct venus_core *core) +{ + struct device *dev; + phys_addr_t mem_phys; + size_t mem_size; + void *mem_va; + void *data; + + dev = core->dev; + mem_phys = core->fw.mem_phys; + mem_size = core->fw.mem_size; + + mem_va = memremap(mem_phys, mem_size, memremap_wc); + if (!mem_va) + return; + + data = vmalloc(mem_size); + if (!data) { + memunmap(mem_va); + return; + } + + memcpy(data, mem_va, mem_size); + memunmap(mem_va); + dev_coredumpv(dev, data, mem_size, gfp_kernel); +} + + venus_coredump(core); + diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h + phys_addr_t mem_phys; + size_t mem_size; diff --git a/drivers/media/platform/qcom/venus/firmware.c b/drivers/media/platform/qcom/venus/firmware.c --- a/drivers/media/platform/qcom/venus/firmware.c +++ b/drivers/media/platform/qcom/venus/firmware.c + core->fw.mem_size = mem_size; + core->fw.mem_phys = mem_phys; +
TV tuners, webcams, video capturers
0ca0ca9805055bb0efc16890f9d6433c65bd07cc
dikshita agarwal stephen boyd swboyd chromium org
drivers
media
platform, qcom, venus
media: vidtv: add media controller support
add media controller support when config_media_controller_dvb is set so that, in the future, a test sequence in v4l-utils can be written without having to know which /dev/foox device should be used.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add media controller support
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['vidtv']
['h', 'c']
2
34
0
--- diff --git a/drivers/media/test-drivers/vidtv/vidtv_bridge.c b/drivers/media/test-drivers/vidtv/vidtv_bridge.c --- a/drivers/media/test-drivers/vidtv/vidtv_bridge.c +++ b/drivers/media/test-drivers/vidtv/vidtv_bridge.c +#include <media/dvbdev.h> +#include <media/media-device.h> +#ifdef config_media_controller_dvb + dvb->mdev.dev = &pdev->dev; + + strscpy(dvb->mdev.model, "vidtv", sizeof(dvb->mdev.model)); + strscpy(dvb->mdev.bus_info, "platform:vidtv", sizeof(dvb->mdev.bus_info)); + + media_device_init(&dvb->mdev); + ret = media_device_register(&dvb->mdev); + if (ret) { + dev_err(dvb->mdev.dev, + "media device register failed (err=%d) ", ret); + goto err_media_device_register; + } + + dvb_register_media_controller(&dvb->adapter, &dvb->mdev); +#endif /* config_media_controller_dvb */ + +#ifdef config_media_controller_dvb +err_media_device_register: + media_device_cleanup(&dvb->mdev); +#endif /* config_media_controller_dvb */ +#ifdef config_media_controller_dvb + media_device_unregister(&dvb->mdev); + media_device_cleanup(&dvb->mdev); +#endif /* config_media_controller_dvb */ + diff --git a/drivers/media/test-drivers/vidtv/vidtv_bridge.h b/drivers/media/test-drivers/vidtv/vidtv_bridge.h --- a/drivers/media/test-drivers/vidtv/vidtv_bridge.h +++ b/drivers/media/test-drivers/vidtv/vidtv_bridge.h +#include <media/media-device.h> + * @mdev: the media_device struct for media controller support. + +#ifdef config_media_controller_dvb + struct media_device mdev; +#endif /* config_media_controller_dvb */
TV tuners, webcams, video capturers
e259572d6ffc036d29d0829f505de2c0149ff0bc
daniel w s almeida
drivers
media
test-drivers, vidtv
usb: ch9: add usb 3.2 ssp attributes
in preparation for usb 3.2 dual-lane support, add sublink speed attribute macros and enum usb_ssp_rate. a usb device that operates in superspeed plus may operate at different speed and lane count. these additional macros and enum values help specifying that.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support usb 3.2 multi-lanes
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h']
2
22
0
--- diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h --- a/include/linux/usb/ch9.h +++ b/include/linux/usb/ch9.h +/* usb 3.2 superspeed plus phy signaling rate generation and lane count */ + +enum usb_ssp_rate { + usb_ssp_gen_unknown = 0, + usb_ssp_gen_2x1, + usb_ssp_gen_1x2, + usb_ssp_gen_2x2, +}; + diff --git a/include/uapi/linux/usb/ch9.h b/include/uapi/linux/usb/ch9.h --- a/include/uapi/linux/usb/ch9.h +++ b/include/uapi/linux/usb/ch9.h +#define usb_ssp_sublink_speed_lse_bps 0 +#define usb_ssp_sublink_speed_lse_kbps 1 +#define usb_ssp_sublink_speed_lse_mbps 2 +#define usb_ssp_sublink_speed_lse_gbps 3 + +#define usb_ssp_sublink_speed_st_sym_rx 0 +#define usb_ssp_sublink_speed_st_asym_rx 1 +#define usb_ssp_sublink_speed_st_sym_tx 2 +#define usb_ssp_sublink_speed_st_asym_tx 3 + +#define usb_ssp_sublink_speed_lp_ss 0 +#define usb_ssp_sublink_speed_lp_ssp 1 +
Universal Serial Bus
f2fc9ff28d1c9bef7760516feadd38164044caae
thinh nguyen
include
linux
linux, usb
usb: gadget: composite: use ssp sublink speed macros
use superspeed plus sublink speed macros to fill the bos descriptor sublink speed attributes in the composite driver. they're self-documented so we can remove some of the comments, and this helps with readability by removing the magic numbers.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support usb 3.2 multi-lanes
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['c']
1
24
21
--- diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c +#include <linux/bitfield.h> - /* ssac = 1 (2 attributes) */ - ssp_cap->bmattributes = cpu_to_le32(1); + ssp_cap->bmattributes = + cpu_to_le32(field_prep(usb_ssp_sublink_speed_attribs, 1) | + field_prep(usb_ssp_sublink_speed_ids, 0)); - /* min rx/tx lane count = 1 */ - cpu_to_le16((1 << 8) | (1 << 12)); + cpu_to_le16(field_prep(usb_ssp_min_sublink_speed_attribute_id, 0) | + field_prep(usb_ssp_min_rx_lane_count, 1) | + field_prep(usb_ssp_min_tx_lane_count, 1)); - /* - * bmsublinkspeedattr[0]: - * st = symmetric, rx - * lse = 3 (gbps) - * lp = 1 (superspeedplus) - * lsm = 10 (10 gbps) - */ - cpu_to_le32((3 << 4) | (1 << 14) | (0xa << 16)); - /* - * bmsublinkspeedattr[1] = - * st = symmetric, tx - * lse = 3 (gbps) - * lp = 1 (superspeedplus) - * lsm = 10 (10 gbps) - */ + cpu_to_le32(field_prep(usb_ssp_sublink_speed_ssid, 0) | + field_prep(usb_ssp_sublink_speed_lse, + usb_ssp_sublink_speed_lse_gbps) | + field_prep(usb_ssp_sublink_speed_st, + usb_ssp_sublink_speed_st_sym_rx) | + field_prep(usb_ssp_sublink_speed_lp, + usb_ssp_sublink_speed_lp_ssp) | + field_prep(usb_ssp_sublink_speed_lsm, 10)); + - cpu_to_le32((3 << 4) | (1 << 14) | - (0xa << 16) | (1 << 7)); + cpu_to_le32(field_prep(usb_ssp_sublink_speed_ssid, 0) | + field_prep(usb_ssp_sublink_speed_lse, + usb_ssp_sublink_speed_lse_gbps) | + field_prep(usb_ssp_sublink_speed_st, + usb_ssp_sublink_speed_st_sym_tx) | + field_prep(usb_ssp_sublink_speed_lp, + usb_ssp_sublink_speed_lp_ssp) | + field_prep(usb_ssp_sublink_speed_lsm, 10));
Universal Serial Bus
121fc3ac2f02a2316c6451f1ee9d8ef5932441d2
thinh nguyen
drivers
usb
gadget
usb: gadget: introduce ssp rates and lanes
a usb device controller operating in superspeed plus may support gen2x1, gen1x2, and/or gen2x2. introduce superspeed plus signaling rate generation and lane count to usb_gadget with the fields ssp_rate and max_ssp_rate. the gadget driver can use these to setup the device bos descriptor and select the desire operating speed and number of lanes.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support usb 3.2 multi-lanes
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h']
1
9
0
--- diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h + * @ssp_rate: current connected superspeed plus signaling rate and lane count. + * @max_ssp_rate: maximum superspeed plus signaling rate and lane count the udc + * can handle. the udc must support this and all slower speeds and lower + * number of lanes. + + /* usb superspeed plus only */ + enum usb_ssp_rate ssp_rate; + enum usb_ssp_rate max_ssp_rate; +
Universal Serial Bus
db615c6264cffcd8f117c5628db1794afbd0f254
thinh nguyen
include
linux
usb
usb: gadget: introduce udc_set_ssp_rate() for ssp
a superspeed plus device may operate at different speed and lane count (i.e. gen2x2, gen1x2, or gen2x1). introduce gadget ops udc_set_ssp_rate() to set the desire corresponding usb_ssp_rate for superspeed plus capable devices.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support usb 3.2 multi-lanes
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
2
13
5
--- diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c - if (udc->gadget->ops->udc_set_speed) { - enum usb_device_speed s; + struct usb_gadget *gadget = udc->gadget; + enum usb_device_speed s; - s = min(speed, udc->gadget->max_speed); - udc->gadget->ops->udc_set_speed(udc->gadget, s); - } + if (speed == usb_speed_unknown) + s = gadget->max_speed; + else + s = min(speed, gadget->max_speed); + + if (s == usb_speed_super_plus && gadget->ops->udc_set_ssp_rate) + gadget->ops->udc_set_ssp_rate(gadget, gadget->max_ssp_rate); + else if (gadget->ops->udc_set_speed) + gadget->ops->udc_set_speed(gadget, s); diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h + void (*udc_set_ssp_rate)(struct usb_gadget *gadget, + enum usb_ssp_rate rate);
Universal Serial Bus
ead4c124852e66b6aa033e34cf9c4f08d40aeffc
thinh nguyen
include
linux
gadget, udc, usb
usb: gadget: composite: report various ssp sublink speeds
if a gadget supports superspeed plus, then it may operate in different sublink speeds. for example, if the gadget supports superspeed plus gen2x2, then it can support 2 sublink speeds gen1 and gen2. inform the host of these speeds in the bos descriptor.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support usb 3.2 multi-lanes
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['c']
1
54
26
- ssid 0 for symmetric rx/tx sublink speed of 10 gbps. - ssid 0 for symmetric rx/tx sublink speed of 5 gbps. - ssid 0 for symmetric rx/tx sublink speed of 5 gbps. - ssid 1 for symmetric rx/tx sublink speed of 10 gbps. --- diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c + u8 ssac = 1; + u8 ssic; + int i; - ssp_cap = cdev->req->buf + le16_to_cpu(bos->wtotallength); - bos->bnumdevicecaps++; + if (cdev->gadget->max_ssp_rate == usb_ssp_gen_2x2) + ssac = 3; - * report typical values. + * paired rx and tx sublink speed attributes share + * the same ssid. + ssic = (ssac + 1) / 2 - 1; - le16_add_cpu(&bos->wtotallength, usb_dt_usb_ssp_cap_size(1)); - ssp_cap->blength = usb_dt_usb_ssp_cap_size(1); + ssp_cap = cdev->req->buf + le16_to_cpu(bos->wtotallength); + bos->bnumdevicecaps++; + + le16_add_cpu(&bos->wtotallength, usb_dt_usb_ssp_cap_size(ssac)); + ssp_cap->blength = usb_dt_usb_ssp_cap_size(ssac); - cpu_to_le32(field_prep(usb_ssp_sublink_speed_attribs, 1) | - field_prep(usb_ssp_sublink_speed_ids, 0)); + cpu_to_le32(field_prep(usb_ssp_sublink_speed_attribs, ssac) | + field_prep(usb_ssp_sublink_speed_ids, ssic)); - ssp_cap->bmsublinkspeedattr[0] = - cpu_to_le32(field_prep(usb_ssp_sublink_speed_ssid, 0) | - field_prep(usb_ssp_sublink_speed_lse, - usb_ssp_sublink_speed_lse_gbps) | - field_prep(usb_ssp_sublink_speed_st, - usb_ssp_sublink_speed_st_sym_rx) | - field_prep(usb_ssp_sublink_speed_lp, - usb_ssp_sublink_speed_lp_ssp) | - field_prep(usb_ssp_sublink_speed_lsm, 10)); - - ssp_cap->bmsublinkspeedattr[1] = - cpu_to_le32(field_prep(usb_ssp_sublink_speed_ssid, 0) | - field_prep(usb_ssp_sublink_speed_lse, - usb_ssp_sublink_speed_lse_gbps) | - field_prep(usb_ssp_sublink_speed_st, - usb_ssp_sublink_speed_st_sym_tx) | - field_prep(usb_ssp_sublink_speed_lp, - usb_ssp_sublink_speed_lp_ssp) | - field_prep(usb_ssp_sublink_speed_lsm, 10)); + /* + * use 1 ssid if the gadget supports up to gen2x1 or not + * specified: + * - ssid 0 for symmetric rx/tx sublink speed of 10 gbps. + * + * use 1 ssid if the gadget supports up to gen1x2: + * - ssid 0 for symmetric rx/tx sublink speed of 5 gbps. + * + * use 2 ssids if the gadget supports up to gen2x2: + * - ssid 0 for symmetric rx/tx sublink speed of 5 gbps. + * - ssid 1 for symmetric rx/tx sublink speed of 10 gbps. + */ + for (i = 0; i < ssac + 1; i++) { + u8 ssid; + u8 mantissa; + u8 type; + + ssid = i >> 1; + + if (cdev->gadget->max_ssp_rate == usb_ssp_gen_2x1 || + cdev->gadget->max_ssp_rate == usb_ssp_gen_unknown) + mantissa = 10; + else + mantissa = 5 << ssid; + + if (i % 2) + type = usb_ssp_sublink_speed_st_sym_tx; + else + type = usb_ssp_sublink_speed_st_sym_rx; + + ssp_cap->bmsublinkspeedattr[i] = + cpu_to_le32(field_prep(usb_ssp_sublink_speed_ssid, ssid) | + field_prep(usb_ssp_sublink_speed_lse, + usb_ssp_sublink_speed_lse_gbps) | + field_prep(usb_ssp_sublink_speed_st, type) | + field_prep(usb_ssp_sublink_speed_lp, + usb_ssp_sublink_speed_lp_ssp) | + field_prep(usb_ssp_sublink_speed_lsm, mantissa)); + }
Universal Serial Bus
7bf0fc5a6b6e45924141c34c065da10bb6858fc2
thinh nguyen
drivers
usb
gadget
usb: gadget: u_audio: free requests only after callback
as per the kernel doc for usb_ep_dequeue(), it states that "this routine is asynchronous, that is, it may return before the completion routine runs". and indeed since v5.0 the dwc3 gadget driver updated its behavior to place dequeued requests on to a cancelled list to be given back later after the endpoint is stopped.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support usb 3.2 multi-lanes
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['c']
1
14
3
--- diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c - if (!prm->ep_enabled || req->status == -eshutdown) + if (!prm->ep_enabled) { + usb_ep_free_request(ep, req); + return; + } + + if (req->status == -eshutdown) - usb_ep_dequeue(ep, prm->ureq[i].req); - usb_ep_free_request(ep, prm->ureq[i].req); + if (usb_ep_dequeue(ep, prm->ureq[i].req)) + usb_ep_free_request(ep, prm->ureq[i].req); + /* + * if usb_ep_dequeue() cannot successfully dequeue the + * request, the request will be freed by the completion + * callback. + */ +
Universal Serial Bus
7de8681be2cde9f6953d3be1fa6ce05f9fe6e637
jack pham
drivers
usb
function, gadget
dt-binding: usb: include usb ssp rates in genxxy
according to the usb 3.2 spec, a superspeed plus device can operate at gen2x2, gen2x1, or gen1x2. if the usb controller device supports multiple lanes at different transfer rates, the user can specify the hw capability via these new speed strings:
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support usb 3.2 multi-lanes
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['yaml']
1
3
0
--- diff --git a/documentation/devicetree/bindings/usb/usb.yaml b/documentation/devicetree/bindings/usb/usb.yaml --- a/documentation/devicetree/bindings/usb/usb.yaml +++ b/documentation/devicetree/bindings/usb/usb.yaml - high-speed - super-speed - super-speed-plus + - super-speed-plus-gen2x1 + - super-speed-plus-gen1x2 + - super-speed-plus-gen2x2
Universal Serial Bus
de4d9ea789530ac0ce3409878422e9389c3a7cd3
thinh nguyen
documentation
devicetree
bindings, usb
usb: common: parse for usb ssp genxxy
the usb "maximum-speed" property can now take the ssp signaling rate generation and lane count with these new strings:
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support usb 3.2 multi-lanes
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
2
36
1
--- diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c +static const char *const ssp_rate[] = { + [usb_ssp_gen_unknown] = "unknown", + [usb_ssp_gen_2x1] = "super-speed-plus-gen2x1", + [usb_ssp_gen_1x2] = "super-speed-plus-gen1x2", + [usb_ssp_gen_2x2] = "super-speed-plus-gen2x2", +}; + - ret = match_string(speed_names, array_size(speed_names), maximum_speed); + ret = match_string(ssp_rate, array_size(ssp_rate), maximum_speed); + if (ret > 0) + return usb_speed_super_plus; + ret = match_string(speed_names, array_size(speed_names), maximum_speed); +enum usb_ssp_rate usb_get_maximum_ssp_rate(struct device *dev) +{ + const char *maximum_speed; + int ret; + + ret = device_property_read_string(dev, "maximum-speed", &maximum_speed); + if (ret < 0) + return usb_ssp_gen_unknown; + + ret = match_string(ssp_rate, array_size(ssp_rate), maximum_speed); + return (ret < 0) ? usb_ssp_gen_unknown : ret; +} +export_symbol_gpl(usb_get_maximum_ssp_rate); + diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h --- a/include/linux/usb/ch9.h +++ b/include/linux/usb/ch9.h +/** + * usb_get_maximum_ssp_rate - get the signaling rate generation and lane count + * of a superspeed plus capable device. + * @dev: pointer to the given usb controller device + * + * if the string from "maximum-speed" property is super-speed-plus-genxxy where + * 'x' is the generation number and 'y' is the number of lanes, then this + * function returns the corresponding enum usb_ssp_rate. + */ +extern enum usb_ssp_rate usb_get_maximum_ssp_rate(struct device *dev); +
Universal Serial Bus
52c2d15703c3a900d5f78cd599b823db40d5100b
thinh nguyen
drivers
usb
common, usb
usb: dwc3: core: check maximum_speed ssp genxxy
the dwc_usb32 controller supports dual-lane superspeed plus. check the maximum_speed property for any limitation in the hw to initialize and validate the maximum number of lanes and speed the device will operate.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support usb 3.2 multi-lanes
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
3
40
0
--- diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c + dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); + + /* + * currently the controller does not have visibility into the hw + * parameter to determine the maximum number of lanes the hw supports. + * if the number of lanes is not specified in the device property, then + * set the default to support dual-lane for dwc_usb32 and single-lane + * for dwc_usb31 for super-speed-plus. + */ + if (dwc->maximum_speed == usb_speed_super_plus) { + switch (dwc->max_ssp_rate) { + case usb_ssp_gen_2x1: + if (hwparam_gen == dwc3_ghwparams3_ssphy_ifc_gen1) + dev_warn(dev, "udc only supports gen 1 "); + break; + case usb_ssp_gen_1x2: + case usb_ssp_gen_2x2: + if (dwc3_ip_is(dwc31)) + dev_warn(dev, "udc only supports single lane "); + break; + case usb_ssp_gen_unknown: + default: + switch (hwparam_gen) { + case dwc3_ghwparams3_ssphy_ifc_gen2: + if (dwc3_ip_is(dwc32)) + dwc->max_ssp_rate = usb_ssp_gen_2x2; + else + dwc->max_ssp_rate = usb_ssp_gen_2x1; + break; + case dwc3_ghwparams3_ssphy_ifc_gen1: + if (dwc3_ip_is(dwc32)) + dwc->max_ssp_rate = usb_ssp_gen_1x2; + break; + } + break; + } + } diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h + * @max_ssp_rate: superspeed plus maximum signaling rate and lane count + enum usb_ssp_rate max_ssp_rate; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c + dwc->gadget->max_ssp_rate = dwc->max_ssp_rate;
Universal Serial Bus
678481467d2e1460a49e626d8e9ba0c7e9742f53
thinh nguyen
drivers
usb
dwc3
usb: dwc3: gadget: implement setting of ssp rate
implement gadget ops udc_set_ssp_rate(). this allows the gadget/core driver to select ssp signaling rate and number of lanes to for dwc_usb32 controller.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support usb 3.2 multi-lanes
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
2
51
1
--- diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h +#define dwc3_dcfg_numlanes(n) (((n) & 0x3) << 30) /* dwc_usb32 only */ + + * @gadget_ssp_rate: gadget driver's maximum supported superspeed plus signaling + * rate and lane count. + enum usb_ssp_rate gadget_ssp_rate; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c +static void __dwc3_gadget_set_ssp_rate(struct dwc3 *dwc) +{ + enum usb_ssp_rate ssp_rate = dwc->gadget_ssp_rate; + u32 reg; + + if (ssp_rate == usb_ssp_gen_unknown) + ssp_rate = dwc->max_ssp_rate; + + reg = dwc3_readl(dwc->regs, dwc3_dcfg); + reg &= ~dwc3_dcfg_speed_mask; + reg &= ~dwc3_dcfg_numlanes(~0); + + if (ssp_rate == usb_ssp_gen_1x2) + reg |= dwc3_dcfg_superspeed; + else if (dwc->max_ssp_rate != usb_ssp_gen_1x2) + reg |= dwc3_dcfg_superspeed_plus; + + if (ssp_rate != usb_ssp_gen_2x1 && + dwc->max_ssp_rate != usb_ssp_gen_2x1) + reg |= dwc3_dcfg_numlanes(1); + + dwc3_writel(dwc->regs, dwc3_dcfg, reg); +} + + if (dwc->gadget_max_speed == usb_speed_super_plus && + dwc3_ip_is(dwc32)) { + __dwc3_gadget_set_ssp_rate(dwc); + return; + } + +static void dwc3_gadget_set_ssp_rate(struct usb_gadget *g, + enum usb_ssp_rate rate) +{ + struct dwc3 *dwc = gadget_to_dwc(g); + unsigned long flags; + + spin_lock_irqsave(&dwc->lock, flags); + dwc->gadget_ssp_rate = rate; + spin_unlock_irqrestore(&dwc->lock, flags); +} + + .udc_set_ssp_rate = dwc3_gadget_set_ssp_rate, - dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed); + if (dwc3_ip_is(dwc32) && dwc->maximum_speed == usb_speed_super_plus) + dwc3_gadget_set_ssp_rate(dwc->gadget, dwc->max_ssp_rate); + else + dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed);
Universal Serial Bus
072cab8a0fe276282272e57138d83299e35455eb
thinh nguyen
drivers
usb
dwc3
usb: dwc3: gadget: track connected ssp rate and lane count
track the number of connected lanes and speed in corresponding enum usb_ssp_rate for superspeed plus capable device.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support usb 3.2 multi-lanes
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
2
25
0
--- diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h +#define dwc3_dsts_connlanes(n) (((n) >> 30) & 0x3) /* dwc_usb32 only */ + diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c + + if (dwc3_ip_is(dwc32) && + dwc->gadget_max_speed > usb_speed_unknown && + dwc->gadget_max_speed < usb_speed_super_plus) + reg &= ~dwc3_dcfg_numlanes(~0); + + u8 lanes = 1; + if (dwc3_ip_is(dwc32)) + lanes = dwc3_dsts_connlanes(reg) + 1; + + dwc->gadget->ssp_rate = usb_ssp_gen_unknown; + + + if (lanes > 1) + dwc->gadget->ssp_rate = usb_ssp_gen_2x2; + else + dwc->gadget->ssp_rate = usb_ssp_gen_2x1; + + if (lanes > 1) { + dwc->gadget->speed = usb_speed_super_plus; + dwc->gadget->ssp_rate = usb_ssp_gen_1x2; + } + dwc->gadget->ssp_rate = usb_ssp_gen_unknown;
Universal Serial Bus
f551037c0770d07e4669d7d4fa423c235291dc59
thinh nguyen
drivers
usb
dwc3
usb: dwc3: gadget: set speed only up to the max supported
the setting of the device speed should be limited by the device's maximum_speed. check and prevent the driver from attempting to configure higher than the maximum_speed.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support usb 3.2 multi-lanes
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['c']
1
10
5
--- diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c + enum usb_device_speed speed; - if (dwc->gadget_max_speed == usb_speed_super_plus && + speed = dwc->gadget_max_speed; + if (speed > dwc->maximum_speed) + speed = dwc->maximum_speed; + + if (speed == usb_speed_super_plus && - switch (dwc->gadget_max_speed) { + switch (speed) { - dev_err(dwc->dev, "invalid speed (%d) ", dwc->gadget_max_speed); + dev_err(dwc->dev, "invalid speed (%d) ", speed); - dwc->gadget_max_speed > usb_speed_unknown && - dwc->gadget_max_speed < usb_speed_super_plus) + speed > usb_speed_unknown && + speed < usb_speed_super_plus)
Universal Serial Bus
450b9e9fabd80d7d5fd29e6f915b696a15acd2bd
thinh nguyen
drivers
usb
dwc3
usb: cdns3: add support for drd cdnsp
patch adds support for cadence drd super speed plus controller(cdnsp). cdnsp drd is a part of cadence cdnsp controller. the drd cdnsp controller has a lot of difference on hardware level but on software level is quite compatible with cdns3 drd. for this reason cdns3 drd part of cdns3 driver was reused for cdnsp driver.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduced new cadence usbssp drd driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
4
148
49
--- diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c - if (is_enabled(config_usb_cdns3_host) && - is_enabled(config_usb_cdns3_gadget)) - dr_mode = usb_dr_mode_otg; - else if (is_enabled(config_usb_cdns3_host)) - dr_mode = usb_dr_mode_host; - else if (is_enabled(config_usb_cdns3_gadget)) - dr_mode = usb_dr_mode_peripheral; + if (cdns->version == cdnsp_controller_v2) { + if (is_enabled(config_usb_cdnsp_host) && + is_enabled(config_usb_cdnsp_gadget)) + dr_mode = usb_dr_mode_otg; + else if (is_enabled(config_usb_cdnsp_host)) + dr_mode = usb_dr_mode_host; + else if (is_enabled(config_usb_cdnsp_gadget)) + dr_mode = usb_dr_mode_peripheral; + } else { + if (is_enabled(config_usb_cdns3_host) && + is_enabled(config_usb_cdns3_gadget)) + dr_mode = usb_dr_mode_otg; + else if (is_enabled(config_usb_cdns3_host)) + dr_mode = usb_dr_mode_host; + else if (is_enabled(config_usb_cdns3_gadget)) + dr_mode = usb_dr_mode_peripheral; + } diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h --- a/drivers/usb/cdns3/core.h +++ b/drivers/usb/cdns3/core.h + * @otg_cdnsp_regs: pointer to base of cdnsp otg registers + * @otg_irq_regs: pointer to interrupt registers + struct cdnsp_otg_regs *otg_cdnsp_regs; + struct cdns3_otg_irq_regs *otg_irq_regs; +#define cdnsp_controller_v2 2 diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c --- a/drivers/usb/cdns3/drd.c +++ b/drivers/usb/cdns3/drd.c - * copyright (c) 2018-2019 cadence. + * copyright (c) 2018-2020 cadence. - * -int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode) +static int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode) + u32 __iomem *override_reg; - if (cdns->version == cdns3_controller_v1) { - reg = readl(&cdns->otg_v1_regs->override); + + if (cdns->version == cdnsp_controller_v2) + override_reg = &cdns->otg_cdnsp_regs->override; + else if (cdns->version == cdns3_controller_v1) + override_reg = &cdns->otg_v1_regs->override; + else + override_reg = &cdns->otg_v0_regs->ctrl1; + + reg = readl(override_reg); + + if (cdns->version != cdns3_controller_v0) - writel(reg, &cdns->otg_v1_regs->override); + else + reg |= override_idpullup_v0; + writel(reg, override_reg); + + if (cdns->version == cdns3_controller_v1) { - } else { - reg = readl(&cdns->otg_v0_regs->ctrl1); - reg |= override_idpullup_v0; - writel(reg, &cdns->otg_v0_regs->ctrl1); - writel(0, &cdns->otg_regs->ien); + writel(0, &cdns->otg_irq_regs->ien); - otgien_vbusvalid_fall_int, &cdns->otg_regs->ien); + otgien_vbusvalid_fall_int, &cdns->otg_irq_regs->ien); - u32 val; + u32 val, ready_bit; + if (cdns->version == cdnsp_controller_v2) + ready_bit = otgsts_cdnsp_xhci_ready; + else + ready_bit = otgsts_cdns3_xhci_ready; + - val & otgsts_xhci_ready, 1, 100000); + val & ready_bit, 1, 100000); - int ret, val; + u32 ready_bit; + int ret, val; + if (cdns->version == cdnsp_controller_v2) + ready_bit = otgsts_cdnsp_dev_ready; + else + ready_bit = otgsts_cdns3_dev_ready; + - val & otgsts_dev_ready, - 1, 100000); + val & ready_bit, 1, 100000); - writel(~0, &cdns->otg_regs->ivect); + writel(~0, &cdns->otg_irq_regs->ivect); - reg = readl(&cdns->otg_regs->ivect); + reg = readl(&cdns->otg_irq_regs->ivect); - writel(~0, &cdns->otg_regs->ivect); + writel(~0, &cdns->otg_irq_regs->ivect); - * in two versions. both are similar, but they have same changes - * in register maps. - * the first register in old version is command register and it's read - * only, so driver should read 0 from it. on the other hand, in v1 - * the first register contains device id number which is not set to 0. - * driver uses this fact to detect the proper version of + * in three versions. all are very similar and are software compatible, + * but they have same changes in register maps. + * the first register in oldest version is command register and it's + * read only. driver should read 0 from it. on the other hand, in v1 + * and v2 the first register contains device id number which is not + * set to 0. driver uses this fact to detect the proper version of + cdns->otg_cdnsp_regs = null; + cdns->otg_irq_regs = (struct cdns3_otg_irq_regs *) + &cdns->otg_v0_regs->ien; + cdns->otg_cdnsp_regs = regs; + - cdns->version = cdns3_controller_v1; - writel(1, &cdns->otg_v1_regs->simulate); + + if (cdns->otg_cdnsp_regs->did == otg_cdnsp_did) { + cdns->otg_irq_regs = (struct cdns3_otg_irq_regs *) + &cdns->otg_cdnsp_regs->ien; + cdns->version = cdnsp_controller_v2; + } else { + cdns->otg_irq_regs = (struct cdns3_otg_irq_regs *) + &cdns->otg_v1_regs->ien; + writel(1, &cdns->otg_v1_regs->simulate); + cdns->version = cdns3_controller_v1; + } + - if (state == otgsts_strap_host) { + + if ((cdns->version == cdnsp_controller_v2 && + state == otgsts_cdnsp_strap_host) || + (cdns->version != cdnsp_controller_v2 && + state == otgsts_strap_host)) { - } else if (state == otgsts_strap_gadget) { + } else if ((cdns->version == cdnsp_controller_v2 && + state == otgsts_cdnsp_strap_gadget) || + (cdns->version != cdnsp_controller_v2 && + state == otgsts_strap_gadget)) { diff --git a/drivers/usb/cdns3/drd.h b/drivers/usb/cdns3/drd.h --- a/drivers/usb/cdns3/drd.h +++ b/drivers/usb/cdns3/drd.h - * cadence usb3 drd header file. + * cadence usb3 and usbssp drd header file. - * copyright (c) 2018-2019 cadence. + * copyright (c) 2018-2020 cadence. -/* drd register interface for version v1. */ +/* drd register interface for version v1 of cdns3 driver. */ -/* drd register interface for version v0. */ +/* drd register interface for version v0 of cdns3 driver. */ +/* drd register interface for cdnsp driver */ +struct cdnsp_otg_regs { + __le32 did; + __le32 rid; + __le32 cfgs1; + __le32 cfgs2; + __le32 cmd; + __le32 sts; + __le32 state; + __le32 ien; + __le32 ivect; + __le32 tmr; + __le32 simulate; + __le32 adpbc_sts; + __le32 adp_ramp_time; + __le32 adpbc_ctrl1; + __le32 adpbc_ctrl2; + __le32 override; + __le32 vbusvalid_dbnc_cfg; + __le32 sessvalid_dbnc_cfg; + __le32 susp_timing_ctrl; +}; + +#define otg_cdnsp_did 0x0004034e + - * common registers interface for both version of drd. + * common registers interface for both cdns3 and cdnsp version of drd. - __le32 different1; +}; + +/* + * interrupt related registers. this registers are mapped in different + * location for cdnsp controller. + */ +struct cdns3_otg_irq_regs { -/* power down usbss-dev. */ +/* power down usbss-dev - only for cdns3.*/ -/* power down cdnsxhci. */ +/* power down cdnsxhci - only for cdns3. */ - * value of the strap pins. + * value of the strap pins for: + * cdns3: + * cdnsp: + * 000 - no default configuration. + * 010 - controller initiall configured as host. + * 100 - controller initially configured as device. +#define otgsts_cdnsp_strap_host 0x01 +#define otgsts_cdnsp_strap_gadget 0x02 + -#define otgsts_xhci_ready bit(26) +#define otgsts_cdns3_xhci_ready bit(26) +#define otgsts_cdnsp_xhci_ready bit(27) + -#define otgsts_dev_ready bit(27) +#define otgsts_cdns3_dev_ready bit(27) +#define otgsts_cdnsp_dev_ready bit(26) +/* vbusvalid/sesvalid override select. */ +#define override_sess_vld_sel bit(10) -int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode);
Universal Serial Bus
db8892bb1bb64b6e3d1381ac342a2ee31e1b76b6
pawel laszczak aswath govindraju a govindraju ti com
drivers
usb
cdns3
usb: cdns3: split core.c into cdns3-plat and core.c file
patch splits file core.c into core.c containing the common reusable code and cnd3-plat.c containing device platform specific code. these changes are required to make possible reuse drd part of cdns3 driver in cdnsp driver.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduced new cadence usbssp drd driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c', 'makefile']
6
343
263
--- diff --git a/drivers/usb/cdns3/makefile b/drivers/usb/cdns3/makefile --- a/drivers/usb/cdns3/makefile +++ b/drivers/usb/cdns3/makefile -cdns3-y := core.o drd.o +cdns3-y := cdns3-plat.o core.o drd.o diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c --- /dev/null +++ b/drivers/usb/cdns3/cdns3-plat.c +// spdx-license-identifier: gpl-2.0 +/* + * cadence usbss drd driver. + * + * copyright (c) 2018-2020 cadence. + * copyright (c) 2017-2018 nxp + * copyright (c) 2019 texas instruments + * + * + * author: peter chen <peter.chen@nxp.com> + * pawel laszczak <pawell@cadence.com> + * roger quadros <rogerq@ti.com> + */ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> + +#include "core.h" + +static int set_phy_power_on(struct cdns3 *cdns) +{ + int ret; + + ret = phy_power_on(cdns->usb2_phy); + if (ret) + return ret; + + ret = phy_power_on(cdns->usb3_phy); + if (ret) + phy_power_off(cdns->usb2_phy); + + return ret; +} + +static void set_phy_power_off(struct cdns3 *cdns) +{ + phy_power_off(cdns->usb3_phy); + phy_power_off(cdns->usb2_phy); +} + +/** + * cdns3_plat_probe - probe for cdns3 core device + * @pdev: pointer to cdns3 core platform device + * + * returns 0 on success otherwise negative errno + */ +static int cdns3_plat_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct resource *res; + struct cdns3 *cdns; + void __iomem *regs; + int ret; + + cdns = devm_kzalloc(dev, sizeof(*cdns), gfp_kernel); + if (!cdns) + return -enomem; + + cdns->dev = dev; + cdns->pdata = dev_get_platdata(dev); + + platform_set_drvdata(pdev, cdns); + + res = platform_get_resource_byname(pdev, ioresource_irq, "host"); + if (!res) { + dev_err(dev, "missing host irq "); + return -enodev; + } + + cdns->xhci_res[0] = *res; + + res = platform_get_resource_byname(pdev, ioresource_mem, "xhci"); + if (!res) { + dev_err(dev, "couldn't get xhci resource "); + return -enxio; + } + + cdns->xhci_res[1] = *res; + + cdns->dev_irq = platform_get_irq_byname(pdev, "peripheral"); + + if (cdns->dev_irq < 0) + return cdns->dev_irq; + + regs = devm_platform_ioremap_resource_byname(pdev, "dev"); + if (is_err(regs)) + return ptr_err(regs); + cdns->dev_regs = regs; + + cdns->otg_irq = platform_get_irq_byname(pdev, "otg"); + if (cdns->otg_irq < 0) + return cdns->otg_irq; + + res = platform_get_resource_byname(pdev, ioresource_mem, "otg"); + if (!res) { + dev_err(dev, "couldn't get otg resource "); + return -enxio; + } + + cdns->phyrst_a_enable = device_property_read_bool(dev, "cdns,phyrst-a-enable"); + + cdns->otg_res = *res; + + cdns->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup"); + if (cdns->wakeup_irq == -eprobe_defer) + return cdns->wakeup_irq; + else if (cdns->wakeup_irq == 0) + return -einval; + + if (cdns->wakeup_irq < 0) { + dev_dbg(dev, "couldn't get wakeup irq "); + cdns->wakeup_irq = 0x0; + } + + cdns->usb2_phy = devm_phy_optional_get(dev, "cdns3,usb2-phy"); + if (is_err(cdns->usb2_phy)) + return ptr_err(cdns->usb2_phy); + + ret = phy_init(cdns->usb2_phy); + if (ret) + return ret; + + cdns->usb3_phy = devm_phy_optional_get(dev, "cdns3,usb3-phy"); + if (is_err(cdns->usb3_phy)) + return ptr_err(cdns->usb3_phy); + + ret = phy_init(cdns->usb3_phy); + if (ret) + goto err_phy3_init; + + ret = set_phy_power_on(cdns); + if (ret) + goto err_phy_power_on; + + ret = cdns3_init(cdns); + if (ret) + goto err_cdns_init; + + device_set_wakeup_capable(dev, true); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + if (!(cdns->pdata && (cdns->pdata->quirks & cdns3_default_pm_runtime_allow))) + pm_runtime_forbid(dev); + + /* + * the controller needs less time between bus and controller suspend, + * and we also needs a small delay to avoid frequently entering low + * power mode. + */ + pm_runtime_set_autosuspend_delay(dev, 20); + pm_runtime_mark_last_busy(dev); + pm_runtime_use_autosuspend(dev); + + return 0; + +err_cdns_init: + set_phy_power_off(cdns); +err_phy_power_on: + phy_exit(cdns->usb3_phy); +err_phy3_init: + phy_exit(cdns->usb2_phy); + + return ret; +} + +/** + * cdns3_remove - unbind drd driver and clean up + * @pdev: pointer to linux platform device + * + * returns 0 on success otherwise negative errno + */ +static int cdns3_plat_remove(struct platform_device *pdev) +{ + struct cdns3 *cdns = platform_get_drvdata(pdev); + struct device *dev = cdns->dev; + + pm_runtime_get_sync(dev); + pm_runtime_disable(dev); + pm_runtime_put_noidle(dev); + cdns3_remove(cdns); + set_phy_power_off(cdns); + phy_exit(cdns->usb2_phy); + phy_exit(cdns->usb3_phy); + return 0; +} + +#ifdef config_pm + +static int cdns3_set_platform_suspend(struct device *dev, + bool suspend, bool wakeup) +{ + struct cdns3 *cdns = dev_get_drvdata(dev); + int ret = 0; + + if (cdns->pdata && cdns->pdata->platform_suspend) + ret = cdns->pdata->platform_suspend(dev, suspend, wakeup); + + return ret; +} + +static int cdns3_controller_suspend(struct device *dev, pm_message_t msg) +{ + struct cdns3 *cdns = dev_get_drvdata(dev); + bool wakeup; + unsigned long flags; + + if (cdns->in_lpm) + return 0; + + if (pmsg_is_auto(msg)) + wakeup = true; + else + wakeup = device_may_wakeup(dev); + + cdns3_set_platform_suspend(cdns->dev, true, wakeup); + set_phy_power_off(cdns); + spin_lock_irqsave(&cdns->lock, flags); + cdns->in_lpm = true; + spin_unlock_irqrestore(&cdns->lock, flags); + dev_dbg(cdns->dev, "%s ends ", __func__); + + return 0; +} + +static int cdns3_controller_resume(struct device *dev, pm_message_t msg) +{ + struct cdns3 *cdns = dev_get_drvdata(dev); + int ret; + unsigned long flags; + + if (!cdns->in_lpm) + return 0; + + ret = set_phy_power_on(cdns); + if (ret) + return ret; + + cdns3_set_platform_suspend(cdns->dev, false, false); + + spin_lock_irqsave(&cdns->lock, flags); + cdns3_resume(cdns, !pmsg_is_auto(msg)); + cdns->in_lpm = false; + spin_unlock_irqrestore(&cdns->lock, flags); + if (cdns->wakeup_pending) { + cdns->wakeup_pending = false; + enable_irq(cdns->wakeup_irq); + } + dev_dbg(cdns->dev, "%s ends ", __func__); + + return ret; +} + +static int cdns3_plat_runtime_suspend(struct device *dev) +{ + return cdns3_controller_suspend(dev, pmsg_auto_suspend); +} + +static int cdns3_plat_runtime_resume(struct device *dev) +{ + return cdns3_controller_resume(dev, pmsg_auto_resume); +} + +#ifdef config_pm_sleep + +static int cdns3_plat_suspend(struct device *dev) +{ + struct cdns3 *cdns = dev_get_drvdata(dev); + + cdns3_suspend(cdns); + + return cdns3_controller_suspend(dev, pmsg_suspend); +} + +static int cdns3_plat_resume(struct device *dev) +{ + return cdns3_controller_resume(dev, pmsg_resume); +} +#endif /* config_pm_sleep */ +#endif /* config_pm */ + +static const struct dev_pm_ops cdns3_pm_ops = { + set_system_sleep_pm_ops(cdns3_plat_suspend, cdns3_plat_resume) + set_runtime_pm_ops(cdns3_plat_runtime_suspend, + cdns3_plat_runtime_resume, null) +}; + +#ifdef config_of +static const struct of_device_id of_cdns3_match[] = { + { .compatible = "cdns,usb3" }, + { }, +}; +module_device_table(of, of_cdns3_match); +#endif + +static struct platform_driver cdns3_driver = { + .probe = cdns3_plat_probe, + .remove = cdns3_plat_remove, + .driver = { + .name = "cdns-usb3", + .of_match_table = of_match_ptr(of_cdns3_match), + .pm = &cdns3_pm_ops, + }, +}; + +module_platform_driver(cdns3_driver); + +module_alias("platform:cdns3"); +module_author("pawel laszczak <pawell@cadence.com>"); +module_license("gpl v2"); +module_description("cadence usb3 drd controller driver"); diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c -static int set_phy_power_on(struct cdns3 *cdns) -{ - int ret; - - ret = phy_power_on(cdns->usb2_phy); - if (ret) - return ret; - - ret = phy_power_on(cdns->usb3_phy); - if (ret) - phy_power_off(cdns->usb2_phy); - - return ret; -} - -static void set_phy_power_off(struct cdns3 *cdns) -{ - phy_power_off(cdns->usb3_phy); - phy_power_off(cdns->usb2_phy); -} - * @pdev: pointer to cdns3 core platform device + * @cdns: pointer to cdnsp structure. -static int cdns3_probe(struct platform_device *pdev) +int cdns3_init(struct cdns3 *cdns) - struct device *dev = &pdev->dev; - struct resource *res; - struct cdns3 *cdns; - void __iomem *regs; + struct device *dev = cdns->dev; - cdns = devm_kzalloc(dev, sizeof(*cdns), gfp_kernel); - if (!cdns) - return -enomem; - - cdns->dev = dev; - cdns->pdata = dev_get_platdata(dev); - - platform_set_drvdata(pdev, cdns); - - res = platform_get_resource_byname(pdev, ioresource_irq, "host"); - if (!res) { - dev_err(dev, "missing host irq "); - return -enodev; - } - - cdns->xhci_res[0] = *res; - - res = platform_get_resource_byname(pdev, ioresource_mem, "xhci"); - if (!res) { - dev_err(dev, "couldn't get xhci resource "); - return -enxio; - } - - cdns->xhci_res[1] = *res; - - cdns->dev_irq = platform_get_irq_byname(pdev, "peripheral"); - if (cdns->dev_irq < 0) - return cdns->dev_irq; - - regs = devm_platform_ioremap_resource_byname(pdev, "dev"); - if (is_err(regs)) - return ptr_err(regs); - cdns->dev_regs = regs; - - cdns->otg_irq = platform_get_irq_byname(pdev, "otg"); - if (cdns->otg_irq < 0) - return cdns->otg_irq; - - res = platform_get_resource_byname(pdev, ioresource_mem, "otg"); - if (!res) { - dev_err(dev, "couldn't get otg resource "); - return -enxio; - } - - cdns->phyrst_a_enable = device_property_read_bool(dev, "cdns,phyrst-a-enable"); - - cdns->otg_res = *res; - - cdns->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup"); - if (cdns->wakeup_irq == -eprobe_defer) - return cdns->wakeup_irq; - else if (cdns->wakeup_irq == 0) - return -einval; - - if (cdns->wakeup_irq < 0) { - dev_dbg(dev, "couldn't get wakeup irq "); - cdns->wakeup_irq = 0x0; - } - - cdns->usb2_phy = devm_phy_optional_get(dev, "cdns3,usb2-phy"); - if (is_err(cdns->usb2_phy)) - return ptr_err(cdns->usb2_phy); - - ret = phy_init(cdns->usb2_phy); - if (ret) - return ret; - - cdns->usb3_phy = devm_phy_optional_get(dev, "cdns3,usb3-phy"); - if (is_err(cdns->usb3_phy)) - return ptr_err(cdns->usb3_phy); - - ret = phy_init(cdns->usb3_phy); - if (ret) - goto err1; - - ret = set_phy_power_on(cdns); - if (ret) - goto err2; - - ret = ptr_err(cdns->role_sw); - goto err3; + return ptr_err(cdns->role_sw); - goto err4; + goto role_switch_unregister; - goto err4; + goto init_failed; - goto err4; + goto init_failed; - device_set_wakeup_capable(dev, true); - pm_runtime_set_active(dev); - pm_runtime_enable(dev); - if (!(cdns->pdata && (cdns->pdata->quirks & cdns3_default_pm_runtime_allow))) - pm_runtime_forbid(dev); - /* - * the controller needs less time between bus and controller suspend, - * and we also needs a small delay to avoid frequently entering low - * power mode. - */ - pm_runtime_set_autosuspend_delay(dev, 20); - pm_runtime_mark_last_busy(dev); - pm_runtime_use_autosuspend(dev); -err4: +init_failed: +role_switch_unregister: -err3: - set_phy_power_off(cdns); -err2: - phy_exit(cdns->usb3_phy); -err1: - phy_exit(cdns->usb2_phy); - * @pdev: pointer to linux platform device + * @cdns: pointer to cdnsp structure. -static int cdns3_remove(struct platform_device *pdev) +int cdns3_remove(struct cdns3 *cdns) - struct cdns3 *cdns = platform_get_drvdata(pdev); - - pm_runtime_get_sync(&pdev->dev); - pm_runtime_disable(&pdev->dev); - pm_runtime_put_noidle(&pdev->dev); - set_phy_power_off(cdns); - phy_exit(cdns->usb2_phy); - phy_exit(cdns->usb3_phy); - return 0; -} - -#ifdef config_pm - -static int cdns3_set_platform_suspend(struct device *dev, - bool suspend, bool wakeup) -{ - struct cdns3 *cdns = dev_get_drvdata(dev); - int ret = 0; - - if (cdns->pdata && cdns->pdata->platform_suspend) - ret = cdns->pdata->platform_suspend(dev, suspend, wakeup); - - return ret; -} - -static int cdns3_controller_suspend(struct device *dev, pm_message_t msg) -{ - struct cdns3 *cdns = dev_get_drvdata(dev); - bool wakeup; - unsigned long flags; - - if (cdns->in_lpm) - return 0; - - if (pmsg_is_auto(msg)) - wakeup = true; - else - wakeup = device_may_wakeup(dev); - - cdns3_set_platform_suspend(cdns->dev, true, wakeup); - set_phy_power_off(cdns); - spin_lock_irqsave(&cdns->lock, flags); - cdns->in_lpm = true; - spin_unlock_irqrestore(&cdns->lock, flags); - dev_dbg(cdns->dev, "%s ends ", __func__); -static int cdns3_controller_resume(struct device *dev, pm_message_t msg) -{ - struct cdns3 *cdns = dev_get_drvdata(dev); - int ret; - unsigned long flags; - - if (!cdns->in_lpm) - return 0; - - ret = set_phy_power_on(cdns); - if (ret) - return ret; - - cdns3_set_platform_suspend(cdns->dev, false, false); - - spin_lock_irqsave(&cdns->lock, flags); - if (cdns->roles[cdns->role]->resume && !pmsg_is_auto(msg)) - cdns->roles[cdns->role]->resume(cdns, false); - - cdns->in_lpm = false; - spin_unlock_irqrestore(&cdns->lock, flags); - if (cdns->wakeup_pending) { - cdns->wakeup_pending = false; - enable_irq(cdns->wakeup_irq); - } - dev_dbg(cdns->dev, "%s ends ", __func__); - - return ret; -} - -static int cdns3_runtime_suspend(struct device *dev) -{ - return cdns3_controller_suspend(dev, pmsg_auto_suspend); -} - -static int cdns3_runtime_resume(struct device *dev) -{ - return cdns3_controller_resume(dev, pmsg_auto_resume); -} - -static int cdns3_suspend(struct device *dev) +int cdns3_suspend(struct cdns3 *cdns) - struct cdns3 *cdns = dev_get_drvdata(dev); + struct device *dev = cdns->dev; - return cdns3_controller_suspend(dev, pmsg_suspend); + return 0; -static int cdns3_resume(struct device *dev) +int cdns3_resume(struct cdns3 *cdns, u8 set_active) - int ret; + struct device *dev = cdns->dev; - ret = cdns3_controller_resume(dev, pmsg_resume); - if (ret) - return ret; + if (cdns->roles[cdns->role]->resume) + cdns->roles[cdns->role]->resume(cdns, false); - pm_runtime_disable(dev); - pm_runtime_set_active(dev); - pm_runtime_enable(dev); + if (set_active) { + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + } - return ret; + return 0; -#endif /* config_pm */ - -static const struct dev_pm_ops cdns3_pm_ops = { - set_system_sleep_pm_ops(cdns3_suspend, cdns3_resume) - set_runtime_pm_ops(cdns3_runtime_suspend, cdns3_runtime_resume, null) -}; - -#ifdef config_of -static const struct of_device_id of_cdns3_match[] = { - { .compatible = "cdns,usb3" }, - { }, -}; -module_device_table(of, of_cdns3_match); -#endif - -static struct platform_driver cdns3_driver = { - .probe = cdns3_probe, - .remove = cdns3_remove, - .driver = { - .name = "cdns-usb3", - .of_match_table = of_match_ptr(of_cdns3_match), - .pm = &cdns3_pm_ops, - }, -}; - -module_platform_driver(cdns3_driver); - -module_alias("platform:cdns3"); -module_author("pawel laszczak <pawell@cadence.com>"); -module_license("gpl v2"); -module_description("cadence usb3 drd controller driver"); diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h --- a/drivers/usb/cdns3/core.h +++ b/drivers/usb/cdns3/core.h +int cdns3_init(struct cdns3 *cdns); +int cdns3_remove(struct cdns3 *cdns); +#ifdef config_pm_sleep +int cdns3_resume(struct cdns3 *cdns, u8 set_active); +int cdns3_suspend(struct cdns3 *cdns); +#endif /* config_pm_sleep */ diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c --- a/drivers/usb/cdns3/drd.c +++ b/drivers/usb/cdns3/drd.c -#include <linux/phy/phy.h> diff --git a/drivers/usb/cdns3/drd.h b/drivers/usb/cdns3/drd.h --- a/drivers/usb/cdns3/drd.h +++ b/drivers/usb/cdns3/drd.h -#include <linux/phy/phy.h>
Universal Serial Bus
f738957277bad824b422399a214b630d7832f884
pawel laszczak aswath govindraju a govindraju ti com
drivers
usb
cdns3
usb: cdns3: moves reusable code to separate module
patch moves common reusable code used by cdns3 and cdnsp driver to cdns-usb-common library. this library include core.c, drd.c and host.c files.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduced new cadence usbssp drd driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'kconfig', 'c', 'makefile']
6
35
7
--- diff --git a/drivers/usb/cdns3/kconfig b/drivers/usb/cdns3/kconfig --- a/drivers/usb/cdns3/kconfig +++ b/drivers/usb/cdns3/kconfig +config cdns_usb_common + tristate + +config cdns_usb_host + bool + + select cdns_usb_common + select cdns_usb_host diff --git a/drivers/usb/cdns3/makefile b/drivers/usb/cdns3/makefile --- a/drivers/usb/cdns3/makefile +++ b/drivers/usb/cdns3/makefile -cdns3-y := cdns3-plat.o core.o drd.o +cdns-usb-common-y := core.o drd.o +cdns3-y := cdns3-plat.o +obj-$(config_cdns_usb_common) += cdns-usb-common.o + +cdns-usb-common-$(config_cdns_usb_host) += host.o -cdns3-$(config_usb_cdns3_host) += host.o - diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c --- a/drivers/usb/cdns3/cdns3-plat.c +++ b/drivers/usb/cdns3/cdns3-plat.c +#include "gadget-export.h" + cdns->gadget_init = cdns3_gadget_init; diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c -#include "gadget.h" -#include "gadget-export.h" - ret = cdns3_gadget_init(cdns); + if (cdns->gadget_init) + ret = cdns->gadget_init(cdns); + else + ret = -enxio; + +export_symbol_gpl(cdns3_init); +export_symbol_gpl(cdns3_remove); +export_symbol_gpl(cdns3_suspend); +export_symbol_gpl(cdns3_resume); + +module_author("peter chen <peter.chen@nxp.com>"); +module_author("pawel laszczak <pawell@cadence.com>"); +module_author("roger quadros <rogerq@ti.com>"); +module_description("cadence usbss and usbssp drd driver"); +module_license("gpl"); diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h --- a/drivers/usb/cdns3/core.h +++ b/drivers/usb/cdns3/core.h + * @gadget_init: pointer to gadget initialization function + + int (*gadget_init)(struct cdns3 *cdns); diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c --- a/drivers/usb/cdns3/drd.c +++ b/drivers/usb/cdns3/drd.c -#include "gadget.h" +export_symbol_gpl(cdns3_drd_gadget_on); +export_symbol_gpl(cdns3_drd_gadget_off);
Universal Serial Bus
394c3a144de89e994c8a2c5ba5dc64fa4e5aa870
pawel laszczak aswath govindraju a govindraju ti com
drivers
usb
cdns3
usb: cdns3: refactoring names in reusable code
patch change the functions and objects names in reusable code. the reusable code includes core.c, core.h, drd.c and drd.h files. it also changes the names of all references to these functions and objects in other cdns3 files. there are a lot of changes, but all changes are very trivial. the reason of this patch is to avoid of mixing prefix cdns3 and cdnsp in in cdnsp driver what could introduce some confusion in understanding of cdnsp driver. this patch assumes to use three different prefixes in cadence usb drivers: cdns: for common reusable code cdnsp: for names related only with cdnsp driver cdns3: for names related only with cdns3 driver
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduced new cadence usbssp drd driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
10
199
198
--- diff --git a/drivers/usb/cdns3/cdns3-imx.c b/drivers/usb/cdns3/cdns3-imx.c --- a/drivers/usb/cdns3/cdns3-imx.c +++ b/drivers/usb/cdns3/cdns3-imx.c - struct cdns3 *cdns = dev_get_drvdata(dev); + struct cdns *cdns = dev_get_drvdata(dev); diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c --- a/drivers/usb/cdns3/cdns3-plat.c +++ b/drivers/usb/cdns3/cdns3-plat.c -static int set_phy_power_on(struct cdns3 *cdns) +static int set_phy_power_on(struct cdns *cdns) -static void set_phy_power_off(struct cdns3 *cdns) +static void set_phy_power_off(struct cdns *cdns) - struct cdns3 *cdns; + struct cdns *cdns; - ret = cdns3_init(cdns); + + ret = cdns_init(cdns); - struct cdns3 *cdns = platform_get_drvdata(pdev); + struct cdns *cdns = platform_get_drvdata(pdev); - cdns3_remove(cdns); + cdns_remove(cdns); - struct cdns3 *cdns = dev_get_drvdata(dev); + struct cdns *cdns = dev_get_drvdata(dev); - struct cdns3 *cdns = dev_get_drvdata(dev); + struct cdns *cdns = dev_get_drvdata(dev); - struct cdns3 *cdns = dev_get_drvdata(dev); + struct cdns *cdns = dev_get_drvdata(dev); - cdns3_resume(cdns, !pmsg_is_auto(msg)); + cdns_resume(cdns, !pmsg_is_auto(msg)); - struct cdns3 *cdns = dev_get_drvdata(dev); + struct cdns *cdns = dev_get_drvdata(dev); - cdns3_suspend(cdns); + cdns_suspend(cdns); diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c -static int cdns3_idle_init(struct cdns3 *cdns); +static int cdns_idle_init(struct cdns *cdns); -static int cdns3_role_start(struct cdns3 *cdns, enum usb_role role) +static int cdns_role_start(struct cdns *cdns, enum usb_role role) - if (cdns->roles[role]->state == cdns3_role_state_active) + if (cdns->roles[role]->state == cdns_role_state_active) - cdns->roles[role]->state = cdns3_role_state_active; + cdns->roles[role]->state = cdns_role_state_active; -static void cdns3_role_stop(struct cdns3 *cdns) +static void cdns_role_stop(struct cdns *cdns) - if (cdns->roles[role]->state == cdns3_role_state_inactive) + if (cdns->roles[role]->state == cdns_role_state_inactive) - cdns->roles[role]->state = cdns3_role_state_inactive; + cdns->roles[role]->state = cdns_role_state_inactive; -static void cdns3_exit_roles(struct cdns3 *cdns) +static void cdns_exit_roles(struct cdns *cdns) - cdns3_role_stop(cdns); - cdns3_drd_exit(cdns); + cdns_role_stop(cdns); + cdns_drd_exit(cdns); - * cdns3_core_init_role - initialize role of operation - * @cdns: pointer to cdns3 structure + * cdns_core_init_role - initialize role of operation + * @cdns: pointer to cdns structure -static int cdns3_core_init_role(struct cdns3 *cdns) +static int cdns_core_init_role(struct cdns *cdns) - ret = cdns3_idle_init(cdns); + ret = cdns_idle_init(cdns); - ret = cdns3_host_init(cdns); + ret = cdns_host_init(cdns); - ret = cdns3_drd_update_mode(cdns); + ret = cdns_drd_update_mode(cdns); - ret = cdns3_role_start(cdns, usb_role_none); + ret = cdns_role_start(cdns, usb_role_none); - ret = cdns3_hw_role_switch(cdns); + ret = cdns_hw_role_switch(cdns); - ret = cdns3_role_start(cdns, usb_role_device); + ret = cdns_role_start(cdns, usb_role_device); - ret = cdns3_role_start(cdns, usb_role_host); + ret = cdns_role_start(cdns, usb_role_host); - cdns3_exit_roles(cdns); + cdns_exit_roles(cdns); - * cdns3_hw_role_state_machine - role switch state machine based on hw events. + * cdns_hw_role_state_machine - role switch state machine based on hw events. -static enum usb_role cdns3_hw_role_state_machine(struct cdns3 *cdns) +static enum usb_role cdns_hw_role_state_machine(struct cdns *cdns) - if (cdns3_is_host(cdns)) + if (cdns_is_host(cdns)) - if (cdns3_is_device(cdns)) + if (cdns_is_device(cdns)) - id = cdns3_get_id(cdns); - vbus = cdns3_get_vbus(cdns); + id = cdns_get_id(cdns); + vbus = cdns_get_vbus(cdns); -static int cdns3_idle_role_start(struct cdns3 *cdns) +static int cdns_idle_role_start(struct cdns *cdns) -static void cdns3_idle_role_stop(struct cdns3 *cdns) +static void cdns_idle_role_stop(struct cdns *cdns) -static int cdns3_idle_init(struct cdns3 *cdns) +static int cdns_idle_init(struct cdns *cdns) - struct cdns3_role_driver *rdrv; + struct cdns_role_driver *rdrv; - rdrv->start = cdns3_idle_role_start; - rdrv->stop = cdns3_idle_role_stop; - rdrv->state = cdns3_role_state_inactive; + rdrv->start = cdns_idle_role_start; + rdrv->stop = cdns_idle_role_stop; + rdrv->state = cdns_role_state_inactive; - * cdns3_hw_role_switch - switch roles based on hw state + * cdns_hw_role_switch - switch roles based on hw state -int cdns3_hw_role_switch(struct cdns3 *cdns) +int cdns_hw_role_switch(struct cdns *cdns) - real_role = cdns3_hw_role_state_machine(cdns); + real_role = cdns_hw_role_state_machine(cdns); - cdns3_role_stop(cdns); + cdns_role_stop(cdns); - ret = cdns3_role_start(cdns, real_role); + ret = cdns_role_start(cdns, real_role); - ret = cdns3_role_start(cdns, current_role); + ret = cdns_role_start(cdns, current_role); -static enum usb_role cdns3_role_get(struct usb_role_switch *sw) +static enum usb_role cdns_role_get(struct usb_role_switch *sw) - struct cdns3 *cdns = usb_role_switch_get_drvdata(sw); + struct cdns *cdns = usb_role_switch_get_drvdata(sw); - * cdns3_role_set - set current role of controller. + * cdns_role_set - set current role of controller. -static int cdns3_role_set(struct usb_role_switch *sw, enum usb_role role) +static int cdns_role_set(struct usb_role_switch *sw, enum usb_role role) - struct cdns3 *cdns = usb_role_switch_get_drvdata(sw); + struct cdns *cdns = usb_role_switch_get_drvdata(sw); - cdns3_role_stop(cdns); - ret = cdns3_role_start(cdns, role); + cdns_role_stop(cdns); + ret = cdns_role_start(cdns, role); - * cdns3_wakeup_irq - interrupt handler for wakeup events - * @irq: irq number for cdns3 core device - * @data: structure of cdns3 + * cdns_wakeup_irq - interrupt handler for wakeup events + * @irq: irq number for cdns3/cdnsp core device + * @data: structure of cdns -static irqreturn_t cdns3_wakeup_irq(int irq, void *data) +static irqreturn_t cdns_wakeup_irq(int irq, void *data) - struct cdns3 *cdns = data; + struct cdns *cdns = data; - * cdns3_probe - probe for cdns3 core device - * @cdns: pointer to cdnsp structure. + * cdns_probe - probe for cdns3/cdnsp core device + * @cdns: pointer to cdns structure. -int cdns3_init(struct cdns3 *cdns) +int cdns_init(struct cdns *cdns) - sw_desc.set = cdns3_role_set; - sw_desc.get = cdns3_role_get; + sw_desc.set = cdns_role_set; + sw_desc.get = cdns_role_get; - cdns3_wakeup_irq, + cdns_wakeup_irq, - ret = cdns3_drd_init(cdns); + ret = cdns_drd_init(cdns); - ret = cdns3_core_init_role(cdns); + ret = cdns_core_init_role(cdns); - cdns3_drd_exit(cdns); + cdns_drd_exit(cdns); -export_symbol_gpl(cdns3_init); +export_symbol_gpl(cdns_init); - * cdns3_remove - unbind drd driver and clean up - * @cdns: pointer to cdnsp structure. + * cdns_remove - unbind drd driver and clean up + * @cdns: pointer to cdns structure. -int cdns3_remove(struct cdns3 *cdns) +int cdns_remove(struct cdns *cdns) - cdns3_exit_roles(cdns); + cdns_exit_roles(cdns); -export_symbol_gpl(cdns3_remove); +export_symbol_gpl(cdns_remove); -int cdns3_suspend(struct cdns3 *cdns) +int cdns_suspend(struct cdns *cdns) -export_symbol_gpl(cdns3_suspend); +export_symbol_gpl(cdns_suspend); -int cdns3_resume(struct cdns3 *cdns, u8 set_active) +int cdns_resume(struct cdns *cdns, u8 set_active) -export_symbol_gpl(cdns3_resume); +export_symbol_gpl(cdns_resume); diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h --- a/drivers/usb/cdns3/core.h +++ b/drivers/usb/cdns3/core.h -struct cdns3; +struct cdns; - * struct cdns3_role_driver - host/gadget role driver + * struct cdns_role_driver - host/gadget role driver -struct cdns3_role_driver { - int (*start)(struct cdns3 *cdns); - void (*stop)(struct cdns3 *cdns); - int (*suspend)(struct cdns3 *cdns, bool do_wakeup); - int (*resume)(struct cdns3 *cdns, bool hibernated); +struct cdns_role_driver { + int (*start)(struct cdns *cdns); + void (*stop)(struct cdns *cdns); + int (*suspend)(struct cdns *cdns, bool do_wakeup); + int (*resume)(struct cdns *cdns, bool hibernated); -#define cdns3_role_state_inactive 0 -#define cdns3_role_state_active 1 +#define cdns_role_state_inactive 0 +#define cdns_role_state_active 1 -#define cdns3_xhci_resources_num 2 +#define cdns_xhci_resources_num 2 - * struct cdns3 - representation of cadence usb3 drd controller. + * struct cdns - representation of cadence usb3 drd controller. - * @host_dev: the child host device pointer for cdns3 core + * @host_dev: the child host device pointer for cdns core -struct cdns3 { +struct cdns { - struct resource xhci_res[cdns3_xhci_resources_num]; + struct resource xhci_res[cdns_xhci_resources_num]; - struct cdns3_otg_common_regs *otg_regs; - struct cdns3_otg_irq_regs *otg_irq_regs; + struct cdns_otg_common_regs *otg_regs; + struct cdns_otg_irq_regs *otg_irq_regs; - struct cdns3_role_driver *roles[usb_role_device + 1]; + struct cdns_role_driver *roles[usb_role_device + 1]; - int (*gadget_init)(struct cdns3 *cdns); + int (*gadget_init)(struct cdns *cdns); -int cdns3_hw_role_switch(struct cdns3 *cdns); -int cdns3_init(struct cdns3 *cdns); -int cdns3_remove(struct cdns3 *cdns); +int cdns_hw_role_switch(struct cdns *cdns); +int cdns_init(struct cdns *cdns); +int cdns_remove(struct cdns *cdns); -int cdns3_resume(struct cdns3 *cdns, u8 set_active); -int cdns3_suspend(struct cdns3 *cdns); +int cdns_resume(struct cdns *cdns, u8 set_active); +int cdns_suspend(struct cdns *cdns); diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c --- a/drivers/usb/cdns3/drd.c +++ b/drivers/usb/cdns3/drd.c - * cdns3_set_mode - change mode of otg core + * cdns_set_mode - change mode of otg core -static int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode) +static int cdns_set_mode(struct cdns *cdns, enum usb_dr_mode mode) -int cdns3_get_id(struct cdns3 *cdns) +int cdns_get_id(struct cdns *cdns) -int cdns3_get_vbus(struct cdns3 *cdns) +int cdns_get_vbus(struct cdns *cdns) -bool cdns3_is_host(struct cdns3 *cdns) +bool cdns_is_host(struct cdns *cdns) - else if (cdns3_get_id(cdns) == cdns3_id_host) + else if (cdns_get_id(cdns) == cdns3_id_host) -bool cdns3_is_device(struct cdns3 *cdns) +bool cdns_is_device(struct cdns *cdns) - if (cdns3_get_id(cdns) == cdns3_id_peripheral) + if (cdns_get_id(cdns) == cdns3_id_peripheral) - * cdns3_otg_disable_irq - disable all otg interrupts + * cdns_otg_disable_irq - disable all otg interrupts -static void cdns3_otg_disable_irq(struct cdns3 *cdns) +static void cdns_otg_disable_irq(struct cdns *cdns) - * cdns3_otg_enable_irq - enable id and sess_valid interrupts + * cdns_otg_enable_irq - enable id and sess_valid interrupts -static void cdns3_otg_enable_irq(struct cdns3 *cdns) +static void cdns_otg_enable_irq(struct cdns *cdns) - * cdns3_drd_host_on - start host. + * cdns_drd_host_on - start host. -int cdns3_drd_host_on(struct cdns3 *cdns) +int cdns_drd_host_on(struct cdns *cdns) - * cdns3_drd_host_off - stop host. + * cdns_drd_host_off - stop host. -void cdns3_drd_host_off(struct cdns3 *cdns) +void cdns_drd_host_off(struct cdns *cdns) - * cdns3_drd_gadget_on - start gadget. + * cdns_drd_gadget_on - start gadget. -int cdns3_drd_gadget_on(struct cdns3 *cdns) +int cdns_drd_gadget_on(struct cdns *cdns) -export_symbol_gpl(cdns3_drd_gadget_on); +export_symbol_gpl(cdns_drd_gadget_on); - * cdns3_drd_gadget_off - stop gadget. + * cdns_drd_gadget_off - stop gadget. -void cdns3_drd_gadget_off(struct cdns3 *cdns) +void cdns_drd_gadget_off(struct cdns *cdns) -export_symbol_gpl(cdns3_drd_gadget_off); +export_symbol_gpl(cdns_drd_gadget_off); - * cdns3_init_otg_mode - initialize drd controller + * cdns_init_otg_mode - initialize drd controller -static int cdns3_init_otg_mode(struct cdns3 *cdns) +static int cdns_init_otg_mode(struct cdns *cdns) - cdns3_otg_disable_irq(cdns); + cdns_otg_disable_irq(cdns); - ret = cdns3_set_mode(cdns, usb_dr_mode_otg); + ret = cdns_set_mode(cdns, usb_dr_mode_otg); - cdns3_otg_enable_irq(cdns); + cdns_otg_enable_irq(cdns); - * cdns3_drd_update_mode - initialize mode of operation + * cdns_drd_update_mode - initialize mode of operation -int cdns3_drd_update_mode(struct cdns3 *cdns) +int cdns_drd_update_mode(struct cdns *cdns) - ret = cdns3_set_mode(cdns, usb_dr_mode_peripheral); + ret = cdns_set_mode(cdns, usb_dr_mode_peripheral); - ret = cdns3_set_mode(cdns, usb_dr_mode_host); + ret = cdns_set_mode(cdns, usb_dr_mode_host); - ret = cdns3_init_otg_mode(cdns); + ret = cdns_init_otg_mode(cdns); -static irqreturn_t cdns3_drd_thread_irq(int irq, void *data) +static irqreturn_t cdns_drd_thread_irq(int irq, void *data) - struct cdns3 *cdns = data; + struct cdns *cdns = data; - cdns3_hw_role_switch(cdns); + cdns_hw_role_switch(cdns); - * cdns3_drd_irq - interrupt handler for otg events + * cdns_drd_irq - interrupt handler for otg events - * @irq: irq number for cdns3 core device - * @data: structure of cdns3 + * @irq: irq number for cdns core device + * @data: structure of cdns -static irqreturn_t cdns3_drd_irq(int irq, void *data) +static irqreturn_t cdns_drd_irq(int irq, void *data) - struct cdns3 *cdns = data; + struct cdns *cdns = data; - cdns3_get_id(cdns)); + cdns_get_id(cdns)); - cdns3_get_vbus(cdns)); + cdns_get_vbus(cdns)); -int cdns3_drd_init(struct cdns3 *cdns) +int cdns_drd_init(struct cdns *cdns) - cdns->otg_irq_regs = (struct cdns3_otg_irq_regs *) + cdns->otg_irq_regs = (struct cdns_otg_irq_regs *) - cdns->otg_irq_regs = (struct cdns3_otg_irq_regs *) + cdns->otg_irq_regs = (struct cdns_otg_irq_regs *) - cdns->otg_irq_regs = (struct cdns3_otg_irq_regs *) + cdns->otg_irq_regs = (struct cdns_otg_irq_regs *) - cdns3_drd_irq, - cdns3_drd_thread_irq, + cdns_drd_irq, + cdns_drd_thread_irq, -int cdns3_drd_exit(struct cdns3 *cdns) +int cdns_drd_exit(struct cdns *cdns) - cdns3_otg_disable_irq(cdns); + cdns_otg_disable_irq(cdns); diff --git a/drivers/usb/cdns3/drd.h b/drivers/usb/cdns3/drd.h --- a/drivers/usb/cdns3/drd.h +++ b/drivers/usb/cdns3/drd.h -struct cdns3_otg_common_regs { +struct cdns_otg_common_regs { -struct cdns3_otg_irq_regs { +struct cdns_otg_irq_regs { -bool cdns3_is_host(struct cdns3 *cdns); -bool cdns3_is_device(struct cdns3 *cdns); -int cdns3_get_id(struct cdns3 *cdns); -int cdns3_get_vbus(struct cdns3 *cdns); -int cdns3_drd_init(struct cdns3 *cdns); -int cdns3_drd_exit(struct cdns3 *cdns); -int cdns3_drd_update_mode(struct cdns3 *cdns); -int cdns3_drd_gadget_on(struct cdns3 *cdns); -void cdns3_drd_gadget_off(struct cdns3 *cdns); -int cdns3_drd_host_on(struct cdns3 *cdns); -void cdns3_drd_host_off(struct cdns3 *cdns); +bool cdns_is_host(struct cdns *cdns); +bool cdns_is_device(struct cdns *cdns); +int cdns_get_id(struct cdns *cdns); +int cdns_get_vbus(struct cdns *cdns); +int cdns_drd_init(struct cdns *cdns); +int cdns_drd_exit(struct cdns *cdns); +int cdns_drd_update_mode(struct cdns *cdns); +int cdns_drd_gadget_on(struct cdns *cdns); +void cdns_drd_gadget_off(struct cdns *cdns); +int cdns_drd_host_on(struct cdns *cdns); +void cdns_drd_host_off(struct cdns *cdns); diff --git a/drivers/usb/cdns3/gadget-export.h b/drivers/usb/cdns3/gadget-export.h --- a/drivers/usb/cdns3/gadget-export.h +++ b/drivers/usb/cdns3/gadget-export.h -int cdns3_gadget_init(struct cdns3 *cdns); +int cdns3_gadget_init(struct cdns *cdns); -static inline int cdns3_gadget_init(struct cdns3 *cdns) +static inline int cdns3_gadget_init(struct cdns *cdns) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c - struct cdns3 *cdns = dev_get_drvdata(priv_dev->dev); + struct cdns *cdns = dev_get_drvdata(priv_dev->dev); -static void cdns3_gadget_exit(struct cdns3 *cdns) +static void cdns3_gadget_exit(struct cdns *cdns) - cdns3_drd_gadget_off(cdns); + cdns_drd_gadget_off(cdns); -static int cdns3_gadget_start(struct cdns3 *cdns) +static int cdns3_gadget_start(struct cdns *cdns) -static int __cdns3_gadget_init(struct cdns3 *cdns) +static int __cdns3_gadget_init(struct cdns *cdns) - cdns3_drd_gadget_on(cdns); + cdns_drd_gadget_on(cdns); -static int cdns3_gadget_suspend(struct cdns3 *cdns, bool do_wakeup) +static int cdns3_gadget_suspend(struct cdns *cdns, bool do_wakeup) -static int cdns3_gadget_resume(struct cdns3 *cdns, bool hibernated) +static int cdns3_gadget_resume(struct cdns *cdns, bool hibernated) - * @cdns: cdns3 instance + * @cdns: cdns instance -int cdns3_gadget_init(struct cdns3 *cdns) +int cdns3_gadget_init(struct cdns *cdns) - struct cdns3_role_driver *rdrv; + struct cdns_role_driver *rdrv; - rdrv->state = cdns3_role_state_inactive; + rdrv->state = cdns_role_state_inactive; diff --git a/drivers/usb/cdns3/host-export.h b/drivers/usb/cdns3/host-export.h --- a/drivers/usb/cdns3/host-export.h +++ b/drivers/usb/cdns3/host-export.h -int cdns3_host_init(struct cdns3 *cdns); +int cdns_host_init(struct cdns *cdns); -static inline int cdns3_host_init(struct cdns3 *cdns) +static inline int cdns_host_init(struct cdns *cdns) -static inline void cdns3_host_exit(struct cdns3 *cdns) { } +static inline void cdns_host_exit(struct cdns *cdns) { } diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c --- a/drivers/usb/cdns3/host.c +++ b/drivers/usb/cdns3/host.c - * cadence usbss drd driver - host side + * cadence usbss and usbssp drd driver - host side -static int __cdns3_host_init(struct cdns3 *cdns) +static int __cdns_host_init(struct cdns *cdns) - cdns3_drd_host_on(cdns); + cdns_drd_host_on(cdns); - cdns3_xhci_resources_num); + cdns_xhci_resources_num); -static void cdns3_host_exit(struct cdns3 *cdns) +static void cdns_host_exit(struct cdns *cdns) - cdns3_drd_host_off(cdns); + cdns_drd_host_off(cdns); -int cdns3_host_init(struct cdns3 *cdns) +int cdns_host_init(struct cdns *cdns) - struct cdns3_role_driver *rdrv; + struct cdns_role_driver *rdrv; - rdrv->start = __cdns3_host_init; - rdrv->stop = cdns3_host_exit; - rdrv->state = cdns3_role_state_inactive; + rdrv->start = __cdns_host_init; + rdrv->stop = cdns_host_exit; + rdrv->state = cdns_role_state_inactive;
Universal Serial Bus
0b490046d8d7c035177ca4f5380f0c3275c4697d
pawel laszczak aswath govindraju a govindraju ti com
drivers
usb
cdns3
usb: cdns3: changed type of gadget_dev in cdns structure
patch changes the type for gadget_dev pointer in cdns structure from pointer to cdns3_device structure to void pointer. this filed is in reusable code and after this change it will be used to point to both cdns3_device or cdnsp_device objects.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduced new cadence usbssp drd driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h']
1
2
2
--- diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h --- a/drivers/usb/cdns3/core.h +++ b/drivers/usb/cdns3/core.h - * @gadget_dev: the child gadget device pointer for cdns3 core + * @gadget_dev: the child gadget device pointer - struct cdns3_device *gadget_dev; + void *gadget_dev;
Universal Serial Bus
ac5bca142759db36bbff2e0834c37fe956171233
pawel laszczak aswath govindraju a govindraju ti com
drivers
usb
cdns3
usb: cdnsp: device side header file for cdnsp driver
patch defines macros, registers and structures used by device side driver.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduced new cadence usbssp drd driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h']
1
1,463
0
--- diff --git a/drivers/usb/cdns3/cdnsp-gadget.h b/drivers/usb/cdns3/cdnsp-gadget.h --- /dev/null +++ b/drivers/usb/cdns3/cdnsp-gadget.h +/* spdx-license-identifier: gpl-2.0 */ +/* + * cadence cdnsp drd driver. + * + * copyright (c) 2020 cadence. + * + * author: pawel laszczak <pawell@cadence.com> + * + * code based on linux xhci driver. + * origin: copyright (c) 2008 intel corp. + */ +#ifndef __linux_cdnsp_gadget_h +#define __linux_cdnsp_gadget_h + +#include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/usb/gadget.h> +#include <linux/irq.h> + +/* max number slots - only 1 is allowed. */ +#define cdnsp_dev_max_slots 1 + +#define cdnsp_ep0_setup_size 512 + +/* one control and 15 for in and 15 for out endpoints. */ +#define cdnsp_endpoints_num 31 + +/* best effort service latency. */ +#define cdnsp_default_besl 0 + +/* device controller command default timeout value in us */ +#define cdnsp_cmd_timeout (15 * 1000) + +/* up to 16 ms to halt an device controller */ +#define cdnsp_max_halt_usec (16 * 1000) + +#define cdnsp_ctx_size 2112 + +/* + * controller register interface. + */ + +/** + * struct cdnsp_cap_regs - cdnsp registers. + * @hc_capbase: length of the capabilities register and controller + * version number + * @hcs_params1: hcsparams1 - structural parameters 1 + * @hcs_params2: hcsparams2 - structural parameters 2 + * @hcs_params3: hcsparams3 - structural parameters 3 + * @hcc_params: hccparams - capability parameters + * @db_off: dboff - doorbell array offset + * @run_regs_off: rtsoff - runtime register space offset + * @hcc_params2: hccparams2 capability parameters 2, + */ +struct cdnsp_cap_regs { + __le32 hc_capbase; + __le32 hcs_params1; + __le32 hcs_params2; + __le32 hcs_params3; + __le32 hcc_params; + __le32 db_off; + __le32 run_regs_off; + __le32 hcc_params2; + /* reserved up to (caplength - 0x1c) */ +}; + +/* hc_capbase bitmasks. */ +/* bits 7:0 - how long is the capabilities register. */ +#define hc_length(p) (((p) >> 00) & genmask(7, 0)) +/* bits 31:16 */ +#define hc_version(p) (((p) >> 16) & genmask(15, 1)) + +/* hcsparams1 - hcs_params1 - bitmasks */ +/* bits 0:7, max device endpoints */ +#define hcs_endpoints_mask genmask(7, 0) +#define hcs_endpoints(p) (((p) & hcs_endpoints_mask) >> 0) + +/* hccparams offset from pci base address */ +#define hcc_params_offset 0x10 + +/* hccparams - hcc_params - bitmasks */ +/* 1: device controller can use 64-bit address pointers. */ +#define hcc_64bit_addr(p) ((p) & bit(0)) +/* 1: device controller uses 64-byte device context structures. */ +#define hcc_64byte_context(p) ((p) & bit(2)) +/* max size for primary stream arrays - 2^(n+1), where n is bits 12:15. */ +#define hcc_max_psa(p) ((((p) >> 12) & 0xf) + 1) +/* extended capabilities pointer from pci base. */ +#define hcc_ext_caps(p) (((p) & genmask(31, 16)) >> 16) + +#define ctx_size(_hcc) (hcc_64byte_context(_hcc) ? 64 : 32) + +/* db_off bitmask - bits 0:1 reserved. */ +#define dboff_mask genmask(31, 2) + +/* run_regs_off bitmask - bits 0:4 reserved. */ +#define rtsoff_mask genmask(31, 5) + +/** + * struct cdnsp_op_regs - device controller operational registers. + * @command: usbcmd - controller command register. + * @status: usbsts - controller status register. + * @page_size: this indicates the page size that the device controller supports. + * if bit n is set, the controller supports a page size of 2^(n+12), + * up to a 128mb page size. 4k is the minimum page size. + * @dnctrl: dnctrl - device notification control register. + * @cmd_ring: crp - 64-bit command ring pointer. + * @dcbaa_ptr: dcbaap - 64-bit device context base address array pointer. + * @config_reg: config - configure register + * @port_reg_base: portscn - base address for port status and control + * each port has a port status and control register, + * followed by a port power management status and control + * register, a port link info register, and a reserved + * register. + */ +struct cdnsp_op_regs { + __le32 command; + __le32 status; + __le32 page_size; + __le32 reserved1; + __le32 reserved2; + __le32 dnctrl; + __le64 cmd_ring; + /* rsvd: offset 0x20-2f. */ + __le32 reserved3[4]; + __le64 dcbaa_ptr; + __le32 config_reg; + /* rsvd: offset 0x3c-3ff. */ + __le32 reserved4[241]; + /* port 1 registers, which serve as a base address for other ports. */ + __le32 port_reg_base; +}; + +/* number of registers per port. */ +#define num_port_regs 4 + +/** + * struct cdnsp_port_regs - port registers. + * @portsc: portsc - port status and control register. + * @portpmsc: portpmsc - port power managements status and control register. + * @portli: portli - port link info register. + */ +struct cdnsp_port_regs { + __le32 portsc; + __le32 portpmsc; + __le32 portli; + __le32 reserved; +}; + +/* + * these bits are read only (ro) and should be saved and written to the + * registers: 0 (connect status) and 10:13 (port speed). + * these bits are also sticky - meaning they're in the aux well and they aren't + * changed by a hot and warm. + */ +#define cdnsp_port_ro (port_connect | dev_speed_mask) + +/* + * these bits are rw; writing a 0 clears the bit, writing a 1 sets the bit: + * bits 5:8 (link state), 25:26 ("wake on" enable state) + */ +#define cdnsp_port_rws (port_pls_mask | port_wkconn_e | port_wkdisc_e) + +/* + * these bits are rw; writing a 1 clears the bit, writing a 0 has no effect: + * bits 1 (port enable/disable), 17 ( connect changed), + * 21 (port reset changed) , 22 (port link state change), + */ +#define cdnsp_port_rw1cs (port_ped | port_csc | port_rc | port_plc) + +/* usbcmd - usb command - bitmasks. */ +/* run/stop, controller execution - do not write unless controller is halted.*/ +#define cmd_r_s bit(0) +/* + * reset device controller - resets internal controller state machine and all + * registers (except pci config regs). + */ +#define cmd_reset bit(1) +/* event interrupt enable - a '1' allows interrupts from the controller. */ +#define cmd_inte bit(2) +/* + * device system error interrupt enable - get out-of-band signal for + * controller errors. + */ +#define cmd_dseie bit(3) +/* device controller save/restore state. */ +#define cmd_css bit(8) +#define cmd_crs bit(9) +/* + * enable wrap event - '1' means device controller generates an event + * when mfindex wraps. + */ +#define cmd_ewe bit(10) +/* 1: device enabled */ +#define cmd_deven bit(17) +/* bits 18:31 are reserved (and should be preserved on writes). */ + +/* command register values to disable interrupts. */ +#define cdnsp_irqs (cmd_inte | cmd_dseie | cmd_ewe) + +/* usbsts - usb status - bitmasks */ +/* controller not running - set to 1 when run/stop bit is cleared. */ +#define sts_halt bit(0) +/* + * serious error, e.g. pci parity error. the controller will clear + * the run/stop bit. + */ +#define sts_fatal bit(2) +/* event interrupt - clear this prior to clearing any ip flags in ir set.*/ +#define sts_eint bit(3) +/* port change detect */ +#define sts_pcd bit(4) +/* save state status - '1' means device controller is saving state. */ +#define sts_sss bit(8) +/* restore state status - '1' means controllers is restoring state. */ +#define sts_rss bit(9) +/* 1: save or restore error */ +#define sts_sre bit(10) +/* 1: device not ready to accept doorbell or op reg writes after reset. */ +#define sts_cnr bit(11) +/* 1: internal device controller error.*/ +#define sts_hce bit(12) + +/* crcr - command ring control register - cmd_ring bitmasks. */ +/* bit 0 is the command ring cycle state. */ +#define cmd_ring_cs bit(0) +/* stop ring immediately - abort the currently executing command. */ +#define cmd_ring_abort bit(2) +/* + * command ring busy. + * set when doorbell register is written with db for command and cleared when + * the controller reached end of cr. + */ +#define cmd_ring_busy(p) ((p) & bit(4)) +/* 1: command ring is running */ +#define cmd_ring_running bit(3) +/* command ring pointer - bit mask for the lower 32 bits. */ +#define cmd_ring_rsvd_bits genmask(5, 0) + +/* config - configure register - config_reg bitmasks. */ +/* bits 0:7 - maximum number of device slots enabled. */ +#define max_devs genmask(7, 0) +/* bit 8: u3 entry enabled, assert plc when controller enters u3. */ +#define config_u3e bit(8) + +/* portsc - port status and control register - port_reg_base bitmasks */ +/* 1: device connected. */ +#define port_connect bit(0) +/* 1: port enabled. */ +#define port_ped bit(1) +/* 1: port reset signaling asserted. */ +#define port_reset bit(4) +/* + * port link state - bits 5:8 + * a read gives the current link pm state of the port, + * a write with link state write strobe sets the link state. + */ +#define port_pls_mask genmask(8, 5) +#define xdev_u0 (0x0 << 5) +#define xdev_u1 (0x1 << 5) +#define xdev_u2 (0x2 << 5) +#define xdev_u3 (0x3 << 5) +#define xdev_disabled (0x4 << 5) +#define xdev_rxdetect (0x5 << 5) +#define xdev_inactive (0x6 << 5) +#define xdev_polling (0x7 << 5) +#define xdev_recovery (0x8 << 5) +#define xdev_hot_reset (0x9 << 5) +#define xdev_comp_mode (0xa << 5) +#define xdev_test_mode (0xb << 5) +#define xdev_resume (0xf << 5) +/* 1: port has power. */ +#define port_power bit(9) +/* + * bits 10:13 indicate device speed: + * 0 - undefined speed - port hasn't be initialized by a reset yet + * 1 - full speed + * 2 - reserved (low speed not supported + * 3 - high speed + * 4 - super speed + * 5 - super speed + * 6-15 reserved + */ +#define dev_speed_mask genmask(13, 10) +#define xdev_fs (0x1 << 10) +#define xdev_hs (0x3 << 10) +#define xdev_ss (0x4 << 10) +#define xdev_ssp (0x5 << 10) +#define dev_undefspeed(p) (((p) & dev_speed_mask) == (0x0 << 10)) +#define dev_fullspeed(p) (((p) & dev_speed_mask) == xdev_fs) +#define dev_highspeed(p) (((p) & dev_speed_mask) == xdev_hs) +#define dev_superspeed(p) (((p) & dev_speed_mask) == xdev_ss) +#define dev_superspeedplus(p) (((p) & dev_speed_mask) == xdev_ssp) +#define dev_superspeed_any(p) (((p) & dev_speed_mask) >= xdev_ss) +#define dev_port_speed(p) (((p) >> 10) & 0x0f) +/* port link state write strobe - set this when changing link state */ +#define port_link_strobe bit(16) +/* 1: connect status change */ +#define port_csc bit(17) +/* 1: warm reset for a usb 3.0 device is done. */ +#define port_wrc bit(19) +/* 1: reset change - 1 to 0 transition of port_reset */ +#define port_rc bit(21) +/* + * port link status change - set on some port link state transitions: + * transition reason + * ---------------------------------------------------------------------------- + * - u3 to resume wakeup signaling from a device + * - resume to recovery to u0 usb 3.0 device resume + * - resume to u0 usb 2.0 device resume + * - u3 to recovery to u0 software resume of usb 3.0 device complete + * - u3 to u0 software resume of usb 2.0 device complete + * - u2 to u0 l1 resume of usb 2.1 device complete + * - u0 to u0 l1 entry rejection by usb 2.1 device + * - u0 to disabled l1 entry error with usb 2.1 device + * - any state to inactive error on usb 3.0 port + */ +#define port_plc bit(22) +/* port configure error change - port failed to configure its link partner. */ +#define port_cec bit(23) +/* wake on connect (enable). */ +#define port_wkconn_e bit(25) +/* wake on disconnect (enable). */ +#define port_wkdisc_e bit(26) +/* indicates if warm reset is being received. */ +#define port_wr bit(31) + +#define port_change_bits (port_csc | port_wrc | port_rc | port_plc | port_cec) + +/* portpmscusb3 - port power management status and control - bitmasks. */ +/* enables u1 entry. */ +#define port_u1_timeout_mask genmask(7, 0) +#define port_u1_timeout(p) ((p) & port_u1_timeout_mask) +/* enables u2 entry .*/ +#define port_u2_timeout_mask genmask(14, 8) +#define port_u2_timeout(p) (((p) << 8) & port_u2_timeout_mask) + +/* portpmscusb2 - port power management status and control - bitmasks. */ +#define port_l1s_mask genmask(2, 0) +#define port_l1s(p) ((p) & port_l1s_mask) +#define port_l1s_ack port_l1s(1) +#define port_l1s_nyet port_l1s(2) +#define port_l1s_stall port_l1s(3) +#define port_l1s_timeout port_l1s(4) +/* remote wake enable. */ +#define port_rwe bit(3) +/* best effort service latency (besl). */ +#define port_besl(p) (((p) << 4) & genmask(7, 4)) +/* hardware lpm enable (hle). */ +#define port_hle bit(16) +/* received best effort service latency (besl). */ +#define port_rrbesl(p) (((p) & genmask(20, 17)) >> 17) +/* port test control. */ +#define port_test_mode_mask genmask(31, 28) +#define port_test_mode(p) (((p) << 28) & port_test_mode_mask) + +/** + * struct cdnsp_intr_reg - interrupt register set. + * @irq_pending: iman - interrupt management register. used to enable + * interrupts and check for pending interrupts. + * @irq_control: imod - interrupt moderation register. + * used to throttle interrupts. + * @erst_size: number of segments in the event ring segment table (erst). + * @erst_base: erst base address. + * @erst_dequeue: event ring dequeue pointer. + * + * each interrupter (defined by a msi-x vector) has an event ring and an event + * ring segment table (erst) associated with it. the event ring is comprised of + * multiple segments of the same size. the controller places events on the ring + * and "updates the cycle bit in the trbs to indicate to software the current + * position of the enqueue pointer." the driver processes those events and + * updates the dequeue pointer. + */ +struct cdnsp_intr_reg { + __le32 irq_pending; + __le32 irq_control; + __le32 erst_size; + __le32 rsvd; + __le64 erst_base; + __le64 erst_dequeue; +}; + +/* iman - interrupt management register - irq_pending bitmasks l. */ +#define iman_ie bit(1) +#define iman_ip bit(0) +/* bits 2:31 need to be preserved */ +#define iman_ie_set(p) (((p) & iman_ie) | 0x2) +#define iman_ie_clear(p) (((p) & iman_ie) & ~(0x2)) + +/* imod - interrupter moderation register - irq_control bitmasks. */ +/* + * minimum interval between interrupts (in 250ns intervals). the interval + * between interrupts will be longer if there are no events on the event ring. + * default is 4000 (1 ms). + */ +#define imod_interval_mask genmask(15, 0) +/* counter used to count down the time to the next interrupt - hw use only */ +#define imod_counter_mask genmask(31, 16) +#define imod_default_interval 0 + +/* erst_size bitmasks. */ +/* preserve bits 16:31 of erst_size. */ +#define erst_size_mask genmask(31, 16) + +/* erst_dequeue bitmasks. */ +/* + * dequeue erst segment index (desi) - segment number (or alias) + * where the current dequeue pointer lies. this is an optional hw hint. + */ +#define erst_desi_mask genmask(2, 0) +/* event handler busy (ehb) - is the event ring scheduled to be serviced. */ +#define erst_ehb bit(3) +#define erst_ptr_mask genmask(3, 0) + +/** + * struct cdnsp_run_regs + * @microframe_index: mfindex - current microframe number. + * @ir_set: array of interrupter registers. + * + * device controller runtime registers: + * "software should read and write these registers using only dword (32 bit) + * or larger accesses" + */ +struct cdnsp_run_regs { + __le32 microframe_index; + __le32 rsvd[7]; + struct cdnsp_intr_reg ir_set[128]; +}; + +/** + * usb2.0 port peripheral configuration registers. + * @ext_cap: header register for extended capability. + * @port_reg1: timer configuration register. + * @port_reg2: timer configuration register. + * @port_reg3: timer configuration register. + * @port_reg4: timer configuration register. + * @port_reg5: timer configuration register. + * @port_reg6: chicken bits for usb20ppp. + */ +struct cdnsp_20port_cap { + __le32 ext_cap; + __le32 port_reg1; + __le32 port_reg2; + __le32 port_reg3; + __le32 port_reg4; + __le32 port_reg5; + __le32 port_reg6; +}; + +/* extended capability register fields */ +#define ext_caps_id(p) (((p) >> 0) & genmask(7, 0)) +#define ext_caps_next(p) (((p) >> 8) & genmask(7, 0)) +/* extended capability ids - id 0 reserved */ +#define ext_caps_protocol 2 + +/* usb 2.0 port peripheral configuration extended capability */ +#define ext_cap_cfg_dev_20port_cap_id 0xc1 +/* + * setting this bit to '1' enables automatic wakeup from l1 state on transfer + * trb prepared when usbssp operates in usb2.0 mode. + */ +#define port_reg6_l1_l0_hw_en bit(1) +/* + * setting this bit to '1' forces full speed when usbssp operates in usb2.0 + * mode (disables high speed). + */ +#define port_reg6_force_fs bit(0) + +/** + * usb3.x port peripheral configuration registers. + * @ext_cap: header register for extended capability. + * @mode_addr: miscellaneous 3xport operation mode configuration register. + * @mode_2: 3x port control register 2. + */ +struct cdnsp_3xport_cap { + __le32 ext_cap; + __le32 mode_addr; + __le32 reserved[52]; + __le32 mode_2; +}; + +/* extended capability header for 3xport configuration registers. */ +#define d_xec_cfg_3xport_cap 0xc0 +#define cfg_3xport_ssp_support bit(31) +#define cfg_3xport_u1_pipe_clk_gate_en bit(0) + +/* revision extended capability id */ +#define rtl_rev_cap 0xc4 +#define rtl_rev_cap_rx_buff_cmd_size bitmask(31, 24) +#define rtl_rev_cap_rx_buff_size bitmask(15, 0) +#define rtl_rev_cap_tx_buff_cmd_size bitmask(31, 24) +#define rtl_rev_cap_tx_buff_size bitmask(15, 0) + +#define cdnsp_ver_1 0x00000000 +#define cdnsp_ver_2 0x10000000 + +#define cdnsp_if_ep_exist(pdev, ep_num, dir) ((pdev)->rev_cap.ep_supported & \ + (bit(ep_num) << ((dir) ? 0 : 16))) + +/** + * struct cdnsp_rev_cap - controller capabilities . + * @ext_cap: header for rtl revision extended capability. + * @rtl_revision: rtl revision. + * @rx_buff_size: rx buffer sizes. + * @tx_buff_size: tx buffer sizes. + * @ep_supported: supported endpoints. + * @ctrl_revision: controller revision id. + */ +struct cdnsp_rev_cap { + __le32 ext_cap; + __le32 rtl_revision; + __le32 rx_buff_size; + __le32 tx_buff_size; + __le32 ep_supported; + __le32 ctrl_revision; +}; + +/* usb2.0 port peripheral configuration registers. */ +#define d_xec_pre_regs_cap 0xc8 +#define reg_chicken_bits_2_offset 0x48 +#define chicken_xdma_2_tp_cache_dis bit(28) + +/* xbuf extended capability id. */ +#define xbuf_cap_id 0xcb +#define xbuf_rx_tag_mask_0_offset 0x1c +#define xbuf_rx_tag_mask_1_offset 0x24 +#define xbuf_tx_cmd_offset 0x2c + +/** + * struct cdnsp_doorbell_array. + * @cmd_db: command ring doorbell register. + * @ep_db: endpoint ring doorbell register. + * bits 0 - 7: endpoint target. + * bits 8 - 15: rsvdz. + * bits 16 - 31: stream id. + */ +struct cdnsp_doorbell_array { + __le32 cmd_db; + __le32 ep_db; +}; + +#define db_value(ep, stream) ((((ep) + 1) & 0xff) | ((stream) << 16)) +#define db_value_ep0_out(ep, stream) ((ep) & 0xff) +#define db_value_cmd 0x00000000 + +/** + * struct cdnsp_container_ctx. + * @type: type of context. used to calculated offsets to contained contexts. + * @size: size of the context data. + * @ctx_size: context data structure size - 64 or 32 bits. + * @dma: dma address of the bytes. + * @bytes: the raw context data given to hw. + * + * represents either a device or input context. holds a pointer to the raw + * memory used for the context (bytes) and dma address of it (dma). + */ +struct cdnsp_container_ctx { + unsigned int type; +#define cdnsp_ctx_type_device 0x1 +#define cdnsp_ctx_type_input 0x2 + int size; + int ctx_size; + dma_addr_t dma; + u8 *bytes; +}; + +/** + * struct cdnsp_slot_ctx + * @dev_info: device speed, and last valid endpoint. + * @dev_port: device port number that is needed to access the usb device. + * @int_target: interrupter target number. + * @dev_state: slot state and device address. + * + * slot context - this assumes the controller uses 32-byte context + * structures. if the controller uses 64-byte contexts, there is an additional + * 32 bytes reserved at the end of the slot context for controller internal use. + */ +struct cdnsp_slot_ctx { + __le32 dev_info; + __le32 dev_port; + __le32 int_target; + __le32 dev_state; + /* offset 0x10 to 0x1f reserved for controller internal use. */ + __le32 reserved[4]; +}; + +/* bits 20:23 in the slot context are the speed for the device. */ +#define slot_speed_fs (xdev_fs << 10) +#define slot_speed_hs (xdev_hs << 10) +#define slot_speed_ss (xdev_ss << 10) +#define slot_speed_ssp (xdev_ssp << 10) + +/* dev_info bitmasks. */ +/* device speed - values defined by portsc device speed field - 20:23. */ +#define dev_speed genmask(23, 20) +#define get_dev_speed(n) (((n) & dev_speed) >> 20) +/* index of the last valid endpoint context in this device context - 27:31. */ +#define last_ctx_mask genmask(31, 27) +#define last_ctx(p) ((p) << 27) +#define last_ctx_to_ep_num(p) (((p) >> 27) - 1) +#define slot_flag bit(0) +#define ep0_flag bit(1) + +/* dev_port bitmasks */ +/* device port number that is needed to access the usb device. */ +#define dev_port(p) (((p) & 0xff) << 16) + +/* dev_state bitmasks */ +/* usb device address - assigned by the controller. */ +#define dev_addr_mask genmask(7, 0) +/* slot state */ +#define slot_state genmask(31, 27) +#define get_slot_state(p) (((p) & slot_state) >> 27) + +#define slot_state_disabled 0 +#define slot_state_enabled slot_state_disabled +#define slot_state_default 1 +#define slot_state_addressed 2 +#define slot_state_configured 3 + +/** + * struct cdnsp_ep_ctx. + * @ep_info: endpoint state, streams, mult, and interval information. + * @ep_info2: information on endpoint type, max packet size, max burst size, + * error count, and whether the controller will force an event for + * all transactions. + * @deq: 64-bit ring dequeue pointer address. if the endpoint only + * defines one stream, this points to the endpoint transfer ring. + * otherwise, it points to a stream context array, which has a + * ring pointer for each flow. + * @tx_info: average trb lengths for the endpoint ring and + * max payload within an endpoint service interval time (esit). + * + * endpoint context - this assumes the controller uses 32-byte context + * structures. if the controller uses 64-byte contexts, there is an additional + * 32 bytes reserved at the end of the endpoint context for controller internal + * use. + */ +struct cdnsp_ep_ctx { + __le32 ep_info; + __le32 ep_info2; + __le64 deq; + __le32 tx_info; + /* offset 0x14 - 0x1f reserved for controller internal use. */ + __le32 reserved[3]; +}; + +/* ep_info bitmasks. */ +/* + * endpoint state - bits 0:2: + * 0 - disabled + * 1 - running + * 2 - halted due to halt condition + * 3 - stopped + * 4 - trb error + * 5-7 - reserved + */ +#define ep_state_mask genmask(3, 0) +#define ep_state_disabled 0 +#define ep_state_running 1 +#define ep_state_halted 2 +#define ep_state_stopped 3 +#define ep_state_error 4 +#define get_ep_ctx_state(ctx) (le32_to_cpu((ctx)->ep_info) & ep_state_mask) + +/* mult - max number of burst within an interval, in ep companion desc. */ +#define ep_mult(p) (((p) << 8) & genmask(9, 8)) +#define ctx_to_ep_mult(p) (((p) & genmask(9, 8)) >> 8) +/* bits 10:14 are max primary streams. */ +/* bit 15 is linear stream array. */ +/* interval - period between requests to an endpoint - 125u increments. */ +#define ep_interval(p) (((p) << 16) & genmask(23, 16)) +#define ep_interval_to_uframes(p) (1 << (((p) & genmask(23, 16)) >> 16)) +#define ctx_to_ep_interval(p) (((p) & genmask(23, 16)) >> 16) +#define ep_maxpstreams_mask genmask(14, 10) +#define ep_maxpstreams(p) (((p) << 10) & ep_maxpstreams_mask) +#define ctx_to_ep_maxpstreams(p) (((p) & ep_maxpstreams_mask) >> 10) +/* endpoint is set up with a linear stream array (vs. secondary stream array) */ +#define ep_has_lsa bit(15) + +/* ep_info2 bitmasks */ +#define error_count(p) (((p) & 0x3) << 1) +#define ctx_to_ep_type(p) (((p) >> 3) & 0x7) +#define ep_type(p) ((p) << 3) +#define isoc_out_ep 1 +#define bulk_out_ep 2 +#define int_out_ep 3 +#define ctrl_ep 4 +#define isoc_in_ep 5 +#define bulk_in_ep 6 +#define int_in_ep 7 +/* bit 6 reserved. */ +/* bit 7 is device initiate disable - for disabling stream selection. */ +#define max_burst(p) (((p) << 8) & genmask(15, 8)) +#define ctx_to_max_burst(p) (((p) & genmask(15, 8)) >> 8) +#define max_packet(p) (((p) << 16) & genmask(31, 16)) +#define max_packet_mask genmask(31, 16) +#define max_packet_decoded(p) (((p) & genmask(31, 16)) >> 16) + +/* tx_info bitmasks. */ +#define ep_avg_trb_length(p) ((p) & genmask(15, 0)) +#define ep_max_esit_payload_lo(p) (((p) << 16) & genmask(31, 16)) +#define ep_max_esit_payload_hi(p) ((((p) & genmask(23, 16)) >> 16) << 24) +#define ctx_to_max_esit_payload_lo(p) (((p) & genmask(31, 16)) >> 16) +#define ctx_to_max_esit_payload_hi(p) (((p) & genmask(31, 24)) >> 24) + +/* deq bitmasks. */ +#define ep_ctx_cycle_mask bit(0) +#define ctx_deq_mask (~0xfl) + +/** + * struct cdnsp_input_control_context + * input control context; + * + * @drop_context: set the bit of the endpoint context you want to disable. + * @add_context: set the bit of the endpoint context you want to enable. + */ +struct cdnsp_input_control_ctx { + __le32 drop_flags; + __le32 add_flags; + __le32 rsvd2[6]; +}; + +/** + * represents everything that is needed to issue a command on the command ring. + * + * @in_ctx: pointer to input context structure. + * @status: command completion code for last command. + * @command_trb: pointer to command trb. + */ +struct cdnsp_command { + /* input context for changing device state. */ + struct cdnsp_container_ctx *in_ctx; + u32 status; + union cdnsp_trb *command_trb; +}; + +/** + * stream context structure. + * + * @stream_ring: 64-bit stream ring address, cycle state, and stream type. + * @reserved: offset 0x14 - 0x1f reserved for controller internal use. + */ +struct cdnsp_stream_ctx { + __le64 stream_ring; + __le32 reserved[2]; +}; + +/* stream context types - bits 3:1 of stream ctx deq ptr. */ +#define sct_for_ctx(p) (((p) << 1) & genmask(3, 1)) +/* secondary stream array type, dequeue pointer is to a transfer ring. */ +#define sct_sec_tr 0 +/* primary stream array type, dequeue pointer is to a transfer ring. */ +#define sct_pri_tr 1 + +/** + * struct cdnsp_stream_info: representing everything that is needed to + * supports stream capable endpoints. + * @stream_rings: array of pointers containing transfer rings for all + * supported streams. + * @num_streams: number of streams, including stream 0. + * @stream_ctx_array: the stream context array may be bigger than the number + * of streams the driver asked for. + * @num_stream_ctxs: number of streams. + * @ctx_array_dma: dma address of context stream array. + * @trb_address_map: for mapping physical trb addresses to segments in + * stream rings. + * @td_count: number of tds associated with endpoint. + * @first_prime_det: first prime packet detected. + * @drbls_count: number of allowed doorbells. + */ +struct cdnsp_stream_info { + struct cdnsp_ring **stream_rings; + unsigned int num_streams; + struct cdnsp_stream_ctx *stream_ctx_array; + unsigned int num_stream_ctxs; + dma_addr_t ctx_array_dma; + struct radix_tree_root trb_address_map; + int td_count; + u8 first_prime_det; +#define stream_drbl_fifo_depth 2 + u8 drbls_count; +}; + +#define stream_log_streams 4 +#define stream_num_streams bit(stream_log_streams) + +#if stream_log_streams > 16 && stream_log_streams < 1 +#error "not suupported stream value" +#endif + +/** + * struct cdnsp_ep - extended device side representation of usb endpoint. + * @endpoint: usb endpoint + * @pending_req_list: list of requests queuing on transfer ring. + * @pdev: device associated with this endpoint. + * @number: endpoint number (1 - 15). + * idx: the device context index (dci). + * interval: interval between packets used for isoc endpoint. + * @name: a human readable name e.g. ep1out. + * @direction: endpoint direction. + * @buffering: number of on-chip buffers related to endpoint. + * @buffering_period; number of on-chip buffers related to periodic endpoint. + * @in_ctx: pointer to input endpoint context structure. + * @out_ctx: pointer to output endpoint context structure. + * @ring: pointer to transfer ring. + * @stream_info: hold stream information. + * @ep_state: current state of endpoint. + * @skip: sometimes the controller can not process isochronous endpoint ring + * quickly enough, and it will miss some isoc tds on the ring and + * generate missed service error event. + * set skip flag when receive a missed service error event and + * process the missed tds on the endpoint ring. + */ +struct cdnsp_ep { + struct usb_ep endpoint; + struct list_head pending_list; + struct cdnsp_device *pdev; + u8 number; + u8 idx; + u32 interval; + char name[20]; + u8 direction; + u8 buffering; + u8 buffering_period; + struct cdnsp_ep_ctx *in_ctx; + struct cdnsp_ep_ctx *out_ctx; + struct cdnsp_ring *ring; + struct cdnsp_stream_info stream_info; + unsigned int ep_state; +#define ep_enabled bit(0) +#define ep_dis_in_rrogress bit(1) +#define ep_halted bit(2) +#define ep_stopped bit(3) +#define ep_wedge bit(4) +#define ep0_halted_status bit(5) +#define ep_has_streams bit(6) + + bool skip; +}; + +/** + * struct cdnsp_device_context_array + * @dev_context_ptr: array of 64-bit dma addresses for device contexts. + * @dma: dma address for device contexts structure. + */ +struct cdnsp_device_context_array { + __le64 dev_context_ptrs[cdnsp_dev_max_slots + 1]; + dma_addr_t dma; +}; + +/** + * struct cdnsp_transfer_event. + * @buffer: 64-bit buffer address, or immediate data. + * @transfer_len: data length transferred. + * @flags: field is interpreted differently based on the type of trb. + */ +struct cdnsp_transfer_event { + __le64 buffer; + __le32 transfer_len; + __le32 flags; +}; + +/* invalidate event after disabling endpoint. */ +#define trb_event_invalidate 8 + +/* transfer event trb length bit mask. */ +/* bits 0:23 */ +#define event_trb_len(p) ((p) & genmask(23, 0)) +/* completion code - only applicable for some types of trbs */ +#define comp_code_mask (0xff << 24) +#define get_comp_code(p) (((p) & comp_code_mask) >> 24) +#define comp_invalid 0 +#define comp_success 1 +#define comp_data_buffer_error 2 +#define comp_babble_detected_error 3 +#define comp_trb_error 5 +#define comp_resource_error 7 +#define comp_no_slots_available_error 9 +#define comp_invalid_stream_type_error 10 +#define comp_slot_not_enabled_error 11 +#define comp_endpoint_not_enabled_error 12 +#define comp_short_packet 13 +#define comp_ring_underrun 14 +#define comp_ring_overrun 15 +#define comp_vf_event_ring_full_error 16 +#define comp_parameter_error 17 +#define comp_context_state_error 19 +#define comp_event_ring_full_error 21 +#define comp_incompatible_device_error 22 +#define comp_missed_service_error 23 +#define comp_command_ring_stopped 24 +#define comp_command_aborted 25 +#define comp_stopped 26 +#define comp_stopped_length_invalid 27 +#define comp_stopped_short_packet 28 +#define comp_max_exit_latency_too_large_error 29 +#define comp_isoch_buffer_overrun 31 +#define comp_event_lost_error 32 +#define comp_undefined_error 33 +#define comp_invalid_stream_id_error 34 + +/*transfer event nrdy bit fields */ +#define trb_to_dev_stream(p) ((p) & genmask(16, 0)) +#define trb_to_host_stream(p) ((p) & genmask(16, 0)) +#define stream_prime_ack 0xfffe +#define stream_rejected 0xffff + +/** transfer event bit fields **/ +#define trb_to_ep_id(p) (((p) & genmask(20, 16)) >> 16) + +/** + * struct cdnsp_link_trb + * @segment_ptr: 64-bit segment pointer. + * @intr_target: interrupter target. + * @control: flags. + */ +struct cdnsp_link_trb { + __le64 segment_ptr; + __le32 intr_target; + __le32 control; +}; + +/* control bitfields */ +#define link_toggle bit(1) + +/** + * struct cdnsp_event_cmd - command completion event trb. + * cmd_trb: pointer to command trb, or the value passed by the event data trb + * status: command completion parameters and error code. + * flags: flags. + */ +struct cdnsp_event_cmd { + __le64 cmd_trb; + __le32 status; + __le32 flags; +}; + +/* flags bitmasks */ + +/* address device - disable setaddress. */ +#define trb_bsr bit(9) + +/* configure endpoint - deconfigure. */ +#define trb_dc bit(9) + +/* force header */ +#define trb_fh_to_packet_type(p) ((p) & genmask(4, 0)) +#define trb_fh_tr_packet 0x4 +#define trb_fh_to_device_address(p) (((p) << 25) & genmask(31, 25)) +#define trb_fh_tr_packet_dev_not 0x6 +#define trb_fh_to_not_type(p) (((p) << 4) & genmask(7, 4)) +#define trb_fh_tr_packet_function_wake 0x1 +#define trb_fh_to_interface(p) (((p) << 8) & genmask(15, 8)) + +enum cdnsp_setup_dev { + setup_context_only, + setup_context_address, +}; + +/* bits 24:31 are the slot id. */ +#define trb_to_slot_id(p) (((p) & genmask(31, 24)) >> 24) +#define slot_id_for_trb(p) (((p) << 24) & genmask(31, 24)) + +/* stop endpoint trb - ep_index to endpoint id for this trb. */ +#define trb_to_ep_index(p) (((p) >> 16) & 0x1f) + +#define ep_id_for_trb(p) ((((p) + 1) << 16) & genmask(20, 16)) + +#define suspend_port_for_trb(p) (((p) & 1) << 23) +#define trb_to_suspend_port(p) (((p) >> 23) & 0x1) +#define last_ep_index 30 + +/* set tr dequeue pointer command trb fields. */ +#define trb_to_stream_id(p) ((((p) & genmask(31, 16)) >> 16)) +#define stream_id_for_trb(p) ((((p)) << 16) & genmask(31, 16)) +#define sct_for_trb(p) (((p) << 1) & 0x7) + +/* link trb specific fields. */ +#define trb_tc bit(1) + +/* port status change event trb fields. */ +/* port id - bits 31:24. */ +#define get_port_id(p) (((p) & genmask(31, 24)) >> 24) +#define set_port_id(p) (((p) << 24) & genmask(31, 24)) +#define event_data bit(2) + +/* normal trb fields. */ +/* transfer_len bitmasks - bits 0:16. */ +#define trb_len(p) ((p) & genmask(16, 0)) +/* td size, packets remaining in this td, bits 21:17 (5 bits, so max 31). */ +#define trb_td_size(p) (min((p), (u32)31) << 17) +#define get_td_size(p) (((p) & genmask(21, 17)) >> 17) +/* + * controller uses the td_size field for tbc if extended tbc + * is enabled (ete). + */ +#define trb_td_size_tbc(p) (min((p), (u32)31) << 17) +/* interrupter target - which msi-x vector to target the completion event at. */ +#define trb_intr_target(p) (((p) << 22) & genmask(31, 22)) +#define get_intr_target(p) (((p) & genmask(31, 22)) >> 22) +/* + * total burst count field, rsvdz on controller with extended tbc + * enabled (ete). + */ +#define trb_tbc(p) (((p) & 0x3) << 7) +#define trb_tlbpc(p) (((p) & 0xf) << 16) + +/* cycle bit - indicates trb ownership by driver or driver.*/ +#define trb_cycle bit(0) +/* + * force next event data trb to be evaluated before task switch. + * used to pass os data back after a td completes. + */ +#define trb_ent bit(1) +/* interrupt on short packet. */ +#define trb_isp bit(2) +/* set pcie no snoop attribute. */ +#define trb_no_snoop bit(3) +/* chain multiple trbs into a td. */ +#define trb_chain bit(4) +/* interrupt on completion. */ +#define trb_ioc bit(5) +/* the buffer pointer contains immediate data. */ +#define trb_idt bit(6) +/* 0 - nrdy during data stage, 1 - nrdy during status stage (only control). */ +#define trb_stat bit(7) +/* block event interrupt. */ +#define trb_bei bit(9) + +/* control transfer trb specific fields. */ +#define trb_dir_in bit(16) + +/* trb bit mask in data stage trb */ +#define trb_setupid_bitmask genmask(9, 8) +#define trb_setupid(p) ((p) << 8) +#define trb_setupid_to_type(p) (((p) & trb_setupid_bitmask) >> 8) + +#define trb_setup_speedid_usb3 0x1 +#define trb_setup_speedid_usb2 0x0 +#define trb_setup_speedid(p) ((p) & (1 << 7)) + +#define trb_setupstat_ack 0x1 +#define trb_setupstat_stall 0x0 +#define trb_setupstat(p) ((p) << 6) + +/* isochronous trb specific fields */ +#define trb_sia bit(31) +#define trb_frame_id(p) (((p) << 20) & genmask(30, 20)) + +struct cdnsp_generic_trb { + __le32 field[4]; +}; + +union cdnsp_trb { + struct cdnsp_link_trb link; + struct cdnsp_transfer_event trans_event; + struct cdnsp_event_cmd event_cmd; + struct cdnsp_generic_trb generic; +}; + +/* trb bit mask. */ +#define trb_type_bitmask genmask(15, 10) +#define trb_type(p) ((p) << 10) +#define trb_field_to_type(p) (((p) & trb_type_bitmask) >> 10) + +/* trb type ids. */ +/* bulk, interrupt, isoc scatter/gather, and control data stage. */ +#define trb_normal 1 +/* setup stage for control transfers. */ +#define trb_setup 2 +/* data stage for control transfers. */ +#define trb_data 3 +/* status stage for control transfers. */ +#define trb_status 4 +/* isoc transfers. */ +#define trb_isoc 5 +/* trb for linking ring segments. */ +#define trb_link 6 +#define trb_event_data 7 +/* transfer ring no-op (not for the command ring). */ +#define trb_tr_noop 8 + +/* command trbs */ +/* enable slot command. */ +#define trb_enable_slot 9 +/* disable slot command. */ +#define trb_disable_slot 10 +/* address device command. */ +#define trb_addr_dev 11 +/* configure endpoint command. */ +#define trb_config_ep 12 +/* evaluate context command. */ +#define trb_eval_context 13 +/* reset endpoint command. */ +#define trb_reset_ep 14 +/* stop transfer ring command. */ +#define trb_stop_ring 15 +/* set transfer ring dequeue pointer command. */ +#define trb_set_deq 16 +/* reset device command. */ +#define trb_reset_dev 17 +/* force event command (opt). */ +#define trb_force_event 18 +/* force header command - generate a transaction or link management packet. */ +#define trb_force_header 22 +/* no-op command - not for transfer rings. */ +#define trb_cmd_noop 23 +/* trb ids 24-31 reserved. */ + +/* event trbs. */ +/* transfer event. */ +#define trb_transfer 32 +/* command completion event. */ +#define trb_completion 33 +/* port status change event. */ +#define trb_port_status 34 +/* device controller event. */ +#define trb_hc_event 37 +/* mfindex wrap event - microframe counter wrapped. */ +#define trb_mfindex_wrap 39 +/* trb ids 40-47 reserved. */ +/* endpoint not ready event. */ +#define trb_endpoint_nrdy 48 +/* trb ids 49-53 reserved. */ +/* halt endpoint command. */ +#define trb_halt_endpoint 54 +/* doorbell overflow event. */ +#define trb_drb_overflow 57 +/* flush endpoint command. */ +#define trb_flush_endpoint 58 + +#define trb_type_link(x) (((x) & trb_type_bitmask) == trb_type(trb_link)) +#define trb_type_link_le32(x) (((x) & cpu_to_le32(trb_type_bitmask)) == \ + cpu_to_le32(trb_type(trb_link))) +#define trb_type_noop_le32(x) (((x) & cpu_to_le32(trb_type_bitmask)) == \ + cpu_to_le32(trb_type(trb_tr_noop))) + +/* + * trbs_per_segment must be a multiple of 4. + * the command ring is 64-byte aligned, so it must also be greater than 16. + */ +#define trbs_per_segment 256 +#define trbs_per_event_segment 256 +#define trbs_per_ev_deq_update 100 +#define trb_segment_size (trbs_per_segment * 16) +#define trb_segment_shift (ilog2(trb_segment_size)) +/* trb buffer pointers can't cross 64kb boundaries. */ +#define trb_max_buff_shift 16 +#define trb_max_buff_size bit(trb_max_buff_shift) +/* how much data is left before the 64kb boundary? */ +#define trb_buff_len_up_to_boundary(addr) (trb_max_buff_size - \ + ((addr) & (trb_max_buff_size - 1))) + +/** + * struct cdnsp_segment - segment related data. + * @trbs: array of transfer request blocks. + * @next: pointer to the next segment. + * @dma: dma address of current segment. + * @bounce_dma: bounce buffer dma address . + * @bounce_buf: bounce buffer virtual address. + * bounce_offs: bounce buffer offset. + * bounce_len: bounce buffer length. + */ +struct cdnsp_segment { + union cdnsp_trb *trbs; + struct cdnsp_segment *next; + dma_addr_t dma; + /* max packet sized bounce buffer for td-fragmant alignment */ + dma_addr_t bounce_dma; + void *bounce_buf; + unsigned int bounce_offs; + unsigned int bounce_len; +}; + +/** + * struct cdnsp_td - transfer descriptor object. + * @td_list: used for binding td with ep_ring->td_list. + * @preq: request associated with this td + * @start_seg: segment containing the first_trb in td. + * @first_trb: first trb for this td. + * @last_trb: last trb related with td. + * @bounce_seg: bounce segment for this td. + * @request_length_set: actual_length of the request has already been set. + * @drbl - td has been added to hw scheduler - only for stream capable + * endpoints. + */ +struct cdnsp_td { + struct list_head td_list; + struct cdnsp_request *preq; + struct cdnsp_segment *start_seg; + union cdnsp_trb *first_trb; + union cdnsp_trb *last_trb; + struct cdnsp_segment *bounce_seg; + bool request_length_set; + bool drbl; +}; + +/** + * struct cdnsp_dequeue_state - new dequeue pointer for transfer ring. + * @new_deq_seg: new dequeue segment. + * @new_deq_ptr: new dequeue pointer. + * @new_cycle_state: new cycle state. + * @stream_id: stream id for which new dequeue pointer has been selected. + */ +struct cdnsp_dequeue_state { + struct cdnsp_segment *new_deq_seg; + union cdnsp_trb *new_deq_ptr; + int new_cycle_state; + unsigned int stream_id; +}; + +enum cdnsp_ring_type { + type_ctrl = 0, + type_isoc, + type_bulk, + type_intr, + type_stream, + type_command, + type_event, +}; + +/** + * struct cdnsp_ring - information describing transfer, command or event ring. + * @first_seg: first segment on transfer ring. + * @last_seg: last segment on transfer ring. + * @enqueue: sw enqueue pointer address. + * @enq_seg: sw enqueue segment address. + * @dequeue: sw dequeue pointer address. + * @deq_seg: sw dequeue segment address. + * @td_list: transfer descriptor list associated with this ring. + * @cycle_state: current cycle bit. write the cycle state into the trb cycle + * field to give ownership of the trb to the device controller + * (if we are the producer) or to check if we own the trb + * (if we are the consumer). + * @stream_id: stream id + * @stream_active: stream is active - prime packet has been detected. + * @stream_rejected: this ring has been rejected by host. + * @num_tds: number of tds associated with ring. + * @num_segs: number of segments. + * @num_trbs_free: number of free trbs on the ring. + * @bounce_buf_len: length of bounce buffer. + * @type: ring type - event, transfer, or command ring. + * @last_td_was_short - td is short td. + * @trb_address_map: for mapping physical trb addresses to segments in + * stream rings. + */ +struct cdnsp_ring { + struct cdnsp_segment *first_seg; + struct cdnsp_segment *last_seg; + union cdnsp_trb *enqueue; + struct cdnsp_segment *enq_seg; + union cdnsp_trb *dequeue; + struct cdnsp_segment *deq_seg; + struct list_head td_list; + u32 cycle_state; + unsigned int stream_id; + unsigned int stream_active; + unsigned int stream_rejected; + int num_tds; + unsigned int num_segs; + unsigned int num_trbs_free; + unsigned int bounce_buf_len; + enum cdnsp_ring_type type; + bool last_td_was_short; + struct radix_tree_root *trb_address_map; +}; + +/** + * struct cdnsp_erst_entry - even ring segment table entry object. + * @seg_addr: 64-bit event ring segment address. + * seg_size: number of trbs in segment.; + */ +struct cdnsp_erst_entry { + __le64 seg_addr; + __le32 seg_size; + /* set to zero */ + __le32 rsvd; +}; + +/** + * struct cdnsp_erst - even ring segment table for event ring. + * @entries: array of event ring segments + * @num_entries: number of segments in entries array. + * @erst_dma_addr: dma address for entries array. + */ +struct cdnsp_erst { + struct cdnsp_erst_entry *entries; + unsigned int num_entries; + dma_addr_t erst_dma_addr; +}; + +/** + * struct cdnsp_request - extended device side representation of usb_request + * object . + * @td: transfer descriptor associated with this request. + * @request: generic usb_request object describing single i/o request. + * @list: used to adding request to endpoint pending_list. + * @pep: extended representation of usb_ep object + * @epnum: endpoint number associated with usb request. + * @direction: endpoint direction for usb request. + */ +struct cdnsp_request { + struct cdnsp_td td; + struct usb_request request; + struct list_head list; + struct cdnsp_ep *pep; + u8 epnum; + unsigned direction:1; +}; + +#define erst_num_segs 1 + +/* stages used during enumeration process.*/ +enum cdnsp_ep0_stage { + cdnsp_setup_stage, + cdnsp_data_stage, + cdnsp_status_stage, +}; + +/** + * struct cdnsp_port - holds information about detected ports. + * @port_num: port number. + * @exist: indicate if port exist. + * maj_rev: major revision. + * min_rev: minor revision. + */ +struct cdnsp_port { + struct cdnsp_port_regs __iomem *regs; + u8 port_num; + u8 exist; + u8 maj_rev; + u8 min_rev; +}; + +#define cdnsp_ext_port_major(x) (((x) >> 24) & 0xff) +#define cdnsp_ext_port_minor(x) (((x) >> 16) & 0xff) +#define cdnsp_ext_port_off(x) ((x) & 0xff) +#define cdnsp_ext_port_count(x) (((x) >> 8) & 0xff) + +/** + * struct cdnsp_device - represent usb device. + * @dev: pointer to device structure associated whit this controller. + * @gadget: device side representation of the peripheral controller. + * @gadget_driver: pointer to the gadget driver. + * @irq: irq line number used by device side. + * @regs:io device memory. + * @cap_regs: capability registers. + * @op_regs: operational registers. + * @run_regs: runtime registers. + * @dba: device base address register. + * @ir_set: current interrupter register set. + * @port20_regs: port 2.0 peripheral configuration registers. + * @port3x_regs: usb3.x port peripheral configuration registers. + * @hcs_params1: cached register copies of read-only hcsparams1 + * @hcc_params: cached register copies of read-only hccparams1 + * @rev_cap: controller capability. + * @setup: temporary buffer for setup packet. + * @ep0_preq: internal allocated request used during enumeration. + * @ep0_stage: ep0 stage during enumeration process. + * @three_stage_setup: three state or two state setup. + * @ep0_expect_in: data in expected for control transfer. + * @setup_id: setup identifier. + * @setup_speed - speed detected for current setup packet. + * @setup_buf: buffer for setup packet. + * @device_address: current device address. + * @may_wakeup: remote wakeup enabled/disabled. + * @lock: lock used in interrupt thread context. + * @hci_version: device controller version. + * @dcbaa: device context base address array. + * @cmd_ring: command ring. + * @cmd: represent all what is needed to issue command on command ring. + * @event_ring: event ring. + * @erst: event ring segment table + * @slot_id: current slot id. should be 0 or 1. + * @out_ctx: output context. + * @in_ctx: input context. + * @eps: array of endpoints object associated with device. + * @usb2_hw_lpm_capable: hardware lpm is enabled; + * @u1_allowed: allow device transition to u1 state. + * @u2_allowed: allow device transition to u2 state + * @device_pool: dma pool for allocating input and output context. + * @segment_pool: dma pool for allocating new segments. + * @cdnsp_state: current state of controller. + * @link_state: current link state. + * @usb2_port - port usb 2.0. + * @usb3_port - port usb 3.0. + * @active_port - current selected port. + * @test_mode: selected test mode. + */ +struct cdnsp_device { + struct device *dev; + struct usb_gadget gadget; + struct usb_gadget_driver *gadget_driver; + unsigned int irq; + void __iomem *regs; + + /* registers map */ + struct cdnsp_cap_regs __iomem *cap_regs; + struct cdnsp_op_regs __iomem *op_regs; + struct cdnsp_run_regs __iomem *run_regs; + struct cdnsp_doorbell_array __iomem *dba; + struct cdnsp_intr_reg __iomem *ir_set; + struct cdnsp_20port_cap __iomem *port20_regs; + struct cdnsp_3xport_cap __iomem *port3x_regs; + + /* cached register copies of read-only cdnsp data */ + __u32 hcs_params1; + __u32 hcs_params3; + __u32 hcc_params; + struct cdnsp_rev_cap rev_cap; + /* lock used in interrupt thread context. */ + spinlock_t lock; + struct usb_ctrlrequest setup; + struct cdnsp_request ep0_preq; + enum cdnsp_ep0_stage ep0_stage; + u8 three_stage_setup; + u8 ep0_expect_in; + u8 setup_id; + u8 setup_speed; + void *setup_buf; + u8 device_address; + int may_wakeup; + u16 hci_version; + + /* data structures */ + struct cdnsp_device_context_array *dcbaa; + struct cdnsp_ring *cmd_ring; + struct cdnsp_command cmd; + struct cdnsp_ring *event_ring; + struct cdnsp_erst erst; + int slot_id; + + /* + * commands to the hardware are passed an "input context" that + * tells the hardware what to change in its data structures. + * the hardware will return changes in an "output context" that + * software must allocate for the hardware. . + */ + struct cdnsp_container_ctx out_ctx; + struct cdnsp_container_ctx in_ctx; + struct cdnsp_ep eps[cdnsp_endpoints_num]; + u8 usb2_hw_lpm_capable:1; + u8 u1_allowed:1; + u8 u2_allowed:1; + + /* dma pools */ + struct dma_pool *device_pool; + struct dma_pool *segment_pool; + +#define cdnsp_state_halted bit(1) +#define cdnsp_state_dying bit(2) +#define cdnsp_state_disconnect_pending bit(3) +#define cdnsp_wakeup_pending bit(4) + unsigned int cdnsp_state; + unsigned int link_state; + + struct cdnsp_port usb2_port; + struct cdnsp_port usb3_port; + struct cdnsp_port *active_port; + u16 test_mode; +}; + +#endif /* __linux_cdnsp_gadget_h */
Universal Serial Bus
e93e58d2740282d32c0278fab283eb0ae158bb59
pawel laszczak
drivers
usb
cdns3
usb: cdnsp: cdns3 add main part of cadence usbssp drd driver
this patch introduces the main part of cadence usbssp drd driver to linux kernel. to reduce the patch size a little bit, the header file gadget.h was intentionally added as separate patch.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduced new cadence usbssp drd driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'kconfig', 'c', 'makefile']
15
6,641
29
--- diff --git a/drivers/usb/makefile b/drivers/usb/makefile --- a/drivers/usb/makefile +++ b/drivers/usb/makefile +obj-$(config_usb_cdns_support) += cdns3/ +obj-$(config_usb_cdnsp_pci) += cdns3/ diff --git a/drivers/usb/cdns3/kconfig b/drivers/usb/cdns3/kconfig --- a/drivers/usb/cdns3/kconfig +++ b/drivers/usb/cdns3/kconfig -config cdns_usb_common - tristate +config usb_cdns_support + tristate "cadence usb support" + depends on usb_support && (usb || usb_gadget) && has_dma + select usb_xhci_platform if usb_xhci_hcd + select usb_role_switch + help + say y here if your system has a cadence usbss or usbssp + dual-role controller. + it supports: dual-role switch, host-only, and peripheral-only. -config cdns_usb_host +config usb_cdns_host +if usb_cdns_support + - depends on usb_support && (usb || usb_gadget) && has_dma - select usb_xhci_platform if usb_xhci_hcd - select usb_role_switch - select cdns_usb_common + depends on usb_cdns_support +endif - select cdns_usb_host + select usb_cdns_host + +if usb_cdns_support + +config usb_cdnsp_pci + tristate "cadence cdnsp dual-role controller" + depends on usb_cdns_support && usb_pci && acpi + help + say y here if your system has a cadence cdnsp dual-role controller. + it supports: dual-role switch host-only, and peripheral-only. + + if you choose to build this driver is a dynamically linked + module, the module will be called cdnsp.ko. +endif + +if usb_cdnsp_pci + +config usb_cdnsp_gadget + bool "cadence cdnsp device controller" + depends on usb_gadget=y || usb_gadget=usb_cdnsp_pci + help + say y here to enable device controller functionality of the + cadence cdnsp-dev driver. + + cadence cdnsp device controller in device mode is + very similar to xhci controller. therefore some algorithms + used has been taken from host driver. + this controller supports ff, hs, ss and ssp mode. + it doesn't support ls. + +config usb_cdnsp_host + bool "cadence cdnsp host controller" + depends on usb=y || usb=usb_cdnsp_pci + select usb_cdns_host + help + say y here to enable host controller functionality of the + cadence driver. + + host controller is compliant with xhci so it uses + standard xhci driver. + +endif diff --git a/drivers/usb/cdns3/makefile b/drivers/usb/cdns3/makefile --- a/drivers/usb/cdns3/makefile +++ b/drivers/usb/cdns3/makefile -cflags_trace.o := -i$(src) +cflags_trace.o := -i$(src) -cdns-usb-common-y := core.o drd.o -cdns3-y := cdns3-plat.o +cdns-usb-common-y := core.o drd.o +cdns3-y := cdns3-plat.o -obj-$(config_usb_cdns3) += cdns3.o -obj-$(config_cdns_usb_common) += cdns-usb-common.o +obj-$(config_usb_cdns3) += cdns3.o +obj-$(config_usb_cdns_support) += cdns-usb-common.o -cdns-usb-common-$(config_cdns_usb_host) += host.o -cdns3-$(config_usb_cdns3_gadget) += gadget.o ep0.o +cdns-usb-common-$(config_usb_cdns_host) += host.o +cdns3-$(config_usb_cdns3_gadget) += gadget.o ep0.o -cdns3-$(config_tracing) += trace.o +cdns3-$(config_tracing) += trace.o -obj-$(config_usb_cdns3_pci_wrap) += cdns3-pci-wrap.o -obj-$(config_usb_cdns3_ti) += cdns3-ti.o -obj-$(config_usb_cdns3_imx) += cdns3-imx.o +obj-$(config_usb_cdns3_pci_wrap) += cdns3-pci-wrap.o +obj-$(config_usb_cdns3_ti) += cdns3-ti.o +obj-$(config_usb_cdns3_imx) += cdns3-imx.o + +cdnsp-udc-pci-y := cdnsp-pci.o +obj-$(config_usb_cdnsp_pci) += cdnsp-udc-pci.o +cdnsp-udc-pci-$(config_usb_cdnsp_gadget) += cdnsp-ring.o cdnsp-gadget.o \ + cdnsp-mem.o cdnsp-ep0.o diff --git a/drivers/usb/cdns3/cdnsp-ep0.c b/drivers/usb/cdns3/cdnsp-ep0.c --- /dev/null +++ b/drivers/usb/cdns3/cdnsp-ep0.c +// spdx-license-identifier: gpl-2.0 +/* + * cadence cdnsp drd driver. + * + * copyright (c) 2020 cadence. + * + * author: pawel laszczak <pawell@cadence.com> + * + */ + +#include <linux/usb/composite.h> +#include <linux/usb/gadget.h> +#include <linux/list.h> + +#include "cdnsp-gadget.h" + +static void cdnsp_ep0_stall(struct cdnsp_device *pdev) +{ + struct cdnsp_request *preq; + struct cdnsp_ep *pep; + + pep = &pdev->eps[0]; + preq = next_request(&pep->pending_list); + + if (pdev->three_stage_setup) { + cdnsp_halt_endpoint(pdev, pep, true); + + if (preq) + cdnsp_gadget_giveback(pep, preq, -econnreset); + } else { + pep->ep_state |= ep0_halted_status; + + if (preq) + list_del(&preq->list); + + cdnsp_status_stage(pdev); + } +} + +static int cdnsp_ep0_delegate_req(struct cdnsp_device *pdev, + struct usb_ctrlrequest *ctrl) +{ + int ret; + + spin_unlock(&pdev->lock); + ret = pdev->gadget_driver->setup(&pdev->gadget, ctrl); + spin_lock(&pdev->lock); + + return ret; +} + +static int cdnsp_ep0_set_config(struct cdnsp_device *pdev, + struct usb_ctrlrequest *ctrl) +{ + enum usb_device_state state = pdev->gadget.state; + u32 cfg; + int ret; + + cfg = le16_to_cpu(ctrl->wvalue); + + switch (state) { + case usb_state_address: + break; + case usb_state_configured: + break; + default: + dev_err(pdev->dev, "set configuration - bad device state "); + return -einval; + } + + ret = cdnsp_ep0_delegate_req(pdev, ctrl); + if (ret) + return ret; + + if (!cfg) + usb_gadget_set_state(&pdev->gadget, usb_state_address); + + return 0; +} + +static int cdnsp_ep0_set_address(struct cdnsp_device *pdev, + struct usb_ctrlrequest *ctrl) +{ + enum usb_device_state state = pdev->gadget.state; + struct cdnsp_slot_ctx *slot_ctx; + unsigned int slot_state; + int ret; + u32 addr; + + addr = le16_to_cpu(ctrl->wvalue); + + if (addr > 127) { + dev_err(pdev->dev, "invalid device address %d ", addr); + return -einval; + } + + slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); + + if (state == usb_state_configured) { + dev_err(pdev->dev, "can't set address from configured state "); + return -einval; + } + + pdev->device_address = le16_to_cpu(ctrl->wvalue); + + slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); + slot_state = get_slot_state(le32_to_cpu(slot_ctx->dev_state)); + if (slot_state == slot_state_addressed) + cdnsp_reset_device(pdev); + + /*set device address*/ + ret = cdnsp_setup_device(pdev, setup_context_address); + if (ret) + return ret; + + if (addr) + usb_gadget_set_state(&pdev->gadget, usb_state_address); + else + usb_gadget_set_state(&pdev->gadget, usb_state_default); + + return 0; +} + +int cdnsp_status_stage(struct cdnsp_device *pdev) +{ + pdev->ep0_stage = cdnsp_status_stage; + pdev->ep0_preq.request.length = 0; + + return cdnsp_ep_enqueue(pdev->ep0_preq.pep, &pdev->ep0_preq); +} + +static int cdnsp_w_index_to_ep_index(__le32 windex) +{ + windex = le32_to_cpu(windex); + + if (!(windex & usb_endpoint_number_mask)) + return 0; + + return ((windex & usb_endpoint_number_mask) * 2) + + (windex & usb_endpoint_dir_mask ? 1 : 0) - 1; +} + +static int cdnsp_ep0_handle_status(struct cdnsp_device *pdev, + struct usb_ctrlrequest *ctrl) +{ + struct cdnsp_ep *pep; + __le16 *response; + int ep_sts = 0; + u16 status = 0; + u32 recipient; + + recipient = ctrl->brequesttype & usb_recip_mask; + + switch (recipient) { + case usb_recip_device: + status = pdev->gadget.is_selfpowered; + status |= pdev->may_wakeup << usb_device_remote_wakeup; + + if (pdev->gadget.speed >= usb_speed_super) { + status |= pdev->u1_allowed << usb_dev_stat_u1_enabled; + status |= pdev->u2_allowed << usb_dev_stat_u2_enabled; + } + break; + case usb_recip_interface: + /* + * function remote wake capable d0 + * function remote wakeup d1 + */ + return cdnsp_ep0_delegate_req(pdev, ctrl); + case usb_recip_endpoint: + pep = &pdev->eps[cdnsp_w_index_to_ep_index(ctrl->windex)]; + ep_sts = get_ep_ctx_state(pep->out_ctx); + + /* check if endpoint is stalled */ + if (ep_sts == ep_state_halted) + status = bit(usb_endpoint_halt); + break; + default: + return -einval; + } + + response = (__le16 *)pdev->setup_buf; + *response = cpu_to_le16(status); + + pdev->ep0_preq.request.length = sizeof(*response); + pdev->ep0_preq.request.buf = pdev->setup_buf; + + return cdnsp_ep_enqueue(pdev->ep0_preq.pep, &pdev->ep0_preq); +} + +static void cdnsp_enter_test_mode(struct cdnsp_device *pdev) +{ + u32 temp; + + temp = readl(&pdev->active_port->regs->portpmsc) & ~genmask(31, 28); + temp |= port_test_mode(pdev->test_mode); + writel(temp, &pdev->active_port->regs->portpmsc); +} + +static int cdnsp_ep0_handle_feature_device(struct cdnsp_device *pdev, + struct usb_ctrlrequest *ctrl, + int set) +{ + enum usb_device_state state; + enum usb_device_speed speed; + u16 tmode; + + state = pdev->gadget.state; + speed = pdev->gadget.speed; + + switch (le16_to_cpu(ctrl->wvalue)) { + case usb_device_remote_wakeup: + pdev->may_wakeup = !!set; + break; + case usb_device_u1_enable: + if (state != usb_state_configured || speed < usb_speed_super) + return -einval; + + pdev->u1_allowed = !!set; + break; + case usb_device_u2_enable: + if (state != usb_state_configured || speed < usb_speed_super) + return -einval; + + pdev->u2_allowed = !!set; + break; + case usb_device_ltm_enable: + return -einval; + case usb_device_test_mode: + if (state != usb_state_configured || speed > usb_speed_high) + return -einval; + + tmode = le16_to_cpu(ctrl->windex); + + if (!set || (tmode & 0xff) != 0) + return -einval; + + tmode = tmode >> 8; + + if (tmode > usb_test_force_enable || tmode < usb_test_j) + return -einval; + + pdev->test_mode = tmode; + + /* + * test mode must be set before status stage but controller + * will start testing sequence after status stage. + */ + cdnsp_enter_test_mode(pdev); + break; + default: + return -einval; + } + + return 0; +} + +static int cdnsp_ep0_handle_feature_intf(struct cdnsp_device *pdev, + struct usb_ctrlrequest *ctrl, + int set) +{ + u16 wvalue, windex; + int ret; + + wvalue = le16_to_cpu(ctrl->wvalue); + windex = le16_to_cpu(ctrl->windex); + + switch (wvalue) { + case usb_intrf_func_suspend: + ret = cdnsp_ep0_delegate_req(pdev, ctrl); + if (ret) + return ret; + + /* + * remote wakeup is enabled when any function within a device + * is enabled for function remote wakeup. + */ + if (windex & usb_intrf_func_suspend_rw) + pdev->may_wakeup++; + else + if (pdev->may_wakeup > 0) + pdev->may_wakeup--; + + return 0; + default: + return -einval; + } + + return 0; +} + +static int cdnsp_ep0_handle_feature_endpoint(struct cdnsp_device *pdev, + struct usb_ctrlrequest *ctrl, + int set) +{ + struct cdnsp_ep *pep; + u32 wvalue; + + wvalue = le16_to_cpu(ctrl->wvalue); + pep = &pdev->eps[cdnsp_w_index_to_ep_index(ctrl->windex)]; + + switch (wvalue) { + case usb_endpoint_halt: + if (!set && (pep->ep_state & ep_wedge)) { + /* resets sequence number */ + cdnsp_halt_endpoint(pdev, pep, 0); + cdnsp_halt_endpoint(pdev, pep, 1); + break; + } + + return cdnsp_halt_endpoint(pdev, pep, set); + default: + dev_warn(pdev->dev, "warn incorrect wvalue %04x ", wvalue); + return -einval; + } + + return 0; +} + +static int cdnsp_ep0_handle_feature(struct cdnsp_device *pdev, + struct usb_ctrlrequest *ctrl, + int set) +{ + switch (ctrl->brequesttype & usb_recip_mask) { + case usb_recip_device: + return cdnsp_ep0_handle_feature_device(pdev, ctrl, set); + case usb_recip_interface: + return cdnsp_ep0_handle_feature_intf(pdev, ctrl, set); + case usb_recip_endpoint: + return cdnsp_ep0_handle_feature_endpoint(pdev, ctrl, set); + default: + return -einval; + } +} + +static int cdnsp_ep0_set_sel(struct cdnsp_device *pdev, + struct usb_ctrlrequest *ctrl) +{ + enum usb_device_state state = pdev->gadget.state; + u16 wlength; + + if (state == usb_state_default) + return -einval; + + wlength = le16_to_cpu(ctrl->wlength); + + if (wlength != 6) { + dev_err(pdev->dev, "set sel should be 6 bytes, got %d ", + wlength); + return -einval; + } + + /* + * to handle set sel we need to receive 6 bytes from host. so let's + * queue a usb_request for 6 bytes. + */ + pdev->ep0_preq.request.length = 6; + pdev->ep0_preq.request.buf = pdev->setup_buf; + + return cdnsp_ep_enqueue(pdev->ep0_preq.pep, &pdev->ep0_preq); +} + +static int cdnsp_ep0_set_isoch_delay(struct cdnsp_device *pdev, + struct usb_ctrlrequest *ctrl) +{ + if (le16_to_cpu(ctrl->windex) || le16_to_cpu(ctrl->wlength)) + return -einval; + + pdev->gadget.isoch_delay = le16_to_cpu(ctrl->wvalue); + + return 0; +} + +static int cdnsp_ep0_std_request(struct cdnsp_device *pdev, + struct usb_ctrlrequest *ctrl) +{ + int ret; + + switch (ctrl->brequest) { + case usb_req_get_status: + ret = cdnsp_ep0_handle_status(pdev, ctrl); + break; + case usb_req_clear_feature: + ret = cdnsp_ep0_handle_feature(pdev, ctrl, 0); + break; + case usb_req_set_feature: + ret = cdnsp_ep0_handle_feature(pdev, ctrl, 1); + break; + case usb_req_set_address: + ret = cdnsp_ep0_set_address(pdev, ctrl); + break; + case usb_req_set_configuration: + ret = cdnsp_ep0_set_config(pdev, ctrl); + break; + case usb_req_set_sel: + ret = cdnsp_ep0_set_sel(pdev, ctrl); + break; + case usb_req_set_isoch_delay: + ret = cdnsp_ep0_set_isoch_delay(pdev, ctrl); + break; + case usb_req_set_interface: + /* + * add request into pending list to block sending status stage + * by libcomposite. + */ + list_add_tail(&pdev->ep0_preq.list, + &pdev->ep0_preq.pep->pending_list); + + ret = cdnsp_ep0_delegate_req(pdev, ctrl); + if (ret == -ebusy) + ret = 0; + + list_del(&pdev->ep0_preq.list); + break; + default: + ret = cdnsp_ep0_delegate_req(pdev, ctrl); + break; + } + + return ret; +} + +void cdnsp_setup_analyze(struct cdnsp_device *pdev) +{ + struct usb_ctrlrequest *ctrl = &pdev->setup; + int ret = 0; + __le16 len; + + if (!pdev->gadget_driver) + goto out; + + if (pdev->gadget.state == usb_state_notattached) { + dev_err(pdev->dev, "err: setup detected in unattached state "); + ret = -einval; + goto out; + } + + /* restore the ep0 to stopped/running state. */ + if (pdev->eps[0].ep_state & ep_halted) + cdnsp_halt_endpoint(pdev, &pdev->eps[0], 0); + + /* + * finishing previous setup transfer by removing request from + * list and informing upper layer + */ + if (!list_empty(&pdev->eps[0].pending_list)) { + struct cdnsp_request *req; + + req = next_request(&pdev->eps[0].pending_list); + cdnsp_ep_dequeue(&pdev->eps[0], req); + } + + len = le16_to_cpu(ctrl->wlength); + if (!len) { + pdev->three_stage_setup = false; + pdev->ep0_expect_in = false; + } else { + pdev->three_stage_setup = true; + pdev->ep0_expect_in = !!(ctrl->brequesttype & usb_dir_in); + } + + if ((ctrl->brequesttype & usb_type_mask) == usb_type_standard) + ret = cdnsp_ep0_std_request(pdev, ctrl); + else + ret = cdnsp_ep0_delegate_req(pdev, ctrl); + + if (!len) + pdev->ep0_stage = cdnsp_status_stage; + + if (ret == usb_gadget_delayed_status) + return; +out: + if (ret < 0) + cdnsp_ep0_stall(pdev); + else if (pdev->ep0_stage == cdnsp_status_stage) + cdnsp_status_stage(pdev); +} diff --git a/drivers/usb/cdns3/cdnsp-gadget.c b/drivers/usb/cdns3/cdnsp-gadget.c --- /dev/null +++ b/drivers/usb/cdns3/cdnsp-gadget.c +// spdx-license-identifier: gpl-2.0 +/* + * cadence cdnsp drd driver. + * + * copyright (c) 2020 cadence. + * + * author: pawel laszczak <pawell@cadence.com> + * + */ + +#include <linux/moduleparam.h> +#include <linux/dma-mapping.h> +#include <linux/module.h> +#include <linux/iopoll.h> +#include <linux/delay.h> +#include <linux/log2.h> +#include <linux/slab.h> +#include <linux/pci.h> +#include <linux/irq.h> +#include <linux/dmi.h> + +#include "core.h" +#include "gadget-export.h" +#include "drd.h" +#include "cdnsp-gadget.h" + +unsigned int cdnsp_port_speed(unsigned int port_status) +{ + /*detect gadget speed based on portsc register*/ + if (dev_superspeedplus(port_status)) + return usb_speed_super_plus; + else if (dev_superspeed(port_status)) + return usb_speed_super; + else if (dev_highspeed(port_status)) + return usb_speed_high; + else if (dev_fullspeed(port_status)) + return usb_speed_full; + + /* if device is detached then speed will be usb_speed_unknown.*/ + return usb_speed_unknown; +} + +/* + * given a port state, this function returns a value that would result in the + * port being in the same state, if the value was written to the port status + * control register. + * save read only (ro) bits and save read/write bits where + * writing a 0 clears the bit and writing a 1 sets the bit (rws). + * for all other types (rw1s, rw1cs, rw, and rz), writing a '0' has no effect. + */ +u32 cdnsp_port_state_to_neutral(u32 state) +{ + /* save read-only status and port state. */ + return (state & cdnsp_port_ro) | (state & cdnsp_port_rws); +} + +/** + * find the offset of the extended capabilities with capability id id. + * @base: pci mmio registers base address. + * @start: address at which to start looking, (0 or hcc_params to start at + * beginning of list) + * @id: extended capability id to search for. + * + * returns the offset of the next matching extended capability structure. + * some capabilities can occur several times, + * e.g., the ext_caps_protocol, and this provides a way to find them all. + */ +int cdnsp_find_next_ext_cap(void __iomem *base, u32 start, int id) +{ + u32 offset = start; + u32 next; + u32 val; + + if (!start || start == hcc_params_offset) { + val = readl(base + hcc_params_offset); + if (val == ~0) + return 0; + + offset = hcc_ext_caps(val) << 2; + if (!offset) + return 0; + }; + + do { + val = readl(base + offset); + if (val == ~0) + return 0; + + if (ext_caps_id(val) == id && offset != start) + return offset; + + next = ext_caps_next(val); + offset += next << 2; + } while (next); + + return 0; +} + +void cdnsp_set_link_state(struct cdnsp_device *pdev, + __le32 __iomem *port_regs, + u32 link_state) +{ + u32 temp; + + temp = readl(port_regs); + temp = cdnsp_port_state_to_neutral(temp); + temp |= port_wkconn_e | port_wkdisc_e; + writel(temp, port_regs); + + temp &= ~port_pls_mask; + temp |= port_link_strobe | link_state; + + writel(temp, port_regs); +} + +static void cdnsp_disable_port(struct cdnsp_device *pdev, + __le32 __iomem *port_regs) +{ + u32 temp = cdnsp_port_state_to_neutral(readl(port_regs)); + + writel(temp | port_ped, port_regs); +} + +static void cdnsp_clear_port_change_bit(struct cdnsp_device *pdev, + __le32 __iomem *port_regs) +{ + u32 portsc = readl(port_regs); + + writel(cdnsp_port_state_to_neutral(portsc) | + (portsc & port_change_bits), port_regs); +} + +static void cdnsp_set_chicken_bits_2(struct cdnsp_device *pdev, u32 bit) +{ + __le32 __iomem *reg; + void __iomem *base; + u32 offset = 0; + + base = &pdev->cap_regs->hc_capbase; + offset = cdnsp_find_next_ext_cap(base, offset, d_xec_pre_regs_cap); + reg = base + offset + reg_chicken_bits_2_offset; + + bit = readl(reg) | bit; + writel(bit, reg); +} + +static void cdnsp_clear_chicken_bits_2(struct cdnsp_device *pdev, u32 bit) +{ + __le32 __iomem *reg; + void __iomem *base; + u32 offset = 0; + + base = &pdev->cap_regs->hc_capbase; + offset = cdnsp_find_next_ext_cap(base, offset, d_xec_pre_regs_cap); + reg = base + offset + reg_chicken_bits_2_offset; + + bit = readl(reg) & ~bit; + writel(bit, reg); +} + +/* + * disable interrupts and begin the controller halting process. + */ +static void cdnsp_quiesce(struct cdnsp_device *pdev) +{ + u32 halted; + u32 mask; + u32 cmd; + + mask = ~(u32)(cdnsp_irqs); + + halted = readl(&pdev->op_regs->status) & sts_halt; + if (!halted) + mask &= ~(cmd_r_s | cmd_deven); + + cmd = readl(&pdev->op_regs->command); + cmd &= mask; + writel(cmd, &pdev->op_regs->command); +} + +/* + * force controller into halt state. + * + * disable any irqs and clear the run/stop bit. + * controller will complete any current and actively pipelined transactions, and + * should halt within 16 ms of the run/stop bit being cleared. + * read controller halted bit in the status register to see when the + * controller is finished. + */ +int cdnsp_halt(struct cdnsp_device *pdev) +{ + int ret; + u32 val; + + cdnsp_quiesce(pdev); + + ret = readl_poll_timeout_atomic(&pdev->op_regs->status, val, + val & sts_halt, 1, + cdnsp_max_halt_usec); + if (ret) { + dev_err(pdev->dev, "error: device halt failed "); + return ret; + } + + pdev->cdnsp_state |= cdnsp_state_halted; + + return 0; +} + +/* + * device controller died, register read returns 0xffffffff, or command never + * ends. + */ +void cdnsp_died(struct cdnsp_device *pdev) +{ + dev_err(pdev->dev, "error: cdnsp controller not responding "); + pdev->cdnsp_state |= cdnsp_state_dying; + cdnsp_halt(pdev); +} + +/* + * set the run bit and wait for the device to be running. + */ +static int cdnsp_start(struct cdnsp_device *pdev) +{ + u32 temp; + int ret; + + temp = readl(&pdev->op_regs->command); + temp |= (cmd_r_s | cmd_deven); + writel(temp, &pdev->op_regs->command); + + pdev->cdnsp_state = 0; + + /* + * wait for the sts_halt status bit to be 0 to indicate the device is + * running. + */ + ret = readl_poll_timeout_atomic(&pdev->op_regs->status, temp, + !(temp & sts_halt), 1, + cdnsp_max_halt_usec); + if (ret) { + pdev->cdnsp_state = cdnsp_state_dying; + dev_err(pdev->dev, "error: controller run failed "); + } + + return ret; +} + +/* + * reset a halted controller. + * + * this resets pipelines, timers, counters, state machines, etc. + * transactions will be terminated immediately, and operational registers + * will be set to their defaults. + */ +int cdnsp_reset(struct cdnsp_device *pdev) +{ + u32 command; + u32 temp; + int ret; + + temp = readl(&pdev->op_regs->status); + + if (temp == ~(u32)0) { + dev_err(pdev->dev, "device not accessible, reset failed. "); + return -enodev; + } + + if ((temp & sts_halt) == 0) { + dev_err(pdev->dev, "controller not halted, aborting reset. "); + return -einval; + } + + command = readl(&pdev->op_regs->command); + command |= cmd_reset; + writel(command, &pdev->op_regs->command); + + ret = readl_poll_timeout_atomic(&pdev->op_regs->command, temp, + !(temp & cmd_reset), 1, + 10 * 1000); + if (ret) { + dev_err(pdev->dev, "error: controller reset failed "); + return ret; + } + + /* + * cdnsp cannot write any doorbells or operational registers other + * than status until the "controller not ready" flag is cleared. + */ + ret = readl_poll_timeout_atomic(&pdev->op_regs->status, temp, + !(temp & sts_cnr), 1, + 10 * 1000); + + if (ret) { + dev_err(pdev->dev, "error: controller not ready to work "); + return ret; + } + + dev_dbg(pdev->dev, "controller ready to work"); + + return ret; +} + +/* + * cdnsp_get_endpoint_index - find the index for an endpoint given its + * descriptor.use the return value to right shift 1 for the bitmask. + * + * index = (epnum * 2) + direction - 1, + * where direction = 0 for out, 1 for in. + * for control endpoints, the in index is used (out index is unused), so + * index = (epnum * 2) + direction - 1 = (epnum * 2) + 1 - 1 = (epnum * 2) + */ +static unsigned int + cdnsp_get_endpoint_index(const struct usb_endpoint_descriptor *desc) +{ + unsigned int index = (unsigned int)usb_endpoint_num(desc); + + if (usb_endpoint_xfer_control(desc)) + return index * 2; + + return (index * 2) + (usb_endpoint_dir_in(desc) ? 1 : 0) - 1; +} + +/* + * find the flag for this endpoint (for use in the control context). use the + * endpoint index to create a bitmask. the slot context is bit 0, endpoint 0 is + * bit 1, etc. + */ +static unsigned int + cdnsp_get_endpoint_flag(const struct usb_endpoint_descriptor *desc) +{ + return 1 << (cdnsp_get_endpoint_index(desc) + 1); +} + +int cdnsp_ep_enqueue(struct cdnsp_ep *pep, struct cdnsp_request *preq) +{ + struct cdnsp_device *pdev = pep->pdev; + struct usb_request *request; + int ret; + + if (preq->epnum == 0 && !list_empty(&pep->pending_list)) + return -ebusy; + + request = &preq->request; + request->actual = 0; + request->status = -einprogress; + preq->direction = pep->direction; + preq->epnum = pep->number; + preq->td.drbl = 0; + + ret = usb_gadget_map_request_by_dev(pdev->dev, request, pep->direction); + if (ret) + return ret; + + list_add_tail(&preq->list, &pep->pending_list); + + switch (usb_endpoint_type(pep->endpoint.desc)) { + case usb_endpoint_xfer_control: + ret = cdnsp_queue_ctrl_tx(pdev, preq); + break; + case usb_endpoint_xfer_bulk: + case usb_endpoint_xfer_int: + ret = cdnsp_queue_bulk_tx(pdev, preq); + break; + case usb_endpoint_xfer_isoc: + ret = cdnsp_queue_isoc_tx_prepare(pdev, preq); + } + + if (ret) + goto unmap; + + return 0; + +unmap: + usb_gadget_unmap_request_by_dev(pdev->dev, &preq->request, + pep->direction); + list_del(&preq->list); + + return ret; +} + +/* + * remove the request's td from the endpoint ring. this may cause the + * controller to stop usb transfers, potentially stopping in the middle of a + * trb buffer. the controller should pick up where it left off in the td, + * unless a set transfer ring dequeue pointer is issued. + * + * the trbs that make up the buffers for the canceled request will be "removed" + * from the ring. since the ring is a contiguous structure, they can't be + * physically removed. instead, there are two options: + * + * 1) if the controller is in the middle of processing the request to be + * canceled, we simply move the ring's dequeue pointer past those trbs + * using the set transfer ring dequeue pointer command. this will be + * the common case, when drivers timeout on the last submitted request + * and attempt to cancel. + * + * 2) if the controller is in the middle of a different td, we turn the trbs + * into a series of 1-trb transfer no-op tds. no-ops shouldn't be chained. + * the controller will need to invalidate the any trbs it has cached after + * the stop endpoint command. + * + * 3) the td may have completed by the time the stop endpoint command + * completes, so software needs to handle that case too. + * + */ +int cdnsp_ep_dequeue(struct cdnsp_ep *pep, struct cdnsp_request *preq) +{ + struct cdnsp_device *pdev = pep->pdev; + int ret; + + if (get_ep_ctx_state(pep->out_ctx) == ep_state_running) { + ret = cdnsp_cmd_stop_ep(pdev, pep); + if (ret) + return ret; + } + + return cdnsp_remove_request(pdev, preq, pep); +} + +static void cdnsp_zero_in_ctx(struct cdnsp_device *pdev) +{ + struct cdnsp_input_control_ctx *ctrl_ctx; + struct cdnsp_slot_ctx *slot_ctx; + struct cdnsp_ep_ctx *ep_ctx; + int i; + + ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); + + /* + * when a device's add flag and drop flag are zero, any subsequent + * configure endpoint command will leave that endpoint's state + * untouched. make sure we don't leave any old state in the input + * endpoint contexts. + */ + ctrl_ctx->drop_flags = 0; + ctrl_ctx->add_flags = 0; + slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); + slot_ctx->dev_info &= cpu_to_le32(~last_ctx_mask); + + /* endpoint 0 is always valid */ + slot_ctx->dev_info |= cpu_to_le32(last_ctx(1)); + for (i = 1; i < cdnsp_endpoints_num; ++i) { + ep_ctx = cdnsp_get_ep_ctx(&pdev->in_ctx, i); + ep_ctx->ep_info = 0; + ep_ctx->ep_info2 = 0; + ep_ctx->deq = 0; + ep_ctx->tx_info = 0; + } +} + +/* issue a configure endpoint command and wait for it to finish. */ +static int cdnsp_configure_endpoint(struct cdnsp_device *pdev) +{ + int ret; + + cdnsp_queue_configure_endpoint(pdev, pdev->cmd.in_ctx->dma); + cdnsp_ring_cmd_db(pdev); + ret = cdnsp_wait_for_cmd_compl(pdev); + if (ret) { + dev_err(pdev->dev, + "err: unexpected command completion code 0x%x. ", ret); + return -einval; + } + + return ret; +} + +static void cdnsp_invalidate_ep_events(struct cdnsp_device *pdev, + struct cdnsp_ep *pep) +{ + struct cdnsp_segment *segment; + union cdnsp_trb *event; + u32 cycle_state; + __le32 data; + + event = pdev->event_ring->dequeue; + segment = pdev->event_ring->deq_seg; + cycle_state = pdev->event_ring->cycle_state; + + while (1) { + data = le32_to_cpu(event->trans_event.flags); + + /* check the owner of the trb. */ + if ((data & trb_cycle) != cycle_state) + break; + + if (trb_field_to_type(data) == trb_transfer && + trb_to_ep_id(data) == (pep->idx + 1)) { + data |= trb_event_invalidate; + event->trans_event.flags = cpu_to_le32(data); + } + + if (cdnsp_last_trb_on_seg(segment, event)) { + cycle_state ^= 1; + segment = pdev->event_ring->deq_seg->next; + event = segment->trbs; + } else { + event++; + } + } +} + +int cdnsp_wait_for_cmd_compl(struct cdnsp_device *pdev) +{ + struct cdnsp_segment *event_deq_seg; + union cdnsp_trb *cmd_trb; + dma_addr_t cmd_deq_dma; + union cdnsp_trb *event; + u32 cycle_state; + __le32 flags; + int ret, val; + u64 cmd_dma; + + cmd_trb = pdev->cmd.command_trb; + pdev->cmd.status = 0; + + ret = readl_poll_timeout_atomic(&pdev->op_regs->cmd_ring, val, + !cmd_ring_busy(val), 1, + cdnsp_cmd_timeout); + if (ret) { + dev_err(pdev->dev, "err: timeout while waiting for command "); + pdev->cdnsp_state = cdnsp_state_dying; + return -etimedout; + } + + event = pdev->event_ring->dequeue; + event_deq_seg = pdev->event_ring->deq_seg; + cycle_state = pdev->event_ring->cycle_state; + + cmd_deq_dma = cdnsp_trb_virt_to_dma(pdev->cmd_ring->deq_seg, cmd_trb); + if (!cmd_deq_dma) + return -einval; + + while (1) { + flags = le32_to_cpu(event->event_cmd.flags); + + /* check the owner of the trb. */ + if ((flags & trb_cycle) != cycle_state) + return -einval; + + cmd_dma = le64_to_cpu(event->event_cmd.cmd_trb); + + /* + * check whether the completion event is for last queued + * command. + */ + if (trb_field_to_type(flags) != trb_completion || + cmd_dma != (u64)cmd_deq_dma) { + if (!cdnsp_last_trb_on_seg(event_deq_seg, event)) { + event++; + continue; + } + + if (cdnsp_last_trb_on_ring(pdev->event_ring, + event_deq_seg, event)) + cycle_state ^= 1; + + event_deq_seg = event_deq_seg->next; + event = event_deq_seg->trbs; + continue; + } + + pdev->cmd.status = get_comp_code(le32_to_cpu(event->event_cmd.status)); + if (pdev->cmd.status == comp_success) + return 0; + + return -pdev->cmd.status; + } +} + +int cdnsp_halt_endpoint(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, + int value) +{ + int ret; + + if (value) { + ret = cdnsp_cmd_stop_ep(pdev, pep); + if (ret) + return ret; + + if (get_ep_ctx_state(pep->out_ctx) == ep_state_stopped) { + cdnsp_queue_halt_endpoint(pdev, pep->idx); + cdnsp_ring_cmd_db(pdev); + ret = cdnsp_wait_for_cmd_compl(pdev); + } + + pep->ep_state |= ep_halted; + } else { + /* + * in device mode driver can call reset endpoint command + * from any endpoint state. + */ + cdnsp_queue_reset_ep(pdev, pep->idx); + cdnsp_ring_cmd_db(pdev); + ret = cdnsp_wait_for_cmd_compl(pdev); + if (ret) + return ret; + + pep->ep_state &= ~ep_halted; + + if (pep->idx != 0 && !(pep->ep_state & ep_wedge)) + cdnsp_ring_doorbell_for_active_rings(pdev, pep); + + pep->ep_state &= ~ep_wedge; + } + + return 0; +} + +static int cdnsp_update_eps_configuration(struct cdnsp_device *pdev, + struct cdnsp_ep *pep) +{ + struct cdnsp_input_control_ctx *ctrl_ctx; + struct cdnsp_slot_ctx *slot_ctx; + int ret = 0; + u32 ep_sts; + int i; + + ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); + + /* don't issue the command if there's no endpoints to update. */ + if (ctrl_ctx->add_flags == 0 && ctrl_ctx->drop_flags == 0) + return 0; + + ctrl_ctx->add_flags |= cpu_to_le32(slot_flag); + ctrl_ctx->add_flags &= cpu_to_le32(~ep0_flag); + ctrl_ctx->drop_flags &= cpu_to_le32(~(slot_flag | ep0_flag)); + + /* fix up context entries field. minimum value is ep0 == bit(1). */ + slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); + for (i = cdnsp_endpoints_num; i >= 1; i--) { + __le32 le32 = cpu_to_le32(bit(i)); + + if ((pdev->eps[i - 1].ring && !(ctrl_ctx->drop_flags & le32)) || + (ctrl_ctx->add_flags & le32) || i == 1) { + slot_ctx->dev_info &= cpu_to_le32(~last_ctx_mask); + slot_ctx->dev_info |= cpu_to_le32(last_ctx(i)); + break; + } + } + + ep_sts = get_ep_ctx_state(pep->out_ctx); + + if ((ctrl_ctx->add_flags != cpu_to_le32(slot_flag) && + ep_sts == ep_state_disabled) || + (ep_sts != ep_state_disabled && ctrl_ctx->drop_flags)) + ret = cdnsp_configure_endpoint(pdev); + + cdnsp_zero_in_ctx(pdev); + + return ret; +} + +/* + * this submits a reset device command, which will set the device state to 0, + * set the device address to 0, and disable all the endpoints except the default + * control endpoint. the usb core should come back and call + * cdnsp_setup_device(), and then re-set up the configuration. + */ +int cdnsp_reset_device(struct cdnsp_device *pdev) +{ + struct cdnsp_slot_ctx *slot_ctx; + int slot_state; + int ret, i; + + slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); + slot_ctx->dev_info = 0; + pdev->device_address = 0; + + /* if device is not setup, there is no point in resetting it. */ + slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); + slot_state = get_slot_state(le32_to_cpu(slot_ctx->dev_state)); + + if (slot_state <= slot_state_default && + pdev->eps[0].ep_state & ep_halted) { + cdnsp_halt_endpoint(pdev, &pdev->eps[0], 0); + } + + /* + * during reset device command controller shall transition the + * endpoint ep0 to the running state. + */ + pdev->eps[0].ep_state &= ~(ep_stopped | ep_halted); + pdev->eps[0].ep_state |= ep_enabled; + + if (slot_state <= slot_state_default) + return 0; + + cdnsp_queue_reset_device(pdev); + cdnsp_ring_cmd_db(pdev); + ret = cdnsp_wait_for_cmd_compl(pdev); + + /* + * after reset device command all not default endpoints + * are in disabled state. + */ + for (i = 1; i < cdnsp_endpoints_num; ++i) + pdev->eps[i].ep_state |= ep_stopped; + + if (ret) + dev_err(pdev->dev, "reset device failed with error code %d", + ret); + + return ret; +} + +/* + * sets the maxpstreams field and the linear stream array field. + * sets the dequeue pointer to the stream context array. + */ +static void cdnsp_setup_streams_ep_input_ctx(struct cdnsp_device *pdev, + struct cdnsp_ep_ctx *ep_ctx, + struct cdnsp_stream_info *stream_info) +{ + u32 max_primary_streams; + + /* maxpstreams is the number of stream context array entries, not the + * number we're actually using. must be in 2^(maxpstreams + 1) format. + * fls(0) = 0, fls(0x1) = 1, fls(0x10) = 2, fls(0x100) = 3, etc. + */ + max_primary_streams = fls(stream_info->num_stream_ctxs) - 2; + ep_ctx->ep_info &= cpu_to_le32(~ep_maxpstreams_mask); + ep_ctx->ep_info |= cpu_to_le32(ep_maxpstreams(max_primary_streams) + | ep_has_lsa); + ep_ctx->deq = cpu_to_le64(stream_info->ctx_array_dma); +} + +/* + * the drivers use this function to prepare a bulk endpoints to use streams. + * + * don't allow the call to succeed if endpoint only supports one stream + * (which means it doesn't support streams at all). + */ +int cdnsp_alloc_streams(struct cdnsp_device *pdev, struct cdnsp_ep *pep) +{ + unsigned int num_streams = usb_ss_max_streams(pep->endpoint.comp_desc); + unsigned int num_stream_ctxs; + int ret; + + if (num_streams == 0) + return 0; + + if (num_streams > stream_num_streams) + return -einval; + + /* + * add two to the number of streams requested to account for + * stream 0 that is reserved for controller usage and one additional + * for task set full response. + */ + num_streams += 2; + + /* the stream context array size must be a power of two */ + num_stream_ctxs = roundup_pow_of_two(num_streams); + + ret = cdnsp_alloc_stream_info(pdev, pep, num_stream_ctxs, num_streams); + if (ret) + return ret; + + cdnsp_setup_streams_ep_input_ctx(pdev, pep->in_ctx, &pep->stream_info); + + pep->ep_state |= ep_has_streams; + pep->stream_info.td_count = 0; + pep->stream_info.first_prime_det = 0; + + /* subtract 1 for stream 0, which drivers can't use. */ + return num_streams - 1; +} + +int cdnsp_disable_slot(struct cdnsp_device *pdev) +{ + int ret; + + cdnsp_queue_slot_control(pdev, trb_disable_slot); + cdnsp_ring_cmd_db(pdev); + ret = cdnsp_wait_for_cmd_compl(pdev); + + pdev->slot_id = 0; + pdev->active_port = null; + + memset(pdev->in_ctx.bytes, 0, cdnsp_ctx_size); + memset(pdev->out_ctx.bytes, 0, cdnsp_ctx_size); + + return ret; +} + +int cdnsp_enable_slot(struct cdnsp_device *pdev) +{ + struct cdnsp_slot_ctx *slot_ctx; + int slot_state; + int ret; + + /* if device is not setup, there is no point in resetting it */ + slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); + slot_state = get_slot_state(le32_to_cpu(slot_ctx->dev_state)); + + if (slot_state != slot_state_disabled) + return 0; + + cdnsp_queue_slot_control(pdev, trb_enable_slot); + cdnsp_ring_cmd_db(pdev); + ret = cdnsp_wait_for_cmd_compl(pdev); + if (ret) + return ret; + + pdev->slot_id = 1; + + return 0; +} + +/* + * issue an address device command with bsr=0 if setup is setup_context_only + * or with bsr = 1 if set_address is setup_context_address. + */ +int cdnsp_setup_device(struct cdnsp_device *pdev, enum cdnsp_setup_dev setup) +{ + struct cdnsp_input_control_ctx *ctrl_ctx; + struct cdnsp_slot_ctx *slot_ctx; + int dev_state = 0; + int ret; + + if (!pdev->slot_id) + return -einval; + + if (!pdev->active_port->port_num) + return -einval; + + slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); + dev_state = get_slot_state(le32_to_cpu(slot_ctx->dev_state)); + + if (setup == setup_context_only && dev_state == slot_state_default) + return 0; + + slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); + ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); + + if (!slot_ctx->dev_info || dev_state == slot_state_default) { + ret = cdnsp_setup_addressable_priv_dev(pdev); + if (ret) + return ret; + } + + cdnsp_copy_ep0_dequeue_into_input_ctx(pdev); + + ctrl_ctx->add_flags = cpu_to_le32(slot_flag | ep0_flag); + ctrl_ctx->drop_flags = 0; + + cdnsp_queue_address_device(pdev, pdev->in_ctx.dma, setup); + cdnsp_ring_cmd_db(pdev); + ret = cdnsp_wait_for_cmd_compl(pdev); + + /* zero the input context control for later use. */ + ctrl_ctx->add_flags = 0; + ctrl_ctx->drop_flags = 0; + + return ret; +} + +void cdnsp_set_usb2_hardware_lpm(struct cdnsp_device *pdev, + struct usb_request *req, + int enable) +{ + if (pdev->active_port != &pdev->usb2_port || !pdev->gadget.lpm_capable) + return; + + if (enable) + writel(port_besl(cdnsp_default_besl) | port_l1s_nyet | port_hle, + &pdev->active_port->regs->portpmsc); + else + writel(port_l1s_nyet, &pdev->active_port->regs->portpmsc); +} + +static int cdnsp_get_frame(struct cdnsp_device *pdev) +{ + return readl(&pdev->run_regs->microframe_index) >> 3; +} + +static int cdnsp_gadget_ep_enable(struct usb_ep *ep, + const struct usb_endpoint_descriptor *desc) +{ + struct cdnsp_input_control_ctx *ctrl_ctx; + struct cdnsp_device *pdev; + struct cdnsp_ep *pep; + unsigned long flags; + u32 added_ctxs; + int ret; + + if (!ep || !desc || desc->bdescriptortype != usb_dt_endpoint || + !desc->wmaxpacketsize) + return -einval; + + pep = to_cdnsp_ep(ep); + pdev = pep->pdev; + + if (dev_warn_once(pdev->dev, pep->ep_state & ep_enabled, + "%s is already enabled ", pep->name)) + return 0; + + spin_lock_irqsave(&pdev->lock, flags); + + added_ctxs = cdnsp_get_endpoint_flag(desc); + if (added_ctxs == slot_flag || added_ctxs == ep0_flag) { + dev_err(pdev->dev, "error: bad endpoint number "); + ret = -einval; + goto unlock; + } + + pep->interval = desc->binterval ? bit(desc->binterval - 1) : 0; + + if (pdev->gadget.speed == usb_speed_full) { + if (usb_endpoint_type(desc) == usb_endpoint_xfer_int) + pep->interval = desc->binterval << 3; + if (usb_endpoint_type(desc) == usb_endpoint_xfer_isoc) + pep->interval = bit(desc->binterval - 1) << 3; + } + + if (usb_endpoint_type(desc) == usb_endpoint_xfer_isoc) { + if (pep->interval > bit(12)) { + dev_err(pdev->dev, "binterval %d not supported ", + desc->binterval); + ret = -einval; + goto unlock; + } + cdnsp_set_chicken_bits_2(pdev, chicken_xdma_2_tp_cache_dis); + } + + ret = cdnsp_endpoint_init(pdev, pep, gfp_atomic); + if (ret) + goto unlock; + + ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); + ctrl_ctx->add_flags = cpu_to_le32(added_ctxs); + ctrl_ctx->drop_flags = 0; + + ret = cdnsp_update_eps_configuration(pdev, pep); + if (ret) { + cdnsp_free_endpoint_rings(pdev, pep); + goto unlock; + } + + pep->ep_state |= ep_enabled; + pep->ep_state &= ~ep_stopped; + +unlock: + spin_unlock_irqrestore(&pdev->lock, flags); + + return ret; +} + +static int cdnsp_gadget_ep_disable(struct usb_ep *ep) +{ + struct cdnsp_input_control_ctx *ctrl_ctx; + struct cdnsp_request *preq; + struct cdnsp_device *pdev; + struct cdnsp_ep *pep; + unsigned long flags; + u32 drop_flag; + int ret = 0; + + if (!ep) + return -einval; + + pep = to_cdnsp_ep(ep); + pdev = pep->pdev; + + spin_lock_irqsave(&pdev->lock, flags); + + if (!(pep->ep_state & ep_enabled)) { + dev_err(pdev->dev, "%s is already disabled ", pep->name); + ret = -einval; + goto finish; + } + + cdnsp_cmd_stop_ep(pdev, pep); + pep->ep_state |= ep_dis_in_rrogress; + cdnsp_cmd_flush_ep(pdev, pep); + + /* remove all queued usb requests. */ + while (!list_empty(&pep->pending_list)) { + preq = next_request(&pep->pending_list); + cdnsp_ep_dequeue(pep, preq); + } + + cdnsp_invalidate_ep_events(pdev, pep); + + pep->ep_state &= ~ep_dis_in_rrogress; + drop_flag = cdnsp_get_endpoint_flag(pep->endpoint.desc); + ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); + ctrl_ctx->drop_flags = cpu_to_le32(drop_flag); + ctrl_ctx->add_flags = 0; + + cdnsp_endpoint_zero(pdev, pep); + + ret = cdnsp_update_eps_configuration(pdev, pep); + cdnsp_free_endpoint_rings(pdev, pep); + + pep->ep_state &= ~ep_enabled; + pep->ep_state |= ep_stopped; + +finish: + spin_unlock_irqrestore(&pdev->lock, flags); + + return ret; +} + +static struct usb_request *cdnsp_gadget_ep_alloc_request(struct usb_ep *ep, + gfp_t gfp_flags) +{ + struct cdnsp_ep *pep = to_cdnsp_ep(ep); + struct cdnsp_request *preq; + + preq = kzalloc(sizeof(*preq), gfp_flags); + if (!preq) + return null; + + preq->epnum = pep->number; + preq->pep = pep; + + return &preq->request; +} + +static void cdnsp_gadget_ep_free_request(struct usb_ep *ep, + struct usb_request *request) +{ + struct cdnsp_request *preq = to_cdnsp_request(request); + + kfree(preq); +} + +static int cdnsp_gadget_ep_queue(struct usb_ep *ep, + struct usb_request *request, + gfp_t gfp_flags) +{ + struct cdnsp_request *preq; + struct cdnsp_device *pdev; + struct cdnsp_ep *pep; + unsigned long flags; + int ret; + + if (!request || !ep) + return -einval; + + pep = to_cdnsp_ep(ep); + pdev = pep->pdev; + + if (!(pep->ep_state & ep_enabled)) { + dev_err(pdev->dev, "%s: can't queue to disabled endpoint ", + pep->name); + return -einval; + } + + preq = to_cdnsp_request(request); + spin_lock_irqsave(&pdev->lock, flags); + ret = cdnsp_ep_enqueue(pep, preq); + spin_unlock_irqrestore(&pdev->lock, flags); + + return ret; +} + +static int cdnsp_gadget_ep_dequeue(struct usb_ep *ep, + struct usb_request *request) +{ + struct cdnsp_ep *pep = to_cdnsp_ep(ep); + struct cdnsp_device *pdev = pep->pdev; + unsigned long flags; + int ret; + + if (!pep->endpoint.desc) { + dev_err(pdev->dev, + "%s: can't dequeue to disabled endpoint ", + pep->name); + return -eshutdown; + } + + spin_lock_irqsave(&pdev->lock, flags); + ret = cdnsp_ep_dequeue(pep, to_cdnsp_request(request)); + spin_unlock_irqrestore(&pdev->lock, flags); + + return ret; +} + +static int cdnsp_gadget_ep_set_halt(struct usb_ep *ep, int value) +{ + struct cdnsp_ep *pep = to_cdnsp_ep(ep); + struct cdnsp_device *pdev = pep->pdev; + struct cdnsp_request *preq; + unsigned long flags = 0; + int ret; + + spin_lock_irqsave(&pdev->lock, flags); + + preq = next_request(&pep->pending_list); + if (value) { + if (preq) { + ret = -eagain; + goto done; + } + } + + ret = cdnsp_halt_endpoint(pdev, pep, value); + +done: + spin_unlock_irqrestore(&pdev->lock, flags); + return ret; +} + +static int cdnsp_gadget_ep_set_wedge(struct usb_ep *ep) +{ + struct cdnsp_ep *pep = to_cdnsp_ep(ep); + struct cdnsp_device *pdev = pep->pdev; + unsigned long flags = 0; + int ret; + + spin_lock_irqsave(&pdev->lock, flags); + pep->ep_state |= ep_wedge; + ret = cdnsp_halt_endpoint(pdev, pep, 1); + spin_unlock_irqrestore(&pdev->lock, flags); + + return ret; +} + +static const struct usb_ep_ops cdnsp_gadget_ep0_ops = { + .enable = cdnsp_gadget_ep_enable, + .disable = cdnsp_gadget_ep_disable, + .alloc_request = cdnsp_gadget_ep_alloc_request, + .free_request = cdnsp_gadget_ep_free_request, + .queue = cdnsp_gadget_ep_queue, + .dequeue = cdnsp_gadget_ep_dequeue, + .set_halt = cdnsp_gadget_ep_set_halt, + .set_wedge = cdnsp_gadget_ep_set_wedge, +}; + +static const struct usb_ep_ops cdnsp_gadget_ep_ops = { + .enable = cdnsp_gadget_ep_enable, + .disable = cdnsp_gadget_ep_disable, + .alloc_request = cdnsp_gadget_ep_alloc_request, + .free_request = cdnsp_gadget_ep_free_request, + .queue = cdnsp_gadget_ep_queue, + .dequeue = cdnsp_gadget_ep_dequeue, + .set_halt = cdnsp_gadget_ep_set_halt, + .set_wedge = cdnsp_gadget_ep_set_wedge, +}; + +void cdnsp_gadget_giveback(struct cdnsp_ep *pep, + struct cdnsp_request *preq, + int status) +{ + struct cdnsp_device *pdev = pep->pdev; + + list_del(&preq->list); + + if (preq->request.status == -einprogress) + preq->request.status = status; + + usb_gadget_unmap_request_by_dev(pdev->dev, &preq->request, + preq->direction); + + if (preq != &pdev->ep0_preq) { + spin_unlock(&pdev->lock); + usb_gadget_giveback_request(&pep->endpoint, &preq->request); + spin_lock(&pdev->lock); + } +} + +static struct usb_endpoint_descriptor cdnsp_gadget_ep0_desc = { + .blength = usb_dt_endpoint_size, + .bdescriptortype = usb_dt_endpoint, + .bmattributes = usb_endpoint_xfer_control, +}; + +static int cdnsp_run(struct cdnsp_device *pdev, + enum usb_device_speed speed) +{ + u32 fs_speed = 0; + u64 temp_64; + u32 temp; + int ret; + + temp_64 = cdnsp_read_64(&pdev->ir_set->erst_dequeue); + temp_64 &= ~erst_ptr_mask; + temp = readl(&pdev->ir_set->irq_control); + temp &= ~imod_interval_mask; + temp |= ((imod_default_interval / 250) & imod_interval_mask); + writel(temp, &pdev->ir_set->irq_control); + + temp = readl(&pdev->port3x_regs->mode_addr); + + switch (speed) { + case usb_speed_super_plus: + temp |= cfg_3xport_ssp_support; + break; + case usb_speed_super: + temp &= ~cfg_3xport_ssp_support; + break; + case usb_speed_high: + break; + case usb_speed_full: + fs_speed = port_reg6_force_fs; + break; + default: + dev_err(pdev->dev, "invalid maximum_speed parameter %d ", + speed); + fallthrough; + case usb_speed_unknown: + /* default to superspeed. */ + speed = usb_speed_super; + break; + } + + if (speed >= usb_speed_super) { + writel(temp, &pdev->port3x_regs->mode_addr); + cdnsp_set_link_state(pdev, &pdev->usb3_port.regs->portsc, + xdev_rxdetect); + } else { + cdnsp_disable_port(pdev, &pdev->usb3_port.regs->portsc); + } + + cdnsp_set_link_state(pdev, &pdev->usb2_port.regs->portsc, + xdev_rxdetect); + + cdnsp_gadget_ep0_desc.wmaxpacketsize = cpu_to_le16(512); + + writel(port_reg6_l1_l0_hw_en | fs_speed, &pdev->port20_regs->port_reg6); + + ret = cdnsp_start(pdev); + if (ret) { + ret = -enodev; + goto err; + } + + temp = readl(&pdev->op_regs->command); + temp |= (cmd_inte); + writel(temp, &pdev->op_regs->command); + + temp = readl(&pdev->ir_set->irq_pending); + writel(iman_ie_set(temp), &pdev->ir_set->irq_pending); + + return 0; +err: + cdnsp_halt(pdev); + return ret; +} + +static int cdnsp_gadget_udc_start(struct usb_gadget *g, + struct usb_gadget_driver *driver) +{ + enum usb_device_speed max_speed = driver->max_speed; + struct cdnsp_device *pdev = gadget_to_cdnsp(g); + unsigned long flags; + int ret; + + spin_lock_irqsave(&pdev->lock, flags); + pdev->gadget_driver = driver; + + /* limit speed if necessary */ + max_speed = min(driver->max_speed, g->max_speed); + ret = cdnsp_run(pdev, max_speed); + + spin_unlock_irqrestore(&pdev->lock, flags); + + return ret; +} + +/* + * update event ring dequeue pointer: + * - when all events have finished + * - to avoid "event ring full error" condition + */ +void cdnsp_update_erst_dequeue(struct cdnsp_device *pdev, + union cdnsp_trb *event_ring_deq, + u8 clear_ehb) +{ + u64 temp_64; + dma_addr_t deq; + + temp_64 = cdnsp_read_64(&pdev->ir_set->erst_dequeue); + + /* if necessary, update the hw's version of the event ring deq ptr. */ + if (event_ring_deq != pdev->event_ring->dequeue) { + deq = cdnsp_trb_virt_to_dma(pdev->event_ring->deq_seg, + pdev->event_ring->dequeue); + temp_64 &= erst_ptr_mask; + temp_64 |= ((u64)deq & (u64)~erst_ptr_mask); + } + + /* clear the event handler busy flag (rw1c). */ + if (clear_ehb) + temp_64 |= erst_ehb; + else + temp_64 &= ~erst_ehb; + + cdnsp_write_64(temp_64, &pdev->ir_set->erst_dequeue); +} + +static void cdnsp_clear_cmd_ring(struct cdnsp_device *pdev) +{ + struct cdnsp_segment *seg; + u64 val_64; + int i; + + cdnsp_initialize_ring_info(pdev->cmd_ring); + + seg = pdev->cmd_ring->first_seg; + for (i = 0; i < pdev->cmd_ring->num_segs; i++) { + memset(seg->trbs, 0, + sizeof(union cdnsp_trb) * (trbs_per_segment - 1)); + seg = seg->next; + } + + /* set the address in the command ring control register. */ + val_64 = cdnsp_read_64(&pdev->op_regs->cmd_ring); + val_64 = (val_64 & (u64)cmd_ring_rsvd_bits) | + (pdev->cmd_ring->first_seg->dma & (u64)~cmd_ring_rsvd_bits) | + pdev->cmd_ring->cycle_state; + cdnsp_write_64(val_64, &pdev->op_regs->cmd_ring); +} + +static void cdnsp_consume_all_events(struct cdnsp_device *pdev) +{ + struct cdnsp_segment *event_deq_seg; + union cdnsp_trb *event_ring_deq; + union cdnsp_trb *event; + u32 cycle_bit; + + event_ring_deq = pdev->event_ring->dequeue; + event_deq_seg = pdev->event_ring->deq_seg; + event = pdev->event_ring->dequeue; + + /* update ring dequeue pointer. */ + while (1) { + cycle_bit = (le32_to_cpu(event->event_cmd.flags) & trb_cycle); + + /* does the controller or driver own the trb? */ + if (cycle_bit != pdev->event_ring->cycle_state) + break; + + cdnsp_inc_deq(pdev, pdev->event_ring); + + if (!cdnsp_last_trb_on_seg(event_deq_seg, event)) { + event++; + continue; + } + + if (cdnsp_last_trb_on_ring(pdev->event_ring, event_deq_seg, + event)) + cycle_bit ^= 1; + + event_deq_seg = event_deq_seg->next; + event = event_deq_seg->trbs; + } + + cdnsp_update_erst_dequeue(pdev, event_ring_deq, 1); +} + +static void cdnsp_stop(struct cdnsp_device *pdev) +{ + u32 temp; + + cdnsp_cmd_flush_ep(pdev, &pdev->eps[0]); + + /* remove internally queued request for ep0. */ + if (!list_empty(&pdev->eps[0].pending_list)) { + struct cdnsp_request *req; + + req = next_request(&pdev->eps[0].pending_list); + if (req == &pdev->ep0_preq) + cdnsp_ep_dequeue(&pdev->eps[0], req); + } + + cdnsp_disable_port(pdev, &pdev->usb2_port.regs->portsc); + cdnsp_disable_port(pdev, &pdev->usb3_port.regs->portsc); + cdnsp_disable_slot(pdev); + cdnsp_halt(pdev); + + temp = readl(&pdev->op_regs->status); + writel((temp & ~0x1fff) | sts_eint, &pdev->op_regs->status); + temp = readl(&pdev->ir_set->irq_pending); + writel(iman_ie_clear(temp), &pdev->ir_set->irq_pending); + + cdnsp_clear_port_change_bit(pdev, &pdev->usb2_port.regs->portsc); + cdnsp_clear_port_change_bit(pdev, &pdev->usb3_port.regs->portsc); + + /* clear interrupt line */ + temp = readl(&pdev->ir_set->irq_pending); + temp |= iman_ip; + writel(temp, &pdev->ir_set->irq_pending); + + cdnsp_consume_all_events(pdev); + cdnsp_clear_cmd_ring(pdev); +} + +/* + * stop controller. + * this function is called by the gadget core when the driver is removed. + * disable slot, disable irqs, and quiesce the controller. + */ +static int cdnsp_gadget_udc_stop(struct usb_gadget *g) +{ + struct cdnsp_device *pdev = gadget_to_cdnsp(g); + unsigned long flags; + + spin_lock_irqsave(&pdev->lock, flags); + cdnsp_stop(pdev); + pdev->gadget_driver = null; + spin_unlock_irqrestore(&pdev->lock, flags); + + return 0; +} + +static int cdnsp_gadget_get_frame(struct usb_gadget *g) +{ + struct cdnsp_device *pdev = gadget_to_cdnsp(g); + + return cdnsp_get_frame(pdev); +} + +static void __cdnsp_gadget_wakeup(struct cdnsp_device *pdev) +{ + struct cdnsp_port_regs __iomem *port_regs; + u32 portpm, portsc; + + port_regs = pdev->active_port->regs; + portsc = readl(&port_regs->portsc) & port_pls_mask; + + /* remote wakeup feature is not enabled by host. */ + if (pdev->gadget.speed < usb_speed_super && portsc == xdev_u2) { + portpm = readl(&port_regs->portpmsc); + + if (!(portpm & port_rwe)) + return; + } + + if (portsc == xdev_u3 && !pdev->may_wakeup) + return; + + cdnsp_set_link_state(pdev, &port_regs->portsc, xdev_u0); + + pdev->cdnsp_state |= cdnsp_wakeup_pending; +} + +static int cdnsp_gadget_wakeup(struct usb_gadget *g) +{ + struct cdnsp_device *pdev = gadget_to_cdnsp(g); + unsigned long flags; + + spin_lock_irqsave(&pdev->lock, flags); + __cdnsp_gadget_wakeup(pdev); + spin_unlock_irqrestore(&pdev->lock, flags); + + return 0; +} + +static int cdnsp_gadget_set_selfpowered(struct usb_gadget *g, + int is_selfpowered) +{ + struct cdnsp_device *pdev = gadget_to_cdnsp(g); + unsigned long flags; + + spin_lock_irqsave(&pdev->lock, flags); + g->is_selfpowered = !!is_selfpowered; + spin_unlock_irqrestore(&pdev->lock, flags); + + return 0; +} + +static int cdnsp_gadget_pullup(struct usb_gadget *gadget, int is_on) +{ + struct cdnsp_device *pdev = gadget_to_cdnsp(gadget); + struct cdns *cdns = dev_get_drvdata(pdev->dev); + + if (!is_on) { + cdnsp_reset_device(pdev); + cdns_clear_vbus(cdns); + } else { + cdns_set_vbus(cdns); + } + return 0; +} + +const struct usb_gadget_ops cdnsp_gadget_ops = { + .get_frame = cdnsp_gadget_get_frame, + .wakeup = cdnsp_gadget_wakeup, + .set_selfpowered = cdnsp_gadget_set_selfpowered, + .pullup = cdnsp_gadget_pullup, + .udc_start = cdnsp_gadget_udc_start, + .udc_stop = cdnsp_gadget_udc_stop, +}; + +static void cdnsp_get_ep_buffering(struct cdnsp_device *pdev, + struct cdnsp_ep *pep) +{ + void __iomem *reg = &pdev->cap_regs->hc_capbase; + int endpoints; + + reg += cdnsp_find_next_ext_cap(reg, 0, xbuf_cap_id); + + if (!pep->direction) { + pep->buffering = readl(reg + xbuf_rx_tag_mask_0_offset); + pep->buffering_period = readl(reg + xbuf_rx_tag_mask_1_offset); + pep->buffering = (pep->buffering + 1) / 2; + pep->buffering_period = (pep->buffering_period + 1) / 2; + return; + } + + endpoints = hcs_endpoints(readl(&pdev->hcs_params1)) / 2; + + /* set to xbuf_tx_tag_mask_0 register. */ + reg += xbuf_tx_cmd_offset + (endpoints * 2 + 2) * sizeof(u32); + /* set reg to xbuf_tx_tag_mask_n related with this endpoint. */ + reg += pep->number * sizeof(u32) * 2; + + pep->buffering = (readl(reg) + 1) / 2; + pep->buffering_period = pep->buffering; +} + +static int cdnsp_gadget_init_endpoints(struct cdnsp_device *pdev) +{ + int max_streams = hcc_max_psa(pdev->hcc_params); + struct cdnsp_ep *pep; + int i; + + init_list_head(&pdev->gadget.ep_list); + + if (max_streams < stream_log_streams) { + dev_err(pdev->dev, "stream size %d not supported ", + max_streams); + return -einval; + } + + max_streams = stream_log_streams; + + for (i = 0; i < cdnsp_endpoints_num; i++) { + bool direction = !(i & 1); /* start from out endpoint. */ + u8 epnum = ((i + 1) >> 1); + + if (!cdnsp_if_ep_exist(pdev, epnum, direction)) + continue; + + pep = &pdev->eps[i]; + pep->pdev = pdev; + pep->number = epnum; + pep->direction = direction; /* 0 for out, 1 for in. */ + + /* + * ep0 is bidirectional, so ep0in and ep0out are represented by + * pdev->eps[0] + */ + if (epnum == 0) { + snprintf(pep->name, sizeof(pep->name), "ep%d%s", + epnum, "bidir"); + + pep->idx = 0; + usb_ep_set_maxpacket_limit(&pep->endpoint, 512); + pep->endpoint.maxburst = 1; + pep->endpoint.ops = &cdnsp_gadget_ep0_ops; + pep->endpoint.desc = &cdnsp_gadget_ep0_desc; + pep->endpoint.comp_desc = null; + pep->endpoint.caps.type_control = true; + pep->endpoint.caps.dir_in = true; + pep->endpoint.caps.dir_out = true; + + pdev->ep0_preq.epnum = pep->number; + pdev->ep0_preq.pep = pep; + pdev->gadget.ep0 = &pep->endpoint; + } else { + snprintf(pep->name, sizeof(pep->name), "ep%d%s", + epnum, (pep->direction) ? "in" : "out"); + + pep->idx = (epnum * 2 + (direction ? 1 : 0)) - 1; + usb_ep_set_maxpacket_limit(&pep->endpoint, 1024); + + pep->endpoint.max_streams = max_streams; + pep->endpoint.ops = &cdnsp_gadget_ep_ops; + list_add_tail(&pep->endpoint.ep_list, + &pdev->gadget.ep_list); + + pep->endpoint.caps.type_iso = true; + pep->endpoint.caps.type_bulk = true; + pep->endpoint.caps.type_int = true; + + pep->endpoint.caps.dir_in = direction; + pep->endpoint.caps.dir_out = !direction; + } + + pep->endpoint.name = pep->name; + pep->in_ctx = cdnsp_get_ep_ctx(&pdev->in_ctx, pep->idx); + pep->out_ctx = cdnsp_get_ep_ctx(&pdev->out_ctx, pep->idx); + cdnsp_get_ep_buffering(pdev, pep); + + dev_dbg(pdev->dev, "init %s, mps: %04x suptype: " + "ctrl: %s, int: %s, bulk: %s, isoc %s, " + "supdir in: %s, out: %s ", + pep->name, 1024, + (pep->endpoint.caps.type_control) ? "yes" : "no", + (pep->endpoint.caps.type_int) ? "yes" : "no", + (pep->endpoint.caps.type_bulk) ? "yes" : "no", + (pep->endpoint.caps.type_iso) ? "yes" : "no", + (pep->endpoint.caps.dir_in) ? "yes" : "no", + (pep->endpoint.caps.dir_out) ? "yes" : "no"); + + init_list_head(&pep->pending_list); + } + + return 0; +} + +static void cdnsp_gadget_free_endpoints(struct cdnsp_device *pdev) +{ + struct cdnsp_ep *pep; + int i; + + for (i = 0; i < cdnsp_endpoints_num; i++) { + pep = &pdev->eps[i]; + if (pep->number != 0 && pep->out_ctx) + list_del(&pep->endpoint.ep_list); + } +} + +void cdnsp_disconnect_gadget(struct cdnsp_device *pdev) +{ + pdev->cdnsp_state |= cdnsp_state_disconnect_pending; + + if (pdev->gadget_driver && pdev->gadget_driver->disconnect) { + spin_unlock(&pdev->lock); + pdev->gadget_driver->disconnect(&pdev->gadget); + spin_lock(&pdev->lock); + } + + pdev->gadget.speed = usb_speed_unknown; + usb_gadget_set_state(&pdev->gadget, usb_state_notattached); + + pdev->cdnsp_state &= ~cdnsp_state_disconnect_pending; +} + +void cdnsp_suspend_gadget(struct cdnsp_device *pdev) +{ + if (pdev->gadget_driver && pdev->gadget_driver->suspend) { + spin_unlock(&pdev->lock); + pdev->gadget_driver->suspend(&pdev->gadget); + spin_lock(&pdev->lock); + } +} + +void cdnsp_resume_gadget(struct cdnsp_device *pdev) +{ + if (pdev->gadget_driver && pdev->gadget_driver->resume) { + spin_unlock(&pdev->lock); + pdev->gadget_driver->resume(&pdev->gadget); + spin_lock(&pdev->lock); + } +} + +void cdnsp_irq_reset(struct cdnsp_device *pdev) +{ + struct cdnsp_port_regs __iomem *port_regs; + + cdnsp_reset_device(pdev); + + port_regs = pdev->active_port->regs; + pdev->gadget.speed = cdnsp_port_speed(readl(port_regs)); + + spin_unlock(&pdev->lock); + usb_gadget_udc_reset(&pdev->gadget, pdev->gadget_driver); + spin_lock(&pdev->lock); + + switch (pdev->gadget.speed) { + case usb_speed_super_plus: + case usb_speed_super: + cdnsp_gadget_ep0_desc.wmaxpacketsize = cpu_to_le16(512); + pdev->gadget.ep0->maxpacket = 512; + break; + case usb_speed_high: + case usb_speed_full: + cdnsp_gadget_ep0_desc.wmaxpacketsize = cpu_to_le16(64); + pdev->gadget.ep0->maxpacket = 64; + break; + default: + /* low speed is not supported. */ + dev_err(pdev->dev, "unknown device speed "); + break; + } + + cdnsp_clear_chicken_bits_2(pdev, chicken_xdma_2_tp_cache_dis); + cdnsp_setup_device(pdev, setup_context_only); + usb_gadget_set_state(&pdev->gadget, usb_state_default); +} + +static void cdnsp_get_rev_cap(struct cdnsp_device *pdev) +{ + void __iomem *reg = &pdev->cap_regs->hc_capbase; + struct cdnsp_rev_cap *rev_cap; + + reg += cdnsp_find_next_ext_cap(reg, 0, rtl_rev_cap); + rev_cap = reg; + + pdev->rev_cap.ctrl_revision = readl(&rev_cap->ctrl_revision); + pdev->rev_cap.rtl_revision = readl(&rev_cap->rtl_revision); + pdev->rev_cap.ep_supported = readl(&rev_cap->ep_supported); + pdev->rev_cap.ext_cap = readl(&rev_cap->ext_cap); + pdev->rev_cap.rx_buff_size = readl(&rev_cap->rx_buff_size); + pdev->rev_cap.tx_buff_size = readl(&rev_cap->tx_buff_size); + + dev_info(pdev->dev, "rev: %08x/%08x, eps: %08x, buff: %08x/%08x ", + pdev->rev_cap.ctrl_revision, pdev->rev_cap.rtl_revision, + pdev->rev_cap.ep_supported, pdev->rev_cap.rx_buff_size, + pdev->rev_cap.tx_buff_size); +} + +static int cdnsp_gen_setup(struct cdnsp_device *pdev) +{ + int ret; + u32 reg; + + pdev->cap_regs = pdev->regs; + pdev->op_regs = pdev->regs + + hc_length(readl(&pdev->cap_regs->hc_capbase)); + pdev->run_regs = pdev->regs + + (readl(&pdev->cap_regs->run_regs_off) & rtsoff_mask); + + /* cache read-only capability registers */ + pdev->hcs_params1 = readl(&pdev->cap_regs->hcs_params1); + pdev->hcc_params = readl(&pdev->cap_regs->hc_capbase); + pdev->hci_version = hc_version(pdev->hcc_params); + pdev->hcc_params = readl(&pdev->cap_regs->hcc_params); + + cdnsp_get_rev_cap(pdev); + + /* make sure the device controller is halted. */ + ret = cdnsp_halt(pdev); + if (ret) + return ret; + + /* reset the internal controller memory state and registers. */ + ret = cdnsp_reset(pdev); + if (ret) + return ret; + + /* + * set dma_mask and coherent_dma_mask to 64-bits, + * if controller supports 64-bit addressing. + */ + if (hcc_64bit_addr(pdev->hcc_params) && + !dma_set_mask(pdev->dev, dma_bit_mask(64))) { + dev_dbg(pdev->dev, "enabling 64-bit dma addresses. "); + dma_set_coherent_mask(pdev->dev, dma_bit_mask(64)); + } else { + /* + * this is to avoid error in cases where a 32-bit usb + * controller is used on a 64-bit capable system. + */ + ret = dma_set_mask(pdev->dev, dma_bit_mask(32)); + if (ret) + return ret; + + dev_dbg(pdev->dev, "enabling 32-bit dma addresses. "); + dma_set_coherent_mask(pdev->dev, dma_bit_mask(32)); + } + + spin_lock_init(&pdev->lock); + + ret = cdnsp_mem_init(pdev, gfp_kernel); + if (ret) + return ret; + + /* + * software workaround for u1: after transition + * to u1 the controller starts gating clock, and in some cases, + * it causes that controller stack. + */ + reg = readl(&pdev->port3x_regs->mode_2); + reg &= ~cfg_3xport_u1_pipe_clk_gate_en; + writel(reg, &pdev->port3x_regs->mode_2); + + return 0; +} + +static int __cdnsp_gadget_init(struct cdns *cdns) +{ + struct cdnsp_device *pdev; + u32 max_speed; + int ret = -enomem; + + cdns_drd_gadget_on(cdns); + + pdev = kzalloc(sizeof(*pdev), gfp_kernel); + if (!pdev) + return -enomem; + + pm_runtime_get_sync(cdns->dev); + + cdns->gadget_dev = pdev; + pdev->dev = cdns->dev; + pdev->regs = cdns->dev_regs; + max_speed = usb_get_maximum_speed(cdns->dev); + + switch (max_speed) { + case usb_speed_full: + case usb_speed_high: + case usb_speed_super: + case usb_speed_super_plus: + break; + default: + dev_err(cdns->dev, "invalid speed parameter %d ", max_speed); + fallthrough; + case usb_speed_unknown: + /* default to ssp */ + max_speed = usb_speed_super_plus; + break; + } + + pdev->gadget.ops = &cdnsp_gadget_ops; + pdev->gadget.name = "cdnsp-gadget"; + pdev->gadget.speed = usb_speed_unknown; + pdev->gadget.sg_supported = 1; + pdev->gadget.max_speed = usb_speed_super_plus; + pdev->gadget.lpm_capable = 1; + + pdev->setup_buf = kzalloc(cdnsp_ep0_setup_size, gfp_kernel); + if (!pdev->setup_buf) + goto free_pdev; + + /* + * controller supports not aligned buffer but it should improve + * performance. + */ + pdev->gadget.quirk_ep_out_aligned_size = true; + + ret = cdnsp_gen_setup(pdev); + if (ret) { + dev_err(pdev->dev, "generic initialization failed %d ", ret); + goto free_setup; + } + + ret = cdnsp_gadget_init_endpoints(pdev); + if (ret) { + dev_err(pdev->dev, "failed to initialize endpoints "); + goto halt_pdev; + } + + ret = usb_add_gadget_udc(pdev->dev, &pdev->gadget); + if (ret) { + dev_err(pdev->dev, "failed to register udc "); + goto free_endpoints; + } + + ret = devm_request_threaded_irq(pdev->dev, cdns->dev_irq, + cdnsp_irq_handler, + cdnsp_thread_irq_handler, irqf_shared, + dev_name(pdev->dev), pdev); + if (ret) + goto del_gadget; + + return 0; + +del_gadget: + usb_del_gadget_udc(&pdev->gadget); +free_endpoints: + cdnsp_gadget_free_endpoints(pdev); +halt_pdev: + cdnsp_halt(pdev); + cdnsp_reset(pdev); + cdnsp_mem_cleanup(pdev); +free_setup: + kfree(pdev->setup_buf); +free_pdev: + kfree(pdev); + + return ret; +} + +static void cdnsp_gadget_exit(struct cdns *cdns) +{ + struct cdnsp_device *pdev = cdns->gadget_dev; + + devm_free_irq(pdev->dev, cdns->dev_irq, pdev); + pm_runtime_mark_last_busy(cdns->dev); + pm_runtime_put_autosuspend(cdns->dev); + usb_del_gadget_udc(&pdev->gadget); + cdnsp_gadget_free_endpoints(pdev); + cdnsp_mem_cleanup(pdev); + kfree(pdev); + cdns->gadget_dev = null; + cdns_drd_gadget_off(cdns); +} + +static int cdnsp_gadget_suspend(struct cdns *cdns, bool do_wakeup) +{ + struct cdnsp_device *pdev = cdns->gadget_dev; + unsigned long flags; + + if (pdev->link_state == xdev_u3) + return 0; + + spin_lock_irqsave(&pdev->lock, flags); + cdnsp_disconnect_gadget(pdev); + cdnsp_stop(pdev); + spin_unlock_irqrestore(&pdev->lock, flags); + + return 0; +} + +static int cdnsp_gadget_resume(struct cdns *cdns, bool hibernated) +{ + struct cdnsp_device *pdev = cdns->gadget_dev; + enum usb_device_speed max_speed; + unsigned long flags; + int ret; + + if (!pdev->gadget_driver) + return 0; + + spin_lock_irqsave(&pdev->lock, flags); + max_speed = pdev->gadget_driver->max_speed; + + /* limit speed if necessary. */ + max_speed = min(max_speed, pdev->gadget.max_speed); + + ret = cdnsp_run(pdev, max_speed); + + if (pdev->link_state == xdev_u3) + __cdnsp_gadget_wakeup(pdev); + + spin_unlock_irqrestore(&pdev->lock, flags); + + return ret; +} + +/** + * cdnsp_gadget_init - initialize device structure + * @cdns: cdnsp instance + * + * this function initializes the gadget. + */ +int cdnsp_gadget_init(struct cdns *cdns) +{ + struct cdns_role_driver *rdrv; + + rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), gfp_kernel); + if (!rdrv) + return -enomem; + + rdrv->start = __cdnsp_gadget_init; + rdrv->stop = cdnsp_gadget_exit; + rdrv->suspend = cdnsp_gadget_suspend; + rdrv->resume = cdnsp_gadget_resume; + rdrv->state = cdns_role_state_inactive; + rdrv->name = "gadget"; + cdns->roles[usb_role_device] = rdrv; + + return 0; +} diff --git a/drivers/usb/cdns3/cdnsp-gadget.h b/drivers/usb/cdns3/cdnsp-gadget.h --- a/drivers/usb/cdns3/cdnsp-gadget.h +++ b/drivers/usb/cdns3/cdnsp-gadget.h +/* + * registers should always be accessed with double word or quad word accesses. + * + * registers with 64-bit address pointers should be written to with + * dword accesses by writing the low dword first (ptr[0]), then the high dword + * (ptr[1]) second. controller implementations that do not support 64-bit + * address pointers will ignore the high dword, and write order is irrelevant. + */ +static inline u64 cdnsp_read_64(__le64 __iomem *regs) +{ + return lo_hi_readq(regs); +} + +static inline void cdnsp_write_64(const u64 val, __le64 __iomem *regs) +{ + lo_hi_writeq(val, regs); +} + +/* cdnsp memory management functions. */ +void cdnsp_mem_cleanup(struct cdnsp_device *pdev); +int cdnsp_mem_init(struct cdnsp_device *pdev, gfp_t flags); +int cdnsp_setup_addressable_priv_dev(struct cdnsp_device *pdev); +void cdnsp_copy_ep0_dequeue_into_input_ctx(struct cdnsp_device *pdev); +void cdnsp_endpoint_zero(struct cdnsp_device *pdev, struct cdnsp_ep *ep); +int cdnsp_endpoint_init(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, + gfp_t mem_flags); +int cdnsp_ring_expansion(struct cdnsp_device *pdev, + struct cdnsp_ring *ring, + unsigned int num_trbs, gfp_t flags); +struct cdnsp_ring *cdnsp_dma_to_transfer_ring(struct cdnsp_ep *ep, u64 address); +int cdnsp_alloc_stream_info(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, + unsigned int num_stream_ctxs, + unsigned int num_streams); +int cdnsp_alloc_streams(struct cdnsp_device *pdev, struct cdnsp_ep *pep); +void cdnsp_free_endpoint_rings(struct cdnsp_device *pdev, struct cdnsp_ep *pep); + +/* device controller glue. */ +int cdnsp_find_next_ext_cap(void __iomem *base, u32 start, int id); +int cdnsp_halt(struct cdnsp_device *pdev); +void cdnsp_died(struct cdnsp_device *pdev); +int cdnsp_reset(struct cdnsp_device *pdev); +irqreturn_t cdnsp_irq_handler(int irq, void *priv); +int cdnsp_setup_device(struct cdnsp_device *pdev, enum cdnsp_setup_dev setup); +void cdnsp_set_usb2_hardware_lpm(struct cdnsp_device *usbsssp_data, + struct usb_request *req, int enable); +irqreturn_t cdnsp_thread_irq_handler(int irq, void *data); + +/* ring, segment, trb, and td functions. */ +dma_addr_t cdnsp_trb_virt_to_dma(struct cdnsp_segment *seg, + union cdnsp_trb *trb); +bool cdnsp_last_trb_on_seg(struct cdnsp_segment *seg, union cdnsp_trb *trb); +bool cdnsp_last_trb_on_ring(struct cdnsp_ring *ring, + struct cdnsp_segment *seg, + union cdnsp_trb *trb); +int cdnsp_wait_for_cmd_compl(struct cdnsp_device *pdev); +void cdnsp_update_erst_dequeue(struct cdnsp_device *pdev, + union cdnsp_trb *event_ring_deq, + u8 clear_ehb); +void cdnsp_initialize_ring_info(struct cdnsp_ring *ring); +void cdnsp_ring_cmd_db(struct cdnsp_device *pdev); +void cdnsp_queue_slot_control(struct cdnsp_device *pdev, u32 trb_type); +void cdnsp_queue_address_device(struct cdnsp_device *pdev, + dma_addr_t in_ctx_ptr, + enum cdnsp_setup_dev setup); +void cdnsp_queue_stop_endpoint(struct cdnsp_device *pdev, + unsigned int ep_index); +int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq); +int cdnsp_queue_bulk_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq); +int cdnsp_queue_isoc_tx_prepare(struct cdnsp_device *pdev, + struct cdnsp_request *preq); +void cdnsp_queue_configure_endpoint(struct cdnsp_device *pdev, + dma_addr_t in_ctx_ptr); +void cdnsp_queue_reset_ep(struct cdnsp_device *pdev, unsigned int ep_index); +void cdnsp_queue_halt_endpoint(struct cdnsp_device *pdev, + unsigned int ep_index); +void cdnsp_queue_flush_endpoint(struct cdnsp_device *pdev, + unsigned int ep_index); +void cdnsp_force_header_wakeup(struct cdnsp_device *pdev, int intf_num); +void cdnsp_queue_reset_device(struct cdnsp_device *pdev); +void cdnsp_queue_new_dequeue_state(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, + struct cdnsp_dequeue_state *deq_state); +void cdnsp_ring_doorbell_for_active_rings(struct cdnsp_device *pdev, + struct cdnsp_ep *pep); +void cdnsp_inc_deq(struct cdnsp_device *pdev, struct cdnsp_ring *ring); +void cdnsp_set_link_state(struct cdnsp_device *pdev, + __le32 __iomem *port_regs, u32 link_state); +u32 cdnsp_port_state_to_neutral(u32 state); + +/* cdnsp device controller contexts. */ +int cdnsp_enable_slot(struct cdnsp_device *pdev); +int cdnsp_disable_slot(struct cdnsp_device *pdev); +struct cdnsp_input_control_ctx + *cdnsp_get_input_control_ctx(struct cdnsp_container_ctx *ctx); +struct cdnsp_slot_ctx *cdnsp_get_slot_ctx(struct cdnsp_container_ctx *ctx); +struct cdnsp_ep_ctx *cdnsp_get_ep_ctx(struct cdnsp_container_ctx *ctx, + unsigned int ep_index); +/* cdnsp gadget interface. */ +void cdnsp_suspend_gadget(struct cdnsp_device *pdev); +void cdnsp_resume_gadget(struct cdnsp_device *pdev); +void cdnsp_disconnect_gadget(struct cdnsp_device *pdev); +void cdnsp_gadget_giveback(struct cdnsp_ep *pep, struct cdnsp_request *preq, + int status); +int cdnsp_ep_enqueue(struct cdnsp_ep *pep, struct cdnsp_request *preq); +int cdnsp_ep_dequeue(struct cdnsp_ep *pep, struct cdnsp_request *preq); +unsigned int cdnsp_port_speed(unsigned int port_status); +void cdnsp_irq_reset(struct cdnsp_device *pdev); +int cdnsp_halt_endpoint(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, int value); +int cdnsp_cmd_stop_ep(struct cdnsp_device *pdev, struct cdnsp_ep *pep); +int cdnsp_cmd_flush_ep(struct cdnsp_device *pdev, struct cdnsp_ep *pep); +void cdnsp_setup_analyze(struct cdnsp_device *pdev); +int cdnsp_status_stage(struct cdnsp_device *pdev); +int cdnsp_reset_device(struct cdnsp_device *pdev); + +/** + * next_request - gets the next request on the given list + * @list: the request list to operate on + * + * caller should take care of locking. this function return null or the first + * request available on list. + */ +static inline struct cdnsp_request *next_request(struct list_head *list) +{ + return list_first_entry_or_null(list, struct cdnsp_request, list); +} + +#define to_cdnsp_ep(ep) (container_of(ep, struct cdnsp_ep, endpoint)) +#define gadget_to_cdnsp(g) (container_of(g, struct cdnsp_device, gadget)) +#define request_to_cdnsp_request(r) (container_of(r, struct cdnsp_request, \ + request)) +#define to_cdnsp_request(r) (container_of(r, struct cdnsp_request, request)) +int cdnsp_remove_request(struct cdnsp_device *pdev, struct cdnsp_request *preq, + struct cdnsp_ep *pep); + diff --git a/drivers/usb/cdns3/cdnsp-mem.c b/drivers/usb/cdns3/cdnsp-mem.c --- /dev/null +++ b/drivers/usb/cdns3/cdnsp-mem.c +// spdx-license-identifier: gpl-2.0 +/* + * cadence cdnsp drd driver. + * + * copyright (c) 2020 cadence. + * + * author: pawel laszczak <pawell@cadence.com> + * + * code based on linux xhci driver. + * origin: copyright (c) 2008 intel corp. + */ + +#include <linux/dma-mapping.h> +#include <linux/dmapool.h> +#include <linux/slab.h> +#include <linux/usb.h> + +#include "cdnsp-gadget.h" + +static void cdnsp_free_stream_info(struct cdnsp_device *pdev, + struct cdnsp_ep *pep); +/* + * allocates a generic ring segment from the ring pool, sets the dma address, + * initializes the segment to zero, and sets the private next pointer to null. + * + * "all components of all command and transfer trbs shall be initialized to '0'" + */ +static struct cdnsp_segment *cdnsp_segment_alloc(struct cdnsp_device *pdev, + unsigned int cycle_state, + unsigned int max_packet, + gfp_t flags) +{ + struct cdnsp_segment *seg; + dma_addr_t dma; + int i; + + seg = kzalloc(sizeof(*seg), flags); + if (!seg) + return null; + + seg->trbs = dma_pool_zalloc(pdev->segment_pool, flags, &dma); + if (!seg->trbs) { + kfree(seg); + return null; + } + + if (max_packet) { + seg->bounce_buf = kzalloc(max_packet, flags | gfp_dma); + if (!seg->bounce_buf) + goto free_dma; + } + + /* if the cycle state is 0, set the cycle bit to 1 for all the trbs. */ + if (cycle_state == 0) { + for (i = 0; i < trbs_per_segment; i++) + seg->trbs[i].link.control |= cpu_to_le32(trb_cycle); + } + seg->dma = dma; + seg->next = null; + + return seg; + +free_dma: + dma_pool_free(pdev->segment_pool, seg->trbs, dma); + kfree(seg); + + return null; +} + +static void cdnsp_segment_free(struct cdnsp_device *pdev, + struct cdnsp_segment *seg) +{ + if (seg->trbs) + dma_pool_free(pdev->segment_pool, seg->trbs, seg->dma); + + kfree(seg->bounce_buf); + kfree(seg); +} + +static void cdnsp_free_segments_for_ring(struct cdnsp_device *pdev, + struct cdnsp_segment *first) +{ + struct cdnsp_segment *seg; + + seg = first->next; + + while (seg != first) { + struct cdnsp_segment *next = seg->next; + + cdnsp_segment_free(pdev, seg); + seg = next; + } + + cdnsp_segment_free(pdev, first); +} + +/* + * make the prev segment point to the next segment. + * + * change the last trb in the prev segment to be a link trb which points to the + * dma address of the next segment. the caller needs to set any link trb + * related flags, such as end trb, toggle cycle, and no snoop. + */ +static void cdnsp_link_segments(struct cdnsp_device *pdev, + struct cdnsp_segment *prev, + struct cdnsp_segment *next, + enum cdnsp_ring_type type) +{ + struct cdnsp_link_trb *link; + u32 val; + + if (!prev || !next) + return; + + prev->next = next; + if (type != type_event) { + link = &prev->trbs[trbs_per_segment - 1].link; + link->segment_ptr = cpu_to_le64(next->dma); + + /* + * set the last trb in the segment to have a trb type id + * of link trb + */ + val = le32_to_cpu(link->control); + val &= ~trb_type_bitmask; + val |= trb_type(trb_link); + link->control = cpu_to_le32(val); + } +} + +/* + * link the ring to the new segments. + * set toggle cycle for the new ring if needed. + */ +static void cdnsp_link_rings(struct cdnsp_device *pdev, + struct cdnsp_ring *ring, + struct cdnsp_segment *first, + struct cdnsp_segment *last, + unsigned int num_segs) +{ + struct cdnsp_segment *next; + + if (!ring || !first || !last) + return; + + next = ring->enq_seg->next; + cdnsp_link_segments(pdev, ring->enq_seg, first, ring->type); + cdnsp_link_segments(pdev, last, next, ring->type); + ring->num_segs += num_segs; + ring->num_trbs_free += (trbs_per_segment - 1) * num_segs; + + if (ring->type != type_event && ring->enq_seg == ring->last_seg) { + ring->last_seg->trbs[trbs_per_segment - 1].link.control &= + ~cpu_to_le32(link_toggle); + last->trbs[trbs_per_segment - 1].link.control |= + cpu_to_le32(link_toggle); + ring->last_seg = last; + } +} + +/* + * we need a radix tree for mapping physical addresses of trbs to which stream + * id they belong to. we need to do this because the device controller won't + * tell us which stream ring the trb came from. we could store the stream id + * in an event data trb, but that doesn't help us for the cancellation case, + * since the endpoint may stop before it reaches that event data trb. + * + * the radix tree maps the upper portion of the trb dma address to a ring + * segment that has the same upper portion of dma addresses. for example, + * say i have segments of size 1kb, that are always 1kb aligned. a segment may + * start at 0x10c91000 and end at 0x10c913f0. if i use the upper 10 bits, the + * key to the stream id is 0x43244. i can use the dma address of the trb to + * pass the radix tree a key to get the right stream id: + * + * 0x10c90fff >> 10 = 0x43243 + * 0x10c912c0 >> 10 = 0x43244 + * 0x10c91400 >> 10 = 0x43245 + * + * obviously, only those trbs with dma addresses that are within the segment + * will make the radix tree return the stream id for that ring. + * + * caveats for the radix tree: + * + * the radix tree uses an unsigned long as a key pair. on 32-bit systems, an + * unsigned long will be 32-bits; on a 64-bit system an unsigned long will be + * 64-bits. since we only request 32-bit dma addresses, we can use that as the + * key on 32-bit or 64-bit systems (it would also be fine if we asked for 64-bit + * pci dma addresses on a 64-bit system). there might be a problem on 32-bit + * extended systems (where the dma address can be bigger than 32-bits), + * if we allow the pci dma mask to be bigger than 32-bits. so don't do that. + */ +static int cdnsp_insert_segment_mapping(struct radix_tree_root *trb_address_map, + struct cdnsp_ring *ring, + struct cdnsp_segment *seg, + gfp_t mem_flags) +{ + unsigned long key; + int ret; + + key = (unsigned long)(seg->dma >> trb_segment_shift); + + /* skip any segments that were already added. */ + if (radix_tree_lookup(trb_address_map, key)) + return 0; + + ret = radix_tree_maybe_preload(mem_flags); + if (ret) + return ret; + + ret = radix_tree_insert(trb_address_map, key, ring); + radix_tree_preload_end(); + + return ret; +} + +static void cdnsp_remove_segment_mapping(struct radix_tree_root *trb_address_map, + struct cdnsp_segment *seg) +{ + unsigned long key; + + key = (unsigned long)(seg->dma >> trb_segment_shift); + if (radix_tree_lookup(trb_address_map, key)) + radix_tree_delete(trb_address_map, key); +} + +static int cdnsp_update_stream_segment_mapping(struct radix_tree_root *trb_address_map, + struct cdnsp_ring *ring, + struct cdnsp_segment *first_seg, + struct cdnsp_segment *last_seg, + gfp_t mem_flags) +{ + struct cdnsp_segment *failed_seg; + struct cdnsp_segment *seg; + int ret; + + seg = first_seg; + do { + ret = cdnsp_insert_segment_mapping(trb_address_map, ring, seg, + mem_flags); + if (ret) + goto remove_streams; + if (seg == last_seg) + return 0; + seg = seg->next; + } while (seg != first_seg); + + return 0; + +remove_streams: + failed_seg = seg; + seg = first_seg; + do { + cdnsp_remove_segment_mapping(trb_address_map, seg); + if (seg == failed_seg) + return ret; + seg = seg->next; + } while (seg != first_seg); + + return ret; +} + +static void cdnsp_remove_stream_mapping(struct cdnsp_ring *ring) +{ + struct cdnsp_segment *seg; + + seg = ring->first_seg; + do { + cdnsp_remove_segment_mapping(ring->trb_address_map, seg); + seg = seg->next; + } while (seg != ring->first_seg); +} + +static int cdnsp_update_stream_mapping(struct cdnsp_ring *ring) +{ + return cdnsp_update_stream_segment_mapping(ring->trb_address_map, ring, + ring->first_seg, ring->last_seg, gfp_atomic); +} + +static void cdnsp_ring_free(struct cdnsp_device *pdev, struct cdnsp_ring *ring) +{ + if (!ring) + return; + + if (ring->first_seg) { + if (ring->type == type_stream) + cdnsp_remove_stream_mapping(ring); + + cdnsp_free_segments_for_ring(pdev, ring->first_seg); + } + + kfree(ring); +} + +void cdnsp_initialize_ring_info(struct cdnsp_ring *ring) +{ + ring->enqueue = ring->first_seg->trbs; + ring->enq_seg = ring->first_seg; + ring->dequeue = ring->enqueue; + ring->deq_seg = ring->first_seg; + + /* + * the ring is initialized to 0. the producer must write 1 to the cycle + * bit to handover ownership of the trb, so pcs = 1. the consumer must + * compare ccs to the cycle bit to check ownership, so ccs = 1. + * + * new rings are initialized with cycle state equal to 1; if we are + * handling ring expansion, set the cycle state equal to the old ring. + */ + ring->cycle_state = 1; + + /* + * each segment has a link trb, and leave an extra trb for sw + * accounting purpose + */ + ring->num_trbs_free = ring->num_segs * (trbs_per_segment - 1) - 1; +} + +/* allocate segments and link them for a ring. */ +static int cdnsp_alloc_segments_for_ring(struct cdnsp_device *pdev, + struct cdnsp_segment **first, + struct cdnsp_segment **last, + unsigned int num_segs, + unsigned int cycle_state, + enum cdnsp_ring_type type, + unsigned int max_packet, + gfp_t flags) +{ + struct cdnsp_segment *prev; + + /* allocate first segment. */ + prev = cdnsp_segment_alloc(pdev, cycle_state, max_packet, flags); + if (!prev) + return -enomem; + + num_segs--; + *first = prev; + + /* allocate all other segments. */ + while (num_segs > 0) { + struct cdnsp_segment *next; + + next = cdnsp_segment_alloc(pdev, cycle_state, + max_packet, flags); + if (!next) { + cdnsp_free_segments_for_ring(pdev, *first); + return -enomem; + } + + cdnsp_link_segments(pdev, prev, next, type); + + prev = next; + num_segs--; + } + + cdnsp_link_segments(pdev, prev, *first, type); + *last = prev; + + return 0; +} + +/* + * create a new ring with zero or more segments. + * + * link each segment together into a ring. + * set the end flag and the cycle toggle bit on the last segment. + */ +static struct cdnsp_ring *cdnsp_ring_alloc(struct cdnsp_device *pdev, + unsigned int num_segs, + enum cdnsp_ring_type type, + unsigned int max_packet, + gfp_t flags) +{ + struct cdnsp_ring *ring; + int ret; + + ring = kzalloc(sizeof *(ring), flags); + if (!ring) + return null; + + ring->num_segs = num_segs; + ring->bounce_buf_len = max_packet; + init_list_head(&ring->td_list); + ring->type = type; + + if (num_segs == 0) + return ring; + + ret = cdnsp_alloc_segments_for_ring(pdev, &ring->first_seg, + &ring->last_seg, num_segs, + 1, type, max_packet, flags); + if (ret) + goto fail; + + /* only event ring does not use link trb. */ + if (type != type_event) + ring->last_seg->trbs[trbs_per_segment - 1].link.control |= + cpu_to_le32(link_toggle); + + cdnsp_initialize_ring_info(ring); + + return ring; +fail: + kfree(ring); + return null; +} + +void cdnsp_free_endpoint_rings(struct cdnsp_device *pdev, struct cdnsp_ep *pep) +{ + cdnsp_ring_free(pdev, pep->ring); + pep->ring = null; + cdnsp_free_stream_info(pdev, pep); +} + +/* + * expand an existing ring. + * allocate a new ring which has same segment numbers and link the two rings. + */ +int cdnsp_ring_expansion(struct cdnsp_device *pdev, + struct cdnsp_ring *ring, + unsigned int num_trbs, + gfp_t flags) +{ + unsigned int num_segs_needed; + struct cdnsp_segment *first; + struct cdnsp_segment *last; + unsigned int num_segs; + int ret; + + num_segs_needed = (num_trbs + (trbs_per_segment - 1) - 1) / + (trbs_per_segment - 1); + + /* allocate number of segments we needed, or double the ring size. */ + num_segs = max(ring->num_segs, num_segs_needed); + + ret = cdnsp_alloc_segments_for_ring(pdev, &first, &last, num_segs, + ring->cycle_state, ring->type, + ring->bounce_buf_len, flags); + if (ret) + return -enomem; + + if (ring->type == type_stream) + ret = cdnsp_update_stream_segment_mapping(ring->trb_address_map, + ring, first, + last, flags); + + if (ret) { + cdnsp_free_segments_for_ring(pdev, first); + + return ret; + } + + cdnsp_link_rings(pdev, ring, first, last, num_segs); + + return 0; +} + +static int cdnsp_init_device_ctx(struct cdnsp_device *pdev) +{ + int size = hcc_64byte_context(pdev->hcc_params) ? 2048 : 1024; + + pdev->out_ctx.type = cdnsp_ctx_type_device; + pdev->out_ctx.size = size; + pdev->out_ctx.ctx_size = ctx_size(pdev->hcc_params); + pdev->out_ctx.bytes = dma_pool_zalloc(pdev->device_pool, gfp_atomic, + &pdev->out_ctx.dma); + + if (!pdev->out_ctx.bytes) + return -enomem; + + pdev->in_ctx.type = cdnsp_ctx_type_input; + pdev->in_ctx.ctx_size = pdev->out_ctx.ctx_size; + pdev->in_ctx.size = size + pdev->out_ctx.ctx_size; + pdev->in_ctx.bytes = dma_pool_zalloc(pdev->device_pool, gfp_atomic, + &pdev->in_ctx.dma); + + if (!pdev->in_ctx.bytes) { + dma_pool_free(pdev->device_pool, pdev->out_ctx.bytes, + pdev->out_ctx.dma); + return -enomem; + } + + return 0; +} + +struct cdnsp_input_control_ctx + *cdnsp_get_input_control_ctx(struct cdnsp_container_ctx *ctx) +{ + if (ctx->type != cdnsp_ctx_type_input) + return null; + + return (struct cdnsp_input_control_ctx *)ctx->bytes; +} + +struct cdnsp_slot_ctx *cdnsp_get_slot_ctx(struct cdnsp_container_ctx *ctx) +{ + if (ctx->type == cdnsp_ctx_type_device) + return (struct cdnsp_slot_ctx *)ctx->bytes; + + return (struct cdnsp_slot_ctx *)(ctx->bytes + ctx->ctx_size); +} + +struct cdnsp_ep_ctx *cdnsp_get_ep_ctx(struct cdnsp_container_ctx *ctx, + unsigned int ep_index) +{ + /* increment ep index by offset of start of ep ctx array. */ + ep_index++; + if (ctx->type == cdnsp_ctx_type_input) + ep_index++; + + return (struct cdnsp_ep_ctx *)(ctx->bytes + (ep_index * ctx->ctx_size)); +} + +static void cdnsp_free_stream_ctx(struct cdnsp_device *pdev, + struct cdnsp_ep *pep) +{ + dma_pool_free(pdev->device_pool, pep->stream_info.stream_ctx_array, + pep->stream_info.ctx_array_dma); +} + +/* the stream context array must be a power of 2. */ +static struct cdnsp_stream_ctx + *cdnsp_alloc_stream_ctx(struct cdnsp_device *pdev, struct cdnsp_ep *pep) +{ + size_t size = sizeof(struct cdnsp_stream_ctx) * + pep->stream_info.num_stream_ctxs; + + if (size > cdnsp_ctx_size) + return null; + + /** + * driver uses intentionally the device_pool to allocated stream + * context array. device pool has 2048 bytes of size what gives us + * 128 entries. + */ + return dma_pool_zalloc(pdev->device_pool, gfp_dma32 | gfp_atomic, + &pep->stream_info.ctx_array_dma); +} + +struct cdnsp_ring *cdnsp_dma_to_transfer_ring(struct cdnsp_ep *pep, u64 address) +{ + if (pep->ep_state & ep_has_streams) + return radix_tree_lookup(&pep->stream_info.trb_address_map, + address >> trb_segment_shift); + + return pep->ring; +} + +/* + * change an endpoint's internal structure so it supports stream ids. + * the number of requested streams includes stream 0, which cannot be used by + * driver. + * + * the number of stream contexts in the stream context array may be bigger than + * the number of streams the driver wants to use. this is because the number of + * stream context array entries must be a power of two. + */ +int cdnsp_alloc_stream_info(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, + unsigned int num_stream_ctxs, + unsigned int num_streams) +{ + struct cdnsp_stream_info *stream_info; + struct cdnsp_ring *cur_ring; + u32 cur_stream; + u64 addr; + int ret; + int mps; + + stream_info = &pep->stream_info; + stream_info->num_streams = num_streams; + stream_info->num_stream_ctxs = num_stream_ctxs; + + /* initialize the array of virtual pointers to stream rings. */ + stream_info->stream_rings = kcalloc(num_streams, + sizeof(struct cdnsp_ring *), + gfp_atomic); + if (!stream_info->stream_rings) + return -enomem; + + /* initialize the array of dma addresses for stream rings for the hw. */ + stream_info->stream_ctx_array = cdnsp_alloc_stream_ctx(pdev, pep); + if (!stream_info->stream_ctx_array) + goto cleanup_stream_rings; + + memset(stream_info->stream_ctx_array, 0, + sizeof(struct cdnsp_stream_ctx) * num_stream_ctxs); + init_radix_tree(&stream_info->trb_address_map, gfp_atomic); + mps = usb_endpoint_maxp(pep->endpoint.desc); + + /* + * allocate rings for all the streams that the driver will use, + * and add their segment dma addresses to the radix tree. + * stream 0 is reserved. + */ + for (cur_stream = 1; cur_stream < num_streams; cur_stream++) { + cur_ring = cdnsp_ring_alloc(pdev, 2, type_stream, mps, + gfp_atomic); + stream_info->stream_rings[cur_stream] = cur_ring; + + if (!cur_ring) + goto cleanup_rings; + + cur_ring->stream_id = cur_stream; + cur_ring->trb_address_map = &stream_info->trb_address_map; + + /* set deq ptr, cycle bit, and stream context type. */ + addr = cur_ring->first_seg->dma | sct_for_ctx(sct_pri_tr) | + cur_ring->cycle_state; + + stream_info->stream_ctx_array[cur_stream].stream_ring = + cpu_to_le64(addr); + + ret = cdnsp_update_stream_mapping(cur_ring); + if (ret) + goto cleanup_rings; + } + + return 0; + +cleanup_rings: + for (cur_stream = 1; cur_stream < num_streams; cur_stream++) { + cur_ring = stream_info->stream_rings[cur_stream]; + if (cur_ring) { + cdnsp_ring_free(pdev, cur_ring); + stream_info->stream_rings[cur_stream] = null; + } + } + +cleanup_stream_rings: + kfree(pep->stream_info.stream_rings); + + return -enomem; +} + +/* frees all stream contexts associated with the endpoint. */ +static void cdnsp_free_stream_info(struct cdnsp_device *pdev, + struct cdnsp_ep *pep) +{ + struct cdnsp_stream_info *stream_info = &pep->stream_info; + struct cdnsp_ring *cur_ring; + int cur_stream; + + if (!(pep->ep_state & ep_has_streams)) + return; + + for (cur_stream = 1; cur_stream < stream_info->num_streams; + cur_stream++) { + cur_ring = stream_info->stream_rings[cur_stream]; + if (cur_ring) { + cdnsp_ring_free(pdev, cur_ring); + stream_info->stream_rings[cur_stream] = null; + } + } + + if (stream_info->stream_ctx_array) + cdnsp_free_stream_ctx(pdev, pep); + + kfree(stream_info->stream_rings); + pep->ep_state &= ~ep_has_streams; +} + +/* all the cdnsp_tds in the ring's td list should be freed at this point.*/ +static void cdnsp_free_priv_device(struct cdnsp_device *pdev) +{ + pdev->dcbaa->dev_context_ptrs[1] = 0; + + cdnsp_free_endpoint_rings(pdev, &pdev->eps[0]); + + if (pdev->in_ctx.bytes) + dma_pool_free(pdev->device_pool, pdev->in_ctx.bytes, + pdev->in_ctx.dma); + + if (pdev->out_ctx.bytes) + dma_pool_free(pdev->device_pool, pdev->out_ctx.bytes, + pdev->out_ctx.dma); + + pdev->in_ctx.bytes = null; + pdev->out_ctx.bytes = null; +} + +static int cdnsp_alloc_priv_device(struct cdnsp_device *pdev, gfp_t flags) +{ + int ret = -enomem; + + ret = cdnsp_init_device_ctx(pdev); + if (ret) + return ret; + + /* allocate endpoint 0 ring. */ + pdev->eps[0].ring = cdnsp_ring_alloc(pdev, 2, type_ctrl, 0, flags); + if (!pdev->eps[0].ring) + goto fail; + + /* point to output device context in dcbaa. */ + pdev->dcbaa->dev_context_ptrs[1] = cpu_to_le64(pdev->out_ctx.dma); + pdev->cmd.in_ctx = &pdev->in_ctx; + + return 0; +fail: + dma_pool_free(pdev->device_pool, pdev->out_ctx.bytes, + pdev->out_ctx.dma); + dma_pool_free(pdev->device_pool, pdev->in_ctx.bytes, + pdev->in_ctx.dma); + + return ret; +} + +void cdnsp_copy_ep0_dequeue_into_input_ctx(struct cdnsp_device *pdev) +{ + struct cdnsp_ep_ctx *ep0_ctx = pdev->eps[0].in_ctx; + struct cdnsp_ring *ep_ring = pdev->eps[0].ring; + dma_addr_t dma; + + dma = cdnsp_trb_virt_to_dma(ep_ring->enq_seg, ep_ring->enqueue); + ep0_ctx->deq = cpu_to_le64(dma | ep_ring->cycle_state); +} + +/* setup an controller private device for a set address command. */ +int cdnsp_setup_addressable_priv_dev(struct cdnsp_device *pdev) +{ + struct cdnsp_slot_ctx *slot_ctx; + struct cdnsp_ep_ctx *ep0_ctx; + u32 max_packets, port; + + ep0_ctx = cdnsp_get_ep_ctx(&pdev->in_ctx, 0); + slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); + + /* only the control endpoint is valid - one endpoint context. */ + slot_ctx->dev_info |= cpu_to_le32(last_ctx(1)); + + switch (pdev->gadget.speed) { + case usb_speed_super_plus: + slot_ctx->dev_info |= cpu_to_le32(slot_speed_ssp); + max_packets = max_packet(512); + break; + case usb_speed_super: + slot_ctx->dev_info |= cpu_to_le32(slot_speed_ss); + max_packets = max_packet(512); + break; + case usb_speed_high: + slot_ctx->dev_info |= cpu_to_le32(slot_speed_hs); + max_packets = max_packet(64); + break; + case usb_speed_full: + slot_ctx->dev_info |= cpu_to_le32(slot_speed_fs); + max_packets = max_packet(64); + break; + default: + /* speed was not set , this shouldn't happen. */ + return -einval; + } + + port = dev_port(pdev->active_port->port_num); + slot_ctx->dev_port |= cpu_to_le32(port); + slot_ctx->dev_state = (pdev->device_address & dev_addr_mask); + ep0_ctx->tx_info = ep_avg_trb_length(0x8); + ep0_ctx->ep_info2 = cpu_to_le32(ep_type(ctrl_ep)); + ep0_ctx->ep_info2 |= cpu_to_le32(max_burst(0) | error_count(3) | + max_packets); + + ep0_ctx->deq = cpu_to_le64(pdev->eps[0].ring->first_seg->dma | + pdev->eps[0].ring->cycle_state); + + return 0; +} + +/* + * convert interval expressed as 2^(binterval - 1) == interval into + * straight exponent value 2^n == interval. + */ +static unsigned int cdnsp_parse_exponent_interval(struct usb_gadget *g, + struct cdnsp_ep *pep) +{ + unsigned int interval; + + interval = clamp_val(pep->endpoint.desc->binterval, 1, 16) - 1; + if (interval != pep->endpoint.desc->binterval - 1) + dev_warn(&g->dev, "ep %s - rounding interval to %d %sframes ", + pep->name, 1 << interval, + g->speed == usb_speed_full ? "" : "micro"); + + /* + * full speed isoc endpoints specify interval in frames, + * not microframes. we are using microframes everywhere, + * so adjust accordingly. + */ + if (g->speed == usb_speed_full) + interval += 3; /* 1 frame = 2^3 uframes */ + + /* controller handles only up to 512ms (2^12). */ + if (interval > 12) + interval = 12; + + return interval; +} + +/* + * convert binterval expressed in microframes (in 1-255 range) to exponent of + * microframes, rounded down to nearest power of 2. + */ +static unsigned int cdnsp_microframes_to_exponent(struct usb_gadget *g, + struct cdnsp_ep *pep, + unsigned int desc_interval, + unsigned int min_exponent, + unsigned int max_exponent) +{ + unsigned int interval; + + interval = fls(desc_interval) - 1; + return clamp_val(interval, min_exponent, max_exponent); +} + +/* + * return the polling interval. + * + * the polling interval is expressed in "microframes". if controllers's interval + * field is set to n, it will service the endpoint every 2^(interval)*125us. + */ +static unsigned int cdnsp_get_endpoint_interval(struct usb_gadget *g, + struct cdnsp_ep *pep) +{ + unsigned int interval = 0; + + switch (g->speed) { + case usb_speed_high: + case usb_speed_super_plus: + case usb_speed_super: + if (usb_endpoint_xfer_int(pep->endpoint.desc) || + usb_endpoint_xfer_isoc(pep->endpoint.desc)) + interval = cdnsp_parse_exponent_interval(g, pep); + break; + case usb_speed_full: + if (usb_endpoint_xfer_isoc(pep->endpoint.desc)) { + interval = cdnsp_parse_exponent_interval(g, pep); + } else if (usb_endpoint_xfer_int(pep->endpoint.desc)) { + interval = pep->endpoint.desc->binterval << 3; + interval = cdnsp_microframes_to_exponent(g, pep, + interval, + 3, 10); + } + + break; + default: + warn_on(1); + } + + return interval; +} + +/* + * the "mult" field in the endpoint context is only set for superspeed isoc eps. + * high speed endpoint descriptors can define "the number of additional + * transaction opportunities per microframe", but that goes in the max burst + * endpoint context field. + */ +static u32 cdnsp_get_endpoint_mult(struct usb_gadget *g, struct cdnsp_ep *pep) +{ + if (g->speed < usb_speed_super || + !usb_endpoint_xfer_isoc(pep->endpoint.desc)) + return 0; + + return pep->endpoint.comp_desc->bmattributes; +} + +static u32 cdnsp_get_endpoint_max_burst(struct usb_gadget *g, + struct cdnsp_ep *pep) +{ + /* super speed and plus have max burst in ep companion desc */ + if (g->speed >= usb_speed_super) + return pep->endpoint.comp_desc->bmaxburst; + + if (g->speed == usb_speed_high && + (usb_endpoint_xfer_isoc(pep->endpoint.desc) || + usb_endpoint_xfer_int(pep->endpoint.desc))) + return (usb_endpoint_maxp(pep->endpoint.desc) & 0x1800) >> 11; + + return 0; +} + +static u32 cdnsp_get_endpoint_type(const struct usb_endpoint_descriptor *desc) +{ + int in; + + in = usb_endpoint_dir_in(desc); + + switch (usb_endpoint_type(desc)) { + case usb_endpoint_xfer_control: + return ctrl_ep; + case usb_endpoint_xfer_bulk: + return in ? bulk_in_ep : bulk_out_ep; + case usb_endpoint_xfer_isoc: + return in ? isoc_in_ep : isoc_out_ep; + case usb_endpoint_xfer_int: + return in ? int_in_ep : int_out_ep; + } + + return 0; +} + +/* + * return the maximum endpoint service interval time (esit) payload. + * basically, this is the maxpacket size, multiplied by the burst size + * and mult size. + */ +static u32 cdnsp_get_max_esit_payload(struct usb_gadget *g, + struct cdnsp_ep *pep) +{ + int max_packet; + int max_burst; + + /* only applies for interrupt or isochronous endpoints*/ + if (usb_endpoint_xfer_control(pep->endpoint.desc) || + usb_endpoint_xfer_bulk(pep->endpoint.desc)) + return 0; + + /* superspeedplus isoc ep sending over 48k per eist. */ + if (g->speed >= usb_speed_super_plus && + usb_ss_ssp_isoc_comp(pep->endpoint.desc->bmattributes)) + return le32_to_cpu(pep->endpoint.comp_desc->wbytesperinterval); + /* superspeed or superspeedplus isoc ep with less than 48k per esit */ + else if (g->speed >= usb_speed_super) + return le16_to_cpu(pep->endpoint.comp_desc->wbytesperinterval); + + max_packet = usb_endpoint_maxp(pep->endpoint.desc); + max_burst = usb_endpoint_maxp_mult(pep->endpoint.desc); + + /* a 0 in max burst means 1 transfer per esit */ + return max_packet * max_burst; +} + +int cdnsp_endpoint_init(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, + gfp_t mem_flags) +{ + enum cdnsp_ring_type ring_type; + struct cdnsp_ep_ctx *ep_ctx; + unsigned int err_count = 0; + unsigned int avg_trb_len; + unsigned int max_packet; + unsigned int max_burst; + unsigned int interval; + u32 max_esit_payload; + unsigned int mult; + u32 endpoint_type; + int ret; + + ep_ctx = pep->in_ctx; + + endpoint_type = cdnsp_get_endpoint_type(pep->endpoint.desc); + if (!endpoint_type) + return -einval; + + ring_type = usb_endpoint_type(pep->endpoint.desc); + + /* + * get values to fill the endpoint context, mostly from ep descriptor. + * the average trb buffer length for bulk endpoints is unclear as we + * have no clue on scatter gather list entry size. for isoc and int, + * set it to max available. + */ + max_esit_payload = cdnsp_get_max_esit_payload(&pdev->gadget, pep); + interval = cdnsp_get_endpoint_interval(&pdev->gadget, pep); + mult = cdnsp_get_endpoint_mult(&pdev->gadget, pep); + max_packet = usb_endpoint_maxp(pep->endpoint.desc); + max_burst = cdnsp_get_endpoint_max_burst(&pdev->gadget, pep); + avg_trb_len = max_esit_payload; + + /* allow 3 retries for everything but isoc, set cerr = 3. */ + if (!usb_endpoint_xfer_isoc(pep->endpoint.desc)) + err_count = 3; + if (usb_endpoint_xfer_bulk(pep->endpoint.desc) && + pdev->gadget.speed == usb_speed_high) + max_packet = 512; + /* controller spec indicates that ctrl ep avg trb length should be 8. */ + if (usb_endpoint_xfer_control(pep->endpoint.desc)) + avg_trb_len = 8; + + /* set up the endpoint ring. */ + pep->ring = cdnsp_ring_alloc(pdev, 2, ring_type, max_packet, mem_flags); + pep->skip = false; + + /* fill the endpoint context */ + ep_ctx->ep_info = cpu_to_le32(ep_max_esit_payload_hi(max_esit_payload) | + ep_interval(interval) | ep_mult(mult)); + ep_ctx->ep_info2 = cpu_to_le32(ep_type(endpoint_type) | + max_packet(max_packet) | max_burst(max_burst) | + error_count(err_count)); + ep_ctx->deq = cpu_to_le64(pep->ring->first_seg->dma | + pep->ring->cycle_state); + + ep_ctx->tx_info = cpu_to_le32(ep_max_esit_payload_lo(max_esit_payload) | + ep_avg_trb_length(avg_trb_len)); + + if (usb_endpoint_xfer_bulk(pep->endpoint.desc) && + pdev->gadget.speed > usb_speed_high) { + ret = cdnsp_alloc_streams(pdev, pep); + if (ret < 0) + return ret; + } + + return 0; +} + +void cdnsp_endpoint_zero(struct cdnsp_device *pdev, struct cdnsp_ep *pep) +{ + pep->in_ctx->ep_info = 0; + pep->in_ctx->ep_info2 = 0; + pep->in_ctx->deq = 0; + pep->in_ctx->tx_info = 0; +} + +static int cdnsp_alloc_erst(struct cdnsp_device *pdev, + struct cdnsp_ring *evt_ring, + struct cdnsp_erst *erst, + gfp_t flags) +{ + struct cdnsp_erst_entry *entry; + struct cdnsp_segment *seg; + unsigned int val; + size_t size; + + size = sizeof(struct cdnsp_erst_entry) * evt_ring->num_segs; + erst->entries = dma_alloc_coherent(pdev->dev, size, + &erst->erst_dma_addr, flags); + if (!erst->entries) + return -enomem; + + erst->num_entries = evt_ring->num_segs; + + seg = evt_ring->first_seg; + for (val = 0; val < evt_ring->num_segs; val++) { + entry = &erst->entries[val]; + entry->seg_addr = cpu_to_le64(seg->dma); + entry->seg_size = cpu_to_le32(trbs_per_segment); + entry->rsvd = 0; + seg = seg->next; + } + + return 0; +} + +static void cdnsp_free_erst(struct cdnsp_device *pdev, struct cdnsp_erst *erst) +{ + size_t size = sizeof(struct cdnsp_erst_entry) * (erst->num_entries); + struct device *dev = pdev->dev; + + if (erst->entries) + dma_free_coherent(dev, size, erst->entries, + erst->erst_dma_addr); + + erst->entries = null; +} + +void cdnsp_mem_cleanup(struct cdnsp_device *pdev) +{ + struct device *dev = pdev->dev; + + cdnsp_free_priv_device(pdev); + cdnsp_free_erst(pdev, &pdev->erst); + + if (pdev->event_ring) + cdnsp_ring_free(pdev, pdev->event_ring); + + pdev->event_ring = null; + + if (pdev->cmd_ring) + cdnsp_ring_free(pdev, pdev->cmd_ring); + + pdev->cmd_ring = null; + + dma_pool_destroy(pdev->segment_pool); + pdev->segment_pool = null; + dma_pool_destroy(pdev->device_pool); + pdev->device_pool = null; + + if (pdev->dcbaa) + dma_free_coherent(dev, sizeof(*pdev->dcbaa), + pdev->dcbaa, pdev->dcbaa->dma); + + pdev->dcbaa = null; + + pdev->usb2_port.exist = 0; + pdev->usb3_port.exist = 0; + pdev->usb2_port.port_num = 0; + pdev->usb3_port.port_num = 0; + pdev->active_port = null; +} + +static void cdnsp_set_event_deq(struct cdnsp_device *pdev) +{ + dma_addr_t deq; + u64 temp; + + deq = cdnsp_trb_virt_to_dma(pdev->event_ring->deq_seg, + pdev->event_ring->dequeue); + + /* update controller event ring dequeue pointer */ + temp = cdnsp_read_64(&pdev->ir_set->erst_dequeue); + temp &= erst_ptr_mask; + + /* + * don't clear the ehb bit (which is rw1c) because + * there might be more events to service. + */ + temp &= ~erst_ehb; + + cdnsp_write_64(((u64)deq & (u64)~erst_ptr_mask) | temp, + &pdev->ir_set->erst_dequeue); +} + +static void cdnsp_add_in_port(struct cdnsp_device *pdev, + struct cdnsp_port *port, + __le32 __iomem *addr) +{ + u32 temp, port_offset; + + temp = readl(addr); + port->maj_rev = cdnsp_ext_port_major(temp); + port->min_rev = cdnsp_ext_port_minor(temp); + + /* port offset and count in the third dword.*/ + temp = readl(addr + 2); + port_offset = cdnsp_ext_port_off(temp); + + port->port_num = port_offset; + port->exist = 1; +} + +/* + * scan the extended capabilities for the "supported protocol capabilities" that + * specify what speeds each port is supposed to be. + */ +static int cdnsp_setup_port_arrays(struct cdnsp_device *pdev, gfp_t flags) +{ + void __iomem *base; + u32 offset; + int i; + + base = &pdev->cap_regs->hc_capbase; + offset = cdnsp_find_next_ext_cap(base, 0, + ext_cap_cfg_dev_20port_cap_id); + pdev->port20_regs = base + offset; + + offset = cdnsp_find_next_ext_cap(base, 0, d_xec_cfg_3xport_cap); + pdev->port3x_regs = base + offset; + + offset = 0; + base = &pdev->cap_regs->hc_capbase; + + /* driver expects max 2 extended protocol capability. */ + for (i = 0; i < 2; i++) { + u32 temp; + + offset = cdnsp_find_next_ext_cap(base, offset, + ext_caps_protocol); + temp = readl(base + offset); + + if (cdnsp_ext_port_major(temp) == 0x03 && + !pdev->usb3_port.port_num) + cdnsp_add_in_port(pdev, &pdev->usb3_port, + base + offset); + + if (cdnsp_ext_port_major(temp) == 0x02 && + !pdev->usb2_port.port_num) + cdnsp_add_in_port(pdev, &pdev->usb2_port, + base + offset); + } + + if (!pdev->usb2_port.exist || !pdev->usb3_port.exist) { + dev_err(pdev->dev, "error: only one port detected "); + return -enodev; + } + + pdev->usb2_port.regs = (struct cdnsp_port_regs *) + (&pdev->op_regs->port_reg_base + num_port_regs * + (pdev->usb2_port.port_num - 1)); + + pdev->usb3_port.regs = (struct cdnsp_port_regs *) + (&pdev->op_regs->port_reg_base + num_port_regs * + (pdev->usb3_port.port_num - 1)); + + return 0; +} + +/* + * initialize memory for cdnsp (one-time init). + * + * program the pagesize register, initialize the device context array, create + * device contexts, set up a command ring segment, create event + * ring (one for now). + */ +int cdnsp_mem_init(struct cdnsp_device *pdev, gfp_t flags) +{ + struct device *dev = pdev->dev; + int ret = -enomem; + unsigned int val; + dma_addr_t dma; + u32 page_size; + u64 val_64; + + /* + * use 4k pages, since that's common and the minimum the + * controller supports + */ + page_size = 1 << 12; + + val = readl(&pdev->op_regs->config_reg); + val |= ((val & ~max_devs) | cdnsp_dev_max_slots) | config_u3e; + writel(val, &pdev->op_regs->config_reg); + + /* + * doorbell array must be physically contiguous + * and 64-byte (cache line) aligned. + */ + pdev->dcbaa = dma_alloc_coherent(dev, sizeof(*pdev->dcbaa), + &dma, gfp_kernel); + if (!pdev->dcbaa) + goto mem_init_fail; + + memset(pdev->dcbaa, 0, sizeof(*pdev->dcbaa)); + pdev->dcbaa->dma = dma; + + cdnsp_write_64(dma, &pdev->op_regs->dcbaa_ptr); + + /* + * initialize the ring segment pool. the ring must be a contiguous + * structure comprised of trbs. the trbs must be 16 byte aligned, + * however, the command ring segment needs 64-byte aligned segments + * and our use of dma addresses in the trb_address_map radix tree needs + * trb_segment_size alignment, so driver pick the greater alignment + * need. + */ + pdev->segment_pool = dma_pool_create("cdnsp ring segments", dev, + trb_segment_size, trb_segment_size, + page_size); + + pdev->device_pool = dma_pool_create("cdnsp input/output contexts", dev, + cdnsp_ctx_size, 64, page_size); + + if (!pdev->segment_pool || !pdev->device_pool) + goto mem_init_fail; + + /* set up the command ring to have one segments for now. */ + pdev->cmd_ring = cdnsp_ring_alloc(pdev, 1, type_command, 0, flags); + if (!pdev->cmd_ring) + goto mem_init_fail; + + /* set the address in the command ring control register */ + val_64 = cdnsp_read_64(&pdev->op_regs->cmd_ring); + val_64 = (val_64 & (u64)cmd_ring_rsvd_bits) | + (pdev->cmd_ring->first_seg->dma & (u64)~cmd_ring_rsvd_bits) | + pdev->cmd_ring->cycle_state; + cdnsp_write_64(val_64, &pdev->op_regs->cmd_ring); + + val = readl(&pdev->cap_regs->db_off); + val &= dboff_mask; + pdev->dba = (void __iomem *)pdev->cap_regs + val; + + /* set ir_set to interrupt register set 0 */ + pdev->ir_set = &pdev->run_regs->ir_set[0]; + + /* + * event ring setup: allocate a normal ring, but also setup + * the event ring segment table (erst). + */ + pdev->event_ring = cdnsp_ring_alloc(pdev, erst_num_segs, type_event, + 0, flags); + if (!pdev->event_ring) + goto mem_init_fail; + + ret = cdnsp_alloc_erst(pdev, pdev->event_ring, &pdev->erst, flags); + if (ret) + goto mem_init_fail; + + /* set erst count with the number of entries in the segment table. */ + val = readl(&pdev->ir_set->erst_size); + val &= erst_size_mask; + val |= erst_num_segs; + writel(val, &pdev->ir_set->erst_size); + + /* set the segment table base address. */ + val_64 = cdnsp_read_64(&pdev->ir_set->erst_base); + val_64 &= erst_ptr_mask; + val_64 |= (pdev->erst.erst_dma_addr & (u64)~erst_ptr_mask); + cdnsp_write_64(val_64, &pdev->ir_set->erst_base); + + /* set the event ring dequeue address. */ + cdnsp_set_event_deq(pdev); + + ret = cdnsp_setup_port_arrays(pdev, flags); + if (ret) + goto mem_init_fail; + + ret = cdnsp_alloc_priv_device(pdev, gfp_atomic); + if (ret) { + dev_err(pdev->dev, + "could not allocate cdnsp_device data structures "); + goto mem_init_fail; + } + + return 0; + +mem_init_fail: + dev_err(pdev->dev, "couldn't initialize memory "); + cdnsp_halt(pdev); + cdnsp_reset(pdev); + cdnsp_mem_cleanup(pdev); + + return ret; +} diff --git a/drivers/usb/cdns3/cdnsp-pci.c b/drivers/usb/cdns3/cdnsp-pci.c --- /dev/null +++ b/drivers/usb/cdns3/cdnsp-pci.c +// spdx-license-identifier: gpl-2.0 +/* + * cadence pci glue driver. + * + * copyright (c) 2019 cadence. + * + * author: pawel laszczak <pawell@cadence.com> + * + */ + +#include <linux/platform_device.h> +#include <linux/dma-mapping.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/pci.h> + +#include "core.h" +#include "gadget-export.h" + +#define pci_bar_host 0 +#define pci_bar_otg 0 +#define pci_bar_dev 2 + +#define pci_dev_fn_host_device 0 +#define pci_dev_fn_otg 1 + +#define pci_driver_name "cdns-pci-usbssp" +#define plat_driver_name "cdns-usbssp" + +#define cdns_vendor_id 0x17cd +#define cdns_device_id 0x0100 +#define cdns_drd_if (pci_class_serial_usb << 8 | 0x80) + +static struct pci_dev *cdnsp_get_second_fun(struct pci_dev *pdev) +{ + struct pci_dev *func; + + /* + * gets the second function. + * it's little tricky, but this platform has two function. + * the fist keeps resources for host/device while the second + * keeps resources for drd/otg. + */ + func = pci_get_device(pdev->vendor, pdev->device, null); + if (!func) + return null; + + if (func->devfn == pdev->devfn) { + func = pci_get_device(pdev->vendor, pdev->device, func); + if (!func) + return null; + } + + return func; +} + +static int cdnsp_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *id) +{ + struct device *dev = &pdev->dev; + struct pci_dev *func; + struct resource *res; + struct cdns *cdnsp; + int ret; + + /* + * for gadget/host pci (devfn) function number is 0, + * for otg pci (devfn) function number is 1. + */ + if (!id || (pdev->devfn != pci_dev_fn_host_device && + pdev->devfn != pci_dev_fn_otg)) + return -einval; + + func = cdnsp_get_second_fun(pdev); + if (!func) + return -einval; + + if (func->class == pci_class_serial_usb_xhci || + pdev->class == pci_class_serial_usb_xhci) { + ret = -einval; + goto put_pci; + } + + ret = pcim_enable_device(pdev); + if (ret) { + dev_err(&pdev->dev, "enabling pci device has failed %d ", ret); + goto put_pci; + } + + pci_set_master(pdev); + if (pci_is_enabled(func)) { + cdnsp = pci_get_drvdata(func); + } else { + cdnsp = kzalloc(sizeof(*cdnsp), gfp_kernel); + if (!cdnsp) { + ret = -enomem; + goto disable_pci; + } + } + + /* for gadget device function number is 0. */ + if (pdev->devfn == 0) { + resource_size_t rsrc_start, rsrc_len; + + /* function 0: host(bar_0) + device(bar_1).*/ + dev_dbg(dev, "initialize resources "); + rsrc_start = pci_resource_start(pdev, pci_bar_dev); + rsrc_len = pci_resource_len(pdev, pci_bar_dev); + res = devm_request_mem_region(dev, rsrc_start, rsrc_len, "dev"); + if (!res) { + dev_dbg(dev, "controller already in use "); + ret = -ebusy; + goto free_cdnsp; + } + + cdnsp->dev_regs = devm_ioremap(dev, rsrc_start, rsrc_len); + if (!cdnsp->dev_regs) { + dev_dbg(dev, "error mapping memory "); + ret = -efault; + goto free_cdnsp; + } + + cdnsp->dev_irq = pdev->irq; + dev_dbg(dev, "usbss-dev physical base addr: %pa ", + &rsrc_start); + + res = &cdnsp->xhci_res[0]; + res->start = pci_resource_start(pdev, pci_bar_host); + res->end = pci_resource_end(pdev, pci_bar_host); + res->name = "xhci"; + res->flags = ioresource_mem; + dev_dbg(dev, "usbss-xhci physical base addr: %pa ", + &res->start); + + /* interrupt for xhci, */ + res = &cdnsp->xhci_res[1]; + res->start = pdev->irq; + res->name = "host"; + res->flags = ioresource_irq; + } else { + res = &cdnsp->otg_res; + res->start = pci_resource_start(pdev, pci_bar_otg); + res->end = pci_resource_end(pdev, pci_bar_otg); + res->name = "otg"; + res->flags = ioresource_mem; + dev_dbg(dev, "cdnsp-drd physical base addr: %pa ", + &res->start); + + /* interrupt for otg/drd. */ + cdnsp->otg_irq = pdev->irq; + } + + if (pci_is_enabled(func)) { + cdnsp->dev = dev; + cdnsp->gadget_init = cdnsp_gadget_init; + + ret = cdns_init(cdnsp); + if (ret) + goto free_cdnsp; + } + + pci_set_drvdata(pdev, cdnsp); + + device_wakeup_enable(&pdev->dev); + if (pci_dev_run_wake(pdev)) + pm_runtime_put_noidle(&pdev->dev); + + return 0; + +free_cdnsp: + if (!pci_is_enabled(func)) + kfree(cdnsp); + +disable_pci: + pci_disable_device(pdev); + +put_pci: + pci_dev_put(func); + + return ret; +} + +static void cdnsp_pci_remove(struct pci_dev *pdev) +{ + struct cdns *cdnsp; + struct pci_dev *func; + + func = cdnsp_get_second_fun(pdev); + cdnsp = (struct cdns *)pci_get_drvdata(pdev); + + if (pci_dev_run_wake(pdev)) + pm_runtime_get_noresume(&pdev->dev); + + if (!pci_is_enabled(func)) { + kfree(cdnsp); + goto pci_put; + } + + cdns_remove(cdnsp); + +pci_put: + pci_dev_put(func); +} + +static int __maybe_unused cdnsp_pci_suspend(struct device *dev) +{ + struct cdns *cdns = dev_get_drvdata(dev); + + return cdns_suspend(cdns); +} + +static int __maybe_unused cdnsp_pci_resume(struct device *dev) +{ + struct cdns *cdns = dev_get_drvdata(dev); + unsigned long flags; + int ret; + + spin_lock_irqsave(&cdns->lock, flags); + ret = cdns_resume(cdns, 1); + spin_unlock_irqrestore(&cdns->lock, flags); + + return ret; +} + +static const struct dev_pm_ops cdnsp_pci_pm_ops = { + set_system_sleep_pm_ops(cdnsp_pci_suspend, cdnsp_pci_resume) +}; + +static const struct pci_device_id cdnsp_pci_ids[] = { + { pci_vendor_id_cdns, cdns_device_id, pci_any_id, pci_any_id, + pci_class_serial_usb_device, pci_any_id }, + { pci_vendor_id_cdns, cdns_device_id, pci_any_id, pci_any_id, + cdns_drd_if, pci_any_id }, + { 0, } +}; + +static struct pci_driver cdnsp_pci_driver = { + .name = "cdnsp-pci", + .id_table = &cdnsp_pci_ids[0], + .probe = cdnsp_pci_probe, + .remove = cdnsp_pci_remove, + .driver = { + .pm = &cdnsp_pci_pm_ops, + } +}; + +module_pci_driver(cdnsp_pci_driver); +module_device_table(pci, cdnsp_pci_ids); + +module_alias("pci:cdnsp"); +module_author("pawel laszczak <pawell@cadence.com>"); +module_license("gpl v2"); +module_description("cadence cdnsp pci driver"); diff --git a/drivers/usb/cdns3/cdnsp-ring.c b/drivers/usb/cdns3/cdnsp-ring.c --- /dev/null +++ b/drivers/usb/cdns3/cdnsp-ring.c +// spdx-license-identifier: gpl-2.0 +/* + * cadence cdnsp drd driver. + * + * copyright (c) 2020 cadence. + * + * author: pawel laszczak <pawell@cadence.com> + * + * code based on linux xhci driver. + * origin: copyright (c) 2008 intel corp + */ + +/* + * ring initialization rules: + * 1. each segment is initialized to zero, except for link trbs. + * 2. ring cycle state = 0. this represents producer cycle state (pcs) or + * consumer cycle state (ccs), depending on ring function. + * 3. enqueue pointer = dequeue pointer = address of first trb in the segment. + * + * ring behavior rules: + * 1. a ring is empty if enqueue == dequeue. this means there will always be at + * least one free trb in the ring. this is useful if you want to turn that + * into a link trb and expand the ring. + * 2. when incrementing an enqueue or dequeue pointer, if the next trb is a + * link trb, then load the pointer with the address in the link trb. if the + * link trb had its toggle bit set, you may need to update the ring cycle + * state (see cycle bit rules). you may have to do this multiple times + * until you reach a non-link trb. + * 3. a ring is full if enqueue++ (for the definition of increment above) + * equals the dequeue pointer. + * + * cycle bit rules: + * 1. when a consumer increments a dequeue pointer and encounters a toggle bit + * in a link trb, it must toggle the ring cycle state. + * 2. when a producer increments an enqueue pointer and encounters a toggle bit + * in a link trb, it must toggle the ring cycle state. + * + * producer rules: + * 1. check if ring is full before you enqueue. + * 2. write the ring cycle state to the cycle bit in the trb you're enqueuing. + * update enqueue pointer between each write (which may update the ring + * cycle state). + * 3. notify consumer. if sw is producer, it rings the doorbell for command + * and endpoint rings. if controller is the producer for the event ring, + * and it generates an interrupt according to interrupt modulation rules. + * + * consumer rules: + * 1. check if trb belongs to you. if the cycle bit == your ring cycle state, + * the trb is owned by the consumer. + * 2. update dequeue pointer (which may update the ring cycle state) and + * continue processing trbs until you reach a trb which is not owned by you. + * 3. notify the producer. sw is the consumer for the event ring, and it + * updates event ring dequeue pointer. controller is the consumer for the + * command and endpoint rings; it generates events on the event ring + * for these. + */ + +#include <linux/scatterlist.h> +#include <linux/dma-mapping.h> +#include <linux/delay.h> +#include <linux/slab.h> +#include <linux/irq.h> + +#include "cdnsp-gadget.h" + +/* + * returns zero if the trb isn't in this segment, otherwise it returns the dma + * address of the trb. + */ +dma_addr_t cdnsp_trb_virt_to_dma(struct cdnsp_segment *seg, + union cdnsp_trb *trb) +{ + unsigned long segment_offset = trb - seg->trbs; + + if (trb < seg->trbs || segment_offset >= trbs_per_segment) + return 0; + + return seg->dma + (segment_offset * sizeof(*trb)); +} + +static bool cdnsp_trb_is_noop(union cdnsp_trb *trb) +{ + return trb_type_noop_le32(trb->generic.field[3]); +} + +static bool cdnsp_trb_is_link(union cdnsp_trb *trb) +{ + return trb_type_link_le32(trb->link.control); +} + +bool cdnsp_last_trb_on_seg(struct cdnsp_segment *seg, union cdnsp_trb *trb) +{ + return trb == &seg->trbs[trbs_per_segment - 1]; +} + +bool cdnsp_last_trb_on_ring(struct cdnsp_ring *ring, + struct cdnsp_segment *seg, + union cdnsp_trb *trb) +{ + return cdnsp_last_trb_on_seg(seg, trb) && (seg->next == ring->first_seg); +} + +static bool cdnsp_link_trb_toggles_cycle(union cdnsp_trb *trb) +{ + return le32_to_cpu(trb->link.control) & link_toggle; +} + +static void cdnsp_trb_to_noop(union cdnsp_trb *trb, u32 noop_type) +{ + if (cdnsp_trb_is_link(trb)) { + /* unchain chained link trbs. */ + trb->link.control &= cpu_to_le32(~trb_chain); + } else { + trb->generic.field[0] = 0; + trb->generic.field[1] = 0; + trb->generic.field[2] = 0; + /* preserve only the cycle bit of this trb. */ + trb->generic.field[3] &= cpu_to_le32(trb_cycle); + trb->generic.field[3] |= cpu_to_le32(trb_type(noop_type)); + } +} + +/* + * updates trb to point to the next trb in the ring, and updates seg if the next + * trb is in a new segment. this does not skip over link trbs, and it does not + * effect the ring dequeue or enqueue pointers. + */ +static void cdnsp_next_trb(struct cdnsp_device *pdev, + struct cdnsp_ring *ring, + struct cdnsp_segment **seg, + union cdnsp_trb **trb) +{ + if (cdnsp_trb_is_link(*trb)) { + *seg = (*seg)->next; + *trb = ((*seg)->trbs); + } else { + (*trb)++; + } +} + +/* + * see cycle bit rules. sw is the consumer for the event ring only. + * don't make a ring full of link trbs. that would be dumb and this would loop. + */ +void cdnsp_inc_deq(struct cdnsp_device *pdev, struct cdnsp_ring *ring) +{ + /* event ring doesn't have link trbs, check for last trb. */ + if (ring->type == type_event) { + if (!cdnsp_last_trb_on_seg(ring->deq_seg, ring->dequeue)) { + ring->dequeue++; + return; + } + + if (cdnsp_last_trb_on_ring(ring, ring->deq_seg, ring->dequeue)) + ring->cycle_state ^= 1; + + ring->deq_seg = ring->deq_seg->next; + ring->dequeue = ring->deq_seg->trbs; + return; + } + + /* all other rings have link trbs. */ + if (!cdnsp_trb_is_link(ring->dequeue)) { + ring->dequeue++; + ring->num_trbs_free++; + } + while (cdnsp_trb_is_link(ring->dequeue)) { + ring->deq_seg = ring->deq_seg->next; + ring->dequeue = ring->deq_seg->trbs; + } +} + +/* + * see cycle bit rules. sw is the consumer for the event ring only. + * don't make a ring full of link trbs. that would be dumb and this would loop. + * + * if we've just enqueued a trb that is in the middle of a td (meaning the + * chain bit is set), then set the chain bit in all the following link trbs. + * if we've enqueued the last trb in a td, make sure the following link trbs + * have their chain bit cleared (so that each link trb is a separate td). + * + * @more_trbs_coming: will you enqueue more trbs before ringing the doorbell. + */ +static void cdnsp_inc_enq(struct cdnsp_device *pdev, + struct cdnsp_ring *ring, + bool more_trbs_coming) +{ + union cdnsp_trb *next; + u32 chain; + + chain = le32_to_cpu(ring->enqueue->generic.field[3]) & trb_chain; + + /* if this is not event ring, there is one less usable trb. */ + if (!cdnsp_trb_is_link(ring->enqueue)) + ring->num_trbs_free--; + next = ++(ring->enqueue); + + /* update the dequeue pointer further if that was a link trb */ + while (cdnsp_trb_is_link(next)) { + /* + * if the caller doesn't plan on enqueuing more tds before + * ringing the doorbell, then we don't want to give the link trb + * to the hardware just yet. we'll give the link trb back in + * cdnsp_prepare_ring() just before we enqueue the td at the + * top of the ring. + */ + if (!chain && !more_trbs_coming) + break; + + next->link.control &= cpu_to_le32(~trb_chain); + next->link.control |= cpu_to_le32(chain); + + /* give this link trb to the hardware */ + wmb(); + next->link.control ^= cpu_to_le32(trb_cycle); + + /* toggle the cycle bit after the last ring segment. */ + if (cdnsp_link_trb_toggles_cycle(next)) + ring->cycle_state ^= 1; + + ring->enq_seg = ring->enq_seg->next; + ring->enqueue = ring->enq_seg->trbs; + next = ring->enqueue; + } +} + +/* + * check to see if there's room to enqueue num_trbs on the ring and make sure + * enqueue pointer will not advance into dequeue segment. + */ +static bool cdnsp_room_on_ring(struct cdnsp_device *pdev, + struct cdnsp_ring *ring, + unsigned int num_trbs) +{ + int num_trbs_in_deq_seg; + + if (ring->num_trbs_free < num_trbs) + return false; + + if (ring->type != type_command && ring->type != type_event) { + num_trbs_in_deq_seg = ring->dequeue - ring->deq_seg->trbs; + + if (ring->num_trbs_free < num_trbs + num_trbs_in_deq_seg) + return false; + } + + return true; +} + +/* + * workaround for l1: controller has issue with resuming from l1 after + * setting doorbell for endpoint during l1 state. this function forces + * resume signal in such case. + */ +static void cdnsp_force_l0_go(struct cdnsp_device *pdev) +{ + if (pdev->active_port == &pdev->usb2_port && pdev->gadget.lpm_capable) + cdnsp_set_link_state(pdev, &pdev->active_port->regs->portsc, xdev_u0); +} + +/* ring the doorbell after placing a command on the ring. */ +void cdnsp_ring_cmd_db(struct cdnsp_device *pdev) +{ + writel(db_value_cmd, &pdev->dba->cmd_db); +} + +/* + * ring the doorbell after placing a transfer on the ring. + * returns true if doorbell was set, otherwise false. + */ +static bool cdnsp_ring_ep_doorbell(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, + unsigned int stream_id) +{ + __le32 __iomem *reg_addr = &pdev->dba->ep_db; + unsigned int ep_state = pep->ep_state; + unsigned int db_value; + + /* + * don't ring the doorbell for this endpoint if endpoint is halted or + * disabled. + */ + if (ep_state & ep_halted || !(ep_state & ep_enabled)) + return false; + + /* for stream capable endpoints driver can ring doorbell only twice. */ + if (pep->ep_state & ep_has_streams) { + if (pep->stream_info.drbls_count >= 2) + return false; + + pep->stream_info.drbls_count++; + } + + pep->ep_state &= ~ep_stopped; + + if (pep->idx == 0 && pdev->ep0_stage == cdnsp_data_stage && + !pdev->ep0_expect_in) + db_value = db_value_ep0_out(pep->idx, stream_id); + else + db_value = db_value(pep->idx, stream_id); + + writel(db_value, reg_addr); + + cdnsp_force_l0_go(pdev); + + /* doorbell was set. */ + return true; +} + +/* + * get the right ring for the given pep and stream_id. + * if the endpoint supports streams, boundary check the usb request's stream id. + * if the endpoint doesn't support streams, return the singular endpoint ring. + */ +static struct cdnsp_ring *cdnsp_get_transfer_ring(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, + unsigned int stream_id) +{ + if (!(pep->ep_state & ep_has_streams)) + return pep->ring; + + if (stream_id == 0 || stream_id >= pep->stream_info.num_streams) { + dev_err(pdev->dev, "err: %s ring doesn't exist for sid: %d. ", + pep->name, stream_id); + return null; + } + + return pep->stream_info.stream_rings[stream_id]; +} + +static struct cdnsp_ring * + cdnsp_request_to_transfer_ring(struct cdnsp_device *pdev, + struct cdnsp_request *preq) +{ + return cdnsp_get_transfer_ring(pdev, preq->pep, + preq->request.stream_id); +} + +/* ring the doorbell for any rings with pending requests. */ +void cdnsp_ring_doorbell_for_active_rings(struct cdnsp_device *pdev, + struct cdnsp_ep *pep) +{ + struct cdnsp_stream_info *stream_info; + unsigned int stream_id; + int ret; + + if (pep->ep_state & ep_dis_in_rrogress) + return; + + /* a ring has pending request if its td list is not empty. */ + if (!(pep->ep_state & ep_has_streams) && pep->number) { + if (pep->ring && !list_empty(&pep->ring->td_list)) + cdnsp_ring_ep_doorbell(pdev, pep, 0); + return; + } + + stream_info = &pep->stream_info; + + for (stream_id = 1; stream_id < stream_info->num_streams; stream_id++) { + struct cdnsp_td *td, *td_temp; + struct cdnsp_ring *ep_ring; + + if (stream_info->drbls_count >= 2) + return; + + ep_ring = cdnsp_get_transfer_ring(pdev, pep, stream_id); + if (!ep_ring) + continue; + + if (!ep_ring->stream_active || ep_ring->stream_rejected) + continue; + + list_for_each_entry_safe(td, td_temp, &ep_ring->td_list, + td_list) { + if (td->drbl) + continue; + + ret = cdnsp_ring_ep_doorbell(pdev, pep, stream_id); + if (ret) + td->drbl = 1; + } + } +} + +/* + * get the hw dequeue pointer controller stopped on, either directly from the + * endpoint context, or if streams are in use from the stream context. + * the returned hw_dequeue contains the lowest four bits with cycle state + * and possible stream context type. + */ +static u64 cdnsp_get_hw_deq(struct cdnsp_device *pdev, + unsigned int ep_index, + unsigned int stream_id) +{ + struct cdnsp_stream_ctx *st_ctx; + struct cdnsp_ep *pep; + + pep = &pdev->eps[stream_id]; + + if (pep->ep_state & ep_has_streams) { + st_ctx = &pep->stream_info.stream_ctx_array[stream_id]; + return le64_to_cpu(st_ctx->stream_ring); + } + + return le64_to_cpu(pep->out_ctx->deq); +} + +/* + * move the controller endpoint ring dequeue pointer past cur_td. + * record the new state of the controller endpoint ring dequeue segment, + * dequeue pointer, and new consumer cycle state in state. + * update internal representation of the ring's dequeue pointer. + * + * we do this in three jumps: + * - first we update our new ring state to be the same as when the + * controller stopped. + * - then we traverse the ring to find the segment that contains + * the last trb in the td. we toggle the controller new cycle state + * when we pass any link trbs with the toggle cycle bit set. + * - finally we move the dequeue state one trb further, toggling the cycle bit + * if we've moved it past a link trb with the toggle cycle bit set. + */ +static void cdnsp_find_new_dequeue_state(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, + unsigned int stream_id, + struct cdnsp_td *cur_td, + struct cdnsp_dequeue_state *state) +{ + bool td_last_trb_found = false; + struct cdnsp_segment *new_seg; + struct cdnsp_ring *ep_ring; + union cdnsp_trb *new_deq; + bool cycle_found = false; + u64 hw_dequeue; + + ep_ring = cdnsp_get_transfer_ring(pdev, pep, stream_id); + if (!ep_ring) + return; + + /* + * dig out the cycle state saved by the controller during the + * stop endpoint command. + */ + hw_dequeue = cdnsp_get_hw_deq(pdev, pep->idx, stream_id); + new_seg = ep_ring->deq_seg; + new_deq = ep_ring->dequeue; + state->new_cycle_state = hw_dequeue & 0x1; + state->stream_id = stream_id; + + /* + * we want to find the pointer, segment and cycle state of the new trb + * (the one after current td's last_trb). we know the cycle state at + * hw_dequeue, so walk the ring until both hw_dequeue and last_trb are + * found. + */ + do { + if (!cycle_found && cdnsp_trb_virt_to_dma(new_seg, new_deq) + == (dma_addr_t)(hw_dequeue & ~0xf)) { + cycle_found = true; + + if (td_last_trb_found) + break; + } + + if (new_deq == cur_td->last_trb) + td_last_trb_found = true; + + if (cycle_found && cdnsp_trb_is_link(new_deq) && + cdnsp_link_trb_toggles_cycle(new_deq)) + state->new_cycle_state ^= 0x1; + + cdnsp_next_trb(pdev, ep_ring, &new_seg, &new_deq); + + /* search wrapped around, bail out. */ + if (new_deq == pep->ring->dequeue) { + dev_err(pdev->dev, + "error: failed finding new dequeue state "); + state->new_deq_seg = null; + state->new_deq_ptr = null; + return; + } + + } while (!cycle_found || !td_last_trb_found); + + state->new_deq_seg = new_seg; + state->new_deq_ptr = new_deq; +} + +/* + * flip_cycle means flip the cycle bit of all but the first and last trb. + * (the last trb actually points to the ring enqueue pointer, which is not part + * of this td.) this is used to remove partially enqueued isoc tds from a ring. + */ +static void cdnsp_td_to_noop(struct cdnsp_device *pdev, + struct cdnsp_ring *ep_ring, + struct cdnsp_td *td, + bool flip_cycle) +{ + struct cdnsp_segment *seg = td->start_seg; + union cdnsp_trb *trb = td->first_trb; + + while (1) { + cdnsp_trb_to_noop(trb, trb_tr_noop); + + /* flip cycle if asked to */ + if (flip_cycle && trb != td->first_trb && trb != td->last_trb) + trb->generic.field[3] ^= cpu_to_le32(trb_cycle); + + if (trb == td->last_trb) + break; + + cdnsp_next_trb(pdev, ep_ring, &seg, &trb); + } +} + +/* + * this td is defined by the trbs starting at start_trb in start_seg and ending + * at end_trb, which may be in another segment. if the suspect dma address is a + * trb in this td, this function returns that trb's segment. otherwise it + * returns 0. + */ +static struct cdnsp_segment *cdnsp_trb_in_td(struct cdnsp_device *pdev, + struct cdnsp_segment *start_seg, + union cdnsp_trb *start_trb, + union cdnsp_trb *end_trb, + dma_addr_t suspect_dma) +{ + struct cdnsp_segment *cur_seg; + union cdnsp_trb *temp_trb; + dma_addr_t end_seg_dma; + dma_addr_t end_trb_dma; + dma_addr_t start_dma; + + start_dma = cdnsp_trb_virt_to_dma(start_seg, start_trb); + cur_seg = start_seg; + + do { + if (start_dma == 0) + return null; + + temp_trb = &cur_seg->trbs[trbs_per_segment - 1]; + /* we may get an event for a link trb in the middle of a td */ + end_seg_dma = cdnsp_trb_virt_to_dma(cur_seg, temp_trb); + /* if the end trb isn't in this segment, this is set to 0 */ + end_trb_dma = cdnsp_trb_virt_to_dma(cur_seg, end_trb); + + if (end_trb_dma > 0) { + /* + * the end trb is in this segment, so suspect should + * be here + */ + if (start_dma <= end_trb_dma) { + if (suspect_dma >= start_dma && + suspect_dma <= end_trb_dma) { + return cur_seg; + } + } else { + /* + * case for one segment with a + * td wrapped around to the top + */ + if ((suspect_dma >= start_dma && + suspect_dma <= end_seg_dma) || + (suspect_dma >= cur_seg->dma && + suspect_dma <= end_trb_dma)) { + return cur_seg; + } + } + + return null; + } + + /* might still be somewhere in this segment */ + if (suspect_dma >= start_dma && suspect_dma <= end_seg_dma) + return cur_seg; + + cur_seg = cur_seg->next; + start_dma = cdnsp_trb_virt_to_dma(cur_seg, &cur_seg->trbs[0]); + } while (cur_seg != start_seg); + + return null; +} + +static void cdnsp_unmap_td_bounce_buffer(struct cdnsp_device *pdev, + struct cdnsp_ring *ring, + struct cdnsp_td *td) +{ + struct cdnsp_segment *seg = td->bounce_seg; + struct cdnsp_request *preq; + size_t len; + + if (!seg) + return; + + preq = td->preq; + + if (!preq->direction) { + dma_unmap_single(pdev->dev, seg->bounce_dma, + ring->bounce_buf_len, dma_to_device); + return; + } + + dma_unmap_single(pdev->dev, seg->bounce_dma, ring->bounce_buf_len, + dma_from_device); + + /* for in transfers we need to copy the data from bounce to sg */ + len = sg_pcopy_from_buffer(preq->request.sg, preq->request.num_sgs, + seg->bounce_buf, seg->bounce_len, + seg->bounce_offs); + if (len != seg->bounce_len) + dev_warn(pdev->dev, "warn wrong bounce buffer read length: %zu != %d ", + len, seg->bounce_len); + + seg->bounce_len = 0; + seg->bounce_offs = 0; +} + +static int cdnsp_cmd_set_deq(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, + struct cdnsp_dequeue_state *deq_state) +{ + struct cdnsp_ring *ep_ring; + int ret; + + if (!deq_state->new_deq_ptr || !deq_state->new_deq_seg) { + cdnsp_ring_doorbell_for_active_rings(pdev, pep); + return 0; + } + + cdnsp_queue_new_dequeue_state(pdev, pep, deq_state); + cdnsp_ring_cmd_db(pdev); + ret = cdnsp_wait_for_cmd_compl(pdev); + + /* + * update the ring's dequeue segment and dequeue pointer + * to reflect the new position. + */ + ep_ring = cdnsp_get_transfer_ring(pdev, pep, deq_state->stream_id); + + if (cdnsp_trb_is_link(ep_ring->dequeue)) { + ep_ring->deq_seg = ep_ring->deq_seg->next; + ep_ring->dequeue = ep_ring->deq_seg->trbs; + } + + while (ep_ring->dequeue != deq_state->new_deq_ptr) { + ep_ring->num_trbs_free++; + ep_ring->dequeue++; + + if (cdnsp_trb_is_link(ep_ring->dequeue)) { + if (ep_ring->dequeue == deq_state->new_deq_ptr) + break; + + ep_ring->deq_seg = ep_ring->deq_seg->next; + ep_ring->dequeue = ep_ring->deq_seg->trbs; + } + } + + /* + * probably there was timeout during handling set dequeue pointer + * command. it's critical error and controller will be stopped. + */ + if (ret) + return -eshutdown; + + /* restart any rings with pending requests */ + cdnsp_ring_doorbell_for_active_rings(pdev, pep); + + return 0; +} + +int cdnsp_remove_request(struct cdnsp_device *pdev, + struct cdnsp_request *preq, + struct cdnsp_ep *pep) +{ + struct cdnsp_dequeue_state deq_state; + struct cdnsp_td *cur_td = null; + struct cdnsp_ring *ep_ring; + struct cdnsp_segment *seg; + int status = -econnreset; + int ret = 0; + u64 hw_deq; + + memset(&deq_state, 0, sizeof(deq_state)); + + cur_td = &preq->td; + ep_ring = cdnsp_request_to_transfer_ring(pdev, preq); + + /* + * if we stopped on the td we need to cancel, then we have to + * move the controller endpoint ring dequeue pointer past + * this td. + */ + hw_deq = cdnsp_get_hw_deq(pdev, pep->idx, preq->request.stream_id); + hw_deq &= ~0xf; + + seg = cdnsp_trb_in_td(pdev, cur_td->start_seg, cur_td->first_trb, + cur_td->last_trb, hw_deq); + + if (seg && (pep->ep_state & ep_enabled)) + cdnsp_find_new_dequeue_state(pdev, pep, preq->request.stream_id, + cur_td, &deq_state); + else + cdnsp_td_to_noop(pdev, ep_ring, cur_td, false); + + /* + * the event handler won't see a completion for this td anymore, + * so remove it from the endpoint ring's td list. + */ + list_del_init(&cur_td->td_list); + ep_ring->num_tds--; + pep->stream_info.td_count--; + + /* + * during disconnecting all endpoint will be disabled so we don't + * have to worry about updating dequeue pointer. + */ + if (pdev->cdnsp_state & cdnsp_state_disconnect_pending) { + status = -eshutdown; + ret = cdnsp_cmd_set_deq(pdev, pep, &deq_state); + } + + cdnsp_unmap_td_bounce_buffer(pdev, ep_ring, cur_td); + cdnsp_gadget_giveback(pep, cur_td->preq, status); + + return ret; +} + +static int cdnsp_update_port_id(struct cdnsp_device *pdev, u32 port_id) +{ + struct cdnsp_port *port = pdev->active_port; + u8 old_port = 0; + + if (port && port->port_num == port_id) + return 0; + + if (port) + old_port = port->port_num; + + if (port_id == pdev->usb2_port.port_num) { + port = &pdev->usb2_port; + } else if (port_id == pdev->usb3_port.port_num) { + port = &pdev->usb3_port; + } else { + dev_err(pdev->dev, "port event with invalid port id %d ", + port_id); + return -einval; + } + + if (port_id != old_port) { + cdnsp_disable_slot(pdev); + pdev->active_port = port; + cdnsp_enable_slot(pdev); + } + + if (port_id == pdev->usb2_port.port_num) + cdnsp_set_usb2_hardware_lpm(pdev, null, 1); + else + writel(port_u1_timeout(1) | port_u2_timeout(1), + &pdev->usb3_port.regs->portpmsc); + + return 0; +} + +static void cdnsp_handle_port_status(struct cdnsp_device *pdev, + union cdnsp_trb *event) +{ + struct cdnsp_port_regs __iomem *port_regs; + u32 portsc, cmd_regs; + bool port2 = false; + u32 link_state; + u32 port_id; + + /* port status change events always have a successful completion code */ + if (get_comp_code(le32_to_cpu(event->generic.field[2])) != comp_success) + dev_err(pdev->dev, "err: incorrect psc event "); + + port_id = get_port_id(le32_to_cpu(event->generic.field[0])); + + if (cdnsp_update_port_id(pdev, port_id)) + goto cleanup; + + port_regs = pdev->active_port->regs; + + if (port_id == pdev->usb2_port.port_num) + port2 = true; + +new_event: + portsc = readl(&port_regs->portsc); + writel(cdnsp_port_state_to_neutral(portsc) | + (portsc & port_change_bits), &port_regs->portsc); + + pdev->gadget.speed = cdnsp_port_speed(portsc); + link_state = portsc & port_pls_mask; + + /* port link state change detected. */ + if ((portsc & port_plc)) { + if (!(pdev->cdnsp_state & cdnsp_wakeup_pending) && + link_state == xdev_resume) { + cmd_regs = readl(&pdev->op_regs->command); + if (!(cmd_regs & cmd_r_s)) + goto cleanup; + + if (dev_superspeed_any(portsc)) { + cdnsp_set_link_state(pdev, &port_regs->portsc, + xdev_u0); + + cdnsp_resume_gadget(pdev); + } + } + + if ((pdev->cdnsp_state & cdnsp_wakeup_pending) && + link_state == xdev_u0) { + pdev->cdnsp_state &= ~cdnsp_wakeup_pending; + + cdnsp_force_header_wakeup(pdev, 1); + cdnsp_ring_cmd_db(pdev); + cdnsp_wait_for_cmd_compl(pdev); + } + + if (link_state == xdev_u0 && pdev->link_state == xdev_u3 && + !dev_superspeed_any(portsc)) + cdnsp_resume_gadget(pdev); + + if (link_state == xdev_u3 && pdev->link_state != xdev_u3) + cdnsp_suspend_gadget(pdev); + + pdev->link_state = link_state; + } + + if (portsc & port_csc) { + /* detach device. */ + if (pdev->gadget.connected && !(portsc & port_connect)) + cdnsp_disconnect_gadget(pdev); + + /* attach device. */ + if (portsc & port_connect) { + if (!port2) + cdnsp_irq_reset(pdev); + + usb_gadget_set_state(&pdev->gadget, usb_state_attached); + } + } + + /* port reset. */ + if ((portsc & (port_rc | port_wrc)) && (portsc & port_connect)) { + cdnsp_irq_reset(pdev); + pdev->u1_allowed = 0; + pdev->u2_allowed = 0; + pdev->may_wakeup = 0; + } + + if (portsc & port_cec) + dev_err(pdev->dev, "port over current detected "); + + if (portsc & port_cec) + dev_err(pdev->dev, "port configure error detected "); + + if (readl(&port_regs->portsc) & port_change_bits) + goto new_event; + +cleanup: + cdnsp_inc_deq(pdev, pdev->event_ring); +} + +static void cdnsp_td_cleanup(struct cdnsp_device *pdev, + struct cdnsp_td *td, + struct cdnsp_ring *ep_ring, + int *status) +{ + struct cdnsp_request *preq = td->preq; + + /* if a bounce buffer was used to align this td then unmap it */ + cdnsp_unmap_td_bounce_buffer(pdev, ep_ring, td); + + /* + * if the controller said we transferred more data than the buffer + * length, play it safe and say we didn't transfer anything. + */ + if (preq->request.actual > preq->request.length) { + preq->request.actual = 0; + *status = 0; + } + + list_del_init(&td->td_list); + ep_ring->num_tds--; + preq->pep->stream_info.td_count--; + + cdnsp_gadget_giveback(preq->pep, preq, *status); +} + +static void cdnsp_finish_td(struct cdnsp_device *pdev, + struct cdnsp_td *td, + struct cdnsp_transfer_event *event, + struct cdnsp_ep *ep, + int *status) +{ + struct cdnsp_ring *ep_ring; + u32 trb_comp_code; + + ep_ring = cdnsp_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer)); + trb_comp_code = get_comp_code(le32_to_cpu(event->transfer_len)); + + if (trb_comp_code == comp_stopped_length_invalid || + trb_comp_code == comp_stopped || + trb_comp_code == comp_stopped_short_packet) { + /* + * the endpoint stop command completion will take care of any + * stopped tds. a stopped td may be restarted, so don't update + * the ring dequeue pointer or take this td off any lists yet. + */ + return; + } + + /* update ring dequeue pointer */ + while (ep_ring->dequeue != td->last_trb) + cdnsp_inc_deq(pdev, ep_ring); + + cdnsp_inc_deq(pdev, ep_ring); + + cdnsp_td_cleanup(pdev, td, ep_ring, status); +} + +/* sum trb lengths from ring dequeue up to stop_trb, _excluding_ stop_trb */ +static int cdnsp_sum_trb_lengths(struct cdnsp_device *pdev, + struct cdnsp_ring *ring, + union cdnsp_trb *stop_trb) +{ + struct cdnsp_segment *seg = ring->deq_seg; + union cdnsp_trb *trb = ring->dequeue; + u32 sum; + + for (sum = 0; trb != stop_trb; cdnsp_next_trb(pdev, ring, &seg, &trb)) { + if (!cdnsp_trb_is_noop(trb) && !cdnsp_trb_is_link(trb)) + sum += trb_len(le32_to_cpu(trb->generic.field[2])); + } + return sum; +} + +static int cdnsp_giveback_first_trb(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, + unsigned int stream_id, + int start_cycle, + struct cdnsp_generic_trb *start_trb) +{ + /* + * pass all the trbs to the hardware at once and make sure this write + * isn't reordered. + */ + wmb(); + + if (start_cycle) + start_trb->field[3] |= cpu_to_le32(start_cycle); + else + start_trb->field[3] &= cpu_to_le32(~trb_cycle); + + if ((pep->ep_state & ep_has_streams) && + !pep->stream_info.first_prime_det) + return 0; + + return cdnsp_ring_ep_doorbell(pdev, pep, stream_id); +} + +/* + * process control tds, update usb request status and actual_length. + */ +static void cdnsp_process_ctrl_td(struct cdnsp_device *pdev, + struct cdnsp_td *td, + union cdnsp_trb *event_trb, + struct cdnsp_transfer_event *event, + struct cdnsp_ep *pep, + int *status) +{ + struct cdnsp_ring *ep_ring; + u32 remaining; + u32 trb_type; + + trb_type = trb_field_to_type(le32_to_cpu(event_trb->generic.field[3])); + ep_ring = cdnsp_dma_to_transfer_ring(pep, le64_to_cpu(event->buffer)); + remaining = event_trb_len(le32_to_cpu(event->transfer_len)); + + /* + * if on data stage then update the actual_length of the usb + * request and flag it as set, so it won't be overwritten in the event + * for the last trb. + */ + if (trb_type == trb_data) { + td->request_length_set = true; + td->preq->request.actual = td->preq->request.length - remaining; + } + + /* at status stage */ + if (!td->request_length_set) + td->preq->request.actual = td->preq->request.length; + + if (pdev->ep0_stage == cdnsp_data_stage && pep->number == 0 && + pdev->three_stage_setup) { + td = list_entry(ep_ring->td_list.next, struct cdnsp_td, + td_list); + pdev->ep0_stage = cdnsp_status_stage; + + cdnsp_giveback_first_trb(pdev, pep, 0, ep_ring->cycle_state, + &td->last_trb->generic); + return; + } + + cdnsp_finish_td(pdev, td, event, pep, status); +} + +/* + * process isochronous tds, update usb request status and actual_length. + */ +static void cdnsp_process_isoc_td(struct cdnsp_device *pdev, + struct cdnsp_td *td, + union cdnsp_trb *ep_trb, + struct cdnsp_transfer_event *event, + struct cdnsp_ep *pep, + int status) +{ + struct cdnsp_request *preq = td->preq; + u32 remaining, requested, ep_trb_len; + bool sum_trbs_for_length = false; + struct cdnsp_ring *ep_ring; + u32 trb_comp_code; + u32 td_length; + + ep_ring = cdnsp_dma_to_transfer_ring(pep, le64_to_cpu(event->buffer)); + trb_comp_code = get_comp_code(le32_to_cpu(event->transfer_len)); + remaining = event_trb_len(le32_to_cpu(event->transfer_len)); + ep_trb_len = trb_len(le32_to_cpu(ep_trb->generic.field[2])); + + requested = preq->request.length; + + /* handle completion code */ + switch (trb_comp_code) { + case comp_success: + preq->request.status = 0; + break; + case comp_short_packet: + preq->request.status = 0; + sum_trbs_for_length = true; + break; + case comp_isoch_buffer_overrun: + case comp_babble_detected_error: + preq->request.status = -eoverflow; + break; + case comp_stopped: + sum_trbs_for_length = true; + break; + case comp_stopped_short_packet: + /* field normally containing residue now contains transferred */ + preq->request.status = 0; + requested = remaining; + break; + case comp_stopped_length_invalid: + requested = 0; + remaining = 0; + break; + default: + sum_trbs_for_length = true; + preq->request.status = -1; + break; + } + + if (sum_trbs_for_length) { + td_length = cdnsp_sum_trb_lengths(pdev, ep_ring, ep_trb); + td_length += ep_trb_len - remaining; + } else { + td_length = requested; + } + + td->preq->request.actual += td_length; + + cdnsp_finish_td(pdev, td, event, pep, &status); +} + +static void cdnsp_skip_isoc_td(struct cdnsp_device *pdev, + struct cdnsp_td *td, + struct cdnsp_transfer_event *event, + struct cdnsp_ep *pep, + int status) +{ + struct cdnsp_ring *ep_ring; + + ep_ring = cdnsp_dma_to_transfer_ring(pep, le64_to_cpu(event->buffer)); + td->preq->request.status = -exdev; + td->preq->request.actual = 0; + + /* update ring dequeue pointer */ + while (ep_ring->dequeue != td->last_trb) + cdnsp_inc_deq(pdev, ep_ring); + + cdnsp_inc_deq(pdev, ep_ring); + + cdnsp_td_cleanup(pdev, td, ep_ring, &status); +} + +/* + * process bulk and interrupt tds, update usb request status and actual_length. + */ +static void cdnsp_process_bulk_intr_td(struct cdnsp_device *pdev, + struct cdnsp_td *td, + union cdnsp_trb *ep_trb, + struct cdnsp_transfer_event *event, + struct cdnsp_ep *ep, + int *status) +{ + u32 remaining, requested, ep_trb_len; + struct cdnsp_ring *ep_ring; + u32 trb_comp_code; + + ep_ring = cdnsp_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer)); + trb_comp_code = get_comp_code(le32_to_cpu(event->transfer_len)); + remaining = event_trb_len(le32_to_cpu(event->transfer_len)); + ep_trb_len = trb_len(le32_to_cpu(ep_trb->generic.field[2])); + requested = td->preq->request.length; + + switch (trb_comp_code) { + case comp_success: + case comp_short_packet: + *status = 0; + break; + case comp_stopped_short_packet: + td->preq->request.actual = remaining; + goto finish_td; + case comp_stopped_length_invalid: + /* stopped on ep trb with invalid length, exclude it. */ + ep_trb_len = 0; + remaining = 0; + break; + } + + if (ep_trb == td->last_trb) + ep_trb_len = requested - remaining; + else + ep_trb_len = cdnsp_sum_trb_lengths(pdev, ep_ring, ep_trb) + + ep_trb_len - remaining; + td->preq->request.actual = ep_trb_len; + +finish_td: + ep->stream_info.drbls_count--; + + cdnsp_finish_td(pdev, td, event, ep, status); +} + +static void cdnsp_handle_tx_nrdy(struct cdnsp_device *pdev, + struct cdnsp_transfer_event *event) +{ + struct cdnsp_generic_trb *generic; + struct cdnsp_ring *ep_ring; + struct cdnsp_ep *pep; + int cur_stream; + int ep_index; + int host_sid; + int dev_sid; + + generic = (struct cdnsp_generic_trb *)event; + ep_index = trb_to_ep_id(le32_to_cpu(event->flags)) - 1; + dev_sid = trb_to_dev_stream(le32_to_cpu(generic->field[0])); + host_sid = trb_to_host_stream(le32_to_cpu(generic->field[2])); + + pep = &pdev->eps[ep_index]; + + if (!(pep->ep_state & ep_has_streams)) + return; + + if (host_sid == stream_prime_ack) { + pep->stream_info.first_prime_det = 1; + for (cur_stream = 1; cur_stream < pep->stream_info.num_streams; + cur_stream++) { + ep_ring = pep->stream_info.stream_rings[cur_stream]; + ep_ring->stream_active = 1; + ep_ring->stream_rejected = 0; + } + } + + if (host_sid == stream_rejected) { + struct cdnsp_td *td, *td_temp; + + pep->stream_info.drbls_count--; + ep_ring = pep->stream_info.stream_rings[dev_sid]; + ep_ring->stream_active = 0; + ep_ring->stream_rejected = 1; + + list_for_each_entry_safe(td, td_temp, &ep_ring->td_list, + td_list) { + td->drbl = 0; + } + } + + cdnsp_ring_doorbell_for_active_rings(pdev, pep); +} + +/* + * if this function returns an error condition, it means it got a transfer + * event with a corrupted trb dma address or endpoint is disabled. + */ +static int cdnsp_handle_tx_event(struct cdnsp_device *pdev, + struct cdnsp_transfer_event *event) +{ + const struct usb_endpoint_descriptor *desc; + bool handling_skipped_tds = false; + struct cdnsp_segment *ep_seg; + struct cdnsp_ring *ep_ring; + int status = -einprogress; + union cdnsp_trb *ep_trb; + dma_addr_t ep_trb_dma; + struct cdnsp_ep *pep; + struct cdnsp_td *td; + u32 trb_comp_code; + int invalidate; + int ep_index; + + invalidate = le32_to_cpu(event->flags) & trb_event_invalidate; + ep_index = trb_to_ep_id(le32_to_cpu(event->flags)) - 1; + trb_comp_code = get_comp_code(le32_to_cpu(event->transfer_len)); + ep_trb_dma = le64_to_cpu(event->buffer); + + pep = &pdev->eps[ep_index]; + ep_ring = cdnsp_dma_to_transfer_ring(pep, le64_to_cpu(event->buffer)); + + /* + * if device is disconnect then all requests will be dequeued + * by upper layers as part of disconnect sequence. + * we don't want handle such event to avoid racing. + */ + if (invalidate || !pdev->gadget.connected) + goto cleanup; + + if (get_ep_ctx_state(pep->out_ctx) == ep_state_disabled) + goto err_out; + + /* some transfer events don't always point to a trb*/ + if (!ep_ring) { + switch (trb_comp_code) { + case comp_invalid_stream_type_error: + case comp_invalid_stream_id_error: + case comp_ring_underrun: + case comp_ring_overrun: + goto cleanup; + default: + dev_err(pdev->dev, "error: %s event for unknown ring ", + pep->name); + goto err_out; + } + } + + /* look for some error cases that need special treatment. */ + switch (trb_comp_code) { + case comp_babble_detected_error: + status = -eoverflow; + break; + case comp_ring_underrun: + case comp_ring_overrun: + /* + * when the isoch ring is empty, the controller will generate + * a ring overrun event for in isoch endpoint or ring + * underrun event for out isoch endpoint. + */ + goto cleanup; + case comp_missed_service_error: + /* + * when encounter missed service error, one or more isoc tds + * may be missed by controller. + * set skip flag of the ep_ring; complete the missed tds as + * short transfer when process the ep_ring next time. + */ + pep->skip = true; + break; + } + + do { + /* + * this trb should be in the td at the head of this ring's td + * list. + */ + if (list_empty(&ep_ring->td_list)) { + if (pep->skip) + pep->skip = false; + + goto cleanup; + } + + td = list_entry(ep_ring->td_list.next, struct cdnsp_td, + td_list); + + /* is this a trb in the currently executing td? */ + ep_seg = cdnsp_trb_in_td(pdev, ep_ring->deq_seg, + ep_ring->dequeue, td->last_trb, + ep_trb_dma); + + /* + * skip the force stopped event. the event_trb(ep_trb_dma) + * of fse is not in the current td pointed by ep_ring->dequeue + * because that the hardware dequeue pointer still at the + * previous trb of the current td. the previous trb maybe a + * link td or the last trb of the previous td. the command + * completion handle will take care the rest. + */ + if (!ep_seg && (trb_comp_code == comp_stopped || + trb_comp_code == comp_stopped_length_invalid)) { + pep->skip = false; + goto cleanup; + } + + desc = td->preq->pep->endpoint.desc; + if (!ep_seg) { + if (!pep->skip || !usb_endpoint_xfer_isoc(desc)) { + /* something is busted, give up! */ + dev_err(pdev->dev, + "error transfer event trb dma ptr not " + "part of current td ep_index %d " + "comp_code %u ", ep_index, + trb_comp_code); + return -einval; + } + + cdnsp_skip_isoc_td(pdev, td, event, pep, status); + goto cleanup; + } + + if (trb_comp_code == comp_short_packet) + ep_ring->last_td_was_short = true; + else + ep_ring->last_td_was_short = false; + + if (pep->skip) { + pep->skip = false; + cdnsp_skip_isoc_td(pdev, td, event, pep, status); + goto cleanup; + } + + ep_trb = &ep_seg->trbs[(ep_trb_dma - ep_seg->dma) + / sizeof(*ep_trb)]; + + if (cdnsp_trb_is_noop(ep_trb)) + goto cleanup; + + if (usb_endpoint_xfer_control(desc)) + cdnsp_process_ctrl_td(pdev, td, ep_trb, event, pep, + &status); + else if (usb_endpoint_xfer_isoc(desc)) + cdnsp_process_isoc_td(pdev, td, ep_trb, event, pep, + status); + else + cdnsp_process_bulk_intr_td(pdev, td, ep_trb, event, pep, + &status); +cleanup: + handling_skipped_tds = pep->skip; + + /* + * do not update event ring dequeue pointer if we're in a loop + * processing missed tds. + */ + if (!handling_skipped_tds) + cdnsp_inc_deq(pdev, pdev->event_ring); + + /* + * if ep->skip is set, it means there are missed tds on the + * endpoint ring need to take care of. + * process them as short transfer until reach the td pointed by + * the event. + */ + } while (handling_skipped_tds); + return 0; + +err_out: + dev_err(pdev->dev, "@%016llx %08x %08x %08x %08x ", + (unsigned long long) + cdnsp_trb_virt_to_dma(pdev->event_ring->deq_seg, + pdev->event_ring->dequeue), + lower_32_bits(le64_to_cpu(event->buffer)), + upper_32_bits(le64_to_cpu(event->buffer)), + le32_to_cpu(event->transfer_len), + le32_to_cpu(event->flags)); + return -einval; +} + +/* + * this function handles all events on the event ring. + * returns true for "possibly more events to process" (caller should call + * again), otherwise false if done. + */ +static bool cdnsp_handle_event(struct cdnsp_device *pdev) +{ + unsigned int comp_code; + union cdnsp_trb *event; + bool update_ptrs = true; + __le32 cycle_bit; + int ret = 0; + u32 flags; + + event = pdev->event_ring->dequeue; + flags = le32_to_cpu(event->event_cmd.flags); + cycle_bit = (flags & trb_cycle); + + /* does the controller or driver own the trb? */ + if (cycle_bit != pdev->event_ring->cycle_state) + return false; + + /* + * barrier between reading the trb_cycle (valid) flag above and any + * reads of the event's flags/data below. + */ + rmb(); + + switch (flags & trb_type_bitmask) { + case trb_type(trb_completion): + /* + * command can't be handled in interrupt context so just + * increment command ring dequeue pointer. + */ + cdnsp_inc_deq(pdev, pdev->cmd_ring); + break; + case trb_type(trb_port_status): + cdnsp_handle_port_status(pdev, event); + update_ptrs = false; + break; + case trb_type(trb_transfer): + ret = cdnsp_handle_tx_event(pdev, &event->trans_event); + if (ret >= 0) + update_ptrs = false; + break; + case trb_type(trb_setup): + pdev->ep0_stage = cdnsp_setup_stage; + pdev->setup_id = trb_setupid_to_type(flags); + pdev->setup_speed = trb_setup_speedid(flags); + pdev->setup = *((struct usb_ctrlrequest *) + &event->trans_event.buffer); + + cdnsp_setup_analyze(pdev); + break; + case trb_type(trb_endpoint_nrdy): + cdnsp_handle_tx_nrdy(pdev, &event->trans_event); + break; + case trb_type(trb_hc_event): { + comp_code = get_comp_code(le32_to_cpu(event->generic.field[2])); + + switch (comp_code) { + case comp_event_ring_full_error: + dev_err(pdev->dev, "event ring full "); + break; + default: + dev_err(pdev->dev, "controller error code 0x%02x ", + comp_code); + } + + break; + } + case trb_type(trb_mfindex_wrap): + case trb_type(trb_drb_overflow): + break; + default: + dev_warn(pdev->dev, "error unknown event type %ld ", + trb_field_to_type(flags)); + } + + if (update_ptrs) + /* update sw event ring dequeue pointer. */ + cdnsp_inc_deq(pdev, pdev->event_ring); + + /* + * caller will call us again to check if there are more items + * on the event ring. + */ + return true; +} + +irqreturn_t cdnsp_thread_irq_handler(int irq, void *data) +{ + struct cdnsp_device *pdev = (struct cdnsp_device *)data; + union cdnsp_trb *event_ring_deq; + int counter = 0; + + spin_lock(&pdev->lock); + + if (pdev->cdnsp_state & (cdnsp_state_halted | cdnsp_state_dying)) { + cdnsp_died(pdev); + spin_unlock(&pdev->lock); + return irq_handled; + } + + event_ring_deq = pdev->event_ring->dequeue; + + while (cdnsp_handle_event(pdev)) { + if (++counter >= trbs_per_ev_deq_update) { + cdnsp_update_erst_dequeue(pdev, event_ring_deq, 0); + event_ring_deq = pdev->event_ring->dequeue; + counter = 0; + } + } + + cdnsp_update_erst_dequeue(pdev, event_ring_deq, 1); + + spin_unlock(&pdev->lock); + + return irq_handled; +} + +irqreturn_t cdnsp_irq_handler(int irq, void *priv) +{ + struct cdnsp_device *pdev = (struct cdnsp_device *)priv; + u32 irq_pending; + u32 status; + + status = readl(&pdev->op_regs->status); + + if (status == ~(u32)0) { + cdnsp_died(pdev); + return irq_handled; + } + + if (!(status & sts_eint)) + return irq_none; + + writel(status | sts_eint, &pdev->op_regs->status); + irq_pending = readl(&pdev->ir_set->irq_pending); + irq_pending |= iman_ip; + writel(irq_pending, &pdev->ir_set->irq_pending); + + if (status & sts_fatal) { + cdnsp_died(pdev); + return irq_handled; + } + + return irq_wake_thread; +} + +/* + * generic function for queuing a trb on a ring. + * the caller must have checked to make sure there's room on the ring. + * + * @more_trbs_coming: will you enqueue more trbs before setting doorbell? + */ +static void cdnsp_queue_trb(struct cdnsp_device *pdev, struct cdnsp_ring *ring, + bool more_trbs_coming, u32 field1, u32 field2, + u32 field3, u32 field4) +{ + struct cdnsp_generic_trb *trb; + + trb = &ring->enqueue->generic; + + trb->field[0] = cpu_to_le32(field1); + trb->field[1] = cpu_to_le32(field2); + trb->field[2] = cpu_to_le32(field3); + trb->field[3] = cpu_to_le32(field4); + + cdnsp_inc_enq(pdev, ring, more_trbs_coming); +} + +/* + * does various checks on the endpoint ring, and makes it ready to + * queue num_trbs. + */ +static int cdnsp_prepare_ring(struct cdnsp_device *pdev, + struct cdnsp_ring *ep_ring, + u32 ep_state, unsigned + int num_trbs, + gfp_t mem_flags) +{ + unsigned int num_trbs_needed; + + /* make sure the endpoint has been added to controller schedule. */ + switch (ep_state) { + case ep_state_stopped: + case ep_state_running: + case ep_state_halted: + break; + default: + dev_err(pdev->dev, "error: incorrect endpoint state "); + return -einval; + } + + while (1) { + if (cdnsp_room_on_ring(pdev, ep_ring, num_trbs)) + break; + + num_trbs_needed = num_trbs - ep_ring->num_trbs_free; + if (cdnsp_ring_expansion(pdev, ep_ring, num_trbs_needed, + mem_flags)) { + dev_err(pdev->dev, "ring expansion failed "); + return -enomem; + } + } + + while (cdnsp_trb_is_link(ep_ring->enqueue)) { + ep_ring->enqueue->link.control |= cpu_to_le32(trb_chain); + /* the cycle bit must be set as the last operation. */ + wmb(); + ep_ring->enqueue->link.control ^= cpu_to_le32(trb_cycle); + + /* toggle the cycle bit after the last ring segment. */ + if (cdnsp_link_trb_toggles_cycle(ep_ring->enqueue)) + ep_ring->cycle_state ^= 1; + ep_ring->enq_seg = ep_ring->enq_seg->next; + ep_ring->enqueue = ep_ring->enq_seg->trbs; + } + return 0; +} + +static int cdnsp_prepare_transfer(struct cdnsp_device *pdev, + struct cdnsp_request *preq, + unsigned int num_trbs) +{ + struct cdnsp_ring *ep_ring; + int ret; + + ep_ring = cdnsp_get_transfer_ring(pdev, preq->pep, + preq->request.stream_id); + if (!ep_ring) + return -einval; + + ret = cdnsp_prepare_ring(pdev, ep_ring, + get_ep_ctx_state(preq->pep->out_ctx), + num_trbs, gfp_atomic); + if (ret) + return ret; + + init_list_head(&preq->td.td_list); + preq->td.preq = preq; + + /* add this td to the tail of the endpoint ring's td list. */ + list_add_tail(&preq->td.td_list, &ep_ring->td_list); + ep_ring->num_tds++; + preq->pep->stream_info.td_count++; + + preq->td.start_seg = ep_ring->enq_seg; + preq->td.first_trb = ep_ring->enqueue; + + return 0; +} + +static unsigned int cdnsp_count_trbs(u64 addr, u64 len) +{ + unsigned int num_trbs; + + num_trbs = div_round_up(len + (addr & (trb_max_buff_size - 1)), + trb_max_buff_size); + if (num_trbs == 0) + num_trbs++; + + return num_trbs; +} + +static unsigned int count_trbs_needed(struct cdnsp_request *preq) +{ + return cdnsp_count_trbs(preq->request.dma, preq->request.length); +} + +static unsigned int count_sg_trbs_needed(struct cdnsp_request *preq) +{ + unsigned int i, len, full_len, num_trbs = 0; + struct scatterlist *sg; + + full_len = preq->request.length; + + for_each_sg(preq->request.sg, sg, preq->request.num_sgs, i) { + len = sg_dma_len(sg); + num_trbs += cdnsp_count_trbs(sg_dma_address(sg), len); + len = min(len, full_len); + full_len -= len; + if (full_len == 0) + break; + } + + return num_trbs; +} + +static unsigned int count_isoc_trbs_needed(struct cdnsp_request *preq) +{ + return cdnsp_count_trbs(preq->request.dma, preq->request.length); +} + +static void cdnsp_check_trb_math(struct cdnsp_request *preq, int running_total) +{ + if (running_total != preq->request.length) + dev_err(preq->pep->pdev->dev, + "%s - miscalculated tx length, " + "queued %#x, asked for %#x (%d) ", + preq->pep->name, running_total, + preq->request.length, preq->request.actual); +} + +/* + * td size is the number of max packet sized packets remaining in the td + * (*not* including this trb). + * + * total td packet count = total_packet_count = + * div_round_up(td size in bytes / wmaxpacketsize) + * + * packets transferred up to and including this trb = packets_transferred = + * rounddown(total bytes transferred including this trb / wmaxpacketsize) + * + * td size = total_packet_count - packets_transferred + * + * it must fit in bits 21:17, so it can't be bigger than 31. + * this is taken care of in the trb_td_size() macro + * + * the last trb in a td must have the td size set to zero. + */ +static u32 cdnsp_td_remainder(struct cdnsp_device *pdev, + int transferred, + int trb_buff_len, + unsigned int td_total_len, + struct cdnsp_request *preq, + bool more_trbs_coming) +{ + u32 maxp, total_packet_count; + + /* one trb with a zero-length data packet. */ + if (!more_trbs_coming || (transferred == 0 && trb_buff_len == 0) || + trb_buff_len == td_total_len) + return 0; + + maxp = usb_endpoint_maxp(preq->pep->endpoint.desc); + total_packet_count = div_round_up(td_total_len, maxp); + + /* queuing functions don't count the current trb into transferred. */ + return (total_packet_count - ((transferred + trb_buff_len) / maxp)); +} + +static int cdnsp_align_td(struct cdnsp_device *pdev, + struct cdnsp_request *preq, u32 enqd_len, + u32 *trb_buff_len, struct cdnsp_segment *seg) +{ + struct device *dev = pdev->dev; + unsigned int unalign; + unsigned int max_pkt; + u32 new_buff_len; + + max_pkt = usb_endpoint_maxp(preq->pep->endpoint.desc); + unalign = (enqd_len + *trb_buff_len) % max_pkt; + + /* we got lucky, last normal trb data on segment is packet aligned. */ + if (unalign == 0) + return 0; + + /* is the last nornal trb alignable by splitting it. */ + if (*trb_buff_len > unalign) { + *trb_buff_len -= unalign; + return 0; + } + + /* + * we want enqd_len + trb_buff_len to sum up to a number aligned to + * number which is divisible by the endpoint's wmaxpacketsize. iow: + * (size of currently enqueued trbs + remainder) % wmaxpacketsize == 0. + */ + new_buff_len = max_pkt - (enqd_len % max_pkt); + + if (new_buff_len > (preq->request.length - enqd_len)) + new_buff_len = (preq->request.length - enqd_len); + + /* create a max max_pkt sized bounce buffer pointed to by last trb. */ + if (preq->direction) { + sg_pcopy_to_buffer(preq->request.sg, + preq->request.num_mapped_sgs, + seg->bounce_buf, new_buff_len, enqd_len); + seg->bounce_dma = dma_map_single(dev, seg->bounce_buf, + max_pkt, dma_to_device); + } else { + seg->bounce_dma = dma_map_single(dev, seg->bounce_buf, + max_pkt, dma_from_device); + } + + if (dma_mapping_error(dev, seg->bounce_dma)) { + /* try without aligning.*/ + dev_warn(pdev->dev, + "failed mapping bounce buffer, not aligning "); + return 0; + } + + *trb_buff_len = new_buff_len; + seg->bounce_len = new_buff_len; + seg->bounce_offs = enqd_len; + + /* + * bounce buffer successful aligned and seg->bounce_dma will be used + * in transfer trb as new transfer buffer address. + */ + return 1; +} + +int cdnsp_queue_bulk_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq) +{ + unsigned int enqd_len, block_len, trb_buff_len, full_len; + unsigned int start_cycle, num_sgs = 0; + struct cdnsp_generic_trb *start_trb; + u32 field, length_field, remainder; + struct scatterlist *sg = null; + bool more_trbs_coming = true; + bool need_zero_pkt = false; + bool zero_len_trb = false; + struct cdnsp_ring *ring; + bool first_trb = true; + unsigned int num_trbs; + struct cdnsp_ep *pep; + u64 addr, send_addr; + int sent_len, ret; + + ring = cdnsp_request_to_transfer_ring(pdev, preq); + if (!ring) + return -einval; + + full_len = preq->request.length; + + if (preq->request.num_sgs) { + num_sgs = preq->request.num_sgs; + sg = preq->request.sg; + addr = (u64)sg_dma_address(sg); + block_len = sg_dma_len(sg); + num_trbs = count_sg_trbs_needed(preq); + } else { + num_trbs = count_trbs_needed(preq); + addr = (u64)preq->request.dma; + block_len = full_len; + } + + pep = preq->pep; + + /* deal with request.zero - need one more td/trb. */ + if (preq->request.zero && preq->request.length && + is_aligned(full_len, usb_endpoint_maxp(pep->endpoint.desc))) { + need_zero_pkt = true; + num_trbs++; + } + + ret = cdnsp_prepare_transfer(pdev, preq, num_trbs); + if (ret) + return ret; + + /* + * don't give the first trb to the hardware (by toggling the cycle bit) + * until we've finished creating all the other trbs. the ring's cycle + * state may change as we enqueue the other trbs, so save it too. + */ + start_trb = &ring->enqueue->generic; + start_cycle = ring->cycle_state; + send_addr = addr; + + /* queue the trbs, even if they are zero-length */ + for (enqd_len = 0; zero_len_trb || first_trb || enqd_len < full_len; + enqd_len += trb_buff_len) { + field = trb_type(trb_normal); + + /* trb buffer should not cross 64kb boundaries */ + trb_buff_len = trb_buff_len_up_to_boundary(addr); + trb_buff_len = min(trb_buff_len, block_len); + if (enqd_len + trb_buff_len > full_len) + trb_buff_len = full_len - enqd_len; + + /* don't change the cycle bit of the first trb until later */ + if (first_trb) { + first_trb = false; + if (start_cycle == 0) + field |= trb_cycle; + } else { + field |= ring->cycle_state; + } + + /* + * chain all the trbs together; clear the chain bit in the last + * trb to indicate it's the last trb in the chain. + */ + if (enqd_len + trb_buff_len < full_len || need_zero_pkt) { + field |= trb_chain; + if (cdnsp_trb_is_link(ring->enqueue + 1)) { + if (cdnsp_align_td(pdev, preq, enqd_len, + &trb_buff_len, + ring->enq_seg)) { + send_addr = ring->enq_seg->bounce_dma; + /* assuming td won't span 2 segs */ + preq->td.bounce_seg = ring->enq_seg; + } + } + } + + if (enqd_len + trb_buff_len >= full_len) { + if (need_zero_pkt && zero_len_trb) { + zero_len_trb = true; + } else { + field &= ~trb_chain; + field |= trb_ioc; + more_trbs_coming = false; + need_zero_pkt = false; + preq->td.last_trb = ring->enqueue; + } + } + + /* only set interrupt on short packet for out endpoints. */ + if (!preq->direction) + field |= trb_isp; + + /* set the trb length, td size, and interrupter fields. */ + remainder = cdnsp_td_remainder(pdev, enqd_len, trb_buff_len, + full_len, preq, + more_trbs_coming); + + length_field = trb_len(trb_buff_len) | trb_td_size(remainder) | + trb_intr_target(0); + + cdnsp_queue_trb(pdev, ring, more_trbs_coming | need_zero_pkt, + lower_32_bits(send_addr), + upper_32_bits(send_addr), + length_field, + field); + + addr += trb_buff_len; + sent_len = trb_buff_len; + while (sg && sent_len >= block_len) { + /* new sg entry */ + --num_sgs; + sent_len -= block_len; + if (num_sgs != 0) { + sg = sg_next(sg); + block_len = sg_dma_len(sg); + addr = (u64)sg_dma_address(sg); + addr += sent_len; + } + } + block_len -= sent_len; + send_addr = addr; + } + + cdnsp_check_trb_math(preq, enqd_len); + ret = cdnsp_giveback_first_trb(pdev, pep, preq->request.stream_id, + start_cycle, start_trb); + + if (ret) + preq->td.drbl = 1; + + return 0; +} + +int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq) +{ + u32 field, length_field, remainder; + struct cdnsp_ep *pep = preq->pep; + struct cdnsp_ring *ep_ring; + int num_trbs; + int ret; + + ep_ring = cdnsp_request_to_transfer_ring(pdev, preq); + if (!ep_ring) + return -einval; + + /* 1 trb for data, 1 for status */ + num_trbs = (pdev->three_stage_setup) ? 2 : 1; + + ret = cdnsp_prepare_transfer(pdev, preq, num_trbs); + if (ret) + return ret; + + /* if there's data, queue data trbs */ + if (pdev->ep0_expect_in) + field = trb_type(trb_data) | trb_ioc; + else + field = trb_isp | trb_type(trb_data) | trb_ioc; + + if (preq->request.length > 0) { + remainder = cdnsp_td_remainder(pdev, 0, preq->request.length, + preq->request.length, preq, 1); + + length_field = trb_len(preq->request.length) | + trb_td_size(remainder) | trb_intr_target(0); + + if (pdev->ep0_expect_in) + field |= trb_dir_in; + + cdnsp_queue_trb(pdev, ep_ring, true, + lower_32_bits(preq->request.dma), + upper_32_bits(preq->request.dma), length_field, + field | ep_ring->cycle_state | + trb_setupid(pdev->setup_id) | + pdev->setup_speed); + + pdev->ep0_stage = cdnsp_data_stage; + } + + /* save the dma address of the last trb in the td. */ + preq->td.last_trb = ep_ring->enqueue; + + /* queue status trb. */ + if (preq->request.length == 0) + field = ep_ring->cycle_state; + else + field = (ep_ring->cycle_state ^ 1); + + if (preq->request.length > 0 && pdev->ep0_expect_in) + field |= trb_dir_in; + + if (pep->ep_state & ep0_halted_status) { + pep->ep_state &= ~ep0_halted_status; + field |= trb_setupstat(trb_setupstat_stall); + } else { + field |= trb_setupstat(trb_setupstat_ack); + } + + cdnsp_queue_trb(pdev, ep_ring, false, 0, 0, trb_intr_target(0), + field | trb_ioc | trb_setupid(pdev->setup_id) | + trb_type(trb_status) | pdev->setup_speed); + + cdnsp_ring_ep_doorbell(pdev, pep, preq->request.stream_id); + + return 0; +} + +int cdnsp_cmd_stop_ep(struct cdnsp_device *pdev, struct cdnsp_ep *pep) +{ + u32 ep_state = get_ep_ctx_state(pep->out_ctx); + int ret = 0; + + if (ep_state == ep_state_stopped || ep_state == ep_state_disabled) + goto ep_stopped; + + cdnsp_queue_stop_endpoint(pdev, pep->idx); + cdnsp_ring_cmd_db(pdev); + ret = cdnsp_wait_for_cmd_compl(pdev); + +ep_stopped: + pep->ep_state |= ep_stopped; + return ret; +} + +int cdnsp_cmd_flush_ep(struct cdnsp_device *pdev, struct cdnsp_ep *pep) +{ + int ret; + + cdnsp_queue_flush_endpoint(pdev, pep->idx); + cdnsp_ring_cmd_db(pdev); + ret = cdnsp_wait_for_cmd_compl(pdev); + + return ret; +} + +/* + * the transfer burst count field of the isochronous trb defines the number of + * bursts that are required to move all packets in this td. only superspeed + * devices can burst up to bmaxburst number of packets per service interval. + * this field is zero based, meaning a value of zero in the field means one + * burst. basically, for everything but superspeed devices, this field will be + * zero. + */ +static unsigned int cdnsp_get_burst_count(struct cdnsp_device *pdev, + struct cdnsp_request *preq, + unsigned int total_packet_count) +{ + unsigned int max_burst; + + if (pdev->gadget.speed < usb_speed_super) + return 0; + + max_burst = preq->pep->endpoint.comp_desc->bmaxburst; + return div_round_up(total_packet_count, max_burst + 1) - 1; +} + +/* + * returns the number of packets in the last "burst" of packets. this field is + * valid for all speeds of devices. usb 2.0 devices can only do one "burst", so + * the last burst packet count is equal to the total number of packets in the + * td. superspeed endpoints can have up to 3 bursts. all but the last burst + * must contain (bmaxburst + 1) number of packets, but the last burst can + * contain 1 to (bmaxburst + 1) packets. + */ +static unsigned int + cdnsp_get_last_burst_packet_count(struct cdnsp_device *pdev, + struct cdnsp_request *preq, + unsigned int total_packet_count) +{ + unsigned int max_burst; + unsigned int residue; + + if (pdev->gadget.speed >= usb_speed_super) { + /* bmaxburst is zero based: 0 means 1 packet per burst. */ + max_burst = preq->pep->endpoint.comp_desc->bmaxburst; + residue = total_packet_count % (max_burst + 1); + + /* + * if residue is zero, the last burst contains (max_burst + 1) + * number of packets, but the tlbpc field is zero-based. + */ + if (residue == 0) + return max_burst; + + return residue - 1; + } + if (total_packet_count == 0) + return 0; + + return total_packet_count - 1; +} + +/* queue function isoc transfer */ +static int cdnsp_queue_isoc_tx(struct cdnsp_device *pdev, + struct cdnsp_request *preq) +{ + int trb_buff_len, td_len, td_remain_len, ret; + unsigned int burst_count, last_burst_pkt; + unsigned int total_pkt_count, max_pkt; + struct cdnsp_generic_trb *start_trb; + bool more_trbs_coming = true; + struct cdnsp_ring *ep_ring; + int running_total = 0; + u32 field, length_field; + int start_cycle; + int trbs_per_td; + u64 addr; + int i; + + ep_ring = preq->pep->ring; + start_trb = &ep_ring->enqueue->generic; + start_cycle = ep_ring->cycle_state; + td_len = preq->request.length; + addr = (u64)preq->request.dma; + td_remain_len = td_len; + + max_pkt = usb_endpoint_maxp(preq->pep->endpoint.desc); + total_pkt_count = div_round_up(td_len, max_pkt); + + /* a zero-length transfer still involves at least one packet. */ + if (total_pkt_count == 0) + total_pkt_count++; + + burst_count = cdnsp_get_burst_count(pdev, preq, total_pkt_count); + last_burst_pkt = cdnsp_get_last_burst_packet_count(pdev, preq, + total_pkt_count); + trbs_per_td = count_isoc_trbs_needed(preq); + + ret = cdnsp_prepare_transfer(pdev, preq, trbs_per_td); + if (ret) + goto cleanup; + + /* + * set isoc specific data for the first trb in a td. + * prevent hw from getting the trbs by keeping the cycle state + * inverted in the first tds isoc trb. + */ + field = trb_type(trb_isoc) | trb_tlbpc(last_burst_pkt) | + !start_cycle | trb_sia | trb_tbc(burst_count); + + /* fill the rest of the trb fields, and remaining normal trbs. */ + for (i = 0; i < trbs_per_td; i++) { + u32 remainder; + + /* calculate trb length. */ + trb_buff_len = trb_buff_len_up_to_boundary(addr); + if (trb_buff_len > td_remain_len) + trb_buff_len = td_remain_len; + + /* set the trb length, td size, & interrupter fields. */ + remainder = cdnsp_td_remainder(pdev, running_total, + trb_buff_len, td_len, preq, + more_trbs_coming); + + length_field = trb_len(trb_buff_len) | trb_intr_target(0); + + /* only first trb is isoc, overwrite otherwise. */ + if (i) { + field = trb_type(trb_normal) | ep_ring->cycle_state; + length_field |= trb_td_size(remainder); + } else { + length_field |= trb_td_size_tbc(burst_count); + } + + /* only set interrupt on short packet for out eps. */ + if (usb_endpoint_dir_out(preq->pep->endpoint.desc)) + field |= trb_isp; + + /* set the chain bit for all except the last trb. */ + if (i < trbs_per_td - 1) { + more_trbs_coming = true; + field |= trb_chain; + } else { + more_trbs_coming = false; + preq->td.last_trb = ep_ring->enqueue; + field |= trb_ioc; + } + + cdnsp_queue_trb(pdev, ep_ring, more_trbs_coming, + lower_32_bits(addr), upper_32_bits(addr), + length_field, field); + + running_total += trb_buff_len; + addr += trb_buff_len; + td_remain_len -= trb_buff_len; + } + + /* check td length */ + if (running_total != td_len) { + dev_err(pdev->dev, "isoc td length unmatch "); + ret = -einval; + goto cleanup; + } + + cdnsp_giveback_first_trb(pdev, preq->pep, preq->request.stream_id, + start_cycle, start_trb); + + return 0; + +cleanup: + /* clean up a partially enqueued isoc transfer. */ + list_del_init(&preq->td.td_list); + ep_ring->num_tds--; + + /* + * use the first td as a temporary variable to turn the tds we've + * queued into no-ops with a software-owned cycle bit. + * that way the hardware won't accidentally start executing bogus tds + * when we partially overwrite them. + * td->first_trb and td->start_seg are already set. + */ + preq->td.last_trb = ep_ring->enqueue; + /* every trb except the first & last will have its cycle bit flipped. */ + cdnsp_td_to_noop(pdev, ep_ring, &preq->td, true); + + /* reset the ring enqueue back to the first trb and its cycle bit. */ + ep_ring->enqueue = preq->td.first_trb; + ep_ring->enq_seg = preq->td.start_seg; + ep_ring->cycle_state = start_cycle; + return ret; +} + +int cdnsp_queue_isoc_tx_prepare(struct cdnsp_device *pdev, + struct cdnsp_request *preq) +{ + struct cdnsp_ring *ep_ring; + u32 ep_state; + int num_trbs; + int ret; + + ep_ring = preq->pep->ring; + ep_state = get_ep_ctx_state(preq->pep->out_ctx); + num_trbs = count_isoc_trbs_needed(preq); + + /* + * check the ring to guarantee there is enough room for the whole + * request. do not insert any td of the usb request to the ring if the + * check failed. + */ + ret = cdnsp_prepare_ring(pdev, ep_ring, ep_state, num_trbs, gfp_atomic); + if (ret) + return ret; + + return cdnsp_queue_isoc_tx(pdev, preq); +} + +/**** command ring operations ****/ +/* + * generic function for queuing a command trb on the command ring. + * driver queue only one command to ring in the moment. + */ +static void cdnsp_queue_command(struct cdnsp_device *pdev, + u32 field1, + u32 field2, + u32 field3, + u32 field4) +{ + cdnsp_prepare_ring(pdev, pdev->cmd_ring, ep_state_running, 1, + gfp_atomic); + + pdev->cmd.command_trb = pdev->cmd_ring->enqueue; + + cdnsp_queue_trb(pdev, pdev->cmd_ring, false, field1, field2, + field3, field4 | pdev->cmd_ring->cycle_state); +} + +/* queue a slot enable or disable request on the command ring */ +void cdnsp_queue_slot_control(struct cdnsp_device *pdev, u32 trb_type) +{ + cdnsp_queue_command(pdev, 0, 0, 0, trb_type(trb_type) | + slot_id_for_trb(pdev->slot_id)); +} + +/* queue an address device command trb */ +void cdnsp_queue_address_device(struct cdnsp_device *pdev, + dma_addr_t in_ctx_ptr, + enum cdnsp_setup_dev setup) +{ + cdnsp_queue_command(pdev, lower_32_bits(in_ctx_ptr), + upper_32_bits(in_ctx_ptr), 0, + trb_type(trb_addr_dev) | + slot_id_for_trb(pdev->slot_id) | + (setup == setup_context_only ? trb_bsr : 0)); +} + +/* queue a reset device command trb */ +void cdnsp_queue_reset_device(struct cdnsp_device *pdev) +{ + cdnsp_queue_command(pdev, 0, 0, 0, trb_type(trb_reset_dev) | + slot_id_for_trb(pdev->slot_id)); +} + +/* queue a configure endpoint command trb */ +void cdnsp_queue_configure_endpoint(struct cdnsp_device *pdev, + dma_addr_t in_ctx_ptr) +{ + cdnsp_queue_command(pdev, lower_32_bits(in_ctx_ptr), + upper_32_bits(in_ctx_ptr), 0, + trb_type(trb_config_ep) | + slot_id_for_trb(pdev->slot_id)); +} + +/* + * suspend is set to indicate "stop endpoint command" is being issued to stop + * activity on an endpoint that is about to be suspended. + */ +void cdnsp_queue_stop_endpoint(struct cdnsp_device *pdev, unsigned int ep_index) +{ + cdnsp_queue_command(pdev, 0, 0, 0, slot_id_for_trb(pdev->slot_id) | + ep_id_for_trb(ep_index) | trb_type(trb_stop_ring)); +} + +/* set transfer ring dequeue pointer command. */ +void cdnsp_queue_new_dequeue_state(struct cdnsp_device *pdev, + struct cdnsp_ep *pep, + struct cdnsp_dequeue_state *deq_state) +{ + u32 trb_stream_id = stream_id_for_trb(deq_state->stream_id); + u32 trb_slot_id = slot_id_for_trb(pdev->slot_id); + u32 type = trb_type(trb_set_deq); + u32 trb_sct = 0; + dma_addr_t addr; + + addr = cdnsp_trb_virt_to_dma(deq_state->new_deq_seg, + deq_state->new_deq_ptr); + + if (deq_state->stream_id) + trb_sct = sct_for_trb(sct_pri_tr); + + cdnsp_queue_command(pdev, lower_32_bits(addr) | trb_sct | + deq_state->new_cycle_state, upper_32_bits(addr), + trb_stream_id, trb_slot_id | + ep_id_for_trb(pep->idx) | type); +} + +void cdnsp_queue_reset_ep(struct cdnsp_device *pdev, unsigned int ep_index) +{ + return cdnsp_queue_command(pdev, 0, 0, 0, + slot_id_for_trb(pdev->slot_id) | + ep_id_for_trb(ep_index) | + trb_type(trb_reset_ep)); +} + +/* + * queue a halt endpoint request on the command ring. + */ +void cdnsp_queue_halt_endpoint(struct cdnsp_device *pdev, unsigned int ep_index) +{ + cdnsp_queue_command(pdev, 0, 0, 0, trb_type(trb_halt_endpoint) | + slot_id_for_trb(pdev->slot_id) | + ep_id_for_trb(ep_index)); +} + +/* + * queue a flush endpoint request on the command ring. + */ +void cdnsp_queue_flush_endpoint(struct cdnsp_device *pdev, + unsigned int ep_index) +{ + cdnsp_queue_command(pdev, 0, 0, 0, trb_type(trb_flush_endpoint) | + slot_id_for_trb(pdev->slot_id) | + ep_id_for_trb(ep_index)); +} + +void cdnsp_force_header_wakeup(struct cdnsp_device *pdev, int intf_num) +{ + u32 lo, mid; + + lo = trb_fh_to_packet_type(trb_fh_tr_packet) | + trb_fh_to_device_address(pdev->device_address); + mid = trb_fh_tr_packet_dev_not | + trb_fh_to_not_type(trb_fh_tr_packet_function_wake) | + trb_fh_to_interface(intf_num); + + cdnsp_queue_command(pdev, lo, mid, 0, + trb_type(trb_force_header) | set_port_id(2)); +} diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c - * cadence usbss drd driver. + * cadence usbss and usbssp drd driver. - ret = cdns_host_init(cdns); + if ((cdns->version == cdnsp_controller_v2 && + is_enabled(config_usb_cdnsp_host)) || + (cdns->version < cdnsp_controller_v2 && + is_enabled(config_usb_cdns3_host))) + ret = cdns_host_init(cdns); + else + ret = -enxio; + diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h --- a/drivers/usb/cdns3/core.h +++ b/drivers/usb/cdns3/core.h - * cadence usbss drd header file. + * cadence usbss and usbssp drd header file. diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c --- a/drivers/usb/cdns3/drd.c +++ b/drivers/usb/cdns3/drd.c - * cadence usbss drd driver. + * cadence usbss and usbssp drd driver. +void cdns_clear_vbus(struct cdns *cdns) +{ + u32 reg; + + if (cdns->version != cdnsp_controller_v2) + return; + + reg = readl(&cdns->otg_cdnsp_regs->override); + reg |= override_sess_vld_sel; + writel(reg, &cdns->otg_cdnsp_regs->override); +} +export_symbol_gpl(cdns_clear_vbus); + +void cdns_set_vbus(struct cdns *cdns) +{ + u32 reg; + + if (cdns->version != cdnsp_controller_v2) + return; + + reg = readl(&cdns->otg_cdnsp_regs->override); + reg &= ~override_sess_vld_sel; + writel(reg, &cdns->otg_cdnsp_regs->override); +} +export_symbol_gpl(cdns_set_vbus); + + diff --git a/drivers/usb/cdns3/drd.h b/drivers/usb/cdns3/drd.h --- a/drivers/usb/cdns3/drd.h +++ b/drivers/usb/cdns3/drd.h +void cdns_clear_vbus(struct cdns *cdns); +void cdns_set_vbus(struct cdns *cdns); diff --git a/drivers/usb/cdns3/gadget-export.h b/drivers/usb/cdns3/gadget-export.h --- a/drivers/usb/cdns3/gadget-export.h +++ b/drivers/usb/cdns3/gadget-export.h - * cadence usbss drd driver - gadget export apis. + * cadence usbss and usbssp drd driver - gadget export apis. -#ifdef config_usb_cdns3_gadget +#if is_enabled(config_usb_cdnsp_gadget) + +int cdnsp_gadget_init(struct cdns *cdns); +#else + +static inline int cdnsp_gadget_init(struct cdns *cdns) +{ + return -enxio; +} + +#endif /* config_usb_cdnsp_gadget */ + +#if is_enabled(config_usb_cdns3_gadget) -#endif +#endif /* config_usb_cdns3_gadget */ diff --git a/drivers/usb/cdns3/host-export.h b/drivers/usb/cdns3/host-export.h --- a/drivers/usb/cdns3/host-export.h +++ b/drivers/usb/cdns3/host-export.h - * cadence usbss drd driver - host export apis + * cadence usbss and usbssp drd driver - host export apis +#if is_enabled(config_usb_cdns_host) + -#ifdef config_usb_cdns3_host -#endif /* config_usb_cdns3_host */ +#endif /* usb_cdns_host */
Universal Serial Bus
3d82904559f4f5a2622db1b21de3edf2eded7664
pawel laszczak
drivers
usb
cdns3
usb: cdns3: change file names for cdns3 driver.
patch adds prefix cdns3- to all file names related only to cdns3 driver.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduced new cadence usbssp drd driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c', 'makefile']
7
11
11
--- diff --git a/drivers/usb/cdns3/makefile b/drivers/usb/cdns3/makefile --- a/drivers/usb/cdns3/makefile +++ b/drivers/usb/cdns3/makefile -cflags_trace.o := -i$(src) +cflags_cdns3-trace.o := -i$(src) -cdns3-$(config_usb_cdns3_gadget) += gadget.o ep0.o +cdns3-$(config_usb_cdns3_gadget) += cdns3-gadget.o cdns3-ep0.o -cdns3-$(config_tracing) += trace.o +cdns3-$(config_tracing) += cdns3-trace.o diff --git a/drivers/usb/cdns3/debug.h b/drivers/usb/cdns3/cdns3-debug.h diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/cdns3-ep0.c --- a/drivers/usb/cdns3/ep0.c +++ b/drivers/usb/cdns3/cdns3-ep0.c -#include "gadget.h" -#include "trace.h" +#include "cdns3-gadget.h" +#include "cdns3-trace.h" diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/cdns3-gadget.c --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/cdns3-gadget.c -#include "gadget.h" -#include "trace.h" +#include "cdns3-gadget.h" +#include "cdns3-trace.h" diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/cdns3-gadget.h diff --git a/drivers/usb/cdns3/trace.c b/drivers/usb/cdns3/cdns3-trace.c --- a/drivers/usb/cdns3/trace.c +++ b/drivers/usb/cdns3/cdns3-trace.c -#include "trace.h" +#include "cdns3-trace.h" diff --git a/drivers/usb/cdns3/trace.h b/drivers/usb/cdns3/cdns3-trace.h --- a/drivers/usb/cdns3/trace.h +++ b/drivers/usb/cdns3/cdns3-trace.h -#include "gadget.h" -#include "debug.h" +#include "cdns3-gadget.h" +#include "cdns3-debug.h" -#define trace_include_file trace +#define trace_include_file cdns3-trace
Universal Serial Bus
64b558f597d1e564c67ba55444da4aaf621dc809
pawel laszczak
drivers
usb
cdns3
maintainers: add cadence usbssp drd ip driver entry
patch adds entry for usbssp (cdnsp) driver into maintarners file.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
introduced new cadence usbssp drd driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['maintainers']
1
9
0
--- diff --git a/maintainers b/maintainers --- a/maintainers +++ b/maintainers +x: drivers/usb/cdns3/cdnsp* + +cadence usbssp drd ip driver +m: pawel laszczak <pawell@cadence.com> +l: linux-usb@vger.kernel.org +s: maintained +t: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git +f: drivers/usb/cdns3/ +x: drivers/usb/cdns3/cdns3*
Universal Serial Bus
bbf60daee7de3969502f8b8a67f9f2dca80c94c6
pawel laszczak
usb: cdns3: add support for ti's am64 soc
add support for usb controller present on the am64x soc.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add support for ti's am64 soc
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['cdns3']
['c']
1
1
0
--- diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c --- a/drivers/usb/cdns3/cdns3-ti.c +++ b/drivers/usb/cdns3/cdns3-ti.c + { .compatible = "ti,am64-usb", },
Universal Serial Bus
4f30b9d2315fafa41841e5cfd5e48ea1d4a14148
aswath govindraju
drivers
usb
cdns3
usb: chipidea: tegra: support host mode
add usb host mode to the tegra hdrc driver. this allows us to benefit from support provided by the generic chipidea driver instead of duplicating the effort in a separate ehci-tegra driver.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support host mode
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['chipidea', 'tegra']
['h', 'kconfig', 'c']
5
356
8
--- diff --git a/drivers/usb/chipidea/kconfig b/drivers/usb/chipidea/kconfig --- a/drivers/usb/chipidea/kconfig +++ b/drivers/usb/chipidea/kconfig - depends on usb_chipidea_udc diff --git a/drivers/usb/chipidea/ci_hdrc_tegra.c b/drivers/usb/chipidea/ci_hdrc_tegra.c --- a/drivers/usb/chipidea/ci_hdrc_tegra.c +++ b/drivers/usb/chipidea/ci_hdrc_tegra.c +#include <linux/io.h> +#include <linux/usb.h> +#include <linux/usb/hcd.h> +#include <linux/usb/of.h> +#include <linux/usb/phy.h> + +#include "../host/ehci.h" + const struct tegra_usb_soc_info *soc; + + bool needs_double_reset; + unsigned int txfifothresh; + enum usb_dr_mode dr_mode; +}; + +static const struct tegra_usb_soc_info tegra20_ehci_soc_info = { + .flags = ci_hdrc_requires_aligned_dma | + ci_hdrc_override_phy_control, + .dr_mode = usb_dr_mode_host, + .txfifothresh = 10, +}; + +static const struct tegra_usb_soc_info tegra30_ehci_soc_info = { + .flags = ci_hdrc_requires_aligned_dma | + ci_hdrc_override_phy_control, + .dr_mode = usb_dr_mode_host, + .txfifothresh = 16, - .flags = ci_hdrc_requires_aligned_dma, + .flags = ci_hdrc_requires_aligned_dma | + ci_hdrc_override_phy_control, + .dr_mode = usb_dr_mode_unknown, + .compatible = "nvidia,tegra20-ehci", + .data = &tegra20_ehci_soc_info, + }, { + .compatible = "nvidia,tegra30-ehci", + .data = &tegra30_ehci_soc_info, + }, { +static int tegra_usb_reset_controller(struct device *dev) +{ + struct reset_control *rst, *rst_utmi; + struct device_node *phy_np; + int err; + + rst = devm_reset_control_get_shared(dev, "usb"); + if (is_err(rst)) { + dev_err(dev, "can't get ehci reset: %pe ", rst); + return ptr_err(rst); + } + + phy_np = of_parse_phandle(dev->of_node, "nvidia,phy", 0); + if (!phy_np) + return -enoent; + + /* + * the 1st usb controller contains some utmi pad registers that are + * global for all the controllers on the chip. those registers are + * also cleared when reset is asserted to the 1st controller. + */ + rst_utmi = of_reset_control_get_shared(phy_np, "utmi-pads"); + if (is_err(rst_utmi)) { + dev_warn(dev, "can't get utmi-pads reset from the phy "); + dev_warn(dev, "continuing, but please update your dt "); + } else { + /* + * phy driver performs utmi-pads reset in a case of a + * non-legacy dt. + */ + reset_control_put(rst_utmi); + } + + of_node_put(phy_np); + + /* reset control is shared, hence initialize it first */ + err = reset_control_deassert(rst); + if (err) + return err; + + err = reset_control_assert(rst); + if (err) + return err; + + udelay(1); + + err = reset_control_deassert(rst); + if (err) + return err; + + return 0; +} + +static int tegra_usb_notify_event(struct ci_hdrc *ci, unsigned int event) +{ + struct tegra_usb *usb = dev_get_drvdata(ci->dev->parent); + struct ehci_hcd *ehci; + + switch (event) { + case ci_hdrc_controller_reset_event: + if (ci->hcd) { + ehci = hcd_to_ehci(ci->hcd); + ehci->has_tdi_phy_lpm = false; + ehci_writel(ehci, usb->soc->txfifothresh << 16, + &ehci->regs->txfill_tuning); + } + break; + } + + return 0; +} + +static int tegra_usb_internal_port_reset(struct ehci_hcd *ehci, + u32 __iomem *portsc_reg, + unsigned long *flags) +{ + u32 saved_usbintr, temp; + unsigned int i, tries; + int retval = 0; + + saved_usbintr = ehci_readl(ehci, &ehci->regs->intr_enable); + /* disable usb interrupt */ + ehci_writel(ehci, 0, &ehci->regs->intr_enable); + spin_unlock_irqrestore(&ehci->lock, *flags); + + /* + * here we have to do port reset at most twice for + * port enable bit to be set. + */ + for (i = 0; i < 2; i++) { + temp = ehci_readl(ehci, portsc_reg); + temp |= port_reset; + ehci_writel(ehci, temp, portsc_reg); + fsleep(10000); + temp &= ~port_reset; + ehci_writel(ehci, temp, portsc_reg); + fsleep(1000); + tries = 100; + do { + fsleep(1000); + /* + * up to this point, port enable bit is + * expected to be set after 2 ms waiting. + * usb1 usually takes extra 45 ms, for safety, + * we take 100 ms as timeout. + */ + temp = ehci_readl(ehci, portsc_reg); + } while (!(temp & port_pe) && tries--); + if (temp & port_pe) + break; + } + if (i == 2) + retval = -etimedout; + + /* + * clear connect status change bit if it's set. + * we can't clear port_pec. it will also cause port_pe to be cleared. + */ + if (temp & port_csc) + ehci_writel(ehci, port_csc, portsc_reg); + + /* + * write to clear any interrupt status bits that might be set + * during port reset. + */ + temp = ehci_readl(ehci, &ehci->regs->status); + ehci_writel(ehci, temp, &ehci->regs->status); + + /* restore original interrupt-enable bits */ + spin_lock_irqsave(&ehci->lock, *flags); + ehci_writel(ehci, saved_usbintr, &ehci->regs->intr_enable); + + return retval; +} + +static int tegra_ehci_hub_control(struct ci_hdrc *ci, u16 typereq, u16 wvalue, + u16 windex, char *buf, u16 wlength, + bool *done, unsigned long *flags) +{ + struct tegra_usb *usb = dev_get_drvdata(ci->dev->parent); + struct ehci_hcd *ehci = hcd_to_ehci(ci->hcd); + u32 __iomem *status_reg; + int retval = 0; + + status_reg = &ehci->regs->port_status[(windex & 0xff) - 1]; + + switch (typereq) { + case setportfeature: + if (wvalue != usb_port_feat_reset || !usb->needs_double_reset) + break; + + /* for usb1 port we need to issue port reset twice internally */ + retval = tegra_usb_internal_port_reset(ehci, status_reg, flags); + *done = true; + break; + } + + return retval; +} + +static void tegra_usb_enter_lpm(struct ci_hdrc *ci, bool enable) +{ + /* + * touching any register which belongs to ahb clock domain will + * hang cpu if usb controller is put into low power mode because + * ahb usb clock is gated on tegra in the lpm. + * + * tegra phy has a separate register for checking the clock status + * and usb_phy_set_suspend() takes care of gating/ungating the clocks + * and restoring the phy state on tegra. hence devlc/portsc registers + * shouldn't be touched directly by the ci driver. + */ + usb_phy_set_suspend(ci->usb_phy, enable); +} + + if (device_property_present(&pdev->dev, "nvidia,needs-double-reset")) + usb->needs_double_reset = true; + + err = tegra_usb_reset_controller(&pdev->dev); + if (err) { + dev_err(&pdev->dev, "failed to reset controller: %d ", err); + goto fail_power_off; + } + + /* + * usb controller registers shouldn't be touched before phy is + * initialized, otherwise cpu will hang because clocks are gated. + * phy driver controls gating of internal usb clocks on tegra. + */ + err = usb_phy_init(usb->phy); + if (err) + goto fail_power_off; + + platform_set_drvdata(pdev, usb); + + usb->soc = soc; + usb->data.dr_mode = soc->dr_mode; + usb->data.enter_lpm = tegra_usb_enter_lpm; + usb->data.hub_control = tegra_ehci_hub_control; + usb->data.notify_event = tegra_usb_notify_event; - goto fail_power_off; + goto phy_shutdown; - platform_set_drvdata(pdev, usb); - +phy_shutdown: + usb_phy_shutdown(usb->phy); + usb_phy_shutdown(usb->phy); diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c -static void ci_hdrc_enter_lpm(struct ci_hdrc *ci, bool enable) +static void ci_hdrc_enter_lpm_common(struct ci_hdrc *ci, bool enable) +static void ci_hdrc_enter_lpm(struct ci_hdrc *ci, bool enable) +{ + return ci->platdata->enter_lpm(ci, enable); +} + + if (!platdata->enter_lpm) + platdata->enter_lpm = ci_hdrc_enter_lpm_common; + diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c +struct ci_hdrc_dma_aligned_buffer { + void *kmalloc_ptr; + void *old_xfer_buffer; + u8 data[0]; +}; + + ci->hcd = hcd; + + ci->hcd = null; - ci->hcd = hcd; - + bool done = false; + if (ci->platdata->hub_control) { + retval = ci->platdata->hub_control(ci, typereq, wvalue, windex, + buf, wlength, &done, &flags); + if (done) + goto done; + } + +static void ci_hdrc_free_dma_aligned_buffer(struct urb *urb) +{ + struct ci_hdrc_dma_aligned_buffer *temp; + size_t length; + + if (!(urb->transfer_flags & urb_aligned_temp_buffer)) + return; + + temp = container_of(urb->transfer_buffer, + struct ci_hdrc_dma_aligned_buffer, data); + + if (usb_urb_dir_in(urb)) { + if (usb_pipeisoc(urb->pipe)) + length = urb->transfer_buffer_length; + else + length = urb->actual_length; + + memcpy(temp->old_xfer_buffer, temp->data, length); + } + urb->transfer_buffer = temp->old_xfer_buffer; + kfree(temp->kmalloc_ptr); + + urb->transfer_flags &= ~urb_aligned_temp_buffer; +} + +static int ci_hdrc_alloc_dma_aligned_buffer(struct urb *urb, gfp_t mem_flags) +{ + struct ci_hdrc_dma_aligned_buffer *temp, *kmalloc_ptr; + const unsigned int ci_hdrc_usb_dma_align = 32; + size_t kmalloc_size; + + if (urb->num_sgs || urb->sg || urb->transfer_buffer_length == 0 || + !((uintptr_t)urb->transfer_buffer & (ci_hdrc_usb_dma_align - 1))) + return 0; + + /* allocate a buffer with enough padding for alignment */ + kmalloc_size = urb->transfer_buffer_length + + sizeof(struct ci_hdrc_dma_aligned_buffer) + + ci_hdrc_usb_dma_align - 1; + + kmalloc_ptr = kmalloc(kmalloc_size, mem_flags); + if (!kmalloc_ptr) + return -enomem; + + /* position our struct dma_aligned_buffer such that data is aligned */ + temp = ptr_align(kmalloc_ptr + 1, ci_hdrc_usb_dma_align) - 1; + temp->kmalloc_ptr = kmalloc_ptr; + temp->old_xfer_buffer = urb->transfer_buffer; + if (usb_urb_dir_out(urb)) + memcpy(temp->data, urb->transfer_buffer, + urb->transfer_buffer_length); + urb->transfer_buffer = temp->data; + + urb->transfer_flags |= urb_aligned_temp_buffer; + + return 0; +} + +static int ci_hdrc_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, + gfp_t mem_flags) +{ + int ret; + + ret = ci_hdrc_alloc_dma_aligned_buffer(urb, mem_flags); + if (ret) + return ret; + + ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); + if (ret) + ci_hdrc_free_dma_aligned_buffer(urb); + + return ret; +} + +static void ci_hdrc_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) +{ + usb_hcd_unmap_urb_for_dma(hcd, urb); + ci_hdrc_free_dma_aligned_buffer(urb); +} + + if (ci->platdata->flags & ci_hdrc_requires_aligned_dma) { + ci_ehci_hc_driver.map_urb_for_dma = ci_hdrc_map_urb_for_dma; + ci_ehci_hc_driver.unmap_urb_for_dma = ci_hdrc_unmap_urb_for_dma; + } + diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h + + /* platform-specific hooks */ + int (*hub_control)(struct ci_hdrc *ci, u16 typereq, u16 wvalue, + u16 windex, char *buf, u16 wlength, + bool *done, unsigned long *flags); + void (*enter_lpm)(struct ci_hdrc *ci, bool enable);
Universal Serial Bus
fc53d5279094e38e6363506339772a7021da2df8
peter geis thierry reding treding nvidia com peter chen peter chen kernel org matt merhar mattmerhar protonmail com nicolas chauvet kwizart gmail com ion agorria ion agorria com
drivers
usb
chipidea, usb
usb: dwc3: add imx8mp dwc3 glue layer driver
imx8mp soc integrate dwc3 3.30b ip and has some customizations to support low power, which has a seprated wakeup irq and additional logic to wakeup usb from low power mode both for host mode and device mode.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add imx8mp dwc3 glue layer driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['dwc3']
['kconfig', 'c', 'makefile']
3
374
0
--- diff --git a/drivers/usb/dwc3/kconfig b/drivers/usb/dwc3/kconfig --- a/drivers/usb/dwc3/kconfig +++ b/drivers/usb/dwc3/kconfig +config usb_dwc3_imx8mp + tristate "nxp imx8mp platform" + depends on of && common_clk + depends on (arch_mxc && arm64) || compile_test + default usb_dwc3 + help + nxp imx8m plus soc use designware core ip for usb2/3 + functionality. + say 'y' or 'm' if you have one such device. + diff --git a/drivers/usb/dwc3/makefile b/drivers/usb/dwc3/makefile --- a/drivers/usb/dwc3/makefile +++ b/drivers/usb/dwc3/makefile +obj-$(config_usb_dwc3_imx8mp) += dwc3-imx8mp.o diff --git a/drivers/usb/dwc3/dwc3-imx8mp.c b/drivers/usb/dwc3/dwc3-imx8mp.c --- /dev/null +++ b/drivers/usb/dwc3/dwc3-imx8mp.c +// spdx-license-identifier: gpl-2.0 +/** + * dwc3-imx8mp.c - nxp imx8mp specific glue layer + * + * copyright (c) 2020 nxp. + */ + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of_platform.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> + +#include "core.h" + +/* usb wakeup registers */ +#define usb_wakeup_ctrl 0x00 + +/* global wakeup interrupt enable, also used to clear interrupt */ +#define usb_wakeup_en bit(31) +/* wakeup from connect or disconnect, only for superspeed */ +#define usb_wakeup_ss_conn bit(5) +/* 0 select vbus_valid, 1 select sessvld */ +#define usb_wakeup_vbus_src_sess_val bit(4) +/* enable signal for wake up from u3 state */ +#define usb_wakeup_u3_en bit(3) +/* enable signal for wake up from id change */ +#define usb_wakeup_id_en bit(2) +/* enable signal for wake up from vbus change */ +#define usb_wakeup_vbus_en bit(1) +/* enable signal for wake up from dp/dm change */ +#define usb_wakeup_dpdm_en bit(0) + +#define usb_wakeup_en_mask genmask(5, 0) + +struct dwc3_imx8mp { + struct device *dev; + struct platform_device *dwc3; + void __iomem *glue_base; + struct clk *hsio_clk; + struct clk *suspend_clk; + int irq; + bool pm_suspended; + bool wakeup_pending; +}; + +static void dwc3_imx8mp_wakeup_enable(struct dwc3_imx8mp *dwc3_imx) +{ + struct dwc3 *dwc3 = platform_get_drvdata(dwc3_imx->dwc3); + u32 val; + + if (!dwc3) + return; + + val = readl(dwc3_imx->glue_base + usb_wakeup_ctrl); + + if ((dwc3->current_dr_role == dwc3_gctl_prtcap_host) && dwc3->xhci) + val |= usb_wakeup_en | usb_wakeup_ss_conn | + usb_wakeup_u3_en | usb_wakeup_dpdm_en; + else if (dwc3->current_dr_role == dwc3_gctl_prtcap_device) + val |= usb_wakeup_en | usb_wakeup_vbus_en | + usb_wakeup_vbus_src_sess_val; + + writel(val, dwc3_imx->glue_base + usb_wakeup_ctrl); +} + +static void dwc3_imx8mp_wakeup_disable(struct dwc3_imx8mp *dwc3_imx) +{ + u32 val; + + val = readl(dwc3_imx->glue_base + usb_wakeup_ctrl); + val &= ~(usb_wakeup_en | usb_wakeup_en_mask); + writel(val, dwc3_imx->glue_base + usb_wakeup_ctrl); +} + +static irqreturn_t dwc3_imx8mp_interrupt(int irq, void *_dwc3_imx) +{ + struct dwc3_imx8mp *dwc3_imx = _dwc3_imx; + struct dwc3 *dwc = platform_get_drvdata(dwc3_imx->dwc3); + + if (!dwc3_imx->pm_suspended) + return irq_handled; + + disable_irq_nosync(dwc3_imx->irq); + dwc3_imx->wakeup_pending = true; + + if ((dwc->current_dr_role == dwc3_gctl_prtcap_host) && dwc->xhci) + pm_runtime_resume(&dwc->xhci->dev); + else if (dwc->current_dr_role == dwc3_gctl_prtcap_device) + pm_runtime_get(dwc->dev); + + return irq_handled; +} + +static int dwc3_imx8mp_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *dwc3_np, *node = dev->of_node; + struct dwc3_imx8mp *dwc3_imx; + int err, irq; + + if (!node) { + dev_err(dev, "device node not found "); + return -einval; + } + + dwc3_imx = devm_kzalloc(dev, sizeof(*dwc3_imx), gfp_kernel); + if (!dwc3_imx) + return -enomem; + + platform_set_drvdata(pdev, dwc3_imx); + + dwc3_imx->dev = dev; + + dwc3_imx->glue_base = devm_platform_ioremap_resource(pdev, 0); + if (is_err(dwc3_imx->glue_base)) + return ptr_err(dwc3_imx->glue_base); + + dwc3_imx->hsio_clk = devm_clk_get(dev, "hsio"); + if (is_err(dwc3_imx->hsio_clk)) { + err = ptr_err(dwc3_imx->hsio_clk); + dev_err(dev, "failed to get hsio clk, err=%d ", err); + return err; + } + + err = clk_prepare_enable(dwc3_imx->hsio_clk); + if (err) { + dev_err(dev, "failed to enable hsio clk, err=%d ", err); + return err; + } + + dwc3_imx->suspend_clk = devm_clk_get(dev, "suspend"); + if (is_err(dwc3_imx->suspend_clk)) { + err = ptr_err(dwc3_imx->suspend_clk); + dev_err(dev, "failed to get suspend clk, err=%d ", err); + goto disable_hsio_clk; + } + + err = clk_prepare_enable(dwc3_imx->suspend_clk); + if (err) { + dev_err(dev, "failed to enable suspend clk, err=%d ", err); + goto disable_hsio_clk; + } + + irq = platform_get_irq(pdev, 0); + if (irq < 0) { + err = irq; + goto disable_clks; + } + dwc3_imx->irq = irq; + + err = devm_request_threaded_irq(dev, irq, null, dwc3_imx8mp_interrupt, + irqf_oneshot, dev_name(dev), dwc3_imx); + if (err) { + dev_err(dev, "failed to request irq #%d --> %d ", irq, err); + goto disable_clks; + } + + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + err = pm_runtime_get_sync(dev); + if (err < 0) + goto disable_rpm; + + dwc3_np = of_get_child_by_name(node, "dwc3"); + if (!dwc3_np) { + dev_err(dev, "failed to find dwc3 core child "); + goto disable_rpm; + } + + err = of_platform_populate(node, null, null, dev); + if (err) { + dev_err(&pdev->dev, "failed to create dwc3 core "); + goto err_node_put; + } + + dwc3_imx->dwc3 = of_find_device_by_node(dwc3_np); + if (!dwc3_imx->dwc3) { + dev_err(dev, "failed to get dwc3 platform device "); + err = -enodev; + goto depopulate; + } + of_node_put(dwc3_np); + + device_set_wakeup_capable(dev, true); + pm_runtime_put(dev); + + return 0; + +depopulate: + of_platform_depopulate(dev); +err_node_put: + of_node_put(dwc3_np); +disable_rpm: + pm_runtime_disable(dev); + pm_runtime_put_noidle(dev); +disable_clks: + clk_disable_unprepare(dwc3_imx->suspend_clk); +disable_hsio_clk: + clk_disable_unprepare(dwc3_imx->hsio_clk); + + return err; +} + +static int dwc3_imx8mp_remove(struct platform_device *pdev) +{ + struct dwc3_imx8mp *dwc3_imx = platform_get_drvdata(pdev); + struct device *dev = &pdev->dev; + + pm_runtime_get_sync(dev); + of_platform_depopulate(dev); + + clk_disable_unprepare(dwc3_imx->suspend_clk); + clk_disable_unprepare(dwc3_imx->hsio_clk); + + pm_runtime_disable(dev); + pm_runtime_put_noidle(dev); + platform_set_drvdata(pdev, null); + + return 0; +} + +static int __maybe_unused dwc3_imx8mp_suspend(struct dwc3_imx8mp *dwc3_imx, + pm_message_t msg) +{ + if (dwc3_imx->pm_suspended) + return 0; + + /* wakeup enable */ + if (pmsg_is_auto(msg) || device_may_wakeup(dwc3_imx->dev)) + dwc3_imx8mp_wakeup_enable(dwc3_imx); + + dwc3_imx->pm_suspended = true; + + return 0; +} + +static int __maybe_unused dwc3_imx8mp_resume(struct dwc3_imx8mp *dwc3_imx, + pm_message_t msg) +{ + struct dwc3 *dwc = platform_get_drvdata(dwc3_imx->dwc3); + int ret = 0; + + if (!dwc3_imx->pm_suspended) + return 0; + + /* wakeup disable */ + dwc3_imx8mp_wakeup_disable(dwc3_imx); + dwc3_imx->pm_suspended = false; + + if (dwc3_imx->wakeup_pending) { + dwc3_imx->wakeup_pending = false; + if (dwc->current_dr_role == dwc3_gctl_prtcap_device) { + pm_runtime_mark_last_busy(dwc->dev); + pm_runtime_put_autosuspend(dwc->dev); + } else { + /* + * add wait for xhci switch from suspend + * clock to normal clock to detect connection. + */ + usleep_range(9000, 10000); + } + enable_irq(dwc3_imx->irq); + } + + return ret; +} + +static int __maybe_unused dwc3_imx8mp_pm_suspend(struct device *dev) +{ + struct dwc3_imx8mp *dwc3_imx = dev_get_drvdata(dev); + int ret; + + ret = dwc3_imx8mp_suspend(dwc3_imx, pmsg_suspend); + + if (device_may_wakeup(dwc3_imx->dev)) + enable_irq_wake(dwc3_imx->irq); + else + clk_disable_unprepare(dwc3_imx->suspend_clk); + + clk_disable_unprepare(dwc3_imx->hsio_clk); + dev_dbg(dev, "dwc3 imx8mp pm suspend. "); + + return ret; +} + +static int __maybe_unused dwc3_imx8mp_pm_resume(struct device *dev) +{ + struct dwc3_imx8mp *dwc3_imx = dev_get_drvdata(dev); + int ret; + + if (device_may_wakeup(dwc3_imx->dev)) { + disable_irq_wake(dwc3_imx->irq); + } else { + ret = clk_prepare_enable(dwc3_imx->suspend_clk); + if (ret) + return ret; + } + + ret = clk_prepare_enable(dwc3_imx->hsio_clk); + if (ret) + return ret; + + ret = dwc3_imx8mp_resume(dwc3_imx, pmsg_resume); + + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + + dev_dbg(dev, "dwc3 imx8mp pm resume. "); + + return ret; +} + +static int __maybe_unused dwc3_imx8mp_runtime_suspend(struct device *dev) +{ + struct dwc3_imx8mp *dwc3_imx = dev_get_drvdata(dev); + + dev_dbg(dev, "dwc3 imx8mp runtime suspend. "); + + return dwc3_imx8mp_suspend(dwc3_imx, pmsg_auto_suspend); +} + +static int __maybe_unused dwc3_imx8mp_runtime_resume(struct device *dev) +{ + struct dwc3_imx8mp *dwc3_imx = dev_get_drvdata(dev); + + dev_dbg(dev, "dwc3 imx8mp runtime resume. "); + + return dwc3_imx8mp_resume(dwc3_imx, pmsg_auto_resume); +} + +static const struct dev_pm_ops dwc3_imx8mp_dev_pm_ops = { + set_system_sleep_pm_ops(dwc3_imx8mp_pm_suspend, dwc3_imx8mp_pm_resume) + set_runtime_pm_ops(dwc3_imx8mp_runtime_suspend, + dwc3_imx8mp_runtime_resume, null) +}; + +static const struct of_device_id dwc3_imx8mp_of_match[] = { + { .compatible = "fsl,imx8mp-dwc3", }, + {}, +}; +module_device_table(of, dwc3_imx8mp_of_match); + +static struct platform_driver dwc3_imx8mp_driver = { + .probe = dwc3_imx8mp_probe, + .remove = dwc3_imx8mp_remove, + .driver = { + .name = "imx8mp-dwc3", + .pm = &dwc3_imx8mp_dev_pm_ops, + .of_match_table = dwc3_imx8mp_of_match, + }, +}; + +module_platform_driver(dwc3_imx8mp_driver); + +module_alias("platform:imx8mp-dwc3"); +module_author("jun.li@nxp.com"); +module_license("gpl v2"); +module_description("designware usb3 imx8mp glue layer");
Universal Serial Bus
6dd2565989b4dca09eeae45a3694ec533c6a99c0
li jun
drivers
usb
dwc3
usb: dwc3: pci: id for tiger lake cpu
tiger lake soc (the versions of it that have integrated usb4 controller) may have two dwc3 controllers. one is part of the pch (platform controller hub, i.e. the chipset) as usual, and the other is inside the actual cpu block.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
id for tiger lake cpu
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['dwc3', 'pci']
['c']
1
4
0
--- diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c +#define pci_device_id_intel_tgl 0x9a15 + { pci_vdevice(intel, pci_device_id_intel_tgl), + (kernel_ulong_t) &dwc3_pci_intel_swnode, }, +
Universal Serial Bus
73203bde3a95a48f27b2454dc6b955280c641afe
heikki krogerus
drivers
usb
dwc3
usb: dwc3: pci: add support for the intel alder lake-p
this patch adds the necessary pci id for intel alder lake-p devices.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add support for the intel alder lake-p
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['dwc3', 'pci']
['c']
1
4
0
--- diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c +#define pci_device_id_intel_adlp 0x51ee + { pci_vdevice(intel, pci_device_id_intel_adlp), + (kernel_ulong_t) &dwc3_pci_intel_swnode, }, +
Universal Serial Bus
f08fc2c30e7806443143db16ac1457145d39b7dd
heikki krogerus felipe balbi balbi kernel org
drivers
usb
dwc3
usb: dwc3: qcom: add acpi device id for sc8180x
it enables usb host support for sc8180x acpi boot, both the standalone one and the one behind urs (usb role switch). and they share the the same dwc3_acpi_pdata with sdm845.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add acpi device id for sc8180x
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['dwc3', 'qcom']
['c']
1
2
0
--- diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c + { "qcom0497", (unsigned long)&sdm845_acpi_urs_pdata }, + { "qcom04a6", (unsigned long)&sdm845_acpi_pdata },
Universal Serial Bus
1edbff9c80ed32071fffa7dbaaea507fdb21ff2d
shawn guo
drivers
usb
dwc3
usb: dwc3: qcom: add urs host support for sdm845 acpi boot
for sdm845 acpi boot, the urs (usb role switch) node in acpi dsdt table holds the memory resource, while interrupt resources reside in the child nodes usb0 and ufn0. it adds usb0 host support by probing urs node, creating platform device for usb0 node, and then retrieve interrupt resources from usb0 platform device.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add urs host support for sdm845 acpi boot
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['dwc3', 'qcom']
['c']
1
56
3
--- diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c + bool is_urs; + struct platform_device *urs_usb; + struct dwc3_qcom *qcom = platform_get_drvdata(pdev); + struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb : pdev; - ret = platform_get_irq_byname(pdev, name); + ret = platform_get_irq_byname(pdev_irq, name); - ret = platform_get_irq(pdev, num); + ret = platform_get_irq(pdev_irq, num); + struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb : + pdev; - irq = platform_get_irq(pdev, 0); + irq = platform_get_irq(pdev_irq, 0); +static struct platform_device * +dwc3_qcom_create_urs_usb_platdev(struct device *dev) +{ + struct fwnode_handle *fwh; + struct acpi_device *adev; + char name[8]; + int ret; + int id; + + /* figure out device id */ + ret = sscanf(fwnode_get_name(dev->fwnode), "urs%d", &id); + if (!ret) + return null; + + /* find the child using name */ + snprintf(name, sizeof(name), "usb%d", id); + fwh = fwnode_get_named_child_node(dev->fwnode, name); + if (!fwh) + return null; + + adev = to_acpi_device_node(fwh); + if (!adev) + return null; + + return acpi_create_platform_device(adev, null); +} + + + if (qcom->acpi_pdata->is_urs) { + qcom->urs_usb = dwc3_qcom_create_urs_usb_platdev(dev); + if (!qcom->urs_usb) { + dev_err(dev, "failed to create urs usb platdev "); + return -enodev; + } + } +static const struct dwc3_acpi_pdata sdm845_acpi_urs_pdata = { + .qscratch_base_offset = sdm845_qscratch_base_offset, + .qscratch_base_size = sdm845_qscratch_size, + .dwc3_core_base_size = sdm845_dwc3_core_size, + .hs_phy_irq_index = 1, + .dp_hs_phy_irq_index = 4, + .dm_hs_phy_irq_index = 3, + .ss_phy_irq_index = 2, + .is_urs = true, +}; + + { "qcom0304", (unsigned long)&sdm845_acpi_urs_pdata },
Universal Serial Bus
c25c210f590e7a37eecd865d84f97d1f40e39786
shawn guo bjorn andersson bjorn andersson linaro org
drivers
usb
dwc3
usb: gadget: u_ether: support configuring interface names.
this patch allows the administrator to configure the interface name of a function using u_ether (e.g., eem, ncm, rndis).
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
support configuring interface names
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['gadget', 'u_ether']
['h', 'c', 'rst']
4
73
17
--- diff --git a/documentation/usb/gadget-testing.rst b/documentation/usb/gadget-testing.rst --- a/documentation/usb/gadget-testing.rst +++ b/documentation/usb/gadget-testing.rst -except for ifname they can be written to until the function is linked to a -configuration. the ifname is read-only and contains the name of the interface -which was assigned by the net core, e. g. usb0. +the ifname can be written to if the function is not bound. a write must be an +interface pattern such as "usb%d", which will cause the net core to choose the +next free usbx interface. by default, it is set to "usb%d". ------------------------ -except for ifname they can be written to until the function is linked to a -configuration. the ifname is read-only and contains the name of the interface -which was assigned by the net core, e. g. usb0. +the ifname can be written to if the function is not bound. a write must be an +interface pattern such as "usb%d", which will cause the net core to choose the +next free usbx interface. by default, it is set to "usb%d". ------------------------------- -except for ifname they can be written to until the function is linked to a -configuration. the ifname is read-only and contains the name of the interface -which was assigned by the net core, e. g. usb0. +the ifname can be written to if the function is not bound. a write must be an +interface pattern such as "usb%d", which will cause the net core to choose the +next free usbx interface. by default, it is set to "usb%d". ------------------------ -except for ifname they can be written to until the function is linked to a -configuration. the ifname is read-only and contains the name of the interface -which was assigned by the net core, e. g. usb0. +the ifname can be written to if the function is not bound. a write must be an +interface pattern such as "usb%d", which will cause the net core to choose the +next free usbx interface. by default, it is set to "usb%d". ------------------------ -except for ifname they can be written to until the function is linked to a -configuration. the ifname is read-only and contains the name of the interface -which was assigned by the net core, e. g. usb0. +the ifname can be written to if the function is not bound. a write must be an +interface pattern such as "usb%d", which will cause the net core to choose the +next free usbx interface. by default, it is set to "usb%d". -------------------------- diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c + bool ifname_set; + struct eth_dev *dev = netdev_priv(net); - ret = scnprintf(name, len, "%s ", netdev_name(net)); + ret = scnprintf(name, len, "%s ", + dev->ifname_set ? net->name : netdev_name(net)); +int gether_set_ifname(struct net_device *net, const char *name, int len) +{ + struct eth_dev *dev = netdev_priv(net); + char tmp[ifnamsiz]; + const char *p; + + if (name[len - 1] == ' ') + len--; + + if (len >= sizeof(tmp)) + return -e2big; + + strscpy(tmp, name, len + 1); + if (!dev_valid_name(tmp)) + return -einval; + + /* require exactly one %d, so binding will not fail with eexist. */ + p = strchr(name, '%'); + if (!p || p[1] != 'd' || strchr(p + 2, '%')) + return -einval; + + strncpy(net->name, tmp, sizeof(net->name)); + dev->ifname_set = true; + + return 0; +} +export_symbol_gpl(gether_set_ifname); + diff --git a/drivers/usb/gadget/function/u_ether.h b/drivers/usb/gadget/function/u_ether.h --- a/drivers/usb/gadget/function/u_ether.h +++ b/drivers/usb/gadget/function/u_ether.h +/** + * gether_set_ifname - set an ethernet-over-usb link interface name + * @net: device representing this link + * @name: new interface name + * @len: length of @name + * + * this sets the interface name of this ethernet-over-usb link. + * a single terminating newline, if any, is ignored. + * returns zero on success, else negative errno. + */ +int gether_set_ifname(struct net_device *net, const char *name, int len); + diff --git a/drivers/usb/gadget/function/u_ether_configfs.h b/drivers/usb/gadget/function/u_ether_configfs.h --- a/drivers/usb/gadget/function/u_ether_configfs.h +++ b/drivers/usb/gadget/function/u_ether_configfs.h - configfs_attr_ro(_f_##_opts_, ifname) + static ssize_t _f_##_opts_ifname_store(struct config_item *item, \ + const char *page, size_t len)\ + { \ + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ + int ret = -ebusy; \ + \ + mutex_lock(&opts->lock); \ + if (!opts->refcnt) \ + ret = gether_set_ifname(opts->net, page, len); \ + mutex_unlock(&opts->lock); \ + return ret ?: len; \ + } \ + \ + configfs_attr(_f_##_opts_, ifname)
Universal Serial Bus
63d152149b2d0860ccf8c4e6596b6175b2b7ace6
lorenzo colitti
drivers
usb
function, gadget
usb: host: ehci-tegra: remove the driver
the chipidea driver now provides usb2 host mode support for nvidia tegra socs. the ehci-tegra driver is obsolete now, remove it and redirect the older kconfig entry to the ci driver.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
remove the driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['host', 'ehci-tegra']
['kconfig', 'c', 'makefile']
3
7
608
--- diff --git a/drivers/usb/host/kconfig b/drivers/usb/host/kconfig --- a/drivers/usb/host/kconfig +++ b/drivers/usb/host/kconfig - select usb_ehci_root_hub_tt - select usb_tegra_phy + select usb_chipidea + select usb_chipidea_host + select usb_chipidea_tegra - this driver enables support for the internal usb host controllers + this option is deprecated now and the driver was removed, use + usb_chipidea_tegra instead. + + enable support for the internal usb host controllers diff --git a/drivers/usb/host/makefile b/drivers/usb/host/makefile --- a/drivers/usb/host/makefile +++ b/drivers/usb/host/makefile -obj-$(config_usb_ehci_tegra) += ehci-tegra.o diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c --- a/drivers/usb/host/ehci-tegra.c +++ /dev/null -// spdx-license-identifier: gpl-2.0+ -/* - * ehci-compliant usb host controller driver for nvidia tegra socs - * - * copyright (c) 2010 google, inc. - * copyright (c) 2009 - 2013 nvidia corporation - */ - -#include <linux/clk.h> -#include <linux/dma-mapping.h> -#include <linux/err.h> -#include <linux/gpio.h> -#include <linux/io.h> -#include <linux/irq.h> -#include <linux/module.h> -#include <linux/of.h> -#include <linux/of_device.h> -#include <linux/of_gpio.h> -#include <linux/platform_device.h> -#include <linux/pm_runtime.h> -#include <linux/reset.h> -#include <linux/slab.h> -#include <linux/usb/ehci_def.h> -#include <linux/usb/tegra_usb_phy.h> -#include <linux/usb.h> -#include <linux/usb/hcd.h> -#include <linux/usb/otg.h> - -#include "ehci.h" - -#define port_wake_bits (port_wkoc_e|port_wkdisc_e|port_wkconn_e) - -#define tegra_usb_dma_align 32 - -#define driver_desc "tegra ehci driver" -#define drv_name "tegra-ehci" - -static struct hc_driver __read_mostly tegra_ehci_hc_driver; - -struct tegra_ehci_soc_config { - bool has_hostpc; -}; - -struct tegra_ehci_hcd { - struct clk *clk; - struct reset_control *rst; - int port_resuming; - bool needs_double_reset; -}; - -static int tegra_reset_usb_controller(struct platform_device *pdev) -{ - struct device_node *phy_np; - struct usb_hcd *hcd = platform_get_drvdata(pdev); - struct tegra_ehci_hcd *tegra = - (struct tegra_ehci_hcd *)hcd_to_ehci(hcd)->priv; - struct reset_control *rst; - int err; - - phy_np = of_parse_phandle(pdev->dev.of_node, "nvidia,phy", 0); - if (!phy_np) - return -enoent; - - /* - * the 1st usb controller contains some utmi pad registers that are - * global for all the controllers on the chip. those registers are - * also cleared when reset is asserted to the 1st controller. - */ - rst = of_reset_control_get_shared(phy_np, "utmi-pads"); - if (is_err(rst)) { - dev_warn(&pdev->dev, - "can't get utmi-pads reset from the phy "); - dev_warn(&pdev->dev, - "continuing, but please update your dt "); - } else { - /* - * phy driver performs utmi-pads reset in a case of - * non-legacy dt. - */ - reset_control_put(rst); - } - - of_node_put(phy_np); - - /* reset control is shared, hence initialize it first */ - err = reset_control_deassert(tegra->rst); - if (err) - return err; - - err = reset_control_assert(tegra->rst); - if (err) - return err; - - udelay(1); - - err = reset_control_deassert(tegra->rst); - if (err) - return err; - - return 0; -} - -static int tegra_ehci_internal_port_reset( - struct ehci_hcd *ehci, - u32 __iomem *portsc_reg -) -{ - u32 temp; - unsigned long flags; - int retval = 0; - int i, tries; - u32 saved_usbintr; - - spin_lock_irqsave(&ehci->lock, flags); - saved_usbintr = ehci_readl(ehci, &ehci->regs->intr_enable); - /* disable usb interrupt */ - ehci_writel(ehci, 0, &ehci->regs->intr_enable); - spin_unlock_irqrestore(&ehci->lock, flags); - - /* - * here we have to do port reset at most twice for - * port enable bit to be set. - */ - for (i = 0; i < 2; i++) { - temp = ehci_readl(ehci, portsc_reg); - temp |= port_reset; - ehci_writel(ehci, temp, portsc_reg); - mdelay(10); - temp &= ~port_reset; - ehci_writel(ehci, temp, portsc_reg); - mdelay(1); - tries = 100; - do { - mdelay(1); - /* - * up to this point, port enable bit is - * expected to be set after 2 ms waiting. - * usb1 usually takes extra 45 ms, for safety, - * we take 100 ms as timeout. - */ - temp = ehci_readl(ehci, portsc_reg); - } while (!(temp & port_pe) && tries--); - if (temp & port_pe) - break; - } - if (i == 2) - retval = -etimedout; - - /* - * clear connect status change bit if it's set. - * we can't clear port_pec. it will also cause port_pe to be cleared. - */ - if (temp & port_csc) - ehci_writel(ehci, port_csc, portsc_reg); - - /* - * write to clear any interrupt status bits that might be set - * during port reset. - */ - temp = ehci_readl(ehci, &ehci->regs->status); - ehci_writel(ehci, temp, &ehci->regs->status); - - /* restore original interrupt enable bits */ - ehci_writel(ehci, saved_usbintr, &ehci->regs->intr_enable); - return retval; -} - -static int tegra_ehci_hub_control( - struct usb_hcd *hcd, - u16 typereq, - u16 wvalue, - u16 windex, - char *buf, - u16 wlength -) -{ - struct ehci_hcd *ehci = hcd_to_ehci(hcd); - struct tegra_ehci_hcd *tegra = (struct tegra_ehci_hcd *)ehci->priv; - u32 __iomem *status_reg; - u32 temp; - unsigned long flags; - int retval = 0; - - status_reg = &ehci->regs->port_status[(windex & 0xff) - 1]; - - spin_lock_irqsave(&ehci->lock, flags); - - if (typereq == getportstatus) { - temp = ehci_readl(ehci, status_reg); - if (tegra->port_resuming && !(temp & port_suspend)) { - /* resume completed, re-enable disconnect detection */ - tegra->port_resuming = 0; - tegra_usb_phy_postresume(hcd->usb_phy); - } - } - - else if (typereq == setportfeature && wvalue == usb_port_feat_suspend) { - temp = ehci_readl(ehci, status_reg); - if ((temp & port_pe) == 0 || (temp & port_reset) != 0) { - retval = -epipe; - goto done; - } - - temp &= ~(port_rwc_bits | port_wkconn_e); - temp |= port_wkdisc_e | port_wkoc_e; - ehci_writel(ehci, temp | port_suspend, status_reg); - - /* - * if a transaction is in progress, there may be a delay in - * suspending the port. poll until the port is suspended. - */ - if (ehci_handshake(ehci, status_reg, port_suspend, - port_suspend, 5000)) - pr_err("%s: timeout waiting for suspend ", __func__); - - set_bit((windex & 0xff) - 1, &ehci->suspended_ports); - goto done; - } - - /* for usb1 port we need to issue port reset twice internally */ - if (tegra->needs_double_reset && - (typereq == setportfeature && wvalue == usb_port_feat_reset)) { - spin_unlock_irqrestore(&ehci->lock, flags); - return tegra_ehci_internal_port_reset(ehci, status_reg); - } - - /* - * tegra host controller will time the resume operation to clear the bit - * when the port control state switches to hs or fs idle. this behavior - * is different from ehci where the host controller driver is required - * to set this bit to a zero after the resume duration is timed in the - * driver. - */ - else if (typereq == clearportfeature && - wvalue == usb_port_feat_suspend) { - temp = ehci_readl(ehci, status_reg); - if ((temp & port_reset) || !(temp & port_pe)) { - retval = -epipe; - goto done; - } - - if (!(temp & port_suspend)) - goto done; - - /* disable disconnect detection during port resume */ - tegra_usb_phy_preresume(hcd->usb_phy); - - ehci->reset_done[windex-1] = jiffies + msecs_to_jiffies(25); - - temp &= ~(port_rwc_bits | port_wake_bits); - /* start resume signalling */ - ehci_writel(ehci, temp | port_resume, status_reg); - set_bit(windex-1, &ehci->resuming_ports); - - spin_unlock_irqrestore(&ehci->lock, flags); - msleep(20); - spin_lock_irqsave(&ehci->lock, flags); - - /* poll until the controller clears resume and suspend */ - if (ehci_handshake(ehci, status_reg, port_resume, 0, 2000)) - pr_err("%s: timeout waiting for resume ", __func__); - if (ehci_handshake(ehci, status_reg, port_suspend, 0, 2000)) - pr_err("%s: timeout waiting for suspend ", __func__); - - ehci->reset_done[windex-1] = 0; - clear_bit(windex-1, &ehci->resuming_ports); - - tegra->port_resuming = 1; - goto done; - } - - spin_unlock_irqrestore(&ehci->lock, flags); - - /* handle the hub control events here */ - return ehci_hub_control(hcd, typereq, wvalue, windex, buf, wlength); - -done: - spin_unlock_irqrestore(&ehci->lock, flags); - return retval; -} - -struct dma_aligned_buffer { - void *kmalloc_ptr; - void *old_xfer_buffer; - u8 data[]; -}; - -static void free_dma_aligned_buffer(struct urb *urb) -{ - struct dma_aligned_buffer *temp; - size_t length; - - if (!(urb->transfer_flags & urb_aligned_temp_buffer)) - return; - - temp = container_of(urb->transfer_buffer, - struct dma_aligned_buffer, data); - - if (usb_urb_dir_in(urb)) { - if (usb_pipeisoc(urb->pipe)) - length = urb->transfer_buffer_length; - else - length = urb->actual_length; - - memcpy(temp->old_xfer_buffer, temp->data, length); - } - urb->transfer_buffer = temp->old_xfer_buffer; - kfree(temp->kmalloc_ptr); - - urb->transfer_flags &= ~urb_aligned_temp_buffer; -} - -static int alloc_dma_aligned_buffer(struct urb *urb, gfp_t mem_flags) -{ - struct dma_aligned_buffer *temp, *kmalloc_ptr; - size_t kmalloc_size; - - if (urb->num_sgs || urb->sg || - urb->transfer_buffer_length == 0 || - !((uintptr_t)urb->transfer_buffer & (tegra_usb_dma_align - 1))) - return 0; - - /* allocate a buffer with enough padding for alignment */ - kmalloc_size = urb->transfer_buffer_length + - sizeof(struct dma_aligned_buffer) + tegra_usb_dma_align - 1; - - kmalloc_ptr = kmalloc(kmalloc_size, mem_flags); - if (!kmalloc_ptr) - return -enomem; - - /* position our struct dma_aligned_buffer such that data is aligned */ - temp = ptr_align(kmalloc_ptr + 1, tegra_usb_dma_align) - 1; - temp->kmalloc_ptr = kmalloc_ptr; - temp->old_xfer_buffer = urb->transfer_buffer; - if (usb_urb_dir_out(urb)) - memcpy(temp->data, urb->transfer_buffer, - urb->transfer_buffer_length); - urb->transfer_buffer = temp->data; - - urb->transfer_flags |= urb_aligned_temp_buffer; - - return 0; -} - -static int tegra_ehci_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, - gfp_t mem_flags) -{ - int ret; - - ret = alloc_dma_aligned_buffer(urb, mem_flags); - if (ret) - return ret; - - ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); - if (ret) - free_dma_aligned_buffer(urb); - - return ret; -} - -static void tegra_ehci_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) -{ - usb_hcd_unmap_urb_for_dma(hcd, urb); - free_dma_aligned_buffer(urb); -} - -static const struct tegra_ehci_soc_config tegra30_soc_config = { - .has_hostpc = true, -}; - -static const struct tegra_ehci_soc_config tegra20_soc_config = { - .has_hostpc = false, -}; - -static const struct of_device_id tegra_ehci_of_match[] = { - { .compatible = "nvidia,tegra30-ehci", .data = &tegra30_soc_config }, - { .compatible = "nvidia,tegra20-ehci", .data = &tegra20_soc_config }, - { }, -}; - -static int tegra_ehci_probe(struct platform_device *pdev) -{ - const struct of_device_id *match; - const struct tegra_ehci_soc_config *soc_config; - struct resource *res; - struct usb_hcd *hcd; - struct ehci_hcd *ehci; - struct tegra_ehci_hcd *tegra; - int err = 0; - int irq; - struct usb_phy *u_phy; - - match = of_match_device(tegra_ehci_of_match, &pdev->dev); - if (!match) { - dev_err(&pdev->dev, "error: no device match found "); - return -enodev; - } - soc_config = match->data; - - /* right now device-tree probed devices don't get dma_mask set. - * since shared usb code relies on it, set it here for now. - * once we have dma capability bindings this can go away. - */ - err = dma_coerce_mask_and_coherent(&pdev->dev, dma_bit_mask(32)); - if (err) - return err; - - hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev, - dev_name(&pdev->dev)); - if (!hcd) { - dev_err(&pdev->dev, "unable to create hcd "); - return -enomem; - } - platform_set_drvdata(pdev, hcd); - ehci = hcd_to_ehci(hcd); - tegra = (struct tegra_ehci_hcd *)ehci->priv; - - hcd->has_tt = 1; - - tegra->clk = devm_clk_get(&pdev->dev, null); - if (is_err(tegra->clk)) { - dev_err(&pdev->dev, "can't get ehci clock "); - err = ptr_err(tegra->clk); - goto cleanup_hcd_create; - } - - tegra->rst = devm_reset_control_get_shared(&pdev->dev, "usb"); - if (is_err(tegra->rst)) { - dev_err(&pdev->dev, "can't get ehci reset "); - err = ptr_err(tegra->rst); - goto cleanup_hcd_create; - } - - err = clk_prepare_enable(tegra->clk); - if (err) - goto cleanup_hcd_create; - - err = tegra_reset_usb_controller(pdev); - if (err) { - dev_err(&pdev->dev, "failed to reset controller "); - goto cleanup_clk_en; - } - - u_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0); - if (is_err(u_phy)) { - err = -eprobe_defer; - goto cleanup_clk_en; - } - hcd->usb_phy = u_phy; - hcd->skip_phy_initialization = 1; - - tegra->needs_double_reset = of_property_read_bool(pdev->dev.of_node, - "nvidia,needs-double-reset"); - - res = platform_get_resource(pdev, ioresource_mem, 0); - hcd->regs = devm_ioremap_resource(&pdev->dev, res); - if (is_err(hcd->regs)) { - err = ptr_err(hcd->regs); - goto cleanup_clk_en; - } - hcd->rsrc_start = res->start; - hcd->rsrc_len = resource_size(res); - - ehci->caps = hcd->regs + 0x100; - ehci->has_hostpc = soc_config->has_hostpc; - - err = usb_phy_init(hcd->usb_phy); - if (err) { - dev_err(&pdev->dev, "failed to initialize phy "); - goto cleanup_clk_en; - } - - u_phy->otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), - gfp_kernel); - if (!u_phy->otg) { - err = -enomem; - goto cleanup_phy; - } - u_phy->otg->host = hcd_to_bus(hcd); - - irq = platform_get_irq(pdev, 0); - if (irq < 0) { - err = irq; - goto cleanup_phy; - } - - otg_set_host(u_phy->otg, &hcd->self); - - err = usb_add_hcd(hcd, irq, irqf_shared); - if (err) { - dev_err(&pdev->dev, "failed to add usb hcd "); - goto cleanup_otg_set_host; - } - device_wakeup_enable(hcd->self.controller); - - return err; - -cleanup_otg_set_host: - otg_set_host(u_phy->otg, null); -cleanup_phy: - usb_phy_shutdown(hcd->usb_phy); -cleanup_clk_en: - clk_disable_unprepare(tegra->clk); -cleanup_hcd_create: - usb_put_hcd(hcd); - return err; -} - -static int tegra_ehci_remove(struct platform_device *pdev) -{ - struct usb_hcd *hcd = platform_get_drvdata(pdev); - struct tegra_ehci_hcd *tegra = - (struct tegra_ehci_hcd *)hcd_to_ehci(hcd)->priv; - - usb_remove_hcd(hcd); - otg_set_host(hcd->usb_phy->otg, null); - usb_phy_shutdown(hcd->usb_phy); - clk_disable_unprepare(tegra->clk); - usb_put_hcd(hcd); - - return 0; -} - -static void tegra_ehci_hcd_shutdown(struct platform_device *pdev) -{ - struct usb_hcd *hcd = platform_get_drvdata(pdev); - - if (hcd->driver->shutdown) - hcd->driver->shutdown(hcd); -} - -static struct platform_driver tegra_ehci_driver = { - .probe = tegra_ehci_probe, - .remove = tegra_ehci_remove, - .shutdown = tegra_ehci_hcd_shutdown, - .driver = { - .name = drv_name, - .of_match_table = tegra_ehci_of_match, - } -}; - -static int tegra_ehci_reset(struct usb_hcd *hcd) -{ - struct ehci_hcd *ehci = hcd_to_ehci(hcd); - int retval; - int txfifothresh; - - retval = ehci_setup(hcd); - if (retval) - return retval; - - /* - * we should really pull this value out of tegra_ehci_soc_config, but - * to avoid needing access to it, make use of the fact that tegra20 is - * the only one so far that needs a value of 10, and tegra20 is the - * only one which doesn't set has_hostpc. - */ - txfifothresh = ehci->has_hostpc ? 0x10 : 10; - ehci_writel(ehci, txfifothresh << 16, &ehci->regs->txfill_tuning); - - return 0; -} - -static const struct ehci_driver_overrides tegra_overrides __initconst = { - .extra_priv_size = sizeof(struct tegra_ehci_hcd), - .reset = tegra_ehci_reset, -}; - -static int __init ehci_tegra_init(void) -{ - if (usb_disabled()) - return -enodev; - - pr_info(drv_name ": " driver_desc " "); - - ehci_init_driver(&tegra_ehci_hc_driver, &tegra_overrides); - - /* - * the tegra hw has some unusual quirks, which require tegra-specific - * workarounds. we override certain hc_driver functions here to - * achieve that. we explicitly do not enhance ehci_driver_overrides to - * allow this more easily, since this is an unusual case, and we don't - * want to encourage others to override these functions by making it - * too easy. - */ - - tegra_ehci_hc_driver.map_urb_for_dma = tegra_ehci_map_urb_for_dma; - tegra_ehci_hc_driver.unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma; - tegra_ehci_hc_driver.hub_control = tegra_ehci_hub_control; - - return platform_driver_register(&tegra_ehci_driver); -} -module_init(ehci_tegra_init); - -static void __exit ehci_tegra_cleanup(void) -{ - platform_driver_unregister(&tegra_ehci_driver); -} -module_exit(ehci_tegra_cleanup); - -module_description(driver_desc); -module_license("gpl"); -module_alias("platform:" drv_name); -module_device_table(of, tegra_ehci_of_match);
Universal Serial Bus
c3590c7656fb103db193e3538cb52b420985482c
dmitry osipenko thierry reding treding nvidia com alan stern stern rowland harvard edu peter chen peter chen kernel org matt merhar mattmerhar protonmail com nicolas chauvet kwizart gmail com peter geis pgwipeout gmail com ion agorria ion agorria com
drivers
usb
host
usb: pd: make svdm version configurable in vdm header
pd rev 3.0 introduces svdm version 2.0. this patch makes the field configuable in the header in order to be able to be compatible with older svdm version.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
make svdm version configurable in vdm header
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['pd']
['h', 'c']
4
17
14
--- diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c -#define dp_header(_dp, cmd) (vdo((_dp)->alt->svid, 1, cmd) | \ +#define dp_header(_dp, cmd) (vdo((_dp)->alt->svid, 1, svdm_ver_1_0, cmd) | \ diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c - response[0] = vdo(usb_sid_pd, 1, cmd_discover_svid); + response[0] = vdo(usb_sid_pd, 1, svdm_ver_1_0, cmd_discover_svid); - response[0] = vdo(usb_sid_pd, 1, + response[0] = vdo(usb_sid_pd, 1, svdm_ver_1_0, - response[0] = vdo(modep->svids[0], 1, + response[0] = vdo(modep->svids[0], 1, svdm_ver_1_0, - response[0] = vdo(svid, 1, cmd_discover_modes); + response[0] = vdo(svid, 1, svdm_ver_1_0, cmd_discover_modes); - response[0] = vdo(adev->svid, 1, cmd_exit_mode); + response[0] = vdo(adev->svid, 1, svdm_ver_1_0, cmd_exit_mode); - 1 : (pd_vdo_cmd(cmd) <= cmd_attention), cmd); + 1 : (pd_vdo_cmd(cmd) <= cmd_attention), svdm_ver_1_0, cmd); - header = vdo(altmode->svid, vdo ? 2 : 1, cmd_enter_mode); + header = vdo(altmode->svid, vdo ? 2 : 1, svdm_ver_1_0, cmd_enter_mode); - header = vdo(altmode->svid, 1, cmd_exit_mode); + header = vdo(altmode->svid, 1, svdm_ver_1_0, cmd_exit_mode); diff --git a/drivers/usb/typec/ucsi/displayport.c b/drivers/usb/typec/ucsi/displayport.c --- a/drivers/usb/typec/ucsi/displayport.c +++ b/drivers/usb/typec/ucsi/displayport.c - dp->header = vdo(usb_typec_dp_sid, 1, cmd_enter_mode); + dp->header = vdo(usb_typec_dp_sid, 1, svdm_ver_1_0, cmd_enter_mode); - dp->header = vdo(usb_typec_dp_sid, 1, cmd_exit_mode); + dp->header = vdo(usb_typec_dp_sid, 1, svdm_ver_1_0, cmd_exit_mode); - dp->header = vdo(usb_typec_dp_sid, 1, cmd); + dp->header = vdo(usb_typec_dp_sid, 1, svdm_ver_1_0, cmd); diff --git a/include/linux/usb/pd_vdo.h b/include/linux/usb/pd_vdo.h --- a/include/linux/usb/pd_vdo.h +++ b/include/linux/usb/pd_vdo.h - * <14:13> :: structured vdm version (can only be 00 == 1.0 currently) + * <14:13> :: structured vdm version -#define vdo(vid, type, custom) \ +#define vdo(vid, type, ver, custom) \ + ((ver) << 13) | \ +#define vdo_svdm_vers_mask vdo_svdm_vers(0x3) +#define pd_vdo_svdm_ver(vdo) (((vdo) >> 13) & 0x3)
Universal Serial Bus
31737c27d665bb3bc8ad9396c63fae2543dd8818
kyle tso heikki krogerus heikki krogerus linux intel com
include
linux
altmodes, tcpm, typec, ucsi, usb
thunderbolt: add support for pcie tunneling disabled (sl5)
recent intel thunderbolt firmware connection manager has support for another security level, sl5, that disables pcie tunneling. this option can be turned on from the bios.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add support for usb4 _osc, a new _osc method that is used to negotiate os support for native usb4 features such as pcie tunneling
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['sysfs-bus-thunderbolt', 'h', 'c', 'rst']
5
28
2
--- diff --git a/documentation/abi/testing/sysfs-bus-thunderbolt b/documentation/abi/testing/sysfs-bus-thunderbolt --- a/documentation/abi/testing/sysfs-bus-thunderbolt +++ b/documentation/abi/testing/sysfs-bus-thunderbolt + nopcie usb4 system where pcie tunneling is disabled from + the bios. diff --git a/documentation/admin-guide/thunderbolt.rst b/documentation/admin-guide/thunderbolt.rst --- a/documentation/admin-guide/thunderbolt.rst +++ b/documentation/admin-guide/thunderbolt.rst +some usb4 systems have a bios setting to disable pcie tunneling. this is +treated as another security level (nopcie). + + nopcie + pcie tunneling is disabled/forbidden from the bios. available in some + usb4 systems. + diff --git a/drivers/thunderbolt/domain.c b/drivers/thunderbolt/domain.c --- a/drivers/thunderbolt/domain.c +++ b/drivers/thunderbolt/domain.c + [tb_security_nopcie] = "nopcie", + bool deauthorization = false; - return sprintf(buf, "%d ", !!tb->cm_ops->disapprove_switch); + /* only meaningful if authorization is supported */ + if (tb->security_level == tb_security_user || + tb->security_level == tb_security_secure) + deauthorization = !!tb->cm_ops->disapprove_switch; + + return sprintf(buf, "%d ", deauthorization); + tb_dbg(tb, "security level set to %s ", + tb_security_names[tb->security_level]); + diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c - if (attr == &dev_attr_device.attr) { + if (attr == &dev_attr_authorized.attr) { + if (sw->tb->security_level == tb_security_nopcie || + sw->tb->security_level == tb_security_dponly) + return 0; + } else if (attr == &dev_attr_device.attr) { diff --git a/include/linux/thunderbolt.h b/include/linux/thunderbolt.h --- a/include/linux/thunderbolt.h +++ b/include/linux/thunderbolt.h + * @tb_security_nopcie: for usb4 systems this level is used when the + * pcie tunneling is disabled from the bios. + tb_security_nopcie,
Universal Serial Bus
3cd542e6e6afb6fa6c34d4094d498f42e22110f5
mika westerberg
drivers
thunderbolt
testing
thunderbolt: allow disabling xdomain protocol
this allows disabling xdomain protocol completely if the user does not plan to use the usb4/thunderbolt peer-to-peer functionality, or for security reasons.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add support for usb4 _osc, a new _osc method that is used to negotiate os support for native usb4 features such as pcie tunneling
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
5
20
3
--- diff --git a/drivers/thunderbolt/domain.c b/drivers/thunderbolt/domain.c --- a/drivers/thunderbolt/domain.c +++ b/drivers/thunderbolt/domain.c - return tb_xdomain_handle_request(tb, type, buf, size); + if (tb_is_xdomain_enabled()) + return tb_xdomain_handle_request(tb, type, buf, size); + break; diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c --- a/drivers/thunderbolt/icm.c +++ b/drivers/thunderbolt/icm.c - icm->xdomain_connected(tb, n->pkg); + if (tb_is_xdomain_enabled()) + icm->xdomain_connected(tb, n->pkg); - icm->xdomain_disconnected(tb, n->pkg); + if (tb_is_xdomain_enabled()) + icm->xdomain_disconnected(tb, n->pkg); diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c + if (!tb_is_xdomain_enabled()) + return; + diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h +bool tb_is_xdomain_enabled(void); diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c --- a/drivers/thunderbolt/xdomain.c +++ b/drivers/thunderbolt/xdomain.c +static bool tb_xdomain_enabled = true; +module_param_named(xdomain, tb_xdomain_enabled, bool, 0444); +module_parm_desc(xdomain, "allow xdomain protocol (default: true)"); + +bool tb_is_xdomain_enabled(void) +{ + return tb_xdomain_enabled; +} +
Universal Serial Bus
5ca67688256a0aeede5cba288eaef4d8e4a9e622
mika westerberg
drivers
thunderbolt
acpi: execute platform _osc also with query bit clear
the platform _osc can change the hardware state when query bit is not set. according to acpi spec it is recommended that the os runs _osc with query bit set until the platform does not mask any of the capabilities. then it should run it with query bit clear in order to actually commit the changes. linux has not been doing this for the reasons that there has not been anything to commit, until now.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add support for usb4 _osc, a new _osc method that is used to negotiate os support for native usb4 features such as pcie tunneling
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['c']
1
31
12
--- diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c -static void acpi_bus_osc_support(void) +static void acpi_bus_osc_negotiate_platform_control(void) - u32 capbuf[2]; + u32 capbuf[2], *capbuf_ret; - if (acpi_success(acpi_run_osc(handle, &context))) { - u32 *capbuf_ret = context.ret.pointer; - if (context.ret.length > osc_support_dword) { - osc_sb_apei_support_acked = - capbuf_ret[osc_support_dword] & osc_sb_apei_support; - osc_pc_lpi_support_confirmed = - capbuf_ret[osc_support_dword] & osc_sb_pclpi_support; - } + + if (acpi_failure(acpi_run_osc(handle, &context))) + return; + + capbuf_ret = context.ret.pointer; + if (context.ret.length <= osc_support_dword) { + return; - /* do we need to check other returned cap? sounds no */ + + /* + * now run _osc again with query flag clear and with the caps + * supported by both the os and the platform. + */ + capbuf[osc_query_dword] = 0; + capbuf[osc_support_dword] = capbuf_ret[osc_support_dword]; + kfree(context.ret.pointer); + + if (acpi_failure(acpi_run_osc(handle, &context))) + return; + + capbuf_ret = context.ret.pointer; + if (context.ret.length > osc_support_dword) { + osc_sb_apei_support_acked = + capbuf_ret[osc_support_dword] & osc_sb_apei_support; + osc_pc_lpi_support_confirmed = + capbuf_ret[osc_support_dword] & osc_sb_pclpi_support; + } + + kfree(context.ret.pointer); - acpi_bus_osc_support(); + acpi_bus_osc_negotiate_platform_control();
Universal Serial Bus
719e1f561afbe020ed175825a9bd25ed62ed1697
mario limonciello
drivers
acpi
acpi: add support for native usb4 control _osc
acpi 6.4 introduced a new _osc capability that is used negotiate native connection manager support. connection manager is the entity that is responsible for tunneling over the usb4 fabric. if the platform rejects the native access then firmware based connection manager is used.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add support for usb4 _osc, a new _osc method that is used to negotiate os support for native usb4 features such as pcie tunneling
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
[]
['h', 'c']
2
86
0
--- diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c +/* + * acpi 6.4 operating system capabilities for usb. + */ +bool osc_sb_native_usb4_support_confirmed; +export_symbol_gpl(osc_sb_native_usb4_support_confirmed); + + if (is_enabled(config_usb4)) + capbuf[osc_support_dword] |= osc_sb_native_usb4_support; + + osc_sb_native_usb4_support_confirmed = + capbuf_ret[osc_support_dword] & osc_sb_native_usb4_support; + } + + kfree(context.ret.pointer); +} + +/* + * native control of usb4 capabilities. if any of the tunneling bits is + * set it means os is in control and we use software based connection + * manager. + */ +u32 osc_sb_native_usb4_control; +export_symbol_gpl(osc_sb_native_usb4_control); + +static void acpi_bus_decode_usb_osc(const char *msg, u32 bits) +{ + printk(kern_info prefix "%s usb3%c displayport%c pcie%c xdomain%c ", msg, + (bits & osc_usb_usb3_tunneling) ? '+' : '-', + (bits & osc_usb_dp_tunneling) ? '+' : '-', + (bits & osc_usb_pcie_tunneling) ? '+' : '-', + (bits & osc_usb_xdomain) ? '+' : '-'); +} + +static u8 sb_usb_uuid_str[] = "23a0d13a-26ab-486c-9c5f-0ffa525a575a"; +static void acpi_bus_osc_negotiate_usb_control(void) +{ + u32 capbuf[3]; + struct acpi_osc_context context = { + .uuid_str = sb_usb_uuid_str, + .rev = 1, + .cap.length = sizeof(capbuf), + .cap.pointer = capbuf, + }; + acpi_handle handle; + acpi_status status; + u32 control; + + if (!osc_sb_native_usb4_support_confirmed) + return; + + if (acpi_failure(acpi_get_handle(null, "\_sb", &handle))) + return; + + control = osc_usb_usb3_tunneling | osc_usb_dp_tunneling | + osc_usb_pcie_tunneling | osc_usb_xdomain; + + capbuf[osc_query_dword] = 0; + capbuf[osc_support_dword] = 0; + capbuf[osc_control_dword] = control; + + status = acpi_run_osc(handle, &context); + if (acpi_failure(status)) + return; + + if (context.ret.length != sizeof(capbuf)) { + printk(kern_info prefix "usb4 _osc: returned invalid length buffer "); + goto out_free; + osc_sb_native_usb4_control = + control & ((u32 *)context.ret.pointer)[osc_control_dword]; + + acpi_bus_decode_usb_osc("usb4 _osc: os supports", control); + acpi_bus_decode_usb_osc("usb4 _osc: os controls", + osc_sb_native_usb4_control); + +out_free: + acpi_bus_osc_negotiate_usb_control(); diff --git a/include/linux/acpi.h b/include/linux/acpi.h --- a/include/linux/acpi.h +++ b/include/linux/acpi.h +#define osc_sb_native_usb4_support 0x00040000 +extern bool osc_sb_native_usb4_support_confirmed; + +/* usb4 capabilities */ +#define osc_usb_usb3_tunneling 0x00000001 +#define osc_usb_dp_tunneling 0x00000002 +#define osc_usb_pcie_tunneling 0x00000004 +#define osc_usb_xdomain 0x00000008 + +extern u32 osc_sb_native_usb4_control;
Universal Serial Bus
5a6a2c0f0f43676df27632d657a3f18b151a7ef8
mika westerberg
drivers
acpi
usb: serial: add maxlinear/exar usb to serial driver
add support for maxlinear/exar usb to serial converters. this driver only supports xr21v141x series but it can be extended to other series from exar as well in future.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add maxlinear/exar usb to serial driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['serial ']
['kconfig', 'c', 'makefile']
3
605
0
--- diff --git a/drivers/usb/serial/kconfig b/drivers/usb/serial/kconfig --- a/drivers/usb/serial/kconfig +++ b/drivers/usb/serial/kconfig +config usb_serial_xr + tristate "usb maxlinear/exar usb to serial driver" + help + say y here if you want to use maxlinear/exar usb to serial converter + devices. + + to compile this driver as a module, choose m here: the + module will be called xr_serial. + diff --git a/drivers/usb/serial/makefile b/drivers/usb/serial/makefile --- a/drivers/usb/serial/makefile +++ b/drivers/usb/serial/makefile +obj-$(config_usb_serial_xr) += xr_serial.o diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c --- /dev/null +++ b/drivers/usb/serial/xr_serial.c +// spdx-license-identifier: gpl-2.0+ +/* + * maxlinear/exar usb to serial driver + * + * copyright (c) 2020 manivannan sadhasivam <mani@kernel.org> + * + * based on the initial driver written by patong yang: + * + * https://lore.kernel.org/r/20180404070634.nhspvmxcjwfgjkcv@advantechmxl-desktop + * + * copyright (c) 2018 patong yang <patong.mxl@gmail.com> + */ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/tty.h> +#include <linux/usb.h> +#include <linux/usb/serial.h> + +struct xr_txrx_clk_mask { + u16 tx; + u16 rx0; + u16 rx1; +}; + +#define xr_int_osc_hz 48000000u +#define xr21v141x_min_speed 46u +#define xr21v141x_max_speed xr_int_osc_hz + +/* usb requests */ +#define xr21v141x_set_req 0 +#define xr21v141x_get_req 1 + +#define xr21v141x_clock_divisor_0 0x04 +#define xr21v141x_clock_divisor_1 0x05 +#define xr21v141x_clock_divisor_2 0x06 +#define xr21v141x_tx_clock_mask_0 0x07 +#define xr21v141x_tx_clock_mask_1 0x08 +#define xr21v141x_rx_clock_mask_0 0x09 +#define xr21v141x_rx_clock_mask_1 0x0a + +/* xr21v141x register blocks */ +#define xr21v141x_uart_reg_block 0 +#define xr21v141x_um_reg_block 4 +#define xr21v141x_uart_custom_block 0x66 + +/* xr21v141x uart manager registers */ +#define xr21v141x_um_fifo_enable_reg 0x10 +#define xr21v141x_um_enable_tx_fifo 0x01 +#define xr21v141x_um_enable_rx_fifo 0x02 + +#define xr21v141x_um_rx_fifo_reset 0x18 +#define xr21v141x_um_tx_fifo_reset 0x1c + +#define xr21v141x_uart_enable_tx 0x1 +#define xr21v141x_uart_enable_rx 0x2 + +#define xr21v141x_uart_mode_ri bit(0) +#define xr21v141x_uart_mode_cd bit(1) +#define xr21v141x_uart_mode_dsr bit(2) +#define xr21v141x_uart_mode_dtr bit(3) +#define xr21v141x_uart_mode_cts bit(4) +#define xr21v141x_uart_mode_rts bit(5) + +#define xr21v141x_uart_break_on 0xff +#define xr21v141x_uart_break_off 0 + +#define xr21v141x_uart_data_mask genmask(3, 0) +#define xr21v141x_uart_data_7 0x7 +#define xr21v141x_uart_data_8 0x8 + +#define xr21v141x_uart_parity_mask genmask(6, 4) +#define xr21v141x_uart_parity_shift 0x4 +#define xr21v141x_uart_parity_none 0x0 +#define xr21v141x_uart_parity_odd 0x1 +#define xr21v141x_uart_parity_even 0x2 +#define xr21v141x_uart_parity_mark 0x3 +#define xr21v141x_uart_parity_space 0x4 + +#define xr21v141x_uart_stop_mask bit(7) +#define xr21v141x_uart_stop_shift 0x7 +#define xr21v141x_uart_stop_1 0x0 +#define xr21v141x_uart_stop_2 0x1 + +#define xr21v141x_uart_flow_mode_none 0x0 +#define xr21v141x_uart_flow_mode_hw 0x1 +#define xr21v141x_uart_flow_mode_sw 0x2 + +#define xr21v141x_uart_mode_gpio_mask genmask(2, 0) +#define xr21v141x_uart_mode_rts_cts 0x1 +#define xr21v141x_uart_mode_dtr_dsr 0x2 +#define xr21v141x_uart_mode_rs485 0x3 +#define xr21v141x_uart_mode_rs485_addr 0x4 + +#define xr21v141x_reg_enable 0x03 +#define xr21v141x_reg_format 0x0b +#define xr21v141x_reg_flow_ctrl 0x0c +#define xr21v141x_reg_xon_char 0x10 +#define xr21v141x_reg_xoff_char 0x11 +#define xr21v141x_reg_loopback 0x12 +#define xr21v141x_reg_tx_break 0x14 +#define xr21v141x_reg_rs845_delay 0x15 +#define xr21v141x_reg_gpio_mode 0x1a +#define xr21v141x_reg_gpio_dir 0x1b +#define xr21v141x_reg_gpio_int_mask 0x1c +#define xr21v141x_reg_gpio_set 0x1d +#define xr21v141x_reg_gpio_clr 0x1e +#define xr21v141x_reg_gpio_status 0x1f + +static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) +{ + struct usb_serial *serial = port->serial; + int ret; + + ret = usb_control_msg(serial->dev, + usb_sndctrlpipe(serial->dev, 0), + xr21v141x_set_req, + usb_dir_out | usb_type_vendor, val, + reg | (block << 8), null, 0, + usb_ctrl_set_timeout); + if (ret < 0) { + dev_err(&port->dev, "failed to set reg 0x%02x: %d ", reg, ret); + return ret; + } + + return 0; +} + +static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) +{ + struct usb_serial *serial = port->serial; + u8 *dmabuf; + int ret; + + dmabuf = kmalloc(1, gfp_kernel); + if (!dmabuf) + return -enomem; + + ret = usb_control_msg(serial->dev, + usb_rcvctrlpipe(serial->dev, 0), + xr21v141x_get_req, + usb_dir_in | usb_type_vendor, 0, + reg | (block << 8), dmabuf, 1, + usb_ctrl_get_timeout); + if (ret == 1) { + *val = *dmabuf; + ret = 0; + } else { + dev_err(&port->dev, "failed to get reg 0x%02x: %d ", reg, ret); + if (ret >= 0) + ret = -eio; + } + + kfree(dmabuf); + + return ret; +} + +static int xr_set_reg_uart(struct usb_serial_port *port, u8 reg, u8 val) +{ + return xr_set_reg(port, xr21v141x_uart_reg_block, reg, val); +} + +static int xr_get_reg_uart(struct usb_serial_port *port, u8 reg, u8 *val) +{ + return xr_get_reg(port, xr21v141x_uart_reg_block, reg, val); +} + +static int xr_set_reg_um(struct usb_serial_port *port, u8 reg, u8 val) +{ + return xr_set_reg(port, xr21v141x_um_reg_block, reg, val); +} + +/* + * according to datasheet, below is the recommended sequence for enabling uart + * module in xr21v141x: + * + * enable tx fifo + * enable tx and rx + * enable rx fifo + */ +static int xr_uart_enable(struct usb_serial_port *port) +{ + int ret; + + ret = xr_set_reg_um(port, xr21v141x_um_fifo_enable_reg, + xr21v141x_um_enable_tx_fifo); + if (ret) + return ret; + + ret = xr_set_reg_uart(port, xr21v141x_reg_enable, + xr21v141x_uart_enable_tx | xr21v141x_uart_enable_rx); + if (ret) + return ret; + + ret = xr_set_reg_um(port, xr21v141x_um_fifo_enable_reg, + xr21v141x_um_enable_tx_fifo | xr21v141x_um_enable_rx_fifo); + + if (ret) + xr_set_reg_uart(port, xr21v141x_reg_enable, 0); + + return ret; +} + +static int xr_uart_disable(struct usb_serial_port *port) +{ + int ret; + + ret = xr_set_reg_uart(port, xr21v141x_reg_enable, 0); + if (ret) + return ret; + + ret = xr_set_reg_um(port, xr21v141x_um_fifo_enable_reg, 0); + + return ret; +} + +static int xr_tiocmget(struct tty_struct *tty) +{ + struct usb_serial_port *port = tty->driver_data; + u8 status; + int ret; + + ret = xr_get_reg_uart(port, xr21v141x_reg_gpio_status, &status); + if (ret) + return ret; + + /* + * modem control pins are active low, so reading '0' means it is active + * and '1' means not active. + */ + ret = ((status & xr21v141x_uart_mode_dtr) ? 0 : tiocm_dtr) | + ((status & xr21v141x_uart_mode_rts) ? 0 : tiocm_rts) | + ((status & xr21v141x_uart_mode_cts) ? 0 : tiocm_cts) | + ((status & xr21v141x_uart_mode_dsr) ? 0 : tiocm_dsr) | + ((status & xr21v141x_uart_mode_ri) ? 0 : tiocm_ri) | + ((status & xr21v141x_uart_mode_cd) ? 0 : tiocm_cd); + + return ret; +} + +static int xr_tiocmset_port(struct usb_serial_port *port, + unsigned int set, unsigned int clear) +{ + u8 gpio_set = 0; + u8 gpio_clr = 0; + int ret = 0; + + /* modem control pins are active low, so set & clr are swapped */ + if (set & tiocm_rts) + gpio_clr |= xr21v141x_uart_mode_rts; + if (set & tiocm_dtr) + gpio_clr |= xr21v141x_uart_mode_dtr; + if (clear & tiocm_rts) + gpio_set |= xr21v141x_uart_mode_rts; + if (clear & tiocm_dtr) + gpio_set |= xr21v141x_uart_mode_dtr; + + /* writing '0' to gpio_{set/clr} bits has no effect, so no need to do */ + if (gpio_clr) + ret = xr_set_reg_uart(port, xr21v141x_reg_gpio_clr, gpio_clr); + + if (gpio_set) + ret = xr_set_reg_uart(port, xr21v141x_reg_gpio_set, gpio_set); + + return ret; +} + +static int xr_tiocmset(struct tty_struct *tty, + unsigned int set, unsigned int clear) +{ + struct usb_serial_port *port = tty->driver_data; + + return xr_tiocmset_port(port, set, clear); +} + +static void xr_dtr_rts(struct usb_serial_port *port, int on) +{ + if (on) + xr_tiocmset_port(port, tiocm_dtr | tiocm_rts, 0); + else + xr_tiocmset_port(port, 0, tiocm_dtr | tiocm_rts); +} + +static void xr_break_ctl(struct tty_struct *tty, int break_state) +{ + struct usb_serial_port *port = tty->driver_data; + u8 state; + + if (break_state == 0) + state = xr21v141x_uart_break_off; + else + state = xr21v141x_uart_break_on; + + dev_dbg(&port->dev, "turning break %s ", + state == xr21v141x_uart_break_off ? "off" : "on"); + xr_set_reg_uart(port, xr21v141x_reg_tx_break, state); +} + +/* tx and rx clock mask values obtained from section 3.3.4 of datasheet */ +static const struct xr_txrx_clk_mask xr21v141x_txrx_clk_masks[] = { + { 0x000, 0x000, 0x000 }, + { 0x000, 0x000, 0x000 }, + { 0x100, 0x000, 0x100 }, + { 0x020, 0x400, 0x020 }, + { 0x010, 0x100, 0x010 }, + { 0x208, 0x040, 0x208 }, + { 0x104, 0x820, 0x108 }, + { 0x844, 0x210, 0x884 }, + { 0x444, 0x110, 0x444 }, + { 0x122, 0x888, 0x224 }, + { 0x912, 0x448, 0x924 }, + { 0x492, 0x248, 0x492 }, + { 0x252, 0x928, 0x292 }, + { 0x94a, 0x4a4, 0xa52 }, + { 0x52a, 0xaa4, 0x54a }, + { 0xaaa, 0x954, 0x4aa }, + { 0xaaa, 0x554, 0xaaa }, + { 0x555, 0xad4, 0x5aa }, + { 0xb55, 0xab4, 0x55a }, + { 0x6b5, 0x5ac, 0xb56 }, + { 0x5b5, 0xd6c, 0x6d6 }, + { 0xb6d, 0xb6a, 0xdb6 }, + { 0x76d, 0x6da, 0xbb6 }, + { 0xedd, 0xdda, 0x76e }, + { 0xddd, 0xbba, 0xeee }, + { 0x7bb, 0xf7a, 0xdde }, + { 0xf7b, 0xef6, 0x7de }, + { 0xdf7, 0xbf6, 0xf7e }, + { 0x7f7, 0xfee, 0xefe }, + { 0xfdf, 0xfbe, 0x7fe }, + { 0xf7f, 0xefe, 0xffe }, + { 0xfff, 0xffe, 0xffd }, +}; + +static int xr_set_baudrate(struct tty_struct *tty, + struct usb_serial_port *port) +{ + u32 divisor, baud, idx; + u16 tx_mask, rx_mask; + int ret; + + baud = clamp(tty->termios.c_ospeed, xr21v141x_min_speed, + xr21v141x_max_speed); + divisor = xr_int_osc_hz / baud; + idx = ((32 * xr_int_osc_hz) / baud) & 0x1f; + tx_mask = xr21v141x_txrx_clk_masks[idx].tx; + + if (divisor & 0x01) + rx_mask = xr21v141x_txrx_clk_masks[idx].rx1; + else + rx_mask = xr21v141x_txrx_clk_masks[idx].rx0; + + dev_dbg(&port->dev, "setting baud rate: %u ", baud); + /* + * xr21v141x uses fractional baud rate generator with 48mhz internal + * oscillator and 19-bit programmable divisor. so theoretically it can + * generate most commonly used baud rates with high accuracy. + */ + ret = xr_set_reg_uart(port, xr21v141x_clock_divisor_0, + divisor & 0xff); + if (ret) + return ret; + + ret = xr_set_reg_uart(port, xr21v141x_clock_divisor_1, + (divisor >> 8) & 0xff); + if (ret) + return ret; + + ret = xr_set_reg_uart(port, xr21v141x_clock_divisor_2, + (divisor >> 16) & 0xff); + if (ret) + return ret; + + ret = xr_set_reg_uart(port, xr21v141x_tx_clock_mask_0, + tx_mask & 0xff); + if (ret) + return ret; + + ret = xr_set_reg_uart(port, xr21v141x_tx_clock_mask_1, + (tx_mask >> 8) & 0xff); + if (ret) + return ret; + + ret = xr_set_reg_uart(port, xr21v141x_rx_clock_mask_0, + rx_mask & 0xff); + if (ret) + return ret; + + ret = xr_set_reg_uart(port, xr21v141x_rx_clock_mask_1, + (rx_mask >> 8) & 0xff); + if (ret) + return ret; + + tty_encode_baud_rate(tty, baud, baud); + + return 0; +} + +static void xr_set_flow_mode(struct tty_struct *tty, + struct usb_serial_port *port) +{ + unsigned int cflag = tty->termios.c_cflag; + u8 flow, gpio_mode; + int ret; + + ret = xr_get_reg_uart(port, xr21v141x_reg_gpio_mode, &gpio_mode); + if (ret) + return; + + if (cflag & crtscts) { + dev_dbg(&port->dev, "enabling hardware flow ctrl "); + + /* + * rts/cts is the default flow control mode, so set gpio mode + * for controlling the pins manually by default. + */ + gpio_mode &= ~xr21v141x_uart_mode_gpio_mask; + gpio_mode |= xr21v141x_uart_mode_rts_cts; + flow = xr21v141x_uart_flow_mode_hw; + } else if (i_ixon(tty)) { + u8 start_char = start_char(tty); + u8 stop_char = stop_char(tty); + + dev_dbg(&port->dev, "enabling sw flow ctrl "); + flow = xr21v141x_uart_flow_mode_sw; + + xr_set_reg_uart(port, xr21v141x_reg_xon_char, start_char); + xr_set_reg_uart(port, xr21v141x_reg_xoff_char, stop_char); + } else { + dev_dbg(&port->dev, "disabling flow ctrl "); + flow = xr21v141x_uart_flow_mode_none; + } + + /* + * as per the datasheet, uart needs to be disabled while writing to + * flow_control register. + */ + xr_uart_disable(port); + xr_set_reg_uart(port, xr21v141x_reg_flow_ctrl, flow); + xr_uart_enable(port); + + xr_set_reg_uart(port, xr21v141x_reg_gpio_mode, gpio_mode); +} + +static void xr_set_termios(struct tty_struct *tty, + struct usb_serial_port *port, + struct ktermios *old_termios) +{ + struct ktermios *termios = &tty->termios; + u8 bits = 0; + int ret; + + if ((old_termios && tty->termios.c_ospeed != old_termios->c_ospeed) || + !old_termios) + xr_set_baudrate(tty, port); + + switch (c_csize(tty)) { + case cs5: + case cs6: + /* cs5 and cs6 are not supported, so just restore old setting */ + termios->c_cflag &= ~csize; + if (old_termios) + termios->c_cflag |= old_termios->c_cflag & csize; + else + bits |= xr21v141x_uart_data_8; + break; + case cs7: + bits |= xr21v141x_uart_data_7; + break; + case cs8: + default: + bits |= xr21v141x_uart_data_8; + break; + } + + if (c_parenb(tty)) { + if (c_cmspar(tty)) { + if (c_parodd(tty)) + bits |= xr21v141x_uart_parity_mark << + xr21v141x_uart_parity_shift; + else + bits |= xr21v141x_uart_parity_space << + xr21v141x_uart_parity_shift; + } else { + if (c_parodd(tty)) + bits |= xr21v141x_uart_parity_odd << + xr21v141x_uart_parity_shift; + else + bits |= xr21v141x_uart_parity_even << + xr21v141x_uart_parity_shift; + } + } + + if (c_cstopb(tty)) + bits |= xr21v141x_uart_stop_2 << xr21v141x_uart_stop_shift; + else + bits |= xr21v141x_uart_stop_1 << xr21v141x_uart_stop_shift; + + ret = xr_set_reg_uart(port, xr21v141x_reg_format, bits); + if (ret) + return; + + /* if baud rate is b0, clear dtr and rts */ + if (c_baud(tty) == b0) + xr_dtr_rts(port, 0); + + xr_set_flow_mode(tty, port); +} + +static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) +{ + int ret; + + ret = xr_uart_enable(port); + if (ret) { + dev_err(&port->dev, "failed to enable uart "); + return ret; + } + + /* setup termios */ + if (tty) + xr_set_termios(tty, port, null); + + ret = usb_serial_generic_open(tty, port); + if (ret) { + xr_uart_disable(port); + return ret; + } + + return 0; +} + +static void xr_close(struct usb_serial_port *port) +{ + usb_serial_generic_close(port); + + xr_uart_disable(port); +} + +static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) +{ + struct usb_device *usb_dev = interface_to_usbdev(serial->interface); + struct usb_driver *driver = serial->type->usb_driver; + struct usb_interface *control_interface; + int ret; + + /* don't bind to control interface */ + if (serial->interface->cur_altsetting->desc.binterfacenumber == 0) + return -enodev; + + /* but claim the control interface during data interface probe */ + control_interface = usb_ifnum_to_if(usb_dev, 0); + ret = usb_driver_claim_interface(driver, control_interface, null); + if (ret) { + dev_err(&serial->interface->dev, "failed to claim control interface "); + return ret; + } + + return 0; +} + +static const struct usb_device_id id_table[] = { + { usb_device(0x04e2, 0x1410) }, /* xr21v141x */ + { } +}; +module_device_table(usb, id_table); + +static struct usb_serial_driver xr_device = { + .driver = { + .owner = this_module, + .name = "xr_serial", + }, + .id_table = id_table, + .num_ports = 1, + .probe = xr_probe, + .open = xr_open, + .close = xr_close, + .break_ctl = xr_break_ctl, + .set_termios = xr_set_termios, + .tiocmget = xr_tiocmget, + .tiocmset = xr_tiocmset, + .dtr_rts = xr_dtr_rts +}; + +static struct usb_serial_driver * const serial_drivers[] = { + &xr_device, null +}; + +module_usb_serial_driver(serial_drivers, id_table); + +module_author("manivannan sadhasivam <mani@kernel.org>"); +module_description("maxlinear/exar usb to serial driver"); +module_license("gpl");
Universal Serial Bus
c2d405aa86b451f197ee95cb08887130b86b765e
manivannan sadhasivam
drivers
usb
serial
usb: serial: ch341: add new product id
add pid for ch340 that's found on cheap programmers.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add new product id
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['serial ', 'ch341']
['c']
1
1
0
--- diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c --- a/drivers/usb/serial/ch341.c +++ b/drivers/usb/serial/ch341.c + { usb_device(0x9986, 0x7523) },
Universal Serial Bus
5563b3b6420362c8a1f468ca04afe6d5f0a8d0a3
niv sardi
drivers
usb
serial
usb: serial: cp210x: add id for acuity brands nlight air adapter
ids of nlight air adapter, acuity brands, inc.: vid: 10c4 pid: 88d8
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add id for acuity brands nlight air adapter
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['serial ', 'cp210x']
['c']
1
1
0
--- diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c + { usb_device(0x10c4, 0x88d8) }, /* acuity brands nlight air adapter */
Universal Serial Bus
ca667a33207daeaf9c62b106815728718def60ec
karan singhal
drivers
usb
serial
usb: serial: cp210x: add some more ge usb ids
ge cs1000 has some more custom usb ids for cp2102n; add them to the driver to have working auto-probing.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add some more ge usb ids
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['serial ', 'cp210x']
['c']
1
2
0
--- diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c + { usb_device(0x1901, 0x0197) }, /* ge cs1000 display serial interface */ + { usb_device(0x1901, 0x0198) }, /* ge cs1000 m.2 key e serial interface */
Universal Serial Bus
42213a0190b535093a604945db05a4225bf43885
sebastian reichel
drivers
usb
serial
usb: serial: cp210x: add support for software flow control
when data is transmitted between two serial ports, the phenomenon of data loss often occurs. the two kinds of flow control commonly used in serial communication are hardware flow control and software flow control.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add support for software flow control
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['serial ', 'cp210x']
['c']
1
65
2
--- diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c +/* cp210x_(get|set)_chars */ +struct cp210x_special_chars { + u8 beofchar; + u8 berrorchar; + u8 bbreakchar; + u8 beventchar; + u8 bxonchar; + u8 bxoffchar; +}; + +static int cp210x_set_chars(struct usb_serial_port *port, + struct cp210x_special_chars *chars) +{ + struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); + struct usb_serial *serial = port->serial; + void *dmabuf; + int result; + + dmabuf = kmemdup(chars, sizeof(*chars), gfp_kernel); + if (!dmabuf) + return -enomem; + + result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), + cp210x_set_chars, reqtype_host_to_interface, 0, + port_priv->binterfacenumber, + dmabuf, sizeof(*chars), usb_ctrl_set_timeout); + + kfree(dmabuf); + + if (result < 0) { + dev_err(&port->dev, "failed to set special chars: %d ", result); + return result; + } + + return 0; +} + - iflag_change = ((a->c_iflag ^ b->c_iflag) & inpck); + iflag_change = ((a->c_iflag ^ b->c_iflag) & (inpck | ixon | ixoff)); + struct cp210x_special_chars chars; - if (old_termios && c_crtscts(tty) == (old_termios->c_cflag & crtscts)) + if (old_termios && + c_crtscts(tty) == (old_termios->c_cflag & crtscts) && + i_ixon(tty) == (old_termios->c_iflag & ixon) && + i_ixoff(tty) == (old_termios->c_iflag & ixoff)) { + } + + if (i_ixon(tty) || i_ixoff(tty)) { + memset(&chars, 0, sizeof(chars)); + + chars.bxonchar = start_char(tty); + chars.bxoffchar = stop_char(tty); + + ret = cp210x_set_chars(port, &chars); + if (ret) + return; + } + if (i_ixoff(tty)) + flow_repl |= cp210x_serial_auto_receive; + else + flow_repl &= ~cp210x_serial_auto_receive; + + if (i_ixon(tty)) + flow_repl |= cp210x_serial_auto_transmit; + else + flow_repl &= ~cp210x_serial_auto_transmit; +
Universal Serial Bus
7748feffcd80f3ee25dae5e6acd3cf90e8e838d8
wang sheng long
drivers
usb
serial
usb: serial: option: update interface mapping for zte p685m
this patch prepares for qmi_wwan driver support for the device. previously "option" driver mapped itself to interfaces 0 and 3 (matching ff/ff/ff), while interface 3 is in fact a qmi port. interfaces 1 and 2 (matching ff/00/00) expose at commands, and weren't supported previously at all. without this patch, a possible conflict would exist if device id was added to qmi_wwan driver for interface 3.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
update interface mapping for zte p685m
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['serial ', 'option']
['c']
1
2
1
--- diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c - { usb_device_and_interface_info(zte_vendor_id, 0x1275, 0xff, 0xff, 0xff) }, + { usb_device(zte_vendor_id, 0x1275), /* zte p685m */ + .driver_info = rsvd(3) | rsvd(4) },
Universal Serial Bus
6420a569504e212d618d4a4736e2c59ed80a8478
lech perczak
drivers
usb
serial
usb: typec: standardize pd revision format with type-c revision
the type-c revision was in a specific bcd format "0120h" for 1.2. usb pd revision numbers follow a similar pattern with "0300h" for 3.0.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add individual version numbers for the partner and the cable, and exposes them in the appropriate sysfs in /sys/class/type
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['sysfs-class-typec', 'c']
2
8
2
- "2.0": usb power delivery release 2.0 - "3.0": usb power delivery release 3.0 - "3.1": usb power delivery release 3.1 --- diff --git a/documentation/abi/testing/sysfs-class-typec b/documentation/abi/testing/sysfs-class-typec --- a/documentation/abi/testing/sysfs-class-typec +++ b/documentation/abi/testing/sysfs-class-typec - specification, or 0 when usb power delivery is not supported. + specification, or 0.0 when usb power delivery is not supported. + + example values: + - "2.0": usb power delivery release 2.0 + - "3.0": usb power delivery release 3.0 + - "3.1": usb power delivery release 3.1 diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c + u16 rev = p->cap->pd_revision; - return sprintf(buf, "%d ", (p->cap->pd_revision >> 8) & 0xff); + return sprintf(buf, "%d.%d ", (rev >> 8) & 0xff, (rev >> 4) & 0xf);
Universal Serial Bus
1ed8459d8f1060c87c7d66fe2d3cbbe4bc9cdd24
benson leung
drivers
usb
testing, typec
usb: typec: provide pd specification revision for cable and partner
the usb power delivery specification section 6.2.1.1.5 outlines revision backward compatibility requirements starting from revision 3.0.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add individual version numbers for the partner and the cable, and exposes them in the appropriate sysfs in /sys/class/type
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['sysfs-class-typec', 'h', 'c']
3
49
4
--- diff --git a/documentation/abi/testing/sysfs-class-typec b/documentation/abi/testing/sysfs-class-typec --- a/documentation/abi/testing/sysfs-class-typec +++ b/documentation/abi/testing/sysfs-class-typec - "3.0": usb power delivery release 3.0 - "3.1": usb power delivery release 3.1 +what: /sys/class/typec/<port>-{partner|cable}/usb_power_delivery_revision +date: january 2021 +contact: benson leung <bleung@chromium.org> +description: + revision number of the supported usb power delivery + specification of the port partner or cable, or 0.0 when usb + power delivery is not supported. + + example values: + - "2.0": usb power delivery release 2.0 + - "3.0": usb power delivery release 3.0 + - "3.1": usb power delivery release 3.1 + diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c + u16 pd_revision; /* 0300h = "3.0" */ + u16 pd_revision; /* 0300h = "3.0" */ +static ssize_t usb_power_delivery_revision_show(struct device *dev, + struct device_attribute *attr, + char *buf); +static device_attr_ro(usb_power_delivery_revision); + + &dev_attr_usb_power_delivery_revision.attr, + partner->pd_revision = desc->pd_revision; + &dev_attr_usb_power_delivery_revision.attr, + cable->pd_revision = desc->pd_revision; - struct typec_port *p = to_typec_port(dev); - u16 rev = p->cap->pd_revision; + u16 rev = 0; - return sprintf(buf, "%d.%d ", (rev >> 8) & 0xff, (rev >> 4) & 0xf); + if (is_typec_partner(dev)) { + struct typec_partner *partner = to_typec_partner(dev); + + rev = partner->pd_revision; + } else if (is_typec_cable(dev)) { + struct typec_cable *cable = to_typec_cable(dev); + + rev = cable->pd_revision; + } else if (is_typec_port(dev)) { + struct typec_port *p = to_typec_port(dev); + + rev = p->cap->pd_revision; + } + return sysfs_emit(buf, "%d.%d ", (rev >> 8) & 0xff, (rev >> 4) & 0xf); -static device_attr_ro(usb_power_delivery_revision); diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h + * @pd_revision: usb power delivery specification revision if supported + u16 pd_revision; /* 0300h = "3.0" */ + + * @pd_revision: usb power delivery specification revision if supported + * + * @pd_revision is based on the setting of the "specification revision" field + * in the message header on the initial "source capabilities" message received + * from the partner, or a "request" message received from the partner, depending + * on whether our port is a sink or a source. + u16 pd_revision; /* 0300h = "3.0" */
Universal Serial Bus
f5030e252687be6e999bd52feb1f79d515b2f684
benson leung
drivers
usb
testing, typec, usb
usb: typec: add typec_partner_set_pd_revision
the partner's pd revision may be resolved later than the port partner registration since the port partner creation may take place once type-c detects the port has changed state, but before pd communication is completed.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add individual version numbers for the partner and the cable, and exposes them in the appropriate sysfs in /sys/class/type
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['h', 'c']
2
31
0
--- diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c +/** + * typec_partner_set_pd_revision - set the pd revision supported by the partner + * @partner: the partner to be updated. + * @pd_revision: usb power delivery specification revision supported by partner + * + * this routine is used to report that the pd revision of the port partner has + * become available. + * + * returns 0 on success or negative error number on failure. + */ +int typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_revision) +{ + int ret; + + if (partner->pd_revision == pd_revision) + return 0; + + partner->pd_revision = pd_revision; + sysfs_notify(&partner->dev.kobj, null, "usb_power_delivery_revision"); + if (pd_revision != 0 && !partner->usb_pd) { + partner->usb_pd = 1; + sysfs_notify(&partner->dev.kobj, null, + "supports_usb_power_delivery"); + } + kobject_uevent(&partner->dev.kobj, kobj_change); + + return 0; +} +export_symbol_gpl(typec_partner_set_pd_revision); + diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h +int typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_revision);
Universal Serial Bus
29b01295a829fba7399ee84afff4e64660e49f04
benson leung
drivers
usb
typec, usb
platform/chrome: cros_ec_typec: report sop' pd revision from status
cros_typec_handle_sop_prime_disc now takes the pd revision provided by the ec_cmd_typec_status command response for the sop'.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add individual version numbers for the partner and the cable, and exposes them in the appropriate sysfs in /sys/class/type
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['c']
1
7
2
--- diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c -static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int port_num) +static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int port_num, u16 pd_revision) + c_desc.pd_revision = pd_revision; - ret = cros_typec_handle_sop_prime_disc(typec, port_num); + u16 sop_prime_revision; + + /* convert bcd to the format preferred by the typec framework */ + sop_prime_revision = (le16_to_cpu(resp.sop_prime_revision) & 0xff00) >> 4; + ret = cros_typec_handle_sop_prime_disc(typec, port_num, sop_prime_revision);
Universal Serial Bus
3b3dd1f0dbfe92781c60f36ea5c22b26360f9909
benson leung
drivers
platform
chrome
platform/chrome: cros_ec_typec: set partner pd revision from status
status provides sop_revision. process it, and set it using the new setter in the typec class.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add individual version numbers for the partner and the cable, and exposes them in the appropriate sysfs in /sys/class/type
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['c']
1
12
2
--- diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c -static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num) +static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num, u16 pd_revision) + ret = typec_partner_set_pd_revision(port->partner, pd_revision); + if (ret < 0) { + dev_err(typec->dev, "failed to update partner pd revision, port: %d ", port_num); + goto disc_exit; + } + - ret = cros_typec_handle_sop_disc(typec, port_num); + u16 sop_revision; + + /* convert bcd to the format preferred by the typec framework */ + sop_revision = (le16_to_cpu(resp.sop_revision) & 0xff00) >> 4; + ret = cros_typec_handle_sop_disc(typec, port_num, sop_revision);
Universal Serial Bus
cefc011f8daf0ff3003208349b85174cda0b708d
benson leung heikki krogerus heikki krogerus linux intel com enric balletbo i serra enric balletbo collabora com prashant malani pmalani chomium org
drivers
platform
chrome
platform/chrome: cros_ec_typec: set opmode to pd on sop connected
when sop discovery is done, set the opmode to pd if status indicates sop is connected.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add individual version numbers for the partner and the cable, and exposes them in the appropriate sysfs in /sys/class/type
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['c']
1
3
0
--- diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c + + if (resp.sop_connected) + typec_set_pwr_opmode(typec->ports[port_num]->port, typec_pwr_mode_pd);
Universal Serial Bus
0371616d8bef6926e9aa05757f35b901268d3724
benson leung
drivers
platform
chrome
usb: typec: tcpm: ams and collision avoidance
this patch provides the implementation of collision avoidance introduced in pd3.0. the start of each atomic message sequence (ams) initiated by the port will be denied if the current ams is not interruptible. the source port will set the cc to sinktxng if it is going to initiate an ams, and sinktxok otherwise. meanwhile, any ams initiated by a sink port will be denied in tcpm if the port partner (source) sets sinktxng except for hard_reset and soft_reset.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
ams, collision avoidance, and protocol error
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['h', 'c']
3
527
98
--- diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c + s(src_soft_reset_wait_snk_tx), \ + s(snk_soft_reset), \ - s(port_reset_wait_off) + s(port_reset_wait_off), \ + \ + s(ams_start) + +#define foreach_ams(s) \ + s(none_ams), \ + s(power_negotiation), \ + s(gotomin), \ + s(soft_reset_ams), \ + s(hard_reset), \ + s(cable_reset), \ + s(get_source_capabilities), \ + s(get_sink_capabilities), \ + s(power_role_swap), \ + s(fast_role_swap), \ + s(data_role_swap), \ + s(vconn_swap), \ + s(source_alert), \ + s(getting_source_extended_capabilities),\ + s(getting_source_sink_status), \ + s(getting_battery_capabilities), \ + s(getting_battery_status), \ + s(getting_manufacturer_information), \ + s(security), \ + s(firmware_update), \ + s(discover_identity), \ + s(source_startup_cable_plug_discover_identity), \ + s(discover_svids), \ + s(discover_modes), \ + s(dfp_to_ufp_enter_mode), \ + s(dfp_to_ufp_exit_mode), \ + s(dfp_to_cable_plug_enter_mode), \ + s(dfp_to_cable_plug_exit_mode), \ + s(attention), \ + s(bist), \ + s(unstructured_vdms), \ + s(structured_vdms), \ + s(country_info), \ + s(country_codes) +enum tcpm_ams { + foreach_ams(generate_enum) +}; + +static const char * const tcpm_ams_str[] = { + foreach_ams(generate_string) +}; + + vdm_state_send_message = 4, + /* collision avoidance and atomic message sequence */ + enum tcpm_state upcoming_state; + enum tcpm_ams ams; + bool in_ams; + +static const char * const pd_rev[] = { + [pd_rev10] = "rev1", + [pd_rev20] = "rev2", + [pd_rev30] = "rev3", +}; + +#define tcpm_sink_tx_ok(port) \ + (tcpm_port_is_sink(port) && \ + ((port)->cc1 == typec_cc_rp_3_0 || (port)->cc2 == typec_cc_rp_3_0)) + +static void tcpm_set_cc(struct tcpm_port *port, enum typec_cc_status cc) +{ + tcpm_log(port, "cc:=%d", cc); + port->cc_req = cc; + port->tcpc->set_cc(port->tcpc, cc); +} + +/* + * determine rp value to set based on maximum current supported + * by a port if configured as source. + * returns cc value to report to link partner. + */ +static enum typec_cc_status tcpm_rp_cc(struct tcpm_port *port) +{ + const u32 *src_pdo = port->src_pdo; + int nr_pdo = port->nr_src_pdo; + int i; + + /* + * search for first entry with matching voltage. + * it should report the maximum supported current. + */ + for (i = 0; i < nr_pdo; i++) { + const u32 pdo = src_pdo[i]; + + if (pdo_type(pdo) == pdo_type_fixed && + pdo_fixed_voltage(pdo) == 5000) { + unsigned int curr = pdo_max_current(pdo); + + if (curr >= 3000) + return typec_cc_rp_3_0; + else if (curr >= 1500) + return typec_cc_rp_1_5; + return typec_cc_rp_def; + } + } + + return typec_cc_rp_def; +} + +static int tcpm_ams_finish(struct tcpm_port *port) +{ + int ret = 0; + + tcpm_log(port, "ams %s finished", tcpm_ams_str[port->ams]); + + if (port->pd_capable && port->pwr_role == typec_source) { + if (port->negotiated_rev >= pd_rev30) + tcpm_set_cc(port, sink_tx_ok); + else + tcpm_set_cc(port, sink_tx_ng); + } else if (port->pwr_role == typec_source) { + tcpm_set_cc(port, tcpm_rp_cc(port)); + } + + port->in_ams = false; + port->ams = none_ams; + + return ret; +} + - return 0; + /* + * usb pd rev 2.0, 8.3.2.2.1: + * usb pd rev 3.0, 8.3.2.1.3: + * "... note that every ams is interruptible until the first + * message in the sequence has been successfully sent (goodcrc + * message received)." + */ + if (port->ams != none_ams) + port->in_ams = true; + break; - return -eagain; + ret = -eagain; + break; - return -eio; + ret = -eio; + break; + + /* some ams don't expect responses. finish them here. */ + if (port->ams == attention || port->ams == source_alert) + tcpm_ams_finish(port); + + return ret; -/* - * determine rp value to set based on maximum current supported - * by a port if configured as source. - * returns cc value to report to link partner. - */ -static enum typec_cc_status tcpm_rp_cc(struct tcpm_port *port) -{ - const u32 *src_pdo = port->src_pdo; - int nr_pdo = port->nr_src_pdo; - int i; - - /* - * search for first entry with matching voltage. - * it should report the maximum supported current. - */ - for (i = 0; i < nr_pdo; i++) { - const u32 pdo = src_pdo[i]; - - if (pdo_type(pdo) == pdo_type_fixed && - pdo_fixed_voltage(pdo) == 5000) { - unsigned int curr = pdo_max_current(pdo); - - if (curr >= 3000) - return typec_cc_rp_3_0; - else if (curr >= 1500) - return typec_cc_rp_1_5; - return typec_cc_rp_def; - } - } - - return typec_cc_rp_def; -} - - tcpm_log(port, "pending state change %s -> %s @ %u ms", - tcpm_states[port->state], tcpm_states[state], - delay_ms); + tcpm_log(port, "pending state change %s -> %s @ %u ms [%s %s]", + tcpm_states[port->state], tcpm_states[state], delay_ms, + pd_rev[port->negotiated_rev], tcpm_ams_str[port->ams]); - tcpm_log(port, "state change %s -> %s", - tcpm_states[port->state], tcpm_states[state]); + tcpm_log(port, "state change %s -> %s [%s %s]", + tcpm_states[port->state], tcpm_states[state], + pd_rev[port->negotiated_rev], tcpm_ams_str[port->ams]); - "skipped %sstate change %s -> %s [%u ms], context state %s", + "skipped %sstate change %s -> %s [%u ms], context state %s [%s %s]", - delay_ms, tcpm_states[port->enter_state]); + delay_ms, tcpm_states[port->enter_state], + pd_rev[port->negotiated_rev], tcpm_ams_str[port->ams]); +static bool tcpm_vdm_ams(struct tcpm_port *port) +{ + switch (port->ams) { + case discover_identity: + case source_startup_cable_plug_discover_identity: + case discover_svids: + case discover_modes: + case dfp_to_ufp_enter_mode: + case dfp_to_ufp_exit_mode: + case dfp_to_cable_plug_enter_mode: + case dfp_to_cable_plug_exit_mode: + case attention: + case unstructured_vdms: + case structured_vdms: + break; + default: + return false; + } + + return true; +} + +static bool tcpm_ams_interruptible(struct tcpm_port *port) +{ + switch (port->ams) { + /* interruptible ams */ + case none_ams: + case security: + case firmware_update: + case discover_identity: + case source_startup_cable_plug_discover_identity: + case discover_svids: + case discover_modes: + case dfp_to_ufp_enter_mode: + case dfp_to_ufp_exit_mode: + case dfp_to_cable_plug_enter_mode: + case dfp_to_cable_plug_exit_mode: + case unstructured_vdms: + case structured_vdms: + case country_info: + case country_codes: + break; + /* non-interruptible ams */ + default: + if (port->in_ams) + return false; + break; + } + + return true; +} + +static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams) +{ + int ret = 0; + + tcpm_log(port, "ams %s start", tcpm_ams_str[ams]); + + if (!tcpm_ams_interruptible(port) && ams != hard_reset) { + port->upcoming_state = invalid_state; + tcpm_log(port, "ams %s not interruptible, aborting", + tcpm_ams_str[port->ams]); + return -eagain; + } + + if (port->pwr_role == typec_source) { + enum typec_cc_status cc_req = port->cc_req; + + port->ams = ams; + + if (ams == hard_reset) { + tcpm_set_cc(port, tcpm_rp_cc(port)); + tcpm_pd_transmit(port, tcpc_tx_hard_reset, null); + tcpm_set_state(port, hard_reset_start, 0); + return ret; + } else if (ams == soft_reset_ams) { + if (!port->explicit_contract) { + port->upcoming_state = invalid_state; + tcpm_set_cc(port, tcpm_rp_cc(port)); + return ret; + } + } else if (tcpm_vdm_ams(port)) { + /* tsinktx is enforced in vdm_run_state_machine */ + if (port->negotiated_rev >= pd_rev30) + tcpm_set_cc(port, sink_tx_ng); + return ret; + } + + if (port->negotiated_rev >= pd_rev30) + tcpm_set_cc(port, sink_tx_ng); + + switch (port->state) { + case src_ready: + case src_startup: + case src_soft_reset_wait_snk_tx: + case soft_reset: + case soft_reset_send: + if (port->negotiated_rev >= pd_rev30) + tcpm_set_state(port, ams_start, + cc_req == sink_tx_ok ? + pd_t_sink_tx : 0); + else + tcpm_set_state(port, ams_start, 0); + break; + default: + if (port->negotiated_rev >= pd_rev30) + tcpm_set_state(port, src_ready, + cc_req == sink_tx_ok ? + pd_t_sink_tx : 0); + else + tcpm_set_state(port, src_ready, 0); + break; + } + } else { + if (port->negotiated_rev >= pd_rev30 && + !tcpm_sink_tx_ok(port) && + ams != soft_reset_ams && + ams != hard_reset) { + port->upcoming_state = invalid_state; + tcpm_log(port, "sink tx no go"); + return -eagain; + } + + port->ams = ams; + + if (ams == hard_reset) { + tcpm_pd_transmit(port, tcpc_tx_hard_reset, null); + tcpm_set_state(port, hard_reset_start, 0); + return ret; + } else if (tcpm_vdm_ams(port)) { + return ret; + } + + if (port->state == snk_ready || + port->state == snk_soft_reset) + tcpm_set_state(port, ams_start, 0); + else + tcpm_set_state(port, snk_ready, 0); + } + + return ret; +} + + tcpm_ams_finish(port); + + tcpm_ams_finish(port); - int i, res; + int i, res = 0; + u32 vdo_hdr = port->vdo_data[0]; - /* prepare and send vdm */ - memset(&msg, 0, sizeof(msg)); - msg.header = pd_header_le(pd_data_vendor_def, - port->pwr_role, - port->data_role, - port->negotiated_rev, - port->message_id, port->vdo_count); - for (i = 0; i < port->vdo_count; i++) - msg.payload[i] = cpu_to_le32(port->vdo_data[i]); - res = tcpm_pd_transmit(port, tcpc_tx_sop, &msg); - if (res < 0) { - port->vdm_state = vdm_state_err_send; - } else { - unsigned long timeout; + /* todo: ams operation for unstructured vdm */ + if (pd_vdo_svdm(vdo_hdr) && pd_vdo_cmdt(vdo_hdr) == cmdt_init) { + switch (pd_vdo_cmd(vdo_hdr)) { + case cmd_discover_ident: + res = tcpm_ams_start(port, discover_identity); + break; + case cmd_discover_svid: + res = tcpm_ams_start(port, discover_svids); + break; + case cmd_discover_modes: + res = tcpm_ams_start(port, discover_modes); + break; + case cmd_enter_mode: + res = tcpm_ams_start(port, dfp_to_ufp_enter_mode); + break; + case cmd_exit_mode: + res = tcpm_ams_start(port, dfp_to_ufp_exit_mode); + break; + case cmd_attention: + res = tcpm_ams_start(port, attention); + break; + case vdo_cmd_vendor(0) ... vdo_cmd_vendor(15): + res = tcpm_ams_start(port, structured_vdms); + break; + default: + res = -eopnotsupp; + break; + } - port->vdm_retries = 0; - port->vdm_state = vdm_state_busy; - timeout = vdm_ready_timeout(port->vdo_data[0]); - mod_vdm_delayed_work(port, timeout); + if (res < 0) + return; + + port->vdm_state = vdm_state_send_message; + mod_vdm_delayed_work(port, (port->negotiated_rev >= pd_rev30 && + port->pwr_role == typec_source && + pd_vdo_svdm(vdo_hdr) && + pd_vdo_cmdt(vdo_hdr) == cmdt_init) ? + pd_t_sink_tx : 0); + if (port->ams != none_ams) + tcpm_ams_finish(port); + tcpm_ams_finish(port); + } + break; + case vdm_state_send_message: + /* prepare and send vdm */ + memset(&msg, 0, sizeof(msg)); + msg.header = pd_header_le(pd_data_vendor_def, + port->pwr_role, + port->data_role, + port->negotiated_rev, + port->message_id, port->vdo_count); + for (i = 0; i < port->vdo_count; i++) + msg.payload[i] = cpu_to_le32(port->vdo_data[i]); + res = tcpm_pd_transmit(port, tcpc_tx_sop, &msg); + if (res < 0) { + port->vdm_state = vdm_state_err_send; + } else { + unsigned long timeout; + + port->vdm_retries = 0; + port->vdm_state = vdm_state_busy; + timeout = vdm_ready_timeout(vdo_hdr); + mod_vdm_delayed_work(port, timeout); - port->vdm_state != vdm_state_busy); + port->vdm_state != vdm_state_busy && + port->vdm_state != vdm_state_send_message); - if (port->pwr_role == typec_source) - next_state = src_send_capabilities; - else - next_state = snk_wait_capabilities; - tcpm_set_state(port, next_state, 0); + if (port->ams == soft_reset_ams) + tcpm_ams_finish(port); + if (port->pwr_role == typec_source) { + port->upcoming_state = src_send_capabilities; + tcpm_ams_start(port, power_negotiation); + } else { + tcpm_set_state(port, snk_wait_capabilities, 0); + } -static void tcpm_set_cc(struct tcpm_port *port, enum typec_cc_status cc) -{ - tcpm_log(port, "cc:=%d", cc); - port->cc_req = cc; - port->tcpc->set_cc(port->tcpc, cc); -} - + port->in_ams = false; + port->ams = none_ams; + enum tcpm_state upcoming_state; - tcpm_set_state(port, src_send_capabilities, 0); + /* snk -> src power/fast_role_swap finished */ + if (port->ams == power_role_swap || + port->ams == fast_role_swap) + tcpm_ams_finish(port); + port->upcoming_state = src_send_capabilities; + tcpm_ams_start(port, power_negotiation); + if (port->ams != none_ams) + tcpm_ams_finish(port); + /* + * if previous ams is interrupted, switch to the upcoming + * state. + */ + if (port->upcoming_state != invalid_state) { + upcoming_state = port->upcoming_state; + port->upcoming_state = invalid_state; + tcpm_set_state(port, upcoming_state, 0); + break; + } + + + if (port->ams == power_role_swap || + port->ams == fast_role_swap) + /* src -> snk power/fast_role_swap finished */ + tcpm_ams_finish(port); + - tcpm_set_state(port, soft_reset_send, + tcpm_set_state(port, snk_soft_reset, - tcpm_check_send_discover(port); + + if (port->ams != none_ams) + tcpm_ams_finish(port); + /* + * if previous ams is interrupted, switch to the upcoming + * state. + */ + if (port->upcoming_state != invalid_state) { + upcoming_state = port->upcoming_state; + port->upcoming_state = invalid_state; + tcpm_set_state(port, upcoming_state, 0); + break; + } + + tcpm_check_send_discover(port); - tcpm_pd_transmit(port, tcpc_tx_hard_reset, null); - tcpm_set_state(port, hard_reset_start, 0); + if (port->ams != none_ams) + tcpm_ams_finish(port); + /* + * state machine will be directed to hard_reset_start, + * thus set upcoming_state to invalid_state. + */ + port->upcoming_state = invalid_state; + tcpm_ams_start(port, hard_reset); + if (port->ams == hard_reset) + tcpm_ams_finish(port); + if (port->ams == hard_reset) + tcpm_ams_finish(port); + if (port->ams == hard_reset) + tcpm_ams_finish(port); - if (port->pwr_role == typec_source) - tcpm_set_state(port, src_send_capabilities, 0); - else + if (port->pwr_role == typec_source) { + port->upcoming_state = src_send_capabilities; + tcpm_ams_start(port, power_negotiation); + } else { + } + break; + case src_soft_reset_wait_snk_tx: + case snk_soft_reset: + if (port->ams != none_ams) + tcpm_ams_finish(port); + port->upcoming_state = soft_reset_send; + tcpm_ams_start(port, soft_reset_ams); + + /* ams intermediate state */ + case ams_start: + if (port->upcoming_state == invalid_state) { + tcpm_set_state(port, port->pwr_role == typec_source ? + src_ready : snk_ready, 0); + break; + } + + upcoming_state = port->upcoming_state; + port->upcoming_state = invalid_state; + tcpm_set_state(port, upcoming_state, 0); + break; + if (port->ams != none_ams) + port->ams = none_ams; - if (port->state == snk_ready) - tcpm_set_state(port, fr_swap_send, 0); - else + if (port->state == snk_ready) { + int ret; + + port->upcoming_state = fr_swap_send; + ret = tcpm_ams_start(port, fast_role_swap); + if (ret == -eagain) + port->upcoming_state = invalid_state; + } else { + } + int ret; - tcpm_set_state(port, get_sink_cap, 0); - port->sink_cap_done = true; - + port->upcoming_state = get_sink_cap; + ret = tcpm_ams_start(port, get_sink_capabilities); + if (ret == -eagain) { + port->upcoming_state = invalid_state; + } else { + port->sink_cap_done = true; + goto unlock; + } - tcpm_set_state(port, dr_swap_send, 0); + port->upcoming_state = dr_swap_send; + ret = tcpm_ams_start(port, data_role_swap); + if (ret == -eagain) { + port->upcoming_state = invalid_state; + goto port_unlock; + } + port->upcoming_state = pr_swap_send; + ret = tcpm_ams_start(port, power_role_swap); + if (ret == -eagain) { + port->upcoming_state = invalid_state; + goto port_unlock; + } + - tcpm_set_state(port, pr_swap_send, 0); + port->upcoming_state = vconn_swap_send; + ret = tcpm_ams_start(port, vconn_swap); + if (ret == -eagain) { + port->upcoming_state = invalid_state; + goto port_unlock; + } + - tcpm_set_state(port, vconn_swap_send, 0); + port->upcoming_state = snk_negotiate_pps_capabilities; + ret = tcpm_ams_start(port, power_negotiation); + if (ret == -eagain) { + port->upcoming_state = invalid_state; + goto port_unlock; + } + - tcpm_set_state(port, snk_negotiate_pps_capabilities, 0); + port->upcoming_state = snk_negotiate_pps_capabilities; + ret = tcpm_ams_start(port, power_negotiation); + if (ret == -eagain) { + port->upcoming_state = invalid_state; + goto port_unlock; + } + - tcpm_set_state(port, snk_negotiate_pps_capabilities, 0); + if (activate) + port->upcoming_state = snk_negotiate_pps_capabilities; + else + port->upcoming_state = snk_negotiate_capabilities; + ret = tcpm_ams_start(port, power_negotiation); + if (ret == -eagain) { + port->upcoming_state = invalid_state; + goto port_unlock; + } + - tcpm_set_state(port, snk_negotiate_pps_capabilities, 0); - } else { - tcpm_set_state(port, snk_negotiate_capabilities, 0); diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h --- a/include/linux/usb/pd.h +++ b/include/linux/usb/pd.h +#define pd_t_sink_tx 16 /* 16 - 20 ms */ diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h --- a/include/linux/usb/tcpm.h +++ b/include/linux/usb/tcpm.h +/* collision avoidance */ +#define sink_tx_ng typec_cc_rp_1_5 +#define sink_tx_ok typec_cc_rp_3_0 +
Universal Serial Bus
0908c5aca31eb5e0c72d7a5dba422629b88e877d
kyle tso heikki krogerus heikki krogerus linux intel com hans de goede hdegoede redhat com
include
linux
tcpm, typec, usb
usb: typec: tcpm: protocol error handling
pd3.0 spec 6.8.1 describes how to handle protocol error. there are general rules defined in table 6-61 which regulate incoming message handling. if the incoming message is unexpected, unsupported, or unrecognized, protocol error occurs. follow the rules to handle these situations. also consider pd2.0 connection (pd2.0 spec table 6-36) for backward compatibilities.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
ams, collision avoidance, and protocol error
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['h', 'c']
2
246
90
--- diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c - s(ams_start) + s(ams_start), \ + s(chunk_not_supp) + enum tcpm_ams next_ams; - if (!tcpm_ams_interruptible(port) && ams != hard_reset) { + if (!tcpm_ams_interruptible(port) && + !(ams == hard_reset || ams == soft_reset_ams)) { - if (!port->explicit_contract) { - port->upcoming_state = invalid_state; + if (!port->explicit_contract) - return ret; - } + tcpm_set_state(port, soft_reset_send, 0); + return ret; + if (pd_vdo_vid(p[0]) != usb_sid_pd) + break; + + case vdo_cmd_vendor(0) ... vdo_cmd_vendor(15): + break; + /* unrecognized svdm */ + response[0] = p[0] | vdo_cmdt(cmdt_rsp_nak); + rlen = 1; + case cmd_discover_ident: + case cmd_discover_svid: + case cmd_discover_modes: + case vdo_cmd_vendor(0) ... vdo_cmd_vendor(15): + break; + /* unrecognized svdm */ + response[0] = p[0] | vdo_cmdt(cmdt_rsp_nak); + rlen = 1; + response[0] = p[0] | vdo_cmdt(cmdt_rsp_nak); + rlen = 1; - if (pd_vdo_svdm(p[0])) + if (pd_vdo_svdm(p[0])) { + } else { + if (port->negotiated_rev >= pd_rev30) + tcpm_queue_message(port, pd_msg_ctrl_not_supp); + } +static void tcpm_pd_handle_state(struct tcpm_port *port, + enum tcpm_state state, + enum tcpm_ams ams, + unsigned int delay_ms) +{ + switch (port->state) { + case src_ready: + case snk_ready: + port->ams = ams; + tcpm_set_state(port, state, delay_ms); + break; + /* 8.3.3.4.1.1 and 6.8.1 power transitioning */ + case snk_transition_sink: + case snk_transition_sink_vbus: + case src_transition_supply: + tcpm_set_state(port, hard_reset_send, 0); + break; + default: + if (!tcpm_ams_interruptible(port)) { + tcpm_set_state(port, port->pwr_role == typec_source ? + src_soft_reset_wait_snk_tx : + snk_soft_reset, + 0); + } else { + /* process the message 6.8.1 */ + port->upcoming_state = state; + port->next_ams = ams; + tcpm_set_state(port, ready_state(port), delay_ms); + } + break; + } +} + +static void tcpm_pd_handle_msg(struct tcpm_port *port, + enum pd_msg_request message, + enum tcpm_ams ams) +{ + switch (port->state) { + case src_ready: + case snk_ready: + port->ams = ams; + tcpm_queue_message(port, message); + break; + /* pd 3.0 spec 8.3.3.4.1.1 and 6.8.1 */ + case snk_transition_sink: + case snk_transition_sink_vbus: + case src_transition_supply: + tcpm_set_state(port, hard_reset_send, 0); + break; + default: + if (!tcpm_ams_interruptible(port)) { + tcpm_set_state(port, port->pwr_role == typec_source ? + src_soft_reset_wait_snk_tx : + snk_soft_reset, + 0); + } else { + port->next_ams = ams; + tcpm_set_state(port, ready_state(port), 0); + /* 6.8.1 process the message */ + tcpm_queue_message(port, message); + } + break; + } +} + - if (port->pwr_role != typec_sink) - break; - - if (rev == pd_rev10) + if (rev == pd_rev10) { + if (port->ams == get_source_capabilities) + tcpm_ams_finish(port); + } + if (port->pwr_role == typec_source) { + if (port->ams == get_source_capabilities) + tcpm_pd_handle_state(port, src_ready, none_ams, 0); + /* unexpected source capabilities */ + else + tcpm_pd_handle_msg(port, + port->negotiated_rev < pd_rev30 ? + pd_msg_ctrl_reject : + pd_msg_ctrl_not_supp, + none_ams); + } else if (port->state == snk_wait_capabilities) { - tcpm_set_state(port, snk_negotiate_capabilities, 0); + port->ams = power_negotiation; + tcpm_set_state(port, snk_negotiate_capabilities, 0); + } else { + if (port->ams == get_source_capabilities) + tcpm_ams_finish(port); + tcpm_pd_handle_state(port, snk_negotiate_capabilities, + power_negotiation, 0); + } - if (port->pwr_role != typec_source || - cnt != 1) { - tcpm_queue_message(port, pd_msg_ctrl_reject); - break; - } - - tcpm_queue_message(port, pd_msg_ctrl_reject); + tcpm_pd_handle_msg(port, + port->negotiated_rev < pd_rev30 ? + pd_msg_ctrl_reject : + pd_msg_ctrl_not_supp, + none_ams); + if (port->pwr_role != typec_source || cnt != 1) { + tcpm_pd_handle_msg(port, + port->negotiated_rev < pd_rev30 ? + pd_msg_ctrl_reject : + pd_msg_ctrl_not_supp, + none_ams); + break; + } + - tcpm_set_state(port, src_negotiate_capabilities, 0); + if (port->state == src_send_capabilities) + tcpm_set_state(port, src_negotiate_capabilities, 0); + else + tcpm_pd_handle_state(port, src_negotiate_capabilities, + power_negotiation, 0); - tcpm_set_state(port, snk_ready, 0); + if (port->ams == get_sink_capabilities) + tcpm_pd_handle_state(port, ready_state(port), none_ams, 0); + /* unexpected sink capabilities */ + else + tcpm_pd_handle_msg(port, + port->negotiated_rev < pd_rev30 ? + pd_msg_ctrl_reject : + pd_msg_ctrl_not_supp, + none_ams); - if (port->state == src_ready || port->state == snk_ready) { - port->bist_request = le32_to_cpu(msg->payload[0]); - tcpm_set_state(port, bist_rx, 0); - } + port->bist_request = le32_to_cpu(msg->payload[0]); + tcpm_pd_handle_state(port, bist_rx, bist, 0); - tcpm_queue_message(port, pd_msg_ctrl_not_supp); + tcpm_pd_handle_msg(port, port->negotiated_rev < pd_rev30 ? + pd_msg_ctrl_reject : + pd_msg_ctrl_not_supp, + none_ams); - tcpm_log(port, "unhandled data message type %#x", type); + tcpm_pd_handle_msg(port, port->negotiated_rev < pd_rev30 ? + pd_msg_ctrl_reject : + pd_msg_ctrl_not_supp, + none_ams); + tcpm_log(port, "unrecognized data message type %#x", type); - switch (port->state) { - case src_ready: - case snk_ready: - tcpm_queue_message(port, pd_msg_data_source_cap); - break; - default: - tcpm_queue_message(port, pd_msg_ctrl_reject); - break; - } + tcpm_pd_handle_msg(port, pd_msg_data_source_cap, get_source_capabilities); - switch (port->state) { - case src_ready: - case snk_ready: - tcpm_queue_message(port, pd_msg_data_sink_cap); - break; - default: - tcpm_queue_message(port, pd_msg_ctrl_reject); - break; - } + tcpm_pd_handle_msg(port, pd_msg_data_sink_cap, get_sink_capabilities); + tcpm_pd_handle_state(port, + port->pwr_role == typec_source ? + src_soft_reset_wait_snk_tx : + snk_soft_reset, + none_ams, 0); + tcpm_pd_handle_state(port, + port->pwr_role == typec_source ? + src_soft_reset_wait_snk_tx : + snk_soft_reset, + none_ams, 0); - port->message_id = 0; - port->rx_msgid = -1; + tcpm_pd_handle_state(port, + port->pwr_role == typec_source ? + src_soft_reset_wait_snk_tx : + snk_soft_reset, + none_ams, 0); + port->ams = soft_reset_ams; - if (port->typec_caps.data != typec_port_drd) { - tcpm_queue_message(port, pd_msg_ctrl_reject); - break; - } - switch (port->state) { - case src_ready: - case snk_ready: - tcpm_set_state(port, dr_swap_accept, 0); - break; - default: - tcpm_queue_message(port, pd_msg_ctrl_wait); - break; - } + if (port->typec_caps.data != typec_port_drd) + tcpm_pd_handle_msg(port, + port->negotiated_rev < pd_rev30 ? + pd_msg_ctrl_reject : + pd_msg_ctrl_not_supp, + none_ams); + else + tcpm_pd_handle_state(port, dr_swap_accept, data_role_swap, 0); - if (port->port_type != typec_port_drp) { - tcpm_queue_message(port, pd_msg_ctrl_reject); - break; - } - switch (port->state) { - case src_ready: - case snk_ready: - tcpm_set_state(port, pr_swap_accept, 0); - break; - default: - tcpm_queue_message(port, pd_msg_ctrl_wait); - break; - } + if (port->port_type != typec_port_drp) + tcpm_pd_handle_msg(port, + port->negotiated_rev < pd_rev30 ? + pd_msg_ctrl_reject : + pd_msg_ctrl_not_supp, + none_ams); + else + tcpm_pd_handle_state(port, pr_swap_accept, power_role_swap, 0); - switch (port->state) { - case src_ready: - case snk_ready: - tcpm_set_state(port, vconn_swap_accept, 0); - break; - default: - tcpm_queue_message(port, pd_msg_ctrl_wait); - break; - } + tcpm_pd_handle_state(port, vconn_swap_accept, vconn_swap, 0); - tcpm_queue_message(port, pd_msg_ctrl_not_supp); + tcpm_pd_handle_msg(port, + port->negotiated_rev < pd_rev30 ? + pd_msg_ctrl_reject : + pd_msg_ctrl_not_supp, + none_ams); - tcpm_log(port, "unhandled ctrl message type %#x", type); + tcpm_pd_handle_msg(port, + port->negotiated_rev < pd_rev30 ? + pd_msg_ctrl_reject : + pd_msg_ctrl_not_supp, + none_ams); + tcpm_log(port, "unrecognized ctrl message type %#x", type); + tcpm_pd_handle_msg(port, pd_msg_ctrl_not_supp, none_ams); + tcpm_pd_handle_state(port, chunk_not_supp, none_ams, pd_t_chunk_not_supp); - tcpm_set_state(port, get_pps_status_send, 0); + tcpm_pd_handle_state(port, get_pps_status_send, + getting_source_sink_status, 0); + - tcpm_set_state(port, ready_state(port), 0); + tcpm_pd_handle_state(port, ready_state(port), none_ams, 0); - tcpm_set_state(port, ready_state(port), 0); + tcpm_pd_handle_state(port, ready_state(port), none_ams, 0); - tcpm_queue_message(port, pd_msg_ctrl_not_supp); + tcpm_pd_handle_msg(port, pd_msg_ctrl_not_supp, none_ams); - tcpm_log(port, "unhandled extended message type %#x", type); + tcpm_pd_handle_msg(port, pd_msg_ctrl_not_supp, none_ams); + tcpm_log(port, "unrecognized extended message type %#x", type); - tcpm_pd_send_sink_caps(port); + ret = tcpm_pd_send_sink_caps(port); + if (ret < 0) { + tcpm_log(port, "unable to send snk caps, ret=%d", ret); + tcpm_set_state(port, snk_soft_reset, 0); + } + tcpm_ams_finish(port); + tcpm_ams_finish(port); + } else { + tcpm_ams_finish(port); + if (port->next_ams != none_ams) { + port->ams = port->next_ams; + port->next_ams = none_ams; + } + + if (port->next_ams != none_ams) { + port->ams = port->next_ams; + port->next_ams = none_ams; + } + + tcpm_ams_finish(port); + tcpm_ams_finish(port); + tcpm_ams_finish(port); + tcpm_ams_finish(port); + + /* chunk state */ + case chunk_not_supp: + tcpm_pd_send_control(port, pd_ctrl_not_supp); + tcpm_set_state(port, port->pwr_role == typec_source ? src_ready : snk_ready, 0); + break; + if (port->hard_reset_count < pd_n_hard_reset_count) + port->ams = hard_reset; diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h --- a/include/linux/usb/pd.h +++ b/include/linux/usb/pd.h +#define pd_t_chunk_not_supp 42 /* 40 - 50 ms */
Universal Serial Bus
8dea75e11380fc59656fe965766ac192a831455f
kyle tso
include
linux
tcpm, typec, usb
usb: typec: tcpm: respond wait if vdm state machine is running
port partner could send pr_swap/dr_swap/vconn_swap/request just after it enters ready states. this will cause conficts if the port is going to send disc_ident in the ready states of tcpm. set a flag indicating that the state machine is processing vdm and respond wait messages until the vdm state machine stops.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
ams, collision avoidance, and protocol error
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['c']
1
73
7
--- diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c + bool vdm_sm_running; + port->vdm_sm_running = false; + port->vdm_sm_running = false; + port->vdm_sm_running = false; + if (res == 0) + port->send_discover = false; - if (res < 0) + if (res < 0) { + port->vdm_sm_running = false; + } + if (port->vdm_state == vdm_state_err_tmout) + port->vdm_sm_running = false; + + + if (port->vdm_sm_running && port->explicit_contract) { + tcpm_pd_handle_msg(port, pd_msg_ctrl_wait, port->ams); + break; + } + + /* set vdm running flag asap */ + if (port->data_role == typec_host && + port->send_discover) + port->vdm_sm_running = true; - if (port->explicit_contract) + if (port->explicit_contract) { - else + if (port->data_role == typec_host && + port->send_discover) + port->vdm_sm_running = true; + } else { + } -eagain : -eopnotsupp); + + if (port->data_role == typec_host && + port->send_discover) + port->vdm_sm_running = true; + + if (port->data_role == typec_device && + port->send_discover) + port->vdm_sm_running = true; + - if (port->typec_caps.data != typec_port_drd) + if (port->typec_caps.data != typec_port_drd) { - else + } else { + if (port->vdm_sm_running) { + tcpm_queue_message(port, pd_msg_ctrl_wait); + break; + } + + } - if (port->port_type != typec_port_drp) + if (port->port_type != typec_port_drp) { - else + } else { + if (port->vdm_sm_running) { + tcpm_queue_message(port, pd_msg_ctrl_wait); + break; + } + + } + if (port->vdm_sm_running) { + tcpm_queue_message(port, pd_msg_ctrl_wait); + break; + } + + port->vdm_sm_running = false; + /* set vdm state machine running flag asap */ + if (port->data_role == typec_device && port->send_discover) + port->vdm_sm_running = true; + if (port->data_role == typec_host && port->send_discover) + port->vdm_sm_running = true; + if (port->data_role == typec_host && port->send_discover) + port->vdm_sm_running = true; + if (port->data_role == typec_host && port->send_discover) + port->vdm_sm_running = true; + if (port->data_role == typec_host && port->send_discover) + port->vdm_sm_running = true; + /* set the vdm flag asap */ + if (port->data_role == typec_host && port->send_discover) + port->vdm_sm_running = true;
Universal Serial Bus
8d3a0578ad1aaadb1c2a2fcc4c51454cbbce2eca
kyle tso heikki krogerus heikki krogerus linux intel com hans de goede hdegoede redhat com
drivers
usb
tcpm, typec
usb: typec: tcpm: add callback to usb communication capable partner
the usb communications capable bit indicates if port partner is capable of communication over the usb data lines (e.g. d+/- or ss tx/rx). notify the status of the bit to low level drivers to perform chip specific operation. for instance, low level driver enables usb switches on d+/d- lines to set up data path when the bit is set.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add callback to usb communication capable partner
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ', 'typec', 'tcpci']
['h', 'c']
2
18
0
--- diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c +static void tcpm_set_partner_usb_comm_capable(struct tcpm_port *port, bool capable) +{ + tcpm_log(port, "setting usb_comm capable %s", capable ? "true" : "false"); + + if (port->tcpc->set_partner_usb_comm_capable) + port->tcpc->set_partner_usb_comm_capable(port->tcpc, capable); +} + + tcpm_set_partner_usb_comm_capable(port, false); + tcpm_set_partner_usb_comm_capable(port, + !!(port->sink_request & rdo_usb_comm)); + tcpm_set_partner_usb_comm_capable(port, + !!(port->source_caps[0] & pdo_fixed_usb_comm)); diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h --- a/include/linux/usb/tcpm.h +++ b/include/linux/usb/tcpm.h + * @set_partner_usb_comm_capable: + * optional; the usb communications capable bit indicates if port + * partner is capable of communication over the usb data lines + * (e.g. d+/- or ss tx/rx). called to notify the status of the bit. + void (*set_partner_usb_comm_capable)(struct tcpc_dev *dev, bool enable);
Universal Serial Bus
a69bdb283f79949b67632878ef1822badae9299f
badhri jagan sridharan
include
linux
tcpm, typec, usb
usb: typec: tcpci: add callback to usb communication capable partner
the usb communications capable bit indicates if port partner is capable of communication over the usb data lines (e.g. d+/- or ss tx/rx). tcpm passes this information for chip specific operations.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add callback to usb communication capable partner
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ', 'typec', 'tcpci']
['h', 'c']
2
15
0
--- diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c +static void tcpci_set_partner_usb_comm_capable(struct tcpc_dev *tcpc, bool capable) +{ + struct tcpci *tcpci = tcpc_to_tcpci(tcpc); + + if (tcpci->data->set_partner_usb_comm_capable) + tcpci->data->set_partner_usb_comm_capable(tcpci, tcpci->data, capable); +} + + tcpci->tcpc.set_partner_usb_comm_capable = tcpci_set_partner_usb_comm_capable; diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h --- a/drivers/usb/typec/tcpm/tcpci.h +++ b/drivers/usb/typec/tcpm/tcpci.h + * @set_partner_usb_comm_capable: + * optional; the usb communications capable bit indicates if port + * partner is capable of communication over the usb data lines + * (e.g. d+/- or ss tx/rx). called to notify the status of the bit. + void (*set_partner_usb_comm_capable)(struct tcpci *tcpci, struct tcpci_data *data, + bool capable);
Universal Serial Bus
372a3d0b6b1e92d8138eeaed7366845a235475ef
badhri jagan sridharan heikki krogerus heikki krogerus linux intel com guenter roeck linux roeck us net
drivers
usb
tcpm, typec
usb: typec: tcpci_maxim: enable data path when partner is usb comm capable
configure usb switches when partner is usb communication capable. the is enabled usb data communication over d+/d- pins.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add callback to usb communication capable partner
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ', 'typec', 'tcpci']
['c']
1
19
0
--- diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.c b/drivers/usb/typec/tcpm/tcpci_maxim.c --- a/drivers/usb/typec/tcpm/tcpci_maxim.c +++ b/drivers/usb/typec/tcpm/tcpci_maxim.c +#define tcpc_vendor_usbsw_ctrl 0x93 +#define tcpc_vendor_usbsw_ctrl_enable_usb_data 0x9 +#define tcpc_vendor_usbsw_ctrl_disable_usb_data 0 +/* enable usb switches when partner is usb communications capable */ +static void max_tcpci_set_partner_usb_comm_capable(struct tcpci *tcpci, struct tcpci_data *data, + bool capable) +{ + struct max_tcpci_chip *chip = tdata_to_max_tcpci(data); + int ret; + + ret = max_tcpci_write8(chip, tcpc_vendor_usbsw_ctrl, capable ? + tcpc_vendor_usbsw_ctrl_enable_usb_data : + tcpc_vendor_usbsw_ctrl_disable_usb_data); + + if (ret < 0) + dev_err(chip->dev, "failed to enable usb switches"); +} + + chip->data.set_partner_usb_comm_capable = max_tcpci_set_partner_usb_comm_capable;
Universal Serial Bus
2a16e18c3400f7ab1deb826a98cf52153d03653e
badhri jagan sridharan heikki krogerus heikki krogerus linux intel com guenter roeck linux roeck us net
drivers
usb
tcpm, typec
usb: typec: manage svdm version
pd spec revision 3.0 version 2.0 + ecns 2020-12-10 6.4.4.2.3 structured vdm version "the structured vdm version field of the discover identity command sent and received during vdm discovery shall be used to determine the lowest common structured vdm version supported by the port partners or cable plug and shall continue to operate using this specification revision until they are detached."
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
common svdm version and vdo from dt
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['h', 'c']
3
65
0
--- diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c + enum usb_pd_svdm_ver svdm_version; +/** + * typec_partner_set_svdm_version - set negotiated structured vdm (svdm) version + * @partner: usb type-c partner that supports svdm + * @svdm_version: negotiated svdm version + * + * this routine is used to save the negotiated svdm version. + */ +void typec_partner_set_svdm_version(struct typec_partner *partner, + enum usb_pd_svdm_ver svdm_version) +{ + partner->svdm_version = svdm_version; +} +export_symbol_gpl(typec_partner_set_svdm_version); + + partner->svdm_version = port->cap->svdm_version; +/** + * typec_get_negotiated_svdm_version - get negotiated svdm version + * @port: usb type-c port. + * + * get the negotiated svdm version. the version is set to the port default + * value stored in typec_capability on partner registration, and updated after + * a successful discover identity if the negotiated value is less than the + * default value. + * + * returns usb_pd_svdm_ver if the partner has been registered otherwise -enodev. + */ +int typec_get_negotiated_svdm_version(struct typec_port *port) +{ + enum usb_pd_svdm_ver svdm_version; + struct device *partner_dev; + + partner_dev = device_find_child(&port->dev, null, partner_match); + if (!partner_dev) + return -enodev; + + svdm_version = to_typec_partner(partner_dev)->svdm_version; + put_device(partner_dev); + + return svdm_version; +} +export_symbol_gpl(typec_get_negotiated_svdm_version); + diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h +enum usb_pd_svdm_ver { + svdm_ver_1_0 = 0, + svdm_ver_2_0 = 1, + svdm_ver_max = svdm_ver_2_0, +}; + + * @svdm_version: usb pd structured vdm version if supported + enum usb_pd_svdm_ver svdm_version; + +void typec_partner_set_svdm_version(struct typec_partner *partner, + enum usb_pd_svdm_ver svdm_version); +int typec_get_negotiated_svdm_version(struct typec_port *port); diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_altmode.h --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h +/** + * typec_altmode_get_svdm_version - get negotiated svdm version + * @altmode: handle to the alternate mode + */ +static inline int +typec_altmode_get_svdm_version(struct typec_altmode *altmode) +{ + return typec_get_negotiated_svdm_version(typec_altmode2port(altmode)); +} +
Universal Serial Bus
3c5960c0559c44c6628341a82167ee0d3e40ee50
kyle tso
drivers
usb
typec, usb
usb: typec: tcpm: determine common svdm version
pd spec revision 3.0 version 2.0 + ecns 2020-12-10 6.4.4.2.3 structured vdm version "the structured vdm version field of the discover identity command sent and received during vdm discovery shall be used to determine the lowest common structured vdm version supported by the port partners or cable plug and shall continue to operate using this specification revision until they are detached."
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
common svdm version and vdo from dt
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['c']
1
61
10
--- diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c + struct typec_port *typec = port->typec_port; + int svdm_version; + svdm_version = typec_get_negotiated_svdm_version(typec); + if (svdm_version < 0) + return 0; + + if (pd_vdo_svdm_ver(p[0]) < svdm_version) + typec_partner_set_svdm_version(port->partner, + pd_vdo_svdm_ver(p[0])); - for (i = 0; i < port->nr_snk_vdo; i++) + /* + * product type dfp and connector type are not defined in svdm + * version 1.0 and shall be set to zero. + */ + if (typec_get_negotiated_svdm_version(typec) < svdm_ver_2_0) + response[1] = port->snk_vdo[0] & ~idh_dfp_mask + & ~idh_conn_mask; + else + response[1] = port->snk_vdo[0]; + for (i = 1; i < port->nr_snk_vdo; i++) + response[0] = (response[0] & ~vdo_svdm_vers_mask) | + (vdo_svdm_vers(typec_get_negotiated_svdm_version(typec))); + if (pd_vdo_svdm_ver(p[0]) < svdm_version) + typec_partner_set_svdm_version(port->partner, + pd_vdo_svdm_ver(p[0])); - response[0] = vdo(usb_sid_pd, 1, svdm_ver_1_0, cmd_discover_svid); + response[0] = vdo(usb_sid_pd, 1, typec_get_negotiated_svdm_version(typec), + cmd_discover_svid); - response[0] = vdo(usb_sid_pd, 1, svdm_ver_1_0, - cmd_discover_svid); + response[0] = vdo(usb_sid_pd, 1, svdm_version, cmd_discover_svid); - response[0] = vdo(modep->svids[0], 1, svdm_ver_1_0, + response[0] = vdo(modep->svids[0], 1, svdm_version, - response[0] = vdo(svid, 1, svdm_ver_1_0, cmd_discover_modes); + response[0] = vdo(svid, 1, svdm_version, cmd_discover_modes); + response[0] = (response[0] & ~vdo_svdm_vers_mask) | + (vdo_svdm_vers(svdm_version)); + response[0] = (response[0] & ~vdo_svdm_vers_mask) | + (vdo_svdm_vers(svdm_version)); + response[0] = (response[0] & ~vdo_svdm_vers_mask) | + (vdo_svdm_vers(svdm_version)); - response[0] = vdo(adev->svid, 1, svdm_ver_1_0, cmd_exit_mode); + int svdm_version = typec_get_negotiated_svdm_version( + port->typec_port); + if (svdm_version < 0) + break; + + response[0] = vdo(adev->svid, 1, svdm_version, + cmd_exit_mode); + int svdm_version = typec_get_negotiated_svdm_version(port->typec_port); + if (svdm_version < 0) + return; + - 1 : (pd_vdo_cmd(cmd) <= cmd_attention), svdm_ver_1_0, cmd); + 1 : (pd_vdo_cmd(cmd) <= cmd_attention), + svdm_version, cmd); + int svdm_version; - header = vdo(altmode->svid, vdo ? 2 : 1, svdm_ver_1_0, cmd_enter_mode); + svdm_version = typec_get_negotiated_svdm_version(port->typec_port); + if (svdm_version < 0) + return svdm_version; + + header = vdo(altmode->svid, vdo ? 2 : 1, svdm_version, cmd_enter_mode); + int svdm_version; - header = vdo(altmode->svid, 1, svdm_ver_1_0, cmd_exit_mode); + svdm_version = typec_get_negotiated_svdm_version(port->typec_port); + if (svdm_version < 0) + return svdm_version; + + header = vdo(altmode->svid, 1, svdm_version, cmd_exit_mode); + port->typec_caps.svdm_version = svdm_ver_2_0;
Universal Serial Bus
5e1d4c49fbc86dab6e005d66f066bd53c9479cde
kyle tso
drivers
usb
tcpm, typec
usb: typec: ucsi: determine common svdm version
this patch implements the following requirement in the spec.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
common svdm version and vdo from dt
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['c']
2
30
3
--- diff --git a/drivers/usb/typec/ucsi/displayport.c b/drivers/usb/typec/ucsi/displayport.c --- a/drivers/usb/typec/ucsi/displayport.c +++ b/drivers/usb/typec/ucsi/displayport.c + int svdm_version; - dp->header = vdo(usb_typec_dp_sid, 1, svdm_ver_1_0, cmd_enter_mode); + svdm_version = typec_altmode_get_svdm_version(alt); + if (svdm_version < 0) { + ret = svdm_version; + goto err_unlock; + } + + dp->header = vdo(usb_typec_dp_sid, 1, svdm_version, cmd_enter_mode); + int svdm_version; - dp->header = vdo(usb_typec_dp_sid, 1, svdm_ver_1_0, cmd_exit_mode); + svdm_version = typec_altmode_get_svdm_version(alt); + if (svdm_version < 0) { + ret = svdm_version; + goto out_unlock; + } + + dp->header = vdo(usb_typec_dp_sid, 1, svdm_version, cmd_exit_mode); + int svdm_version; + svdm_version = typec_altmode_get_svdm_version(alt); + if (svdm_version < 0) { + mutex_unlock(&dp->con->lock); + return svdm_version; + } + - dp->header = vdo(usb_typec_dp_sid, 1, svdm_ver_1_0, cmd); + if (pd_vdo_svdm_ver(header) < svdm_version) { + typec_partner_set_svdm_version(dp->con->partner, pd_vdo_svdm_ver(header)); + svdm_version = pd_vdo_svdm_ver(header); + } + + dp->header = vdo(usb_typec_dp_sid, 1, svdm_version, cmd); diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c + cap->svdm_version = svdm_ver_2_0;
Universal Serial Bus
372adf075a43028a62e6123b9cd969f8f20e4afc
kyle tso
drivers
usb
typec, ucsi
usb: typec: displayport: fill the negotiated svdm version in the header
vdm header now requires svdm version. get it from typec_partner.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
common svdm version and vdo from dt
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['c']
1
13
4
--- diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c -#define dp_header(_dp, cmd) (vdo((_dp)->alt->svid, 1, svdm_ver_1_0, cmd) | \ - vdo_opos(usb_typec_dp_mode)) +#define dp_header(_dp, ver, cmd) (vdo((_dp)->alt->svid, 1, ver, cmd) \ + | vdo_opos(usb_typec_dp_mode)) - u32 header = dp_header(dp, dp_cmd_configure); + int svdm_version = typec_altmode_get_svdm_version(dp->alt); + u32 header; + if (svdm_version < 0) + return svdm_version; + + header = dp_header(dp, svdm_version, dp_cmd_configure); + int svdm_version; - header = dp_header(dp, dp_cmd_status_update); + svdm_version = typec_altmode_get_svdm_version(dp->alt); + if (svdm_version < 0) + break; + header = dp_header(dp, svdm_version, dp_cmd_status_update);
Universal Serial Bus
4c93cad8cc78bd382aded3155cf05736ecfd0910
kyle tso heikki krogerus heikki krogerus linux intel com
drivers
usb
altmodes, typec
dt-bindings: connector: add svdm vdo properties
add bindings of vdo properties of usb pd svdm so that they can be used in device tree.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
common svdm version and vdo from dt
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['yaml', 'h']
2
321
1
--- diff --git a/documentation/devicetree/bindings/connector/usb-connector.yaml b/documentation/devicetree/bindings/connector/usb-connector.yaml --- a/documentation/devicetree/bindings/connector/usb-connector.yaml +++ b/documentation/devicetree/bindings/connector/usb-connector.yaml + sink-vdos: + description: an array of u32 with each entry (vdm objects) providing additional information + corresponding to the product, the detailed bit definitions and the order of each vdo can be + found in "usb power delivery specification revision 3.0, version 2.0 + ecns 2020-12-10" + chapter 6.4.4.3.1 discover identity. user can specify the vdo array via + vdo_idh/_cert/_product/_ufp/_dfp/_pcable/_acable(1/2)/_vpd() defined in + dt-bindings/usb/pd.h. + minitems: 3 + maxitems: 6 + $ref: /schemas/types.yaml#/definitions/uint32-array + diff --git a/include/dt-bindings/usb/pd.h b/include/dt-bindings/usb/pd.h --- a/include/dt-bindings/usb/pd.h +++ b/include/dt-bindings/usb/pd.h - #endif /* __dt_power_delivery_h */ + +/* + * svdm identity header + * -------------------- + * <31> :: data capable as a usb host + * <30> :: data capable as a usb device + * <29:27> :: product type (ufp / cable / vpd) + * <26> :: modal operation supported (1b == yes) + * <25:23> :: product type (dfp) (svdm version 2.0+ only; set to zero in version 1.0) + * <22:21> :: connector type (svdm version 2.0+ only; set to zero in version 1.0) + * <20:16> :: reserved, shall be set to zero + * <15:0> :: usb-if assigned vid for this cable vendor + */ +/* sop product type (ufp) */ +#define idh_ptype_not_ufp 0 +#define idh_ptype_hub 1 +#define idh_ptype_periph 2 +#define idh_ptype_psd 3 +#define idh_ptype_ama 5 + +/* sop' product type (cable plug / vpd) */ +#define idh_ptype_not_cable 0 +#define idh_ptype_pcable 3 +#define idh_ptype_acable 4 +#define idh_ptype_vpd 6 + +/* sop product type (dfp) */ +#define idh_ptype_not_dfp 0 +#define idh_ptype_dfp_hub 1 +#define idh_ptype_dfp_host 2 +#define idh_ptype_dfp_pb 3 + +#define vdo_idh(usbh, usbd, ufp_cable, is_modal, dfp, conn, vid) \ + ((usbh) << 31 | (usbd) << 30 | ((ufp_cable) & 0x7) << 27 \ + | (is_modal) << 26 | ((dfp) & 0x7) << 23 | ((conn) & 0x3) << 21 \ + | ((vid) & 0xffff)) + +/* + * cert stat vdo + * ------------- + * <31:0> : usb-if assigned xid for this cable + */ +#define vdo_cert(xid) ((xid) & 0xffffffff) + +/* + * product vdo + * ----------- + * <31:16> : usb product id + * <15:0> : usb bcddevice + */ +#define vdo_product(pid, bcd) (((pid) & 0xffff) << 16 | ((bcd) & 0xffff)) + +/* + * ufp vdo (pd revision 3.0+ only) + * -------- + * <31:29> :: ufp vdo version + * <28> :: reserved + * <27:24> :: device capability + * <23:22> :: connector type (10b == receptacle, 11b == captive plug) + * <21:11> :: reserved + * <10:8> :: vconn power (ama only) + * <7> :: vconn required (ama only, 0b == no, 1b == yes) + * <6> :: vbus required (ama only, 0b == yes, 1b == no) + * <5:3> :: alternate modes + * <2:0> :: usb highest speed + */ +/* ufp vdo version */ +#define ufp_vdo_ver1_2 2 + +/* device capability */ +#define dev_usb2_capable bit(0) +#define dev_usb2_billboard bit(1) +#define dev_usb3_capable bit(2) +#define dev_usb4_capable bit(3) + +/* connector type */ +#define ufp_receptacle 2 +#define ufp_captive 3 + +/* vconn power (ama only, set to ama_vconn_not_req if vconn is not required) */ +#define ama_vconn_pwr_1w 0 +#define ama_vconn_pwr_1w5 1 +#define ama_vconn_pwr_2w 2 +#define ama_vconn_pwr_3w 3 +#define ama_vconn_pwr_4w 4 +#define ama_vconn_pwr_5w 5 +#define ama_vconn_pwr_6w 6 + +/* vconn required (ama only) */ +#define ama_vconn_not_req 0 +#define ama_vconn_req 1 + +/* vbus required (ama only) */ +#define ama_vbus_req 0 +#define ama_vbus_not_req 1 + +/* alternate modes */ +#define ufp_altmode_not_supp 0 +#define ufp_altmode_tbt3 bit(0) +#define ufp_altmode_recfg bit(1) +#define ufp_altmode_no_recfg bit(2) + +/* usb highest speed */ +#define ufp_usb2_only 0 +#define ufp_usb32_gen1 1 +#define ufp_usb32_4_gen2 2 +#define ufp_usb4_gen3 3 + +#define vdo_ufp(ver, cap, conn, vcpwr, vcr, vbr, alt, spd) \ + (((ver) & 0x7) << 29 | ((cap) & 0xf) << 24 | ((conn) & 0x3) << 22 \ + | ((vcpwr) & 0x7) << 8 | (vcr) << 7 | (vbr) << 6 | ((alt) & 0x7) << 3 \ + | ((spd) & 0x7)) + +/* + * dfp vdo (pd revision 3.0+ only) + * -------- + * <31:29> :: dfp vdo version + * <28:27> :: reserved + * <26:24> :: host capability + * <23:22> :: connector type (10b == receptacle, 11b == captive plug) + * <21:5> :: reserved + * <4:0> :: port number + */ +#define dfp_vdo_ver1_1 1 +#define host_usb2_capable bit(0) +#define host_usb3_capable bit(1) +#define host_usb4_capable bit(2) +#define dfp_receptacle 2 +#define dfp_captive 3 + +#define vdo_dfp(ver, cap, conn, pnum) \ + (((ver) & 0x7) << 29 | ((cap) & 0x7) << 24 | ((conn) & 0x3) << 22 \ + | ((pnum) & 0x1f)) + +/* + * passive cable vdo + * --------- + * <31:28> :: cable hw version + * <27:24> :: cable fw version + * <23:21> :: vdo version + * <20> :: reserved, shall be set to zero + * <19:18> :: type-c to type-c/captive (10b == c, 11b == captive) + * <17> :: reserved, shall be set to zero + * <16:13> :: cable latency (0001 == <10ns(~1m length)) + * <12:11> :: cable termination type (10b == vconn not req, 01b == vconn req) + * <10:9> :: maximum vbus voltage (00b == 20v, 01b == 30v, 10b == 40v, 11b == 50v) + * <8:7> :: reserved, shall be set to zero + * <6:5> :: vbus current handling capability (01b == 3a, 10b == 5a) + * <4:3> :: reserved, shall be set to zero + * <2:0> :: usb highest speed + * + * active cable vdo 1 + * --------- + * <31:28> :: cable hw version + * <27:24> :: cable fw version + * <23:21> :: vdo version + * <20> :: reserved, shall be set to zero + * <19:18> :: connector type (10b == c, 11b == captive) + * <17> :: reserved, shall be set to zero + * <16:13> :: cable latency (0001 == <10ns(~1m length)) + * <12:11> :: cable termination type (10b == one end active, 11b == both ends active vconn req) + * <10:9> :: maximum vbus voltage (00b == 20v, 01b == 30v, 10b == 40v, 11b == 50v) + * <8> :: sbu supported (0b == supported, 1b == not supported) + * <7> :: sbu type (0b == passive, 1b == active) + * <6:5> :: vbus current handling capability (01b == 3a, 10b == 5a) + * <4> :: vbus through cable (0b == no, 1b == yes) + * <3> :: sop" controller present? (0b == no, 1b == yes) + * <2:0> :: usb highest speed + */ +/* cable vdo version */ +#define cable_vdo_ver1_0 0 +#define cable_vdo_ver1_3 3 + +/* connector type */ +#define cable_ctype 2 +#define cable_captive 3 + +/* cable latency */ +#define cable_latency_1m 1 +#define cable_latency_2m 2 +#define cable_latency_3m 3 +#define cable_latency_4m 4 +#define cable_latency_5m 5 +#define cable_latency_6m 6 +#define cable_latency_7m 7 +#define cable_latency_7m_plus 8 + +/* cable termination type */ +#define pcable_vconn_not_req 0 +#define pcable_vconn_req 1 +#define acable_one_end 2 +#define acable_both_end 3 + +/* maximum vbus voltage */ +#define cable_max_vbus_20v 0 +#define cable_max_vbus_30v 1 +#define cable_max_vbus_40v 2 +#define cable_max_vbus_50v 3 + +/* active cable sbu supported/type */ +#define acable_sbu_supp 0 +#define acable_sbu_not_supp 1 +#define acable_sbu_passive 0 +#define acable_sbu_active 1 + +/* vbus current handling capability */ +#define cable_curr_def 0 +#define cable_curr_3a 1 +#define cable_curr_5a 2 + +/* usb highest speed */ +#define cable_usb2_only 0 +#define cable_usb32_gen1 1 +#define cable_usb32_4_gen2 2 +#define cable_usb4_gen3 3 + +#define vdo_pcable(hw, fw, ver, conn, lat, term, vbm, cur, spd) \ + (((hw) & 0xf) << 28 | ((fw) & 0xf) << 24 | ((ver) & 0x7) << 21 \ + | ((conn) & 0x3) << 18 | ((lat) & 0xf) << 13 | ((term) & 0x3) << 11 \ + | ((vbm) & 0x3) << 9 | ((cur) & 0x3) << 5 | ((spd) & 0x7)) +#define vdo_acable1(hw, fw, ver, conn, lat, term, vbm, sbu, sbut, cur, vbt, sopp, spd) \ + (((hw) & 0xf) << 28 | ((fw) & 0xf) << 24 | ((ver) & 0x7) << 21 \ + | ((conn) & 0x3) << 18 | ((lat) & 0xf) << 13 | ((term) & 0x3) << 11 \ + | ((vbm) & 0x3) << 9 | (sbu) << 8 | (sbut) << 7 | ((cur) & 0x3) << 5 \ + | (vbt) << 4 | (sopp) << 3 | ((spd) & 0x7)) + +/* + * active cable vdo 2 + * --------- + * <31:24> :: maximum operating temperature + * <23:16> :: shutdown temperature + * <15> :: reserved, shall be set to zero + * <14:12> :: u3/cld power + * <11> :: u3 to u0 transition mode (0b == direct, 1b == through u3s) + * <10> :: physical connection (0b == copper, 1b == optical) + * <9> :: active element (0b == redriver, 1b == retimer) + * <8> :: usb4 supported (0b == yes, 1b == no) + * <7:6> :: usb2 hub hops consumed + * <5> :: usb2 supported (0b == yes, 1b == no) + * <4> :: usb3.2 supported (0b == yes, 1b == no) + * <3> :: usb lanes supported (0b == one lane, 1b == two lanes) + * <2> :: optically isolated active cable (0b == no, 1b == yes) + * <1> :: reserved, shall be set to zero + * <0> :: usb gen (0b == gen1, 1b == gen2+) + */ +/* u3/cld power*/ +#define acab2_u3_cld_10mw_plus 0 +#define acab2_u3_cld_10mw 1 +#define acab2_u3_cld_5mw 2 +#define acab2_u3_cld_1mw 3 +#define acab2_u3_cld_500uw 4 +#define acab2_u3_cld_200uw 5 +#define acab2_u3_cld_50uw 6 + +/* other active cable vdo 2 fields */ +#define acab2_u3u0_direct 0 +#define acab2_u3u0_u3s 1 +#define acab2_phy_copper 0 +#define acab2_phy_optical 1 +#define acab2_redriver 0 +#define acab2_retimer 1 +#define acab2_usb4_supp 0 +#define acab2_usb4_not_supp 1 +#define acab2_usb2_supp 0 +#define acab2_usb2_not_supp 1 +#define acab2_usb32_supp 0 +#define acab2_usb32_not_supp 1 +#define acab2_lanes_one 0 +#define acab2_lanes_two 1 +#define acab2_opt_iso_no 0 +#define acab2_opt_iso_yes 1 +#define acab2_gen_1 0 +#define acab2_gen_2_plus 1 + +#define vdo_acable2(mtemp, stemp, u3p, trans, phy, ele, u4, hops, u2, u32, lane, iso, gen) \ + (((mtemp) & 0xff) << 24 | ((stemp) & 0xff) << 16 | ((u3p) & 0x7) << 12 \ + | (trans) << 11 | (phy) << 10 | (ele) << 9 | (u4) << 8 \ + | ((hops) & 0x3) << 6 | (u2) << 5 | (u32) << 4 | (lane) << 3 \ + | (iso) << 2 | (gen)) + +/* + * vpd vdo + * --------- + * <31:28> :: hw version + * <27:24> :: fw version + * <23:21> :: vdo version + * <20:17> :: reserved, shall be set to zero + * <16:15> :: maximum vbus voltage (00b == 20v, 01b == 30v, 10b == 40v, 11b == 50v) + * <14> :: charge through current support (0b == 3a, 1b == 5a) + * <13> :: reserved, shall be set to zero + * <12:7> :: vbus impedance + * <6:1> :: ground impedance + * <0> :: charge through support (0b == no, 1b == yes) + */ +#define vpd_vdo_ver1_0 0 +#define vpd_max_vbus_20v 0 +#define vpd_max_vbus_30v 1 +#define vpd_max_vbus_40v 2 +#define vpd_max_vbus_50v 3 +#define vpdct_curr_3a 0 +#define vpdct_curr_5a 1 +#define vpdct_not_supp 0 +#define vpdct_supp 1 + +#define vdo_vpd(hw, fw, ver, vbm, curr, vbi, gi, ct) \ + (((hw) & 0xf) << 28 | ((fw) & 0xf) << 24 | ((ver) & 0x7) << 21 \ + | ((vbm) & 0x3) << 15 | (curr) << 14 | ((vbi) & 0x3f) << 7 \ + | ((gi) & 0x3f) << 1 | (ct)) + +#endif /* __dt_power_delivery_h */
Universal Serial Bus
630dce2810b9f09d312aed4189300e785254c24b
kyle tso heikki krogerus heikki krogerus linux intel com rob herring robh kernel org
documentation
devicetree
bindings, connector, usb
usb: typec: tcpm: get sink vdo from fwnode
commit a079973f462a ("usb: typec: tcpm: remove tcpc_config configuration mechanism") removed the tcpc_config which includes the sink vdo and it is not yet added back with fwnode. add it now.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
common svdm version and vdo from dt
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['typec ']
['c']
1
14
0
--- diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c + /* sink-vdos is optional */ + ret = fwnode_property_count_u32(fwnode, "sink-vdos"); + if (ret < 0) + ret = 0; + + port->nr_snk_vdo = min(ret, vdo_max_objects); + if (port->nr_snk_vdo) { + ret = fwnode_property_read_u32_array(fwnode, "sink-vdos", + port->snk_vdo, + port->nr_snk_vdo); + if (ret < 0) + return ret; + } +
Universal Serial Bus
f5d1d63e7359c6b3c65097b4941756b3d8ac0be0
kyle tso heikki krogerus heikki krogerus linux intel com
drivers
usb
tcpm, typec
usb: usbtmc: add usbtmc_ioctl_get_stb
this new ioctl reads the status byte (stb) from the device and returns the stb unmodified to the application. the srq_asserted bit is not taken into account and not changed.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['usbtmc']
['h', 'c']
2
8
0
--- diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c + case usbtmc_ioctl_get_stb: + retval = usbtmc_get_stb(file_data, &tmp_byte); + if (retval > 0) + retval = put_user(tmp_byte, (__u8 __user *)arg); + break; + diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h --- a/include/uapi/linux/usb/tmc.h +++ b/include/uapi/linux/usb/tmc.h +#define usbtmc_ioctl_get_stb _ior(usbtmc_ioc_nr, 26, __u8) +
Universal Serial Bus
c9784e23c1020e63d6dba5e10ca8bf3d8b85c19c
dave penkler
drivers
usb
class, linux, usb
usb: usbtmc: add separate usbtmc_ioctl_get_srq_stb
this new ioctl only returns the status byte (stb) that was originally sent by the device due to a service request (srq) condition.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['usbtmc']
['h', 'c']
2
32
0
--- diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c +static int usbtmc_ioctl_get_srq_stb(struct usbtmc_file_data *file_data, + void __user *arg) +{ + struct usbtmc_device_data *data = file_data->data; + struct device *dev = &data->intf->dev; + int srq_asserted = 0; + __u8 stb = 0; + int rv; + + spin_lock_irq(&data->dev_lock); + srq_asserted = atomic_xchg(&file_data->srq_asserted, srq_asserted); + + if (srq_asserted) { + stb = file_data->srq_byte; + spin_unlock_irq(&data->dev_lock); + rv = put_user(stb, (__u8 __user *)arg); + } else { + spin_unlock_irq(&data->dev_lock); + rv = -enomsg; + } + + dev_dbg(dev, "stb:0x%02x with srq received %d ", (unsigned int)stb, rv); + + return rv; +} + + case usbtmc_ioctl_get_srq_stb: + retval = usbtmc_ioctl_get_srq_stb(file_data, + (void __user *)arg); + break; + diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h --- a/include/uapi/linux/usb/tmc.h +++ b/include/uapi/linux/usb/tmc.h +#define usbtmc_ioctl_get_srq_stb _ior(usbtmc_ioc_nr, 27, __u8)
Universal Serial Bus
d1d9defdc6d582119d29f5d88f810b72bb1837fa
dave penkler
drivers
usb
class, linux, usb
usb: bdc: remove the bdc pci driver
the bdc pci driver was only used for design verification with an pci/fpga board. the board no longer exists and is not in use anywhere. all instances of this core now exist as a memory mapped device on the platform bus.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
remove the bdc pci driver
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['bdc']
['kconfig', 'c', 'makefile']
3
0
141
--- diff --git a/drivers/usb/gadget/udc/bdc/kconfig b/drivers/usb/gadget/udc/bdc/kconfig --- a/drivers/usb/gadget/udc/bdc/kconfig +++ b/drivers/usb/gadget/udc/bdc/kconfig - -if usb_bdc_udc - -comment "platform support" -config usb_bdc_pci - tristate "bdc support for pcie based platforms" - depends on usb_pci - default usb_bdc_udc - help - enable support for platforms which have bdc connected through pcie, such as lego3 fpga platform. -endif diff --git a/drivers/usb/gadget/udc/bdc/makefile b/drivers/usb/gadget/udc/bdc/makefile --- a/drivers/usb/gadget/udc/bdc/makefile +++ b/drivers/usb/gadget/udc/bdc/makefile - -obj-$(config_usb_bdc_pci) += bdc_pci.o diff --git a/drivers/usb/gadget/udc/bdc/bdc_pci.c b/drivers/usb/gadget/udc/bdc/bdc_pci.c --- a/drivers/usb/gadget/udc/bdc/bdc_pci.c +++ /dev/null -// spdx-license-identifier: gpl-2.0+ -/* - * bdc_pci.c - brcm bdc usb3.0 device controller pci interface file. - * - * copyright (c) 2014 broadcom corporation - * - * author: ashwini pahuja - * - * based on drivers under drivers/usb/ - */ - -#include <linux/kernel.h> -#include <linux/module.h> -#include <linux/slab.h> -#include <linux/pci.h> -#include <linux/pci_ids.h> -#include <linux/platform_device.h> - -#include "bdc.h" - -#define bdc_pci_pid 0x1570 - -struct bdc_pci { - struct device *dev; - struct platform_device *bdc; -}; - -static int bdc_setup_msi(struct pci_dev *pci) -{ - int ret; - - ret = pci_enable_msi(pci); - if (ret) { - pr_err("failed to allocate msi entry "); - return ret; - } - - return ret; -} - -static int bdc_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) -{ - struct resource res[2]; - struct platform_device *bdc; - struct bdc_pci *glue; - int ret = -enomem; - - glue = devm_kzalloc(&pci->dev, sizeof(*glue), gfp_kernel); - if (!glue) - return -enomem; - - glue->dev = &pci->dev; - ret = pci_enable_device(pci); - if (ret) { - dev_err(&pci->dev, "failed to enable pci device "); - return -enodev; - } - pci_set_master(pci); - - bdc = platform_device_alloc(brcm_bdc_name, platform_devid_auto); - if (!bdc) - return -enomem; - - memset(res, 0x00, sizeof(struct resource) * array_size(res)); - bdc_setup_msi(pci); - - res[0].start = pci_resource_start(pci, 0); - res[0].end = pci_resource_end(pci, 0); - res[0].name = brcm_bdc_name; - res[0].flags = ioresource_mem; - - res[1].start = pci->irq; - res[1].name = brcm_bdc_name; - res[1].flags = ioresource_irq; - - ret = platform_device_add_resources(bdc, res, array_size(res)); - if (ret) { - dev_err(&pci->dev, - "couldn't add resources to bdc device "); - platform_device_put(bdc); - return ret; - } - - pci_set_drvdata(pci, glue); - - dma_set_coherent_mask(&bdc->dev, pci->dev.coherent_dma_mask); - - bdc->dev.dma_mask = pci->dev.dma_mask; - bdc->dev.dma_parms = pci->dev.dma_parms; - bdc->dev.parent = &pci->dev; - glue->bdc = bdc; - - ret = platform_device_add(bdc); - if (ret) { - dev_err(&pci->dev, "failed to register bdc device "); - platform_device_put(bdc); - return ret; - } - - return 0; -} - -static void bdc_pci_remove(struct pci_dev *pci) -{ - struct bdc_pci *glue = pci_get_drvdata(pci); - - platform_device_unregister(glue->bdc); - pci_disable_msi(pci); -} - -static struct pci_device_id bdc_pci_id_table[] = { - { pci_device(pci_vendor_id_broadcom, bdc_pci_pid), }, - {} /* terminating entry */ -}; - -module_device_table(pci, bdc_pci_id_table); - -static struct pci_driver bdc_pci_driver = { - .name = "bdc-pci", - .id_table = bdc_pci_id_table, - .probe = bdc_pci_probe, - .remove = bdc_pci_remove, -}; - -module_author("ashwini pahuja <ashwini.linux@gmail.com>"); -module_license("gpl"); -module_description("brcm bdc usb3 pci glue layer"); -module_pci_driver(bdc_pci_driver);
Universal Serial Bus
7766cafea0eca6a7cc0ffc947bc95be19295575f
al cooper
drivers
usb
bdc, gadget, udc
spi: cadence-quadspi: add qspi support for intel lgm soc
add qspi controller support for intel lgm soc.
this release allows to map an uid to a different one in a mount; it also adds support for selecting the preemption model at runtime; support for a low-overhead memory error detector designed to be used in production; support for the acrn hypervisor designed for embedded systems; btrfs initial support for zoned devices, subpage blocks sizes and performance improvements; support for eager nfs writes; support for a thermal power management to control the surface temperature of embedded devices in an unified way; the napi polling can be moved to a kernel thread; and support for non-blocking path lookups. as always, there are many other features, new drivers, improvements and fixes.
add qspi controller support for intel lgm soc
['core (various)', 'file systems', 'memory management', 'block layer', 'tracing, perf and bpf', 'virtualization', 'cryptography', 'security', 'networking', 'architectures x86 arm risc-v powerpc mips csky s390 pa-risc c6x']
['graphics', 'power management', 'storage', 'drivers in the staging area', 'networking', 'audio', 'tablets, touch screens, keyboards, mouses', 'tv tuners, webcams, video capturers', 'universal serial bus', 'serial peripheral interface (spi)', 'watchdog', 'serial', 'cpu frequency scaling', 'device voltage and frequency scaling', 'voltage, current regulators, power capping, power supply', 'real time clock (rtc)', 'pin controllers (pinctrl)', 'multi media card (mmc)', 'memory technology devices (mtd)', 'industrial i/o (iio)', 'multi function devices (mfd)', 'pulse-width modulation (pwm)', 'inter-integrated circuit (i2c + i3c)', 'hardware monitoring (hwmon)', 'general purpose i/o (gpio)', 'leds', 'dma engines', 'cryptography hardware acceleration', 'pci', 'non-transparent bridge (ntb)', 'thunderbolt', 'clock', 'phy ("physical layer" framework)', 'cxl (compute express link)', 'various']
['cadence-quadspi']
['kconfig', 'c']
2
4
1
--- diff --git a/drivers/spi/kconfig b/drivers/spi/kconfig --- a/drivers/spi/kconfig +++ b/drivers/spi/kconfig - depends on of && (arm || arm64 || compile_test) + depends on of && (arm || arm64 || x86 || compile_test) diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c --- a/drivers/spi/spi-cadence-quadspi.c +++ b/drivers/spi/spi-cadence-quadspi.c + { + .compatible = "intel,lgm-qspi", + },
Serial Peripheral Interface (SPI)
ab2d28750aacb773dc42d72fbad59146e8a6db5e
ramuthevar vadivel murugan
drivers
spi